annotate simtool/pnnprog.c @ 217:52c0da56e979

simtool code: select_ef_opl() factored out
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 07 Mar 2021 18:18:29 +0000
parents cd66e13eccf3
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 /*
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
2 * This module implements functions for admin programming of EF_PNN.
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
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
12 static u_char *
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
13 add_field(dp, bytes_avail, namearg, type)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
14 u_char *dp;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
15 char *namearg;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
16 unsigned bytes_avail, type;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
17 {
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
18 u_char gsm7_buf[289];
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
19 unsigned nsept, noct;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
20 int rc;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
21
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
22 if (bytes_avail < 4) {
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
23 fprintf(stderr,
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
24 "error: PNN record is too short for name element\n");
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
25 return(0);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
26 }
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
27 rc = qstring_arg_to_gsm7(namearg, gsm7_buf, (bytes_avail-3) * 8 / 7);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
28 if (rc < 0)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
29 return(0);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
30 nsept = rc;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
31 gsm7_buf[nsept] = 0;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
32 noct = (nsept * 7 + 7) / 8;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
33 *dp++ = type;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
34 *dp++ = noct + 1;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
35 *dp++ = 0x80 | (nsept & 7);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
36 gsm7_pack(gsm7_buf, dp, noct);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
37 dp += noct;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
38 return dp;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
39 }
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
40
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
41 cmd_pnn_write(argc, argv)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
42 char **argv;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
43 {
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
44 int rc;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
45 unsigned recno;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
46 u_char record[255], *dp, *endp;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
47
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
48 rc = select_ef_pnn();
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
49 if (rc < 0)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
50 return(rc);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
51 recno = strtoul(argv[1], 0, 0);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
52 if (recno < 1 || recno > curfile_record_count) {
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
53 fprintf(stderr, "error: specified record number is invalid\n");
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
54 return(-1);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
55 }
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
56 dp = record;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
57 endp = record + curfile_record_len;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
58 dp = add_field(dp, endp - dp, argv[2], 0x43);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
59 if (!dp)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
60 return(-1);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
61 if (argv[3]) {
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
62 dp = add_field(dp, endp - dp, argv[3], 0x45);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
63 if (!dp)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
64 return(-1);
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
65 }
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
66 while (dp < endp)
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
67 *dp++ = 0xFF;
3a2f43460582 fc-simtool pnn-write command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents:
diff changeset
68 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
69 }
216
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 cmd_pnn_erase(argc, argv)
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
72 char **argv;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
73 {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
74 int rc;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
75 unsigned recno, startrec, endrec;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
76 u_char record[255];
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
77
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
78 rc = select_ef_pnn();
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
79 if (rc < 0)
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
80 return(rc);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
81 startrec = strtoul(argv[1], 0, 0);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
82 if (startrec < 1 || startrec > curfile_record_count) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
83 fprintf(stderr,
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
84 "error: specified starting record number is invalid\n");
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
85 return(-1);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
86 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
87 if (!argv[2])
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
88 endrec = startrec;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
89 else if (!strcmp(argv[2], "end"))
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
90 endrec = curfile_record_count;
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
91 else {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
92 endrec = strtoul(argv[2], 0, 0);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
93 if (endrec < 1 || endrec > curfile_record_count) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
94 fprintf(stderr,
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
95 "error: specified final record number is invalid\n");
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
96 return(-1);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
97 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
98 if (startrec > endrec) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
99 fprintf(stderr,
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
100 "error: reverse record range specified\n");
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
101 return(-1);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
102 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
103 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
104 memset(record, 0xFF, curfile_record_len);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
105 for (recno = startrec; recno <= endrec; recno++) {
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
106 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
107 if (rc < 0)
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
108 return(rc);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
109 }
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
110 return(0);
cd66e13eccf3 fc-simtool pnn-erase command implemented
Mychaela Falconia <falcon@freecalypso.org>
parents: 215
diff changeset
111 }