diff options
author | Sven Schwermer <sven.schwermer@disruptive-technologies.com> | 2022-11-08 10:17:08 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@aleksander.es> | 2022-12-06 14:03:47 +0000 |
commit | e96ea83f61e714eb8bfa959b9a5394f630f5a8b9 (patch) | |
tree | 1acaa62175d0210231af6a0a8f4054a96acf51c8 | |
parent | 279d1c99c4d7c4021215b9d7293f1a8d4fd47917 (diff) |
iface-modem-3gpp: Check before registering
If the modem is already registered when ModemManager probes the modem,
it will ignore the registration state since the modem is not enabled
yet. Always querying the registration state before starting the
registration procedure makes sure to catch such cases and not perform
unnecessary registration steps.
Signed-off-by: Sven Schwermer <sven.schwermer@disruptive-technologies.com>
-rw-r--r-- | src/mm-iface-modem-3gpp.c | 115 |
1 files changed, 71 insertions, 44 deletions
diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 5fdcaaf3..6766ddf6 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -402,6 +402,7 @@ typedef struct { MMIfaceModem3gpp *self; MmGdbusModem3gpp *skeleton; GCancellable *cancellable; + gboolean force_registration; gchar *operator_id; GTimer *timer; guint max_registration_time; @@ -556,55 +557,24 @@ register_in_network_ready (MMIfaceModem3gpp *self, run_registration_checks (task); } -void -mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self, - const gchar *operator_id, - gboolean force_registration, - guint max_registration_time, - GAsyncReadyCallback callback, - gpointer user_data) +static void +initial_registration_checks_ready (MMIfaceModem3gpp *self, + GAsyncResult *res, + GTask *task) { + Private *priv; RegisterInNetworkContext *ctx; - const gchar *current_operator_code; GError *error = NULL; - GTask *task; - Private *priv; + const gchar *current_operator_code; MMModem3gppRegistrationState reg_state; priv = get_private (self); + ctx = g_task_get_task_data (task); - ctx = g_slice_new0 (RegisterInNetworkContext); - ctx->self = g_object_ref (self); - ctx->operator_id = (operator_id && operator_id[0]) ? g_strdup (operator_id) : NULL; - ctx->max_registration_time = max_registration_time; - - task = g_task_new (self, NULL, callback, user_data); - g_task_set_task_data (task, ctx, (GDestroyNotify)register_in_network_context_free); - - g_object_get (self, - MM_IFACE_MODEM_3GPP_DBUS_SKELETON, &ctx->skeleton, - NULL); - if (!ctx->skeleton) { - g_task_return_new_error (task, - MM_CORE_ERROR, - MM_CORE_ERROR_FAILED, - "Couldn't get interface skeleton"); - g_object_unref (task); - return; - } - - /* Validate input MCC/MNC */ - if (ctx->operator_id && !mm_3gpp_parse_operator_id (ctx->operator_id, NULL, NULL, NULL, &error)) { - g_assert (error != NULL); - g_task_return_error (task, error); - g_object_unref (task); - return; - } - - /* (Try to) cancel previous registration request */ - if (priv->pending_registration_cancellable) { - g_cancellable_cancel (priv->pending_registration_cancellable); - g_clear_object (&priv->pending_registration_cancellable); + if (!mm_iface_modem_3gpp_run_registration_checks_finish (self, res, &error)) { + mm_obj_info (self, "Initial 3GPP registration check failed: %s", error->message); + g_error_free (error); + /* Just continue as if nothing happened */ } current_operator_code = mm_gdbus_modem3gpp_get_operator_code (ctx->skeleton); @@ -613,7 +583,7 @@ mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self, /* Manual registration requested? */ if (ctx->operator_id) { /* If already registered manually with the requested operator, we're done */ - if (!force_registration && + if (!ctx->force_registration && (g_strcmp0 (current_operator_code, ctx->operator_id) == 0) && mm_modem_3gpp_registration_state_is_registered (reg_state) && priv->manual_registration) { @@ -634,7 +604,7 @@ mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self, else { /* If the modem is already registered and the last time it was asked * automatic registration, we're done */ - if (!force_registration && + if (!ctx->force_registration && mm_modem_3gpp_registration_state_is_registered (reg_state) && !priv->manual_registration) { mm_obj_info (self, "already registered automatically in network '%s'," @@ -666,6 +636,63 @@ mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self, task); } +void +mm_iface_modem_3gpp_register_in_network (MMIfaceModem3gpp *self, + const gchar *operator_id, + gboolean force_registration, + guint max_registration_time, + GAsyncReadyCallback callback, + gpointer user_data) +{ + Private *priv; + RegisterInNetworkContext *ctx; + GTask *task; + GError *error = NULL; + + priv = get_private (self); + + ctx = g_slice_new0 (RegisterInNetworkContext); + ctx->self = g_object_ref (self); + ctx->force_registration = force_registration; + ctx->operator_id = (operator_id && operator_id[0]) ? g_strdup (operator_id) : NULL; + ctx->max_registration_time = max_registration_time; + + task = g_task_new (self, NULL, callback, user_data); + g_task_set_task_data (task, ctx, (GDestroyNotify)register_in_network_context_free); + + g_object_get (self, + MM_IFACE_MODEM_3GPP_DBUS_SKELETON, &ctx->skeleton, + NULL); + if (!ctx->skeleton) { + g_task_return_new_error (task, + MM_CORE_ERROR, + MM_CORE_ERROR_FAILED, + "Couldn't get interface skeleton"); + g_object_unref (task); + return; + } + + /* Validate input MCC/MNC */ + if (ctx->operator_id && !mm_3gpp_parse_operator_id (ctx->operator_id, NULL, NULL, NULL, &error)) { + g_assert (error != NULL); + g_task_return_error (task, error); + g_object_unref (task); + return; + } + + /* (Try to) cancel previous registration request */ + if (priv->pending_registration_cancellable) { + g_cancellable_cancel (priv->pending_registration_cancellable); + g_clear_object (&priv->pending_registration_cancellable); + } + + /* Query initial registration state here in order to avoid re-registering. */ + mm_iface_modem_3gpp_run_registration_checks ( + self, + (GAsyncReadyCallback)initial_registration_checks_ready, + task); +} + /*****************************************************************************/ /* Request to reregister using the last settings */ |