Re: [PATCH] can: isotp: implement N_Ar timeout handling for FC transmission

From: Oliver Hartkopp

Date: Thu Sep 03 2026 - 07:15:21 EST


Hi Wentian,

On 03.09.26 11:38, yewentian395 wrote:

Just a gentle ping on the frame_txtime addition to rxtimer you
mentioned. Happy to help with a patch if that saves you time.

This is my current patch which is sitting on my dev machine:

diff --git a/net/can/isotp.c b/net/can/isotp.c
index 130a0dbec78c..5119afc2f67d 100644
--- a/net/can/isotp.c
+++ b/net/can/isotp.c
@@ -125,10 +125,11 @@ MODULE_PARM_DESC(max_pdu_size, "maximum isotp pdu size (default "
#define ISOTP_FC_WT 1 /* wait */
#define ISOTP_FC_OVFLW 2 /* overflow */

#define ISOTP_FC_TIMEOUT 1 /* 1 sec */
#define ISOTP_ECHO_TIMEOUT 2 /* 2 secs */
+#define ISOTP_MAX_FRAME_TXTIME_NS (100 * NSEC_PER_MSEC) /* max N_Ar/N_As */

/* so->tx_result[so->tx_gen % ISOTP_TX_RESULT_SLOTS] holds the packed value
* (err << ISOTP_TX_RESULT_GEN_BITS | gen) for each tx generation slot, so it
* can be handled with a single READ_ONCE()/WRITE_ONCE() access.
*/
@@ -346,11 +347,12 @@ static int isotp_send_fc(struct sock *sk, int ae, u8 flowstatus)

/* reset last CF frame rx timestamp for rx stmin enforcement */
so->lastrxcf_tstamp = ktime_set(0, 0);

/* start rx timeout watchdog */
- hrtimer_start(&so->rxtimer, ktime_set(ISOTP_FC_TIMEOUT, 0),
+ hrtimer_start(&so->rxtimer,
+ ktime_set(ISOTP_FC_TIMEOUT, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
return 0;
}

static void isotp_rcv_skb(struct sk_buff *skb, struct sock *sk)
@@ -1304,11 +1306,11 @@ static int isotp_sendmsg(struct socket *sock, struct msghdr *msg, size_t size)
wake_up_interruptible(&so->wait);
return -EADDRNOTAVAIL;
}
/* WAIT_FIRST_FC for standard FF, else stays ISOTP_SENDING */
WRITE_ONCE(so->tx.state, new_state);
- hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, 0),
+ hrtimer_start(tx_hrt, ktime_set(hrtimer_sec, so->frame_txtime),
HRTIMER_MODE_REL_SOFT);
spin_unlock_bh(&so->rx_lock);

/* send the first or only CAN frame */
cf->flags = so->ll.tx_flags;
@@ -1711,10 +1713,12 @@ static int isotp_setsockopt_locked(struct socket *sock, int level, int optname,

/* check for frame_txtime changes (0 => no changes) */
if (so->opt.frame_txtime) {
if (so->opt.frame_txtime == CAN_ISOTP_FRAME_TXTIME_ZERO)
so->frame_txtime = 0;
+ else if (so->opt.frame_txtime > ISOTP_MAX_FRAME_TXTIME_NS)
+ return -EINVAL;
else
so->frame_txtime = so->opt.frame_txtime;
}
break;


But this patch will be part of a big chunk of patches to introduce the CAN XL support for ISO 15765-2 Ed.5 here:

https://github.com/hartkopp/canxl-isotp

And the latest patch set is here:
https://github.com/hartkopp/xl-isotp/tree/claude/can-isotp-patches-rebase-v3

There are currently stable fixes on the fly that always have impacts on the isotp code. An it is really annoying to rebase and rebase and rebase. Especially the code split(!) into different .c and .h files always has to be checked by hand. Therefore I'll wait for all the current stable patches to be landed in mainline and stable and then add this patch here to the series of cleanup and enhancement patches.

Best regards,
Oliver