FreeCalypso > hg > fc-sim-tools
annotate libcommon/dumpdirfunc.c @ 86:de23872796cb
fc-uicc-tool: update-rec-imm and update-rec-fill ported over from fc-simtool
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 11 Apr 2021 03:19:22 +0000 |
parents | c9ef9e91dd8e |
children |
rev | line source |
---|---|
9
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the common function for dumping EF_DIR. |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "simresp.h" |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 static void |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 dump_aid(tlv, outf) |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_char *tlv; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 FILE *outf; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 unsigned reclen, n; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 reclen = tlv[1]; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 fputs(" AID:", outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 for (n = 0; n < reclen; n++) |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 fprintf(outf, " %02X", tlv[n+2]); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 putc('\n', outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 static void |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 dump_label(tlv, outf) |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 u_char *tlv; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 FILE *outf; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 int rc; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 unsigned textlen; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 fputs(" Label: ", outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 rc = validate_alpha_field(tlv + 2, tlv[1], &textlen); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 if (rc < 0) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 fputs("malformed\n", outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 print_alpha_field(tlv + 2, textlen, outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 putc('\n', outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 static void |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 dump_unknown_tlv(tlv, outf) |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 u_char *tlv; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 FILE *outf; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 unsigned reclen, n; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 reclen = tlv[1] + 2; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 fputs(" TLV:", outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 for (n = 0; n < reclen; n++) |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 fprintf(outf, " %02X", tlv[n]); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 putc('\n', outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 void |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 dump_efdir_record(outf) |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 FILE *outf; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 unsigned totlen, reclen; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 u_char *dp, *endp; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 if (sim_resp_data[0] != 0x61) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 fprintf(outf, " bad: first byte != 0x61\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 totlen = sim_resp_data[1]; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (totlen < 3 || totlen > 0x7F) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(outf, " bad: global length byte 0x%02X is invalid\n", |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 totlen); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 return; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 if (totlen + 2 > sim_resp_data_len) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 fprintf(outf, |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 " bad: TLV global length exceeds EF record length\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 return; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 dp = sim_resp_data + 2; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 endp = sim_resp_data + 2 + totlen; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 while (dp < endp) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (endp - dp < 2) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 trunc_error: fprintf(outf, " bad: truncated TLV record\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 if ((dp[0] & 0x1F) == 0x1F) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 fprintf(outf, " bad: extended tag not supported\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 return; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (dp[1] & 0x80) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 fprintf(outf, " bad: extended length not supported\n"); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 return; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 reclen = dp[1] + 2; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (endp - dp < reclen) |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 goto trunc_error; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 switch (dp[0]) { |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 case 0x4F: |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 dump_aid(dp, outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 break; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 case 0x50: |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 dump_label(dp, outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 break; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 default: |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 dump_unknown_tlv(dp, outf); |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 dp += reclen; |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } |
c9ef9e91dd8e
new libcommon, initial version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 } |