From 9b7916395e21e4efe3d0fc76adad30c3b1f169be Mon Sep 17 00:00:00 2001 From: erin_yueh Date: Thu, 17 Jan 2008 08:35:53 +0000 Subject: gsmd: fix CMT_parse comma error (Sean Chiang) git-svn-id: http://svn.openmoko.org/trunk/src/target/gsm@3861 99fdad57-331a-0410-800a-d7fa5415bdb3 --- src/gsmd/sms_cb.c | 45 ++++++++++++++++++++++++++++++++++++++------- src/util/event.c | 2 ++ 2 files changed, 40 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/gsmd/sms_cb.c b/src/gsmd/sms_cb.c index 0e97749..7d69f12 100644 --- a/src/gsmd/sms_cb.c +++ b/src/gsmd/sms_cb.c @@ -39,6 +39,7 @@ #include #include #include +#include static const char *ts0705_memtype_name[] = { [GSM0705_MEMTYPE_NONE] = "NONE", @@ -431,9 +432,10 @@ static int cmt_parse(const char *buf, int len, const char *param, { /* TODO: TEXT mode */ u_int8_t pdu[SMS_MAX_PDU_SIZE]; - const char *comma = strchr(param, ','); - char *cr; + const char *cr = NULL; int i; + char tmp[64]; + struct gsm_extrsp *er; struct gsmd_evt_auxdata *aux; struct gsmd_sms_list *msg; struct gsmd_ucmd *ucmd = usock_build_event(GSMD_MSG_EVENT, @@ -446,14 +448,43 @@ static int cmt_parse(const char *buf, int len, const char *param, aux = (struct gsmd_evt_auxdata *) ucmd->buf; msg = (struct gsmd_sms_list *) aux->data; - if (!comma) { + cr = strchr(param, '\n'); + + if (!cr) { talloc_free(ucmd); - return -EINVAL; + return -EAGAIN; } - len = strtoul(comma + 1, &cr, 10); - if (cr[0] != '\n') { + + strncpy(tmp, param, (cr-param)); + tmp[(cr-param)] = '\0'; + + er = extrsp_parse(gsmd_tallocs, tmp); + + if ( !er ) { talloc_free(ucmd); - return -EAGAIN; + return -ENOMEM; + } + + //extrsp_dump(er); + + if ( er->num_tokens == 2 && + er->tokens[0].type == GSMD_ECMD_RTT_EMPTY && + er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC ) { + + aux->u.sms.alpha[0] = '\0'; + len = er->tokens[1].u.numeric; + } + else if ( er->num_tokens == 2 && + er->tokens[0].type == GSMD_ECMD_RTT_STRING && + er->tokens[1].type == GSMD_ECMD_RTT_NUMERIC ) { + + strcpy(aux->u.sms.alpha, er->tokens[0].u.string); + len = er->tokens[1].u.numeric; + } + else { + talloc_free(ucmd); + talloc_free(er); + return -EINVAL; } cr ++; diff --git a/src/util/event.c b/src/util/event.c index 88f315f..de1da99 100644 --- a/src/util/event.c +++ b/src/util/event.c @@ -64,6 +64,8 @@ static int insms_handler(struct lgsm_handle *lh, int evt, (sms->time_stamp[6] & 8) ? '-' : '+', (((sms->time_stamp[6] << 4) | (sms->time_stamp[6] >> 4)) & 0x3f) >> 2); + if ( strlen(aux->u.sms.alpha) ) + printf("From %s\n", aux->u.sms.alpha); if (sms->payload.coding_scheme == ALPHABET_DEFAULT) { unpacking_7bit_character(&sms->payload, payload); printf("\"%s\"\n", payload); -- cgit v1.2.3