blob: 17916878b0f17b746c2b3626e0d52005ee19f8dc [file] [log] [blame]
Neels Hofmeyrc69ee852016-05-10 12:50:31 +02001/* Code used by both libbsc and libmsc (common_cs means "BSC or MSC").
2 *
3 * (C) 2016 by sysmocom s.m.f.c. <info@sysmocom.de>
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +02004 * (C) 2008-2010 by Harald Welte <laforge@gnumonks.org>
Neels Hofmeyrc69ee852016-05-10 12:50:31 +02005 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
16 *
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 *
20 */
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +020021
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020022#include <osmocom/core/utils.h>
23
24#include <osmocom/vty/command.h>
25#include <osmocom/vty/logging.h>
26#include <osmocom/vty/stats.h>
27
28#include <openbsc/vty.h>
29
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +020030#include <openbsc/gsm_data.h>
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020031#include <openbsc/gsm_subscriber.h>
32
33struct cmd_node net_node = {
34 GSMNET_NODE,
35 "%s(config-net)# ",
36 1,
37};
38
39#define NETWORK_STR "Configure the GSM network\n"
40#define CODE_CMD_STR "Code commands\n"
41#define NAME_CMD_STR "Name Commands\n"
42#define NAME_STR "Name to use\n"
43
44DEFUN(cfg_net,
45 cfg_net_cmd,
46 "network", NETWORK_STR)
47{
48 vty->index = gsmnet_from_vty(vty);
49 vty->node = GSMNET_NODE;
50
51 return CMD_SUCCESS;
52}
53
54DEFUN(cfg_net_ncc,
55 cfg_net_ncc_cmd,
56 "network country code <1-999>",
57 "Set the GSM network country code\n"
58 "Country commands\n"
59 CODE_CMD_STR
60 "Network Country Code to use\n")
61{
62 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
63
64 gsmnet->country_code = atoi(argv[0]);
65
66 return CMD_SUCCESS;
67}
68
69DEFUN(cfg_net_mnc,
70 cfg_net_mnc_cmd,
71 "mobile network code <0-999>",
72 "Set the GSM mobile network code\n"
73 "Network Commands\n"
74 CODE_CMD_STR
75 "Mobile Network Code to use\n")
76{
77 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
78
79 gsmnet->network_code = atoi(argv[0]);
80
81 return CMD_SUCCESS;
82}
83
84DEFUN(cfg_net_name_short,
85 cfg_net_name_short_cmd,
86 "short name NAME",
87 "Set the short GSM network name\n" NAME_CMD_STR NAME_STR)
88{
89 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
90
Harald Welte4a824ca2017-05-29 13:54:27 +020091 osmo_talloc_replace_string(gsmnet, &gsmnet->name_short, argv[0]);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020092 return CMD_SUCCESS;
93}
94
95DEFUN(cfg_net_name_long,
96 cfg_net_name_long_cmd,
97 "long name NAME",
98 "Set the long GSM network name\n" NAME_CMD_STR NAME_STR)
99{
100 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
101
Harald Welte4a824ca2017-05-29 13:54:27 +0200102 osmo_talloc_replace_string(gsmnet, &gsmnet->name_long, argv[0]);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200103 return CMD_SUCCESS;
104}
105
106DEFUN(cfg_net_auth_policy,
107 cfg_net_auth_policy_cmd,
108 "auth policy (closed|accept-all|regexp|token)",
109 "Authentication (not cryptographic)\n"
110 "Set the GSM network authentication policy\n"
111 "Require the MS to be activated in HLR\n"
112 "Accept all MS, whether in HLR or not\n"
113 "Use regular expression for IMSI authorization decision\n"
114 "Use SMS-token based authentication\n")
115{
116 enum gsm_auth_policy policy = gsm_auth_policy_parse(argv[0]);
117 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
118
119 gsmnet->auth_policy = policy;
120
121 return CMD_SUCCESS;
122}
123
124DEFUN(cfg_net_authorize_regexp, cfg_net_authorize_regexp_cmd,
125 "authorized-regexp REGEXP",
126 "Set regexp for IMSI which will be used for authorization decision\n"
127 "Regular expression, IMSIs matching it are allowed to use the network\n")
128{
129 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
130 if (gsm_parse_reg(gsmnet, &gsmnet->authorized_regexp,
131 &gsmnet->authorized_reg_str, argc, argv) != 0) {
132 vty_out(vty, "%%Failed to parse the authorized-regexp: '%s'%s",
133 argv[0], VTY_NEWLINE);
134 return CMD_WARNING;
135 }
136
137 return CMD_SUCCESS;
138}
139
140DEFUN(cfg_net_reject_cause,
141 cfg_net_reject_cause_cmd,
142 "location updating reject cause <2-111>",
143 "Set the reject cause of location updating reject\n"
144 "Set the reject cause of location updating reject\n"
145 "Set the reject cause of location updating reject\n"
146 "Set the reject cause of location updating reject\n"
147 "Cause Value as Per GSM TS 04.08\n")
148{
149 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
150
151 gsmnet->reject_cause = atoi(argv[0]);
152
153 return CMD_SUCCESS;
154}
155
156DEFUN(cfg_net_encryption,
157 cfg_net_encryption_cmd,
158 "encryption a5 (0|1|2|3)",
159 "Encryption options\n"
160 "A5 encryption\n" "A5/0: No encryption\n"
161 "A5/1: Encryption\n" "A5/2: Export-grade Encryption\n"
162 "A5/3: 'New' Secure Encryption\n")
163{
164 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
165
Neels Hofmeyrcc7db182016-12-18 23:52:38 +0100166 gsmnet->a5_encryption = atoi(argv[0]);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200167
168 return CMD_SUCCESS;
169}
170
Harald Welte2483f1b2016-06-19 18:06:02 +0200171DEFUN(cfg_net_authentication,
172 cfg_net_authentication_cmd,
173 "authentication (optional|required)",
174 "Whether to enforce MS authentication in 2G\n"
175 "Allow MS to attach via 2G BSC without authentication\n"
176 "Always do authentication\n")
177{
178 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
179
180 gsmnet->authentication_required = (argv[0][0] == 'r') ? true : false;
181
182 return CMD_SUCCESS;
183}
184
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200185DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd,
186 "rrlp mode (none|ms-based|ms-preferred|ass-preferred)",
187 "Radio Resource Location Protocol\n"
188 "Set the Radio Resource Location Protocol Mode\n"
189 "Don't send RRLP request\n"
190 "Request MS-based location\n"
191 "Request any location, prefer MS-based\n"
192 "Request any location, prefer MS-assisted\n")
193{
194 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
195
196 gsmnet->rrlp.mode = rrlp_mode_parse(argv[0]);
197
198 return CMD_SUCCESS;
199}
200
201DEFUN(cfg_net_mm_info, cfg_net_mm_info_cmd,
202 "mm info (0|1)",
203 "Mobility Management\n"
204 "Send MM INFO after LOC UPD ACCEPT\n"
205 "Disable\n" "Enable\n")
206{
207 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
208
209 gsmnet->send_mm_info = atoi(argv[0]);
210
211 return CMD_SUCCESS;
212}
213
Vadim Yanitskiy7f3724e2017-03-31 23:27:44 +0700214DEFUN(cfg_net_dyn_ts_allow_tch_f,
215 cfg_net_dyn_ts_allow_tch_f_cmd,
216 "dyn_ts_allow_tch_f (0|1)",
217 "Allow or disallow allocating TCH/F on TCH_F_TCH_H_PDCH timeslots\n"
218 "Disallow TCH/F on TCH_F_TCH_H_PDCH (default)\n"
219 "Allow TCH/F on TCH_F_TCH_H_PDCH\n")
220{
221 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
222 gsmnet->dyn_ts_allow_tch_f = atoi(argv[0]) ? true : false;
223 return CMD_SUCCESS;
224}
225
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200226DEFUN(cfg_net_timezone,
227 cfg_net_timezone_cmd,
228 "timezone <-19-19> (0|15|30|45)",
229 "Set the Timezone Offset of the network\n"
230 "Timezone offset (hours)\n"
231 "Timezone offset (00 minutes)\n"
232 "Timezone offset (15 minutes)\n"
233 "Timezone offset (30 minutes)\n"
234 "Timezone offset (45 minutes)\n"
235 )
236{
237 struct gsm_network *net = vty->index;
238 int tzhr = atoi(argv[0]);
239 int tzmn = atoi(argv[1]);
240
241 net->tz.hr = tzhr;
242 net->tz.mn = tzmn;
243 net->tz.dst = 0;
244 net->tz.override = 1;
245
246 return CMD_SUCCESS;
247}
248
249DEFUN(cfg_net_timezone_dst,
250 cfg_net_timezone_dst_cmd,
251 "timezone <-19-19> (0|15|30|45) <0-2>",
252 "Set the Timezone Offset of the network\n"
253 "Timezone offset (hours)\n"
254 "Timezone offset (00 minutes)\n"
255 "Timezone offset (15 minutes)\n"
256 "Timezone offset (30 minutes)\n"
257 "Timezone offset (45 minutes)\n"
258 "DST offset (hours)\n"
259 )
260{
261 struct gsm_network *net = vty->index;
262 int tzhr = atoi(argv[0]);
263 int tzmn = atoi(argv[1]);
264 int tzdst = atoi(argv[2]);
265
266 net->tz.hr = tzhr;
267 net->tz.mn = tzmn;
268 net->tz.dst = tzdst;
269 net->tz.override = 1;
270
271 return CMD_SUCCESS;
272}
273
274DEFUN(cfg_net_no_timezone,
275 cfg_net_no_timezone_cmd,
276 "no timezone",
277 NO_STR
278 "Disable network timezone override, use system tz\n")
279{
280 struct gsm_network *net = vty->index;
281
282 net->tz.override = 0;
283
284 return CMD_SUCCESS;
285}
286
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200287DEFUN(cfg_net_per_loc_upd, cfg_net_per_loc_upd_cmd,
288 "periodic location update <6-1530>",
289 "Periodic Location Updating Interval\n"
290 "Periodic Location Updating Interval\n"
291 "Periodic Location Updating Interval\n"
292 "Periodic Location Updating Interval in Minutes\n")
293{
294 struct gsm_network *net = vty->index;
295
296 net->t3212 = atoi(argv[0]) / 6;
297
298 return CMD_SUCCESS;
299}
300
301DEFUN(cfg_net_no_per_loc_upd, cfg_net_no_per_loc_upd_cmd,
302 "no periodic location update",
303 NO_STR
304 "Periodic Location Updating Interval\n"
305 "Periodic Location Updating Interval\n"
306 "Periodic Location Updating Interval\n")
307{
308 struct gsm_network *net = vty->index;
309
310 net->t3212 = 0;
311
312 return CMD_SUCCESS;
313}
314
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200315static struct gsm_network *vty_global_gsm_network = NULL;
316
317/* initialize VTY elements used in both BSC and MSC */
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200318int common_cs_vty_init(struct gsm_network *network,
319 int (* config_write_net )(struct vty *))
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200320{
321 OSMO_ASSERT(vty_global_gsm_network == NULL);
322 vty_global_gsm_network = network;
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200323
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200324 osmo_stats_vty_add_cmds();
325
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200326 install_element(CONFIG_NODE, &cfg_net_cmd);
327 install_node(&net_node, config_write_net);
328 vty_install_default(GSMNET_NODE);
329 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
330 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
331 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
332 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
333 install_element(GSMNET_NODE, &cfg_net_auth_policy_cmd);
334 install_element(GSMNET_NODE, &cfg_net_authorize_regexp_cmd);
335 install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd);
336 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Harald Welte2483f1b2016-06-19 18:06:02 +0200337 install_element(GSMNET_NODE, &cfg_net_authentication_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200338 install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd);
339 install_element(GSMNET_NODE, &cfg_net_mm_info_cmd);
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200340 install_element(GSMNET_NODE, &cfg_net_timezone_cmd);
341 install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd);
342 install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200343 install_element(GSMNET_NODE, &cfg_net_per_loc_upd_cmd);
344 install_element(GSMNET_NODE, &cfg_net_no_per_loc_upd_cmd);
Vadim Yanitskiy7f3724e2017-03-31 23:27:44 +0700345 install_element(GSMNET_NODE, &cfg_net_dyn_ts_allow_tch_f_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200346
347 return CMD_SUCCESS;
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200348}
349
350struct gsm_network *gsmnet_from_vty(struct vty *v)
351{
352 /* It can't hurt to force callers to continue to pass the vty instance
353 * to this function, in case we'd like to retrieve the global
354 * gsm_network instance from the vty at some point in the future. But
355 * until then, just return the global pointer, which should have been
356 * initialized by common_cs_vty_init().
357 */
358 OSMO_ASSERT(vty_global_gsm_network);
359 return vty_global_gsm_network;
360}