diff options
-rw-r--r-- | introspection/mm-modem-gsm-network.xml | 2 | ||||
-rw-r--r-- | src/mm-generic-gsm.c | 62 | ||||
-rwxr-xr-x | test/mm-test.py | 26 |
3 files changed, 77 insertions, 13 deletions
diff --git a/introspection/mm-modem-gsm-network.xml b/introspection/mm-modem-gsm-network.xml index 84742591..934e8e0b 100644 --- a/introspection/mm-modem-gsm-network.xml +++ b/introspection/mm-modem-gsm-network.xml @@ -23,7 +23,7 @@ <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_scan"/> <arg name="results" type="aa{ss}" direction="out"> <tp:docstring> - Found networks. It's an array of dictionaries (strings for keys and values), the list of known keys is the following: status, operator-long, operator-short, operator-num. + Found networks. It's an array of dictionaries (strings for keys and values), the list of known keys is the following: status, operator-long, operator-short, operator-num, access-tech. </tp:docstring> </arg> </method> diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c index a63c33a8..ac78e12b 100644 --- a/src/mm-generic-gsm.c +++ b/src/mm-generic-gsm.c @@ -1132,21 +1132,27 @@ scan_done (MMSerialPort *port, GRegex *r; GMatchInfo *match_info; GError *err = NULL; + gboolean umts_format = TRUE; reply = strstr (reply, "+COPS: ") + 7; /* Pattern without crazy escaping using | for matching: (|\d|,"|.+|","|.+|","|.+|"\)?,|\d|) */ - /* Quirk: Sony-Ericsson TM-506 sometimes includes a stray ')' like so: + /* Cell access technology (GSM, UTRAN, etc) got added later and not all + * modems implement it. Some modesm have quirks that make it hard to + * use one regular experession for matching both pre-UMTS and UMTS + * responses. So try UMTS-format first and fall back to pre-UMTS if + * we get no UMTS-formst matches. + */ + + /* Quirk: Sony-Ericsson TM-506 sometimes includes a stray ')' like so, + * which is what makes it hard to match both pre-UMTS and UMTS in + * the same regex: * * +COPS: (2,"","T-Mobile","31026",0),(1,"AT&T","AT&T","310410"),0) - * - * Quirk: Motorola C-series (BUSlink SCWi275u) don't include the operator - * number, like so: - * - * +COPS: (2,"T-Mobile","","310260"),(0,"Cingular Wireless","","310410") */ - r = g_regex_new ("\\((\\d),\"(.*)\",\"(.*)\",\"(.*)\"\\)?[,]?[(\\d)]?\\)", G_REGEX_UNGREEDY, 0, &err); + + r = g_regex_new ("\\((\\d),\"(.*)\",\"(.*)\",\"(.*)\"[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &err); if (err) { g_error ("Invalid regular expression: %s", err->message); g_error_free (err); @@ -1155,11 +1161,39 @@ scan_done (MMSerialPort *port, goto out; } - results = g_ptr_array_new (); + /* If we didn't get any hits, try the pre-UMTS format match */ + if (!g_regex_match (r, reply, 0, &match_info)) { + g_regex_unref (r); + if (match_info) { + g_match_info_free (match_info); + match_info = NULL; + } + + /* Pre-UMTS format doesn't include the cell access technology after + * the numeric operator element. + * + * Ex: Motorola C-series (BUSlink SCWi275u) like so: + * + * +COPS: (2,"T-Mobile","","310260"),(0,"Cingular Wireless","","310410") + */ + r = g_regex_new ("\\((\\d),\"(.*)\",\"(.*)\",\"(.*)\"\\)", G_REGEX_UNGREEDY, 0, &err); + if (err) { + g_error ("Invalid regular expression: %s", err->message); + g_error_free (err); + info->error = g_error_new_literal (MM_MODEM_ERROR, MM_MODEM_ERROR_GENERAL, + "Could not parse scan results."); + goto out; + } - g_regex_match (r, reply, 0, &match_info); + g_regex_match (r, reply, 0, &match_info); + umts_format = FALSE; + } + + /* Parse the results */ + results = g_ptr_array_new (); while (g_match_info_matches (match_info)) { GHashTable *hash; + char *access_tech = NULL; hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); g_hash_table_insert (hash, g_strdup ("status"), g_match_info_fetch (match_info, 1)); @@ -1167,6 +1201,16 @@ scan_done (MMSerialPort *port, g_hash_table_insert (hash, g_strdup ("operator-short"), g_match_info_fetch (match_info, 3)); g_hash_table_insert (hash, g_strdup ("operator-num"), g_match_info_fetch (match_info, 4)); + /* Only try for access technology with UMTS-format matches */ + if (umts_format) + access_tech = g_match_info_fetch (match_info, 5); + if (access_tech && (strlen (access_tech) == 1)) { + /* Recognized access technologies are between '0' and '6' inclusive... */ + if ((access_tech[0] >= 48) && (access_tech[0] <= 54)) + g_hash_table_insert (hash, g_strdup ("access-tech"), access_tech); + } else + g_free (access_tech); + g_ptr_array_add (results, hash); g_match_info_next (match_info, NULL); } diff --git a/test/mm-test.py b/test/mm-test.py index 05075449..67769c57 100755 --- a/test/mm-test.py +++ b/test/mm-test.py @@ -146,7 +146,7 @@ def inspect_gsm(proxy, dump_private): print "Signal quality: %d" % net.GetSignalQuality() print "Scanning..." - results = net.Scan(timeout=60) + results = net.Scan(timeout=120) for r in results: status = r['status'] if status == "1": @@ -158,10 +158,30 @@ def inspect_gsm(proxy, dump_private): else: status = "(Unknown)" + access_tech = "" + try: + access_tech_num = r['access-tech'] + if access_tech_num == "0": + access_tech = "(GSM)" + elif access_tech_num == "1": + access_tech = "(Compact GSM)" + elif access_tech_num == "2": + access_tech = "(UMTS)" + elif access_tech_num == "3": + access_tech = "(EDGE)" + elif access_tech_num == "4": + access_tech = "(HSDPA)" + elif access_tech_num == "5": + access_tech = "(HSUPA)" + elif access_tech_num == "6": + access_tech = "(HSPA)" + except KeyError: + pass + if len(r['operator-long']): - print "%s: %s" % (r['operator-long'], status) + print "%s: %s %s" % (r['operator-long'], status, access_tech) else: - print "%s: %s" % (r['operator-short'], status) + print "%s: %s %s" % (r['operator-short'], status, access_tech) dump_private = False |