Exemple #1
0
def print_packet(pkt):
    # Further decode and print the packet
    dpkt = DPacketMessage.decode(pkt)
    print(dpkt)

    if isinstance(dpkt, ConnectIndMessage):
        hw.decoder_state.cur_aa = dpkt.aa
Exemple #2
0
def handle_packet(pkt):
    # Further decode the packet
    dpkt = DPacketMessage.decode(pkt)

    # Ignore non-advertisements (shouldn't get any)
    if not isinstance(dpkt, AdvertMessage):
        print("Unexpected packet")
        print(dpkt)
        print()
        return

    global advertisers

    if isinstance(dpkt, _AdvaMessage) or isinstance(
            dpkt, AdvDirectIndMessage) or (isinstance(dpkt, AdvExtIndMessage)
                                           and dpkt.AdvA is not None):
        adva = _str_mac(dpkt.AdvA)

        if not adva in advertisers:
            advertisers[adva] = Advertiser()
            print("Found %s..." % adva)

        advertisers[adva].rssi = dpkt.rssi
        advertisers[adva].hits += 1

        if isinstance(dpkt, ScanRspMessage):
            advertisers[adva].scan_rsp = dpkt
        else:
            advertisers[adva].adv = dpkt
def print_packet(pkt, quiet):
    # Further decode and print the packet
    dpkt = DPacketMessage.decode(pkt)
    if not (quiet and isinstance(dpkt, DataMessage) and dpkt.data_length == 0):
        print(dpkt, end='\n\n')

    # Record the packet if PCAP writing is enabled
    if pcwriter:
        if isinstance(dpkt, DataMessage):
            pdu_type = 3 if dpkt.data_dir else 2
        else:
            pdu_type = 0
        pcwriter.write_packet(int(pkt.ts_epoch * 1000000), pkt.aa, pkt.chan,
                              pkt.rssi, pkt.body, pkt.phy, pdu_type)

    # React to the packet
    if isinstance(dpkt, AdvaMessage) or isinstance(
            dpkt, AdvDirectIndMessage) or (isinstance(dpkt, AdvExtIndMessage)
                                           and dpkt.AdvA is not None):
        _dtm(dpkt.AdvA)

    if isinstance(dpkt, ConnectIndMessage):
        # PCAP write is already done here, safe to update cur_aa
        hw.decoder_state.cur_aa = dpkt.aa_conn
        hw.decoder_state.last_chan = -1
Exemple #4
0
def get_mac_from_irk():
    hw.mark_and_flush()
    print("Waiting for advertisement with suitable RPA...")
    while True:
        msg = hw.recv_and_decode()
        if not isinstance(msg, PacketMessage):
            continue
        dpkt = DPacketMessage.decode(msg)
        if isinstance(dpkt, AdvaMessage) or \
                isinstance(dpkt, AdvDirectIndMessage) or \
                (isinstance(dpkt, AdvExtIndMessage) and dpkt.AdvA is not None):
            print("Found target MAC: %s" % str_mac(dpkt.AdvA))
            return dpkt.AdvA
Exemple #5
0
def print_packet(pkt):
    if pcwriter:
        pcwriter.write_packet(int(pkt.ts_epoch * 1000000), pkt.aa, pkt.chan, pkt.rssi, pkt.body)

    # Further decode and print the packet
    dpkt = DPacketMessage.decode(pkt)
    print(dpkt)

    # React to the packet
    if isinstance(dpkt, AdvaMessage) or isinstance(dpkt, AdvDirectIndMessage) or (
            isinstance(dpkt, AdvExtIndMessage) and dpkt.AdvA is not None):
        _dtm(dpkt.AdvA)

    if isinstance(dpkt, ConnectIndMessage):
        # PCAP write is already done here, safe to update cur_aa
        hw.decoder_state.cur_aa = dpkt.aa
Exemple #6
0
def print_packet(pkt):
    # Further decode and print the packet
    dpkt = DPacketMessage.decode(pkt)
    print(dpkt)

    # do a ping every fourth message
    global msg_ctr
    MCMASK = 3
    if (msg_ctr & MCMASK) == MCMASK:
        hw.cmd_transmit(3, b'\x12')  # LL_PING_REQ
    msg_ctr += 1

    # also test sending LL_CONNECTION_UPDATE_IND
    if msg_ctr == 0x40:
        # WinSize = 0x04
        # WinOffset = 0x0008
        # Interval = 0x0030
        # Latency = 0x0003
        # Timeout = 0x0080
        # Instant = 0x0080
        hw.cmd_transmit(3, b'\x00\x04\x08\x00\x30\x00\x03\x00\x80\x00\x80\x00')
        print("sent change!")
Exemple #7
0
def print_packet(pkt):
    # ignore low RSSI junk at start in RSSI filter mode for top MAC mode
    if _delay_top_mac and pkt.rssi < _rssi_min:
        return

    if pcwriter:
        pcwriter.write_packet(int(pkt.ts_epoch * 1000000), pkt.aa, pkt.chan,
                              pkt.rssi, pkt.body)

    # Further decode and print the packet
    dpkt = DPacketMessage.decode(pkt)
    print(dpkt)

    # React to the packet
    if isinstance(dpkt, _AdvaMessage) or isinstance(
            dpkt, AdvDirectIndMessage) or (isinstance(dpkt, AdvExtIndMessage)
                                           and dpkt.AdvA is not None):
        _dtm(dpkt.AdvA)

    if isinstance(dpkt, ConnectIndMessage):
        # PCAP write is already done here, safe to update cur_aa
        hw.decoder_state.cur_aa = dpkt.aa