diff options
author | erin_yueh <erin_yueh@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2007-12-12 12:48:10 +0000 |
---|---|---|
committer | erin_yueh <erin_yueh@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2007-12-12 12:48:10 +0000 |
commit | 30c802206150291d388c14d9588faf32804d4b18 (patch) | |
tree | f8b707fb50991afd2d49ba849f04a1cbafd47c81 /src/gsmd | |
parent | 3a4c4251d068f481ddef3c355d8e0936c5b3440b (diff) |
gsmd: 2nd try for retrieving PIN status (Erin Yueh)
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@3636 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/gsmd')
-rw-r--r-- | src/gsmd/usock.c | 80 |
1 files changed, 43 insertions, 37 deletions
diff --git a/src/gsmd/usock.c b/src/gsmd/usock.c index 76adc9b..5b9eb1c 100644 --- a/src/gsmd/usock.c +++ b/src/gsmd/usock.c @@ -303,47 +303,64 @@ static int pin_cmd_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) 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; - default: + case GSMD_PIN_GET_STATUS: + cmd = atcmd_fill("AT+CPIN?", 8 + 1, &get_cpin_cb, gu, 0, NULL); break; + default: + 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 @@ static int get_imsi_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) 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 @@ static int usock_rcv_phone(struct gsmd_user *gu, struct gsmd_msg_hdr *gph, 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; } |