blob: e1cf97e87eb07e8e46657130e128146163f705e9 [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 Welte799e0c92010-04-30 21:49:24 +020032
33#include <vty/command.h>
34#include <vty/vty.h>
35
Harald Welte799e0c92010-04-30 21:49:24 +020036static struct gbproxy_config *g_cfg = NULL;
37
38/*
39 * vty code for mgcp below
40 */
Harald Welteb77c6972010-05-01 11:28:43 +020041static struct cmd_node gbproxy_node = {
Harald Welte799e0c92010-04-30 21:49:24 +020042 GBPROXY_NODE,
43 "%s(gbproxy)#",
44 1,
45};
46
47static int config_write_gbproxy(struct vty *vty)
48{
49 struct in_addr ia;
50
51 vty_out(vty, "gbproxy%s", VTY_NEWLINE);
52
53 if (g_cfg->nsip_listen_ip) {
54 ia.s_addr = htonl(g_cfg->nsip_listen_ip);
Harald Welted9c69cc2010-05-12 15:57:38 +000055 vty_out(vty, " nsip bss local ip %s%s", inet_ntoa(ia),
Harald Welte799e0c92010-04-30 21:49:24 +020056 VTY_NEWLINE);
57 }
Harald Welted9c69cc2010-05-12 15:57:38 +000058 vty_out(vty, " nsip bss local port %u%s", g_cfg->nsip_listen_port,
Harald Welte799e0c92010-04-30 21:49:24 +020059 VTY_NEWLINE);
60 ia.s_addr = htonl(g_cfg->nsip_sgsn_ip);
Harald Welted9c69cc2010-05-12 15:57:38 +000061 vty_out(vty, " nsip sgsn remote ip %s%s", inet_ntoa(ia),
Harald Welte799e0c92010-04-30 21:49:24 +020062 VTY_NEWLINE);
Harald Welted9c69cc2010-05-12 15:57:38 +000063 vty_out(vty, " nsip sgsn remote port %u%s", g_cfg->nsip_sgsn_port,
Harald Welte799e0c92010-04-30 21:49:24 +020064 VTY_NEWLINE);
Harald Welted9c69cc2010-05-12 15:57:38 +000065 vty_out(vty, " nsip sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
Harald Welte799e0c92010-04-30 21:49:24 +020066 VTY_NEWLINE);
Harald Welted9c69cc2010-05-12 15:57:38 +000067 vty_out(vty, " nsip sgsn nsvci %u%s", g_cfg->nsip_sgsn_nsvci,
Harald Welte799e0c92010-04-30 21:49:24 +020068 VTY_NEWLINE);
69
70 return CMD_SUCCESS;
71}
72
Harald Welte799e0c92010-04-30 21:49:24 +020073DEFUN(cfg_gbproxy,
74 cfg_gbproxy_cmd,
75 "gbproxy",
76 "Configure the Gb proxy")
77{
78 vty->node = GBPROXY_NODE;
79 return CMD_SUCCESS;
80}
81
82DEFUN(cfg_nsip_bss_local_ip,
83 cfg_nsip_bss_local_ip_cmd,
84 "nsip bss local ip A.B.C.D",
85 "Set the IP address on which we listen for BSS connects")
86{
87 struct in_addr ia;
88
89 inet_aton(argv[0], &ia);
90 g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
91
92 return CMD_SUCCESS;
93}
94
95DEFUN(cfg_nsip_bss_local_port,
96 cfg_nsip_bss_local_port_cmd,
97 "nsip bss local port <0-65534>",
98 "Set the UDP port on which we listen for BSS connects")
99{
100 unsigned int port = atoi(argv[0]);
101
102 g_cfg->nsip_listen_port = port;
103 return CMD_SUCCESS;
104}
105
106
107DEFUN(cfg_nsip_sgsn_ip,
108 cfg_nsip_sgsn_ip_cmd,
109 "nsip sgsn remote ip A.B.C.D",
110 "Set the IP of the SGSN to which the proxy shall connect")
111{
112 struct in_addr ia;
113
114 inet_aton(argv[0], &ia);
115 g_cfg->nsip_sgsn_ip = ntohl(ia.s_addr);
116
117 return CMD_SUCCESS;
118}
119
120DEFUN(cfg_nsip_sgsn_port,
121 cfg_nsip_sgsn_port_cmd,
122 "nsip sgsn remote port <0-65534>",
123 "Set the UDP port of the SGSN to which the proxy shall connect")
124{
125 unsigned int port = atoi(argv[0]);
126
127 g_cfg->nsip_sgsn_port = port;
128 return CMD_SUCCESS;
129}
130
131DEFUN(cfg_nsip_sgsn_nsei,
132 cfg_nsip_sgsn_nsei_cmd,
133 "nsip sgsn nsei <0-65534>",
134 "Set the NSEI to be used in the connection with the SGSN")
135{
136 unsigned int port = atoi(argv[0]);
137
138 g_cfg->nsip_sgsn_nsei = port;
139 return CMD_SUCCESS;
140}
141
142DEFUN(cfg_nsip_sgsn_nsvci,
143 cfg_nsip_sgsn_nsvci_cmd,
144 "nsip sgsn nsvci <0-65534>",
145 "Set the NSVCI to be used in the connection with the SGSN")
146{
147 unsigned int port = atoi(argv[0]);
148
149 g_cfg->nsip_sgsn_nsvci = port;
150 return CMD_SUCCESS;
151}
152
Harald Welte799e0c92010-04-30 21:49:24 +0200153int gbproxy_vty_init(void)
154{
Harald Welte995a2d32010-05-12 16:50:52 +0000155 install_element_ve(&show_gbproxy_cmd);
Harald Welte799e0c92010-04-30 21:49:24 +0200156
157 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
158 install_node(&gbproxy_node, config_write_gbproxy);
159 install_default(GBPROXY_NODE);
160 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_ip_cmd);
161 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_port_cmd);
162 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_ip_cmd);
163 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_port_cmd);
164 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
165 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsvci_cmd);
166
167 return 0;
168}
169
170int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
171{
172 int rc;
173
174 g_cfg = cfg;
175 rc = vty_read_config_file(config_file);
176 if (rc < 0) {
177 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
178 return rc;
179 }
180
181 return 0;
182}
183