Skip to content

Commit 0ae18a8

Browse files
Zhang Changzhongmarckleinebudde
Zhang Changzhong
authored andcommitted
can: j1939: add rxtimer for multipacket broadcast session
According to SAE J1939/21 (Chapter 5.12.3 and APPENDIX C), for transmit side the required time interval between packets of a multipacket broadcast message is 50 to 200 ms, the responder shall use a timeout of 250ms (provides margin allowing for the maximumm spacing of 200ms). For receive side a timeout will occur when a time of greater than 750 ms elapsed between two message packets when more packets were expected. So this patch fix and add rxtimer for multipacket broadcast session. Fixes: 9d71dd0 ("can: add support of SAE J1939 protocol") Signed-off-by: Zhang Changzhong <[email protected]> Link: https://lore.kernel.org/r/[email protected] Acked-by: Oleksij Rempel <[email protected]> Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent 2b8b2e3 commit 0ae18a8

File tree

1 file changed

+20
-8
lines changed

1 file changed

+20
-8
lines changed

net/can/j1939/transport.c

+20-8
Original file line numberDiff line numberDiff line change
@@ -723,10 +723,12 @@ static int j1939_session_tx_rts(struct j1939_session *session)
723723
return ret;
724724

725725
session->last_txcmd = dat[0];
726-
if (dat[0] == J1939_TP_CMD_BAM)
726+
if (dat[0] == J1939_TP_CMD_BAM) {
727727
j1939_tp_schedule_txtimer(session, 50);
728-
729-
j1939_tp_set_rxtimeout(session, 1250);
728+
j1939_tp_set_rxtimeout(session, 250);
729+
} else {
730+
j1939_tp_set_rxtimeout(session, 1250);
731+
}
730732

731733
netdev_dbg(session->priv->ndev, "%s: 0x%p\n", __func__, session);
732734

@@ -1687,11 +1689,15 @@ static void j1939_xtp_rx_rts(struct j1939_priv *priv, struct sk_buff *skb,
16871689
}
16881690
session->last_cmd = cmd;
16891691

1690-
j1939_tp_set_rxtimeout(session, 1250);
1691-
1692-
if (cmd != J1939_TP_CMD_BAM && !session->transmission) {
1693-
j1939_session_txtimer_cancel(session);
1694-
j1939_tp_schedule_txtimer(session, 0);
1692+
if (cmd == J1939_TP_CMD_BAM) {
1693+
if (!session->transmission)
1694+
j1939_tp_set_rxtimeout(session, 750);
1695+
} else {
1696+
if (!session->transmission) {
1697+
j1939_session_txtimer_cancel(session);
1698+
j1939_tp_schedule_txtimer(session, 0);
1699+
}
1700+
j1939_tp_set_rxtimeout(session, 1250);
16951701
}
16961702

16971703
j1939_session_put(session);
@@ -1742,6 +1748,7 @@ static void j1939_xtp_rx_dat_one(struct j1939_session *session,
17421748
int offset;
17431749
int nbytes;
17441750
bool final = false;
1751+
bool remain = false;
17451752
bool do_cts_eoma = false;
17461753
int packet;
17471754

@@ -1817,6 +1824,8 @@ static void j1939_xtp_rx_dat_one(struct j1939_session *session,
18171824
j1939_cb_is_broadcast(&session->skcb)) {
18181825
if (session->pkt.rx >= session->pkt.total)
18191826
final = true;
1827+
else
1828+
remain = true;
18201829
} else {
18211830
/* never final, an EOMA must follow */
18221831
if (session->pkt.rx >= session->pkt.last)
@@ -1826,6 +1835,9 @@ static void j1939_xtp_rx_dat_one(struct j1939_session *session,
18261835
if (final) {
18271836
j1939_session_timers_cancel(session);
18281837
j1939_session_completed(session);
1838+
} else if (remain) {
1839+
if (!session->transmission)
1840+
j1939_tp_set_rxtimeout(session, 750);
18291841
} else if (do_cts_eoma) {
18301842
j1939_tp_set_rxtimeout(session, 1250);
18311843
if (!session->transmission)

0 commit comments

Comments
 (0)