blob: 48fcd701830c2a7182af9027a0b01cdfd0c7b913 [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
Harald Welte220f4872018-02-04 09:04:16 +01009 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
Neels Hofmeyre9920f22017-07-10 15:07:22 +020011 * (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
Harald Welte220f4872018-02-04 09:04:16 +010016 * GNU General Public License for more details.
Neels Hofmeyre9920f22017-07-10 15:07:22 +020017 *
Harald Welte220f4872018-02-04 09:04:16 +010018 * You should have received a copy of the GNU General Public License
Neels Hofmeyre9920f22017-07-10 15:07:22 +020019 * 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>
Stefan Sperling29248252018-02-22 18:09:28 +010028#include <osmocom/vty/misc.h>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020029#include <osmocom/core/utils.h>
30
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020031#include <osmocom/mgcp_client/mgcp_client.h>
Neels Hofmeyre9920f22017-07-10 15:07:22 +020032
Neels Hofmeyre6d8e912018-08-23 16:36:48 +020033#define MGW_STR MGCP_CLIENT_MGW_STR
Neels Hofmeyre9920f22017-07-10 15:07:22 +020034
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020035void *global_mgcp_client_ctx = NULL;
36struct mgcp_client_conf *global_mgcp_client_conf = NULL;
Neels Hofmeyre9920f22017-07-10 15:07:22 +020037
Neels Hofmeyr87203f22017-10-31 01:15:45 +010038DEFUN(cfg_mgw_local_ip, cfg_mgw_local_ip_cmd,
39 "mgw local-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010040 MGW_STR "local bind to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020041 "local bind IP address\n")
42{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020043 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020044 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020045 OSMO_ASSERT(global_mgcp_client_ctx);
46 global_mgcp_client_conf->local_addr =
47 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020048 return CMD_SUCCESS;
49}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010050ALIAS_DEPRECATED(cfg_mgw_local_ip, cfg_mgcpgw_local_ip_cmd,
51 "mgcpgw local-ip A.B.C.D",
52 MGW_STR "local bind to connect to MGCP gateway with\n"
53 "local bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020054
Neels Hofmeyr87203f22017-10-31 01:15:45 +010055DEFUN(cfg_mgw_local_port, cfg_mgw_local_port_cmd,
56 "mgw local-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010057 MGW_STR "local port to connect to MGW from\n"
Neels Hofmeyre9920f22017-07-10 15:07:22 +020058 "local bind port\n")
59{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020060 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020061 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020062 global_mgcp_client_conf->local_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020063 return CMD_SUCCESS;
64}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010065ALIAS_DEPRECATED(cfg_mgw_local_port, cfg_mgcpgw_local_port_cmd,
66 "mgcpgw local-port <0-65535>",
67 MGW_STR "local bind to connect to MGCP gateway with\n"
68 "local bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020069
Neels Hofmeyr87203f22017-10-31 01:15:45 +010070DEFUN(cfg_mgw_remote_ip, cfg_mgw_remote_ip_cmd,
71 "mgw remote-ip A.B.C.D",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010072 MGW_STR "remote IP address to reach the MGW at\n"
73 "remote IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020074{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020075 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020076 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020077 OSMO_ASSERT(global_mgcp_client_ctx);
78 global_mgcp_client_conf->remote_addr =
79 talloc_strdup(global_mgcp_client_ctx, argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020080 return CMD_SUCCESS;
81}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010082ALIAS_DEPRECATED(cfg_mgw_remote_ip, cfg_mgcpgw_remote_ip_cmd,
83 "mgcpgw remote-ip A.B.C.D",
84 MGW_STR "remote bind to connect to MGCP gateway with\n"
85 "remote bind IP address\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020086
Neels Hofmeyr87203f22017-10-31 01:15:45 +010087DEFUN(cfg_mgw_remote_port, cfg_mgw_remote_port_cmd,
88 "mgw remote-port <0-65535>",
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +010089 MGW_STR "remote port to reach the MGW at\n"
90 "remote port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +020091{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020092 if (!global_mgcp_client_conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +020093 return CMD_ERR_NOTHING_TODO;
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +020094 global_mgcp_client_conf->remote_port = atoi(argv[0]);
Neels Hofmeyre9920f22017-07-10 15:07:22 +020095 return CMD_SUCCESS;
96}
Neels Hofmeyr87203f22017-10-31 01:15:45 +010097ALIAS_DEPRECATED(cfg_mgw_remote_port, cfg_mgcpgw_remote_port_cmd,
98 "mgcpgw remote-port <0-65535>",
99 MGW_STR "remote bind to connect to MGCP gateway with\n"
100 "remote bind port\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200101
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100102DEFUN(cfg_mgw_endpoint_range, cfg_mgw_endpoint_range_cmd,
103 "mgw endpoint-range <1-65534> <1-65534>",
104 MGW_STR "usable range of endpoint identifiers\n"
Neels Hofmeyr54dd4b32017-10-31 01:18:33 +0100105 "set first usable endpoint identifier\n"
106 "set last usable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200107{
108 uint16_t first_endpoint = atoi(argv[0]);
109 uint16_t last_endpoint = atoi(argv[1]);
110
111 if (last_endpoint < first_endpoint) {
112 vty_out(vty, "last endpoint must be greater than first endpoint!%s",
113 VTY_NEWLINE);
114 return CMD_SUCCESS;
115 }
116
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200117 global_mgcp_client_conf->first_endpoint = first_endpoint;
118 global_mgcp_client_conf->last_endpoint = last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200119 return CMD_SUCCESS;
120}
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100121ALIAS_DEPRECATED(cfg_mgw_endpoint_range, cfg_mgcpgw_endpoint_range_cmd,
122 "mgcpgw endpoint-range <1-65534> <1-65534>",
123 MGW_STR "usable range of endpoint identifiers\n"
124 "set first useable endpoint identifier\n"
125 "set the last useable endpoint identifier\n")
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200126
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000127#define BTS_START_STR "First UDP port allocated for the BTS side\n"
128#define UDP_PORT_STR "UDP Port number\n"
129DEFUN(cfg_mgw_rtp_bts_base_port,
130 cfg_mgw_rtp_bts_base_port_cmd,
131 "mgw bts-base <0-65534>",
132 MGW_STR
133 BTS_START_STR
134 UDP_PORT_STR)
135{
136 global_mgcp_client_conf->bts_base = atoi(argv[0]);
137 return CMD_SUCCESS;
138}
139ALIAS_DEPRECATED(cfg_mgw_rtp_bts_base_port,
140 cfg_mgcpgw_rtp_bts_base_port_cmd,
141 "mgcpgw bts-base <0-65534>",
142 MGW_STR
143 BTS_START_STR
144 UDP_PORT_STR)
145
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200146int mgcp_client_config_write(struct vty *vty, const char *indent)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200147{
148 const char *addr;
149 int port;
150 uint16_t first_endpoint;
151 uint16_t last_endpoint;
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000152 uint16_t bts_base;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200153
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200154 addr = global_mgcp_client_conf->local_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200155 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100156 vty_out(vty, "%smgw local-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200157 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200158 port = global_mgcp_client_conf->local_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200159 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100160 vty_out(vty, "%smgw local-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200161 (uint16_t)port, VTY_NEWLINE);
162
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200163 addr = global_mgcp_client_conf->remote_addr;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200164 if (addr)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100165 vty_out(vty, "%smgw remote-ip %s%s", indent, addr,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200166 VTY_NEWLINE);
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200167 port = global_mgcp_client_conf->remote_port;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200168 if (port >= 0)
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100169 vty_out(vty, "%smgw remote-port %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200170 (uint16_t)port, VTY_NEWLINE);
171
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200172 first_endpoint = global_mgcp_client_conf->first_endpoint;
173 last_endpoint = global_mgcp_client_conf->last_endpoint;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200174 if (last_endpoint != 0) {
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100175 vty_out(vty, "%smgw endpoint-range %u %u%s", indent,
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200176 first_endpoint, last_endpoint, VTY_NEWLINE);
177 }
178
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000179 bts_base = global_mgcp_client_conf->bts_base;
180 if (bts_base) {
181 vty_out(vty, "%smgw bts-base %u%s", indent,
182 bts_base, VTY_NEWLINE);
183 }
184
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200185 return CMD_SUCCESS;
186}
187
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200188void mgcp_client_vty_init(void *talloc_ctx, int node, struct mgcp_client_conf *conf)
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200189{
Neels Hofmeyr3a8e7232017-09-04 01:02:56 +0200190 global_mgcp_client_ctx = talloc_ctx;
191 global_mgcp_client_conf = conf;
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200192
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100193 install_element(node, &cfg_mgw_local_ip_cmd);
194 install_element(node, &cfg_mgw_local_port_cmd);
195 install_element(node, &cfg_mgw_remote_ip_cmd);
196 install_element(node, &cfg_mgw_remote_port_cmd);
197 install_element(node, &cfg_mgw_endpoint_range_cmd);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000198 install_element(node, &cfg_mgw_rtp_bts_base_port_cmd);
Neels Hofmeyr87203f22017-10-31 01:15:45 +0100199
200 /* deprecated 'mgcpgw' commands */
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200201 install_element(node, &cfg_mgcpgw_local_ip_cmd);
202 install_element(node, &cfg_mgcpgw_local_port_cmd);
203 install_element(node, &cfg_mgcpgw_remote_ip_cmd);
204 install_element(node, &cfg_mgcpgw_remote_port_cmd);
205 install_element(node, &cfg_mgcpgw_endpoint_range_cmd);
Neels Hofmeyrc0dcc3c2017-12-02 18:31:34 +0000206 install_element(node, &cfg_mgcpgw_rtp_bts_base_port_cmd);
Stefan Sperling29248252018-02-22 18:09:28 +0100207
208 osmo_fsm_vty_add_cmds();
Neels Hofmeyre9920f22017-07-10 15:07:22 +0200209}