blob: 873fa2041741c890b7870d36ba28e7f154028376 [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 Weltecd4dd4d2010-05-18 17:20:49 +020029#include <osmocore/rate_ctr.h>
Harald Welte288be162010-05-01 16:48:27 +020030
31#include <openbsc/debug.h>
32#include <openbsc/sgsn.h>
33#include <openbsc/gprs_ns.h>
Harald Welted193cb32010-05-17 22:58:03 +020034#include <openbsc/gprs_sgsn.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020035#include <openbsc/vty.h>
Harald Welte288be162010-05-01 16:48:27 +020036
Harald Welte4b037e42010-05-19 19:45:32 +020037#include <osmocom/vty/command.h>
38#include <osmocom/vty/vty.h>
Harald Welte288be162010-05-01 16:48:27 +020039
Harald Welted193cb32010-05-17 22:58:03 +020040#include <pdp.h>
41
Harald Welte288be162010-05-01 16:48:27 +020042static struct sgsn_config *g_cfg = NULL;
43
44static struct cmd_node sgsn_node = {
45 SGSN_NODE,
46 "%s(sgsn)#",
47 1,
48};
49
50static int config_write_sgsn(struct vty *vty)
51{
Harald Welte77289c22010-05-18 14:32:29 +020052 struct sgsn_ggsn_ctx *gctx;
Harald Welte288be162010-05-01 16:48:27 +020053
54 vty_out(vty, "sgsn%s", VTY_NEWLINE);
55
Harald Weltee300d002010-06-02 12:41:34 +020056 vty_out(vty, " gtp local-ip %s%s",
57 inet_ntoa(g_cfg->gtp_listenaddr.sin_addr), VTY_NEWLINE);
58
Harald Welted193cb32010-05-17 22:58:03 +020059 llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) {
Harald Welteff3bde82010-05-19 15:09:09 +020060 vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id,
Harald Welted193cb32010-05-17 22:58:03 +020061 inet_ntoa(gctx->remote_addr), VTY_NEWLINE);
Harald Welteff3bde82010-05-19 15:09:09 +020062 vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id,
Harald Welted193cb32010-05-17 22:58:03 +020063 gctx->gtp_version, VTY_NEWLINE);
Harald Welte288be162010-05-01 16:48:27 +020064 }
65
66 return CMD_SUCCESS;
67}
68
Harald Weltee300d002010-06-02 12:41:34 +020069#define SGSN_STR "Configure the SGSN"
70
71DEFUN(cfg_sgsn, cfg_sgsn_cmd,
72 "sgsn",
73 SGSN_STR)
Harald Welte288be162010-05-01 16:48:27 +020074{
75 vty->node = SGSN_NODE;
76 return CMD_SUCCESS;
77}
78
Harald Weltee300d002010-06-02 12:41:34 +020079DEFUN(cfg_sgsn_bind_addr, cfg_sgsn_bind_addr_cmd,
80 "gtp local-ip A.B.C.D",
81 "GTP Parameters\n"
82 "Set the IP address for the local GTP bind\n")
83{
84 inet_aton(argv[0], &g_cfg->gtp_listenaddr.sin_addr);
85
86 return CMD_SUCCESS;
87}
88
Harald Welted193cb32010-05-17 22:58:03 +020089DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd,
90 "ggsn <0-255> remote-ip A.B.C.D",
91 "")
92{
93 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +020094 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welte288be162010-05-01 16:48:27 +020095
Harald Welted193cb32010-05-17 22:58:03 +020096 inet_aton(argv[1], &ggc->remote_addr);
Harald Welte288be162010-05-01 16:48:27 +020097
Harald Welted193cb32010-05-17 22:58:03 +020098 return CMD_SUCCESS;
99}
100
101#if 0
102DEFUN(cfg_ggsn_remote_port, cfg_ggsn_remote_port_cmd,
103 "ggsn <0-255> remote-port <0-65535>",
104 "")
105{
106 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +0200107 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welted193cb32010-05-17 22:58:03 +0200108 uint16_t port = atoi(argv[1]);
109
110}
111#endif
112
113DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd,
114 "ggsn <0-255> gtp-version (0|1)",
115 "")
116{
117 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +0200118 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welted193cb32010-05-17 22:58:03 +0200119
120 if (atoi(argv[1]))
121 ggc->gtp_version = 1;
122 else
123 ggc->gtp_version = 0;
124
125 return CMD_SUCCESS;
126}
127
128#if 0
129DEFUN(cfg_apn_ggsn, cfg_apn_ggsn_cmd,
130 "apn APNAME ggsn <0-255>",
131 "")
132{
133 struct apn_ctx **
134}
135#endif
136
137const struct value_string gprs_mm_st_strs[] = {
138 { GMM_DEREGISTERED, "DEREGISTERED" },
139 { GMM_COMMON_PROC_INIT, "COMMON PROCEDURE (INIT)" },
140 { GMM_REGISTERED_NORMAL, "REGISTERED (NORMAL)" },
Harald Weltebffeff82010-06-09 15:50:45 +0200141 { GMM_REGISTERED_SUSPENDED, "REGISTERED (SUSPENDED)" },
Harald Welted193cb32010-05-17 22:58:03 +0200142 { GMM_DEREGISTERED_INIT, "DEREGISTERED (INIT)" },
143 { 0, NULL }
144};
145
146static void vty_dump_pdp(struct vty *vty, const char *pfx,
147 struct sgsn_pdp_ctx *pdp)
148{
149 vty_out(vty, "%sPDP Context IMSI: %s, SAPI: %u, NSAPI: %u%s",
Harald Welte6abf94e2010-05-18 10:35:06 +0200150 pfx, pdp->mm->imsi, pdp->sapi, pdp->nsapi, VTY_NEWLINE);
Harald Welted193cb32010-05-17 22:58:03 +0200151 vty_out(vty, "%s APN: %s\n", pfx, pdp->lib->apn_use.v);
Harald Welteefbdee92010-06-10 00:20:12 +0200152 vty_out_rate_ctr_group(vty, " ", pdp->ctrg);
Harald Welted193cb32010-05-17 22:58:03 +0200153}
154
155static void vty_dump_mmctx(struct vty *vty, const char *pfx,
156 struct sgsn_mm_ctx *mm, int pdp)
157{
158 vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s",
159 pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE);
160 vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s", pfx, mm->msisdn,
161 mm->tlli, VTY_NEWLINE);
162 vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, "
163 "Cell ID: %u%s", pfx,
164 get_value_string(gprs_mm_st_strs, mm->mm_state),
165 mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac,
166 mm->cell_id, VTY_NEWLINE);
167
Harald Welte8acd88f2010-05-18 10:57:45 +0200168 vty_out_rate_ctr_group(vty, " ", mm->ctrg);
169
Harald Welted193cb32010-05-17 22:58:03 +0200170 if (pdp) {
171 struct sgsn_pdp_ctx *pdp;
172
173 llist_for_each_entry(pdp, &mm->pdp_list, list)
174 vty_dump_pdp(vty, " ", pdp);
175 }
176}
177
178DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn",
179 SHOW_STR "Display information about the SGSN")
180{
181 /* FIXME: statistics */
182 return CMD_SUCCESS;
183}
184
185#define MMCTX_STR "MM Context\n"
186#define INCLUDE_PDP_STR "Include PDP Context Information\n"
187
188#if 0
189DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd,
190 "show mm-context tlli HEX [pdp]",
191 SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR)
192{
193 uint32_t tlli;
194 struct sgsn_mm_ctx *mm;
195
196 tlli = strtoul(argv[0], NULL, 16);
197 mm = sgsn_mm_ctx_by_tlli(tlli);
198 if (!mm) {
199 vty_out(vty, "No MM context for TLLI %08x%s",
200 tlli, VTY_NEWLINE);
201 return CMD_WARNING;
202 }
203 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
204 return CMD_SUCCESS;
205}
206#endif
207
208DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd,
209 "show mm-context imsi IMSI [pdp]",
210 SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n"
211 INCLUDE_PDP_STR)
212{
213 struct sgsn_mm_ctx *mm;
214
215 mm = sgsn_mm_ctx_by_imsi(argv[0]);
216 if (!mm) {
217 vty_out(vty, "No MM context for IMSI %s%s",
218 argv[0], VTY_NEWLINE);
219 return CMD_WARNING;
220 }
221 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
222 return CMD_SUCCESS;
223}
224
225DEFUN(swow_mmctx_all, show_mmctx_all_cmd,
226 "show mm-context all [pdp]",
227 SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR)
228{
229 struct sgsn_mm_ctx *mm;
230
231 llist_for_each_entry(mm, &sgsn_mm_ctxts, list)
232 vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0);
233
234 return CMD_SUCCESS;
235}
236
237DEFUN(show_ggsn, show_ggsn_cmd,
238 "show ggsn",
239 "")
240{
241
242}
243
244DEFUN(show_pdpctx_all, show_pdpctx_all_cmd,
245 "show pdp-context all",
246 SHOW_STR "Display information on PDP Context\n")
247{
248 struct sgsn_pdp_ctx *pdp;
249
250 llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list)
251 vty_dump_pdp(vty, "", pdp);
252
253 return CMD_SUCCESS;
254}
Harald Welte288be162010-05-01 16:48:27 +0200255
256int sgsn_vty_init(void)
257{
Harald Welted193cb32010-05-17 22:58:03 +0200258 install_element_ve(&show_sgsn_cmd);
259 //install_element_ve(&show_mmctx_tlli_cmd);
260 install_element_ve(&show_mmctx_imsi_cmd);
261 install_element_ve(&show_mmctx_all_cmd);
262 install_element_ve(&show_pdpctx_all_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200263
264 install_element(CONFIG_NODE, &cfg_sgsn_cmd);
265 install_node(&sgsn_node, config_write_sgsn);
266 install_default(SGSN_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200267 install_element(SGSN_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +0200268 install_element(SGSN_NODE, &ournode_end_cmd);
Harald Weltee300d002010-06-02 12:41:34 +0200269 install_element(SGSN_NODE, &cfg_sgsn_bind_addr_cmd);
Harald Welted193cb32010-05-17 22:58:03 +0200270 install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd);
271 //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd);
272 install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200273
274 return 0;
275}
276
277int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg)
278{
279 int rc;
280
281 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200282 rc = vty_read_config_file(config_file, NULL);
Harald Welte288be162010-05-01 16:48:27 +0200283 if (rc < 0) {
284 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
285 return rc;
286 }
287
288 return 0;
289}