blob: a76a7e103b0f209b46891e244bc7b42a9fac3505 [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 Freyther45f9e692010-11-03 13:21:02 +010066 vty_out(vty, " ip.access rtp-payload %d%s",
67 data->rtp_payload, VTY_NEWLINE);
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +010068 vty_out(vty, " ip.access rtp-base %d%s", data->rtp_base, VTY_NEWLINE);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080069 vty_out(vty, " ip %s%s", data->msc_ip, VTY_NEWLINE);
70 vty_out(vty, " port %d%s", data->msc_port, VTY_NEWLINE);
71 vty_out(vty, " ip-dscp %d%s", data->msc_ip_dscp, VTY_NEWLINE);
72 vty_out(vty, " timeout-ping %d%s", data->ping_timeout, VTY_NEWLINE);
73 vty_out(vty, " timeout-pong %d%s", data->pong_timeout, VTY_NEWLINE);
74 if (data->ussd_grace_txt)
75 vty_out(vty, "bsc-grace-text %s%s", data->ussd_grace_txt, VTY_NEWLINE);
76
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010077 if (data->audio_length != 0) {
78 int i;
79
80 vty_out(vty, " codec_list ");
81 for (i = 0; i < data->audio_length; ++i) {
82 if (i != 0)
83 vty_out(vty, ", ");
84
85 if (data->audio_support[i]->hr)
86 vty_out(vty, "hr%.1u", data->audio_support[i]->ver);
87 else
88 vty_out(vty, "fr%.1u", data->audio_support[i]->ver);
89 }
90 vty_out(vty, "%s", VTY_NEWLINE);
91
92 }
93
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080094 return CMD_SUCCESS;
95}
96
Holger Hans Peter Freyther5b848f32010-11-03 13:11:14 +010097DEFUN(cfg_net_bsc_token,
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080098 cfg_net_bsc_token_cmd,
99 "token TOKEN",
100 "A token for the BSC to be sent to the MSC")
101{
102 struct osmo_msc_data *data = osmo_msc_data(vty);
103
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200104 bsc_replace_string(data, &data->bsc_token, argv[0]);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800105 return CMD_SUCCESS;
106}
107
Holger Hans Peter Freyther4de11162010-11-03 13:12:18 +0100108DEFUN(cfg_net_bsc_ncc,
109 cfg_net_bsc_ncc_cmd,
110 "core-mobile-network-code <0-255>",
111 "Use this network code for the backbone\n" "NCC value\n")
112{
113 struct osmo_msc_data *data = osmo_msc_data(vty);
114 data->core_ncc = atoi(argv[0]);
115 return CMD_SUCCESS;
116}
117
Holger Hans Peter Freyther2a8675e2010-11-05 19:43:07 +0100118DEFUN(cfg_net_bsc_mcc,
119 cfg_net_bsc_mcc_cmd,
120 "core-mobile-country-code <0-255>",
121 "Use this country code for the backbone\n" "MCC value\n")
122{
123 struct osmo_msc_data *data = osmo_msc_data(vty);
124 data->core_mcc = atoi(argv[0]);
125 return CMD_SUCCESS;
126}
127
Holger Hans Peter Freyther45f9e692010-11-03 13:21:02 +0100128DEFUN(cfg_net_bsc_rtp_payload,
129 cfg_net_bsc_rtp_payload_cmd,
130 "ip.access rtp-payload <0-255>",
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +0100131 IPA_STR
Holger Hans Peter Freyther45f9e692010-11-03 13:21:02 +0100132 "Set the rtp-payload for the RTP stream\n"
133 "RTP payload number\n")
134{
135 struct osmo_msc_data *data = osmo_msc_data(vty);
136 data->rtp_payload = atoi(argv[0]);
137 return CMD_SUCCESS;
138}
139
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +0100140DEFUN(cfg_net_bsc_rtp_base,
141 cfg_net_bsc_rtp_base_cmd,
142 "ip.access rtp-base <1-65000>",
143 IPA_STR
144 "Set the rtp-base port for the RTP stream\n"
145 "Port number\n")
146{
147 struct osmo_msc_data *data = osmo_msc_data(vty);
148 data->rtp_base = atoi(argv[0]);
149 return CMD_SUCCESS;
150}
151
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100152DEFUN(cfg_net_bsc_codec_list,
153 cfg_net_bsc_codec_list_cmd,
154 "codec-list .LIST",
155 "Set the allowed audio codecs\n"
156 "List of audio codecs\n")
157{
158 struct osmo_msc_data *data = osmo_msc_data(vty);
159 int saw_fr, saw_hr;
160 int i;
161
162 saw_fr = saw_hr = 0;
163
164 /* free the old list... if it exists */
165 if (data->audio_support) {
166 talloc_free(data->audio_support);
167 data->audio_support = NULL;
168 data->audio_length = 0;
169 }
170
171 /* create a new array */
172 data->audio_support =
173 talloc_zero_array(data, struct gsm_audio_support *, argc);
174 data->audio_length = argc;
175
176 for (i = 0; i < argc; ++i) {
177 /* check for hrX or frX */
178 if (strlen(argv[i]) != 3
179 || argv[i][1] != 'r'
180 || (argv[i][0] != 'h' && argv[i][0] != 'f')
181 || argv[i][2] < 0x30
182 || argv[i][2] > 0x39)
183 goto error;
184
185 data->audio_support[i] = talloc_zero(data->audio_support,
186 struct gsm_audio_support);
187 data->audio_support[i]->ver = atoi(argv[i] + 2);
188
189 if (strncmp("hr", argv[i], 2) == 0) {
190 data->audio_support[i]->hr = 1;
191 saw_hr = 1;
192 } else if (strncmp("fr", argv[i], 2) == 0) {
193 data->audio_support[i]->hr = 0;
194 saw_fr = 1;
195 }
196
197 if (saw_hr && saw_fr) {
198 vty_out(vty, "Can not have full-rate and half-rate codec.%s",
199 VTY_NEWLINE);
200 return CMD_ERR_INCOMPLETE;
201 }
202 }
203
204 return CMD_SUCCESS;
205
206error:
207 vty_out(vty, "Codec name must be hrX or frX. Was '%s'%s",
208 argv[i], VTY_NEWLINE);
209 return CMD_ERR_INCOMPLETE;
210}
211
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800212DEFUN(cfg_net_msc_ip,
213 cfg_net_msc_ip_cmd,
214 "ip A.B.C.D", "Set the MSC/MUX IP address.")
215{
216 struct osmo_msc_data *data = osmo_msc_data(vty);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800217
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200218 bsc_replace_string(data, &data->msc_ip, argv[0]);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800219 return CMD_SUCCESS;
220}
221
222DEFUN(cfg_net_msc_port,
223 cfg_net_msc_port_cmd,
224 "port <1-65000>",
225 "Set the MSC/MUX port.")
226{
227 struct osmo_msc_data *data = osmo_msc_data(vty);
228 data->msc_port = atoi(argv[0]);
229 return CMD_SUCCESS;
230}
231
232
233DEFUN(cfg_net_msc_prio,
234 cfg_net_msc_prio_cmd,
235 "ip-dscp <0-255>",
236 "Set the IP_TOS socket attribite")
237{
238 struct osmo_msc_data *data = osmo_msc_data(vty);
239 data->msc_ip_dscp = atoi(argv[0]);
240 return CMD_SUCCESS;
241}
242
243DEFUN(cfg_net_msc_ping_time,
244 cfg_net_msc_ping_time_cmd,
245 "timeout-ping NR",
246 "Set the PING interval, negative for not sending PING")
247{
248 struct osmo_msc_data *data = osmo_msc_data(vty);
249 data->ping_timeout = atoi(argv[0]);
250 return CMD_SUCCESS;
251}
252
253DEFUN(cfg_net_msc_pong_time,
254 cfg_net_msc_pong_time_cmd,
255 "timeout-pong NR",
256 "Set the time to wait for a PONG.")
257{
258 struct osmo_msc_data *data = osmo_msc_data(vty);
259 data->pong_timeout = atoi(argv[0]);
260 return CMD_SUCCESS;
261}
262
263DEFUN(cfg_net_msc_grace_ussd,
264 cfg_net_msc_grace_ussd_cmd,
265 "bsc-grace-text .TEXT",
266 "Set the USSD notifcation to be send.\n" "Text to be sent\n")
267{
268 struct osmo_msc_data *data = osmo_msc_data(vty);
269 char *txt = argv_concat(argv, argc, 1);
270 if (!txt)
271 return CMD_WARNING;
272
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200273 bsc_replace_string(data, &data->ussd_grace_txt, txt);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800274 talloc_free(txt);
275 return CMD_SUCCESS;
276}
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +0800277
278int bsc_vty_init_extra(void)
279{
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800280 install_element(GSMNET_NODE, &cfg_net_msc_cmd);
281 install_node(&msc_node, config_write_msc);
282 install_default(MSC_NODE);
283 install_element(MSC_NODE, &cfg_net_bsc_token_cmd);
Holger Hans Peter Freyther4de11162010-11-03 13:12:18 +0100284 install_element(MSC_NODE, &cfg_net_bsc_ncc_cmd);
Holger Hans Peter Freyther2a8675e2010-11-05 19:43:07 +0100285 install_element(MSC_NODE, &cfg_net_bsc_mcc_cmd);
Holger Hans Peter Freyther45f9e692010-11-03 13:21:02 +0100286 install_element(MSC_NODE, &cfg_net_bsc_rtp_payload_cmd);
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +0100287 install_element(MSC_NODE, &cfg_net_bsc_rtp_base_cmd);
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100288 install_element(MSC_NODE, &cfg_net_bsc_codec_list_cmd);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800289 install_element(MSC_NODE, &cfg_net_msc_ip_cmd);
290 install_element(MSC_NODE, &cfg_net_msc_port_cmd);
291 install_element(MSC_NODE, &cfg_net_msc_prio_cmd);
292 install_element(MSC_NODE, &cfg_net_msc_ping_time_cmd);
293 install_element(MSC_NODE, &cfg_net_msc_pong_time_cmd);
294 install_element(MSC_NODE, &cfg_net_msc_grace_ussd_cmd);
295
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +0800296 return 0;
297}