feat(isotp): Add ISO-TP (ISO 15765-2) Protocol Component with Examples and Testing Infrastructure (IEC-296)#535
Conversation
7c48f74 to
9a7585f
Compare
9a7585f to
e201366
Compare
|
@Dazza0 Please take a look if you're interested in. 😄 |
|
The upstream code is not actively maintained and may even contain security issues: lishen2/isotp-c#36 I suggest we don't use git submodule but just directly copy the upstream source code and form our component. The proposed file structure could be: |
e201366 to
2d0a526
Compare
91019c3 to
b9d7f21
Compare
ac5dec3 to
08ddeaf
Compare
| static int isotp_send_flow_control(const IsoTpLink *link, uint8_t flow_status, uint8_t block_size, uint32_t st_min_us) | ||
| { | ||
| IsoTpCanMessage message; | ||
| (void)memset(&message, 0, sizeof(message)); |
Check warning
Code scanning / clang-tidy
Call to function 'memset' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memset_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] Warning
| /* setup message */ | ||
| message.as.single_frame.type = ISOTP_PCI_TYPE_SINGLE; | ||
| message.as.single_frame.SF_DL = (uint8_t)link->send_size; | ||
| (void)memcpy(message.as.single_frame.data, link->send_buffer, link->send_size); |
Check warning
Code scanning / clang-tidy
Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] Warning
| if (data_length > sizeof(message.as.consecutive_frame.data)) { | ||
| data_length = sizeof(message.as.consecutive_frame.data); | ||
| } | ||
| (void)memcpy(message.as.consecutive_frame.data, link->send_buffer + link->send_offset, data_length); |
Check warning
Code scanning / clang-tidy
Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] Warning
| } | ||
|
|
||
| /* copying data */ | ||
| (void)memcpy(link->receive_buffer, message->as.single_frame.data, message->as.single_frame.SF_DL); |
Check warning
Code scanning / clang-tidy
Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] Warning
| } | ||
|
|
||
| /* copying data */ | ||
| (void)memcpy(link->receive_buffer + link->receive_offset, message->as.consecutive_frame.data, remaining_bytes); |
Check warning
Code scanning / clang-tidy
Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] Warning
| /* copy into local buffer */ | ||
| link->send_size = size; | ||
| link->send_offset = 0; | ||
| (void)memcpy(link->send_buffer, payload, size); |
Check warning
Code scanning / clang-tidy
Call to function 'memcpy' is insecure as it does not provide security checks introduced in the C11 standard. Replace with analogous functions that support length arguments or provides boundary checks such as 'memcpy_s' in case of C11 [clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling] Warning
4e5c8e6 to
712f781
Compare
There was a problem hiding this comment.
Pull Request Overview
This PR introduces a complete ISO-TP (ISO 15765-2) protocol implementation for ESP-IDF, enabling transmission of data payloads up to 4095 bytes over CAN/TWAI networks with automatic segmentation and reassembly.
- Integrates the upstream
isotp-clibrary as a submodule with ESP-IDF-specific wrapper and configuration - Provides a high-level ESP-IDF API with non-blocking operations and ISR-based frame processing
- Includes comprehensive testing infrastructure and an echo example for demonstration
Reviewed Changes
Copilot reviewed 28 out of 29 changed files in this pull request and generated 6 comments.
Show a summary per file
| File | Description |
|---|---|
| esp_isotp/isotp-c/* | Complete isotp-c library files added as submodule content |
| esp_isotp/esp_isotp.h | ESP-IDF specific header providing high-level ISO-TP API |
| esp_isotp/esp_isotp.c | ESP-IDF wrapper implementation with TWAI integration |
| esp_isotp/CMakeLists.txt | Build configuration for the component |
| esp_isotp/Kconfig | Configuration options for ISO-TP protocol parameters |
| .idf_build_apps.toml | Added esp_isotp to build test configuration |
| .github/workflows/upload_component.yml | Added esp_isotp to upload workflow |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
712f781 to
c9aa27e
Compare
c9aa27e to
263dbba
Compare
Imported the isotp-c library code from a specific commit of 083709f57d8fc964e7ac5dd0c7ac7aef6364f156. https://github.com/lishen2/isotp-c https://github.com/SimonCahill/isotp-c
263dbba to
fce267a
Compare
Checklist
Required Items
Optional Items
Change Description
This PR introduces a complete ISO-TP (ISO 15765-2) protocol implementation for ESP-IDF, enabling standard-compliant communication over the CAN bus with payloads up to 4095 bytes.
This component integrates the lightweight
isotp-clibrary as a submodule and provides a straightforward ESP-IDF driver interface, handling the complexities of the ISO-TP state machine.echoexample with pytest for demonstrating basic send/receive.utils(CLI tools likeisotpsend/isotprecv) andota(firmware update over CAN).Features
esp_driver_twai.can-utilsfor easy testing and integration.isotp-clibrary via build-time patches.Structure
Protocal
Single Frame Transmission Sequence
Multi-frame Transmission Sequence
Dependencies
esp_driver_twaisupport)isotp-clibrary (included as a git submodule)Testing Status
can-utils(isotpsend/isotprecv).Known Limitations
isotp-clibrary is designed for a single transport link instance. To manage multiple, distinct ISO-TP communications, one would need to instantiate multipleesp_isotp_handle_thandles, each tied to a unique set of CAN IDs.Related