blob: 09395ed6bfdb49aa5c9f6776c2a6ff6870405bf1 [file] [log] [blame]
Harald Welte799e0c92010-04-30 21:49:24 +02001/*
2 * (C) 2010 by Harald Welte <laforge@gnumonks.org>
3 * (C) 2010 by On-Waves
4 * All Rights Reserved
5 *
6 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01007 * it under the terms of the GNU Affero General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
Harald Welte799e0c92010-04-30 21:49:24 +02009 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010014 * GNU Affero General Public License for more details.
Harald Welte799e0c92010-04-30 21:49:24 +020015 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010016 * You should have received a copy of the GNU Affero General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte799e0c92010-04-30 21:49:24 +020018 *
19 */
20
Harald Welte799e0c92010-04-30 21:49:24 +020021#include <sys/socket.h>
22#include <netinet/in.h>
23#include <arpa/inet.h>
24
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010025#include <osmocom/core/talloc.h>
Harald Welte799e0c92010-04-30 21:49:24 +020026
27#include <openbsc/debug.h>
Harald Welteb77c6972010-05-01 11:28:43 +020028#include <openbsc/gb_proxy.h>
29#include <openbsc/gprs_ns.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020030#include <openbsc/vty.h>
Harald Welte799e0c92010-04-30 21:49:24 +020031
Harald Welte4b037e42010-05-19 19:45:32 +020032#include <osmocom/vty/command.h>
33#include <osmocom/vty/vty.h>
Harald Welte799e0c92010-04-30 21:49:24 +020034
Harald Welte799e0c92010-04-30 21:49:24 +020035static struct gbproxy_config *g_cfg = NULL;
36
37/*
38 * vty code for mgcp below
39 */
Harald Welteb77c6972010-05-01 11:28:43 +020040static struct cmd_node gbproxy_node = {
Harald Welte799e0c92010-04-30 21:49:24 +020041 GBPROXY_NODE,
42 "%s(gbproxy)#",
43 1,
44};
45
46static int config_write_gbproxy(struct vty *vty)
47{
Harald Welte799e0c92010-04-30 21:49:24 +020048 vty_out(vty, "gbproxy%s", VTY_NEWLINE);
49
Harald Welteff3bde82010-05-19 15:09:09 +020050 vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
Harald Welte799e0c92010-04-30 21:49:24 +020051 VTY_NEWLINE);
Harald Welte799e0c92010-04-30 21:49:24 +020052
53 return CMD_SUCCESS;
54}
55
Harald Welte799e0c92010-04-30 21:49:24 +020056DEFUN(cfg_gbproxy,
57 cfg_gbproxy_cmd,
58 "gbproxy",
59 "Configure the Gb proxy")
60{
61 vty->node = GBPROXY_NODE;
62 return CMD_SUCCESS;
63}
64
Harald Welte799e0c92010-04-30 21:49:24 +020065DEFUN(cfg_nsip_sgsn_nsei,
66 cfg_nsip_sgsn_nsei_cmd,
Harald Welteff3bde82010-05-19 15:09:09 +020067 "sgsn nsei <0-65534>",
Holger Hans Peter Freyther2eb6e2c2011-11-05 15:14:59 +010068 "SGSN information\n"
69 "NSEI to be used in the connection with the SGSN\n"
70 "The NSEI\n")
Harald Welte799e0c92010-04-30 21:49:24 +020071{
72 unsigned int port = atoi(argv[0]);
73
74 g_cfg->nsip_sgsn_nsei = port;
75 return CMD_SUCCESS;
76}
77
Harald Welte799e0c92010-04-30 21:49:24 +020078int gbproxy_vty_init(void)
79{
Harald Welte995a2d32010-05-12 16:50:52 +000080 install_element_ve(&show_gbproxy_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +020081
82 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
83 install_node(&gbproxy_node, config_write_gbproxy);
84 install_default(GBPROXY_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +020085 install_element(GBPROXY_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +020086 install_element(GBPROXY_NODE, &ournode_end_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +020087 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +020088
89 return 0;
90}
91
92int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
93{
94 int rc;
95
96 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +020097 rc = vty_read_config_file(config_file, NULL);
Harald Welte799e0c92010-04-30 21:49:24 +020098 if (rc < 0) {
99 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
100 return rc;
101 }
102
103 return 0;
104}
105