diff --git a/scapy/contrib/automotive/doip.py b/scapy/contrib/automotive/doip.py index b9d279bcf6b..3fcbdc5dad4 100644 --- a/scapy/contrib/automotive/doip.py +++ b/scapy/contrib/automotive/doip.py @@ -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 diff --git a/test/contrib/automotive/doip.uts b/test/contrib/automotive/doip.uts index 9a7d61e3b7d..b5963a0d817 100644 --- a/test/contrib/automotive/doip.uts +++ b/test/contrib/automotive/doip.uts @@ -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()) @@ -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 diff --git a/test/pcaps/doip_functional_request.pcap.gz b/test/pcaps/doip_functional_request.pcap.gz new file mode 100644 index 00000000000..c2b9e9cf35f Binary files /dev/null and b/test/pcaps/doip_functional_request.pcap.gz differ