diff options
author | Dan Williams <dcbw@redhat.com> | 2009-10-06 11:39:40 -0700 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2009-10-06 11:39:40 -0700 |
commit | d867b1fe6a11302c0efcd40bba2a898bc9080b1c (patch) | |
tree | 01aa2cdaa55d669c40b41e326289e76386095bd1 /src | |
parent | 912b98723b2965b9aaf1f0328781a2730d7cc178 (diff) |
gsm: add cell access technology reporting to Scan()
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-generic-gsm.c | 62 |
1 files changed, 53 insertions, 9 deletions
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); } |