blob: f3f711c0b997d6c011bbc816196c3f825bf875d5 [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 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 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 General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License along
18 * with this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 */
22
23#include <bsc_data.h>
24
25#include <osmocore/talloc.h>
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +080026#include <osmocore/gsm48.h>
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080027
28#include <osmocom/vty/command.h>
29#include <osmocom/vty/vty.h>
30
31#include <unistd.h>
32#include <netdb.h>
33
34#undef PACKAGE_NAME
35#undef PACKAGE_VERSION
36#undef PACKAGE_BUGREPORT
37#undef PACKAGE_TARNAME
38#undef PACKAGE_STRING
39#include <cellmgr_config.h>
40
41extern struct bsc_data bsc;
42
43static struct vty_app_info vty_info = {
44 .name = "Cellmgr-ng",
45 .version = VERSION,
46 .go_parent_cb = NULL,
47};
48
49/* vty code */
50enum cellmgr_node {
51 CELLMGR_NODE = _LAST_OSMOVTY_NODE,
52};
53
54static struct cmd_node cell_node = {
55 CELLMGR_NODE,
56 "%s(cellmgr)#",
57 1,
58};
59
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080060static int config_write_cell(struct vty *vty)
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080061{
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080062 vty_out(vty, "cellmgr%s", VTY_NEWLINE);
63 vty_out(vty, " mtp dpc %d%s", bsc.dpc, VTY_NEWLINE);
64 vty_out(vty, " mtp opc %d%s", bsc.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 Freytherb38b33b2010-11-26 21:21:04 +0100106DEFUN(cfg_net_mtp_ni, cfg_net_mtp_ni_cmd,
107 "mtp ni NR",
108 "Set the MTP NI to be used.\n" "NR")
109{
110 bsc.ni_ni = atoi(argv[0]);
111 return CMD_SUCCESS;
112}
113
114DEFUN(cfg_net_mtp_spare, cfg_net_mtp_spare_cmd,
115 "mtp spare NR",
116 "Set the MTP Spare to be used.\n" "NR")
117{
118 bsc.ni_spare = atoi(argv[0]);
119 return CMD_SUCCESS;
120}
121
122
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800123DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
124 "udp dest ip IP",
125 "Set the IP when UDP mode is supposed to be used.")
126{
127 struct hostent *hosts;
128 struct in_addr *addr;
129
130 hosts = gethostbyname(argv[0]);
131 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
132 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
133 return CMD_WARNING;
134 }
135
136 addr = (struct in_addr *) hosts->h_addr_list[0];
137 bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
138 return CMD_SUCCESS;
139}
140
141DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
142 "udp dest port PORT_NR",
143 "If UDP mode is used specify the UDP dest port")
144{
145 bsc.udp_port = atoi(argv[0]);
146 return CMD_SUCCESS;
147}
148
149DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
150 "udp src port PORT_NR",
151 "Set the UDP source port to be used.")
152{
153 bsc.src_port = atoi(argv[0]);
154 return CMD_SUCCESS;
155}
156
157DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
158 "udp reset TIMEOUT",
159 "Set the timeout to take the link down")
160{
161 bsc.link.udp.reset_timeout = atoi(argv[0]);
162 return CMD_SUCCESS;
163}
164
165DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
166 "mtp sltm once (0|1)",
167 "Send SLTMs until the link is established.")
168{
169 bsc.once = !!atoi(argv[0]);
170 return CMD_SUCCESS;
171}
172
173DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
174 "msc ip IP",
175 "Set the MSC IP")
176{
177 struct hostent *hosts;
178 struct in_addr *addr;
179
180 hosts = gethostbyname(argv[0]);
181 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
182 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
183 return CMD_WARNING;
184 }
185
186 addr = (struct in_addr *) hosts->h_addr_list[0];
187
188 bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr));
189 return CMD_SUCCESS;
190}
191
192DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
193 "msc ip-dscp <0-255>",
194 "Set the IP DSCP on the A-link\n"
195 "Set the DSCP in IP packets to the MSC")
196{
197 bsc.msc_ip_dscp = atoi(argv[0]);
198 return CMD_SUCCESS;
199}
200
201ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
202 "msc ip-tos <0-255>",
203 "Set the IP DSCP on the A-link\n"
204 "Set the DSCP in IP packets to the MSC")
205
206DEFUN(cfg_msc_token, cfg_msc_token_cmd,
207 "msc token TOKEN",
208 "Set the Token to be used for the MSC")
209{
210 bsc.token = talloc_strdup(NULL, argv[0]);
211 return CMD_SUCCESS;
212}
213
214DEFUN(cfg_ping_time, cfg_ping_time_cmd,
215 "timeout ping NR",
216 "Set the PING interval. Negative to disable it")
217{
218 bsc.ping_time = atoi(argv[0]);
219 return CMD_SUCCESS;
220}
221
222DEFUN(cfg_pong_time, cfg_pong_time_cmd,
223 "timeout pong NR",
224 "Set the PING interval. Negative to disable it")
225{
226 bsc.pong_time = atoi(argv[0]);
227 return CMD_SUCCESS;
228}
229
230DEFUN(cfg_msc_time, cfg_msc_time_cmd,
231 "timeout msc NR",
232 "Set the MSC connect timeout")
233{
234 bsc.msc_time = atoi(argv[0]);
235 return CMD_SUCCESS;
236}
237
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800238static void update_lai(struct bsc_data *bsc)
239{
240 gsm48_generate_lai(&bsc->lai, bsc->mcc, bsc->mnc, bsc->lac);
241}
242
243DEFUN(cfg_mnc, cfg_mnc_cmd,
244 "network-code NR",
245 "Set the Mobile Network Code\n" "Number\n")
246{
247 bsc.mnc = atoi(argv[0]);
248 update_lai(&bsc);
249 return CMD_SUCCESS;
250}
251
252DEFUN(cfg_mcc, cfg_mcc_cmd,
253 "country-code NR",
254 "Set the Mobile Country Code\n" "Number\n")
255{
256 bsc.mcc = atoi(argv[0]);
257 update_lai(&bsc);
258 return CMD_SUCCESS;
259}
260
261DEFUN(cfg_lac, cfg_lac_cmd,
262 "location-area-code NR",
263 "Set the Location Area Code\n" "Number\n")
264{
265 bsc.lac = atoi(argv[0]);
266 update_lai(&bsc);
267 return CMD_SUCCESS;
268}
269
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800270void cell_vty_init(void)
271{
272 cmd_init(1);
273 vty_init(&vty_info);
274
275 install_element(CONFIG_NODE, &cfg_cell_cmd);
276 install_node(&cell_node, config_write_cell);
277
278 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
279 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
Holger Hans Peter Freytherb38b33b2010-11-26 21:21:04 +0100280 install_element(CELLMGR_NODE, &cfg_net_mtp_ni_cmd);
281 install_element(CELLMGR_NODE, &cfg_net_mtp_spare_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800282 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
283 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
284 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
285 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
286 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
287 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
288 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
289 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
290 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
291 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
292 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
293 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800294 install_element(CELLMGR_NODE, &cfg_mcc_cmd);
295 install_element(CELLMGR_NODE, &cfg_mnc_cmd);
296 install_element(CELLMGR_NODE, &cfg_lac_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800297}
298
299const char *openbsc_copyright = "";