From 8a74805ea6c41e8e17983da6cec06e2466c072d1 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Sat, 11 Nov 2017 08:11:50 +0100 Subject: [PATCH] NMT: Add support for receiving 8-Bit-SMS, because it is mandatory Benefone Dragon uses this coding scheme for SMS-Submit. --- src/nmt/sms.c | 28 ++++++++++++++++++++++------ src/test/test_sms.c | 39 ++++++++++++++++++++++++++++++++------- 2 files changed, 54 insertions(+), 13 deletions(-) diff --git a/src/nmt/sms.c b/src/nmt/sms.c index d1d2fc6..abb6edf 100644 --- a/src/nmt/sms.c +++ b/src/nmt/sms.c @@ -360,8 +360,8 @@ static void sms_submit_report(nmt_t *nmt, uint8_t ref, int error) * receive from lower layer */ -/* decdoe message from 8 bit data */ -static void decode_message(const uint8_t *data, int length, char *message) +/* decode 7-bit character message from 8 bit data */ +static void decode_message_7(const uint8_t *data, int length, char *message) { int fill; int i; @@ -408,6 +408,7 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) int orig_digits, dest_digits, msg_chars; uint8_t orig_type, orig_plan, dest_type, dest_plan; int tp_vpf_present = 0; + int coding = 0; int rc; /* decode ref */ @@ -515,7 +516,13 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) PDEBUG(DSMS, DEBUG_NOTICE, "short data coding scheme IE\n"); return -FSC_ERROR_IN_MS; } - if (data[0] != 0) { + if (data[0] == 0x00) { + PDEBUG(DSMS, DEBUG_DEBUG, "SMS coding is 7 bits (got 0x%02x)\n", data[0]); + coding = 7; + } else if ((data[0] & 0xf0) == 0x30) { + PDEBUG(DSMS, DEBUG_DEBUG, "SMS coding is 8 bits (got 0x%02x)\n", data[0]); + coding = 8; + } else { PDEBUG(DSMS, DEBUG_NOTICE, "SMS coding unsupported (got 0x%02x)\n", data[0]); return -FSC_ERROR_IN_MS; } @@ -539,14 +546,23 @@ static int decode_sms_submit(nmt_t *nmt, const uint8_t *data, int length) } msg_data = data + 1; msg_chars = data[0]; - msg_len = (msg_chars * 7 + 7) / 8; + if (coding == 7) + msg_len = (msg_chars * 7 + 7) / 8; + else + msg_len = msg_chars; if (length < 1 + msg_len) { PDEBUG(DSMS, DEBUG_NOTICE, "short read user data IE\n"); return -FSC_ERROR_IN_MS; } char message[msg_chars + 1]; - decode_message(msg_data, msg_len, message); - PDEBUG(DSMS, DEBUG_DEBUG, "Decoded message: '%s'\n", message); + if (coding == 7) { + decode_message_7(msg_data, msg_len, message); + PDEBUG(DSMS, DEBUG_DEBUG, "Decoded message: '%s'\n", message); + } else { + memcpy(message, msg_data, msg_len); + message[msg_len] = '\0'; + PDEBUG(DSMS, DEBUG_DEBUG, "Included message: '%s'\n", message); + } PDEBUG(DSMS, DEBUG_INFO, "Submitting SMS to upper layer\n"); diff --git a/src/test/test_sms.c b/src/test/test_sms.c index 867113b..1706dd3 100644 --- a/src/test/test_sms.c +++ b/src/test/test_sms.c @@ -9,14 +9,22 @@ #include "../common/timer.h" #include "../nmt/nmt.h" -static const uint8_t test_mo_sms_data[] = { +static const uint8_t test_mo_sms_data1[] = { 0x00, 0x00, 0x00, 0xa1, 0x41, 0x0f, 0x11, 0x00, 0x04, 0xa1, 0x8a, 0x51, 0x00, 0x00, 0xff, 0x05, 0xc8, 0x20, 0x93, 0xf9, 0x7c, }; +static const uint8_t test_mo_sms_data2[] = { + 0x00, 0x02, 0x07, 0xa1, 0xa9, 0x62, 0x65, + 0xf4, 0x41, 0x10, 0x11, 0x02, 0x03, 0xa1, + 0x21, 0xf3, + 0x00, 0x30, 0xff, 0x06, 0x48, 0x61, 0x6c, + 0x6c, 0x6f, 0x21, +}; -static const char *test_mo_sms_text = "HALLO"; +static const char *test_mo_sms_text1 = "HALLO"; +static const char *test_mo_sms_text2 = "Hallo!"; static const char *test_mt_sms_text = "Moin Moin"; static const char *test_mt_sms_tel = "4948416068"; @@ -121,13 +129,30 @@ int main(void) sms_init_sender(nmt); sms_reset(nmt); - printf("(submitting SMS)\n"); + printf("(submitting SMS 7-bit encoded)\n"); dms_buffer_count = 0; - for (i = 0; i < sizeof(test_mo_sms_data); i++) - dms_receive(nmt, test_mo_sms_data + i, 1, 1); + for (i = 0; i < sizeof(test_mo_sms_data1); i++) + dms_receive(nmt, test_mo_sms_data1 + i, 1, 1); - assert(dms_buffer_count == strlen(test_mo_sms_text), "Expecting SMS text length to match"); - assert(!memcmp(dms_buffer, test_mo_sms_text, dms_buffer_count), "Expecting SMS text to match"); + assert(dms_buffer_count == strlen(test_mo_sms_text1), "Expecting SMS text length to match"); + assert(!memcmp(dms_buffer, test_mo_sms_text1, dms_buffer_count), "Expecting SMS text to match"); + + sms_cleanup_sender(nmt); + free(nmt); + + ok(); + + nmt = calloc(sizeof(*nmt), 1); + sms_init_sender(nmt); + sms_reset(nmt); + + printf("(submitting SMS 8-bit encoded)\n"); + dms_buffer_count = 0; + for (i = 0; i < sizeof(test_mo_sms_data2); i++) + dms_receive(nmt, test_mo_sms_data2 + i, 1, 1); + + assert(dms_buffer_count == strlen(test_mo_sms_text2), "Expecting SMS text length to match"); + assert(!memcmp(dms_buffer, test_mo_sms_text2, dms_buffer_count), "Expecting SMS text to match"); sms_cleanup_sender(nmt); free(nmt);