diff mbox series

[1/1] atmodem: sim: when reading sim files, avoid incomplete result lines

Message ID 20240507144618.33676-2-c.ronco@kerlink.fr (mailing list archive)
State Accepted
Commit 7802d80a9619c09a32eb488dc0297815d74cd1e2
Headers show
Series atmodem: sim: when reading sim files, avoid incomplete result lines | expand

Commit Message

Christophe Ronco May 7, 2024, 2:46 p.m. UTC
Modem ME310G1 sometimes add incomplete result lines to first AT+CRSM
command. Example:
AT+CRSM=192,12258
+CRSM: 0
+CRSM: 144,0,62178202412183022FE28A01058B032F06068002000A880110

OK

Parse all result lines starting with prefix until a line with at least sw1
and sw2 parameters is found.
---
 drivers/atmodem/sim.c | 16 ++++++++++++----
 1 file changed, 12 insertions(+), 4 deletions(-)
diff mbox series

Patch

diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index d75a09c2..1f63090b 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -107,6 +107,7 @@  static void get_response_common_cb(gboolean ok, GAtResult *result,
 	int str;
 	unsigned char access[3];
 	unsigned char file_status;
+	gboolean result_found = FALSE;
 
 	decode_at_error(&error, g_at_result_final_response(result));
 
@@ -117,11 +118,18 @@  static void get_response_common_cb(gboolean ok, GAtResult *result,
 
 	g_at_result_iter_init(&iter, result);
 
-	if (!g_at_result_iter_next(&iter, prefix))
-		goto error;
+	/* some Telit modems sometimes return incomplete result lines */
+	/* get first result line with mandatory parameters */
+	while (g_at_result_iter_next(&iter, prefix)) {
+		if (!g_at_result_iter_next_number(&iter, &sw1))
+			continue;
+		if (!g_at_result_iter_next_number(&iter, &sw2))
+			continue;
+		result_found = TRUE;
+	}
 
-	g_at_result_iter_next_number(&iter, &sw1);
-	g_at_result_iter_next_number(&iter, &sw2);
+	if (!result_found)
+		goto error;
 
 	if (!g_at_result_iter_next_hexstring(&iter, &response, &len) ||
 			(sw1 != 0x90 && sw1 != 0x91 && sw1 != 0x92) ||