Workshop

Build your bench, and go further

Enough to move from reading to practice: a virtual CAN bus, the commands that matter, the vocabulary, and where to go next.

A CAN bench without a car

You don't need a vehicle to get started. Linux ships with SocketCAN; a virtual vcan interface behaves like a real bus, and the ICSim simulator provides a dashboard to drive.

Create a virtual CAN bus (Linux, SocketCAN)
sudo modprobe vcan
sudo ip link add dev vcan0 type vcan
sudo ip link set up vcan0
Launch the ICSim simulator
./icsim vcan0        # the simulated dashboard
./controls vcan0     # the controller that generates the traffic

Reproduce it for real

The virtual bench is enough to learn the method; copper makes it concrete. Four builds, from the simplest at fifteen euros to the most striking for a demo, all documented and reproducible.

From a toy bench to a cluster that lights up
BuildHardwareWhat it reproduces
Two-node bench2 Arduino or ESP32, 2 transceivers (MCP2515 or native TWAI), 2 resistors of 120 ohmsThe heart of reversing: one node sends, the other listens. Sniff, diff, inject.
ESP32 bridge1 ESP32 with ESP32RET or CANMIMCapture, replay and man-in-the-middle on a real bus, driven from the PC (SavvyCAN).
Raspberry Pi + CAN-HAT1 Raspberry Pi, 1 CAN hat (PiCAN, Waveshare)The same candump / cansend as the Workshop, but on a physical can0 interface.
Real instrument clusterA scrapyard cluster, a power supply, a terminated busThe needles move for real when you forge the frames. The demo that sticks.
  • Wiring: CAN-H to CAN-H, CAN-L to CAN-L, and a 120 ohm resistor at each end of the bus.
  • The classic trap: many MCP2515 modules use an 8 MHz crystal, not 16. If the clock does not match, the bus stays silent.
  • Bit rate: most examples run at 250 or 500 kbit/s, and both nodes must be set the same.

The bridge to this site: a Raspberry Pi with a CAN-HAT exposes a real SocketCAN interface. Every command shown above works unchanged, and ICSim runs on it with no modification.

Move ICSim from the virtual bus to a real CAN interface
sudo ip link set can0 type can bitrate 500000
sudo ip link set up can0
./icsim can0        # the same cluster, on the physical bus
./controls can0

can-utils cheat sheet

The everyday commands
CommandWhat it does
candump vcan0Show every frame on the bus live.
candump -l vcan0Log to a file (candump-*.log) for replay.
canplayer -I file.logReplay a recording exactly as captured.
cansend vcan0 123#DEADBEEFSend a frame: identifier 0x123, data DE AD BE EF.
cangen vcan0 -I i -L 8 -D rGenerate random frames: load and fuzzing.
cansniffer vcan0A view grouped by identifier, with changing bytes highlighted.
cansend vcan0 000#0000000000000000Hammer identifier 0: an illustration of a denial of service.

Glossary

ECU
One of the vehicle's computers: engine, braking, cabin, and so on.
Frame
The unit of data transmitted on the bus: one identifier and up to eight bytes.
Identifier (CAN ID)
The field that describes a frame's contents and sets its arbitration priority.
ISO-TP
The transport layer (ISO 15765-2) that segments messages longer than eight bytes.
UDS
Standardised diagnostic services (ISO 14229), on top of the bus.
DoIP
Diagnostics over IP (ISO 13400): diagnostics carried by Ethernet.
SecOC
Secure Onboard Communication: authenticates messages (a MAC and a freshness counter).
DTC
Diagnostic Trouble Code: a fault code recorded by an ECU.
PID (OBD)
Parameter ID: the identifier of a standard value readable through the OBD-II port.
CAN-FD
An evolution of CAN: a higher bit rate and up to 64 data bytes per frame.
Bus-off
The state in which a node disconnects itself after too many errors.

To go further