Skip to content

Commit 0022dfd

Browse files
hsfz: Fix acknowledgment transfer packet structure. (#4758)
1 parent 6c658dd commit 0022dfd

File tree

2 files changed

+24
-2
lines changed

2 files changed

+24
-2
lines changed

scapy/contrib/automotive/bmw/hsfz.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,15 +59,19 @@ class HSFZ(Packet):
5959
IntField('length', None),
6060
ShortEnumField('control', 1, control_words),
6161
ConditionalField(
62-
XByteField('source', 0), lambda p: p.control == 1),
62+
XByteField('source', 0), lambda p: p._hasaddrs()),
6363
ConditionalField(
64-
XByteField('target', 0), lambda p: p.control == 1),
64+
XByteField('target', 0), lambda p: p._hasaddrs()),
6565
ConditionalField(
6666
StrFixedLenField("identification_string",
6767
None, None, lambda p: p.length),
6868
lambda p: p.control == 0x11)
6969
]
7070

71+
def _hasaddrs(self):
72+
# type: () -> bool
73+
return self.control == 0x01 or self.control == 0x02
74+
7175
def hashret(self):
7276
# type: () -> bytes
7377
hdr_hash = struct.pack("B", self.source ^ self.target)

test/contrib/automotive/bmw/hsfz.uts

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,24 @@ assert pkt.control == 1
7676
assert pkt.securitySeed == b"0" * 0xfff00
7777

7878

79+
= Dissect diagnostic request
80+
81+
pkt = HSFZ(hex_bytes("000000050001f41022f150"))
82+
assert pkt.length == 5
83+
assert pkt.control == 0x01
84+
assert pkt.source == 0xf4
85+
assert pkt.target == 0x10
86+
87+
88+
= Dissect acknowledgment transfer
89+
90+
pkt = HSFZ(hex_bytes("000000050002f41022f150"))
91+
assert pkt.length == 5
92+
assert pkt.control == 0x02
93+
assert pkt.source == 0xf4
94+
assert pkt.target == 0x10
95+
96+
7997
= Dissect identification
8098

8199
pkt = HSFZ(bytes.fromhex("000000320011444941474144523130424d574d4143374346436343463837393343424d5756494e5742413558373333333246483735373334"))

0 commit comments

Comments
 (0)