aboutsummaryrefslogtreecommitdiff
path: root/src/mm-modem-helpers.c
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2011-10-27 16:38:11 -0500
committerDan Williams <dcbw@redhat.com>2011-10-27 16:38:11 -0500
commit889ae2fb4bae97b174fc0088b15427b1d035abc6 (patch)
tree1a5c5888ca468a484bda77054941a7d19dbef0d6 /src/mm-modem-helpers.c
parentccad4aaa9d151537d6fa421d17d676409a6f688b (diff)
gsm: fix parsing of unsolicited CREG/CGREG response with RAC
Diffstat (limited to 'src/mm-modem-helpers.c')
-rw-r--r--src/mm-modem-helpers.c48
1 files changed, 34 insertions, 14 deletions
diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c
index 078a671e..0bf62378 100644
--- a/src/mm-modem-helpers.c
+++ b/src/mm-modem-helpers.c
@@ -11,7 +11,7 @@
* GNU General Public License for more details:
*
* Copyright (C) 2008 - 2009 Novell, Inc.
- * Copyright (C) 2009 - 2010 Red Hat, Inc.
+ * Copyright (C) 2009 - 2011 Red Hat, Inc.
*/
#include <config.h>
@@ -355,6 +355,20 @@ parse_uint (char *str, int base, glong nmin, glong nmax, gboolean *valid)
return *valid ? (guint) ret : 0;
}
+static gboolean
+item_is_lac_not_stat (GMatchInfo *info, guint32 item)
+{
+ char *str;
+ gboolean is_lac = FALSE;
+
+ /* A <stat> will always be a single digit, without quotes */
+ str = g_match_info_fetch (info, item);
+ g_assert (str);
+ is_lac = (strchr (str, '"') || strlen (str) > 1);
+ g_free (str);
+ return is_lac;
+}
+
gboolean
mm_gsm_parse_creg_response (GMatchInfo *info,
guint32 *out_reg_state,
@@ -401,13 +415,8 @@ mm_gsm_parse_creg_response (GMatchInfo *info,
* CREG=2 (non-standard): +CREG: <n>,<stat>,<lac>,<ci>
*/
- /* To distinguish, check length of the third match item. If it's
- * more than one digit or has quotes in it then it's a LAC and we
- * got the first format.
- */
- str = g_match_info_fetch (info, 3);
- if (str && (strchr (str, '"') || strlen (str) > 1)) {
- g_free (str);
+ /* Check if the third item is the LAC to distinguish the two cases */
+ if (item_is_lac_not_stat (info, 3)) {
istat = 2;
ilac = 3;
ici = 4;
@@ -418,12 +427,23 @@ mm_gsm_parse_creg_response (GMatchInfo *info,
ici = 5;
}
} else if (n_matches == 7) {
- /* CREG=2 (non-standard): +CREG: <n>,<stat>,<lac>,<ci>,<AcT> */
- istat = 3;
- ilac = 4;
- ici = 5;
- iact = 6;
- }
+ /* CREG=2 (solicited): +CREG: <n>,<stat>,<lac>,<ci>,<AcT>
+ * CREG=2 (unsolicited with RAC): +CREG: <stat>,<lac>,<ci>,<AcT>,<RAC>
+ */
+
+ /* Check if the third item is the LAC to distinguish the two cases */
+ if (item_is_lac_not_stat (info, 3)) {
+ istat = 2;
+ ilac = 3;
+ ici = 4;
+ iact = 5;
+ } else {
+ istat = 3;
+ ilac = 4;
+ ici = 5;
+ iact = 6;
+ }
+ }
/* Status */
str = g_match_info_fetch (info, istat);