Skip to content
Merged
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
15 changes: 13 additions & 2 deletions scapy/contrib/automotive/bmw/hsfz.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,23 @@ class HSFZ(Packet):
ConditionalField(
StrFixedLenField("identification_string",
None, None, lambda p: p.length),
lambda p: p.control == 0x11 and p.length != 0)
lambda p: p._hasidstring())
]

def _hasaddrs(self):
# type: () -> bool
return self.control == 0x01 or self.control == 0x02
# Address present in diagnostic_req_res, acknowledge_transfer and
# two byte length alive_check frames.
return self.control == 0x01 or \
self.control == 0x02 or \
(self.control == 0x12 and self.length == 2)

def _hasidstring(self):
# type: () -> bool
# ID string is present in some vehicle_ident_data frames and in
# long alive_check grames.
return (self.control == 0x11 and self.length != 0) or \
(self.control == 0x12 and self.length > 2)

def hashret(self):
# type: () -> bytes
Expand Down
14 changes: 13 additions & 1 deletion test/contrib/automotive/bmw/hsfz.uts
Original file line number Diff line number Diff line change
Expand Up @@ -111,9 +111,21 @@ assert pkt.length == 0
assert pkt.control == 0x11


= Test HSFZSocket
= Dissect alive check
pkt = HSFZ(bytes.fromhex("000000200012444941474144523130424d5756494e5858585858585858585858585858585858"))
assert pkt.length == 32
assert pkt.control == 0x12
assert b"BMW" in pkt.identification_string

pkt = HSFZ(bytes.fromhex("00000002001200f4"))
assert pkt.length == 2
assert pkt.control == 0x12
assert pkt.source == 0x00
assert pkt.target == 0xf4


= Test HSFZSocket

server_up = threading.Event()
def server():
buffer = bytes(HSFZ(control=1, source=0xf4, target=0x10) / Raw(b'\x11\x22\x33' * 1024))
Expand Down