From b317996a8e18ba039d3d8ffb9968139d6d0bf9c1 Mon Sep 17 00:00:00 2001 From: Aleksander Morgado Date: Mon, 22 Oct 2012 17:05:25 +0200 Subject: iface-modem: always ensure that current bands is a subset of supported bands In QMI modems the logic behind supported and current bands is completely separated in different services (DMS vs NAS). Actually, the list reported by NAS as current band preferences seems to include more values than the ones reported by DMS as supported bands (e.g. CDMA bands are reported even if the firmware image is GSM/HSPA only). So, just clean up the list of current preferred bands so that no more than those given as supported is used. --- src/mm-modem-helpers.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'src/mm-modem-helpers.c') diff --git a/src/mm-modem-helpers.c b/src/mm-modem-helpers.c index fe30317c..8cf9a29f 100644 --- a/src/mm-modem-helpers.c +++ b/src/mm-modem-helpers.c @@ -165,6 +165,56 @@ mm_netmask_to_cidr (const gchar *netmask) /*****************************************************************************/ +GArray * +mm_filter_current_bands (const GArray *supported_bands, + const GArray *current_bands) +{ + /* We will assure that the list given in 'current' bands maps the list + * given in 'supported' bands, unless 'UNKNOWN' or 'ANY' is given, of + * course */ + guint i; + GArray *filtered; + + if (!supported_bands || + supported_bands->len == 0 || + !current_bands || + current_bands->len == 0) + return NULL; + + if (supported_bands->len == 1 && + (g_array_index (supported_bands, MMModemBand, 0) == MM_MODEM_BAND_UNKNOWN || + g_array_index (supported_bands, MMModemBand, 0) == MM_MODEM_BAND_ANY)) + return NULL; + + if (current_bands->len == 1 && + (g_array_index (current_bands, MMModemBand, 0) == MM_MODEM_BAND_UNKNOWN || + g_array_index (current_bands, MMModemBand, 0) == MM_MODEM_BAND_ANY)) + return NULL; + + filtered = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), current_bands->len); + + for (i = 0; i < current_bands->len; i++) { + guint j; + + for (j = 0; j < supported_bands->len; j++) { + if (g_array_index (supported_bands, MMModemBand, j) == g_array_index (current_bands, MMModemBand, i)) { + g_array_append_val (filtered, g_array_index (current_bands, MMModemBand, i)); + /* Found */ + break; + } + } + } + + if (filtered->len == 0) { + g_array_unref (filtered); + return NULL; + } + + return filtered; +} + +/*****************************************************************************/ + /* +CREG: (GSM 07.07 CREG=1 unsolicited) */ #define CREG1 "\\+(CREG|CGREG):\\s*0*([0-9])" -- cgit v1.2.3-70-g09d2