% Regression tests for the UDS layer

# More information at http://www.secdev.org/projects/UTscapy/


############
############

+ Basic operations

= Load module
load_contrib("automotive.uds", globals_dict=globals())
load_contrib("automotive.ecu", globals_dict=globals())

from scapy.contrib.automotive.uds_ecu_states import *

= Check if positive response answers

dsc = UDS(b'\x10')
dscpr = UDS(b'\x50')
assert dscpr.answers(dsc)

= Check hashret
dsc.hashret() == dscpr.hashret()

= Check if negative response answers

dsc = UDS(b'\x10')
neg = UDS(b'\x7f\x10')
assert neg.answers(dsc)

= CHECK hashret NEG
dsc.hashret() == neg.hashret()

= Check if negative response answers not

dsc = UDS(b'\x10')
neg = UDS(b'\x7f\x11')
assert not neg.answers(dsc)

= Check if positive response answers not

dsc = UDS(b'\x10')
somePacket = UDS(b'\x49')
assert not somePacket.answers(dsc)

= Check UDS_DSC

dsc = UDS(b'\x10\x01')
assert dsc.service == 0x10
assert dsc.diagnosticSessionType == 0x01

= Check UDS_DSC

dsc = UDS()/UDS_DSC(b'\x01')
assert dsc.service == 0x10
assert dsc.diagnosticSessionType == 0x01

= Check UDS_DSCPR

dscpr = UDS(b'\x50\x02beef')
assert dscpr.service == 0x50
assert dscpr.diagnosticSessionType == 0x02

assert not dscpr.answers(dsc)

= Check UDS_DSCPR

dscpr = UDS()/UDS_DSCPR(b'\x01beef')
assert dscpr.service == 0x50
assert dscpr.diagnosticSessionType == 0x01
assert dscpr.sessionParameterRecord == b"beef"

assert dscpr.answers(dsc)

= Check UDS_DSC

dsc = UDS()/UDS_DSC(b'\x01')
assert dsc.service == 0x10
assert dsc.diagnosticSessionType == 0x01

= Check UDS_DSCPR

dscpr = UDS()/UDS_DSCPR(b'\x01beef')
assert dscpr.service == 0x50
assert dscpr.diagnosticSessionType == 0x01
assert dscpr.sessionParameterRecord == b"beef"

assert dscpr.answers(dsc)

= Check UDS_DSC modifies ecu state

dsc = UDS()/UDS_DSC(b'\x09')
assert dsc.service == 0x10
assert dsc.diagnosticSessionType == 0x09

= Check UDS_DSCPR modifies ecu state

dscpr = UDS()/UDS_DSCPR(b'\x09beef')
assert dscpr.service == 0x50
assert dscpr.diagnosticSessionType == 0x09
assert dscpr.sessionParameterRecord == b"beef"

ecu = Ecu()
ecu.update(dsc)
ecu.update(dscpr)
assert ecu.state.session == 9

= Check UDS_ER

er = UDS(b'\x11\x01')
assert er.service == 0x11
assert er.resetType == 0x01

= Check UDS_ER

er = UDS()/UDS_ER(resetType="hardReset")
assert er.service == 0x11
assert er.resetType == 0x01

= Check UDS_ERPR

erpr = UDS(b'\x51\x01')
assert erpr.service == 0x51
assert erpr.resetType == 0x01

assert erpr.answers(er)

= Check UDS_ERPR

erpr = UDS(b'\x51\x04\x10')
assert erpr.service == 0x51
assert erpr.resetType == 0x04
assert erpr.powerDownTime == 0x10

= Check UDS_ERPR modifies ecu state

erpr = UDS(b'\x51\x04\x10')
assert erpr.service == 0x51
assert erpr.resetType == 0x04
assert erpr.powerDownTime == 0x10

ecu = Ecu()
ecu.state.security_level = 5
ecu.state.session = 3
ecu.state.communication_control = 4
ecu.update(er)
ecu.update(erpr)

