ISOTP, race condition #100807
Unanswered
Sergey1560
asked this question in
General
ISOTP, race condition
#100807
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
Hello.
I think I found some kind of race condition in the isotp library.
What it looks like: when sending a packet larger than 7 bytes, the isotp_send function never returns. There is no return in blocking mode, and the callback is not called in non-blocking mode.
I ran several tests with different receivers on CAN BUS.
The sender in my case is an NRF52840 with a Zephyr v4.1.99-ff8f0c579eeb (Nordic SDK) .
There are two receivers (not simultaneously): a Linux host with the ISOTP kernel module and a host with STM32.
Sending data to a Linux host always worked, but on STM32 it always froze. сandump output shows that all packets were transmitted, but there was no return from the iso_send function.
For debugging, I added some messages to the isotp library code.
Here is the debug output when the Linux host receives data:
0x783 - sending ID
0x784 - FC ID
And log output:
Here is the debug output when data is received by the host with stm32:
Log output:
As you can see, all the data has been transferred, but the transfer hasn't completed.
The difference is in the sctx->tx_backlog variable, which is declared as uint8_t. In the case of stm32, the FC packet arrives significantly faster than from the Linux host, and the rx-callback function (send_can_rx_cb and send_process_fc) is called before send_can_tx_cb. As a result of the "sctx->tx_backlog--;" operation, sctx->tx_backlog becomes 255, and everything breaks.
Candump output shows that Linux responds with an FC packet in about 170 uS, while stm32 responds about 40 uS.
To fix the problem, I think it's enough to add a check before decrementing sctx->tx_backlog.
In the send_can_tx_cb (zephyr/subsys/canbus/isotp/isotp.c, line 765) function, replace the code:
with this:
In my case, this solved the problem.
It would be great if someone more experienced could take a look at this.
Beta Was this translation helpful? Give feedback.
All reactions