forked from auracaster/bumble_mirror
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.
|
Snooper that saves or streames HCI packets using the PCAP format.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
PCAP_MAGIC = 0xa1b2c3d4
|
PCAP_MAGIC = 0xA1B2C3D4
|
||||||
DLT_BLUETOOTH_HCI_H4_WITH_PHDR = 201
|
DLT_BLUETOOTH_HCI_H4_WITH_PHDR = 201
|
||||||
|
|
||||||
def __init__(self, fifo):
|
def __init__(self, fifo):
|
||||||
self.output = fifo
|
self.output = fifo
|
||||||
|
|
||||||
# Write the header
|
# Write the header
|
||||||
self.output.write(struct.pack("<IHHIIII",
|
self.output.write(
|
||||||
self.PCAP_MAGIC,
|
struct.pack(
|
||||||
2, 4, # Major and Minor PCAP Version
|
"<IHHIIII",
|
||||||
0, 0, # Reserved 1 and 2
|
self.PCAP_MAGIC,
|
||||||
65535, # SnapLen
|
2,
|
||||||
# FCS and f are set to 0 implicitly by the next line
|
4, # Major and Minor PCAP Version
|
||||||
self.DLT_BLUETOOTH_HCI_H4_WITH_PHDR # The DLT in this PCAP
|
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):
|
def snoop(self, hci_packet: bytes, direction: Snooper.Direction):
|
||||||
now = datetime.datetime.now(datetime.timezone.utc)
|
now = datetime.datetime.now(datetime.timezone.utc)
|
||||||
@@ -139,16 +144,18 @@ class PcapSnooper(Snooper):
|
|||||||
|
|
||||||
# Emit the record
|
# Emit the record
|
||||||
self.output.write(
|
self.output.write(
|
||||||
struct.pack("<IIII",
|
struct.pack(
|
||||||
sec, # Timestamp (Seconds)
|
"<IIII",
|
||||||
usec, # Timestamp (Microseconds)
|
sec, # Timestamp (Seconds)
|
||||||
len(hci_packet)+4,
|
usec, # Timestamp (Microseconds)
|
||||||
len(hci_packet)+4 # +4 because of the addtional direction info...
|
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
|
+ 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
|
_SNOOPER_INSTANCE_COUNT = 0
|
||||||
@@ -179,7 +186,7 @@ def create_snooper(spec: str) -> Generator[Snooper, None, None]:
|
|||||||
utcnow: the value of `datetime.now(tz=datetime.timezone.utc)`
|
utcnow: the value of `datetime.now(tz=datetime.timezone.utc)`
|
||||||
pid: the current process ID.
|
pid: the current process ID.
|
||||||
instance: the instance ID in the current process.
|
instance: the instance ID in the current process.
|
||||||
|
|
||||||
pcapsnoop
|
pcapsnoop
|
||||||
The syntax for the type-specific arguments for this type is:
|
The syntax for the type-specific arguments for this type is:
|
||||||
<io-type>:<io-type-specific-arguments>
|
<io-type>:<io-type-specific-arguments>
|
||||||
@@ -195,11 +202,11 @@ def create_snooper(spec: str) -> Generator[Snooper, None, None]:
|
|||||||
utcnow: the value of `datetime.now(tz=datetime.timezone.utc)`
|
utcnow: the value of `datetime.now(tz=datetime.timezone.utc)`
|
||||||
pid: the current process ID.
|
pid: the current process ID.
|
||||||
instance: the instance ID in the current process.
|
instance: the instance ID in the current process.
|
||||||
|
|
||||||
pipe
|
pipe
|
||||||
The type-specific arguments for this I/O type is a string that is converted
|
The type-specific arguments for this I/O type is a string that is converted
|
||||||
to a path using the python `str.format()` string formatting. The log
|
to a path using the python `str.format()` string formatting. The log
|
||||||
records will be written to the named pipe referenced by this path
|
records will be written to the named pipe referenced by this path
|
||||||
if it can be opened. The keyword args that may be referenced by the
|
if it can be opened. The keyword args that may be referenced by the
|
||||||
string pattern are:
|
string pattern are:
|
||||||
now: the value of `datetime.now()`
|
now: the value of `datetime.now()`
|
||||||
|
|||||||
Reference in New Issue
Block a user