ModemManager: [PATCH 1/2] Improvements to SIM PIN handling




From 7c718db20958c200bc9dcb086763bfe0ebb91399 Mon Sep 17 00:00:00 2001
From: Eric Shienbrood <ers google com>
Date: Thu, 14 Jul 2011 19:11:54 -0400
Subject: [PATCH] Correctly track the number of SIM PIN retries left.

There are other operations besides SendPin and SendPuk that
can result in the retry count being decremented. An EnablePin
or ChangePin in which an incorrect PIN is supplied will also
decrement the retry count, and will put the SIM into blocked
mode (requiring a PUK) if the retry count drops to zero. To
correctly track this, the retry count needs to be fetched after
each of these operations, and also initially when AT+CPIN? returns
READY.
---
 .../org.freedesktop.ModemManager.Modem.xml         |    6 ++-
 src/mm-generic-gsm.c                               |   33 +++++++++++++++++++-
 2 files changed, 36 insertions(+), 3 deletions(-)

diff --git a/introspection/org.freedesktop.ModemManager.Modem.xml b/introspection/org.freedesktop.ModemManager.Modem.xml
index a71a634..3540dbe 100644
--- a/introspection/org.freedesktop.ModemManager.Modem.xml
+++ b/introspection/org.freedesktop.ModemManager.Modem.xml
@@ -171,8 +171,10 @@
 
     <property name="UnlockRetries" type="u" access="read">
       <tp:docstring>
-        The number of unlock retries remaining for the unlock code given by the property UnlockRequired, or 999 if
-        the device does not support reporting unlock retries.
+        The number of unlock retries remaining for the unlock code given by the
+        property UnlockRequired, or 999 if the device does not support reporting
+        unlock retries. If UnlockRequired is blank, this property gives the
+        number of tries allowed for changing or disabling sim-pin.
       </tp:docstring>
     </property>
 
diff --git a/src/mm-generic-gsm.c b/src/mm-generic-gsm.c
index 82e51f6..82dcf00 100644
--- a/src/mm-generic-gsm.c
+++ b/src/mm-generic-gsm.c
@@ -295,7 +295,10 @@ pin_check_done (MMAtSerialPort *port,
         if (g_str_has_prefix (str, "READY")) {
             mm_modem_base_set_unlock_required (MM_MODEM_BASE (info->modem), NULL);
             if (MM_MODEM_GSM_CARD_GET_INTERFACE (info->modem)->get_unlock_retries)
-                mm_modem_base_set_unlock_retries (MM_MODEM_BASE (info->modem), 0);
+                mm_modem_gsm_card_get_unlock_retries (MM_MODEM_GSM_CARD (info->modem),
+                                                      "sim-pin",
+                                                      get_unlock_retries_cb,
+                                                      NULL);
             else
                 mm_modem_base_set_unlock_retries (MM_MODEM_BASE (info->modem),
                                                   MM_MODEM_GSM_CARD_UNLOCK_RETRIES_NOT_SUPPORTED);
@@ -2219,6 +2222,32 @@ pin_puk_recheck_done (MMModem *modem, GError *error, gpointer user_data)
     mm_callback_info_schedule (info);
 }
 
+/* Following an operation other than unlock that requires
+ * a pin, refetch the retry count, which may have changed
+ * if an incorrect PIN was supplied. Check also for a SIM_PUK
+ * error, which occurs if PIN retries has reached zero. */
+static void
+update_pin_puk_status(MMCallbackInfo *info, GError *error)
+{
+    const char *pin_type = "sim-pin";
+
+    if (error) {
+        if (error->domain != MM_MOBILE_ERROR)
+            return;
+        if (error->code == MM_MOBILE_ERROR_SIM_PUK) {
+            mm_modem_base_set_unlock_required (MM_MODEM_BASE (info->modem),
+                                               "sim-puk");
+            pin_type = "sim-puk";
+        } else if (error->code != MM_MOBILE_ERROR_WRONG_PASSWORD) {
+            return;
+        }
+    }
+    mm_modem_gsm_card_get_unlock_retries (MM_MODEM_GSM_CARD (info->modem),
+                                          pin_type,
+                                          get_unlock_retries_cb,
+                                          NULL);
+}
+
 static void
 send_puk_done (MMAtSerialPort *port,
                GString *response,
@@ -2369,6 +2398,7 @@ enable_pin_done (MMAtSerialPort *port,
     if (mm_callback_info_check_modem_removed (info))
         return;
 
+    update_pin_puk_status(info, error);
     if (error)
         info->error = g_error_copy (error);
     mm_callback_info_schedule (info);
@@ -2404,6 +2434,7 @@ change_pin_done (MMAtSerialPort *port,
     if (mm_callback_info_check_modem_removed (info))
         return;
 
+    update_pin_puk_status(info, error);
     if (error)
         info->error = g_error_copy (error);
     mm_callback_info_schedule (info);
-- 
1.7.3.1



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]