Linux CAN drivers development
 help / color / mirror / Atom feed
* [PATCH v4 1/3] j1939: restrict amount of consecutive retransmission requests
@ 2026-07-06 22:41 Alexander Hölzl
  2026-07-06 22:41 ` [PATCH v4 2/3] j1939: fix implementation not handling holds correctly Alexander Hölzl
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Alexander Hölzl @ 2026-07-06 22:41 UTC (permalink / raw)
  To: o.rempel; +Cc: robin, linux-kernel, kernel, linux-can, Alexander Hölzl

In J1939 segmented messages the receiver of a segmented message
can request the retranmission of sent data frames. In the current
implementation there was no limit on the amount of consecutive
retransmission requests which were allowed. The standard states
that after two retransmission requests (so three transmissions
in total) the connection should be aborted with reason 5,
'maximum retransmit request limit reached'.
See SAE J1939-22 2025: 5.10.3.2 Connection Mode Clear to Send
and 5.12.3 Device Response Time and Timeout Defaults.

This commit introduces a retransmit counter and aborts the segmented
data transfer if the retransmit limit is reached.

Signed-off-by: Alexander Hölzl <alexander.hoelzl@gmx.net>
---
Hello,
sorry I was also a bit slow, I survived the heatwave now I can do
something again :)

I've added an additional commit to introduce the retransmit counting
as discussed in the previous review. I've added additional tests to
test the retransmit abort as well as the abort on requesting an 
already acked frame.
I've also renamed the tests from cts_hold to 
rx_cts as they now also test other parts of the rx_cts path so I though
they should have a more generic name.

I've added the comments and fixed the spelling mistakes, I hope I did
not add any new ones.

 net/can/j1939/j1939-priv.h |  2 ++
 net/can/j1939/transport.c  | 22 ++++++++++++++++++++++
 2 files changed, 24 insertions(+)

diff --git a/net/can/j1939/j1939-priv.h b/net/can/j1939/j1939-priv.h
index 81f58924b4ac..16867d803092 100644
--- a/net/can/j1939/j1939-priv.h
+++ b/net/can/j1939/j1939-priv.h
@@ -285,6 +285,8 @@ struct j1939_session {
 		unsigned int block;
 		/* dpo - ETP.CM_DPO, Data Packet Offset */
 		unsigned int dpo;
+		/* retransmits - amount of received retransmit requests (including holds) */
+		unsigned int retransmits;
 	} pkt;
 	struct hrtimer txtimer, rxtimer;
 };
diff --git a/net/can/j1939/transport.c b/net/can/j1939/transport.c
index df93d57907da..6f999b18bbca 100644
--- a/net/can/j1939/transport.c
+++ b/net/can/j1939/transport.c
@@ -32,6 +32,14 @@
 #define J1939_ETP_CMD_EOMA 0x17
 #define J1939_ETP_CMD_ABORT 0xff
 
+/* Maximum amount of transmission attempts for a given packet number to
+ * be sent. According to SAE J1939-21 2022 - 5.12.3 Device Response Time and
+ * Timeout Defaults there should be no more than 2 retries (3 requests in total)
+ * before the connection is aborted with reason 5 which corresponds to
+ * J1939_XTP_ABORT_FAULT in this implementation.
+ */
+#define J1939_CTS_MAX_NUM_TRANSMITS 3
+
 enum j1939_xtp_abort {
 	J1939_XTP_NO_ABORT = 0,
 	J1939_XTP_ABORT_BUSY = 1,
@@ -1457,6 +1465,19 @@ j1939_xtp_rx_cts_one(struct j1939_session *session, struct sk_buff *skb)
 	else if (dat[1] > session->pkt.block /* 0xff for etp */)
 		goto out_session_cancel;
 
+	/* If the 'next packet number to be sent' in the CTS is smaller or
+	 * equal to an already sent packet it is a retransmit request.
+	 */
+	if (session->pkt.tx >= pkt) {
+		session->pkt.retransmits++;
+		if (session->pkt.retransmits >= J1939_CTS_MAX_NUM_TRANSMITS) {
+			err = J1939_XTP_ABORT_FAULT;
+			goto out_session_cancel;
+		}
+	} else {
+		session->pkt.retransmits = 0;
+	}
+
 	/* set packet counters only when not CTS(0) */
 	session->pkt.tx_acked = pkt - 1;
 	j1939_session_skb_drop_old(session);
@@ -1669,6 +1690,7 @@ j1939_session *j1939_xtp_rx_rts_session_new(struct j1939_priv *priv,
 
 	session->pkt.rx = 0;
 	session->pkt.tx = 0;
+	session->pkt.retransmits = 0;
 
 	session->tskey = priv->rx_tskey++;
 	j1939_sk_errqueue(session, J1939_ERRQUEUE_RX_RTS);
-- 
2.55.0


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2026-07-06 22:58 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-07-06 22:41 [PATCH v4 1/3] j1939: restrict amount of consecutive retransmission requests Alexander Hölzl
2026-07-06 22:41 ` [PATCH v4 2/3] j1939: fix implementation not handling holds correctly Alexander Hölzl
2026-07-06 22:58   ` sashiko-bot
2026-07-06 22:41 ` [PATCH v4 3/3] j1939: add J1939 rx CTS tests Alexander Hölzl
2026-07-06 22:52   ` sashiko-bot
2026-07-06 22:58 ` [PATCH v4 1/3] j1939: restrict amount of consecutive retransmission requests sashiko-bot

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox