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.
This commit is contained in:
Aleksander Morgado
2012-10-22 17:05:25 +02:00
parent 8e4d93c04e
commit b317996a8e
3 changed files with 68 additions and 5 deletions

View File

@@ -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 ());

View File

@@ -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])"

View File

@@ -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 */
/*****************************************************************************/