blob: 980dfa44b397ca8a03901c27205a4ef37c4d2af1 [file] [log] [blame]
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +08001/* Osmo BSC VTY Configuration */
2/* (C) 2009-2010 by Holger Hans Peter Freyther
Holger Hans Peter Freyther85531cc2010-10-06 20:37:09 +08003 * (C) 2009-2010 by On-Waves
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +08004 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080022#include <openbsc/gsm_data.h>
23#include <openbsc/osmo_msc_data.h>
24#include <openbsc/vty.h>
25
26#include <osmocore/talloc.h>
27
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +010028
29#define IPA_STR "IP.ACCESS specific\n"
30
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080031extern struct gsm_network *bsc_gsmnet;
32
33static struct osmo_msc_data *osmo_msc_data(struct vty *vty)
34{
35 return bsc_gsmnet->msc_data;
36}
37
38static struct cmd_node msc_node = {
39 MSC_NODE,
40 "%s(msc)#",
41 1,
42};
43
44DEFUN(cfg_net_msc, cfg_net_msc_cmd,
45 "msc", "Configure MSC details")
46{
47 vty->index = bsc_gsmnet;
48 vty->node = MSC_NODE;
49
50 return CMD_SUCCESS;
51}
52
53static int config_write_msc(struct vty *vty)
54{
55 struct osmo_msc_data *data = osmo_msc_data(vty);
56
57 vty_out(vty, " msc%s", VTY_NEWLINE);
58 if (data->bsc_token)
59 vty_out(vty, " token %s%s", data->bsc_token, VTY_NEWLINE);
Holger Hans Peter Freyther4de11162010-11-03 13:12:18 +010060 if (data->core_ncc != -1)
61 vty_out(vty, " core-mobile-network-code %d%s",
62 data->core_ncc, VTY_NEWLINE);
Holger Hans Peter Freyther2a8675e2010-11-05 19:43:07 +010063 if (data->core_mcc != -1)
64 vty_out(vty, " core-mobile-country-code %d%s",
65 data->core_mcc, VTY_NEWLINE);
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +010066 vty_out(vty, " ip.access rtp-base %d%s", data->rtp_base, VTY_NEWLINE);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080067 vty_out(vty, " ip %s%s", data->msc_ip, VTY_NEWLINE);
68 vty_out(vty, " port %d%s", data->msc_port, VTY_NEWLINE);
69 vty_out(vty, " ip-dscp %d%s", data->msc_ip_dscp, VTY_NEWLINE);
70 vty_out(vty, " timeout-ping %d%s", data->ping_timeout, VTY_NEWLINE);
71 vty_out(vty, " timeout-pong %d%s", data->pong_timeout, VTY_NEWLINE);
72 if (data->ussd_grace_txt)
73 vty_out(vty, "bsc-grace-text %s%s", data->ussd_grace_txt, VTY_NEWLINE);
Holger Hans Peter Freyther625b6e42010-11-22 18:25:02 +010074 vty_out(vty, " bsc-grace-timeout %d%s", data->ussd_grace_timeout, VTY_NEWLINE);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080075
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010076 if (data->audio_length != 0) {
77 int i;
78
79 vty_out(vty, " codec_list ");
80 for (i = 0; i < data->audio_length; ++i) {
81 if (i != 0)
82 vty_out(vty, ", ");
83
84 if (data->audio_support[i]->hr)
85 vty_out(vty, "hr%.1u", data->audio_support[i]->ver);
86 else
87 vty_out(vty, "fr%.1u", data->audio_support[i]->ver);
88 }
89 vty_out(vty, "%s", VTY_NEWLINE);
90
91 }
92
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080093 return CMD_SUCCESS;
94}
95
Holger Hans Peter Freyther5b848f32010-11-03 13:11:14 +010096DEFUN(cfg_net_bsc_token,
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080097 cfg_net_bsc_token_cmd,
98 "token TOKEN",
99 "A token for the BSC to be sent to the MSC")
100{
101 struct osmo_msc_data *data = osmo_msc_data(vty);
102
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200103 bsc_replace_string(data, &data->bsc_token, argv[0]);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800104 return CMD_SUCCESS;
105}
106
Holger Hans Peter Freyther4de11162010-11-03 13:12:18 +0100107DEFUN(cfg_net_bsc_ncc,
108 cfg_net_bsc_ncc_cmd,
109 "core-mobile-network-code <0-255>",
110 "Use this network code for the backbone\n" "NCC value\n")
111{
112 struct osmo_msc_data *data = osmo_msc_data(vty);
113 data->core_ncc = atoi(argv[0]);
114 return CMD_SUCCESS;
115}
116
Holger Hans Peter Freyther2a8675e2010-11-05 19:43:07 +0100117DEFUN(cfg_net_bsc_mcc,
118 cfg_net_bsc_mcc_cmd,
119 "core-mobile-country-code <0-255>",
120 "Use this country code for the backbone\n" "MCC value\n")
121{
122 struct osmo_msc_data *data = osmo_msc_data(vty);
123 data->core_mcc = atoi(argv[0]);
124 return CMD_SUCCESS;
125}
126
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +0100127DEFUN(cfg_net_bsc_rtp_base,
128 cfg_net_bsc_rtp_base_cmd,
129 "ip.access rtp-base <1-65000>",
130 IPA_STR
131 "Set the rtp-base port for the RTP stream\n"
132 "Port number\n")
133{
134 struct osmo_msc_data *data = osmo_msc_data(vty);
135 data->rtp_base = atoi(argv[0]);
136 return CMD_SUCCESS;
137}
138
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100139DEFUN(cfg_net_bsc_codec_list,
140 cfg_net_bsc_codec_list_cmd,
141 "codec-list .LIST",
142 "Set the allowed audio codecs\n"
143 "List of audio codecs\n")
144{
145 struct osmo_msc_data *data = osmo_msc_data(vty);
146 int saw_fr, saw_hr;
147 int i;
148
149 saw_fr = saw_hr = 0;
150
151 /* free the old list... if it exists */
152 if (data->audio_support) {
153 talloc_free(data->audio_support);
154 data->audio_support = NULL;
155 data->audio_length = 0;
156 }
157
158 /* create a new array */
159 data->audio_support =
160 talloc_zero_array(data, struct gsm_audio_support *, argc);
161 data->audio_length = argc;
162
163 for (i = 0; i < argc; ++i) {
164 /* check for hrX or frX */
165 if (strlen(argv[i]) != 3
166 || argv[i][1] != 'r'
167 || (argv[i][0] != 'h' && argv[i][0] != 'f')
168 || argv[i][2] < 0x30
169 || argv[i][2] > 0x39)
170 goto error;
171
172 data->audio_support[i] = talloc_zero(data->audio_support,
173 struct gsm_audio_support);
174 data->audio_support[i]->ver = atoi(argv[i] + 2);
175
176 if (strncmp("hr", argv[i], 2) == 0) {
177 data->audio_support[i]->hr = 1;
178 saw_hr = 1;
179 } else if (strncmp("fr", argv[i], 2) == 0) {
180 data->audio_support[i]->hr = 0;
181 saw_fr = 1;
182 }
183
184 if (saw_hr && saw_fr) {
185 vty_out(vty, "Can not have full-rate and half-rate codec.%s",
186 VTY_NEWLINE);
187 return CMD_ERR_INCOMPLETE;
188 }
189 }
190
191 return CMD_SUCCESS;
192
193error:
194 vty_out(vty, "Codec name must be hrX or frX. Was '%s'%s",
195 argv[i], VTY_NEWLINE);
196 return CMD_ERR_INCOMPLETE;
197}
198
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800199DEFUN(cfg_net_msc_ip,
200 cfg_net_msc_ip_cmd,
201 "ip A.B.C.D", "Set the MSC/MUX IP address.")
202{
203 struct osmo_msc_data *data = osmo_msc_data(vty);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800204
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200205 bsc_replace_string(data, &data->msc_ip, argv[0]);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800206 return CMD_SUCCESS;
207}
208
209DEFUN(cfg_net_msc_port,
210 cfg_net_msc_port_cmd,
211 "port <1-65000>",
212 "Set the MSC/MUX port.")
213{
214 struct osmo_msc_data *data = osmo_msc_data(vty);
215 data->msc_port = atoi(argv[0]);
216 return CMD_SUCCESS;
217}
218
219
220DEFUN(cfg_net_msc_prio,
221 cfg_net_msc_prio_cmd,
222 "ip-dscp <0-255>",
223 "Set the IP_TOS socket attribite")
224{
225 struct osmo_msc_data *data = osmo_msc_data(vty);
226 data->msc_ip_dscp = atoi(argv[0]);
227 return CMD_SUCCESS;
228}
229
230DEFUN(cfg_net_msc_ping_time,
231 cfg_net_msc_ping_time_cmd,
232 "timeout-ping NR",
233 "Set the PING interval, negative for not sending PING")
234{
235 struct osmo_msc_data *data = osmo_msc_data(vty);
236 data->ping_timeout = atoi(argv[0]);
237 return CMD_SUCCESS;
238}
239
240DEFUN(cfg_net_msc_pong_time,
241 cfg_net_msc_pong_time_cmd,
242 "timeout-pong NR",
243 "Set the time to wait for a PONG.")
244{
245 struct osmo_msc_data *data = osmo_msc_data(vty);
246 data->pong_timeout = atoi(argv[0]);
247 return CMD_SUCCESS;
248}
249
250DEFUN(cfg_net_msc_grace_ussd,
251 cfg_net_msc_grace_ussd_cmd,
252 "bsc-grace-text .TEXT",
253 "Set the USSD notifcation to be send.\n" "Text to be sent\n")
254{
255 struct osmo_msc_data *data = osmo_msc_data(vty);
256 char *txt = argv_concat(argv, argc, 1);
257 if (!txt)
258 return CMD_WARNING;
259
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200260 bsc_replace_string(data, &data->ussd_grace_txt, txt);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800261 talloc_free(txt);
262 return CMD_SUCCESS;
263}
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +0800264
Holger Hans Peter Freyther625b6e42010-11-22 18:25:02 +0100265DEFUN(cfg_net_msc_grace_timeout,
266 cfg_net_msc_grace_timeout_cmd,
267 "bsc-grace-timeout NR",
268 "Switch from Grace to Off in NR seconds.\n" "Timeout in seconds\n")
269{
270 struct osmo_msc_data *data = osmo_msc_data(vty);
271 data->ussd_grace_timeout = atoi(argv[0]);
272 return CMD_SUCCESS;
273}
274
275
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +0800276int bsc_vty_init_extra(void)
277{
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800278 install_element(GSMNET_NODE, &cfg_net_msc_cmd);
279 install_node(&msc_node, config_write_msc);
280 install_default(MSC_NODE);
281 install_element(MSC_NODE, &cfg_net_bsc_token_cmd);
Holger Hans Peter Freyther4de11162010-11-03 13:12:18 +0100282 install_element(MSC_NODE, &cfg_net_bsc_ncc_cmd);
Holger Hans Peter Freyther2a8675e2010-11-05 19:43:07 +0100283 install_element(MSC_NODE, &cfg_net_bsc_mcc_cmd);
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +0100284 install_element(MSC_NODE, &cfg_net_bsc_rtp_base_cmd);
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100285 install_element(MSC_NODE, &cfg_net_bsc_codec_list_cmd);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800286 install_element(MSC_NODE, &cfg_net_msc_ip_cmd);
287 install_element(MSC_NODE, &cfg_net_msc_port_cmd);
288 install_element(MSC_NODE, &cfg_net_msc_prio_cmd);
289 install_element(MSC_NODE, &cfg_net_msc_ping_time_cmd);
290 install_element(MSC_NODE, &cfg_net_msc_pong_time_cmd);
291 install_element(MSC_NODE, &cfg_net_msc_grace_ussd_cmd);
Holger Hans Peter Freyther625b6e42010-11-22 18:25:02 +0100292 install_element(MSC_NODE, &cfg_net_msc_grace_timeout_cmd);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800293
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +0800294 return 0;
295}