CAN Bus Fundamentals
CAN (Controller Area Network) is the primary communication protocol in vehicles. It's a broadcast protocol with no authentication, making it vulnerable to sniffing and injection attacks. The last sections cover ISO-TP, the segmentation layer that carries any diagnostic request longer than a single frame.
CAN Frame Structure
CAN Frame (Standard 11-bit ID):
+---------------+-------+------+--------------+------+
| Arbitration | RTR | DLC | Data | CRC |
| ID (11b) | (1b) | (4b) | (0-8 bytes) | |
+---------------+-------+------+--------------+------+
Example CAN message:
ID: 0x7DF (OBD-II broadcast)
DLC: 8
Data: 02 01 0C 00 00 00 00 00
└─┴─┴─ Request RPM
Key characteristics:
- No source/destination - broadcast only
- Priority by arbitration ID (lower = higher priority)
- No authentication mechanism
- Typical speeds: 500 kbps (high), 125 kbps (low)An Identifier And Eight Bytes Need A DBC
The example above decodes because OBD-II PIDs are standardised, in SAE J1979; a manufacturer frame is not. Its
meaning lives in a DBC, Vector's text format from the same 1990s CANdb lineage, which names messages
(BO_) and signals
(SG_), the latter
with start bit, length, byte order, signedness, scale, offset and unit. Without it, 0x2A0 and eight bytes is
uninterpretable: a byte change is visible, that bytes two and three are a twelve-bit little-endian temperature at
0.1 °C is not. DBC describes periodic signal traffic and ODX describes diagnostics, so neither replaces the other.
The format has no formal schema, ARXML has taken the job over on newer networks, and SOME/IP IDL describes
services, not CAN signals.
CAN Hardware Setup
# Required hardware:
# - CANable, PEAK PCAN, or similar USB-CAN adapter
# - OBD-II to DB9 cable
# Set up CAN interface on Linux
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
# Verify interface
ip -details link show can0
# can-utils installation
sudo apt install can-utils
# Basic sniffing
candump can0
# With timestamps and colors
candump -c -t a can0
# Filter specific IDs
candump can0,7DF:7FFWhy ISO-TP Exists
A classic CAN frame carries eight data bytes, one of them the PCI header, leaving seven for content; CAN FD allows
64. Nothing in a CAN frame says a message continues in the next one, and diagnostic payloads are routinely longer —
a 0x22 on a large
identifier, a 0x36
transfer block — so ISO 15765-2, ISO-TP, supplies segmentation, reassembly and flow control over a pair of
arbitration IDs.
The current edition is ISO 15765-2:2024 (Edition 4, April 2024), which replaced the 2016 Edition 3 most vehicles in the field were validated against. It restructured the document around the OSI model and added the T_Data primitive without changing the frame format, and a fifth edition was still a committee draft (ISO/CD 15765-2) at the time of writing.
The cost is easy to understate. A RequestDownload answer advertising
0x0400 as its largest
TransferData request sets a budget of 1,024 bytes for the whole
0x36 message, service
identifier and block counter included. On classic CAN the First Frame carries six of those bytes and each Consecutive
Frame seven, so the remaining 1,018 need 146 frames: 147 ISO-TP frames for a single transfer block. Block size is a
byte budget rather than a frame count, which is why the transfer sequence on the
OBD-II page stops where it does.
The Four Frame Types and the PCI Nibble
Each frame opens with an N_PCI byte: high nibble the type, low nibble type-specific. Single Frame
0x0N carries the whole
PDU, N being its length — seven bytes on classic CAN, six with extended addressing. First Frame
0x1N opens a
multi-frame PDU and declares its total, the low nibble as the top four bits of a 12-bit count and the next byte the
rest, so 10 14
announces 20 bytes and leaves six of payload. Consecutive Frame
0x2N continues it, N
starting at 1 and wrapping from 0x0F to 0x00 — not back to 1. Flow Control
0x3N is the
receiver's reply.
# ReadDataByIdentifier 0xF190 (VIN), classic CAN, physical addressing.
# Request on 0x7E0, answer on 0x7E8, unused bytes zero-padded.
0x7E0 03 22 F1 90 00 00 00 00
^^ PCI 0x0_: Single Frame, low nibble 3 = 3 payload bytes
^^ 0x22 ReadDataByIdentifier
^^^^^ DID 0xF190, the VIN
# The answer is 62 F1 90 plus 17 VIN bytes: 20 bytes in total, 0x014.
0x7E8 10 14 62 F1 90 57 56 57 FF 0x1_ length 0x014, first 6 payload bytes
0x7E0 30 00 00 00 00 00 00 00 FC 0x3_ FS=0 continue, BS=0, STmin=0
0x7E8 21 5A 5A 5A 31 4B 5A 4D CF 0x2_ sequence 1, 7 payload bytes
0x7E8 22 30 30 30 30 30 30 31 CF 0x2_ sequence 2, final 7 bytesThe FF declares the application PDU length, so the receiver stops at 0x014 and treats the rest as padding; the sequence number is checked, not inferred from arrival order.
ISO-TP segmentation of a 1,024-byte transfer block
Scroll sideways to see the whole diagram
Flow Control: FS, BS and STmin
The receiver answers every First Frame, and every completed block, with a three-byte Flow Control — PCI, block size, minimum separation time, the PCI nibble being the flow status.
| FS | Meaning | What the sender must do |
|---|---|---|
| 0 | ContinueToSend | Send up to BS frames, then wait for another FC |
| 1 | Wait | Stop; only N_WFTmax of these are allowed |
| 2 | Overflow | Abort the PDU; the receiver cannot hold that size |
| 3–15 | Reserved | A protocol error, not ContinueToSend |
Block size is how many consecutive frames the sender may emit before it must stop and wait; zero means no further flow control. STmin is the floor between frames: 0x00 to 0x7F in milliseconds, 0xF1 to 0xF9 in hundreds of microseconds — the CAN FD addition — and the rest reserved, treated as 0x7F, 127 ms.
Overflow is the declared length exceeding the receiver's buffer — not a bus fault, and not retryable. Wait means it is alive and asking for time, the only back-pressure the protocol has.
A Wait Frame, Byte For Byte
Flow Control is three content bytes — status, block size, STmin — and nothing else, so an ECU that answers without
padding sends three bytes and
candump prints it
as [3]. Only the
status carries meaning; the other two are whatever the receiver's own configuration holds.
# FS=Wait as an ECU emits it: a long request goes out on 0x7E0 and the ECU's
# Flow Control comes back on 0x7E8. Derived from the encoding rules, not
# captured. Content is status, block size and STmin, so an unpadded frame is
# three bytes long.
0x7E8 31 00 00
^^ PCI 0x3_, low nibble 1 = Wait
^^ BS
^^ STmin
# Nothing forces those two to zero on a Wait, and they are not read by the
# sender: the same receiver configured BS=8 and STmin=0x0A emits
0x7E8 31 08 0A
# Padded to a full eight-byte frame (CAN_ISOTP_TX_PADDING) it is the same
# three bytes plus filler, 0xCC by default.
0x7E8 31 08 0A CC CC CC CC CCOn receipt the sender stops after the frame it has already sent, does not advance the sequence number, restarts its N_Bs timer, and waits for another Flow Control. Both halves of that matter. Pausing without holding the sequence number is not a pause: the counter belongs to frames the receiver accepted, so spending one on a frame it was not ready for desynchronises the transfer even if the bytes arrive. The next ContinueToSend resumes at the next sequence number; another Wait extends the pause.
A tester that ignores the Wait keeps sending, and nothing in the protocol obliges the receiver to buffer what it did
not ask for. The visible result is a transfer that stops mid-way — the same shape as a bus fault or a dropped
frame — so read the trace for the
31 frame before
concluding anything about the harness. Two further details are worth knowing when you go looking. The kernel sender
does not count Wait frames: its Flow Control handler restarts the one-second timer and does nothing else, so an ECU
that answers Wait indefinitely holds
isotpsend open
indefinitely, and the N_WFTmax limit in the table above is not enforced by the sender at all. And the kernel never
emits one — its Flow Control goes out only as ContinueToSend or Overflow — so a bench receiver that must stall a
sender has to
cansend the
31 frame itself, and
then finish the transfer with hand-built Consecutive Frames, because the stalled sender will not continue without a
ContinueToSend.
CAN FD: Escape Sequences and 32-bit Lengths
CAN FD keeps the four types and changes the two fields sized for eight bytes. A Single Frame longer than eight bytes sets the low nibble to zero and puts the real length in the second byte, so one frame holds 8 to 62 bytes. A First Frame with a 12-bit length of zero escapes: the next four bytes are a big-endian 32-bit length, leaving 58 payload bytes. A Consecutive Frame carries 63. The boundaries move — 7 to 62 for a Single Frame, 6 to 62 for a First Frame — so a parser reading the SF nibble as a length sees zero bytes where 62 were sent.
The Single Frame Escape, Worked
A Single Frame is the case a reader meets first, and the one where the fault hides best. Up to seven payload bytes the two link layers agree: the length is the low nibble of the PCI byte and the payload starts at byte 1. The escape begins one byte above that ceiling — the nibble goes to zero and the real length moves to the second byte, so the payload starts at byte 2 and the header costs two bytes instead of one.
# The same ReadDataByIdentifier 0xF190 answer, 20-byte VIN PDU, both link
# layers. Derived from the encoding rules, not captured from a vehicle.
# Classic CAN, DLC 8, three frames.
0x7E8 10 14 62 F1 90 57 56 57 FF 0x1_, length 0x014, 6 payload bytes
0x7E0 30 00 00 00 00 00 00 00 FC 0x3_, continue
0x7E8 21 5A 5A 5A 31 4B 5A 4D CF 0x2_, sequence 1
0x7E8 22 30 30 30 30 30 30 31 CF 0x2_, sequence 2, 20 bytes in total
# CAN FD, DLC 12 = 24 bytes, one frame.
0x7E8 00 14 62 F1 90 57 56 57 5A 5A 5A 31 4B 5A 4D 30
30 30 30 30 30 31 CC CC
byte 0 00 type 0x0_, low nibble 0 = escaped length
1 14 SF_DL, 0x14 = 20 payload bytes
2-21 62 ... payload starts at byte 2: 62 F1 90, then 17 VIN bytes
22-23 CC CC padding to the next legal DLC length, 2 bytes
Read byte 0 on its own and the frame says Single Frame, length zero, which is what a parser written for classical
CAN believes: it returns an empty answer and the 20 bytes that did arrive are discarded. The same answer cost a
First Frame, a Flow Control and two Consecutive Frames a moment ago, so the saving is real — one frame carries all
20 payload bytes plus two of padding, and nothing is left to reassemble. The reverse also holds, and it is the one
that breaks a filter: a three-byte request keeps the nibble form on CAN FD, so
03 22 F1 90 is
byte-identical on both buses. The kernel reaches the escape only when the PDU will not fit the nibble form — the
test that clears it is
size <= CAN_MAX_DLEN - SF_PCI_SZ4 - ae
in net/can/isotp.c —
and a receiver accepts the escape only when the frame is genuinely FD and longer than eight bytes.
The First Frame 32-bit Escape
# CAN FD First Frame, DLC 15 = 64 bytes, using the 32-bit length escape.
# Derived from the encoding rules, not captured from a vehicle.
byte 0 1 2 3 4 5 6 ... 63
10 00 00 00 10 00 63 ... (58 payload bytes)
0 10 FF, type 0x1_, low nibble 0 = escaped length
1 00 the 12-bit field reads 0x000, the escape marker
2-5 00 00 10 00 N_PDU length, big-endian: 0x00001000 = 4,096 bytes
6.. 63 ... payload starts at byte 6: 0x63 ReadMemoryByAddress
response, then 57 data bytes
On a 64-byte frame the escape costs four bytes of payload: the length field grows from two bytes to six, so a First
Frame still carries 58 bytes but declares any length a 32-bit field holds instead of stopping at 4,095. The frame
above is derived from those rules rather than captured, and its declared length is 4,096 — one more than the 12-bit
field can express. Read the first two bytes together: 10 00
is type 0x1_ with a 12-bit length of zero, and zero is the escape marker, not an empty PDU. A parser that trusts the
nibble-and-byte field and skips the four-byte branch reports a zero-length answer and discards 4,096 bytes that did
arrive.
DLC Codes and Byte Counts
In CAN FD the Data Length Code is four bits: sixteen codes, each a fixed size rather than a count of bytes. A payload of 9, 10, 11 or 13 bytes cannot be sent as itself, so the controller rounds up and pads.
| DLC | Bytes on the wire |
|---|---|
| 0–8 | Same as the DLC; classical CAN stops at 8 |
| 9 | 12 — the first code that cannot hold its own number |
| 10 | 16 |
| 11 | 20 |
| 12 | 24 |
| 13 | 32 |
| 14 | 48 |
| 15 | 64 — a full FD frame |
That is the strip-by-DLC trap. The declared N_PDU length says where the message ends; the DLC says how many bytes were on the wire, padding included. Strip to the DLC and a ten-byte Single Frame arrives as twelve, its last two bytes padding, and a length-prefixed parser downstream is told the wrong size. The kernel pads with 0xCC by default and, when asked, checks padding length or content rather than ignoring it.
CAN FD Timing: Transmitter Delay Compensation
The data phase is where FD stops behaving like a classical bus, for arithmetic reasons. A bit at 500 kbps lasts
2 µs; at 2 Mbps, 500 ns, and the transceiver loop from TX pin back to RX eats a good fraction of that. A controller
sampling at its own sample point can still be reading the previous bit, so CAN FD adds a second one,
SSP = TDCV + TDCO
after the bit starts as the transmitter sees it.
All three count clock periods — the minimum time quantum ISO 11898-1 defines, not the time quanta the rest of bittiming uses. tdcv is the measured loop delay, supplied by the device per frame under TDC auto and taken from the user only under TDC manual. tdco carries the point past the transceiver's decode delay. tdcf is a filter window: below it nothing is compensated and the normal sample point stands.
Netlink enforces the combinations: a nest without a mode is refused, and so is a mode without parameters. TDCO is
mandatory whenever the nest appears; TDCV is mandatory under manual and refused under auto. Omitting
tdc-mode is the
documented recommendation — the kernel decides, computes a default TDCO and takes TDCV from the device.
Two things make “TDC is on” worth checking.
can_calc_tdco()
implements ISO 11898-1 §11.3.3, which applies TDC only when the data-phase prescaler is 1 or 2; above that the
automatic path clears both mode bits and returns without an error, so the command succeeds and nothing is
compensated. The nest is also read only alongside a data bittiming argument.
A sample-point error at 500 kbps is a fraction of a bit and invisible. At 2 Mbps the same absolute delay is four times that fraction, which is the difference between a tolerable error and sampling the wrong bit: the frame fails its check and the controller raises an error frame. A tester sees CRC and bit errors only on frames with a fast data phase, and nothing on classical traffic — a signature that reads as termination or a bad crimp, and is not. The controller goes error-passive, then bus-off, so the bus dies only under FD load.
fd-non-iso is the
other setting that presents as a wiring fault. It sets the controller's non-ISO bit —
CCCR.NISO on an
M_CAN — switching the CRC to the 2012 CAN FD whitepaper instead of ISO 11898-1:2015. The modes do not interoperate:
a payload-bearing FD frame is rejected by every node not in the same one. Classical frames are untouched, so the
vehicle still starts and only the FD segment looks broken.
# Derived from the netlink attribute rules, not captured: no CAN FD
# hardware is attached here. TDC is parsed only alongside a data
# bittiming argument, and changing that needs the interface down.
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000 dbitrate 2000000 \
dsample-point 0.750 fd on tdc-mode auto tdco 15
sudo ip link set can0 up
ip -details link show can0
# can <FD,TDC-AUTO> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
# dbitrate 2000000 dsample-point 0.750
# tdco 15 tdcf 0
# No TDC-AUTO in that list means the prescaler was above 2 and
# can_calc_tdco() declined. Manual mode takes both values; a tdcv
# under auto is refused:
# ip link set can0 type can ... tdc-mode manual tdcv 42 tdco 15
# ip link set can0 type can ... tdc-mode auto tdcv 42 -> EOPNOTSUPPWhich Interfaces Expose tdc-mode
The attribute exists only when the driver supplies
tdc_const. With it NULL,
can_tdc_changelink() refuses the nest with
EOPNOTSUPP — “The device does not support TDC” — and a dump prints nothing, so a missing
tdc-mode is a driver boundary, not a mistyped command.
Read from this tree, not measured:
mcp251xfd,
rcar_canfd,
xilinx_can,
etas_es58x and the
dummy_can test driver set it.
m_can and
flexcan do not, though both compensate in hardware — m_can writes TDCR, flexcan owns FDCTRL.TDCEN — and
neither do
gs_usb,
kvaser_usb or
peak_usb, whose firmware keeps the timing.
The measured value is a second question. Under auto, netlink emits
IFLA_CAN_TDC_TDCV
only when the driver also sets
do_get_auto_tdcv — verified on
rcar_canfd and
xilinx_can — so
tdco without
tdcv is normal on the others.
CAN XL: 2,048 Bytes And Several Networks
CAN XL is the third frame format in ISO 11898-1:2024, Edition 3, which withdrew the 2015 edition and covers CAN CC, CAN FD, CAN XL and CAN FD light in one document. Its data field runs from 1 to 2,048 bytes in one-byte steps: an eleven-bit DLC of 0 to 2047 where the length is the code plus one. That is 32 times the FD ceiling, and a payload that cost 293 frames on classic CAN fits in one.
Arbitration is unchanged — an 11-bit identifier, lower wins — and that is what preserves priority: an XL frame that loses arbitration waits exactly as an FD frame did. What changed is the field's job. CAN CC and CAN FD use one identifier for arbitration and addressing; XL splits them into an 11-bit priority ID and a 32-bit acceptance field transmitted in the arbitration phase, and the controller's acceptance filter matches the latter. A capture keyed on the identifier is keyed on priority alone.
Two control-field bytes make the bus carry several networks. The 8-bit service data unit type (SDT) names the payload's higher-layer protocol — an EtherType for CAN, its values assigned in CiA 611-1 rather than by ISO. The 8-bit VCID, the virtual CAN network ID, lets up to 256 logical networks share one segment. That is what bites a tester: the same priority ID under two VCIDs is two conversations, so an identifier-keyed dump merges 256 networks into one column, and the field the hardware matched goes unprinted.
The data phase runs at a second, higher bit rate, up to 20 Mbit/s — a transceiver property, not a controller one: 20 Mbit/s needs CAN SIC XL parts as specified in CiA 610-3, while a high-speed (ISO 11898-2) or SIC (CiA 601-4) transceiver caps the controller lower. Switching the transceiver out of arbitration mode is what the PWM phase does, signalled by the duration of the ADH and DAH bits at the two rate-switch boundaries, so netlink carries it as a separate control mode. It is exclusive: TMS cannot be combined with CAN FD or with XL TDC.
Three top-level attributes carry it:
IFLA_CAN_XL_DATA_BITTIMING,
IFLA_CAN_XL_TDC and
IFLA_CAN_XL_PWM. The last two are nests, and neither sits inside the FD ones — XL TDC reuses the
IFLA_CAN_TDC_TDCV,
TDCO and
TDCF children, XL PWM the
IFLA_CAN_PWM_PWMS,
PWML and
PWMO.
ip spells them
xl,
xbitrate,
xsample-point,
xtdc-mode,
xtdco,
tms,
pwms,
pwml and
pwmo.
# Derived from the netlink validation rules, not captured: no CAN XL
# hardware is attached here. XL needs both bittimings, and naming a TDC
# mode makes TDCO mandatory.
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000 xbitrate 10000000 xl on xtdc-mode auto xtdco 15
sudo ip link set can0 up
ip -details link show can0
# can <XL,XL-TDC-AUTO> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
# Then the XL bittiming block -- xbitrate, xsample-point, xtq, xprop-seg --
# and the TDC nest as xtdco and xtdcf. xtdcv appears only in manual mode, or
# on a driver that can report what it measured.
# Transceiver mode switching instead: tms cannot coexist with fd or
# xtdc-mode. Leaving pwms, pwml and pwmo out lets can_calc_pwm() derive them.
sudo ip link set can0 down
sudo ip link set can0 type can bitrate 500000 xbitrate 20000000 xl on tms on
sudo ip link set can0 up
ip -details link show can0
# can <XL,TMS> state ERROR-ACTIVE (berr-counter tx 0 rx 0) restart-ms 0
# ... then the PWM nest as pwms, pwml and pwmo
# Half a triple is refused: tms on pwms 40 -> EOPNOTSUPP
Read from source, not run: in this tree the only driver advertising
CAN_CTRLMODE_XL or TMS is
dummy_can, the test driver, so the surface exists without a vehicle-grade adapter to describe from a
bench.
ISO-TP Has No CAN XL Transport
Bench Or Written Authorisation
CAN XL supplies the link layer; UDS over ISO-TP on XL needs a transport mainline does not have.
isotp_setsockopt_locked()
accepts only CAN_MTU
(16) or CANFD_MTU
(72) as ll.mtu
and answers anything else with EINVAL,
so the 2,060-byte CANXL_MTU
is refused at the socket option, before bind. The file knows classical and CAN FD only,
tx_dl stops at 64,
and CAN XL appears in it nowhere.
For a tester that is a change of layer. There is no diagnostic session on XL in the socket sense: a raw
CAN_RAW socket,
CANXL_XLF on
frames you build, N_PCI and flow control assembled by hand, and filtering on the 32-bit acceptance field rather
than the priority ID.
isotpsend and
isotpdump stop at
the CAN FD boundary.
What The Two CRCs Buy
CAN XL carries two CRC fields where classic CAN carries one 15-bit field: a 13-bit preface CRC over the control field and a 32-bit frame CRC over the whole frame, cascaded so that the second protects the first. Both are specified to Hamming distance 6, so any five randomly distributed bit errors are detected, and CiA puts the undetected-error rate below 10-20 at these lengths. The classic CRC was sized for eight data bytes.
Neither field is authentication. Both are computed by the transmitter over bits the transmitter chose, so a node that can drive the bus computes a correct CRC for whatever it sends. Passing both checks is evidence the bits arrived as sent, and no more.
Addressing and Padding
Normal addressing puts the address in the arbitration ID:
0x7E0 to
0x7E7 for requests,
0x7E8 to
0x7EF for answers and
0x7DF for a
functional broadcast; on 29-bit CAN,
0x18DA<TA><SA>
is physical and 0x18DB<TA><SA>
functional, so a tester at 0xF1 addressing an ECU at 0x42 sends 0x18DA42F1 and listens on 0x18DAF142.
Extended addressing spends the first payload byte on the target address and shortens every frame by one; mixed addressing adds an extension byte to IDs that already carry the addresses. Padding fills the bytes after a Single Frame's payload and after the last Consecutive Frame, with an OEM-chosen value — 0x00, 0xAA and 0xCC all appear — that the receiver may check.
# Extended addressing: one address byte (AE) ahead of the PCI, so every
# frame carries one payload byte less. Derived from the encoding rules,
# not captured; AE 0x42 is the target ECU in both frames.
0x7E0 42 06 2E F1 90 41 42 43 AE 42, SF 0x06, 6 payload bytes: a full frame
0x7E0 42 10 14 62 F1 90 57 56 AE 42, FF length 0x014, 5 payload bytes, not 6The Single Frame is at its ceiling at six payload bytes and the First Frame at five, one below the normal-addressing figures in the VIN example. Consecutive frames drop to six as well, so the 20-byte VIN answer costs four frames instead of three even though its bytes are identical. Mixed addressing leaves the addresses in the identifier and adds an extension byte in the same position, so the same one-byte shift applies, and a parser written for normal addressing is a byte out from its first read.
Timing Parameters
Six timers, three per side: B bounds the wait on Flow Control, C the gap between frames.
| Parameter | Owner | Bounds |
|---|---|---|
| N_As | Sender | Transmission of one frame |
| N_Ar | Receiver | Transmission of a Flow Control or consecutive frame |
| N_Bs | Sender | Wait for Flow Control, after an FF or a block |
| N_Br | Receiver | Delay before it begins to send Flow Control |
| N_Cs | Sender | Delay before the next consecutive frame |
| N_Cr | Receiver | Wait for the next consecutive frame |
1000 ms is the default for N_Bs and N_Cr, the two timers that wait on the other side, in both the kernel stack and
the Python one. N_As and N_Ar are a different kind of value in the kernel: not a wait but a per-frame transmit time,
defaulting to 50 microseconds, which is why
isotpsend -t takes
nanoseconds. N_Br and N_Cs are reported, not waited on. The mistakes that matter: reading N_Cr as a request timeout
when it only bounds frames inside one PDU — answer time is the P2 and P2* budget on the
OBD-II page — reading STmin as a deadline when it is a floor, and
blaming the bus for an N_As overrun from a transmit queue that cannot drain.
Where This Becomes a Testing Observation
None of these is a fault in the standard, which says the transport is unconfirmed and unauthenticated; each is what a trace reveals.
- A First Frame whose declared length is allocated without a bound is the classic length-overflow primitive: the count comes off the wire and drives a buffer size.
- A receiver that accepts a consecutive frame by arrival order instead of sequence number is desynchronised from the first lost frame, and the finished PDU then carries another message's tail.
- STmin and Wait are the only back-pressure there is: 100 microseconds on a 500 kbps bus cannot be honoured, and unlimited Wait holds a sender, and its session, open. A sender that ignores Wait looks like a bus fault instead.
Tooling
The maintained Python implementation is can-isotp,
release 2.0.7 (May 2025) and the library udsoncan builds its SocketCAN connection on. Version 2 runs the transport
in an internal thread, so there is no process()
loop.
# pip install python-can can-isotp
# Needs a real CAN interface: a USB adapter on a bench or in the car.
import can
import isotp
bus = can.interface.Bus(channel='can0', interface='socketcan')
address = isotp.Address(
addressing_mode=isotp.AddressingMode.Normal_11bits,
txid=0x7E0, # tester to ECU
rxid=0x7E8, # ECU to tester
)
params = {
'blocksize': 8, # BS we advertise, 0 = no further FC
'stmin': 0, # ms between the frames we accept
'wftmax': 0, # we never answer with FS=Wait
'rx_flowcontrol_timeout': 1000, # N_Bs, ms
'rx_consecutive_frame_timeout': 1000, # N_Cr, ms
'max_frame_size': 4095, # refuse a bigger declared FF
'blocking_send': True, # send() returns once the PDU is out
}
stack = isotp.CanStack(bus=bus, address=address, params=params)
stack.start() # v2.x runs the transport in a thread
stack.send(b'\x22\xF1\x90', send_timeout=2) # 22 F1 90, segmented if needed
answer = stack.recv(block=True, timeout=2)
print(answer.hex() if answer else 'no response')
stack.stop()
bus.shutdown()
On Linux the kernel does this better: ISO-TP is mainline since 5.10, at
net/can/isotp.c. The
family stays PF_CAN
and the type SOCK_DGRAM;
the protocol argument is
CAN_ISOTP, with the IDs
in sockaddr_can.can_addr.tp
— it is not a separate address family. Two limits: the stack cannot answer a First Frame with Wait, and the largest
PDU is a module parameter. can-utils ships
isotpsend,
isotpdump and
isotpsniffer on the
same socket.
The three tools make the VIN read from the frame-type example reproducible without writing a client:
# can0 must already be up at the vehicle's bitrate. -s is the ID isotpsend
# transmits on, -d the one it expects the answer on; the PDU is read from
# stdin as space-separated hex, so the request is three bytes here.
echo 22 F1 90 | isotpsend -s 7E0 -d 7E8 can0
# The same pair of IDs, decoded frame by frame. Run it in a second terminal
# before the send, or it misses the exchange. isotpdump explains each PCI and
# prints that frame's payload; it does not join frames into a PDU.
isotpdump -s 7E8 -d 7E0 -t a can0
Expect one line per frame — [FF] ln: 20,
then [CF] sn: 1 and
[CF] sn: 2 — so the
reassembly is still yours to do. isotpsniffer
is the tool that joins them, and the two views are compared on the
CAN attacks page.
Sending ISO-TP On A CAN FD Bus
The command above is a classical CAN client: its link layer defaults to CAN_MTU
with an eight-byte payload, so on an FD bus it still segments into seven-byte Consecutive Frames and a 62-byte
Single Frame is never produced. -L
sets the three members of struct can_isotp_ll_options.
# can0 has to be up with FD and a data bitrate before any of these work:
# sudo ip link set can0 type can bitrate 500000 dbitrate 2000000 fd on
# Classical CAN: mtu 16, tx_dl 8, no flags. Identical to omitting -L.
echo 22 F1 90 | isotpsend -s 7E0 -d 7E8 can0
# CAN FD, 64-byte frames, no bit-rate switch on the data phase.
echo 22 F1 90 | isotpsend -s 7E0 -d 7E8 -L 72:64:0 can0
# CAN FD with BRS: tx_flags 0x01 is CANFD_BRS, the data phase at dbitrate.
echo 22 F1 90 | isotpsend -s 7E0 -d 7E8 -L 72:64:1 can0
# The listening side needs no -L: isotpdump opens a raw socket and turns on
# CAN_RAW_FD_FRAMES unconditionally, so it decodes both frame types.
isotpdump -s 7E8 -d 7E0 -t a can0
The three fields are decimal and colon-separated, parsed as
%hhu:%hhu:%hhu into
mtu,
tx_dl and
tx_flags. Leave the
base alone: this page speaks hex everywhere else, and
72 here is decimal
seventy-two.
mtu is the frame type the socket generates and accepts: 16 is
CAN_MTU, the
classical frame, and 72 is
CANFD_MTU; the kernel
accepts no other value. tx_dl is a byte count, not a DLC code, and it must be one of 8, 12, 16, 20,
24, 32, 48 or 64 — the kernel rejects anything else as not being a legal ISO 11898-1 length. It is also the most the
stack will place in one frame, so 64 is what buys the 62-byte Single Frame. tx_flags is copied
straight into canfd_frame.flags
on every frame the socket builds: 1 is
CANFD_BRS, 2
CANFD_ESI, 4
CANFD_FDF, and 0
keeps the whole frame at the arbitration bitrate.
A mismatch fails in three different places, and two of them are quiet. First,
isotpsend only issues
the CAN_ISOTP_LL_OPTS
setsockopt when tx_dl
is non-zero, so -L 72:0:0
is accepted and does nothing: you stay on classical CAN with nothing on stderr to say so. Second,
mtu 72 against an
interface whose MTU is still 16 fails at bind, not at send — the kernel compares the device MTU with
ll.mtu in
isotp_bind() — so
fd on is a
prerequisite and the symptom is bind: Invalid argument.
Third, the receive direction is strict in both ways:
isotp_rcv() drops
any frame whose length is not exactly the configured mtu, so an FD socket never sees a classical answer and a
classical socket never sees an FD one. That last one looks like silence — the request writes, the process exits 0,
and nothing comes back — so set the link layer from the frame type of the answer, not of the request.
Extended Addressing: The Flag And The Byte
Two different things wear the same flag name here.
isotpsend -x 42
adds the address byte, because it sets
CAN_ISOTP_EXTEND_ADDR
on the kernel transport and the stack then writes 0x42 into
data[0] of every
frame it builds. isotpdump -x
only expects it: that tool is a raw-socket decoder with no transport of its own, so its flag shifts the PCI
decode by one byte and filters on the value.
# AE 0x42 in both directions: the 42 in the byte map above.
echo 22 F1 90 | isotpsend -s 7E0 -d 7E8 -x 42 can0
# on the wire: 7E0 42 03 22 F1 90 AE, SF 0x03, 3 payload bytes
# Separate addresses per direction: tx first, then rx.
echo 22 F1 90 | isotpsend -s 7E0 -d 7E8 -x 42:43 can0
# isotpdump decodes what has already been captured, so both sides are named:
# -x is the address expected on the -s identifier, -X the one on -d.
# -X without -x is rejected outright. 'any' matches every address.
isotpdump -s 7E8 -d 7E0 -x any -X any -t a can0
A single value covers both directions because the kernel copies
ext_address into
rx_ext_address
unless CAN_ISOTP_RX_EXT_ADDR
is set as well, which is what the two-value form does. The byte is the entire mechanism: with it the Single Frame
ceiling falls from seven payload bytes to six and the First Frame from six to five, so the 20-byte VIN answer needs
four frames instead of three. On the decode side, setting the flag makes
isotpdump print the
address in braces after the identifier —
7E042 [5] — and
move its PCI decode one byte right; leaving it off makes the tool read the address byte as the PCI, and 0x42 matches
none of the four type nibbles, so the frame prints as
[??] with no length
and no payload — a frame that looks corrupt rather than misconfigured.
The Rest Of The isotpsend Flag Set
The padding flags are named.
-p [tx]:[rx] sets
the filler byte and enables padding in that direction: -p CC
pads transmissions with 0xCC, -p :AA
turns on receive padding only, and two values do both. The kernel default is already 0xCC, so naming it changes
what the socket accepts, not what it sends.
-P l|c|a checks
frames the socket receives, which for a sender is the Flow Control and nothing else: a receiver's
enforcement of padding on data frames is not something isotpsend
can audit. Two traps: -P c
without a receive pad value rejects every frame, having nothing to compare against, and
-P l without one
asserts the opposite, that the frame is the shortest legal length for its content. Only the first character is
read.
-f takes a
nanosecond value and overrides only the gap: it sets
CAN_ISOTP_FORCE_TXSTMIN
plus a separate CAN_ISOTP_TX_STMIN
sockopt, so the kernel uses it instead of the ECU's STmin while block size and the wait for Flow Control stand —
the tool's “ignore FC” overstates it.
-D <len> is
not a diagnostic mode: it suppresses stdin and writes a synthetic PDU counting 0x01 upward.
-g sleeps
microseconds before each PDU rather than waiting for a frame.
-b takes no
argument and blocks until transmission completes —
-b <bs>
belongs to isotprecv.
-C never awaits
Flow Control and cannot be combined with
-S.
-t takes nanoseconds, and
-t 0 is not zero: a zero
frame_txtime means “keep the current value”, so the 50-microsecond default survives and every frame is
still paced. Linux 5.18 added
CAN_ISOTP_FRAME_TXTIME_ZERO, which can-utils spells
-t ZERO, and it is the only way to take N_As out of the gap the kernel computes — the measurement that
attributes the overrun rather than blaming the bus. A burst can also outrun a transmit queue, so treat it as a
measurement, not a default.
Testing Whether A Peer Enforces Padding
-P audits what a
socket receives, so the receiver has to be a different socket on a different interface: two adapters on one
machine, or two machines. Both ends on one adapter's loopback is one kernel checking itself — it demonstrates
check_pad(), not the
peer's behaviour.
Give the receiving side a pad value as well as a check, then send the same synthetic PDU with the filler right and then wrong:
# Receiver on the far side: -p :CC names the filler it expects (rx only),
# -P a checks both length and content. Derived, not captured.
isotprecv -s 7E8 -d 7E0 -p :CC -P a can1
# -D 20 sends a synthetic 20-byte PDU counting 0x01 upward, so neither
# side needs stdin; -p CC pads the tx direction with 0xCC.
isotpsend -s 7E0 -d 7E8 -p CC -D 20 can0
# The same PDU with the wrong filler. This is the send that must fail.
isotpsend -s 7E0 -d 7E8 -p AA -D 20 can0
Run the pair twice. With no
-P on the receiver both sends deliver the same 20 bytes: whatever filler arrives is accepted, which is
the ignore case. With
-p :CC -P a the first send delivers 20 bytes and the second delivers nothing — the check fails, the read
returns
EBADMSG, and
isotprecv never inspects that return, so it prints a blank line and exits 0. Watch the wire with
candump before reading that blank line as enforcement.
ISO-TP Bench Exercise
Run the transport with no vehicle attached. A vcan interface loops every frame back to each socket on it, so isotpsend and isotprecv on one machine complete a real segmented exchange; a CANable or PEAK adapter with a bench ECU or spare cluster gives the same exercise at 500 kbps with real timing. Done when the 20-byte PDU you reassembled by hand from the candump lines is byte-identical to the one isotpsniffer prints, and you can name the frames that carried padding.
Evidence Collection
A frame-level claim needs the interface it was seen on and the bytes as they arrived. Record:
Interface and bitrate:
The interface name, the programmed bitrate, and whether FD with BRS was on, taken from ip -details link show can0. A capture at the wrong bitrate still produces lines; they are error frames.
Identifiers and payloads: Each arbitration ID with its full payload, the PCI byte and any padding included, and whether the frame was standard or extended. Strip the PCI and the trace is no longer evidence of an ISO-TP exchange.
ISO-TP state: The declared N_PDU length from the First Frame, the Flow Control that answered it (FS, BS, STmin), and the sequence numbers of the Consecutive Frames. That is what separates a completed PDU from a truncated one.
Link-layer options:
For an FD exchange, the mtu, tx_dl and tx_flags the sending socket was configured with. The same request produces a different exchange at -L 72:64:1.
Capture hash: SHA-256 of the candump log kept beside the log itself. The timestamp in a candump -l file name is the only other provenance the format carries.
Derived or captured: Say which lines came from a vehicle or bench and which were constructed from the encoding rules. Several examples in this section are derived, and a derived frame presented as a capture is the easiest error to make and the hardest to spot later.
False Positive Identification
- A frame that never crossed your bus: A trace from another segment, or a forwarded copy behind the gateway. The identifier is on the wire you tapped only if the tap sat upstream of the filter.
-
Padding read as payload:
A declared PDU length of
0x14inside a frame whose DLC carries twenty-four bytes on the wire still means twenty payload bytes. Everything past the declared length is filler,0xCCby default. - A 62-byte Single Frame read as empty: The FD escape puts the real length in byte 1 and zero in the low nibble of byte 0. A parser written for classical CAN reports length zero and discards the twenty bytes that did arrive.
- DLC mistaken for a byte count: A ten-byte payload ships as twelve. A length taken from the DLC is two bytes long, and the error travels into whatever parses the result.
-
A Wait frame read as a bus fault:
A transfer that stops mid-way may be the receiver holding the sender with
FS=Wait. Read the trace for the0x31frame before blaming termination. -
TDC that was never applied:
Above a data-phase prescaler of 2 the automatic path clears both mode bits and returns without an error. A missing
TDC-AUTOin the dump is a driver or prescaler boundary, not a mistyped flag.
Interface And Exchange Checklist
Bring the interface up
- ☐ Set the bitrate before the interface comes up:
ip link set can0 type can bitrate 500000, then bring it up. - ☐ Keep the output of
ip -details -statistics link show can0: the error counters and the bitrate line are the control for every later measurement. - ☐ Choose classical or FD from the frame type of the answer, not of the request: a mismatch either fails at bind or silently drops the reply.
- ☐ Start the listener before the sender.
isotpdumpopened after the request misses the exchange it was meant to decode.
Read the exchange
- ☐ Reassemble at least one PDU by hand from the raw frames, then compare it with
isotpsnifferoutput. That is the check that the PCI decode is right. - ☐ Record the declared PDU length together with the DLC, and note which padding byte the peer uses before trimming anything.
- ☐ Test padding enforcement from a second interface or a second machine. One adapter looping back to itself tests
check_pad(), not the peer. - ☐ Note whether the reply came back in the same session or after a restart, since a bus-off drops the ISO-TP state as well as the transfer.