scapy.layers.can

A minimal implementation of the CANopen protocol, based on Wireshark dissectors. See https://wiki.wireshark.org/CANopen

class scapy.layers.can.CAN

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
CAN fields

flags

FlagsField (3 bits)

<Flag 0 ()>

identifier

XBitField (29 bits)

0

length

FieldLenField

None

reserved

ThreeBytesField

0

data

StrLenField

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.SignalPacket

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)
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.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.LEFloatSignalField(name, default, start, scaling=1, unit='', offset=0, ndigits=3)

Bases: scapy.layers.can.SignalField

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

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

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_allowed_exceptions = ()
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.SignalHeader

Bases: scapy.layers.can.CAN

aliastypes
extract_padding(s)
fields_desc
SignalHeader fields

flags

FlagsField (3 bits)

<Flag 0 ()>

identifier

XBitField (29 bits)

0

length

LenField

None

reserved

ThreeBytesField

0