Skip to content

Commit 2a4c4ae

Browse files
authored
Add parsing of ExtendedDataRecord to UDS_DTCs (#4117)
* Add UDS_DTC parsing for ExtendedDataRecords * add dict for DTC descriptions
1 parent e307445 commit 2a4c4ae

File tree

1 file changed

+29
-5
lines changed
  • scapy/contrib/automotive

1 file changed

+29
-5
lines changed

scapy/contrib/automotive/uds.py

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1013,6 +1013,8 @@ class UDS_RDTCI(Packet):
10131013

10141014
class DTC(Packet):
10151015
name = 'Diagnostic Trouble Code'
1016+
dtc_descriptions = {} # Customize this dictionary for each individual ECU / OEM
1017+
10161018
fields_desc = [
10171019
BitEnumField("system", 0, 2, {
10181020
0: "Powertrain",
@@ -1032,7 +1034,7 @@ def extract_padding(self, s):
10321034
return '', s
10331035

10341036

1035-
class DTC_Status(Packet):
1037+
class DTCAndStatusRecord(Packet):
10361038
name = 'DTC and status record'
10371039
fields_desc = [
10381040
PacketField("dtc", None, pkt_cls=DTC),
@@ -1043,6 +1045,26 @@ def extract_padding(self, s):
10431045
return '', s
10441046

10451047

1048+
class DTCExtendedData(Packet):
1049+
name = 'Diagnostic Trouble Code Extended Data'
1050+
dataTypes = ObservableDict()
1051+
1052+
fields_desc = [
1053+
ByteEnumField("data_type", 0, dataTypes),
1054+
XByteField("record", 0)
1055+
]
1056+
1057+
def extract_padding(self, s):
1058+
return '', s
1059+
1060+
1061+
class DTCExtendedDataRecord(Packet):
1062+
fields_desc = [
1063+
PacketField("dtcAndStatus", None, pkt_cls=DTCAndStatusRecord),
1064+
PacketListField("extendedData", None, pkt_cls=DTCExtendedData)
1065+
]
1066+
1067+
10461068
class UDS_RDTCIPR(Packet):
10471069
name = 'ReadDTCInformationPositiveResponse'
10481070
fields_desc = [
@@ -1063,14 +1085,16 @@ class UDS_RDTCIPR(Packet):
10631085
lambda pkt: pkt.reportType in [0x01, 0x07,
10641086
0x11, 0x12]),
10651087
ConditionalField(PacketListField('DTCAndStatusRecord', None,
1066-
pkt_cls=DTC_Status),
1088+
pkt_cls=DTCAndStatusRecord),
10671089
lambda pkt: pkt.reportType in [0x02, 0x0A, 0x0B,
10681090
0x0C, 0x0D, 0x0E,
10691091
0x0F, 0x13, 0x15]),
10701092
ConditionalField(StrField('dataRecord', b""),
1071-
lambda pkt: pkt.reportType in [0x03, 0x04, 0x05,
1072-
0x06, 0x08, 0x09,
1073-
0x10, 0x14])
1093+
lambda pkt: pkt.reportType in [0x03, 0x08, 0x09,
1094+
0x10, 0x14]),
1095+
ConditionalField(PacketField('extendedDataRecord', None,
1096+
pkt_cls=DTCExtendedDataRecord),
1097+
lambda pkt: pkt.reportType in [0x06])
10741098
]
10751099

10761100
def answers(self, other):

0 commit comments

Comments
 (0)