Exemplo n.º 1
0
 def extract_hci_event_with_code(packet_bytes, event_code=None):
     hci_event = hci_packets.EventPacketView(bt_packets.PacketViewLittleEndian(list(packet_bytes)))
     if hci_event is None:
         return None
     if event_code is not None and hci_event.GetEventCode() != event_code:
         return None
     return hci_event
Exemplo n.º 2
0
 def ReadBdAddrCompleteCapture():
     return Capture(lambda packet: b'\x0e\x0a\x01\x09\x10' in packet.event,
       lambda packet: hci_packets.ReadBdAddrCompleteView(
                   hci_packets.CommandCompleteView(
                             hci_packets.EventPacketView(
                                 bt_packets.PacketViewLittleEndian(
                                     list(packet.event))))))
Exemplo n.º 3
0
 def LeConnectionCompleteCapture():
     return Capture(lambda packet: packet.event[0] == 0x3e
                    and (packet.event[2] == 0x01 or packet.event[2] == 0x0a),
         lambda packet: hci_packets.LeConnectionCompleteView(
             hci_packets.LeMetaEventView(
                             hci_packets.EventPacketView(
                                 bt_packets.PacketViewLittleEndian(
                                     list(packet.event))))))
Exemplo n.º 4
0
 def ReadBdAddrCompleteCapture():
     return Capture(
         lambda packet: packet.payload[0:5] == b'\x0e\x0a\x01\x09\x10',
         lambda packet: hci_packets.ReadBdAddrCompleteView(
             hci_packets.CommandCompleteView(
                 hci_packets.EventPacketView(
                     bt_packets.PacketViewLittleEndian(list(packet.payload))
                 ))))
Exemplo n.º 5
0
 def _extract_matching_event(packet_bytes, event_code):
     event = hci_packets.EventPacketView(
         bt_packets.PacketViewLittleEndian(list(packet_bytes)))
     if event is None:
         return None
     if event_code is not None and event.GetEventCode() != event_code:
         return None
     return event
Exemplo n.º 6
0
 def get_connect_request(packet):
     if b'\x04\x0a' in packet.event:
         nonlocal connection_request
         connection_request = hci_packets.ConnectionRequestView(
             hci_packets.EventPacketView(
                 bt_packets.PacketViewLittleEndian(
                     list(packet.event))))
         return True
     return False
Exemplo n.º 7
0
 def get_handle(packet_bytes):
     if b'\x03\x0b\x00' in packet_bytes:
         nonlocal conn_handle
         cc_view = hci_packets.ConnectionCompleteView(
             hci_packets.EventPacketView(
                 bt_packets.PacketViewLittleEndian(
                     list(packet_bytes))))
         conn_handle = cc_view.GetConnectionHandle()
         return True
     return False
Exemplo n.º 8
0
 def _handle_control_packet(self, l2cap_packet):
     packet_bytes = l2cap_packet.payload
     l2cap_view = l2cap_packets.BasicFrameView(
         bt_packets.PacketViewLittleEndian(list(packet_bytes)))
     if l2cap_view.GetChannelId() != 1:
         return
     l2cap_control_view = l2cap_packets.ControlView(l2cap_view.GetPayload())
     fn = self.control_table.get(l2cap_control_view.GetCode())
     if fn is not None:
         fn(l2cap_control_view)
Exemplo n.º 9
0
 def get_handle(packet):
     packet_bytes = packet.payload
     nonlocal handle
     if b'\x3e\x13\x01\x00' in packet_bytes:
         cc_view = hci_packets.LeConnectionCompleteView(
             hci_packets.LeMetaEventView(
                 hci_packets.EventView(
                     bt_packets.PacketViewLittleEndian(
                         list(packet_bytes)))))
         handle = cc_view.GetConnectionHandle()
         return True
     if b'\x3e\x13\x0A\x00' in packet_bytes:
         cc_view = hci_packets.LeEnhancedConnectionCompleteView(
             hci_packets.LeMetaEventView(
                 hci_packets.EventView(
                     bt_packets.PacketViewLittleEndian(
                         list(packet_bytes)))))
         handle = cc_view.GetConnectionHandle()
         return True
     return False
