Skip to content

Commit

Permalink
Fix #4547: Change hashret of DoIP (#4586)
Browse files Browse the repository at this point in the history
* Fix #4547: Change hashret of DoIP

* debug

* update timeout
  • Loading branch information
polybassa authored Nov 23, 2024
1 parent 680107d commit 45de3db
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 4 deletions.
5 changes: 1 addition & 4 deletions scapy/contrib/automotive/doip.py
Original file line number Diff line number Diff line change
Expand Up @@ -239,10 +239,7 @@ def answers(self, other):

def hashret(self):
# type: () -> bytes
if self.payload_type in [0x8001, 0x8002, 0x8003]:
return bytes(self)[:2] + struct.pack(
"H", self.target_address ^ self.source_address)
return bytes(self)[:2]
return bytes(self)[:3]

def post_build(self, pkt, pay):
# type: (bytes, bytes) -> bytes
Expand Down
26 changes: 26 additions & 0 deletions test/contrib/automotive/doip.uts
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

= Load Contrib Layer

from test.testsocket import TestSocket, cleanup_testsockets, UnstableSocket

load_contrib("automotive.doip", globals_dict=globals())
load_contrib("automotive.uds", globals_dict=globals())

Expand Down Expand Up @@ -406,6 +408,30 @@ assert pkts[0][DoIP].payload_length == 2
assert pkts[0][DoIP:2].payload_length == 7
assert pkts[1][DoIP].payload_length == 103

= Doip logical addressing

filename = scapy_path("/test/pcaps/doip_functional_request.pcap.gz")
tx_sock = TestSocket(DoIP)
rx_sock = TestSocket(DoIP)
tx_sock.pair(rx_sock)

for pkt in PcapReader(filename):
if pkt.haslayer(DoIP):
tx_sock.send(pkt[DoIP])

ans, unans = rx_sock.sr(DoIP(bytes(DoIP(payload_type=0x8001, source_address=0xe80, target_address=0xe400) / UDS() / UDS_TP())), multi=True, timeout=0.1, verbose=False)

cleanup_testsockets()

ans.summary()
if unans:
unans.summary()

assert len(ans) == 8
ans.summary()
assert len(unans) == 0


+ DoIP Communication tests

= Load libraries
Expand Down
Binary file added test/pcaps/doip_functional_request.pcap.gz
Binary file not shown.

0 comments on commit 45de3db

Please sign in to comment.