diff options
author | Dan Williams <dcbw@redhat.com> | 2011-10-27 16:38:11 -0500 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2011-10-27 16:38:11 -0500 |
commit | 889ae2fb4bae97b174fc0088b15427b1d035abc6 (patch) | |
tree | 1a5c5888ca468a484bda77054941a7d19dbef0d6 | |
parent | ccad4aaa9d151537d6fa421d17d676409a6f688b (diff) |
gsm: fix parsing of unsolicited CREG/CGREG response with RAC
-rw-r--r-- | src/mm-modem-helpers.c | 48 | ||||
-rw-r--r-- | src/tests/test-modem-helpers.c | 11 |
2 files changed, 40 insertions, 19 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); diff --git a/src/tests/test-modem-helpers.c b/src/tests/test-modem-helpers.c index 866dfd9a..3b8e2e24 100644 --- a/src/tests/test-modem-helpers.c +++ b/src/tests/test-modem-helpers.c @@ -491,8 +491,9 @@ test_creg_match (const char *test, g_assert (data); g_assert (result); - g_print ("\nTesting %s +CREG %s response...\n", + g_print ("\nTesting %s +C%sREG %s response...\n", test, + result->cgreg ? "G" : "", solicited ? "solicited" : "unsolicited"); array = solicited ? data->solicited_creg : data->unsolicited_creg; @@ -743,13 +744,13 @@ test_creg2_gobi_weird_solicited (void *f, gpointer d) } static void -test_creg2_unsolicited_with_rac (void *f, gpointer d) +test_cgreg2_unsolicited_with_rac (void *f, gpointer d) { TestData *data = (TestData *) d; const char *reply = "\r\n+CGREG: 1,\"1422\",\"00000142\",3,\"00\"\r\n"; - const CregResult result = { 1, 0x1422, 0x0142, 3, 8, FALSE }; + const CregResult result = { 1, 0x1422, 0x0142, 3, 8, TRUE }; - test_creg_match ("CREG=2 with RAC", FALSE, reply, data, &result); + test_creg_match ("CGREG=2 with RAC", FALSE, reply, data, &result); } static void @@ -1272,7 +1273,6 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_creg2_md400_unsolicited, data)); g_test_suite_add (suite, TESTCASE (test_creg2_s8500_wave_unsolicited, data)); g_test_suite_add (suite, TESTCASE (test_creg2_gobi_weird_solicited, data)); - g_test_suite_add (suite, TESTCASE (test_creg2_unsolicited_with_rac, data)); g_test_suite_add (suite, TESTCASE (test_cgreg1_solicited, data)); g_test_suite_add (suite, TESTCASE (test_cgreg1_unsolicited, data)); @@ -1280,6 +1280,7 @@ int main (int argc, char **argv) g_test_suite_add (suite, TESTCASE (test_cgreg2_f3607gw_unsolicited, data)); g_test_suite_add (suite, TESTCASE (test_cgreg2_md400_unsolicited, data)); g_test_suite_add (suite, TESTCASE (test_cgreg2_x220_unsolicited, data)); + g_test_suite_add (suite, TESTCASE (test_cgreg2_unsolicited_with_rac, data)); g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi_unsolicited, data)); g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi2_unsolicited, data)); |