blob: 01c6b357f5dfd631852423bee03312f547f70503 [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 Hofmeyr90843962017-09-04 15:04:35 +020028#include <osmocom/msc/vty.h>
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020029
Neels Hofmeyr90843962017-09-04 15:04:35 +020030#include <osmocom/msc/gsm_data.h>
31#include <osmocom/msc/gsm_subscriber.h>
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020032
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
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200106DEFUN(cfg_net_encryption,
107 cfg_net_encryption_cmd,
Harald Welte7b222aa2017-12-23 19:30:32 +0100108 "encryption a5 <0-3> [<0-3>] [<0-3>] [<0-3>]",
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200109 "Encryption options\n"
Harald Welte7b222aa2017-12-23 19:30:32 +0100110 "GSM A5 Air Interface Encryption\n"
111 "A5/n Algorithm Number\n"
112 "A5/n Algorithm Number\n"
113 "A5/n Algorithm Number\n"
114 "A5/n Algorithm Number\n")
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200115{
116 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
Harald Welte7b222aa2017-12-23 19:30:32 +0100117 unsigned int i;
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200118
Harald Welte7b222aa2017-12-23 19:30:32 +0100119 gsmnet->a5_encryption_mask = 0;
120 for (i = 0; i < argc; i++)
121 gsmnet->a5_encryption_mask |= (1 << atoi(argv[i]));
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200122
123 return CMD_SUCCESS;
124}
125
Harald Welte2483f1b2016-06-19 18:06:02 +0200126DEFUN(cfg_net_authentication,
127 cfg_net_authentication_cmd,
128 "authentication (optional|required)",
129 "Whether to enforce MS authentication in 2G\n"
130 "Allow MS to attach via 2G BSC without authentication\n"
131 "Always do authentication\n")
132{
133 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
134
135 gsmnet->authentication_required = (argv[0][0] == 'r') ? true : false;
136
137 return CMD_SUCCESS;
138}
139
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200140DEFUN(cfg_net_rrlp_mode, cfg_net_rrlp_mode_cmd,
141 "rrlp mode (none|ms-based|ms-preferred|ass-preferred)",
142 "Radio Resource Location Protocol\n"
143 "Set the Radio Resource Location Protocol Mode\n"
144 "Don't send RRLP request\n"
145 "Request MS-based location\n"
146 "Request any location, prefer MS-based\n"
147 "Request any location, prefer MS-assisted\n")
148{
149 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
150
151 gsmnet->rrlp.mode = rrlp_mode_parse(argv[0]);
152
153 return CMD_SUCCESS;
154}
155
156DEFUN(cfg_net_mm_info, cfg_net_mm_info_cmd,
157 "mm info (0|1)",
158 "Mobility Management\n"
159 "Send MM INFO after LOC UPD ACCEPT\n"
160 "Disable\n" "Enable\n")
161{
162 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
163
164 gsmnet->send_mm_info = atoi(argv[0]);
165
166 return CMD_SUCCESS;
167}
168
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200169DEFUN(cfg_net_timezone,
170 cfg_net_timezone_cmd,
171 "timezone <-19-19> (0|15|30|45)",
172 "Set the Timezone Offset of the network\n"
173 "Timezone offset (hours)\n"
174 "Timezone offset (00 minutes)\n"
175 "Timezone offset (15 minutes)\n"
176 "Timezone offset (30 minutes)\n"
177 "Timezone offset (45 minutes)\n"
178 )
179{
180 struct gsm_network *net = vty->index;
181 int tzhr = atoi(argv[0]);
182 int tzmn = atoi(argv[1]);
183
184 net->tz.hr = tzhr;
185 net->tz.mn = tzmn;
186 net->tz.dst = 0;
187 net->tz.override = 1;
188
189 return CMD_SUCCESS;
190}
191
192DEFUN(cfg_net_timezone_dst,
193 cfg_net_timezone_dst_cmd,
194 "timezone <-19-19> (0|15|30|45) <0-2>",
195 "Set the Timezone Offset of the network\n"
196 "Timezone offset (hours)\n"
197 "Timezone offset (00 minutes)\n"
198 "Timezone offset (15 minutes)\n"
199 "Timezone offset (30 minutes)\n"
200 "Timezone offset (45 minutes)\n"
201 "DST offset (hours)\n"
202 )
203{
204 struct gsm_network *net = vty->index;
205 int tzhr = atoi(argv[0]);
206 int tzmn = atoi(argv[1]);
207 int tzdst = atoi(argv[2]);
208
209 net->tz.hr = tzhr;
210 net->tz.mn = tzmn;
211 net->tz.dst = tzdst;
212 net->tz.override = 1;
213
214 return CMD_SUCCESS;
215}
216
217DEFUN(cfg_net_no_timezone,
218 cfg_net_no_timezone_cmd,
219 "no timezone",
220 NO_STR
221 "Disable network timezone override, use system tz\n")
222{
223 struct gsm_network *net = vty->index;
224
225 net->tz.override = 0;
226
227 return CMD_SUCCESS;
228}
229
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200230DEFUN(cfg_net_per_loc_upd, cfg_net_per_loc_upd_cmd,
231 "periodic location update <6-1530>",
232 "Periodic Location Updating Interval\n"
233 "Periodic Location Updating Interval\n"
234 "Periodic Location Updating Interval\n"
235 "Periodic Location Updating Interval in Minutes\n")
236{
237 struct gsm_network *net = vty->index;
238
239 net->t3212 = atoi(argv[0]) / 6;
240
241 return CMD_SUCCESS;
242}
243
244DEFUN(cfg_net_no_per_loc_upd, cfg_net_no_per_loc_upd_cmd,
245 "no periodic location update",
246 NO_STR
247 "Periodic Location Updating Interval\n"
248 "Periodic Location Updating Interval\n"
249 "Periodic Location Updating Interval\n")
250{
251 struct gsm_network *net = vty->index;
252
253 net->t3212 = 0;
254
255 return CMD_SUCCESS;
256}
257
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200258static struct gsm_network *vty_global_gsm_network = NULL;
259
260/* initialize VTY elements used in both BSC and MSC */
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200261int common_cs_vty_init(struct gsm_network *network,
262 int (* config_write_net )(struct vty *))
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200263{
264 OSMO_ASSERT(vty_global_gsm_network == NULL);
265 vty_global_gsm_network = network;
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200266
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200267 osmo_stats_vty_add_cmds();
268
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200269 install_element(CONFIG_NODE, &cfg_net_cmd);
270 install_node(&net_node, config_write_net);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200271 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
272 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
273 install_element(GSMNET_NODE, &cfg_net_name_short_cmd);
274 install_element(GSMNET_NODE, &cfg_net_name_long_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200275 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Harald Welte2483f1b2016-06-19 18:06:02 +0200276 install_element(GSMNET_NODE, &cfg_net_authentication_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200277 install_element(GSMNET_NODE, &cfg_net_rrlp_mode_cmd);
278 install_element(GSMNET_NODE, &cfg_net_mm_info_cmd);
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200279 install_element(GSMNET_NODE, &cfg_net_timezone_cmd);
280 install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd);
281 install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd);
Neels Hofmeyre2f24d52017-05-08 15:12:20 +0200282 install_element(GSMNET_NODE, &cfg_net_per_loc_upd_cmd);
283 install_element(GSMNET_NODE, &cfg_net_no_per_loc_upd_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200284
285 return CMD_SUCCESS;
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200286}
287
288struct gsm_network *gsmnet_from_vty(struct vty *v)
289{
290 /* It can't hurt to force callers to continue to pass the vty instance
291 * to this function, in case we'd like to retrieve the global
292 * gsm_network instance from the vty at some point in the future. But
293 * until then, just return the global pointer, which should have been
294 * initialized by common_cs_vty_init().
295 */
296 OSMO_ASSERT(vty_global_gsm_network);
297 return vty_global_gsm_network;
298}