scapy.contrib.isotp.isotp_utils

class scapy.contrib.isotp.isotp_utils.ISOTPMessageBuilder(use_ext_address: bool | None = None, rx_id: int | ~typing.List[int] | ~typing.Iterable[int] | None = None, basecls: ~typing.Type[~scapy.contrib.isotp.isotp_packet.ISOTP] = <class 'scapy.contrib.isotp.isotp_packet.ISOTP'>)[source]

Bases: object

Initialize a ISOTPMessageBuilder object

Utility class to build ISOTP messages out of CAN frames, used by both ISOTP.defragment() and ISOTPSession.

This class attempts to interpret some CAN frames as ISOTP frames, both with and without extended addressing at the same time. For example, if an extended address of 07 is being used, all frames will also be interpreted as ISOTP single-frame messages.

CAN frames are fed to an ISOTPMessageBuilder object with the feed() method and the resulting ISOTP frames can be extracted using the pop() method.

Parameters:
  • use_ext_address – True for only attempting to defragment with extended addressing, False for only attempting to defragment without extended addressing, or None for both

  • rx_id – Destination Identifier

  • basecls – The class of packets that will be returned, defaults to ISOTP

class Bucket(total_len: int, first_piece: bytes, ts: EDecimal | float)[source]

Bases: object

Helper class to store not finished ISOTP messages while building.

push(piece: bytes) None[source]
property count: int

Returns the number of ready ISOTP messages built from the provided can frames

Returns:

Number of ready ISOTP messages

feed(can: Iterable[Packet] | Packet) None[source]

Attempt to feed an incoming CAN frame into the state machine

pop(identifier: int | None = None, ext_addr: int | None = None) ISOTP | None[source]

Returns a built ISOTP message

Parameters:
  • identifier – if not None, only return isotp messages with this destination

  • ext_addr – if identifier is not None, only return isotp messages with this extended address for destination

Returns:

an ISOTP packet, or None if no message is ready

class scapy.contrib.isotp.isotp_utils.ISOTPMessageBuilderIter(builder: ISOTPMessageBuilder)[source]

Bases: object

Iterator class for ISOTPMessageBuilder

next() ISOTP[source]
slots = ['builder']
class scapy.contrib.isotp.isotp_utils.ISOTPSession(*args: Any, **kwargs: Any)[source]

Bases: DefaultSession

Defragment ISOTP packets ‘on-the-flow’.

Usage:
>>> sniff(session=ISOTPSession)
recv(sock: SuperSocket) Iterator[Packet][source]

Will be called by sniff() to ask for a packet