From f9a7bbe8404545e8046c39d2bf3d64d1f7746357 Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Tue, 12 Sep 2023 14:24:38 +0200 Subject: [PATCH 1/2] Add UDS_DTC parsing for ExtendedDataRecords --- scapy/contrib/automotive/uds.py | 32 +++++++++++++++++++++++++++----- 1 file changed, 27 insertions(+), 5 deletions(-) diff --git a/scapy/contrib/automotive/uds.py b/scapy/contrib/automotive/uds.py index 8b0dcf6f18f..e806f165289 100644 --- a/scapy/contrib/automotive/uds.py +++ b/scapy/contrib/automotive/uds.py @@ -1032,7 +1032,7 @@ def extract_padding(self, s): return '', s -class DTC_Status(Packet): +class DTCAndStatusRecord(Packet): name = 'DTC and status record' fields_desc = [ PacketField("dtc", None, pkt_cls=DTC), @@ -1043,6 +1043,26 @@ def extract_padding(self, s): return '', s +class DTCExtendedData(Packet): + name = 'Diagnostic Trouble Code Extended Data' + dataTypes = ObservableDict() + + fields_desc = [ + ByteEnumField("data_type", 0, dataTypes), + XByteField("record", 0) + ] + + def extract_padding(self, s): + return '', s + + +class DTCExtendedDataRecord(Packet): + fields_desc = [ + PacketField("dtcAndStatus", None, pkt_cls=DTCAndStatusRecord), + PacketListField("extendedData", None, pkt_cls=DTCExtendedData) + ] + + class UDS_RDTCIPR(Packet): name = 'ReadDTCInformationPositiveResponse' fields_desc = [ @@ -1063,14 +1083,16 @@ class UDS_RDTCIPR(Packet): lambda pkt: pkt.reportType in [0x01, 0x07, 0x11, 0x12]), ConditionalField(PacketListField('DTCAndStatusRecord', None, - pkt_cls=DTC_Status), + pkt_cls=DTCAndStatusRecord), lambda pkt: pkt.reportType in [0x02, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x13, 0x15]), ConditionalField(StrField('dataRecord', b""), - lambda pkt: pkt.reportType in [0x03, 0x04, 0x05, - 0x06, 0x08, 0x09, - 0x10, 0x14]) + lambda pkt: pkt.reportType in [0x03, 0x08, 0x09, + 0x10, 0x14]), + ConditionalField(PacketField('extendedDataRecord', None, + pkt_cls=DTCExtendedDataRecord), + lambda pkt: pkt.reportType in [0x06]) ] def answers(self, other): From e76abe4ea35b1721e7435b8e186228d7e3349e0f Mon Sep 17 00:00:00 2001 From: Nils Weiss Date: Tue, 12 Sep 2023 14:27:42 +0200 Subject: [PATCH 2/2] add dict for DTC descriptions --- scapy/contrib/automotive/uds.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/scapy/contrib/automotive/uds.py b/scapy/contrib/automotive/uds.py index e806f165289..bbe0316144c 100644 --- a/scapy/contrib/automotive/uds.py +++ b/scapy/contrib/automotive/uds.py @@ -1013,6 +1013,8 @@ class UDS_RDTCI(Packet): class DTC(Packet): name = 'Diagnostic Trouble Code' + dtc_descriptions = {} # Customize this dictionary for each individual ECU / OEM + fields_desc = [ BitEnumField("system", 0, 2, { 0: "Powertrain",