#socket-can #iso-tp #can #iso-15762-2

socketcan-isotp

A common application of ISO-TP or ISO 15762-2 is for example Unified Diagnostic Services (UDS) used in automotive ECUs for diagnostics

5 releases (3 stable)

1.0.2 Jun 28, 2023
1.0.1 May 20, 2022
1.0.0 Aug 28, 2021
0.1.1 Feb 18, 2020
0.1.0 Dec 10, 2019

#3 in #iso-tp

Download history 1195/week @ 2025-09-16 1190/week @ 2025-09-23 1131/week @ 2025-09-30 1259/week @ 2025-10-07 1014/week @ 2025-10-14 864/week @ 2025-10-21 912/week @ 2025-10-28 771/week @ 2025-11-04 587/week @ 2025-11-11 1056/week @ 2025-11-18 624/week @ 2025-11-25 619/week @ 2025-12-02 406/week @ 2025-12-09 315/week @ 2025-12-16 111/week @ 2025-12-23 44/week @ 2025-12-30

969 downloads per month
Used in ecu_diagnostics

BSD-3-Clause

24KB
423 lines

📦✨ socketcan-isotp

Socketcan IsoTP Rust crate

Build Status crates.io crates.io

Docs

Built with 🦀

SocketCAN ISO-TP crate. Based on socketcan-rs and isotp.h.

The Linux kernel supports using CAN-devices through a network-like API. This crate allows easy access to this functionality without having to wrestle libc calls.

ISO-TP or ISO 15762-2 allows sending data packets that exceed the eight byte of a default CAN frame. A common application of ISO-TP is for example Unified Diagnostic Services (UDS) used in automotive ECUs for diagnostics.

can-isotp is an ISO-TP kernel module that takes care of handling the ISO-TP protocol. Instructions on how the can-isotp kernel module can be build and loaded can be found at https://github.com/hartkopp/can-isotp.

use socketcan_isotp::{self, IsoTpSocket, StandardId};

fn main() -> Result<(), socketcan_isotp::Error> {
    let mut tp_socket = IsoTpSocket::open(
        "vcan0",
        StandardId::new(0x123).expect("Invalid src id"),
        StandardId::new(0x321).expect("Invalid dst id"),
    )?;

    let buffer = tp_socket.read()?;
    println!("read {} bytes", buffer.len());

    for x in buffer {
        print!("{:X?} ", x);
    }

    println!("");

    Ok(())
}

Dev Setup

Setup Isotp Kernel Module: https://github.com/hartkopp/can-isotp

Setup virtual can interface.

sudo modprobe vcan && \
sudo ip link add dev vcan0 type vcan && \
sudo ip link set up vcan0

Dependencies

~2.5MB
~52K SLoC