annotate uicc/createfile.c @ 22:f893cdde97a4

updated top-level README added
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 08:20:20 +0000
parents b70d35f5476f
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
15
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements commands that exercise ETSI TS 102 222
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 * CREATE FILE and DELETE FILE operations.
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4 */
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <sys/types.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <ctype.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
8 #include <stdio.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
9 #include <stdlib.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include <string.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11 #include <strings.h>
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 #include "simresp.h"
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 cmd_create_file(argc, argv)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char **argv;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 u_char apdu[260], inbuf[252], *dp;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 unsigned len1, len2;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 int rc;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 rc = read_hex_data_file(argv[1], inbuf, 252);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (rc < 0)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 return(rc);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 len1 = rc;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 dp = apdu + 5;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 *dp++ = 0x62;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 if (len1 < 0x80) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 *dp++ = len1;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 len2 = len1 + 2;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 } else {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 *dp++ = 0x81;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 *dp++ = len1;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 len2 = len1 + 3;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 bcopy(inbuf, dp, len1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 /* command header */
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 apdu[0] = 0x00;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 apdu[1] = 0xE0;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 apdu[2] = 0;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40 apdu[3] = 0;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 apdu[4] = len2;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 rc = apdu_exchange(apdu, len2 + 5);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 if (rc < 0)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 return(rc);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 if (sim_resp_sw != 0x9000) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 return(0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 cmd_delete_file(argc, argv)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 char **argv;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 u_char apdu[7];
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 unsigned file_id;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 int rc;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (!isxdigit(argv[1][0]) || !isxdigit(argv[1][1]) ||
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 !isxdigit(argv[1][2]) || !isxdigit(argv[1][3]) || argv[1][4]) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 fprintf(stderr, "error: 4-digit hex argument required\n");
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 file_id = strtoul(argv[1], 0, 16);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 /* form command APDU */
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 apdu[0] = 0x00;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 apdu[1] = 0xE4;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 apdu[2] = 0;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
69 apdu[3] = 0;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
70 apdu[4] = 2;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
71 apdu[5] = file_id >> 8;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
72 apdu[6] = file_id;
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 rc = apdu_exchange(apdu, 7);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 if (rc < 0)
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 return(rc);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 if (sim_resp_sw != 0x9000) {
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 fprintf(stderr, "bad SW response: %04X\n", sim_resp_sw);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 return(-1);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 }
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 return(0);
b70d35f5476f fc-uicc-tool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
81 }