blob: f8129c06303e2a1f413cee0e89bad11d3624998c [file] [log] [blame]
Neels Hofmeyr87203f22017-10-31 01:15:45 +01001/* MGCP client interface to quagga VTY */
Neels Hofmeyre9920f22017-07-10 15:07:22 +02002/* (C) 2016 by sysmocom s.m.f.c. GmbH <info@sysmocom.de>
3 * Based on OpenBSC interface to quagga VTY (libmsc/vty_interface_layer3.c)
4 * (C) 2009 by Harald Welte <laforge@gnumonks.org>
5 * (C) 2009-2011 by Holger Hans Peter Freyther
6 * All Rights Reserved
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU Affero General Public License as published by
10 * the Free Software Foundation; either version 3 of the License, or
11 * (at your option) any later version.
12 *
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Affero General Public License for more details.
17 *
18 * You should have received a copy of the GNU Affero General Public License
19 * along with this program. If not, see <http://www.gnu.org/licenses/>.
20 *
21 */
22
23#include <inttypes.h>
24#include <stdlib.h>
25#include <talloc.h>
26
27#include <osmocom/vty/command.h>
28#include <osmocom/core/utils.h>
29
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020030#include <osmocom/mgcp_client/mgcp_client.h>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020031
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010032#define MGW_STR "Configure MGCP connection to Media Gateway\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020033
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020034void *global_mgcp_client_ctx = NULL;
35struct mgcp_client_conf *global_mgcp_client_conf = NULL;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020036
Neels Hofmeyr87203f22017-10-31 01:15:45 +010037DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd,
38 "mgw local-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010039 MGW_STR "local bind to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020040 "local bind IP address\n")
41{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020042 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020043 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020044 OSMO_ASSERT(global_mgcp_client_ctx);
45 global_mgcp_client_conf->local_addr =
46 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020047 return CMD_SUCCESS;
48}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010049ALIAS_DEPRECATED(cfg_mgw_local_ip, cfg_mgcpgw_local_ip_cmd,
50 "mgcpgw local-ip A.B.C.D",
51 MGW_STR "local bind to connect to MGCP gateway with\n"
52 "local bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020053
Neels Hofmeyr87203f22017-10-31 01:15:45 +010054DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd,
55 "mgw local-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010056 MGW_STR "local port to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020057 "local bind port\n")
58{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020059 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020060 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020061 global_mgcp_client_conf->local_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020062 return CMD_SUCCESS;
63}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010064ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd,
65 "mgcpgw local-port <0-65535>",
66 MGW_STR "local bind to connect to MGCP gateway with\n"
67 "local bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020068
Neels Hofmeyr87203f22017-10-31 01:15:45 +010069DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd,
70 "mgw remote-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010071 MGW_STR "remote IP address to reach the MGW at\n"
72 "remote IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020073{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020074 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020075 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020076 OSMO_ASSERT(global_mgcp_client_ctx);
77 global_mgcp_client_conf->remote_addr =
78 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020079 return CMD_SUCCESS;
80}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010081ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd,
82 "mgcpgw remote-ip A.B.C.D",
83 MGW_STR "remote bind to connect to MGCP gateway with\n"
84 "remote bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020085
Neels Hofmeyr87203f22017-10-31 01:15:45 +010086DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd,
87 "mgw remote-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010088 MGW_STR "remote port to reach the MGW at\n"
89 "remote port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020090{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020091 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020092 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020093 global_mgcp_client_conf->remote_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020094 return CMD_SUCCESS;
95}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010096ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd,
97 "mgcpgw remote-port <0-65535>",
98 MGW_STR "remote bind to connect to MGCP gateway with\n"
99 "remote bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200100
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100101DEFUN(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd,
102 "mgw endpoint-range <1-65534> <1-65534>",
103 MGW_STR "usable range of endpoint identifiers\n"
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +0100104 "set first usable endpoint identifier\n"
105 "set last usable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200106{
107 uint16_t first_endpoint = atoi(argv[0]);
108 uint16_t last_endpoint = atoi(argv[1]);
109
110 if (last_endpoint < first_endpoint) {
111 vty_out(vty, "last endpoint must be greater than first endpoint!%s",
112 VTY_NEWLINE);
113 return CMD_SUCCESS;
114 }
115
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200116 global_mgcp_client_conf->first_endpoint = first_endpoint;
117 global_mgcp_client_conf->last_endpoint = last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200118 return CMD_SUCCESS;
119}
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100120ALIAS_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd,
121 "mgcpgw endpoint-range <1-65534> <1-65534>",
122 MGW_STR "usable range of endpoint identifiers\n"
123 "set first useable endpoint identifier\n"
124 "set the last useable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200125
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000126#define BTS_START_STR "First UDP port allocated for the BTS side\n"
127#define UDP_PORT_STR "UDP Port number\n"
128DEFUN(cfg_mgw_rtp_bts_base_port,
129 cfg_mgw_rtp_bts_base_port_cmd,
130 "mgw bts-base <0-65534>",
131 MGW_STR
132 BTS_START_STR
133 UDP_PORT_STR)
134{
135 global_mgcp_client_conf->bts_base = atoi(argv[0]);
136 return CMD_SUCCESS;
137}
138ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port,
139 cfg_mgcpgw_rtp_bts_base_port_cmd,
140 "mgcpgw bts-base <0-65534>",
141 MGW_STR
142 BTS_START_STR
143 UDP_PORT_STR)
144
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200145int mgcp_client_config_write(struct vty *vty, const char *indent)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200146{
147 const char *addr;
148 int port;
149 uint16_t first_endpoint;
150 uint16_t last_endpoint;
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000151 uint16_t bts_base;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200152
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200153 addr = global_mgcp_client_conf->local_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200154 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100155 vty_out(vty, "%smgw local-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200156 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200157 port = global_mgcp_client_conf->local_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200158 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100159 vty_out(vty, "%smgw local-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200160 (uint16_t)port, VTY_NEWLINE);
161
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200162 addr = global_mgcp_client_conf->remote_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200163 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100164 vty_out(vty, "%smgw remote-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200165 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200166 port = global_mgcp_client_conf->remote_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200167 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100168 vty_out(vty, "%smgw remote-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200169 (uint16_t)port, VTY_NEWLINE);
170
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200171 first_endpoint = global_mgcp_client_conf->first_endpoint;
172 last_endpoint = global_mgcp_client_conf->last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200173 if (last_endpoint != 0) {
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100174 vty_out(vty, "%smgw endpoint-range %u %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200175 first_endpoint, last_endpoint, VTY_NEWLINE);
176 }
177
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000178 bts_base = global_mgcp_client_conf->bts_base;
179 if (bts_base) {
180 vty_out(vty, "%smgw bts-base %u%s", indent,
181 bts_base, VTY_NEWLINE);
182 }
183
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200184 return CMD_SUCCESS;
185}
186
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200187void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200188{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200189 global_mgcp_client_ctx = talloc_ctx;
190 global_mgcp_client_conf = conf;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200191
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100192 install_element(node, &cfg_mgw_local_ip_cmd);
193 install_element(node, &cfg_mgw_local_port_cmd);
194 install_element(node, &cfg_mgw_remote_ip_cmd);
195 install_element(node, &cfg_mgw_remote_port_cmd);
196 install_element(node, &cfg_mgw_endpoint_range_cmd);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000197 install_element(node, &cfg_mgw_rtp_bts_base_port_cmd);
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100198
199 /* deprecated 'mgcpgw' commands */
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200200 install_element(node, &cfg_mgcpgw_local_ip_cmd);
201 install_element(node, &cfg_mgcpgw_local_port_cmd);
202 install_element(node, &cfg_mgcpgw_remote_ip_cmd);
203 install_element(node, &cfg_mgcpgw_remote_port_cmd);
204 install_element(node, &cfg_mgcpgw_endpoint_range_cmd);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000205 install_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd);
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200206}