FreeCalypso > hg > fc-pcsc-tools
annotate simtool/plmnsel.c @ 117:b89bc690dec4
fc-simtool user-sum: support output redirection
author | Mychaela Falconia <falcon@freecalypso.org> |
---|---|
date | Fri, 19 Feb 2021 07:39:26 +0000 |
parents | 32acef9d20ff |
children | 3ddbc3fea5f0 |
rev | line source |
---|---|
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
1 /* |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
2 * This module implements commands for working with EF_PLMNsel. |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
3 */ |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
4 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
5 #include <sys/types.h> |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
6 #include <stdio.h> |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
7 #include <stdlib.h> |
100
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
8 #include <string.h> |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
9 #include <strings.h> |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
10 #include "simresp.h" |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
11 #include "curfile.h" |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
12 #include "file_id.h" |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
13 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
14 static |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
15 select_ef_plmnsel() |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
16 { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
17 int rc; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
18 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
19 rc = select_op(DF_GSM); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
20 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
21 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
22 rc = select_op(EF_PLMNsel); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
23 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
24 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
25 rc = parse_ef_select_response(); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
26 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
27 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
28 if (curfile_structure != 0x00) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
29 fprintf(stderr, "error: EF_PLMNsel is not transparent\n"); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
30 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
31 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
32 if (curfile_total_size < 24) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
33 fprintf(stderr, |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
34 "error: EF_PLMNsel is shorter than spec minimum of 24 bytes\n"); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
35 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
36 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
37 if (curfile_total_size > 255) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
38 fprintf(stderr, |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
39 "error: EF_PLMNsel is longer than our 255 byte limit\n"); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
40 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
41 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
42 if (curfile_total_size % 3) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
43 fprintf(stderr, |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
44 "error: EF_PLMNsel length is not a multiple of 3 bytes\n"); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
45 return(-1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
46 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
47 return(0); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
48 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
49 |
113
32acef9d20ff
fc-simtool plmnsel-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
50 cmd_plmnsel_dump(argc, argv, outf) |
101
63c76f9d678a
plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
51 char **argv; |
113
32acef9d20ff
fc-simtool plmnsel-dump: support output redirection
Mychaela Falconia <falcon@freecalypso.org>
parents:
102
diff
changeset
|
52 FILE *outf; |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
53 { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
54 int rc, gap_flag; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
55 u_char *dp, *endp; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
56 char ascbuf[8]; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
57 unsigned idx, linelen; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
58 |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
59 rc = select_ef_plmnsel(); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
60 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
61 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
62 rc = readbin_op(0, curfile_total_size); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
63 if (rc < 0) |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
64 return(rc); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
65 dp = sim_resp_data; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
66 endp = sim_resp_data + sim_resp_data_len; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
67 gap_flag = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
68 linelen = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
69 for (idx = 0; dp < endp; idx++, dp += 3) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
70 if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
71 gap_flag = 1; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
72 continue; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
73 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
74 if (gap_flag) { |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
75 if (linelen) { |
101
63c76f9d678a
plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
76 putc('\n', outf); |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
77 linelen = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
78 } |
101
63c76f9d678a
plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
79 fprintf(outf, "GAP, continuing at index %u:\n", idx); |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
80 gap_flag = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
81 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
82 if (linelen >= 10) { |
101
63c76f9d678a
plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
83 putc('\n', outf); |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
84 linelen = 0; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
85 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
86 decode_plmn_3bytes(dp, ascbuf, 1); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
87 if (linelen) |
101
63c76f9d678a
plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
88 putc(' ', outf); |
63c76f9d678a
plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
89 fputs(ascbuf, outf); |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
90 linelen++; |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
91 } |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
92 if (linelen) |
101
63c76f9d678a
plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents:
100
diff
changeset
|
93 putc('\n', outf); |
53
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
94 return(0); |
4eb447be01c0
fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff
changeset
|
95 } |
99
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
96 |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
97 cmd_plmnsel_write(argc, argv) |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
98 char **argv; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
99 { |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
100 int rc; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
101 unsigned idx; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
102 u_char rec[3]; |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
103 |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
104 rc = select_ef_plmnsel(); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
105 if (rc < 0) |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
106 return(rc); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
107 idx = strtoul(argv[1], 0, 0); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
108 if (idx >= curfile_total_size / 3) { |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
109 fprintf(stderr, "error: specified index is out of range\n"); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
110 return(-1); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
111 } |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
112 rc = encode_plmn_3bytes(argv[2], rec); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
113 if (rc < 0) |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
114 return(rc); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
115 return update_bin_op(idx * 3, rec, 3); |
d2e800abd257
fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
53
diff
changeset
|
116 } |
100
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
117 |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
118 cmd_plmnsel_erase(argc, argv) |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
119 char **argv; |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
120 { |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
121 int rc; |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
122 unsigned idx, start, end, nrec; |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
123 u_char rec[3]; |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
124 |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
125 rc = select_ef_plmnsel(); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
126 if (rc < 0) |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
127 return(rc); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
128 nrec = curfile_total_size / 3; |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
129 start = strtoul(argv[1], 0, 0); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
130 if (start >= nrec) { |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
131 fprintf(stderr, |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
132 "error: specified starting index is out of range\n"); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
133 return(-1); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
134 } |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
135 if (!argv[2]) |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
136 end = start; |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
137 else if (!strcmp(argv[2], "end")) |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
138 end = nrec - 1; |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
139 else { |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
140 end = strtoul(argv[1], 0, 0); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
141 if (end >= nrec) { |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
142 fprintf(stderr, |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
143 "error: specified ending index is out of range\n"); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
144 return(-1); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
145 } |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
146 if (start > end) { |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
147 fprintf(stderr, |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
148 "error: reverse index range specified\n"); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
149 return(-1); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
150 } |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
151 } |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
152 memset(rec, 0xFF, 3); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
153 for (idx = start; idx <= end; idx++) { |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
154 rc = update_bin_op(idx * 3, rec, 3); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
155 if (rc < 0) |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
156 return(rc); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
157 } |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
158 return(0); |
a75c0aafb367
plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
99
diff
changeset
|
159 } |
102
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
160 |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
161 cmd_plmnsel_erase_all(argc, argv) |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
162 char **argv; |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
163 { |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
164 int rc; |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
165 u_char ffbuf[255]; |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
166 |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
167 rc = select_ef_plmnsel(); |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
168 if (rc < 0) |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
169 return(rc); |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
170 memset(ffbuf, 0xFF, curfile_total_size); |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
171 return update_bin_op(0, ffbuf, curfile_total_size); |
9ce95d9c5c34
plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
101
diff
changeset
|
172 } |