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