FreeCalypso > hg > freecalypso-hwlab
comparison simtool/select.c @ 86:54c444eb084b
fc-simtool: SELECT response decoding implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Sun, 24 Jan 2021 01:42:15 +0000 |
parents | b57cf64ece29 |
children | 2a0d1d5b9313 |
comparison
equal
deleted
inserted
replaced
85:b57cf64ece29 | 86:54c444eb084b |
---|---|
52 return(-1); | 52 return(-1); |
53 } | 53 } |
54 return(0); | 54 return(0); |
55 } | 55 } |
56 | 56 |
57 static void | |
58 show_secret_code_status(name, byte) | |
59 char *name; | |
60 unsigned byte; | |
61 { | |
62 printf("Status of %s: %s, %u attempts left\n", name, | |
63 byte & 0x80 ? "initialized" : "not initialized", | |
64 byte & 0x0F); | |
65 } | |
66 | |
67 static void | |
68 show_access_conditions(oper_name, cond_code) | |
69 char *oper_name; | |
70 unsigned cond_code; | |
71 { | |
72 static char *cond_names[16] = | |
73 {"ALW", "CHV1", "CHV2", "RFU3", | |
74 "ADM4", "ADM5", "ADM6", "ADM7", | |
75 "ADM8", "ADM9", "ADM10", "ADM11", | |
76 "ADM12", "ADM13", "ADM14", "NEV"}; | |
77 | |
78 printf("Access condition for %s: %s\n", oper_name, | |
79 cond_names[cond_code]); | |
80 } | |
81 | |
57 cmd_select(argc, argv) | 82 cmd_select(argc, argv) |
58 char **argv; | 83 char **argv; |
59 { | 84 { |
60 unsigned file_id; | 85 unsigned file_id; |
86 int rc; | |
61 | 87 |
62 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && | 88 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && |
63 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) | 89 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) |
64 file_id = strtoul(argv[1], 0, 16); | 90 file_id = strtoul(argv[1], 0, 16); |
65 else { | 91 else { |
66 fprintf(stderr, | 92 fprintf(stderr, |
67 "select: only hex file IDs are currently supported\n"); | 93 "select: only hex file IDs are currently supported\n"); |
68 return(-1); | 94 return(-1); |
69 } | 95 } |
70 return select_op(file_id); | 96 rc = select_op(file_id); |
97 if (rc < 0) | |
98 return(rc); | |
99 if (sim_resp_data_len < 14) { | |
100 fprintf(stderr, | |
101 "error: response length of %u bytes is too short for any file type\n", | |
102 sim_resp_data_len); | |
103 return(-1); | |
104 } | |
105 switch (sim_resp_data[6]) { | |
106 case 0x01: | |
107 printf("File type: MF\n"); | |
108 goto mf_or_df; | |
109 case 0x02: | |
110 printf("File type: DF\n"); | |
111 mf_or_df: | |
112 if (sim_resp_data_len < 22) { | |
113 fprintf(stderr, | |
114 "error: response length of %u bytes is too short for MF/DF\n", | |
115 sim_resp_data_len); | |
116 return(-1); | |
117 } | |
118 printf("File characteristics: %02X\n", sim_resp_data[13]); | |
119 printf("Number of DF children: %u\n", sim_resp_data[14]); | |
120 printf("Number of EF children: %u\n", sim_resp_data[15]); | |
121 printf("Number of secret codes: %u\n", sim_resp_data[16]); | |
122 show_secret_code_status("PIN1", sim_resp_data[18]); | |
123 show_secret_code_status("PUK1", sim_resp_data[19]); | |
124 show_secret_code_status("PIN2", sim_resp_data[20]); | |
125 show_secret_code_status("PUK2", sim_resp_data[21]); | |
126 break; | |
127 case 0x04: | |
128 printf("File type: EF\n"); | |
129 printf("File size: %u\n", | |
130 (sim_resp_data[2] << 8) | sim_resp_data[3]); | |
131 switch (sim_resp_data[13]) { | |
132 case 0x00: | |
133 printf("Structure: transparent\n"); | |
134 break; | |
135 case 0x01: | |
136 printf("Structure: linear fixed\n"); | |
137 goto ef_record_based; | |
138 case 0x03: | |
139 printf("Structure: cyclic\n"); | |
140 ef_record_based: | |
141 if (sim_resp_data_len < 15) { | |
142 fprintf(stderr, | |
143 "error: response length of %u bytes is too short for record-based EF\n", | |
144 sim_resp_data_len); | |
145 return(-1); | |
146 } | |
147 printf("Record length: %u\n", sim_resp_data[14]); | |
148 break; | |
149 default: | |
150 printf("Structure: %02X (unknown)\n", | |
151 sim_resp_data[13]); | |
152 } | |
153 printf("File status: %02X\n", sim_resp_data[11]); | |
154 show_access_conditions("UPDATE", sim_resp_data[8] & 0xF); | |
155 show_access_conditions("READ & SEEK", sim_resp_data[8] >> 4); | |
156 show_access_conditions("INCREASE", sim_resp_data[9] >> 4); | |
157 show_access_conditions("INVALIDATE", sim_resp_data[10] & 0xF); | |
158 show_access_conditions("REHABILITATE", sim_resp_data[10] >> 4); | |
159 break; | |
160 default: | |
161 printf("File type: %02X (unknown)\n", sim_resp_data[6]); | |
162 } | |
163 return(0); | |
71 } | 164 } |