How linux-can/can-utils works
Project type and purpose
• This is an open-source collection of userspace CLI utilities (c-written) for interacting with the Linux CAN (SocketCAN) subsystem.
• Purpose: display, record, generate, replay, and bridge CAN traffic; provide measurement/test tools; support ISO-TP, J1939 protocols; configure serial-to-CAN (“slcan”) interfaces.
File structure
• Top level: CMakeLists.txt, Makefile, individual .c/.h files, utility subdirectories (calc-bit-timing, isobusfs, j1939_timedate, j1939_vehicle_position, mcp251xfd).
• /: shared headers for CAN and other protocols.
• cmake/: toolchain cross-compile configs.
• .github/workflows/: CI build and static analysis.
• Licenses, style guides, build scripts (check_cc.sh).
Extract insights from README
• Utilities are grouped by functionality: basic CAN tools, IP-socket CAN, in-kernel gateway config, bus measurement/testing, ISO-TP, J1939/ISOBus, log converters, serial line config.
• Mentions external projects: socketcand, cannelloni.
• Build instructions use CMake, support Android, Raspberry Pi, cross-compiling.
Main components
a. External environment:
– Physical CAN bus (CAN transceiver, CAN hardware).
– Serial interface (slcan adapter/line discipline).
– IP network (for socketcand/cannelloni or isotpserver).
b. Kernel layers:
– CAN network stack (CAN_RAW, BCM, ISO-TP, SOC_J1939 sockets).
– slcan line discipline driver.
– J1939 kernel module.
c. Userspace libraries:
– lib.c, lib.h (common routines).
– libj1939.c, libj1939.h (J1939 helper functions).
d. Build system:
– CMake toolchain files, Makefile, GitHub CI workflows.
– Basic tools: candump, canplayer, cansend, cangen, cansequence, cansniffer.
– Gateway config: cangw (netlink).
– Bus measurement: canbusload, calc-bit-timing, canfdtest, canerrsim.
– ISO-TP: isotpsend/recv/sniffer/dump, isotpserver, isotpperf, isotptun.
– J1939: j1939acd, j1939cat, j1939spy, j1939sr, testj1939 (use SOC_J1939).
– Log converters: asc2log, log2asc, log2long.
– SLCAN: slcan_attach, slcand, slcanpty.
– Special sub-projects: isobusfs, j1939_timedate, j1939_vehicle_position, mcp251xfd (show these as separate functional clusters with their own source directories).
Relationships and interactions
• Utilities open specific socket types (CAN_RAW, BCM, ISO-TP, SOC_J1939) to send/receive frames via the kernel.
• slcan tools bind a serial line to a virtual CAN network interface.
• isotpserver and socketcand bridge between CAN and TCP/IP.
• cangw uses netlink to configure in-kernel CAN gateway.
• Shared code (lib.c/libj1939) is linked into each utility.
• The build system compiles each .c into separate executables and installs headers/libraries.
Important architectural patterns
• Layered architecture: Physical CAN → Kernel drivers/stacks → Shared libraries → CLI utilities.
• Modular CLI tools: each utility is its own component, reusing common libs.
• Extensibility: subdirectories (calc-bit-timing, mcp251xfd, isobusfs, etc.) represent optional modules.
Final checklist
• All major utilities and sub-projects represented.
• Kernel interfaces clearly labeled.
• Build system and CI shown as separate supporting component.