diff --git a/scapy/contrib/automotive/bmw/hsfz.py b/scapy/contrib/automotive/bmw/hsfz.py index d3269e39d5f..8eb49f7a1e1 100644 --- a/scapy/contrib/automotive/bmw/hsfz.py +++ b/scapy/contrib/automotive/bmw/hsfz.py @@ -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 diff --git a/test/contrib/automotive/bmw/hsfz.uts b/test/contrib/automotive/bmw/hsfz.uts index 5bd92cabd89..479608babec 100644 --- a/test/contrib/automotive/bmw/hsfz.uts +++ b/test/contrib/automotive/bmw/hsfz.uts @@ -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))