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