diff options
-rw-r--r-- | include/gsmd/machineplugin.h | 1 | ||||
-rw-r--r-- | include/gsmd/usock.h | 6 | ||||
-rw-r--r-- | include/libgsmd/misc.h | 1 | ||||
-rw-r--r-- | src/gsmd/machine_generic.c | 1 | ||||
-rw-r--r-- | src/gsmd/machine_gta01.c | 47 | ||||
-rw-r--r-- | src/gsmd/machine_tihtc.c | 1 | ||||
-rw-r--r-- | src/gsmd/usock.c | 13 | ||||
-rw-r--r-- | src/libgsmd/Makefile.am | 2 | ||||
-rw-r--r-- | src/util/shell.c | 8 |
9 files changed, 79 insertions, 1 deletions
diff --git a/include/gsmd/machineplugin.h b/include/gsmd/machineplugin.h index 7a66031..c3ed801 100644 --- a/include/gsmd/machineplugin.h +++ b/include/gsmd/machineplugin.h @@ -11,6 +11,7 @@ struct gsmd; struct gsmd_machine_plugin { struct llist_head list; unsigned char *name; + int (*power)(struct gsmd *g, int power); int (*ex_submit)(struct gsmd *g); int (*detect)(struct gsmd *g); int (*init)(struct gsmd *g, int fd); diff --git a/include/gsmd/usock.h b/include/gsmd/usock.h index 3580a83..7340807 100644 --- a/include/gsmd/usock.h +++ b/include/gsmd/usock.h @@ -24,6 +24,7 @@ enum gsmd_msg_type { GSMD_MSG_PIN = 8, GSMD_MSG_SMS = 9, GSMD_MSG_CB = 10, + GSMD_MSG_MODEM = 11, __NUM_GSMD_MSGS }; @@ -57,6 +58,11 @@ enum gsmd_msg_phone { GSMD_PHONE_POWERDOWN = 2, }; +enum gsmd_msg_modem { + GSMD_MODEM_POWERUP = 1, + GSMD_MODEM_POWERDOWN = 2, +}; + enum gsmd_msg_cb { GSMD_CB_SUBSCRIBE = 1, GSMD_CB_UNSUBSCRIBE = 2, diff --git a/include/libgsmd/misc.h b/include/libgsmd/misc.h index 206b2e1..165994e 100644 --- a/include/libgsmd/misc.h +++ b/include/libgsmd/misc.h @@ -9,6 +9,7 @@ #include <libgsmd/libgsmd.h> extern int lgsm_phone_power(struct lgsm_handle *lh, int power); +extern int lgsm_modem_power(struct lgsm_handle *lh, int power); enum lgsm_info_type { LGSM_INFO_TYPE_NONE = 0, diff --git a/src/gsmd/machine_generic.c b/src/gsmd/machine_generic.c index 3d80bbf..536192d 100644 --- a/src/gsmd/machine_generic.c +++ b/src/gsmd/machine_generic.c @@ -56,6 +56,7 @@ static int generic_init(struct gsmd *g, int fd) struct gsmd_machine_plugin gsmd_machine_plugin = { .name = "generic", + .power = NULL, .ex_submit = NULL, .detect = &generic_detect, .init = &generic_init, diff --git a/src/gsmd/machine_gta01.c b/src/gsmd/machine_gta01.c index f035ab1..88e007a 100644 --- a/src/gsmd/machine_gta01.c +++ b/src/gsmd/machine_gta01.c @@ -15,6 +15,52 @@ #include <gsmd/atcmd.h> #define GSMD_MODEM_WAKEUP_TIMEOUT 3 +#define GSMD_MODEM_POWEROFF_TIMEOUT 3 + +static void poweroff_timeout(struct gsmd_timer *tmr, void *data) +{ + exit(0); +} + +static struct gsmd_timer * poweroff_timer(struct gsmd *g) +{ + struct timeval tv; + tv.tv_sec = GSMD_MODEM_POWEROFF_TIMEOUT; + tv.tv_usec = 0; + DEBUGP("Create power off timer\n"); + + return gsmd_timer_create(&tv,&poweroff_timeout,g); +} + +static int gta01_power(struct gsmd *g, int power) +{ + struct gsmd_atcmd * cmd = NULL; + + switch (power) + { + case GSMD_MODEM_POWERUP: + break; + + case GSMD_MODEM_POWERDOWN: + + //After send AT@POFF to GSM modem, modem will not work anymore and gsmd get no response + cmd = atcmd_fill("AT@POFF", 7+1, NULL, g, 0, poweroff_timer); + + if (!cmd) + return -ENOMEM; + + llist_add_tail(&cmd->list, &g->pending_atcmds); + if (llist_empty(&g->busy_atcmds) && !llist_empty(&g->pending_atcmds)) { + atcmd_wake_pending_queue(g); + } + break; + + default: + return -EINVAL; + } + + return 0; +} static int null_wakeup_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) { @@ -103,6 +149,7 @@ static int gta01_init(struct gsmd *g, int fd) struct gsmd_machine_plugin gsmd_machine_plugin = { .name = "TI Calypso / FIC firmware", + .power = >a01_power, .ex_submit = &atcmd_wakeup_modem, .detect = >a01_detect, .init = >a01_init, diff --git a/src/gsmd/machine_tihtc.c b/src/gsmd/machine_tihtc.c index 6fe52f0..b07d32e 100644 --- a/src/gsmd/machine_tihtc.c +++ b/src/gsmd/machine_tihtc.c @@ -66,6 +66,7 @@ static int tihtc_init(struct gsmd *g, int fd) struct gsmd_machine_plugin gsmd_machine_plugin = { .name = "TI Calypso / HTC firmware", + .power = NULL, .ex_submit = NULL, .detect = &tihtc_detect, .init = &tihtc_init, diff --git a/src/gsmd/usock.c b/src/gsmd/usock.c index 3dc74d3..0b81306 100644 --- a/src/gsmd/usock.c +++ b/src/gsmd/usock.c @@ -288,6 +288,18 @@ static int usock_rcv_phone(struct gsmd_user *gu, struct gsmd_msg_hdr *gph, return atcmd_submit(gu->gsmd, cmd); } +static int usock_rcv_modem(struct gsmd_user *gu, struct gsmd_msg_hdr *gph, + int len) +{ + struct gsmd *g = gu->gsmd; + + if (g->machinepl->power) { + g->machinepl->power(g, gph->msg_subtype); + } + + return 0; +} + static int network_vmail_cb(struct gsmd_atcmd *cmd, void *ctx, char *resp) { struct gsmd_user *gu = ctx; @@ -1168,6 +1180,7 @@ static usock_msg_handler *pcmd_type_handlers[__NUM_GSMD_MSGS] = { [GSMD_MSG_SMS] = &usock_rcv_sms, [GSMD_MSG_CB] = &usock_rcv_cb, [GSMD_MSG_PHONEBOOK] = &usock_rcv_phonebook, + [GSMD_MSG_MODEM] = &usock_rcv_modem, }; static int usock_rcv_pcmd(struct gsmd_user *gu, char *buf, int len) diff --git a/src/libgsmd/Makefile.am b/src/libgsmd/Makefile.am index 20a6725..83c2ae9 100644 --- a/src/libgsmd/Makefile.am +++ b/src/libgsmd/Makefile.am @@ -5,6 +5,6 @@ AM_CFLAGS = -std=gnu99 lib_LTLIBRARIES = libgsmd.la libgsmd_la_LDFLAGS = -Wc,-nostartfiles -version-info $(LIBVERSION) -libgsmd_la_SOURCES = libgsmd.c libgsmd_input.c libgsmd_voicecall.c libgsmd_passthrough.c libgsmd_event.c libgsmd_phone.c libgsmd_network.c libgsmd_pin.c libgsmd_sms.c libgsmd_phonebook.c +libgsmd_la_SOURCES = libgsmd.c libgsmd_input.c libgsmd_voicecall.c libgsmd_passthrough.c libgsmd_event.c libgsmd_phone.c libgsmd_network.c libgsmd_pin.c libgsmd_sms.c libgsmd_phonebook.c libgsmd_modem.c noinst_HEADERS = lgsm_internals.h diff --git a/src/util/shell.c b/src/util/shell.c index 6a07fe6..5c57598 100644 --- a/src/util/shell.c +++ b/src/util/shell.c @@ -356,6 +356,8 @@ static int shell_help(void) "\tH\tHangup call\n" "\tO\tPower On\n" "\to\tPower Off\n" + "\tM\tModem Power On\n" + "\tm\tModem Power Off\n" "\tr\tRegister to network\n" "\tR\tRegister to given operator (R=number)\n" "\tU\tUnregister from netowrk\n" @@ -675,6 +677,12 @@ int shell_main(struct lgsm_handle *lgsmh, int sync) printf("Get imsi\n"); lgsm_get_imsi(lgsmh); pending_responses ++; + } else if (!strncmp(buf, "M", 1)) { + printf("Modem Power On\n"); + lgsm_modem_power(lgsmh, 1); + } else if (!strncmp(buf, "m", 1)) { + printf("Modem Power Off\n"); + lgsm_modem_power(lgsmh, 0); } else { printf("Unknown command `%s'\n", buf); } |