Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #4547: Change hashret of DoIP #4586

Merged
merged 3 commits into from
Nov 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
Loading