# HG changeset patch # User Mychaela Falconia # Date 1517690234 0 # Node ID 18c692984549f3a60f07d8aaac26ea9f49b17511 # Parent 978571e23318f100f7f07b802f0cd71deabc06fe uptools/libcoding: hex line decoding implemented diff -r 978571e23318 -r 18c692984549 uptools/libcoding/Makefile --- a/uptools/libcoding/Makefile Sat Feb 03 20:07:05 2018 +0000 +++ b/uptools/libcoding/Makefile Sat Feb 03 20:37:14 2018 +0000 @@ -1,6 +1,7 @@ CC= gcc CFLAGS= -O2 -OBJS= decode_helpers.o gsm7_decode.o gsm7_decode_tables.o ucs2_decode.o +OBJS= decode_helpers.o gsm7_decode.o gsm7_decode_tables.o hexdecode.o \ + ucs2_decode.o LIB= libcoding.a all: ${LIB} diff -r 978571e23318 -r 18c692984549 uptools/libcoding/hexdecode.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/uptools/libcoding/hexdecode.c Sat Feb 03 20:37:14 2018 +0000 @@ -0,0 +1,37 @@ +/* + * This library module implements decoding of long hex strings, + * such as SMS PDUs. + */ + +#include +#include + +decode_hex_line(inbuf, outbuf, outmax) + char *inbuf; + u_char *outbuf; + unsigned outmax; +{ + char *inp = inbuf; + u_char *outp = outbuf; + unsigned outcnt = 0; + int c, d[2], i; + + while (*inp) { + if (!isxdigit(inp[0]) || !isxdigit(inp[1])) + return(-1); + if (outcnt >= outmax) + break; + for (i = 0; i < 2; i++) { + c = *inp++; + if (isdigit(c)) + d[i] = c - '0'; + else if (isupper(c)) + d[i] = c - 'A' + 10; + else + d[i] = c - 'a' + 10; + } + *outp++ = (d[0] << 4) | d[1]; + outcnt++; + } + return outcnt; +}