blob: ec18fcbf905f01026c2dcc2de28cfd203d51f1b9 [file] [log] [blame]
Harald Welte288be162010-05-01 16:48:27 +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#include <openbsc/sgsn.h>
31#include <openbsc/gprs_ns.h>
32
33#include <vty/command.h>
34#include <vty/vty.h>
35
36static struct sgsn_config *g_cfg = NULL;
37
38static struct cmd_node sgsn_node = {
39 SGSN_NODE,
40 "%s(sgsn)#",
41 1,
42};
43
44static int config_write_sgsn(struct vty *vty)
45{
46 struct in_addr ia;
47
48 vty_out(vty, "sgsn%s", VTY_NEWLINE);
49
50 if (g_cfg->nsip_listen_ip) {
51 ia.s_addr = htonl(g_cfg->nsip_listen_ip);
52 vty_out(vty, " nsip local ip %s%s", inet_ntoa(ia),
53 VTY_NEWLINE);
54 }
55 vty_out(vty, " nsip local port %u%s", g_cfg->nsip_listen_port,
56 VTY_NEWLINE);
57
58 return CMD_SUCCESS;
59}
60
61DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn",
62 SHOW_STR "Display information about the SGSN")
63{
64 /* FIXME: iterate over list of NS-VC's and display their state */
65 struct gprs_ns_inst *nsi = g_cfg->nsi;
66 struct gprs_nsvc *nsvc;
67
68 llist_for_each_entry(nsvc, &nsi->gprs_nsvcs, list) {
69 vty_out(vty, "NSEI %5u, NS-VC %5u, %s-mode, %s %s%s",
70 nsvc->nsei, nsvc->nsvci,
71 nsvc->remote_end_is_sgsn ? "BSS" : "SGSN",
72 nsvc->state & NSE_S_ALIVE ? "ALIVE" : "DEAD",
73 nsvc->state & NSE_S_BLOCKED ? "BLOCKED" : "UNBLOCKED",
74 VTY_NEWLINE);
75 if (nsvc->nsi->ll == GPRS_NS_LL_UDP)
76 vty_out(vty, " remote peer %s:%u%s",
77 inet_ntoa(nsvc->ip.bts_addr.sin_addr),
78 ntohs(nsvc->ip.bts_addr.sin_port), VTY_NEWLINE);
79 }
80
81 return CMD_SUCCESS;
82}
83
84DEFUN(cfg_sgsn,
85 cfg_sgsn_cmd,
86 "sgsn",
87 "Configure the SGSN")
88{
89 vty->node = SGSN_NODE;
90 return CMD_SUCCESS;
91}
92
93
94DEFUN(cfg_nsip_local_ip,
95 cfg_nsip_local_ip_cmd,
96 "nsip local ip A.B.C.D",
97 "Set the IP address on which we listen for BSS connects")
98{
99 struct in_addr ia;
100
101 inet_aton(argv[0], &ia);
102 g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
103
104 return CMD_SUCCESS;
105}
106
107DEFUN(cfg_nsip_local_port,
108 cfg_nsip_local_port_cmd,
109 "nsip local port <0-65534>",
110 "Set the UDP port on which we listen for BSS connects")
111{
112 unsigned int port = atoi(argv[0]);
113
114 g_cfg->nsip_listen_port = port;
115 return CMD_SUCCESS;
116}
117
118
119
120
121int sgsn_vty_init(void)
122{
123 install_element(VIEW_NODE, &show_sgsn_cmd);
124
125 install_element(CONFIG_NODE, &cfg_sgsn_cmd);
126 install_node(&sgsn_node, config_write_sgsn);
127 install_default(SGSN_NODE);
128 install_element(SGSN_NODE, &cfg_nsip_local_ip_cmd);
129 install_element(SGSN_NODE, &cfg_nsip_local_port_cmd);
130
131 return 0;
132}
133
134int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg)
135{
136 int rc;
137
138 g_cfg = cfg;
139 rc = vty_read_config_file(config_file);
140 if (rc < 0) {
141 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
142 return rc;
143 }
144
145 return 0;
146}