FreeCalypso > hg > fc-pcsc-tools
comparison simtool/smsp_dump.c @ 38:f5a26c1d0b93
fc-simtool smsp-dump implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 12 Feb 2021 20:39:15 +0000 |
parents | simtool/pbdump.c@72a24b8538eb |
children | f1ea981ab225 |
comparison
equal
deleted
inserted
replaced
37:acf343dace04 | 38:f5a26c1d0b93 |
---|---|
1 /* | |
2 * This module implements intelligent dumping of EF_SMSP (smsp-dump). | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <stdio.h> | |
7 #include "simresp.h" | |
8 #include "curfile.h" | |
9 | |
10 static | |
11 check_blank_area(dp, endp) | |
12 u_char *dp, *endp; | |
13 { | |
14 while (dp < endp) | |
15 if (*dp++ != 0xFF) | |
16 return(-1); | |
17 return(0); | |
18 } | |
19 | |
20 static void | |
21 dump_da_field(binaddr, outf) | |
22 u_char *binaddr; | |
23 FILE *outf; | |
24 { | |
25 char digits[21]; | |
26 | |
27 fputs("DA=", outf); | |
28 if (binaddr[0] < 1 || binaddr[0] > 20) { | |
29 malformed: fputs("malformed ", outf); | |
30 return; | |
31 } | |
32 if ((binaddr[0] & 1) && (binaddr[(binaddr[0] >> 1) + 2] & 0xF0) != 0xF0) | |
33 goto malformed; | |
34 if (check_blank_area(binaddr + 2 + ((binaddr[0] + 1) >> 1), | |
35 binaddr + 12) < 0) | |
36 goto malformed; | |
37 /* all checks passed */ | |
38 decode_address_digits(binaddr + 2, digits, binaddr[0]); | |
39 fprintf(outf, "%s,0x%02X ", digits, binaddr[1]); | |
40 } | |
41 | |
42 static void | |
43 dump_sca_field(binaddr, outf) | |
44 u_char *binaddr; | |
45 FILE *outf; | |
46 { | |
47 char digits[21]; | |
48 int rc; | |
49 | |
50 fputs("SC=", outf); | |
51 if (binaddr[0] < 2 || binaddr[0] > 11) { | |
52 malformed: fputs("malformed ", outf); | |
53 return; | |
54 } | |
55 rc = decode_phone_number(binaddr + 2, binaddr[0] - 1, digits); | |
56 if (rc < 0) | |
57 goto malformed; | |
58 rc = check_blank_area(binaddr + 1 + binaddr[0], binaddr + 12); | |
59 if (rc < 0) | |
60 goto malformed; | |
61 /* all checks passed */ | |
62 fprintf(outf, "%s,0x%02X ", digits, binaddr[1]); | |
63 } | |
64 | |
65 static void | |
66 dump_record(recno, outf) | |
67 unsigned recno; | |
68 FILE *outf; | |
69 { | |
70 int rc; | |
71 unsigned textlen; | |
72 u_char *fixp; | |
73 | |
74 fprintf(outf, "#%u: ", recno); | |
75 if (sim_resp_data_len > 28) { | |
76 rc = validate_alpha_field(sim_resp_data, | |
77 sim_resp_data_len - 28, | |
78 &textlen); | |
79 if (rc < 0) { | |
80 malformed: fprintf(outf, "malformed record\n"); | |
81 return; | |
82 } | |
83 } else | |
84 textlen = 0; | |
85 fixp = sim_resp_data + sim_resp_data_len - 28; | |
86 if ((fixp[0] & 0xE0) != 0xE0) | |
87 goto malformed; | |
88 if ((fixp[0] & 0x01) && check_blank_area(fixp + 1, fixp + 13) < 0) | |
89 goto malformed; | |
90 if ((fixp[0] & 0x02) && check_blank_area(fixp + 13, fixp + 25) < 0) | |
91 goto malformed; | |
92 if ((fixp[0] & 0x04) && fixp[25] != 0xFF) | |
93 goto malformed; | |
94 if ((fixp[0] & 0x08) && fixp[26] != 0xFF) | |
95 goto malformed; | |
96 if ((fixp[0] & 0x10) && fixp[27] != 0xFF) | |
97 goto malformed; | |
98 /* basic checks passed, emit present fields */ | |
99 if (!(fixp[0] & 0x01)) | |
100 dump_da_field(fixp + 1, outf); | |
101 if (!(fixp[0] & 0x02)) | |
102 dump_sca_field(fixp + 13, outf); | |
103 if (!(fixp[0] & 0x04)) | |
104 fprintf(outf, "PID=0x%02X ", fixp[25]); | |
105 if (!(fixp[0] & 0x08)) | |
106 fprintf(outf, "DCS=0x%02X ", fixp[26]); | |
107 if (!(fixp[0] & 0x10)) | |
108 fprintf(outf, "VP=%u ", fixp[27]); | |
109 print_alpha_field(sim_resp_data, textlen, outf); | |
110 putc('\n', outf); | |
111 } | |
112 | |
113 cmd_smsp_dump(argc, argv) | |
114 char **argv; | |
115 { | |
116 int rc; | |
117 FILE *outf; | |
118 unsigned recno; | |
119 | |
120 rc = select_ef_smsp(); | |
121 if (rc < 0) | |
122 return(rc); | |
123 if (argv[1]) { | |
124 outf = fopen(argv[1], "w"); | |
125 if (!outf) { | |
126 perror(argv[1]); | |
127 return(-1); | |
128 } | |
129 } else | |
130 outf = stdout; | |
131 for (recno = 1; recno <= curfile_record_count; recno++) { | |
132 rc = readrec_op(recno, 0x04, curfile_record_len); | |
133 if (rc < 0) { | |
134 if (argv[1]) | |
135 fclose(outf); | |
136 return(rc); | |
137 } | |
138 dump_record(recno, outf); | |
139 } | |
140 if (argv[1]) | |
141 fclose(outf); | |
142 return(0); | |
143 } |