From: Pekka Pessi <[email protected]>

The PIN reset requires that modem waits for corresponding PUK code.
---
 drivers/atmodem/sim.c |   14 ++++++++++++--
 1 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/drivers/atmodem/sim.c b/drivers/atmodem/sim.c
index 21bc933..a80891c 100644
--- a/drivers/atmodem/sim.c
+++ b/drivers/atmodem/sim.c
@@ -44,6 +44,7 @@
 struct sim_data {
        GAtChat *chat;
        unsigned int vendor;
+       enum ofono_sim_password_type cpin_type;
        guint epev_id;
        guint epev_source;
 };
@@ -459,6 +460,8 @@ static void at_cpin_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
        int len = sizeof(at_sim_name) / sizeof(*at_sim_name);
        const char *final = g_at_result_final_response(result);
 
+       sd->cpin_type = OFONO_SIM_PASSWORD_NONE;
+
        if (sd->vendor == OFONO_VENDOR_WAVECOM && ok && strlen(final) > 7)
                decode_at_error(&error, "OK");
        else
@@ -498,6 +501,8 @@ static void at_cpin_cb(gboolean ok, GAtResult *result, 
gpointer user_data)
 
        DBG("crsm_pin_cb: %s", pin_required);
 
+       sd->cpin_type = pin_type;
+
        cb(&error, pin_type, cbd->data);
 }
 
@@ -616,8 +621,9 @@ error:
        CALLBACK_WITH_FAILURE(cb, data);
 }
 
-static void at_pin_send_puk(struct ofono_sim *sim, const char *puk,
-                               const char *passwd,
+static void at_pin_send_puk(struct ofono_sim *sim,
+                               enum ofono_sim_password_type type,
+                               const char *puk, const char *passwd,
                                ofono_sim_lock_unlock_cb_t cb, void *data)
 {
        struct sim_data *sd = ofono_sim_get_data(sim);
@@ -628,6 +634,10 @@ static void at_pin_send_puk(struct ofono_sim *sim, const 
char *puk,
        if (!cbd)
                goto error;
 
+       if (type != OFONO_SIM_PASSWORD_SIM_PIN ||
+                       sd->cpin_type != OFONO_SIM_PASSWORD_SIM_PUK)
+               goto error;
+
        snprintf(buf, sizeof(buf), "AT+CPIN=\"%s\",\"%s\"", puk, passwd);
 
        ret = g_at_chat_send(sd->chat, buf, none_prefix,
-- 
1.7.0.4

_______________________________________________
ofono mailing list
[email protected]
http://lists.ofono.org/listinfo/ofono

Reply via email to