Skip to content

Commit cd82c20

Browse files
committed
samples: cellular: modem_shell: Fix printing of PDN events
Two PDN events were missing from a mapping table. Furthermore, if an event which was missing from the table was received, modem_shell crashed. Added the missing events and implemented mapping using similar approach which is used elsewhere in the sample, which handles missing items gracefully. TNSW-66408 Signed-off-by: Tommi Kangas <tommi.kangas@nordicsemi.no>
1 parent e9fd9ca commit cd82c20

File tree

1 file changed

+21
-10
lines changed

1 file changed

+21
-10
lines changed

samples/cellular/modem_shell/src/link/link_shell_pdn.c

+21-10
Original file line numberDiff line numberDiff line change
@@ -33,24 +33,35 @@ struct link_shell_pdn_info {
3333
uint8_t cid;
3434
};
3535

36-
static const char *const event_str[] = {
37-
[PDN_EVENT_CNEC_ESM] = "ESM",
38-
[PDN_EVENT_ACTIVATED] = "activated",
39-
[PDN_EVENT_DEACTIVATED] = "deactivated",
40-
[PDN_EVENT_IPV6_UP] = "IPv6 up",
41-
[PDN_EVENT_IPV6_DOWN] = "IPv6 down",
42-
[PDN_EVENT_NETWORK_DETACH] = "network detach",
43-
[PDN_EVENT_CTX_DESTROYED] = "context destroyed",
44-
};
36+
const char *link_pdn_event_to_string(enum pdn_event event, char *out_str_buf)
37+
{
38+
struct mapping_tbl_item const mapping_table[] = {
39+
/* PDN_EVENT_CNEC_ESM is handled separately */
40+
{ PDN_EVENT_ACTIVATED, "activated" },
41+
{ PDN_EVENT_DEACTIVATED, "deactivated" },
42+
{ PDN_EVENT_IPV6_UP, "IPv6 up" },
43+
{ PDN_EVENT_IPV6_DOWN, "IPv6 down" },
44+
{ PDN_EVENT_NETWORK_DETACH, "network detach" },
45+
{ PDN_EVENT_APN_RATE_CONTROL_ON, "APN rate control on" },
46+
{ PDN_EVENT_APN_RATE_CONTROL_OFF, "APN rate control off" },
47+
{ PDN_EVENT_CTX_DESTROYED, "context destroyed" },
48+
{ -1, NULL }
49+
};
50+
51+
return link_shell_map_to_string(mapping_table, event, out_str_buf);
52+
}
4553

4654
void link_pdn_event_handler(uint8_t cid, enum pdn_event event, int reason)
4755
{
56+
char str_buf[32];
57+
4858
switch (event) {
4959
case PDN_EVENT_CNEC_ESM:
5060
mosh_print("PDN event: PDP context %d, %s", cid, pdn_esm_strerror(reason));
5161
break;
5262
default:
53-
mosh_print("PDN event: PDP context %d %s", cid, event_str[event]);
63+
mosh_print("PDN event: PDP context %d %s", cid,
64+
link_pdn_event_to_string(event, str_buf));
5465
if (cid == 0) {
5566
#if defined(CONFIG_MOSH_STARTUP_CMDS)
5667
if (event == PDN_EVENT_ACTIVATED) {

0 commit comments

Comments
 (0)