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
@@ -152,7 +152,7 @@ class UDS_DSCPR(Packet):
152152
153153 def answers (self , other ):
154154 return isinstance (other , UDS_DSC ) and \
155- other .diagnosticSessionType == self .diagnosticSessionType
155+ other .diagnosticSessionType == self .diagnosticSessionType
156156
157157
158158bind_layers (UDS , UDS_DSCPR , service = 0x50 )
@@ -218,7 +218,7 @@ class UDS_SAPR(Packet):
218218
219219 def answers (self , other ):
220220 return isinstance (other , UDS_SA ) \
221- and other .securityAccessType == self .securityAccessType
221+ and other .securityAccessType == self .securityAccessType
222222
223223
224224bind_layers (UDS , UDS_SAPR , service = 0x67 )
@@ -273,7 +273,7 @@ class UDS_CCPR(Packet):
273273
274274 def answers (self , other ):
275275 return isinstance (other , UDS_CC ) \
276- and other .controlType == self .controlType
276+ and other .controlType == self .controlType
277277
278278
279279bind_layers (UDS , UDS_CCPR , service = 0x68 )
@@ -429,7 +429,7 @@ class UDS_AUTHPR(Packet):
429429
430430 def answers (self , other ):
431431 return isinstance (other , UDS_AUTH ) \
432- and other .subFunction == self .subFunction
432+ and other .subFunction == self .subFunction
433433
434434
435435bind_layers (UDS , UDS_AUTHPR , service = 0x69 )
@@ -491,8 +491,8 @@ class UDS_ATPPR(Packet):
491491
492492 def answers (self , other ):
493493 return isinstance (other , UDS_ATP ) \
494- and other .timingParameterAccessType == \
495- self .timingParameterAccessType
494+ and other .timingParameterAccessType == \
495+ self .timingParameterAccessType
496496
497497
498498bind_layers (UDS , UDS_ATPPR , service = 0xC3 )
@@ -605,7 +605,7 @@ class UDS_ROEPR(Packet):
605605
606606 def answers (self , other ):
607607 return isinstance (other , UDS_ROE ) \
608- and other .eventType == self .eventType
608+ and other .eventType == self .eventType
609609
610610
611611bind_layers (UDS , UDS_ROEPR , service = 0xC6 )
@@ -644,7 +644,7 @@ class UDS_LCPR(Packet):
644644
645645 def answers (self , other ):
646646 return isinstance (other , UDS_LC ) \
647- and other .linkControlType == self .linkControlType
647+ and other .linkControlType == self .linkControlType
648648
649649
650650bind_layers (UDS , UDS_LCPR , service = 0xC7 )
@@ -673,7 +673,7 @@ class UDS_RDBIPR(Packet):
673673
674674 def answers (self , other ):
675675 return isinstance (other , UDS_RDBI ) \
676- and self .dataIdentifier in other .identifiers
676+ and self .dataIdentifier in other .identifiers
677677
678678
679679bind_layers (UDS , UDS_RDBIPR , service = 0x62 )
@@ -743,7 +743,7 @@ class UDS_RSDBIPR(Packet):
743743
744744 def answers (self , other ):
745745 return isinstance (other , UDS_RSDBI ) \
746- and other .dataIdentifier == self .dataIdentifier
746+ and other .dataIdentifier == self .dataIdentifier
747747
748748
749749bind_layers (UDS , UDS_RSDBIPR , service = 0x64 )
@@ -780,7 +780,7 @@ class UDS_RDBPIPR(Packet):
780780
781781 def answers (self , other ):
782782 return isinstance (other , UDS_RDBPI ) \
783- and other .periodicDataIdentifier == self .periodicDataIdentifier
783+ and other .periodicDataIdentifier == self .periodicDataIdentifier
784784
785785
786786bind_layers (UDS , UDS_RDBPIPR , service = 0x6A )
@@ -812,7 +812,7 @@ class UDS_DDDIPR(Packet):
812812
813813 def answers (self , other ):
814814 return isinstance (other , UDS_DDDI ) \
815- and other .subFunction == self .subFunction
815+ and other .subFunction == self .subFunction
816816
817817
818818bind_layers (UDS , UDS_DDDIPR , service = 0x6C )
@@ -839,7 +839,7 @@ class UDS_WDBIPR(Packet):
839839
840840 def answers (self , other ):
841841 return isinstance (other , UDS_WDBI ) \
842- and other .dataIdentifier == self .dataIdentifier
842+ and other .dataIdentifier == self .dataIdentifier
843843
844844
845845bind_layers (UDS , UDS_WDBIPR , service = 0x6E )
@@ -900,8 +900,8 @@ class UDS_WMBAPR(Packet):
900900
901901 def answers (self , other ):
902902 return isinstance (other , UDS_WMBA ) \
903- and other .memorySizeLen == self .memorySizeLen \
904- and other .memoryAddressLen == self .memoryAddressLen
903+ and other .memorySizeLen == self .memorySizeLen \
904+ and other .memoryAddressLen == self .memoryAddressLen
905905
906906
907907bind_layers (UDS , UDS_WMBAPR , service = 0x7D )
@@ -956,39 +956,12 @@ class UDS_RDTCI(Packet):
956956 20 : 'reportDTCFaultDetectionCounter' ,
957957 21 : 'reportDTCWithPermanentStatus'
958958 }
959- dtcStatus = {
960- 1 : 'TestFailed' ,
961- 2 : 'TestFailedThisOperationCycle' ,
962- 4 : 'PendingDTC' ,
963- 8 : 'ConfirmedDTC' ,
964- 16 : 'TestNotCompletedSinceLastClear' ,
965- 32 : 'TestFailedSinceLastClear' ,
966- 64 : 'TestNotCompletedThisOperationCycle' ,
967- 128 : 'WarningIndicatorRequested'
968- }
969- dtcStatusMask = {
970- 1 : 'ActiveDTCs' ,
971- 4 : 'PendingDTCs' ,
972- 8 : 'ConfirmedOrStoredDTCs' ,
973- 255 : 'AllRecordDTCs'
974- }
975- dtcSeverityMask = {
976- # 0: 'NoSeverityInformation',
977- 1 : 'NoClassInformation' ,
978- 2 : 'WWH-OBDClassA' ,
979- 4 : 'WWH-OBDClassB1' ,
980- 8 : 'WWH-OBDClassB2' ,
981- 16 : 'WWH-OBDClassC' ,
982- 32 : 'MaintenanceRequired' ,
983- 64 : 'CheckAtNextHalt' ,
984- 128 : 'CheckImmediately'
985- }
986959 name = 'ReadDTCInformation'
987960 fields_desc = [
988961 ByteEnumField ('reportType' , 0 , reportTypes ),
989- ConditionalField (FlagsField ('DTCSeverityMask' , 0 , 8 , dtcSeverityMask ),
962+ ConditionalField (ByteField ('DTCSeverityMask' , 0 ),
990963 lambda pkt : pkt .reportType in [0x07 , 0x08 ]),
991- ConditionalField (FlagsField ('DTCStatusMask' , 0 , 8 , dtcStatusMask ),
964+ ConditionalField (XByteField ('DTCStatusMask' , 0 ),
992965 lambda pkt : pkt .reportType in [
993966 0x01 , 0x02 , 0x07 , 0x08 , 0x0f , 0x11 , 0x12 , 0x13 ]),
994967 ConditionalField (ByteField ('DTCHighByte' , 0 ),
@@ -1010,25 +983,11 @@ class UDS_RDTCI(Packet):
1010983bind_layers (UDS , UDS_RDTCI , service = 0x19 )
1011984
1012985
1013- class DTC (Packet ):
1014- name = 'DTC and status record'
1015- fields_desc = [
1016- BitEnumField ("system" , 0 , 2 , {0 : "Powertrain" , 1 : "Chassis" , 2 : "Body" , 3 : "Network" }),
1017- BitEnumField ("type" , 0 , 2 , {0 : "Generic" , 1 : "ManufacturerSpecific" , 2 : "Generic" , 3 : "Generic" }),
1018- BitField ("numeric_value_code" , 0 , 12 ),
1019- ByteField ("additional_information_code" , 0 ),
1020- FlagsField ("status" , 0 , 8 , UDS_RDTCI .dtcStatus )
1021- ]
1022-
1023- def extract_padding (self , s ):
1024- return '' , s
1025-
1026-
1027986class UDS_RDTCIPR (Packet ):
1028987 name = 'ReadDTCInformationPositiveResponse'
1029988 fields_desc = [
1030989 ByteEnumField ('reportType' , 0 , UDS_RDTCI .reportTypes ),
1031- ConditionalField (FlagsField ('DTCStatusAvailabilityMask' , 0 , 8 , UDS_RDTCI . dtcStatus ),
990+ ConditionalField (XByteField ('DTCStatusAvailabilityMask' , 0 ),
1032991 lambda pkt : pkt .reportType in [0x01 , 0x07 , 0x11 ,
1033992 0x12 , 0x02 , 0x0A ,
1034993 0x0B , 0x0C , 0x0D ,
@@ -1044,7 +1003,7 @@ class UDS_RDTCIPR(Packet):
10441003 ConditionalField (ShortField ('DTCCount' , 0 ),
10451004 lambda pkt : pkt .reportType in [0x01 , 0x07 ,
10461005 0x11 , 0x12 ]),
1047- ConditionalField (PacketListField ('DTCAndStatusRecord' , None , pkt_cls = DTC ),
1006+ ConditionalField (StrField ('DTCAndStatusRecord' , b"" ),
10481007 lambda pkt : pkt .reportType in [0x02 , 0x0A , 0x0B ,
10491008 0x0C , 0x0D , 0x0E ,
10501009 0x0F , 0x13 , 0x15 ]),
@@ -1056,7 +1015,7 @@ class UDS_RDTCIPR(Packet):
10561015
10571016 def answers (self , other ):
10581017 return isinstance (other , UDS_RDTCI ) \
1059- and other .reportType == self .reportType
1018+ and other .reportType == self .reportType
10601019
10611020
10621021bind_layers (UDS , UDS_RDTCIPR , service = 0x59 )
@@ -1091,8 +1050,8 @@ class UDS_RCPR(Packet):
10911050
10921051 def answers (self , other ):
10931052 return isinstance (other , UDS_RC ) \
1094- and other .routineControlType == self .routineControlType \
1095- and other .routineIdentifier == self .routineIdentifier
1053+ and other .routineControlType == self .routineControlType \
1054+ and other .routineIdentifier == self .routineIdentifier
10961055
10971056
10981057bind_layers (UDS , UDS_RCPR , service = 0x71 )
@@ -1211,7 +1170,7 @@ class UDS_TDPR(Packet):
12111170
12121171 def answers (self , other ):
12131172 return isinstance (other , UDS_TD ) \
1214- and other .blockSequenceCounter == self .blockSequenceCounter
1173+ and other .blockSequenceCounter == self .blockSequenceCounter
12151174
12161175
12171176bind_layers (UDS , UDS_TDPR , service = 0x76 )
@@ -1300,24 +1259,24 @@ def _contains_data_format_identifier(packet):
13001259 fmt = 'B' ),
13011260 lambda p : p .modeOfOperation != 2 ),
13021261 ConditionalField (StrLenField ('maxNumberOfBlockLength' , b"" ,
1303- length_from = lambda p : p .lengthFormatIdentifier ),
1262+ length_from = lambda p : p .lengthFormatIdentifier ),
13041263 lambda p : p .modeOfOperation != 2 ),
13051264 ConditionalField (BitField ('compressionMethod' , 0 , 4 ),
13061265 lambda p : p .modeOfOperation != 0x02 ),
13071266 ConditionalField (BitField ('encryptingMethod' , 0 , 4 ),
13081267 lambda p : p .modeOfOperation != 0x02 ),
13091268 ConditionalField (FieldLenField ('fileSizeOrDirInfoParameterLength' ,
1310- None ,
1311- length_of = 'fileSizeUncompressedOrDirInfoLength' ),
1269+ None ,
1270+ length_of = 'fileSizeUncompressedOrDirInfoLength' ),
13121271 lambda p : p .modeOfOperation not in [1 , 2 , 3 ]),
13131272 ConditionalField (StrLenField ('fileSizeUncompressedOrDirInfoLength' ,
13141273 b"" ,
13151274 length_from = lambda p :
13161275 p .fileSizeOrDirInfoParameterLength ),
13171276 lambda p : p .modeOfOperation not in [1 , 2 , 3 ]),
13181277 ConditionalField (StrLenField ('fileSizeCompressed' , b"" ,
1319- length_from = lambda p :
1320- p .fileSizeOrDirInfoParameterLength ),
1278+ length_from = lambda p :
1279+ p .fileSizeOrDirInfoParameterLength ),
13211280 lambda p : p .modeOfOperation not in [1 , 2 , 3 , 5 ]),
13221281 ]
13231282
@@ -1351,7 +1310,7 @@ class UDS_IOCBIPR(Packet):
13511310
13521311 def answers (self , other ):
13531312 return isinstance (other , UDS_IOCBI ) \
1354- and other .dataIdentifier == self .dataIdentifier
1313+ and other .dataIdentifier == self .dataIdentifier
13551314
13561315
13571316bind_layers (UDS , UDS_IOCBIPR , service = 0x6F )
@@ -1416,8 +1375,8 @@ class UDS_NR(Packet):
14161375
14171376 def answers (self , other ):
14181377 return self .requestServiceId == other .service and \
1419- (self .negativeResponseCode != 0x78 or
1420- conf .contribs ['UDS' ]['treat-response-pending-as-answer' ])
1378+ (self .negativeResponseCode != 0x78 or
1379+ conf .contribs ['UDS' ]['treat-response-pending-as-answer' ])
14211380
14221381
14231382bind_layers (UDS , UDS_NR , service = 0x7f )
0 commit comments