annotate simtool/plmnsel.c @ 102:9ce95d9c5c34

plmnsel-erase-all command implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Wed, 17 Feb 2021 23:25:47 +0000
parents 63c76f9d678a
children 32acef9d20ff
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
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
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
50 cmd_plmnsel_dump(argc, argv)
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
51 char **argv;
53
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 {
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 int rc, gap_flag;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 u_char *dp, *endp;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 char ascbuf[8];
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 unsigned idx, linelen;
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
57 FILE *outf;
53
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);
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
65 if (argv[1]) {
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
66 outf = fopen(argv[1], "w");
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
67 if (!outf) {
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
68 perror(argv[1]);
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
69 return(-1);
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
70 }
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
71 } else
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
72 outf = stdout;
53
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
73 dp = sim_resp_data;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
74 endp = sim_resp_data + sim_resp_data_len;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
75 gap_flag = 0;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
76 linelen = 0;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
77 for (idx = 0; dp < endp; idx++, dp += 3) {
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
78 if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF) {
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
79 gap_flag = 1;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
80 continue;
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 (gap_flag) {
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
83 if (linelen) {
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
84 putc('\n', outf);
53
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
85 linelen = 0;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
86 }
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
87 fprintf(outf, "GAP, continuing at index %u:\n", idx);
53
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
88 gap_flag = 0;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
89 }
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
90 if (linelen >= 10) {
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
91 putc('\n', outf);
53
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
92 linelen = 0;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
93 }
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
94 decode_plmn_3bytes(dp, ascbuf, 1);
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
95 if (linelen)
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
96 putc(' ', outf);
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
97 fputs(ascbuf, outf);
53
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
98 linelen++;
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
99 }
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
100 if (linelen)
101
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
101 putc('\n', outf);
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
102 if (argv[1])
63c76f9d678a plmnsel-dump can now write to file
Mychaela Falconia <falcon@freecalypso.org>
parents: 100
diff changeset
103 fclose(outf);
53
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
104 return(0);
4eb447be01c0 fc-simtool plmnsel-dump implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
105 }
99
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
106
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
107 cmd_plmnsel_write(argc, argv)
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
108 char **argv;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
109 {
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
110 int rc;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
111 unsigned idx;
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
112 u_char rec[3];
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
113
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
114 rc = select_ef_plmnsel();
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
115 if (rc < 0)
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
116 return(rc);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
117 idx = strtoul(argv[1], 0, 0);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
118 if (idx >= curfile_total_size / 3) {
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
119 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
120 return(-1);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
121 }
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
122 rc = encode_plmn_3bytes(argv[2], rec);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
123 if (rc < 0)
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
124 return(rc);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
125 return update_bin_op(idx * 3, rec, 3);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
126 }
100
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
127
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
128 cmd_plmnsel_erase(argc, argv)
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
129 char **argv;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
130 {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
131 int rc;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
132 unsigned idx, start, end, nrec;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
133 u_char rec[3];
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 rc = select_ef_plmnsel();
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
136 if (rc < 0)
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
137 return(rc);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
138 nrec = curfile_total_size / 3;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
139 start = strtoul(argv[1], 0, 0);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
140 if (start >= nrec) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
141 fprintf(stderr,
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
142 "error: specified starting index is out of range\n");
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
143 return(-1);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
144 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
145 if (!argv[2])
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
146 end = start;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
147 else if (!strcmp(argv[2], "end"))
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
148 end = nrec - 1;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
149 else {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
150 end = strtoul(argv[1], 0, 0);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
151 if (end >= nrec) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
152 fprintf(stderr,
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
153 "error: specified ending index is out of range\n");
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
154 return(-1);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
155 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
156 if (start > end) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
157 fprintf(stderr,
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
158 "error: reverse index range specified\n");
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
159 return(-1);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
160 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
161 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
162 memset(rec, 0xFF, 3);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
163 for (idx = start; idx <= end; idx++) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
164 rc = update_bin_op(idx * 3, rec, 3);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
165 if (rc < 0)
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
166 return(rc);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
167 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
168 return(0);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
169 }
102
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
170
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
171 cmd_plmnsel_erase_all(argc, argv)
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
172 char **argv;
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
173 {
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
174 int rc;
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
175 u_char ffbuf[255];
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
176
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
177 rc = select_ef_plmnsel();
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
178 if (rc < 0)
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
179 return(rc);
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
180 memset(ffbuf, 0xFF, curfile_total_size);
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
181 return update_bin_op(0, ffbuf, curfile_total_size);
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
182 }