Skip to content

Commit 29433fc

Browse files
Hsfz: Improve incorrect tester field naming. (#4818)
Based on https://gitlab.com/LarsVoelker/wireshark/-/commit/3c4a5165a69d371d2abae1f271fbd806f9a31819, I improved the naming of the fields for this particular command.
1 parent 449142a commit 29433fc

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

scapy/contrib/automotive/bmw/hsfz.py

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -59,23 +59,31 @@ class HSFZ(Packet):
5959
IntField('length', None),
6060
ShortEnumField('control', 1, control_words),
6161
ConditionalField(
62-
XByteField('source', 0), lambda p: p._hasaddrs()),
62+
XByteField('source', 0), lambda p: p._has_srctgt_addrs()),
6363
ConditionalField(
64-
XByteField('target', 0), lambda p: p._hasaddrs()),
64+
XByteField('target', 0), lambda p: p._has_srctgt_addrs()),
65+
ConditionalField(
66+
XByteField('expected', 0), lambda p: p._has_exprecv_addrs()),
67+
ConditionalField(
68+
XByteField('received', 0), lambda p: p._has_exprecv_addrs()),
6569
ConditionalField(
6670
StrFixedLenField("identification_string",
6771
None, None, lambda p: p.length),
6872
lambda p: p._hasidstring())
6973
]
7074

71-
def _hasaddrs(self):
75+
def _has_srctgt_addrs(self):
7276
# type: () -> bool
7377
# Address present in diagnostic_req_res, acknowledge_transfer,
74-
# two byte length alive_check and incorrect_tester_address frames.
78+
# and two byte length alive_check frames.
7579
return self.control == 0x01 or \
7680
self.control == 0x02 or \
77-
(self.control == 0x12 and self.length == 2) or \
78-
self.control == 0x40
81+
(self.control == 0x12 and self.length == 2)
82+
83+
def _has_exprecv_addrs(self):
84+
# type: () -> bool
85+
# Address present in incorrect_tester_address frames.
86+
return self.control == 0x40
7987

8088
def _hasidstring(self):
8189
# type: () -> bool

test/contrib/automotive/bmw/hsfz.uts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -128,8 +128,8 @@ assert pkt.target == 0xf4
128128
pkt = HSFZ(bytes.fromhex("000000020040fff4"))
129129
assert pkt.length == 2
130130
assert pkt.control == 0x40
131-
assert pkt.source == 0xff
132-
assert pkt.target == 0xf4
131+
assert pkt.expected == 0xff
132+
assert pkt.received == 0xf4
133133

134134

135135
= Test HSFZSocket

0 commit comments

Comments
 (0)