diff options
author | laforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2007-08-16 04:18:54 +0000 |
---|---|---|
committer | laforge <laforge@99fdad57-331a-0410-800a-d7fa5415bdb3> | 2007-08-16 04:18:54 +0000 |
commit | 66ddffab0a8fe2f517d83859ffb20467acd0cbe6 (patch) | |
tree | f207a43dddc8205763309e8b9b3bb5043f96647e /src/util | |
parent | 00361c2946aef3975e302d5a5957ae239da21de8 (diff) |
From 294d27e78680d497da22e3a8ad679f50d1ba29e5 Mon Sep 17 00:00:00 2001
From: Andrzej Zaborowski <balrog@zabor.org>
Date: Wed, 11 Jul 2007 16:11:10 +0200
Subject: [PATCH] SMS support in gsmd and in libgsmd.
This adds the proper support for sms related calls in libgsmd and their
implementation in gsmd.
I assumed that conversion between data coding schemes is to be done on the
client side because the {packing,unpacking}* calls were exported. TEXT mode
support is non-functional, but the code only has to be filled in the right
places to make it work, if it is ever needed.
I had been lucky to be able to test with the different kinds of messages with
exotic formats because I just got a bunch of network messages today (urging to
top-up the credit).
I tried to not modify the libgsmd api, although I would prefer to have a
totally different api, possibly with synchronous calls that just return the
result of an operation, for a exmaple a whole list of messages, rather than the
client waiting for an unknown number of events each with one message.
git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@2710 99fdad57-331a-0410-800a-d7fa5415bdb3
Diffstat (limited to 'src/util')
-rw-r--r-- | src/util/shell.c | 127 |
1 files changed, 104 insertions, 23 deletions
diff --git a/src/util/shell.c b/src/util/shell.c index 9a7084d..3f83d30 100644 --- a/src/util/shell.c +++ b/src/util/shell.c @@ -32,6 +32,7 @@ #include <libgsmd/phonebook.h> #include <libgsmd/sms.h> #include <gsmd/usock.h> +#include <gsmd/ts0705.h> #define STDIN_BUF_SIZE 1024 @@ -76,22 +77,98 @@ static int pb_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) /* this is the handler for receiving sms responses */ static int sms_msghandler(struct lgsm_handle *lh, struct gsmd_msg_hdr *gmh) -{ - char *payload; +{ + char payload[GSMD_SMS_DATA_MAXLEN]; + int *result; + struct gsmd_sms_list *sms; + static const char *type[] = { "Unread", "Received", "Unsent", "Sent" }; switch (gmh->msg_subtype) { case GSMD_SMS_LIST: - break; - case GSMD_SMS_READ: - case GSMD_SMS_SEND: - case GSMD_SMS_WRITE: + case GSMD_SMS_READ: + sms = (struct gsmd_sms_list *) ((void *) gmh + sizeof(*gmh)); + printf("%s message %i from/to %s%s, at %i%i-%i%i-%i%i " + "%i%i:%i%i:%i%i, GMT%c%i\n", type[sms->stat], + sms->index, + ((sms->addr.type & __GSMD_TOA_TON_MASK) == + GSMD_TOA_TON_INTERNATIONAL) ? "+" : "", + sms->addr.number, + sms->time_stamp[0] & 0xf, + sms->time_stamp[0] >> 4, + sms->time_stamp[1] & 0xf, + sms->time_stamp[1] >> 4, + sms->time_stamp[2] & 0xf, + sms->time_stamp[2] >> 4, + sms->time_stamp[3] & 0xf, + sms->time_stamp[3] >> 4, + sms->time_stamp[4] & 0xf, + sms->time_stamp[4] >> 4, + sms->time_stamp[5] & 0xf, + sms->time_stamp[5] >> 4, + (sms->time_stamp[6] & 8) ? '-' : '+', + (((sms->time_stamp[6] << 4) | + (sms->time_stamp[6] >> 4)) & 0x3f) >> 2); + if (sms->payload.coding_scheme == ALPHABET_DEFAULT) { + unpacking_7bit_character(&sms->payload, payload); + printf("\"%s\"\n", payload); + } else if (sms->payload.coding_scheme == ALPHABET_8BIT) + printf("8-bit encoded data\n"); + else if (sms->payload.coding_scheme == ALPHABET_UCS2) + printf("Unicode-16 encoded text\n"); + break; + case GSMD_SMS_SEND: + result = (int *) ((void *) gmh + sizeof(*gmh)); + if (*result >= 0) { + printf("Send: message sent as ref %i\n", *result); + break; + } + + switch (-*result) { + case 42: + printf("Store: congestion\n"); + break; + default: + printf("Store: error %i\n", *result); + break; + } + break; + case GSMD_SMS_WRITE: + result = (int *) ((void *) gmh + sizeof(*gmh)); + if (*result >= 0) { + printf("Store: message stored with index %i\n", + *result); + break; + } + + switch (-*result) { + case GSM0705_CMS_SIM_NOT_INSERTED: + printf("Store: SIM not inserted\n"); + break; + default: + printf("Store: error %i\n", *result); + break; + } + break; case GSMD_SMS_DELETE: - payload = (char *)gmh + sizeof(*gmh); - printf("%s\n", payload); - break; + result = (int *) ((void *) gmh + sizeof(*gmh)); + switch (*result) { + case 0: + printf("Delete: success\n"); + break; + case GSM0705_CMS_SIM_NOT_INSERTED: + printf("Delete: SIM not inserted\n"); + break; + case GSM0705_CMS_INVALID_MEMORY_INDEX: + printf("Delete: invalid memory index\n"); + break; + default: + printf("Delete: error %i\n", *result); + break; + } + break; default: return -EINVAL; - } + } } static int shell_help(void) @@ -101,7 +178,8 @@ static int shell_help(void) "\tH\tHangup call\n" "\tO\tPower On\n" "\to\tPower Off\n" - "\tR\tRegister Netowrk\n" + "\tR\tRegister Network\n" + "\tU\tUnregister from netowrk\n" "\tT\tSend DTMF Tone\n" "\tpd\tPB Delete (pb=index)\n" "\tpr\tPB Read (pr=index)\n" @@ -197,6 +275,9 @@ int shell_main(struct lgsm_handle *lgsmh) } else if (!strcmp(buf, "R")) { printf("Register\n"); lgsm_netreg_register(lgsmh, 0); + } else if (!strcmp(buf, "U")) { + printf("Unregister\n"); + lgsm_netreg_register(lgsmh, 2); } else if (!strcmp(buf, "q")) { exit(0); } else if (buf[0] == 'T') { @@ -239,7 +320,7 @@ int shell_main(struct lgsm_handle *lgsmh) pb.index = atoi(ptr+1); fcomma = strchr(buf, ','); - lcomma = strrchr(buf, ','); + lcomma = strchr(fcomma+1, ','); strncpy(pb.numb, fcomma+1, (lcomma-fcomma-1)); pb.numb[(lcomma-fcomma-1)] = '\0'; if ( '+' == pb.numb[0] ) @@ -279,25 +360,25 @@ int shell_main(struct lgsm_handle *lgsmh) ptr = strchr(buf, '='); fcomma = strchr(buf, ','); - strncpy(sms.addr, ptr+1, (fcomma-ptr-1)); + strncpy(sms.addr, ptr+1, fcomma-ptr-1); sms.addr[fcomma-ptr-1] = '\0'; - strncpy(sms.data, fcomma+1, strlen(fcomma+1)); - sms.data[strlen(fcomma+1)] = '\0'; - - lgsmd_sms_send(lgsmh, &sms); + packing_7bit_character(fcomma+1, &sms); + + lgsmd_sms_send(lgsmh, &sms); } else if ( !strncmp(buf, "sw", 2)) { printf("Write SMS\n"); struct lgsm_sms_write sms_write; ptr = strchr(buf, '='); - sms_write.stat = atoi(ptr+1); + sms_write.stat = atoi(ptr+1); fcomma = strchr(buf, ','); - lcomma = strrchr(buf, ','); - strncpy(sms_write.sms.addr, fcomma+1, (lcomma-fcomma-1)); + lcomma = strchr(fcomma+1, ','); + strncpy(sms_write.sms.addr, + fcomma+1, lcomma-fcomma-1); sms_write.sms.addr[lcomma-fcomma-1] = '\0'; - strncpy(sms_write.sms.data, lcomma+1, strlen(lcomma+1)); - sms_write.sms.data[strlen(lcomma+1)] = '\0'; - + packing_7bit_character( + lcomma+1, &sms_write.sms); + lgsmd_sms_write(lgsmh, &sms_write); } else { printf("Unknown command `%s'\n", buf); |