scapy.contrib.isotp¶
ISOTPSocket.
-
class
scapy.contrib.isotp.
ISOTP
(*args, **kargs)[source]¶ Bases:
scapy.base_classes.Gen
[scapy.packet.Packet
]-
aliastypes
¶
-
default_fields
¶
-
direction
¶
-
dst
¶
-
exdst
¶
-
explicit
¶
-
exsrc
¶
-
fields
¶
-
fields_desc
¶ Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | DATA | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ISOTP
ISOTP fields¶ data
b''
-
fieldtype
¶
-
name
¶
-
original
¶
-
overload_fields
¶
-
overloaded_fields
¶
-
packetfields
¶
-
payload
¶
-
post_transforms
¶
-
raw_packet_cache
¶
-
raw_packet_cache_fields
¶
-
sent_time
¶
-
sniffed_on
¶
-
src
¶
-
time
¶
-
underlayer
¶
-
wirelen
¶
-
-
class
scapy.contrib.isotp.
ISOTPHeader
(*args, **kargs)[source]¶ Bases:
scapy.base_classes.Gen
[scapy.packet.Packet
]-
aliastypes
¶
-
fields_desc
¶ Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |FLAGS| IDENTIFIER | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LENGTH | RESERVED | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | +-+-+-+-+-+-+-+-+ Fig. ISOTPHeader
ISOTPHeader fields¶ flags
<Flag 0 ()>
identifier
XBitField
(29 bits)0
length
None
reserved
0
-
-
class
scapy.contrib.isotp.
ISOTPHeaderEA
(*args, **kargs)[source]¶ Bases:
scapy.base_classes.Gen
[scapy.packet.Packet
]-
aliastypes
¶
-
fields_desc
¶ Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |FLAGS| IDENTIFIER | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | LENGTH | RESERVED | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | |EXTENDED ADDRES| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ISOTPHeaderEA
ISOTPHeaderEA fields¶ flags
<Flag 0 ()>
identifier
XBitField
(29 bits)0
length
None
reserved
0
extended_address
0
-
-
class
scapy.contrib.isotp.
ISOTPMessageBuilder
(use_ext_addr=None, did=None, basecls=None)[source]¶ Bases:
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.
-
property
count
¶ Returns the number of ready ISOTP messages built from the provided can frames
-
pop
(identifier=None, ext_addr=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
-
property
-
class
scapy.contrib.isotp.
ISOTPNativeSocket
(iface=None, sid=0, did=0, extended_addr=None, extended_rx_addr=None, listen_only=False, padding=False, transmit_time=100, basecls=<class 'scapy.contrib.isotp.ISOTP'>)[source]¶ Bases:
scapy.supersocket.SuperSocket
-
auxdata_available
= True¶
-
can_isotp_fc_options_fmt
= '@3B'¶
-
can_isotp_ll_options_fmt
= '@3B'¶
-
can_isotp_options_fmt
= '@2I4B'¶
-
desc
= 'read/write packets at a given CAN interface using CAN_ISOTP socket '¶
-
sockaddr_can_fmt
= '@H3I'¶
-
-
scapy.contrib.isotp.
ISOTPScan
(sock, scan_range=range(0, 2048), extended_addressing=False, extended_scan_range=range(0, 256), noise_listen_time=2, sniff_time=0.1, output_format=None, can_interface=None, extended_can_id=False, verbose=False)[source]¶ Scan for ISOTP Sockets on a bus and return findings
Scan for ISOTP Sockets in the defined range and returns found sockets in a specified format. The format can be:
text: human readable output
code: python code for copy&paste
sockets: if output format is not specified, ISOTPSockets will be created and returned in a list
- Parameters
sock – CANSocket object to communicate with the bus under scan
scan_range – range of CAN-Identifiers to scan. Default is 0x0 - 0x7ff
extended_addressing – scan with ISOTP extended addressing
extended_scan_range – range for ISOTP extended addressing values
noise_listen_time – seconds to listen for default communication on the bus
sniff_time – time the scan waits for isotp flow control responses after sending a first frame
output_format – defines the format of the returned results (text, code or sockets). Provide a string e.g. “text”. Default is “socket”.
can_interface – interface used to create the returned code/sockets
extended_can_id – Use Extended CAN-Frames
verbose – displays information during scan
- Returns
-
class
scapy.contrib.isotp.
ISOTPSession
(*args, **kwargs)[source]¶ Bases:
scapy.sessions.DefaultSession
Defragment ISOTP packets ‘on-the-flow’.
Usage: >>> sniff(session=ISOTPSession)
-
scapy.contrib.isotp.
ISOTPSocket
[source]¶ alias of
scapy.contrib.isotp.ISOTPSoftSocket
-
class
scapy.contrib.isotp.
ISOTPSocketImplementation
(can_socket, src_id, dst_id, padding=False, extended_addr=None, extended_rx_addr=None, rx_block_size=0, rx_separation_time_min=0, listen_only=False)[source]¶ Bases:
scapy.automaton.SelectableObject
Implementation of an ISOTP “state machine”.
Most of the ISOTP logic was taken from https://github.com/hartkopp/can-isotp/blob/master/net/can/isotp.c
This class is separated from ISOTPSoftSocket to make sure the background thread can’t hold a reference to ISOTPSoftSocket, allowing it to be collected by the GC.
-
on_recv
(cf)[source]¶ Function that must be called every time a CAN frame is received, to advance the state machine.
-
-
class
scapy.contrib.isotp.
ISOTPSoftSocket
(can_socket=None, sid=0, did=0, extended_addr=None, extended_rx_addr=None, rx_block_size=0, rx_separation_time_min=0, padding=False, listen_only=False, basecls=<class 'scapy.contrib.isotp.ISOTP'>)[source]¶ Bases:
scapy.supersocket.SuperSocket
This class is a wrapper around the ISOTPSocketImplementation, for the reasons described below.
The ISOTPSoftSocket aims to be fully compatible with the Linux ISOTP sockets provided by the can-isotp kernel module, while being usable on any operating system. Therefore, this socket needs to be able to respond to an incoming FF frame with a FC frame even before the recv() method is called. A thread is needed for receiving CAN frames in the background, and since the lower layer CAN implementation is not guaranteed to have a functioning POSIX select(), each ISOTP socket needs its own CAN receiver thread. SuperSocket automatically calls the close() method when the GC destroys an ISOTPSoftSocket. However, note that if any thread holds a reference to an ISOTPSoftSocket object, it will not be collected by the GC.
The implementation of the ISOTP protocol, along with the necessary thread, are stored in the ISOTPSocketImplementation class, and therefore:
There no reference from ISOTPSocketImplementation to ISOTPSoftSocket
ISOTPSoftSocket can be normally garbage collected
Upon destruction, ISOTPSoftSocket.close() will be called
ISOTPSoftSocket.close() will call ISOTPSocketImplementation.close()
RX background thread can be stopped by the garbage collector
-
begin_send
(p)[source]¶ Begin the transmission of message p. This method returns after sending the first frame. If multiple frames are necessary to send the message, this socket will unable to send other messages until either the transmission of this frame succeeds or it fails.
-
nonblocking_socket
= True¶
-
class
scapy.contrib.isotp.
ISOTP_CF
(*args, **kargs)[source]¶ Bases:
scapy.base_classes.Gen
[scapy.packet.Packet
]-
aliastypes
¶
-
fields_desc
¶ Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | TYPE | INDEX | DATA | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ISOTP_CF
ISOTP_CF fields¶ type
2
index
BitField
(4 bits)0
data
b''
-
-
class
scapy.contrib.isotp.
ISOTP_FC
(*args, **kargs)[source]¶ Bases:
scapy.base_classes.Gen
[scapy.packet.Packet
]-
aliastypes
¶
-
fields_desc
¶ Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | TYPE |FC FLAG| BLOCK SIZE |SEPARATION TIME| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ISOTP_FC
ISOTP_FC fields¶ type
3
fc_flag
0
block_size
0
separation_time
0
-
-
class
scapy.contrib.isotp.
ISOTP_FF
(*args, **kargs)[source]¶ Bases:
scapy.base_classes.Gen
[scapy.packet.Packet
]-
aliastypes
¶
-
fields_desc
¶ Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | TYPE | MESSAGE SIZE | EXTENDED MESSAGE SIZE | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | DATA | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ISOTP_FF
ISOTP_FF fields¶ type
1
message_size
BitField
(12 bits)0
extended_message_size
BitField
(Cond) (32 bits)0
data
b''
-
-
class
scapy.contrib.isotp.
ISOTP_SF
(*args, **kargs)[source]¶ Bases:
scapy.base_classes.Gen
[scapy.packet.Packet
]-
aliastypes
¶
-
fields_desc
¶ Display RFC-like schema
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | TYPE |MESSAGE| DATA | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. ISOTP_SF
ISOTP_SF fields¶ type
0
message_size
BitFieldLenField
(4 bits)None
data
b''
-