modem-helpers: provide list of scanned networks in a list of structs

We provide the result of the +COPS=? parsing in a GList of MM3gppNetworkInfo
structures. We avoid the previous hash table, or using a dictionary, as a
list of structs with a predefined set of elements, which should be easier for
plugins wanting to make their own version
This commit is contained in:
Aleksander Morgado
2011-11-30 13:29:00 +01:00
parent a265798e0d
commit a92e9c59c1
3 changed files with 299 additions and 258 deletions

View File

@@ -25,6 +25,7 @@
#include <ModemManager.h> #include <ModemManager.h>
#include <mm-errors-types.h> #include <mm-errors-types.h>
#include <mm-enums-types.h>
#include "mm-modem-helpers.h" #include "mm-modem-helpers.h"
#include "mm-log.h" #include "mm-log.h"
@@ -46,10 +47,20 @@ mm_strip_tag (const char *str, const char *cmd)
/*************************************************************************/ /*************************************************************************/
static void static void
save_scan_value (GHashTable *hash, const char *key, GMatchInfo *info, guint32 num) mm_3gpp_network_info_free (MM3gppNetworkInfo *info)
{ {
char *quoted; g_free (info->operator_long);
size_t len; g_free (info->operator_short);
g_free (info->operator_code);
g_free (info);
}
void
mm_3gpp_network_info_list_free (GList *info_list)
{
g_list_foreach (info_list, (GFunc)mm_3gpp_network_info_free, NULL);
g_list_free (info_list);
}
static MMModemAccessTech static MMModemAccessTech
get_mm_access_tech_from_etsi_access_tech (guint act) get_mm_access_tech_from_etsi_access_tech (guint act)
@@ -77,11 +88,15 @@ get_mm_access_tech_from_etsi_access_tech (guint act)
} }
} }
g_return_if_fail (info != NULL); static gchar *
get_unquoted_scan_value (GMatchInfo *info, guint32 num)
{
gchar *quoted;
gsize len;
quoted = g_match_info_fetch (info, num); quoted = g_match_info_fetch (info, num);
if (!quoted) if (!quoted)
return; return NULL;
len = strlen (quoted); len = strlen (quoted);
@@ -94,24 +109,53 @@ get_mm_access_tech_from_etsi_access_tech (guint act)
if (!strlen (quoted)) { if (!strlen (quoted)) {
g_free (quoted); g_free (quoted);
return; return NULL;
} }
g_hash_table_insert (hash, g_strdup (key), quoted); return quoted;
} }
/* If the response was successfully parsed (even if no valid entries were static MMModem3gppNetworkAvailability
* found) the pointer array will be returned. parse_network_status (const gchar *str)
*/ {
GPtrArray * /* Expecting a value between '0' and '3' inclusive */
mm_gsm_parse_scan_response (const char *reply, GError **error) if (!str ||
strlen (str) != 1 ||
str[0] < '0' ||
str[0] > '3') {
mm_warn ("Cannot parse network status: '%s'", str);
return MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN;
}
return (MMModem3gppNetworkAvailability) (str[0] - '0');
}
static MMModemAccessTech
parse_access_tech (const gchar *str)
{
/* Recognized access technologies are between '0' and '7' inclusive... */
if (!str ||
strlen (str) != 1 ||
str[0] < '0' ||
str[0] > '7') {
mm_warn ("Cannot parse access tech: '%s'", str);
return MM_MODEM_ACCESS_TECH_UNKNOWN;
}
return get_mm_access_tech_from_etsi_access_tech (str[0] - '0');
}
GList *
mm_3gpp_parse_scan_response (const gchar *reply,
GError **error)
{ {
/* Got valid reply */
GPtrArray *results = NULL;
GRegex *r; GRegex *r;
GList *info_list = NULL;
GMatchInfo *match_info; GMatchInfo *match_info;
GError *err = NULL;
gboolean umts_format = TRUE; gboolean umts_format = TRUE;
GEnumClass *network_availability_class;
GEnumClass *access_tech_class;
GError *inner_error = NULL;
g_return_val_if_fail (reply != NULL, NULL); g_return_val_if_fail (reply != NULL, NULL);
if (error) if (error)
@@ -140,13 +184,13 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
* +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)
*/ */
r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &err); r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^,\\)]*)[\\)]?,(\\d)\\)", G_REGEX_UNGREEDY, 0, &inner_error);
if (err) { if (inner_error) {
mm_err ("Invalid regular expression: %s", err->message); mm_err ("Invalid regular expression: %s", inner_error->message);
g_error_free (err); g_error_free (inner_error);
g_set_error_literal (error, g_set_error_literal (error,
MM_CORE_ERROR, MM_CORE_ERROR_FAILED, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not parse scan results."); "Could not parse scan results");
return NULL; return NULL;
} }
@@ -169,13 +213,13 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
* +COPS: (2,"T - Mobile",,"31026"),(1,"Einstein PCS",,"31064"),(1,"Cingular",,"31041"),,(0,1,3),(0,2) * +COPS: (2,"T - Mobile",,"31026"),(1,"Einstein PCS",,"31064"),(1,"Cingular",,"31041"),,(0,1,3),(0,2)
*/ */
r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, &err); r = g_regex_new ("\\((\\d),([^,\\)]*),([^,\\)]*),([^\\)]*)\\)", G_REGEX_UNGREEDY, 0, &inner_error);
if (err) { if (inner_error) {
mm_err ("Invalid regular expression: %s", err->message); mm_err ("Invalid regular expression: %s", inner_error->message);
g_error_free (err); g_error_free (inner_error);
g_set_error_literal (error, g_set_error_literal (error,
MM_CORE_ERROR, MM_CORE_ERROR_FAILED, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
"Could not parse scan results."); "Could not parse scan results");
return NULL; return NULL;
} }
@@ -183,39 +227,43 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
umts_format = FALSE; umts_format = FALSE;
} }
network_availability_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_3GPP_NETWORK_AVAILABILITY));
access_tech_class = G_ENUM_CLASS (g_type_class_ref (MM_TYPE_MODEM_ACCESS_TECH));
/* Parse the results */ /* Parse the results */
results = g_ptr_array_new ();
while (g_match_info_matches (match_info)) { while (g_match_info_matches (match_info)) {
GHashTable *hash; MM3gppNetworkInfo *info;
char *access_tech = NULL; gchar *tmp;
const char *tmp;
gboolean valid = FALSE; gboolean valid = FALSE;
hash = g_hash_table_new_full (g_str_hash, g_str_equal, g_free, g_free); info = g_new0 (MM3gppNetworkInfo, 1);
save_scan_value (hash, MM_SCAN_TAG_STATUS, match_info, 1); tmp = get_unquoted_scan_value (match_info, 1);
save_scan_value (hash, MM_SCAN_TAG_OPER_LONG, match_info, 2); info->status = parse_network_status (tmp);
save_scan_value (hash, MM_SCAN_TAG_OPER_SHORT, match_info, 3); g_free (tmp);
save_scan_value (hash, MM_SCAN_TAG_OPER_NUM, match_info, 4);
/* Only try for access technology with UMTS-format matches */ info->operator_long = get_unquoted_scan_value (match_info, 2);
if (umts_format) info->operator_short = get_unquoted_scan_value (match_info, 3);
access_tech = g_match_info_fetch (match_info, 5); info->operator_code = get_unquoted_scan_value (match_info, 4);
if (access_tech && (strlen (access_tech) == 1)) {
/* Recognized access technologies are between '0' and '6' inclusive... */ /* Only try for access technology with UMTS-format matches.
if ((access_tech[0] >= '0') && (access_tech[0] <= '6')) * If none give, assume GSM */
g_hash_table_insert (hash, g_strdup (MM_SCAN_TAG_ACCESS_TECH), access_tech); tmp = (umts_format ?
} else get_unquoted_scan_value (match_info, 5) :
g_free (access_tech); NULL);
info->access_tech = (tmp ?
parse_access_tech (tmp) :
MM_MODEM_ACCESS_TECH_GSM);
g_free (tmp);
/* If the operator number isn't valid (ie, at least 5 digits), /* If the operator number isn't valid (ie, at least 5 digits),
* ignore the scan result; it's probably the parameter stuff at the * ignore the scan result; it's probably the parameter stuff at the
* end of the +COPS response. The regex will sometimes catch this * end of the +COPS response. The regex will sometimes catch this
* but there's no good way to ignore it. * but there's no good way to ignore it.
*/ */
tmp = g_hash_table_lookup (hash, MM_SCAN_TAG_OPER_NUM); if (info->operator_code && (strlen (info->operator_code) >= 5)) {
if (tmp && (strlen (tmp) >= 5)) {
valid = TRUE; valid = TRUE;
tmp = info->operator_code;
while (*tmp) { while (*tmp) {
if (!isdigit (*tmp) && (*tmp != '-')) { if (!isdigit (*tmp) && (*tmp != '-')) {
valid = FALSE; valid = FALSE;
@@ -223,13 +271,28 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
} }
tmp++; tmp++;
} }
if (valid)
g_ptr_array_add (results, hash);
} }
if (!valid) if (valid) {
g_hash_table_destroy (hash); GEnumValue *network_availability;
GEnumValue *access_tech;
network_availability = g_enum_get_value (network_availability_class,
info->status);
access_tech = g_enum_get_value (access_tech_class,
info->access_tech);
mm_dbg ("Found network '%s' ('%s','%s'); availability: %s, access tech: %s",
info->operator_code,
info->operator_short ? info->operator_short : "no short name",
info->operator_long ? info->operator_long : "no long name",
network_availability->value_nick,
access_tech->value_nick);
info_list = g_list_prepend (info_list, info);
}
else
mm_3gpp_network_info_free (info);
g_match_info_next (match_info, NULL); g_match_info_next (match_info, NULL);
} }
@@ -237,16 +300,10 @@ mm_gsm_parse_scan_response (const char *reply, GError **error)
g_match_info_free (match_info); g_match_info_free (match_info);
g_regex_unref (r); g_regex_unref (r);
return results; g_type_class_unref (network_availability_class);
} g_type_class_unref (access_tech_class);
void return info_list;
mm_gsm_destroy_scan_data (gpointer data)
{
GPtrArray *results = (GPtrArray *) data;
g_ptr_array_foreach (results, (GFunc) g_hash_table_destroy, NULL);
g_ptr_array_free (results, TRUE);
} }
/*************************************************************************/ /*************************************************************************/

