blob: ae6be5e4bd5b3355c074c8270adfe43e26d89f22 [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>
30
31#include <vty/command.h>
32#include <vty/vty.h>
33
34struct gbproxy_config {
35 u_int32_t nsip_listen_ip;
36 u_int16_t nsip_listen_port;
37
38 u_int32_t nsip_sgsn_ip;
39 u_int16_t nsip_sgsn_port;
40
41 u_int16_t nsip_sgsn_nsei;
42 u_int16_t nsip_sgsn_nsvci;
43};
44
45static struct gbproxy_config *g_cfg = NULL;
46
47/*
48 * vty code for mgcp below
49 */
50struct cmd_node gbproxy_node = {
51 GBPROXY_NODE,
52 "%s(gbproxy)#",
53 1,
54};
55
56static int config_write_gbproxy(struct vty *vty)
57{
58 struct in_addr ia;
59
60 vty_out(vty, "gbproxy%s", VTY_NEWLINE);
61
62 if (g_cfg->nsip_listen_ip) {
63 ia.s_addr = htonl(g_cfg->nsip_listen_ip);
64 vty_out(vty, " nsip bss local ip %s%s", inet_ntoa(ia),
65 VTY_NEWLINE);
66 }
67 vty_out(vty, " nsip bss local port %u%s", g_cfg->nsip_listen_port,
68 VTY_NEWLINE);
69 ia.s_addr = htonl(g_cfg->nsip_sgsn_ip);
70 vty_out(vty, " nsip sgsn remote ip %s%s", inet_ntoa(ia),
71 VTY_NEWLINE);
72 vty_out(vty, " nsip sgsn remote port %u%s", g_cfg->nsip_sgsn_port,
73 VTY_NEWLINE);
74 vty_out(vty, " nsip sgsn nsei %u%s", g_cfg->nsip_sgsn_nsei,
75 VTY_NEWLINE);
76 vty_out(vty, " nsip sgsn nsvci %u%s", g_cfg->nsip_sgsn_nsvci,
77 VTY_NEWLINE);
78
79 return CMD_SUCCESS;
80}
81
82DEFUN(show_gbproxy, show_gbproxy_cmd, "show gbproxy",
83 SHOW_STR "Display information about the Gb proxy")
84{
85 /* FIXME: iterate over list of NS-VC's and display their state */
86
87 return CMD_SUCCESS;
88}
89
90DEFUN(cfg_gbproxy,
91 cfg_gbproxy_cmd,
92 "gbproxy",
93 "Configure the Gb proxy")
94{
95 vty->node = GBPROXY_NODE;
96 return CMD_SUCCESS;
97}
98
99DEFUN(cfg_nsip_bss_local_ip,
100 cfg_nsip_bss_local_ip_cmd,
101 "nsip bss local ip A.B.C.D",
102 "Set the IP address on which we listen for BSS connects")
103{
104 struct in_addr ia;
105
106 inet_aton(argv[0], &ia);
107 g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
108
109 return CMD_SUCCESS;
110}
111
112DEFUN(cfg_nsip_bss_local_port,
113 cfg_nsip_bss_local_port_cmd,
114 "nsip bss local port <0-65534>",
115 "Set the UDP port on which we listen for BSS connects")
116{
117 unsigned int port = atoi(argv[0]);
118
119 g_cfg->nsip_listen_port = port;
120 return CMD_SUCCESS;
121}
122
123
124DEFUN(cfg_nsip_sgsn_ip,
125 cfg_nsip_sgsn_ip_cmd,
126 "nsip sgsn remote ip A.B.C.D",
127 "Set the IP of the SGSN to which the proxy shall connect")
128{
129 struct in_addr ia;
130
131 inet_aton(argv[0], &ia);
132 g_cfg->nsip_sgsn_ip = ntohl(ia.s_addr);
133
134 return CMD_SUCCESS;
135}
136
137DEFUN(cfg_nsip_sgsn_port,
138 cfg_nsip_sgsn_port_cmd,
139 "nsip sgsn remote port <0-65534>",
140 "Set the UDP port of the SGSN to which the proxy shall connect")
141{
142 unsigned int port = atoi(argv[0]);
143
144 g_cfg->nsip_sgsn_port = port;
145 return CMD_SUCCESS;
146}
147
148DEFUN(cfg_nsip_sgsn_nsei,
149 cfg_nsip_sgsn_nsei_cmd,
150 "nsip sgsn nsei <0-65534>",
151 "Set the NSEI to be used in the connection with the SGSN")
152{
153 unsigned int port = atoi(argv[0]);
154
155 g_cfg->nsip_sgsn_nsei = port;
156 return CMD_SUCCESS;
157}
158
159DEFUN(cfg_nsip_sgsn_nsvci,
160 cfg_nsip_sgsn_nsvci_cmd,
161 "nsip sgsn nsvci <0-65534>",
162 "Set the NSVCI to be used in the connection with the SGSN")
163{
164 unsigned int port = atoi(argv[0]);
165
166 g_cfg->nsip_sgsn_nsvci = port;
167 return CMD_SUCCESS;
168}
169
170
171int gbproxy_vty_init(void)
172{
173 install_element(VIEW_NODE, &show_gbproxy_cmd);
174
175 install_element(CONFIG_NODE, &cfg_gbproxy_cmd);
176 install_node(&gbproxy_node, config_write_gbproxy);
177 install_default(GBPROXY_NODE);
178 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_ip_cmd);
179 install_element(GBPROXY_NODE, &cfg_nsip_bss_local_port_cmd);
180 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_ip_cmd);
181 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_port_cmd);
182 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsei_cmd);
183 install_element(GBPROXY_NODE, &cfg_nsip_sgsn_nsvci_cmd);
184
185 return 0;
186}
187
188int gbproxy_parse_config(const char *config_file, struct gbproxy_config *cfg)
189{
190 int rc;
191
192 g_cfg = cfg;
193 rc = vty_read_config_file(config_file);
194 if (rc < 0) {
195 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
196 return rc;
197 }
198
199 return 0;
200}
201