blob: 2532a88400988da252b3649b8b2967ec4334994d [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
37#include <vty/command.h>
38#include <vty/vty.h>
39
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{
52 struct in_addr ia;
Harald Welte77289c22010-05-18 14:32:29 +020053 struct sgsn_ggsn_ctx *gctx;
Harald Welte288be162010-05-01 16:48:27 +020054
55 vty_out(vty, "sgsn%s", VTY_NEWLINE);
56
Harald Welted193cb32010-05-17 22:58:03 +020057 llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) {
Harald Welteff3bde82010-05-19 15:09:09 +020058 vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id,
Harald Welted193cb32010-05-17 22:58:03 +020059 inet_ntoa(gctx->remote_addr), VTY_NEWLINE);
Harald Welteff3bde82010-05-19 15:09:09 +020060 vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id,
Harald Welted193cb32010-05-17 22:58:03 +020061 gctx->gtp_version, VTY_NEWLINE);
Harald Welte288be162010-05-01 16:48:27 +020062 }
63
64 return CMD_SUCCESS;
65}
66
67DEFUN(cfg_sgsn,
68 cfg_sgsn_cmd,
69 "sgsn",
70 "Configure the SGSN")
71{
72 vty->node = SGSN_NODE;
73 return CMD_SUCCESS;
74}
75
Harald Welted193cb32010-05-17 22:58:03 +020076DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd,
77 "ggsn <0-255> remote-ip A.B.C.D",
78 "")
79{
80 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +020081 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welte288be162010-05-01 16:48:27 +020082
Harald Welted193cb32010-05-17 22:58:03 +020083 inet_aton(argv[1], &ggc->remote_addr);
Harald Welte288be162010-05-01 16:48:27 +020084
Harald Welted193cb32010-05-17 22:58:03 +020085 return CMD_SUCCESS;
86}
87
88#if 0
89DEFUN(cfg_ggsn_remote_port, cfg_ggsn_remote_port_cmd,
90 "ggsn <0-255> remote-port <0-65535>",
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 Welted193cb32010-05-17 22:58:03 +020095 uint16_t port = atoi(argv[1]);
96
97}
98#endif
99
100DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd,
101 "ggsn <0-255> gtp-version (0|1)",
102 "")
103{
104 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +0200105 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welted193cb32010-05-17 22:58:03 +0200106
107 if (atoi(argv[1]))
108 ggc->gtp_version = 1;
109 else
110 ggc->gtp_version = 0;
111
112 return CMD_SUCCESS;
113}
114
115#if 0
116DEFUN(cfg_apn_ggsn, cfg_apn_ggsn_cmd,
117 "apn APNAME ggsn <0-255>",
118 "")
119{
120 struct apn_ctx **
121}
122#endif
123
124const struct value_string gprs_mm_st_strs[] = {
125 { GMM_DEREGISTERED, "DEREGISTERED" },
126 { GMM_COMMON_PROC_INIT, "COMMON PROCEDURE (INIT)" },
127 { GMM_REGISTERED_NORMAL, "REGISTERED (NORMAL)" },
128 { GMM_REGISTERED_SUSPENDED, "REGISTeRED (SUSPENDED)" },
129 { GMM_DEREGISTERED_INIT, "DEREGISTERED (INIT)" },
130 { 0, NULL }
131};
132
133static void vty_dump_pdp(struct vty *vty, const char *pfx,
134 struct sgsn_pdp_ctx *pdp)
135{
136 vty_out(vty, "%sPDP Context IMSI: %s, SAPI: %u, NSAPI: %u%s",
Harald Welte6abf94e2010-05-18 10:35:06 +0200137 pfx, pdp->mm->imsi, pdp->sapi, pdp->nsapi, VTY_NEWLINE);
Harald Welted193cb32010-05-17 22:58:03 +0200138 vty_out(vty, "%s APN: %s\n", pfx, pdp->lib->apn_use.v);
139 /* FIXME: statistics */
Harald Welte8acd88f2010-05-18 10:57:45 +0200140 //vty_out_rate_ctr_group(vty, " ", pdp->ctrg);
Harald Welted193cb32010-05-17 22:58:03 +0200141}
142
143static void vty_dump_mmctx(struct vty *vty, const char *pfx,
144 struct sgsn_mm_ctx *mm, int pdp)
145{
146 vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s",
147 pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE);
148 vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s", pfx, mm->msisdn,
149 mm->tlli, VTY_NEWLINE);
150 vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, "
151 "Cell ID: %u%s", pfx,
152 get_value_string(gprs_mm_st_strs, mm->mm_state),
153 mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac,
154 mm->cell_id, VTY_NEWLINE);
155
Harald Welte8acd88f2010-05-18 10:57:45 +0200156 vty_out_rate_ctr_group(vty, " ", mm->ctrg);
157
Harald Welted193cb32010-05-17 22:58:03 +0200158 if (pdp) {
159 struct sgsn_pdp_ctx *pdp;
160
161 llist_for_each_entry(pdp, &mm->pdp_list, list)
162 vty_dump_pdp(vty, " ", pdp);
163 }
164}
165
166DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn",
167 SHOW_STR "Display information about the SGSN")
168{
169 /* FIXME: statistics */
170 return CMD_SUCCESS;
171}
172
173#define MMCTX_STR "MM Context\n"
174#define INCLUDE_PDP_STR "Include PDP Context Information\n"
175
176#if 0
177DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd,
178 "show mm-context tlli HEX [pdp]",
179 SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR)
180{
181 uint32_t tlli;
182 struct sgsn_mm_ctx *mm;
183
184 tlli = strtoul(argv[0], NULL, 16);
185 mm = sgsn_mm_ctx_by_tlli(tlli);
186 if (!mm) {
187 vty_out(vty, "No MM context for TLLI %08x%s",
188 tlli, VTY_NEWLINE);
189 return CMD_WARNING;
190 }
191 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
192 return CMD_SUCCESS;
193}
194#endif
195
196DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd,
197 "show mm-context imsi IMSI [pdp]",
198 SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n"
199 INCLUDE_PDP_STR)
200{
201 struct sgsn_mm_ctx *mm;
202
203 mm = sgsn_mm_ctx_by_imsi(argv[0]);
204 if (!mm) {
205 vty_out(vty, "No MM context for IMSI %s%s",
206 argv[0], VTY_NEWLINE);
207 return CMD_WARNING;
208 }
209 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
210 return CMD_SUCCESS;
211}
212
213DEFUN(swow_mmctx_all, show_mmctx_all_cmd,
214 "show mm-context all [pdp]",
215 SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR)
216{
217 struct sgsn_mm_ctx *mm;
218
219 llist_for_each_entry(mm, &sgsn_mm_ctxts, list)
220 vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0);
221
222 return CMD_SUCCESS;
223}
224
225DEFUN(show_ggsn, show_ggsn_cmd,
226 "show ggsn",
227 "")
228{
229
230}
231
232DEFUN(show_pdpctx_all, show_pdpctx_all_cmd,
233 "show pdp-context all",
234 SHOW_STR "Display information on PDP Context\n")
235{
236 struct sgsn_pdp_ctx *pdp;
237
238 llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list)
239 vty_dump_pdp(vty, "", pdp);
240
241 return CMD_SUCCESS;
242}
Harald Welte288be162010-05-01 16:48:27 +0200243
244int sgsn_vty_init(void)
245{
Harald Welted193cb32010-05-17 22:58:03 +0200246 install_element_ve(&show_sgsn_cmd);
247 //install_element_ve(&show_mmctx_tlli_cmd);
248 install_element_ve(&show_mmctx_imsi_cmd);
249 install_element_ve(&show_mmctx_all_cmd);
250 install_element_ve(&show_pdpctx_all_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200251
252 install_element(CONFIG_NODE, &cfg_sgsn_cmd);
253 install_node(&sgsn_node, config_write_sgsn);
254 install_default(SGSN_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200255 install_element(SGSN_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +0200256 install_element(SGSN_NODE, &ournode_end_cmd);
Harald Welted193cb32010-05-17 22:58:03 +0200257 install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd);
258 //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd);
259 install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200260
261 return 0;
262}
263
264int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg)
265{
266 int rc;
267
268 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200269 rc = vty_read_config_file(config_file, NULL);
Harald Welte288be162010-05-01 16:48:27 +0200270 if (rc < 0) {
271 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
272 return rc;
273 }
274
275 return 0;
276}