mirror of
https://github.com/google/bumble.git
synced 2026-04-18 00:45:32 +00:00
Formatted with
This commit is contained in:
@@ -116,21 +116,26 @@ class PcapSnooper(Snooper):
|
||||
Snooper that saves or streames HCI packets using the PCAP format.
|
||||
"""
|
||||
|
||||
PCAP_MAGIC = 0xa1b2c3d4
|
||||
PCAP_MAGIC = 0xA1B2C3D4
|
||||
DLT_BLUETOOTH_HCI_H4_WITH_PHDR = 201
|
||||
|
||||
def __init__(self, fifo):
|
||||
self.output = fifo
|
||||
|
||||
# Write the header
|
||||
self.output.write(struct.pack("<IHHIIII",
|
||||
self.PCAP_MAGIC,
|
||||
2, 4, # Major and Minor PCAP Version
|
||||
0, 0, # Reserved 1 and 2
|
||||
65535, # SnapLen
|
||||
# FCS and f are set to 0 implicitly by the next line
|
||||
self.DLT_BLUETOOTH_HCI_H4_WITH_PHDR # The DLT in this PCAP
|
||||
))
|
||||
self.output.write(
|
||||
struct.pack(
|
||||
"<IHHIIII",
|
||||
self.PCAP_MAGIC,
|
||||
2,
|
||||
4, # Major and Minor PCAP Version
|
||||
0,
|
||||
0, # Reserved 1 and 2
|
||||
65535, # SnapLen
|
||||
# FCS and f are set to 0 implicitly by the next line
|
||||
self.DLT_BLUETOOTH_HCI_H4_WITH_PHDR, # The DLT in this PCAP
|
||||
)
|
||||
)
|
||||
|
||||
def snoop(self, hci_packet: bytes, direction: Snooper.Direction):
|
||||
now = datetime.datetime.now(datetime.timezone.utc)
|
||||
@@ -139,16 +144,18 @@ class PcapSnooper(Snooper):
|
||||
|
||||
# Emit the record
|
||||
self.output.write(
|
||||
struct.pack("<IIII",
|
||||
sec, # Timestamp (Seconds)
|
||||
usec, # Timestamp (Microseconds)
|
||||
len(hci_packet)+4,
|
||||
len(hci_packet)+4 # +4 because of the addtional direction info...
|
||||
struct.pack(
|
||||
"<IIII",
|
||||
sec, # Timestamp (Seconds)
|
||||
usec, # Timestamp (Microseconds)
|
||||
len(hci_packet) + 4,
|
||||
len(hci_packet) + 4, # +4 because of the addtional direction info...
|
||||
)
|
||||
+ struct.pack(">I", int(direction)) # ...thats being added here
|
||||
+ struct.pack(">I", int(direction)) # ...thats being added here
|
||||
+ hci_packet
|
||||
)
|
||||
self.output.flush() # flush after every packet for live logging
|
||||
self.output.flush() # flush after every packet for live logging
|
||||
|
||||
|
||||
# -----------------------------------------------------------------------------
|
||||
_SNOOPER_INSTANCE_COUNT = 0
|
||||
|
||||
Reference in New Issue
Block a user