~/Rev_

ISO-TP in Userspace: Why I Didn't Use the Kernel's CAN_ISOTP Socket

Linux ships an ISO-TP socket. I wrote my own anyway, because a diagnostic tool has to see every frame, speak to many ECUs at once, and run the same way on adapters that aren't SocketCAN.

2026-11-15#D/Xcan
work: 15 Nov 2026 · Built (6 protocol tests + 13 end-to-end, in Rust) · D/Xcan, CAN, Protocols, Rust

The problem ISO-TP solves

A classic CAN frame carries 8 bytes. A VIN is 17, and a module's fault-code list can run to hundreds of bytes. ISO 15765-2 splits a message into a first frame (with the total length), then numbered consecutive frames, while the receiver paces the sender with flow control (block size and a minimum gap between frames).


Why not the kernel socket

CAN_ISOTP is fast and correct, but it gives you one conversation per socket, with the frames hidden. A scan tool needs three things it doesn't give me:

  • Functional requests: one broadcast to 0x7DF, and every ECU that answers sends its own multi-frame reply. That means reassembling several conversations at once, and sending flow control back to each ECU's physical address.
  • Tracing: every frame visible, for the log and for reverse engineering.
  • Portability: the same code drives the simulator and ELM327/OBDLink serial adapters, which aren't SocketCAN at all.

The design

  • A reassembler keyed by source ID, so interleaved replies from the engine and the transmission don't corrupt each other.
  • Sequence numbers wrap 0x0–0xF and are checked, so a dropped frame fails loudly instead of yielding silently corrupt data.
  • Flow-control wait frames reset the timer, overflow aborts, and STmin is honored in both its millisecond and 100-microsecond encodings.
  • Discovery filters to the diagnostic range (0x700–0x7FF). On a live bus, ordinary broadcast traffic would otherwise get parsed as ISO-TP garbage.

Tested frame by frame

The simulator speaks ISO-TP back. Its VIN reply is 20 bytes, so the test asserts that a flow-control frame actually went out. An airbag module that answers "response pending" (UDS NRC 0x78) before the real data exercises the wait path.


Lessons

  • Use the kernel when you own both ends of one conversation. A scan tool has many conversations at once and needs to see all of them.
  • Filter before you parse. Not everything on a bus is meant for you.
  • A test double that speaks the protocol catches far more than mocks of your own functions.

Sources: D/Xcan build-01, build-02 and build-05 (15 Nov 2026)