diff options
author | Aleksander Morgado <aleksander@aleksander.es> | 2019-12-18 15:02:37 +0100 |
---|---|---|
committer | Dan Williams <dcbw@redhat.com> | 2020-01-06 20:17:08 +0000 |
commit | 88983fd1572cc912ad0f905caf172a976f6433f0 (patch) | |
tree | 4f347b3317422e8ad8052e6939ff4f83ab1ea16a | |
parent | a1966222e9df597f5b6ab98cc383b7065463967e (diff) |
cinterion: use common re-registration logic when needed
If the modem requires +COPS re-registration after setting modes,
use the common logic provided by the 3GPP interface, which
already knows e.g. whether the registration was automatic or the
actual requested operator id in case of being manual.
-rw-r--r-- | plugins/cinterion/mm-broadband-modem-cinterion.c | 89 |
1 files changed, 18 insertions, 71 deletions
diff --git a/plugins/cinterion/mm-broadband-modem-cinterion.c b/plugins/cinterion/mm-broadband-modem-cinterion.c index a99db326..fc6381d8 100644 --- a/plugins/cinterion/mm-broadband-modem-cinterion.c +++ b/plugins/cinterion/mm-broadband-modem-cinterion.c @@ -74,9 +74,6 @@ struct _MMBroadbandModemCinterionPrivate { /* Command to go into sleep mode */ gchar *sleep_mode_cmd; - /* Cached manual selection attempt */ - gchar *manual_operator_id; - /* Cached supported bands in Cinterion format */ guint supported_bands; @@ -1054,6 +1051,20 @@ set_current_modes_finish (MMIfaceModem *self, } static void +set_current_modes_reregister_in_network_ready (MMIfaceModem3gpp *self, + GAsyncResult *res, + GTask *task) +{ + GError *error = NULL; + + if (!mm_iface_modem_3gpp_reregister_in_network_finish (self, res, &error)) + g_task_return_error (task, error); + else + g_task_return_boolean (task, TRUE); + g_object_unref (task); +} + +static void allowed_access_technology_update_ready (MMBroadbandModemCinterion *self, GAsyncResult *res, GTask *task) @@ -1105,10 +1116,10 @@ set_current_modes (MMIfaceModem *_self, * AT+COPS=,,, (i.e. just without a last value). Instead, we need to * re-run the last manual/automatic selection command which succeeded, * (or auto by default if none was launched) */ - if (self->priv->manual_operator_id) - command = g_strdup_printf ("+COPS=1,2,\"%s\"", self->priv->manual_operator_id); - else - command = g_strdup ("+COPS=0"); + mm_iface_modem_3gpp_reregister_in_network (MM_IFACE_MODEM_3GPP (self), + (GAsyncReadyCallback) set_current_modes_reregister_in_network_ready, + task); + return; } mm_base_modem_at_command ( @@ -1123,66 +1134,6 @@ set_current_modes (MMIfaceModem *_self, } /*****************************************************************************/ -/* Register in network (3GPP interface) */ - -static gboolean -register_in_network_finish (MMIfaceModem3gpp *self, - GAsyncResult *res, - GError **error) -{ - return g_task_propagate_boolean (G_TASK (res), error); -} - -static void -cops_write_ready (MMBaseModem *_self, - GAsyncResult *res, - GTask *task) -{ - MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (_self); - GError *error = NULL; - - if (!mm_base_modem_at_command_full_finish (_self, res, &error)) - g_task_return_error (task, error); - else { - g_free (self->priv->manual_operator_id); - self->priv->manual_operator_id = g_strdup (g_task_get_task_data (task)); - g_task_return_boolean (task, TRUE); - } - g_object_unref (task); -} - -static void -register_in_network (MMIfaceModem3gpp *self, - const gchar *operator_id, - GCancellable *cancellable, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GTask *task; - gchar *command; - - task = g_task_new (self, cancellable, callback, user_data); - g_task_set_task_data (task, g_strdup (operator_id), g_free); - - /* If the user sent a specific network to use, lock it in. */ - if (operator_id) - command = g_strdup_printf ("+COPS=1,2,\"%s\"", operator_id); - else - command = g_strdup ("+COPS=0"); - - mm_base_modem_at_command_full (MM_BASE_MODEM (self), - mm_base_modem_peek_best_at_port (MM_BASE_MODEM (self), NULL), - command, - 120, - FALSE, - FALSE, /* raw */ - cancellable, - (GAsyncReadyCallback)cops_write_ready, - task); - g_free (command); -} - -/*****************************************************************************/ /* Supported bands (Modem interface) */ static GArray * @@ -1865,7 +1816,6 @@ finalize (GObject *object) MMBroadbandModemCinterion *self = MM_BROADBAND_MODEM_CINTERION (object); g_free (self->priv->sleep_mode_cmd); - g_free (self->priv->manual_operator_id); if (self->priv->cnmi_supported_mode) g_array_unref (self->priv->cnmi_supported_mode); @@ -1930,9 +1880,6 @@ iface_modem_3gpp_init (MMIfaceModem3gpp *iface) iface->setup_unsolicited_events_finish = modem_3gpp_setup_cleanup_unsolicited_events_finish; iface->cleanup_unsolicited_events = modem_3gpp_cleanup_unsolicited_events; iface->cleanup_unsolicited_events_finish = modem_3gpp_setup_cleanup_unsolicited_events_finish; - - iface->register_in_network = register_in_network; - iface->register_in_network_finish = register_in_network_finish; } static void |