blob: ba6bc1e958b903d897223d906a7b493325de2d88 [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 Freyther45f9e692010-11-03 13:21:02 +010063 vty_out(vty, " ip.access rtp-payload %d%s",
64 data->rtp_payload, VTY_NEWLINE);
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +010065 vty_out(vty, " ip.access rtp-base %d%s", data->rtp_base, VTY_NEWLINE);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080066 vty_out(vty, " ip %s%s", data->msc_ip, VTY_NEWLINE);
67 vty_out(vty, " port %d%s", data->msc_port, VTY_NEWLINE);
68 vty_out(vty, " ip-dscp %d%s", data->msc_ip_dscp, VTY_NEWLINE);
69 vty_out(vty, " timeout-ping %d%s", data->ping_timeout, VTY_NEWLINE);
70 vty_out(vty, " timeout-pong %d%s", data->pong_timeout, VTY_NEWLINE);
71 if (data->ussd_grace_txt)
72 vty_out(vty, "bsc-grace-text %s%s", data->ussd_grace_txt, VTY_NEWLINE);
73
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +010074 if (data->audio_length != 0) {
75 int i;
76
77 vty_out(vty, " codec_list ");
78 for (i = 0; i < data->audio_length; ++i) {
79 if (i != 0)
80 vty_out(vty, ", ");
81
82 if (data->audio_support[i]->hr)
83 vty_out(vty, "hr%.1u", data->audio_support[i]->ver);
84 else
85 vty_out(vty, "fr%.1u", data->audio_support[i]->ver);
86 }
87 vty_out(vty, "%s", VTY_NEWLINE);
88
89 }
90
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080091 return CMD_SUCCESS;
92}
93
Holger Hans Peter Freyther5b848f32010-11-03 13:11:14 +010094DEFUN(cfg_net_bsc_token,
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +080095 cfg_net_bsc_token_cmd,
96 "token TOKEN",
97 "A token for the BSC to be sent to the MSC")
98{
99 struct osmo_msc_data *data = osmo_msc_data(vty);
100
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200101 bsc_replace_string(data, &data->bsc_token, argv[0]);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800102 return CMD_SUCCESS;
103}
104
Holger Hans Peter Freyther4de11162010-11-03 13:12:18 +0100105DEFUN(cfg_net_bsc_ncc,
106 cfg_net_bsc_ncc_cmd,
107 "core-mobile-network-code <0-255>",
108 "Use this network code for the backbone\n" "NCC value\n")
109{
110 struct osmo_msc_data *data = osmo_msc_data(vty);
111 data->core_ncc = atoi(argv[0]);
112 return CMD_SUCCESS;
113}
114
Holger Hans Peter Freyther45f9e692010-11-03 13:21:02 +0100115DEFUN(cfg_net_bsc_rtp_payload,
116 cfg_net_bsc_rtp_payload_cmd,
117 "ip.access rtp-payload <0-255>",
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +0100118 IPA_STR
Holger Hans Peter Freyther45f9e692010-11-03 13:21:02 +0100119 "Set the rtp-payload for the RTP stream\n"
120 "RTP payload number\n")
121{
122 struct osmo_msc_data *data = osmo_msc_data(vty);
123 data->rtp_payload = 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
265int bsc_vty_init_extra(void)
266{
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800267 install_element(GSMNET_NODE, &cfg_net_msc_cmd);
268 install_node(&msc_node, config_write_msc);
269 install_default(MSC_NODE);
270 install_element(MSC_NODE, &cfg_net_bsc_token_cmd);
Holger Hans Peter Freyther4de11162010-11-03 13:12:18 +0100271 install_element(MSC_NODE, &cfg_net_bsc_ncc_cmd);
Holger Hans Peter Freyther45f9e692010-11-03 13:21:02 +0100272 install_element(MSC_NODE, &cfg_net_bsc_rtp_payload_cmd);
Holger Hans Peter Freytherfe166222010-11-03 13:32:48 +0100273 install_element(MSC_NODE, &cfg_net_bsc_rtp_base_cmd);
Holger Hans Peter Freyther7bf66c52010-11-03 13:55:49 +0100274 install_element(MSC_NODE, &cfg_net_bsc_codec_list_cmd);
Holger Hans Peter Freyther47b26012010-09-15 23:28:49 +0800275 install_element(MSC_NODE, &cfg_net_msc_ip_cmd);
276 install_element(MSC_NODE, &cfg_net_msc_port_cmd);
277 install_element(MSC_NODE, &cfg_net_msc_prio_cmd);
278 install_element(MSC_NODE, &cfg_net_msc_ping_time_cmd);
279 install_element(MSC_NODE, &cfg_net_msc_pong_time_cmd);
280 install_element(MSC_NODE, &cfg_net_msc_grace_ussd_cmd);
281
Holger Hans Peter Freythercacbc732010-06-30 14:59:23 +0800282 return 0;
283}