annotate simtool/select.c @ 95:5f826e428641

fc-simtool: readef command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jan 2021 20:47:00 +0000
parents b84df973cd8b
children
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
95
5f826e428641 fc-simtool: readef command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 94
diff changeset
67 void
86
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;
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
87 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 file_id = strtoul(argv[1], 0, 16);
87
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
90 else
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
91 file_id = find_symbolic_file_name(argv[1]);
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
92 if (file_id < 0) {
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 fprintf(stderr,
87
2a0d1d5b9313 fc-simtool: symbolic file names implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 86
diff changeset
94 "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
95 return(-1);
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
96 }
86
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
97 rc = select_op(file_id);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
98 if (rc < 0)
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
99 return(rc);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
100 if (sim_resp_data_len < 14) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
101 fprintf(stderr,
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
102 "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
103 sim_resp_data_len);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
104 return(-1);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
105 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
106 switch (sim_resp_data[6]) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
107 case 0x01:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
108 printf("File type: MF\n");
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
109 goto mf_or_df;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
110 case 0x02:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
111 printf("File type: DF\n");
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
112 mf_or_df:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
113 if (sim_resp_data_len < 22) {
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
114 fprintf(stderr,
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
115 "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
116 sim_resp_data_len);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
117 return(-1);
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
118 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
119 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
120 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
121 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
122 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
123 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
124 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
125 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
126 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
127 break;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
128 case 0x04:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
129 printf("File type: EF\n");
93
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
130 curfile_total_size = (sim_resp_data[2] << 8) | sim_resp_data[3];
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
131 printf("File size: %u\n", curfile_total_size);
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
132 curfile_structure = sim_resp_data[13];
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
133 switch (curfile_structure) {
86
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];
93
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
151 if (curfile_record_len &&
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
152 curfile_total_size % curfile_record_len == 0) {
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
153 curfile_record_count =
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
154 curfile_total_size / curfile_record_len;
89
fb75855a74a9 fc-simtool: select response parsing: show number of records
Mychaela Falconia <falcon@freecalypso.org>
parents: 87
diff changeset
155 printf("Number of records: %u\n",
93
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
156 curfile_record_count);
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
157 } else
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
158 curfile_record_count = 0;
86
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
159 break;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
160 default:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
161 printf("Structure: %02X (unknown)\n",
93
d4150123ca45 fc-simtool: some refactoring of SELECT response parsing
Mychaela Falconia <falcon@freecalypso.org>
parents: 89
diff changeset
162 curfile_structure);
86
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
163 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
164 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
165 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
166 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
167 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
168 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
169 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
170 break;
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
171 default:
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
172 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
173 }
54c444eb084b fc-simtool: SELECT response decoding implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 85
diff changeset
174 return(0);
85
b57cf64ece29 fc-simtool project started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
175 }
94
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
176
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
177 parse_ef_select_response()
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
178 {
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
179 if (sim_resp_data_len < 14) {
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
180 fprintf(stderr,
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
181 "error: SELECT response length of %u bytes is too short\n",
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
182 sim_resp_data_len);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
183 return(-1);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
184 }
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
185 if (sim_resp_data[6] != 0x04) {
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
186 fprintf(stderr, "error: selected file is not an EF\n");
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
187 return(-1);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
188 }
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
189 curfile_total_size = (sim_resp_data[2] << 8) | sim_resp_data[3];
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
190 curfile_structure = sim_resp_data[13];
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
191 switch (curfile_structure) {
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
192 case 0x00:
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
193 /* transparent */
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
194 break;
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
195 case 0x01:
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
196 case 0x03:
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
197 /* record-based */
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
198 if (sim_resp_data_len < 15) {
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
199 fprintf(stderr,
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
200 "error: SELECT response length of %u bytes is too short for record-based EF\n",
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
201 sim_resp_data_len);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
202 return(-1);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
203 }
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
204 curfile_record_len = sim_resp_data[14];
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
205 if (!curfile_record_len) {
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
206 fprintf(stderr,
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
207 "error: SELECT response indicates record length of 0\n");
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
208 return(-1);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
209 }
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
210 if (curfile_total_size % curfile_record_len) {
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
211 fprintf(stderr,
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
212 "error: returned file size is not divisible by record length\n");
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
213 return(-1);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
214 }
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
215 curfile_record_count = curfile_total_size / curfile_record_len;
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
216 break;
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
217 default:
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
218 fprintf(stderr, "error: unknown EF structure code %02X\n",
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
219 curfile_structure);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
220 return(-1);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
221 }
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
222 return(0);
b84df973cd8b fc-simtool: parse_ef_select_response() function added
Mychaela Falconia <falcon@freecalypso.org>
parents: 93
diff changeset
223 }