assert ecu.state.session == 1

= Check UDS_SA

sa = UDS(b'\x27\x00c0ffee')
assert sa.service == 0x27
assert sa.securityAccessType == 0x0
assert sa.securityKey == b'c0ffee'

= Check UDS_SAPR

sapr = UDS(b'\x67\x00')
assert sapr.service == 0x67
assert sapr.securityAccessType == 0x0

assert sapr.answers(sa)

= Check UDS_SA

sa = UDS(b'\x27\x01c0ffee')
assert sa.service == 0x27
assert sa.securityAccessType == 0x1
assert sa.securityAccessDataRecord == b'c0ffee'

= Check UDS_SAPR

sapr = UDS(b'\x67\x01c0ffee')
assert sapr.service == 0x67
assert sapr.securityAccessType == 0x1
assert sapr.securitySeed == b'c0ffee'

assert sapr.answers(sa)

= Check UDS_SA

sa = UDS(b'\x27\x06c0ffee')
assert sa.service == 0x27
assert sa.securityAccessType == 0x6
assert sa.securityKey == b'c0ffee'


= Check UDS_SAPR modifies ecu state

sapr = UDS(b'\x67\x06')
assert sapr.service == 0x67
assert sapr.securityAccessType == 0x6

ecu = Ecu()
ecu.update(sa)
ecu.update(sapr)
assert ecu.state.security_level == 6

= Check UDS_SA

sa = UDS(b'\x27\x01c0ffee')
assert sa.service == 0x27
assert sa.securityAccessType == 0x1
assert sa.securityAccessDataRecord == b'c0ffee'

= Check UDS_SAPR

sapr = UDS(b'\x67\x01c0ffee')
assert sapr.service == 0x67
assert sapr.securityAccessType == 0x1
assert sapr.securitySeed == b'c0ffee'


= Check UDS_CC

cc = UDS(b'\x28\x01\xff')
assert cc.service == 0x28
assert cc.controlType == 0x1
assert cc.communicationType0 == 0x3
assert cc.communicationType1 == 0x3
assert cc.communicationType2 == 0xf

= Check UDS_CCPR

ccpr = UDS(b'\x68\x01')
assert ccpr.service == 0x68
assert ccpr.controlType == 0x1

assert ccpr.answers(cc)

= Check UDS_CCPR modifies ecu state

ccpr = UDS(b'\x68\x01')
assert ccpr.service == 0x68
assert ccpr.controlType == 0x1

ecu = Ecu()
ecu.update(cc)
ecu.update(ccpr)
assert ecu.state.communication_control == 1

= Check UDS_TP

tp = UDS(b'\x3E\x01')
assert tp.service == 0x3e
assert tp.subFunction == 0x1

= Check UDS_TPPR

tppr = UDS(b'\x7E\x01')
assert tppr.service == 0x7e
assert tppr.zeroSubFunction == 0x1

assert tppr.answers(tp)

= Check UDS_ATP

atp = UDS(b'\x83\x01')
assert atp.service == 0x83
assert atp.timingParameterAccessType == 0x1

= Check UDS_ATPPR

atppr = UDS(b'\xc3\x01')
assert atppr.service == 0xc3
assert atppr.timingParameterAccessType == 0x1

assert atppr.answers(atp)

= Check UDS_ATP

atp = UDS(b'\x83\x04coffee')
assert atp.service == 0x83
assert atp.timingParameterAccessType == 0x4
assert atp.timingParameterRequestRecord == b'coffee'

= Check UDS_ATPPR

atppr = UDS(b'\xc3\x03coffee')
assert atppr.service == 0xc3
assert atppr.timingParameterAccessType == 0x3
assert atppr.timingParameterResponseRecord == b'coffee'

= Check UDS_SDT

sdt = UDS(b'\x84coffee')
assert sdt.service == 0x84
assert sdt.securityDataRequestRecord == b'coffee'

= Check UDS_SDTPR

