FreeCalypso > hg > fc-sim-tools
annotate uicc/select.c @ 93:6041c601304d
fcsim1-mkprov: revert OTA key addition
It appears that GrcardSIM2 cards (which is what we got for FCSIM1)
do not support OTA after all, contrary to what we were previously
led to believe by some tech support emails from Grcard - apparently
those support emails and OTA descriptions referred to some other
card model(s).
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 21 Apr 2021 05:38:39 +0000 |
parents | db131929ee96 |
children |
rev | line source |
---|---|
15
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <ctype.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <string.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <strings.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdio.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdlib.h> |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include "simresp.h" |
87
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
8 #include "efstruct.h" |
15
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 u_char std_aid_usim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02}; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 u_char std_aid_isim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x04}; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 unsigned last_sel_file_record_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 elem_select_op(file_id) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 unsigned file_id; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 u_char cmd[7]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 last_sel_file_record_len = 0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 /* SELECT command APDU */ |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 cmd[0] = 0x00; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 cmd[1] = 0xA4; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 cmd[2] = 0x00; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 cmd[3] = 0x04; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 cmd[4] = 2; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 cmd[5] = file_id >> 8; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 cmd[6] = file_id; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return apdu_exchange(cmd, 7); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 select_op(file_id) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 unsigned file_id; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 u_char cmd[7]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 unsigned expect_resp_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 last_sel_file_record_len = 0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 /* SELECT command APDU */ |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 cmd[0] = 0x00; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 cmd[1] = 0xA4; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 cmd[2] = 0x00; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 cmd[3] = 0x04; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 cmd[4] = 2; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 cmd[5] = file_id >> 8; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 cmd[6] = file_id; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rc = apdu_exchange(cmd, 7); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if ((sim_resp_sw & 0xFF00) != 0x6100) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 "error or unexpected SW response to SELECT of 0x%04X: %04X\n", |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 file_id, sim_resp_sw); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 expect_resp_len = sim_resp_sw & 0xFF; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 /* GET RESPONSE follow-up */ |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 cmd[1] = 0xC0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 cmd[2] = 0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 cmd[3] = 0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 cmd[4] = expect_resp_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 rc = apdu_exchange(cmd, 5); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 if (sim_resp_sw != 0x9000) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 "bad SW resp to GET RESPONSE after SELECT: %04X\n", |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 sim_resp_sw); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (sim_resp_data_len != expect_resp_len) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 "error: GET RESPONSE after SELECT returned %u bytes, expected %u\n", |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 sim_resp_data_len, expect_resp_len); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 select_aid_op(aid, aid_len) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 u_char *aid; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 unsigned aid_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 u_char cmd[21]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 unsigned expect_resp_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 last_sel_file_record_len = 0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 /* SELECT command APDU */ |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 cmd[0] = 0x00; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 cmd[1] = 0xA4; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 cmd[2] = 0x04; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 cmd[3] = 0x04; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 cmd[4] = aid_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 bcopy(aid, cmd + 5, aid_len); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
98 rc = apdu_exchange(cmd, aid_len + 5); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
100 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
101 if ((sim_resp_sw & 0xFF00) != 0x6100) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
103 "error or unexpected SW response to SELECT by AID: %04X\n", |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 sim_resp_sw); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
105 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
106 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
107 expect_resp_len = sim_resp_sw & 0xFF; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 /* GET RESPONSE follow-up */ |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
109 cmd[1] = 0xC0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 cmd[2] = 0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 cmd[3] = 0; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 cmd[4] = expect_resp_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 rc = apdu_exchange(cmd, 5); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
114 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
116 if (sim_resp_sw != 0x9000) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 "bad SW resp to GET RESPONSE after SELECT: %04X\n", |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 sim_resp_sw); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
122 if (sim_resp_data_len != expect_resp_len) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
123 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
124 "error: GET RESPONSE after SELECT returned %u bytes, expected %u\n", |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
125 sim_resp_data_len, expect_resp_len); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
126 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
127 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
128 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
129 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
130 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
131 select_resp_header_check(ret_offset, ret_length) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
132 unsigned *ret_offset, *ret_length; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
133 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
134 unsigned offset, len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
135 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
136 if (sim_resp_data_len < 2) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
137 tooshort: fprintf(stderr, "error: SELECT response is too short\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
138 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
139 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
140 if (sim_resp_data[0] != 0x62) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
141 fprintf(stderr, "error: SELECT response first byte != 0x62\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
142 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
143 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
144 len = sim_resp_data[1]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
145 if (len <= 0x7F) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
146 offset = 2; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
147 return_check: if (offset + len > sim_resp_data_len) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
148 goto tooshort; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
149 if (ret_offset) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
150 *ret_offset = offset; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
151 if (ret_length) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
152 *ret_length = len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
153 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
154 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
155 if (len != 0x81) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
156 fprintf(stderr, "SELECT response: first length byte is bad\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
157 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
158 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
159 if (sim_resp_data_len < 3) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
160 goto tooshort; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
161 len = sim_resp_data[2]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
162 offset = 3; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
163 goto return_check; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
164 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
165 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
166 static void |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
167 check_for_record_struct(tlv) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
168 u_char *tlv; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
169 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
170 unsigned reclen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
171 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
172 if (tlv[1] != 5) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
173 return; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
174 if (tlv[2] & 0x80) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
175 return; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
176 if ((tlv[2] & 0x38) == 0x38) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
177 return; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
178 if ((tlv[2] & 0x03) != 0x02) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
179 return; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
180 reclen = (tlv[4] << 8) | tlv[5]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
181 if (reclen < 1 || reclen > 255) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
182 return; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
183 last_sel_file_record_len = reclen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
184 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
185 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
186 parse_and_display_select_response(outf) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
187 FILE *outf; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
188 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
189 unsigned offset, totlen, reclen, n; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
190 u_char *dp, *endp; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
191 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
192 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
193 rc = select_resp_header_check(&offset, &totlen); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
194 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
195 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
196 dp = sim_resp_data + offset; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
197 endp = sim_resp_data + offset + totlen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
198 while (dp < endp) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
199 if (endp - dp < 2) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
200 trunc_error: fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
201 "error: truncated TLV record in SELECT response\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
202 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
203 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
204 if ((dp[0] & 0x1F) == 0x1F) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
205 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
206 "error: extended tag not supported in SELECT response\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
207 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
208 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
209 if (dp[1] & 0x80) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
210 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
211 "error: extended length not supported in SELECT response\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
212 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
213 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
214 reclen = dp[1] + 2; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
215 if (endp - dp < reclen) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
216 goto trunc_error; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
217 if (dp[0] == 0x82) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
218 check_for_record_struct(dp); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
219 for (n = 0; n < reclen; n++) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
220 if (n) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
221 putc(' ', outf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
222 fprintf(outf, "%02X", *dp++); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
223 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
224 putc('\n', outf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
225 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
226 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
227 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
228 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
229 cmd_select(argc, argv, outf) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
230 char **argv; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
231 FILE *outf; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
232 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
233 int file_id, rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
234 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
235 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
236 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
237 file_id = strtoul(argv[1], 0, 16); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
238 else |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
239 file_id = find_symbolic_file_name(argv[1]); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
240 if (file_id < 0) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
241 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
242 "error: file ID argument is not a hex value or a recognized symbolic name\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
243 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
244 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
245 rc = select_op(file_id); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
246 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
247 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
248 return parse_and_display_select_response(outf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
249 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
250 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
251 cmd_select_aid(argc, argv, outf) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
252 char **argv; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
253 FILE *outf; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
254 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
255 u_char aid[16]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
256 unsigned aid_len; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
257 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
258 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
259 rc = decode_hex_data_from_string(argv[1], aid, 1, 16); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
260 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
261 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
262 aid_len = rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
263 rc = select_aid_op(aid, aid_len); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
264 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
265 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
266 return parse_and_display_select_response(outf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
267 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
268 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
269 cmd_select_usim(argc, argv, outf) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
270 char **argv; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
271 FILE *outf; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
272 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
273 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
274 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
275 rc = select_aid_op(std_aid_usim, 7); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
276 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
277 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
278 return parse_and_display_select_response(outf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
279 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
280 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
281 cmd_select_isim(argc, argv, outf) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
282 char **argv; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
283 FILE *outf; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
284 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
285 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
286 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
287 rc = select_aid_op(std_aid_isim, 7); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
288 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
289 return(rc); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
290 return parse_and_display_select_response(outf); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
291 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
292 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
293 u_char * |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
294 extract_select_resp_tag(sought_tag) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
295 unsigned sought_tag; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
296 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
297 unsigned offset, totlen, reclen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
298 u_char *dp, *endp; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
299 int rc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
300 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
301 rc = select_resp_header_check(&offset, &totlen); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
302 if (rc < 0) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
303 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
304 dp = sim_resp_data + offset; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
305 endp = sim_resp_data + offset + totlen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
306 while (dp < endp) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
307 if (endp - dp < 2) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
308 trunc_error: fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
309 "error: truncated TLV record in SELECT response\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
310 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
311 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
312 if ((dp[0] & 0x1F) == 0x1F) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
313 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
314 "error: extended tag not supported in SELECT response\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
315 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
316 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
317 if (dp[1] & 0x80) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
318 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
319 "error: extended length not supported in SELECT response\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
320 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
321 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
322 reclen = dp[1] + 2; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
323 if (endp - dp < reclen) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
324 goto trunc_error; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
325 if (dp[0] == sought_tag) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
326 return(dp); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
327 dp += reclen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
328 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
329 fprintf(stderr, "error: tag 0x%02X not found in SELECT response\n", |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
330 sought_tag); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
331 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
332 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
333 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
334 select_resp_get_transparent(lenp) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
335 unsigned *lenp; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
336 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
337 u_char *tlv; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
338 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
339 tlv = extract_select_resp_tag(0x82); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
340 if (!tlv) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
341 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
342 if (tlv[1] != 2) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
343 bad_file_desc: fprintf(stderr, "error: file type is not transparent EF\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
344 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
345 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
346 if (tlv[2] & 0x80) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
347 goto bad_file_desc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
348 if ((tlv[2] & 0x38) == 0x38) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
349 goto bad_file_desc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
350 if ((tlv[2] & 0x07) != 0x01) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
351 goto bad_file_desc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
352 tlv = extract_select_resp_tag(0x80); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
353 if (!tlv) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
354 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
355 if (tlv[1] != 2) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
356 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
357 "error: file size TLV element has wrong length\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
358 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
359 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
360 if (lenp) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
361 *lenp = (tlv[2] << 8) | tlv[3]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
362 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
363 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
364 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
365 select_resp_get_linear_fixed(rec_len_ret, rec_count_ret) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
366 unsigned *rec_len_ret, *rec_count_ret; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
367 { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
368 u_char *tlv; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
369 unsigned reclen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
370 |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
371 tlv = extract_select_resp_tag(0x82); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
372 if (!tlv) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
373 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
374 if (tlv[1] != 5) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
375 bad_file_desc: fprintf(stderr, "error: file type is not linear fixed EF\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
376 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
377 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
378 if (tlv[2] & 0x80) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
379 goto bad_file_desc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
380 if ((tlv[2] & 0x38) == 0x38) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
381 goto bad_file_desc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
382 if ((tlv[2] & 0x07) != 0x02) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
383 goto bad_file_desc; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
384 reclen = (tlv[4] << 8) | tlv[5]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
385 if (reclen < 1 || reclen > 255) { |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
386 fprintf(stderr, |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
387 "error: SELECT response gives invalid record length\n"); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
388 return(-1); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
389 } |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
390 if (rec_len_ret) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
391 *rec_len_ret = reclen; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
392 if (rec_count_ret) |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
393 *rec_count_ret = tlv[6]; |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
394 return(0); |
b70d35f5476f
fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
395 } |
87
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
396 |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
397 select_resp_get_ef_struct(efs) |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
398 struct ef_struct *efs; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
399 { |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
400 u_char *tlv; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
401 |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
402 tlv = extract_select_resp_tag(0x82); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
403 if (!tlv) |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
404 return(-1); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
405 if (tlv[1] < 2) { |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
406 bad_file_desc: fprintf(stderr, "error: unable to figure out file structure\n"); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
407 return(-1); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
408 } |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
409 if (tlv[2] & 0x80) |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
410 goto bad_file_desc; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
411 if ((tlv[2] & 0x38) == 0x38) |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
412 goto bad_file_desc; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
413 efs->structure = tlv[2] & 0x07; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
414 switch (efs->structure) { |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
415 case 0x01: |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
416 if (tlv[1] != 2) { |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
417 fprintf(stderr, |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
418 "error: file descriptor TLV element has wrong length\n"); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
419 return(-1); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
420 } |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
421 tlv = extract_select_resp_tag(0x80); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
422 if (!tlv) |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
423 return(-1); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
424 if (tlv[1] != 2) { |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
425 fprintf(stderr, |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
426 "error: file size TLV element has wrong length\n"); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
427 return(-1); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
428 } |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
429 efs->total_size = (tlv[2] << 8) | tlv[3]; |
89
db131929ee96
fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
430 if (efs->total_size > 0x8000) { |
db131929ee96
fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
431 fprintf(stderr, |
db131929ee96
fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
432 "error: transparent file size exceeds UICC protocol limit\n"); |
db131929ee96
fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
433 return(-1); |
db131929ee96
fc-uicc-tool: extended readef ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
87
diff
changeset
|
434 } |
87
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
435 return(0); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
436 case 0x02: |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
437 case 0x06: |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
438 if (tlv[1] != 5) { |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
439 fprintf(stderr, |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
440 "error: file descriptor TLV element has wrong length\n"); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
441 return(-1); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
442 } |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
443 efs->record_len = (tlv[4] << 8) | tlv[5]; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
444 if (efs->record_len < 1 || efs->record_len > 255) { |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
445 fprintf(stderr, |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
446 "error: SELECT response gives invalid record length\n"); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
447 return(-1); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
448 } |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
449 efs->record_count = tlv[6]; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
450 efs->total_size = efs->record_len * efs->record_count; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
451 return(0); |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
452 default: |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
453 goto bad_file_desc; |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
454 } |
0e46bbb801e0
fc-uicc-tool: internal code in preparation for porting
Mychaela Falconia <falcon@freecalypso.org>
parents:
15
diff
changeset
|
455 } |