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