FreeCalypso > hg > fc-pcsc-tools
comparison simtool/pbdump.c @ 8:4a9bf783491d
phone number decoding factored out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Feb 2021 00:07:24 +0000 |
parents | ce189c97b7b1 |
children | dc565e91069d |
comparison
equal
deleted
inserted
replaced
7:4360a7906f34 | 8:4a9bf783491d |
---|---|
7 #include <strings.h> | 7 #include <strings.h> |
8 #include <stdio.h> | 8 #include <stdio.h> |
9 #include <stdlib.h> | 9 #include <stdlib.h> |
10 #include "simresp.h" | 10 #include "simresp.h" |
11 #include "curfile.h" | 11 #include "curfile.h" |
12 | |
13 static char gsm_address_digits[16] = | |
14 {'0','1','2','3','4','5','6','7','8','9','*','#','a','b','c','?'}; | |
15 | |
16 static | |
17 decode_number(data, nbytes, out) | |
18 u_char *data; | |
19 unsigned nbytes; | |
20 char *out; | |
21 { | |
22 u_char *dp, *endp; | |
23 int c; | |
24 | |
25 dp = data; | |
26 endp = data + nbytes; | |
27 while (dp < endp) { | |
28 c = *dp & 0xF; | |
29 if (c == 0xF) | |
30 return(-1); | |
31 *out++ = gsm_address_digits[c]; | |
32 c = *dp >> 4; | |
33 if (c == 0xF) { | |
34 if (dp + 1 == endp) | |
35 break; | |
36 else | |
37 return(-1); | |
38 } | |
39 *out++ = gsm_address_digits[c]; | |
40 dp++; | |
41 } | |
42 *out = '\0'; | |
43 return(0); | |
44 } | |
45 | 12 |
46 static | 13 static |
47 check_blank_area(dp, endp) | 14 check_blank_area(dp, endp) |
48 u_char *dp, *endp; | 15 u_char *dp, *endp; |
49 { | 16 { |
75 } else | 42 } else |
76 textlen = 0; | 43 textlen = 0; |
77 fixp = sim_resp_data + sim_resp_data_len - 14; | 44 fixp = sim_resp_data + sim_resp_data_len - 14; |
78 if (fixp[0] < 2 || fixp[0] > 11) | 45 if (fixp[0] < 2 || fixp[0] > 11) |
79 goto malformed; | 46 goto malformed; |
80 rc = decode_number(fixp + 2, fixp[0] - 1, digits); | 47 rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits); |
81 if (rc < 0) | 48 if (rc < 0) |
82 goto malformed; | 49 goto malformed; |
83 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12); | 50 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12); |
84 if (rc < 0) | 51 if (rc < 0) |
85 goto malformed; | 52 goto malformed; |