annotate simtool/readops.c @ 98:66c0cb0e9876

fc-simtool: telecom-sum (summary info) command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 24 Jan 2021 22:46:41 +0000
parents 0ead9444a698
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
92
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 #include <sys/types.h>
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 #include <stdio.h>
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 #include <stdlib.h>
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 #include <pcsclite.h>
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <winscard.h>
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include "globals.h"
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 readbin_op(offset, len)
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 unsigned offset, len;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 {
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 u_char cmd[5];
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 int rc;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 /* READ BINARY command APDU */
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 cmd[0] = 0xA0;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 cmd[1] = 0xB0;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 cmd[2] = offset >> 8;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 cmd[3] = offset;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 cmd[4] = len;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 rc = apdu_exchange(cmd, 5);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 if (rc < 0)
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 return(rc);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (sim_resp_sw != 0x9000) {
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "bad SW response to READ BINARY: %04X\n",
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 sim_resp_sw);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 return(-1);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 }
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (sim_resp_data_len != len) {
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 fprintf(stderr,
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 "error: READ BINARY returned %u bytes, expected %u\n",
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 sim_resp_data_len, len);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 return(-1);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 }
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 return(0);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 }
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 readrec_op(recno, mode, len)
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 unsigned recno, mode, len;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 {
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 u_char cmd[5];
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 int rc;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 /* READ RECORD command APDU */
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 cmd[0] = 0xA0;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 cmd[1] = 0xB2;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 cmd[2] = recno;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 cmd[3] = mode;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 cmd[4] = len;
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 rc = apdu_exchange(cmd, 5);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 if (rc < 0)
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 return(rc);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (sim_resp_sw != 0x9000) {
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr, "bad SW response to READ RECORD: %04X\n",
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 sim_resp_sw);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 return(-1);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 }
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 if (sim_resp_data_len != len) {
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 fprintf(stderr,
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 "error: READ RECORD returned %u bytes, expected %u\n",
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 sim_resp_data_len, len);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 return(-1);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 }
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 return(0);
0ead9444a698 fc-simtool: read operation functions factored out
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 }