1616 BitEnumField , BitField , XByteField , FieldListField , \
1717 XShortField , X3BytesField , XIntField , ByteField , \
1818 ShortField , ObservableDict , XShortEnumField , XByteEnumField , StrLenField , \
19- FieldLenField , XStrFixedLenField , XStrLenField , FlagsField , PacketListField
19+ FieldLenField , XStrFixedLenField , XStrLenField
2020from scapy .packet import Packet , bind_layers , NoPayload
2121from scapy .config import conf
2222from scapy .error import log_loading
@@ -491,7 +491,8 @@ class UDS_ATPPR(Packet):
491491
492492 def answers (self , other ):
493493 return isinstance (other , UDS_ATP ) \
494- and other .timingParameterAccessType == self .timingParameterAccessType
494+ and other .timingParameterAccessType == \
495+ self .timingParameterAccessType
495496
496497
497498bind_layers (UDS , UDS_ATPPR , service = 0xC3 )
@@ -955,39 +956,12 @@ class UDS_RDTCI(Packet):
955956 20 : 'reportDTCFaultDetectionCounter' ,
956957 21 : 'reportDTCWithPermanentStatus'
957958 }
958- dtcStatus = {
959- 1 : 'TestFailed' ,
960- 2 : 'TestFailedThisOperationCycle' ,
961- 4 : 'PendingDTC' ,
962- 8 : 'ConfirmedDTC' ,
963- 16 : 'TestNotCompletedSinceLastClear' ,
964- 32 : 'TestFailedSinceLastClear' ,
965- 64 : 'TestNotCompletedThisOperationCycle' ,
966- 128 : 'WarningIndicatorRequested'
967- }
968- dtcStatusMask = {
969- 1 : 'ActiveDTCs' ,
970- 4 : 'PendingDTCs' ,
971- 8 : 'ConfirmedOrStoredDTCs' ,
972- 255 : 'AllRecordDTCs'
973- }
974- dtcSeverityMask = {
975- # 0: 'NoSeverityInformation',
976- 1 : 'NoClassInformation' ,
977- 2 : 'WWH-OBDClassA' ,
978- 4 : 'WWH-OBDClassB1' ,
979- 8 : 'WWH-OBDClassB2' ,
980- 16 : 'WWH-OBDClassC' ,
981- 32 : 'MaintenanceRequired' ,
982- 64 : 'CheckAtNextHalt' ,
983- 128 : 'CheckImmediately'
984- }
985959 name = 'ReadDTCInformation'
986960 fields_desc = [
987961 ByteEnumField ('reportType' , 0 , reportTypes ),
988- ConditionalField (FlagsField ('DTCSeverityMask' , 0 , 8 , dtcSeverityMask ),
962+ ConditionalField (ByteField ('DTCSeverityMask' , 0 ),
989963 lambda pkt : pkt .reportType in [0x07 , 0x08 ]),
990- ConditionalField (FlagsField ('DTCStatusMask' , 0 , 8 , dtcStatusMask ),
964+ ConditionalField (XByteField ('DTCStatusMask' , 0 ),
991965 lambda pkt : pkt .reportType in [
992966 0x01 , 0x02 , 0x07 , 0x08 , 0x0f , 0x11 , 0x12 , 0x13 ]),
993967 ConditionalField (ByteField ('DTCHighByte' , 0 ),
@@ -1009,48 +983,11 @@ class UDS_RDTCI(Packet):
1009983bind_layers (UDS , UDS_RDTCI , service = 0x19 )
1010984
1011985
1012- class DTC (Packet ):
1013- name = 'DTC and status record'
1014- fields_desc = [
1015- BitEnumField ("system" , 0 , 2 , {
1016- 0 : "Powertrain" , 1 : "Chassis" , 2 : "Body" , 3 : "Network" }),
1017- BitEnumField ("type" , 0 , 2 , {
1018- 0 : "Generic" , 1 : "ManufacturerSpecific" , 2 : "Generic" , 3 : "Generic" }),
1019- BitField ("numeric_value_code" , 0 , 12 ),
1020- ByteField ("additional_information_code" , 0 ),
1021- FlagsField ("status" , 0 , 8 , UDS_RDTCI .dtcStatus )
1022- ]
1023-
1024- def extract_padding (self , s ):
1025- return '' , s
1026-
1027-
1028- class DTCExtendedData (Packet ):
1029- name = 'Diagnostic Trouble Code Extended Data'
1030- dataTypes = ObservableDict ()
1031-
1032- fields_desc = [
1033- ByteEnumField ("data_type" , 0 , dataTypes ),
1034- XByteField ("record" , 0 )
1035- ]
1036-
1037- def extract_padding (self , s ):
1038- return '' , s
1039-
1040-
1041- class DTCExtendedDataRecord (Packet ):
1042- fields_desc = [
1043- PacketField ("dtcAndStatus" , None , pkt_cls = DTCAndStatusRecord ),
1044- PacketListField ("extendedData" , None , pkt_cls = DTCExtendedData )
1045- ]
1046-
1047-
1048986class UDS_RDTCIPR (Packet ):
1049987 name = 'ReadDTCInformationPositiveResponse'
1050988 fields_desc = [
1051989 ByteEnumField ('reportType' , 0 , UDS_RDTCI .reportTypes ),
1052- ConditionalField (FlagsField ('DTCStatusAvailabilityMask' , 0 , 8 ,
1053- UDS_RDTCI .dtcStatus ),
990+ ConditionalField (XByteField ('DTCStatusAvailabilityMask' , 0 ),
1054991 lambda pkt : pkt .reportType in [0x01 , 0x07 , 0x11 ,
1055992 0x12 , 0x02 , 0x0A ,
1056993 0x0B , 0x0C , 0x0D ,
@@ -1066,7 +1003,7 @@ class UDS_RDTCIPR(Packet):
10661003 ConditionalField (ShortField ('DTCCount' , 0 ),
10671004 lambda pkt : pkt .reportType in [0x01 , 0x07 ,
10681005 0x11 , 0x12 ]),
1069- ConditionalField (PacketListField ('DTCAndStatusRecord' , None , pkt_cls = DTC ),
1006+ ConditionalField (StrField ('DTCAndStatusRecord' , b"" ),
10701007 lambda pkt : pkt .reportType in [0x02 , 0x0A , 0x0B ,
10711008 0x0C , 0x0D , 0x0E ,
10721009 0x0F , 0x13 , 0x15 ]),
@@ -1324,24 +1261,24 @@ def _contains_data_format_identifier(packet):
13241261 fmt = 'B' ),
13251262 lambda p : p .modeOfOperation != 2 ),
13261263 ConditionalField (StrLenField ('maxNumberOfBlockLength' , b"" ,
1327- length_from = lambda p : p .lengthFormatIdentifier ),
1264+ length_from = lambda p : p .lengthFormatIdentifier ),
13281265 lambda p : p .modeOfOperation != 2 ),
13291266 ConditionalField (BitField ('compressionMethod' , 0 , 4 ),
13301267 lambda p : p .modeOfOperation != 0x02 ),
13311268 ConditionalField (BitField ('encryptingMethod' , 0 , 4 ),
13321269 lambda p : p .modeOfOperation != 0x02 ),
13331270 ConditionalField (FieldLenField ('fileSizeOrDirInfoParameterLength' ,
1334- None ,
1335- length_of = 'fileSizeUncompressedOrDirInfoLength' ),
1271+ None ,
1272+ length_of = 'fileSizeUncompressedOrDirInfoLength' ),
13361273 lambda p : p .modeOfOperation not in [1 , 2 , 3 ]),
13371274 ConditionalField (StrLenField ('fileSizeUncompressedOrDirInfoLength' ,
13381275 b"" ,
13391276 length_from = lambda p :
13401277 p .fileSizeOrDirInfoParameterLength ),
13411278 lambda p : p .modeOfOperation not in [1 , 2 , 3 ]),
13421279 ConditionalField (StrLenField ('fileSizeCompressed' , b"" ,
1343- length_from = lambda p :
1344- p .fileSizeOrDirInfoParameterLength ),
1280+ length_from = lambda p :
1281+ p .fileSizeOrDirInfoParameterLength ),
13451282 lambda p : p .modeOfOperation not in [1 , 2 , 3 , 5 ]),
13461283 ]
13471284
0 commit comments