comparison simtool/fplmn.c @ 103:9b2cb2b9c910

fc-simtool fplmn-* commands implemented
author Mychaela Falconia <falcon@freecalypso.org>
date Thu, 18 Feb 2021 00:17:14 +0000
parents simtool/plmnsel.c@9ce95d9c5c34
children 8a27f45bc1e6
comparison
equal deleted inserted replaced
102:9ce95d9c5c34 103:9b2cb2b9c910
1 /*
2 * This module implements commands for working with EF_FPLMN.
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 "simresp.h"
11 #include "curfile.h"
12 #include "file_id.h"
13
14 static
15 select_ef_fplmn()
16 {
17 int rc;
18
19 rc = select_op(DF_GSM);
20 if (rc < 0)
21 return(rc);
22 rc = select_op(EF_FPLMN);
23 if (rc < 0)
24 return(rc);
25 rc = parse_ef_select_response();
26 if (rc < 0)
27 return(rc);
28 if (curfile_structure != 0x00) {
29 fprintf(stderr, "error: EF_FPLMN is not transparent\n");
30 return(-1);
31 }
32 if (curfile_total_size != 12) {
33 fprintf(stderr,
34 "error: EF_FPLMN size does not equal 12 bytes\n");
35 return(-1);
36 }
37 return(0);
38 }
39
40 cmd_fplmn_dump(argc, argv)
41 char **argv;
42 {
43 int rc;
44 u_char *dp;
45 char ascbuf[8];
46 unsigned idx;
47
48 rc = select_ef_fplmn();
49 if (rc < 0)
50 return(rc);
51 rc = readbin_op(0, 12);
52 if (rc < 0)
53 return(rc);
54 dp = sim_resp_data;
55 for (idx = 0; idx < 4; idx++, dp += 3) {
56 if (idx)
57 putchar(' ');
58 if (dp[0] == 0xFF && dp[1] == 0xFF && dp[2] == 0xFF)
59 fputs("-blank-", stdout);
60 else {
61 decode_plmn_3bytes(dp, ascbuf, 1);
62 fputs(ascbuf, stdout);
63 }
64 }
65 putchar('\n');
66 return(0);
67 }
68
69 cmd_fplmn_write(argc, argv)
70 char **argv;
71 {
72 int rc;
73 unsigned idx;
74 u_char rec[3];
75
76 rc = select_ef_fplmn();
77 if (rc < 0)
78 return(rc);
79 idx = strtoul(argv[1], 0, 0);
80 if (idx >= 4) {
81 fprintf(stderr, "error: specified index is out of range\n");
82 return(-1);
83 }
84 rc = encode_plmn_3bytes(argv[2], rec);
85 if (rc < 0)
86 return(rc);
87 return update_bin_op(idx * 3, rec, 3);
88 }
89
90 cmd_fplmn_erase(argc, argv)
91 char **argv;
92 {
93 int rc;
94 unsigned idx, start, end;
95 u_char rec[3];
96
97 rc = select_ef_fplmn();
98 if (rc < 0)
99 return(rc);
100 start = strtoul(argv[1], 0, 0);
101 if (start >= 4) {
102 fprintf(stderr,
103 "error: specified starting index is out of range\n");
104 return(-1);
105 }
106 if (!argv[2])
107 end = start;
108 else if (!strcmp(argv[2], "end"))
109 end = 3;
110 else {
111 end = strtoul(argv[1], 0, 0);
112 if (end >= 4) {
113 fprintf(stderr,
114 "error: specified ending index is out of range\n");
115 return(-1);
116 }
117 if (start > end) {
118 fprintf(stderr,
119 "error: reverse index range specified\n");
120 return(-1);
121 }
122 }
123 memset(rec, 0xFF, 3);
124 for (idx = start; idx <= end; idx++) {
125 rc = update_bin_op(idx * 3, rec, 3);
126 if (rc < 0)
127 return(rc);
128 }
129 return(0);
130 }
131
132 cmd_fplmn_erase_all(argc, argv)
133 char **argv;
134 {
135 int rc;
136 u_char ffbuf[12];
137
138 rc = select_ef_fplmn();
139 if (rc < 0)
140 return(rc);
141 memset(ffbuf, 0xFF, 12);
142 return update_bin_op(0, ffbuf, 12);
143 }