annotate simtool/oplprog.c @ 228:a93de68711b8

original README is now README.old
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 14 Mar 2021 18:16:27 +0000
parents f376ba028311
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
1 /*
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
2 * This module implements functions for admin programming of EF_OPL.
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
3 */
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
4
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
5 #include <sys/types.h>
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
6 #include <stdio.h>
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
7 #include <stdlib.h>
216
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
8 #include <string.h>
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
9 #include <strings.h>
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
10 #include "curfile.h"
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
11
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
12 cmd_opl_write(argc, argv)
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 char **argv;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 {
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 int rc;
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
16 unsigned recno, lac;
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
17 u_char record[255];
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
19 rc = select_ef_opl();
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 if (rc < 0)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21 return(rc);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 recno = strtoul(argv[1], 0, 0);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 if (recno < 1 || recno > curfile_record_count) {
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 fprintf(stderr, "error: specified record number is invalid\n");
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(-1);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
27 rc = encode_plmn_3bytes(argv[2], record);
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
28 if (rc < 0) {
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
29 fprintf(stderr, "error: invalid MCC-MNC argument\n");
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
30 return(rc);
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 }
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
32 lac = strtoul(argv[3], 0, 16);
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
33 record[3] = lac >> 8;
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
34 record[4] = lac;
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
35 lac = strtoul(argv[4], 0, 16);
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
36 record[5] = lac >> 8;
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
37 record[6] = lac;
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
38 record[7] = strtoul(argv[5], 0, 0);
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
39 if (curfile_record_len > 8)
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
40 memset(record + 8, 0xFF, curfile_record_len - 8);
215
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 return update_rec_op(recno, 0x04, record, curfile_record_len);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 }
216
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
43
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
44 cmd_opl_erase(argc, argv)
216
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
45 char **argv;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
46 {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
47 int rc;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
48 unsigned recno, startrec, endrec;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
49 u_char record[255];
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
50
218
f376ba028311 fc-simtool opl-erase and opl-write implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 216
diff changeset
51 rc = select_ef_opl();
216
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
52 if (rc < 0)
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
53 return(rc);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
54 startrec = strtoul(argv[1], 0, 0);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
55 if (startrec < 1 || startrec > curfile_record_count) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
56 fprintf(stderr,
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
57 "error: specified starting record number is invalid\n");
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
58 return(-1);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
59 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
60 if (!argv[2])
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
61 endrec = startrec;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
62 else if (!strcmp(argv[2], "end"))
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
63 endrec = curfile_record_count;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
64 else {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
65 endrec = strtoul(argv[2], 0, 0);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
66 if (endrec < 1 || endrec > curfile_record_count) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
67 fprintf(stderr,
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
68 "error: specified final record number is invalid\n");
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
69 return(-1);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
70 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
71 if (startrec > endrec) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
72 fprintf(stderr,
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
73 "error: reverse record range specified\n");
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
74 return(-1);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
75 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
76 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
77 memset(record, 0xFF, curfile_record_len);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
78 for (recno = startrec; recno <= endrec; recno++) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
79 rc = update_rec_op(recno, 0x04, record, curfile_record_len);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
80 if (rc < 0)
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
81 return(rc);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
82 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
83 return(0);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
84 }