FreeCalypso > hg > fc-pcsc-tools
annotate simtool/bfsearch.c @ 217:52c0da56e979
simtool code: select_ef_opl() factored out
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 07 Mar 2021 18:18:29 +0000 |
parents | 26d7a8815515 |
children |
rev | line source |
---|---|
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements a brute force search of file ID space at a given |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * file system directory level. |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <ctype.h> |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "simresp.h" |
149
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
11 #include "file_id.h" |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 parse_skip_ids(argv, array, total) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 char **argv; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 unsigned *array, total; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 unsigned n; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 for (n = 0; n < total; n++) { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 if (!isxdigit(argv[n][0]) || !isxdigit(argv[n][1]) || |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 !isxdigit(argv[n][2]) || !isxdigit(argv[n][3]) || |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 argv[n][4]) { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 fprintf(stderr, "error: argument is not 4-digit hex\n"); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 return(-1); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 array[n] = strtoul(argv[n], 0, 16); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 return(0); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 |
148
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
32 static void |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
33 report_ef_struct(outf) |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
34 FILE *outf; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
35 { |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
36 unsigned total_size, record_len; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
37 |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
38 fputs("EF, ", outf); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
39 total_size = (sim_resp_data[2] << 8) | sim_resp_data[3]; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
40 switch (sim_resp_data[13]) { |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
41 case 0x00: |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
42 fprintf(outf, "transparent, length %u\n", total_size); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
43 return; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
44 case 0x01: |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
45 fputs("linear fixed, ", outf); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
46 break; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
47 case 0x03: |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
48 fputs("cyclic, ", outf); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
49 break; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
50 default: |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
51 fprintf(outf, "struct 0x%02X\n", sim_resp_data[13]); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
52 return; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
53 } |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
54 if (sim_resp_data_len < 15) { |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
55 fprintf(outf, "response struct cut off\n"); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
56 return; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
57 } |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
58 record_len = sim_resp_data[14]; |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
59 fprintf(outf, "record length %u", record_len); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
60 if (record_len && total_size % record_len == 0) |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
61 fprintf(outf, ", %u records", total_size / record_len); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
62 putc('\n', outf); |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
63 } |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
64 |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 cmd_bfsearch(argc, argv, outf) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 char **argv; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 FILE *outf; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 unsigned skip_ids[8], num_skip_ids; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 unsigned bfs, n; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 int rc; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 num_skip_ids = argc - 1; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 rc = parse_skip_ids(argv + 1, skip_ids, num_skip_ids); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (rc < 0) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 return(rc); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 rc = elem_select_op(skip_ids[0]); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 if (rc < 0) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(rc); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 if (!rc) { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 fprintf(stderr, "error: starting file ID 0x%04X not found\n", |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 skip_ids[0]); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 return(-1); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 for (bfs = 0; bfs <= 0xFFFF; bfs++) { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 for (n = 0; n < num_skip_ids; n++) { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if (bfs == skip_ids[n]) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 break; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (n < num_skip_ids) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 continue; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 rc = elem_select_op(bfs); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (rc < 0) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 return(rc); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 if (!rc) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 continue; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 rc = get_response_op(); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 if (rc < 0) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 return(rc); |
148
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
100 fprintf(outf, "%04X: ", bfs); |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 if (sim_resp_data_len < 14) |
148
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
102 fprintf(outf, "too-short response struct\n"); |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 else { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 switch (sim_resp_data[6]) { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 case 0x01: |
148
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
106 fprintf(outf, "MF\n"); |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 break; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 case 0x02: |
148
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
109 fprintf(outf, "DF\n"); |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 break; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 case 0x04: |
148
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
112 report_ef_struct(outf); |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 break; |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 default: |
148
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
115 fprintf(outf, "unknown file type %02X\n", |
db43bc57ecf7
fc-simtool bfsearch: better reporting of EF structure
Mychaela Falconia <falcon@freecalypso.org>
parents:
146
diff
changeset
|
116 sim_resp_data[6]); |
145
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 rc = elem_select_op(skip_ids[0]); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 if (rc < 0) |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 return(rc); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 if (!rc) { |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 fprintf(stderr, |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 "reselecting starting file ID 0x%04X not-found error\n", |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 skip_ids[0]); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 return(-1); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 } |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 return(0); |
c2889812788e
fc-simtool bfsearch implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 } |
149
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
131 |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
132 static |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
133 bfsearch_dir(path, pathlen, siblings, nsiblings, outf) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
134 unsigned *path, pathlen, *siblings, nsiblings; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
135 FILE *outf; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
136 { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
137 unsigned bfs, n; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
138 unsigned df_children[255], ndfc; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
139 unsigned childpath[8]; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
140 int rc; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
141 |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
142 for (n = 0; n < pathlen; n++) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
143 rc = elem_select_op(path[n]); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
144 if (rc < 0) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
145 return(rc); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
146 if (!rc) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
147 fprintf(stderr, |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
148 "error selecting 0x%04X: file not found\n", |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
149 path[n]); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
150 return(-1); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
151 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
152 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
153 ndfc = 0; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
154 for (bfs = 0; bfs <= 0xFFFF; bfs++) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
155 for (n = 0; n < pathlen; n++) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
156 if (bfs == path[n]) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
157 break; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
158 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
159 if (n < pathlen) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
160 continue; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
161 for (n = 0; n < nsiblings; n++) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
162 if (bfs == siblings[n]) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
163 break; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
164 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
165 if (n < nsiblings) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
166 continue; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
167 rc = elem_select_op(bfs); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
168 if (rc < 0) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
169 return(rc); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
170 if (!rc) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
171 continue; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
172 rc = get_response_op(); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
173 if (rc < 0) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
174 return(rc); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
175 for (n = 0; n < pathlen; n++) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
176 fprintf(outf, "%04X/", path[n]); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
177 fprintf(outf, "%04X: ", bfs); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
178 if (sim_resp_data_len < 14) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
179 fprintf(outf, "too-short response struct\n"); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
180 else { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
181 switch (sim_resp_data[6]) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
182 case 0x01: |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
183 fprintf(outf, "MF\n"); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
184 break; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
185 case 0x02: |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
186 fprintf(outf, "DF\n"); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
187 if (ndfc < 255) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
188 df_children[ndfc++] = bfs; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
189 break; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
190 case 0x04: |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
191 report_ef_struct(outf); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
192 break; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
193 default: |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
194 fprintf(outf, "unknown file type %02X\n", |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
195 sim_resp_data[6]); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
196 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
197 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
198 rc = elem_select_op(path[pathlen-1]); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
199 if (rc < 0) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
200 return(rc); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
201 if (!rc) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
202 fprintf(stderr, |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
203 "reselecting starting file ID 0x%04X not-found error\n", |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
204 path[pathlen-1]); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
205 return(-1); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
206 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
207 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
208 if (pathlen >= 8) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
209 return(0); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
210 for (n = 0; n < pathlen; n++) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
211 childpath[n] = path[n]; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
212 for (n = 0; n < ndfc; n++) { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
213 childpath[pathlen] = df_children[n]; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
214 rc = bfsearch_dir(childpath, pathlen + 1, df_children, ndfc, |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
215 outf); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
216 if (rc < 0) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
217 return(rc); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
218 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
219 return(0); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
220 } |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
221 |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
222 cmd_bfsearch_full(argc, argv, outf) |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
223 char **argv; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
224 FILE *outf; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
225 { |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
226 unsigned initpath; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
227 |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
228 initpath = FILEID_MF; |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
229 return bfsearch_dir(&initpath, 1, &initpath, 1, outf); |
26d7a8815515
fc-simtool bfsearch-full implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
148
diff
changeset
|
230 } |