ublox: rework support config loading
Make mm_ublox_get_support_config() return FALSE only when GError is set. And also, prepare a preload_support_config() method to be run before using any information from the support configuration (i.e. don't do it in load_supported_bands(), do it in load_current_bands() or in set_current_bands().
This commit is contained in:
@@ -71,6 +71,67 @@ struct _MMBroadbandModemUbloxPrivate {
|
||||
GRegex *pbready_regex;
|
||||
};
|
||||
|
||||
/*****************************************************************************/
|
||||
/* Per-model configuration loading */
|
||||
|
||||
static void
|
||||
preload_support_config (MMBroadbandModemUblox *self)
|
||||
{
|
||||
const gchar *model;
|
||||
GError *error = NULL;
|
||||
|
||||
/* Make sure we load only once */
|
||||
if (self->priv->support_config.loaded)
|
||||
return;
|
||||
|
||||
model = mm_iface_modem_get_model (MM_IFACE_MODEM (self));
|
||||
|
||||
if (!mm_ublox_get_support_config (model, &self->priv->support_config, &error)) {
|
||||
mm_warn ("loading support configuration failed: %s", error->message);
|
||||
g_error_free (error);
|
||||
|
||||
/* default to NOT SUPPORTED if unknown model */
|
||||
self->priv->support_config.method = BAND_UPDATE_NEEDS_UNKNOWN;
|
||||
self->priv->support_config.uact = FEATURE_UNSUPPORTED;
|
||||
self->priv->support_config.ubandsel = FEATURE_UNSUPPORTED;
|
||||
} else
|
||||
mm_dbg ("support configuration found for '%s'", model);
|
||||
|
||||
switch (self->priv->support_config.method) {
|
||||
case BAND_UPDATE_NEEDS_CFUN:
|
||||
mm_dbg (" band update requires low-power mode");
|
||||
break;
|
||||
case BAND_UPDATE_NEEDS_COPS:
|
||||
mm_dbg (" band update requires explicit unregistration");
|
||||
break;
|
||||
case BAND_UPDATE_NEEDS_UNKNOWN:
|
||||
/* not an error, this just means we don't need anything special */
|
||||
break;
|
||||
}
|
||||
|
||||
switch (self->priv->support_config.uact) {
|
||||
case FEATURE_SUPPORTED:
|
||||
mm_dbg (" UACT based band configuration supported");
|
||||
break;
|
||||
case FEATURE_UNSUPPORTED:
|
||||
mm_dbg (" UACT based band configuration unsupported");
|
||||
break;
|
||||
case FEATURE_SUPPORT_UNKNOWN:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
switch (self->priv->support_config.ubandsel) {
|
||||
case FEATURE_SUPPORTED:
|
||||
mm_dbg (" UBANDSEL based band configuration supported");
|
||||
break;
|
||||
case FEATURE_UNSUPPORTED:
|
||||
mm_dbg (" UBANDSEL based band configuration unsupported");
|
||||
break;
|
||||
case FEATURE_SUPPORT_UNKNOWN:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
static gboolean
|
||||
@@ -105,22 +166,20 @@ load_supported_bands_finish (MMIfaceModem *self,
|
||||
}
|
||||
|
||||
static void
|
||||
load_supported_bands (MMIfaceModem *_self,
|
||||
load_supported_bands (MMIfaceModem *self,
|
||||
GAsyncReadyCallback callback,
|
||||
gpointer user_data)
|
||||
{
|
||||
MMBroadbandModemUblox *self = MM_BROADBAND_MODEM_UBLOX (_self);
|
||||
GTask *task;
|
||||
GError *error = NULL;
|
||||
GArray *bands = NULL;
|
||||
const gchar *model;
|
||||
|
||||
model = mm_iface_modem_get_model (_self);
|
||||
GTask *task;
|
||||
GError *error = NULL;
|
||||
GArray *bands = NULL;
|
||||
const gchar *model;
|
||||
|
||||
model = mm_iface_modem_get_model (MM_BROADBAND_MODEM_UBLOX (self));
|
||||
task = g_task_new (_self, NULL, callback, user_data);
|
||||
|
||||
bands = mm_ublox_get_supported_bands (model, &error);
|
||||
if (!bands || !mm_ublox_get_support_config (model, &self->priv->support_config, &error))
|
||||
if (!bands)
|
||||
g_task_return_error (task, error);
|
||||
else
|
||||
g_task_return_pointer (task, bands, (GDestroyNotify) g_array_unref);
|
||||
@@ -157,8 +216,7 @@ load_current_bands (MMIfaceModem *_self,
|
||||
{
|
||||
MMBroadbandModemUblox *self = MM_BROADBAND_MODEM_UBLOX (_self);
|
||||
|
||||
g_assert (self->priv->support_config.uact != FEATURE_SUPPORT_UNKNOWN &&
|
||||
self->priv->support_config.ubandsel != FEATURE_SUPPORT_UNKNOWN);
|
||||
preload_support_config (self);
|
||||
|
||||
if (self->priv->support_config.ubandsel == FEATURE_SUPPORTED) {
|
||||
mm_base_modem_at_command (
|
||||
@@ -451,6 +509,8 @@ set_current_modes (MMIfaceModem *self,
|
||||
gchar *command;
|
||||
GError *error = NULL;
|
||||
|
||||
preload_support_config (MM_BROADBAND_MODEM_UBLOX (self));
|
||||
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
|
||||
/* Handle ANY */
|
||||
@@ -481,6 +541,8 @@ set_current_bands (MMIfaceModem *_self,
|
||||
gchar *command;
|
||||
const gchar *model;
|
||||
|
||||
preload_support_config (self);
|
||||
|
||||
task = g_task_new (self, NULL, callback, user_data);
|
||||
|
||||
model = mm_iface_modem_get_model (_self);
|
||||
@@ -1265,6 +1327,7 @@ mm_broadband_modem_ublox_init (MMBroadbandModemUblox *self)
|
||||
self->priv->profile = MM_UBLOX_USB_PROFILE_UNKNOWN;
|
||||
self->priv->mode = MM_UBLOX_NETWORKING_MODE_UNKNOWN;
|
||||
self->priv->any_allowed = MM_MODEM_MODE_NONE;
|
||||
self->priv->support_config.loaded = FALSE;
|
||||
self->priv->support_config.method = BAND_UPDATE_NEEDS_UNKNOWN;
|
||||
self->priv->support_config.uact = FEATURE_SUPPORT_UNKNOWN;
|
||||
self->priv->support_config.ubandsel = FEATURE_SUPPORT_UNKNOWN;
|
||||
|
@@ -926,30 +926,32 @@ static const BandConfiguration band_configuration[] = {
|
||||
},
|
||||
};
|
||||
|
||||
/* Returns AT command support configuration */
|
||||
|
||||
gboolean mm_ublox_get_support_config (const gchar *model,
|
||||
UbloxSupportConfig *config,
|
||||
GError **error)
|
||||
gboolean
|
||||
mm_ublox_get_support_config (const gchar *model,
|
||||
UbloxSupportConfig *config,
|
||||
GError **error)
|
||||
{
|
||||
guint i;
|
||||
|
||||
if (model) {
|
||||
for (i = 0; i < G_N_ELEMENTS (band_configuration); i++)
|
||||
if (g_str_has_prefix (model, band_configuration[i].model)) {
|
||||
config->method = band_configuration[i].method;
|
||||
config->uact = band_configuration[i].uact;
|
||||
config->ubandsel = band_configuration[i].ubandsel;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
if (i == G_N_ELEMENTS (band_configuration) || !(model)) {
|
||||
if (!model) {
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"Unknown support found for modem: %s", model);
|
||||
"Support configuration unknown for unknown model");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (band_configuration); i++) {
|
||||
/* NOTE: matching by prefix! */
|
||||
if (g_str_has_prefix (model, band_configuration[i].model)) {
|
||||
config->loaded = TRUE;
|
||||
config->method = band_configuration[i].method;
|
||||
config->uact = band_configuration[i].uact;
|
||||
config->ubandsel = band_configuration[i].ubandsel;
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
g_set_error (error, MM_CORE_ERROR, MM_CORE_ERROR_FAILED,
|
||||
"No support configuration found for modem: %s", model);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@@ -35,6 +35,7 @@ typedef enum {
|
||||
} UpdateMethod;
|
||||
|
||||
typedef struct UbloxSupportConfig {
|
||||
gboolean loaded;
|
||||
UpdateMethod method;
|
||||
FeatureSupport uact;
|
||||
FeatureSupport ubandsel;
|
||||
|
Reference in New Issue
Block a user