FreeCalypso > hg > freecalypso-hwlab
annotate simtool/writeops.c @ 115:0dcd666292e4
fc-simtool: pb-erase-one command implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Thu, 28 Jan 2021 02:56:10 +0000 |
parents | fa7005185b84 |
children |
rev | line source |
---|---|
100
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 #include <sys/types.h> |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 #include <string.h> |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 #include <strings.h> |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 #include <stdio.h> |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <stdlib.h> |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <pcsclite.h> |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <winscard.h> |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include "globals.h" |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 update_bin_op(offset, data, len) |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 unsigned offset, len; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 u_char *data; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 { |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 u_char cmd[260]; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 int rc; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 /* UPDATE BINARY command APDU */ |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 cmd[0] = 0xA0; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 cmd[1] = 0xD6; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 cmd[2] = offset >> 8; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 cmd[3] = offset; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 cmd[4] = len; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 bcopy(data, cmd + 5, len); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 rc = apdu_exchange(cmd, len + 5); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (rc < 0) |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 return(rc); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (sim_resp_sw != 0x9000) { |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 fprintf(stderr, "bad SW response to UPDATE BINARY: %04X\n", |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 sim_resp_sw); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(-1); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 return(0); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 } |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 update_rec_op(recno, mode, data, len) |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 unsigned recno, mode, len; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 u_char *data; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 { |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 u_char cmd[260]; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 int rc; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 /* UPDATE RECORD command APDU */ |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 cmd[0] = 0xA0; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 cmd[1] = 0xDC; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 cmd[2] = recno; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 cmd[3] = mode; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 cmd[4] = len; |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 bcopy(data, cmd + 5, len); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 rc = apdu_exchange(cmd, len + 5); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(rc); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
52 if (sim_resp_sw != 0x9000) { |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 fprintf(stderr, "bad SW response to UPDATE RECORD: %04X\n", |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 sim_resp_sw); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 return(-1); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 } |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return(0); |
fa7005185b84
fc-simtool: restore-file command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |