Skip to content

Commit

Permalink
modem: cmux: Simplify resync mechanism
Browse files Browse the repository at this point in the history
Some modems don't start sending resync flags as described in
3G TS 27.010 V2.0.0 5.2.5, which results in the CMUX being
stuck in resync mode for said modems.

This patch simplifies the resync mechanism to simply drop
invalid frames, and wait for atleast two consequtive frame
flags (stop+start).

Signed-off-by: Bjarki Arge Andreasen <[email protected]>
  • Loading branch information
bjarki-andreasen authored and carlescufi committed Jan 11, 2024
1 parent 06b5792 commit 3debfc8
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 42 deletions.
5 changes: 1 addition & 4 deletions include/zephyr/modem/cmux.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,7 @@ enum modem_cmux_state {

enum modem_cmux_receive_state {
MODEM_CMUX_RECEIVE_STATE_SOF = 0,
MODEM_CMUX_RECEIVE_STATE_RESYNC_0,
MODEM_CMUX_RECEIVE_STATE_RESYNC_1,
MODEM_CMUX_RECEIVE_STATE_RESYNC_2,
MODEM_CMUX_RECEIVE_STATE_RESYNC_3,
MODEM_CMUX_RECEIVE_STATE_RESYNC,
MODEM_CMUX_RECEIVE_STATE_ADDRESS,
MODEM_CMUX_RECEIVE_STATE_ADDRESS_CONT,
MODEM_CMUX_RECEIVE_STATE_CONTROL,
Expand Down
46 changes: 8 additions & 38 deletions subsys/modem/modem_cmux.c
Original file line number Diff line number Diff line change
Expand Up @@ -642,60 +642,30 @@ static void modem_cmux_on_frame(struct modem_cmux *cmux)
modem_cmux_on_dlci_frame(cmux);
}

static void modem_cmux_transmit_resync(struct modem_cmux *cmux)
{
static const uint8_t resync[3] = {0xF9, 0xF9, 0xF9};

modem_pipe_transmit(cmux->pipe, resync, sizeof(resync));
}

static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t byte)
{
uint8_t fcs;

switch (cmux->receive_state) {
case MODEM_CMUX_RECEIVE_STATE_SOF:
if (byte == 0xF9) {
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_ADDRESS;
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC;
break;
}

modem_cmux_transmit_resync(cmux);
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0;
break;

case MODEM_CMUX_RECEIVE_STATE_RESYNC_0:
if (byte == 0xF9) {
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_1;
}

break;

case MODEM_CMUX_RECEIVE_STATE_RESYNC_1:
if (byte == 0xF9) {
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_2;
} else {
modem_cmux_transmit_resync(cmux);
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0;
}

break;

case MODEM_CMUX_RECEIVE_STATE_RESYNC_2:
if (byte == 0xF9) {
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_3;
} else {
modem_cmux_transmit_resync(cmux);
cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_RESYNC_0;
}

break;

case MODEM_CMUX_RECEIVE_STATE_RESYNC_3:
case MODEM_CMUX_RECEIVE_STATE_RESYNC:
/*
* Allow any number of consequtive flags (0xF9).
* 0xF9 could also be a valid address field for DLCI 62.
*/
if (byte == 0xF9) {
break;
}

__fallthrough;

case MODEM_CMUX_RECEIVE_STATE_ADDRESS:
/* Initialize */
cmux->receive_buf_len = 0;
Expand Down

0 comments on commit 3debfc8

Please sign in to comment.