comparison simtool/readops.c @ 92:0ead9444a698

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