r3636 - in trunk/src/target/gsm: include/gsmd include/libgsmd src/gsmd src/libgsmd src/util
erin_yueh at sita.openmoko.org
erin_yueh at sita.openmoko.org
Wed Dec 12 13:48:20 CET 2007
Author: erin_yueh
Date: 2007-12-12 13:48:10 +0100 (Wed, 12 Dec 2007)
New Revision: 3636
Modified:
trunk/src/target/gsm/include/gsmd/event.h
trunk/src/target/gsm/include/gsmd/usock.h
trunk/src/target/gsm/include/libgsmd/misc.h
trunk/src/target/gsm/include/libgsmd/pin.h
trunk/src/target/gsm/src/gsmd/usock.c
trunk/src/target/gsm/src/libgsmd/libgsmd_phone.c
trunk/src/target/gsm/src/libgsmd/libgsmd_pin.c
trunk/src/target/gsm/src/util/shell.c
Log:
gsmd: 2nd try for retrieving PIN status (Erin Yueh)
Modified: trunk/src/target/gsm/include/gsmd/event.h
===================================================================
--- trunk/src/target/gsm/include/gsmd/event.h 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/include/gsmd/event.h 2007-12-12 12:48:10 UTC (rev 3636)
@@ -43,6 +43,25 @@
__NUM_GSMD_PIN
};
+static const char *pin_type_names[__NUM_GSMD_PIN] = {
+ [GSMD_PIN_NONE] = "NONE",
+ [GSMD_PIN_SIM_PIN] = "SIM PIN",
+ [GSMD_PIN_SIM_PUK] = "SIM PUK",
+ [GSMD_PIN_PH_SIM_PIN] = "Phone-to-SIM PIN",
+ [GSMD_PIN_PH_FSIM_PIN] = "Phone-to-very-first SIM PIN",
+ [GSMD_PIN_PH_FSIM_PUK] = "Phone-to-very-first SIM PUK",
+ [GSMD_PIN_SIM_PIN2] = "SIM PIN2",
+ [GSMD_PIN_SIM_PUK2] = "SIM PUK2",
+ [GSMD_PIN_PH_NET_PIN] = "Network personalization PIN",
+ [GSMD_PIN_PH_NET_PUK] = "Network personalizaiton PUK",
+ [GSMD_PIN_PH_NETSUB_PIN]= "Network subset personalisation PIN",
+ [GSMD_PIN_PH_NETSUB_PUK]= "Network subset personalisation PUK",
+ [GSMD_PIN_PH_SP_PIN] = "Service provider personalisation PIN",
+ [GSMD_PIN_PH_SP_PUK] = "Service provider personalisation PUK",
+ [GSMD_PIN_PH_CORP_PIN] = "Corporate personalisation PIN",
+ [GSMD_PIN_PH_CORP_PUK] = "Corporate personalisation PUK",
+};
+
enum gsmd_call_type {
GSMD_CALL_NONE = 0,
GSMD_CALL_UNSPEC = 1,
Modified: trunk/src/target/gsm/include/gsmd/usock.h
===================================================================
--- trunk/src/target/gsm/include/gsmd/usock.h 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/include/gsmd/usock.h 2007-12-12 12:48:10 UTC (rev 3636)
@@ -89,13 +89,13 @@
enum gsmd_msg_pin_type {
GSMD_PIN_INPUT = 1,
+ GSMD_PIN_GET_STATUS = 2,
};
enum gsmd_msg_phone {
GSMD_PHONE_POWERUP = 1,
GSMD_PHONE_POWERDOWN = 2,
GSMD_PHONE_GET_IMSI = 3,
- GSMD_PIN_GET_STATUS = 4,
};
enum gsmd_msg_modem {
Modified: trunk/src/target/gsm/include/libgsmd/misc.h
===================================================================
--- trunk/src/target/gsm/include/libgsmd/misc.h 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/include/libgsmd/misc.h 2007-12-12 12:48:10 UTC (rev 3636)
@@ -79,6 +79,5 @@
/* Retrieve IMSI information */
extern int lgsm_get_imsi(struct lgsm_handle *lh);
-/* Get PIN status information */
-extern int lgsm_pin_status(struct lgsm_handle *lh);
+
#endif
Modified: trunk/src/target/gsm/include/libgsmd/pin.h
===================================================================
--- trunk/src/target/gsm/include/libgsmd/pin.h 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/include/libgsmd/pin.h 2007-12-12 12:48:10 UTC (rev 3636)
@@ -5,5 +5,6 @@
extern int lgsm_pin(struct lgsm_handle *lh, unsigned int type,
const char *pin, const char *newpin);
-
+/* Get PIN status information */
+extern int lgsm_pin_status(struct lgsm_handle *lh);
#endif
Modified: trunk/src/target/gsm/src/gsmd/usock.c
===================================================================
--- trunk/src/target/gsm/src/gsmd/usock.c 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/src/gsmd/usock.c 2007-12-12 12:48:10 UTC (rev 3636)
@@ -303,47 +303,64 @@
cmd->id, sizeof(ret), &ret);
}
+static int get_cpin_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
+{
+ enum gsmd_pin_type type;
+
+ if (!strncmp(resp, "+CPIN: ", 7)) {
+ unsigned int i;
+ resp += 7;
+ for (i = 0; i < __NUM_GSMD_PIN; i++) {
+ if(!strcmp(resp,pin_type_names[i]))
+ type = i;
+ }
+ }
+
+ return gsmd_ucmd_submit(ctx, GSMD_MSG_PIN, GSMD_PIN_GET_STATUS,
+ cmd->id, sizeof(type), &type);
+}
+
static int usock_rcv_pin(struct gsmd_user *gu, struct gsmd_msg_hdr *gph,
int len)
{
struct gsmd_pin *gp = (struct gsmd_pin *) ((void *)gph + sizeof(*gph));
struct gsmd_atcmd *cmd;
- if (gph->len < sizeof(*gp) || len < sizeof(*gp)+sizeof(*gph))
- return -EINVAL;
-
- gsmd_log(GSMD_DEBUG, "pin type=%u, pin='%s', newpin='%s'\n",
- gp->type, gp->pin, gp->newpin);
-
switch (gph->msg_subtype) {
case GSMD_PIN_INPUT:
- /* FIXME */
- break;
- default:
- gsmd_log(GSMD_ERROR, "unknown pin type %u\n",
- gph->msg_subtype);
- return -EINVAL;
- }
+ if (gph->len < sizeof(*gp) || len < sizeof(*gp)+sizeof(*gph))
+ return -EINVAL;
- cmd = atcmd_fill("AT+CPIN=\"", 9+GSMD_PIN_MAXLEN+3+GSMD_PIN_MAXLEN+2,
+ gsmd_log(GSMD_DEBUG, "pin type=%u, pin='%s', newpin='%s'\n",
+ gp->type, gp->pin, gp->newpin);
+
+ cmd = atcmd_fill("AT+CPIN=\"", 9+GSMD_PIN_MAXLEN+3+GSMD_PIN_MAXLEN+2,
&pin_cmd_cb, gu, 0, NULL);
- if (!cmd)
- return -ENOMEM;
+ if (!cmd)
+ return -ENOMEM;
- strncat(cmd->buf, gp->pin, sizeof(gp->pin));
+ strncat(cmd->buf, gp->pin, sizeof(gp->pin));
- switch (gp->type) {
- case GSMD_PIN_SIM_PUK:
- case GSMD_PIN_SIM_PUK2:
- strcat(cmd->buf, "\",\"");
- strncat(cmd->buf, gp->newpin, sizeof(gp->newpin));
+ switch (gp->type) {
+ case GSMD_PIN_SIM_PUK:
+ case GSMD_PIN_SIM_PUK2:
+ strcat(cmd->buf, "\",\"");
+ strncat(cmd->buf, gp->newpin, sizeof(gp->newpin));
+ break;
+ default:
+ break;
+ }
+ strcat(cmd->buf, "\"");
break;
+ case GSMD_PIN_GET_STATUS:
+ cmd = atcmd_fill("AT+CPIN?", 8 + 1, &get_cpin_cb, gu, 0, NULL);
+ break;
default:
- break;
+ gsmd_log(GSMD_ERROR, "unknown pin type %u\n",
+ gph->msg_subtype);
+ return -EINVAL;
}
- strcat(cmd->buf, "\"");
-
return atcmd_submit(gu->gsmd, cmd);
}
@@ -383,14 +400,6 @@
cmd->id, strlen(resp) + 1, resp);
}
-static int get_cpin_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp)
-{
- DEBUGP("resp: %s\n", resp);
-
- return gsmd_ucmd_submit(ctx, GSMD_MSG_PHONE, GSMD_PIN_GET_STATUS,
- cmd->id, strlen(resp) + 1, resp);
-}
-
static int usock_rcv_phone(struct gsmd_user *gu, struct gsmd_msg_hdr *gph,
int len)
{
@@ -410,10 +419,7 @@
case GSMD_PHONE_GET_IMSI:
cmd = atcmd_fill("AT+CIMI", 7 + 1, &get_imsi_cb, gu, 0, NULL);
break;
-
- case GSMD_PIN_GET_STATUS:
- cmd = atcmd_fill("AT+CPIN?", 8 + 1, &get_cpin_cb, gu, 0, NULL);
- break;
+
default:
return -EINVAL;
}
Modified: trunk/src/target/gsm/src/libgsmd/libgsmd_phone.c
===================================================================
--- trunk/src/target/gsm/src/libgsmd/libgsmd_phone.c 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/src/libgsmd/libgsmd_phone.c 2007-12-12 12:48:10 UTC (rev 3636)
@@ -50,7 +50,3 @@
return lgsm_send_simple(lh, GSMD_MSG_PHONE, GSMD_PHONE_GET_IMSI);
}
-int lgsm_pin_status(struct lgsm_handle *lh)
-{
- return lgsm_send_simple(lh, GSMD_MSG_PHONE, GSMD_PIN_GET_STATUS);
-}
Modified: trunk/src/target/gsm/src/libgsmd/libgsmd_pin.c
===================================================================
--- trunk/src/target/gsm/src/libgsmd/libgsmd_pin.c 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/src/libgsmd/libgsmd_pin.c 2007-12-12 12:48:10 UTC (rev 3636)
@@ -28,25 +28,6 @@
#include <gsmd/event.h>
#include <libgsmd/libgsmd.h>
-static const char *pin_type_names[__NUM_GSMD_PIN] = {
- [GSMD_PIN_NONE] = "NONE",
- [GSMD_PIN_SIM_PIN] = "SIM PIN",
- [GSMD_PIN_SIM_PUK] = "SIM PUK",
- [GSMD_PIN_PH_SIM_PIN] = "Phone-to-SIM PIN",
- [GSMD_PIN_PH_FSIM_PIN] = "Phone-to-very-first SIM PIN",
- [GSMD_PIN_PH_FSIM_PUK] = "Phone-to-very-first SIM PUK",
- [GSMD_PIN_SIM_PIN2] = "SIM PIN2",
- [GSMD_PIN_SIM_PUK2] = "SIM PUK2",
- [GSMD_PIN_PH_NET_PIN] = "Network personalization PIN",
- [GSMD_PIN_PH_NET_PUK] = "Network personalizaiton PUK",
- [GSMD_PIN_PH_NETSUB_PIN]= "Network subset personalisation PIN",
- [GSMD_PIN_PH_NETSUB_PUK]= "Network subset personalisation PUK",
- [GSMD_PIN_PH_SP_PIN] = "Service provider personalisation PIN",
- [GSMD_PIN_PH_SP_PUK] = "Service provider personalisation PUK",
- [GSMD_PIN_PH_CORP_PIN] = "Corporate personalisation PIN",
- [GSMD_PIN_PH_CORP_PUK] = "Corporate personalisation PUK",
-};
-
const char *lgsm_pin_name(enum gsmd_pin_type ptype)
{
if (ptype >= __NUM_GSMD_PIN)
@@ -55,6 +36,11 @@
return pin_type_names[ptype];
}
+int lgsm_pin_status(struct lgsm_handle *lh)
+{
+ return lgsm_send_simple(lh, GSMD_MSG_PIN, GSMD_PIN_GET_STATUS);
+}
+
int lgsm_pin(struct lgsm_handle *lh, unsigned int type,
const char *pin, const char *newpin)
{
@@ -98,3 +84,4 @@
return rc;
}
+
Modified: trunk/src/target/gsm/src/util/shell.c
===================================================================
--- trunk/src/target/gsm/src/util/shell.c 2007-12-12 12:06:20 UTC (rev 3635)
+++ trunk/src/target/gsm/src/util/shell.c 2007-12-12 12:48:10 UTC (rev 3636)
@@ -356,10 +356,6 @@
payload = (char *)gmh + sizeof(*gmh);
printf("imsi <%s>\n", payload);
break;
- case GSMD_PIN_GET_STATUS:
- payload = (char *)gmh + sizeof(*gmh);
- printf("%s\n", payload);
- break;
case GSMD_PHONE_POWERUP:
if (*intresult)
printf("Modem power-up failed: %i\n", *intresult);
@@ -382,11 +378,19 @@
static int pin_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh)
{
int result = *(int *) gmh->data;
-
- if (result)
- printf("PIN error %i\n", result);
- else
- printf("PIN accepted!\n");
+ switch (gmh->msg_subtype) {
+ case GSMD_PIN_GET_STATUS:
+ printf("PIN STATUS: %i\n", result);
+ break;
+ case GSMD_PIN_INPUT:
+ if (result)
+ printf("PIN error %i\n", result);
+ else
+ printf("PIN accepted!\n");
+ break;
+ default:
+ return -EINVAL;
+ }
pending_responses --;
return 0;
}
More information about the commitlog
mailing list