blob: bc2673da0fbe3b7441d00756c7a339956d2c8d61 [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>
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +020025#include <osmocom/core/sockaddr_str.h>
Stefan Sperling1e174872018-10-25 18:36:10 +020026#include <osmocom/vty/misc.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020027#include <osmocom/mgcp/mgcp.h>
Neels Hofmeyr67793542017-09-08 04:25:16 +020028#include <osmocom/mgcp/mgcp_common.h>
Philipp Maier993ea6b2020-08-04 18:26:50 +020029#include <osmocom/mgcp/osmux.h>
30#include <osmocom/mgcp/mgcp_protocol.h>
Philipp Maier87bd9be2017-08-22 16:35:41 +020031#include <osmocom/mgcp/vty.h>
32#include <osmocom/mgcp/mgcp_conn.h>
Philipp Maier37d11c82018-02-01 14:38:12 +010033#include <osmocom/mgcp/mgcp_endp.h>
Philipp Maierc66ab2c2020-06-02 20:55:34 +020034#include <osmocom/mgcp/mgcp_trunk.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020035
36#include <string.h>
Philipp Maierbca0ef62018-07-09 17:20:51 +020037#include <inttypes.h>
Stefan Sperling12086582018-06-26 15:26:28 +020038#include <limits.h>
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020039
40#define RTCP_OMIT_STR "Drop RTCP packets in both directions\n"
41#define RTP_PATCH_STR "Modify RTP packet header in both directions\n"
42#define RTP_KEEPALIVE_STR "Send dummy UDP packet to net RTP destination\n"
Philipp Maier9fc8a022019-02-20 12:26:52 +010043#define RTP_TS101318_RFC5993_CONV_STR "Convert GSM-HR from TS101318 to RFC5993 and vice versa\n"
44
Philipp Maier19c430f2020-09-22 15:52:50 +020045#define X(x) (1 << x)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020046
47static struct mgcp_config *g_cfg = NULL;
48
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020049struct cmd_node mgcp_node = {
50 MGCP_NODE,
51 "%s(config-mgcp)# ",
52 1,
53};
54
55struct cmd_node trunk_node = {
56 TRUNK_NODE,
57 "%s(config-mgcp-trunk)# ",
58 1,
59};
60
61static int config_write_mgcp(struct vty *vty)
62{
Philipp Maier6fbbeec2020-07-01 23:00:54 +020063 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +020064 OSMO_ASSERT(trunk);
Harald Weltec39b1bf2020-03-08 11:29:39 +010065
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020066 vty_out(vty, "mgcp%s", VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +020067 vty_out(vty, " domain %s%s", g_cfg->domain, VTY_NEWLINE);
Eric2764bdb2021-08-23 22:11:47 +020068 if (strlen(g_cfg->local_ip))
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020069 vty_out(vty, " local ip %s%s", g_cfg->local_ip, VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +020070 vty_out(vty, " bind ip %s%s", g_cfg->source_addr, VTY_NEWLINE);
71 vty_out(vty, " bind port %u%s", g_cfg->source_port, VTY_NEWLINE);
72 vty_out(vty, " rtp port-range %u %u%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +020073 g_cfg->net_ports.range_start, g_cfg->net_ports.range_end,
74 VTY_NEWLINE);
Eric2764bdb2021-08-23 22:11:47 +020075 if (strlen(g_cfg->net_ports.bind_addr_v4))
Philipp Maierf53796c2020-06-02 20:38:28 +020076 vty_out(vty, " rtp bind-ip %s%s",
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +020077 g_cfg->net_ports.bind_addr_v4, VTY_NEWLINE);
Eric2764bdb2021-08-23 22:11:47 +020078 if (strlen(g_cfg->net_ports.bind_addr_v6))
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +020079 vty_out(vty, " rtp bind-ip-v6 %s%s",
80 g_cfg->net_ports.bind_addr_v6, VTY_NEWLINE);
Philipp Maier1cb1e382017-11-02 17:16:04 +010081 if (g_cfg->net_ports.bind_addr_probe)
Philipp Maierf53796c2020-06-02 20:38:28 +020082 vty_out(vty, " rtp ip-probing%s", VTY_NEWLINE);
Philipp Maier1cb1e382017-11-02 17:16:04 +010083 else
Philipp Maierf53796c2020-06-02 20:38:28 +020084 vty_out(vty, " no rtp ip-probing%s", VTY_NEWLINE);
85 vty_out(vty, " rtp ip-dscp %d%s", g_cfg->endp_dscp, VTY_NEWLINE);
Harald Welte55a92292021-04-28 19:06:34 +020086 if (g_cfg->endp_priority)
87 vty_out(vty, " rtp socket-priority %d%s", g_cfg->endp_priority, VTY_NEWLINE);
Harald Weltec39b1bf2020-03-08 11:29:39 +010088 if (trunk->keepalive_interval == MGCP_KEEPALIVE_ONCE)
Philipp Maierf53796c2020-06-02 20:38:28 +020089 vty_out(vty, " rtp keep-alive once%s", VTY_NEWLINE);
Harald Weltec39b1bf2020-03-08 11:29:39 +010090 else if (trunk->keepalive_interval)
Philipp Maierf53796c2020-06-02 20:38:28 +020091 vty_out(vty, " rtp keep-alive %d%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +010092 trunk->keepalive_interval, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020093 else
Philipp Maierf53796c2020-06-02 20:38:28 +020094 vty_out(vty, " no rtp keep-alive%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020095
Harald Weltec39b1bf2020-03-08 11:29:39 +010096 if (trunk->omit_rtcp)
Philipp Maierf53796c2020-06-02 20:38:28 +020097 vty_out(vty, " rtcp-omit%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +020098 else
Philipp Maierf53796c2020-06-02 20:38:28 +020099 vty_out(vty, " no rtcp-omit%s", VTY_NEWLINE);
Harald Weltec39b1bf2020-03-08 11:29:39 +0100100 if (trunk->force_constant_ssrc
101 || trunk->force_aligned_timing
102 || trunk->rfc5993_hr_convert) {
Philipp Maierf53796c2020-06-02 20:38:28 +0200103 vty_out(vty, " %srtp-patch ssrc%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +0100104 trunk->force_constant_ssrc ? "" : "no ",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200105 VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200106 vty_out(vty, " %srtp-patch timestamp%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +0100107 trunk->force_aligned_timing ? "" : "no ",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200108 VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200109 vty_out(vty, " %srtp-patch rfc5993hr%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +0100110 trunk->rfc5993_hr_convert ? "" : "no ",
Philipp Maier9fc8a022019-02-20 12:26:52 +0100111 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200112 } else
Philipp Maierf53796c2020-06-02 20:38:28 +0200113 vty_out(vty, " no rtp-patch%s", VTY_NEWLINE);
Harald Weltec39b1bf2020-03-08 11:29:39 +0100114 if (trunk->audio_fmtp_extra)
Philipp Maierf53796c2020-06-02 20:38:28 +0200115 vty_out(vty, " sdp audio fmtp-extra %s%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +0100116 trunk->audio_fmtp_extra, VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200117 vty_out(vty, " %ssdp audio-payload send-ptime%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +0100118 trunk->audio_send_ptime ? "" : "no ", VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200119 vty_out(vty, " %ssdp audio-payload send-name%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +0100120 trunk->audio_send_name ? "" : "no ", VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200121 vty_out(vty, " number endpoints %u%s",
Philipp Maier889fe7f2020-07-06 17:44:12 +0200122 trunk->v.vty_number_endpoints, VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200123 vty_out(vty, " %sallow-transcoding%s",
Harald Weltec39b1bf2020-03-08 11:29:39 +0100124 trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
Eric2764bdb2021-08-23 22:11:47 +0200125 if (strlen(g_cfg->call_agent_addr))
Philipp Maierf53796c2020-06-02 20:38:28 +0200126 vty_out(vty, " call-agent ip %s%s", g_cfg->call_agent_addr,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200127 VTY_NEWLINE);
128 if (g_cfg->force_ptime > 0)
Philipp Maierf53796c2020-06-02 20:38:28 +0200129 vty_out(vty, " rtp force-ptime %d%s", g_cfg->force_ptime,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200130 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200131
Pau Espin Pedrol928a20b2022-09-23 15:38:24 +0200132 switch (g_cfg->osmux_use) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200133 case OSMUX_USAGE_ON:
Philipp Maierf53796c2020-06-02 20:38:28 +0200134 vty_out(vty, " osmux on%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200135 break;
136 case OSMUX_USAGE_ONLY:
Philipp Maierf53796c2020-06-02 20:38:28 +0200137 vty_out(vty, " osmux only%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200138 break;
139 case OSMUX_USAGE_OFF:
140 default:
Philipp Maierf53796c2020-06-02 20:38:28 +0200141 vty_out(vty, " osmux off%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200142 break;
143 }
Pau Espin Pedrol928a20b2022-09-23 15:38:24 +0200144 if (g_cfg->osmux_use != OSMUX_USAGE_OFF) {
Pau Espin Pedrol70c03f52022-10-04 16:49:41 +0200145 if (g_cfg->osmux_addr_v4)
146 vty_out(vty, " osmux bind-ip %s%s",
147 g_cfg->osmux_addr_v4, VTY_NEWLINE);
148 if (g_cfg->osmux_addr_v6)
149 vty_out(vty, " osmux bind-ip-v6 %s%s",
150 g_cfg->osmux_addr_v6, VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200151 vty_out(vty, " osmux batch-factor %d%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200152 g_cfg->osmux_batch, VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200153 vty_out(vty, " osmux batch-size %u%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200154 g_cfg->osmux_batch_size, VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200155 vty_out(vty, " osmux port %u%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200156 g_cfg->osmux_port, VTY_NEWLINE);
Philipp Maierf53796c2020-06-02 20:38:28 +0200157 vty_out(vty, " osmux dummy %s%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200158 g_cfg->osmux_dummy ? "on" : "off", VTY_NEWLINE);
159 }
Oliver Smithe36b7752019-01-22 16:31:36 +0100160
161 if (g_cfg->conn_timeout)
Philipp Maierf53796c2020-06-02 20:38:28 +0200162 vty_out(vty, " conn-timeout %u%s", g_cfg->conn_timeout, VTY_NEWLINE);
Oliver Smithe36b7752019-01-22 16:31:36 +0100163
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200164 return CMD_SUCCESS;
165}
166
Philipp Maiercede2a42018-07-03 14:14:21 +0200167static void dump_rtp_end(struct vty *vty, struct mgcp_conn_rtp *conn)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200168{
Philipp Maiercede2a42018-07-03 14:14:21 +0200169 struct mgcp_rtp_state *state = &conn->state;
170 struct mgcp_rtp_end *end = &conn->end;
Philipp Maierbc0346e2018-06-07 09:52:16 +0200171 struct mgcp_rtp_codec *codec = end->codec;
Stefan Sperlingb7974e22018-10-29 13:22:00 +0100172 struct rate_ctr *tx_packets, *tx_bytes;
173 struct rate_ctr *rx_packets, *rx_bytes;
Philipp Maiercede2a42018-07-03 14:14:21 +0200174 struct rate_ctr *dropped_packets;
175
Pau Espin Pedroldaf5bce2022-09-22 19:14:24 +0200176 tx_packets = rate_ctr_group_get_ctr(conn->ctrg, RTP_PACKETS_TX_CTR);
177 tx_bytes = rate_ctr_group_get_ctr(conn->ctrg, RTP_OCTETS_TX_CTR);
178 rx_packets = rate_ctr_group_get_ctr(conn->ctrg, RTP_PACKETS_RX_CTR);
179 rx_bytes = rate_ctr_group_get_ctr(conn->ctrg, RTP_OCTETS_RX_CTR);
180 dropped_packets = rate_ctr_group_get_ctr(conn->ctrg, RTP_DROPPED_PACKETS_CTR);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200181
182 vty_out(vty,
Stefan Sperlingb7974e22018-10-29 13:22:00 +0100183 " Packets Sent: %" PRIu64 " (%" PRIu64 " bytes total)%s"
184 " Packets Received: %" PRIu64 " (%" PRIu64 " bytes total)%s"
Philipp Maierbca0ef62018-07-09 17:20:51 +0200185 " Timestamp Errs: %" PRIu64 "->%" PRIu64 "%s"
186 " Dropped Packets: %" PRIu64 "%s"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200187 " Payload Type: %d Rate: %u Channels: %d %s"
188 " Frame Duration: %u Frame Denominator: %u%s"
189 " FPP: %d Packet Duration: %u%s"
190 " FMTP-Extra: %s Audio-Name: %s Sub-Type: %s%s"
191 " Output-Enabled: %d Force-PTIME: %d%s",
Stefan Sperlingb7974e22018-10-29 13:22:00 +0100192 tx_packets->current, tx_bytes->current, VTY_NEWLINE,
193 rx_packets->current, rx_bytes->current, VTY_NEWLINE,
Philipp Maier9e1d1642018-05-09 16:26:34 +0200194 state->in_stream.err_ts_ctr->current,
195 state->out_stream.err_ts_ctr->current,
Pau Espin Pedrol83df47c2022-09-21 20:07:59 +0200196 VTY_NEWLINE,
Philipp Maiercede2a42018-07-03 14:14:21 +0200197 dropped_packets->current, VTY_NEWLINE,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200198 codec->payload_type, codec->rate, codec->channels, VTY_NEWLINE,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200199 codec->frame_duration_num, codec->frame_duration_den,
200 VTY_NEWLINE, end->frames_per_packet, end->packet_duration_ms,
201 VTY_NEWLINE, end->fmtp_extra, codec->audio_name,
202 codec->subtype_name, VTY_NEWLINE, end->output_enabled,
203 end->force_output_ptime, VTY_NEWLINE);
Pau Espin Pedrolea7aaf22022-09-22 21:07:54 +0200204 if (mgcp_conn_rtp_is_osmux(conn)) {
205 struct rate_ctr *rx_chunks, *rx_octets, *rtp_tx, *rtp_tx_dropped, *octets_tx;
206 rx_chunks = rate_ctr_group_get_ctr(conn->osmux.ctrg, OSMUX_CHUNKS_RX_CTR);
207 rx_octets = rate_ctr_group_get_ctr(conn->osmux.ctrg, OSMUX_OCTETS_RX_CTR);
208 rtp_tx = rate_ctr_group_get_ctr(conn->osmux.ctrg, OSMUX_RTP_PACKETS_TX_CTR);
209 rtp_tx_dropped = rate_ctr_group_get_ctr(conn->osmux.ctrg, OSMUX_RTP_PACKETS_TX_DROPPED_CTR);
210 octets_tx = rate_ctr_group_get_ctr(conn->osmux.ctrg, OSMUX_AMR_OCTETS_TX_CTR);
211 vty_out(vty,
212 " Osmux:%s"
213 " State: %s%s"
214 " Local CID: %d%s"
215 " Remote CID: %d%s"
216 " Chunks received: %" PRIu64 " (%" PRIu64 " bytes total)%s"
217 " RTP Packets encoded (Tx): %" PRIu64 " (%" PRIu64 " AMR octets total)%s"
218 " AMR payloads Dropped (Tx): %" PRIu64 "%s",
219 VTY_NEWLINE, osmux_state_str(conn->osmux.state), VTY_NEWLINE,
220 conn->osmux.local_cid_allocated ? conn->osmux.local_cid : -1, VTY_NEWLINE,
221 conn->osmux.remote_cid_present ? conn->osmux.remote_cid : -1, VTY_NEWLINE,
222 rx_chunks->current, rx_octets->current, VTY_NEWLINE,
223 rtp_tx->current, octets_tx->current, VTY_NEWLINE,
224 rtp_tx_dropped->current, VTY_NEWLINE
225 );
226
227 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200228}
229
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200230static void dump_endpoint(struct vty *vty, struct mgcp_endpoint *endp,
Philipp Maierd70eef62021-07-19 13:53:28 +0200231 unsigned int trunk_nr, enum mgcp_trunk_type trunk_type, int show_stats)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200232{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200233 struct mgcp_conn *conn;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200234
Philipp Maierd70eef62021-07-19 13:53:28 +0200235 vty_out(vty, "%s trunk %u endpoint %s:%s",
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200236 trunk_type == MGCP_TRUNK_VIRTUAL ? "Virtual" : "E1", trunk_nr, endp->name, VTY_NEWLINE);
Philipp Maier8d6a1932020-06-18 12:19:31 +0200237 vty_out(vty, " Availability: %s%s",
238 mgcp_endp_avail(endp) ? "available" : "not in service", VTY_NEWLINE);
Stefan Sperling12086582018-06-26 15:26:28 +0200239
240 if (llist_empty(&endp->conns)) {
241 vty_out(vty, " No active connections%s", VTY_NEWLINE);
242 return;
243 }
244
245 llist_for_each_entry(conn, &endp->conns, entry) {
246 vty_out(vty, " CONN: %s%s", mgcp_conn_dump(conn), VTY_NEWLINE);
247
248 if (show_stats) {
Ericfbf78d12021-08-23 22:31:39 +0200249 if (endp->trunk->cfg->conn_timeout) {
Oliver Smithe36b7752019-01-22 16:31:36 +0100250 struct timeval remaining;
251 osmo_timer_remaining(&conn->watchdog, NULL, &remaining);
252 vty_out(vty, " Currently remaining timeout (seconds): %d.%06d%s",
253 (int)remaining.tv_sec, (int)remaining.tv_usec, VTY_NEWLINE);
254 }
255
Stefan Sperling12086582018-06-26 15:26:28 +0200256 /* FIXME: Also add verbosity for other
257 * connection types (E1) as soon as
258 * the implementation is available */
259 if (conn->type == MGCP_CONN_TYPE_RTP) {
260 dump_rtp_end(vty, &conn->u.rtp);
261 }
262 }
263 }
264}
265
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200266static void dump_ratectr_global(struct vty *vty, struct mgcp_ratectr_global *ratectr)
267{
268 vty_out(vty, "%s", VTY_NEWLINE);
269 vty_out(vty, "Rate counters (global):%s", VTY_NEWLINE);
270
271 if (ratectr->mgcp_general_ctr_group) {
272 vty_out(vty, " %s:%s",
273 ratectr->mgcp_general_ctr_group->desc->
274 group_description, VTY_NEWLINE);
275 vty_out_rate_ctr_group_fmt(vty,
276 " %25n: %10c (%S/s %M/m %H/h %D/d) %d",
277 ratectr->mgcp_general_ctr_group);
278 }
279}
280
Philipp Maier889fe7f2020-07-06 17:44:12 +0200281static void dump_ratectr_trunk(struct vty *vty, struct mgcp_trunk *trunk)
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200282{
Philipp Maier889fe7f2020-07-06 17:44:12 +0200283 struct mgcp_ratectr_trunk *ratectr = &trunk->ratectr;
284
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200285 vty_out(vty, "%s", VTY_NEWLINE);
286 vty_out(vty, "Rate counters (trunk):%s", VTY_NEWLINE);
287
288 if (ratectr->mgcp_crcx_ctr_group) {
289 vty_out(vty, " %s:%s",
290 ratectr->mgcp_crcx_ctr_group->desc->group_description,
291 VTY_NEWLINE);
292 vty_out_rate_ctr_group_fmt(vty,
293 " %25n: %10c (%S/s %M/m %H/h %D/d) %d",
294 ratectr->mgcp_crcx_ctr_group);
295 }
296 if (ratectr->mgcp_dlcx_ctr_group) {
297 vty_out(vty, " %s:%s",
298 ratectr->mgcp_dlcx_ctr_group->desc->group_description,
299 VTY_NEWLINE);
300 vty_out_rate_ctr_group_fmt(vty,
301 " %25n: %10c (%S/s %M/m %H/h %D/d) %d",
302 ratectr->mgcp_dlcx_ctr_group);
303 }
304 if (ratectr->mgcp_mdcx_ctr_group) {
305 vty_out(vty, " %s:%s",
306 ratectr->mgcp_mdcx_ctr_group->desc->group_description,
307 VTY_NEWLINE);
308 vty_out_rate_ctr_group_fmt(vty,
309 " %25n: %10c (%S/s %M/m %H/h %D/d) %d",
310 ratectr->mgcp_mdcx_ctr_group);
311 }
312 if (ratectr->all_rtp_conn_stats) {
313 vty_out(vty, " %s:%s",
314 ratectr->all_rtp_conn_stats->desc->group_description,
315 VTY_NEWLINE);
316 vty_out_rate_ctr_group_fmt(vty,
317 " %25n: %10c (%S/s %M/m %H/h %D/d) %d",
318 ratectr->all_rtp_conn_stats);
319 }
Pau Espin Pedrol582c2bf2022-09-22 17:53:44 +0200320 if (ratectr->all_osmux_conn_stats) {
321 vty_out(vty, " %s:%s",
322 ratectr->all_osmux_conn_stats->desc->group_description,
323 VTY_NEWLINE);
324 vty_out_rate_ctr_group_fmt(vty,
325 " %25n: %10c (%S/s %M/m %H/h %D/d) %d",
326 ratectr->all_osmux_conn_stats);
327 }
Philipp Maier889fe7f2020-07-06 17:44:12 +0200328
329 if (ratectr->e1_stats && trunk->trunk_type == MGCP_TRUNK_E1) {
330 vty_out(vty, " %s:%s",
331 ratectr->e1_stats->desc->group_description,
332 VTY_NEWLINE);
333 vty_out_rate_ctr_group_fmt(vty,
334 " %25n: %10c (%S/s %M/m %H/h %D/d) %d",
335 ratectr->e1_stats);
336 }
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200337}
338
339
Keithfe53edd2021-05-04 15:23:30 -0500340static void dump_trunk(struct vty *vty, struct mgcp_trunk *trunk, int show_stats, int active_only)
Stefan Sperling12086582018-06-26 15:26:28 +0200341{
342 int i;
Keithfe53edd2021-05-04 15:23:30 -0500343 int active_count = 0;
Stefan Sperling12086582018-06-26 15:26:28 +0200344
345 vty_out(vty, "%s trunk %d with %d endpoints:%s",
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200346 trunk->trunk_type == MGCP_TRUNK_VIRTUAL ? "Virtual" : "E1",
Philipp Maier869b21c2020-07-03 16:04:16 +0200347 trunk->trunk_nr, trunk->number_endpoints, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200348
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200349 if (!trunk->endpoints) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200350 vty_out(vty, "No endpoints allocated yet.%s", VTY_NEWLINE);
351 return;
352 }
353
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200354 for (i = 0; i < trunk->number_endpoints; ++i) {
355 struct mgcp_endpoint *endp = trunk->endpoints[i];
Keithfe53edd2021-05-04 15:23:30 -0500356 if (!active_only || !llist_empty(&endp->conns)) {
357 dump_endpoint(vty, endp, trunk->trunk_nr, trunk->trunk_type,
358 show_stats);
359 if (i < trunk->number_endpoints - 1)
360 vty_out(vty, "%s", VTY_NEWLINE);
361 }
362 if (!llist_empty(&endp->conns))
363 active_count++;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200364 }
Stefan Sperling1e174872018-10-25 18:36:10 +0200365
Keithfe53edd2021-05-04 15:23:30 -0500366 if (active_count == 0)
367 vty_out(vty, "No endpoints in use.%s", VTY_NEWLINE);
368
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200369 if (show_stats)
Philipp Maier889fe7f2020-07-06 17:44:12 +0200370 dump_ratectr_trunk(vty, trunk);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200371}
372
Keithfe53edd2021-05-04 15:23:30 -0500373static int mgcp_show(struct vty *vty, int argc, const char **argv,
374 int show_stats, int active_only)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200375{
Philipp Maier14b27a82020-06-02 20:15:30 +0200376 struct mgcp_trunk *trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200377
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200378 llist_for_each_entry(trunk, &g_cfg->trunks, entry)
Keithfe53edd2021-05-04 15:23:30 -0500379 dump_trunk(vty, trunk, show_stats, active_only);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200380
Pau Espin Pedrol928a20b2022-09-23 15:38:24 +0200381 if (g_cfg->osmux_use != OSMUX_USAGE_OFF)
Pau Espin Pedrol8de58e72019-04-24 13:33:46 +0200382 vty_out(vty, "Osmux used CID: %d%s", osmux_cid_pool_count_used(),
Philipp Maier87bd9be2017-08-22 16:35:41 +0200383 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200384
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200385 if (show_stats)
386 dump_ratectr_global(vty, &g_cfg->ratectr);
387
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200388 return CMD_SUCCESS;
389}
390
Keithfe53edd2021-05-04 15:23:30 -0500391#define SHOW_MGCP_STR "Display information about the MGCP Media Gateway\n"
392
393DEFUN(show_mgcp, show_mgcp_cmd,
394 "show mgcp [stats]",
395 SHOW_STR
396 SHOW_MGCP_STR
397 "Include statistics\n")
398{
399 int show_stats = argc >= 1;
400 return mgcp_show(vty, argc, argv, show_stats, 0);
401}
402
403DEFUN(show_mgcp_active, show_mgcp_active_cmd,
404 "show mgcp active",
405 SHOW_STR
406 SHOW_MGCP_STR
407 "Show only endpoints with active connections\n")
408{
409 return mgcp_show(vty, argc, argv, 0, 1);
410}
411
Stefan Sperling12086582018-06-26 15:26:28 +0200412static void
Philipp Maier14b27a82020-06-02 20:15:30 +0200413dump_mgcp_endpoint(struct vty *vty, struct mgcp_trunk *trunk, const char *epname)
Stefan Sperling12086582018-06-26 15:26:28 +0200414{
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200415 struct mgcp_endpoint *endp;
Stefan Sperling12086582018-06-26 15:26:28 +0200416
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200417 if (trunk) {
418 /* If a trunk is given, search on that specific trunk only */
419 endp = mgcp_endp_by_name_trunk(NULL, epname, trunk);
420 if (!endp) {
Philipp Maierd70eef62021-07-19 13:53:28 +0200421 vty_out(vty, "endpoint %s not configured on trunk %u%s", epname, trunk->trunk_nr, VTY_NEWLINE);
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200422 return;
423 }
424 } else {
425 /* If no trunk is given, search on all possible trunks */
426 endp = mgcp_endp_by_name(NULL, epname, g_cfg);
427 if (!endp) {
428 vty_out(vty, "endpoint %s not configured%s", epname, VTY_NEWLINE);
429 return;
Stefan Sperling12086582018-06-26 15:26:28 +0200430 }
431 }
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200432
433 trunk = endp->trunk;
434 dump_endpoint(vty, endp, trunk->trunk_nr, trunk->trunk_type, true);
Stefan Sperling12086582018-06-26 15:26:28 +0200435}
436
437DEFUN(show_mcgp_endpoint, show_mgcp_endpoint_cmd,
438 "show mgcp endpoint NAME",
439 SHOW_STR
440 SHOW_MGCP_STR
441 "Display information about an endpoint\n" "The name of the endpoint\n")
442{
Philipp Maierc66ab2c2020-06-02 20:55:34 +0200443 dump_mgcp_endpoint(vty, NULL, argv[0]);
Stefan Sperling12086582018-06-26 15:26:28 +0200444 return CMD_SUCCESS;
445}
446
447DEFUN(show_mcgp_trunk_endpoint, show_mgcp_trunk_endpoint_cmd,
448 "show mgcp trunk <0-64> endpoint NAME",
449 SHOW_STR
450 SHOW_MGCP_STR
451 "Display information about a trunk\n" "Trunk number\n"
452 "Display information about an endpoint\n" "The name of the endpoint\n")
453{
Philipp Maier14b27a82020-06-02 20:15:30 +0200454 struct mgcp_trunk *trunk;
Stefan Sperling12086582018-06-26 15:26:28 +0200455 int trunkidx = atoi(argv[0]);
456
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200457 trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_E1, trunkidx);
Stefan Sperling12086582018-06-26 15:26:28 +0200458 if (!trunk) {
459 vty_out(vty, "trunk %d not found%s", trunkidx, VTY_NEWLINE);
460 return CMD_WARNING;
461 }
462
463 dump_mgcp_endpoint(vty, trunk, argv[1]);
464 return CMD_SUCCESS;
465}
466
Philipp Maier87bd9be2017-08-22 16:35:41 +0200467DEFUN(cfg_mgcp, cfg_mgcp_cmd, "mgcp", "Configure the MGCP")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200468{
469 vty->node = MGCP_NODE;
470 return CMD_SUCCESS;
471}
472
Philipp Maier19c430f2020-09-22 15:52:50 +0200473DEFUN_USRATTR(cfg_mgcp_local_ip,
474 cfg_mgcp_local_ip_cmd,
475 X(MGW_CMD_ATTR_NEWCONN),
476 "local ip " VTY_IPV46_CMD,
477 "Local options for the SDP record\n"
478 IP_STR
479 "IPv4 Address to use in SDP record\n"
480 "IPv6 Address to use in SDP record\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200481{
Eric2764bdb2021-08-23 22:11:47 +0200482 osmo_strlcpy(g_cfg->local_ip, argv[0], sizeof(g_cfg->local_ip));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200483 return CMD_SUCCESS;
484}
485
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200486#define BIND_STR "Listen/Bind related socket option\n"
487DEFUN(cfg_mgcp_bind_ip,
488 cfg_mgcp_bind_ip_cmd,
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +0200489 "bind ip " VTY_IPV46_CMD,
490 BIND_STR IP_STR
491 "IPv4 Address to bind to\n"
492 "IPv6 Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200493{
Eric2764bdb2021-08-23 22:11:47 +0200494 osmo_strlcpy(g_cfg->source_addr, argv[0], sizeof(g_cfg->source_addr));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200495 return CMD_SUCCESS;
496}
497
498DEFUN(cfg_mgcp_bind_port,
499 cfg_mgcp_bind_port_cmd,
500 "bind port <0-65534>",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200501 BIND_STR "Port information\n" "UDP port to listen for MGCP messages\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200502{
503 unsigned int port = atoi(argv[0]);
504 g_cfg->source_port = port;
505 return CMD_SUCCESS;
506}
507
Philipp Maier8cfe7df2020-09-22 16:18:26 +0200508DEFUN_DEPRECATED(cfg_mgcp_bind_early,
509 cfg_mgcp_bind_early_cmd,
510 "bind early (0|1)",
511 BIND_STR
512 "Bind local ports on start up\n" "Bind on demand\n" "Bind on startup\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200513{
Philipp Maier8cfe7df2020-09-22 16:18:26 +0200514 return CMD_SUCCESS;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200515}
516
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200517#define RTP_STR "RTP configuration\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200518#define UDP_PORT_STR "UDP Port number\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +0200519#define NET_START_STR "First UDP port allocated\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200520#define RANGE_START_STR "Start of the range of ports\n"
521#define RANGE_END_STR "End of the range of ports\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200522
Philipp Maierf1889d82017-11-08 14:59:39 +0100523DEFUN(cfg_mgcp_rtp_port_range,
524 cfg_mgcp_rtp_port_range_cmd,
Philipp Maiera19547b2018-05-22 13:44:34 +0200525 "rtp port-range <1024-65534> <1025-65535>",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200526 RTP_STR "Range of ports to use for the NET side\n"
527 RANGE_START_STR RANGE_END_STR)
528{
Philipp Maiera19547b2018-05-22 13:44:34 +0200529 int start;
530 int end;
531
532 start = atoi(argv[0]);
533 end = atoi(argv[1]);
534
535 if (end < start) {
536 vty_out(vty, "range end port (%i) must be greater than the range start port (%i)!%s",
537 end, start, VTY_NEWLINE);
538 return CMD_WARNING;
539 }
540
541 if (start & 1) {
542 vty_out(vty, "range must begin at an even port number, autocorrecting port (%i) to: %i%s",
543 start, start & 0xFFFE, VTY_NEWLINE);
544 start &= 0xFFFE;
545 }
546
547 if ((end & 1) == 0) {
548 vty_out(vty, "range must end at an odd port number, autocorrecting port (%i) to: %i%s",
549 end, end | 1, VTY_NEWLINE);
550 end |= 1;
551 }
552
553 g_cfg->net_ports.range_start = start;
554 g_cfg->net_ports.range_end = end;
555 g_cfg->net_ports.last_port = g_cfg->net_ports.range_start;
556
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200557 return CMD_SUCCESS;
558}
Philipp Maierf1889d82017-11-08 14:59:39 +0100559ALIAS_DEPRECATED(cfg_mgcp_rtp_port_range,
560 cfg_mgcp_rtp_net_range_cmd,
561 "rtp net-range <0-65534> <0-65534>",
562 RTP_STR "Range of ports to use for the NET side\n"
563 RANGE_START_STR RANGE_END_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200564
Philipp Maier19c430f2020-09-22 15:52:50 +0200565DEFUN_USRATTR(cfg_mgcp_rtp_bind_ip,
566 cfg_mgcp_rtp_bind_ip_cmd,
567 X(MGW_CMD_ATTR_NEWCONN),
568 "rtp bind-ip A.B.C.D",
569 RTP_STR "Bind endpoints facing the Network\n"
570 "IPv4 Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200571{
Eric2764bdb2021-08-23 22:11:47 +0200572 osmo_strlcpy(g_cfg->net_ports.bind_addr_v4, argv[0], sizeof(g_cfg->net_ports.bind_addr_v4));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200573 return CMD_SUCCESS;
574}
Philipp Maierf1889d82017-11-08 14:59:39 +0100575ALIAS_DEPRECATED(cfg_mgcp_rtp_bind_ip,
576 cfg_mgcp_rtp_net_bind_ip_cmd,
577 "rtp net-bind-ip A.B.C.D",
578 RTP_STR "Bind endpoints facing the Network\n" "Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200579
Philipp Maier19c430f2020-09-22 15:52:50 +0200580DEFUN_USRATTR(cfg_mgcp_rtp_no_bind_ip,
581 cfg_mgcp_rtp_no_bind_ip_cmd,
582 X(MGW_CMD_ATTR_NEWCONN),
583 "no rtp bind-ip",
584 NO_STR RTP_STR "Bind endpoints facing the Network\n"
585 "Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200586{
Eric2764bdb2021-08-23 22:11:47 +0200587 osmo_strlcpy(g_cfg->net_ports.bind_addr_v4, "", sizeof(g_cfg->net_ports.bind_addr_v4));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200588 return CMD_SUCCESS;
589}
Philipp Maierf1889d82017-11-08 14:59:39 +0100590ALIAS_DEPRECATED(cfg_mgcp_rtp_no_bind_ip,
591 cfg_mgcp_rtp_no_net_bind_ip_cmd,
592 "no rtp net-bind-ip",
593 NO_STR RTP_STR "Bind endpoints facing the Network\n"
594 "Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200595
Philipp Maier19c430f2020-09-22 15:52:50 +0200596DEFUN_USRATTR(cfg_mgcp_rtp_bind_ip_v6,
597 cfg_mgcp_rtp_bind_ip_v6_cmd,
598 X(MGW_CMD_ATTR_NEWCONN),
599 "rtp bind-ip-v6 " VTY_IPV6_CMD,
600 RTP_STR "Bind endpoints facing the Network\n"
601 "IPv6 Address to bind to\n")
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +0200602{
Eric2764bdb2021-08-23 22:11:47 +0200603 osmo_strlcpy(g_cfg->net_ports.bind_addr_v6, argv[0], sizeof(g_cfg->net_ports.bind_addr_v6));
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +0200604 return CMD_SUCCESS;
605}
606
Philipp Maier19c430f2020-09-22 15:52:50 +0200607DEFUN_USRATTR(cfg_mgcp_rtp_no_bind_ip_v6,
608 cfg_mgcp_rtp_no_bind_ip_v6_cmd,
609 X(MGW_CMD_ATTR_NEWCONN),
610 "no rtp bind-ip-v6",
611 NO_STR RTP_STR "Bind endpoints facing the Network\n"
612 "Address to bind to\n")
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +0200613{
Eric2764bdb2021-08-23 22:11:47 +0200614 osmo_strlcpy(g_cfg->net_ports.bind_addr_v6, "", sizeof(g_cfg->net_ports.bind_addr_v6));
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +0200615 return CMD_SUCCESS;
616}
617
Philipp Maier19c430f2020-09-22 15:52:50 +0200618DEFUN_USRATTR(cfg_mgcp_rtp_net_bind_ip_probing,
619 cfg_mgcp_rtp_net_bind_ip_probing_cmd,
620 X(MGW_CMD_ATTR_NEWCONN),
621 "rtp ip-probing",
622 RTP_STR "automatic rtp bind ip selection\n")
Philipp Maier1cb1e382017-11-02 17:16:04 +0100623{
624 g_cfg->net_ports.bind_addr_probe = true;
625 return CMD_SUCCESS;
626}
627
Philipp Maier19c430f2020-09-22 15:52:50 +0200628DEFUN_USRATTR(cfg_mgcp_rtp_no_net_bind_ip_probing,
629 cfg_mgcp_rtp_no_net_bind_ip_probing_cmd,
630 X(MGW_CMD_ATTR_NEWCONN),
631 "no rtp ip-probing",
632 NO_STR RTP_STR "no automatic rtp bind ip selection\n")
Philipp Maier1cb1e382017-11-02 17:16:04 +0100633{
634 g_cfg->net_ports.bind_addr_probe = false;
635 return CMD_SUCCESS;
636}
637
Philipp Maier19c430f2020-09-22 15:52:50 +0200638DEFUN_USRATTR(cfg_mgcp_rtp_ip_dscp,
639 cfg_mgcp_rtp_ip_dscp_cmd,
640 X(MGW_CMD_ATTR_NEWCONN),
Harald Welte5936a9c2021-04-27 22:30:52 +0200641 "rtp ip-dscp <0-63>",
Philipp Maier19c430f2020-09-22 15:52:50 +0200642 RTP_STR
Harald Welte5936a9c2021-04-27 22:30:52 +0200643 "Use specified DSCP for the audio stream (including Osmux)\n" "The DSCP value\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200644{
645 int dscp = atoi(argv[0]);
646 g_cfg->endp_dscp = dscp;
647 return CMD_SUCCESS;
648}
649
Harald Welte55a92292021-04-28 19:06:34 +0200650DEFUN_USRATTR(cfg_mgcp_rtp_priority,
651 cfg_mgcp_rtp_priority_cmd,
652 X(MGW_CMD_ATTR_NEWCONN),
653 "rtp socket-priority <0-255>",
654 RTP_STR
655 "socket priority (values > 6 require CAP_NET_ADMIN)\n" "socket priority value\n")
656{
657 int prio = atoi(argv[0]);
658 g_cfg->endp_priority = prio;
659 return CMD_SUCCESS;
660}
661
Philipp Maier87bd9be2017-08-22 16:35:41 +0200662#define FORCE_PTIME_STR "Force a fixed ptime for packets sent"
Philipp Maier19c430f2020-09-22 15:52:50 +0200663DEFUN_USRATTR(cfg_mgcp_rtp_force_ptime,
664 cfg_mgcp_rtp_force_ptime_cmd,
665 X(MGW_CMD_ATTR_NEWCONN),
666 "rtp force-ptime (10|20|40)",
667 RTP_STR FORCE_PTIME_STR
668 "The required ptime (packet duration) in ms\n" "10 ms\n20 ms\n40 ms\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200669{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200670 g_cfg->force_ptime = atoi(argv[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200671 return CMD_SUCCESS;
672}
673
Philipp Maier19c430f2020-09-22 15:52:50 +0200674DEFUN_USRATTR(cfg_mgcp_no_rtp_force_ptime,
675 cfg_mgcp_no_rtp_force_ptime_cmd,
676 X(MGW_CMD_ATTR_NEWCONN),
677 "no rtp force-ptime", NO_STR RTP_STR FORCE_PTIME_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200678{
Philipp Maier87bd9be2017-08-22 16:35:41 +0200679 g_cfg->force_ptime = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200680 return CMD_SUCCESS;
681}
682
Philipp Maier19c430f2020-09-22 15:52:50 +0200683DEFUN_USRATTR(cfg_mgcp_sdp_fmtp_extra,
684 cfg_mgcp_sdp_fmtp_extra_cmd,
685 X(MGW_CMD_ATTR_NEWCONN),
686 "sdp audio fmtp-extra .NAME",
687 "Add extra fmtp for the SDP file\n" "Audio\n" "Fmtp-extra\n"
688 "Extra Information\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200689{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200690 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200691 OSMO_ASSERT(trunk);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200692 char *txt = argv_concat(argv, argc, 0);
693 if (!txt)
694 return CMD_WARNING;
695
Philipp Maierd19de2e2020-06-03 13:55:33 +0200696 osmo_talloc_replace_string(g_cfg, &trunk->audio_fmtp_extra, txt);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200697 talloc_free(txt);
698 return CMD_SUCCESS;
699}
700
Philipp Maier19c430f2020-09-22 15:52:50 +0200701DEFUN_USRATTR(cfg_mgcp_allow_transcoding,
702 cfg_mgcp_allow_transcoding_cmd,
703 X(MGW_CMD_ATTR_NEWCONN),
704 "allow-transcoding", "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200705{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200706 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200707 OSMO_ASSERT(trunk);
708 trunk->no_audio_transcoding = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200709 return CMD_SUCCESS;
710}
711
Philipp Maier19c430f2020-09-22 15:52:50 +0200712DEFUN_USRATTR(cfg_mgcp_no_allow_transcoding,
713 cfg_mgcp_no_allow_transcoding_cmd,
714 X(MGW_CMD_ATTR_NEWCONN),
715 "no allow-transcoding", NO_STR "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200716{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200717 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200718 OSMO_ASSERT(trunk);
719 trunk->no_audio_transcoding = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200720 return CMD_SUCCESS;
721}
722
723#define SDP_STR "SDP File related options\n"
724#define AUDIO_STR "Audio payload options\n"
Philipp Maier7f90ddb2020-06-02 21:52:53 +0200725DEFUN_DEPRECATED(cfg_mgcp_sdp_payload_number,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200726 cfg_mgcp_sdp_payload_number_cmd,
727 "sdp audio-payload number <0-255>",
Philipp Maier87bd9be2017-08-22 16:35:41 +0200728 SDP_STR AUDIO_STR "Number\n" "Payload number\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200729{
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200730 return CMD_SUCCESS;
731}
732
Philipp Maier87bd9be2017-08-22 16:35:41 +0200733ALIAS_DEPRECATED(cfg_mgcp_sdp_payload_number,
734 cfg_mgcp_sdp_payload_number_cmd_old,
735 "sdp audio payload number <0-255>",
736 SDP_STR AUDIO_STR AUDIO_STR "Number\n" "Payload number\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200737
Philipp Maier7f90ddb2020-06-02 21:52:53 +0200738DEFUN_DEPRECATED(cfg_mgcp_sdp_payload_name,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200739 cfg_mgcp_sdp_payload_name_cmd,
740 "sdp audio-payload name NAME",
741 SDP_STR AUDIO_STR "Name\n" "Payload name\n")
742{
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200743 return CMD_SUCCESS;
744}
745
746ALIAS_DEPRECATED(cfg_mgcp_sdp_payload_name, cfg_mgcp_sdp_payload_name_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200747 "sdp audio payload name NAME",
748 SDP_STR AUDIO_STR AUDIO_STR "Name\n" "Payload name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200749
Philipp Maier19c430f2020-09-22 15:52:50 +0200750DEFUN_USRATTR(cfg_mgcp_sdp_payload_send_ptime,
751 cfg_mgcp_sdp_payload_send_ptime_cmd,
752 X(MGW_CMD_ATTR_NEWCONN),
753 "sdp audio-payload send-ptime",
754 SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200755{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200756 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200757 OSMO_ASSERT(trunk);
758 trunk->audio_send_ptime = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200759 return CMD_SUCCESS;
760}
761
Philipp Maier19c430f2020-09-22 15:52:50 +0200762DEFUN_USRATTR(cfg_mgcp_no_sdp_payload_send_ptime,
763 cfg_mgcp_no_sdp_payload_send_ptime_cmd,
764 X(MGW_CMD_ATTR_NEWCONN),
765 "no sdp audio-payload send-ptime",
766 NO_STR SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200767{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200768 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200769 OSMO_ASSERT(trunk);
770 trunk->audio_send_ptime = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200771 return CMD_SUCCESS;
772}
773
Philipp Maier19c430f2020-09-22 15:52:50 +0200774DEFUN_USRATTR(cfg_mgcp_sdp_payload_send_name,
775 cfg_mgcp_sdp_payload_send_name_cmd,
776 X(MGW_CMD_ATTR_NEWCONN),
777 "sdp audio-payload send-name",
778 SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200779{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200780 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200781 OSMO_ASSERT(trunk);
782 trunk->audio_send_name = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200783 return CMD_SUCCESS;
784}
785
Philipp Maier19c430f2020-09-22 15:52:50 +0200786DEFUN_USRATTR(cfg_mgcp_no_sdp_payload_send_name,
787 cfg_mgcp_no_sdp_payload_send_name_cmd,
788 X(MGW_CMD_ATTR_NEWCONN),
789 "no sdp audio-payload send-name",
790 NO_STR SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200791{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200792 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200793 OSMO_ASSERT(trunk);
794 trunk->audio_send_name = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200795 return CMD_SUCCESS;
796}
797
Philipp Maierba94b6d2020-09-22 16:14:32 +0200798DEFUN_DEPRECATED(cfg_mgcp_loop,
799 cfg_mgcp_loop_cmd,
800 "loop (0|1)",
801 "Loop audio for all endpoints on main trunk\n" "Don't Loop\n" "Loop\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200802{
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200803 return CMD_SUCCESS;
804}
805
Philipp Maier19c430f2020-09-22 15:52:50 +0200806DEFUN_USRATTR(cfg_mgcp_force_realloc,
807 cfg_mgcp_force_realloc_cmd,
808 X(MGW_CMD_ATTR_NEWCONN),
809 "force-realloc (0|1)",
810 "Force endpoint reallocation when the endpoint is still seized\n"
811 "Don't force reallocation\n" "force reallocation\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200812{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200813 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200814 OSMO_ASSERT(trunk);
815 trunk->force_realloc = atoi(argv[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200816 return CMD_SUCCESS;
817}
818
Philipp Maier19c430f2020-09-22 15:52:50 +0200819DEFUN_ATTR(cfg_mgcp_rtp_accept_all,
820 cfg_mgcp_rtp_accept_all_cmd,
821 "rtp-accept-all (0|1)",
822 "Accept all RTP packets, even when the originating IP/Port does not match\n"
823 "enable filter\n" "disable filter\n",
824 CMD_ATTR_IMMEDIATE)
Philipp Maier87bd9be2017-08-22 16:35:41 +0200825{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200826 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200827 OSMO_ASSERT(trunk);
828 trunk->rtp_accept_all = atoi(argv[0]);
Philipp Maier87bd9be2017-08-22 16:35:41 +0200829 return CMD_SUCCESS;
830}
831
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200832DEFUN(cfg_mgcp_number_endp,
833 cfg_mgcp_number_endp_cmd,
Philipp Maier869b21c2020-07-03 16:04:16 +0200834 "number endpoints <1-65534>",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200835 "Number options\n" "Endpoints available\n" "Number endpoints\n")
836{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200837 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200838 OSMO_ASSERT(trunk);
Philipp Maier889fe7f2020-07-06 17:44:12 +0200839 trunk->v.vty_number_endpoints = atoi(argv[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200840 return CMD_SUCCESS;
841}
842
Philipp Maier19c430f2020-09-22 15:52:50 +0200843DEFUN_ATTR(cfg_mgcp_omit_rtcp,
844 cfg_mgcp_omit_rtcp_cmd,
845 "rtcp-omit", RTCP_OMIT_STR,
846 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200847{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200848 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200849 trunk->omit_rtcp = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200850 return CMD_SUCCESS;
851}
852
Philipp Maier19c430f2020-09-22 15:52:50 +0200853DEFUN_ATTR(cfg_mgcp_no_omit_rtcp,
854 cfg_mgcp_no_omit_rtcp_cmd,
855 "no rtcp-omit",
856 NO_STR RTCP_OMIT_STR,
857 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200858{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200859 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200860 OSMO_ASSERT(trunk);
861 trunk->omit_rtcp = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200862 return CMD_SUCCESS;
863}
864
Philipp Maier19c430f2020-09-22 15:52:50 +0200865DEFUN_USRATTR(cfg_mgcp_patch_rtp_ssrc,
866 cfg_mgcp_patch_rtp_ssrc_cmd,
867 X(MGW_CMD_ATTR_NEWCONN),
868 "rtp-patch ssrc", RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200869{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200870 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200871 OSMO_ASSERT(trunk);
872 trunk->force_constant_ssrc = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200873 return CMD_SUCCESS;
874}
875
Philipp Maier19c430f2020-09-22 15:52:50 +0200876DEFUN_USRATTR(cfg_mgcp_no_patch_rtp_ssrc,
877 cfg_mgcp_no_patch_rtp_ssrc_cmd,
878 X(MGW_CMD_ATTR_NEWCONN),
879 "no rtp-patch ssrc", NO_STR RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200880{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200881 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200882 OSMO_ASSERT(trunk);
883 trunk->force_constant_ssrc = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200884 return CMD_SUCCESS;
885}
886
Philipp Maier19c430f2020-09-22 15:52:50 +0200887DEFUN_USRATTR(cfg_mgcp_patch_rtp_ts,
888 cfg_mgcp_patch_rtp_ts_cmd,
889 X(MGW_CMD_ATTR_NEWCONN),
890 "rtp-patch timestamp", RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200891{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200892 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200893 OSMO_ASSERT(trunk);
894 trunk->force_aligned_timing = 1;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200895 return CMD_SUCCESS;
896}
897
Philipp Maier19c430f2020-09-22 15:52:50 +0200898DEFUN_USRATTR(cfg_mgcp_no_patch_rtp_ts,
899 cfg_mgcp_no_patch_rtp_ts_cmd,
900 X(MGW_CMD_ATTR_NEWCONN),
901 "no rtp-patch timestamp", NO_STR RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200902{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200903 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200904 OSMO_ASSERT(trunk);
905 trunk->force_aligned_timing = 0;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200906 return CMD_SUCCESS;
907}
908
Philipp Maier19c430f2020-09-22 15:52:50 +0200909DEFUN_USRATTR(cfg_mgcp_patch_rtp_rfc5993hr,
910 cfg_mgcp_patch_rtp_rfc5993hr_cmd,
911 X(MGW_CMD_ATTR_NEWCONN),
912 "rtp-patch rfc5993hr", RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
Philipp Maier9fc8a022019-02-20 12:26:52 +0100913{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200914 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200915 OSMO_ASSERT(trunk);
916 trunk->rfc5993_hr_convert = true;
Philipp Maier9fc8a022019-02-20 12:26:52 +0100917 return CMD_SUCCESS;
918}
919
Philipp Maier19c430f2020-09-22 15:52:50 +0200920DEFUN_USRATTR(cfg_mgcp_no_patch_rtp_rfc5993hr,
921 cfg_mgcp_no_patch_rtp_rfc5993hr_cmd,
922 X(MGW_CMD_ATTR_NEWCONN),
923 "no rtp-patch rfc5993hr", NO_STR RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
Philipp Maier9fc8a022019-02-20 12:26:52 +0100924{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200925 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200926 OSMO_ASSERT(trunk);
927 trunk->rfc5993_hr_convert = false;
Philipp Maier9fc8a022019-02-20 12:26:52 +0100928 return CMD_SUCCESS;
929}
930
Philipp Maier19c430f2020-09-22 15:52:50 +0200931DEFUN_USRATTR(cfg_mgcp_no_patch_rtp,
932 cfg_mgcp_no_patch_rtp_cmd,
933 X(MGW_CMD_ATTR_NEWCONN),
934 "no rtp-patch", NO_STR RTP_PATCH_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200935{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200936 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200937 OSMO_ASSERT(trunk);
938 trunk->force_constant_ssrc = 0;
939 trunk->force_aligned_timing = 0;
940 trunk->rfc5993_hr_convert = false;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200941 return CMD_SUCCESS;
942}
943
Philipp Maier19c430f2020-09-22 15:52:50 +0200944DEFUN_ATTR(cfg_mgcp_rtp_keepalive,
945 cfg_mgcp_rtp_keepalive_cmd,
946 "rtp keep-alive <1-120>",
947 RTP_STR RTP_KEEPALIVE_STR "Keep alive interval in secs\n",
948 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200949{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200950 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200951 OSMO_ASSERT(trunk);
952 mgcp_trunk_set_keepalive(trunk, atoi(argv[0]));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200953 return CMD_SUCCESS;
954}
955
Philipp Maier19c430f2020-09-22 15:52:50 +0200956DEFUN_ATTR(cfg_mgcp_rtp_keepalive_once,
957 cfg_mgcp_rtp_keepalive_once_cmd,
958 "rtp keep-alive once",
959 RTP_STR RTP_KEEPALIVE_STR "Send dummy packet only once after CRCX/MDCX\n",
960 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200961{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200962 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200963 OSMO_ASSERT(trunk);
964 mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200965 return CMD_SUCCESS;
966}
967
Philipp Maier19c430f2020-09-22 15:52:50 +0200968DEFUN_ATTR(cfg_mgcp_no_rtp_keepalive,
969 cfg_mgcp_no_rtp_keepalive_cmd,
970 "no rtp keep-alive", NO_STR RTP_STR RTP_KEEPALIVE_STR,
971 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200972{
Philipp Maier6fbbeec2020-07-01 23:00:54 +0200973 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +0200974 OSMO_ASSERT(trunk);
975 mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_NEVER);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200976 return CMD_SUCCESS;
977}
978
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +0200979#define CALL_AGENT_STR "Call agent information\n"
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200980DEFUN(cfg_mgcp_agent_addr,
981 cfg_mgcp_agent_addr_cmd,
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +0200982 "call-agent ip " VTY_IPV46_CMD,
983 CALL_AGENT_STR IP_STR
984 "IPv4 Address of the call agent\n"
985 "IPv6 Address of the call agent\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200986{
Eric2764bdb2021-08-23 22:11:47 +0200987 osmo_strlcpy(g_cfg->call_agent_addr, argv[0], sizeof(g_cfg->call_agent_addr));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200988 return CMD_SUCCESS;
989}
990
991ALIAS_DEPRECATED(cfg_mgcp_agent_addr, cfg_mgcp_agent_addr_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +0200992 "call agent ip A.B.C.D",
993 CALL_AGENT_STR CALL_AGENT_STR IP_STR
994 "IPv4 Address of the callagent\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200995
Philipp Maier21be42a2020-05-29 21:39:48 +0200996DEFUN(cfg_mgcp_trunk, cfg_mgcp_trunk_cmd,
Philipp Maier0653cc82020-08-10 22:52:51 +0200997 "trunk <0-64>", "Configure a SS7 trunk\n" "Trunk Nr\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +0200998{
Philipp Maier14b27a82020-06-02 20:15:30 +0200999 struct mgcp_trunk *trunk;
Philipp Maierd70eef62021-07-19 13:53:28 +02001000 unsigned int index = atoi(argv[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001001
Philipp Maier6fbbeec2020-07-01 23:00:54 +02001002 trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_E1, index);
Harald Weltec39b1bf2020-03-08 11:29:39 +01001003 if (!trunk) {
1004 trunk = mgcp_trunk_alloc(g_cfg, MGCP_TRUNK_E1, index);
Philipp Maier2d681fd2020-05-29 16:20:25 +02001005 if (!trunk) {
1006 vty_out(vty, "%%Unable to allocate trunk %u.%s",
1007 index, VTY_NEWLINE);
Harald Weltec39b1bf2020-03-08 11:29:39 +01001008 return CMD_WARNING;
Philipp Maier2d681fd2020-05-29 16:20:25 +02001009 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001010 }
1011
1012 vty->node = TRUNK_NODE;
1013 vty->index = trunk;
1014 return CMD_SUCCESS;
1015}
1016
1017static int config_write_trunk(struct vty *vty)
1018{
Philipp Maier14b27a82020-06-02 20:15:30 +02001019 struct mgcp_trunk *trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001020
1021 llist_for_each_entry(trunk, &g_cfg->trunks, entry) {
Philipp Maierd19de2e2020-06-03 13:55:33 +02001022
1023 /* Due to historical reasons, the virtual trunk is configured
1024 using separate VTY parameters, so we omit writing the trunk
1025 config of trunk 0 here. The configuration for the virtual
1026 trunk is written by config_write_mgcp(). */
1027
Philipp Maier31682a32020-11-26 00:39:35 +01001028 if (trunk->trunk_type == MGCP_TRUNK_VIRTUAL
1029 && trunk->trunk_nr == MGCP_VIRT_TRUNK_ID)
Philipp Maierd19de2e2020-06-03 13:55:33 +02001030 continue;
1031
Philipp Maierd70eef62021-07-19 13:53:28 +02001032 vty_out(vty, " trunk %u%s", trunk->trunk_nr, VTY_NEWLINE);
Philipp Maier889fe7f2020-07-06 17:44:12 +02001033 vty_out(vty, " line %u%s", trunk->e1.vty_line_nr, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001034 vty_out(vty, " %ssdp audio-payload send-ptime%s",
1035 trunk->audio_send_ptime ? "" : "no ", VTY_NEWLINE);
1036 vty_out(vty, " %ssdp audio-payload send-name%s",
1037 trunk->audio_send_name ? "" : "no ", VTY_NEWLINE);
1038
1039 if (trunk->keepalive_interval == MGCP_KEEPALIVE_ONCE)
1040 vty_out(vty, " rtp keep-alive once%s", VTY_NEWLINE);
1041 else if (trunk->keepalive_interval)
1042 vty_out(vty, " rtp keep-alive %d%s",
1043 trunk->keepalive_interval, VTY_NEWLINE);
1044 else
1045 vty_out(vty, " no rtp keep-alive%s", VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001046 vty_out(vty, " force-realloc %d%s",
1047 trunk->force_realloc, VTY_NEWLINE);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001048 vty_out(vty, " rtp-accept-all %d%s",
1049 trunk->rtp_accept_all, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001050 if (trunk->omit_rtcp)
1051 vty_out(vty, " rtcp-omit%s", VTY_NEWLINE);
1052 else
1053 vty_out(vty, " no rtcp-omit%s", VTY_NEWLINE);
Philipp Maier9fc8a022019-02-20 12:26:52 +01001054 if (trunk->force_constant_ssrc || trunk->force_aligned_timing
Philipp Maierd19de2e2020-06-03 13:55:33 +02001055 || trunk->rfc5993_hr_convert) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001056 vty_out(vty, " %srtp-patch ssrc%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001057 trunk->force_constant_ssrc ? "" : "no ",
1058 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001059 vty_out(vty, " %srtp-patch timestamp%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001060 trunk->force_aligned_timing ? "" : "no ",
1061 VTY_NEWLINE);
Philipp Maier9fc8a022019-02-20 12:26:52 +01001062 vty_out(vty, " %srtp-patch rfc5993hr%s",
1063 trunk->rfc5993_hr_convert ? "" : "no ",
1064 VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001065 } else
1066 vty_out(vty, " no rtp-patch%s", VTY_NEWLINE);
1067 if (trunk->audio_fmtp_extra)
1068 vty_out(vty, " sdp audio fmtp-extra %s%s",
1069 trunk->audio_fmtp_extra, VTY_NEWLINE);
1070 vty_out(vty, " %sallow-transcoding%s",
1071 trunk->no_audio_transcoding ? "no " : "", VTY_NEWLINE);
1072 }
1073
1074 return CMD_SUCCESS;
1075}
1076
Philipp Maier19c430f2020-09-22 15:52:50 +02001077DEFUN_USRATTR(cfg_trunk_sdp_fmtp_extra,
1078 cfg_trunk_sdp_fmtp_extra_cmd,
1079 X(MGW_CMD_ATTR_NEWCONN),
1080 "sdp audio fmtp-extra .NAME",
1081 "Add extra fmtp for the SDP file\n" "Audio\n" "Fmtp-extra\n"
1082 "Extra Information\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001083{
Philipp Maier14b27a82020-06-02 20:15:30 +02001084 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001085 char *txt = argv_concat(argv, argc, 0);
1086 if (!txt)
1087 return CMD_WARNING;
1088
1089 osmo_talloc_replace_string(g_cfg, &trunk->audio_fmtp_extra, txt);
1090 talloc_free(txt);
1091 return CMD_SUCCESS;
1092}
1093
Philipp Maier7f90ddb2020-06-02 21:52:53 +02001094DEFUN_DEPRECATED(cfg_trunk_payload_number,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001095 cfg_trunk_payload_number_cmd,
1096 "sdp audio-payload number <0-255>",
1097 SDP_STR AUDIO_STR "Number\n" "Payload Number\n")
1098{
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001099 return CMD_SUCCESS;
1100}
1101
1102ALIAS_DEPRECATED(cfg_trunk_payload_number, cfg_trunk_payload_number_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001103 "sdp audio payload number <0-255>",
1104 SDP_STR AUDIO_STR AUDIO_STR "Number\n" "Payload Number\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001105
Philipp Maier7f90ddb2020-06-02 21:52:53 +02001106DEFUN_DEPRECATED(cfg_trunk_payload_name,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001107 cfg_trunk_payload_name_cmd,
1108 "sdp audio-payload name NAME",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001109 SDP_STR AUDIO_STR "Payload\n" "Payload Name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001110{
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001111 return CMD_SUCCESS;
1112}
1113
1114ALIAS_DEPRECATED(cfg_trunk_payload_name, cfg_trunk_payload_name_cmd_old,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001115 "sdp audio payload name NAME",
1116 SDP_STR AUDIO_STR AUDIO_STR "Payload\n" "Payload Name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001117
Philipp Maierba94b6d2020-09-22 16:14:32 +02001118DEFUN_DEPRECATED(cfg_trunk_loop,
1119 cfg_trunk_loop_cmd,
1120 "loop (0|1)",
1121 "Loop audio for all endpoints on this trunk\n" "Don't Loop\n" "Loop\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001122{
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001123 return CMD_SUCCESS;
1124}
1125
Philipp Maier41425e92020-11-26 00:41:59 +01001126DEFUN_USRATTR(cfg_trunk_force_realloc,
1127 cfg_trunk_force_realloc_cmd,
1128 X(MGW_CMD_ATTR_NEWCONN),
1129 "force-realloc (0|1)",
1130 "Force endpoint reallocation when the endpoint is still seized\n"
1131 "Don't force reallocation\n" "force reallocation\n")
1132{
1133 struct mgcp_trunk *trunk = vty->index;
1134 OSMO_ASSERT(trunk);
1135 trunk->force_realloc = atoi(argv[0]);
1136 return CMD_SUCCESS;
1137}
1138
1139DEFUN_ATTR(cfg_trunk_rtp_accept_all,
1140 cfg_trunk_rtp_accept_all_cmd,
1141 "rtp-accept-all (0|1)",
1142 "Accept all RTP packets, even when the originating IP/Port does not match\n"
1143 "enable filter\n" "disable filter\n",
1144 CMD_ATTR_IMMEDIATE)
1145{
1146 struct mgcp_trunk *trunk = vty->index;
1147 OSMO_ASSERT(trunk);
1148 trunk->rtp_accept_all = atoi(argv[0]);
1149 return CMD_SUCCESS;
1150}
1151
Philipp Maier19c430f2020-09-22 15:52:50 +02001152DEFUN_USRATTR(cfg_trunk_sdp_payload_send_ptime,
1153 cfg_trunk_sdp_payload_send_ptime_cmd,
1154 X(MGW_CMD_ATTR_NEWCONN),
1155 "sdp audio-payload send-ptime",
1156 SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001157{
Philipp Maier14b27a82020-06-02 20:15:30 +02001158 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001159 trunk->audio_send_ptime = 1;
1160 return CMD_SUCCESS;
1161}
1162
Philipp Maier19c430f2020-09-22 15:52:50 +02001163DEFUN_USRATTR(cfg_trunk_no_sdp_payload_send_ptime,
1164 cfg_trunk_no_sdp_payload_send_ptime_cmd,
1165 X(MGW_CMD_ATTR_NEWCONN),
1166 "no sdp audio-payload send-ptime",
1167 NO_STR SDP_STR AUDIO_STR "Send SDP ptime (packet duration) attribute\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001168{
Philipp Maier14b27a82020-06-02 20:15:30 +02001169 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001170 trunk->audio_send_ptime = 0;
1171 return CMD_SUCCESS;
1172}
1173
Philipp Maier19c430f2020-09-22 15:52:50 +02001174DEFUN_USRATTR(cfg_trunk_sdp_payload_send_name,
1175 cfg_trunk_sdp_payload_send_name_cmd,
1176 X(MGW_CMD_ATTR_NEWCONN),
1177 "sdp audio-payload send-name",
1178 SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001179{
Philipp Maier14b27a82020-06-02 20:15:30 +02001180 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001181 trunk->audio_send_name = 1;
1182 return CMD_SUCCESS;
1183}
1184
Philipp Maier19c430f2020-09-22 15:52:50 +02001185DEFUN_USRATTR(cfg_trunk_no_sdp_payload_send_name,
1186 cfg_trunk_no_sdp_payload_send_name_cmd,
1187 X(MGW_CMD_ATTR_NEWCONN),
1188 "no sdp audio-payload send-name",
1189 NO_STR SDP_STR AUDIO_STR "Send SDP rtpmap with the audio name\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001190{
Philipp Maier14b27a82020-06-02 20:15:30 +02001191 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001192 trunk->audio_send_name = 0;
1193 return CMD_SUCCESS;
1194}
1195
Philipp Maier19c430f2020-09-22 15:52:50 +02001196DEFUN_ATTR(cfg_trunk_omit_rtcp,
1197 cfg_trunk_omit_rtcp_cmd,
1198 "rtcp-omit", RTCP_OMIT_STR,
1199 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001200{
Philipp Maier14b27a82020-06-02 20:15:30 +02001201 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001202 trunk->omit_rtcp = 1;
1203 return CMD_SUCCESS;
1204}
1205
Philipp Maier19c430f2020-09-22 15:52:50 +02001206DEFUN_ATTR(cfg_trunk_no_omit_rtcp,
1207 cfg_trunk_no_omit_rtcp_cmd,
1208 "no rtcp-omit", NO_STR RTCP_OMIT_STR,
1209 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001210{
Philipp Maier14b27a82020-06-02 20:15:30 +02001211 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001212 trunk->omit_rtcp = 0;
1213 return CMD_SUCCESS;
1214}
1215
Philipp Maier19c430f2020-09-22 15:52:50 +02001216DEFUN_USRATTR(cfg_trunk_patch_rtp_ssrc,
1217 cfg_trunk_patch_rtp_ssrc_cmd,
1218 X(MGW_CMD_ATTR_NEWCONN),
1219 "rtp-patch ssrc", RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001220{
Philipp Maier14b27a82020-06-02 20:15:30 +02001221 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001222 trunk->force_constant_ssrc = 1;
1223 return CMD_SUCCESS;
1224}
1225
Philipp Maier19c430f2020-09-22 15:52:50 +02001226DEFUN_USRATTR(cfg_trunk_no_patch_rtp_ssrc,
1227 cfg_trunk_no_patch_rtp_ssrc_cmd,
1228 X(MGW_CMD_ATTR_NEWCONN),
1229 "no rtp-patch ssrc", NO_STR RTP_PATCH_STR "Force a fixed SSRC\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001230{
Philipp Maier14b27a82020-06-02 20:15:30 +02001231 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001232 trunk->force_constant_ssrc = 0;
1233 return CMD_SUCCESS;
1234}
1235
Philipp Maier19c430f2020-09-22 15:52:50 +02001236DEFUN_USRATTR(cfg_trunk_patch_rtp_ts,
1237 cfg_trunk_patch_rtp_ts_cmd,
1238 X(MGW_CMD_ATTR_NEWCONN),
1239 "rtp-patch timestamp", RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001240{
Philipp Maier14b27a82020-06-02 20:15:30 +02001241 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001242 trunk->force_aligned_timing = 1;
1243 return CMD_SUCCESS;
1244}
1245
Philipp Maier19c430f2020-09-22 15:52:50 +02001246DEFUN_USRATTR(cfg_trunk_no_patch_rtp_ts,
1247 cfg_trunk_no_patch_rtp_ts_cmd,
1248 X(MGW_CMD_ATTR_NEWCONN),
1249 "no rtp-patch timestamp", NO_STR RTP_PATCH_STR "Adjust RTP timestamp\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001250{
Philipp Maier14b27a82020-06-02 20:15:30 +02001251 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001252 trunk->force_aligned_timing = 0;
1253 return CMD_SUCCESS;
1254}
1255
Philipp Maier19c430f2020-09-22 15:52:50 +02001256DEFUN_USRATTR(cfg_trunk_patch_rtp_rfc5993hr,
1257 cfg_trunk_patch_rtp_rfc5993hr_cmd,
1258 X(MGW_CMD_ATTR_NEWCONN),
1259 "rtp-patch rfc5993hr", RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
Philipp Maier9fc8a022019-02-20 12:26:52 +01001260{
Philipp Maier14b27a82020-06-02 20:15:30 +02001261 struct mgcp_trunk *trunk = vty->index;
Philipp Maier9fc8a022019-02-20 12:26:52 +01001262 trunk->rfc5993_hr_convert = true;
1263 return CMD_SUCCESS;
1264}
1265
Philipp Maier19c430f2020-09-22 15:52:50 +02001266DEFUN_USRATTR(cfg_trunk_no_patch_rtp_rfc5993hr,
1267 cfg_trunk_no_patch_rtp_rfc5993hr_cmd,
1268 X(MGW_CMD_ATTR_NEWCONN),
1269 "no rtp-patch rfc5993hr", NO_STR RTP_PATCH_STR RTP_TS101318_RFC5993_CONV_STR)
Philipp Maier9fc8a022019-02-20 12:26:52 +01001270{
Philipp Maier14b27a82020-06-02 20:15:30 +02001271 struct mgcp_trunk *trunk = vty->index;
Philipp Maier9fc8a022019-02-20 12:26:52 +01001272 trunk->rfc5993_hr_convert = false;
1273 return CMD_SUCCESS;
1274}
1275
Philipp Maier19c430f2020-09-22 15:52:50 +02001276DEFUN_USRATTR(cfg_trunk_no_patch_rtp,
1277 cfg_trunk_no_patch_rtp_cmd,
1278 X(MGW_CMD_ATTR_NEWCONN),
1279 "no rtp-patch", NO_STR RTP_PATCH_STR)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001280{
Philipp Maier14b27a82020-06-02 20:15:30 +02001281 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001282 trunk->force_constant_ssrc = 0;
1283 trunk->force_aligned_timing = 0;
Philipp Maier9fc8a022019-02-20 12:26:52 +01001284 trunk->rfc5993_hr_convert = false;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001285 return CMD_SUCCESS;
1286}
1287
Philipp Maier19c430f2020-09-22 15:52:50 +02001288DEFUN_ATTR(cfg_trunk_rtp_keepalive,
1289 cfg_trunk_rtp_keepalive_cmd,
1290 "rtp keep-alive <1-120>",
1291 RTP_STR RTP_KEEPALIVE_STR "Keep-alive interval in secs\n",
1292 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001293{
Philipp Maier14b27a82020-06-02 20:15:30 +02001294 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001295 mgcp_trunk_set_keepalive(trunk, atoi(argv[0]));
1296 return CMD_SUCCESS;
1297}
1298
Philipp Maier19c430f2020-09-22 15:52:50 +02001299DEFUN_ATTR(cfg_trunk_rtp_keepalive_once,
1300 cfg_trunk_rtp_keepalive_once_cmd,
1301 "rtp keep-alive once",
1302 RTP_STR RTP_KEEPALIVE_STR "Send dummy packet only once after CRCX/MDCX\n",
1303 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001304{
Philipp Maier14b27a82020-06-02 20:15:30 +02001305 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001306 mgcp_trunk_set_keepalive(trunk, MGCP_KEEPALIVE_ONCE);
1307 return CMD_SUCCESS;
1308}
1309
Philipp Maier19c430f2020-09-22 15:52:50 +02001310DEFUN_ATTR(cfg_trunk_no_rtp_keepalive,
1311 cfg_trunk_no_rtp_keepalive_cmd,
1312 "no rtp keep-alive", NO_STR RTP_STR RTP_KEEPALIVE_STR,
1313 CMD_ATTR_IMMEDIATE)
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001314{
Philipp Maier14b27a82020-06-02 20:15:30 +02001315 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001316 mgcp_trunk_set_keepalive(trunk, 0);
1317 return CMD_SUCCESS;
1318}
1319
Philipp Maier19c430f2020-09-22 15:52:50 +02001320DEFUN_USRATTR(cfg_trunk_allow_transcoding,
1321 cfg_trunk_allow_transcoding_cmd,
1322 X(MGW_CMD_ATTR_NEWCONN),
1323 "allow-transcoding", "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001324{
Philipp Maier14b27a82020-06-02 20:15:30 +02001325 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001326 trunk->no_audio_transcoding = 0;
1327 return CMD_SUCCESS;
1328}
1329
Philipp Maier19c430f2020-09-22 15:52:50 +02001330DEFUN_USRATTR(cfg_trunk_no_allow_transcoding,
1331 cfg_trunk_no_allow_transcoding_cmd,
1332 X(MGW_CMD_ATTR_NEWCONN),
1333 "no allow-transcoding", NO_STR "Allow transcoding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001334{
Philipp Maier14b27a82020-06-02 20:15:30 +02001335 struct mgcp_trunk *trunk = vty->index;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001336 trunk->no_audio_transcoding = 1;
1337 return CMD_SUCCESS;
1338}
1339
Philipp Maier889fe7f2020-07-06 17:44:12 +02001340#define LINE_STR "Configure trunk for given Line\nE1/T1 Line Number\n"
1341
1342DEFUN(cfg_trunk_line,
1343 cfg_trunk_line_cmd,
1344 "line <0-255>",
1345 LINE_STR)
1346{
1347 struct mgcp_trunk *trunk = vty->index;
1348 int line_nr = atoi(argv[0]);
1349 trunk->e1.vty_line_nr = line_nr;
1350 return CMD_SUCCESS;
1351}
1352
Philipp Maier87bd9be2017-08-22 16:35:41 +02001353DEFUN(loop_conn,
1354 loop_conn_cmd,
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001355 "loop-endpoint <0-64> NAME (0|1)",
1356 "Loop a given endpoint\n" "Trunk number\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001357 "The name in hex of the endpoint\n" "Disable the loop\n"
1358 "Enable the loop\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001359{
Philipp Maier14b27a82020-06-02 20:15:30 +02001360 struct mgcp_trunk *trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001361 struct mgcp_endpoint *endp;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001362 struct mgcp_conn *conn;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001363
Philipp Maier6fbbeec2020-07-01 23:00:54 +02001364 trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_E1, atoi(argv[0]));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001365 if (!trunk) {
1366 vty_out(vty, "%%Trunk %d not found in the config.%s",
1367 atoi(argv[0]), VTY_NEWLINE);
1368 return CMD_WARNING;
1369 }
1370
1371 if (!trunk->endpoints) {
Philipp Maierd70eef62021-07-19 13:53:28 +02001372 vty_out(vty, "%%Trunk %u has no endpoints allocated.%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001373 trunk->trunk_nr, VTY_NEWLINE);
1374 return CMD_WARNING;
1375 }
1376
1377 int endp_no = strtoul(argv[1], NULL, 16);
1378 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1379 vty_out(vty, "Loopback number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001380 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001381 return CMD_WARNING;
1382 }
1383
Philipp Maierc66ab2c2020-06-02 20:55:34 +02001384 endp = trunk->endpoints[endp_no];
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001385 int loop = atoi(argv[2]);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001386 llist_for_each_entry(conn, &endp->conns, entry) {
1387 if (conn->type == MGCP_CONN_TYPE_RTP)
1388 /* Handle it like a MDCX, switch on SSRC patching if enabled */
1389 mgcp_rtp_end_config(endp, 1, &conn->u.rtp.end);
1390 else {
1391 /* FIXME: Introduce support for other connection (E1)
1392 * types when implementation is available */
1393 vty_out(vty, "%%Can't enable SSRC patching,"
1394 "connection %s is not an RTP connection.%s",
1395 mgcp_conn_dump(conn), VTY_NEWLINE);
1396 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001397
Philipp Maier87bd9be2017-08-22 16:35:41 +02001398 if (loop)
1399 conn->mode = MGCP_CONN_LOOPBACK;
1400 else
1401 conn->mode = conn->mode_orig;
1402 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001403
1404 return CMD_SUCCESS;
1405}
1406
Philipp Maier87bd9be2017-08-22 16:35:41 +02001407DEFUN(tap_rtp,
1408 tap_rtp_cmd,
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +02001409 "tap-rtp <0-64> ENDPOINT CONN (in|out) " VTY_IPV46_CMD " <0-65534>",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001410 "Forward data on endpoint to a different system\n" "Trunk number\n"
1411 "The endpoint in hex\n"
Philipp Maier87bd9be2017-08-22 16:35:41 +02001412 "The connection id in hex\n"
1413 "Forward incoming data\n"
1414 "Forward leaving data\n"
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +02001415 "Destination IPv4 of the data\n"
1416 "Destination IPv6 of the data\n"
1417 "Destination port\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001418{
1419 struct mgcp_rtp_tap *tap;
Philipp Maier14b27a82020-06-02 20:15:30 +02001420 struct mgcp_trunk *trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001421 struct mgcp_endpoint *endp;
Philipp Maier87bd9be2017-08-22 16:35:41 +02001422 struct mgcp_conn_rtp *conn;
Philipp Maier01d24a32017-11-21 17:26:09 +01001423 const char *conn_id = NULL;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001424
Philipp Maier6fbbeec2020-07-01 23:00:54 +02001425 trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_E1, atoi(argv[0]));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001426 if (!trunk) {
1427 vty_out(vty, "%%Trunk %d not found in the config.%s",
1428 atoi(argv[0]), VTY_NEWLINE);
1429 return CMD_WARNING;
1430 }
1431
1432 if (!trunk->endpoints) {
Philipp Maierd70eef62021-07-19 13:53:28 +02001433 vty_out(vty, "%%Trunk %u has no endpoints allocated.%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001434 trunk->trunk_nr, VTY_NEWLINE);
1435 return CMD_WARNING;
1436 }
1437
1438 int endp_no = strtoul(argv[1], NULL, 16);
1439 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1440 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001441 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001442 return CMD_WARNING;
1443 }
1444
Philipp Maierc66ab2c2020-06-02 20:55:34 +02001445 endp = trunk->endpoints[endp_no];
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001446
Philipp Maier01d24a32017-11-21 17:26:09 +01001447 conn_id = argv[2];
Philipp Maier87bd9be2017-08-22 16:35:41 +02001448 conn = mgcp_conn_get_rtp(endp, conn_id);
1449 if (!conn) {
Philipp Maier01d24a32017-11-21 17:26:09 +01001450 vty_out(vty, "Conn ID %s is invalid.%s",
1451 conn_id, VTY_NEWLINE);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001452 return CMD_WARNING;
1453 }
1454
1455 if (strcmp(argv[3], "in") == 0)
1456 tap = &conn->tap_in;
1457 else if (strcmp(argv[3], "out") == 0)
1458 tap = &conn->tap_out;
1459 else {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001460 vty_out(vty, "Unknown mode... tricked vty?%s", VTY_NEWLINE);
1461 return CMD_WARNING;
1462 }
1463
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001464 memset(&tap->forward, 0, sizeof(tap->forward));
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +02001465
1466 tap->forward.u.sa.sa_family = osmo_ip_str_type(argv[4]);
1467 switch (tap->forward.u.sa.sa_family) {
1468 case AF_INET:
1469 if (inet_pton(AF_INET, argv[4], &tap->forward.u.sin.sin_addr) != 1)
1470 return CMD_WARNING;
1471 tap->forward.u.sin.sin_port = htons(atoi(argv[5]));
1472 break;
1473 case AF_INET6:
1474 if (inet_pton(AF_INET6, argv[4], &tap->forward.u.sin6.sin6_addr) != 1)
1475 return CMD_WARNING;
1476 tap->forward.u.sin6.sin6_port = htons(atoi(argv[5]));
1477 break;
1478 default:
1479 return CMD_WARNING;
1480 }
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001481 tap->enabled = 1;
1482 return CMD_SUCCESS;
1483}
1484
1485DEFUN(free_endp, free_endp_cmd,
1486 "free-endpoint <0-64> NUMBER",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001487 "Free the given endpoint\n" "Trunk number\n" "Endpoint number in hex.\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001488{
Philipp Maier14b27a82020-06-02 20:15:30 +02001489 struct mgcp_trunk *trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001490 struct mgcp_endpoint *endp;
1491
Philipp Maier6fbbeec2020-07-01 23:00:54 +02001492 trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_E1, atoi(argv[0]));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001493 if (!trunk) {
1494 vty_out(vty, "%%Trunk %d not found in the config.%s",
1495 atoi(argv[0]), VTY_NEWLINE);
1496 return CMD_WARNING;
1497 }
1498
1499 if (!trunk->endpoints) {
Philipp Maierd70eef62021-07-19 13:53:28 +02001500 vty_out(vty, "%%Trunk %u has no endpoints allocated.%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001501 trunk->trunk_nr, VTY_NEWLINE);
1502 return CMD_WARNING;
1503 }
1504
1505 int endp_no = strtoul(argv[1], NULL, 16);
1506 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1507 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001508 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001509 return CMD_WARNING;
1510 }
1511
Philipp Maierc66ab2c2020-06-02 20:55:34 +02001512 endp = trunk->endpoints[endp_no];
Philipp Maier1355d7e2018-02-01 14:30:06 +01001513 mgcp_endp_release(endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001514 return CMD_SUCCESS;
1515}
1516
1517DEFUN(reset_endp, reset_endp_cmd,
1518 "reset-endpoint <0-64> NUMBER",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001519 "Reset the given endpoint\n" "Trunk number\n" "Endpoint number in hex.\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001520{
Philipp Maier14b27a82020-06-02 20:15:30 +02001521 struct mgcp_trunk *trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001522 struct mgcp_endpoint *endp;
1523 int endp_no, rc;
1524
Philipp Maier6fbbeec2020-07-01 23:00:54 +02001525 trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_E1, atoi(argv[0]));
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001526 if (!trunk) {
1527 vty_out(vty, "%%Trunk %d not found in the config.%s",
1528 atoi(argv[0]), VTY_NEWLINE);
1529 return CMD_WARNING;
1530 }
1531
1532 if (!trunk->endpoints) {
Philipp Maierd70eef62021-07-19 13:53:28 +02001533 vty_out(vty, "%%Trunk %u has no endpoints allocated.%s",
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001534 trunk->trunk_nr, VTY_NEWLINE);
1535 return CMD_WARNING;
1536 }
1537
1538 endp_no = strtoul(argv[1], NULL, 16);
1539 if (endp_no < 1 || endp_no >= trunk->number_endpoints) {
1540 vty_out(vty, "Endpoint number %s/%d is invalid.%s",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001541 argv[1], endp_no, VTY_NEWLINE);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001542 return CMD_WARNING;
1543 }
1544
Philipp Maierc66ab2c2020-06-02 20:55:34 +02001545 endp = trunk->endpoints[endp_no];
1546 rc = mgcp_send_reset_ep(endp);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001547 if (rc < 0) {
1548 vty_out(vty, "Error %d sending reset.%s", rc, VTY_NEWLINE);
1549 return CMD_WARNING;
1550 }
1551 return CMD_SUCCESS;
1552}
1553
1554DEFUN(reset_all_endp, reset_all_endp_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001555 "reset-all-endpoints", "Reset all endpoints\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001556{
1557 int rc;
1558
1559 rc = mgcp_send_reset_all(g_cfg);
1560 if (rc < 0) {
1561 vty_out(vty, "Error %d during endpoint reset.%s",
1562 rc, VTY_NEWLINE);
1563 return CMD_WARNING;
1564 }
1565 return CMD_SUCCESS;
1566}
1567
1568#define OSMUX_STR "RTP multiplexing\n"
1569DEFUN(cfg_mgcp_osmux,
1570 cfg_mgcp_osmux_cmd,
1571 "osmux (on|off|only)",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001572 OSMUX_STR "Enable OSMUX\n" "Disable OSMUX\n" "Only use OSMUX\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001573{
Philipp Maier6fbbeec2020-07-01 23:00:54 +02001574 struct mgcp_trunk *trunk = mgcp_trunk_by_num(g_cfg, MGCP_TRUNK_VIRTUAL, MGCP_VIRT_TRUNK_ID);
Philipp Maierd19de2e2020-06-03 13:55:33 +02001575 OSMO_ASSERT(trunk);
1576
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001577 if (strcmp(argv[0], "off") == 0) {
Pau Espin Pedrol928a20b2022-09-23 15:38:24 +02001578 g_cfg->osmux_use = OSMUX_USAGE_OFF;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001579 return CMD_SUCCESS;
Pau Espin Pedrolb542b042019-04-23 13:09:32 +02001580 } else if (strcmp(argv[0], "on") == 0)
Pau Espin Pedrol928a20b2022-09-23 15:38:24 +02001581 g_cfg->osmux_use = OSMUX_USAGE_ON;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001582 else if (strcmp(argv[0], "only") == 0)
Pau Espin Pedrol928a20b2022-09-23 15:38:24 +02001583 g_cfg->osmux_use = OSMUX_USAGE_ONLY;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001584
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001585 return CMD_SUCCESS;
Pau Espin Pedrolb542b042019-04-23 13:09:32 +02001586
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001587}
1588
1589DEFUN(cfg_mgcp_osmux_ip,
1590 cfg_mgcp_osmux_ip_cmd,
Pau Espin Pedrol70c03f52022-10-04 16:49:41 +02001591 "osmux bind-ip " VTY_IPV4_CMD,
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +02001592 OSMUX_STR IP_STR
Pau Espin Pedrol70c03f52022-10-04 16:49:41 +02001593 "IPv4 Address to bind to\n")
1594{
1595 osmo_talloc_replace_string(g_cfg, &g_cfg->osmux_addr_v4, argv[0]);
1596 return CMD_SUCCESS;
1597}
1598
1599DEFUN(cfg_mgcp_osmux_ip_v6,
1600 cfg_mgcp_osmux_ip_v6_cmd,
1601 "osmux bind-ip-v6 " VTY_IPV6_CMD,
1602 OSMUX_STR IP_STR
Pau Espin Pedrola790f0c2020-08-31 13:29:11 +02001603 "IPv6 Address to bind to\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001604{
Pau Espin Pedrol70c03f52022-10-04 16:49:41 +02001605 osmo_talloc_replace_string(g_cfg, &g_cfg->osmux_addr_v6, argv[0]);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001606 return CMD_SUCCESS;
1607}
1608
1609DEFUN(cfg_mgcp_osmux_batch_factor,
1610 cfg_mgcp_osmux_batch_factor_cmd,
1611 "osmux batch-factor <1-8>",
1612 OSMUX_STR "Batching factor\n" "Number of messages in the batch\n")
1613{
1614 g_cfg->osmux_batch = atoi(argv[0]);
1615 return CMD_SUCCESS;
1616}
1617
1618DEFUN(cfg_mgcp_osmux_batch_size,
1619 cfg_mgcp_osmux_batch_size_cmd,
1620 "osmux batch-size <1-65535>",
1621 OSMUX_STR "batch size\n" "Batch size in bytes\n")
1622{
1623 g_cfg->osmux_batch_size = atoi(argv[0]);
1624 return CMD_SUCCESS;
1625}
1626
1627DEFUN(cfg_mgcp_osmux_port,
1628 cfg_mgcp_osmux_port_cmd,
Philipp Maier87bd9be2017-08-22 16:35:41 +02001629 "osmux port <1-65535>", OSMUX_STR "port\n" "UDP port\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001630{
1631 g_cfg->osmux_port = atoi(argv[0]);
1632 return CMD_SUCCESS;
1633}
1634
1635DEFUN(cfg_mgcp_osmux_dummy,
1636 cfg_mgcp_osmux_dummy_cmd,
1637 "osmux dummy (on|off)",
Philipp Maier87bd9be2017-08-22 16:35:41 +02001638 OSMUX_STR "Dummy padding\n" "Enable dummy padding\n"
1639 "Disable dummy padding\n")
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001640{
1641 if (strcmp(argv[0], "on") == 0)
1642 g_cfg->osmux_dummy = 1;
1643 else if (strcmp(argv[0], "off") == 0)
1644 g_cfg->osmux_dummy = 0;
1645
1646 return CMD_SUCCESS;
1647}
1648
Philipp Maier12943ea2018-01-17 15:40:25 +01001649DEFUN(cfg_mgcp_domain,
1650 cfg_mgcp_domain_cmd,
Neels Hofmeyr352eed02018-08-20 23:59:32 +02001651 "domain NAME",
1652 "Set the domain part expected in MGCP messages' endpoint names\n"
1653 "Qualified domain name expected in MGCP endpoint names, or '*' to accept any domain\n")
Philipp Maier12943ea2018-01-17 15:40:25 +01001654{
1655 osmo_strlcpy(g_cfg->domain, argv[0], sizeof(g_cfg->domain));
1656 return CMD_SUCCESS;
1657}
1658
Oliver Smithe36b7752019-01-22 16:31:36 +01001659DEFUN(cfg_mgcp_conn_timeout,
1660 cfg_mgcp_conn_timeout_cmd,
Oliver Smithd2ce4442019-06-26 09:56:44 +02001661 "conn-timeout <0-65534>",
1662 "Set a time after which inactive connections (CIs) are closed. Set to 0 to disable timeout. This can be used to"
1663 " work around interoperability problems causing connections to stay open forever, and slowly exhausting all"
Oliver Smith189f29e2019-06-26 12:08:20 +02001664 " available ports. Enable keep-alive packets in MGW clients when using this option together with LCLS (OsmoBSC,"
1665 " OsmoMSC: 'rtp keep-alive')!\n"
Oliver Smithe36b7752019-01-22 16:31:36 +01001666 "Timeout value (sec.)\n")
1667{
1668 g_cfg->conn_timeout = strtoul(argv[0], NULL, 10);
1669 return CMD_SUCCESS;
1670}
1671
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001672int mgcp_vty_init(void)
1673{
1674 install_element_ve(&show_mgcp_cmd);
Keithfe53edd2021-05-04 15:23:30 -05001675 install_element_ve(&show_mgcp_active_cmd);
Stefan Sperling12086582018-06-26 15:26:28 +02001676 install_element_ve(&show_mgcp_endpoint_cmd);
1677 install_element_ve(&show_mgcp_trunk_endpoint_cmd);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001678 install_element(ENABLE_NODE, &loop_conn_cmd);
1679 install_element(ENABLE_NODE, &tap_rtp_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001680 install_element(ENABLE_NODE, &free_endp_cmd);
1681 install_element(ENABLE_NODE, &reset_endp_cmd);
1682 install_element(ENABLE_NODE, &reset_all_endp_cmd);
1683
1684 install_element(CONFIG_NODE, &cfg_mgcp_cmd);
1685 install_node(&mgcp_node, config_write_mgcp);
1686
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001687 install_element(MGCP_NODE, &cfg_mgcp_local_ip_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001688 install_element(MGCP_NODE, &cfg_mgcp_bind_ip_cmd);
1689 install_element(MGCP_NODE, &cfg_mgcp_bind_port_cmd);
1690 install_element(MGCP_NODE, &cfg_mgcp_bind_early_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001691 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_range_cmd);
Philipp Maierf1889d82017-11-08 14:59:39 +01001692 install_element(MGCP_NODE, &cfg_mgcp_rtp_port_range_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001693 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_bind_ip_cmd);
Philipp Maierf1889d82017-11-08 14:59:39 +01001694 install_element(MGCP_NODE, &cfg_mgcp_rtp_bind_ip_cmd);
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +02001695 install_element(MGCP_NODE, &cfg_mgcp_rtp_bind_ip_v6_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001696 install_element(MGCP_NODE, &cfg_mgcp_rtp_no_net_bind_ip_cmd);
Philipp Maierf1889d82017-11-08 14:59:39 +01001697 install_element(MGCP_NODE, &cfg_mgcp_rtp_no_bind_ip_cmd);
Pau Espin Pedrol8a2a1b22020-09-02 20:46:24 +02001698 install_element(MGCP_NODE, &cfg_mgcp_rtp_no_bind_ip_v6_cmd);
Philipp Maier1cb1e382017-11-02 17:16:04 +01001699 install_element(MGCP_NODE, &cfg_mgcp_rtp_net_bind_ip_probing_cmd);
1700 install_element(MGCP_NODE, &cfg_mgcp_rtp_no_net_bind_ip_probing_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001701 install_element(MGCP_NODE, &cfg_mgcp_rtp_ip_dscp_cmd);
Harald Welte55a92292021-04-28 19:06:34 +02001702 install_element(MGCP_NODE, &cfg_mgcp_rtp_priority_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001703 install_element(MGCP_NODE, &cfg_mgcp_rtp_force_ptime_cmd);
1704 install_element(MGCP_NODE, &cfg_mgcp_no_rtp_force_ptime_cmd);
1705 install_element(MGCP_NODE, &cfg_mgcp_rtp_keepalive_cmd);
1706 install_element(MGCP_NODE, &cfg_mgcp_rtp_keepalive_once_cmd);
1707 install_element(MGCP_NODE, &cfg_mgcp_no_rtp_keepalive_cmd);
1708 install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd);
1709 install_element(MGCP_NODE, &cfg_mgcp_agent_addr_cmd_old);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001710 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd);
1711 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd);
1712 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_number_cmd_old);
1713 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_name_cmd_old);
1714 install_element(MGCP_NODE, &cfg_mgcp_loop_cmd);
1715 install_element(MGCP_NODE, &cfg_mgcp_force_realloc_cmd);
Philipp Maier87bd9be2017-08-22 16:35:41 +02001716 install_element(MGCP_NODE, &cfg_mgcp_rtp_accept_all_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001717 install_element(MGCP_NODE, &cfg_mgcp_number_endp_cmd);
1718 install_element(MGCP_NODE, &cfg_mgcp_omit_rtcp_cmd);
1719 install_element(MGCP_NODE, &cfg_mgcp_no_omit_rtcp_cmd);
1720 install_element(MGCP_NODE, &cfg_mgcp_patch_rtp_ssrc_cmd);
1721 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_ssrc_cmd);
1722 install_element(MGCP_NODE, &cfg_mgcp_patch_rtp_ts_cmd);
1723 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_ts_cmd);
1724 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_cmd);
Philipp Maier9fc8a022019-02-20 12:26:52 +01001725 install_element(MGCP_NODE, &cfg_mgcp_patch_rtp_rfc5993hr_cmd);
1726 install_element(MGCP_NODE, &cfg_mgcp_no_patch_rtp_rfc5993hr_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001727 install_element(MGCP_NODE, &cfg_mgcp_sdp_fmtp_extra_cmd);
1728 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_send_ptime_cmd);
1729 install_element(MGCP_NODE, &cfg_mgcp_no_sdp_payload_send_ptime_cmd);
1730 install_element(MGCP_NODE, &cfg_mgcp_sdp_payload_send_name_cmd);
1731 install_element(MGCP_NODE, &cfg_mgcp_no_sdp_payload_send_name_cmd);
1732 install_element(MGCP_NODE, &cfg_mgcp_osmux_cmd);
1733 install_element(MGCP_NODE, &cfg_mgcp_osmux_ip_cmd);
Pau Espin Pedrol70c03f52022-10-04 16:49:41 +02001734 install_element(MGCP_NODE, &cfg_mgcp_osmux_ip_v6_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001735 install_element(MGCP_NODE, &cfg_mgcp_osmux_batch_factor_cmd);
1736 install_element(MGCP_NODE, &cfg_mgcp_osmux_batch_size_cmd);
1737 install_element(MGCP_NODE, &cfg_mgcp_osmux_port_cmd);
1738 install_element(MGCP_NODE, &cfg_mgcp_osmux_dummy_cmd);
1739 install_element(MGCP_NODE, &cfg_mgcp_allow_transcoding_cmd);
1740 install_element(MGCP_NODE, &cfg_mgcp_no_allow_transcoding_cmd);
Philipp Maier12943ea2018-01-17 15:40:25 +01001741 install_element(MGCP_NODE, &cfg_mgcp_domain_cmd);
Oliver Smithe36b7752019-01-22 16:31:36 +01001742 install_element(MGCP_NODE, &cfg_mgcp_conn_timeout_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001743
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001744 install_element(MGCP_NODE, &cfg_mgcp_trunk_cmd);
1745 install_node(&trunk_node, config_write_trunk);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001746 install_element(TRUNK_NODE, &cfg_trunk_rtp_keepalive_cmd);
1747 install_element(TRUNK_NODE, &cfg_trunk_rtp_keepalive_once_cmd);
1748 install_element(TRUNK_NODE, &cfg_trunk_no_rtp_keepalive_cmd);
1749 install_element(TRUNK_NODE, &cfg_trunk_payload_number_cmd);
1750 install_element(TRUNK_NODE, &cfg_trunk_payload_name_cmd);
1751 install_element(TRUNK_NODE, &cfg_trunk_payload_number_cmd_old);
1752 install_element(TRUNK_NODE, &cfg_trunk_payload_name_cmd_old);
1753 install_element(TRUNK_NODE, &cfg_trunk_loop_cmd);
Philipp Maier41425e92020-11-26 00:41:59 +01001754 install_element(TRUNK_NODE, &cfg_trunk_force_realloc_cmd);
1755 install_element(TRUNK_NODE, &cfg_trunk_rtp_accept_all_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001756 install_element(TRUNK_NODE, &cfg_trunk_omit_rtcp_cmd);
1757 install_element(TRUNK_NODE, &cfg_trunk_no_omit_rtcp_cmd);
1758 install_element(TRUNK_NODE, &cfg_trunk_patch_rtp_ssrc_cmd);
1759 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_ssrc_cmd);
1760 install_element(TRUNK_NODE, &cfg_trunk_patch_rtp_ts_cmd);
Philipp Maier9fc8a022019-02-20 12:26:52 +01001761 install_element(TRUNK_NODE, &cfg_trunk_patch_rtp_rfc5993hr_cmd);
1762 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_rfc5993hr_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001763 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_ts_cmd);
1764 install_element(TRUNK_NODE, &cfg_trunk_no_patch_rtp_cmd);
1765 install_element(TRUNK_NODE, &cfg_trunk_sdp_fmtp_extra_cmd);
1766 install_element(TRUNK_NODE, &cfg_trunk_sdp_payload_send_ptime_cmd);
1767 install_element(TRUNK_NODE, &cfg_trunk_no_sdp_payload_send_ptime_cmd);
1768 install_element(TRUNK_NODE, &cfg_trunk_sdp_payload_send_name_cmd);
1769 install_element(TRUNK_NODE, &cfg_trunk_no_sdp_payload_send_name_cmd);
1770 install_element(TRUNK_NODE, &cfg_trunk_allow_transcoding_cmd);
1771 install_element(TRUNK_NODE, &cfg_trunk_no_allow_transcoding_cmd);
Philipp Maier889fe7f2020-07-06 17:44:12 +02001772 install_element(TRUNK_NODE, &cfg_trunk_line_cmd);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001773
1774 return 0;
1775}
1776
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001777int mgcp_parse_config(const char *config_file, struct mgcp_config *cfg,
1778 enum mgcp_role role)
1779{
1780 int rc;
Philipp Maier14b27a82020-06-02 20:15:30 +02001781 struct mgcp_trunk *trunk;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001782
Pau Espin Pedrol5892b2e2022-08-11 19:21:45 +02001783 cfg->osmux_port = OSMUX_DEFAULT_PORT;
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001784 cfg->osmux_batch = 4;
1785 cfg->osmux_batch_size = OSMUX_BATCH_DEFAULT_MAX;
1786
1787 g_cfg = cfg;
1788 rc = vty_read_config_file(config_file, NULL);
1789 if (rc < 0) {
Philipp Maier87bd9be2017-08-22 16:35:41 +02001790 fprintf(stderr, "Failed to parse the config file: '%s'\n",
1791 config_file);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001792 return rc;
1793 }
1794
Eric2764bdb2021-08-23 22:11:47 +02001795 if (!strlen(g_cfg->source_addr)) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001796 fprintf(stderr, "You need to specify a bind address.\n");
1797 return -1;
1798 }
1799
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001800 llist_for_each_entry(trunk, &g_cfg->trunks, entry) {
Philipp Maier889fe7f2020-07-06 17:44:12 +02001801 if (mgcp_trunk_equip(trunk) != 0) {
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001802 LOGP(DLMGCP, LOGL_ERROR,
Philipp Maierd70eef62021-07-19 13:53:28 +02001803 "Failed to initialize trunk %u (%d endpoints)\n",
Philipp Maier48454982017-11-10 16:46:41 +01001804 trunk->trunk_nr, trunk->number_endpoints);
Neels Hofmeyrf83ec562017-09-07 19:18:40 +02001805 return -1;
1806 }
1807 }
1808 cfg->role = role;
1809
1810 return 0;
1811}