diff options
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/Makefile.am | 2 | ||||
-rw-r--r-- | src/util/atcmd.c | 66 | ||||
-rw-r--r-- | src/util/atcmd.h | 2 | ||||
-rw-r--r-- | src/util/event.c | 27 | ||||
-rw-r--r-- | src/util/libgsmd-tool.c | 11 | ||||
-rw-r--r-- | src/util/pin.c | 2 | ||||
-rw-r--r-- | src/util/shell.c | 44 | ||||
-rw-r--r-- | src/util/shell.h | 2 |
8 files changed, 148 insertions, 8 deletions
diff --git a/src/util/Makefile.am b/src/util/Makefile.am index aee83ca..fb17c85 100644 --- a/src/util/Makefile.am +++ b/src/util/Makefile.am @@ -3,7 +3,7 @@ AM_CFLAGS = -std=gnu99 bin_PROGRAMS = libgsmd-tool -libgsmd_tool_SOURCES = libgsmd-tool.c shell.c event.c pin.c +libgsmd_tool_SOURCES = libgsmd-tool.c shell.c event.c pin.c atcmd.c libgsmd_tool_LDADD = ../libgsmd/libgsmd.la libgsmd_tool_LDFLAGS = -dynamic diff --git a/src/util/atcmd.c b/src/util/atcmd.c new file mode 100644 index 0000000..6cf9aa7 --- /dev/null +++ b/src/util/atcmd.c @@ -0,0 +1,66 @@ +#include <stdio.h> +#include <string.h> +#include <stdlib.h> +#include <unistd.h> + +#include <libgsmd/libgsmd.h> + +#define STDIN_BUF_SIZE 1024 + +/* this is the handler for receiving passthrough responses */ +static int pt_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) +{ + char *payload = (char *)gmh + sizeof(*gmh); + printf("RSTR=`%s'\n", payload); +} + +int atcmd_main(struct lgsm_handle *lgsmh) +{ + int rc; + char buf[STDIN_BUF_SIZE+1]; + char rbuf[STDIN_BUF_SIZE+1]; + int rlen = sizeof(rbuf); + fd_set readset; + + lgsm_register_handler(lgsmh, GSMD_MSG_PASSTHROUGH, &pt_msghandler); + + FD_ZERO(&readset); + + while (1) { + fd_set readset; + int gsm_fd = lgsm_fd(lgsmh); + FD_SET(0, &readset); + FD_SET(gsm_fd, &readset); + + rc = select(gsm_fd+1, &readset, NULL, NULL, NULL); + if (rc <= 0) + break; + if (FD_ISSET(gsm_fd, &readset)) { + /* we've received something on the gsmd socket, pass it + * on to the library */ + rc = read(gsm_fd, buf, sizeof(buf)); + if (rc <= 0) { + printf("ERROR reding from gsm_fd\n"); + break; + } + rc = lgsm_handle_packet(lgsmh, buf, rc); + } + if (FD_ISSET(0, &readset)) { + /* we've received something on stdin. send it as passthrough + * to gsmd */ + rc = fscanf(stdin, "%s", buf); + if (rc == EOF) { + printf("EOF\n"); + return -1; + } + if (rc <= 0) { + printf("NULL\n"); + continue; + } + printf("STR=`%s'\n", buf); + } + /* this is a synchronous call for a passthrough command */ + lgsm_passthrough(lgsmh, buf, rbuf, &rlen); + printf("RSTR=`%s'\n", rbuf); + } +} diff --git a/src/util/atcmd.h b/src/util/atcmd.h new file mode 100644 index 0000000..3a385ae --- /dev/null +++ b/src/util/atcmd.h @@ -0,0 +1,2 @@ + +extern int atcmd_main(struct lgsm_handle *lgsmh); diff --git a/src/util/event.c b/src/util/event.c index 601ea9a..0f09d47 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -20,7 +20,32 @@ static int clip_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata static int netreg_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { - printf("EVENT: Netreg\n"); + printf("EVENT: Netreg "); + + switch (aux->u.netreg.state) { + case 0: + printf("not searching for network "); + break; + case 1: + printf("registered (home network) "); + break; + case 2: + printf("searching for network "); + break; + case 3: + printf("registration denied "); + break; + case 5: + printf("registered (roaming) "); + break; + } + + if (aux->u.netreg.lac) + printf("LocationAreaCode=0x%04X ", aux->u.netreg.lac); + if (aux->u.netreg.ci) + printf("CellID=0x%04X ", aux->u.netreg.ci); + + printf("\n"); return 0; } diff --git a/src/util/libgsmd-tool.c b/src/util/libgsmd-tool.c index 8d4674c..42a8e7c 100644 --- a/src/util/libgsmd-tool.c +++ b/src/util/libgsmd-tool.c @@ -10,6 +10,8 @@ #include "pin.h" #include "event.h" +#include "shell.h" +#include "atcmd.h" #ifndef ARRAY_SIZE #define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0])) @@ -22,12 +24,14 @@ enum mode_enum { MODE_NONE, MODE_SHELL, MODE_EVENTLOG, + MODE_ATCMD, }; static char *modes[] = { [MODE_NONE] = "", [MODE_SHELL] = "shell", [MODE_EVENTLOG] = "eventlog", + [MODE_ATCMD] = "atcmd", }; static int parse_mode(char *modestr) @@ -56,7 +60,9 @@ static void help(void) printf("Usage:\n" "\t-h\t--help\tPrint this Help message\n" "\t-V\t--version\tPrint version number\n" - "\t-v\t--verbose\tBe more verbose\n"); + "\t-v\t--verbose\tBe more verbose\n" + "\t-m\t--mode\tSet mode {passthrough,atcmd}\n" + ); } int main(int argc, char **argv) @@ -107,6 +113,9 @@ int main(int argc, char **argv) event_init(lgsmh); switch (mode) { + case MODE_ATCMD: + atcmd_main(lgsmh); + break; case MODE_SHELL: shell_main(lgsmh); break; diff --git a/src/util/pin.c b/src/util/pin.c index b855e53..c51bd81 100644 --- a/src/util/pin.c +++ b/src/util/pin.c @@ -22,7 +22,7 @@ static int pin_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata } else { do { printf("Please enter PIN: "); - rc = fscanf(stdin, "%32s\n", &pinbuf); + rc = fscanf(stdin, "%32s", &pinbuf); } while (rc < 1); return lgsm_pin(lh, pinbuf); diff --git a/src/util/shell.c b/src/util/shell.c index 77f0c57..2875758 100644 --- a/src/util/shell.c +++ b/src/util/shell.c @@ -4,6 +4,8 @@ #include <unistd.h> #include <libgsmd/libgsmd.h> +#include <libgsmd/voicecall.h> +#include <libgsmd/misc.h> #define STDIN_BUF_SIZE 1024 @@ -14,6 +16,17 @@ static int pt_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) printf("RSTR=`%s'\n", payload); } +static int shell_help(void) +{ + printf( "\tA\tAnswer incoming call\n" + "\tD\tDial outgoing number\n" + "\tH\tHangup call\n" + "\tO\tPower On\n" + "\to\tPower Off\n" + "\tR\tRegister Netowrk\n" + ); +} + int shell_main(struct lgsm_handle *lgsmh) { int rc; @@ -48,6 +61,7 @@ int shell_main(struct lgsm_handle *lgsmh) if (FD_ISSET(0, &readset)) { /* we've received something on stdin. send it as passthrough * to gsmd */ + printf("# "); rc = fscanf(stdin, "%s", buf); if (rc == EOF) { printf("EOF\n"); @@ -57,10 +71,32 @@ int shell_main(struct lgsm_handle *lgsmh) printf("NULL\n"); continue; } - printf("STR=`%s'\n", buf); + if (!strcmp(buf, "h")) { + shell_help(); + } else if (!strcmp(buf, "?")) { + shell_help(); + } else if (!strcmp(buf, "H")) { + printf("Hangup\n"); + lgsm_voice_hangup(lgsmh); + } else if (buf[0] == 'D') { + struct lgsm_addr addr; + printf("Dial %s\n", buf+1); + addr.type = 129; + strncpy(addr.addr, buf+1, sizeof(addr.addr)-1); + addr.addr[sizeof(addr.addr)-1] = '\0'; + lgsm_voice_out_init(lgsmh, &addr); + } else if (!strcmp(buf, "A")) { + printf("Answer\n"); + lgsm_voice_in_accept(lgsmh); + } else if (!strcmp(buf, "O")) { + lgsm_phone_power(lgsmh, 1); + } else if (!strcmp(buf, "o")) { + lgsm_phone_power(lgsmh, 0); + } else if (!strcmp(buf, "R")) { + lgsm_netreg_register(lgsmh, 0); + } else { + printf("Unknown command `%s'\n", buf); + } } - /* this is a synchronous call for a passthrough command */ - lgsm_passthrough(lgsmh, buf, rbuf, &rlen); - printf("RSTR=`%s'\n", rbuf); } } diff --git a/src/util/shell.h b/src/util/shell.h new file mode 100644 index 0000000..d383de9 --- /dev/null +++ b/src/util/shell.h @@ -0,0 +1,2 @@ + +extern int shell_main(struct lgsm_handle *lgsmh); |