blob: 5f9853b813acf298f5c51222df56fc60b9d897b5 [file] [log] [blame]
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001/* A Media Gateway Control Protocol Media Gateway: RFC 3435 */
2/* The protocol implementation */
3
4/*
5 * (C) 2009-2014 by Holger Hans Peter Freyther <zecke@selfish.org>
6 * (C) 2009-2011 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 Affero General Public License as published by
11 * the Free Software Foundation; either version 3 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 Affero General Public License for more details.
18 *
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/>.
21 *
22 */
23
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020024#include <osmocom/core/talloc.h>
Stefan Sperling1e174872018-10-25 18:36:10 +020025#include <osmocom/vty/misc.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020026#include <osmocom/mgcp/mgcp.h>
Neels Hofmeyr67793542017-09-08 04:25:16 +020027#include <osmocom/mgcp/mgcp_common.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020028#include <osmocom/mgcp/mgcp_internal.h>
29#include <osmocom/mgcp/vty.h>
30#include <osmocom/mgcp/mgcp_conn.h>
Philipp Maier37d11c82018-02-01 14:38:12 +010031#include <osmocom/mgcp/mgcp_endp.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020032
33#include <string.h>
Philipp Maierbca0ef62018-07-09 17:20:51 +020034#include <inttypes.h>
Stefan Sperling12086582018-06-26 15:26:28 +020035#include <limits.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020036
37#define RTCP_OMIT_STR "Drop RTCP packets in both directions\n"
38#define RTP_PATCH_STR "Modify RTP packet header in both directions\n"
39#define RTP_KEEPALIVE_STR "Send dummy UDP packet to net RTP destination\n"
Philipp Maier9fc8a022019-02-20 12:26:52 +010040#define RTP_TS101318_RFC5993_CONV_STR "Convert GSM-HR from TS101318 to RFC5993 and vice versa\n"
41
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020042
43static struct mgcp_config *g_cfg = NULL;
44
45static struct mgcp_trunk_config *find_trunk(struct mgcp_config *cfg, int nr)
46{
47 struct mgcp_trunk_config *trunk;
48
49 if (nr == 0)
50 trunk = &cfg->trunk;
51 else
52 trunk = mgcp_trunk_num(cfg, nr);
53
54 return trunk;
55}
56
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020057struct cmd_node mgcp_node = {
58 MGCP_NODE,
59 "%s(config-mgcp)# ",
60 1,
61};
62
63struct cmd_node trunk_node = {
64 TRUNK_NODE,
65 "%s(config-mgcp-trunk)# ",
66 1,
67};
68
69static int config_write_mgcp(struct vty *vty)
70{
71 vty_out(vty, "mgcp%s", VTY_NEWLINE);
Philipp Maier12943ea2018-01-17 15:40:25 +010072 vty_out(vty, " domain %s%s", g_cfg->domain, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020073 if (g_cfg->local_ip)
74 vty_out(vty, " local ip %s%s", g_cfg->local_ip, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020075 vty_out(vty, " bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
76 vty_out(vty, " bind port %u%s", g_cfg->source_port, VTY_NEWLINE);
Philipp Maierf1889d82017-11-08 14:59:39 +010077 vty_out(vty, " rtp port-range %u %u%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +020078 g_cfg->net_ports.range_start, g_cfg->net_ports.range_end,
79 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020080 if (g_cfg->net_ports.bind_addr)
Philipp Maierf1889d82017-11-08 14:59:39 +010081 vty_out(vty, " rtp bind-ip %s%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +020082 g_cfg->net_ports.bind_addr, VTY_NEWLINE);
Philipp Maier1cb1e382017-11-02 17:16:04 +010083 if (g_cfg->net_ports.bind_addr_probe)
84 vty_out(vty, " rtp ip-probing%s", VTY_NEWLINE);
85 else
86 vty_out(vty, " no rtp ip-probing%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020087 vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
88 if (g_cfg->trunk.keepalive_interval == MGCP_KEEPALIVE_ONCE)
89 vty_out(vty, " rtp keep-alive once%s", VTY_NEWLINE);
90 else if (g_cfg->trunk.keepalive_interval)
91 vty_out(vty, " rtp keep-alive %d%s",
92 g_cfg->trunk.keepalive_interval, VTY_NEWLINE);
93 else
94 vty_out(vty, " no rtp keep-alive%s", VTY_NEWLINE);
95
96 if (g_cfg->trunk.omit_rtcp)
97 vty_out(vty, " rtcp-omit%s", VTY_NEWLINE);
98 else
99 vty_out(vty, " no rtcp-omit%s", VTY_NEWLINE);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200100 if (g_cfg->trunk.force_constant_ssrc
Philipp Maier9fc8a022019-02-20 12:26:52 +0100101 || g_cfg->trunk.force_aligned_timing
102 || g_cfg->trunk.rfc5993_hr_convert) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200103 vty_out(vty, " %srtp-patch ssrc%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200104 g_cfg->trunk.force_constant_ssrc ? "" : "no ",
105 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200106 vty_out(vty, " %srtp-patch timestamp%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200107 g_cfg->trunk.force_aligned_timing ? "" : "no ",
108 VTY_NEWLINE);
Philipp Maier9fc8a022019-02-20 12:26:52 +0100109 vty_out(vty, " %srtp-patch rfc5993hr%s",
110 g_cfg->trunk.rfc5993_hr_convert ? "" : "no ",
111 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200112 } else
113 vty_out(vty, " no rtp-patch%s", VTY_NEWLINE);
114 if (g_cfg->trunk.audio_payload != -1)
115 vty_out(vty, " sdp audio-payload number %d%s",
116 g_cfg->trunk.audio_payload, VTY_NEWLINE);
117 if (g_cfg->trunk.audio_name)
118 vty_out(vty, " sdp audio-payload name %s%s",
119 g_cfg->trunk.audio_name, VTY_NEWLINE);
120 if (g_cfg->trunk.audio_fmtp_extra)
121 vty_out(vty, " sdp audio fmtp-extra %s%s",
122 g_cfg->trunk.audio_fmtp_extra, VTY_NEWLINE);
123 vty_out(vty, " %ssdp audio-payload send-ptime%s",
124 g_cfg->trunk.audio_send_ptime ? "" : "no ", VTY_NEWLINE);
125 vty_out(vty, " %ssdp audio-payload send-name%s",
126 g_cfg->trunk.audio_send_name ? "" : "no ", VTY_NEWLINE);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200127 vty_out(vty, " loop %u%s", ! !g_cfg->trunk.audio_loop, VTY_NEWLINE);
128 vty_out(vty, " number endpoints %u%s",
Philipp Maierfcd06552017-11-10 17:32:22 +0100129 g_cfg->trunk.vty_number_endpoints - 1, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200130 vty_out(vty, " %sallow-transcoding%s",
131 g_cfg->trunk.no_audio_transcoding ? "no " : "", VTY_NEWLINE);
132 if (g_cfg->call_agent_addr)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200133 vty_out(vty, " call-agent ip %s%s", g_cfg->call_agent_addr,
134 VTY_NEWLINE);
135 if (g_cfg->force_ptime > 0)
136 vty_out(vty, " rtp force-ptime %d%s", g_cfg->force_ptime,
137 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200138
139 switch (g_cfg->osmux) {
140 case OSMUX_USAGE_ON:
141 vty_out(vty, " osmux on%s", VTY_NEWLINE);
142 break;
143 case OSMUX_USAGE_ONLY:
144 vty_out(vty, " osmux only%s", VTY_NEWLINE);
145 break;
146 case OSMUX_USAGE_OFF:
147 default:
148 vty_out(vty, " osmux off%s", VTY_NEWLINE);
149 break;
150 }
151 if (g_cfg->osmux) {
152 vty_out(vty, " osmux bind-ip %s%s",
153 g_cfg->osmux_addr, VTY_NEWLINE);
154 vty_out(vty, " osmux batch-factor %d%s",
155 g_cfg->osmux_batch, VTY_NEWLINE);
156 vty_out(vty, " osmux batch-size %u%s",
157 g_cfg->osmux_batch_size, VTY_NEWLINE);
158 vty_out(vty, " osmux port %u%s",
159 g_cfg->osmux_port, VTY_NEWLINE);
160 vty_out(vty, " osmux dummy %s%s",
161 g_cfg->osmux_dummy ? "on" : "off", VTY_NEWLINE);
162 }
Oliver Smithe36b7752019-01-22 16:31:36 +0100163
164 if (g_cfg->conn_timeout)
165 vty_out(vty, " conn-timeout %u%s", g_cfg->conn_timeout, VTY_NEWLINE);
166
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200167 return CMD_SUCCESS;
168}
169
Philipp Maiercede2a42018-07-03 14:14:21 +0200170static void dump_rtp_end(struct vty *vty, struct mgcp_conn_rtp *conn)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200171{
Philipp Maiercede2a42018-07-03 14:14:21 +0200172 struct mgcp_rtp_state *state = &conn->state;
173 struct mgcp_rtp_end *end = &conn->end;
Philipp Maierbc0346e2018-06-07 09:52:16 +0200174 struct mgcp_rtp_codec *codec = end->codec;
Stefan Sperlingb7974e22018-10-29 13:22:00 +0100175 struct rate_ctr *tx_packets, *tx_bytes;
176 struct rate_ctr *rx_packets, *rx_bytes;
Philipp Maiercede2a42018-07-03 14:14:21 +0200177 struct rate_ctr *dropped_packets;
178
Stefan Sperlingb7974e22018-10-29 13:22:00 +0100179 tx_packets = &conn->rate_ctr_group->ctr[RTP_PACKETS_TX_CTR];
180 tx_bytes = &conn->rate_ctr_group->ctr[RTP_OCTETS_TX_CTR];
181 rx_packets = &conn->rate_ctr_group->ctr[RTP_PACKETS_RX_CTR];
182 rx_bytes = &conn->rate_ctr_group->ctr[RTP_OCTETS_RX_CTR];
Philipp Maiercede2a42018-07-03 14:14:21 +0200183 dropped_packets = &conn->rate_ctr_group->ctr[RTP_DROPPED_PACKETS_CTR];
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200184
185 vty_out(vty,
Stefan Sperlingb7974e22018-10-29 13:22:00 +0100186 " Packets Sent: %" PRIu64 " (%" PRIu64 " bytes total)%s"
187 " Packets Received: %" PRIu64 " (%" PRIu64 " bytes total)%s"
Philipp Maierbca0ef62018-07-09 17:20:51 +0200188 " Timestamp Errs: %" PRIu64 "->%" PRIu64 "%s"
189 " Dropped Packets: %" PRIu64 "%s"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200190 " Payload Type: %d Rate: %u Channels: %d %s"
191 " Frame Duration: %u Frame Denominator: %u%s"
192 " FPP: %d Packet Duration: %u%s"
193 " FMTP-Extra: %s Audio-Name: %s Sub-Type: %s%s"
194 " Output-Enabled: %d Force-PTIME: %d%s",
Stefan Sperlingb7974e22018-10-29 13:22:00 +0100195 tx_packets->current, tx_bytes->current, VTY_NEWLINE,
196 rx_packets->current, rx_bytes->current, VTY_NEWLINE,
Philipp Maier9e1d1642018-05-09 16:26:34 +0200197 state->in_stream.err_ts_ctr->current,
198 state->out_stream.err_ts_ctr->current,
199 VTY_NEWLINE,
Philipp Maiercede2a42018-07-03 14:14:21 +0200200 dropped_packets->current, VTY_NEWLINE,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200201 codec->payload_type, codec->rate, codec->channels, VTY_NEWLINE,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200202 codec->frame_duration_num, codec->frame_duration_den,
203 VTY_NEWLINE, end->frames_per_packet, end->packet_duration_ms,
204 VTY_NEWLINE, end->fmtp_extra, codec->audio_name,
205 codec->subtype_name, VTY_NEWLINE, end->output_enabled,
206 end->force_output_ptime, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200207}
208
Stefan Sperling12086582018-06-26 15:26:28 +0200209static void dump_endpoint(struct vty *vty, struct mgcp_endpoint *endp, int epidx,
210 int trunk_nr, enum mgcp_trunk_type trunk_type, int show_stats)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200211{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200212 struct mgcp_conn *conn;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200213
Stefan Sperling12086582018-06-26 15:26:28 +0200214 vty_out(vty, "%s trunk %d endpoint %s%.2x:%s",
215 trunk_type == MGCP_TRUNK_VIRTUAL ? "Virtual" : "E1", trunk_nr,
216 trunk_type == MGCP_TRUNK_VIRTUAL ? MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK : "",
217 epidx, VTY_NEWLINE);
218
219 if (llist_empty(&endp->conns)) {
220 vty_out(vty, " No active connections%s", VTY_NEWLINE);
221 return;
222 }
223
224 llist_for_each_entry(conn, &endp->conns, entry) {
225 vty_out(vty, " CONN: %s%s", mgcp_conn_dump(conn), VTY_NEWLINE);
226
227 if (show_stats) {
Oliver Smithe36b7752019-01-22 16:31:36 +0100228 if (endp->cfg->conn_timeout) {
229 struct timeval remaining;
230 osmo_timer_remaining(&conn->watchdog, NULL, &remaining);
231 vty_out(vty, " Currently remaining timeout (seconds): %d.%06d%s",
232 (int)remaining.tv_sec, (int)remaining.tv_usec, VTY_NEWLINE);
233 }
234
Stefan Sperling12086582018-06-26 15:26:28 +0200235 /* FIXME: Also add verbosity for other
236 * connection types (E1) as soon as
237 * the implementation is available */
238 if (conn->type == MGCP_CONN_TYPE_RTP) {
239 dump_rtp_end(vty, &conn->u.rtp);
240 }
241 }
242 }
243}
244
245static void dump_trunk(struct vty *vty, struct mgcp_trunk_config *cfg, int show_stats)
246{
247 int i;
248
249 vty_out(vty, "%s trunk %d with %d endpoints:%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200250 cfg->trunk_type == MGCP_TRUNK_VIRTUAL ? "Virtual" : "E1",
251 cfg->trunk_nr, cfg->number_endpoints - 1, VTY_NEWLINE);
252
253 if (!cfg->endpoints) {
254 vty_out(vty, "No endpoints allocated yet.%s", VTY_NEWLINE);
255 return;
256 }
257
258 for (i = 1; i < cfg->number_endpoints; ++i) {
259 struct mgcp_endpoint *endp = &cfg->endpoints[i];
Stefan Sperling12086582018-06-26 15:26:28 +0200260 dump_endpoint(vty, endp, i, cfg->trunk_nr, cfg->trunk_type, show_stats);
261 if (i < cfg->number_endpoints - 1)
262 vty_out(vty, "%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200263 }
Stefan Sperling1e174872018-10-25 18:36:10 +0200264
265 if (show_stats && cfg->mgcp_crcx_ctr_group) {
266 vty_out(vty, " %s:%s", cfg->mgcp_crcx_ctr_group->desc->group_description, VTY_NEWLINE);
267 vty_out_rate_ctr_group_fmt(vty, " %25n: %10c (%S/s %M/m %H/h %D/d) %d", cfg->mgcp_crcx_ctr_group);
268 }
Stefan Sperling8ab3fbb2018-10-30 14:57:25 +0100269 if (show_stats && cfg->mgcp_dlcx_ctr_group) {
270 vty_out(vty, " %s:%s", cfg->mgcp_dlcx_ctr_group->desc->group_description, VTY_NEWLINE);
271 vty_out_rate_ctr_group_fmt(vty, " %25n: %10c (%S/s %M/m %H/h %D/d) %d", cfg->mgcp_dlcx_ctr_group);
272 }
Stefan Sperlingaa823bf2018-10-29 14:51:41 +0100273 if (show_stats && cfg->mgcp_mdcx_ctr_group) {
274 vty_out(vty, " %s:%s", cfg->mgcp_mdcx_ctr_group->desc->group_description, VTY_NEWLINE);
275 vty_out_rate_ctr_group_fmt(vty, " %25n: %10c (%S/s %M/m %H/h %D/d) %d", cfg->mgcp_mdcx_ctr_group);
276 }
Stefan Sperlingba25eab2018-10-30 14:32:31 +0100277 if (show_stats && cfg->all_rtp_conn_stats) {
278 vty_out(vty, " %s:%s", cfg->all_rtp_conn_stats->desc->group_description, VTY_NEWLINE);
279 vty_out_rate_ctr_group_fmt(vty, " %25n: %10c (%S/s %M/m %H/h %D/d) %d", cfg->all_rtp_conn_stats);
280 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200281}
282
Stefan Sperling12086582018-06-26 15:26:28 +0200283#define SHOW_MGCP_STR "Display information about the MGCP Media Gateway\n"
284
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200285DEFUN(show_mcgp, show_mgcp_cmd,
286 "show mgcp [stats]",
287 SHOW_STR
Stefan Sperling12086582018-06-26 15:26:28 +0200288 SHOW_MGCP_STR
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200289 "Include Statistics\n")
290{
291 struct mgcp_trunk_config *trunk;
292 int show_stats = argc >= 1;
293
294 dump_trunk(vty, &g_cfg->trunk, show_stats);
295
296 llist_for_each_entry(trunk, &g_cfg->trunks, entry)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200297 dump_trunk(vty, trunk, show_stats);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200298
299 if (g_cfg->osmux)
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +0200300 vty_out(vty, "Osmux used CID: %d%s", osmux_cid_pool_count_used(),
Philipp Maier87bd9be2017-08-22 16:35:41 +0200301 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200302
303 return CMD_SUCCESS;
304}
305
Stefan Sperling12086582018-06-26 15:26:28 +0200306static void
307dump_mgcp_endpoint(struct vty *vty, struct mgcp_trunk_config *trunk, const char *epname)
308{
309 const size_t virt_prefix_len = sizeof(MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK) - 1;
310 unsigned long epidx;
311 char *endp;
312 int i;
313
314 if (strncmp(epname, MGCP_ENDPOINT_PREFIX_VIRTUAL_TRUNK, virt_prefix_len) == 0)
315 epname += virt_prefix_len;
316 errno = 0;
317 epidx = strtoul(epname, &endp, 16);
318 if (epname[0] == '\0' || *endp != '\0') {
319 vty_out(vty, "endpoint name '%s' is not a hex number%s", epname, VTY_NEWLINE);
320 return;
321 }
322 if ((errno == ERANGE && epidx == ULONG_MAX) /* parsed value out of range */
323 || epidx >= trunk->number_endpoints) {
324 vty_out(vty, "endpoint %.2lx not configured on trunk %d%s", epidx, trunk->trunk_nr, VTY_NEWLINE);
325 return;
326 }
327
328 for (i = 0; i < trunk->number_endpoints; ++i) {
329 struct mgcp_endpoint *endp = &trunk->endpoints[i];
330 if (i == epidx) {
331 dump_endpoint(vty, endp, i, trunk->trunk_nr, trunk->trunk_type, true);
332 break;
333 }
334 }
335}
336
337DEFUN(show_mcgp_endpoint, show_mgcp_endpoint_cmd,
338 "show mgcp endpoint NAME",
339 SHOW_STR
340 SHOW_MGCP_STR
341 "Display information about an endpoint\n" "The name of the endpoint\n")
342{
343 struct mgcp_trunk_config *trunk;
344
345 dump_mgcp_endpoint(vty, &g_cfg->trunk, argv[0]);
346 llist_for_each_entry(trunk, &g_cfg->trunks, entry)
347 dump_mgcp_endpoint(vty, trunk, argv[0]);
348
349 return CMD_SUCCESS;
350}
351
352DEFUN(show_mcgp_trunk_endpoint, show_mgcp_trunk_endpoint_cmd,
353 "show mgcp trunk <0-64> endpoint NAME",
354 SHOW_STR
355 SHOW_MGCP_STR
356 "Display information about a trunk\n" "Trunk number\n"
357 "Display information about an endpoint\n" "The name of the endpoint\n")
358{
359 struct mgcp_trunk_config *trunk;
360 int trunkidx = atoi(argv[0]);
361
362 trunk = find_trunk(g_cfg, trunkidx);
363 if (!trunk) {
364 vty_out(vty, "trunk %d not found%s", trunkidx, VTY_NEWLINE);
365 return CMD_WARNING;
366 }
367
368 dump_mgcp_endpoint(vty, trunk, argv[1]);
369 return CMD_SUCCESS;
370}
371
Philipp Maier87bd9be2017-08-22 16:35:41 +0200372DEFUN(cfg_mgcp, cfg_mgcp_cmd, "mgcp", "Configure the MGCP")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200373{
374 vty->node = MGCP_NODE;
375 return CMD_SUCCESS;
376}
377
378DEFUN(cfg_mgcp_local_ip,
379 cfg_mgcp_local_ip_cmd,
380 "local ip A.B.C.D",
381 "Local options for the SDP record\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +0200382 IP_STR "IPv4 Address to use in SDP record\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200383{
384 osmo_talloc_replace_string(g_cfg, &g_cfg->local_ip, argv[0]);
385 return CMD_SUCCESS;
386}
387
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200388#define BIND_STR "Listen/Bind related socket option\n"
389DEFUN(cfg_mgcp_bind_ip,
390 cfg_mgcp_bind_ip_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200391 "bind ip A.B.C.D", BIND_STR IP_STR "IPv4 Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200392{
393 osmo_talloc_replace_string(g_cfg, &g_cfg->source_addr, argv[0]);
394 return CMD_SUCCESS;
395}
396
397DEFUN(cfg_mgcp_bind_port,
398 cfg_mgcp_bind_port_cmd,
399 "bind port <0-65534>",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200400 BIND_STR "Port information\n" "UDP port to listen for MGCP messages\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200401{
402 unsigned int port = atoi(argv[0]);
403 g_cfg->source_port = port;
404 return CMD_SUCCESS;
405}
406
407DEFUN(cfg_mgcp_bind_early,
408 cfg_mgcp_bind_early_cmd,
409 "bind early (0|1)",
410 BIND_STR
Philipp Maier87bd9be2017-08-22 16:35:41 +0200411 "Bind local ports on start up\n" "Bind on demand\n" "Bind on startup\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200412{
413 vty_out(vty, "bind early is deprecated, remove it from the config.\n");
414 return CMD_WARNING;
415}
416
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200417#define RTP_STR "RTP configuration\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200418#define UDP_PORT_STR "UDP Port number\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +0200419#define NET_START_STR "First UDP port allocated\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200420#define RANGE_START_STR "Start of the range of ports\n"
421#define RANGE_END_STR "End of the range of ports\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200422
Philipp Maierf1889d82017-11-08 14:59:39 +0100423DEFUN(cfg_mgcp_rtp_port_range,
424 cfg_mgcp_rtp_port_range_cmd,
Philipp Maiera19547b2018-05-22 13:44:34 +0200425 "rtp port-range <1024-65534> <1025-65535>",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200426 RTP_STR "Range of ports to use for the NET side\n"
427 RANGE_START_STR RANGE_END_STR)
428{
Philipp Maiera19547b2018-05-22 13:44:34 +0200429 int start;
430 int end;
431
432 start = atoi(argv[0]);
433 end = atoi(argv[1]);
434
435 if (end < start) {
436 vty_out(vty, "range end port (%i) must be greater than the range start port (%i)!%s",
437 end, start, VTY_NEWLINE);
438 return CMD_WARNING;
439 }
440
441 if (start & 1) {
442 vty_out(vty, "range must begin at an even port number, autocorrecting port (%i) to: %i%s",
443 start, start & 0xFFFE, VTY_NEWLINE);
444 start &= 0xFFFE;
445 }
446
447 if ((end & 1) == 0) {
448 vty_out(vty, "range must end at an odd port number, autocorrecting port (%i) to: %i%s",
449 end, end | 1, VTY_NEWLINE);
450 end |= 1;
451 }
452
453 g_cfg->net_ports.range_start = start;
454 g_cfg->net_ports.range_end = end;
455 g_cfg->net_ports.last_port = g_cfg->net_ports.range_start;
456
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200457 return CMD_SUCCESS;
458}
Philipp Maierf1889d82017-11-08 14:59:39 +0100459ALIAS_DEPRECATED(cfg_mgcp_rtp_port_range,
460 cfg_mgcp_rtp_net_range_cmd,
461 "rtp net-range <0-65534> <0-65534>",
462 RTP_STR "Range of ports to use for the NET side\n"
463 RANGE_START_STR RANGE_END_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200464
Philipp Maierf1889d82017-11-08 14:59:39 +0100465DEFUN(cfg_mgcp_rtp_bind_ip,
466 cfg_mgcp_rtp_bind_ip_cmd,
467 "rtp bind-ip A.B.C.D",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200468 RTP_STR "Bind endpoints facing the Network\n" "Address to bind to\n")
469{
470 osmo_talloc_replace_string(g_cfg, &g_cfg->net_ports.bind_addr, argv[0]);
471 return CMD_SUCCESS;
472}
Philipp Maierf1889d82017-11-08 14:59:39 +0100473ALIAS_DEPRECATED(cfg_mgcp_rtp_bind_ip,
474 cfg_mgcp_rtp_net_bind_ip_cmd,
475 "rtp net-bind-ip A.B.C.D",
476 RTP_STR "Bind endpoints facing the Network\n" "Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200477
Philipp Maierf1889d82017-11-08 14:59:39 +0100478DEFUN(cfg_mgcp_rtp_no_bind_ip,
479 cfg_mgcp_rtp_no_bind_ip_cmd,
480 "no rtp bind-ip",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200481 NO_STR RTP_STR "Bind endpoints facing the Network\n"
482 "Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200483{
484 talloc_free(g_cfg->net_ports.bind_addr);
485 g_cfg->net_ports.bind_addr = NULL;
486 return CMD_SUCCESS;
487}
Philipp Maierf1889d82017-11-08 14:59:39 +0100488ALIAS_DEPRECATED(cfg_mgcp_rtp_no_bind_ip,
489 cfg_mgcp_rtp_no_net_bind_ip_cmd,
490 "no rtp net-bind-ip",
491 NO_STR RTP_STR "Bind endpoints facing the Network\n"
492 "Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200493
Philipp Maier1cb1e382017-11-02 17:16:04 +0100494DEFUN(cfg_mgcp_rtp_net_bind_ip_probing,
495 cfg_mgcp_rtp_net_bind_ip_probing_cmd,
496 "rtp ip-probing",
497 RTP_STR "automatic rtp bind ip selection\n")
498{
499 g_cfg->net_ports.bind_addr_probe = true;
500 return CMD_SUCCESS;
501}
502
503DEFUN(cfg_mgcp_rtp_no_net_bind_ip_probing,
504 cfg_mgcp_rtp_no_net_bind_ip_probing_cmd,
505 "no rtp ip-probing",
506 NO_STR RTP_STR "no automatic rtp bind ip selection\n")
507{
508 g_cfg->net_ports.bind_addr_probe = false;
509 return CMD_SUCCESS;
510}
511
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200512DEFUN(cfg_mgcp_rtp_ip_dscp,
513 cfg_mgcp_rtp_ip_dscp_cmd,
514 "rtp ip-dscp <0-255>",
515 RTP_STR
516 "Apply IP_TOS to the audio stream (including Osmux)\n" "The DSCP value\n")
517{
518 int dscp = atoi(argv[0]);
519 g_cfg->endp_dscp = dscp;
520 return CMD_SUCCESS;
521}
522
523ALIAS_DEPRECATED(cfg_mgcp_rtp_ip_dscp, cfg_mgcp_rtp_ip_tos_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200524 "rtp ip-tos <0-255>",
525 RTP_STR
526 "Apply IP_TOS to the audio stream\n" "The DSCP value\n")
527#define FORCE_PTIME_STR "Force a fixed ptime for packets sent"
528 DEFUN(cfg_mgcp_rtp_force_ptime,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200529 cfg_mgcp_rtp_force_ptime_cmd,
530 "rtp force-ptime (10|20|40)",
531 RTP_STR FORCE_PTIME_STR
Philipp Maier87bd9be2017-08-22 16:35:41 +0200532 "The required ptime (packet duration) in ms\n" "10 ms\n20 ms\n40 ms\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200533{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200534 g_cfg->force_ptime = atoi(argv[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200535 return CMD_SUCCESS;
536}
537
538DEFUN(cfg_mgcp_no_rtp_force_ptime,
539 cfg_mgcp_no_rtp_force_ptime_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200540 "no rtp force-ptime", NO_STR RTP_STR FORCE_PTIME_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200541{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200542 g_cfg->force_ptime = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200543 return CMD_SUCCESS;
544}
545
546DEFUN(cfg_mgcp_sdp_fmtp_extra,
547 cfg_mgcp_sdp_fmtp_extra_cmd,
548 "sdp audio fmtp-extra .NAME",
549 "Add extra fmtp for the SDP file\n" "Audio\n" "Fmtp-extra\n"
550 "Extra Information\n")
551{
552 char *txt = argv_concat(argv, argc, 0);
553 if (!txt)
554 return CMD_WARNING;
555
556 osmo_talloc_replace_string(g_cfg, &g_cfg->trunk.audio_fmtp_extra, txt);
557 talloc_free(txt);
558 return CMD_SUCCESS;
559}
560
561DEFUN(cfg_mgcp_allow_transcoding,
562 cfg_mgcp_allow_transcoding_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200563 "allow-transcoding", "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200564{
565 g_cfg->trunk.no_audio_transcoding = 0;
566 return CMD_SUCCESS;
567}
568
569DEFUN(cfg_mgcp_no_allow_transcoding,
570 cfg_mgcp_no_allow_transcoding_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200571 "no allow-transcoding", NO_STR "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200572{
573 g_cfg->trunk.no_audio_transcoding = 1;
574 return CMD_SUCCESS;
575}
576
577#define SDP_STR "SDP File related options\n"
578#define AUDIO_STR "Audio payload options\n"
579DEFUN(cfg_mgcp_sdp_payload_number,
580 cfg_mgcp_sdp_payload_number_cmd,
581 "sdp audio-payload number <0-255>",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200582 SDP_STR AUDIO_STR "Number\n" "Payload number\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200583{
584 unsigned int payload = atoi(argv[0]);
585 g_cfg->trunk.audio_payload = payload;
586 return CMD_SUCCESS;
587}
588
Philipp Maier87bd9be2017-08-22 16:35:41 +0200589ALIAS_DEPRECATED(cfg_mgcp_sdp_payload_number,
590 cfg_mgcp_sdp_payload_number_cmd_old,
591 "sdp audio payload number <0-255>",
592 SDP_STR AUDIO_STR AUDIO_STR "Number\n" "Payload number\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200593
Philipp Maier87bd9be2017-08-22 16:35:41 +0200594 DEFUN(cfg_mgcp_sdp_payload_name,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200595 cfg_mgcp_sdp_payload_name_cmd,
596 "sdp audio-payload name NAME",
597 SDP_STR AUDIO_STR "Name\n" "Payload name\n")
598{
599 osmo_talloc_replace_string(g_cfg, &g_cfg->trunk.audio_name, argv[0]);
600 return CMD_SUCCESS;
601}
602
603ALIAS_DEPRECATED(cfg_mgcp_sdp_payload_name, cfg_mgcp_sdp_payload_name_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200604 "sdp audio payload name NAME",
605 SDP_STR AUDIO_STR AUDIO_STR "Name\n" "Payload name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200606
Philipp Maier87bd9be2017-08-22 16:35:41 +0200607 DEFUN(cfg_mgcp_sdp_payload_send_ptime,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200608 cfg_mgcp_sdp_payload_send_ptime_cmd,
609 "sdp audio-payload send-ptime",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200610 SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200611{
612 g_cfg->trunk.audio_send_ptime = 1;
613 return CMD_SUCCESS;
614}
615
616DEFUN(cfg_mgcp_no_sdp_payload_send_ptime,
617 cfg_mgcp_no_sdp_payload_send_ptime_cmd,
618 "no sdp audio-payload send-ptime",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200619 NO_STR SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200620{
621 g_cfg->trunk.audio_send_ptime = 0;
622 return CMD_SUCCESS;
623}
624
625DEFUN(cfg_mgcp_sdp_payload_send_name,
626 cfg_mgcp_sdp_payload_send_name_cmd,
627 "sdp audio-payload send-name",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200628 SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200629{
630 g_cfg->trunk.audio_send_name = 1;
631 return CMD_SUCCESS;
632}
633
634DEFUN(cfg_mgcp_no_sdp_payload_send_name,
635 cfg_mgcp_no_sdp_payload_send_name_cmd,
636 "no sdp audio-payload send-name",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200637 NO_STR SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200638{
639 g_cfg->trunk.audio_send_name = 0;
640 return CMD_SUCCESS;
641}
642
643DEFUN(cfg_mgcp_loop,
644 cfg_mgcp_loop_cmd,
645 "loop (0|1)",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200646 "Loop audio for all endpoints on main trunk\n" "Don't Loop\n" "Loop\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200647{
648 if (g_cfg->osmux) {
649 vty_out(vty, "Cannot use `loop' with `osmux'.%s", VTY_NEWLINE);
650 return CMD_WARNING;
651 }
652 g_cfg->trunk.audio_loop = atoi(argv[0]);
653 return CMD_SUCCESS;
654}
655
656DEFUN(cfg_mgcp_force_realloc,
657 cfg_mgcp_force_realloc_cmd,
658 "force-realloc (0|1)",
659 "Force endpoint reallocation when the endpoint is still seized\n"
660 "Don't force reallocation\n" "force reallocation\n")
661{
662 g_cfg->trunk.force_realloc = atoi(argv[0]);
663 return CMD_SUCCESS;
664}
665
Philipp Maier87bd9be2017-08-22 16:35:41 +0200666DEFUN(cfg_mgcp_rtp_accept_all,
667 cfg_mgcp_rtp_accept_all_cmd,
668 "rtp-accept-all (0|1)",
669 "Accept all RTP packets, even when the originating IP/Port does not match\n"
670 "enable filter\n" "disable filter\n")
671{
672 g_cfg->trunk.rtp_accept_all = atoi(argv[0]);
673 return CMD_SUCCESS;
674}
675
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200676DEFUN(cfg_mgcp_number_endp,
677 cfg_mgcp_number_endp_cmd,
678 "number endpoints <0-65534>",
679 "Number options\n" "Endpoints available\n" "Number endpoints\n")
680{
681 /* + 1 as we start counting at one */
Philipp Maierfcd06552017-11-10 17:32:22 +0100682 g_cfg->trunk.vty_number_endpoints = atoi(argv[0]) + 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200683 return CMD_SUCCESS;
684}
685
Philipp Maier87bd9be2017-08-22 16:35:41 +0200686DEFUN(cfg_mgcp_omit_rtcp, cfg_mgcp_omit_rtcp_cmd, "rtcp-omit", RTCP_OMIT_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200687{
688 g_cfg->trunk.omit_rtcp = 1;
689 return CMD_SUCCESS;
690}
691
692DEFUN(cfg_mgcp_no_omit_rtcp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200693 cfg_mgcp_no_omit_rtcp_cmd, "no rtcp-omit", NO_STR RTCP_OMIT_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200694{
695 g_cfg->trunk.omit_rtcp = 0;
696 return CMD_SUCCESS;
697}
698
699DEFUN(cfg_mgcp_patch_rtp_ssrc,
700 cfg_mgcp_patch_rtp_ssrc_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200701 "rtp-patch ssrc", RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200702{
703 g_cfg->trunk.force_constant_ssrc = 1;
704 return CMD_SUCCESS;
705}
706
707DEFUN(cfg_mgcp_no_patch_rtp_ssrc,
708 cfg_mgcp_no_patch_rtp_ssrc_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200709 "no rtp-patch ssrc", NO_STR RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200710{
711 g_cfg->trunk.force_constant_ssrc = 0;
712 return CMD_SUCCESS;
713}
714
715DEFUN(cfg_mgcp_patch_rtp_ts,
716 cfg_mgcp_patch_rtp_ts_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200717 "rtp-patch timestamp", RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200718{
719 g_cfg->trunk.force_aligned_timing = 1;
720 return CMD_SUCCESS;
721}
722
723DEFUN(cfg_mgcp_no_patch_rtp_ts,
724 cfg_mgcp_no_patch_rtp_ts_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200725 "no rtp-patch timestamp", NO_STR RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200726{
727 g_cfg->trunk.force_aligned_timing = 0;
728 return CMD_SUCCESS;
729}
730
Philipp Maier9fc8a022019-02-20 12:26:52 +0100731DEFUN(cfg_mgcp_patch_rtp_rfc5993hr,
732 cfg_mgcp_patch_rtp_rfc5993hr_cmd,
733 "rtp-patch rfc5993hr", RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
734{
735 g_cfg->trunk.rfc5993_hr_convert = true;
736 return CMD_SUCCESS;
737}
738
739DEFUN(cfg_mgcp_no_patch_rtp_rfc5993hr,
740 cfg_mgcp_no_patch_rtp_rfc5993hr_cmd,
741 "no rtp-patch rfc5993hr", NO_STR RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
742{
743 g_cfg->trunk.rfc5993_hr_convert = false;
744 return CMD_SUCCESS;
745}
746
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200747DEFUN(cfg_mgcp_no_patch_rtp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200748 cfg_mgcp_no_patch_rtp_cmd, "no rtp-patch", NO_STR RTP_PATCH_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200749{
750 g_cfg->trunk.force_constant_ssrc = 0;
751 g_cfg->trunk.force_aligned_timing = 0;
Philipp Maier9fc8a022019-02-20 12:26:52 +0100752 g_cfg->trunk.rfc5993_hr_convert = false;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200753 return CMD_SUCCESS;
754}
755
756DEFUN(cfg_mgcp_rtp_keepalive,
757 cfg_mgcp_rtp_keepalive_cmd,
758 "rtp keep-alive <1-120>",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200759 RTP_STR RTP_KEEPALIVE_STR "Keep alive interval in secs\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200760{
761 mgcp_trunk_set_keepalive(&g_cfg->trunk, atoi(argv[0]));
762 return CMD_SUCCESS;
763}
764
765DEFUN(cfg_mgcp_rtp_keepalive_once,
766 cfg_mgcp_rtp_keepalive_once_cmd,
767 "rtp keep-alive once",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200768 RTP_STR RTP_KEEPALIVE_STR "Send dummy packet only once after CRCX/MDCX\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200769{
770 mgcp_trunk_set_keepalive(&g_cfg->trunk, MGCP_KEEPALIVE_ONCE);
771 return CMD_SUCCESS;
772}
773
774DEFUN(cfg_mgcp_no_rtp_keepalive,
775 cfg_mgcp_no_rtp_keepalive_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200776 "no rtp keep-alive", NO_STR RTP_STR RTP_KEEPALIVE_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200777{
Philipp Maiere726d4f2017-11-01 10:41:34 +0100778 mgcp_trunk_set_keepalive(&g_cfg->trunk, MGCP_KEEPALIVE_NEVER);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200779 return CMD_SUCCESS;
780}
781
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200782#define CALL_AGENT_STR "Callagent information\n"
783DEFUN(cfg_mgcp_agent_addr,
784 cfg_mgcp_agent_addr_cmd,
785 "call-agent ip A.B.C.D",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200786 CALL_AGENT_STR IP_STR "IPv4 Address of the callagent\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200787{
788 osmo_talloc_replace_string(g_cfg, &g_cfg->call_agent_addr, argv[0]);
789 return CMD_SUCCESS;
790}
791
792ALIAS_DEPRECATED(cfg_mgcp_agent_addr, cfg_mgcp_agent_addr_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200793 "call agent ip A.B.C.D",
794 CALL_AGENT_STR CALL_AGENT_STR IP_STR
795 "IPv4 Address of the callagent\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200796
Philipp Maier87bd9be2017-08-22 16:35:41 +0200797 DEFUN(cfg_mgcp_trunk, cfg_mgcp_trunk_cmd,
798 "trunk <1-64>", "Configure a SS7 trunk\n" "Trunk Nr\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200799{
800 struct mgcp_trunk_config *trunk;
801 int index = atoi(argv[0]);
802
803 trunk = mgcp_trunk_num(g_cfg, index);
804 if (!trunk)
805 trunk = mgcp_trunk_alloc(g_cfg, index);
806
807 if (!trunk) {
808 vty_out(vty, "%%Unable to allocate trunk %u.%s",
809 index, VTY_NEWLINE);
810 return CMD_WARNING;
811 }
812
813 vty->node = TRUNK_NODE;
814 vty->index = trunk;
815 return CMD_SUCCESS;
816}
817
818static int config_write_trunk(struct vty *vty)
819{
820 struct mgcp_trunk_config *trunk;
821
822 llist_for_each_entry(trunk, &g_cfg->trunks, entry) {
823 vty_out(vty, " trunk %d%s", trunk->trunk_nr, VTY_NEWLINE);
824 vty_out(vty, " sdp audio-payload number %d%s",
825 trunk->audio_payload, VTY_NEWLINE);
826 vty_out(vty, " sdp audio-payload name %s%s",
827 trunk->audio_name, VTY_NEWLINE);
828 vty_out(vty, " %ssdp audio-payload send-ptime%s",
829 trunk->audio_send_ptime ? "" : "no ", VTY_NEWLINE);
830 vty_out(vty, " %ssdp audio-payload send-name%s",
831 trunk->audio_send_name ? "" : "no ", VTY_NEWLINE);
832
833 if (trunk->keepalive_interval == MGCP_KEEPALIVE_ONCE)
834 vty_out(vty, " rtp keep-alive once%s", VTY_NEWLINE);
835 else if (trunk->keepalive_interval)
836 vty_out(vty, " rtp keep-alive %d%s",
837 trunk->keepalive_interval, VTY_NEWLINE);
838 else
839 vty_out(vty, " no rtp keep-alive%s", VTY_NEWLINE);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200840 vty_out(vty, " loop %d%s", trunk->audio_loop, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200841 vty_out(vty, " force-realloc %d%s",
842 trunk->force_realloc, VTY_NEWLINE);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200843 vty_out(vty, " rtp-accept-all %d%s",
844 trunk->rtp_accept_all, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200845 if (trunk->omit_rtcp)
846 vty_out(vty, " rtcp-omit%s", VTY_NEWLINE);
847 else
848 vty_out(vty, " no rtcp-omit%s", VTY_NEWLINE);
Philipp Maier9fc8a022019-02-20 12:26:52 +0100849 if (trunk->force_constant_ssrc || trunk->force_aligned_timing
850 || g_cfg->trunk.rfc5993_hr_convert) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200851 vty_out(vty, " %srtp-patch ssrc%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200852 trunk->force_constant_ssrc ? "" : "no ",
853 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200854 vty_out(vty, " %srtp-patch timestamp%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200855 trunk->force_aligned_timing ? "" : "no ",
856 VTY_NEWLINE);
Philipp Maier9fc8a022019-02-20 12:26:52 +0100857 vty_out(vty, " %srtp-patch rfc5993hr%s",
858 trunk->rfc5993_hr_convert ? "" : "no ",
859 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200860 } else
861 vty_out(vty, " no rtp-patch%s", VTY_NEWLINE);
862 if (trunk->audio_fmtp_extra)
863 vty_out(vty, " sdp audio fmtp-extra %s%s",
864 trunk->audio_fmtp_extra, VTY_NEWLINE);
865 vty_out(vty, " %sallow-transcoding%s",
866 trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
867 }
868
869 return CMD_SUCCESS;
870}
871
872DEFUN(cfg_trunk_sdp_fmtp_extra,
873 cfg_trunk_sdp_fmtp_extra_cmd,
874 "sdp audio fmtp-extra .NAME",
875 "Add extra fmtp for the SDP file\n" "Audio\n" "Fmtp-extra\n"
876 "Extra Information\n")
877{
878 struct mgcp_trunk_config *trunk = vty->index;
879 char *txt = argv_concat(argv, argc, 0);
880 if (!txt)
881 return CMD_WARNING;
882
883 osmo_talloc_replace_string(g_cfg, &trunk->audio_fmtp_extra, txt);
884 talloc_free(txt);
885 return CMD_SUCCESS;
886}
887
888DEFUN(cfg_trunk_payload_number,
889 cfg_trunk_payload_number_cmd,
890 "sdp audio-payload number <0-255>",
891 SDP_STR AUDIO_STR "Number\n" "Payload Number\n")
892{
893 struct mgcp_trunk_config *trunk = vty->index;
894 unsigned int payload = atoi(argv[0]);
895
896 trunk->audio_payload = payload;
897 return CMD_SUCCESS;
898}
899
900ALIAS_DEPRECATED(cfg_trunk_payload_number, cfg_trunk_payload_number_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200901 "sdp audio payload number <0-255>",
902 SDP_STR AUDIO_STR AUDIO_STR "Number\n" "Payload Number\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200903
Philipp Maier87bd9be2017-08-22 16:35:41 +0200904 DEFUN(cfg_trunk_payload_name,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200905 cfg_trunk_payload_name_cmd,
906 "sdp audio-payload name NAME",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200907 SDP_STR AUDIO_STR "Payload\n" "Payload Name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200908{
909 struct mgcp_trunk_config *trunk = vty->index;
910
911 osmo_talloc_replace_string(g_cfg, &trunk->audio_name, argv[0]);
912 return CMD_SUCCESS;
913}
914
915ALIAS_DEPRECATED(cfg_trunk_payload_name, cfg_trunk_payload_name_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200916 "sdp audio payload name NAME",
917 SDP_STR AUDIO_STR AUDIO_STR "Payload\n" "Payload Name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200918
Philipp Maier87bd9be2017-08-22 16:35:41 +0200919 DEFUN(cfg_trunk_loop,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200920 cfg_trunk_loop_cmd,
921 "loop (0|1)",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200922 "Loop audio for all endpoints on this trunk\n" "Don't Loop\n" "Loop\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200923{
924 struct mgcp_trunk_config *trunk = vty->index;
925
926 if (g_cfg->osmux) {
927 vty_out(vty, "Cannot use `loop' with `osmux'.%s", VTY_NEWLINE);
928 return CMD_WARNING;
929 }
930 trunk->audio_loop = atoi(argv[0]);
931 return CMD_SUCCESS;
932}
933
934DEFUN(cfg_trunk_sdp_payload_send_ptime,
935 cfg_trunk_sdp_payload_send_ptime_cmd,
936 "sdp audio-payload send-ptime",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200937 SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200938{
939 struct mgcp_trunk_config *trunk = vty->index;
940 trunk->audio_send_ptime = 1;
941 return CMD_SUCCESS;
942}
943
944DEFUN(cfg_trunk_no_sdp_payload_send_ptime,
945 cfg_trunk_no_sdp_payload_send_ptime_cmd,
946 "no sdp audio-payload send-ptime",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200947 NO_STR SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200948{
949 struct mgcp_trunk_config *trunk = vty->index;
950 trunk->audio_send_ptime = 0;
951 return CMD_SUCCESS;
952}
953
954DEFUN(cfg_trunk_sdp_payload_send_name,
955 cfg_trunk_sdp_payload_send_name_cmd,
956 "sdp audio-payload send-name",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200957 SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200958{
959 struct mgcp_trunk_config *trunk = vty->index;
960 trunk->audio_send_name = 1;
961 return CMD_SUCCESS;
962}
963
964DEFUN(cfg_trunk_no_sdp_payload_send_name,
965 cfg_trunk_no_sdp_payload_send_name_cmd,
966 "no sdp audio-payload send-name",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200967 NO_STR SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200968{
969 struct mgcp_trunk_config *trunk = vty->index;
970 trunk->audio_send_name = 0;
971 return CMD_SUCCESS;
972}
973
Philipp Maier87bd9be2017-08-22 16:35:41 +0200974DEFUN(cfg_trunk_omit_rtcp, cfg_trunk_omit_rtcp_cmd, "rtcp-omit", RTCP_OMIT_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200975{
976 struct mgcp_trunk_config *trunk = vty->index;
977 trunk->omit_rtcp = 1;
978 return CMD_SUCCESS;
979}
980
981DEFUN(cfg_trunk_no_omit_rtcp,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200982 cfg_trunk_no_omit_rtcp_cmd, "no rtcp-omit", NO_STR RTCP_OMIT_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200983{
984 struct mgcp_trunk_config *trunk = vty->index;
985 trunk->omit_rtcp = 0;
986 return CMD_SUCCESS;
987}
988
989DEFUN(cfg_trunk_patch_rtp_ssrc,
990 cfg_trunk_patch_rtp_ssrc_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200991 "rtp-patch ssrc", RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200992{
993 struct mgcp_trunk_config *trunk = vty->index;
994 trunk->force_constant_ssrc = 1;
995 return CMD_SUCCESS;
996}
997
998DEFUN(cfg_trunk_no_patch_rtp_ssrc,
999 cfg_trunk_no_patch_rtp_ssrc_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001000 "no rtp-patch ssrc", NO_STR RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001001{
1002 struct mgcp_trunk_config *trunk = vty->index;
1003 trunk->force_constant_ssrc = 0;
1004 return CMD_SUCCESS;
1005}
1006
1007DEFUN(cfg_trunk_patch_rtp_ts,
1008 cfg_trunk_patch_rtp_ts_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001009 "rtp-patch timestamp", RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001010{
1011 struct mgcp_trunk_config *trunk = vty->index;
1012 trunk->force_aligned_timing = 1;
1013 return CMD_SUCCESS;
1014}
1015
1016DEFUN(cfg_trunk_no_patch_rtp_ts,
1017 cfg_trunk_no_patch_rtp_ts_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001018 "no rtp-patch timestamp", NO_STR RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001019{
1020 struct mgcp_trunk_config *trunk = vty->index;
1021 trunk->force_aligned_timing = 0;
1022 return CMD_SUCCESS;
1023}
1024
Philipp Maier9fc8a022019-02-20 12:26:52 +01001025DEFUN(cfg_trunk_patch_rtp_rfc5993hr,
1026 cfg_trunk_patch_rtp_rfc5993hr_cmd,
1027 "rtp-patch rfc5993hr", RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
1028{
1029 struct mgcp_trunk_config *trunk = vty->index;
1030 trunk->rfc5993_hr_convert = true;
1031 return CMD_SUCCESS;
1032}
1033
1034DEFUN(cfg_trunk_no_patch_rtp_rfc5993hr,
1035 cfg_trunk_no_patch_rtp_rfc5993hr_cmd,
1036 "no rtp-patch rfc5993hr", NO_STR RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
1037{
1038 struct mgcp_trunk_config *trunk = vty->index;
1039 trunk->rfc5993_hr_convert = false;
1040 return CMD_SUCCESS;
1041}
1042
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001043DEFUN(cfg_trunk_no_patch_rtp,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001044 cfg_trunk_no_patch_rtp_cmd, "no rtp-patch", NO_STR RTP_PATCH_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001045{
1046 struct mgcp_trunk_config *trunk = vty->index;
1047 trunk->force_constant_ssrc = 0;
1048 trunk->force_aligned_timing = 0;
Philipp Maier9fc8a022019-02-20 12:26:52 +01001049 trunk->rfc5993_hr_convert = false;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001050 return CMD_SUCCESS;
1051}
1052
1053DEFUN(cfg_trunk_rtp_keepalive,
1054 cfg_trunk_rtp_keepalive_cmd,
1055 "rtp keep-alive <1-120>",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001056 RTP_STR RTP_KEEPALIVE_STR "Keep-alive interval in secs\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001057{
1058 struct mgcp_trunk_config *trunk = vty->index;
1059 mgcp_trunk_set_keepalive(trunk, atoi(argv[0]));
1060 return CMD_SUCCESS;
1061}
1062
1063DEFUN(cfg_trunk_rtp_keepalive_once,
1064 cfg_trunk_rtp_keepalive_once_cmd,
1065 "rtp keep-alive once",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001066 RTP_STR RTP_KEEPALIVE_STR "Send dummy packet only once after CRCX/MDCX\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001067{
1068 struct mgcp_trunk_config *trunk = vty->index;
1069 mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
1070 return CMD_SUCCESS;
1071}
1072
1073DEFUN(cfg_trunk_no_rtp_keepalive,
1074 cfg_trunk_no_rtp_keepalive_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001075 "no rtp keep-alive", NO_STR RTP_STR RTP_KEEPALIVE_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001076{
1077 struct mgcp_trunk_config *trunk = vty->index;
1078 mgcp_trunk_set_keepalive(trunk, 0);
1079 return CMD_SUCCESS;
1080}
1081
1082DEFUN(cfg_trunk_allow_transcoding,
1083 cfg_trunk_allow_transcoding_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001084 "allow-transcoding", "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001085{
1086 struct mgcp_trunk_config *trunk = vty->index;
1087 trunk->no_audio_transcoding = 0;
1088 return CMD_SUCCESS;
1089}
1090
1091DEFUN(cfg_trunk_no_allow_transcoding,
1092 cfg_trunk_no_allow_transcoding_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001093 "no allow-transcoding", NO_STR "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001094{
1095 struct mgcp_trunk_config *trunk = vty->index;
1096 trunk->no_audio_transcoding = 1;
1097 return CMD_SUCCESS;
1098}
1099
Philipp Maier87bd9be2017-08-22 16:35:41 +02001100DEFUN(loop_conn,
1101 loop_conn_cmd,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001102 "loop-endpoint <0-64> NAME (0|1)",
1103 "Loop a given endpoint\n" "Trunk number\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001104 "The name in hex of the endpoint\n" "Disable the loop\n"
1105 "Enable the loop\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001106{
1107 struct mgcp_trunk_config *trunk;
1108 struct mgcp_endpoint *endp;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001109 struct mgcp_conn *conn;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001110
1111 trunk = find_trunk(g_cfg, atoi(argv[0]));
1112 if (!trunk) {
1113 vty_out(vty, "%%Trunk %d not found in the config.%s",
1114 atoi(argv[0]), VTY_NEWLINE);
1115 return CMD_WARNING;
1116 }
1117
1118 if (!trunk->endpoints) {
1119 vty_out(vty, "%%Trunk %d has no endpoints allocated.%s",
1120 trunk->trunk_nr, VTY_NEWLINE);
1121 return CMD_WARNING;
1122 }
1123
1124 int endp_no = strtoul(argv[1], NULL, 16);
1125 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1126 vty_out(vty, "Loopback number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001127 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001128 return CMD_WARNING;
1129 }
1130
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001131 endp = &trunk->endpoints[endp_no];
1132 int loop = atoi(argv[2]);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001133 llist_for_each_entry(conn, &endp->conns, entry) {
1134 if (conn->type == MGCP_CONN_TYPE_RTP)
1135 /* Handle it like a MDCX, switch on SSRC patching if enabled */
1136 mgcp_rtp_end_config(endp, 1, &conn->u.rtp.end);
1137 else {
1138 /* FIXME: Introduce support for other connection (E1)
1139 * types when implementation is available */
1140 vty_out(vty, "%%Can't enable SSRC patching,"
1141 "connection %s is not an RTP connection.%s",
1142 mgcp_conn_dump(conn), VTY_NEWLINE);
1143 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001144
Philipp Maier87bd9be2017-08-22 16:35:41 +02001145 if (loop)
1146 conn->mode = MGCP_CONN_LOOPBACK;
1147 else
1148 conn->mode = conn->mode_orig;
1149 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001150
1151 return CMD_SUCCESS;
1152}
1153
Philipp Maier87bd9be2017-08-22 16:35:41 +02001154DEFUN(tap_rtp,
1155 tap_rtp_cmd,
1156 "tap-rtp <0-64> ENDPOINT CONN (in|out) A.B.C.D <0-65534>",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001157 "Forward data on endpoint to a different system\n" "Trunk number\n"
1158 "The endpoint in hex\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001159 "The connection id in hex\n"
1160 "Forward incoming data\n"
1161 "Forward leaving data\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001162 "destination IP of the data\n" "destination port\n")
1163{
1164 struct mgcp_rtp_tap *tap;
1165 struct mgcp_trunk_config *trunk;
1166 struct mgcp_endpoint *endp;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001167 struct mgcp_conn_rtp *conn;
Philipp Maier01d24a32017-11-21 17:26:09 +01001168 const char *conn_id = NULL;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001169
1170 trunk = find_trunk(g_cfg, atoi(argv[0]));
1171 if (!trunk) {
1172 vty_out(vty, "%%Trunk %d not found in the config.%s",
1173 atoi(argv[0]), VTY_NEWLINE);
1174 return CMD_WARNING;
1175 }
1176
1177 if (!trunk->endpoints) {
1178 vty_out(vty, "%%Trunk %d has no endpoints allocated.%s",
1179 trunk->trunk_nr, VTY_NEWLINE);
1180 return CMD_WARNING;
1181 }
1182
1183 int endp_no = strtoul(argv[1], NULL, 16);
1184 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1185 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001186 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001187 return CMD_WARNING;
1188 }
1189
1190 endp = &trunk->endpoints[endp_no];
1191
Philipp Maier01d24a32017-11-21 17:26:09 +01001192 conn_id = argv[2];
Philipp Maier87bd9be2017-08-22 16:35:41 +02001193 conn = mgcp_conn_get_rtp(endp, conn_id);
1194 if (!conn) {
Philipp Maier01d24a32017-11-21 17:26:09 +01001195 vty_out(vty, "Conn ID %s is invalid.%s",
1196 conn_id, VTY_NEWLINE);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001197 return CMD_WARNING;
1198 }
1199
1200 if (strcmp(argv[3], "in") == 0)
1201 tap = &conn->tap_in;
1202 else if (strcmp(argv[3], "out") == 0)
1203 tap = &conn->tap_out;
1204 else {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001205 vty_out(vty, "Unknown mode... tricked vty?%s", VTY_NEWLINE);
1206 return CMD_WARNING;
1207 }
1208
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001209 memset(&tap->forward, 0, sizeof(tap->forward));
Philipp Maier87bd9be2017-08-22 16:35:41 +02001210 inet_aton(argv[4], &tap->forward.sin_addr);
1211 tap->forward.sin_port = htons(atoi(argv[5]));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001212 tap->enabled = 1;
1213 return CMD_SUCCESS;
1214}
1215
1216DEFUN(free_endp, free_endp_cmd,
1217 "free-endpoint <0-64> NUMBER",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001218 "Free the given endpoint\n" "Trunk number\n" "Endpoint number in hex.\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001219{
1220 struct mgcp_trunk_config *trunk;
1221 struct mgcp_endpoint *endp;
1222
1223 trunk = find_trunk(g_cfg, atoi(argv[0]));
1224 if (!trunk) {
1225 vty_out(vty, "%%Trunk %d not found in the config.%s",
1226 atoi(argv[0]), VTY_NEWLINE);
1227 return CMD_WARNING;
1228 }
1229
1230 if (!trunk->endpoints) {
1231 vty_out(vty, "%%Trunk %d has no endpoints allocated.%s",
1232 trunk->trunk_nr, VTY_NEWLINE);
1233 return CMD_WARNING;
1234 }
1235
1236 int endp_no = strtoul(argv[1], NULL, 16);
1237 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1238 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001239 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001240 return CMD_WARNING;
1241 }
1242
1243 endp = &trunk->endpoints[endp_no];
Philipp Maier1355d7e2018-02-01 14:30:06 +01001244 mgcp_endp_release(endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001245 return CMD_SUCCESS;
1246}
1247
1248DEFUN(reset_endp, reset_endp_cmd,
1249 "reset-endpoint <0-64> NUMBER",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001250 "Reset the given endpoint\n" "Trunk number\n" "Endpoint number in hex.\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001251{
1252 struct mgcp_trunk_config *trunk;
1253 struct mgcp_endpoint *endp;
1254 int endp_no, rc;
1255
1256 trunk = find_trunk(g_cfg, atoi(argv[0]));
1257 if (!trunk) {
1258 vty_out(vty, "%%Trunk %d not found in the config.%s",
1259 atoi(argv[0]), VTY_NEWLINE);
1260 return CMD_WARNING;
1261 }
1262
1263 if (!trunk->endpoints) {
1264 vty_out(vty, "%%Trunk %d has no endpoints allocated.%s",
1265 trunk->trunk_nr, VTY_NEWLINE);
1266 return CMD_WARNING;
1267 }
1268
1269 endp_no = strtoul(argv[1], NULL, 16);
1270 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1271 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001272 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001273 return CMD_WARNING;
1274 }
1275
1276 endp = &trunk->endpoints[endp_no];
1277 rc = mgcp_send_reset_ep(endp, ENDPOINT_NUMBER(endp));
1278 if (rc < 0) {
1279 vty_out(vty, "Error %d sending reset.%s", rc, VTY_NEWLINE);
1280 return CMD_WARNING;
1281 }
1282 return CMD_SUCCESS;
1283}
1284
1285DEFUN(reset_all_endp, reset_all_endp_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001286 "reset-all-endpoints", "Reset all endpoints\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001287{
1288 int rc;
1289
1290 rc = mgcp_send_reset_all(g_cfg);
1291 if (rc < 0) {
1292 vty_out(vty, "Error %d during endpoint reset.%s",
1293 rc, VTY_NEWLINE);
1294 return CMD_WARNING;
1295 }
1296 return CMD_SUCCESS;
1297}
1298
1299#define OSMUX_STR "RTP multiplexing\n"
1300DEFUN(cfg_mgcp_osmux,
1301 cfg_mgcp_osmux_cmd,
1302 "osmux (on|off|only)",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001303 OSMUX_STR "Enable OSMUX\n" "Disable OSMUX\n" "Only use OSMUX\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001304{
1305 if (strcmp(argv[0], "off") == 0) {
1306 g_cfg->osmux = OSMUX_USAGE_OFF;
1307 return CMD_SUCCESS;
Pau Espin Pedrolb542b042019-04-23 13:09:32 +02001308 } else if (strcmp(argv[0], "on") == 0)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001309 g_cfg->osmux = OSMUX_USAGE_ON;
1310 else if (strcmp(argv[0], "only") == 0)
1311 g_cfg->osmux = OSMUX_USAGE_ONLY;
1312
1313 if (g_cfg->trunk.audio_loop) {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001314 vty_out(vty, "Cannot use `loop' with `osmux'.%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001315 return CMD_WARNING;
1316 }
1317
1318 return CMD_SUCCESS;
Pau Espin Pedrolb542b042019-04-23 13:09:32 +02001319
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001320}
1321
1322DEFUN(cfg_mgcp_osmux_ip,
1323 cfg_mgcp_osmux_ip_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001324 "osmux bind-ip A.B.C.D", OSMUX_STR IP_STR "IPv4 Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001325{
1326 osmo_talloc_replace_string(g_cfg, &g_cfg->osmux_addr, argv[0]);
1327 return CMD_SUCCESS;
1328}
1329
1330DEFUN(cfg_mgcp_osmux_batch_factor,
1331 cfg_mgcp_osmux_batch_factor_cmd,
1332 "osmux batch-factor <1-8>",
1333 OSMUX_STR "Batching factor\n" "Number of messages in the batch\n")
1334{
1335 g_cfg->osmux_batch = atoi(argv[0]);
1336 return CMD_SUCCESS;
1337}
1338
1339DEFUN(cfg_mgcp_osmux_batch_size,
1340 cfg_mgcp_osmux_batch_size_cmd,
1341 "osmux batch-size <1-65535>",
1342 OSMUX_STR "batch size\n" "Batch size in bytes\n")
1343{
1344 g_cfg->osmux_batch_size = atoi(argv[0]);
1345 return CMD_SUCCESS;
1346}
1347
1348DEFUN(cfg_mgcp_osmux_port,
1349 cfg_mgcp_osmux_port_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001350 "osmux port <1-65535>", OSMUX_STR "port\n" "UDP port\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001351{
1352 g_cfg->osmux_port = atoi(argv[0]);
1353 return CMD_SUCCESS;
1354}
1355
1356DEFUN(cfg_mgcp_osmux_dummy,
1357 cfg_mgcp_osmux_dummy_cmd,
1358 "osmux dummy (on|off)",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001359 OSMUX_STR "Dummy padding\n" "Enable dummy padding\n"
1360 "Disable dummy padding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001361{
1362 if (strcmp(argv[0], "on") == 0)
1363 g_cfg->osmux_dummy = 1;
1364 else if (strcmp(argv[0], "off") == 0)
1365 g_cfg->osmux_dummy = 0;
1366
1367 return CMD_SUCCESS;
1368}
1369
Philipp Maier12943ea2018-01-17 15:40:25 +01001370DEFUN(cfg_mgcp_domain,
1371 cfg_mgcp_domain_cmd,
Neels Hofmeyr352eed02018-08-20 23:59:32 +02001372 "domain NAME",
1373 "Set the domain part expected in MGCP messages' endpoint names\n"
1374 "Qualified domain name expected in MGCP endpoint names, or '*' to accept any domain\n")
Philipp Maier12943ea2018-01-17 15:40:25 +01001375{
1376 osmo_strlcpy(g_cfg->domain, argv[0], sizeof(g_cfg->domain));
1377 return CMD_SUCCESS;
1378}
1379
Oliver Smithe36b7752019-01-22 16:31:36 +01001380DEFUN(cfg_mgcp_conn_timeout,
1381 cfg_mgcp_conn_timeout_cmd,
Oliver Smithd2ce4442019-06-26 09:56:44 +02001382 "conn-timeout <0-65534>",
1383 "Set a time after which inactive connections (CIs) are closed. Set to 0 to disable timeout. This can be used to"
1384 " work around interoperability problems causing connections to stay open forever, and slowly exhausting all"
Oliver Smith189f29e2019-06-26 12:08:20 +02001385 " available ports. Enable keep-alive packets in MGW clients when using this option together with LCLS (OsmoBSC,"
1386 " OsmoMSC: 'rtp keep-alive')!\n"
Oliver Smithe36b7752019-01-22 16:31:36 +01001387 "Timeout value (sec.)\n")
1388{
1389 g_cfg->conn_timeout = strtoul(argv[0], NULL, 10);
1390 return CMD_SUCCESS;
1391}
1392
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001393int mgcp_vty_init(void)
1394{
1395 install_element_ve(&show_mgcp_cmd);
Stefan Sperling12086582018-06-26 15:26:28 +02001396 install_element_ve(&show_mgcp_endpoint_cmd);
1397 install_element_ve(&show_mgcp_trunk_endpoint_cmd);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001398 install_element(ENABLE_NODE, &loop_conn_cmd);
1399 install_element(ENABLE_NODE, &tap_rtp_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001400 install_element(ENABLE_NODE, &free_endp_cmd);
1401 install_element(ENABLE_NODE, &reset_endp_cmd);
1402 install_element(ENABLE_NODE, &reset_all_endp_cmd);
1403
1404 install_element(CONFIG_NODE, &cfg_mgcp_cmd);
1405 install_node(&mgcp_node, config_write_mgcp);
1406
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001407 install_element(MGCP_NODE, &cfg_mgcp_local_ip_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001408 install_element(MGCP_NODE, &cfg_mgcp_bind_ip_cmd);
1409 install_element(MGCP_NODE, &cfg_mgcp_bind_port_cmd);
1410 install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001411 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_range_cmd);
Philipp Maierf1889d82017-11-08 14:59:39 +01001412 install_element(MGCP_NODE, &cfg_mgcp_rtp_port_range_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001413 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_bind_ip_cmd);
Philipp Maierf1889d82017-11-08 14:59:39 +01001414 install_element(MGCP_NODE, &cfg_mgcp_rtp_bind_ip_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001415 install_element(MGCP_NODE, &cfg_mgcp_rtp_no_net_bind_ip_cmd);
Philipp Maierf1889d82017-11-08 14:59:39 +01001416 install_element(MGCP_NODE, &cfg_mgcp_rtp_no_bind_ip_cmd);
Philipp Maier1cb1e382017-11-02 17:16:04 +01001417 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_bind_ip_probing_cmd);
1418 install_element(MGCP_NODE, &cfg_mgcp_rtp_no_net_bind_ip_probing_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001419 install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);
1420 install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_tos_cmd);
1421 install_element(MGCP_NODE, &cfg_mgcp_rtp_force_ptime_cmd);
1422 install_element(MGCP_NODE, &cfg_mgcp_no_rtp_force_ptime_cmd);
1423 install_element(MGCP_NODE, &cfg_mgcp_rtp_keepalive_cmd);
1424 install_element(MGCP_NODE, &cfg_mgcp_rtp_keepalive_once_cmd);
1425 install_element(MGCP_NODE, &cfg_mgcp_no_rtp_keepalive_cmd);
1426 install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd);
1427 install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd_old);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001428 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd);
1429 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd);
1430 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd_old);
1431 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd_old);
1432 install_element(MGCP_NODE, &cfg_mgcp_loop_cmd);
1433 install_element(MGCP_NODE, &cfg_mgcp_force_realloc_cmd);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001434 install_element(MGCP_NODE, &cfg_mgcp_rtp_accept_all_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001435 install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd);
1436 install_element(MGCP_NODE, &cfg_mgcp_omit_rtcp_cmd);
1437 install_element(MGCP_NODE, &cfg_mgcp_no_omit_rtcp_cmd);
1438 install_element(MGCP_NODE, &cfg_mgcp_patch_rtp_ssrc_cmd);
1439 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_ssrc_cmd);
1440 install_element(MGCP_NODE, &cfg_mgcp_patch_rtp_ts_cmd);
1441 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_ts_cmd);
1442 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_cmd);
Philipp Maier9fc8a022019-02-20 12:26:52 +01001443 install_element(MGCP_NODE, &cfg_mgcp_patch_rtp_rfc5993hr_cmd);
1444 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_rfc5993hr_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001445 install_element(MGCP_NODE, &cfg_mgcp_sdp_fmtp_extra_cmd);
1446 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_send_ptime_cmd);
1447 install_element(MGCP_NODE, &cfg_mgcp_no_sdp_payload_send_ptime_cmd);
1448 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_send_name_cmd);
1449 install_element(MGCP_NODE, &cfg_mgcp_no_sdp_payload_send_name_cmd);
1450 install_element(MGCP_NODE, &cfg_mgcp_osmux_cmd);
1451 install_element(MGCP_NODE, &cfg_mgcp_osmux_ip_cmd);
1452 install_element(MGCP_NODE, &cfg_mgcp_osmux_batch_factor_cmd);
1453 install_element(MGCP_NODE, &cfg_mgcp_osmux_batch_size_cmd);
1454 install_element(MGCP_NODE, &cfg_mgcp_osmux_port_cmd);
1455 install_element(MGCP_NODE, &cfg_mgcp_osmux_dummy_cmd);
1456 install_element(MGCP_NODE, &cfg_mgcp_allow_transcoding_cmd);
1457 install_element(MGCP_NODE, &cfg_mgcp_no_allow_transcoding_cmd);
Philipp Maier12943ea2018-01-17 15:40:25 +01001458 install_element(MGCP_NODE, &cfg_mgcp_domain_cmd);
Oliver Smithe36b7752019-01-22 16:31:36 +01001459 install_element(MGCP_NODE, &cfg_mgcp_conn_timeout_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001460
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001461 install_element(MGCP_NODE, &cfg_mgcp_trunk_cmd);
1462 install_node(&trunk_node, config_write_trunk);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001463 install_element(TRUNK_NODE, &cfg_trunk_rtp_keepalive_cmd);
1464 install_element(TRUNK_NODE, &cfg_trunk_rtp_keepalive_once_cmd);
1465 install_element(TRUNK_NODE, &cfg_trunk_no_rtp_keepalive_cmd);
1466 install_element(TRUNK_NODE, &cfg_trunk_payload_number_cmd);
1467 install_element(TRUNK_NODE, &cfg_trunk_payload_name_cmd);
1468 install_element(TRUNK_NODE, &cfg_trunk_payload_number_cmd_old);
1469 install_element(TRUNK_NODE, &cfg_trunk_payload_name_cmd_old);
1470 install_element(TRUNK_NODE, &cfg_trunk_loop_cmd);
1471 install_element(TRUNK_NODE, &cfg_trunk_omit_rtcp_cmd);
1472 install_element(TRUNK_NODE, &cfg_trunk_no_omit_rtcp_cmd);
1473 install_element(TRUNK_NODE, &cfg_trunk_patch_rtp_ssrc_cmd);
1474 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_ssrc_cmd);
1475 install_element(TRUNK_NODE, &cfg_trunk_patch_rtp_ts_cmd);
Philipp Maier9fc8a022019-02-20 12:26:52 +01001476 install_element(TRUNK_NODE, &cfg_trunk_patch_rtp_rfc5993hr_cmd);
1477 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_rfc5993hr_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001478 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_ts_cmd);
1479 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_cmd);
1480 install_element(TRUNK_NODE, &cfg_trunk_sdp_fmtp_extra_cmd);
1481 install_element(TRUNK_NODE, &cfg_trunk_sdp_payload_send_ptime_cmd);
1482 install_element(TRUNK_NODE, &cfg_trunk_no_sdp_payload_send_ptime_cmd);
1483 install_element(TRUNK_NODE, &cfg_trunk_sdp_payload_send_name_cmd);
1484 install_element(TRUNK_NODE, &cfg_trunk_no_sdp_payload_send_name_cmd);
1485 install_element(TRUNK_NODE, &cfg_trunk_allow_transcoding_cmd);
1486 install_element(TRUNK_NODE, &cfg_trunk_no_allow_transcoding_cmd);
1487
1488 return 0;
1489}
1490
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001491int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg,
1492 enum mgcp_role role)
1493{
1494 int rc;
1495 struct mgcp_trunk_config *trunk;
1496
1497 cfg->osmux_port = OSMUX_PORT;
1498 cfg->osmux_batch = 4;
1499 cfg->osmux_batch_size = OSMUX_BATCH_DEFAULT_MAX;
1500
1501 g_cfg = cfg;
1502 rc = vty_read_config_file(config_file, NULL);
1503 if (rc < 0) {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001504 fprintf(stderr, "Failed to parse the config file: '%s'\n",
1505 config_file);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001506 return rc;
1507 }
1508
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001509 if (!g_cfg->source_addr) {
1510 fprintf(stderr, "You need to specify a bind address.\n");
1511 return -1;
1512 }
1513
Philipp Maier48454982017-11-10 16:46:41 +01001514 if (mgcp_endpoints_allocate(&g_cfg->trunk) != 0) {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001515 LOGP(DLMGCP, LOGL_ERROR,
Philipp Maier48454982017-11-10 16:46:41 +01001516 "Failed to initialize the virtual trunk (%d endpoints)\n",
1517 g_cfg->trunk.number_endpoints);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001518 return -1;
1519 }
1520
1521 llist_for_each_entry(trunk, &g_cfg->trunks, entry) {
Philipp Maier48454982017-11-10 16:46:41 +01001522 if (mgcp_endpoints_allocate(trunk) != 0) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001523 LOGP(DLMGCP, LOGL_ERROR,
Philipp Maier48454982017-11-10 16:46:41 +01001524 "Failed to initialize trunk %d (%d endpoints)\n",
1525 trunk->trunk_nr, trunk->number_endpoints);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001526 return -1;
1527 }
1528 }
1529 cfg->role = role;
1530
1531 return 0;
1532}