blob: f1ac86ee59514f290992c2c9aac0c35306366004 [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 Freyther0e4e35f2010-09-30 03:04:28 +080065 vty_out(vty, " country-code %d%s", bsc.mcc, VTY_NEWLINE);
66 vty_out(vty, " network-code %d%s", bsc.mnc, VTY_NEWLINE);
67 vty_out(vty, " location-area-code %d%s", bsc.lac, VTY_NEWLINE);
Holger Hans Peter Freyther2656e8f2010-09-30 00:41:37 +080068 if (bsc.udp_ip)
69 vty_out(vty, " udp dest ip %s%s", bsc.udp_ip, VTY_NEWLINE);
70 vty_out(vty, " udp dest port %d%s", bsc.udp_port, VTY_NEWLINE);
71 vty_out(vty, " udp src port %d%s", bsc.src_port, VTY_NEWLINE);
72 vty_out(vty, " udp reset %d%s", bsc.link.udp.reset_timeout, VTY_NEWLINE);
73 vty_out(vty, " mtp sltm once %d%s", bsc.once, VTY_NEWLINE);
74 vty_out(vty, " msc ip %s%s", bsc.msc_address, VTY_NEWLINE);
75 vty_out(vty, " msc ip-dscp %d%s", bsc.msc_ip_dscp, VTY_NEWLINE);
76 vty_out(vty, " msc token %s%s", bsc.token, VTY_NEWLINE);
77
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +080078 return CMD_SUCCESS;
79}
80
81DEFUN(cfg_cell, cfg_cell_cmd,
82 "cellmgr", "Configure the Cellmgr")
83{
84 vty->node = CELLMGR_NODE;
85 return CMD_SUCCESS;
86}
87
88DEFUN(cfg_net_dpc, cfg_net_dpc_cmd,
89 "mtp dpc DPC_NR",
90 "Set the DPC to be used.")
91{
92 bsc.dpc = atoi(argv[0]);
93 return CMD_SUCCESS;
94}
95
96DEFUN(cfg_net_opc, cfg_net_opc_cmd,
97 "mtp opc OPC_NR",
98 "Set the OPC to be used.")
99{
100 bsc.opc = atoi(argv[0]);
101 return CMD_SUCCESS;
102}
103
104DEFUN(cfg_udp_dst_ip, cfg_udp_dst_ip_cmd,
105 "udp dest ip IP",
106 "Set the IP when UDP mode is supposed to be used.")
107{
108 struct hostent *hosts;
109 struct in_addr *addr;
110
111 hosts = gethostbyname(argv[0]);
112 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
113 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
114 return CMD_WARNING;
115 }
116
117 addr = (struct in_addr *) hosts->h_addr_list[0];
118 bsc.udp_ip = talloc_strdup(NULL, inet_ntoa(*addr));
119 return CMD_SUCCESS;
120}
121
122DEFUN(cfg_udp_dst_port, cfg_udp_dst_port_cmd,
123 "udp dest port PORT_NR",
124 "If UDP mode is used specify the UDP dest port")
125{
126 bsc.udp_port = atoi(argv[0]);
127 return CMD_SUCCESS;
128}
129
130DEFUN(cfg_udp_src_port, cfg_udp_src_port_cmd,
131 "udp src port PORT_NR",
132 "Set the UDP source port to be used.")
133{
134 bsc.src_port = atoi(argv[0]);
135 return CMD_SUCCESS;
136}
137
138DEFUN(cfg_udp_reset, cfg_udp_reset_cmd,
139 "udp reset TIMEOUT",
140 "Set the timeout to take the link down")
141{
142 bsc.link.udp.reset_timeout = atoi(argv[0]);
143 return CMD_SUCCESS;
144}
145
146DEFUN(cfg_sltm_once, cfg_sltm_once_cmd,
147 "mtp sltm once (0|1)",
148 "Send SLTMs until the link is established.")
149{
150 bsc.once = !!atoi(argv[0]);
151 return CMD_SUCCESS;
152}
153
154DEFUN(cfg_msc_ip, cfg_msc_ip_cmd,
155 "msc ip IP",
156 "Set the MSC IP")
157{
158 struct hostent *hosts;
159 struct in_addr *addr;
160
161 hosts = gethostbyname(argv[0]);
162 if (!hosts || hosts->h_length < 1 || hosts->h_addrtype != AF_INET) {
163 vty_out(vty, "Failed to resolve '%s'%s", argv[0], VTY_NEWLINE);
164 return CMD_WARNING;
165 }
166
167 addr = (struct in_addr *) hosts->h_addr_list[0];
168
169 bsc.msc_address = talloc_strdup(NULL, inet_ntoa(*addr));
170 return CMD_SUCCESS;
171}
172
173DEFUN(cfg_msc_ip_dscp, cfg_msc_ip_dscp_cmd,
174 "msc ip-dscp <0-255>",
175 "Set the IP DSCP on the A-link\n"
176 "Set the DSCP in IP packets to the MSC")
177{
178 bsc.msc_ip_dscp = atoi(argv[0]);
179 return CMD_SUCCESS;
180}
181
182ALIAS_DEPRECATED(cfg_msc_ip_dscp, cfg_msc_ip_tos_cmd,
183 "msc ip-tos <0-255>",
184 "Set the IP DSCP on the A-link\n"
185 "Set the DSCP in IP packets to the MSC")
186
187DEFUN(cfg_msc_token, cfg_msc_token_cmd,
188 "msc token TOKEN",
189 "Set the Token to be used for the MSC")
190{
191 bsc.token = talloc_strdup(NULL, argv[0]);
192 return CMD_SUCCESS;
193}
194
195DEFUN(cfg_ping_time, cfg_ping_time_cmd,
196 "timeout ping NR",
197 "Set the PING interval. Negative to disable it")
198{
199 bsc.ping_time = atoi(argv[0]);
200 return CMD_SUCCESS;
201}
202
203DEFUN(cfg_pong_time, cfg_pong_time_cmd,
204 "timeout pong NR",
205 "Set the PING interval. Negative to disable it")
206{
207 bsc.pong_time = atoi(argv[0]);
208 return CMD_SUCCESS;
209}
210
211DEFUN(cfg_msc_time, cfg_msc_time_cmd,
212 "timeout msc NR",
213 "Set the MSC connect timeout")
214{
215 bsc.msc_time = atoi(argv[0]);
216 return CMD_SUCCESS;
217}
218
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800219static void update_lai(struct bsc_data *bsc)
220{
221 gsm48_generate_lai(&bsc->lai, bsc->mcc, bsc->mnc, bsc->lac);
222}
223
224DEFUN(cfg_mnc, cfg_mnc_cmd,
225 "network-code NR",
226 "Set the Mobile Network Code\n" "Number\n")
227{
228 bsc.mnc = atoi(argv[0]);
229 update_lai(&bsc);
230 return CMD_SUCCESS;
231}
232
233DEFUN(cfg_mcc, cfg_mcc_cmd,
234 "country-code NR",
235 "Set the Mobile Country Code\n" "Number\n")
236{
237 bsc.mcc = atoi(argv[0]);
238 update_lai(&bsc);
239 return CMD_SUCCESS;
240}
241
242DEFUN(cfg_lac, cfg_lac_cmd,
243 "location-area-code NR",
244 "Set the Location Area Code\n" "Number\n")
245{
246 bsc.lac = atoi(argv[0]);
247 update_lai(&bsc);
248 return CMD_SUCCESS;
249}
250
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800251void cell_vty_init(void)
252{
253 cmd_init(1);
254 vty_init(&vty_info);
255
256 install_element(CONFIG_NODE, &cfg_cell_cmd);
257 install_node(&cell_node, config_write_cell);
258
259 install_element(CELLMGR_NODE, &cfg_net_dpc_cmd);
260 install_element(CELLMGR_NODE, &cfg_net_opc_cmd);
261 install_element(CELLMGR_NODE, &cfg_udp_dst_ip_cmd);
262 install_element(CELLMGR_NODE, &cfg_udp_dst_port_cmd);
263 install_element(CELLMGR_NODE, &cfg_udp_src_port_cmd);
264 install_element(CELLMGR_NODE, &cfg_udp_reset_cmd);
265 install_element(CELLMGR_NODE, &cfg_sltm_once_cmd);
266 install_element(CELLMGR_NODE, &cfg_msc_ip_cmd);
267 install_element(CELLMGR_NODE, &cfg_msc_token_cmd);
268 install_element(CELLMGR_NODE, &cfg_msc_ip_dscp_cmd);
269 install_element(CELLMGR_NODE, &cfg_msc_ip_tos_cmd);
270 install_element(CELLMGR_NODE, &cfg_ping_time_cmd);
271 install_element(CELLMGR_NODE, &cfg_pong_time_cmd);
272 install_element(CELLMGR_NODE, &cfg_msc_time_cmd);
Holger Hans Peter Freyther0e4e35f2010-09-30 03:04:28 +0800273 install_element(CELLMGR_NODE, &cfg_mcc_cmd);
274 install_element(CELLMGR_NODE, &cfg_mnc_cmd);
275 install_element(CELLMGR_NODE, &cfg_lac_cmd);
Holger Hans Peter Freyther7942abc2010-09-30 00:34:46 +0800276}
277
278const char *openbsc_copyright = "";