blob: beb936bfd5682602a32f8a0ae7b89bb5e84055bb [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
Neels Hofmeyrc0164792017-09-04 15:15:32 +020028#include <osmocom/bsc/vty.h>
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020029
Neels Hofmeyrc0164792017-09-04 15:15:32 +020030#include <osmocom/bsc/gsm_data.h>
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020031
32struct cmd_node net_node = {
33 GSMNET_NODE,
34 "%s(config-net)# ",
35 1,
36};
37
38#define NETWORK_STR "Configure the GSM network\n"
39#define CODE_CMD_STR "Code commands\n"
40#define NAME_CMD_STR "Name Commands\n"
41#define NAME_STR "Name to use\n"
42
43DEFUN(cfg_net,
44 cfg_net_cmd,
45 "network", NETWORK_STR)
46{
47 vty->index = gsmnet_from_vty(vty);
48 vty->node = GSMNET_NODE;
49
50 return CMD_SUCCESS;
51}
52
53DEFUN(cfg_net_ncc,
54 cfg_net_ncc_cmd,
55 "network country code <1-999>",
56 "Set the GSM network country code\n"
57 "Country commands\n"
58 CODE_CMD_STR
59 "Network Country Code to use\n")
60{
61 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
62
63 gsmnet->country_code = atoi(argv[0]);
64
65 return CMD_SUCCESS;
66}
67
68DEFUN(cfg_net_mnc,
69 cfg_net_mnc_cmd,
70 "mobile network code <0-999>",
71 "Set the GSM mobile network code\n"
72 "Network Commands\n"
73 CODE_CMD_STR
74 "Mobile Network Code to use\n")
75{
76 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
77
78 gsmnet->network_code = atoi(argv[0]);
79
80 return CMD_SUCCESS;
81}
82
83DEFUN(cfg_net_name_short,
84 cfg_net_name_short_cmd,
85 "short name NAME",
86 "Set the short GSM network name\n" NAME_CMD_STR NAME_STR)
87{
88 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
89
Harald Welte4a824ca2017-05-29 13:54:27 +020090 osmo_talloc_replace_string(gsmnet, &gsmnet->name_short, argv[0]);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020091 return CMD_SUCCESS;
92}
93
94DEFUN(cfg_net_name_long,
95 cfg_net_name_long_cmd,
96 "long name NAME",
97 "Set the long GSM network name\n" NAME_CMD_STR NAME_STR)
98{
99 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
100
Harald Welte4a824ca2017-05-29 13:54:27 +0200101 osmo_talloc_replace_string(gsmnet, &gsmnet->name_long, argv[0]);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200102 return CMD_SUCCESS;
103}
104
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200105DEFUN(cfg_net_reject_cause,
106 cfg_net_reject_cause_cmd,
107 "location updating reject cause <2-111>",
108 "Set the reject cause of location updating reject\n"
109 "Set the reject cause of location updating reject\n"
110 "Set the reject cause of location updating reject\n"
111 "Set the reject cause of location updating reject\n"
112 "Cause Value as Per GSM TS 04.08\n")
113{
114 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
115
116 gsmnet->reject_cause = atoi(argv[0]);
117
118 return CMD_SUCCESS;
119}
120
121DEFUN(cfg_net_encryption,
122 cfg_net_encryption_cmd,
123 "encryption a5 (0|1|2|3)",
124 "Encryption options\n"
125 "A5 encryption\n" "A5/0: No encryption\n"
126 "A5/1: Encryption\n" "A5/2: Export-grade Encryption\n"
127 "A5/3: 'New' Secure Encryption\n")
128{
129 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
130
Neels Hofmeyrcc7db182016-12-18 23:52:38 +0100131 gsmnet->a5_encryption = atoi(argv[0]);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200132
133 return CMD_SUCCESS;
134}
135
136DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd,
137 "rrlp mode (none|ms-based|ms-preferred|ass-preferred)",
138 "Radio Resource Location Protocol\n"
139 "Set the Radio Resource Location Protocol Mode\n"
140 "Don't send RRLP request\n"
141 "Request MS-based location\n"
142 "Request any location, prefer MS-based\n"
143 "Request any location, prefer MS-assisted\n")
144{
145 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
146
147 gsmnet->rrlp.mode = rrlp_mode_parse(argv[0]);
148
149 return CMD_SUCCESS;
150}
151
152DEFUN(cfg_net_mm_info, cfg_net_mm_info_cmd,
153 "mm info (0|1)",
154 "Mobility Management\n"
155 "Send MM INFO after LOC UPD ACCEPT\n"
156 "Disable\n" "Enable\n")
157{
158 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
159
160 gsmnet->send_mm_info = atoi(argv[0]);
161
162 return CMD_SUCCESS;
163}
164
Vadim Yanitskiy7f3724e2017-03-31 23:27:44 +0700165DEFUN(cfg_net_dyn_ts_allow_tch_f,
166 cfg_net_dyn_ts_allow_tch_f_cmd,
167 "dyn_ts_allow_tch_f (0|1)",
168 "Allow or disallow allocating TCH/F on TCH_F_TCH_H_PDCH timeslots\n"
169 "Disallow TCH/F on TCH_F_TCH_H_PDCH (default)\n"
170 "Allow TCH/F on TCH_F_TCH_H_PDCH\n")
171{
172 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
173 gsmnet->dyn_ts_allow_tch_f = atoi(argv[0]) ? true : false;
174 return CMD_SUCCESS;
175}
176
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200177DEFUN(cfg_net_timezone,
178 cfg_net_timezone_cmd,
179 "timezone <-19-19> (0|15|30|45)",
180 "Set the Timezone Offset of the network\n"
181 "Timezone offset (hours)\n"
182 "Timezone offset (00 minutes)\n"
183 "Timezone offset (15 minutes)\n"
184 "Timezone offset (30 minutes)\n"
185 "Timezone offset (45 minutes)\n"
186 )
187{
188 struct gsm_network *net = vty->index;
189 int tzhr = atoi(argv[0]);
190 int tzmn = atoi(argv[1]);
191
192 net->tz.hr = tzhr;
193 net->tz.mn = tzmn;
194 net->tz.dst = 0;
195 net->tz.override = 1;
196
197 return CMD_SUCCESS;
198}
199
200DEFUN(cfg_net_timezone_dst,
201 cfg_net_timezone_dst_cmd,
202 "timezone <-19-19> (0|15|30|45) <0-2>",
203 "Set the Timezone Offset of the network\n"
204 "Timezone offset (hours)\n"
205 "Timezone offset (00 minutes)\n"
206 "Timezone offset (15 minutes)\n"
207 "Timezone offset (30 minutes)\n"
208 "Timezone offset (45 minutes)\n"
209 "DST offset (hours)\n"
210 )
211{
212 struct gsm_network *net = vty->index;
213 int tzhr = atoi(argv[0]);
214 int tzmn = atoi(argv[1]);
215 int tzdst = atoi(argv[2]);
216
217 net->tz.hr = tzhr;
218 net->tz.mn = tzmn;
219 net->tz.dst = tzdst;
220 net->tz.override = 1;
221
222 return CMD_SUCCESS;
223}
224
225DEFUN(cfg_net_no_timezone,
226 cfg_net_no_timezone_cmd,
227 "no timezone",
228 NO_STR
229 "Disable network timezone override, use system tz\n")
230{
231 struct gsm_network *net = vty->index;
232
233 net->tz.override = 0;
234
235 return CMD_SUCCESS;
236}
237
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200238DEFUN(cfg_net_per_loc_upd, cfg_net_per_loc_upd_cmd,
239 "periodic location update <6-1530>",
240 "Periodic Location Updating Interval\n"
241 "Periodic Location Updating Interval\n"
242 "Periodic Location Updating Interval\n"
243 "Periodic Location Updating Interval in Minutes\n")
244{
245 struct gsm_network *net = vty->index;
246
247 net->t3212 = atoi(argv[0]) / 6;
248
249 return CMD_SUCCESS;
250}
251
252DEFUN(cfg_net_no_per_loc_upd, cfg_net_no_per_loc_upd_cmd,
253 "no periodic location update",
254 NO_STR
255 "Periodic Location Updating Interval\n"
256 "Periodic Location Updating Interval\n"
257 "Periodic Location Updating Interval\n")
258{
259 struct gsm_network *net = vty->index;
260
261 net->t3212 = 0;
262
263 return CMD_SUCCESS;
264}
265
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200266static struct gsm_network *vty_global_gsm_network = NULL;
267
268/* initialize VTY elements used in both BSC and MSC */
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200269int common_cs_vty_init(struct gsm_network *network,
270 int (* config_write_net )(struct vty *))
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200271{
272 OSMO_ASSERT(vty_global_gsm_network == NULL);
273 vty_global_gsm_network = network;
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200274
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200275 osmo_stats_vty_add_cmds();
276
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200277 install_element(CONFIG_NODE, &cfg_net_cmd);
278 install_node(&net_node, config_write_net);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200279 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
280 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
281 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
282 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200283 install_element(GSMNET_NODE, &cfg_net_reject_cause_cmd);
284 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
285 install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd);
286 install_element(GSMNET_NODE, &cfg_net_mm_info_cmd);
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200287 install_element(GSMNET_NODE, &cfg_net_timezone_cmd);
288 install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd);
289 install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd);
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200290 install_element(GSMNET_NODE, &cfg_net_per_loc_upd_cmd);
291 install_element(GSMNET_NODE, &cfg_net_no_per_loc_upd_cmd);
Vadim Yanitskiy7f3724e2017-03-31 23:27:44 +0700292 install_element(GSMNET_NODE, &cfg_net_dyn_ts_allow_tch_f_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200293
294 return CMD_SUCCESS;
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200295}
296
297struct gsm_network *gsmnet_from_vty(struct vty *v)
298{
299 /* It can't hurt to force callers to continue to pass the vty instance
300 * to this function, in case we'd like to retrieve the global
301 * gsm_network instance from the vty at some point in the future. But
302 * until then, just return the global pointer, which should have been
303 * initialized by common_cs_vty_init().
304 */
305 OSMO_ASSERT(vty_global_gsm_network);
306 return vty_global_gsm_network;
307}