FreeCalypso > hg > fc-pcsc-tools
comparison simtool/pbdump.c @ 19:72a24b8538eb
meaty function of pb-dump moved back into simtool, out of libcommon
Upon further reflection, I am not going to keep any of the pb-*
commands in the new version of fc-uicc-tool: they are logically
incorrect for UICC/USIM anyway, as they access phonebook files
via old classic SIM paths, rather than their USIM paths. OTOH,
I am going to implement new SMSP commands in fc-simtool, and I
do not plan to replicate them in fc-uicc-tool either. Guts of
fc-simtool pb-dump belong in simtool/pbdump.c, not in libcommon,
just like the guts of the future smsp-dump command will belong
in its own respective implementation module.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Feb 2021 03:33:26 +0000 |
parents | dc565e91069d |
children | 1861d9fb7751 |
comparison
equal
deleted
inserted
replaced
18:2ef261371347 | 19:72a24b8538eb |
---|---|
3 */ | 3 */ |
4 | 4 |
5 #include <sys/types.h> | 5 #include <sys/types.h> |
6 #include <stdio.h> | 6 #include <stdio.h> |
7 #include <stdlib.h> | 7 #include <stdlib.h> |
8 #include "simresp.h" | |
8 #include "curfile.h" | 9 #include "curfile.h" |
10 | |
11 static | |
12 check_blank_area(dp, endp) | |
13 u_char *dp, *endp; | |
14 { | |
15 while (dp < endp) | |
16 if (*dp++ != 0xFF) | |
17 return(-1); | |
18 return(0); | |
19 } | |
20 | |
21 static void | |
22 dump_record(recno, outf) | |
23 unsigned recno; | |
24 FILE *outf; | |
25 { | |
26 int rc; | |
27 unsigned textlen; | |
28 u_char *fixp; | |
29 char digits[21]; | |
30 | |
31 fprintf(outf, "#%u: ", recno); | |
32 if (sim_resp_data_len > 14) { | |
33 rc = validate_alpha_field(sim_resp_data, | |
34 sim_resp_data_len - 14, | |
35 &textlen); | |
36 if (rc < 0) { | |
37 malformed: fprintf(outf, "malformed record\n"); | |
38 return; | |
39 } | |
40 } else | |
41 textlen = 0; | |
42 fixp = sim_resp_data + sim_resp_data_len - 14; | |
43 if (fixp[0] < 2 || fixp[0] > 11) | |
44 goto malformed; | |
45 rc = decode_phone_number(fixp + 2, fixp[0] - 1, digits); | |
46 if (rc < 0) | |
47 goto malformed; | |
48 rc = check_blank_area(fixp + 1 + fixp[0], fixp + 12); | |
49 if (rc < 0) | |
50 goto malformed; | |
51 /* all checks passed */ | |
52 fprintf(outf, "%s,0x%02X ", digits, fixp[1]); | |
53 if (fixp[12] != 0xFF) | |
54 fprintf(outf, "CCP=%u ", fixp[12]); | |
55 if (fixp[13] != 0xFF) | |
56 fprintf(outf, "EXT=%u ", fixp[13]); | |
57 print_alpha_field(sim_resp_data, textlen, outf); | |
58 putc('\n', outf); | |
59 } | |
9 | 60 |
10 cmd_pb_dump(argc, argv) | 61 cmd_pb_dump(argc, argv) |
11 char **argv; | 62 char **argv; |
12 { | 63 { |
13 int rc; | 64 int rc; |
32 fclose(outf); | 83 fclose(outf); |
33 return(rc); | 84 return(rc); |
34 } | 85 } |
35 if (check_simresp_all_blank()) | 86 if (check_simresp_all_blank()) |
36 continue; | 87 continue; |
37 dump_phonebook_record(recno, outf); | 88 dump_record(recno, outf); |
38 } | 89 } |
39 if (argv[2]) | 90 if (argv[2]) |
40 fclose(outf); | 91 fclose(outf); |
41 return(0); | 92 return(0); |
42 } | 93 } |
74 rc = readrec_op(recno, 0x04, curfile_record_len); | 125 rc = readrec_op(recno, 0x04, curfile_record_len); |
75 if (rc < 0) | 126 if (rc < 0) |
76 return(rc); | 127 return(rc); |
77 if (check_simresp_all_blank()) | 128 if (check_simresp_all_blank()) |
78 continue; | 129 continue; |
79 dump_phonebook_record(recno, stdout); | 130 dump_record(recno, stdout); |
80 } | 131 } |
81 return(0); | 132 return(0); |
82 } | 133 } |