From 9597555a362cd28c02e9bbfe4f55c4b90ecdfa34 Mon Sep 17 00:00:00 2001 From: Andreas Eversberg Date: Thu, 8 Aug 2013 12:38:53 +0200 Subject: Add special 7-bit encoding and decoding functions for USSD coding Handling 7-bit coding is a little different for USSD, as TS 03.38 states: To avoid the situation where the receiving entity confuses 7 binary zero pad bits as the @ character, the carriage return or character shall be used for padding in this situation [...]. If is intended to be the last character and the message (including the wanted ) ends on an octet boundary, then another must be added together with a padding bit 0. The receiving entity will perform the carriage return function twice, but this will not result in misoperation as the definition of [...] is identical to the definition of . The receiving entity shall remove the final character where the message ends on an octet boundary with as the last character. Jacob has verified the fix with fakeBTS and the wireshark dissector. Fixes: OW#947 Reviewed-by: Jacob Erlbeck --- tests/ussd/ussd_test.c | 22 ++++++++++++++++++++++ tests/ussd/ussd_test.ok | 21 +++++++++++++++++++++ 2 files changed, 43 insertions(+) (limited to 'tests') diff --git a/tests/ussd/ussd_test.c b/tests/ussd/ussd_test.c index 55384f10..d41c141d 100644 --- a/tests/ussd/ussd_test.c +++ b/tests/ussd/ussd_test.c @@ -22,6 +22,7 @@ #include #include #include +#include #include #include #include @@ -68,6 +69,20 @@ static int parse_mangle_ussd(const uint8_t *_data, int len) struct log_info info = {}; +void gsm_7bit_ussd(char *text) +{ + uint8_t coded[256]; + char decoded[256]; + int y; + + printf("original = %s\n", osmo_hexdump((uint8_t *)text, strlen(text))); + gsm_7bit_encode_ussd(coded, text, &y); + printf("encoded = %s\n", osmo_hexdump(coded, y)); + gsm_7bit_decode_ussd(decoded, coded, y * 8 / 7); + y = strlen(decoded); + printf("decoded = %s\n\n", osmo_hexdump((uint8_t *)decoded, y)); +} + int main(int argc, char **argv) { struct ussd_request req; @@ -93,5 +108,12 @@ int main(int argc, char **argv) printf("Result for %d is %d\n", rc, i); } + printf(" case test for 7 bit encode\n"); + gsm_7bit_ussd("01234567"); + gsm_7bit_ussd("0123456"); + gsm_7bit_ussd("01234567\r"); + gsm_7bit_ussd("0123456\r"); + gsm_7bit_ussd("012345\r"); + return 0; } diff --git a/tests/ussd/ussd_test.ok b/tests/ussd/ussd_test.ok index 1b6316e8..91f2a315 100644 --- a/tests/ussd/ussd_test.ok +++ b/tests/ussd/ussd_test.ok @@ -51,3 +51,24 @@ Result for 0 is 8 Result for 0 is 7 Result for 0 is 6 Result for 1 is 5 + case test for 7 bit encode +original = 30 31 32 33 34 35 36 37 +encoded = b0 98 6c 46 ab d9 6e +decoded = 30 31 32 33 34 35 36 37 + +original = 30 31 32 33 34 35 36 +encoded = b0 98 6c 46 ab d9 1a +decoded = 30 31 32 33 34 35 36 + +original = 30 31 32 33 34 35 36 37 0d +encoded = b0 98 6c 46 ab d9 6e 0d +decoded = 30 31 32 33 34 35 36 37 0d + +original = 30 31 32 33 34 35 36 0d +encoded = b0 98 6c 46 ab d9 1a 0d +decoded = 30 31 32 33 34 35 36 0d 0d + +original = 30 31 32 33 34 35 0d +encoded = b0 98 6c 46 ab 35 1a +decoded = 30 31 32 33 34 35 0d + -- cgit v1.2.3