r3869 - in trunk/src/target/OM-2007.2/applications/openmoko-dialer2: . src/phone-kit

chris at sita.openmoko.org chris at sita.openmoko.org
Thu Jan 17 17:50:05 CET 2008


Author: chris
Date: 2008-01-17 17:50:04 +0100 (Thu, 17 Jan 2008)
New Revision: 3869

Modified:
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.c
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.h
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-network.c
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.c
   trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.h
Log:
        * src/phone-kit/moko-listener.c: (moko_listener_on_pin_requested):
        * src/phone-kit/moko-listener.h: 
        Flesh out on_pin_requested a bit better

        * src/phone-kit/moko-network.c: (on_pin_requested),
        (gsmd_eventhandler), (pin_msghandler):
        Handle PIN completely in on_pin_requested, provide custom messages for
        different PIN types

        * src/phone-kit/moko-pin.c: (get_pin_from_user),
        (display_pin_error):
        * src/phone-kit/moko-pin.h:
        Allow setting a custom message for PIN entry dialog


Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	2008-01-17 15:24:45 UTC (rev 3868)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/ChangeLog	2008-01-17 16:50:04 UTC (rev 3869)
@@ -1,5 +1,21 @@
 2008-01-17  Chris Lord  <chris at openedhand.com>
 
+	* src/phone-kit/moko-listener.c: (moko_listener_on_pin_requested):
+	* src/phone-kit/moko-listener.h:
+	Flesh out on_pin_requested a bit better
+
+	* src/phone-kit/moko-network.c: (on_pin_requested),
+	(gsmd_eventhandler), (pin_msghandler):
+	Handle PIN completely in on_pin_requested, provide custom messages for
+	different PIN types
+
+	* src/phone-kit/moko-pin.c: (get_pin_from_user),
+	(display_pin_error):
+	* src/phone-kit/moko-pin.h:
+	Allow setting a custom message for PIN entry dialog
+
+2008-01-17  Chris Lord  <chris at openedhand.com>
+
 	* src/phone-kit/moko-network.c: (moko_network_dispose), (io_func),
 	(network_init_gsmd):
 	Use GIOChannel instead of GSource for polling (simplifies code)

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.c	2008-01-17 15:24:45 UTC (rev 3868)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.c	2008-01-17 16:50:04 UTC (rev 3869)
@@ -62,11 +62,12 @@
 void
 moko_listener_on_pin_requested (MokoListener *listener,
                                  struct lgsm_handle *handle,
-                                 int type)
+                                 enum gsmd_pin_type type,
+                                 int error)
 {
   MokoListenerInterface *interface = MOKO_LISTENER_GET_INTERFACE (listener);
   if (interface->on_pin_requested)
-    interface->on_pin_requested (listener, handle, type);
+    interface->on_pin_requested (listener, handle, type, error);
 }
 
 void

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.h	2008-01-17 15:24:45 UTC (rev 3868)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-listener.h	2008-01-17 16:50:04 UTC (rev 3869)
@@ -27,6 +27,7 @@
 #include <libgsmd/sms.h>
 #include <libgsmd/voicecall.h>
 #include <libgsmd/phonebook.h>
+#include <libgsmd/pin.h>
 #include <gsmd/usock.h>
 
 #define MOKO_TYPE_LISTENER		(moko_listener_get_type ())
@@ -47,7 +48,8 @@
                                   struct lgsm_handle *handle, int type,
                                   int lac, int cell);
   void  (*on_pin_requested)      (MokoListener *listener,
-                                  struct lgsm_handle *handle, int type);
+                                  struct lgsm_handle *handle,
+                                  enum gsmd_pin_type type, int error);
   void  (*on_network_name)       (MokoListener *listener,
                                   struct lgsm_handle *handle,
                                   const gchar *name);
