class scapy.contrib.automotive.ecu.ECU(init_session=None, init_security_level=None, init_communication_control=None, logging=True, verbose=True, store_supported_responses=True)

Bases: object

A ECU object can be used to
  • track the states of an ECU.

  • to log all modification to an ECU

  • to extract supported responses of a real ECU

Usage: >>> print(“This ecu logs, tracks and creates supported responses”) >>> my_virtual_ecu = ECU() >>> my_virtual_ecu.update(PacketList([…])) >>> my_virtual_ecu.supported_responses >>> print(“Another ecu just tracks”) >>> my_tracking_ecu = ECU(logging=False, store_supported_responses=False) # noqa: E501 >>> my_tracking_ecu.update(PacketList([…])) >>> print(“Another ecu just logs all modifications to it”) >>> my_logging_ecu = ECU(verbose=False, store_supported_responses=False) # noqa: E501 >>> my_logging_ecu.update(PacketList([…])) >>> my_logging_ecu.log >>> print(“Another ecu just creates supported responses”) >>> my_response_ecu = ECU(verbose=False, logging=False) >>> my_response_ecu.update(PacketList([…])) >>> my_response_ecu.supported_responses

property communication_control
property current_security_level
property current_session
property supported_responses
property unanswered_packets
class scapy.contrib.automotive.ecu.ECUResponse(session=1, security_level=0, responses=<Raw load='\x7f\x10' |>, answers=None)

Bases: object

Encapsulates a response and the according ECU state. A list of this objects can be used to configure a ECU Answering Machine. This is useful, if you want to clone the behaviour of a real ECU on a bus.

Usage: >>> print(“Generates a ECUResponse which answers on UDS()/UDS_RDBI(identifiers=[2]) if ECU is in session 2 and has security_level 2”) # noqa: E501 >>> ECUResponse(session=2, security_level=2, responses=UDS()/UDS_RDBIPR(dataIdentifier=2)/Raw(b”deadbeef1”)) # noqa: E501 >>> print(“Further examples”) >>> ECUResponse(session=range(3,5), security_level=[3,4], responses=UDS()/UDS_RDBIPR(dataIdentifier=3)/Raw(b”deadbeef2”)) # noqa: E501 >>> ECUResponse(session=[5,6,7], security_level=range(5,7), responses=UDS()/UDS_RDBIPR(dataIdentifier=5)/Raw(b”deadbeef3”)) # noqa: E501 >>> ECUResponse(session=lambda x: 8 < x <= 10, security_level=lambda x: x > 10, responses=UDS()/UDS_RDBIPR(dataIdentifier=9)/Raw(b”deadbeef4”)) # noqa: E501

class scapy.contrib.automotive.ecu.ECUSession(*args, **kwargs)

Bases: scapy.sessions.DefaultSession

Tracks modification to an ECU ‘on-the-flow’.

Usage: >>> sniff(session=ECUSession)

class scapy.contrib.automotive.ecu.ECU_State(session=1, tester_present=False, security_level=0, communication_control=0, **kwargs)

Bases: object

property tp
class scapy.contrib.automotive.ecu.ECU_am(**kargs)

Bases: scapy.ansmachine.AnsweringMachine

AnsweringMachine which emulates the basic behaviour of a real world ECU. Provide a list of ECUResponse objects to configure the behaviour of this AnsweringMachine.

param supported_responses

List of ECUResponse objects to define the behaviour. The default response is generalReject.

param main_socket

Defines the object of the socket to send and receive packets.

param broadcast_socket

Defines the object of the broadcast socket. Listen-only, responds with the main_socket. None to disable broadcast capabilities.

param basecls

Provide a basecls of the used protocol

Usage: >>> resp = ECUResponse(session=range(0,255), security_level=0, responses=UDS() / UDS_NR(negativeResponseCode=0x7f, requestServiceId=0x10)) # noqa: E501 >>> sock = ISOTPSocket(can_iface, sid=0x700, did=0x600, basecls=UDS) # noqa: E501 >>> answering_machine = ECU_am(supported_responses=[resp], main_socket=sock, basecls=UDS) # noqa: E501 >>> sim = threading.Thread(target=answering_machine, kwargs={‘count’: 4, ‘timeout’:5}) # noqa: E501 >>> sim.start()

function_name = 'ECU_am'
parse_options(supported_responses=None, main_socket=None, broadcast_socket=None, basecls=<class 'scapy.packet.Raw'>, timeout=None)
print_reply(req, reply)
sniff_options_list = ['store', 'opened_socket', 'count', 'filter', 'prn', 'stop_filter', 'timeout']