From e7805f8d721ce12488cd4b42ceda9299281e25e2 Mon Sep 17 00:00:00 2001 From: Tomi Fontanilles Date: Tue, 19 Mar 2024 08:33:34 +0200 Subject: [PATCH] modem: cmux: improve frame debug logging - Add the frame data length to the frame header log. - Log the dropped frames as well. Signed-off-by: Tomi Fontanilles --- subsys/modem/modem_cmux.c | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/subsys/modem/modem_cmux.c b/subsys/modem/modem_cmux.c index 0f77a8d59a5..6fdc1e52841 100644 --- a/subsys/modem/modem_cmux.c +++ b/subsys/modem/modem_cmux.c @@ -126,18 +126,22 @@ static const char *modem_cmux_frame_type_to_str(enum modem_cmux_frame_types fram return ""; } +static void modem_cmux_log_frame(const struct modem_cmux_frame *frame, + const char *action, size_t hexdump_len) +{ + LOG_DBG("%s ch:%u cr:%u pf:%u type:%s dlen:%u", action, frame->dlci_address, + frame->cr, frame->pf, modem_cmux_frame_type_to_str(frame->type), frame->data_len); + LOG_HEXDUMP_DBG(frame->data, hexdump_len, "data:"); +} + static void modem_cmux_log_transmit_frame(const struct modem_cmux_frame *frame) { - LOG_DBG("ch:%u,cr:%u,pf:%u,type:%s", frame->dlci_address, frame->cr, frame->pf, - modem_cmux_frame_type_to_str(frame->type)); - LOG_HEXDUMP_DBG(frame->data, frame->data_len, "data:"); + modem_cmux_log_frame(frame, "tx", frame->data_len); } static void modem_cmux_log_received_frame(const struct modem_cmux_frame *frame) { - LOG_DBG("ch:%u,cr:%u,pf:%u,type:%s", frame->dlci_address, frame->cr, frame->pf, - modem_cmux_frame_type_to_str(frame->type)); - LOG_HEXDUMP_DBG(frame->data, frame->data_len, "data:"); + modem_cmux_log_frame(frame, "rcvd", frame->data_len); } static const char *modem_cmux_command_type_to_str(enum modem_cmux_command_types command_type) @@ -652,6 +656,19 @@ static void modem_cmux_on_frame(struct modem_cmux *cmux) } } +static void modem_cmux_drop_frame(struct modem_cmux *cmux) +{ + LOG_WRN("Dropped frame"); + cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_SOF; + +#if defined(CONFIG_MODEM_CMUX_LOG_LEVEL_DBG) + struct modem_cmux_frame *frame = &cmux->frame; + + frame->data = cmux->receive_buf; + modem_cmux_log_frame(frame, "dropped", MIN(frame->data_len, cmux->receive_buf_size)); +#endif +} + static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t byte) { uint8_t fcs; @@ -797,15 +814,14 @@ static void modem_cmux_process_received_byte(struct modem_cmux *cmux, uint8_t by break; case MODEM_CMUX_RECEIVE_STATE_DROP: - LOG_WRN("Dropped frame"); - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_SOF; + modem_cmux_drop_frame(cmux); break; case MODEM_CMUX_RECEIVE_STATE_EOF: /* Validate byte is EOF */ if (byte != 0xF9) { /* Unexpected byte */ - cmux->receive_state = MODEM_CMUX_RECEIVE_STATE_SOF; + modem_cmux_drop_frame(cmux); break; }