diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/pin.c | 15 | ||||
-rw-r--r-- | src/util/shell.c | 36 | ||||
-rw-r--r-- | src/util/shell.h | 2 |
3 files changed, 40 insertions, 13 deletions
diff --git a/src/util/pin.c b/src/util/pin.c index fdd0099..b873535 100644 --- a/src/util/pin.c +++ b/src/util/pin.c @@ -27,24 +27,28 @@ #include <libgsmd/event.h> #include <libgsmd/pin.h> +#include "shell.h" + #define PIN_SIZE 8 -static char *pin; +static const 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) +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='%s') ", lgsm_pin_name(aux->u.pin.type)); + printf("EVENT: PIN request (type='%s') ", lgsm_pin_name(type)); /* FIXME: read pin from STDIN and send it back via lgsm_pin */ if (type == 1 && pin) { printf("Auto-responding with pin `%s'\n", pin); - lgsm_pin(lh, type, pin, NULL); + pending_responses ++; + return lgsm_pin(lh, type, pin, NULL); } else { do { printf("Please enter %s: ", lgsm_pin_name(type)); @@ -64,10 +68,9 @@ static int pin_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata break; } + pending_responses ++; return lgsm_pin(lh, type, pinbuf, newpin); } - - return 0; } int pin_init(struct lgsm_handle *lh, const char *pin_preset) diff --git a/src/util/shell.c b/src/util/shell.c index 031ed34..373ce33 100644 --- a/src/util/shell.c +++ b/src/util/shell.c @@ -44,7 +44,7 @@ static int nFIND = 0; static int nREADRG = 0; -static int pending_responses = 0; +int pending_responses = 0; /* this is the handler for receiving passthrough responses */ static int pt_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) @@ -373,6 +373,32 @@ static int phone_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) return 0; } +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"); + pending_responses --; + return 0; +} + +static const struct msghandler_s { + int type; + lgsm_msg_handler *fn; +} msghandlers[] = { + { GSMD_MSG_PASSTHROUGH, pt_msghandler }, + { GSMD_MSG_PHONEBOOK, pb_msghandler }, + { GSMD_MSG_SMS, sms_msghandler }, + { GSMD_MSG_NETWORK, net_msghandler }, + { GSMD_MSG_PHONE, phone_msghandler }, + { GSMD_MSG_PIN, pin_msghandler }, + + { 0, 0 } +}; + static int shell_help(void) { printf( "\tA\tAnswer incoming call\n" @@ -424,12 +450,10 @@ int shell_main(struct lgsm_handle *lgsmh, int sync) fd_set readset; char *ptr, *fcomma, *lcomma; int gsm_fd = lgsm_fd(lgsmh); + const struct msghandler_s *hndl; - lgsm_register_handler(lgsmh, GSMD_MSG_PASSTHROUGH, &pt_msghandler); - lgsm_register_handler(lgsmh, GSMD_MSG_PHONEBOOK, &pb_msghandler); - lgsm_register_handler(lgsmh, GSMD_MSG_SMS, &sms_msghandler); - lgsm_register_handler(lgsmh, GSMD_MSG_NETWORK, &net_msghandler); - lgsm_register_handler(lgsmh, GSMD_MSG_PHONE, &phone_msghandler); + for (hndl = msghandlers; hndl->fn; hndl ++) + lgsm_register_handler(lgsmh, hndl->type, hndl->fn); fcntl(0, F_SETFD, O_NONBLOCK); fcntl(gsm_fd, F_SETFD, O_NONBLOCK); diff --git a/src/util/shell.h b/src/util/shell.h index f0bebb3..81a8dc3 100644 --- a/src/util/shell.h +++ b/src/util/shell.h @@ -1,2 +1,2 @@ - extern int shell_main(struct lgsm_handle *lgsmh, int sync); +extern int pending_responses; |