blob: b59529c582e4bd045de38738cc6dd32864d18962 [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>
Harald Welted193cb32010-05-17 22:58:03 +020028#include <osmocore/utils.h>
Harald Welte288be162010-05-01 16:48:27 +020029
30#include <openbsc/debug.h>
31#include <openbsc/sgsn.h>
32#include <openbsc/gprs_ns.h>
Harald Welted193cb32010-05-17 22:58:03 +020033#include <openbsc/gprs_sgsn.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020034#include <openbsc/vty.h>
Harald Welte288be162010-05-01 16:48:27 +020035
36#include <vty/command.h>
37#include <vty/vty.h>
38
Harald Welted193cb32010-05-17 22:58:03 +020039#include <pdp.h>
40
Harald Welte288be162010-05-01 16:48:27 +020041static struct sgsn_config *g_cfg = NULL;
42
43static struct cmd_node sgsn_node = {
44 SGSN_NODE,
45 "%s(sgsn)#",
46 1,
47};
48
49static int config_write_sgsn(struct vty *vty)
50{
51 struct in_addr ia;
Harald Welted193cb32010-05-17 22:58:03 +020052 struct ggsn_ctx *gctx;
Harald Welte288be162010-05-01 16:48:27 +020053
54 vty_out(vty, "sgsn%s", VTY_NEWLINE);
55
56 if (g_cfg->nsip_listen_ip) {
57 ia.s_addr = htonl(g_cfg->nsip_listen_ip);
58 vty_out(vty, " nsip local ip %s%s", inet_ntoa(ia),
59 VTY_NEWLINE);
60 }
61 vty_out(vty, " nsip local port %u%s", g_cfg->nsip_listen_port,
62 VTY_NEWLINE);
63
Harald Welted193cb32010-05-17 22:58:03 +020064 llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) {
65 vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id,
66 inet_ntoa(gctx->remote_addr), VTY_NEWLINE);
67 vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id,
68 gctx->gtp_version, VTY_NEWLINE);
Harald Welte288be162010-05-01 16:48:27 +020069 }
70
71 return CMD_SUCCESS;
72}
73
74DEFUN(cfg_sgsn,
75 cfg_sgsn_cmd,
76 "sgsn",
77 "Configure the SGSN")
78{
79 vty->node = SGSN_NODE;
80 return CMD_SUCCESS;
81}
82
83
84DEFUN(cfg_nsip_local_ip,
85 cfg_nsip_local_ip_cmd,
86 "nsip local ip A.B.C.D",
87 "Set the IP address on which we listen for BSS connects")
88{
89 struct in_addr ia;
90
91 inet_aton(argv[0], &ia);
92 g_cfg->nsip_listen_ip = ntohl(ia.s_addr);
93
94 return CMD_SUCCESS;
95}
96
97DEFUN(cfg_nsip_local_port,
98 cfg_nsip_local_port_cmd,
99 "nsip local port <0-65534>",
100 "Set the UDP port on which we listen for BSS connects")
101{
102 unsigned int port = atoi(argv[0]);
103
104 g_cfg->nsip_listen_port = port;
Harald Welted193cb32010-05-17 22:58:03 +0200105
Harald Welte288be162010-05-01 16:48:27 +0200106 return CMD_SUCCESS;
107}
108
Harald Welted193cb32010-05-17 22:58:03 +0200109DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd,
110 "ggsn <0-255> remote-ip A.B.C.D",
111 "")
112{
113 uint32_t id = atoi(argv[0]);
114 struct ggsn_ctx *ggc = ggsn_ctx_find_alloc(id);
Harald Welte288be162010-05-01 16:48:27 +0200115
Harald Welted193cb32010-05-17 22:58:03 +0200116 inet_aton(argv[1], &ggc->remote_addr);
Harald Welte288be162010-05-01 16:48:27 +0200117
Harald Welted193cb32010-05-17 22:58:03 +0200118 return CMD_SUCCESS;
119}
120
121#if 0
122DEFUN(cfg_ggsn_remote_port, cfg_ggsn_remote_port_cmd,
123 "ggsn <0-255> remote-port <0-65535>",
124 "")
125{
126 uint32_t id = atoi(argv[0]);
127 struct ggsn_ctx *ggc = ggsn_ctx_find_alloc(id);
128 uint16_t port = atoi(argv[1]);
129
130}
131#endif
132
133DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd,
134 "ggsn <0-255> gtp-version (0|1)",
135 "")
136{
137 uint32_t id = atoi(argv[0]);
138 struct ggsn_ctx *ggc = ggsn_ctx_find_alloc(id);
139 uint16_t port = atoi(argv[1]);
140
141 if (atoi(argv[1]))
142 ggc->gtp_version = 1;
143 else
144 ggc->gtp_version = 0;
145
146 return CMD_SUCCESS;
147}
148
149#if 0
150DEFUN(cfg_apn_ggsn, cfg_apn_ggsn_cmd,
151 "apn APNAME ggsn <0-255>",
152 "")
153{
154 struct apn_ctx **
155}
156#endif
157
158const struct value_string gprs_mm_st_strs[] = {
159 { GMM_DEREGISTERED, "DEREGISTERED" },
160 { GMM_COMMON_PROC_INIT, "COMMON PROCEDURE (INIT)" },
161 { GMM_REGISTERED_NORMAL, "REGISTERED (NORMAL)" },
162 { GMM_REGISTERED_SUSPENDED, "REGISTeRED (SUSPENDED)" },
163 { GMM_DEREGISTERED_INIT, "DEREGISTERED (INIT)" },
164 { 0, NULL }
165};
166
167static void vty_dump_pdp(struct vty *vty, const char *pfx,
168 struct sgsn_pdp_ctx *pdp)
169{
170 vty_out(vty, "%sPDP Context IMSI: %s, SAPI: %u, NSAPI: %u%s",
171 pfx, pdp->mm->imsi, 2342 /* FIXME */, pdp->nsapi, VTY_NEWLINE);
172 vty_out(vty, "%s APN: %s\n", pfx, pdp->lib->apn_use.v);
173 /* FIXME: statistics */
174}
175
176static void vty_dump_mmctx(struct vty *vty, const char *pfx,
177 struct sgsn_mm_ctx *mm, int pdp)
178{
179 vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s",
180 pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE);
181 vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s", pfx, mm->msisdn,
182 mm->tlli, VTY_NEWLINE);
183 vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, "
184 "Cell ID: %u%s", pfx,
185 get_value_string(gprs_mm_st_strs, mm->mm_state),
186 mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac,
187 mm->cell_id, VTY_NEWLINE);
188
189 if (pdp) {
190 struct sgsn_pdp_ctx *pdp;
191
192 llist_for_each_entry(pdp, &mm->pdp_list, list)
193 vty_dump_pdp(vty, " ", pdp);
194 }
195}
196
197DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn",
198 SHOW_STR "Display information about the SGSN")
199{
200 /* FIXME: statistics */
201 return CMD_SUCCESS;
202}
203
204#define MMCTX_STR "MM Context\n"
205#define INCLUDE_PDP_STR "Include PDP Context Information\n"
206
207#if 0
208DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd,
209 "show mm-context tlli HEX [pdp]",
210 SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR)
211{
212 uint32_t tlli;
213 struct sgsn_mm_ctx *mm;
214
215 tlli = strtoul(argv[0], NULL, 16);
216 mm = sgsn_mm_ctx_by_tlli(tlli);
217 if (!mm) {
218 vty_out(vty, "No MM context for TLLI %08x%s",
219 tlli, VTY_NEWLINE);
220 return CMD_WARNING;
221 }
222 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
223 return CMD_SUCCESS;
224}
225#endif
226
227DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd,
228 "show mm-context imsi IMSI [pdp]",
229 SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n"
230 INCLUDE_PDP_STR)
231{
232 struct sgsn_mm_ctx *mm;
233
234 mm = sgsn_mm_ctx_by_imsi(argv[0]);
235 if (!mm) {
236 vty_out(vty, "No MM context for IMSI %s%s",
237 argv[0], VTY_NEWLINE);
238 return CMD_WARNING;
239 }
240 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
241 return CMD_SUCCESS;
242}
243
244DEFUN(swow_mmctx_all, show_mmctx_all_cmd,
245 "show mm-context all [pdp]",
246 SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR)
247{
248 struct sgsn_mm_ctx *mm;
249
250 llist_for_each_entry(mm, &sgsn_mm_ctxts, list)
251 vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0);
252
253 return CMD_SUCCESS;
254}
255
256DEFUN(show_ggsn, show_ggsn_cmd,
257 "show ggsn",
258 "")
259{
260
261}
262
263DEFUN(show_pdpctx_all, show_pdpctx_all_cmd,
264 "show pdp-context all",
265 SHOW_STR "Display information on PDP Context\n")
266{
267 struct sgsn_pdp_ctx *pdp;
268
269 llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list)
270 vty_dump_pdp(vty, "", pdp);
271
272 return CMD_SUCCESS;
273}
Harald Welte288be162010-05-01 16:48:27 +0200274
275int sgsn_vty_init(void)
276{
Harald Welted193cb32010-05-17 22:58:03 +0200277 install_element_ve(&show_sgsn_cmd);
278 //install_element_ve(&show_mmctx_tlli_cmd);
279 install_element_ve(&show_mmctx_imsi_cmd);
280 install_element_ve(&show_mmctx_all_cmd);
281 install_element_ve(&show_pdpctx_all_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200282
283 install_element(CONFIG_NODE, &cfg_sgsn_cmd);
284 install_node(&sgsn_node, config_write_sgsn);
285 install_default(SGSN_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200286 install_element(SGSN_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +0200287 install_element(SGSN_NODE, &ournode_end_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200288 install_element(SGSN_NODE, &cfg_nsip_local_ip_cmd);
289 install_element(SGSN_NODE, &cfg_nsip_local_port_cmd);
Harald Welted193cb32010-05-17 22:58:03 +0200290 install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd);
291 //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd);
292 install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200293
294 return 0;
295}
296
297int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg)
298{
299 int rc;
300
301 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200302 rc = vty_read_config_file(config_file, NULL);
Harald Welte288be162010-05-01 16:48:27 +0200303 if (rc < 0) {
304 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
305 return rc;
306 }
307
308 return 0;
309}