/* * canbus_isotp.h * ISO-TP (ISO 15765-2) transport layer for CAN bus. * Handles multi-frame messaging (> 8 bytes) required by UDS and OBD-II. */ #pragma once #include #include #ifdef __cplusplus extern "C" { #endif typedef enum { ISOTP_OK = 0, ISOTP_TIMEOUT, ISOTP_OVERFLOW, ISOTP_ERROR, } isotp_status_t; /* * Send an ISO-TP message (blocking). * Handles Single Frame for len <= 7, or First Frame + Consecutive Frames. * Waits for Flow Control frame from receiver if multi-frame. * * tx_id: CAN arbitration ID for outgoing frames * rx_id: CAN arbitration ID for incoming Flow Control * data/len: payload to send * timeout_ms: max wait for Flow Control response */ isotp_status_t isotp_send(uint32_t tx_id, uint32_t rx_id, const uint8_t *data, size_t len, int timeout_ms); /* * Receive an ISO-TP message (blocking). * Reassembles Single Frame or First Frame + Consecutive Frames. * Sends Flow Control frame to sender if multi-frame. * * rx_id: CAN arbitration ID to listen for * buf/buf_cap: output buffer * out_len: actual received length * timeout_ms: max wait time */ isotp_status_t isotp_recv(uint32_t rx_id, uint8_t *buf, size_t buf_cap, size_t *out_len, int timeout_ms); /* * Request-Response: send then receive (most common UDS pattern). * Combines isotp_send() + isotp_recv() with proper FC handling. * * tx_id/rx_id: CAN ID pair (e.g. 0x7E0/0x7E8 for ECU diagnostics) */ isotp_status_t isotp_request(uint32_t tx_id, uint32_t rx_id, const uint8_t *req, size_t req_len, uint8_t *resp, size_t resp_cap, size_t *resp_len, int timeout_ms); /* * Install ISO-TP RX hook into the CAN driver callback chain. * Must be called after can_driver_set_rx_callback() so that the * previous callback (sniff/record) is preserved in the chain. */ void isotp_install_hook(void); #ifdef __cplusplus } #endif