diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2018-12-24 16:09:06 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2019-01-30 12:10:03 +0100 |
commit | c3f4fe063f59a706bec35fab3839f9f873420c75 (patch) | |
tree | 59942d1001d472a1a785db5fae79df5fd726a23d | |
parent | f2e3798bb328aac2d27896274d4737c314caf257 (diff) | |
download | ModemManager-c3f4fe063f59a706bec35fab3839f9f873420c75.tar.gz |
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().
-rw-r--r-- | plugins/ublox/mm-broadband-modem-ublox.c | 85 | ||||
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.c | 38 | ||||
-rw-r--r-- | plugins/ublox/mm-modem-helpers-ublox.h | 1 |
3 files changed, 95 insertions, 29 deletions
diff --git a/plugins/ublox/mm-broadband-modem-ublox.c b/plugins/ublox/mm-broadband-modem-ublox.c index 8cc0ee44b..7ca433358 100644 --- a/plugins/ublox/mm-broadband-modem-ublox.c +++ b/plugins/ublox/mm-broadband-modem-ublox.c @@ -72,6 +72,67 @@ struct _MMBroadbandModemUbloxPrivate { }; /*****************************************************************************/ +/* 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 acquire_power_operation (MMBroadbandModemUblox *self, @@ -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; diff --git a/plugins/ublox/mm-modem-helpers-ublox.c b/plugins/ublox/mm-modem-helpers-ublox.c index 1fc598bf0..702992b3d 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.c +++ b/plugins/ublox/mm-modem-helpers-ublox.c @@ -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; } diff --git a/plugins/ublox/mm-modem-helpers-ublox.h b/plugins/ublox/mm-modem-helpers-ublox.h index 4a0eec1e1..1531552cd 100644 --- a/plugins/ublox/mm-modem-helpers-ublox.h +++ b/plugins/ublox/mm-modem-helpers-ublox.h @@ -35,6 +35,7 @@ typedef enum { } UpdateMethod; typedef struct UbloxSupportConfig { + gboolean loaded; UpdateMethod method; FeatureSupport uact; FeatureSupport ubandsel; |