From 5815d9547c0be1cf1f1421aa44b9d9b394dd1391 Mon Sep 17 00:00:00 2001 From: Andrzej Zaborowski Date: Tue, 15 Feb 2011 08:58:51 +0100 Subject: modem.c: Handle SIM Resets The assumption so far was that SIM state would only go from NOT_PRESENT -> INSERTED -> READY -> NOT_PRESENT because there's no method to unauthenticate from SIM without removing. We need to be able to switch to INSERTED when SIM is being reset, reinitialised, etc. because going to NOT_PRESENT and then immediately INSERTED would be logically wrong. --- src/modem.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/modem.c b/src/modem.c index bf8b0c08..3dd44ad1 100644 --- a/src/modem.c +++ b/src/modem.c @@ -532,7 +532,7 @@ static void common_online_cb(const struct ofono_error *error, void *data) * * Additionally, this process can be interrupted by the following * events: - * - Sim being removed + * - Sim being removed or reset * - SetProperty(Powered, False) being called * - SetProperty(Lockdown, True) being called * @@ -546,7 +546,7 @@ static void common_online_cb(const struct ofono_error *error, void *data) /* The powered operation is pending */ break; case MODEM_STATE_PRE_SIM: - /* Go back offline if the sim was removed */ + /* Go back offline if the sim was removed or reset */ modem->driver->set_online(modem, 0, NULL, NULL); break; case MODEM_STATE_ONLINE: @@ -598,9 +598,13 @@ static void sim_state_watch(enum ofono_sim_state new_state, void *user) switch (new_state) { case OFONO_SIM_STATE_NOT_PRESENT: - modem_change_state(modem, MODEM_STATE_PRE_SIM); - break; case OFONO_SIM_STATE_INSERTED: + if (modem->modem_state != MODEM_STATE_PRE_SIM) { + if (modem->modem_state == MODEM_STATE_ONLINE) + modem->get_online = TRUE; + + modem_change_state(modem, MODEM_STATE_PRE_SIM); + } break; case OFONO_SIM_STATE_READY: modem_change_state(modem, MODEM_STATE_OFFLINE); -- cgit v1.2.3