diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2013-08-15 18:57:10 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2013-08-19 09:46:36 +0200 |
commit | 3f7f0be5fa1f18067dbcefb993b3cc7a5df0c4e2 (patch) | |
tree | 2820dcdbbb75ded9a34ecbb957a3fe4e513fdf79 | |
parent | d1a20b308292e27fbdbd0a7f1190adb9930a7dc3 (diff) |
huawei: improve ^NDISSTATQRY parser for newer firmware
Newer firmware for Huawei devices will not split the IPv4 and IPv6 info in
different lines for the ^NDISSTATQRY reply; instead they will be included in the
same line. E.g. instead of
^NDISSTATQRY: 1,,,IPV4
^NDISSTATQRY: 0,33,,IPV6
OK
We may have:
^NDISSTATQRY:0,,,"IPV4",0,33,,"IPV6"
Also note the optional spaces after the ':', and that in the new version the
strings are enclosed in double quotes.
https://bugzilla.gnome.org/show_bug.cgi?id=705339
-rw-r--r-- | plugins/huawei/mm-modem-helpers-huawei.c | 64 | ||||
-rw-r--r-- | plugins/huawei/tests/test-modem-helpers-huawei.c | 10 |
2 files changed, 46 insertions, 28 deletions
diff --git a/plugins/huawei/mm-modem-helpers-huawei.c b/plugins/huawei/mm-modem-helpers-huawei.c index d9b038df..f5abe579 100644 --- a/plugins/huawei/mm-modem-helpers-huawei.c +++ b/plugins/huawei/mm-modem-helpers-huawei.c @@ -46,40 +46,50 @@ mm_huawei_parse_ndisstatqry_response (const gchar *response, *ipv6_available = FALSE; /* The response maybe as: - * <CR><LF>^NDISSTATQRY: 1,,,IPV4<CR><LF>^NDISSTATQRY: 0,33,,IPV6<CR><LF> - * <CR><LF><CR><LF>OK<CR><LF> - * So we have to split the status for IPv4 and IPv6. For now, we only care - * about IPv4. + * ^NDISSTATQRY: 1,,,IPV4 + * ^NDISSTATQRY: 0,33,,IPV6 + * OK + * + * Or, in newer firmwares: + * ^NDISSTATQRY:0,,,"IPV4",0,,,"IPV6" + * OK */ - r = g_regex_new ("\\^NDISSTATQRY:\\s*(\\d),(.*),(.*),(.*)(\\r\\n)?", + r = g_regex_new ("\\^NDISSTATQRY:\\s*(\\d),([^,]*),([^,]*),([^,\\r\\n]*)(?:\\r\\n)?" + "(?:\\^NDISSTATQRY:)?\\s*,?(\\d)?,?([^,]*)?,?([^,]*)?,?([^,\\r\\n]*)?(?:\\r\\n)?", G_REGEX_DOLLAR_ENDONLY | G_REGEX_RAW, 0, NULL); g_assert (r != NULL); g_regex_match_full (r, response, strlen (response), 0, 0, &match_info, &inner_error); - while (!inner_error && g_match_info_matches (match_info)) { - gchar *ip_type_str; - guint connected; - - /* Read values */ - ip_type_str = mm_get_string_unquoted_from_match_info (match_info, 4); - if (!ip_type_str || - !mm_get_uint_from_match_info (match_info, 1, &connected) || - (connected != 0 && connected != 1)) { - inner_error = g_error_new (MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't parse ^NDISSTATQRY fields"); - } else if (g_ascii_strcasecmp (ip_type_str, "IPV4") == 0) { - *ipv4_available = TRUE; - *ipv4_connected = (gboolean)connected; - } else if (g_ascii_strcasecmp (ip_type_str, "IPV6") == 0) { - *ipv6_available = TRUE; - *ipv6_connected = (gboolean)connected; - } + if (!inner_error && g_match_info_matches (match_info)) { + guint ip_type_field = 4; + + /* IPv4 and IPv6 are fields 4 and (if available) 8 */ + + while (!inner_error && ip_type_field <= 8) { + gchar *ip_type_str; + guint connected; - g_free (ip_type_str); - if (!inner_error) - g_match_info_next (match_info, &inner_error); + ip_type_str = mm_get_string_unquoted_from_match_info (match_info, ip_type_field); + if (!ip_type_str) + break; + + if (!mm_get_uint_from_match_info (match_info, (ip_type_field - 3), &connected) || + (connected != 0 && connected != 1)) { + inner_error = g_error_new (MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't parse ^NDISSTATQRY fields"); + } else if (g_ascii_strcasecmp (ip_type_str, "IPV4") == 0) { + *ipv4_available = TRUE; + *ipv4_connected = (gboolean)connected; + } else if (g_ascii_strcasecmp (ip_type_str, "IPV6") == 0) { + *ipv6_available = TRUE; + *ipv6_connected = (gboolean)connected; + } + + g_free (ip_type_str); + ip_type_field += 4; + } } g_match_info_free (match_info); diff --git a/plugins/huawei/tests/test-modem-helpers-huawei.c b/plugins/huawei/tests/test-modem-helpers-huawei.c index c1bc0ed8..ea4cd956 100644 --- a/plugins/huawei/tests/test-modem-helpers-huawei.c +++ b/plugins/huawei/tests/test-modem-helpers-huawei.c @@ -55,7 +55,15 @@ static const NdisstatqryTest ndisstatqry_tests[] = { "^NDISSTATQRY: 1,,,IPV6", TRUE, FALSE, TRUE, TRUE }, { "^NDISSTATQRY: 0,,,IPV4\r\n" "^NDISSTATQRY: 0,,,IPV6", TRUE, FALSE, TRUE, FALSE }, - { NULL, FALSE, FALSE, FALSE, FALSE } + { "^NDISSTATQRY: 1,,,\"IPV4\",1,,,\"IPV6\"", TRUE, TRUE, TRUE, TRUE }, + { "^NDISSTATQRY: 1,,,\"IPV4\",0,,,\"IPV6\"", TRUE, TRUE, TRUE, FALSE }, + { "^NDISSTATQRY: 0,,,\"IPV4\",1,,,\"IPV6\"", TRUE, FALSE, TRUE, TRUE }, + { "^NDISSTATQRY: 0,,,\"IPV4\",0,,,\"IPV6\"", TRUE, FALSE, TRUE, FALSE }, + { "^NDISSTATQRY: 1,,,\"IPV4\",1,,,\"IPV6\"\r\n", TRUE, TRUE, TRUE, TRUE }, + { "^NDISSTATQRY: 1,,,\"IPV4\",0,,,\"IPV6\"\r\n", TRUE, TRUE, TRUE, FALSE }, + { "^NDISSTATQRY: 0,,,\"IPV4\",1,,,\"IPV6\"\r\n", TRUE, FALSE, TRUE, TRUE }, + { "^NDISSTATQRY: 0,,,\"IPV4\",0,,,\"IPV6\"\r\n", TRUE, FALSE, TRUE, FALSE }, + { NULL, FALSE, FALSE, FALSE, FALSE } }; static void |