annotate uicc/select.c @ 132:5af88fa11b54

fc-uicc-tool: SELECT response parsing implemented (basic)
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 04 Feb 2021 01:36:54 +0000
parents d0929cb42e1c
children 69628bcfec17
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
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 select_op(file_id)
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 unsigned file_id;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 {
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_char cmd[7];
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int rc;
131
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
16 unsigned expect_resp_len;
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 /* SELECT command APDU */
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 cmd[0] = 0x00;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 cmd[1] = 0xA4;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 cmd[2] = 0x00;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 cmd[3] = 0x04;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 cmd[4] = 2;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 cmd[5] = file_id >> 8;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 cmd[6] = file_id;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 rc = apdu_exchange(cmd, 7);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (rc < 0)
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 return(rc);
131
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
29 if ((sim_resp_sw & 0xFF00) != 0x6100) {
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
30 fprintf(stderr,
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
31 "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
32 file_id, sim_resp_sw);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
33 return(-1);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
34 }
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
35 expect_resp_len = sim_resp_sw & 0xFF;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
36 /* GET RESPONSE follow-up */
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
37 cmd[1] = 0xC0;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
38 cmd[2] = 0;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
39 cmd[3] = 0;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
40 cmd[4] = expect_resp_len;
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
41 rc = apdu_exchange(cmd, 5);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
42 if (rc < 0)
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
43 return(rc);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
44 if (sim_resp_sw != 0x9000) {
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
45 fprintf(stderr,
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
46 "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
47 sim_resp_sw);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
48 return(-1);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
49 }
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
50 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
51 fprintf(stderr,
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
52 "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
53 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 return(-1);
d0929cb42e1c fc-uicc-tool: GET RESPONSE after SELECT
Mychaela Falconia <falcon@freecalypso.org>
parents: 130
diff changeset
55 }
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 return(0);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 }
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
132
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
59 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
60 unsigned *ret_offset, *ret_length;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
61 {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
62 unsigned offset, len;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
63
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
64 if (sim_resp_data_len < 2) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
65 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
66 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
67 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
68 if (sim_resp_data[0] != 0x62) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
69 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
70 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
71 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
72 len = sim_resp_data[1];
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
73 if (len <= 0x7F) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
74 offset = 2;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
75 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
76 goto tooshort;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
77 if (ret_offset)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
78 *ret_offset = offset;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
79 if (ret_length)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
80 *ret_length = len;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
81 return(0);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
82 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
83 if (len != 0x81) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
84 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
85 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
86 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
87 if (sim_resp_data_len < 3)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
88 goto tooshort;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
89 len = sim_resp_data[2];
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
90 offset = 3;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
91 goto return_check;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
92 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
93
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
94 parse_and_display_select_response()
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
95 {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
96 unsigned offset, totlen, reclen, n;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
97 u_char *dp, *endp;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
98 int rc;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
99
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
100 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
101 if (rc < 0)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
102 return(rc);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
103 dp = sim_resp_data + offset;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
104 endp = sim_resp_data + offset + totlen;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
105 while (dp < endp) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
106 if (endp - dp < 2) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
107 trunc_error: fprintf(stderr,
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
108 "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
109 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
110 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
111 if ((dp[0] & 0x1F) == 0x1F) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
112 fprintf(stderr,
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
113 "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
114 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
115 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
116 if (dp[1] & 0x80) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
117 fprintf(stderr,
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
118 "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
119 return(-1);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
120 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
121 reclen = dp[1] + 2;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
122 if (endp - dp < reclen)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
123 goto trunc_error;
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
124 for (n = 0; n < reclen; n++) {
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
125 if (n)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
126 putchar(' ');
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
127 printf("%02X", *dp++);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
128 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
129 putchar('\n');
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
130 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
131 return(0);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
132 }
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
133
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
134 cmd_select(argc, argv)
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
135 char **argv;
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
136 {
132
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
137 int file_id, rc;
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
138
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
139 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) &&
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
140 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
141 file_id = strtoul(argv[1], 0, 16);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
142 else
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
143 file_id = find_symbolic_file_name(argv[1]);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
144 if (file_id < 0) {
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
145 fprintf(stderr,
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
146 "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
147 return(-1);
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
148 }
132
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
149 rc = select_op(file_id);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
150 if (rc < 0)
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
151 return(rc);
5af88fa11b54 fc-uicc-tool: SELECT response parsing implemented (basic)
Mychaela Falconia <falcon@freecalypso.org>
parents: 131
diff changeset
152 return parse_and_display_select_response();
130
f691a19f191d fc-uicc-tool skeleton started
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
153 }