modem: cmux: Simplify resync mechanism

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 <bjarki@arge-andreasen.me>
This commit is contained in:
Bjarki Arge Andreasen 2024-01-09 15:13:57 +01:00 committed by Carles Cufí
parent 06b57926a2
commit 3debfc8c8d
2 changed files with 9 additions and 42 deletions

View file

@ -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,

View file

@ -642,13 +642,6 @@ 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;
@ -656,46 +649,23 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by
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;