pkt = defragment_l2cap(pkt)

        if encryption_enabled and pkt:
            # Manually save packets here
            driver.packets_buffer.append(
                NORDIC_BLE(board=75, protocol=2, flags=0x01) / pkt)

        # if packet is incorrectly decoded, you may not be using the dongle
        if pkt is None:
            none_count += 1
            if none_count >= 16:
                print(Fore.RED + 'NRF52 Dongle not detected')
                sys.exit(0)
            continue
        elif BTLE_DATA in pkt and BTLE_EMPTY_PDU not in pkt:
            update_timeout('scan_timeout')
            # Print slave data channel PDUs summary
            if not encryption_enabled:
                print(Fore.MAGENTA + "RX <--- " + pkt.summary()[7:])
            else:
                print(Fore.MAGENTA + "RX <--- [Encrypted]{" +
                      pkt.summary()[7:] + "}")

        if BTLE_DATA in pkt:
            none_count = 0
            update_timeout('crash_timeout')
        # --------------- Process Link Layer Packets here ------------------------------------
        # Check if packet from advertised is received
        if (
                BTLE_SCAN_RSP in pkt or BTLE_ADV_IND in pkt
        ) and pkt.AdvA == advertiser_address.lower() and connecting == False:
예제 #2
0
while True:
    pkt = None
    # Receive packet from the NRF52 Dongle
    data = driver.raw_receive()
    if data:
        # Decode Bluetooth Low Energy Data
        pkt = BTLE(data)
        # if packet is incorrectly decoded, you may not be using the dongle
        if pkt is None:
            none_count += 1
            if none_count >= 4:
                print(Fore.RED + 'NRF52 Dongle not detected')
                sys.exit(0)
            continue
        elif BTLE_DATA in pkt and BTLE_EMPTY_PDU not in pkt:
            update_timeout('scan_timeout')
            # Print slave data channel PDUs summary
            print(Fore.MAGENTA + "Slave RX <--- " + pkt.summary()[7:])
        # --------------- Process Link Layer Packets here ------------------------------------
        # Check if packet from advertised is received
        if pkt and (BTLE_SCAN_RSP in pkt or BTLE_ADV in pkt) and pkt.AdvA == advertiser_address.lower() \
                and connecting == False:
            connecting = True
            update_timeout('scan_timeout')
            disable_timeout('crash_timeout')
            slave_addr_type = pkt.TxAdd

            print(Fore.GREEN + advertiser_address.upper() + ': ' +
                  pkt.summary()[7:] + ' Detected')
            # Send connection request to advertiser
            conn_request = BTLE(