diff --git a/scapy/contrib/automotive/uds.py b/scapy/contrib/automotive/uds.py index 8b0dcf6f18f..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", @@ -1032,7 +1034,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 +1045,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 +1085,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):