Holger Hans Peter Freyther | 6f38c06 | 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 | f41fb1f | 2010-02-26 20:16:37 +0100 | [diff] [blame] | 27 | #include <osmocore/talloc.h> |
| 28 | |
Holger Hans Peter Freyther | 6f38c06 | 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 | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 32 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 33 | |
Harald Welte | bd9591f | 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 | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 36 | |
Holger Hans Peter Freyther | e8d1371 | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 37 | #include <string.h> |
| 38 | |
Holger Hans Peter Freyther | 6f38c06 | 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 | e8d1371 | 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 | 6f38c06 | 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); |
Holger Hans Peter Freyther | 2ea9118 | 2010-08-05 07:10:56 +0800 | [diff] [blame] | 59 | |
| 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 Freyther | f330729 | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 62 | 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 Freyther | 2ea9118 | 2010-08-05 07:10:56 +0800 | [diff] [blame] | 66 | 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 Freyther | f330729 | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 68 | 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 Freyther | 3140c4f | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 72 | vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE); |
Holger Hans Peter Freyther | f89a988 | 2010-04-13 09:28:40 +0200 | [diff] [blame] | 73 | 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 Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 77 | vty_out(vty, " loop %u%s", !!g_cfg->audio_loop, VTY_NEWLINE); |
Holger Hans Peter Freyther | e8d1371 | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 78 | vty_out(vty, " number endpoints %u%s", g_cfg->number_endpoints - 1, VTY_NEWLINE); |
Holger Hans Peter Freyther | 19ff679 | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 79 | if (g_cfg->call_agent_addr) |
Holger Hans Peter Freyther | e8d1371 | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 80 | vty_out(vty, " call agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 81 | |
| 82 | return CMD_SUCCESS; |
| 83 | } |
| 84 | |
| 85 | DEFUN(show_mcgp, show_mgcp_cmd, "show mgcp", |
| 86 | SHOW_STR "Display information about the MGCP Media Gateway") |
| 87 | { |
| 88 | int i; |
| 89 | |
| 90 | vty_out(vty, "MGCP is up and running with %u endpoints:%s", g_cfg->number_endpoints - 1, VTY_NEWLINE); |
| 91 | for (i = 1; i < g_cfg->number_endpoints; ++i) { |
| 92 | struct mgcp_endpoint *endp = &g_cfg->endpoints[i]; |
Holger Hans Peter Freyther | a65a0e7 | 2010-07-29 02:43:14 +0800 | [diff] [blame] | 93 | 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 | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 94 | i, endp->ci, |
Holger Hans Peter Freyther | fab76aa | 2010-08-05 01:34:51 +0800 | [diff] [blame] | 95 | ntohs(endp->net_end.rtp_port), ntohs(endp->net_end.rtcp_port), |
| 96 | ntohs(endp->bts_end.rtp_port), ntohs(endp->bts_end.rtcp_port), |
| 97 | inet_ntoa(endp->bts_end.addr), |
| 98 | endp->bts_end.packets, endp->bts_state.lost_no, |
| 99 | endp->net_end.packets, endp->net_state.lost_no, |
Holger Hans Peter Freyther | 6de5b11 | 2010-04-07 09:37:17 +0200 | [diff] [blame] | 100 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | return CMD_SUCCESS; |
| 104 | } |
| 105 | |
| 106 | DEFUN(cfg_mgcp, |
| 107 | cfg_mgcp_cmd, |
| 108 | "mgcp", |
| 109 | "Configure the MGCP") |
| 110 | { |
| 111 | vty->node = MGCP_NODE; |
| 112 | return CMD_SUCCESS; |
| 113 | } |
| 114 | |
| 115 | DEFUN(cfg_mgcp_local_ip, |
| 116 | cfg_mgcp_local_ip_cmd, |
Holger Hans Peter Freyther | 5c9a645 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 117 | "local ip A.B.C.D", |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 118 | "Set the IP to be used in SDP records") |
| 119 | { |
| 120 | if (g_cfg->local_ip) |
| 121 | talloc_free(g_cfg->local_ip); |
| 122 | g_cfg->local_ip = talloc_strdup(g_cfg, argv[0]); |
| 123 | return CMD_SUCCESS; |
| 124 | } |
| 125 | |
| 126 | DEFUN(cfg_mgcp_bts_ip, |
| 127 | cfg_mgcp_bts_ip_cmd, |
Holger Hans Peter Freyther | 5c9a645 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 128 | "bts ip A.B.C.D", |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 129 | "Set the IP of the BTS for RTP forwarding") |
| 130 | { |
| 131 | if (g_cfg->bts_ip) |
| 132 | talloc_free(g_cfg->bts_ip); |
| 133 | g_cfg->bts_ip = talloc_strdup(g_cfg, argv[0]); |
| 134 | inet_aton(g_cfg->bts_ip, &g_cfg->bts_in); |
| 135 | return CMD_SUCCESS; |
| 136 | } |
| 137 | |
| 138 | DEFUN(cfg_mgcp_bind_ip, |
| 139 | cfg_mgcp_bind_ip_cmd, |
Holger Hans Peter Freyther | 5c9a645 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 140 | "bind ip A.B.C.D", |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 141 | "Bind the MGCP to this local addr") |
| 142 | { |
| 143 | if (g_cfg->source_addr) |
| 144 | talloc_free(g_cfg->source_addr); |
| 145 | g_cfg->source_addr = talloc_strdup(g_cfg, argv[0]); |
| 146 | return CMD_SUCCESS; |
| 147 | } |
| 148 | |
| 149 | DEFUN(cfg_mgcp_bind_port, |
| 150 | cfg_mgcp_bind_port_cmd, |
| 151 | "bind port <0-65534>", |
| 152 | "Bind the MGCP to this port") |
| 153 | { |
| 154 | unsigned int port = atoi(argv[0]); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 155 | g_cfg->source_port = port; |
| 156 | return CMD_SUCCESS; |
| 157 | } |
| 158 | |
| 159 | DEFUN(cfg_mgcp_bind_early, |
| 160 | cfg_mgcp_bind_early_cmd, |
| 161 | "bind early (0|1)", |
| 162 | "Bind all RTP ports early") |
| 163 | { |
Holger Hans Peter Freyther | 7140dae | 2010-08-05 03:22:24 +0800 | [diff] [blame] | 164 | vty_out(vty, "bind early is deprecated, remove it from the config.\n"); |
| 165 | return CMD_WARNING; |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 166 | } |
| 167 | |
Holger Hans Peter Freyther | ee4657c | 2010-08-05 03:46:07 +0800 | [diff] [blame] | 168 | DEFUN(cfg_mgcp_rtp_bts_base_port, |
| 169 | cfg_mgcp_rtp_bts_base_port_cmd, |
| 170 | "rtp bts-base <0-65534>", |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 171 | "Base port to use") |
| 172 | { |
| 173 | unsigned int port = atoi(argv[0]); |
Holger Hans Peter Freyther | 2ea9118 | 2010-08-05 07:10:56 +0800 | [diff] [blame] | 174 | g_cfg->bts_ports.mode = PORT_ALLOC_STATIC; |
| 175 | g_cfg->bts_ports.base_port = port; |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 176 | return CMD_SUCCESS; |
| 177 | } |
| 178 | |
Holger Hans Peter Freyther | f330729 | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 179 | DEFUN(cfg_mgcp_rtp_bts_range, |
| 180 | cfg_mgcp_rtp_bts_range_cmd, |
| 181 | "rtp bts-range <0-65534> <0-65534>", |
| 182 | "Range of ports to allocate for endpoints\n" |
| 183 | "Start of the range of ports\n" "End of the range of ports\n") |
| 184 | { |
| 185 | g_cfg->bts_ports.mode = PORT_ALLOC_DYNAMIC; |
| 186 | g_cfg->bts_ports.range_start = atoi(argv[0]); |
| 187 | g_cfg->bts_ports.range_end = atoi(argv[1]); |
| 188 | g_cfg->bts_ports.last_port = g_cfg->bts_ports.range_start; |
| 189 | return CMD_SUCCESS; |
| 190 | } |
| 191 | |
| 192 | DEFUN(cfg_mgcp_rtp_net_range, |
| 193 | cfg_mgcp_rtp_net_range_cmd, |
| 194 | "rtp net-range <0-65534> <0-65534>", |
| 195 | "Range of ports to allocate for endpoints\n" |
| 196 | "Start of the range of ports\n" "End of the range of ports\n") |
| 197 | { |
| 198 | g_cfg->net_ports.mode = PORT_ALLOC_DYNAMIC; |
| 199 | g_cfg->net_ports.range_start = atoi(argv[0]); |
| 200 | g_cfg->net_ports.range_end = atoi(argv[1]); |
| 201 | g_cfg->net_ports.last_port = g_cfg->net_ports.range_start; |
| 202 | return CMD_SUCCESS; |
| 203 | } |
| 204 | |
Holger Hans Peter Freyther | 81938e9 | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 205 | DEFUN(cfg_mgcp_rtp_net_base_port, |
| 206 | cfg_mgcp_rtp_net_base_port_cmd, |
| 207 | "rtp net-base <0-65534>", |
| 208 | "Base port to use for network port\n" "Port\n") |
| 209 | { |
| 210 | unsigned int port = atoi(argv[0]); |
Holger Hans Peter Freyther | 2ea9118 | 2010-08-05 07:10:56 +0800 | [diff] [blame] | 211 | g_cfg->net_ports.mode = PORT_ALLOC_STATIC; |
| 212 | g_cfg->net_ports.base_port = port; |
Holger Hans Peter Freyther | 81938e9 | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 213 | return CMD_SUCCESS; |
| 214 | } |
| 215 | |
Holger Hans Peter Freyther | ee4657c | 2010-08-05 03:46:07 +0800 | [diff] [blame] | 216 | ALIAS_DEPRECATED(cfg_mgcp_rtp_bts_base_port, cfg_mgcp_rtp_base_port_cmd, |
| 217 | "rtp base <0-65534>", "Base port to use") |
| 218 | |
Holger Hans Peter Freyther | 3140c4f | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 219 | DEFUN(cfg_mgcp_rtp_ip_dscp, |
| 220 | cfg_mgcp_rtp_ip_dscp_cmd, |
| 221 | "rtp ip-dscp <0-255>", |
| 222 | "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.") |
Holger Hans Peter Freyther | 489d0a6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 223 | { |
Holger Hans Peter Freyther | 3140c4f | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 224 | int dscp = atoi(argv[0]); |
| 225 | g_cfg->endp_dscp = dscp; |
Holger Hans Peter Freyther | 489d0a6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 226 | return CMD_SUCCESS; |
| 227 | } |
| 228 | |
Holger Hans Peter Freyther | 3140c4f | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 229 | ALIAS_DEPRECATED(cfg_mgcp_rtp_ip_dscp, cfg_mgcp_rtp_ip_tos_cmd, |
| 230 | "rtp ip-tos <0-255>", |
| 231 | "Set the IP_TOS socket attribute on the RTP/RTCP sockets.\n" "The DSCP value.") |
| 232 | |
| 233 | |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 234 | DEFUN(cfg_mgcp_sdp_payload_number, |
| 235 | cfg_mgcp_sdp_payload_number_cmd, |
| 236 | "sdp audio payload number <1-255>", |
| 237 | "Set the audio codec to use") |
| 238 | { |
| 239 | unsigned int payload = atoi(argv[0]); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 240 | g_cfg->audio_payload = payload; |
| 241 | return CMD_SUCCESS; |
| 242 | } |
| 243 | |
| 244 | DEFUN(cfg_mgcp_sdp_payload_name, |
| 245 | cfg_mgcp_sdp_payload_name_cmd, |
| 246 | "sdp audio payload name NAME", |
| 247 | "Set the audio name to use") |
| 248 | { |
| 249 | if (g_cfg->audio_name) |
| 250 | talloc_free(g_cfg->audio_name); |
| 251 | g_cfg->audio_name = talloc_strdup(g_cfg, argv[0]); |
| 252 | return CMD_SUCCESS; |
| 253 | } |
| 254 | |
| 255 | DEFUN(cfg_mgcp_loop, |
| 256 | cfg_mgcp_loop_cmd, |
| 257 | "loop (0|1)", |
| 258 | "Loop the audio") |
| 259 | { |
| 260 | g_cfg->audio_loop = atoi(argv[0]); |
| 261 | return CMD_SUCCESS; |
| 262 | } |
| 263 | |
| 264 | DEFUN(cfg_mgcp_number_endp, |
| 265 | cfg_mgcp_number_endp_cmd, |
| 266 | "number endpoints <0-65534>", |
| 267 | "The number of endpoints to allocate. This is not dynamic.") |
| 268 | { |
| 269 | /* + 1 as we start counting at one */ |
| 270 | g_cfg->number_endpoints = atoi(argv[0]) + 1; |
| 271 | return CMD_SUCCESS; |
| 272 | } |
| 273 | |
Holger Hans Peter Freyther | 19ff679 | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 274 | DEFUN(cfg_mgcp_agent_addr, |
| 275 | cfg_mgcp_agent_addr_cmd, |
| 276 | "call agent ip IP", |
| 277 | "Set the address of the call agent.") |
| 278 | { |
| 279 | if (g_cfg->call_agent_addr) |
| 280 | talloc_free(g_cfg->call_agent_addr); |
| 281 | g_cfg->call_agent_addr = talloc_strdup(g_cfg, argv[0]); |
| 282 | return CMD_SUCCESS; |
| 283 | } |
| 284 | |
Holger Hans Peter Freyther | b33ded1 | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 285 | DEFUN(loop_endp, |
| 286 | loop_endp_cmd, |
| 287 | "loop-endpoint NAME (0|1)", |
| 288 | "Loop a given endpoint\n" |
Holger Hans Peter Freyther | 84d8899 | 2010-08-03 23:00:03 +0800 | [diff] [blame] | 289 | "The name in hex of the endpoint\n" "Disable the loop\n" "Enable the loop\n") |
Holger Hans Peter Freyther | b33ded1 | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 290 | { |
| 291 | struct mgcp_endpoint *endp; |
| 292 | |
| 293 | int endp_no = strtoul(argv[0], NULL, 16); |
| 294 | if (endp_no < 1 || endp_no >= g_cfg->number_endpoints) { |
| 295 | vty_out(vty, "Loopback number %s/%d is invalid.%s", |
| 296 | argv[0], endp_no, VTY_NEWLINE); |
| 297 | return CMD_WARNING; |
| 298 | } |
| 299 | |
| 300 | |
| 301 | endp = &g_cfg->endpoints[endp_no]; |
| 302 | int loop = atoi(argv[1]); |
| 303 | |
| 304 | if (loop) |
| 305 | endp->conn_mode = MGCP_CONN_LOOPBACK; |
| 306 | else |
| 307 | endp->conn_mode = endp->orig_mode; |
Holger Hans Peter Freyther | 73aa514 | 2010-08-05 12:07:00 +0000 | [diff] [blame^] | 308 | endp->allow_patch = 1; |
Holger Hans Peter Freyther | b33ded1 | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 309 | |
| 310 | return CMD_SUCCESS; |
| 311 | } |
| 312 | |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 313 | int mgcp_vty_init(void) |
| 314 | { |
Holger Hans Peter Freyther | 8a22385 | 2010-05-14 02:45:52 +0800 | [diff] [blame] | 315 | install_element_ve(&show_mgcp_cmd); |
Holger Hans Peter Freyther | b33ded1 | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 316 | install_element(ENABLE_NODE, &loop_endp_cmd); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 317 | |
| 318 | install_element(CONFIG_NODE, &cfg_mgcp_cmd); |
| 319 | install_node(&mgcp_node, config_write_mgcp); |
Holger Hans Peter Freyther | b33ded1 | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 320 | |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 321 | install_default(MGCP_NODE); |
Harald Welte | 58ed1cb | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 322 | install_element(MGCP_NODE, &ournode_exit_cmd); |
Harald Welte | dc82b9b | 2010-05-14 19:11:04 +0200 | [diff] [blame] | 323 | install_element(MGCP_NODE, &ournode_end_cmd); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 324 | install_element(MGCP_NODE, &cfg_mgcp_local_ip_cmd); |
| 325 | install_element(MGCP_NODE, &cfg_mgcp_bts_ip_cmd); |
| 326 | install_element(MGCP_NODE, &cfg_mgcp_bind_ip_cmd); |
| 327 | install_element(MGCP_NODE, &cfg_mgcp_bind_port_cmd); |
| 328 | install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd); |
| 329 | install_element(MGCP_NODE, &cfg_mgcp_rtp_base_port_cmd); |
Holger Hans Peter Freyther | ee4657c | 2010-08-05 03:46:07 +0800 | [diff] [blame] | 330 | install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_base_port_cmd); |
Holger Hans Peter Freyther | 81938e9 | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 331 | install_element(MGCP_NODE, &cfg_mgcp_rtp_net_base_port_cmd); |
Holger Hans Peter Freyther | f330729 | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 332 | install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_range_cmd); |
| 333 | install_element(MGCP_NODE, &cfg_mgcp_rtp_net_range_cmd); |
Holger Hans Peter Freyther | 3140c4f | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 334 | install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd); |
Holger Hans Peter Freyther | 489d0a6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 335 | install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 336 | install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd); |
| 337 | install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd); |
| 338 | install_element(MGCP_NODE, &cfg_mgcp_loop_cmd); |
| 339 | install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd); |
Holger Hans Peter Freyther | 19ff679 | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 340 | install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 341 | return 0; |
| 342 | } |
| 343 | |
| 344 | int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) |
| 345 | { |
| 346 | int i, rc; |
| 347 | |
| 348 | g_cfg = cfg; |
Harald Welte | 4015287 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 349 | rc = vty_read_config_file(config_file, NULL); |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 350 | if (rc < 0) { |
| 351 | fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file); |
| 352 | return rc; |
| 353 | } |
| 354 | |
| 355 | |
| 356 | if (!g_cfg->bts_ip) |
| 357 | fprintf(stderr, "No BTS ip address specified. This will allow everyone to connect.\n"); |
| 358 | |
Holger Hans Peter Freyther | bdd3cc3 | 2010-03-30 13:00:10 +0200 | [diff] [blame] | 359 | if (!g_cfg->source_addr) { |
| 360 | fprintf(stderr, "You need to specify a bind address.\n"); |
| 361 | return -1; |
| 362 | } |
| 363 | |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 364 | if (mgcp_endpoints_allocate(g_cfg) != 0) { |
| 365 | fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n", g_cfg->number_endpoints); |
| 366 | return -1; |
| 367 | } |
| 368 | |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 369 | /* early bind */ |
Holger Hans Peter Freyther | 7140dae | 2010-08-05 03:22:24 +0800 | [diff] [blame] | 370 | for (i = 1; i < g_cfg->number_endpoints; ++i) { |
| 371 | struct mgcp_endpoint *endp = &g_cfg->endpoints[i]; |
| 372 | int rtp_port; |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 373 | |
Holger Hans Peter Freyther | f330729 | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 374 | if (g_cfg->bts_ports.mode == PORT_ALLOC_STATIC) { |
| 375 | rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), |
| 376 | g_cfg->bts_ports.base_port); |
| 377 | if (mgcp_bind_bts_rtp_port(endp, rtp_port) != 0) { |
| 378 | LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); |
| 379 | return -1; |
| 380 | } |
Holger Hans Peter Freyther | 05d8f5f | 2010-08-05 08:08:17 +0800 | [diff] [blame] | 381 | endp->bts_end.local_alloc = PORT_ALLOC_STATIC; |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 382 | } |
Holger Hans Peter Freyther | 81938e9 | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 383 | |
Holger Hans Peter Freyther | f330729 | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 384 | if (g_cfg->net_ports.mode == PORT_ALLOC_STATIC) { |
| 385 | rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), |
| 386 | g_cfg->net_ports.base_port); |
| 387 | if (mgcp_bind_net_rtp_port(endp, rtp_port) != 0) { |
| 388 | LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); |
| 389 | return -1; |
| 390 | } |
Holger Hans Peter Freyther | 05d8f5f | 2010-08-05 08:08:17 +0800 | [diff] [blame] | 391 | endp->net_end.local_alloc = PORT_ALLOC_STATIC; |
Holger Hans Peter Freyther | 81938e9 | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 392 | } |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 393 | } |
| 394 | |
Holger Hans Peter Freyther | 6434452 | 2010-08-05 01:28:22 +0800 | [diff] [blame] | 395 | return 0; |
Holger Hans Peter Freyther | 6f38c06 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 396 | } |
| 397 | |