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 | /* |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 5 | * (C) 2009-2011 by Holger Hans Peter Freyther <zecke@selfish.org> |
| 6 | * (C) 2009-2011 by On-Waves |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 7 | * All Rights Reserved |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 10 | * 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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 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 |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 17 | * GNU Affero General Public License for more details. |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 18 | * |
Harald Welte | 9af6ddf | 2011-01-01 15:25:50 +0100 | [diff] [blame] | 19 | * 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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <sys/types.h> |
| 25 | |
Holger Hans Peter Freyther | 1ebad74 | 2010-02-26 20:16:37 +0100 | [diff] [blame] | 26 | #include <osmocore/talloc.h> |
| 27 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 28 | #include <openbsc/debug.h> |
| 29 | #include <openbsc/mgcp.h> |
| 30 | #include <openbsc/mgcp_internal.h> |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 31 | #include <openbsc/vty.h> |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 32 | |
Harald Welte | 4b037e4 | 2010-05-19 19:45:32 +0200 | [diff] [blame] | 33 | #include <osmocom/vty/command.h> |
| 34 | #include <osmocom/vty/vty.h> |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 35 | |
Holger Hans Peter Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 36 | #include <string.h> |
| 37 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 38 | static struct mgcp_config *g_cfg = NULL; |
| 39 | |
| 40 | /* |
| 41 | * vty code for mgcp below |
| 42 | */ |
| 43 | struct cmd_node mgcp_node = { |
| 44 | MGCP_NODE, |
| 45 | "%s(mgcp)#", |
| 46 | 1, |
| 47 | }; |
| 48 | |
| 49 | static 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 Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 53 | 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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 55 | 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 Freyther | 15e7389 | 2010-08-05 07:10:56 +0800 | [diff] [blame] | 58 | |
| 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 Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 61 | 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 Freyther | 15e7389 | 2010-08-05 07:10:56 +0800 | [diff] [blame] | 65 | 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 Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 67 | 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 Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 71 | vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE); |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 72 | 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 Freyther | b79994c | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 80 | if (g_cfg->call_agent_addr) |
Holger Hans Peter Freyther | 8d9833e | 2010-04-16 16:59:48 +0200 | [diff] [blame] | 81 | vty_out(vty, " call agent ip %s%s", g_cfg->call_agent_addr, VTY_NEWLINE); |
Holger Hans Peter Freyther | a2a10eb | 2010-09-17 03:58:52 +0800 | [diff] [blame] | 82 | if (g_cfg->transcoder_ip) |
| 83 | vty_out(vty, " transcoder-mgw %s%s", g_cfg->transcoder_ip, VTY_NEWLINE); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 84 | |
Holger Hans Peter Freyther | 54aaa0f | 2010-09-17 23:35:53 +0800 | [diff] [blame] | 85 | 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 Freyther | b98ba72 | 2010-09-19 04:21:39 +0800 | [diff] [blame] | 90 | vty_out(vty, " transcoder-remote-base %u%s", g_cfg->transcoder_remote_base, VTY_NEWLINE); |
Holger Hans Peter Freyther | 54aaa0f | 2010-09-17 23:35:53 +0800 | [diff] [blame] | 91 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 92 | return CMD_SUCCESS; |
| 93 | } |
| 94 | |
| 95 | DEFUN(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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 100 | 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 Freyther | bd7b3c5 | 2010-11-01 21:04:54 +0100 | [diff] [blame] | 104 | 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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 105 | i, endp->ci, |
Holger Hans Peter Freyther | a17d701 | 2010-08-05 01:34:51 +0800 | [diff] [blame] | 106 | 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 Freyther | bd7b3c5 | 2010-11-01 21:04:54 +0100 | [diff] [blame] | 111 | endp->trans_net.packets, endp->trans_bts.packets, |
Holger Hans Peter Freyther | b4b135e | 2010-04-07 09:37:17 +0200 | [diff] [blame] | 112 | VTY_NEWLINE); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 113 | } |
| 114 | |
| 115 | return CMD_SUCCESS; |
| 116 | } |
| 117 | |
| 118 | DEFUN(cfg_mgcp, |
| 119 | cfg_mgcp_cmd, |
| 120 | "mgcp", |
| 121 | "Configure the MGCP") |
| 122 | { |
| 123 | vty->node = MGCP_NODE; |
| 124 | return CMD_SUCCESS; |
| 125 | } |
| 126 | |
| 127 | DEFUN(cfg_mgcp_local_ip, |
| 128 | cfg_mgcp_local_ip_cmd, |
Holger Hans Peter Freyther | 1384af6 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 129 | "local ip A.B.C.D", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 130 | "Set the IP to be used in SDP records") |
| 131 | { |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 132 | bsc_replace_string(g_cfg, &g_cfg->local_ip, argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 133 | return CMD_SUCCESS; |
| 134 | } |
| 135 | |
| 136 | DEFUN(cfg_mgcp_bts_ip, |
| 137 | cfg_mgcp_bts_ip_cmd, |
Holger Hans Peter Freyther | 1384af6 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 138 | "bts ip A.B.C.D", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 139 | "Set the IP of the BTS for RTP forwarding") |
| 140 | { |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 141 | bsc_replace_string(g_cfg, &g_cfg->bts_ip, argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 142 | inet_aton(g_cfg->bts_ip, &g_cfg->bts_in); |
| 143 | return CMD_SUCCESS; |
| 144 | } |
| 145 | |
| 146 | DEFUN(cfg_mgcp_bind_ip, |
| 147 | cfg_mgcp_bind_ip_cmd, |
Holger Hans Peter Freyther | 1384af6 | 2010-05-14 02:27:50 +0800 | [diff] [blame] | 148 | "bind ip A.B.C.D", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 149 | "Bind the MGCP to this local addr") |
| 150 | { |
Holger Hans Peter Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 151 | bsc_replace_string(g_cfg, &g_cfg->source_addr, argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 152 | return CMD_SUCCESS; |
| 153 | } |
| 154 | |
| 155 | DEFUN(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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 161 | g_cfg->source_port = port; |
| 162 | return CMD_SUCCESS; |
| 163 | } |
| 164 | |
| 165 | DEFUN(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 Freyther | f1a168d | 2010-08-05 03:22:24 +0800 | [diff] [blame] | 170 | vty_out(vty, "bind early is deprecated, remove it from the config.\n"); |
| 171 | return CMD_WARNING; |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 172 | } |
| 173 | |
Holger Hans Peter Freyther | c5f9248 | 2010-09-17 23:34:36 +0800 | [diff] [blame] | 174 | static 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 | |
| 181 | static 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 Freyther | 196349d | 2010-08-05 03:46:07 +0800 | [diff] [blame] | 190 | DEFUN(cfg_mgcp_rtp_bts_base_port, |
| 191 | cfg_mgcp_rtp_bts_base_port_cmd, |
| 192 | "rtp bts-base <0-65534>", |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 193 | "Base port to use") |
| 194 | { |
Holger Hans Peter Freyther | c5f9248 | 2010-09-17 23:34:36 +0800 | [diff] [blame] | 195 | parse_base(&g_cfg->bts_ports, argv); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 196 | return CMD_SUCCESS; |
| 197 | } |
| 198 | |
Holger Hans Peter Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 199 | DEFUN(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 Freyther | c5f9248 | 2010-09-17 23:34:36 +0800 | [diff] [blame] | 205 | parse_range(&g_cfg->bts_ports, argv); |
Holger Hans Peter Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 206 | return CMD_SUCCESS; |
| 207 | } |
| 208 | |
| 209 | DEFUN(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 Freyther | c5f9248 | 2010-09-17 23:34:36 +0800 | [diff] [blame] | 215 | parse_range(&g_cfg->net_ports, argv); |
Holger Hans Peter Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 216 | return CMD_SUCCESS; |
| 217 | } |
| 218 | |
Holger Hans Peter Freyther | 314584a | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 219 | DEFUN(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 Freyther | c5f9248 | 2010-09-17 23:34:36 +0800 | [diff] [blame] | 224 | parse_base(&g_cfg->net_ports, argv); |
Holger Hans Peter Freyther | 314584a | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 225 | return CMD_SUCCESS; |
| 226 | } |
| 227 | |
Holger Hans Peter Freyther | 196349d | 2010-08-05 03:46:07 +0800 | [diff] [blame] | 228 | ALIAS_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 Freyther | 54aaa0f | 2010-09-17 23:35:53 +0800 | [diff] [blame] | 231 | DEFUN(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 | |
| 241 | DEFUN(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 Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 250 | DEFUN(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 Freyther | 75492e6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 254 | { |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 255 | int dscp = atoi(argv[0]); |
| 256 | g_cfg->endp_dscp = dscp; |
Holger Hans Peter Freyther | 75492e6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 257 | return CMD_SUCCESS; |
| 258 | } |
| 259 | |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 260 | ALIAS_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 Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 265 | DEFUN(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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 271 | g_cfg->trunk.audio_payload = payload; |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 272 | return CMD_SUCCESS; |
| 273 | } |
| 274 | |
| 275 | DEFUN(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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 280 | bsc_replace_string(g_cfg, &g_cfg->trunk.audio_name, argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 281 | return CMD_SUCCESS; |
| 282 | } |
| 283 | |
| 284 | DEFUN(cfg_mgcp_loop, |
| 285 | cfg_mgcp_loop_cmd, |
| 286 | "loop (0|1)", |
| 287 | "Loop the audio") |
| 288 | { |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 289 | g_cfg->trunk.audio_loop = atoi(argv[0]); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 290 | return CMD_SUCCESS; |
| 291 | } |
| 292 | |
| 293 | DEFUN(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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 299 | g_cfg->trunk.number_endpoints = atoi(argv[0]) + 1; |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 300 | return CMD_SUCCESS; |
| 301 | } |
| 302 | |
Holger Hans Peter Freyther | b79994c | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 303 | DEFUN(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 Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 308 | bsc_replace_string(g_cfg, &g_cfg->call_agent_addr, argv[0]); |
Holger Hans Peter Freyther | b79994c | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 309 | return CMD_SUCCESS; |
| 310 | } |
| 311 | |
Holger Hans Peter Freyther | a2a10eb | 2010-09-17 03:58:52 +0800 | [diff] [blame] | 312 | DEFUN(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 Freyther | 3e9a7f8 | 2010-10-12 23:21:54 +0200 | [diff] [blame] | 318 | bsc_replace_string(g_cfg, &g_cfg->transcoder_ip, argv[0]); |
Holger Hans Peter Freyther | a2a10eb | 2010-09-17 03:58:52 +0800 | [diff] [blame] | 319 | inet_aton(g_cfg->transcoder_ip, &g_cfg->transcoder_in); |
| 320 | |
| 321 | return CMD_SUCCESS; |
| 322 | } |
| 323 | |
Holger Hans Peter Freyther | 88b597e | 2010-11-01 20:06:45 +0100 | [diff] [blame] | 324 | DEFUN(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 Freyther | b98ba72 | 2010-09-19 04:21:39 +0800 | [diff] [blame] | 338 | DEFUN(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 Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 348 | DEFUN(loop_endp, |
| 349 | loop_endp_cmd, |
| 350 | "loop-endpoint NAME (0|1)", |
| 351 | "Loop a given endpoint\n" |
Holger Hans Peter Freyther | ebc824c | 2010-08-03 23:00:03 +0800 | [diff] [blame] | 352 | "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] | 353 | { |
| 354 | struct mgcp_endpoint *endp; |
| 355 | |
| 356 | int endp_no = strtoul(argv[0], NULL, 16); |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 357 | if (endp_no < 1 || endp_no >= g_cfg->trunk.number_endpoints) { |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 358 | 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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 364 | endp = &g_cfg->trunk.endpoints[endp_no]; |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 365 | 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 Freyther | 6357a8e | 2010-08-05 12:07:00 +0000 | [diff] [blame] | 371 | endp->allow_patch = 1; |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 372 | |
| 373 | return CMD_SUCCESS; |
| 374 | } |
| 375 | |
Holger Hans Peter Freyther | 260d6ed | 2010-08-06 01:12:21 +0800 | [diff] [blame] | 376 | DEFUN(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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 392 | if (endp_no < 1 || endp_no >= g_cfg->trunk.number_endpoints) { |
Holger Hans Peter Freyther | 260d6ed | 2010-08-06 01:12:21 +0800 | [diff] [blame] | 393 | 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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 398 | endp = &g_cfg->trunk.endpoints[endp_no]; |
Holger Hans Peter Freyther | 260d6ed | 2010-08-06 01:12:21 +0800 | [diff] [blame] | 399 | |
| 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 Freyther | 0e01d09 | 2010-08-06 02:05:15 +0800 | [diff] [blame] | 417 | tap->enabled = 1; |
Holger Hans Peter Freyther | 260d6ed | 2010-08-06 01:12:21 +0800 | [diff] [blame] | 418 | return CMD_SUCCESS; |
| 419 | } |
| 420 | |
Holger Hans Peter Freyther | 5508fe3 | 2010-08-08 16:39:57 +0800 | [diff] [blame] | 421 | DEFUN(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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 428 | if (endp_no < 1 || endp_no >= g_cfg->trunk.number_endpoints) { |
Holger Hans Peter Freyther | 5508fe3 | 2010-08-08 16:39:57 +0800 | [diff] [blame] | 429 | 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 Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 434 | endp = &g_cfg->trunk.endpoints[endp_no]; |
Holger Hans Peter Freyther | 5508fe3 | 2010-08-08 16:39:57 +0800 | [diff] [blame] | 435 | mgcp_free_endp(endp); |
| 436 | return CMD_SUCCESS; |
| 437 | } |
| 438 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 439 | int mgcp_vty_init(void) |
| 440 | { |
Holger Hans Peter Freyther | b5be7ac | 2010-05-14 02:45:52 +0800 | [diff] [blame] | 441 | install_element_ve(&show_mgcp_cmd); |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 442 | install_element(ENABLE_NODE, &loop_endp_cmd); |
Holger Hans Peter Freyther | 260d6ed | 2010-08-06 01:12:21 +0800 | [diff] [blame] | 443 | install_element(ENABLE_NODE, &tap_call_cmd); |
Holger Hans Peter Freyther | 5508fe3 | 2010-08-08 16:39:57 +0800 | [diff] [blame] | 444 | install_element(ENABLE_NODE, &free_endp_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 445 | |
| 446 | install_element(CONFIG_NODE, &cfg_mgcp_cmd); |
| 447 | install_node(&mgcp_node, config_write_mgcp); |
Holger Hans Peter Freyther | c597a4e | 2010-08-03 02:57:02 +0800 | [diff] [blame] | 448 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 449 | install_default(MGCP_NODE); |
Harald Welte | 62ab20c | 2010-05-14 18:59:17 +0200 | [diff] [blame] | 450 | install_element(MGCP_NODE, &ournode_exit_cmd); |
Harald Welte | 54f7424 | 2010-05-14 19:11:04 +0200 | [diff] [blame] | 451 | install_element(MGCP_NODE, &ournode_end_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 452 | 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 Freyther | 196349d | 2010-08-05 03:46:07 +0800 | [diff] [blame] | 458 | install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_base_port_cmd); |
Holger Hans Peter Freyther | 314584a | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 459 | install_element(MGCP_NODE, &cfg_mgcp_rtp_net_base_port_cmd); |
Holger Hans Peter Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 460 | install_element(MGCP_NODE, &cfg_mgcp_rtp_bts_range_cmd); |
| 461 | install_element(MGCP_NODE, &cfg_mgcp_rtp_net_range_cmd); |
Holger Hans Peter Freyther | 54aaa0f | 2010-09-17 23:35:53 +0800 | [diff] [blame] | 462 | install_element(MGCP_NODE, &cfg_mgcp_rtp_transcoder_range_cmd); |
| 463 | install_element(MGCP_NODE, &cfg_mgcp_rtp_transcoder_base_cmd); |
Holger Hans Peter Freyther | d0c3229 | 2010-07-27 20:34:45 +0800 | [diff] [blame] | 464 | install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd); |
Holger Hans Peter Freyther | 75492e6 | 2010-05-31 10:22:00 +0800 | [diff] [blame] | 465 | install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 466 | 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 Freyther | b79994c | 2010-03-31 11:46:41 +0200 | [diff] [blame] | 470 | install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd); |
Holger Hans Peter Freyther | a2a10eb | 2010-09-17 03:58:52 +0800 | [diff] [blame] | 471 | install_element(MGCP_NODE, &cfg_mgcp_transcoder_cmd); |
Holger Hans Peter Freyther | 88b597e | 2010-11-01 20:06:45 +0100 | [diff] [blame] | 472 | install_element(MGCP_NODE, &cfg_mgcp_no_transcoder_cmd); |
Holger Hans Peter Freyther | b98ba72 | 2010-09-19 04:21:39 +0800 | [diff] [blame] | 473 | install_element(MGCP_NODE, &cfg_mgcp_transcoder_remote_base_cmd); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 474 | return 0; |
| 475 | } |
| 476 | |
| 477 | int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg) |
| 478 | { |
| 479 | int i, rc; |
| 480 | |
| 481 | g_cfg = cfg; |
Harald Welte | dcccb18 | 2010-05-16 20:52:23 +0200 | [diff] [blame] | 482 | rc = vty_read_config_file(config_file, NULL); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 483 | 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 Freyther | 95e4d34 | 2010-03-30 13:00:10 +0200 | [diff] [blame] | 492 | if (!g_cfg->source_addr) { |
| 493 | fprintf(stderr, "You need to specify a bind address.\n"); |
| 494 | return -1; |
| 495 | } |
| 496 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 497 | if (mgcp_endpoints_allocate(g_cfg) != 0) { |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 498 | fprintf(stderr, "Failed to allocate endpoints: %d. Quitting.\n", |
| 499 | g_cfg->trunk.number_endpoints); |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 500 | return -1; |
| 501 | } |
| 502 | |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 503 | /* early bind */ |
Holger Hans Peter Freyther | 88ad772 | 2011-02-28 00:56:17 +0100 | [diff] [blame^] | 504 | for (i = 1; i < g_cfg->trunk.number_endpoints; ++i) { |
| 505 | struct mgcp_endpoint *endp = &g_cfg->trunk.endpoints[i]; |
Holger Hans Peter Freyther | f1a168d | 2010-08-05 03:22:24 +0800 | [diff] [blame] | 506 | int rtp_port; |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 507 | |
Holger Hans Peter Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 508 | 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 Freyther | f138f91 | 2010-08-05 08:08:17 +0800 | [diff] [blame] | 515 | endp->bts_end.local_alloc = PORT_ALLOC_STATIC; |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 516 | } |
Holger Hans Peter Freyther | 314584a | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 517 | |
Holger Hans Peter Freyther | 1be9f2f | 2010-08-05 07:20:09 +0800 | [diff] [blame] | 518 | 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 Freyther | f138f91 | 2010-08-05 08:08:17 +0800 | [diff] [blame] | 525 | endp->net_end.local_alloc = PORT_ALLOC_STATIC; |
Holger Hans Peter Freyther | 314584a | 2010-08-05 04:10:21 +0800 | [diff] [blame] | 526 | } |
Holger Hans Peter Freyther | 218f856 | 2010-09-18 02:30:02 +0800 | [diff] [blame] | 527 | |
| 528 | if (g_cfg->transcoder_ip && g_cfg->transcoder_ports.mode == PORT_ALLOC_STATIC) { |
Holger Hans Peter Freyther | bd7b3c5 | 2010-11-01 21:04:54 +0100 | [diff] [blame] | 529 | /* network side */ |
Holger Hans Peter Freyther | 218f856 | 2010-09-18 02:30:02 +0800 | [diff] [blame] | 530 | rtp_port = rtp_calculate_port(ENDPOINT_NUMBER(endp), |
| 531 | g_cfg->transcoder_ports.base_port); |
Holger Hans Peter Freyther | bd7b3c5 | 2010-11-01 21:04:54 +0100 | [diff] [blame] | 532 | if (mgcp_bind_trans_net_rtp_port(endp, rtp_port) != 0) { |
Holger Hans Peter Freyther | 218f856 | 2010-09-18 02:30:02 +0800 | [diff] [blame] | 533 | LOGP(DMGCP, LOGL_FATAL, "Failed to bind: %d\n", rtp_port); |
| 534 | return -1; |
| 535 | } |
Holger Hans Peter Freyther | 2126233 | 2010-11-01 20:53:31 +0100 | [diff] [blame] | 536 | endp->trans_net.local_alloc = PORT_ALLOC_STATIC; |
Holger Hans Peter Freyther | bd7b3c5 | 2010-11-01 21:04:54 +0100 | [diff] [blame] | 537 | |
| 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 Freyther | 218f856 | 2010-09-18 02:30:02 +0800 | [diff] [blame] | 546 | } |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 547 | } |
| 548 | |
Holger Hans Peter Freyther | 8b5772e | 2010-08-05 01:28:22 +0800 | [diff] [blame] | 549 | return 0; |
Holger Hans Peter Freyther | 7bdc637 | 2010-02-20 21:21:02 +0100 | [diff] [blame] | 550 | } |
| 551 | |