sdtpr = UDS(b'\xC4coffee')
assert sdtpr.service == 0xC4
assert sdtpr.securityDataResponseRecord == b'coffee'

assert sdtpr.answers(sdt)

= Check UDS_CDTCS

cdtcs = UDS(b'\x85\x00coffee')
assert cdtcs.service == 0x85
assert cdtcs.DTCSettingType == 0
assert cdtcs.DTCSettingControlOptionRecord == b'coffee'

= Check UDS_CDTCSPR

cdtcspr = UDS(b'\xC5\x00')
assert cdtcspr.service == 0xC5
assert cdtcspr.DTCSettingType == 0

assert cdtcspr.answers(cdtcs)

= Check UDS_ROE

roe = UDS(b'\x86\x00\x10coffee')
assert roe.service == 0x86
assert roe.eventType == 0
assert roe.eventWindowTime == 16
assert roe.eventTypeRecord == b'coffee'

= Check UDS_ROEPR

roepr = UDS(b'\xC6\x00\x01\x10coffee')
assert roepr.service == 0xC6
assert roepr.eventType == 0
assert roepr.numberOfIdentifiedEvents == 1
assert roepr.eventWindowTime == 16
assert roepr.eventTypeRecord == b'coffee'

assert roepr.answers(roe)

= Check UDS_LC

lc = UDS(b'\x87\x01\x02')
assert lc.service == 0x87
assert lc.linkControlType == 0x01
assert lc.baudrateIdentifier == 0x02

= Check UDS_LCPR

lcpr = UDS(b'\xC7\x01')
assert lcpr.service == 0xC7
assert lcpr.linkControlType == 0x01

assert lcpr.answers(lc)

= Check UDS_LC

lc = UDS(b'\x87\x02\x02\x03\x04')
assert lc.service == 0x87
assert lc.linkControlType == 0x02
assert lc.baudrateHighByte == 0x02
assert lc.baudrateMiddleByte == 0x03
assert lc.baudrateLowByte == 0x04

= Check UDS_RDBI

rdbi = UDS(b'\x22\x01\x02')
assert rdbi.service == 0x22
assert rdbi.identifiers[0] == 0x0102

= Build UDS_RDBI

rdbi = UDS()/UDS_RDBI(identifiers=[0x102])
assert rdbi.service == 0x22
assert rdbi.identifiers[0] == 0x0102
assert bytes(rdbi) == b'\x22\x01\x02'

= Check UDS_RDBI2

rdbi = UDS(b'\x22\x01\x02\x03\x04')
assert rdbi.service == 0x22
assert rdbi.identifiers[0] == 0x0102
assert rdbi.identifiers[1] == 0x0304
assert raw(rdbi) == b'\x22\x01\x02\x03\x04'

= Build UDS_RDBI2

rdbi = UDS()/UDS_RDBI(identifiers=[0x102, 0x304])
assert rdbi.service == 0x22
assert rdbi.identifiers[0] == 0x0102
assert rdbi.identifiers[1] == 0x0304
assert raw(rdbi) == b'\x22\x01\x02\x03\x04'

= Test observable dict used in UDS_RDBI, setter

UDS_RDBI.dataIdentifiers[0x102] = "turbo"
UDS_RDBI.dataIdentifiers[0x103] = "fullspeed"

rdbi = UDS()/UDS_RDBI(identifiers=[0x102, 0x103])

assert "turbo" in plain_str(repr(rdbi))
assert "fullspeed" in plain_str(repr(rdbi))

= Test observable dict used in UDS_RDBI, deleter

UDS_RDBI.dataIdentifiers[0x102] = "turbo"

rdbi = UDS()/UDS_RDBI(identifiers=[0x102, 0x103])
assert "turbo" in plain_str(repr(rdbi))

del UDS_RDBI.dataIdentifiers[0x102]
UDS_RDBI.dataIdentifiers[0x103] = "slowspeed"

rdbi = UDS()/UDS_RDBI(identifiers=[0x102, 0x103])

