sim: Check for SIM lockout condition
authorDenis Kenzior <denkenz@gmail.com>
Fri, 18 Feb 2011 17:24:08 +0000 (11:24 -0600)
committerDenis Kenzior <denkenz@gmail.com>
Fri, 18 Feb 2011 17:28:43 +0000 (11:28 -0600)
When a user tries to lock/unlock/change a PIN and enters it wrongly
several times, it is possible to lock themselves out.  In this case we
should drop to a pre-sim state, wait for the user to enter the PUK and
re-init the sim.

src/sim.c

index 58b4fee..c39269d 100644 (file)
--- a/src/sim.c
+++ b/src/sim.c
@@ -624,7 +624,7 @@ static void sim_unlock_cb(const struct ofono_error *error, void *data)
                DBusMessage *reply = __ofono_error_failed(sim->pending);
 
                __ofono_dbus_pending_reply(&sim->pending, reply);
-               sim_pin_retries_check(sim);
+               sim_pin_check(sim);
 
                return;
        }
@@ -640,7 +640,7 @@ static void sim_lock_cb(const struct ofono_error *error, void *data)
                DBusMessage *reply = __ofono_error_failed(sim->pending);
 
                __ofono_dbus_pending_reply(&sim->pending, reply);
-               sim_pin_retries_check(sim);
+               sim_pin_check(sim);
 
                return;
        }
@@ -711,7 +711,7 @@ static void sim_change_pin_cb(const struct ofono_error *error, void *data)
                __ofono_dbus_pending_reply(&sim->pending,
                                __ofono_error_failed(sim->pending));
 
-               sim_pin_retries_check(sim);
+               sim_pin_check(sim);
 
                return;
        }
@@ -2231,6 +2231,15 @@ static void sim_pin_query_cb(const struct ofono_error *error,
                                                &pin_name);
        }
 
+       if (pin_type != OFONO_SIM_PASSWORD_NONE &&
+                       sim->state == OFONO_SIM_STATE_READY) {
+               /* Force the sim state out of READY */
+               sim_free_main_state(sim);
+
+               sim->state = OFONO_SIM_STATE_INSERTED;
+               __ofono_modem_sim_reset(__ofono_atom_get_modem(sim->atom));
+       }
+
        sim_pin_retries_check(sim);
 
 checkdone: