diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-22 17:05:25 +0200 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-10-22 19:06:49 +0200 |
commit | b317996a8e18ba039d3d8ffb9968139d6d0bf9c1 (patch) | |
tree | 6de53ebee3e7abbf1f803599ef1500f857999198 | |
parent | 8e4d93c04eed7eefb25da22bfa071f6650b4203c (diff) |
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.
-rw-r--r-- | src/mm-iface-modem.c | 20 | ||||
-rw-r--r-- | src/mm-modem-helpers.c | 50 | ||||
-rw-r--r-- | src/mm-modem-helpers.h | 3 |
3 files changed, 68 insertions, 5 deletions
diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index 68b6ba55..f29ad273 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -2757,15 +2757,25 @@ load_current_bands_ready (MMIfaceModem *self, GAsyncResult *res, EnablingContext *ctx) { - GArray *bands_array; + GArray *current_bands; + GArray *filtered_bands; + GArray *supported_bands; GError *error = NULL; - bands_array = MM_IFACE_MODEM_GET_INTERFACE (self)->load_current_bands_finish (self, res, &error); + current_bands = MM_IFACE_MODEM_GET_INTERFACE (self)->load_current_bands_finish (self, res, &error); - if (bands_array) { + supported_bands = (mm_common_bands_variant_to_garray ( + mm_gdbus_modem_get_supported_bands (ctx->skeleton))); + filtered_bands = mm_filter_current_bands (supported_bands, current_bands); + if (current_bands) + g_array_unref (current_bands); + if (supported_bands) + g_array_unref (supported_bands); + + if (filtered_bands) { mm_gdbus_modem_set_bands (ctx->skeleton, - mm_common_bands_garray_to_variant (bands_array)); - g_array_unref (bands_array); + mm_common_bands_garray_to_variant (filtered_bands)); + g_array_unref (filtered_bands); } else mm_gdbus_modem_set_bands (ctx->skeleton, mm_common_build_bands_unknown ()); 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: <stat> (GSM 07.07 CREG=1 unsolicited) */ #define CREG1 "\\+(CREG|CGREG):\\s*0*([0-9])" diff --git a/src/mm-modem-helpers.h b/src/mm-modem-helpers.h index b8573aa5..e66f259a 100644 --- a/src/mm-modem-helpers.h +++ b/src/mm-modem-helpers.h @@ -61,6 +61,9 @@ gchar *mm_create_device_identifier (guint vid, guint mm_netmask_to_cidr (const gchar *netmask); +GArray *mm_filter_current_bands (const GArray *supported_bands, + const GArray *current_bands); + /*****************************************************************************/ /* 3GPP specific helpers and utilities */ /*****************************************************************************/ |