gsm: add cell access technology reporting to Scan()

This commit is contained in:
Dan Williams
2009-10-06 11:39:40 -07:00
parent 912b98723b
commit d867b1fe6a
3 changed files with 77 additions and 13 deletions

View File

@@ -23,7 +23,7 @@
<annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_scan"/> <annotation name="org.freedesktop.DBus.GLib.CSymbol" value="impl_gsm_modem_scan"/>
<arg name="results" type="aa{ss}" direction="out"> <arg name="results" type="aa{ss}" direction="out">
<tp:docstring> <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> </tp:docstring>
</arg> </arg>
</method> </method>

View File

@@ -1132,21 +1132,27 @@ scan_done (MMSerialPort *port,
GRegex *r; GRegex *r;
GMatchInfo *match_info; GMatchInfo *match_info;
GError *err = NULL; GError *err = NULL;
gboolean umts_format = TRUE;
reply = strstr (reply, "+COPS: ") + 7; reply = strstr (reply, "+COPS: ") + 7;
/* Pattern without crazy escaping using | for matching: (|\d|,"|.+|","|.+|","|.+|"\)?,|\d|) */ /* 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) * +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) { if (err) {
g_error ("Invalid regular expression: %s", err->message); g_error ("Invalid regular expression: %s", err->message);
g_error_free (err); g_error_free (err);
@@ -1155,11 +1161,39 @@ scan_done (MMSerialPort *port,
goto out; 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;
}
g_regex_match (r, reply, 0, &match_info); /* 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);
umts_format = FALSE;
}
/* Parse the results */
results = g_ptr_array_new ();
while (g_match_info_matches (match_info)) { while (g_match_info_matches (match_info)) {
GHashTable *hash; GHashTable *hash;
char *access_tech = NULL;
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); 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)); 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-short"), g_match_info_fetch (match_info, 3));
g_hash_table_insert (hash, g_strdup ("operator-num"), g_match_info_fetch (match_info, 4)); 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_ptr_array_add (results, hash);
g_match_info_next (match_info, NULL); g_match_info_next (match_info, NULL);
} }

View File

@@ -146,7 +146,7 @@ def inspect_gsm(proxy, dump_private):
print "Signal quality: %d" % net.GetSignalQuality() print "Signal quality: %d" % net.GetSignalQuality()
print "Scanning..." print "Scanning..."
results = net.Scan(timeout=60) results = net.Scan(timeout=120)
for r in results: for r in results:
status = r['status'] status = r['status']
if status == "1": if status == "1":
@@ -158,10 +158,30 @@ def inspect_gsm(proxy, dump_private):
else: else:
status = "(Unknown)" 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']): if len(r['operator-long']):
print "%s: %s" % (r['operator-long'], status) print "%s: %s %s" % (r['operator-long'], status, access_tech)
else: else:
print "%s: %s" % (r['operator-short'], status) print "%s: %s %s" % (r['operator-short'], status, access_tech)
dump_private = False dump_private = False