assert "turbo" not in plain_str(repr(rdbi))
assert "slowspeed" in plain_str(repr(rdbi))

= Check UDS_RDBIPR

rdbipr = UDS(b'\x62\x01\x02dieselgate')
assert rdbipr.service == 0x62
assert rdbipr.dataIdentifier == 0x0102
assert rdbipr.load == b'dieselgate'

assert rdbipr.answers(rdbi)

= Check UDS_RMBA

rmba = UDS(b'\x23\x11\x02\x02')
assert rmba.service == 0x23
assert rmba.memorySizeLen == 1
assert rmba.memoryAddressLen == 1
assert rmba.memoryAddress1 == 2
assert rmba.memorySize1 == 2

= Check UDS_RMBA

rmba = UDS(b'\x23\x22\x02\x02\x03\x03')
assert rmba.service == 0x23
assert rmba.memorySizeLen == 2
assert rmba.memoryAddressLen == 2
assert rmba.memoryAddress2 == 0x202
assert rmba.memorySize2 == 0x303

= Check UDS_RMBA

rmba = UDS(b'\x23\x33\x02\x02\x02\x03\x03\x03')
assert rmba.service == 0x23
assert rmba.memorySizeLen == 3
assert rmba.memoryAddressLen == 3
assert rmba.memoryAddress3 == 0x20202
assert rmba.memorySize3 == 0x30303

= Check UDS_RMBA

rmba = UDS(b'\x23\x44\x02\x02\x02\x02\x03\x03\x03\x03')
assert rmba.service == 0x23
assert rmba.memorySizeLen == 4
assert rmba.memoryAddressLen == 4
assert rmba.memoryAddress4 == 0x2020202
assert rmba.memorySize4 == 0x3030303

= Check UDS_RMBAPR

rmbapr = UDS(b'\x63muchData')
assert rmbapr.service == 0x63
assert rmbapr.dataRecord == b'muchData'

assert rmbapr.answers(rmba)

= Check UDS_RSDBI

rsdbi = UDS(b'\x24\x12\x34')
assert rsdbi.service == 0x24
assert rsdbi.dataIdentifier == 0x1234

= Check UDS_RSDBIPR

rsdbipr = UDS(b'\x64\x12\x34\xffmuchData')
assert rsdbipr.service == 0x64
assert rsdbipr.dataIdentifier == 0x1234
assert rsdbipr.scalingByte == 255
assert rsdbipr.dataRecord == b'muchData'

assert rsdbipr.answers(rsdbi)

= Check UDS_RSDBPI

rsdbpi = UDS(b'\x2a\x12\x34coffee')
assert rsdbpi.service == 0x2a
assert rsdbpi.transmissionMode == 0x12
assert rsdbpi.periodicDataIdentifier == 0x34
assert rsdbpi.furtherPeriodicDataIdentifier == b'coffee'

= Check UDS_RSDBPIPR

rsdbpipr = UDS(b'\x6a\xff\x12\x34')
assert rsdbpipr.service == 0x6a
assert rsdbpipr.periodicDataIdentifier == 255
assert rsdbpipr.dataRecord == b'\x12\x34'

assert not rsdbpipr.answers(rsdbpi)

= Check UDS_RSDBPIPR

rsdbpipr = UDS(b'\x6a\x34\x12\x34')
assert rsdbpipr.service == 0x6a
assert rsdbpipr.periodicDataIdentifier == 0x34
assert rsdbpipr.dataRecord == b'\x12\x34'

assert rsdbpipr.answers(rsdbpi)

= Check UDS_DDDI

dddi = UDS(b'\x2c\x12coffee')
assert dddi.service == 0x2c
assert dddi.subFunction == 0x12
assert dddi.dataRecord == b'coffee'

= Check UDS_DDDIPR

dddipr = UDS(b'\x6c\x12\x44\x55')
assert dddipr.service == 0x6c
assert dddipr.subFunction == 0x12
assert dddipr.dynamicallyDefinedDataIdentifier == 0x4455

assert dddipr.answers(dddi)

= Check UDS_WDBI

wdbi = UDS(b'\x2e\x01\x02dieselgate')
assert wdbi.service == 0x2e
assert wdbi.dataIdentifier == 0x0102
assert wdbi.load == b'dieselgate'

= Build UDS_WDBI

wdbi = UDS()/UDS_WDBI(dataIdentifier=0x0102)/Raw(load=b'dieselgate')
assert wdbi.service == 0x2e
assert wdbi.dataIdentifier == 0x0102
assert wdbi.load == b'dieselgate'
assert bytes(wdbi) == b'\x2e\x01\x02dieselgate'

= Check UDS_WDBI

wdbi = UDS(b'\x2e\x01\x02dieselgate')
assert wdbi.service == 0x2e
assert wdbi.dataIdentifier == 0x0102
assert wdbi.load == b'dieselgate'

wdbi = UDS(b'\x2e\x02\x02benzingate')
assert wdbi.service == 0x2e
assert wdbi.dataIdentifier == 0x0202
assert wdbi.load == b'benzingate'


= Check UDS_WDBIPR

wdbipr = UDS(b'\x6e\x02\x02')
assert wdbipr.service == 0x6e
assert wdbipr.dataIdentifier == 0x0202

assert wdbipr.answers(wdbi)

= Check UDS_WMBA

wmba = UDS(b'\x3d\x11\x02\x02muchData')
assert wmba.service == 0x3d
assert wmba.memorySizeLen == 1
assert wmba.memoryAddressLen == 1
assert wmba.memoryAddress1 == 2
assert wmba.memorySize1 == 2
assert wmba.dataRecord == b'muchData'

= Check UDS_WMBAPR

wmbapr = UDS(b'\x7d\x11\x02\x02')
assert wmbapr.service == 0x7d
assert wmbapr.memorySizeLen == 1
assert wmbapr.memoryAddressLen == 1
assert wmbapr.memoryAddress1 == 2
assert wmbapr.memorySize1 == 2

assert wmbapr.answers(wmba)

= Check UDS_WMBA

wmba = UDS(b'\x3d\x22\x02\x02\x03\x03muchData')
assert wmba.service == 0x3d
assert wmba.memorySizeLen == 2
assert wmba.memoryAddressLen == 2
assert wmba.memoryAddress2 == 0x202
assert wmba.memorySize2 == 0x303
assert wmba.dataRecord == b'muchData'

= Check UDS_WMBAPR

wmbapr = UDS(b'\x7d\x22\x02\x02\x03\x03')
assert wmbapr.service == 0x7d
assert wmbapr.memorySizeLen == 2
assert wmbapr.memoryAddressLen == 2
assert wmbapr.memoryAddress2 == 0x202
assert wmbapr.memorySize2 == 0x303

assert wmbapr.answers(wmba)

= Check UDS_WMBA

wmba = UDS(b'\x3d\x33\x02\x02\x02\x03\x03\x03muchData')
assert wmba.service == 0x3d
assert wmba.memorySizeLen == 3
assert wmba.memoryAddressLen == 3
assert wmba.memoryAddress3 == 0x20202
assert wmba.memorySize3 == 0x30303
assert wmba.dataRecord == b'muchData'

= Check UDS_WMBA

wmba = UDS(b'\x3d\x44\x02\x02\x02\x02\x03\x03\x03\x03muchData')
assert wmba.service == 0x3d
assert wmba.memorySizeLen == 4
assert wmba.memoryAddressLen == 4
assert wmba.memoryAddress4 == 0x2020202
assert wmba.memorySize4 == 0x3030303
assert wmba.dataRecord == b'muchData'

= Check UDS_WMBAPR

wmbapr = UDS(b'\x7d\x33\x02\x02\x02\x03\x03\x03')
assert wmbapr.service == 0x7d
assert wmbapr.memorySizeLen == 3
assert wmbapr.memoryAddressLen == 3
assert wmbapr.memoryAddress3 == 0x20202
assert wmbapr.memorySize3 == 0x30303

