gsm: fix parsing of unsolicited CREG/CGREG response with RAC

This commit is contained in:
Dan Williams
2011-10-27 16:38:11 -05:00
parent ccad4aaa9d
commit 889ae2fb4b
2 changed files with 40 additions and 19 deletions

View File

@@ -11,7 +11,7 @@
* GNU General Public License for more details: * GNU General Public License for more details:
* *
* Copyright (C) 2008 - 2009 Novell, Inc. * Copyright (C) 2008 - 2009 Novell, Inc.
* Copyright (C) 2009 - 2010 Red Hat, Inc. * Copyright (C) 2009 - 2011 Red Hat, Inc.
*/ */
#include <config.h> #include <config.h>
@@ -355,6 +355,20 @@ parse_uint (char *str, int base, glong nmin, glong nmax, gboolean *valid)
return *valid ? (guint) ret : 0; 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 gboolean
mm_gsm_parse_creg_response (GMatchInfo *info, mm_gsm_parse_creg_response (GMatchInfo *info,
guint32 *out_reg_state, guint32 *out_reg_state,
@@ -401,13 +415,8 @@ mm_gsm_parse_creg_response (GMatchInfo *info,
* CREG=2 (non-standard): +CREG: <n>,<stat>,<lac>,<ci> * CREG=2 (non-standard): +CREG: <n>,<stat>,<lac>,<ci>
*/ */
/* To distinguish, check length of the third match item. If it's /* Check if the third item is the LAC to distinguish the two cases */
* more than one digit or has quotes in it then it's a LAC and we if (item_is_lac_not_stat (info, 3)) {
* got the first format.
*/
str = g_match_info_fetch (info, 3);
if (str && (strchr (str, '"') || strlen (str) > 1)) {
g_free (str);
istat = 2; istat = 2;
ilac = 3; ilac = 3;
ici = 4; ici = 4;
@@ -418,12 +427,23 @@ mm_gsm_parse_creg_response (GMatchInfo *info,
ici = 5; ici = 5;
} }
} else if (n_matches == 7) { } else if (n_matches == 7) {
/* CREG=2 (non-standard): +CREG: <n>,<stat>,<lac>,<ci>,<AcT> */ /* 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; istat = 3;
ilac = 4; ilac = 4;
ici = 5; ici = 5;
iact = 6; iact = 6;
} }
}
/* Status */ /* Status */
str = g_match_info_fetch (info, istat); str = g_match_info_fetch (info, istat);

View File

@@ -491,8 +491,9 @@ test_creg_match (const char *test,
g_assert (data); g_assert (data);
g_assert (result); g_assert (result);
g_print ("\nTesting %s +CREG %s response...\n", g_print ("\nTesting %s +C%sREG %s response...\n",
test, test,
result->cgreg ? "G" : "",
solicited ? "solicited" : "unsolicited"); solicited ? "solicited" : "unsolicited");
array = solicited ? data->solicited_creg : data->unsolicited_creg; array = solicited ? data->solicited_creg : data->unsolicited_creg;
@@ -743,13 +744,13 @@ test_creg2_gobi_weird_solicited (void *f, gpointer d)
} }
static void static void
test_creg2_unsolicited_with_rac (void *f, gpointer d) test_cgreg2_unsolicited_with_rac (void *f, gpointer d)
{ {
TestData *data = (TestData *) d; TestData *data = (TestData *) d;
const char *reply = "\r\n+CGREG: 1,\"1422\",\"00000142\",3,\"00\"\r\n"; 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 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_md400_unsolicited, data));
g_test_suite_add (suite, TESTCASE (test_creg2_s8500_wave_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_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_solicited, data));
g_test_suite_add (suite, TESTCASE (test_cgreg1_unsolicited, 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_f3607gw_unsolicited, data));
g_test_suite_add (suite, TESTCASE (test_cgreg2_md400_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_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_multi_unsolicited, data));
g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi2_unsolicited, data)); g_test_suite_add (suite, TESTCASE (test_creg_cgreg_multi2_unsolicited, data));