diff options
author | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-09 19:48:43 +0100 |
---|---|---|
committer | Aleksander Morgado <aleksander@lanedo.com> | 2012-03-16 14:53:24 +0100 |
commit | d27e40ae9aea1166831920a92d4eba4f3f51605d (patch) | |
tree | 8afa0f609852eb5a501bdd98e56c7f012e34a007 /src | |
parent | 6de2e3f72cb058ce31b93274ede144d95c5440bc (diff) |
core: new `Initializing' state in the global modem state machine
We need to define a state to be used while the modem is being initialized, so
that we forbid any operation on the modem on already exported interfaces, while
there are interfaces pending to get exported.
This Initializing state will also cover the state between having the SIM
unlocked (which launches re-initialization) and being completely initialized.
Diffstat (limited to 'src')
-rw-r--r-- | src/mm-broadband-modem.c | 72 | ||||
-rw-r--r-- | src/mm-iface-modem-3gpp.c | 24 | ||||
-rw-r--r-- | src/mm-iface-modem-cdma.c | 22 | ||||
-rw-r--r-- | src/mm-iface-modem.c | 34 | ||||
-rw-r--r-- | src/mm-sim.c | 13 |
5 files changed, 128 insertions, 37 deletions
diff --git a/src/mm-broadband-modem.c b/src/mm-broadband-modem.c index 67996312..7473d231 100644 --- a/src/mm-broadband-modem.c +++ b/src/mm-broadband-modem.c @@ -6066,6 +6066,7 @@ disable (MMBaseModem *self, g_assert_not_reached (); break; + case MM_MODEM_STATE_INITIALIZING: case MM_MODEM_STATE_LOCKED: case MM_MODEM_STATE_DISABLED: /* Just return success, don't relaunch enabling */ @@ -6338,6 +6339,14 @@ enable (MMBaseModem *self, g_assert_not_reached (); break; + case MM_MODEM_STATE_INITIALIZING: + g_simple_async_result_set_error (result, + MM_CORE_ERROR, + MM_CORE_ERROR_WRONG_STATE, + "Cannot enable modem: " + "device not fully initialized yet"); + break; + case MM_MODEM_STATE_LOCKED: g_simple_async_result_set_error (result, MM_CORE_ERROR, @@ -6663,6 +6672,12 @@ initialize_step (InitializeContext *ctx) case INITIALIZE_STEP_LAST: /* All initialized without errors! */ + + /* Set as disabled (a.k.a. initialized) */ + mm_iface_modem_update_state (MM_IFACE_MODEM (ctx->self), + MM_MODEM_STATE_DISABLED, + MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); + g_simple_async_result_set_op_res_gboolean (G_SIMPLE_ASYNC_RESULT (ctx->result), TRUE); initialize_context_complete_and_free (ctx); return; @@ -6677,18 +6692,55 @@ initialize (MMBaseModem *self, GAsyncReadyCallback callback, gpointer user_data) { - InitializeContext *ctx; + GSimpleAsyncResult *result; - ctx = g_new0 (InitializeContext, 1); - ctx->self = g_object_ref (self); - ctx->cancellable = g_object_ref (cancellable); - ctx->result = g_simple_async_result_new (G_OBJECT (self), - callback, - user_data, - initialize); - ctx->step = INITIALIZE_STEP_FIRST; + result = g_simple_async_result_new (G_OBJECT (self), callback, user_data, initialize); + + /* Check state before launching modem initialization */ + switch (MM_BROADBAND_MODEM (self)->priv->modem_state) { + case MM_MODEM_STATE_UNKNOWN: + case MM_MODEM_STATE_LOCKED: { + InitializeContext *ctx; + + ctx = g_new0 (InitializeContext, 1); + ctx->self = g_object_ref (self); + ctx->cancellable = g_object_ref (cancellable); + ctx->result = result; + ctx->step = INITIALIZE_STEP_FIRST; + + /* Set as being initialized, even if we were locked before */ + mm_iface_modem_update_state (MM_IFACE_MODEM (self), + MM_MODEM_STATE_INITIALIZING, + MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); + + initialize_step (ctx); + return; + } + + case MM_MODEM_STATE_INITIALIZING: + g_simple_async_result_set_error (result, + MM_CORE_ERROR, + MM_CORE_ERROR_WRONG_STATE, + "Cannot initialize modem: " + "already being initialized"); + break; + + case MM_MODEM_STATE_DISABLED: + case MM_MODEM_STATE_DISABLING: + case MM_MODEM_STATE_ENABLING: + case MM_MODEM_STATE_ENABLED: + case MM_MODEM_STATE_SEARCHING: + case MM_MODEM_STATE_REGISTERED: + case MM_MODEM_STATE_DISCONNECTING: + case MM_MODEM_STATE_CONNECTING: + case MM_MODEM_STATE_CONNECTED: + /* Just return success, don't relaunch initialization */ + g_simple_async_result_set_op_res_gboolean (result, TRUE); + break; + } - initialize_step (ctx); + g_simple_async_result_complete_in_idle (result); + g_object_unref (result); } /*****************************************************************************/ diff --git a/src/mm-iface-modem-3gpp.c b/src/mm-iface-modem-3gpp.c index 78cf94d3..16ddce6d 100644 --- a/src/mm-iface-modem-3gpp.c +++ b/src/mm-iface-modem-3gpp.c @@ -173,11 +173,19 @@ handle_register_auth_ready (MMBaseModem *self, g_assert_not_reached (); break; - case MM_MODEM_STATE_LOCKED: + case MM_MODEM_STATE_INITIALIZING: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, - "Cannot register modem: device locked"); + "Cannot register modem: " + "device not fully initialized yet"); + handle_register_context_free (ctx); + return; + + case MM_MODEM_STATE_LOCKED: + /* We should never have such request in LOCKED state + * (interface wasn't exported yet) */ + g_assert_not_reached (); break; case MM_MODEM_STATE_ENABLED: @@ -358,11 +366,19 @@ handle_scan_auth_ready (MMBaseModem *self, g_assert_not_reached (); break; - case MM_MODEM_STATE_LOCKED: + case MM_MODEM_STATE_INITIALIZING: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, - "Cannot scan networks: device locked"); + "Cannot scan networks: " + "device not fully initialized yet"); + handle_scan_context_free (ctx); + return; + + case MM_MODEM_STATE_LOCKED: + /* We should never have such request in LOCKED state + * (interface wasn't exported yet) */ + g_assert_not_reached (); break; case MM_MODEM_STATE_DISABLED: diff --git a/src/mm-iface-modem-cdma.c b/src/mm-iface-modem-cdma.c index ec5d27e6..bb338893 100644 --- a/src/mm-iface-modem-cdma.c +++ b/src/mm-iface-modem-cdma.c @@ -135,12 +135,19 @@ handle_activate_auth_ready (MMBaseModem *self, g_assert_not_reached (); break; - case MM_MODEM_STATE_LOCKED: + case MM_MODEM_STATE_INITIALIZING: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, "Cannot perform OTA activation: " - "device locked"); + "device not fully initialized yet"); + handle_activate_context_free (ctx); + return; + + case MM_MODEM_STATE_LOCKED: + /* We should never have such request in LOCKED state + * (interface wasn't exported yet) */ + g_assert_not_reached (); break; case MM_MODEM_STATE_ENABLED: @@ -278,12 +285,19 @@ handle_activate_manual_auth_ready (MMBaseModem *self, g_assert_not_reached (); break; - case MM_MODEM_STATE_LOCKED: + case MM_MODEM_STATE_INITIALIZING: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, MM_CORE_ERROR_WRONG_STATE, "Cannot perform manual activation: " - "device locked"); + "device not fully initialized yet"); + handle_activate_manual_context_free (ctx); + return; + + case MM_MODEM_STATE_LOCKED: + /* We should never have such request in LOCKED state + * (interface wasn't exported yet) */ + g_assert_not_reached (); break; case MM_MODEM_STATE_ENABLED: diff --git a/src/mm-iface-modem.c b/src/mm-iface-modem.c index b32de65d..50618496 100644 --- a/src/mm-iface-modem.c +++ b/src/mm-iface-modem.c @@ -985,10 +985,11 @@ mm_iface_modem_update_state (MMIfaceModem *self, NULL); /* Signal status change */ - mm_gdbus_modem_emit_state_changed (skeleton, - old_state, - new_state, - reason); + if (skeleton) + mm_gdbus_modem_emit_state_changed (skeleton, + old_state, + new_state, + reason); /* If we go to registered state (from unregistered), setup signal * quality and access technologies periodic retrieval */ @@ -1287,6 +1288,7 @@ handle_reset_auth_ready (MMBaseModem *self, switch (modem_state) { case MM_MODEM_STATE_UNKNOWN: + case MM_MODEM_STATE_INITIALIZING: case MM_MODEM_STATE_LOCKED: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, @@ -1399,6 +1401,7 @@ handle_factory_reset_auth_ready (MMBaseModem *self, switch (modem_state) { case MM_MODEM_STATE_UNKNOWN: + case MM_MODEM_STATE_INITIALIZING: case MM_MODEM_STATE_LOCKED: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, @@ -1662,6 +1665,7 @@ handle_set_bands_auth_ready (MMBaseModem *self, switch (modem_state) { case MM_MODEM_STATE_UNKNOWN: + case MM_MODEM_STATE_INITIALIZING: case MM_MODEM_STATE_LOCKED: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, @@ -1905,6 +1909,7 @@ handle_set_allowed_modes_auth_ready (MMBaseModem *self, switch (modem_state) { case MM_MODEM_STATE_UNKNOWN: + case MM_MODEM_STATE_INITIALIZING: case MM_MODEM_STATE_LOCKED: g_dbus_method_invocation_return_error (ctx->invocation, MM_CORE_ERROR, @@ -2000,10 +2005,13 @@ static void reinitialize_ready (MMBaseModem *self, GAsyncResult *res) { - mm_base_modem_initialize_finish (self, res, NULL); - mm_iface_modem_update_state (MM_IFACE_MODEM (self), - MM_MODEM_STATE_DISABLED, - MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); + GError *error = NULL; + + mm_base_modem_initialize_finish (self, res, &error); + if (error) { + mm_warn ("Modem reinitialization failed: '%s'", error->message); + g_error_free (error); + } } static gboolean @@ -2030,23 +2038,19 @@ set_lock_status (MMIfaceModem *self, if (lock == MM_MODEM_LOCK_NONE || lock == MM_MODEM_LOCK_SIM_PIN2 || lock == MM_MODEM_LOCK_SIM_PUK2) { - /* Notify transition from UNKNOWN/LOCKED to DISABLED */ + /* Notify transition from INITIALIZING/LOCKED to DISABLED */ if (old_lock != MM_MODEM_LOCK_NONE && old_lock != MM_MODEM_LOCK_SIM_PIN2 && old_lock != MM_MODEM_LOCK_SIM_PUK2) { - /* Only restart initialization if going from LOCKED to DISABLED. + /* Only restart initialization if leaving LOCKED. * If this is the case, we do NOT update the state yet, we wait * to be completely re-initialized to do so. */ if (old_lock != MM_MODEM_LOCK_UNKNOWN) g_idle_add ((GSourceFunc)restart_initialize_idle, self); - else - mm_iface_modem_update_state (self, - MM_MODEM_STATE_DISABLED, - MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); } } else { if (old_lock == MM_MODEM_LOCK_UNKNOWN) { - /* Notify transition from UNKNOWN to LOCKED */ + /* Notify transition from INITIALIZING to LOCKED */ mm_iface_modem_update_state (self, MM_MODEM_STATE_LOCKED, MM_MODEM_STATE_CHANGE_REASON_UNKNOWN); diff --git a/src/mm-sim.c b/src/mm-sim.c index 573fc24a..57ffee21 100644 --- a/src/mm-sim.c +++ b/src/mm-sim.c @@ -489,11 +489,15 @@ typedef struct { MMSim *self; GSimpleAsyncResult *result; GError *save_error; + gulong wait_for_unlock_id; } SendPinPukContext; static void send_pin_puk_context_complete_and_free (SendPinPukContext *ctx) { + if (ctx->wait_for_unlock_id) + g_signal_handler_disconnect (ctx->self->priv->modem, + ctx->wait_for_unlock_id); if (ctx->save_error) g_error_free (ctx->save_error); g_simple_async_result_complete (ctx->result); @@ -568,16 +572,17 @@ unlock_check_ready (MMIfaceModem *modem, g_simple_async_result_take_error (ctx->result, ctx->save_error); ctx->save_error = NULL; g_clear_error (&error); - } - else if (error) + } else if (error) g_simple_async_result_take_error (ctx->result, error); else g_simple_async_result_take_error (ctx->result, error_for_unlock_check (lock)); - } else - g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); + send_pin_puk_context_complete_and_free (ctx); + } + g_simple_async_result_set_op_res_gboolean (ctx->result, TRUE); send_pin_puk_context_complete_and_free (ctx); + return; } static void |