cinterion: consolidate setting current bands in 2G and 3G devices

This commit is contained in:
Aleksander Morgado
2014-02-27 11:32:05 +01:00
parent c1e2a3a5bc
commit f2024b78b2
3 changed files with 46 additions and 69 deletions

View File

@@ -942,7 +942,7 @@ scfg_test_ready (MMBaseModem *_self,
&error)) &error))
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (simple, error);
else { else {
mm_cinterion_build_band (bands, 0, &self->priv->supported_bands, NULL); mm_cinterion_build_band (bands, 0, FALSE, &self->priv->supported_bands, NULL);
g_assert (self->priv->supported_bands != 0); g_assert (self->priv->supported_bands != 0);
g_simple_async_result_set_op_res_gpointer (simple, bands, (GDestroyNotify)g_array_unref); g_simple_async_result_set_op_res_gpointer (simple, bands, (GDestroyNotify)g_array_unref);
} }
@@ -1070,6 +1070,7 @@ set_bands_3g (MMIfaceModem *_self,
if (!mm_cinterion_build_band (bands_array, if (!mm_cinterion_build_band (bands_array,
self->priv->supported_bands, self->priv->supported_bands,
FALSE, /* 2G and 3G */
&band, &band,
&error)) { &error)) {
g_simple_async_result_take_error (simple, error); g_simple_async_result_take_error (simple, error);
@@ -1095,78 +1096,37 @@ set_bands_3g (MMIfaceModem *_self,
} }
static void static void
set_bands_2g (MMIfaceModem *self, set_bands_2g (MMIfaceModem *_self,
GArray *bands_array, GArray *bands_array,
GSimpleAsyncResult *result) GSimpleAsyncResult *simple)
{ {
GArray *bands_array_final; MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self);
gchar *cinterion_band = NULL; GError *error = NULL;
guint i; guint band = 0;
gchar *bands_string;
gchar *cmd; gchar *cmd;
gchar *bandstr;
/* If the iface properly checked the given list against the supported bands, if (!mm_cinterion_build_band (bands_array,
* it's not possible to get an array longer than 4 here. */ self->priv->supported_bands,
g_assert (bands_array->len <= 4); TRUE, /* 2G only */
&band,
/* The special case of ANY should be treated separately. */ &error)) {
if (bands_array->len == 1 && g_simple_async_result_take_error (simple, error);
g_array_index (bands_array, MMModemBand, 0) == MM_MODEM_BAND_ANY) { g_simple_async_result_complete_in_idle (simple);
const CinterionBand2G *all; g_object_unref (simple);
/* All bands is the last element in our 2G bands array */
all = &bands_2g[G_N_ELEMENTS (bands_2g) - 1];
/* We build an array with all bands to set; so that we use the same
* logic to build the cinterion_band, and so that we can log the list of
* bands being set properly */
bands_array_final = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), 4);
g_array_append_vals (bands_array_final, all->mm_bands, all->n_mm_bands);
} else
bands_array_final = g_array_ref (bands_array);
for (i = 0; !cinterion_band && i < G_N_ELEMENTS (bands_2g); i++) {
GArray *supported_combination;
supported_combination = g_array_sized_new (FALSE, FALSE, sizeof (MMModemBand), bands_2g[i].n_mm_bands);
g_array_append_vals (supported_combination, bands_2g[i].mm_bands, bands_2g[i].n_mm_bands);
/* Check if the given array is exactly one of the supported combinations */
if (mm_common_bands_garray_cmp (bands_array_final, supported_combination))
cinterion_band = g_strdup (bands_2g[i].cinterion_band);
g_array_unref (supported_combination);
}
bands_string = mm_common_build_bands_string ((MMModemBand *)bands_array_final->data,
bands_array_final->len);
g_array_unref (bands_array_final);
if (!cinterion_band) {
g_simple_async_result_set_error (result,
MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED,
"The given band combination is not supported: '%s'",
bands_string);
g_simple_async_result_complete_in_idle (result);
g_object_unref (result);
g_free (bands_string);
return; return;
} }
/* Build string with the value, in the proper charset */
mm_dbg ("Setting new bands to use: '%s'", bands_string); bandstr = g_strdup_printf ("%u", band);
cinterion_band = (mm_broadband_modem_take_and_convert_to_current_charset ( bandstr = mm_broadband_modem_take_and_convert_to_current_charset (MM_BROADBAND_MODEM (self), bandstr);
MM_BROADBAND_MODEM (self), if (!bandstr) {
cinterion_band)); g_simple_async_result_set_error (simple,
if (!cinterion_band) {
g_simple_async_result_set_error (result,
MM_CORE_ERROR, MM_CORE_ERROR,
MM_CORE_ERROR_UNSUPPORTED, MM_CORE_ERROR_UNSUPPORTED,
"Couldn't convert band set to current charset"); "Couldn't convert band set to current charset");
g_simple_async_result_complete_in_idle (result); g_simple_async_result_complete_in_idle (simple);
g_object_unref (result); g_object_unref (simple);
g_free (bands_string);
return; return;
} }
@@ -1176,20 +1136,17 @@ set_bands_2g (MMIfaceModem *self,
* the modem to connect at that specific frequency only. Note that we will be * the modem to connect at that specific frequency only. Note that we will be
* passing double-quote enclosed strings here! * passing double-quote enclosed strings here!
*/ */
cmd = g_strdup_printf ("^SCFG=\"Radio/Band\",\"%s\",\"%s\"", cmd = g_strdup_printf ("^SCFG=\"Radio/Band\",\"%s\",\"%s\"", bandstr, bandstr);
cinterion_band,
cinterion_band);
mm_base_modem_at_command (MM_BASE_MODEM (self), mm_base_modem_at_command (MM_BASE_MODEM (self),
cmd, cmd,
15, 15,
FALSE, FALSE,
(GAsyncReadyCallback)scfg_set_ready, (GAsyncReadyCallback)scfg_set_ready,
result); simple);
g_free (cmd); g_free (cmd);
g_free (cinterion_band); g_free (bandstr);
g_free (bands_string);
} }
static void static void

