blob: 6e24e1523ad75db9dfbf58b376a6242e36414ea5 [file] [log] [blame]
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +08001/* Osmo BSC VTY Configuration */
2/* (C) 2009-2010 by Holger Hans Peter Freyther
Holger Hans Peter Freyther51808442010-10-06 20:37:09 +08003 * (C) 2009-2010 by On-Waves
Holger Hans Peter Freyther58ef6e42010-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 Freyther8c4dca22010-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 Freyther7dcd8e32010-11-03 13:32:48 +010028
29#define IPA_STR "IP.ACCESS specific\n"
30
Holger Hans Peter Freyther8c4dca22010-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 Freyther21a1cf32010-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 Freyther3e0525f2010-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 Freyther7dcd8e32010-11-03 13:32:48 +010066 vty_out(vty, " ip.access rtp-base %d%s", data->rtp_base, VTY_NEWLINE);
Holger Hans Peter Freyther8c4dca22010-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);
74
Holger Hans Peter Freyther5ce65172010-11-03 13:55:49 +010075 if (data->audio_length != 0) {
76 int i;
77
78 vty_out(vty, " codec_list ");
79 for (i = 0; i < data->audio_length; ++i) {
80 if (i != 0)
81 vty_out(vty, ", ");
82
83 if (data->audio_support[i]->hr)
84 vty_out(vty, "hr%.1u", data->audio_support[i]->ver);
85 else
86 vty_out(vty, "fr%.1u", data->audio_support[i]->ver);
87 }
88 vty_out(vty, "%s", VTY_NEWLINE);
89
90 }
91
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +080092 return CMD_SUCCESS;
93}
94
Holger Hans Peter Freytherf3ce67d2010-11-03 13:11:14 +010095DEFUN(cfg_net_bsc_token,
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +080096 cfg_net_bsc_token_cmd,
97 "token TOKEN",
98 "A token for the BSC to be sent to the MSC")
99{
100 struct osmo_msc_data *data = osmo_msc_data(vty);
101
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200102 bsc_replace_string(data, &data->bsc_token, argv[0]);
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +0800103 return CMD_SUCCESS;
104}
105
Holger Hans Peter Freyther21a1cf32010-11-03 13:12:18 +0100106DEFUN(cfg_net_bsc_ncc,
107 cfg_net_bsc_ncc_cmd,
108 "core-mobile-network-code <0-255>",
109 "Use this network code for the backbone\n" "NCC value\n")
110{
111 struct osmo_msc_data *data = osmo_msc_data(vty);
112 data->core_ncc = atoi(argv[0]);
113 return CMD_SUCCESS;
114}
115
Holger Hans Peter Freyther3e0525f2010-11-05 19:43:07 +0100116DEFUN(cfg_net_bsc_mcc,
117 cfg_net_bsc_mcc_cmd,
118 "core-mobile-country-code <0-255>",
119 "Use this country code for the backbone\n" "MCC value\n")
120{
121 struct osmo_msc_data *data = osmo_msc_data(vty);
122 data->core_mcc = atoi(argv[0]);
123 return CMD_SUCCESS;
124}
125
Holger Hans Peter Freyther7dcd8e32010-11-03 13:32:48 +0100126DEFUN(cfg_net_bsc_rtp_base,
127 cfg_net_bsc_rtp_base_cmd,
128 "ip.access rtp-base <1-65000>",
129 IPA_STR
130 "Set the rtp-base port for the RTP stream\n"
131 "Port number\n")
132{
133 struct osmo_msc_data *data = osmo_msc_data(vty);
134 data->rtp_base = atoi(argv[0]);
135 return CMD_SUCCESS;
136}
137
Holger Hans Peter Freyther5ce65172010-11-03 13:55:49 +0100138DEFUN(cfg_net_bsc_codec_list,
139 cfg_net_bsc_codec_list_cmd,
140 "codec-list .LIST",
141 "Set the allowed audio codecs\n"
142 "List of audio codecs\n")
143{
144 struct osmo_msc_data *data = osmo_msc_data(vty);
145 int saw_fr, saw_hr;
146 int i;
147
148 saw_fr = saw_hr = 0;
149
150 /* free the old list... if it exists */
151 if (data->audio_support) {
152 talloc_free(data->audio_support);
153 data->audio_support = NULL;
154 data->audio_length = 0;
155 }
156
157 /* create a new array */
158 data->audio_support =
159 talloc_zero_array(data, struct gsm_audio_support *, argc);
160 data->audio_length = argc;
161
162 for (i = 0; i < argc; ++i) {
163 /* check for hrX or frX */
164 if (strlen(argv[i]) != 3
165 || argv[i][1] != 'r'
166 || (argv[i][0] != 'h' && argv[i][0] != 'f')
167 || argv[i][2] < 0x30
168 || argv[i][2] > 0x39)
169 goto error;
170
171 data->audio_support[i] = talloc_zero(data->audio_support,
172 struct gsm_audio_support);
173 data->audio_support[i]->ver = atoi(argv[i] + 2);
174
175 if (strncmp("hr", argv[i], 2) == 0) {
176 data->audio_support[i]->hr = 1;
177 saw_hr = 1;
178 } else if (strncmp("fr", argv[i], 2) == 0) {
179 data->audio_support[i]->hr = 0;
180 saw_fr = 1;
181 }
182
183 if (saw_hr && saw_fr) {
184 vty_out(vty, "Can not have full-rate and half-rate codec.%s",
185 VTY_NEWLINE);
186 return CMD_ERR_INCOMPLETE;
187 }
188 }
189
190 return CMD_SUCCESS;
191
192error:
193 vty_out(vty, "Codec name must be hrX or frX. Was '%s'%s",
194 argv[i], VTY_NEWLINE);
195 return CMD_ERR_INCOMPLETE;
196}
197
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +0800198DEFUN(cfg_net_msc_ip,
199 cfg_net_msc_ip_cmd,
200 "ip A.B.C.D", "Set the MSC/MUX IP address.")
201{
202 struct osmo_msc_data *data = osmo_msc_data(vty);
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +0800203
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200204 bsc_replace_string(data, &data->msc_ip, argv[0]);
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +0800205 return CMD_SUCCESS;
206}
207
208DEFUN(cfg_net_msc_port,
209 cfg_net_msc_port_cmd,
210 "port <1-65000>",
211 "Set the MSC/MUX port.")
212{
213 struct osmo_msc_data *data = osmo_msc_data(vty);
214 data->msc_port = atoi(argv[0]);
215 return CMD_SUCCESS;
216}
217
218
219DEFUN(cfg_net_msc_prio,
220 cfg_net_msc_prio_cmd,
221 "ip-dscp <0-255>",
222 "Set the IP_TOS socket attribite")
223{
224 struct osmo_msc_data *data = osmo_msc_data(vty);
225 data->msc_ip_dscp = atoi(argv[0]);
226 return CMD_SUCCESS;
227}
228
229DEFUN(cfg_net_msc_ping_time,
230 cfg_net_msc_ping_time_cmd,
231 "timeout-ping NR",
232 "Set the PING interval, negative for not sending PING")
233{
234 struct osmo_msc_data *data = osmo_msc_data(vty);
235 data->ping_timeout = atoi(argv[0]);
236 return CMD_SUCCESS;
237}
238
239DEFUN(cfg_net_msc_pong_time,
240 cfg_net_msc_pong_time_cmd,
241 "timeout-pong NR",
242 "Set the time to wait for a PONG.")
243{
244 struct osmo_msc_data *data = osmo_msc_data(vty);
245 data->pong_timeout = atoi(argv[0]);
246 return CMD_SUCCESS;
247}
248
249DEFUN(cfg_net_msc_grace_ussd,
250 cfg_net_msc_grace_ussd_cmd,
251 "bsc-grace-text .TEXT",
252 "Set the USSD notifcation to be send.\n" "Text to be sent\n")
253{
254 struct osmo_msc_data *data = osmo_msc_data(vty);
255 char *txt = argv_concat(argv, argc, 1);
256 if (!txt)
257 return CMD_WARNING;
258
Holger Hans Peter Freyther7c831f62010-10-12 23:21:54 +0200259 bsc_replace_string(data, &data->ussd_grace_txt, txt);
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +0800260 talloc_free(txt);
261 return CMD_SUCCESS;
262}
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +0800263
264int bsc_vty_init_extra(void)
265{
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +0800266 install_element(GSMNET_NODE, &cfg_net_msc_cmd);
267 install_node(&msc_node, config_write_msc);
268 install_default(MSC_NODE);
269 install_element(MSC_NODE, &cfg_net_bsc_token_cmd);
Holger Hans Peter Freyther21a1cf32010-11-03 13:12:18 +0100270 install_element(MSC_NODE, &cfg_net_bsc_ncc_cmd);
Holger Hans Peter Freyther3e0525f2010-11-05 19:43:07 +0100271 install_element(MSC_NODE, &cfg_net_bsc_mcc_cmd);
Holger Hans Peter Freyther7dcd8e32010-11-03 13:32:48 +0100272 install_element(MSC_NODE, &cfg_net_bsc_rtp_base_cmd);
Holger Hans Peter Freyther5ce65172010-11-03 13:55:49 +0100273 install_element(MSC_NODE, &cfg_net_bsc_codec_list_cmd);
Holger Hans Peter Freyther8c4dca22010-09-15 23:28:49 +0800274 install_element(MSC_NODE, &cfg_net_msc_ip_cmd);
275 install_element(MSC_NODE, &cfg_net_msc_port_cmd);
276 install_element(MSC_NODE, &cfg_net_msc_prio_cmd);
277 install_element(MSC_NODE, &cfg_net_msc_ping_time_cmd);
278 install_element(MSC_NODE, &cfg_net_msc_pong_time_cmd);
279 install_element(MSC_NODE, &cfg_net_msc_grace_ussd_cmd);
280
Holger Hans Peter Freyther58ef6e42010-06-30 14:59:23 +0800281 return 0;
282}