# HG changeset patch # User Mychaela Falconia # Date 1517988622 0 # Node ID 7154a231e4b5b9538d1e73480c329c9692aa0aec # Parent 15120d15cab5a070e4ca9caf3338a829a1685c7d uptools/libcoding: SMS dest address parsing and encoding implemented diff -r 15120d15cab5 -r 7154a231e4b5 uptools/libcoding/Makefile --- a/uptools/libcoding/Makefile Wed Feb 07 06:50:14 2018 +0000 +++ b/uptools/libcoding/Makefile Wed Feb 07 07:30:22 2018 +0000 @@ -2,8 +2,8 @@ CFLAGS= -O2 OBJS= alpha_addr.o decode_helpers.o grokdcs.o gsm7_decode.o \ gsm7_decode_tables.o gsm7_encode.o gsm7_encode_table.o gsm7_pack.o \ - gsm7_unpack.o gsmtime.o hexdecode.o hexdump.o number_decode.o scaddr.o \ - ucs2_decode.o utf8_decode.o + gsm7_unpack.o gsmtime.o hexdecode.o hexdump.o number_decode.o \ + number_encode.o scaddr.o ucs2_decode.o utf8_decode.o LIB= libcoding.a all: ${LIB} diff -r 15120d15cab5 -r 7154a231e4b5 uptools/libcoding/number_encode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uptools/libcoding/number_encode.c Wed Feb 07 07:30:22 2018 +0000 @@ -0,0 +1,80 @@ +/* + * This library module implements the function that parses SMS destination + * addresses given by the user and encodes them into the GSM 03.40 + * TP-Destination-Address structure. + */ + +#include +#include +#include + +digit_char_to_gsm(ch) +{ + switch (ch) { + case '0': + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '7': + case '8': + case '9': + return (ch - '0'); + case '*': + return 0xA; + case '#': + return 0xB; + case 'a': + case 'b': + case 'c': + return (ch - 'a' + 0xC); + case 'A': + case 'B': + case 'C': + return (ch - 'A' + 0xC); + } + return (-1); +} + +parse_and_encode_dest_addr(input, outbuf) + char *input; + u_char *outbuf; +{ + char *cp, *endp; + int d; + u_char digits[20]; + unsigned n; + + cp = input; + if (*cp == '+') { + outbuf[1] = 0x91; + cp++; + } else + outbuf[1] = 0x81; + if (digit_char_to_gsm(*cp) < 0) + return(-1); + n = 0; + while ((d = digit_char_to_gsm(*cp)) >= 0) { + cp++; + if (n >= 20) + return(-1); + digits[n++] = d; + } + outbuf[0] = n; + while (n < 20) + digits[n++] = 0xF; + if (*cp == ',') { + cp++; + if (!isdigit(*cp)) + return(-1); + outbuf[1] = strtoul(cp, &endp, 0); + if (*endp) + return(-1); + } else if (*cp) + return(-1); + for (n = 0; n < 10; n++) + outbuf[2+n] = (digits[n*2+1] << 4) | digits[n*2]; + return(0); +}