FreeCalypso > hg > fc-pcsc-tools
annotate uicc/createfile.c @ 139:c13ed9194ecd
fc-uicc-tool create-file implemented
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 24 Feb 2021 17:08:37 +0000 |
parents | |
children | 13ab44761ea6 |
rev | line source |
---|---|
139
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements commands that exercise ETSI TS 102 222 |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 * CREATE FILE and DELETE FILE operations. |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 */ |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <sys/types.h> |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <string.h> |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <strings.h> |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "simresp.h" |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 cmd_create_file(argc, argv) |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 char **argv; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 { |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 u_char apdu[260], inbuf[252], *dp; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 unsigned len1, len2; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int rc; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 rc = decode_hex_data_from_string(argv[1], inbuf, 1, 252); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (rc < 0) |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 return(rc); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 len1 = rc; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 dp = apdu + 5; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 *dp++ = 0x62; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 if (len1 < 0x80) { |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 *dp++ = len1; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 len2 = len1 + 2; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 } else { |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 *dp++ = 0x81; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 *dp++ = len1; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 len2 = len1 + 3; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 } |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 bcopy(inbuf, dp, len1); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 /* command header */ |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 apdu[0] = 0x00; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 apdu[1] = 0xE0; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 apdu[2] = 0; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 apdu[3] = 0; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 apdu[4] = len2; |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 rc = apdu_exchange(apdu, len2 + 5); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 if (rc < 0) |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 return(rc); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 if (sim_resp_sw != 0x9000) { |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(-1); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return(0); |
c13ed9194ecd
fc-uicc-tool create-file implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |