Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 1 | /* 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 Freyther | 1ebad74 | 2010-02-26 20:16:37 +0100 | [diff] [blame] | 27 | #include <osmocore/talloc.h> |
| 28 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 29 | #include <openbsc/debug.h> |
| 30 | #include <openbsc/mgcp.h> |
| 31 | #include <openbsc/mgcp_internal.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 32 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 33 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 34 | #include <osmocom/vty/command.h> |
| 35 | #include <osmocom/vty/vty.h> |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 37 | #include <string.h> |
| 38 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 39 | static struct mgcp_config *g_cfg = NULL; |
| 40 | |
| 41 | /* |
| 42 | * vty code for mgcp below |
| 43 | */ |
| 44 | struct cmd_node mgcp_node = { |
| 45 | MGCP_NODE, |
| 46 | "%s(mgcp)#", |
| 47 | 1, |
| 48 | }; |
| 49 | |
| 50 | static 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 Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 54 | 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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 56 | 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); |
| 59 | vty_out(vty, " bind early %u%s", !!g_cfg->early_bind, VTY_NEWLINE); |
| 60 | vty_out(vty, " rtp base %u%s", g_cfg->rtp_base_port, VTY_NEWLINE); |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 61 | vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE); |
Holger Hans Peter Freyther | 2d42505 | 2010-04-13 09:28:40 +0200 | [diff] [blame] | 62 | if (g_cfg->audio_payload != -1) |
| 63 | vty_out(vty, " sdp audio payload number %d%s", g_cfg->audio_payload, VTY_NEWLINE); |
| 64 | if (g_cfg->audio_name) |
| 65 | vty_out(vty, " sdp audio payload name %s%s", g_cfg->audio_name, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 66 | vty_out(vty, " loop %u%s", !!g_cfg->audio_loop, VTY_NEWLINE); |
Holger Hans Peter Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 67 | vty_out(vty, " number endpoints %u%s", g_cfg->number_endpoints - 1, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 68 | if (g_cfg->forward_ip) |
Holger Hans Peter Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 69 | vty_out(vty, " forward audio ip %s%s", g_cfg->forward_ip, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 70 | if (g_cfg->forward_port != 0) |
Holger Hans Peter Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 71 | vty_out(vty, " forward audio port %d%s", g_cfg->forward_port, VTY_NEWLINE); |
Holger Hans Peter Freyther | b79994c | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 72 | if (g_cfg->call_agent_addr) |
Holger Hans Peter Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 73 | vty_out(vty, " call agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 74 | |
| 75 | return CMD_SUCCESS; |
| 76 | } |
| 77 | |
| 78 | DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp", |
| 79 | SHOW_STR "Display information about the MGCP Media Gateway") |
| 80 | { |
| 81 | int i; |
| 82 | |
| 83 | vty_out(vty, "MGCP is up and running with %u endpoints:%s", g_cfg->number_endpoints - 1, VTY_NEWLINE); |
| 84 | for (i = 1; i < g_cfg->number_endpoints; ++i) { |
| 85 | struct mgcp_endpoint *endp = &g_cfg->endpoints[i]; |
Holger Hans Peter Freyther | 1aa4246 | 2010-07-29 02:43:14 +0800 | [diff] [blame] | 86 | 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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 87 | i, endp->ci, |
| 88 | ntohs(endp->net_rtp), ntohs(endp->net_rtcp), |
Holger Hans Peter Freyther | 6c0729f | 2010-04-05 09:00:53 +0200 | [diff] [blame] | 89 | ntohs(endp->bts_rtp), ntohs(endp->bts_rtcp), |
Holger Hans Peter Freyther | 1aa4246 | 2010-07-29 02:43:14 +0800 | [diff] [blame] | 90 | inet_ntoa(endp->bts), endp->in_bts, endp->bts_lost_no, |
| 91 | endp->in_remote, endp->net_lost_no, |
Holger Hans Peter Freyther | b4b135e | 2010-04-07 09:37:17 +0200 | [diff] [blame] | 92 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 93 | } |
| 94 | |
| 95 | return CMD_SUCCESS; |
| 96 | } |
| 97 | |
| 98 | DEFUN(cfg_mgcp, |
| 99 | cfg_mgcp_cmd, |
| 100 | "mgcp", |
| 101 | "Configure the MGCP") |
| 102 | { |
| 103 | vty->node = MGCP_NODE; |
| 104 | return CMD_SUCCESS; |
| 105 | } |
| 106 | |
| 107 | DEFUN(cfg_mgcp_local_ip, |
| 108 | cfg_mgcp_local_ip_cmd, |
Holger Hans Peter Freyther | 1384af6 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 109 | "local ip A.B.C.D", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 110 | "Set the IP to be used in SDP records") |
| 111 | { |
| 112 | if (g_cfg->local_ip) |
| 113 | talloc_free(g_cfg->local_ip); |
| 114 | g_cfg->local_ip = talloc_strdup(g_cfg, argv[0]); |
| 115 | return CMD_SUCCESS; |
| 116 | } |
| 117 | |
| 118 | DEFUN(cfg_mgcp_bts_ip, |
| 119 | cfg_mgcp_bts_ip_cmd, |
Holger Hans Peter Freyther | 1384af6 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 120 | "bts ip A.B.C.D", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 121 | "Set the IP of the BTS for RTP forwarding") |
| 122 | { |
| 123 | if (g_cfg->bts_ip) |
| 124 | talloc_free(g_cfg->bts_ip); |
| 125 | g_cfg->bts_ip = talloc_strdup(g_cfg, argv[0]); |
| 126 | inet_aton(g_cfg->bts_ip, &g_cfg->bts_in); |
| 127 | return CMD_SUCCESS; |
| 128 | } |
| 129 | |
| 130 | DEFUN(cfg_mgcp_bind_ip, |
| 131 | cfg_mgcp_bind_ip_cmd, |
Holger Hans Peter Freyther | 1384af6 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 132 | "bind ip A.B.C.D", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 133 | "Bind the MGCP to this local addr") |
| 134 | { |
| 135 | if (g_cfg->source_addr) |
| 136 | talloc_free(g_cfg->source_addr); |
| 137 | g_cfg->source_addr = talloc_strdup(g_cfg, argv[0]); |
| 138 | return CMD_SUCCESS; |
| 139 | } |
| 140 | |
| 141 | DEFUN(cfg_mgcp_bind_port, |
| 142 | cfg_mgcp_bind_port_cmd, |
| 143 | "bind port <0-65534>", |
| 144 | "Bind the MGCP to this port") |
| 145 | { |
| 146 | unsigned int port = atoi(argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 147 | g_cfg->source_port = port; |
| 148 | return CMD_SUCCESS; |
| 149 | } |
| 150 | |
| 151 | DEFUN(cfg_mgcp_bind_early, |
| 152 | cfg_mgcp_bind_early_cmd, |
| 153 | "bind early (0|1)", |
| 154 | "Bind all RTP ports early") |
| 155 | { |
| 156 | unsigned int bind = atoi(argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 157 | g_cfg->early_bind = bind == 1; |
| 158 | return CMD_SUCCESS; |
| 159 | } |
| 160 | |
| 161 | DEFUN(cfg_mgcp_rtp_base_port, |
| 162 | cfg_mgcp_rtp_base_port_cmd, |
| 163 | "rtp base <0-65534>", |
| 164 | "Base port to use") |
| 165 | { |
| 166 | unsigned int port = atoi(argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 167 | g_cfg->rtp_base_port = port; |
| 168 | return CMD_SUCCESS; |
| 169 | } |
| 170 | |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 171 | DEFUN(cfg_mgcp_rtp_ip_dscp, |
| 172 | cfg_mgcp_rtp_ip_dscp_cmd, |
| 173 | "rtp ip-dscp <0-255>", |
| 174 | "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.") |
Holger Hans Peter Freyther | 75492e6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 175 | { |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 176 | int dscp = atoi(argv[0]); |
| 177 | g_cfg->endp_dscp = dscp; |
Holger Hans Peter Freyther | 75492e6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 178 | return CMD_SUCCESS; |
| 179 | } |
| 180 | |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 181 | ALIAS_DEPRECATED(cfg_mgcp_rtp_ip_dscp, cfg_mgcp_rtp_ip_tos_cmd, |
| 182 | "rtp ip-tos <0-255>", |
| 183 | "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.") |
| 184 | |
| 185 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 186 | DEFUN(cfg_mgcp_sdp_payload_number, |
| 187 | cfg_mgcp_sdp_payload_number_cmd, |
| 188 | "sdp audio payload number <1-255>", |
| 189 | "Set the audio codec to use") |
| 190 | { |
| 191 | unsigned int payload = atoi(argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 192 | g_cfg->audio_payload = payload; |
| 193 | return CMD_SUCCESS; |
| 194 | } |
| 195 | |
| 196 | DEFUN(cfg_mgcp_sdp_payload_name, |
| 197 | cfg_mgcp_sdp_payload_name_cmd, |
| 198 | "sdp audio payload name NAME", |
| 199 | "Set the audio name to use") |
| 200 | { |
| 201 | if (g_cfg->audio_name) |
| 202 | talloc_free(g_cfg->audio_name); |
| 203 | g_cfg->audio_name = talloc_strdup(g_cfg, argv[0]); |
| 204 | return CMD_SUCCESS; |
| 205 | } |
| 206 | |
| 207 | DEFUN(cfg_mgcp_loop, |
| 208 | cfg_mgcp_loop_cmd, |
| 209 | "loop (0|1)", |
| 210 | "Loop the audio") |
| 211 | { |
| 212 | g_cfg->audio_loop = atoi(argv[0]); |
| 213 | return CMD_SUCCESS; |
| 214 | } |
| 215 | |
| 216 | DEFUN(cfg_mgcp_number_endp, |
| 217 | cfg_mgcp_number_endp_cmd, |
| 218 | "number endpoints <0-65534>", |
| 219 | "The number of endpoints to allocate. This is not dynamic.") |
| 220 | { |
| 221 | /* + 1 as we start counting at one */ |
| 222 | g_cfg->number_endpoints = atoi(argv[0]) + 1; |
| 223 | return CMD_SUCCESS; |
| 224 | } |
| 225 | |
| 226 | DEFUN(cfg_mgcp_forward_ip, |
| 227 | cfg_mgcp_forward_ip_cmd, |
Holger Hans Peter Freyther | 1384af6 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 228 | "forward audio ip A.B.C.D", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 229 | "Forward packets from and to the IP. This disables most of the MGCP feature.") |
| 230 | { |
| 231 | if (g_cfg->forward_ip) |
| 232 | talloc_free(g_cfg->forward_ip); |
| 233 | g_cfg->forward_ip = talloc_strdup(g_cfg, argv[0]); |
| 234 | return CMD_SUCCESS; |
| 235 | } |
| 236 | |
| 237 | DEFUN(cfg_mgcp_forward_port, |
| 238 | cfg_mgcp_forward_port_cmd, |
| 239 | "forward audio port <1-15000>", |
| 240 | "Forward packets from and to the port. This disables most of the MGCP feature.") |
| 241 | { |
| 242 | g_cfg->forward_port = atoi(argv[0]); |
| 243 | return CMD_SUCCESS; |
| 244 | } |
| 245 | |
Holger Hans Peter Freyther | b79994c | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 246 | DEFUN(cfg_mgcp_agent_addr, |
| 247 | cfg_mgcp_agent_addr_cmd, |
| 248 | "call agent ip IP", |
| 249 | "Set the address of the call agent.") |
| 250 | { |
| 251 | if (g_cfg->call_agent_addr) |
| 252 | talloc_free(g_cfg->call_agent_addr); |
| 253 | g_cfg->call_agent_addr = talloc_strdup(g_cfg, argv[0]); |
| 254 | return CMD_SUCCESS; |
| 255 | } |
| 256 | |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 257 | DEFUN(loop_endp, |
| 258 | loop_endp_cmd, |
| 259 | "loop-endpoint NAME (0|1)", |
| 260 | "Loop a given endpoint\n" |
Holger Hans Peter Freyther | ebc824c | 2010-08-03 23:00:03 +0800 | [diff] [blame^] | 261 | "The name in hex of the endpoint\n" "Disable the loop\n" "Enable the loop\n") |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 262 | { |
| 263 | struct mgcp_endpoint *endp; |
| 264 | |
| 265 | int endp_no = strtoul(argv[0], NULL, 16); |
| 266 | if (endp_no < 1 || endp_no >= g_cfg->number_endpoints) { |
| 267 | vty_out(vty, "Loopback number %s/%d is invalid.%s", |
| 268 | argv[0], endp_no, VTY_NEWLINE); |
| 269 | return CMD_WARNING; |
| 270 | } |
| 271 | |
| 272 | |
| 273 | endp = &g_cfg->endpoints[endp_no]; |
| 274 | int loop = atoi(argv[1]); |
| 275 | |
| 276 | if (loop) |
| 277 | endp->conn_mode = MGCP_CONN_LOOPBACK; |
| 278 | else |
| 279 | endp->conn_mode = endp->orig_mode; |
| 280 | |
| 281 | return CMD_SUCCESS; |
| 282 | } |
| 283 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 284 | int mgcp_vty_init(void) |
| 285 | { |
Holger Hans Peter Freyther | b5be7ac | 2010-05-14 02:45:52 +0800 | [diff] [blame] | 286 | install_element_ve(&show_mgcp_cmd); |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 287 | install_element(ENABLE_NODE, &loop_endp_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 288 | |
| 289 | install_element(CONFIG_NODE, &cfg_mgcp_cmd); |
| 290 | install_node(&mgcp_node, config_write_mgcp); |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 291 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 292 | install_default(MGCP_NODE); |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 293 | install_element(MGCP_NODE, &ournode_exit_cmd); |
Harald Welte | 54f7424 | 2010-05-14 19:11:04 +0200 | [diff] [blame] | 294 | install_element(MGCP_NODE, &ournode_end_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 295 | install_element(MGCP_NODE, &cfg_mgcp_local_ip_cmd); |
| 296 | install_element(MGCP_NODE, &cfg_mgcp_bts_ip_cmd); |
| 297 | install_element(MGCP_NODE, &cfg_mgcp_bind_ip_cmd); |
| 298 | install_element(MGCP_NODE, &cfg_mgcp_bind_port_cmd); |
| 299 | install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd); |
| 300 | install_element(MGCP_NODE, &cfg_mgcp_rtp_base_port_cmd); |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 301 | install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd); |
Holger Hans Peter Freyther | 75492e6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 302 | install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 303 | install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd); |
| 304 | install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd); |
| 305 | install_element(MGCP_NODE, &cfg_mgcp_loop_cmd); |
| 306 | install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd); |
| 307 | install_element(MGCP_NODE, &cfg_mgcp_forward_ip_cmd); |
| 308 | install_element(MGCP_NODE, &cfg_mgcp_forward_port_cmd); |
Holger Hans Peter Freyther | b79994c | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 309 | install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 310 | return 0; |
| 311 | } |
| 312 | |
| 313 | int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) |
| 314 | { |
| 315 | int i, rc; |
| 316 | |
| 317 | g_cfg = cfg; |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 318 | rc = vty_read_config_file(config_file, NULL); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 319 | if (rc < 0) { |
| 320 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 321 | return rc; |
| 322 | } |
| 323 | |
| 324 | |
| 325 | if (!g_cfg->bts_ip) |
| 326 | fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n"); |
| 327 | |
Holger Hans Peter Freyther | 95e4d34 | 2010-03-30 13:00:10 +0200 | [diff] [blame] | 328 | if (!g_cfg->source_addr) { |
| 329 | fprintf(stderr, "You need to specify a bind address.\n"); |
| 330 | return -1; |
| 331 | } |
| 332 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 333 | if (mgcp_endpoints_allocate(g_cfg) != 0) { |
| 334 | fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n", g_cfg->number_endpoints); |
| 335 | return -1; |
| 336 | } |
| 337 | |
| 338 | /* |
| 339 | * This application supports two modes. |
Holger Hans Peter Freyther | a581136 | 2010-04-30 13:32:05 +0800 | [diff] [blame] | 340 | * 1.) a true MGCP gateway with support for AUEP, CRCX, MDCX, DLCX |
| 341 | * 2.) plain forwarding of RTP packets on the endpoints. |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 342 | * both modes are mutual exclusive |
| 343 | */ |
| 344 | if (g_cfg->forward_ip) { |
| 345 | int port = g_cfg->rtp_base_port; |
| 346 | if (g_cfg->forward_port != 0) |
| 347 | port = g_cfg->forward_port; |
| 348 | |
| 349 | if (!g_cfg->early_bind) { |
| 350 | LOGP(DMGCP, LOGL_NOTICE, "Forwarding requires early bind.\n"); |
| 351 | return -1; |
| 352 | } |
| 353 | |
| 354 | /* |
| 355 | * Store the forward IP and assign a ci. For early bind |
| 356 | * the sockets will be created after this. |
| 357 | */ |
| 358 | for (i = 1; i < g_cfg->number_endpoints; ++i) { |
| 359 | struct mgcp_endpoint *endp = &g_cfg->endpoints[i]; |
| 360 | inet_aton(g_cfg->forward_ip, &endp->remote); |
| 361 | endp->ci = CI_UNUSED + 23; |
| 362 | endp->net_rtp = htons(rtp_calculate_port(ENDPOINT_NUMBER(endp), port)); |
| 363 | endp->net_rtcp = htons(rtp_calculate_port(ENDPOINT_NUMBER(endp), port) + 1); |
| 364 | } |
| 365 | |
| 366 | LOGP(DMGCP, LOGL_NOTICE, "Configured for Audio Forwarding.\n"); |
| 367 | } |
| 368 | |
| 369 | /* early bind */ |
| 370 | if (g_cfg->early_bind) { |
| 371 | for (i = 1; i < g_cfg->number_endpoints; ++i) { |
| 372 | struct mgcp_endpoint *endp = &g_cfg->endpoints[i]; |
| 373 | int rtp_port; |
| 374 | |
| 375 | rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), g_cfg->rtp_base_port); |
| 376 | if (mgcp_bind_rtp_port(endp, rtp_port) != 0) { |
Holger Hans Peter Freyther | 590cd98 | 2010-02-26 13:10:51 +0100 | [diff] [blame] | 377 | LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 378 | return -1; |
| 379 | } |
| 380 | } |
| 381 | } |
| 382 | |
| 383 | return !!g_cfg->forward_ip; |
| 384 | } |
| 385 | |