blob: bf8b7d4b0dfb58e5d2046fe7f1a621040c8b458e [file] [log] [blame]
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +01001/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
2/* The protocol implementation */
3
4/*
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +01005 * (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org>
6 * (C) 2009-2011 by On-Waves
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +01007 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +010010 * it under the terms of the GNU Affero General Public License as published by
11 * the Free Software Foundation; either version 3 of the License, or
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010012 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * GNU Affero General Public License for more details.
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010018 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010019 * You should have received a copy of the GNU Affero General Public License
20 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010021 *
22 */
23
24#include <sys/types.h>
25
Holger Hans Peter Freyther1ebad742010-02-26 20:16:37 +010026#include <osmocore/talloc.h>
27
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010028#include <openbsc/debug.h>
29#include <openbsc/mgcp.h>
30#include <openbsc/mgcp_internal.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020031#include <openbsc/vty.h>
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010032
Harald Welte4b037e42010-05-19 19:45:32 +020033#include <osmocom/vty/command.h>
34#include <osmocom/vty/vty.h>
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010035
Holger Hans Peter Freyther8d9833e2010-04-16 16:59:48 +020036#include <string.h>
37
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010038static struct mgcp_config *g_cfg = NULL;
39
40/*
41 * vty code for mgcp below
42 */
43struct cmd_node mgcp_node = {
44 MGCP_NODE,
45 "%s(mgcp)#",
46 1,
47};
48
49static int config_write_mgcp(struct vty *vty)
50{
51 vty_out(vty, "mgcp%s", VTY_NEWLINE);
52 if (g_cfg->local_ip)
Holger Hans Peter Freyther8d9833e2010-04-16 16:59:48 +020053 vty_out(vty, " local ip %s%s", g_cfg->local_ip, VTY_NEWLINE);
54 if (g_cfg->bts_ip && strlen(g_cfg->bts_ip) != 0)
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010055 vty_out(vty, " bts ip %s%s", g_cfg->bts_ip, VTY_NEWLINE);
56 vty_out(vty, " bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
57 vty_out(vty, " bind port %u%s", g_cfg->source_port, VTY_NEWLINE);
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +080058
59 if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC)
60 vty_out(vty, " rtp bts-base %u%s", g_cfg->bts_ports.base_port, VTY_NEWLINE);
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +080061 else
62 vty_out(vty, " rtp bts-range %u %u%s",
63 g_cfg->bts_ports.range_start, g_cfg->bts_ports.range_end, VTY_NEWLINE);
64
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +080065 if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC)
66 vty_out(vty, " rtp net-base %u%s", g_cfg->net_ports.base_port, VTY_NEWLINE);
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +080067 else
68 vty_out(vty, " rtp net-range %u %u%s",
69 g_cfg->net_ports.range_start, g_cfg->net_ports.range_end, VTY_NEWLINE);
70
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +080071 vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +010072 if (g_cfg->trunk.audio_payload != -1)
73 vty_out(vty, " sdp audio payload number %d%s",
74 g_cfg->trunk.audio_payload, VTY_NEWLINE);
75 if (g_cfg->trunk.audio_name)
76 vty_out(vty, " sdp audio payload name %s%s",
77 g_cfg->trunk.audio_name, VTY_NEWLINE);
78 vty_out(vty, " loop %u%s", !!g_cfg->trunk.audio_loop, VTY_NEWLINE);
79 vty_out(vty, " number endpoints %u%s", g_cfg->trunk.number_endpoints - 1, VTY_NEWLINE);
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +020080 if (g_cfg->call_agent_addr)
Holger Hans Peter Freyther8d9833e2010-04-16 16:59:48 +020081 vty_out(vty, " call agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE);
Holger Hans Peter Freythera2a10eb2010-09-17 03:58:52 +080082 if (g_cfg->transcoder_ip)
83 vty_out(vty, " transcoder-mgw %s%s", g_cfg->transcoder_ip, VTY_NEWLINE);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010084
Holger Hans Peter Freyther54aaa0f2010-09-17 23:35:53 +080085 if (g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC)
86 vty_out(vty, " rtp transcoder-base %u%s", g_cfg->transcoder_ports.base_port, VTY_NEWLINE);
87 else
88 vty_out(vty, " rtp transcoder-range %u %u%s",
89 g_cfg->transcoder_ports.range_start, g_cfg->transcoder_ports.range_end, VTY_NEWLINE);
Holger Hans Peter Freytherb98ba722010-09-19 04:21:39 +080090 vty_out(vty, " transcoder-remote-base %u%s", g_cfg->transcoder_remote_base, VTY_NEWLINE);
Holger Hans Peter Freyther54aaa0f2010-09-17 23:35:53 +080091
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010092 return CMD_SUCCESS;
93}
94
95DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp",
96 SHOW_STR "Display information about the MGCP Media Gateway")
97{
98 int i;
99
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100100 vty_out(vty, "MGCP is up and running with %u endpoints:%s",
101 g_cfg->trunk.number_endpoints - 1, VTY_NEWLINE);
102 for (i = 1; i < g_cfg->trunk.number_endpoints; ++i) {
103 struct mgcp_endpoint *endp = &g_cfg->trunk.endpoints[i];
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100104 vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s traffic received bts: %u/%u remote: %u/%u transcoder: %u/%u%s",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100105 i, endp->ci,
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +0800106 ntohs(endp->net_end.rtp_port), ntohs(endp->net_end.rtcp_port),
107 ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port),
108 inet_ntoa(endp->bts_end.addr),
109 endp->bts_end.packets, endp->bts_state.lost_no,
110 endp->net_end.packets, endp->net_state.lost_no,
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100111 endp->trans_net.packets, endp->trans_bts.packets,
Holger Hans Peter Freytherb4b135e2010-04-07 09:37:17 +0200112 VTY_NEWLINE);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100113 }
114
115 return CMD_SUCCESS;
116}
117
118DEFUN(cfg_mgcp,
119 cfg_mgcp_cmd,
120 "mgcp",
121 "Configure the MGCP")
122{
123 vty->node = MGCP_NODE;
124 return CMD_SUCCESS;
125}
126
127DEFUN(cfg_mgcp_local_ip,
128 cfg_mgcp_local_ip_cmd,
Holger Hans Peter Freyther1384af62010-05-14 02:27:50 +0800129 "local ip A.B.C.D",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100130 "Set the IP to be used in SDP records")
131{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200132 bsc_replace_string(g_cfg, &g_cfg->local_ip, argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100133 return CMD_SUCCESS;
134}
135
136DEFUN(cfg_mgcp_bts_ip,
137 cfg_mgcp_bts_ip_cmd,
Holger Hans Peter Freyther1384af62010-05-14 02:27:50 +0800138 "bts ip A.B.C.D",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100139 "Set the IP of the BTS for RTP forwarding")
140{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200141 bsc_replace_string(g_cfg, &g_cfg->bts_ip, argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100142 inet_aton(g_cfg->bts_ip, &g_cfg->bts_in);
143 return CMD_SUCCESS;
144}
145
146DEFUN(cfg_mgcp_bind_ip,
147 cfg_mgcp_bind_ip_cmd,
Holger Hans Peter Freyther1384af62010-05-14 02:27:50 +0800148 "bind ip A.B.C.D",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100149 "Bind the MGCP to this local addr")
150{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200151 bsc_replace_string(g_cfg, &g_cfg->source_addr, argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100152 return CMD_SUCCESS;
153}
154
155DEFUN(cfg_mgcp_bind_port,
156 cfg_mgcp_bind_port_cmd,
157 "bind port <0-65534>",
158 "Bind the MGCP to this port")
159{
160 unsigned int port = atoi(argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100161 g_cfg->source_port = port;
162 return CMD_SUCCESS;
163}
164
165DEFUN(cfg_mgcp_bind_early,
166 cfg_mgcp_bind_early_cmd,
167 "bind early (0|1)",
168 "Bind all RTP ports early")
169{
Holger Hans Peter Freytherf1a168d2010-08-05 03:22:24 +0800170 vty_out(vty, "bind early is deprecated, remove it from the config.\n");
171 return CMD_WARNING;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100172}
173
Holger Hans Peter Freytherc5f92482010-09-17 23:34:36 +0800174static void parse_base(struct mgcp_port_range *range, const char **argv)
175{
176 unsigned int port = atoi(argv[0]);
177 range->mode = PORT_ALLOC_STATIC;
178 range->base_port = port;
179}
180
181static void parse_range(struct mgcp_port_range *range, const char **argv)
182{
183 range->mode = PORT_ALLOC_DYNAMIC;
184 range->range_start = atoi(argv[0]);
185 range->range_end = atoi(argv[1]);
186 range->last_port = g_cfg->bts_ports.range_start;
187}
188
189
Holger Hans Peter Freyther196349d2010-08-05 03:46:07 +0800190DEFUN(cfg_mgcp_rtp_bts_base_port,
191 cfg_mgcp_rtp_bts_base_port_cmd,
192 "rtp bts-base <0-65534>",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100193 "Base port to use")
194{
Holger Hans Peter Freytherc5f92482010-09-17 23:34:36 +0800195 parse_base(&g_cfg->bts_ports, argv);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100196 return CMD_SUCCESS;
197}
198
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800199DEFUN(cfg_mgcp_rtp_bts_range,
200 cfg_mgcp_rtp_bts_range_cmd,
201 "rtp bts-range <0-65534> <0-65534>",
202 "Range of ports to allocate for endpoints\n"
203 "Start of the range of ports\n" "End of the range of ports\n")
204{
Holger Hans Peter Freytherc5f92482010-09-17 23:34:36 +0800205 parse_range(&g_cfg->bts_ports, argv);
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800206 return CMD_SUCCESS;
207}
208
209DEFUN(cfg_mgcp_rtp_net_range,
210 cfg_mgcp_rtp_net_range_cmd,
211 "rtp net-range <0-65534> <0-65534>",
212 "Range of ports to allocate for endpoints\n"
213 "Start of the range of ports\n" "End of the range of ports\n")
214{
Holger Hans Peter Freytherc5f92482010-09-17 23:34:36 +0800215 parse_range(&g_cfg->net_ports, argv);
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800216 return CMD_SUCCESS;
217}
218
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800219DEFUN(cfg_mgcp_rtp_net_base_port,
220 cfg_mgcp_rtp_net_base_port_cmd,
221 "rtp net-base <0-65534>",
222 "Base port to use for network port\n" "Port\n")
223{
Holger Hans Peter Freytherc5f92482010-09-17 23:34:36 +0800224 parse_base(&g_cfg->net_ports, argv);
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800225 return CMD_SUCCESS;
226}
227
Holger Hans Peter Freyther196349d2010-08-05 03:46:07 +0800228ALIAS_DEPRECATED(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_base_port_cmd,
229 "rtp base <0-65534>", "Base port to use")
230
Holger Hans Peter Freyther54aaa0f2010-09-17 23:35:53 +0800231DEFUN(cfg_mgcp_rtp_transcoder_range,
232 cfg_mgcp_rtp_transcoder_range_cmd,
233 "rtp transcoder-range <0-65534> <0-65534>",
234 "Range of ports to allocate for the transcoder\n"
235 "Start of the range of ports\n" "End of the range of ports\n")
236{
237 parse_range(&g_cfg->transcoder_ports, argv);
238 return CMD_SUCCESS;
239}
240
241DEFUN(cfg_mgcp_rtp_transcoder_base,
242 cfg_mgcp_rtp_transcoder_base_cmd,
243 "rtp transcoder-base <0-65534>",
244 "Base port for the transcoder range\n" "Port\n")
245{
246 parse_base(&g_cfg->transcoder_ports, argv);
247 return CMD_SUCCESS;
248}
249
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800250DEFUN(cfg_mgcp_rtp_ip_dscp,
251 cfg_mgcp_rtp_ip_dscp_cmd,
252 "rtp ip-dscp <0-255>",
253 "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.")
Holger Hans Peter Freyther75492e62010-05-31 10:22:00 +0800254{
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800255 int dscp = atoi(argv[0]);
256 g_cfg->endp_dscp = dscp;
Holger Hans Peter Freyther75492e62010-05-31 10:22:00 +0800257 return CMD_SUCCESS;
258}
259
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800260ALIAS_DEPRECATED(cfg_mgcp_rtp_ip_dscp, cfg_mgcp_rtp_ip_tos_cmd,
261 "rtp ip-tos <0-255>",
262 "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.")
263
264
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100265DEFUN(cfg_mgcp_sdp_payload_number,
266 cfg_mgcp_sdp_payload_number_cmd,
267 "sdp audio payload number <1-255>",
268 "Set the audio codec to use")
269{
270 unsigned int payload = atoi(argv[0]);
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100271 g_cfg->trunk.audio_payload = payload;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100272 return CMD_SUCCESS;
273}
274
275DEFUN(cfg_mgcp_sdp_payload_name,
276 cfg_mgcp_sdp_payload_name_cmd,
277 "sdp audio payload name NAME",
278 "Set the audio name to use")
279{
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100280 bsc_replace_string(g_cfg, &g_cfg->trunk.audio_name, argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100281 return CMD_SUCCESS;
282}
283
284DEFUN(cfg_mgcp_loop,
285 cfg_mgcp_loop_cmd,
286 "loop (0|1)",
287 "Loop the audio")
288{
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100289 g_cfg->trunk.audio_loop = atoi(argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100290 return CMD_SUCCESS;
291}
292
293DEFUN(cfg_mgcp_number_endp,
294 cfg_mgcp_number_endp_cmd,
295 "number endpoints <0-65534>",
296 "The number of endpoints to allocate. This is not dynamic.")
297{
298 /* + 1 as we start counting at one */
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100299 g_cfg->trunk.number_endpoints = atoi(argv[0]) + 1;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100300 return CMD_SUCCESS;
301}
302
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +0200303DEFUN(cfg_mgcp_agent_addr,
304 cfg_mgcp_agent_addr_cmd,
305 "call agent ip IP",
306 "Set the address of the call agent.")
307{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200308 bsc_replace_string(g_cfg, &g_cfg->call_agent_addr, argv[0]);
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +0200309 return CMD_SUCCESS;
310}
311
Holger Hans Peter Freythera2a10eb2010-09-17 03:58:52 +0800312DEFUN(cfg_mgcp_transcoder,
313 cfg_mgcp_transcoder_cmd,
314 "transcoder-mgw A.B.C.D",
315 "Use a MGW to detranscoder RTP\n"
316 "The IP address of the MGW")
317{
Holger Hans Peter Freyther3e9a7f82010-10-12 23:21:54 +0200318 bsc_replace_string(g_cfg, &g_cfg->transcoder_ip, argv[0]);
Holger Hans Peter Freythera2a10eb2010-09-17 03:58:52 +0800319 inet_aton(g_cfg->transcoder_ip, &g_cfg->transcoder_in);
320
321 return CMD_SUCCESS;
322}
323
Holger Hans Peter Freyther88b597e2010-11-01 20:06:45 +0100324DEFUN(cfg_mgcp_no_transcoder,
325 cfg_mgcp_no_transcoder_cmd,
326 NO_STR "transcoder-mgw",
327 "Disable the transcoding\n")
328{
329 if (g_cfg->transcoder_ip) {
330 LOGP(DMGCP, LOGL_NOTICE, "Disabling transcoding on future calls.\n");
331 talloc_free(g_cfg->transcoder_ip);
332 g_cfg->transcoder_ip = NULL;
333 }
334
335 return CMD_SUCCESS;
336}
337
Holger Hans Peter Freytherb98ba722010-09-19 04:21:39 +0800338DEFUN(cfg_mgcp_transcoder_remote_base,
339 cfg_mgcp_transcoder_remote_base_cmd,
340 "transcoder-remote-base <0-65534>",
341 "Set the base port for the transcoder\n" "The RTP base port on the transcoder")
342{
343 g_cfg->transcoder_remote_base = atoi(argv[0]);
344 return CMD_SUCCESS;
345}
346
347
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800348DEFUN(loop_endp,
349 loop_endp_cmd,
350 "loop-endpoint NAME (0|1)",
351 "Loop a given endpoint\n"
Holger Hans Peter Freytherebc824c2010-08-03 23:00:03 +0800352 "The name in hex of the endpoint\n" "Disable the loop\n" "Enable the loop\n")
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800353{
354 struct mgcp_endpoint *endp;
355
356 int endp_no = strtoul(argv[0], NULL, 16);
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100357 if (endp_no < 1 || endp_no >= g_cfg->trunk.number_endpoints) {
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800358 vty_out(vty, "Loopback number %s/%d is invalid.%s",
359 argv[0], endp_no, VTY_NEWLINE);
360 return CMD_WARNING;
361 }
362
363
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100364 endp = &g_cfg->trunk.endpoints[endp_no];
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800365 int loop = atoi(argv[1]);
366
367 if (loop)
368 endp->conn_mode = MGCP_CONN_LOOPBACK;
369 else
370 endp->conn_mode = endp->orig_mode;
Holger Hans Peter Freyther6357a8e2010-08-05 12:07:00 +0000371 endp->allow_patch = 1;
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800372
373 return CMD_SUCCESS;
374}
375
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800376DEFUN(tap_call,
377 tap_call_cmd,
378 "tap-call ENDPOINT (bts-in|bts-out|net-in|net-out) A.B.C.D <0-65534>",
379 "Forward data on endpoint to a different system\n"
380 "The endpoint in hex\n"
381 "Forward the data coming from the bts\n"
382 "Forward the data coming from the bts leaving to the network\n"
383 "Forward the data coming from the net\n"
384 "Forward the data coming from the net leaving to the bts\n"
385 "destination IP of the data\n" "destination port\n")
386{
387 struct mgcp_rtp_tap *tap;
388 struct mgcp_endpoint *endp;
389 int port = 0;
390
391 int endp_no = strtoul(argv[0], NULL, 16);
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100392 if (endp_no < 1 || endp_no >= g_cfg->trunk.number_endpoints) {
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800393 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
394 argv[0], endp_no, VTY_NEWLINE);
395 return CMD_WARNING;
396 }
397
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100398 endp = &g_cfg->trunk.endpoints[endp_no];
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800399
400 if (strcmp(argv[1], "bts-in") == 0) {
401 port = MGCP_TAP_BTS_IN;
402 } else if (strcmp(argv[1], "bts-out") == 0) {
403 port = MGCP_TAP_BTS_OUT;
404 } else if (strcmp(argv[1], "net-in") == 0) {
405 port = MGCP_TAP_NET_IN;
406 } else if (strcmp(argv[1], "net-out") == 0) {
407 port = MGCP_TAP_NET_OUT;
408 } else {
409 vty_out(vty, "Unknown mode... tricked vty?%s", VTY_NEWLINE);
410 return CMD_WARNING;
411 }
412
413 tap = &endp->taps[port];
414 memset(&tap->forward, 0, sizeof(tap->forward));
415 inet_aton(argv[2], &tap->forward.sin_addr);
416 tap->forward.sin_port = htons(atoi(argv[3]));
Holger Hans Peter Freyther0e01d092010-08-06 02:05:15 +0800417 tap->enabled = 1;
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800418 return CMD_SUCCESS;
419}
420
Holger Hans Peter Freyther5508fe32010-08-08 16:39:57 +0800421DEFUN(free_endp, free_endp_cmd,
422 "free-endpoint NUMBER",
423 "Free the given endpoint\n" "Endpoint number in hex.\n")
424{
425 struct mgcp_endpoint *endp;
426
427 int endp_no = strtoul(argv[0], NULL, 16);
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100428 if (endp_no < 1 || endp_no >= g_cfg->trunk.number_endpoints) {
Holger Hans Peter Freyther5508fe32010-08-08 16:39:57 +0800429 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
430 argv[0], endp_no, VTY_NEWLINE);
431 return CMD_WARNING;
432 }
433
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100434 endp = &g_cfg->trunk.endpoints[endp_no];
Holger Hans Peter Freyther5508fe32010-08-08 16:39:57 +0800435 mgcp_free_endp(endp);
436 return CMD_SUCCESS;
437}
438
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100439int mgcp_vty_init(void)
440{
Holger Hans Peter Freytherb5be7ac2010-05-14 02:45:52 +0800441 install_element_ve(&show_mgcp_cmd);
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800442 install_element(ENABLE_NODE, &loop_endp_cmd);
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800443 install_element(ENABLE_NODE, &tap_call_cmd);
Holger Hans Peter Freyther5508fe32010-08-08 16:39:57 +0800444 install_element(ENABLE_NODE, &free_endp_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100445
446 install_element(CONFIG_NODE, &cfg_mgcp_cmd);
447 install_node(&mgcp_node, config_write_mgcp);
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800448
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100449 install_default(MGCP_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200450 install_element(MGCP_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +0200451 install_element(MGCP_NODE, &ournode_end_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100452 install_element(MGCP_NODE, &cfg_mgcp_local_ip_cmd);
453 install_element(MGCP_NODE, &cfg_mgcp_bts_ip_cmd);
454 install_element(MGCP_NODE, &cfg_mgcp_bind_ip_cmd);
455 install_element(MGCP_NODE, &cfg_mgcp_bind_port_cmd);
456 install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd);
457 install_element(MGCP_NODE, &cfg_mgcp_rtp_base_port_cmd);
Holger Hans Peter Freyther196349d2010-08-05 03:46:07 +0800458 install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_base_port_cmd);
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800459 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_base_port_cmd);
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800460 install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_range_cmd);
461 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_range_cmd);
Holger Hans Peter Freyther54aaa0f2010-09-17 23:35:53 +0800462 install_element(MGCP_NODE, &cfg_mgcp_rtp_transcoder_range_cmd);
463 install_element(MGCP_NODE, &cfg_mgcp_rtp_transcoder_base_cmd);
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800464 install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);
Holger Hans Peter Freyther75492e62010-05-31 10:22:00 +0800465 install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100466 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd);
467 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd);
468 install_element(MGCP_NODE, &cfg_mgcp_loop_cmd);
469 install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd);
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +0200470 install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd);
Holger Hans Peter Freythera2a10eb2010-09-17 03:58:52 +0800471 install_element(MGCP_NODE, &cfg_mgcp_transcoder_cmd);
Holger Hans Peter Freyther88b597e2010-11-01 20:06:45 +0100472 install_element(MGCP_NODE, &cfg_mgcp_no_transcoder_cmd);
Holger Hans Peter Freytherb98ba722010-09-19 04:21:39 +0800473 install_element(MGCP_NODE, &cfg_mgcp_transcoder_remote_base_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100474 return 0;
475}
476
477int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
478{
479 int i, rc;
480
481 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200482 rc = vty_read_config_file(config_file, NULL);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100483 if (rc < 0) {
484 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
485 return rc;
486 }
487
488
489 if (!g_cfg->bts_ip)
490 fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n");
491
Holger Hans Peter Freyther95e4d342010-03-30 13:00:10 +0200492 if (!g_cfg->source_addr) {
493 fprintf(stderr, "You need to specify a bind address.\n");
494 return -1;
495 }
496
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100497 if (mgcp_endpoints_allocate(g_cfg) != 0) {
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100498 fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n",
499 g_cfg->trunk.number_endpoints);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100500 return -1;
501 }
502
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100503 /* early bind */
Holger Hans Peter Freyther88ad7722011-02-28 00:56:17 +0100504 for (i = 1; i < g_cfg->trunk.number_endpoints; ++i) {
505 struct mgcp_endpoint *endp = &g_cfg->trunk.endpoints[i];
Holger Hans Peter Freytherf1a168d2010-08-05 03:22:24 +0800506 int rtp_port;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100507
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800508 if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC) {
509 rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
510 g_cfg->bts_ports.base_port);
511 if (mgcp_bind_bts_rtp_port(endp, rtp_port) != 0) {
512 LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
513 return -1;
514 }
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +0800515 endp->bts_end.local_alloc = PORT_ALLOC_STATIC;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100516 }
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800517
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800518 if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC) {
519 rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
520 g_cfg->net_ports.base_port);
521 if (mgcp_bind_net_rtp_port(endp, rtp_port) != 0) {
522 LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
523 return -1;
524 }
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +0800525 endp->net_end.local_alloc = PORT_ALLOC_STATIC;
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800526 }
Holger Hans Peter Freyther218f8562010-09-18 02:30:02 +0800527
528 if (g_cfg->transcoder_ip && g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) {
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100529 /* network side */
Holger Hans Peter Freyther218f8562010-09-18 02:30:02 +0800530 rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
531 g_cfg->transcoder_ports.base_port);
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100532 if (mgcp_bind_trans_net_rtp_port(endp, rtp_port) != 0) {
Holger Hans Peter Freyther218f8562010-09-18 02:30:02 +0800533 LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
534 return -1;
535 }
Holger Hans Peter Freyther21262332010-11-01 20:53:31 +0100536 endp->trans_net.local_alloc = PORT_ALLOC_STATIC;
Holger Hans Peter Freytherbd7b3c52010-11-01 21:04:54 +0100537
538 /* bts side */
539 rtp_port = rtp_calculate_port(endp_back_channel(ENDPOINT_NUMBER(endp)),
540 g_cfg->transcoder_ports.base_port);
541 if (mgcp_bind_trans_bts_rtp_port(endp, rtp_port) != 0) {
542 LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
543 return -1;
544 }
545 endp->trans_bts.local_alloc = PORT_ALLOC_STATIC;
Holger Hans Peter Freyther218f8562010-09-18 02:30:02 +0800546 }
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100547 }
548
Holger Hans Peter Freyther8b5772e2010-08-05 01:28:22 +0800549 return 0;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100550}
551