View File

@@ -48,6 +48,18 @@ static const CinterionBand cinterion_bands[] = {
{ (1 << 8), MM_MODEM_BAND_U800 } { (1 << 8), MM_MODEM_BAND_U800 }
}; };
/* Check valid combinations in 2G-only devices */
#define VALIDATE_2G_BAND(cinterion_mask) \
(cinterion_mask == 1 || \
cinterion_mask == 2 || \
cinterion_mask == 4 || \
cinterion_mask == 8 || \
cinterion_mask == 3 || \
cinterion_mask == 5 || \
cinterion_mask == 10 || \
cinterion_mask == 12 || \
cinterion_mask == 15)
/*****************************************************************************/ /*****************************************************************************/
/* ^SCFG (3G) test parser /* ^SCFG (3G) test parser
* *
@@ -228,6 +240,7 @@ mm_cinterion_parse_scfg_response (const gchar *response,
gboolean gboolean
mm_cinterion_build_band (GArray *bands, mm_cinterion_build_band (GArray *bands,
guint supported, guint supported,
gboolean only_2g,
guint *out_band, guint *out_band,
GError **error) GError **error)
{ {
@@ -249,6 +262,12 @@ mm_cinterion_build_band (GArray *bands,
} }
} }
} }
/* 2G-only modems only support a subset of the possible band
* combinations. Detect it early and error out.
*/
if (only_2g && !VALIDATE_2G_BAND (band))
band = 0;
} }
if (band == 0) { if (band == 0) {

View File

@@ -39,6 +39,7 @@ gboolean mm_cinterion_parse_scfg_response (const gchar *response,
gboolean mm_cinterion_build_band (GArray *bands, gboolean mm_cinterion_build_band (GArray *bands,
guint supported, guint supported,
gboolean only_2g,
guint *out_band, guint *out_band,
GError **error); GError **error);