#include #include #include #include #include #include #include #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); } 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; 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 */ printf("# "); rc = fscanf(stdin, "%s", buf); if (rc == EOF) { printf("EOF\n"); return -1; } if (rc <= 0) { printf("NULL\n"); continue; } 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); } } } }