View File

@@ -22,15 +22,19 @@
#include "mm-modem-cdma.h" #include "mm-modem-cdma.h"
#include "mm-charsets.h" #include "mm-charsets.h"
#define MM_SCAN_TAG_STATUS "status" /* Network scan results expected */
#define MM_SCAN_TAG_OPER_LONG "operator-long" typedef struct {
#define MM_SCAN_TAG_OPER_SHORT "operator-short" MMModem3gppNetworkAvailability status;
#define MM_SCAN_TAG_OPER_NUM "operator-num" gchar *operator_long;
#define MM_SCAN_TAG_ACCESS_TECH "access-tech" gchar *operator_short;
gchar *operator_code; /* mandatory */
MMModemAccessTech access_tech;
} MM3gppNetworkInfo;
GPtrArray *mm_gsm_parse_scan_response (const char *reply, GError **error); void mm_3gpp_network_info_list_free (GList *info_list);
void mm_gsm_destroy_scan_data (gpointer data); GList *mm_3gpp_parse_scan_response (const gchar *reply,
GError **error);
GPtrArray *mm_gsm_creg_regex_get (gboolean solicited); GPtrArray *mm_gsm_creg_regex_get (gboolean solicited);

View File

@@ -24,394 +24,373 @@ typedef struct {
GPtrArray *unsolicited_creg; GPtrArray *unsolicited_creg;
} TestData; } TestData;
#define MM_SCAN_TAG_STATUS "status"
#define MM_SCAN_TAG_OPER_LONG "operator-long"
#define MM_SCAN_TAG_OPER_SHORT "operator-short"
#define MM_SCAN_TAG_OPER_NUM "operator-num"
#define MM_SCAN_TAG_ACCESS_TECH "access-tech"
typedef struct {
const char *status;
const char *oper_long;
const char *oper_short;
const char *oper_num;
const char *tech;
} OperEntry;
#define ARRAY_LEN(i) (sizeof (i) / sizeof (i[0]))
static void static void
test_cops_results (const char *desc, test_cops_results (const gchar *desc,
const char *reply, const gchar *reply,
OperEntry *expected_results, MM3gppNetworkInfo *expected_results,
guint32 expected_results_len) guint32 expected_results_len)
{ {
guint i; GList *l;
GError *error = NULL; GError *error = NULL;
GPtrArray *results; GList *results;
g_print ("\nTesting %s +COPS response...\n", desc); g_print ("\nTesting %s +COPS response...\n", desc);
results = mm_gsm_parse_scan_response (reply, &error); results = mm_3gpp_parse_scan_response (reply, &error);
g_assert (results); g_assert (results);
g_assert (error == NULL); g_assert_no_error (error);
g_assert_cmpuint (g_list_length (results), ==, expected_results_len);
g_assert (results->len == expected_results_len); for (l = results; l; l = g_list_next (l)) {
MM3gppNetworkInfo *info = l->data;
gboolean found = FALSE;
guint i;
for (i = 0; i < results->len; i++) { for (i = 0; !found && i < expected_results_len; i++) {
GHashTable *entry = g_ptr_array_index (results, i); MM3gppNetworkInfo *expected;
const char *value;
OperEntry *expected = &expected_results[i];
value = g_hash_table_lookup (entry, MM_SCAN_TAG_STATUS); expected = &expected_results[i];
g_assert (value); if (g_str_equal (info->operator_code, expected->operator_code) &&
g_assert (strcmp (value, expected->status) == 0); info->access_tech == expected->access_tech) {
found = TRUE;
value = g_hash_table_lookup (entry, MM_SCAN_TAG_OPER_LONG); g_assert_cmpuint (info->status, ==, expected->status);
if (expected->oper_long) {
g_assert (value);
g_assert (strcmp (value, expected->oper_long) == 0);
} else
g_assert (value == NULL);
value = g_hash_table_lookup (entry, MM_SCAN_TAG_OPER_SHORT); if (expected->operator_long)
if (expected->oper_short) { g_assert_cmpstr (info->operator_long, ==, expected->operator_long);
g_assert (value); else
g_assert (strcmp (value, expected->oper_short) == 0); g_assert (info->operator_long == NULL);
} else
g_assert (value == NULL);
value = g_hash_table_lookup (entry, MM_SCAN_TAG_OPER_NUM); if (expected->operator_short)
g_assert (expected->oper_num); g_assert_cmpstr (info->operator_short, ==, expected->operator_short);
g_assert (value); else
g_assert (strcmp (value, expected->oper_num) == 0); g_assert (info->operator_short == NULL);
value = g_hash_table_lookup (entry, MM_SCAN_TAG_ACCESS_TECH); g_debug ("info: %s, expected: %s", info->operator_code, expected->operator_code);
if (expected->tech) { }
g_assert (value);
g_assert (strcmp (value, expected->tech) == 0);
} else
g_assert (value == NULL);
} }
mm_gsm_destroy_scan_data (results); g_assert (found == TRUE);
}
mm_3gpp_network_info_list_free (results);
} }
static void static void
test_cops_response_tm506 (void *f, gpointer d) test_cops_response_tm506 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"\",\"T-Mobile\",\"31026\",0),(2,\"T - Mobile\",\"T - Mobile\",\"310260\"),2),(1,\"AT&T\",\"AT&T\",\"310410\"),0)"; const gchar *reply = "+COPS: (2,\"\",\"T-Mobile\",\"31026\",0),(2,\"T - Mobile\",\"T - Mobile\",\"310260\"),2),(1,\"AT&T\",\"AT&T\",\"310410\"),0)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", NULL, "T-Mobile", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, NULL, "T-Mobile", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "2", "T - Mobile", "T - Mobile", "310260", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T - Mobile", "T - Mobile", "310260", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" } { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM }
}; };
test_cops_results ("TM-506", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("TM-506", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_gt3gplus (void *f, gpointer d) test_cops_response_gt3gplus (void *f, gpointer d)
{ {
const char *reply = "+COPS: (1,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"Cingular\",\"Cingular\",\"310410\",0),,(0, 1, 3),(0-2)"; const char *reply = "+COPS: (1,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"Cingular\",\"Cingular\",\"310410\",0),,(0, 1, 3),(0-2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "1", "T-Mobile US", "TMO US", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "T-Mobile US", "TMO US", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "Cingular", "Cingular", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "Cingular", "Cingular", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("GlobeTrotter 3G+ (nozomi)", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("GlobeTrotter 3G+ (nozomi)", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_ac881 (void *f, gpointer d) test_cops_response_ac881 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (1,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),)"; const char *reply = "+COPS: (1,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "1", "T-Mobile", "TMO", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "T-Mobile", "TMO", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Sierra AirCard 881", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Sierra AirCard 881", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_gtmax36 (void *f, gpointer d) test_cops_response_gtmax36 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0, 1,)"; const char *reply = "+COPS: (2,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0, 1,)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile US", "TMO US", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile US", "TMO US", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Option GlobeTrotter MAX 3.6", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Option GlobeTrotter MAX 3.6", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_ac860 (void *f, gpointer d) test_cops_response_ac860 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"Cingular\",\"Cinglr\",\"310410\",2),(1,\"Cingular\",\"Cinglr\",\"310410\",0),,)"; const char *reply = "+COPS: (2,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"Cingular\",\"Cinglr\",\"310410\",2),(1,\"Cingular\",\"Cinglr\",\"310410\",0),,)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", "TMO", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "TMO", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "Cingular", "Cinglr", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "Cingular", "Cinglr", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "Cingular", "Cinglr", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "Cingular", "Cinglr", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Sierra AirCard 860", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Sierra AirCard 860", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_gtm378 (void *f, gpointer d) test_cops_response_gtm378 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0, 1, 3),(0-2)"; const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0, 1, 3),(0-2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", "T-Mobile", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "T-Mobile", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Option GTM378", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Option GTM378", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_motoc (void *f, gpointer d) test_cops_response_motoc (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"\",\"310260\"),(0,\"Cingular Wireless\",\"\",\"310410\")"; const char *reply = "+COPS: (2,\"T-Mobile\",\"\",\"310260\"),(0,\"Cingular Wireless\",\"\",\"310410\")";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", NULL, "310260", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", NULL, "310260", MM_MODEM_ACCESS_TECH_GSM },
{ "0", "Cingular Wireless", NULL, "310410", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN, "Cingular Wireless", NULL, "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("BUSlink SCWi275u (Motorola C-series)", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("BUSlink SCWi275u (Motorola C-series)", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_mf627a (void *f, gpointer d) test_cops_response_mf627a (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"AT&T@\",\"AT&TD\",\"310410\",0),(3,\"Voicestream Wireless Corporation\",\"VSTREAM\",\"31026\",0),"; const char *reply = "+COPS: (2,\"AT&T@\",\"AT&TD\",\"310410\",0),(3,\"Voicestream Wireless Corporation\",\"VSTREAM\",\"31026\",0),";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "AT&T@", "AT&TD", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "AT&T@", "AT&TD", "310410", MM_MODEM_ACCESS_TECH_GSM },
{ "3", "Voicestream Wireless Corporation", "VSTREAM", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, "Voicestream Wireless Corporation", "VSTREAM", "31026", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("ZTE MF627 (A)", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("ZTE MF627 (A)", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_mf627b (void *f, gpointer d) test_cops_response_mf627b (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"AT&Tp\",\"AT&T@\",\"310410\",0),(3,\"\",\"\",\"31026\",0),"; const char *reply = "+COPS: (2,\"AT&Tp\",\"AT&T@\",\"310410\",0),(3,\"\",\"\",\"31026\",0),";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "AT&Tp", "AT&T@", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "AT&Tp", "AT&T@", "310410", MM_MODEM_ACCESS_TECH_GSM },
{ "3", NULL, NULL, "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, NULL, NULL, "31026", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("ZTE MF627 (B)", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("ZTE MF627 (B)", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_e160g (void *f, gpointer d) test_cops_response_e160g (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)"; const char *reply = "+COPS: (2,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", "TMO", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "TMO", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Huawei E160G", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Huawei E160G", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_mercury (void *f, gpointer d) test_cops_response_mercury (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"\",\"\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),(1,\"T-Mobile\",\"TMO\",\"31026\",0),,(0,1,2,3,4),(0,1,2)"; const char *reply = "+COPS: (2,\"\",\"\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),(1,\"T-Mobile\",\"TMO\",\"31026\",0),,(0,1,2,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", NULL, NULL, "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, NULL, NULL, "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "T-Mobile", "TMO", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "T-Mobile", "TMO", "31026", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Sierra AT&T USBConnect Mercury", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Sierra AT&T USBConnect Mercury", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_quicksilver (void *f, gpointer d) test_cops_response_quicksilver (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"AT&T\",\"\",\"310410\",0),(2,\"\",\"\",\"3104100\",2),(1,\"AT&T\",\"\",\"310260\",0),,(0-4),(0-2)"; const char *reply = "+COPS: (2,\"AT&T\",\"\",\"310410\",0),(2,\"\",\"\",\"3104100\",2),(1,\"AT&T\",\"\",\"310260\",0),,(0-4),(0-2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "AT&T", NULL, "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "AT&T", NULL, "310410", MM_MODEM_ACCESS_TECH_GSM },
{ "2", NULL, NULL, "3104100", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, NULL, NULL, "3104100", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", NULL, "310260", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", NULL, "310260", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Option AT&T Quicksilver", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Option AT&T Quicksilver", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_icon225 (void *f, gpointer d) test_cops_response_icon225 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0, 1, 3),(0-2)"; const char *reply = "+COPS: (2,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0, 1, 3),(0-2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile US", "TMO US", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile US", "TMO US", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Option iCON 225", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Option iCON 225", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_icon452 (void *f, gpointer d) test_cops_response_icon452 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (1,\"T-Mobile US\",\"TMO US\",\"31026\",0),(2,\"T-Mobile\",\"T-Mobile\",\"310260\",2),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)"; const char *reply = "+COPS: (1,\"T-Mobile US\",\"TMO US\",\"31026\",0),(2,\"T-Mobile\",\"T-Mobile\",\"310260\",2),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "1", "T-Mobile US", "TMO US", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "T-Mobile US", "TMO US", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "2", "T-Mobile", "T-Mobile", "310260", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "T-Mobile", "310260", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" } { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM }
}; };
test_cops_results ("Option iCON 452", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Option iCON 452", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_f3507g (void *f, gpointer d) test_cops_response_f3507g (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T - Mobile\",\"T - Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2)"; const char *reply = "+COPS: (2,\"T - Mobile\",\"T - Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T - Mobile", "T - Mobile", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T - Mobile", "T - Mobile", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" } { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS }
}; };
test_cops_results ("Ericsson F3507g", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Ericsson F3507g", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_f3607gw (void *f, gpointer d) test_cops_response_f3607gw (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T - Mobile\",\"T - Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\"),2),(1,\"AT&T\",\"AT&T\",\"310410\"),0)"; const char *reply = "+COPS: (2,\"T - Mobile\",\"T - Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\"),2),(1,\"AT&T\",\"AT&T\",\"310410\"),0)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T - Mobile", "T - Mobile", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T - Mobile", "T - Mobile", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" } { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM }
}; };
test_cops_results ("Ericsson F3607gw", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Ericsson F3607gw", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_mc8775 (void *f, gpointer d) test_cops_response_mc8775 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)"; const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", "T-Mobile", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "T-Mobile", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" } { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM }
}; };
test_cops_results ("Sierra MC8775", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Sierra MC8775", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_n80 (void *f, gpointer d) test_cops_response_n80 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T - Mobile\",,\"31026\"),(1,\"Einstein PCS\",,\"31064\"),(1,\"Cingular\",,\"31041\"),,(0,1,3),(0,2)"; const char *reply = "+COPS: (2,\"T - Mobile\",,\"31026\"),(1,\"Einstein PCS\",,\"31064\"),(1,\"Cingular\",,\"31041\"),,(0,1,3),(0,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T - Mobile", NULL, "31026", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T - Mobile", NULL, "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "Einstein PCS", NULL, "31064", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "Einstein PCS", NULL, "31064", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "Cingular", NULL, "31041", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "Cingular", NULL, "31041", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Nokia N80", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Nokia N80", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_e1550 (void *f, gpointer d) test_cops_response_e1550 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)"; const char *reply = "+COPS: (2,\"T-Mobile\",\"TMO\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", "TMO", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "TMO", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Huawei E1550", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Huawei E1550", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_mf622 (void *f, gpointer d) test_cops_response_mf622 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"\",\"\",\"310410\",0),"; const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"\",\"\",\"310410\",0),";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", "T-Mobile", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "T-Mobile", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", NULL, NULL, "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, NULL, NULL, "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("ZTE MF622", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("ZTE MF622", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_e226 (void *f, gpointer d) test_cops_response_e226 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (1,\"\",\"\",\"31026\",0),(1,\"\",\"\",\"310410\",2),(1,\"\",\"\",\"310410\",0),,(0,1,3,4),(0,1,2)"; const char *reply = "+COPS: (1,\"\",\"\",\"31026\",0),(1,\"\",\"\",\"310410\",2),(1,\"\",\"\",\"310410\",0),,(0,1,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "1", NULL, NULL, "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, NULL, NULL, "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", NULL, NULL, "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, NULL, NULL, "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", NULL, NULL, "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, NULL, NULL, "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Huawei E226", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Huawei E226", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_xu870 (void *f, gpointer d) test_cops_response_xu870 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (0,\"AT&T MicroCell\",\"AT&T MicroCell\",\"310410\",2)\r\n+COPS: (1,\"AT&T MicroCell\",\"AT&T MicroCell\",\"310410\",0)\r\n+COPS: (1,\"T-Mobile\",\"TMO\",\"31026\",0)\r\n"; const char *reply = "+COPS: (0,\"AT&T MicroCell\",\"AT&T MicroCell\",\"310410\",2)\r\n+COPS: (1,\"AT&T MicroCell\",\"AT&T MicroCell\",\"310410\",0)\r\n+COPS: (1,\"T-Mobile\",\"TMO\",\"31026\",0)\r\n";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "0", "AT&T MicroCell", "AT&T MicroCell", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_UNKNOWN, "AT&T MicroCell", "AT&T MicroCell", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T MicroCell", "AT&T MicroCell", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T MicroCell", "AT&T MicroCell", "310410", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "T-Mobile", "TMO", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "T-Mobile", "TMO", "31026", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Novatel XU870", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Novatel XU870", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_gtultraexpress (void *f, gpointer d) test_cops_response_gtultraexpress (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)"; const char *reply = "+COPS: (2,\"T-Mobile US\",\"TMO US\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile US", "TMO US", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile US", "TMO US", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Option GlobeTrotter Ultra Express", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Option GlobeTrotter Ultra Express", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_n2720 (void *f, gpointer d) test_cops_response_n2720 (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T - Mobile\",,\"31026\",0),\r\n(1,\"AT&T\",,\"310410\",0),,(0,1,3),(0,2)"; const char *reply = "+COPS: (2,\"T - Mobile\",,\"31026\",0),\r\n(1,\"AT&T\",,\"310410\",0),,(0,1,3),(0,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T - Mobile", NULL, "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T - Mobile", NULL, "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", NULL, "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", NULL, "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Nokia 2720", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Nokia 2720", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_gobi (void *f, gpointer d) test_cops_response_gobi (void *f, gpointer d)
{ {
const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)"; const char *reply = "+COPS: (2,\"T-Mobile\",\"T-Mobile\",\"31026\",0),(1,\"AT&T\",\"AT&T\",\"310410\",2),(1,\"AT&T\",\"AT&T\",\"310410\",0),,(0,1,2,3,4),(0,1,2)";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "T-Mobile", "T-Mobile", "31026", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "T-Mobile", "T-Mobile", "31026", MM_MODEM_ACCESS_TECH_GSM },
{ "1", "AT&T", "AT&T", "310410", "2" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_UMTS },
{ "1", "AT&T", "AT&T", "310410", "0" }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_AVAILABLE, "AT&T", "AT&T", "310410", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Qualcomm Gobi", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Qualcomm Gobi", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
@@ -422,41 +401,41 @@ test_cops_response_sek600i (void *f, gpointer d)
* which is which... * which is which...
*/ */
const char *reply = "+COPS: (2,\"blau\",\"\",\"26203\"),(2,\"blau\",\"\",\"26203\"),(3,\"\",\"\",\"26201\"),(3,\"\",\"\",\"26202\"),(3,\"\",\"\",\"26207\"),(3,\"\",\"\",\"26201\"),(3,\"\",\"\",\"26207\")"; const char *reply = "+COPS: (2,\"blau\",\"\",\"26203\"),(2,\"blau\",\"\",\"26203\"),(3,\"\",\"\",\"26201\"),(3,\"\",\"\",\"26202\"),(3,\"\",\"\",\"26207\"),(3,\"\",\"\",\"26201\"),(3,\"\",\"\",\"26207\")";
static OperEntry expected[] = { static MM3gppNetworkInfo expected[] = {
{ "2", "blau", NULL, "26203", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "blau", NULL, "26203", MM_MODEM_ACCESS_TECH_GSM },
{ "2", "blau", NULL, "26203", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_CURRENT, "blau", NULL, "26203", MM_MODEM_ACCESS_TECH_GSM },
{ "3", NULL, NULL, "26201", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, NULL, NULL, "26201", MM_MODEM_ACCESS_TECH_GSM },
{ "3", NULL, NULL, "26202", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, NULL, NULL, "26202", MM_MODEM_ACCESS_TECH_GSM },
{ "3", NULL, NULL, "26207", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, NULL, NULL, "26207", MM_MODEM_ACCESS_TECH_GSM },
{ "3", NULL, NULL, "26201", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, NULL, NULL, "26201", MM_MODEM_ACCESS_TECH_GSM },
{ "3", NULL, NULL, "26207", NULL }, { MM_MODEM_3GPP_NETWORK_AVAILABILITY_FORBIDDEN, NULL, NULL, "26207", MM_MODEM_ACCESS_TECH_GSM },
}; };
test_cops_results ("Sony-Ericsson K600i", reply, &expected[0], ARRAY_LEN (expected)); test_cops_results ("Sony-Ericsson K600i", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
test_cops_response_gsm_invalid (void *f, gpointer d) test_cops_response_gsm_invalid (void *f, gpointer d)
{ {
const char *reply = "+COPS: (0,1,2,3),(1,2,3,4)"; const gchar *reply = "+COPS: (0,1,2,3),(1,2,3,4)";
GPtrArray *results; GList *results;
GError *error = NULL; GError *error = NULL;
results = mm_gsm_parse_scan_response (reply, &error); results = mm_3gpp_parse_scan_response (reply, &error);
g_assert (results != NULL); g_assert (results == NULL);
g_assert (error == NULL); g_assert_no_error (error);
} }
static void static void
test_cops_response_umts_invalid (void *f, gpointer d) test_cops_response_umts_invalid (void *f, gpointer d)
{ {
const char *reply = "+COPS: (0,1,2,3,4),(1,2,3,4,5)"; const char *reply = "+COPS: (0,1,2,3,4),(1,2,3,4,5)";
GPtrArray *results; GList *results;
GError *error = NULL; GError *error = NULL;
results = mm_gsm_parse_scan_response (reply, &error); results = mm_3gpp_parse_scan_response (reply, &error);
g_assert (results != NULL); g_assert (results == NULL);
g_assert (error == NULL); g_assert_no_error (error);
} }
typedef struct { typedef struct {
@@ -1178,7 +1157,7 @@ test_cind_response_linktop_lw273 (void *f, gpointer d)
{ "message", 0, 1 } { "message", 0, 1 }
}; };
test_cind_results ("LW273", reply, &expected[0], ARRAY_LEN (expected)); test_cind_results ("LW273", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static void static void
@@ -1195,7 +1174,7 @@ test_cind_response_moto_v3m (void *f, gpointer d)
{ "smsfull", 0, 1 } { "smsfull", 0, 1 }
}; };
test_cind_results ("Motorola V3m", reply, &expected[0], ARRAY_LEN (expected)); test_cind_results ("Motorola V3m", reply, &expected[0], G_N_ELEMENTS (expected));
} }
static TestData * static TestData *
@@ -1242,6 +1221,7 @@ int main (int argc, char **argv)
gint result; gint result;
DevidItem *item = &devids[0]; DevidItem *item = &devids[0];
g_type_init ();
g_test_init (&argc, &argv, NULL); g_test_init (&argc, &argv, NULL);
suite = g_test_get_root (); suite = g_test_get_root ();