annotate simtool/plmnsel.c @ 208:ead7e546ad75

scripts/fcsim1-sst created
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 05:39:23 +0000
parents 3bde063234aa
children
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
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);
197
3ddbc3fea5f0 encode_plmn_3bytes() error handling change
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
113 if (rc < 0) {
3ddbc3fea5f0 encode_plmn_3bytes() error handling change
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
114 fprintf(stderr, "error: invalid MCC-MNC argument\n");
99
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
115 return(rc);
197
3ddbc3fea5f0 encode_plmn_3bytes() error handling change
Mychaela Falconia <falcon@freecalypso.org>
parents: 113
diff changeset
116 }
99
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
117 return update_bin_op(idx * 3, rec, 3);
d2e800abd257 fc-simtool plmnsel-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 53
diff changeset
118 }
100
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
119
198
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
120 cmd_plmnsel_write_list(argc, argv)
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
121 char **argv;
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
122 {
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
123 int rc;
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
124 u_char buf[255];
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
125
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
126 rc = select_ef_plmnsel();
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
127 if (rc < 0)
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
128 return(rc);
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
129 rc = read_plmn_list_from_file(argv[1], buf, curfile_total_size);
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
130 if (rc < 0)
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
131 return(rc);
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
132 return update_bin_op(0, buf, curfile_total_size);
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
133 }
3bde063234aa fc-simtool plmnsel-write-list command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 197
diff changeset
134
100
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
135 cmd_plmnsel_erase(argc, argv)
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
136 char **argv;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
137 {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
138 int rc;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
139 unsigned idx, start, end, nrec;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
140 u_char rec[3];
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
141
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
142 rc = select_ef_plmnsel();
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
143 if (rc < 0)
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
144 return(rc);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
145 nrec = curfile_total_size / 3;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
146 start = strtoul(argv[1], 0, 0);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
147 if (start >= nrec) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
148 fprintf(stderr,
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
149 "error: specified starting index is out of range\n");
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
150 return(-1);
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 if (!argv[2])
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
153 end = start;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
154 else if (!strcmp(argv[2], "end"))
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
155 end = nrec - 1;
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
156 else {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
157 end = strtoul(argv[1], 0, 0);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
158 if (end >= nrec) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
159 fprintf(stderr,
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
160 "error: specified ending index is out of range\n");
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
161 return(-1);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
162 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
163 if (start > end) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
164 fprintf(stderr,
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
165 "error: reverse index range specified\n");
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
166 return(-1);
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 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
169 memset(rec, 0xFF, 3);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
170 for (idx = start; idx <= end; idx++) {
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
171 rc = update_bin_op(idx * 3, rec, 3);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
172 if (rc < 0)
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
173 return(rc);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
174 }
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
175 return(0);
a75c0aafb367 plmnsel-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 99
diff changeset
176 }
102
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
177
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
178 cmd_plmnsel_erase_all(argc, argv)
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
179 char **argv;
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
180 {
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
181 int rc;
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
182 u_char ffbuf[255];
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
183
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
184 rc = select_ef_plmnsel();
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
185 if (rc < 0)
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
186 return(rc);
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
187 memset(ffbuf, 0xFF, curfile_total_size);
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
188 return update_bin_op(0, ffbuf, curfile_total_size);
9ce95d9c5c34 plmnsel-erase-all command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 101
diff changeset
189 }