From: Pekka Pessi <pekka.pe...@nokia.com>

If SIM is not ready, the ofono_sim_driver indicates that with
query_passwd_state callback returning OFONO_SIM_PASSWORD_INVALID.

After the driver determines that SIM is ready, it calls
ofono_sim_ready_notify().

Based on patches by Kristen Accardi and Denis Kenzior.
---
 include/sim.h |    2 ++
 src/sim.c     |   26 ++++++++++++++++++++++++++
 2 files changed, 28 insertions(+), 0 deletions(-)

diff --git a/include/sim.h b/include/sim.h
index 7860e24..f4171d1 100644
--- a/include/sim.h
+++ b/include/sim.h
@@ -188,6 +188,8 @@ enum ofono_sim_state ofono_sim_get_state(struct ofono_sim 
*sim);
 
 void ofono_sim_inserted_notify(struct ofono_sim *sim, ofono_bool_t inserted);
 
+void ofono_sim_ready_notify(struct ofono_sim *sim);
+
 /* This will queue an operation to read all available records with id from the
  * SIM.  Callback cb will be called every time a record has been read, or once
  * if an error has occurred.  For transparent files, the callback will only
diff --git a/src/sim.c b/src/sim.c
index 695562f..b0462c8 100644
--- a/src/sim.c
+++ b/src/sim.c
@@ -86,6 +86,8 @@ struct ofono_sim {
        unsigned char *efimg;
        unsigned short efimg_length;
 
+       gboolean waiting_ready;
+
        enum ofono_sim_state state;
        struct ofono_watchlist *state_watches;
 
@@ -1407,6 +1409,14 @@ static void sim_pin_query_cb(const struct ofono_error 
*error,
                goto checkdone;
        }
 
+       if (pin_type == OFONO_SIM_PASSWORD_INVALID) {
+               DBG("Waiting for ready notification");
+
+               sim->waiting_ready = TRUE;
+
+               return;
+       }
+
        if (sim->pin_type != pin_type) {
                sim->pin_type = pin_type;
                pin_name = sim_passwd_name(pin_type);
@@ -1431,6 +1441,8 @@ checkdone:
 
 static void sim_pin_check(struct ofono_sim *sim)
 {
+       sim->waiting_ready = FALSE;
+
        if (!sim->driver->query_passwd_state) {
                sim_initialize_after_pin(sim);
                return;
@@ -1439,6 +1451,20 @@ static void sim_pin_check(struct ofono_sim *sim)
        sim->driver->query_passwd_state(sim, sim_pin_query_cb, sim);
 }
 
+void ofono_sim_ready_notify(struct ofono_sim *sim)
+{
+       DBG("");
+
+       if (sim == NULL)
+               return;
+
+       if (sim->state != OFONO_SIM_STATE_INSERTED)
+               return;
+
+       if (sim->waiting_ready)
+               sim_pin_check(sim);
+}
+
 static void sim_efli_read_cb(int ok, int length, int record,
                                const unsigned char *data,
                                int record_length, void *userdata)
-- 
1.7.1

_______________________________________________
ofono mailing list
ofono@ofono.org
http://lists.ofono.org/listinfo/ofono

Reply via email to