blob: 6ddf549cdeaf7350bb1585290d119f19c3391520 [file] [log] [blame]
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +08001/* VTY code for the Cellmgr */
2/*
3 * (C) 2010 by Holger Hans Peter Freyther <zecke@selfish.org>
4 * (C) 2010 by On-Waves
5 * All Rights Reserved
6 *
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +01007 * 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
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080010 * (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
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +010015 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080016 *
Holger Hans Peter Freytherde56c222011-01-16 17:45:14 +010017 * 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/>.
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080019 *
20 */
21
22#include <bsc_data.h>
23
24#include <osmocore/talloc.h>
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080025#include <osmocore/gsm48.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080026
27#include <osmocom/vty/command.h>
28#include <osmocom/vty/vty.h>
29
30#include <unistd.h>
31#include <netdb.h>
32
33#undef PACKAGE_NAME
34#undef PACKAGE_VERSION
35#undef PACKAGE_BUGREPORT
36#undef PACKAGE_TARNAME
37#undef PACKAGE_STRING
38#include <cellmgr_config.h>
39
40extern struct bsc_data bsc;
41
42static struct vty_app_info vty_info = {
43 .name = "Cellmgr-ng",
44 .version = VERSION,
45 .go_parent_cb = NULL,
46};
47
48/* vty code */
49enum cellmgr_node {
50 CELLMGR_NODE = _LAST_OSMOVTY_NODE,
51};
52
53static struct cmd_node cell_node = {
54 CELLMGR_NODE,
55 "%s(cellmgr)#",
56 1,
57};
58
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080059static int config_write_cell(struct vty *vty)
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080060{
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080061 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
62 vty_out(vty, " mtp dpc %d%s", bsc.dpc, VTY_NEWLINE);
63 vty_out(vty, " mtp opc %d%s", bsc.opc, VTY_NEWLINE);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +010064 vty_out(vty, " mtp sccp-opc %d%s", bsc.sccp_opc, VTY_NEWLINE);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +010065 vty_out(vty, " mtp ni %d%s", bsc.ni_ni, VTY_NEWLINE);
66 vty_out(vty, " mtp spare %d%s", bsc.ni_spare, VTY_NEWLINE);
Holger Hans Peter Freyther3bbb58b2010-11-26 21:25:38 +010067 vty_out(vty, " mtp sltm once %d%s", bsc.once, VTY_NEWLINE);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080068 vty_out(vty, " country-code %d%s", bsc.mcc, VTY_NEWLINE);
69 vty_out(vty, " network-code %d%s", bsc.mnc, VTY_NEWLINE);
70 vty_out(vty, " location-area-code %d%s", bsc.lac, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080071 if (bsc.udp_ip)
72 vty_out(vty, " udp dest ip %s%s", bsc.udp_ip, VTY_NEWLINE);
73 vty_out(vty, " udp dest port %d%s", bsc.udp_port, VTY_NEWLINE);
74 vty_out(vty, " udp src port %d%s", bsc.src_port, VTY_NEWLINE);
75 vty_out(vty, " udp reset %d%s", bsc.link.udp.reset_timeout, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080076 vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE);
77 vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE);
78 vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE);
79
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080080 return CMD_SUCCESS;
81}
82
83DEFUN(cfg_cell, cfg_cell_cmd,
84 "cellmgr", "Configure the Cellmgr")
85{
86 vty->node = CELLMGR_NODE;
87 return CMD_SUCCESS;
88}
89
90DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
91 "mtp dpc DPC_NR",
92 "Set the DPC to be used.")
93{
94 bsc.dpc = atoi(argv[0]);
95 return CMD_SUCCESS;
96}
97
98DEFUN(cfg_net_opc, cfg_net_opc_cmd,
99 "mtp opc OPC_NR",
100 "Set the OPC to be used.")
101{
102 bsc.opc = atoi(argv[0]);
103 return CMD_SUCCESS;
104}
105
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100106DEFUN(cfg_net_sccp_opc, cfg_net_sccp_opc_cmd,
107 "mtp sccp-opc OPC_NR",
108 "Set the SCCP OPC to be used.")
109{
110 bsc.sccp_opc = atoi(argv[0]);
111 return CMD_SUCCESS;
112}
113
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100114DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
115 "mtp ni NR",
116 "Set the MTP NI to be used.\n" "NR")
117{
118 bsc.ni_ni = atoi(argv[0]);
119 return CMD_SUCCESS;
120}
121
122DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
123 "mtp spare NR",
124 "Set the MTP Spare to be used.\n" "NR")
125{
126 bsc.ni_spare = atoi(argv[0]);
127 return CMD_SUCCESS;
128}
129
130
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800131DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
132 "udp dest ip IP",
133 "Set the IP when UDP mode is supposed to be used.")
134{
135 struct hostent *hosts;
136 struct in_addr *addr;
137
138 hosts = gethostbyname(argv[0]);
139 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
140 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
141 return CMD_WARNING;
142 }
143
144 addr = (struct in_addr *) hosts->h_addr_list[0];
145 bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
146 return CMD_SUCCESS;
147}
148
149DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
150 "udp dest port PORT_NR",
151 "If UDP mode is used specify the UDP dest port")
152{
153 bsc.udp_port = atoi(argv[0]);
154 return CMD_SUCCESS;
155}
156
157DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
158 "udp src port PORT_NR",
159 "Set the UDP source port to be used.")
160{
161 bsc.src_port = atoi(argv[0]);
162 return CMD_SUCCESS;
163}
164
165DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
166 "udp reset TIMEOUT",
167 "Set the timeout to take the link down")
168{
169 bsc.link.udp.reset_timeout = atoi(argv[0]);
170 return CMD_SUCCESS;
171}
172
173DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
174 "mtp sltm once (0|1)",
175 "Send SLTMs until the link is established.")
176{
177 bsc.once = !!atoi(argv[0]);
178 return CMD_SUCCESS;
179}
180
181DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
182 "msc ip IP",
183 "Set the MSC IP")
184{
185 struct hostent *hosts;
186 struct in_addr *addr;
187
188 hosts = gethostbyname(argv[0]);
189 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
190 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
191 return CMD_WARNING;
192 }
193
194 addr = (struct in_addr *) hosts->h_addr_list[0];
195
196 bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr));
197 return CMD_SUCCESS;
198}
199
200DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
201 "msc ip-dscp <0-255>",
202 "Set the IP DSCP on the A-link\n"
203 "Set the DSCP in IP packets to the MSC")
204{
205 bsc.msc_ip_dscp = atoi(argv[0]);
206 return CMD_SUCCESS;
207}
208
209ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
210 "msc ip-tos <0-255>",
211 "Set the IP DSCP on the A-link\n"
212 "Set the DSCP in IP packets to the MSC")
213
214DEFUN(cfg_msc_token, cfg_msc_token_cmd,
215 "msc token TOKEN",
216 "Set the Token to be used for the MSC")
217{
218 bsc.token = talloc_strdup(NULL, argv[0]);
219 return CMD_SUCCESS;
220}
221
222DEFUN(cfg_ping_time, cfg_ping_time_cmd,
223 "timeout ping NR",
224 "Set the PING interval. Negative to disable it")
225{
226 bsc.ping_time = atoi(argv[0]);
227 return CMD_SUCCESS;
228}
229
230DEFUN(cfg_pong_time, cfg_pong_time_cmd,
231 "timeout pong NR",
232 "Set the PING interval. Negative to disable it")
233{
234 bsc.pong_time = atoi(argv[0]);
235 return CMD_SUCCESS;
236}
237
238DEFUN(cfg_msc_time, cfg_msc_time_cmd,
239 "timeout msc NR",
240 "Set the MSC connect timeout")
241{
242 bsc.msc_time = atoi(argv[0]);
243 return CMD_SUCCESS;
244}
245
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800246static void update_lai(struct bsc_data *bsc)
247{
248 gsm48_generate_lai(&bsc->lai, bsc->mcc, bsc->mnc, bsc->lac);
249}
250
251DEFUN(cfg_mnc, cfg_mnc_cmd,
252 "network-code NR",
253 "Set the Mobile Network Code\n" "Number\n")
254{
255 bsc.mnc = atoi(argv[0]);
256 update_lai(&bsc);
257 return CMD_SUCCESS;
258}
259
260DEFUN(cfg_mcc, cfg_mcc_cmd,
261 "country-code NR",
262 "Set the Mobile Country Code\n" "Number\n")
263{
264 bsc.mcc = atoi(argv[0]);
265 update_lai(&bsc);
266 return CMD_SUCCESS;
267}
268
269DEFUN(cfg_lac, cfg_lac_cmd,
270 "location-area-code NR",
271 "Set the Location Area Code\n" "Number\n")
272{
273 bsc.lac = atoi(argv[0]);
274 update_lai(&bsc);
275 return CMD_SUCCESS;
276}
277
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800278void cell_vty_init(void)
279{
280 cmd_init(1);
281 vty_init(&vty_info);
282
283 install_element(CONFIG_NODE, &cfg_cell_cmd);
284 install_node(&cell_node, config_write_cell);
285
286 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
287 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
Holger Hans Peter Freyther7a725562011-01-01 13:34:58 +0100288 install_element(CELLMGR_NODE, &cfg_net_sccp_opc_cmd);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100289 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
290 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800291 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
292 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
293 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
294 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
295 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
296 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
297 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
298 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
299 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
300 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
301 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
302 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800303 install_element(CELLMGR_NODE, &cfg_mcc_cmd);
304 install_element(CELLMGR_NODE, &cfg_mnc_cmd);
305 install_element(CELLMGR_NODE, &cfg_lac_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800306}
307
308const char *openbsc_copyright = "";