blob: b1c006cb80e3137b61457f8653a5c25c3a3f4953 [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/*
5 * (C) 2009-2010 by Holger Hans Peter Freyther <zecke@selfish.org>
6 * (C) 2009-2010 by On-Waves
7 * All Rights Reserved
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (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
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
22 *
23 */
24
25#include <sys/types.h>
26
Holger Hans Peter Freyther1ebad742010-02-26 20:16:37 +010027#include <osmocore/talloc.h>
28
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010029#include <openbsc/debug.h>
30#include <openbsc/mgcp.h>
31#include <openbsc/mgcp_internal.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020032#include <openbsc/vty.h>
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010033
Harald Welte4b037e42010-05-19 19:45:32 +020034#include <osmocom/vty/command.h>
35#include <osmocom/vty/vty.h>
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010036
Holger Hans Peter Freyther8d9833e2010-04-16 16:59:48 +020037#include <string.h>
38
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010039static struct mgcp_config *g_cfg = NULL;
40
41/*
42 * vty code for mgcp below
43 */
44struct cmd_node mgcp_node = {
45 MGCP_NODE,
46 "%s(mgcp)#",
47 1,
48};
49
50static int config_write_mgcp(struct vty *vty)
51{
52 vty_out(vty, "mgcp%s", VTY_NEWLINE);
53 if (g_cfg->local_ip)
Holger Hans Peter Freyther8d9833e2010-04-16 16:59:48 +020054 vty_out(vty, " local ip %s%s", g_cfg->local_ip, VTY_NEWLINE);
55 if (g_cfg->bts_ip && strlen(g_cfg->bts_ip) != 0)
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010056 vty_out(vty, " bts ip %s%s", g_cfg->bts_ip, VTY_NEWLINE);
57 vty_out(vty, " bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
58 vty_out(vty, " bind port %u%s", g_cfg->source_port, VTY_NEWLINE);
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +080059
60 if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC)
61 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 +080062 else
63 vty_out(vty, " rtp bts-range %u %u%s",
64 g_cfg->bts_ports.range_start, g_cfg->bts_ports.range_end, VTY_NEWLINE);
65
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +080066 if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC)
67 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 +080068 else
69 vty_out(vty, " rtp net-range %u %u%s",
70 g_cfg->net_ports.range_start, g_cfg->net_ports.range_end, VTY_NEWLINE);
71
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +080072 vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
Holger Hans Peter Freyther2d425052010-04-13 09:28:40 +020073 if (g_cfg->audio_payload != -1)
74 vty_out(vty, " sdp audio payload number %d%s", g_cfg->audio_payload, VTY_NEWLINE);
75 if (g_cfg->audio_name)
76 vty_out(vty, " sdp audio payload name %s%s", g_cfg->audio_name, VTY_NEWLINE);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010077 vty_out(vty, " loop %u%s", !!g_cfg->audio_loop, VTY_NEWLINE);
Holger Hans Peter Freyther8d9833e2010-04-16 16:59:48 +020078 vty_out(vty, " number endpoints %u%s", g_cfg->number_endpoints - 1, VTY_NEWLINE);
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +020079 if (g_cfg->call_agent_addr)
Holger Hans Peter Freyther8d9833e2010-04-16 16:59:48 +020080 vty_out(vty, " call agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE);
Holger Hans Peter Freythera2a10eb2010-09-17 03:58:52 +080081 if (g_cfg->transcoder_ip)
82 vty_out(vty, " transcoder-mgw %s%s", g_cfg->transcoder_ip, VTY_NEWLINE);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010083
84 return CMD_SUCCESS;
85}
86
87DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp",
88 SHOW_STR "Display information about the MGCP Media Gateway")
89{
90 int i;
91
92 vty_out(vty, "MGCP is up and running with %u endpoints:%s", g_cfg->number_endpoints - 1, VTY_NEWLINE);
93 for (i = 1; i < g_cfg->number_endpoints; ++i) {
94 struct mgcp_endpoint *endp = &g_cfg->endpoints[i];
Holger Hans Peter Freyther1aa42462010-07-29 02:43:14 +080095 vty_out(vty, " Endpoint 0x%.2x: CI: %d net: %u/%u bts: %u/%u on %s traffic received bts: %u/%u remote: %u/%u%s",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +010096 i, endp->ci,
Holger Hans Peter Freythera17d7012010-08-05 01:34:51 +080097 ntohs(endp->net_end.rtp_port), ntohs(endp->net_end.rtcp_port),
98 ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port),
99 inet_ntoa(endp->bts_end.addr),
100 endp->bts_end.packets, endp->bts_state.lost_no,
101 endp->net_end.packets, endp->net_state.lost_no,
Holger Hans Peter Freytherb4b135e2010-04-07 09:37:17 +0200102 VTY_NEWLINE);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100103 }
104
105 return CMD_SUCCESS;
106}
107
108DEFUN(cfg_mgcp,
109 cfg_mgcp_cmd,
110 "mgcp",
111 "Configure the MGCP")
112{
113 vty->node = MGCP_NODE;
114 return CMD_SUCCESS;
115}
116
117DEFUN(cfg_mgcp_local_ip,
118 cfg_mgcp_local_ip_cmd,
Holger Hans Peter Freyther1384af62010-05-14 02:27:50 +0800119 "local ip A.B.C.D",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100120 "Set the IP to be used in SDP records")
121{
122 if (g_cfg->local_ip)
123 talloc_free(g_cfg->local_ip);
124 g_cfg->local_ip = talloc_strdup(g_cfg, argv[0]);
125 return CMD_SUCCESS;
126}
127
128DEFUN(cfg_mgcp_bts_ip,
129 cfg_mgcp_bts_ip_cmd,
Holger Hans Peter Freyther1384af62010-05-14 02:27:50 +0800130 "bts ip A.B.C.D",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100131 "Set the IP of the BTS for RTP forwarding")
132{
133 if (g_cfg->bts_ip)
134 talloc_free(g_cfg->bts_ip);
135 g_cfg->bts_ip = talloc_strdup(g_cfg, argv[0]);
136 inet_aton(g_cfg->bts_ip, &g_cfg->bts_in);
137 return CMD_SUCCESS;
138}
139
140DEFUN(cfg_mgcp_bind_ip,
141 cfg_mgcp_bind_ip_cmd,
Holger Hans Peter Freyther1384af62010-05-14 02:27:50 +0800142 "bind ip A.B.C.D",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100143 "Bind the MGCP to this local addr")
144{
145 if (g_cfg->source_addr)
146 talloc_free(g_cfg->source_addr);
147 g_cfg->source_addr = talloc_strdup(g_cfg, argv[0]);
148 return CMD_SUCCESS;
149}
150
151DEFUN(cfg_mgcp_bind_port,
152 cfg_mgcp_bind_port_cmd,
153 "bind port <0-65534>",
154 "Bind the MGCP to this port")
155{
156 unsigned int port = atoi(argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100157 g_cfg->source_port = port;
158 return CMD_SUCCESS;
159}
160
161DEFUN(cfg_mgcp_bind_early,
162 cfg_mgcp_bind_early_cmd,
163 "bind early (0|1)",
164 "Bind all RTP ports early")
165{
Holger Hans Peter Freytherf1a168d2010-08-05 03:22:24 +0800166 vty_out(vty, "bind early is deprecated, remove it from the config.\n");
167 return CMD_WARNING;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100168}
169
Holger Hans Peter Freyther196349d2010-08-05 03:46:07 +0800170DEFUN(cfg_mgcp_rtp_bts_base_port,
171 cfg_mgcp_rtp_bts_base_port_cmd,
172 "rtp bts-base <0-65534>",
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100173 "Base port to use")
174{
175 unsigned int port = atoi(argv[0]);
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +0800176 g_cfg->bts_ports.mode = PORT_ALLOC_STATIC;
177 g_cfg->bts_ports.base_port = port;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100178 return CMD_SUCCESS;
179}
180
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800181DEFUN(cfg_mgcp_rtp_bts_range,
182 cfg_mgcp_rtp_bts_range_cmd,
183 "rtp bts-range <0-65534> <0-65534>",
184 "Range of ports to allocate for endpoints\n"
185 "Start of the range of ports\n" "End of the range of ports\n")
186{
187 g_cfg->bts_ports.mode = PORT_ALLOC_DYNAMIC;
188 g_cfg->bts_ports.range_start = atoi(argv[0]);
189 g_cfg->bts_ports.range_end = atoi(argv[1]);
190 g_cfg->bts_ports.last_port = g_cfg->bts_ports.range_start;
191 return CMD_SUCCESS;
192}
193
194DEFUN(cfg_mgcp_rtp_net_range,
195 cfg_mgcp_rtp_net_range_cmd,
196 "rtp net-range <0-65534> <0-65534>",
197 "Range of ports to allocate for endpoints\n"
198 "Start of the range of ports\n" "End of the range of ports\n")
199{
200 g_cfg->net_ports.mode = PORT_ALLOC_DYNAMIC;
201 g_cfg->net_ports.range_start = atoi(argv[0]);
202 g_cfg->net_ports.range_end = atoi(argv[1]);
203 g_cfg->net_ports.last_port = g_cfg->net_ports.range_start;
204 return CMD_SUCCESS;
205}
206
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800207DEFUN(cfg_mgcp_rtp_net_base_port,
208 cfg_mgcp_rtp_net_base_port_cmd,
209 "rtp net-base <0-65534>",
210 "Base port to use for network port\n" "Port\n")
211{
212 unsigned int port = atoi(argv[0]);
Holger Hans Peter Freyther15e73892010-08-05 07:10:56 +0800213 g_cfg->net_ports.mode = PORT_ALLOC_STATIC;
214 g_cfg->net_ports.base_port = port;
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800215 return CMD_SUCCESS;
216}
217
Holger Hans Peter Freyther196349d2010-08-05 03:46:07 +0800218ALIAS_DEPRECATED(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_base_port_cmd,
219 "rtp base <0-65534>", "Base port to use")
220
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800221DEFUN(cfg_mgcp_rtp_ip_dscp,
222 cfg_mgcp_rtp_ip_dscp_cmd,
223 "rtp ip-dscp <0-255>",
224 "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.")
Holger Hans Peter Freyther75492e62010-05-31 10:22:00 +0800225{
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800226 int dscp = atoi(argv[0]);
227 g_cfg->endp_dscp = dscp;
Holger Hans Peter Freyther75492e62010-05-31 10:22:00 +0800228 return CMD_SUCCESS;
229}
230
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800231ALIAS_DEPRECATED(cfg_mgcp_rtp_ip_dscp, cfg_mgcp_rtp_ip_tos_cmd,
232 "rtp ip-tos <0-255>",
233 "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.")
234
235
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100236DEFUN(cfg_mgcp_sdp_payload_number,
237 cfg_mgcp_sdp_payload_number_cmd,
238 "sdp audio payload number <1-255>",
239 "Set the audio codec to use")
240{
241 unsigned int payload = atoi(argv[0]);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100242 g_cfg->audio_payload = payload;
243 return CMD_SUCCESS;
244}
245
246DEFUN(cfg_mgcp_sdp_payload_name,
247 cfg_mgcp_sdp_payload_name_cmd,
248 "sdp audio payload name NAME",
249 "Set the audio name to use")
250{
251 if (g_cfg->audio_name)
252 talloc_free(g_cfg->audio_name);
253 g_cfg->audio_name = talloc_strdup(g_cfg, argv[0]);
254 return CMD_SUCCESS;
255}
256
257DEFUN(cfg_mgcp_loop,
258 cfg_mgcp_loop_cmd,
259 "loop (0|1)",
260 "Loop the audio")
261{
262 g_cfg->audio_loop = atoi(argv[0]);
263 return CMD_SUCCESS;
264}
265
266DEFUN(cfg_mgcp_number_endp,
267 cfg_mgcp_number_endp_cmd,
268 "number endpoints <0-65534>",
269 "The number of endpoints to allocate. This is not dynamic.")
270{
271 /* + 1 as we start counting at one */
272 g_cfg->number_endpoints = atoi(argv[0]) + 1;
273 return CMD_SUCCESS;
274}
275
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +0200276DEFUN(cfg_mgcp_agent_addr,
277 cfg_mgcp_agent_addr_cmd,
278 "call agent ip IP",
279 "Set the address of the call agent.")
280{
281 if (g_cfg->call_agent_addr)
282 talloc_free(g_cfg->call_agent_addr);
283 g_cfg->call_agent_addr = talloc_strdup(g_cfg, argv[0]);
284 return CMD_SUCCESS;
285}
286
Holger Hans Peter Freythera2a10eb2010-09-17 03:58:52 +0800287DEFUN(cfg_mgcp_transcoder,
288 cfg_mgcp_transcoder_cmd,
289 "transcoder-mgw A.B.C.D",
290 "Use a MGW to detranscoder RTP\n"
291 "The IP address of the MGW")
292{
293 if (g_cfg->transcoder_ip)
294 talloc_free(g_cfg->transcoder_ip);
295 g_cfg->transcoder_ip = talloc_strdup(g_cfg, argv[0]);
296 inet_aton(g_cfg->transcoder_ip, &g_cfg->transcoder_in);
297
298 return CMD_SUCCESS;
299}
300
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800301DEFUN(loop_endp,
302 loop_endp_cmd,
303 "loop-endpoint NAME (0|1)",
304 "Loop a given endpoint\n"
Holger Hans Peter Freytherebc824c2010-08-03 23:00:03 +0800305 "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 +0800306{
307 struct mgcp_endpoint *endp;
308
309 int endp_no = strtoul(argv[0], NULL, 16);
310 if (endp_no < 1 || endp_no >= g_cfg->number_endpoints) {
311 vty_out(vty, "Loopback number %s/%d is invalid.%s",
312 argv[0], endp_no, VTY_NEWLINE);
313 return CMD_WARNING;
314 }
315
316
317 endp = &g_cfg->endpoints[endp_no];
318 int loop = atoi(argv[1]);
319
320 if (loop)
321 endp->conn_mode = MGCP_CONN_LOOPBACK;
322 else
323 endp->conn_mode = endp->orig_mode;
Holger Hans Peter Freyther6357a8e2010-08-05 12:07:00 +0000324 endp->allow_patch = 1;
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800325
326 return CMD_SUCCESS;
327}
328
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800329DEFUN(tap_call,
330 tap_call_cmd,
331 "tap-call ENDPOINT (bts-in|bts-out|net-in|net-out) A.B.C.D <0-65534>",
332 "Forward data on endpoint to a different system\n"
333 "The endpoint in hex\n"
334 "Forward the data coming from the bts\n"
335 "Forward the data coming from the bts leaving to the network\n"
336 "Forward the data coming from the net\n"
337 "Forward the data coming from the net leaving to the bts\n"
338 "destination IP of the data\n" "destination port\n")
339{
340 struct mgcp_rtp_tap *tap;
341 struct mgcp_endpoint *endp;
342 int port = 0;
343
344 int endp_no = strtoul(argv[0], NULL, 16);
345 if (endp_no < 1 || endp_no >= g_cfg->number_endpoints) {
346 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
347 argv[0], endp_no, VTY_NEWLINE);
348 return CMD_WARNING;
349 }
350
351 endp = &g_cfg->endpoints[endp_no];
352
353 if (strcmp(argv[1], "bts-in") == 0) {
354 port = MGCP_TAP_BTS_IN;
355 } else if (strcmp(argv[1], "bts-out") == 0) {
356 port = MGCP_TAP_BTS_OUT;
357 } else if (strcmp(argv[1], "net-in") == 0) {
358 port = MGCP_TAP_NET_IN;
359 } else if (strcmp(argv[1], "net-out") == 0) {
360 port = MGCP_TAP_NET_OUT;
361 } else {
362 vty_out(vty, "Unknown mode... tricked vty?%s", VTY_NEWLINE);
363 return CMD_WARNING;
364 }
365
366 tap = &endp->taps[port];
367 memset(&tap->forward, 0, sizeof(tap->forward));
368 inet_aton(argv[2], &tap->forward.sin_addr);
369 tap->forward.sin_port = htons(atoi(argv[3]));
Holger Hans Peter Freyther0e01d092010-08-06 02:05:15 +0800370 tap->enabled = 1;
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800371 return CMD_SUCCESS;
372}
373
Holger Hans Peter Freyther5508fe32010-08-08 16:39:57 +0800374DEFUN(free_endp, free_endp_cmd,
375 "free-endpoint NUMBER",
376 "Free the given endpoint\n" "Endpoint number in hex.\n")
377{
378 struct mgcp_endpoint *endp;
379
380 int endp_no = strtoul(argv[0], NULL, 16);
381 if (endp_no < 1 || endp_no >= g_cfg->number_endpoints) {
382 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
383 argv[0], endp_no, VTY_NEWLINE);
384 return CMD_WARNING;
385 }
386
387 endp = &g_cfg->endpoints[endp_no];
388 mgcp_free_endp(endp);
389 return CMD_SUCCESS;
390}
391
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100392int mgcp_vty_init(void)
393{
Holger Hans Peter Freytherb5be7ac2010-05-14 02:45:52 +0800394 install_element_ve(&show_mgcp_cmd);
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800395 install_element(ENABLE_NODE, &loop_endp_cmd);
Holger Hans Peter Freyther260d6ed2010-08-06 01:12:21 +0800396 install_element(ENABLE_NODE, &tap_call_cmd);
Holger Hans Peter Freyther5508fe32010-08-08 16:39:57 +0800397 install_element(ENABLE_NODE, &free_endp_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100398
399 install_element(CONFIG_NODE, &cfg_mgcp_cmd);
400 install_node(&mgcp_node, config_write_mgcp);
Holger Hans Peter Freytherc597a4e2010-08-03 02:57:02 +0800401
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100402 install_default(MGCP_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200403 install_element(MGCP_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +0200404 install_element(MGCP_NODE, &ournode_end_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100405 install_element(MGCP_NODE, &cfg_mgcp_local_ip_cmd);
406 install_element(MGCP_NODE, &cfg_mgcp_bts_ip_cmd);
407 install_element(MGCP_NODE, &cfg_mgcp_bind_ip_cmd);
408 install_element(MGCP_NODE, &cfg_mgcp_bind_port_cmd);
409 install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd);
410 install_element(MGCP_NODE, &cfg_mgcp_rtp_base_port_cmd);
Holger Hans Peter Freyther196349d2010-08-05 03:46:07 +0800411 install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_base_port_cmd);
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800412 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_base_port_cmd);
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800413 install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_range_cmd);
414 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_range_cmd);
Holger Hans Peter Freytherd0c32292010-07-27 20:34:45 +0800415 install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);
Holger Hans Peter Freyther75492e62010-05-31 10:22:00 +0800416 install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100417 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd);
418 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd);
419 install_element(MGCP_NODE, &cfg_mgcp_loop_cmd);
420 install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd);
Holger Hans Peter Freytherb79994c2010-03-31 11:46:41 +0200421 install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd);
Holger Hans Peter Freythera2a10eb2010-09-17 03:58:52 +0800422 install_element(MGCP_NODE, &cfg_mgcp_transcoder_cmd);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100423 return 0;
424}
425
426int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg)
427{
428 int i, rc;
429
430 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200431 rc = vty_read_config_file(config_file, NULL);
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100432 if (rc < 0) {
433 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
434 return rc;
435 }
436
437
438 if (!g_cfg->bts_ip)
439 fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n");
440
Holger Hans Peter Freyther95e4d342010-03-30 13:00:10 +0200441 if (!g_cfg->source_addr) {
442 fprintf(stderr, "You need to specify a bind address.\n");
443 return -1;
444 }
445
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100446 if (mgcp_endpoints_allocate(g_cfg) != 0) {
447 fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n", g_cfg->number_endpoints);
448 return -1;
449 }
450
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100451 /* early bind */
Holger Hans Peter Freytherf1a168d2010-08-05 03:22:24 +0800452 for (i = 1; i < g_cfg->number_endpoints; ++i) {
453 struct mgcp_endpoint *endp = &g_cfg->endpoints[i];
454 int rtp_port;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100455
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800456 if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC) {
457 rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
458 g_cfg->bts_ports.base_port);
459 if (mgcp_bind_bts_rtp_port(endp, rtp_port) != 0) {
460 LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
461 return -1;
462 }
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +0800463 endp->bts_end.local_alloc = PORT_ALLOC_STATIC;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100464 }
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800465
Holger Hans Peter Freyther1be9f2f2010-08-05 07:20:09 +0800466 if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC) {
467 rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp),
468 g_cfg->net_ports.base_port);
469 if (mgcp_bind_net_rtp_port(endp, rtp_port) != 0) {
470 LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port);
471 return -1;
472 }
Holger Hans Peter Freytherf138f912010-08-05 08:08:17 +0800473 endp->net_end.local_alloc = PORT_ALLOC_STATIC;
Holger Hans Peter Freyther314584a2010-08-05 04:10:21 +0800474 }
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100475 }
476
Holger Hans Peter Freyther8b5772e2010-08-05 01:28:22 +0800477 return 0;
Holger Hans Peter Freyther7bdc6372010-02-20 21:21:02 +0100478}
479