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