assert not wmbapr.answers(wmba)

= Check UDS_WMBAPR

wmbapr = UDS(b'\x7d\x44\x02\x02\x02\x02\x03\x03\x03\x03')
assert wmbapr.service == 0x7d
assert wmbapr.memorySizeLen == 4
assert wmbapr.memoryAddressLen == 4
assert wmbapr.memoryAddress4 == 0x2020202
assert wmbapr.memorySize4 == 0x3030303

assert wmbapr.answers(wmba)

= Check UDS_CDTCI

cdtci = UDS(b'\x14\x44\x02\x03')
assert cdtci.service == 0x14
assert cdtci.groupOfDTCHighByte == 0x44
assert cdtci.groupOfDTCMiddleByte == 0x02
assert cdtci.groupOfDTCLowByte == 0x3

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x44')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x44

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x01\xff')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x01
assert rdtci.DTCStatusMask == 0xff

= Check UDS_RDTCIPR

rdtcipr = UDS(b'\x59\x01\xff\xee\xdd\xaa')
assert rdtcipr.service == 0x59
assert rdtcipr.reportType == 1
assert rdtcipr.DTCStatusAvailabilityMask == 0xff
assert rdtcipr.DTCFormatIdentifier == 0xee
assert rdtcipr.DTCCount == 0xddaa

assert rdtcipr.answers(rdtci)

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x02\xff')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x02
assert rdtci.DTCStatusMask == 0xff

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x0f\xff')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x0f
assert rdtci.DTCStatusMask == 0xff

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x11\xff')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x11
assert rdtci.DTCStatusMask == 0xff

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x12\xff')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x12
assert rdtci.DTCStatusMask == 0xff

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x13\xff')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x13
assert rdtci.DTCStatusMask == 0xff

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x03\xff\xee\xdd\xaa')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x03
assert rdtci.DTCHighByte == 0xff
assert rdtci.DTCMiddleByte == 0xee
assert rdtci.DTCLowByte == 0xdd
assert rdtci.DTCSnapshotRecordNumber == 0xaa

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x04\xff\xee\xdd\xaa')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x04
assert rdtci.DTCHighByte == 0xff
assert rdtci.DTCMiddleByte == 0xee
assert rdtci.DTCLowByte == 0xdd
assert rdtci.DTCSnapshotRecordNumber == 0xaa

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x05\xaa')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x05
assert rdtci.DTCSnapshotRecordNumber == 0xaa

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x06\xff\xee\xdd\xaa')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x06
assert rdtci.DTCHighByte == 0xff
assert rdtci.DTCMiddleByte == 0xee
assert rdtci.DTCLowByte == 0xdd
assert rdtci.DTCExtendedDataRecordNumber == 0xaa

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x07\xaa\xbb')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x07
assert rdtci.DTCSeverityMask == 0xaa
assert rdtci.DTCStatusMask == 0xbb

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x08\xaa\xbb')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x08
assert rdtci.DTCSeverityMask == 0xaa
assert rdtci.DTCStatusMask == 0xbb

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x09\xff\xee\xdd')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x09
assert rdtci.DTCHighByte == 0xff
assert rdtci.DTCMiddleByte == 0xee
assert rdtci.DTCLowByte == 0xdd

= Check UDS_RDTCI

rdtci = UDS(b'\x19\x10\xff\xee\xdd\xaa')
assert rdtci.service == 0x19
assert rdtci.reportType == 0x10
assert rdtci.DTCHighByte == 0xff
assert rdtci.DTCMiddleByte == 0xee
assert rdtci.DTCLowByte == 0xdd
assert rdtci.DTCExtendedDataRecordNumber == 0xaa


= Check UDS_RDTCIPR

