Skip to content

Commit f380fcc

Browse files
tomi-fontmmahadevan108
authored andcommitted
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]>
1 parent a30e41f commit f380fcc

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
@@ -460,10 +460,15 @@ static void modem_cellular_chat_on_cxreg(struct modem_chat *chat, char **argv, u
460460
struct modem_cellular_data *data = (struct modem_cellular_data *)user_data;
461461
enum cellular_registration_status registration_status = 0;
462462

463-
if (argc == 2) {
464-
registration_status = atoi(argv[1]);
465-
} else if (argc == 3 || argc == 6) {
463+
/* This receives both +C*REG? read command answers and unsolicited notifications.
464+
* Their syntax differs in that the former has one more parameter, <n>, which is first.
465+
*/
466+
if (argc >= 3 && argv[2][0] != '"') {
467+
/* +CEREG: <n>,<stat>[,<tac>[...]] */
466468
registration_status = atoi(argv[2]);
469+
} else if (argc >= 2) {
470+
/* +CEREG: <stat>[,<tac>[...]] */
471+
registration_status = atoi(argv[1]);
467472
} else {
468473
return;
469474
}
@@ -472,7 +477,7 @@ static void modem_cellular_chat_on_cxreg(struct modem_chat *chat, char **argv, u
472477
data->registration_status_gsm = registration_status;
473478
} else if (strcmp(argv[0], "+CGREG: ") == 0) {
474479
data->registration_status_gprs = registration_status;
475-
} else {
480+
} else { /* CEREG */
476481
data->registration_status_lte = registration_status;
477482
}
478483

0 commit comments

Comments
 (0)