scapy.layers.can
A minimal implementation of the CANopen protocol, based on Wireshark dissectors. See https://wiki.wireshark.org/CANopen
- class scapy.layers.can.BEFloatSignalField(name, default, start, scaling=1, unit='', offset=0, ndigits=3)
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.BESignedSignalField(name, default, start, size, scaling=1, unit='', offset=0, ndigits=3)
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.BEUnsignedSignalField(name, default, start, size, scaling=1, unit='', offset=0, ndigits=3)
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.CAN(*args, **kargs)
Bases:
scapy.packet.Packet
A minimal implementation of the CANopen protocol, based on Wireshark dissectors. See https://wiki.wireshark.org/CANopen
- aliastypes
- extract_padding(p)
- 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 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | | DATA | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ Fig. CAN
CAN fields flags
FlagsField
(3 bits)<Flag 0 ()>
identifier
XBitField
(29 bits)0
length
None
reserved
0
data
b''
- static inv_endianness(pkt)
Invert the order of the first four bytes of a CAN packet
This method is meant to be used specifically to convert a CAN packet between the pcap format and the socketCAN format
- Parameters
pkt – str of the CAN packet
- Returns
packet str with the first four bytes swapped
- post_build(pkt, pay)
Implements the swap-bytes functionality when building
this is based on a copy of the Packet.self_build default method. The goal is to affect only the CAN layer data and keep under layers (e.g LinuxCooked) unchanged
- post_dissect(s)
- pre_dissect(s)
Implements the swap-bytes functionality when dissecting
- class scapy.layers.can.CandumpReader(filename, interface=None)
Bases:
object
A stateful candump reader. Each packet is returned as a CAN packet
- close()
- dispatch(callback)
call the specified callback routine for each packet read
This is just a convenience function for the main loop that allows for easy launching of packet processing in a thread.
- fileno()
- next()
implement the iterator protocol on a set of packets
- nonblocking_socket = True
- static open(filename)
Open (if necessary) filename.
- read_all(count=- 1)
return a list of all packets in the candump file
- read_packet(size=65535)
return a single packet read from the file or None if filters apply
raise EOFError when no more packets are available
- recv(size=65535)
Emulate a socket
- static select(sockets, remain=None)
- class scapy.layers.can.LEFloatSignalField(name, default, start, scaling=1, unit='', offset=0, ndigits=3)
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.LESignedSignalField(name, default, start, size, scaling=1, unit='', offset=0, ndigits=3)
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.LEUnsignedSignalField(name, default, start, size, scaling=1, unit='', offset=0, ndigits=3)
Bases:
scapy.layers.can.SignalField
- class scapy.layers.can.SignalField(name, default, start, size, scaling=1, unit='', offset=0, ndigits=3, fmt='B')
Bases:
scapy.fields.ScalingField
- addfield(pkt, s, val)
- getfield(pkt, s)
- i2len(pkt, x)
- randval()
- size
- start
- class scapy.layers.can.SignalHeader(*args, **kargs)
Bases:
scapy.layers.can.CAN
- aliastypes
- extract_padding(s)
- 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. SignalHeader
SignalHeader fields flags
FlagsField
(3 bits)<Flag 0 ()>
identifier
XBitField
(29 bits)0
length
None
reserved
0
- class scapy.layers.can.SignalPacket(*args, **kargs)
Bases:
scapy.packet.Packet
- aliastypes
- post_dissect(s)
SignalFields can be dissected on packets with unordered fields. The order of SignalFields is defined from the start parameter. After a build, the consumed bytes of the length of all SignalFields have to be removed from the SignalPacket.
- pre_dissect(s)
- scapy.layers.can.rdcandump(filename, count=- 1, interface=None)
Read a candump log file and return a packet list
filename: file to read count: read only <count> packets interfaces: return only packets from a specified interface