rdtcipr = UDS(b'\x59\x02\xff\xee\xdd\xaa')
assert rdtcipr.service == 0x59
assert rdtcipr.reportType == 2
assert rdtcipr.DTCStatusAvailabilityMask == 0xff
assert rdtcipr.DTCAndStatusRecord == b'\xee\xdd\xaa'

assert not rdtcipr.answers(rdtci)

= Check UDS_RDTCIPR

rdtcipr = UDS(b'\x59\x03\xff\xee\xdd\xaa')
assert rdtcipr.service == 0x59
assert rdtcipr.reportType == 3
assert rdtcipr.dataRecord == b'\xff\xee\xdd\xaa'

= Check UDS_RC

rc = UDS(b'\x31\x03\xff\xee\xdd\xaa')
assert rc.service == 0x31
assert rc.routineControlType == 3
assert rc.routineIdentifier == 0xffee
assert rc.load == b'\xdd\xaa'

= Check UDS_RC

rc = UDS(b'\x31\x03\xff\xee\xdd\xaa')
assert rc.service == 0x31
assert rc.routineControlType == 3
assert rc.routineIdentifier == 0xffee
assert rc.load == b'\xdd\xaa'


= Check UDS_RCPR

rcpr = UDS(b'\x71\x03\xff\xee\xdd\xaa')
assert rcpr.service == 0x71
assert rcpr.routineControlType == 3
assert rcpr.routineIdentifier == 0xffee
assert rcpr.load == b'\xdd\xaa'

= Check UDS_RD

rd = UDS(b'\x34\xaa\x11\x02\x02')
assert rd.service == 0x34
assert rd.dataFormatIdentifier == 0xaa
assert rd.memorySizeLen == 1
assert rd.memoryAddressLen == 1
assert rd.memoryAddress1 == 2
assert rd.memorySize1 == 2


= Check UDS_RD

rd = UDS(b'\x34\xaa\x22\x02\x02\x03\x03')
assert rd.service == 0x34
assert rd.dataFormatIdentifier == 0xaa
assert rd.memorySizeLen == 2
assert rd.memoryAddressLen == 2
assert rd.memoryAddress2 == 0x202
assert rd.memorySize2 == 0x303

= Check UDS_RD

rd = UDS(b'\x34\xaa\x33\x02\x02\x02\x03\x03\x03')
assert rd.service == 0x34
assert rd.dataFormatIdentifier == 0xaa
assert rd.memorySizeLen == 3
assert rd.memoryAddressLen == 3
assert rd.memoryAddress3 == 0x20202
assert rd.memorySize3 == 0x30303

= Check UDS_RD

rd = UDS(b'\x34\xaa\x44\x02\x02\x02\x02\x03\x03\x03\x03')
assert rd.service == 0x34
assert rd.dataFormatIdentifier == 0xaa
assert rd.memorySizeLen == 4
assert rd.memoryAddressLen == 4
assert rd.memoryAddress4 == 0x2020202
assert rd.memorySize4 == 0x3030303


= Check UDS_RDPR

rdpr = UDS(b'\x74\x40\x02\x02\x02\x02\x03\x03\x03\x03')
assert rdpr.service == 0x74
assert rdpr.memorySizeLen == 4
assert rdpr.reserved == 0
assert rdpr.maxNumberOfBlockLength == b'\x02\x02\x02\x02\x03\x03\x03\x03'

assert rdpr.answers(rd)

= Check UDS_RU

ru = UDS(b'\x35\xaa\x11\x02\x02')
assert ru.service == 0x35
assert ru.dataFormatIdentifier == 0xaa
assert ru.memorySizeLen == 1
assert ru.memoryAddressLen == 1
assert ru.memoryAddress1 == 2
assert ru.memorySize1 == 2

= Check UDS_RU

ru = UDS(b'\x35\xaa\x22\x02\x02\x03\x03')
assert ru.service == 0x35
assert ru.dataFormatIdentifier == 0xaa
assert ru.memorySizeLen == 2
assert ru.memoryAddressLen == 2
assert ru.memoryAddress2 == 0x202
assert ru.memorySize2 == 0x303


