File tree Expand file tree Collapse file tree
scapy/contrib/automotive/bmw
test/contrib/automotive/bmw Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -65,12 +65,23 @@ class HSFZ(Packet):
6565 ConditionalField (
6666 StrFixedLenField ("identification_string" ,
6767 None , None , lambda p : p .length ),
68- lambda p : p .control == 0x11 and p . length != 0 )
68+ lambda p : p ._hasidstring () )
6969 ]
7070
7171 def _hasaddrs (self ):
7272 # type: () -> bool
73- return self .control == 0x01 or self .control == 0x02
73+ # Address present in diagnostic_req_res, acknowledge_transfer and
74+ # two byte length alive_check frames.
75+ return self .control == 0x01 or \
76+ self .control == 0x02 or \
77+ (self .control == 0x12 and self .length == 2 )
78+
79+ def _hasidstring (self ):
80+ # type: () -> bool
81+ # ID string is present in some vehicle_ident_data frames and in
82+ # long alive_check grames.
83+ return (self .control == 0x11 and self .length != 0 ) or \
84+ (self .control == 0x12 and self .length > 2 )
7485
7586 def hashret (self ):
7687 # type: () -> bytes
Original file line number Diff line number Diff line change @@ -111,9 +111,21 @@ assert pkt.length == 0
111111assert pkt.control == 0x11
112112
113113
114- = Test HSFZSocket
114+ = Dissect alive check
115+ pkt = HSFZ(bytes.fromhex("000000200012444941474144523130424d5756494e5858585858585858585858585858585858"))
116+ assert pkt.length == 32
117+ assert pkt.control == 0x12
118+ assert b"BMW" in pkt.identification_string
119+
120+ pkt = HSFZ(bytes.fromhex("00000002001200f4"))
121+ assert pkt.length == 2
122+ assert pkt.control == 0x12
123+ assert pkt.source == 0x00
124+ assert pkt.target == 0xf4
115125
116126
127+ = Test HSFZSocket
128+
117129server_up = threading.Event()
118130def server():
119131 buffer = bytes(HSFZ(control=1, source=0xf4, target=0x10) / Raw(b'\x11\x22\x33' * 1024))
You can’t perform that action at this time.
0 commit comments