Exemplo n.º 10
0
 def payload_handle(packet):
     packet_bytes = packet.payload
     if b'\x3e\x13\x01\x00' in packet_bytes:
         nonlocal conn_handle
         cc_view = hci_packets.LeConnectionCompleteView(
             hci_packets.LeMetaEventView(
                 hci_packets.EventPacketView(
                     bt_packets.PacketViewLittleEndian(
                         list(packet_bytes)))))
         conn_handle = cc_view.GetConnectionHandle()
         return True
     return False
Exemplo n.º 11
0
 def get_address_from_complete(packet):
     packet_bytes = packet.event
     if b'\x0e\x0a\x01\x09\x10' in packet_bytes:
         nonlocal address
         addr_view = hci_packets.ReadBdAddrCompleteView(
             hci_packets.CommandCompleteView(
                 hci_packets.EventPacketView(
                     bt_packets.PacketViewLittleEndian(
                         list(packet_bytes)))))
         address = addr_view.GetBdAddr()
         return True
     return False
Exemplo n.º 12
0
 def get_handle(packet):
     packet_bytes = packet.event
     nonlocal handle
     nonlocal address
     if b'\x3e\x13\x01\x00' in packet_bytes:
         cc_view = hci_packets.LeConnectionCompleteView(
             hci_packets.LeMetaEventView(
                 hci_packets.EventPacketView(
                     bt_packets.PacketViewLittleEndian(
                         list(packet_bytes)))))
         handle = cc_view.GetConnectionHandle()
         address = cc_view.GetPeerAddress()
         return True
     if b'\x3e\x13\x0A\x00' in packet_bytes:
         cc_view = hci_packets.LeEnhancedConnectionCompleteView(
             hci_packets.LeMetaEventView(
                 hci_packets.EventPacketView(
                     bt_packets.PacketViewLittleEndian(
                         list(packet_bytes)))))
         handle = cc_view.GetConnectionHandle()
         address = cc_view.GetPeerResolvablePrivateAddress()
         return True
     return False
Exemplo n.º 13
0
 def ConnectionCompleteCapture():
     return Capture(
         lambda packet: packet.payload[0:3] == b'\x03\x0b\x00',
         lambda packet: hci_packets.ConnectionCompleteView(
             hci_packets.EventPacketView(
                 bt_packets.PacketViewLittleEndian(list(packet.payload)))))
Exemplo n.º 14
0
 def ConnectionCompleteCapture():
     return Capture(lambda packet: b'\x03\x0b\x00' in packet.event,
       lambda packet: hci_packets.ConnectionCompleteView(
                             hci_packets.EventPacketView(
                                 bt_packets.PacketViewLittleEndian(
                                     list(packet.event)))))
Exemplo n.º 15
0
 def ConnectionRequestCapture():
     return Capture(lambda packet: b'\x04\x0a' in packet.event,
       lambda packet: hci_packets.ConnectionRequestView(
                             hci_packets.EventPacketView(
                                 bt_packets.PacketViewLittleEndian(
                                     list(packet.event)))))
Exemplo n.º 16
0
 def ConnectionRequestCapture():
     return Capture(
         lambda packet: packet.payload[0:2] == b'\x04\x0a',
         lambda packet: hci_packets.ConnectionRequestView(
             hci_packets.EventPacketView(
                 bt_packets.PacketViewLittleEndian(list(packet.payload)))))
Exemplo n.º 17
0
 def _basic_frame_with_fcs(packet):
     if packet is None:
         return None
     return l2cap_packets.BasicFrameWithFcsView(
         bt_packets.PacketViewLittleEndian(list(packet.payload)))
Exemplo n.º 18
0
 def DisconnectionCompleteCapture():
     return Capture(
         lambda packet: packet.payload[0:2] == b'\x05\x04',
         lambda packet: hci_packets.DisconnectionCompleteView(
             hci_packets.EventPacketView(
                 bt_packets.PacketViewLittleEndian(list(packet.payload)))))
Exemplo n.º 19
0
 def LogEventCode():
     return lambda event: logging.info(
         "Received event: %x" % hci_packets.EventView(
             bt_packets.PacketViewLittleEndian(list(event.payload))
         ).GetEventCode())