annotate libcommon/dumpdirfunc.c @ 92:9c3155221b0e

doc/Low-level-commands: readef command documented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 19:18:20 +0000
parents 2c72709e0891
children dcfec53643c5
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 dump_aid(tlv)
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 u_char *tlv;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 unsigned reclen, n;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 reclen = tlv[1];
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 printf(" AID:");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 for (n = 0; n < reclen; n++)
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 printf(" %02X", tlv[n+2]);
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 putchar('\n');
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 }
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 static void
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 dump_label(tlv)
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 u_char *tlv;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 int rc;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 unsigned textlen;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 printf(" Label: ");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 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
31 if (rc < 0) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 printf("malformed\n");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 print_alpha_field(tlv + 2, textlen, stdout);
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 putchar('\n');
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 static void
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 dump_unknown_tlv(tlv)
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 u_char *tlv;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 unsigned reclen, n;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 reclen = tlv[1] + 2;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 printf(" TLV:");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 for (n = 0; n < reclen; n++)
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 printf(" %02X", tlv[n]);
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 putchar('\n');
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 void
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 dump_efdir_record()
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 unsigned totlen, reclen;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 u_char *dp, *endp;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 if (sim_resp_data[0] != 0x61) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 printf(" bad: first byte != 0x61\n");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return;
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 totlen = sim_resp_data[1];
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (totlen < 3 || totlen > 0x7F) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 printf(" bad: global length byte 0x%02X is invalid\n", totlen);
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 return;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 if (totlen + 2 > sim_resp_data_len) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 printf(" bad: TLV global length exceeds EF record length\n");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 return;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 dp = sim_resp_data + 2;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 endp = sim_resp_data + 2 + totlen;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 while (dp < endp) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (endp - dp < 2) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 trunc_error: printf(" bad: truncated TLV record\n");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 return;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if ((dp[0] & 0x1F) == 0x1F) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 printf(" bad: extended tag not supported\n");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 if (dp[1] & 0x80) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 printf(" bad: extended length not supported\n");
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 return;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 reclen = dp[1] + 2;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (endp - dp < reclen)
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 goto trunc_error;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 switch (dp[0]) {
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 case 0x4F:
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
91 dump_aid(dp);
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 break;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 case 0x50:
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 dump_label(dp);
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 break;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 default:
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 dump_unknown_tlv(dp);
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 dp += reclen;
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 }
2c72709e0891 EF_DIR dump meaty function factored out into libcommon
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
101 }