FreeCalypso > hg > fc-sim-tools
comparison simtool/smsp_set.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 the user-oriented smsp-set and smsp-set-tag commands. | |
3 */ | |
4 | |
5 #include <sys/types.h> | |
6 #include <ctype.h> | |
7 #include <string.h> | |
8 #include <strings.h> | |
9 #include <stdio.h> | |
10 #include <stdlib.h> | |
11 #include "curfile.h" | |
12 | |
13 static | |
14 set_param_da(arg, fixp) | |
15 char *arg; | |
16 u_char *fixp; | |
17 { | |
18 int rc; | |
19 | |
20 rc = encode_phone_number_arg(arg, fixp + 1, 1); | |
21 if (rc < 0) | |
22 return(rc); | |
23 fixp[0] &= 0xFE; | |
24 return(0); | |
25 } | |
26 | |
27 static | |
28 set_param_sc(arg, fixp) | |
29 char *arg; | |
30 u_char *fixp; | |
31 { | |
32 int rc; | |
33 | |
34 rc = encode_phone_number_arg(arg, fixp + 13, 0); | |
35 if (rc < 0) | |
36 return(rc); | |
37 fixp[0] &= 0xFD; | |
38 return(0); | |
39 } | |
40 | |
41 static | |
42 set_param_pid(arg, fixp) | |
43 char *arg; | |
44 u_char *fixp; | |
45 { | |
46 char *endp; | |
47 | |
48 if (!isdigit(*arg)) { | |
49 inv: fprintf(stderr, "error: invalid PID= parameter\n"); | |
50 return(-1); | |
51 } | |
52 fixp[25] = strtoul(arg, &endp, 0); | |
53 if (*endp) | |
54 goto inv; | |
55 fixp[0] &= 0xFB; | |
56 return(0); | |
57 } | |
58 | |
59 static | |
60 set_param_dcs(arg, fixp) | |
61 char *arg; | |
62 u_char *fixp; | |
63 { | |
64 char *endp; | |
65 | |
66 if (!isdigit(*arg)) { | |
67 inv: fprintf(stderr, "error: invalid DCS= parameter\n"); | |
68 return(-1); | |
69 } | |
70 fixp[26] = strtoul(arg, &endp, 0); | |
71 if (*endp) | |
72 goto inv; | |
73 fixp[0] &= 0xF7; | |
74 return(0); | |
75 } | |
76 | |
77 static | |
78 set_param_vp(arg, fixp) | |
79 char *arg; | |
80 u_char *fixp; | |
81 { | |
82 char *endp; | |
83 | |
84 if (!isdigit(*arg)) { | |
85 inv: fprintf(stderr, "error: invalid VP= parameter\n"); | |
86 return(-1); | |
87 } | |
88 fixp[27] = strtoul(arg, &endp, 0); | |
89 if (*endp) | |
90 goto inv; | |
91 fixp[0] &= 0xEF; | |
92 return(0); | |
93 } | |
94 | |
95 static | |
96 set_param(arg, fixp) | |
97 char *arg; | |
98 u_char *fixp; | |
99 { | |
100 if (!strncasecmp(arg, "DA=", 3)) | |
101 return set_param_da(arg + 3, fixp); | |
102 if (!strncasecmp(arg, "SC=", 3)) | |
103 return set_param_sc(arg + 3, fixp); | |
104 if (!strncasecmp(arg, "PID=", 4)) | |
105 return set_param_pid(arg + 4, fixp); | |
106 if (!strncasecmp(arg, "DCS=", 4)) | |
107 return set_param_dcs(arg + 4, fixp); | |
108 if (!strncasecmp(arg, "VP=", 3)) | |
109 return set_param_vp(arg + 3, fixp); | |
110 fprintf(stderr, "error: non-understood parameter \"%s\"\n", arg); | |
111 return(-1); | |
112 } | |
113 | |
114 cmd_smsp_set(argc, argv) | |
115 char **argv; | |
116 { | |
117 int rc; | |
118 unsigned recno; | |
119 u_char record[255], *fixp; | |
120 char **ap; | |
121 | |
122 rc = select_ef_smsp(); | |
123 if (rc < 0) | |
124 return(rc); | |
125 recno = strtoul(argv[1], 0, 0); | |
126 if (recno < 1 || recno > curfile_record_count) { | |
127 fprintf(stderr, "error: specified record number is invalid\n"); | |
128 return(-1); | |
129 } | |
130 memset(record, 0xFF, curfile_record_len); | |
131 fixp = record + curfile_record_len - 28; | |
132 for (ap = argv + 2; *ap; ap++) { | |
133 rc = set_param(*ap, fixp); | |
134 if (rc < 0) | |
135 return(rc); | |
136 } | |
137 return update_rec_op(recno, 0x04, record, curfile_record_len); | |
138 } | |
139 | |
140 cmd_smsp_set_tag(argc, argv) | |
141 char **argv; | |
142 { | |
143 int rc; | |
144 unsigned recno; | |
145 u_char record[255], *fixp; | |
146 char **ap; | |
147 | |
148 rc = select_ef_smsp(); | |
149 if (rc < 0) | |
150 return(rc); | |
151 recno = strtoul(argv[1], 0, 0); | |
152 if (recno < 1 || recno > curfile_record_count) { | |
153 fprintf(stderr, "error: specified record number is invalid\n"); | |
154 return(-1); | |
155 } | |
156 memset(record, 0xFF, curfile_record_len); | |
157 rc = qstring_arg_to_gsm7(argv[2], record, curfile_record_len - 28); | |
158 if (rc < 0) | |
159 return(rc); | |
160 fixp = record + curfile_record_len - 28; | |
161 for (ap = argv + 3; *ap; ap++) { | |
162 rc = set_param(*ap, fixp); | |
163 if (rc < 0) | |
164 return(rc); | |
165 } | |
166 return update_rec_op(recno, 0x04, record, curfile_record_len); | |
167 } |