86890704fd
todo: add documentation & wireshark dissector
998 lines
No EOL
28 KiB
Text
Executable file
998 lines
No EOL
28 KiB
Text
Executable file
% Regression tests for the CCP layer
|
|
|
|
# More information at http://www.secdev.org/projects/UTscapy/
|
|
|
|
|
|
############
|
|
############
|
|
|
|
+ Basic operations
|
|
|
|
= Load module
|
|
|
|
load_contrib("automotive.ccp")
|
|
|
|
= Build CRO CONNECT
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=1)/CONNECT(station_address=0x02)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 1
|
|
assert cro.cmd == 1
|
|
assert cro.station_address == 0x02
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x01\x01\x02\x00\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO CONNECT
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x01\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.answers(cro)
|
|
assert dto.identifier == 0x700
|
|
assert dto.length == 8
|
|
assert dto.flags == 0
|
|
assert dto.ctr == 1
|
|
assert dto.load == b"\xff" * 5
|
|
|
|
= Build CRO EXCHANGE_ID
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=18)/EXCHANGE_ID(ccp_master_device_id=b'abcdef')
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 18
|
|
assert cro.cmd == 0x17
|
|
assert cro.ccp_master_device_id == b"abcdef"
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x17\x12abcdef'
|
|
|
|
= Dissect DTO EXCHANGE_ID
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x12\x04\x02\x03\x03\xff')
|
|
|
|
assert dto.ctr == 18
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x04\x02\x03\x03\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 18
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.slave_device_ID_length == 4
|
|
assert dto.data_type_qualifier == 2
|
|
assert dto.resource_availability_mask == 3
|
|
assert dto.resource_protection_mask == 3
|
|
assert dto.ccp_reserved == b"\xff"
|
|
|
|
= Build CRO GET_SEED
|
|
|
|
cro = CCP(identifier=0x711)/CRO(ctr=19)/GET_SEED(resource=2)
|
|
|
|
assert cro.identifier == 0x711
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 19
|
|
assert cro.cmd == 0x12
|
|
assert cro.resource == 2
|
|
assert cro.ccp_reserved == b"\xff" * 5
|
|
|
|
assert bytes(cro) == b'\x00\x00\x07\x11\x08\x00\x00\x00\x12\x13\x02\xff\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO GET_SEED
|
|
|
|
dto = CCP(b'\x00\x00\x07\x11\x08\x00\x00\x00\xff\x00\x13\x01\x14\x15\x16\x17')
|
|
|
|
assert dto.ctr == 19
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x01\x14\x15\x16\x17'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 19
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.protection_status == 0x1
|
|
assert dto.seed == b'\x14\x15\x16\x17'
|
|
|
|
= Build CRO UNLOCK
|
|
|
|
cro = CCP(identifier=0x711)/CRO(ctr=20)/UNLOCK(key=b"123456")
|
|
|
|
assert cro.identifier == 0x711
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 20
|
|
assert cro.cmd == 0x13
|
|
assert cro.key == b"123456"
|
|
|
|
assert bytes(cro) == b'\x00\x00\x07\x11\x08\x00\x00\x00\x13\x14123456'
|
|
|
|
= Dissect DTO UNLOCK
|
|
|
|
dto = CCP(b'\x00\x00\x07\x11\x08\x00\x00\x00\xff\x00\x14\x02\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 20
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x02\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 20
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.privilege_status == 0x2
|
|
assert dto.ccp_reserved == b"\xff" * 4
|
|
|
|
= Build CRO SET_MTA
|
|
|
|
cro = CCP(identifier=0x711)/CRO(ctr=21)/SET_MTA(mta_num=0, address_extension=0x02, address=0x34002000)
|
|
|
|
assert cro.identifier == 0x711
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 21
|
|
assert cro.cmd == 0x02
|
|
assert cro.mta_num == 0
|
|
assert cro.address_extension == 2
|
|
assert cro.address == 0x34002000
|
|
|
|
assert bytes(cro) == b'\x00\x00\x07\x11\x08\x00\x00\x00\x02\x15\x00\x02\x34\x00\x20\x00'
|
|
|
|
= Dissect DTO SET_MTA
|
|
|
|
dto = CCP(b'\x00\x00\x07\x11\x08\x00\x00\x00\xff\x00\x15\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 21
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 21
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b"\xff" * 5
|
|
|
|
= Build CRO DNLOAD
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=17)/DNLOAD(size=0x05, data=b'abcde')
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 17
|
|
assert cro.cmd == 3
|
|
assert cro.size == 0x05
|
|
assert cro.data == b'abcde'
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x03\x11\x05abcde'
|
|
|
|
= Dissect DTO DNLOAD
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x11\x02\x34\x00\x20\x05')
|
|
|
|
assert dto.ctr == 17
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x024\x00 \x05'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 17
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.MTA0_extension == 2
|
|
assert dto.MTA0_address == 0x34002005
|
|
|
|
= Build CRO DNLOAD_6
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x40)/DNLOAD_6(data=b'abcdef')
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x40
|
|
assert cro.cmd == 0x23
|
|
assert cro.data == b'abcdef'
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x23\x40abcdef'
|
|
|
|
= Dissect DTO DNLOAD_6
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x40\x02\x34\x00\x20\x06')
|
|
|
|
assert dto.ctr == 64
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x024\x00 \x06'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 64
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.MTA0_extension == 2
|
|
assert dto.MTA0_address == 0x34002006
|
|
|
|
= Build CRO UPLOAD
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x41)/UPLOAD(size=4)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x41
|
|
assert cro.cmd == 0x04
|
|
assert cro.size == 4
|
|
assert cro.ccp_reserved == b"\xff" * 5
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x04\x41\x04\xff\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO UPLOAD
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x41\x10\x11\x12\x13\xff')
|
|
|
|
assert dto.ctr == 65
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x10\x11\x12\x13\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 65
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.data == b"\x10\x11\x12\x13\xff"
|
|
|
|
= Build CRO SHORT_UP
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x42)/SHORT_UP(size=4, address_extension=0, address=0x12345678)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x42
|
|
assert cro.cmd == 0x0f
|
|
assert cro.size == 4
|
|
assert cro.address == 0x12345678
|
|
assert cro.address_extension == 0
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0f\x42\x04\x00\x12\x34\x56\x78'
|
|
|
|
= Dissect DTO SHORT_UP
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x42\x10\x11\x12\x13\xff')
|
|
|
|
assert dto.ctr == 66
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x10\x11\x12\x13\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 66
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.data == b"\x10\x11\x12\x13\xff"
|
|
|
|
= Build CRO SELECT_CAL_PAGE
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x43)/SELECT_CAL_PAGE()
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x43
|
|
assert cro.cmd == 0x11
|
|
assert cro.ccp_reserved == b"\xff" * 6
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x11\x43\xff\xff\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO SELECT_CAL_PAGE
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x43\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 67
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 67
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b"\xff\xff\xff\xff\xff"
|
|
|
|
= Build CRO GET_DAQ_SIZE
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x44)/GET_DAQ_SIZE(DAQ_num=0x03, DTO_identifier=0x1020304)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x44
|
|
assert cro.cmd == 0x14
|
|
assert cro.DAQ_num == 0x03
|
|
assert cro.ccp_reserved == 00
|
|
assert cro.DTO_identifier == 0x01020304
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x14\x44\x03\x00\x01\x02\x03\x04'
|
|
|
|
= Dissect DTO GET_DAQ_SIZE
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x44\x10\x08\xff\xff\xff')
|
|
|
|
assert dto.ctr == 68
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x10\x08\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 68
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.DAQ_list_size == 16
|
|
assert dto.first_pid == 8
|
|
assert dto.ccp_reserved == b"\xff\xff\xff"
|
|
|
|
= Build CRO SET_DAQ_PTR
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x45)/SET_DAQ_PTR(DAQ_num=3, ODT_num=5, ODT_element=2)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x45
|
|
assert cro.cmd == 0x15
|
|
assert cro.DAQ_num == 0x03
|
|
assert cro.ODT_num == 5
|
|
assert cro.ODT_element == 2
|
|
assert cro.ccp_reserved == b"\xff\xff\xff"
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x15\x45\x03\x05\x02\xff\xff\xff'
|
|
|
|
= Dissect DTO SET_DAQ_PTR
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x45\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 69
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 69
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO WRITE_DAQ
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x46)/WRITE_DAQ(DAQ_size=2, address_extension=1, address=0x2004200)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x46
|
|
assert cro.cmd == 0x16
|
|
assert cro.DAQ_size == 0x02
|
|
assert cro.address_extension == 1
|
|
assert cro.address == 0x2004200
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x16\x46\x02\x01\x02\x00\x42\x00'
|
|
|
|
= Dissect DTO WRITE_DAQ
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x46\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 70
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 70
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO START_STOP
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x47)/START_STOP(mode=1, DAQ_num=3, ODT_num=7, event_channel=2, transmission_rate=1)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x47
|
|
assert cro.cmd == 0x06
|
|
assert cro.mode == 0x01
|
|
assert cro.DAQ_num == 3
|
|
assert cro.event_channel == 2
|
|
assert cro.transmission_rate == 1
|
|
assert cro.ODT_num == 7
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x06\x47\x01\x03\x07\x02\x00\x01'
|
|
|
|
= Dissect DTO START_STOP
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x47\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 71
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 71
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO DISCONNECT
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x48)/DISCONNECT(type="temporary", station_address=0x208)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x48
|
|
assert cro.cmd == 0x07
|
|
assert cro.type == 0x00
|
|
assert cro.station_address == 0x208
|
|
assert cro.ccp_reserved0 == b"\xff"
|
|
assert cro.ccp_reserved == b"\xff" * 2
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x07\x48\x00\xff\x08\x02\xff\xff'
|
|
|
|
= Dissect DTO DISCONNECT
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x48\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 72
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 72
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO SET_S_STATUS
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x49)/SET_S_STATUS(session_status="RUN+CAL")
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x49
|
|
assert cro.cmd == 0x0c
|
|
assert cro.session_status == 0x81
|
|
assert cro.ccp_reserved == b"\xff" * 5
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0c\x49\x81\xff\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO SET_S_STATUS
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x49\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 73
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 73
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO GET_S_STATUS
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x4a)/GET_S_STATUS()
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x4a
|
|
assert cro.cmd == 0x0D
|
|
assert cro.ccp_reserved == b"\xff" * 6
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0d\x4a\xff\xff\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO GET_S_STATUS
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x4a\x81\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 74
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x81\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 74
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.session_status == 0x81
|
|
assert dto.information_qualifier == 0xff
|
|
assert dto.information == b"\xff" * 3
|
|
|
|
= Build CRO BUILD_CHKSUM
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x50)/BUILD_CHKSUM(size=0x8000)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x50
|
|
assert cro.cmd == 0x0e
|
|
assert cro.size == 0x8000
|
|
assert cro.ccp_reserved == b"\xff" * 2
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x0e\x50\x00\x00\x80\x00\xff\xff'
|
|
|
|
= Dissect DTO BUILD_CHKSUM
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x50\x02\x12\x34\xff\xff')
|
|
|
|
assert dto.ctr == 80
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x02\x12\x34\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 80
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.checksum_size == 2
|
|
assert dto.checksum_data == b'\x12\x34'
|
|
assert dto.ccp_reserved == b'\xff\xff'
|
|
|
|
= Dissect DTO BUILD_CHKSUM2
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x50\x04\x12\x34\x56\x78')
|
|
|
|
assert dto.ctr == 80
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x04\x12\x34\x56\x78'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 80
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.checksum_size == 4
|
|
assert dto.checksum_data == b'\x12\x34\x56\x78'
|
|
assert dto.ccp_reserved == b''
|
|
|
|
= Build CRO CLEAR_MEMORY
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x51)/CLEAR_MEMORY(size=0x8000)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x51
|
|
assert cro.cmd == 0x10
|
|
assert cro.size == 0x8000
|
|
assert cro.ccp_reserved == b"\xff" * 2
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x10\x51\x00\x00\x80\x00\xff\xff'
|
|
|
|
= Dissect DTO CLEAR_MEMORY
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x51\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 81
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 81
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO PROGRAM
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x52)/PROGRAM(size=0x3, data=b"\x10\x11\x12")
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x52
|
|
assert cro.cmd == 0x18
|
|
assert cro.size == 0x3
|
|
assert cro.data == b"\x10\x11\x12"
|
|
assert cro.ccp_reserved == b"\xff" * 5
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x18\x52\x03\x10\x11\x12\xff\xff'
|
|
|
|
= Dissect DTO PROGRAM
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x52\x02\x34\x00\x20\x03')
|
|
|
|
assert dto.ctr == 82
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x02\x34\x00\x20\x03'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 82
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.MTA0_extension == 2
|
|
assert dto.MTA0_address == 0x34002003
|
|
|
|
= Build CRO PROGRAM_6
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x53)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12")
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x53
|
|
assert cro.cmd == 0x22
|
|
assert cro.data == b"\x10\x11\x12\x10\x11\x12"
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x22\x53\x10\x11\x12\x10\x11\x12'
|
|
|
|
= Dissect DTO PROGRAM_6
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x53\x02\x34\x00\x20\x06')
|
|
|
|
assert dto.ctr == 83
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x02\x34\x00\x20\x06'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 83
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.MTA0_extension == 2
|
|
assert dto.MTA0_address == 0x34002006
|
|
|
|
= Build CRO MOVE
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x54)/MOVE(size=0x8000)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x54
|
|
assert cro.cmd == 0x19
|
|
assert cro.size == 0x8000
|
|
assert cro.ccp_reserved == b'\xff\xff'
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x19\x54\x00\x00\x80\x00\xff\xff'
|
|
|
|
= Dissect DTO MOVE
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x54\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 84
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 84
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
|
|
= Build CRO DIAG_SERVICE
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x55)/DIAG_SERVICE(diag_service=0x8000)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x55
|
|
assert cro.cmd == 0x20
|
|
assert cro.diag_service == 0x8000
|
|
assert cro.ccp_reserved == b'\xff\xff\xff\xff'
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x20\x55\x80\x00\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO DIAG_SERVICE
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x55\x20\x00\xff\xff\xff')
|
|
|
|
assert dto.ctr == 85
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x20\x00\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 85
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.data_length == 0x20
|
|
assert dto.data_type == 0x00
|
|
assert dto.ccp_reserved == b"\xff\xff\xff"
|
|
|
|
= Build CRO ACTION_SERVICE
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x56)/ACTION_SERVICE(action_service=0x8000)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x56
|
|
assert cro.cmd == 0x21
|
|
assert cro.action_service == 0x8000
|
|
assert cro.ccp_reserved == b'\xff\xff\xff\xff'
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x21\x56\x80\x00\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO ACTION_SERVICE
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x56\x20\x00\xff\xff\xff')
|
|
|
|
assert dto.ctr == 86
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x20\x00\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 86
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.data_length == 0x20
|
|
assert dto.data_type == 0x00
|
|
assert dto.ccp_reserved == b"\xff\xff\xff"
|
|
|
|
= Build CRO TEST
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x60)/TEST(station_address=0x80)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x60
|
|
assert cro.cmd == 0x05
|
|
assert cro.station_address == 0x80
|
|
assert cro.ccp_reserved == b"\xff" * 4
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x05\x60\x80\x00\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO TEST
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x60\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 96
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 96
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO START_STOP_ALL
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x61)/START_STOP_ALL(type="start")
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x61
|
|
assert cro.cmd == 0x08
|
|
assert cro.type == 0x01
|
|
assert cro.ccp_reserved == b"\xff" * 5
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x08\x61\x01\xff\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO START_STOP_ALL
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x61\xff\xff\xff\xff\xff')
|
|
|
|
assert dto.ctr == 97
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 97
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == True
|
|
assert dto.load == b'\xff\xff\xff\xff\xff'
|
|
|
|
= Build CRO GET_ACTIVE_CAL_PAGE
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x62)/GET_ACTIVE_CAL_PAGE()
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x62
|
|
assert cro.cmd == 0x09
|
|
assert cro.ccp_reserved == b"\xff" * 6
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x09\x62\xff\xff\xff\xff\xff\xff'
|
|
|
|
= Dissect DTO GET_ACTIVE_CAL_PAGE
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x62\x01\x11\x44\x77\x22')
|
|
|
|
assert dto.ctr == 98
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x01\x11\x44\x77\x22'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 98
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.address_extension == 1
|
|
assert dto.address == 0x11447722
|
|
|
|
= Build CRO GET_CCP_VERSION
|
|
|
|
cro = CCP(identifier=0x700)/CRO(ctr=0x63)/GET_CCP_VERSION(main_protocol_version=2, release_version=1)
|
|
|
|
assert cro.identifier == 0x700
|
|
assert cro.length == 8
|
|
assert cro.flags == 0
|
|
assert cro.ctr == 0x63
|
|
assert cro.cmd == 0x1b
|
|
assert cro.main_protocol_version == 2
|
|
assert cro.release_version == 1
|
|
assert cro.ccp_reserved == b"\xff" * 4
|
|
assert bytes(cro) == b'\x00\x00\x07\x00\x08\x00\x00\x00\x1b\x63\x02\x01\xff\xff\xff\xff'
|
|
|
|
assert dto.hashret() != cro.hashret()
|
|
assert not dto.answers(cro)
|
|
|
|
= Dissect DTO GET_CCP_VERSION
|
|
|
|
dto = CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x63\x02\x01\xff\xff\xff')
|
|
|
|
assert dto.ctr == 99
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert dto.load == b'\x02\x01\xff\xff\xff'
|
|
# answers will interpret payload
|
|
assert dto.answers(cro)
|
|
assert dto.ctr == 99
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.main_protocol_version == 2
|
|
assert dto.release_version == 1
|
|
assert dto.ccp_reserved == b"\xff" * 3
|
|
|
|
assert dto.hashret() == cro.hashret()
|
|
|
|
+ Tests on a virtual CAN-Bus
|
|
~ needs_root linux
|
|
|
|
= Load modules
|
|
~ needs_root linux conf
|
|
import can
|
|
from subprocess import call
|
|
import time
|
|
|
|
conf.contribs['CANSocket'] = {'use-python-can': True}
|
|
load_contrib("cansocket")
|
|
|
|
iface0 = "vcan0"
|
|
|
|
= Initialize a virtual CAN interface
|
|
~ needs_root linux conf
|
|
if 0 != call("cansend %s 000#" % iface0, shell=True):
|
|
# vcan0 is not enabled
|
|
if 0 != call("sudo modprobe vcan", shell=True):
|
|
raise Exception("modprobe vcan failed")
|
|
if 0 != call("sudo ip link add name %s type vcan" % iface0, shell=True):
|
|
print("add %s failed: Maybe it was already up?" % iface0)
|
|
if 0 != call("sudo ip link set dev %s up" % iface0, shell=True):
|
|
raise Exception("could not bring up %s" % iface0)
|
|
|
|
if 0 != call("cansend %s 000#" % iface0, shell=True):
|
|
raise Exception("cansend doesn't work")
|
|
|
|
print("CAN should work now")
|
|
|
|
= CAN Socket sr1 with dto.ansers(cro) == True
|
|
~ needs_root linux
|
|
|
|
sock1 = CANSocket(iface=can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000), basecls=CCP)
|
|
sock2 = CANSocket(iface=can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000))
|
|
|
|
def ecu():
|
|
pkts = sock2.sniff(count=1, timeout=1)
|
|
if len(pkts) == 1:
|
|
cro = CRO(pkts[0].data)
|
|
assert cro.cmd == 0x22
|
|
assert cro.data == b"\x10\x11\x12\x10\x11\x12"
|
|
sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x53\x02\x34\x00\x20\x06'))
|
|
|
|
|
|
thread = threading.Thread(target=ecu)
|
|
thread.start()
|
|
time.sleep(0.1)
|
|
|
|
dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x53)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=1)
|
|
thread.join()
|
|
|
|
assert dto.ctr == 83
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 0
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.MTA0_extension == 2
|
|
assert dto.MTA0_address == 0x34002006
|
|
|
|
sock1.close()
|
|
sock2.close()
|
|
|
|
|
|
= CAN Socket sr1 with dto.ansers(cro) == False
|
|
~ needs_root linux
|
|
|
|
sock1 = CANSocket(iface=can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000), basecls=CCP)
|
|
sock2 = CANSocket(iface=can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000))
|
|
|
|
def ecu():
|
|
pkts = sock2.sniff(count=1, timeout=1)
|
|
if len(pkts) == 1:
|
|
cro = CRO(pkts[0].data)
|
|
assert cro.cmd == 0x22
|
|
assert cro.data == b"\x10\x11\x12\x10\x11\x12"
|
|
sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x00\x55\x02\x34\x00\x20\x06'))
|
|
|
|
|
|
thread = threading.Thread(target=ecu)
|
|
thread.start()
|
|
time.sleep(0.1)
|
|
gotTimeout = False
|
|
try:
|
|
dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x54)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=1)
|
|
except CANSocketTimeoutElapsed as e:
|
|
gotTimeout = True
|
|
|
|
assert gotTimeout
|
|
thread.join()
|
|
|
|
sock1.close()
|
|
sock2.close()
|
|
|
|
= CAN Socket sr1 with error code
|
|
~ needs_root linux
|
|
|
|
sock1 = CANSocket(iface=can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000), basecls=CCP)
|
|
sock2 = CANSocket(iface=can.interface.Bus(bustype='socketcan', channel='vcan0', bitrate=250000))
|
|
|
|
def ecu():
|
|
pkts = sock2.sniff(count=1, timeout=1)
|
|
if len(pkts) == 1:
|
|
cro = CRO(pkts[0].data)
|
|
assert cro.cmd == 0x22
|
|
assert cro.data == b"\x10\x11\x12\x10\x11\x12"
|
|
sock2.send(CCP(b'\x00\x00\x07\x00\x08\x00\x00\x00\xff\x01\x55\xff\xff\xff\xff\xff'))
|
|
|
|
|
|
thread = threading.Thread(target=ecu)
|
|
thread.start()
|
|
time.sleep(0.1)
|
|
|
|
dto = sock1.sr1(CCP(identifier=0x700)/CRO(ctr=0x55)/PROGRAM_6(data=b"\x10\x11\x12\x10\x11\x12"), timeout=1)
|
|
thread.join()
|
|
|
|
assert dto.ctr == 85
|
|
assert dto.packet_id == 0xff
|
|
assert dto.return_code == 1
|
|
assert hasattr(dto, "load") == False
|
|
assert dto.MTA0_extension == 0xff
|
|
assert dto.MTA0_address == 0xffffffff
|
|
|
|
sock1.close()
|
|
sock2.close() |