= Check UDS_RU

ru = UDS(b'\x35\xaa\x33\x02\x02\x02\x03\x03\x03')
assert ru.service == 0x35
assert ru.dataFormatIdentifier == 0xaa
assert ru.memorySizeLen == 3
assert ru.memoryAddressLen == 3
assert ru.memoryAddress3 == 0x20202
assert ru.memorySize3 == 0x30303


= Check UDS_RU

ru = UDS(b'\x35\xaa\x44\x02\x02\x02\x02\x03\x03\x03\x03')
assert ru.service == 0x35
assert ru.dataFormatIdentifier == 0xaa
assert ru.memorySizeLen == 4
assert ru.memoryAddressLen == 4
assert ru.memoryAddress4 == 0x2020202
assert ru.memorySize4 == 0x3030303


= Check UDS_RUPR

rupr = UDS(b'\x75\x40\x02\x02\x02\x02\x03\x03\x03\x03')
assert rupr.service == 0x75
assert rupr.memorySizeLen == 4
assert rupr.reserved == 0
assert rupr.maxNumberOfBlockLength == b'\x02\x02\x02\x02\x03\x03\x03\x03'

assert rupr.answers(ru)

= Check UDS_TD

td = UDS(b'\x36\xaapayload')
assert td.service == 0x36
assert td.blockSequenceCounter == 0xaa
assert td.transferRequestParameterRecord == b'payload'

= Check UDS_TD

td = UDS(b'\x36\xaapayload')
assert td.service == 0x36
assert td.blockSequenceCounter == 0xaa
assert td.transferRequestParameterRecord == b'payload'

= Check UDS_TDPR

tdpr = UDS(b'\x76\xaapayload')
assert tdpr.service == 0x76
assert tdpr.blockSequenceCounter == 0xaa
assert tdpr.transferResponseParameterRecord == b'payload'

assert tdpr.answers(td)

= Check UDS_RTE

rte = UDS(b'\x37payload')
assert rte.service == 0x37
assert rte.transferRequestParameterRecord == b'payload'

= Check UDS_RTEPR

rtepr = UDS(b'\x77payload')
assert rtepr.service == 0x77
assert rtepr.transferResponseParameterRecord == b'payload'

assert rtepr.answers(rte)

= Check UDS_IOCBI

iocbi = UDS(b'\x2f\x23\x34\xffcoffee')
assert iocbi.service == 0x2f
assert iocbi.dataIdentifier == 0x2334
assert iocbi.controlOptionRecord == 255
assert iocbi.controlEnableMaskRecord == b'coffee'

= Check UDS_RFT

rft = UDS(b'\x38\x01\x00\x1ED:\\mapdata\\europe\\germany1.yxz\x11\x02\xC3\x50\x75\x30')
assert rft.service == 0x38
assert rft.modeOfOperation == 0x01
assert rft.filePathAndNameLength == 0x001e
assert rft.filePathAndName == b'D:\\mapdata\\europe\\germany1.yxz'
assert rft.compressionMethod == 1
assert rft.encryptingMethod == 1
assert rft.fileSizeParameterLength == 0x02
assert rft.fileSizeUnCompressed == b'\xc3\x50'
assert rft.fileSizeCompressed == b'\x75\x30'

= Check UDS_RFTPR

rftpr = UDS(b'\x78\x01\x02\xc3\x50\x11')
assert rftpr.service == 0x78
assert rftpr.modeOfOperation == 0x01
assert rftpr.lengthFormatIdentifier == 0x02
assert rftpr.maxNumberOfBlockLength == b'\xc3\x50'
assert rftpr.compressionMethod == 1
assert rftpr.encryptingMethod == 1

assert rftpr.answers(rft)

= Check UDS_NRC

nrc = UDS(b'\x7f\x22\x33')
assert nrc.service == 0x7f
assert nrc.requestServiceId == 0x22
assert nrc.negativeResponseCode == 0x33
