Skip to content

Commit dac7a0f

Browse files
SeppoTakalojhedberg
authored andcommitted
modem: cmux: Clean debugging a bit
Full CMUX frames are way too much to fill the debug log so disable those by default. Sometimes it is enough to see the CMD and response types, without hexdump. Added also debug messages for opening and closing events. Signed-off-by: Seppo Takalo <[email protected]>
1 parent f0f5f8c commit dac7a0f

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

subsys/modem/Kconfig

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,12 @@ module = MODEM_CMUX
5555
module-str = modem_cmux
5656
source "subsys/logging/Kconfig.template.log_config"
5757

58+
config MODEM_CMUX_LOG_FRAMES
59+
bool "Log CMUX frames"
60+
depends on MODEM_CMUX_LOG_LEVEL_DBG
61+
help
62+
Enable logging of CMUX frames. This can produce a lot of log data.
63+
5864
endif
5965

6066
config MODEM_PIPE

subsys/modem/modem_cmux.c

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ static struct modem_cmux_command *modem_cmux_command_wrap(const uint8_t *data)
101101
return (struct modem_cmux_command *)data;
102102
}
103103

104+
#if CONFIG_MODEM_CMUX_LOG_FRAMES
104105
static const char *modem_cmux_frame_type_to_str(enum modem_cmux_frame_types frame_type)
105106
{
106107
switch (frame_type) {
@@ -131,8 +132,14 @@ static void modem_cmux_log_frame(const struct modem_cmux_frame *frame,
131132
{
132133
LOG_DBG("%s ch:%u cr:%u pf:%u type:%s dlen:%u", action, frame->dlci_address,
133134
frame->cr, frame->pf, modem_cmux_frame_type_to_str(frame->type), frame->data_len);
134-
LOG_HEXDUMP_DBG(frame->data, hexdump_len, "data:");
135+
if (hexdump_len > 0) {
136+
LOG_HEXDUMP_DBG(frame->data, hexdump_len, "data:");
137+
}
135138
}
139+
#else
140+
#define modem_cmux_log_frame(frame, action, hexdump_len) \
141+
do { ARG_UNUSED(frame); ARG_UNUSED(action); ARG_UNUSED(hexdump_len); } while (0)
142+
#endif /* CONFIG_MODEM_CMUX_LOG_FRAMES */
136143

137144
static void modem_cmux_log_transmit_frame(const struct modem_cmux_frame *frame)
138145
{
@@ -225,14 +232,12 @@ static void modem_cmux_log_transmit_command(const struct modem_cmux_command *com
225232
{
226233
LOG_DBG("ea:%u,cr:%u,type:%s", command->type.ea, command->type.cr,
227234
modem_cmux_command_type_to_str(command->type.value));
228-
LOG_HEXDUMP_DBG(command->value, command->length.value, "data:");
229235
}
230236

231237
static void modem_cmux_log_received_command(const struct modem_cmux_command *command)
232238
{
233239
LOG_DBG("ea:%u,cr:%u,type:%s", command->type.ea, command->type.cr,
234240
modem_cmux_command_type_to_str(command->type.value));
235-
LOG_HEXDUMP_DBG(command->value, command->length.value, "data:");
236241
}
237242

238243
static void modem_cmux_raise_event(struct modem_cmux *cmux, enum modem_cmux_event event)
@@ -438,6 +443,7 @@ static void modem_cmux_on_cld_command(struct modem_cmux *cmux, struct modem_cmux
438443
k_work_cancel_delayable(&cmux->disconnect_work);
439444
}
440445

446+
LOG_DBG("CMUX disconnected");
441447
cmux->state = MODEM_CMUX_STATE_DISCONNECTED;
442448
k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER);
443449
cmux->flow_control_on = false;
@@ -455,6 +461,7 @@ static void modem_cmux_on_control_frame_ua(struct modem_cmux *cmux)
455461
return;
456462
}
457463

464+
LOG_DBG("CMUX connected");
458465
cmux->state = MODEM_CMUX_STATE_CONNECTED;
459466
k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER);
460467
cmux->flow_control_on = true;
@@ -534,6 +541,7 @@ static void modem_cmux_on_control_frame_sabm(struct modem_cmux *cmux)
534541
return;
535542
}
536543

544+
LOG_DBG("CMUX connection request received");
537545
cmux->state = MODEM_CMUX_STATE_CONNECTED;
538546
k_mutex_lock(&cmux->transmit_rb_lock, K_FOREVER);
539547
cmux->flow_control_on = true;
@@ -561,7 +569,7 @@ static void modem_cmux_on_control_frame(struct modem_cmux *cmux)
561569
break;
562570

563571
default:
564-
LOG_WRN("Unknown %s frame type", "control");
572+
LOG_WRN("Unknown %s frame type %d", "control", cmux->frame.type);
565573
break;
566574
}
567575
}
@@ -586,6 +594,7 @@ static void modem_cmux_on_dlci_frame_ua(struct modem_cmux_dlci *dlci)
586594
{
587595
switch (dlci->state) {
588596
case MODEM_CMUX_DLCI_STATE_OPENING:
597+
LOG_DBG("DLCI %u opened", dlci->dlci_address);
589598
dlci->state = MODEM_CMUX_DLCI_STATE_OPEN;
590599
modem_pipe_notify_opened(&dlci->pipe);
591600
k_work_cancel_delayable(&dlci->open_work);
@@ -595,6 +604,7 @@ static void modem_cmux_on_dlci_frame_ua(struct modem_cmux_dlci *dlci)
595604
break;
596605

597606
case MODEM_CMUX_DLCI_STATE_CLOSING:
607+
LOG_DBG("DLCI %u closed", dlci->dlci_address);
598608
dlci->state = MODEM_CMUX_DLCI_STATE_CLOSED;
599609
modem_pipe_notify_closed(&dlci->pipe);
600610
k_work_cancel_delayable(&dlci->close_work);
@@ -637,6 +647,7 @@ static void modem_cmux_on_dlci_frame_sabm(struct modem_cmux_dlci *dlci)
637647
return;
638648
}
639649

650+
LOG_DBG("DLCI %u SABM request accepted, DLCI opened", dlci->dlci_address);
640651
dlci->state = MODEM_CMUX_DLCI_STATE_OPEN;
641652
modem_pipe_notify_opened(&dlci->pipe);
642653
k_mutex_lock(&dlci->receive_rb_lock, K_FOREVER);
@@ -655,6 +666,7 @@ static void modem_cmux_on_dlci_frame_disc(struct modem_cmux_dlci *dlci)
655666
return;
656667
}
657668

669+
LOG_DBG("DLCI %u disconnected", dlci->dlci_address);
658670
dlci->state = MODEM_CMUX_DLCI_STATE_CLOSED;
659671
modem_pipe_notify_closed(&dlci->pipe);
660672
}
@@ -690,7 +702,8 @@ static void modem_cmux_on_dlci_frame(struct modem_cmux *cmux)
690702
break;
691703

692704
default:
693-
LOG_WRN("Unknown %s frame type", "DLCI");
705+
LOG_WRN("Unknown %s frame type (%d, DLCI %d)", "DLCI", cmux->frame.type,
706+
cmux->frame.dlci_address);
694707
break;
695708
}
696709
}

0 commit comments

Comments
 (0)