Fix default values in UDS
diff --git a/scapy/contrib/automotive/uds.py b/scapy/contrib/automotive/uds.py
index 5d23928..19b72c4 100644
--- a/scapy/contrib/automotive/uds.py
+++ b/scapy/contrib/automotive/uds.py
@@ -20,6 +20,7 @@
from scapy.error import log_loading
from scapy.utils import PeriodicSenderThread
from scapy.contrib.isotp import ISOTP
+from scapy.compat import Dict, Union, Tuple, Any
"""
UDS
@@ -91,13 +92,14 @@
0xC5: 'ControlDTCSettingPositiveResponse',
0xC6: 'ResponseOnEventPositiveResponse',
0xC7: 'LinkControlPositiveResponse',
- 0x7f: 'NegativeResponse'})
+ 0x7f: 'NegativeResponse'}) # type: Dict[int, str]
name = 'UDS'
fields_desc = [
XByteEnumField('service', 0, services)
]
def answers(self, other):
+ # type: (Union[UDS, Packet]) -> bool
if other.__class__ != self.__class__:
return False
if self.service == 0x7f:
@@ -111,6 +113,7 @@
return False
def hashret(self):
+ # type: () -> bytes
if self.service == 0x7f:
return struct.pack('B', self.requestServiceId)
return struct.pack('B', self.service & ~0x40)
@@ -132,6 +135,7 @@
@staticmethod
def get_log(pkt):
+ # type: (UDS_DSC) -> Tuple[str, Any]
return pkt.sprintf("%UDS.service%"), \
pkt.sprintf("%UDS_DSC.diagnosticSessionType%")
@@ -144,7 +148,7 @@
fields_desc = [
ByteEnumField('diagnosticSessionType', 0,
UDS_DSC.diagnosticSessionTypes),
- StrField('sessionParameterRecord', B"")
+ StrField('sessionParameterRecord', b"")
]
def answers(self, other):
@@ -173,6 +177,7 @@
0x03: 'softReset',
0x04: 'enableRapidPowerShutDown',
0x05: 'disableRapidPowerShutDown',
+ 0x41: 'powerDown',
0x7F: 'ISOSAEReserved'}
name = 'ECUReset'
fields_desc = [
@@ -217,9 +222,9 @@
name = 'SecurityAccess'
fields_desc = [
ByteField('securityAccessType', 0),
- ConditionalField(StrField('securityAccessDataRecord', B""),
+ ConditionalField(StrField('securityAccessDataRecord', b""),
lambda pkt: pkt.securityAccessType % 2 == 1),
- ConditionalField(StrField('securityKey', B""),
+ ConditionalField(StrField('securityKey', b""),
lambda pkt: pkt.securityAccessType % 2 == 0)
]
@@ -240,7 +245,7 @@
name = 'SecurityAccessPositiveResponse'
fields_desc = [
ByteField('securityAccessType', 0),
- ConditionalField(StrField('securitySeed', B""),
+ ConditionalField(StrField('securitySeed', b""),
lambda pkt: pkt.securityAccessType % 2 == 1),
]
@@ -380,7 +385,7 @@
fields_desc = [
ByteEnumField('timingParameterAccessType', 0,
timingParameterAccessTypes),
- ConditionalField(StrField('timingParameterRequestRecord', B""),
+ ConditionalField(StrField('timingParameterRequestRecord', b""),
lambda pkt: pkt.timingParameterAccessType == 0x4)
]
@@ -393,7 +398,7 @@
fields_desc = [
ByteEnumField('timingParameterAccessType', 0,
UDS_ATP.timingParameterAccessTypes),
- ConditionalField(StrField('timingParameterResponseRecord', B""),
+ ConditionalField(StrField('timingParameterResponseRecord', b""),
lambda pkt: pkt.timingParameterAccessType == 0x3)
]
@@ -410,7 +415,7 @@
class UDS_SDT(Packet):
name = 'SecuredDataTransmission'
fields_desc = [
- StrField('securityDataRequestRecord', B"")
+ StrField('securityDataRequestRecord', b"")
]
@staticmethod
@@ -424,7 +429,7 @@
class UDS_SDTPR(Packet):
name = 'SecuredDataTransmissionPositiveResponse'
fields_desc = [
- StrField('securityDataResponseRecord', B"")
+ StrField('securityDataResponseRecord', b"")
]
def answers(self, other):
@@ -448,7 +453,7 @@
name = 'ControlDTCSetting'
fields_desc = [
ByteEnumField('DTCSettingType', 0, DTCSettingTypes),
- StrField('DTCSettingControlOptionRecord', B"")
+ StrField('DTCSettingControlOptionRecord', b"")
]
@staticmethod
@@ -489,7 +494,7 @@
fields_desc = [
ByteEnumField('eventType', 0, eventTypes),
ByteField('eventWindowTime', 0),
- StrField('eventTypeRecord', B"")
+ StrField('eventTypeRecord', b"")
]
@@ -502,7 +507,7 @@
ByteEnumField('eventType', 0, UDS_ROE.eventTypes),
ByteField('numberOfIdentifiedEvents', 0),
ByteField('eventWindowTime', 0),
- StrField('eventTypeRecord', B"")
+ StrField('eventTypeRecord', b"")
]
def answers(self, other):
@@ -567,7 +572,7 @@
dataIdentifiers = ObservableDict()
name = 'ReadDataByIdentifier'
fields_desc = [
- FieldListField("identifiers", [0],
+ FieldListField("identifiers", None,
XShortEnumField('dataIdentifier', 0,
dataIdentifiers))
]
@@ -627,9 +632,9 @@
@staticmethod
def get_log(pkt):
- addr = getattr(pkt, "memoryAddress%d" % pkt.memoryAddressLen)
- size = getattr(pkt, "memorySize%d" % pkt.memorySizeLen)
- return pkt.sprintf("%UDS.service%"), (addr, size)
+ return pkt.sprintf("%UDS.service%"), \
+ (getattr(pkt, "memoryAddress%d" % pkt.memoryAddressLen),
+ getattr(pkt, "memorySize%d" % pkt.memorySizeLen))
bind_layers(UDS, UDS_RMBA, service=0x23)
@@ -638,7 +643,7 @@
class UDS_RMBAPR(Packet):
name = 'ReadMemoryByAddressPositiveResponse'
fields_desc = [
- StrField('dataRecord', None, fmt="B")
+ StrField('dataRecord', b"", fmt="B")
]
def answers(self, other):
@@ -670,7 +675,7 @@
fields_desc = [
XShortEnumField('dataIdentifier', 0, UDS_RSDBI.dataIdentifiers),
ByteField('scalingByte', 0),
- StrField('dataRecord', None, fmt="B")
+ StrField('dataRecord', b"", fmt="B")
]
def answers(self, other):
@@ -694,7 +699,7 @@
fields_desc = [
ByteEnumField('transmissionMode', 0, transmissionModes),
ByteField('periodicDataIdentifier', 0),
- StrField('furtherPeriodicDataIdentifier', 0, fmt="B")
+ StrField('furtherPeriodicDataIdentifier', b"", fmt="B")
]
@@ -706,7 +711,7 @@
name = 'ReadDataByPeriodicIdentifierPositiveResponse'
fields_desc = [
ByteField('periodicDataIdentifier', 0),
- StrField('dataRecord', None, fmt="B")
+ StrField('dataRecord', b"", fmt="B")
]
def answers(self, other):
@@ -727,7 +732,7 @@
0x3: "clearDynamicallyDefinedDataIdentifier"}
fields_desc = [
ByteEnumField('subFunction', 0, subFunctions),
- StrField('dataRecord', 0, fmt="B")
+ StrField('dataRecord', b"", fmt="B")
]
@@ -808,7 +813,7 @@
lambda pkt: pkt.memorySizeLen == 3),
ConditionalField(XIntField('memorySize4', 0),
lambda pkt: pkt.memorySizeLen == 4),
- StrField('dataRecord', b'\x00', fmt="B"),
+ StrField('dataRecord', b'', fmt="B"),
]
@@ -970,11 +975,11 @@
ConditionalField(ShortField('DTCCount', 0),
lambda pkt: pkt.reportType in [0x01, 0x07,
0x11, 0x12]),
- ConditionalField(StrField('DTCAndStatusRecord', 0),
+ ConditionalField(StrField('DTCAndStatusRecord', b""),
lambda pkt: pkt.reportType in [0x02, 0x0A, 0x0B,
0x0C, 0x0D, 0x0E,
0x0F, 0x13, 0x15]),
- ConditionalField(StrField('dataRecord', 0),
+ ConditionalField(StrField('dataRecord', b""),
lambda pkt: pkt.reportType in [0x03, 0x04, 0x05,
0x06, 0x08, 0x09,
0x10, 0x14])
@@ -1005,7 +1010,7 @@
fields_desc = [
ByteEnumField('routineControlType', 0, routineControlTypes),
XShortEnumField('routineIdentifier', 0, routineControlIdentifiers),
- StrField('routineControlOptionRecord', 0, fmt="B"),
+ StrField('routineControlOptionRecord', b"", fmt="B"),
]
@staticmethod
@@ -1026,7 +1031,7 @@
UDS_RC.routineControlTypes),
XShortEnumField('routineIdentifier', 0,
UDS_RC.routineControlIdentifiers),
- StrField('routineStatusRecord', 0, fmt="B"),
+ StrField('routineStatusRecord', b"", fmt="B"),
]
def answers(self, other):
@@ -1087,7 +1092,7 @@
fields_desc = [
BitField('memorySizeLen', 0, 4),
BitField('reserved', 0, 4),
- StrField('maxNumberOfBlockLength', 0, fmt="B"),
+ StrField('maxNumberOfBlockLength', b"", fmt="B"),
]
def answers(self, other):
@@ -1142,7 +1147,7 @@
fields_desc = [
BitField('memorySizeLen', 0, 4),
BitField('reserved', 0, 4),
- StrField('maxNumberOfBlockLength', 0, fmt="B"),
+ StrField('maxNumberOfBlockLength', b"", fmt="B"),
]
def answers(self, other):
@@ -1161,7 +1166,7 @@
name = 'TransferData'
fields_desc = [
ByteField('blockSequenceCounter', 0),
- StrField('transferRequestParameterRecord', 0, fmt="B")
+ StrField('transferRequestParameterRecord', b"", fmt="B")
]
@staticmethod
@@ -1177,7 +1182,7 @@
name = 'TransferDataPositiveResponse'
fields_desc = [
ByteField('blockSequenceCounter', 0),
- StrField('transferResponseParameterRecord', 0, fmt="B")
+ StrField('transferResponseParameterRecord', b"", fmt="B")
]
def answers(self, other):
@@ -1196,7 +1201,7 @@
class UDS_RTE(Packet):
name = 'RequestTransferExit'
fields_desc = [
- StrField('transferRequestParameterRecord', 0, fmt="B")
+ StrField('transferRequestParameterRecord', b"", fmt="B")
]
@staticmethod
@@ -1211,7 +1216,7 @@
class UDS_RTEPR(Packet):
name = 'RequestTransferExitPositiveResponse'
fields_desc = [
- StrField('transferResponseParameterRecord', 0, fmt="B")
+ StrField('transferResponseParameterRecord', b"", fmt="B")
]
def answers(self, other):
@@ -1328,7 +1333,7 @@
fields_desc = [
XShortEnumField('dataIdentifier', 0, dataIdentifiers),
ByteField('controlOptionRecord', 0),
- StrField('controlEnableMaskRecord', 0, fmt="B")
+ StrField('controlEnableMaskRecord', b"", fmt="B")
]
@staticmethod
@@ -1343,7 +1348,7 @@
name = 'InputOutputControlByIdentifierPositiveResponse'
fields_desc = [
XShortField('dataIdentifier', 0),
- StrField('controlStatusRecord', 0, fmt="B")
+ StrField('controlStatusRecord', b"", fmt="B")
]
def answers(self, other):