Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion btsnoop/bt/hci_acl.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""
Parse HCI ACL packets
"""
import dataclasses
import struct
import ctypes
from ctypes import c_uint
Expand Down Expand Up @@ -52,6 +53,18 @@ class ACL_HEADER( ctypes.Union ):
PB_COMPLETE_L2CAP_PDU : "ACL_PB COMPLETE_L2CAP_PDU"
}


@dataclasses.dataclass
class HciPacketACL:
handle: int
pb: int
bc: int
length: int
data: bytearray

def __repr__(self):
return f"HciPacketACL(handle={self.handle}, pb={self.pb} ({pb_to_str(self.pb)}, bc={self.bc}, length={self.length}, data={self.data})"

def pb_to_str(pb):
"""
Return a string representing the packet boundary flag
Expand All @@ -60,6 +73,7 @@ def pb_to_str(pb):
return PB_FLAGS[pb]



def parse(data):
"""
Parse HCI ACL data
Expand All @@ -77,4 +91,4 @@ def parse(data):
bc = int(hdr.b.bc)
length = int(hdr.b.length)
# print(f'ACL::{struct.unpack("<BB", data[:2])}', handle, pb, bc, length)
return (handle, pb, bc, length, data[4:])
return HciPacketACL(handle, pb, bc, length, data[4:])
2 changes: 1 addition & 1 deletion btsnoop/bt/hci_cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -504,4 +504,4 @@ def parse(data):
Returns a tuple of (opcode, length, data)
"""
opcode, length = struct.unpack("<HB", data[:3])
return opcode, length, data[3:]
return parse_cmd_data(opcode, data[3:])
4 changes: 2 additions & 2 deletions btsnoop/bt/hci_evt.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,8 +385,8 @@ def parse(data):
# print(f'EVT::{struct.unpack("<H", data[:2])}', evtcode, length)

if evtcode != HCI_LE_META_EVENT: ## Non-LE
return (evtcode, length, None, data[2:])
return parse_evt_data(evtcode, None, data[2:])
else: ## LE
subevtcode = struct.unpack("<B", data[2:3])[0]
# length -= 1 # Subtract length of SubEvent code # TODO: while this makes sense, does the protocol do it like this? or is the length inclusive of everything (even the subevt code?)
return (evtcode, length, subevtcode, data[3:])
return parse_evt_data(evtcode, subevtcode, data[3:])