FreeCalypso > hg > freecalypso-hwlab
comparison uicc/select.c @ 138:baf5bd698764
fc-uicc-tool: select-aid command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 04 Feb 2021 04:51:08 +0000 |
parents | 51d6aaa43a7b |
children | 6c6e8705dc70 |
comparison
equal
deleted
inserted
replaced
137:c331560c15a4 | 138:baf5bd698764 |
---|---|
28 return(rc); | 28 return(rc); |
29 if ((sim_resp_sw & 0xFF00) != 0x6100) { | 29 if ((sim_resp_sw & 0xFF00) != 0x6100) { |
30 fprintf(stderr, | 30 fprintf(stderr, |
31 "error or unexpected SW response to SELECT of 0x%04X: %04X\n", | 31 "error or unexpected SW response to SELECT of 0x%04X: %04X\n", |
32 file_id, sim_resp_sw); | 32 file_id, sim_resp_sw); |
33 return(-1); | |
34 } | |
35 expect_resp_len = sim_resp_sw & 0xFF; | |
36 /* GET RESPONSE follow-up */ | |
37 cmd[1] = 0xC0; | |
38 cmd[2] = 0; | |
39 cmd[3] = 0; | |
40 cmd[4] = expect_resp_len; | |
41 rc = apdu_exchange(cmd, 5); | |
42 if (rc < 0) | |
43 return(rc); | |
44 if (sim_resp_sw != 0x9000) { | |
45 fprintf(stderr, | |
46 "bad SW resp to GET RESPONSE after SELECT: %04X\n", | |
47 sim_resp_sw); | |
48 return(-1); | |
49 } | |
50 if (sim_resp_data_len != expect_resp_len) { | |
51 fprintf(stderr, | |
52 "error: GET RESPONSE after SELECT returned %u bytes, expected %u\n", | |
53 sim_resp_data_len, expect_resp_len); | |
54 return(-1); | |
55 } | |
56 return(0); | |
57 } | |
58 | |
59 select_aid_op(aid, aid_len) | |
60 u_char *aid; | |
61 unsigned aid_len; | |
62 { | |
63 u_char cmd[21]; | |
64 int rc; | |
65 unsigned expect_resp_len; | |
66 | |
67 /* SELECT command APDU */ | |
68 cmd[0] = 0x00; | |
69 cmd[1] = 0xA4; | |
70 cmd[2] = 0x04; | |
71 cmd[3] = 0x04; | |
72 cmd[4] = aid_len; | |
73 bcopy(aid, cmd + 5, aid_len); | |
74 rc = apdu_exchange(cmd, aid_len + 5); | |
75 if (rc < 0) | |
76 return(rc); | |
77 if ((sim_resp_sw & 0xFF00) != 0x6100) { | |
78 fprintf(stderr, | |
79 "error or unexpected SW response to SELECT by AID: %04X\n", | |
80 sim_resp_sw); | |
33 return(-1); | 81 return(-1); |
34 } | 82 } |
35 expect_resp_len = sim_resp_sw & 0xFF; | 83 expect_resp_len = sim_resp_sw & 0xFF; |
36 /* GET RESPONSE follow-up */ | 84 /* GET RESPONSE follow-up */ |
37 cmd[1] = 0xC0; | 85 cmd[1] = 0xC0; |
150 if (rc < 0) | 198 if (rc < 0) |
151 return(rc); | 199 return(rc); |
152 return parse_and_display_select_response(); | 200 return parse_and_display_select_response(); |
153 } | 201 } |
154 | 202 |
203 cmd_select_aid(argc, argv) | |
204 char **argv; | |
205 { | |
206 u_char aid[16]; | |
207 unsigned aid_len; | |
208 int rc; | |
209 | |
210 rc = decode_hex_data_from_string(argv[1], aid, 16); | |
211 if (rc < 0) | |
212 return(rc); | |
213 aid_len = rc; | |
214 rc = select_aid_op(aid, aid_len); | |
215 if (rc < 0) | |
216 return(rc); | |
217 return parse_and_display_select_response(); | |
218 } | |
219 | |
155 u_char * | 220 u_char * |
156 extract_select_resp_tag(sought_tag) | 221 extract_select_resp_tag(sought_tag) |
157 unsigned sought_tag; | 222 unsigned sought_tag; |
158 { | 223 { |
159 unsigned offset, totlen, reclen; | 224 unsigned offset, totlen, reclen; |