blob: 3c7d0640bd8c9102d0c7bf107725cbb7f83ec3fa [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);
152 /* FIXME: statistics */
Harald Welte8acd88f2010-05-18 10:57:45 +0200153 //vty_out_rate_ctr_group(vty, " ", pdp->ctrg);
Harald Welted193cb32010-05-17 22:58:03 +0200154}
155
156static void vty_dump_mmctx(struct vty *vty, const char *pfx,
157 struct sgsn_mm_ctx *mm, int pdp)
158{
159 vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s",
160 pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE);
161 vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s", pfx, mm->msisdn,
162 mm->tlli, VTY_NEWLINE);
163 vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, "
164 "Cell ID: %u%s", pfx,
165 get_value_string(gprs_mm_st_strs, mm->mm_state),
166 mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac,
167 mm->cell_id, VTY_NEWLINE);
168
Harald Welte8acd88f2010-05-18 10:57:45 +0200169 vty_out_rate_ctr_group(vty, " ", mm->ctrg);
170
Harald Welted193cb32010-05-17 22:58:03 +0200171 if (pdp) {
172 struct sgsn_pdp_ctx *pdp;
173
174 llist_for_each_entry(pdp, &mm->pdp_list, list)
175 vty_dump_pdp(vty, " ", pdp);
176 }
177}
178
179DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn",
180 SHOW_STR "Display information about the SGSN")
181{
182 /* FIXME: statistics */
183 return CMD_SUCCESS;
184}
185
186#define MMCTX_STR "MM Context\n"
187#define INCLUDE_PDP_STR "Include PDP Context Information\n"
188
189#if 0
190DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd,
191 "show mm-context tlli HEX [pdp]",
192 SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR)
193{
194 uint32_t tlli;
195 struct sgsn_mm_ctx *mm;
196
197 tlli = strtoul(argv[0], NULL, 16);
198 mm = sgsn_mm_ctx_by_tlli(tlli);
199 if (!mm) {
200 vty_out(vty, "No MM context for TLLI %08x%s",
201 tlli, VTY_NEWLINE);
202 return CMD_WARNING;
203 }
204 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
205 return CMD_SUCCESS;
206}
207#endif
208
209DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd,
210 "show mm-context imsi IMSI [pdp]",
211 SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n"
212 INCLUDE_PDP_STR)
213{
214 struct sgsn_mm_ctx *mm;
215
216 mm = sgsn_mm_ctx_by_imsi(argv[0]);
217 if (!mm) {
218 vty_out(vty, "No MM context for IMSI %s%s",
219 argv[0], VTY_NEWLINE);
220 return CMD_WARNING;
221 }
222 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
223 return CMD_SUCCESS;
224}
225
226DEFUN(swow_mmctx_all, show_mmctx_all_cmd,
227 "show mm-context all [pdp]",
228 SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR)
229{
230 struct sgsn_mm_ctx *mm;
231
232 llist_for_each_entry(mm, &sgsn_mm_ctxts, list)
233 vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0);
234
235 return CMD_SUCCESS;
236}
237
238DEFUN(show_ggsn, show_ggsn_cmd,
239 "show ggsn",
240 "")
241{
242
243}
244
245DEFUN(show_pdpctx_all, show_pdpctx_all_cmd,
246 "show pdp-context all",
247 SHOW_STR "Display information on PDP Context\n")
248{
249 struct sgsn_pdp_ctx *pdp;
250
251 llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list)
252 vty_dump_pdp(vty, "", pdp);
253
254 return CMD_SUCCESS;
255}
Harald Welte288be162010-05-01 16:48:27 +0200256
257int sgsn_vty_init(void)
258{
Harald Welted193cb32010-05-17 22:58:03 +0200259 install_element_ve(&show_sgsn_cmd);
260 //install_element_ve(&show_mmctx_tlli_cmd);
261 install_element_ve(&show_mmctx_imsi_cmd);
262 install_element_ve(&show_mmctx_all_cmd);
263 install_element_ve(&show_pdpctx_all_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200264
265 install_element(CONFIG_NODE, &cfg_sgsn_cmd);
266 install_node(&sgsn_node, config_write_sgsn);
267 install_default(SGSN_NODE);
Harald Welte62ab20c2010-05-14 18:59:17 +0200268 install_element(SGSN_NODE, &ournode_exit_cmd);
Harald Welte54f74242010-05-14 19:11:04 +0200269 install_element(SGSN_NODE, &ournode_end_cmd);
Harald Weltee300d002010-06-02 12:41:34 +0200270 install_element(SGSN_NODE, &cfg_sgsn_bind_addr_cmd);
Harald Welted193cb32010-05-17 22:58:03 +0200271 install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd);
272 //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd);
273 install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd);
Harald Welte288be162010-05-01 16:48:27 +0200274
275 return 0;
276}
277
278int sgsn_parse_config(const char *config_file, struct sgsn_config *cfg)
279{
280 int rc;
281
282 g_cfg = cfg;
Harald Weltedcccb182010-05-16 20:52:23 +0200283 rc = vty_read_config_file(config_file, NULL);
Harald Welte288be162010-05-01 16:48:27 +0200284 if (rc < 0) {
285 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
286 return rc;
287 }
288
289 return 0;
290}