FreeCalypso > hg > fc-pcsc-tools
annotate simtool/smserase.c @ 74:8562d8508cf2
grcard2-set-{adm,super}-hex commands implemented
It appears that GrcardSIM2 cards allow arbitrary 64-bit keys
for ADM and SUPER ADM, not necessarily consisting of ASCII digits
like the specs require for standard PIN and PUK, and pySim-prog.py
in fact sets the ADM key to 4444444444444444 in hex by default,
which is not an ASCII digit string. If the cards allow such keys,
we need to support them too.
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Tue, 16 Feb 2021 04:10:36 +0000 |
parents | 10030acba82f |
children |
rev | line source |
---|---|
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
2 * This module implements the sms-erase family of commands. |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <string.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
7 #include <strings.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
8 #include <stdio.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
9 #include <stdlib.h> |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "curfile.h" |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
11 #include "file_id.h" |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
13 #define SMS_RECORD_LEN 176 |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
14 |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
15 static |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
16 select_ef_sms() |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
17 { |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
18 int rc; |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
19 |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
20 rc = select_op(DF_TELECOM); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
21 if (rc < 0) |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
22 return(rc); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
23 rc = select_op(EF_SMS); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
24 if (rc < 0) |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
25 return(rc); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
26 rc = parse_ef_select_response(); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
27 if (rc < 0) |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
28 return(rc); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
29 if (curfile_structure != 0x01) { |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
30 fprintf(stderr, "error: EF_SMS is not linear fixed\n"); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
31 return(-1); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
32 } |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
33 if (curfile_record_len != SMS_RECORD_LEN) { |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
34 fprintf(stderr, |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
35 "error: EF_SMS has record length of %u bytes, expected 176\n", |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
36 curfile_record_len); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
37 return(-1); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
38 } |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
39 return(0); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
40 } |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
41 |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
42 cmd_sms_erase_all(argc, argv) |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 unsigned recno; |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
47 u_char record[SMS_RECORD_LEN]; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
49 rc = select_ef_sms(); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
50 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
51 return(rc); |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
52 memset(record, 0xFF, SMS_RECORD_LEN); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
53 record[0] = 0; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 for (recno = 1; recno <= curfile_record_count; recno++) { |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
55 rc = update_rec_op(recno, 0x04, record, SMS_RECORD_LEN); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
62 cmd_sms_erase_one(argc, argv) |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 unsigned recno; |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
67 u_char record[SMS_RECORD_LEN]; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
69 rc = select_ef_sms(); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 return(rc); |
40
4c240a37e7c4
fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
72 recno = strtoul(argv[1], 0, 0); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 if (recno < 1 || recno > curfile_record_count) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 fprintf(stderr, "error: specified record number is invalid\n"); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
76 } |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
77 memset(record, 0xFF, SMS_RECORD_LEN); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
78 record[0] = 0; |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
79 return update_rec_op(recno, 0x04, record, SMS_RECORD_LEN); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
82 cmd_sms_erase_range(argc, argv) |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
83 char **argv; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 int rc; |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 unsigned recno, startrec, endrec; |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
87 u_char record[SMS_RECORD_LEN]; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
88 |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
89 rc = select_ef_sms(); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 return(rc); |
40
4c240a37e7c4
fc-simtool smsp-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
14
diff
changeset
|
92 startrec = strtoul(argv[1], 0, 0); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
93 if (startrec < 1 || startrec > curfile_record_count) { |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 fprintf(stderr, |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 "error: specified starting record number is invalid\n"); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
96 return(-1); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
97 } |
57
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
98 if (!strcmp(argv[2], "end")) |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
99 endrec = curfile_record_count; |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
100 else { |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
101 endrec = strtoul(argv[2], 0, 0); |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
102 if (endrec < 1 || endrec > curfile_record_count) { |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
103 fprintf(stderr, |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
104 "error: specified final record number is invalid\n"); |
57
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
105 return(-1); |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
106 } |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
107 if (startrec > endrec) { |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
108 fprintf(stderr, |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
109 "error: reverse record range specified\n"); |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
110 return(-1); |
10030acba82f
fc-simtool *-erase-range commands: allow "end" keyword
Mychaela Falconia <falcon@freecalypso.org>
parents:
42
diff
changeset
|
111 } |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
112 } |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
113 memset(record, 0xFF, SMS_RECORD_LEN); |
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
114 record[0] = 0; |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
115 for (recno = startrec; recno <= endrec; recno++) { |
42
2714d379edc2
fc-simtool sms-erase-* command family implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
40
diff
changeset
|
116 rc = update_rec_op(recno, 0x04, record, SMS_RECORD_LEN); |
1
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
117 if (rc < 0) |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
118 return(rc); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
119 } |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
120 return(0); |
2071b28cd0c7
simtool: first refactored version
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
121 } |