annotate uicc/select.c @ 139:6c6e8705dc70

fc-uicc-tool: select-usim and select-isim implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Feb 2021 05:00:12 +0000
parents baf5bd698764
children 429a8f80426e
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <ctype.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <string.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <strings.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <stdio.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdlib.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <pcsclite.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <winscard.h>
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include "globals.h"
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10
139
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
11 u_char std_aid_usim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x02};
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
12 u_char std_aid_isim[7] = {0xA0, 0x00, 0x00, 0x00, 0x87, 0x10, 0x04};
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
13
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 select_op(file_id)
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 unsigned file_id;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char cmd[7];
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 int rc;
131
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
19 unsigned expect_resp_len;
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 /* SELECT command APDU */
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 cmd[0] = 0x00;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cmd[1] = 0xA4;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cmd[2] = 0x00;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd[3] = 0x04;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 cmd[4] = 2;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 cmd[5] = file_id >> 8;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 cmd[6] = file_id;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 rc = apdu_exchange(cmd, 7);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 if (rc < 0)
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 return(rc);
131
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
32 if ((sim_resp_sw & 0xFF00) != 0x6100) {
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
33 fprintf(stderr,
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
34 "error or unexpected SW response to SELECT of 0x%04X: %04X\n",
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
35 file_id, sim_resp_sw);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
36 return(-1);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
37 }
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
38 expect_resp_len = sim_resp_sw & 0xFF;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
39 /* GET RESPONSE follow-up */
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
40 cmd[1] = 0xC0;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
41 cmd[2] = 0;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
42 cmd[3] = 0;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
43 cmd[4] = expect_resp_len;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
44 rc = apdu_exchange(cmd, 5);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
45 if (rc < 0)
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
46 return(rc);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
47 if (sim_resp_sw != 0x9000) {
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
48 fprintf(stderr,
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
49 "bad SW resp to GET RESPONSE after SELECT: %04X\n",
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
50 sim_resp_sw);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
51 return(-1);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
52 }
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
53 if (sim_resp_data_len != expect_resp_len) {
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
54 fprintf(stderr,
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
55 "error: GET RESPONSE after SELECT returned %u bytes, expected %u\n",
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
56 sim_resp_data_len, expect_resp_len);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
57 return(-1);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
58 }
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 return(0);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 }
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61
138
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
62 select_aid_op(aid, aid_len)
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
63 u_char *aid;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
64 unsigned aid_len;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
65 {
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
66 u_char cmd[21];
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
67 int rc;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
68 unsigned expect_resp_len;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
69
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
70 /* SELECT command APDU */
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
71 cmd[0] = 0x00;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
72 cmd[1] = 0xA4;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
73 cmd[2] = 0x04;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
74 cmd[3] = 0x04;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
75 cmd[4] = aid_len;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
76 bcopy(aid, cmd + 5, aid_len);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
77 rc = apdu_exchange(cmd, aid_len + 5);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
78 if (rc < 0)
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
79 return(rc);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
80 if ((sim_resp_sw & 0xFF00) != 0x6100) {
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
81 fprintf(stderr,
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
82 "error or unexpected SW response to SELECT by AID: %04X\n",
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
83 sim_resp_sw);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
84 return(-1);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
85 }
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
86 expect_resp_len = sim_resp_sw & 0xFF;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
87 /* GET RESPONSE follow-up */
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
88 cmd[1] = 0xC0;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
89 cmd[2] = 0;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
90 cmd[3] = 0;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
91 cmd[4] = expect_resp_len;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
92 rc = apdu_exchange(cmd, 5);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
93 if (rc < 0)
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
94 return(rc);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
95 if (sim_resp_sw != 0x9000) {
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
96 fprintf(stderr,
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
97 "bad SW resp to GET RESPONSE after SELECT: %04X\n",
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
98 sim_resp_sw);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
99 return(-1);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
100 }
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
101 if (sim_resp_data_len != expect_resp_len) {
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
102 fprintf(stderr,
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
103 "error: GET RESPONSE after SELECT returned %u bytes, expected %u\n",
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
104 sim_resp_data_len, expect_resp_len);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
105 return(-1);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
106 }
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
107 return(0);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
108 }
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
109
132
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
110 select_resp_header_check(ret_offset, ret_length)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
111 unsigned *ret_offset, *ret_length;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
112 {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
113 unsigned offset, len;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
114
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
115 if (sim_resp_data_len < 2) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
116 tooshort: fprintf(stderr, "error: SELECT response is too short\n");
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
117 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
118 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
119 if (sim_resp_data[0] != 0x62) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
120 fprintf(stderr, "error: SELECT response first byte != 0x62\n");
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
121 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
122 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
123 len = sim_resp_data[1];
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
124 if (len <= 0x7F) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
125 offset = 2;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
126 return_check: if (offset + len > sim_resp_data_len)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
127 goto tooshort;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
128 if (ret_offset)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
129 *ret_offset = offset;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
130 if (ret_length)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
131 *ret_length = len;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
132 return(0);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
133 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
134 if (len != 0x81) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
135 fprintf(stderr, "SELECT response: first length byte is bad\n");
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
136 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
137 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
138 if (sim_resp_data_len < 3)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
139 goto tooshort;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
140 len = sim_resp_data[2];
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
141 offset = 3;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
142 goto return_check;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
143 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
144
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
145 parse_and_display_select_response()
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
146 {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
147 unsigned offset, totlen, reclen, n;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
148 u_char *dp, *endp;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
149 int rc;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
150
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
151 rc = select_resp_header_check(&offset, &totlen);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
152 if (rc < 0)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
153 return(rc);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
154 dp = sim_resp_data + offset;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
155 endp = sim_resp_data + offset + totlen;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
156 while (dp < endp) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
157 if (endp - dp < 2) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
158 trunc_error: fprintf(stderr,
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
159 "error: truncated TLV record in SELECT response\n");
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
160 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
161 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
162 if ((dp[0] & 0x1F) == 0x1F) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
163 fprintf(stderr,
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
164 "error: extended tag not supported in SELECT response\n");
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
165 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
166 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
167 if (dp[1] & 0x80) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
168 fprintf(stderr,
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
169 "error: extended length not supported in SELECT response\n");
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
170 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
171 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
172 reclen = dp[1] + 2;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
173 if (endp - dp < reclen)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
174 goto trunc_error;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
175 for (n = 0; n < reclen; n++) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
176 if (n)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
177 putchar(' ');
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
178 printf("%02X", *dp++);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
179 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
180 putchar('\n');
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
181 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
182 return(0);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
183 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
184
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
185 cmd_select(argc, argv)
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
186 char **argv;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
187 {
132
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
188 int file_id, rc;
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
189
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
190 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
191 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4])
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
192 file_id = strtoul(argv[1], 0, 16);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
193 else
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
194 file_id = find_symbolic_file_name(argv[1]);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
195 if (file_id < 0) {
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
196 fprintf(stderr,
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
197 "error: file ID argument is not a hex value or a recognized symbolic name\n");
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
198 return(-1);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
199 }
132
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
200 rc = select_op(file_id);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
201 if (rc < 0)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
202 return(rc);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
203 return parse_and_display_select_response();
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
204 }
134
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
205
138
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
206 cmd_select_aid(argc, argv)
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
207 char **argv;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
208 {
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
209 u_char aid[16];
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
210 unsigned aid_len;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
211 int rc;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
212
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
213 rc = decode_hex_data_from_string(argv[1], aid, 16);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
214 if (rc < 0)
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
215 return(rc);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
216 aid_len = rc;
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
217 rc = select_aid_op(aid, aid_len);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
218 if (rc < 0)
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
219 return(rc);
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
220 return parse_and_display_select_response();
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
221 }
baf5bd698764 fc-uicc-tool: select-aid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 135
diff changeset
222
139
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
223 cmd_select_usim()
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
224 {
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
225 int rc;
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
226
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
227 rc = select_aid_op(std_aid_usim, 7);
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
228 if (rc < 0)
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
229 return(rc);
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
230 return parse_and_display_select_response();
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
231 }
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
232
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
233 cmd_select_isim()
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
234 {
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
235 int rc;
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
236
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
237 rc = select_aid_op(std_aid_isim, 7);
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
238 if (rc < 0)
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
239 return(rc);
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
240 return parse_and_display_select_response();
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
241 }
6c6e8705dc70 fc-uicc-tool: select-usim and select-isim implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 138
diff changeset
242
134
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
243 u_char *
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
244 extract_select_resp_tag(sought_tag)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
245 unsigned sought_tag;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
246 {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
247 unsigned offset, totlen, reclen;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
248 u_char *dp, *endp;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
249 int rc;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
250
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
251 rc = select_resp_header_check(&offset, &totlen);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
252 if (rc < 0)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
253 return(0);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
254 dp = sim_resp_data + offset;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
255 endp = sim_resp_data + offset + totlen;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
256 while (dp < endp) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
257 if (endp - dp < 2) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
258 trunc_error: fprintf(stderr,
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
259 "error: truncated TLV record in SELECT response\n");
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
260 return(0);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
261 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
262 if ((dp[0] & 0x1F) == 0x1F) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
263 fprintf(stderr,
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
264 "error: extended tag not supported in SELECT response\n");
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
265 return(0);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
266 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
267 if (dp[1] & 0x80) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
268 fprintf(stderr,
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
269 "error: extended length not supported in SELECT response\n");
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
270 return(0);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
271 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
272 reclen = dp[1] + 2;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
273 if (endp - dp < reclen)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
274 goto trunc_error;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
275 if (dp[0] == sought_tag)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
276 return(dp);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
277 dp += reclen;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
278 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
279 fprintf(stderr, "error: tag 0x%02X not found in SELECT response\n",
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
280 sought_tag);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
281 return(0);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
282 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
283
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
284 select_resp_get_transparent(lenp)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
285 unsigned *lenp;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
286 {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
287 u_char *tlv;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
288
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
289 tlv = extract_select_resp_tag(0x82);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
290 if (!tlv)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
291 return(-1);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
292 if (tlv[1] != 2) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
293 bad_file_desc: fprintf(stderr, "error: file type is not transparent EF\n");
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
294 return(-1);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
295 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
296 if (tlv[2] & 0x80)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
297 goto bad_file_desc;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
298 if ((tlv[2] & 0x38) == 0x38)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
299 goto bad_file_desc;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
300 if ((tlv[2] & 0x07) != 0x01)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
301 goto bad_file_desc;
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
302 tlv = extract_select_resp_tag(0x80);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
303 if (!tlv)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
304 return(-1);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
305 if (tlv[1] != 2) {
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
306 fprintf(stderr,
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
307 "error: file size TLV element has wrong length\n");
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
308 return(-1);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
309 }
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
310 if (lenp)
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
311 *lenp = (tlv[2] << 8) | tlv[3];
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
312 return(0);
69628bcfec17 fc-uicc-tool: iccid command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 132
diff changeset
313 }
135
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
314
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
315 select_resp_get_linear_fixed(rec_len_ret, rec_count_ret)
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
316 unsigned *rec_len_ret, *rec_count_ret;
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
317 {
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
318 u_char *tlv;
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
319 unsigned reclen;
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
320
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
321 tlv = extract_select_resp_tag(0x82);
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
322 if (!tlv)
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
323 return(-1);
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
324 if (tlv[1] != 5) {
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
325 bad_file_desc: fprintf(stderr, "error: file type is not linear fixed EF\n");
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
326 return(-1);
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
327 }
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
328 if (tlv[2] & 0x80)
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
329 goto bad_file_desc;
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
330 if ((tlv[2] & 0x38) == 0x38)
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
331 goto bad_file_desc;
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
332 if ((tlv[2] & 0x07) != 0x02)
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
333 goto bad_file_desc;
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
334 reclen = (tlv[4] << 8) | tlv[5];
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
335 if (reclen < 1 || reclen > 255) {
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
336 fprintf(stderr,
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
337 "error: SELECT response gives invalid record length\n");
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
338 return(-1);
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
339 }
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
340 if (rec_len_ret)
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
341 *rec_len_ret = reclen;
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
342 if (rec_count_ret)
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
343 *rec_count_ret = tlv[6];
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
344 return(0);
51d6aaa43a7b fc-uicc-tool: telecom-sum command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 134
diff changeset
345 }