blob: e76172058f58a7e38cd6f4bb319913a1d6be312d [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
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (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
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License along
17 * with this program; if not, write to the Free Software Foundation, Inc.,
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
19 *
20 */
21
22#include <sys/types.h>
23#include <sys/socket.h>
24#include <netinet/in.h>
25#include <arpa/inet.h>
26
27#include <osmocore/talloc.h>
28
29#include <openbsc/debug.h>
Harald Welteb77c6972010-05-01 11:28:43 +020030#include <openbsc/gb_proxy.h>
31#include <openbsc/gprs_ns.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020032#include <openbsc/vty.h>
Harald Welte799e0c92010-04-30 21:49:24 +020033
34#include <vty/command.h>
35#include <vty/vty.h>
36
Harald Welte799e0c92010-04-30 21:49:24 +020037static struct gbproxy_config *g_cfg = NULL;
38
39/*
40 * vty code for mgcp below
41 */
Harald Welteb77c6972010-05-01 11:28:43 +020042static struct cmd_node gbproxy_node = {
Harald Welte799e0c92010-04-30 21:49:24 +020043 GBPROXY_NODE,
44 "%s(gbproxy)#",
45 1,
46};
47
48static int config_write_gbproxy(struct vty *vty)
49{
50 struct in_addr ia;
51
52 vty_out(vty, "gbproxy%s", VTY_NEWLINE);
53
Harald Welteff3bde82010-05-19 15:09:09 +020054 vty_out(vty, " sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
Harald Welte799e0c92010-04-30 21:49:24 +020055 VTY_NEWLINE);
Harald Welte799e0c92010-04-30 21:49:24 +020056
57 return CMD_SUCCESS;
58}
59
Harald Welte799e0c92010-04-30 21:49:24 +020060DEFUN(cfg_gbproxy,
61 cfg_gbproxy_cmd,
62 "gbproxy",
63 "Configure the Gb proxy")
64{
65 vty->node = GBPROXY_NODE;
66 return CMD_SUCCESS;
67}
68
Harald Welte799e0c92010-04-30 21:49:24 +020069DEFUN(cfg_nsip_sgsn_nsei,
70 cfg_nsip_sgsn_nsei_cmd,
Harald Welteff3bde82010-05-19 15:09:09 +020071 "sgsn nsei <0-65534>",
Harald Welte799e0c92010-04-30 21:49:24 +020072 "Set the NSEI to be used in the connection with the SGSN")
73{
74 unsigned int port = atoi(argv[0]);
75
76 g_cfg->nsip_sgsn_nsei = port;
77 return CMD_SUCCESS;
78}
79
Harald Welte799e0c92010-04-30 21:49:24 +020080int gbproxy_vty_init(void)
81{
Harald Welte995a2d32010-05-12 16:50:52 +000082 install_element_ve(&show_gbproxy_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +020083
84 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
85 install_node(&gbproxy_node, config_write_gbproxy);
86 install_default(GBPROXY_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +020087 install_element(GBPROXY_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +020088 install_element(GBPROXY_NODE, &ournode_end_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +020089 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +020090
91 return 0;
92}
93
94int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
95{
96 int rc;
97
98 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +020099 rc = vty_read_config_file(config_file, NULL);
Harald Welte799e0c92010-04-30 21:49:24 +0200100 if (rc < 0) {
101 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
102 return rc;
103 }
104
105 return 0;
106}
107