Skip to content

Commit ef0841e

Browse files
csanchezdllmarckleinebudde
authored andcommitted
can: slcan: allow reception of short error messages
Allows slcan to receive short messages (typically errors) from the serial interface. When error support was added to slcan protocol in b32ff46 ("can: slcan: extend the protocol with error info") the minimum valid message size changed from 5 (minimum standard can frame tIII0) to 3 ("e1a" is a valid protocol message, it is one of the examples given in the comments for slcan_bump_err() ), but the check for minimum message length prodicating all decoding was not adjusted. This makes short error messages discarded and error frames not being generated. This patch changes the minimum length to the new minimum (3 characters, excluding terminator, is now a valid message). Signed-off-by: Carlos Sanchez <[email protected]> Fixes: b32ff46 ("can: slcan: extend the protocol with error info") Reviewed-by: Vincent Mailhol <[email protected]> Link: https://patch.msgid.link/[email protected] Cc: [email protected] Signed-off-by: Marc Kleine-Budde <[email protected]>
1 parent be19a92 commit ef0841e

File tree

1 file changed

+20
-6
lines changed

1 file changed

+20
-6
lines changed

drivers/net/can/slcan/slcan-core.c

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,21 @@ MODULE_AUTHOR("Dario Binacchi <[email protected]>");
7171
#define SLCAN_CMD_LEN 1
7272
#define SLCAN_SFF_ID_LEN 3
7373
#define SLCAN_EFF_ID_LEN 8
74+
#define SLCAN_DATA_LENGTH_LEN 1
75+
#define SLCAN_ERROR_LEN 1
7476
#define SLCAN_STATE_LEN 1
7577
#define SLCAN_STATE_BE_RXCNT_LEN 3
7678
#define SLCAN_STATE_BE_TXCNT_LEN 3
77-
#define SLCAN_STATE_FRAME_LEN (1 + SLCAN_CMD_LEN + \
78-
SLCAN_STATE_BE_RXCNT_LEN + \
79-
SLCAN_STATE_BE_TXCNT_LEN)
79+
#define SLCAN_STATE_MSG_LEN (SLCAN_CMD_LEN + \
80+
SLCAN_STATE_LEN + \
81+
SLCAN_STATE_BE_RXCNT_LEN + \
82+
SLCAN_STATE_BE_TXCNT_LEN)
83+
#define SLCAN_ERROR_MSG_LEN_MIN (SLCAN_CMD_LEN + \
84+
SLCAN_ERROR_LEN + \
85+
SLCAN_DATA_LENGTH_LEN)
86+
#define SLCAN_FRAME_MSG_LEN_MIN (SLCAN_CMD_LEN + \
87+
SLCAN_SFF_ID_LEN + \
88+
SLCAN_DATA_LENGTH_LEN)
8089
struct slcan {
8190
struct can_priv can;
8291

@@ -176,6 +185,9 @@ static void slcan_bump_frame(struct slcan *sl)
176185
u32 tmpid;
177186
char *cmd = sl->rbuff;
178187

188+
if (sl->rcount < SLCAN_FRAME_MSG_LEN_MIN)
189+
return;
190+
179191
skb = alloc_can_skb(sl->dev, &cf);
180192
if (unlikely(!skb)) {
181193
sl->dev->stats.rx_dropped++;
@@ -281,7 +293,7 @@ static void slcan_bump_state(struct slcan *sl)
281293
return;
282294
}
283295

284-
if (state == sl->can.state || sl->rcount < SLCAN_STATE_FRAME_LEN)
296+
if (state == sl->can.state || sl->rcount != SLCAN_STATE_MSG_LEN)
285297
return;
286298

287299
cmd += SLCAN_STATE_BE_RXCNT_LEN + SLCAN_CMD_LEN + 1;
@@ -328,6 +340,9 @@ static void slcan_bump_err(struct slcan *sl)
328340
bool rx_errors = false, tx_errors = false, rx_over_errors = false;
329341
int i, len;
330342

343+
if (sl->rcount < SLCAN_ERROR_MSG_LEN_MIN)
344+
return;
345+
331346
/* get len from sanitized ASCII value */
332347
len = cmd[1];
333348
if (len >= '0' && len < '9')
@@ -456,8 +471,7 @@ static void slcan_bump(struct slcan *sl)
456471
static void slcan_unesc(struct slcan *sl, unsigned char s)
457472
{
458473
if ((s == '\r') || (s == '\a')) { /* CR or BEL ends the pdu */
459-
if (!test_and_clear_bit(SLF_ERROR, &sl->flags) &&
460-
sl->rcount > 4)
474+
if (!test_and_clear_bit(SLF_ERROR, &sl->flags))
461475
slcan_bump(sl);
462476

463477
sl->rcount = 0;

0 commit comments

Comments
 (0)