@@ -87,7 +89,8 @@
                                 struct lgsm_handle *handle, int type,
                                 int lac, int cell);
 void  moko_listener_on_pin_requested      (MokoListener *listener,
-                                struct lgsm_handle *handle, int type);
+                                struct lgsm_handle *handle,
+                                enum gsmd_pin_type type, int error);
 void  moko_listener_on_network_name       (MokoListener *listener,
                                 struct lgsm_handle *handle,
                                 const gchar *name);

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-network.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-network.c	2008-01-17 15:24:45 UTC (rev 3868)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-network.c	2008-01-17 16:50:04 UTC (rev 3869)
@@ -72,6 +72,9 @@
   gint                      retry_opers_n;
   guint                     retry_imsi;
   gint                      retry_imsi_n;
+  
+  gint                      pin_attempts;
+  enum gsmd_pin_type        pin_type;
 
   /* gsmd connection variables */
   GIOChannel                *channel;
@@ -231,7 +234,7 @@
 
 static void
 on_pin_requested (MokoListener *listener, struct lgsm_handle *handle,
-                  int type)
+                  enum gsmd_pin_type type, int error)
 {
   MokoNetworkPrivate *priv;
   gchar *pin;
@@ -241,12 +244,75 @@
 
   g_debug ("Pin Requested");
   
-  pin = get_pin_from_user ();
-  if (!pin)
-    return;
+  if (priv->pin_attempts < 3) {
+    const char *message;
+    
+    switch (type) {
+      case GSMD_PIN_READY :
+        g_debug ("Received GSMD_PIN_READY, ignoring");
+        return;
+      
+      default :
+      case GSMD_PIN_SIM_PIN :         /* SIM PIN */
+        message = "Enter PIN";
+        break;
+      case GSMD_PIN_SIM_PUK :         /* SIM PUK */
+        message = "Enter PUK";
+        break;
+      case GSMD_PIN_PH_SIM_PIN :      /* phone-to-SIM password */
+        message = "Enter SIM PIN";
+        break;
+      case GSMD_PIN_PH_FSIM_PIN :     /* phone-to-very-first SIM password */
+        message = "Enter new SIM PIN";
+        break;
+      case GSMD_PIN_PH_FSIM_PUK :     /* phone-to-very-first SIM PUK password */
+        message = "Enter new SIM PUK";
+        break;
+      case GSMD_PIN_SIM_PIN2 :        /* SIM PIN2 */
+        message = "Enter PIN2";
+        break;
+      case GSMD_PIN_SIM_PUK2 :        /* SIM PUK2 */
+        message = "Enter PUK2";
+        break;
+      case GSMD_PIN_PH_NET_PIN :      /* network personalisation password */
+        message = "Enter network PIN";
+        break;
+      case GSMD_PIN_PH_NET_PUK :      /* network personalisation PUK */
+        message = "Enter network PUK";
+        break;
+      case GSMD_PIN_PH_NETSUB_PIN :   /* network subset personalisation PIN */
+        message = "Enter network subset PIN";
+        break;
+      case GSMD_PIN_PH_NETSUB_PUK :   /* network subset personalisation PUK */
+        message = "Enter network subset PUK";
+        break;
+      case GSMD_PIN_PH_SP_PIN :       /* service provider personalisation PIN */
+        message = "Enter service provider PIN";
+        break;
+      case GSMD_PIN_PH_SP_PUK :       /* service provider personalisation PUK */
+        message = "Enter service provider PUK";
+        break;
+      case GSMD_PIN_PH_CORP_PIN :     /* corporate personalisation PIN */
+        message = "Enter corporate PIN";
+        break;
+      case GSMD_PIN_PH_CORP_PUK :     /* corporate personalisation PUK */
+        message = "Enter corporate PUK";
+        break;
+    }
+    
+    pin = get_pin_from_user (message);
+    if (!pin) {
+      g_debug ("No PIN entered, not requestiong");
+      return;
+    }
   
-  lgsm_pin (handle, 1, pin, NULL);
-  g_free (pin);
+    lgsm_pin (handle, 1, pin, NULL);
+    g_free (pin);
+    
+    priv->pin_attempts ++;
+  } else {
+    display_pin_error ("Maximum number of PIN attempts reached.");
+  }
 }
 
 static void
