From 2797211645d452446cb7b329ee9d3d3a923f8520 Mon Sep 17 00:00:00 2001 From: laforge Date: Sat, 10 Mar 2007 02:22:04 +0000 Subject: * properly implement PIN/PUK handling throughout gsmd/libgsmd/util git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@1314 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/util/pin.c | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'src/util') diff --git a/src/util/pin.c b/src/util/pin.c index 7bfd8da..fdd0099 100644 --- a/src/util/pin.c +++ b/src/util/pin.c @@ -25,29 +25,46 @@ #include #include +#include -#define PIN_SIZE 32 +#define PIN_SIZE 8 static char *pin; static char pinbuf[PIN_SIZE+1]; +static char pinbuf2[PIN_SIZE+1]; static int pin_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { int rc; + int type = aux->u.pin.type; + char *newpin = NULL; - printf("EVENT: PIN request (type=%u) ", aux->u.pin.type); + printf("EVENT: PIN request (type='%s') ", lgsm_pin_name(aux->u.pin.type)); /* FIXME: read pin from STDIN and send it back via lgsm_pin */ - if (aux->u.pin.type == 1 && pin) { + if (type == 1 && pin) { printf("Auto-responding with pin `%s'\n", pin); - lgsm_pin(lh, pin); + lgsm_pin(lh, type, pin, NULL); } else { do { - printf("Please enter PIN: "); - rc = fscanf(stdin, "%32s", &pinbuf); + printf("Please enter %s: ", lgsm_pin_name(type)); + rc = fscanf(stdin, "%8s", &pinbuf); } while (rc < 1); - return lgsm_pin(lh, pinbuf); + switch (type) { + case GSMD_PIN_SIM_PUK: + case GSMD_PIN_SIM_PUK2: + do { + printf("Please enter new PIN: "); + rc = fscanf(stdin, "%8s", &pinbuf2); + newpin = pinbuf2; + } while (rc < 1); + break; + default: + break; + } + + return lgsm_pin(lh, type, pinbuf, newpin); } return 0; -- cgit v1.2.3