annotate simtool/select.c @ 89:fb75855a74a9

fc-simtool: select response parsing: show number of records
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jan 2021 18:03:55 +0000
parents 2a0d1d5b9313
children d4150123ca45
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <string.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <strings.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdlib.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <pcsclite.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <winscard.h>
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "globals.h"
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 select_op(file_id)
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned file_id;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_char cmd[7];
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int rc;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned expect_resp_len;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 /* SELECT command APDU */
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 cmd[0] = 0xA0;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 cmd[1] = 0xA4;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 cmd[2] = 0;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 cmd[3] = 0;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cmd[4] = 2;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cmd[5] = file_id >> 8;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd[6] = file_id;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc = apdu_exchange(cmd, 7);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc < 0)
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(rc);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 if ((sim_resp_sw & 0xFF00) != 0x9F00) {
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 fprintf(stderr,
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 "error or unexpected SW response to SELECT of 0x%04X: %04X\n",
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 file_id, sim_resp_sw);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 return(-1);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 expect_resp_len = sim_resp_sw & 0xFF;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 /* GET RESPONSE follow-up */
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 cmd[1] = 0xC0;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 cmd[4] = expect_resp_len;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 rc = apdu_exchange(cmd, 5);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 if (rc < 0)
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return(rc);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 if (sim_resp_sw != 0x9000) {
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 fprintf(stderr,
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 "bad SW resp to GET RESPONSE after SELECT: %04X\n",
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 sim_resp_sw);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 return(-1);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 }
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 if (sim_resp_data_len != expect_resp_len) {
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 fprintf(stderr,
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 "error: GET RESPONSE after SELECT returned %u bytes, expected %u\n",
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 sim_resp_data_len, expect_resp_len);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 return(-1);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 }
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(0);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56
86
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
57 static void
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
58 show_secret_code_status(name, byte)
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
59 char *name;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
60 unsigned byte;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
61 {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
62 printf("Status of %s: %s, %u attempts left\n", name,
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
63 byte & 0x80 ? "initialized" : "not initialized",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
64 byte & 0x0F);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
65 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
66
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
67 static void
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
68 show_access_conditions(oper_name, cond_code)
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
69 char *oper_name;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
70 unsigned cond_code;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
71 {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
72 static char *cond_names[16] =
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
73 {"ALW", "CHV1", "CHV2", "RFU3",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
74 "ADM4", "ADM5", "ADM6", "ADM7",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
75 "ADM8", "ADM9", "ADM10", "ADM11",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
76 "ADM12", "ADM13", "ADM14", "NEV"};
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
77
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
78 printf("Access condition for %s: %s\n", oper_name,
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
79 cond_names[cond_code]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
80 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
81
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
82 cmd_select(argc, argv)
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 char **argv;
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
84 {
87
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
85 int file_id, rc;
89
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
86 unsigned file_size;
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 file_id = strtoul(argv[1], 0, 16);
87
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
91 else
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
92 file_id = find_symbolic_file_name(argv[1]);
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
93 if (file_id < 0) {
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 fprintf(stderr,
87
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
95 "error: file ID argument is not a hex value or a recognized symbolic name\n");
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 return(-1);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
97 }
86
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
98 rc = select_op(file_id);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
99 if (rc < 0)
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
100 return(rc);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
101 if (sim_resp_data_len < 14) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
102 fprintf(stderr,
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
103 "error: response length of %u bytes is too short for any file type\n",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
104 sim_resp_data_len);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
105 return(-1);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
106 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
107 switch (sim_resp_data[6]) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
108 case 0x01:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
109 printf("File type: MF\n");
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
110 goto mf_or_df;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
111 case 0x02:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
112 printf("File type: DF\n");
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
113 mf_or_df:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
114 if (sim_resp_data_len < 22) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
115 fprintf(stderr,
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
116 "error: response length of %u bytes is too short for MF/DF\n",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
117 sim_resp_data_len);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
118 return(-1);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
119 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
120 printf("File characteristics: %02X\n", sim_resp_data[13]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
121 printf("Number of DF children: %u\n", sim_resp_data[14]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
122 printf("Number of EF children: %u\n", sim_resp_data[15]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
123 printf("Number of secret codes: %u\n", sim_resp_data[16]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
124 show_secret_code_status("PIN1", sim_resp_data[18]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
125 show_secret_code_status("PUK1", sim_resp_data[19]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
126 show_secret_code_status("PIN2", sim_resp_data[20]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
127 show_secret_code_status("PUK2", sim_resp_data[21]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
128 break;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
129 case 0x04:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
130 printf("File type: EF\n");
89
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
131 file_size = (sim_resp_data[2] << 8) | sim_resp_data[3];
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
132 printf("File size: %u\n", file_size);
86
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
133 switch (sim_resp_data[13]) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
134 case 0x00:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
135 printf("Structure: transparent\n");
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
136 break;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
137 case 0x01:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
138 printf("Structure: linear fixed\n");
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
139 goto ef_record_based;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
140 case 0x03:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
141 printf("Structure: cyclic\n");
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
142 ef_record_based:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
143 if (sim_resp_data_len < 15) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
144 fprintf(stderr,
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
145 "error: response length of %u bytes is too short for record-based EF\n",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
146 sim_resp_data_len);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
147 return(-1);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
148 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
149 printf("Record length: %u\n", sim_resp_data[14]);
89
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
150 curfile_record_len = sim_resp_data[14];
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
151 if (file_size % curfile_record_len == 0)
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
152 printf("Number of records: %u\n",
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
153 file_size / curfile_record_len);
86
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
154 break;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
155 default:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
156 printf("Structure: %02X (unknown)\n",
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
157 sim_resp_data[13]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
158 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
159 printf("File status: %02X\n", sim_resp_data[11]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
160 show_access_conditions("UPDATE", sim_resp_data[8] & 0xF);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
161 show_access_conditions("READ & SEEK", sim_resp_data[8] >> 4);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
162 show_access_conditions("INCREASE", sim_resp_data[9] >> 4);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
163 show_access_conditions("INVALIDATE", sim_resp_data[10] & 0xF);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
164 show_access_conditions("REHABILITATE", sim_resp_data[10] >> 4);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
165 break;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
166 default:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
167 printf("File type: %02X (unknown)\n", sim_resp_data[6]);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
168 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
169 return(0);
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
170 }