From a04e6effed0b81ec7495df2a1448484645b20cc5 Mon Sep 17 00:00:00 2001 From: laforge Date: Fri, 12 Jan 2007 23:57:33 +0000 Subject: - use talloc (of samba project) to debug memory allocations and simplify code - introduce new ucmd_alloc() function - add DTMF support to gsmd, libgsmd and gsmd-util - fix crash of libgsmd when events don't have handlers registered - implement call progress for TI modem - split modem init string in separate commands to fit our parser git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@544 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/util/atcmd.c | 5 +++++ src/util/event.c | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ src/util/shell.c | 19 +++++++++++++++++-- 3 files changed, 71 insertions(+), 2 deletions(-) (limited to 'src/util') diff --git a/src/util/atcmd.c b/src/util/atcmd.c index 2e2c016..5e95ca0 100644 --- a/src/util/atcmd.c +++ b/src/util/atcmd.c @@ -25,14 +25,19 @@ int atcmd_main(struct lgsm_handle *lgsmh) lgsm_register_handler(lgsmh, GSMD_MSG_PASSTHROUGH, &pt_msghandler); +#if 1 fcntl(0, F_SETFD, O_NONBLOCK); + fcntl(1, F_SETFD, O_NONBLOCK); + fcntl(2, F_SETFD, O_NONBLOCK); fcntl(lgsm_fd(lgsmh), F_SETFD, O_NONBLOCK); +#endif FD_ZERO(&readset); while (1) { fd_set readset; int gsm_fd = lgsm_fd(lgsmh); + FD_SET(0, &readset); FD_SET(gsm_fd, &readset); diff --git a/src/util/event.c b/src/util/event.c index bff895d..014abda 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -1,6 +1,7 @@ #include #include +#include #include #include @@ -18,6 +19,13 @@ static int clip_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata return 0; } +static int colp_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) +{ + printf("EVENT: Outgoing call colp = %s\n", aux->u.colp.addr.number); + + return 0; +} + static int netreg_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) { printf("EVENT: Netreg "); @@ -56,14 +64,55 @@ static int sigq_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata return 0; } +static const char *cprog_names[] = { + [GSMD_CALLPROG_SETUP] = "SETUP", + [GSMD_CALLPROG_DISCONNECT] = "DISCONNECT", + [GSMD_CALLPROG_ALERT] = "ALERT", + [GSMD_CALLPROG_CALL_PROCEED] = "PROCEED", + [GSMD_CALLPROG_SYNC] = "SYNC", + [GSMD_CALLPROG_PROGRESS] = "PROGRESS", + [GSMD_CALLPROG_CONNECTED] = "CONNECTED", + [GSMD_CALLPROG_RELEASE] = "RELEASE", + [GSMD_CALLPROG_REJECT] = "REJECT", + [GSMD_CALLPROG_UNKNOWN] = "UNKNOWN", +}; + +static const char *cdir_names[] = { + [GSMD_CALL_DIR_MO] = "Outgoing", + [GSMD_CALL_DIR_MT] = "Incoming", + [GSMD_CALL_DIR_CCBS] = "CCBS", + [GSMD_CALL_DIR_MO_REDIAL] = "Outgoing Redial", +}; + +static int cprog_handler(struct lgsm_handle *lh, int evt, struct gsmd_evt_auxdata *aux) +{ + const char *name, *dir; + + if (aux->u.call_status.prog >= ARRAY_SIZE(cprog_names)) + name = "UNDEFINED"; + else + name = cprog_names[aux->u.call_status.prog]; + + if (aux->u.call_status.dir >= ARRAY_SIZE(cdir_names)) + dir = ""; + else + dir = cdir_names[aux->u.call_status.dir]; + + printf("EVENT: %s Call Progress: %s\n", dir, name); + + return 0; +} + int event_init(struct lgsm_handle *lh) { int rc; rc = lgsm_evt_handler_register(lh, GSMD_EVT_IN_CALL, &incall_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_IN_CLIP, &clip_handler); + rc |= lgsm_evt_handler_register(lh, GSMD_EVT_OUT_COLP, &colp_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_NETREG, &netreg_handler); rc |= lgsm_evt_handler_register(lh, GSMD_EVT_SIGNAL, &sigq_handler); + rc |= lgsm_evt_handler_register(lh, GSMD_EVT_OUT_STATUS, &cprog_handler); return rc; } diff --git a/src/util/shell.c b/src/util/shell.c index b90cd19..b8f0877 100644 --- a/src/util/shell.c +++ b/src/util/shell.c @@ -25,6 +25,7 @@ static int shell_help(void) "\tO\tPower On\n" "\to\tPower Off\n" "\tR\tRegister Netowrk\n" + "\tq\tQuit\n" ); } @@ -43,6 +44,8 @@ int shell_main(struct lgsm_handle *lgsmh) FD_ZERO(&readset); + printf("# "); + while (1) { fd_set readset; int gsm_fd = lgsm_fd(lgsmh); @@ -63,8 +66,7 @@ int shell_main(struct lgsm_handle *lgsmh) rc = lgsm_handle_packet(lgsmh, buf, rc); } if (FD_ISSET(0, &readset)) { - /* we've received something on stdin. send it as passthrough - * to gsmd */ + /* we've received something on stdin. */ printf("# "); rc = fscanf(stdin, "%s", buf); if (rc == EOF) { @@ -84,6 +86,8 @@ int shell_main(struct lgsm_handle *lgsmh) lgsm_voice_hangup(lgsmh); } else if (buf[0] == 'D') { struct lgsm_addr addr; + if (strlen(buf) < 2) + continue; printf("Dial %s\n", buf+1); addr.type = 129; strncpy(addr.addr, buf+1, sizeof(addr.addr)-1); @@ -93,11 +97,22 @@ int shell_main(struct lgsm_handle *lgsmh) printf("Answer\n"); lgsm_voice_in_accept(lgsmh); } else if (!strcmp(buf, "O")) { + printf("Power-On\n"); lgsm_phone_power(lgsmh, 1); } else if (!strcmp(buf, "o")) { + printf("Power-Off\n"); lgsm_phone_power(lgsmh, 0); } else if (!strcmp(buf, "R")) { + printf("Register\n"); + lgsm_phone_power(lgsmh, 0); lgsm_netreg_register(lgsmh, 0); + } else if (!strcmp(buf, "q")) { + exit(0); + } else if (buf[0] == 'T') { + if (strlen(buf) < 2) + continue; + printf("DTMF: %c\n", buf[1]); + lgsm_voice_dtmf(lgsmh, buf[1]); } else { printf("Unknown command `%s'\n", buf); } -- cgit v1.2.3