FreeCalypso > hg > freecalypso-tools
comparison uptools/libcoding/number_encode.c @ 358:7154a231e4b5
uptools/libcoding: SMS dest address parsing and encoding implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 07 Feb 2018 07:30:22 +0000 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
357:15120d15cab5 | 358:7154a231e4b5 |
---|---|
1 /* | |
2 * This library module implements the function that parses SMS destination | |
3 * addresses given by the user and encodes them into the GSM 03.40 | |
4 * TP-Destination-Address structure. | |
5 */ | |
6 | |
7 #include <sys/types.h> | |
8 #include <ctype.h> | |
9 #include <stdlib.h> | |
10 | |
11 digit_char_to_gsm(ch) | |
12 { | |
13 switch (ch) { | |
14 case '0': | |
15 case '1': | |
16 case '2': | |
17 case '3': | |
18 case '4': | |
19 case '5': | |
20 case '6': | |
21 case '7': | |
22 case '8': | |
23 case '9': | |
24 return (ch - '0'); | |
25 case '*': | |
26 return 0xA; | |
27 case '#': | |
28 return 0xB; | |
29 case 'a': | |
30 case 'b': | |
31 case 'c': | |
32 return (ch - 'a' + 0xC); | |
33 case 'A': | |
34 case 'B': | |
35 case 'C': | |
36 return (ch - 'A' + 0xC); | |
37 } | |
38 return (-1); | |
39 } | |
40 | |
41 parse_and_encode_dest_addr(input, outbuf) | |
42 char *input; | |
43 u_char *outbuf; | |
44 { | |
45 char *cp, *endp; | |
46 int d; | |
47 u_char digits[20]; | |
48 unsigned n; | |
49 | |
50 cp = input; | |
51 if (*cp == '+') { | |
52 outbuf[1] = 0x91; | |
53 cp++; | |
54 } else | |
55 outbuf[1] = 0x81; | |
56 if (digit_char_to_gsm(*cp) < 0) | |
57 return(-1); | |
58 n = 0; | |
59 while ((d = digit_char_to_gsm(*cp)) >= 0) { | |
60 cp++; | |
61 if (n >= 20) | |
62 return(-1); | |
63 digits[n++] = d; | |
64 } | |
65 outbuf[0] = n; | |
66 while (n < 20) | |
67 digits[n++] = 0xF; | |
68 if (*cp == ',') { | |
69 cp++; | |
70 if (!isdigit(*cp)) | |
71 return(-1); | |
72 outbuf[1] = strtoul(cp, &endp, 0); | |
73 if (*endp) | |
74 return(-1); | |
75 } else if (*cp) | |
76 return(-1); | |
77 for (n = 0; n < 10; n++) | |
78 outbuf[2+n] = (digits[n*2+1] << 4) | digits[n*2]; | |
79 return(0); | |
80 } |