1616 BitEnumField , BitField , XByteField , FieldListField , \
1717 XShortField , X3BytesField , XIntField , ByteField , \
1818 ShortField , ObservableDict , XShortEnumField , XByteEnumField , StrLenField , \
19- FieldLenField , XStrFixedLenField , XStrLenField , FlagsField , PacketListField , \
20- PacketField
19+ FieldLenField , XStrFixedLenField , XStrLenField , FlagsField , PacketListField
2120from scapy .packet import Packet , bind_layers , NoPayload
2221from scapy .config import conf
2322from scapy .error import log_loading
@@ -153,7 +152,7 @@ class UDS_DSCPR(Packet):
153152
154153 def answers (self , other ):
155154 return isinstance (other , UDS_DSC ) and \
156- other .diagnosticSessionType == self .diagnosticSessionType
155+ other .diagnosticSessionType == self .diagnosticSessionType
157156
158157
159158bind_layers (UDS , UDS_DSCPR , service = 0x50 )
@@ -219,7 +218,7 @@ class UDS_SAPR(Packet):
219218
220219 def answers (self , other ):
221220 return isinstance (other , UDS_SA ) \
222- and other .securityAccessType == self .securityAccessType
221+ and other .securityAccessType == self .securityAccessType
223222
224223
225224bind_layers (UDS , UDS_SAPR , service = 0x67 )
@@ -274,7 +273,7 @@ class UDS_CCPR(Packet):
274273
275274 def answers (self , other ):
276275 return isinstance (other , UDS_CC ) \
277- and other .controlType == self .controlType
276+ and other .controlType == self .controlType
278277
279278
280279bind_layers (UDS , UDS_CCPR , service = 0x68 )
@@ -430,7 +429,7 @@ class UDS_AUTHPR(Packet):
430429
431430 def answers (self , other ):
432431 return isinstance (other , UDS_AUTH ) \
433- and other .subFunction == self .subFunction
432+ and other .subFunction == self .subFunction
434433
435434
436435bind_layers (UDS , UDS_AUTHPR , service = 0x69 )
@@ -492,8 +491,8 @@ class UDS_ATPPR(Packet):
492491
493492 def answers (self , other ):
494493 return isinstance (other , UDS_ATP ) \
495- and other .timingParameterAccessType == \
496- self .timingParameterAccessType
494+ and other .timingParameterAccessType == \
495+ self .timingParameterAccessType
497496
498497
499498bind_layers (UDS , UDS_ATPPR , service = 0xC3 )
@@ -606,7 +605,7 @@ class UDS_ROEPR(Packet):
606605
607606 def answers (self , other ):
608607 return isinstance (other , UDS_ROE ) \
609- and other .eventType == self .eventType
608+ and other .eventType == self .eventType
610609
611610
612611bind_layers (UDS , UDS_ROEPR , service = 0xC6 )
@@ -645,7 +644,7 @@ class UDS_LCPR(Packet):
645644
646645 def answers (self , other ):
647646 return isinstance (other , UDS_LC ) \
648- and other .linkControlType == self .linkControlType
647+ and other .linkControlType == self .linkControlType
649648
650649
651650bind_layers (UDS , UDS_LCPR , service = 0xC7 )
@@ -674,7 +673,7 @@ class UDS_RDBIPR(Packet):
674673
675674 def answers (self , other ):
676675 return isinstance (other , UDS_RDBI ) \
677- and self .dataIdentifier in other .identifiers
676+ and self .dataIdentifier in other .identifiers
678677
679678
680679bind_layers (UDS , UDS_RDBIPR , service = 0x62 )
@@ -744,7 +743,7 @@ class UDS_RSDBIPR(Packet):
744743
745744 def answers (self , other ):
746745 return isinstance (other , UDS_RSDBI ) \
747- and other .dataIdentifier == self .dataIdentifier
746+ and other .dataIdentifier == self .dataIdentifier
748747
749748
750749bind_layers (UDS , UDS_RSDBIPR , service = 0x64 )
@@ -781,7 +780,7 @@ class UDS_RDBPIPR(Packet):
781780
782781 def answers (self , other ):
783782 return isinstance (other , UDS_RDBPI ) \
784- and other .periodicDataIdentifier == self .periodicDataIdentifier
783+ and other .periodicDataIdentifier == self .periodicDataIdentifier
785784
786785
787786bind_layers (UDS , UDS_RDBPIPR , service = 0x6A )
@@ -813,7 +812,7 @@ class UDS_DDDIPR(Packet):
813812
814813 def answers (self , other ):
815814 return isinstance (other , UDS_DDDI ) \
816- and other .subFunction == self .subFunction
815+ and other .subFunction == self .subFunction
817816
818817
819818bind_layers (UDS , UDS_DDDIPR , service = 0x6C )
@@ -840,7 +839,7 @@ class UDS_WDBIPR(Packet):
840839
841840 def answers (self , other ):
842841 return isinstance (other , UDS_WDBI ) \
843- and other .dataIdentifier == self .dataIdentifier
842+ and other .dataIdentifier == self .dataIdentifier
844843
845844
846845bind_layers (UDS , UDS_WDBIPR , service = 0x6E )
@@ -901,8 +900,8 @@ class UDS_WMBAPR(Packet):
901900
902901 def answers (self , other ):
903902 return isinstance (other , UDS_WMBA ) \
904- and other .memorySizeLen == self .memorySizeLen \
905- and other .memoryAddressLen == self .memoryAddressLen
903+ and other .memorySizeLen == self .memorySizeLen \
904+ and other .memoryAddressLen == self .memoryAddressLen
906905
907906
908907bind_layers (UDS , UDS_WMBAPR , service = 0x7D )
@@ -1012,32 +1011,12 @@ class UDS_RDTCI(Packet):
10121011
10131012
10141013class DTC (Packet ):
1015- name = 'Diagnostic Trouble Code'
1016- dtc_descriptions = {} # Customize this dictionary for each individual ECU / OEM
1017-
1014+ name = 'DTC and status record'
10181015 fields_desc = [
1019- BitEnumField ("system" , 0 , 2 , {
1020- 0 : "Powertrain" ,
1021- 1 : "Chassis" ,
1022- 2 : "Body" ,
1023- 3 : "Network" }),
1024- BitEnumField ("type" , 0 , 2 , {
1025- 0 : "Generic" ,
1026- 1 : "ManufacturerSpecific" ,
1027- 2 : "Generic" ,
1028- 3 : "Generic" }),
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" }),
10291018 BitField ("numeric_value_code" , 0 , 12 ),
10301019 ByteField ("additional_information_code" , 0 ),
1031- ]
1032-
1033- def extract_padding (self , s ):
1034- return '' , s
1035-
1036-
1037- class DTCAndStatusRecord (Packet ):
1038- name = 'DTC and status record'
1039- fields_desc = [
1040- PacketField ("dtc" , None , pkt_cls = DTC ),
10411020 FlagsField ("status" , 0 , 8 , UDS_RDTCI .dtcStatus )
10421021 ]
10431022
@@ -1069,11 +1048,12 @@ class UDS_RDTCIPR(Packet):
10691048 name = 'ReadDTCInformationPositiveResponse'
10701049 fields_desc = [
10711050 ByteEnumField ('reportType' , 0 , UDS_RDTCI .reportTypes ),
1072- ConditionalField (
1073- FlagsField ('DTCStatusAvailabilityMask' , 0 , 8 , UDS_RDTCI .dtcStatus ),
1074- lambda pkt : pkt .reportType in [0x01 , 0x07 , 0x11 , 0x12 , 0x02 , 0x0A ,
1075- 0x0B , 0x0C , 0x0D , 0x0E , 0x0F , 0x13 ,
1076- 0x15 ]),
1051+ ConditionalField (FlagsField ('DTCStatusAvailabilityMask' , 0 , 8 , UDS_RDTCI .dtcStatus ),
1052+ lambda pkt : pkt .reportType in [0x01 , 0x07 , 0x11 ,
1053+ 0x12 , 0x02 , 0x0A ,
1054+ 0x0B , 0x0C , 0x0D ,
1055+ 0x0E , 0x0F , 0x13 ,
1056+ 0x15 ]),
10771057 ConditionalField (ByteEnumField ('DTCFormatIdentifier' , 0 ,
10781058 {0 : 'ISO15031-6DTCFormat' ,
10791059 1 : 'UDS-1DTCFormat' ,
@@ -1084,8 +1064,7 @@ class UDS_RDTCIPR(Packet):
10841064 ConditionalField (ShortField ('DTCCount' , 0 ),
10851065 lambda pkt : pkt .reportType in [0x01 , 0x07 ,
10861066 0x11 , 0x12 ]),
1087- ConditionalField (PacketListField ('DTCAndStatusRecord' , None ,
1088- pkt_cls = DTCAndStatusRecord ),
1067+ ConditionalField (PacketListField ('DTCAndStatusRecord' , None , pkt_cls = DTC ),
10891068 lambda pkt : pkt .reportType in [0x02 , 0x0A , 0x0B ,
10901069 0x0C , 0x0D , 0x0E ,
10911070 0x0F , 0x13 , 0x15 ]),
@@ -1099,7 +1078,7 @@ class UDS_RDTCIPR(Packet):
10991078
11001079 def answers (self , other ):
11011080 return isinstance (other , UDS_RDTCI ) \
1102- and other .reportType == self .reportType
1081+ and other .reportType == self .reportType
11031082
11041083
11051084bind_layers (UDS , UDS_RDTCIPR , service = 0x59 )
@@ -1134,8 +1113,8 @@ class UDS_RCPR(Packet):
11341113
11351114 def answers (self , other ):
11361115 return isinstance (other , UDS_RC ) \
1137- and other .routineControlType == self .routineControlType \
1138- and other .routineIdentifier == self .routineIdentifier
1116+ and other .routineControlType == self .routineControlType \
1117+ and other .routineIdentifier == self .routineIdentifier
11391118
11401119
11411120bind_layers (UDS , UDS_RCPR , service = 0x71 )
@@ -1254,7 +1233,7 @@ class UDS_TDPR(Packet):
12541233
12551234 def answers (self , other ):
12561235 return isinstance (other , UDS_TD ) \
1257- and other .blockSequenceCounter == self .blockSequenceCounter
1236+ and other .blockSequenceCounter == self .blockSequenceCounter
12581237
12591238
12601239bind_layers (UDS , UDS_TDPR , service = 0x76 )
@@ -1394,7 +1373,7 @@ class UDS_IOCBIPR(Packet):
13941373
13951374 def answers (self , other ):
13961375 return isinstance (other , UDS_IOCBI ) \
1397- and other .dataIdentifier == self .dataIdentifier
1376+ and other .dataIdentifier == self .dataIdentifier
13981377
13991378
14001379bind_layers (UDS , UDS_IOCBIPR , service = 0x6F )
@@ -1459,8 +1438,8 @@ class UDS_NR(Packet):
14591438
14601439 def answers (self , other ):
14611440 return self .requestServiceId == other .service and \
1462- (self .negativeResponseCode != 0x78 or
1463- conf .contribs ['UDS' ]['treat-response-pending-as-answer' ])
1441+ (self .negativeResponseCode != 0x78 or
1442+ conf .contribs ['UDS' ]['treat-response-pending-as-answer' ])
14641443
14651444
14661445bind_layers (UDS , UDS_NR , service = 0x7f )
0 commit comments