FreeCalypso > hg > fc-sim-tools
annotate uicc/erasefile.c @ 93:6041c601304d
fcsim1-mkprov: revert OTA key addition
It appears that GrcardSIM2 cards (which is what we got for FCSIM1)
do not support OTA after all, contrary to what we were previously
led to believe by some tech support emails from Grcard - apparently
those support emails and OTA descriptions referred to some other
card model(s).
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Wed, 21 Apr 2021 05:38:39 +0000 |
parents | 5560261fc516 |
children |
rev | line source |
---|---|
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements the erase-file command. |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <ctype.h> |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <stdio.h> |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdlib.h> |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <string.h> |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include <strings.h> |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
11 #include "efstruct.h" |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 static |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
14 erase_transparent(efs, fill_byte) |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
15 struct ef_struct *efs; |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 u_char data[255]; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 unsigned off, cc; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 int rc; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 memset(data, fill_byte, 255); |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
22 for (off = 0; off < efs->total_size; off += cc) { |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
23 cc = efs->total_size - off; |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 if (cc > 255) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 cc = 255; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 rc = update_bin_op(off, data, cc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(0); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 static |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
34 erase_records(efs, fill_byte) |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
35 struct ef_struct *efs; |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 u_char data[255]; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 unsigned recno; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 int rc; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
41 memset(data, fill_byte, efs->record_len); |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
42 for (recno = 1; recno <= efs->record_count; recno++) { |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
43 rc = update_rec_op(recno, 0x04, data, efs->record_len); |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return(0); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 static |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
51 erase_cyclic(efs, fill_byte) |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
52 struct ef_struct *efs; |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 u_char data[255]; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 unsigned count; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 int rc; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
58 memset(data, fill_byte, efs->record_len); |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
59 for (count = 0; count < efs->record_count; count++) { |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
60 rc = update_rec_op(0, 0x03, data, efs->record_len); |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return(0); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 cmd_erase_file(argc, argv) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 char **argv; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 int file_id, rc; |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
71 struct ef_struct efs; |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 unsigned fill_byte; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (isxdigit(argv[1][0]) && isxdigit(argv[1][1]) && |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 isxdigit(argv[1][2]) && isxdigit(argv[1][3]) && !argv[1][4]) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 file_id = strtoul(argv[1], 0, 16); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 else |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 file_id = find_symbolic_file_name(argv[1]); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
79 if (file_id < 0) { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 fprintf(stderr, |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 "error: file ID argument is not a hex value or a recognized symbolic name\n"); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 return(-1); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 rc = select_op(file_id); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 return(rc); |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
87 rc = select_resp_get_ef_struct(&efs); |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 if (rc < 0) |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
89 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (argc > 2) { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 fill_byte = strtoul(argv[2], 0, 16); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (fill_byte > 0xFF) { |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 fprintf(stderr, "error: invalid fill byte argument\n"); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 return(-1); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 } else |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 fill_byte = 0xFF; |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
98 switch (efs.structure) { |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
99 case 0x01: |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
100 /* transparent */ |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
101 rc = erase_transparent(&efs, fill_byte); |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
102 break; |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
103 case 0x02: |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
104 /* record-based */ |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
105 rc = erase_records(&efs, fill_byte); |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
106 break; |
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
107 case 0x06: |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
108 /* cyclic */ |
92
5560261fc516
fc-uicc-tool: erase-file ported over from fc-simtool
Mychaela Falconia <falcon@freecalypso.org>
parents:
10
diff
changeset
|
109 rc = erase_cyclic(&efs, fill_byte); |
10
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
110 break; |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
111 } |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 return(rc); |
ddd767f6e15b
fc-simtool ported over
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
113 } |