comparison uicc/createfile.c @ 15:b70d35f5476f

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