@@ -486,9 +552,10 @@
     }
     break;
   case GSMD_EVT_PIN :
+    priv->pin_type = aux->u.pin.type;
     for (l = priv->listeners; l; l = l->next) {
       moko_listener_on_pin_requested (MOKO_LISTENER (l->data), priv->handle,
-                                      aux->u.pin.type);
+                                      aux->u.pin.type, 0);
     }
     break;
   case GSMD_EVT_OUT_STATUS :
@@ -644,36 +711,19 @@
 static int
 pin_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
 {
+  GList *l;
+
+  MokoNetwork *network = moko_network_get_default ();
+  MokoNetworkPrivate *priv = network->priv;
+  
   int result = *(int *) gmh->data;
-  static int attempt = 0;
-  
-  /* store the number of pin attempts */
-  attempt++;
-  
-  /* must not do more than three attempts */
-  if (attempt > 3)
-  {
-    char *msg = "Maximum number of PIN attempts reached";
-    g_debug (msg);
-    display_pin_error (msg);
-  }
  
-  if (result)
-  {
-    gchar *pin = NULL;
-    char *msg = g_strdup_printf ("PIN error: %i", result);
-    
-    g_debug (msg);
-    display_pin_error (msg);
-    g_free (msg);
-    
-    pin = get_pin_from_user ();
-    if (!pin) return 0;
-    lgsm_pin (lh, 1, pin, NULL);
-    g_free (pin);
-  }
-  else
-  {
+  if (result) {
+    for (l = priv->listeners; l; l = l->next) {
+      moko_listener_on_pin_requested (MOKO_LISTENER (l->data), priv->handle,
+                                      priv->pin_type, result);
+    }
+  } else {
     /* PIN accepted, so let's make sure the phone is now powered on */
     g_debug ("PIN accepted!");
     lgsm_phone_power (lh, 1);

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.c
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.c	2008-01-17 15:24:45 UTC (rev 3868)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.c	2008-01-17 16:50:04 UTC (rev 3869)
@@ -15,6 +15,7 @@
 
 #include <gtk/gtk.h>
 
+#include "moko-pin.h"
 #include "moko-dialer-textview.h"
 #include "moko-dialer-panel.h"
 
@@ -70,13 +71,13 @@
 
 
 char*
-get_pin_from_user ()
+get_pin_from_user (const char *message)
 {
   GtkWidget *pad;
   gchar *pin;
   MokoPinData data;
   
-  data.dialog = gtk_dialog_new_with_buttons ("Enter PIN", NULL, 0,
+  data.dialog = gtk_dialog_new_with_buttons (message, NULL, 0,
                                              GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
                                              GTK_STOCK_OK, GTK_RESPONSE_OK, NULL);
   gtk_dialog_set_has_separator (GTK_DIALOG (data.dialog), FALSE);
@@ -106,7 +107,7 @@
 }
 
 void
-display_pin_error (char *message)
+display_pin_error (const char *message)
 {
   GtkWidget *dlg;
   
@@ -115,3 +116,4 @@
   gtk_dialog_run (GTK_DIALOG (dlg));
   gtk_widget_destroy (dlg);
 }
+

Modified: trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.h
===================================================================
--- trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.h	2008-01-17 15:24:45 UTC (rev 3868)
+++ trunk/src/target/OM-2007.2/applications/openmoko-dialer2/src/phone-kit/moko-pin.h	2008-01-17 16:50:04 UTC (rev 3869)
@@ -13,5 +13,11 @@
  *  GNU Lesser Public License for more details.
  */
 
-char *get_pin_from_user ();
-void *display_pin_error (char *message);
+#ifndef MOKO_PIN_H
+#define MOKO_PIN_H
+
+char *get_pin_from_user (const char *message);
+void display_pin_error (const char *message);
+
+#endif
+





More information about the commitlog mailing list