コード例 #1
0
    def from_connection_buffer(connection):

        # Possible TODO: Convert this to a Katai Struct parser with a proper .ksy grammar.
        return ConnectionInformation(
            u32(connection[:4]),
            connection[0x28:0x2E][::-1],
            u32(connection[0x4C:0x50]),
            u32(connection[0x1C:0x20]) & 1 << 15 == 0,
            u16(connection[0x64:0x66]),
            connection[0x78:0x88],
            u8(connection[0xA7:0xA8]),
            connection[0x68:0x68 + u8(connection[0xA7:0xA8])],
            u8(connection[0x9C:0x9D]) - 127,
            connection[0x30:0x38],
            connection[0x38:0x40],
            connection[0x0C:0x0D],
        )
コード例 #2
0
ファイル: hci.py プロジェクト: seemoo-lab/internalblue
 def from_data(data):
     return HCI_Diag(u8(data[0:1]), data[1:])
コード例 #3
0
ファイル: hci.py プロジェクト: seemoo-lab/internalblue
 def from_data(data):
     data = bytes(data)  # bytearray to bytes
     handle = u16(unbits(bits_str(data[0:2])[0:12].rjust(16, "0")))
     bp = u8(unbits(bits_str(data[1:2])[4:6].rjust(8, "0")))
     bc = u8(unbits(bits_str(data[1:2])[6:8].rjust(8, "0")))
     return HCI_Acl(handle, bp, bc, u16(data[2:4]), data[4:])
コード例 #4
0
ファイル: hci.py プロジェクト: seemoo-lab/internalblue
 def from_data(data):
     data = bytes(data)  # bytearray to bytes
     handle = u16(unbits(bits_str(data[0:2])[0:12].rjust(16, "0")))
     ps = u8(unbits(bits_str(data[1:2])[4:6].rjust(8, "0")))
     return HCI_Sco(handle, ps, u8(data[2]), data[3:])
コード例 #5
0
def lereceiveStatusCallback(record):
    """
    RXDN Callback Function

    Depends on the raspi3_rxdn.py or eval_rxdn.py script,
    which patches the _connTaskRxDone() function and copies
    info from the LE connection struct to HCI.
    """

    hcipkt = record[0]  # get HCI Event packet

    if not issubclass(hcipkt.__class__, hci.HCI_Event):
        return

    if hcipkt.data[0:4] == "RXDN":
        data = hcipkt.data[4:]

        # Raspi 3 gets errors
        if len(data) < 239:
            return

        # if raspi or s8:
        packet_curr_nesn_sn = u8(data[0xa0])

        # elif eval:
        #    packet_curr_nesn_sn = u8(data[0xa4])

        packet_channel_map = data[0x54:0x7b]
        packet_channel = data[0x83]
        packet_event_ctr = u16(data[0x8e:0x90])
        packet_rssi = data[0]

        if internalblue.last_nesn_sn and (
            (internalblue.last_nesn_sn ^ packet_curr_nesn_sn)
                & 0b1100) != 0b1100:
            internalblue.logger.info(
                "             ^----------------------------- ERROR --------------------------------"
            )

        # currently only supported by eval board: check if we also went into the process payload routine,
        # which probably corresponds to a correct CRC
        # if self.last_success_event and (self.last_success_event + 1) != packet_event_ctr:
        #    internalblue.logger.debug("             ^----------------------------- MISSED -------------------------------")

        # TODO example for setting the channel map
        # timeout needs to be zero, because we are already in an event reception routine!
        # self.sendHciCommand(0x2014, '\x00\x00\xff\x00\x00', timeout=0)

        internalblue.last_nesn_sn = packet_curr_nesn_sn

        # draw channel with rssi color
        color = '\033[92m'  # green
        if 0xc8 > packet_rssi >= 0xc0:
            color = '\033[93m'  # yellow
        elif packet_rssi < 0xc0:
            color = '\033[91m'  # red

        channels_total = packet_channel_map[37]
        channel_map = 0x0000000000
        if channels_total <= 37:  # raspi 3 messes up with this during blacklisting
            for channel in range(0, channels_total):
                channel_map |= (0b1 << 39) >> packet_channel_map[channel]

        internalblue.logger.info(
            "LE event %5d, map %10x, RSSI %d: %s%s*\033[0m " %
            (packet_event_ctr, channel_map, (packet_rssi & 0x7f) -
             (128 * (packet_rssi >> 7)), color, ' ' * packet_channel))