blob: 35c13ddc878bbc18e025c2dd36a0c2df5f3c67c3 [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
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020083DEFUN(cfg_net_encryption,
84 cfg_net_encryption_cmd,
85 "encryption a5 (0|1|2|3)",
86 "Encryption options\n"
87 "A5 encryption\n" "A5/0: No encryption\n"
88 "A5/1: Encryption\n" "A5/2: Export-grade Encryption\n"
89 "A5/3: 'New' Secure Encryption\n")
90{
91 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
92
Neels Hofmeyrcc7db182016-12-18 23:52:38 +010093 gsmnet->a5_encryption = atoi(argv[0]);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +020094
95 return CMD_SUCCESS;
96}
97
Vadim Yanitskiy7f3724e2017-03-31 23:27:44 +070098DEFUN(cfg_net_dyn_ts_allow_tch_f,
99 cfg_net_dyn_ts_allow_tch_f_cmd,
100 "dyn_ts_allow_tch_f (0|1)",
101 "Allow or disallow allocating TCH/F on TCH_F_TCH_H_PDCH timeslots\n"
102 "Disallow TCH/F on TCH_F_TCH_H_PDCH (default)\n"
103 "Allow TCH/F on TCH_F_TCH_H_PDCH\n")
104{
105 struct gsm_network *gsmnet = gsmnet_from_vty(vty);
106 gsmnet->dyn_ts_allow_tch_f = atoi(argv[0]) ? true : false;
107 return CMD_SUCCESS;
108}
109
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200110DEFUN(cfg_net_timezone,
111 cfg_net_timezone_cmd,
112 "timezone <-19-19> (0|15|30|45)",
113 "Set the Timezone Offset of the network\n"
114 "Timezone offset (hours)\n"
115 "Timezone offset (00 minutes)\n"
116 "Timezone offset (15 minutes)\n"
117 "Timezone offset (30 minutes)\n"
118 "Timezone offset (45 minutes)\n"
119 )
120{
121 struct gsm_network *net = vty->index;
122 int tzhr = atoi(argv[0]);
123 int tzmn = atoi(argv[1]);
124
125 net->tz.hr = tzhr;
126 net->tz.mn = tzmn;
127 net->tz.dst = 0;
128 net->tz.override = 1;
129
130 return CMD_SUCCESS;
131}
132
133DEFUN(cfg_net_timezone_dst,
134 cfg_net_timezone_dst_cmd,
135 "timezone <-19-19> (0|15|30|45) <0-2>",
136 "Set the Timezone Offset of the network\n"
137 "Timezone offset (hours)\n"
138 "Timezone offset (00 minutes)\n"
139 "Timezone offset (15 minutes)\n"
140 "Timezone offset (30 minutes)\n"
141 "Timezone offset (45 minutes)\n"
142 "DST offset (hours)\n"
143 )
144{
145 struct gsm_network *net = vty->index;
146 int tzhr = atoi(argv[0]);
147 int tzmn = atoi(argv[1]);
148 int tzdst = atoi(argv[2]);
149
150 net->tz.hr = tzhr;
151 net->tz.mn = tzmn;
152 net->tz.dst = tzdst;
153 net->tz.override = 1;
154
155 return CMD_SUCCESS;
156}
157
158DEFUN(cfg_net_no_timezone,
159 cfg_net_no_timezone_cmd,
160 "no timezone",
161 NO_STR
162 "Disable network timezone override, use system tz\n")
163{
164 struct gsm_network *net = vty->index;
165
166 net->tz.override = 0;
167
168 return CMD_SUCCESS;
169}
170
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200171DEFUN(cfg_net_per_loc_upd, cfg_net_per_loc_upd_cmd,
172 "periodic location update <6-1530>",
173 "Periodic Location Updating Interval\n"
174 "Periodic Location Updating Interval\n"
175 "Periodic Location Updating Interval\n"
176 "Periodic Location Updating Interval in Minutes\n")
177{
178 struct gsm_network *net = vty->index;
179
180 net->t3212 = atoi(argv[0]) / 6;
181
182 return CMD_SUCCESS;
183}
184
185DEFUN(cfg_net_no_per_loc_upd, cfg_net_no_per_loc_upd_cmd,
186 "no periodic location update",
187 NO_STR
188 "Periodic Location Updating Interval\n"
189 "Periodic Location Updating Interval\n"
190 "Periodic Location Updating Interval\n")
191{
192 struct gsm_network *net = vty->index;
193
194 net->t3212 = 0;
195
196 return CMD_SUCCESS;
197}
198
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200199static struct gsm_network *vty_global_gsm_network = NULL;
200
201/* initialize VTY elements used in both BSC and MSC */
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200202int common_cs_vty_init(struct gsm_network *network,
203 int (* config_write_net )(struct vty *))
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200204{
205 OSMO_ASSERT(vty_global_gsm_network == NULL);
206 vty_global_gsm_network = network;
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200207
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200208 osmo_stats_vty_add_cmds();
209
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200210 install_element(CONFIG_NODE, &cfg_net_cmd);
211 install_node(&net_node, config_write_net);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200212 install_element(GSMNET_NODE, &cfg_net_ncc_cmd);
213 install_element(GSMNET_NODE, &cfg_net_mnc_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200214 install_element(GSMNET_NODE, &cfg_net_encryption_cmd);
Neels Hofmeyr640b7942016-05-14 03:24:41 +0200215 install_element(GSMNET_NODE, &cfg_net_timezone_cmd);
216 install_element(GSMNET_NODE, &cfg_net_timezone_dst_cmd);
217 install_element(GSMNET_NODE, &cfg_net_no_timezone_cmd);
Neels Hofmeyrce4d88b2017-05-08 15:12:20 +0200218 install_element(GSMNET_NODE, &cfg_net_per_loc_upd_cmd);
219 install_element(GSMNET_NODE, &cfg_net_no_per_loc_upd_cmd);
Vadim Yanitskiy7f3724e2017-03-31 23:27:44 +0700220 install_element(GSMNET_NODE, &cfg_net_dyn_ts_allow_tch_f_cmd);
Neels Hofmeyr06d39fd2016-05-12 01:16:58 +0200221
222 return CMD_SUCCESS;
Neels Hofmeyrb90eabf2016-05-11 18:48:39 +0200223}
224
225struct gsm_network *gsmnet_from_vty(struct vty *v)
226{
227 /* It can't hurt to force callers to continue to pass the vty instance
228 * to this function, in case we'd like to retrieve the global
229 * gsm_network instance from the vty at some point in the future. But
230 * until then, just return the global pointer, which should have been
231 * initialized by common_cs_vty_init().
232 */
233 OSMO_ASSERT(vty_global_gsm_network);
234 return vty_global_gsm_network;
235}