Skip to content

Commit c2097f6

Browse files
tomi-fontrlubos
authored andcommitted
[nrf fromlist] drivers: modem_cellular: fix handling of +C*REG answers
`+C*REG:` may be received as AT read command answer or unsolicited notification. Their syntax differs, and even the overall parameter count varies depending on what `<n>` is used in the `AT+CEREG=` write command. To handle all cases properly, check the parameter count and the presence of the `<tac>` parameter (which is a string and thus begins with `"`) to figure out what is the position of `<stat>`. Signed-off-by: Tomi Fontanilles <[email protected]> (cherry picked from commit 46366b9a4330b18d1eb0210d001532c75a215885) Upstream PR #: 80512 Signed-off-by: Tomi Fontanilles <[email protected]>
1 parent 53f2704 commit c2097f6

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

drivers/modem/modem_cellular.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -454,10 +454,15 @@ static void modem_cellular_chat_on_cxreg(struct modem_chat *chat, char **argv, u
454454
struct modem_cellular_data *data = (struct modem_cellular_data *)user_data;
455455
enum cellular_registration_status registration_status = 0;
456456

457-
if (argc == 2) {
458-
registration_status = atoi(argv[1]);
459-
} else if (argc == 3 || argc == 6) {
457+
/* This receives both +C*REG? read command answers and unsolicited notifications.
458+
* Their syntax differs in that the former has one more parameter, <n>, which is first.
459+
*/
460+
if (argc >= 3 && argv[2][0] != '"') {
461+
/* +CEREG: <n>,<stat>[,<tac>[...]] */
460462
registration_status = atoi(argv[2]);
463+
} else if (argc >= 2) {
464+
/* +CEREG: <stat>[,<tac>[...]] */
465+
registration_status = atoi(argv[1]);
461466
} else {
462467
return;
463468
}
@@ -466,7 +471,7 @@ static void modem_cellular_chat_on_cxreg(struct modem_chat *chat, char **argv, u
466471
data->registration_status_gsm = registration_status;
467472
} else if (strcmp(argv[0], "+CGREG: ") == 0) {
468473
data->registration_status_gprs = registration_status;
469-
} else {
474+
} else { /* CEREG */
470475
data->registration_status_lte = registration_status;
471476
}
472477

0 commit comments

Comments
 (0)