blob: 888f53a1326bd7c06e078f71e144bb647f198c72 [file] [log] [blame]
Harald Welte288be162010-05-01 16:48:27 +02001/*
Harald Welte89837d42016-05-06 23:28:11 +02002 * (C) 2010-2016 by Harald Welte <laforge@gnumonks.org>
Harald Welte288be162010-05-01 16:48:27 +02003 * (C) 2010 by On-Waves
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02004 * (C) 2015 by Holger Hans Peter Freyther
Harald Welte288be162010-05-01 16:48:27 +02005 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte9af6ddf2011-01-01 15:25:50 +01008 * it under the terms of the GNU Affero General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
Harald Welte288be162010-05-01 16:48:27 +020010 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
Harald Welte9af6ddf2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte288be162010-05-01 16:48:27 +020016 *
Harald Welte9af6ddf2011-01-01 15:25:50 +010017 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <http://www.gnu.org/licenses/>.
Harald Welte288be162010-05-01 16:48:27 +020019 *
20 */
21
Harald Welte288be162010-05-01 16:48:27 +020022#include <sys/socket.h>
23#include <netinet/in.h>
24#include <arpa/inet.h>
Jacob Erlbeck207f4a52014-11-11 14:01:48 +010025#include <time.h>
Harald Welte288be162010-05-01 16:48:27 +020026
Pablo Neira Ayuso136f4532011-03-22 16:47:59 +010027#include <osmocom/core/talloc.h>
28#include <osmocom/core/utils.h>
29#include <osmocom/core/rate_ctr.h>
Harald Welte53373bc2016-04-20 17:11:43 +020030#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
Harald Welte288be162010-05-01 16:48:27 +020031
32#include <openbsc/debug.h>
33#include <openbsc/sgsn.h>
Harald Welteea34a4e2012-06-16 14:59:56 +080034#include <osmocom/gprs/gprs_ns.h>
Harald Welted193cb32010-05-17 22:58:03 +020035#include <openbsc/gprs_sgsn.h>
Harald Welte62ab20c2010-05-14 18:59:17 +020036#include <openbsc/vty.h>
Neels Hofmeyreaaee922016-12-08 21:22:58 +010037#include <openbsc/gsup_client.h>
Harald Welte288be162010-05-01 16:48:27 +020038
Harald Welte4b037e42010-05-19 19:45:32 +020039#include <osmocom/vty/command.h>
40#include <osmocom/vty/vty.h>
Pablo Neira Ayuso6110a3f2011-03-28 19:35:00 +020041#include <osmocom/vty/misc.h>
Max93408ae2016-06-28 14:10:16 +020042#include <osmocom/crypt/gprs_cipher.h>
Jacob Erlbeck80547992014-12-19 19:19:46 +010043#include <osmocom/abis/ipa.h>
44
Harald Welted193cb32010-05-17 22:58:03 +020045#include <pdp.h>
46
Neels Hofmeyr2188a772016-05-20 21:59:55 +020047#include "../../bscconfig.h"
48
49#ifdef BUILD_IU
50#include <openbsc/iu.h>
51#endif
52
Harald Welte288be162010-05-01 16:48:27 +020053static struct sgsn_config *g_cfg = NULL;
54
Jacob Erlbeck106f5472014-11-04 10:08:37 +010055const struct value_string sgsn_auth_pol_strs[] = {
56 { SGSN_AUTH_POLICY_OPEN, "accept-all" },
57 { SGSN_AUTH_POLICY_CLOSED, "closed" },
58 { SGSN_AUTH_POLICY_ACL_ONLY, "acl-only" },
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +010059 { SGSN_AUTH_POLICY_REMOTE, "remote" },
Jacob Erlbeck106f5472014-11-04 10:08:37 +010060 { 0, NULL }
61};
62
Harald Welte94508822015-08-15 19:08:21 +020063/* Section 11.2.2 / Table 11.3a GPRS Mobility management timers – MS side */
64#define GSM0408_T3312_SECS (10*60) /* periodic RAU interval, default 54min */
65
66/* Section 11.2.2 / Table 11.4 MM timers netwokr side */
67#define GSM0408_T3322_SECS 6 /* DETACH_REQ -> DETACH_ACC */
68#define GSM0408_T3350_SECS 6 /* waiting for ATT/RAU/TMSI COMPL */
69#define GSM0408_T3360_SECS 6 /* waiting for AUTH/CIPH RESP */
70#define GSM0408_T3370_SECS 6 /* waiting for ID RESP */
71
Alexander Couzens5ba6fb32017-01-31 18:04:27 +010072/* Section 11.2.2 / Table 11.4a MM timers network side */
Harald Welte94508822015-08-15 19:08:21 +020073#define GSM0408_T3313_SECS 30 /* waiting for paging response */
74#define GSM0408_T3314_SECS 44 /* force to STBY on expiry, Ready timer */
75#define GSM0408_T3316_SECS 44
76
77/* Section 11.3 / Table 11.2d Timers of Session Management - network side */
78#define GSM0408_T3385_SECS 8 /* wait for ACT PDP CTX REQ */
79#define GSM0408_T3386_SECS 8 /* wait for MODIFY PDP CTX ACK */
80#define GSM0408_T3395_SECS 8 /* wait for DEACT PDP CTX ACK */
81#define GSM0408_T3397_SECS 8 /* wait for DEACT AA PDP CTX ACK */
82
83#define DECLARE_TIMER(number, doc) \
84 DEFUN(cfg_sgsn_T##number, \
85 cfg_sgsn_T##number##_cmd, \
86 "timer t" #number " <0-65535>", \
87 "Configure GPRS Timers\n" \
Holger Hans Peter Freytherfe60cfb2015-11-02 12:55:07 +010088 doc "\nTimer Value in seconds\n") \
Harald Welte94508822015-08-15 19:08:21 +020089{ \
90 int value = atoi(argv[0]); \
91 \
92 if (value < 0 || value > 65535) { \
93 vty_out(vty, "Timer value %s out of range.%s", \
94 argv[0], VTY_NEWLINE); \
95 return CMD_WARNING; \
96 } \
97 \
98 g_cfg->timers.T##number = value; \
99 return CMD_SUCCESS; \
100}
101
102DECLARE_TIMER(3312, "Periodic RA Update timer (s)")
Neels Hofmeyr65482c92015-10-19 14:37:12 +0200103DECLARE_TIMER(3322, "Detach request -> accept timer (s)")
Harald Welte94508822015-08-15 19:08:21 +0200104DECLARE_TIMER(3350, "Waiting for ATT/RAU/TMSI_COMPL timer (s)")
105DECLARE_TIMER(3360, "Waiting for AUTH/CIPH response timer (s)")
106DECLARE_TIMER(3370, "Waiting for IDENTITY response timer (s)")
107
108DECLARE_TIMER(3313, "Waiting for paging response timer (s)")
109DECLARE_TIMER(3314, "Force to STANDBY on expiry timer (s)")
Holger Hans Peter Freytherfe60cfb2015-11-02 12:55:07 +0100110DECLARE_TIMER(3316, "AA-Ready timer (s)")
Harald Welte94508822015-08-15 19:08:21 +0200111
112DECLARE_TIMER(3385, "Wait for ACT PDP CTX REQ timer (s)")
113DECLARE_TIMER(3386, "Wait for MODIFY PDP CTX ACK timer (s)")
114DECLARE_TIMER(3395, "Wait for DEACT PDP CTX ACK timer (s)")
115DECLARE_TIMER(3397, "Wait for DEACT AA PDP CTX ACK timer (s)")
116
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100117
Harald Weltec5d4a0c2010-07-02 22:47:59 +0200118#define GSM48_MAX_APN_LEN 102 /* 10.5.6.1 */
Neels Hofmeyr30f7bcb2015-11-08 20:34:47 +0100119/* TODO: consolidate with gprs_apn_to_str(). */
120/** Copy apn to a static buffer, replacing the length octets in apn_enc with '.'
121 * and terminating with a '\0'. Return the static buffer.
122 * len: the length of the encoded APN (which has no terminating zero).
123 */
Harald Weltec5d4a0c2010-07-02 22:47:59 +0200124static char *gprs_apn2str(uint8_t *apn, unsigned int len)
125{
126 static char apnbuf[GSM48_MAX_APN_LEN+1];
Holger Hans Peter Freyther80e03652013-07-04 18:44:16 +0200127 unsigned int i = 0;
Harald Weltec5d4a0c2010-07-02 22:47:59 +0200128
129 if (!apn)
130 return "";
131
132 if (len > sizeof(apnbuf)-1)
133 len = sizeof(apnbuf)-1;
134
135 memcpy(apnbuf, apn, len);
136 apnbuf[len] = '\0';
137
138 /* replace the domain name step sizes with dots */
139 while (i < len) {
140 unsigned int step = apnbuf[i];
141 apnbuf[i] = '.';
142 i += step+1;
143 }
144
145 return apnbuf+1;
146}
147
Holger Hans Peter Freythera2730302014-03-23 18:08:26 +0100148char *gprs_pdpaddr2str(uint8_t *pdpa, uint8_t len)
Harald Weltec5d4a0c2010-07-02 22:47:59 +0200149{
150 static char str[INET6_ADDRSTRLEN + 10];
151
152 if (!pdpa || len < 2)
153 return "none";
154
155 switch (pdpa[0] & 0x0f) {
156 case PDP_TYPE_ORG_IETF:
157 switch (pdpa[1]) {
158 case PDP_TYPE_N_IETF_IPv4:
159 if (len < 2 + 4)
160 break;
161 strcpy(str, "IPv4 ");
162 inet_ntop(AF_INET, pdpa+2, str+5, sizeof(str)-5);
163 return str;
164 case PDP_TYPE_N_IETF_IPv6:
165 if (len < 2 + 8)
166 break;
167 strcpy(str, "IPv6 ");
168 inet_ntop(AF_INET6, pdpa+2, str+5, sizeof(str)-5);
169 return str;
170 default:
171 break;
172 }
173 break;
174 case PDP_TYPE_ORG_ETSI:
175 if (pdpa[1] == PDP_TYPE_N_ETSI_PPP)
176 return "PPP";
177 break;
178 default:
179 break;
180 }
181
182 return "invalid";
183}
184
Harald Welte288be162010-05-01 16:48:27 +0200185static struct cmd_node sgsn_node = {
186 SGSN_NODE,
Harald Welte570ce242012-08-17 13:16:10 +0200187 "%s(config-sgsn)# ",
Harald Welte288be162010-05-01 16:48:27 +0200188 1,
189};
190
191static int config_write_sgsn(struct vty *vty)
192{
Harald Welte77289c22010-05-18 14:32:29 +0200193 struct sgsn_ggsn_ctx *gctx;
Harald Welte7f6da482013-03-19 11:00:13 +0100194 struct imsi_acl_entry *acl;
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100195 struct apn_ctx *actx;
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800196 struct ares_addr_node *server;
Harald Welte288be162010-05-01 16:48:27 +0200197
198 vty_out(vty, "sgsn%s", VTY_NEWLINE);
199
Harald Weltee300d002010-06-02 12:41:34 +0200200 vty_out(vty, " gtp local-ip %s%s",
201 inet_ntoa(g_cfg->gtp_listenaddr.sin_addr), VTY_NEWLINE);
202
Harald Welted193cb32010-05-17 22:58:03 +0200203 llist_for_each_entry(gctx, &sgsn_ggsn_ctxts, list) {
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800204 if (gctx->id == UINT32_MAX)
205 continue;
206
Harald Welteff3bde82010-05-19 15:09:09 +0200207 vty_out(vty, " ggsn %u remote-ip %s%s", gctx->id,
Harald Welted193cb32010-05-17 22:58:03 +0200208 inet_ntoa(gctx->remote_addr), VTY_NEWLINE);
Harald Welteff3bde82010-05-19 15:09:09 +0200209 vty_out(vty, " ggsn %u gtp-version %u%s", gctx->id,
Harald Welted193cb32010-05-17 22:58:03 +0200210 gctx->gtp_version, VTY_NEWLINE);
Harald Welte288be162010-05-01 16:48:27 +0200211 }
212
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800213 if (sgsn->cfg.dynamic_lookup)
214 vty_out(vty, " ggsn dynamic%s", VTY_NEWLINE);
215
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800216 for (server = sgsn->ares_servers; server; server = server->next)
217 vty_out(vty, " grx-dns-add %s%s", inet_ntoa(server->addr.addr4), VTY_NEWLINE);
218
Max93408ae2016-06-28 14:10:16 +0200219 if (g_cfg->cipher != GPRS_ALGO_GEA0)
220 vty_out(vty, " encryption %s%s",
221 get_value_string(gprs_cipher_names, g_cfg->cipher),
222 VTY_NEWLINE);
Jacob Erlbeck39f040d2014-12-18 12:46:47 +0100223 if (g_cfg->gsup_server_addr.sin_addr.s_addr)
224 vty_out(vty, " gsup remote-ip %s%s",
225 inet_ntoa(g_cfg->gsup_server_addr.sin_addr), VTY_NEWLINE);
226 if (g_cfg->gsup_server_port)
227 vty_out(vty, " gsup remote-port %d%s",
228 g_cfg->gsup_server_port, VTY_NEWLINE);
Max176b62a2016-07-04 11:09:07 +0200229 vty_out(vty, " auth-policy %s%s",
230 get_value_string(sgsn_auth_pol_strs, g_cfg->auth_policy),
231 VTY_NEWLINE);
Neels Hofmeyr568a7272015-10-12 11:57:38 +0200232
233 vty_out(vty, " gsup oap-id %d%s",
234 (int)g_cfg->oap.client_id, VTY_NEWLINE);
235 if (g_cfg->oap.secret_k_present != 0)
236 vty_out(vty, " gsup oap-k %s%s",
237 osmo_hexdump_nospc(g_cfg->oap.secret_k, sizeof(g_cfg->oap.secret_k)),
238 VTY_NEWLINE);
239 if (g_cfg->oap.secret_opc_present != 0)
240 vty_out(vty, " gsup oap-opc %s%s",
241 osmo_hexdump_nospc(g_cfg->oap.secret_opc, sizeof(g_cfg->oap.secret_opc)),
242 VTY_NEWLINE);
243
Harald Welte7f6da482013-03-19 11:00:13 +0100244 llist_for_each_entry(acl, &g_cfg->imsi_acl, list)
245 vty_out(vty, " imsi-acl add %s%s", acl->imsi, VTY_NEWLINE);
246
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100247 if (llist_empty(&sgsn_apn_ctxts))
248 vty_out(vty, " ! apn * ggsn 0%s", VTY_NEWLINE);
249 llist_for_each_entry(actx, &sgsn_apn_ctxts, list) {
250 if (strlen(actx->imsi_prefix) > 0)
Holger Hans Peter Freytherb7ae0b32015-05-29 15:11:55 +0200251 vty_out(vty, " apn %s imsi-prefix %s ggsn %u%s",
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100252 actx->name, actx->imsi_prefix, actx->ggsn->id,
253 VTY_NEWLINE);
254 else
Holger Hans Peter Freytherb7ae0b32015-05-29 15:11:55 +0200255 vty_out(vty, " apn %s ggsn %u%s", actx->name,
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100256 actx->ggsn->id, VTY_NEWLINE);
257 }
258
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +0200259 if (g_cfg->cdr.filename)
260 vty_out(vty, " cdr filename %s%s", g_cfg->cdr.filename, VTY_NEWLINE);
261 else
262 vty_out(vty, " no cdr filename%s", VTY_NEWLINE);
263 vty_out(vty, " cdr interval %d%s", g_cfg->cdr.interval, VTY_NEWLINE);
264
Harald Welte94508822015-08-15 19:08:21 +0200265 vty_out(vty, " timer t3312 %d%s", g_cfg->timers.T3312, VTY_NEWLINE);
266 vty_out(vty, " timer t3322 %d%s", g_cfg->timers.T3322, VTY_NEWLINE);
267 vty_out(vty, " timer t3350 %d%s", g_cfg->timers.T3350, VTY_NEWLINE);
268 vty_out(vty, " timer t3360 %d%s", g_cfg->timers.T3360, VTY_NEWLINE);
269 vty_out(vty, " timer t3370 %d%s", g_cfg->timers.T3370, VTY_NEWLINE);
270 vty_out(vty, " timer t3313 %d%s", g_cfg->timers.T3313, VTY_NEWLINE);
271 vty_out(vty, " timer t3314 %d%s", g_cfg->timers.T3314, VTY_NEWLINE);
272 vty_out(vty, " timer t3316 %d%s", g_cfg->timers.T3316, VTY_NEWLINE);
273 vty_out(vty, " timer t3385 %d%s", g_cfg->timers.T3385, VTY_NEWLINE);
274 vty_out(vty, " timer t3386 %d%s", g_cfg->timers.T3386, VTY_NEWLINE);
275 vty_out(vty, " timer t3395 %d%s", g_cfg->timers.T3395, VTY_NEWLINE);
276 vty_out(vty, " timer t3397 %d%s", g_cfg->timers.T3397, VTY_NEWLINE);
277
Philippf1f34362016-08-26 17:00:21 +0200278 if (g_cfg->pcomp_rfc1144.active) {
279 vty_out(vty, " compression rfc1144 active slots %d%s",
280 g_cfg->pcomp_rfc1144.s01 + 1, VTY_NEWLINE);
281 } else if (g_cfg->pcomp_rfc1144.passive) {
282 vty_out(vty, " compression rfc1144 passive%s", VTY_NEWLINE);
283 } else
284 vty_out(vty, " no compression rfc1144%s", VTY_NEWLINE);
285
Philipp73f83d52016-09-02 13:38:01 +0200286 if (g_cfg->dcomp_v42bis.active && g_cfg->dcomp_v42bis.p0 == 1) {
287 vty_out(vty,
288 " compression v42bis active direction sgsn codewords %d strlen %d%s",
289 g_cfg->dcomp_v42bis.p1, g_cfg->dcomp_v42bis.p2,
290 VTY_NEWLINE);
291 } else if (g_cfg->dcomp_v42bis.active && g_cfg->dcomp_v42bis.p0 == 2) {
292 vty_out(vty,
293 " compression v42bis active direction ms codewords %d strlen %d%s",
294 g_cfg->dcomp_v42bis.p1, g_cfg->dcomp_v42bis.p2,
295 VTY_NEWLINE);
296 } else if (g_cfg->dcomp_v42bis.active && g_cfg->dcomp_v42bis.p0 == 3) {
297 vty_out(vty,
298 " compression v42bis active direction both codewords %d strlen %d%s",
299 g_cfg->dcomp_v42bis.p1, g_cfg->dcomp_v42bis.p2,
300 VTY_NEWLINE);
301 } else if (g_cfg->dcomp_v42bis.passive) {
302 vty_out(vty, " compression v42bis passive%s", VTY_NEWLINE);
303 } else
304 vty_out(vty, " no compression v42bis%s", VTY_NEWLINE);
305
Neels Hofmeyr2188a772016-05-20 21:59:55 +0200306#ifdef BUILD_IU
307 iu_vty_config_write(vty, " ");
308#endif
309
Harald Welte288be162010-05-01 16:48:27 +0200310 return CMD_SUCCESS;
311}
312
Holger Hans Peter Freyther1491f2e2011-11-05 15:21:16 +0100313#define SGSN_STR "Configure the SGSN\n"
314#define GGSN_STR "Configure the GGSN information\n"
Harald Weltee300d002010-06-02 12:41:34 +0200315
316DEFUN(cfg_sgsn, cfg_sgsn_cmd,
317 "sgsn",
318 SGSN_STR)
Harald Welte288be162010-05-01 16:48:27 +0200319{
320 vty->node = SGSN_NODE;
321 return CMD_SUCCESS;
322}
323
Harald Weltee300d002010-06-02 12:41:34 +0200324DEFUN(cfg_sgsn_bind_addr, cfg_sgsn_bind_addr_cmd,
325 "gtp local-ip A.B.C.D",
326 "GTP Parameters\n"
Holger Hans Peter Freyther1491f2e2011-11-05 15:21:16 +0100327 "Set the IP address for the local GTP bind\n"
328 "IPv4 Address\n")
Harald Weltee300d002010-06-02 12:41:34 +0200329{
330 inet_aton(argv[0], &g_cfg->gtp_listenaddr.sin_addr);
331
332 return CMD_SUCCESS;
333}
334
Harald Welted193cb32010-05-17 22:58:03 +0200335DEFUN(cfg_ggsn_remote_ip, cfg_ggsn_remote_ip_cmd,
336 "ggsn <0-255> remote-ip A.B.C.D",
Holger Hans Peter Freyther1491f2e2011-11-05 15:21:16 +0100337 GGSN_STR "GGSN Number\n" IP_STR "IPv4 Address\n")
Harald Welted193cb32010-05-17 22:58:03 +0200338{
339 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +0200340 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welte288be162010-05-01 16:48:27 +0200341
Harald Welted193cb32010-05-17 22:58:03 +0200342 inet_aton(argv[1], &ggc->remote_addr);
Harald Welte288be162010-05-01 16:48:27 +0200343
Harald Welted193cb32010-05-17 22:58:03 +0200344 return CMD_SUCCESS;
345}
346
347#if 0
348DEFUN(cfg_ggsn_remote_port, cfg_ggsn_remote_port_cmd,
349 "ggsn <0-255> remote-port <0-65535>",
350 "")
351{
352 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +0200353 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welted193cb32010-05-17 22:58:03 +0200354 uint16_t port = atoi(argv[1]);
355
356}
357#endif
358
359DEFUN(cfg_ggsn_gtp_version, cfg_ggsn_gtp_version_cmd,
360 "ggsn <0-255> gtp-version (0|1)",
Holger Hans Peter Freyther1491f2e2011-11-05 15:21:16 +0100361 GGSN_STR "GGSN Number\n" "GTP Version\n"
362 "Version 0\n" "Version 1\n")
Harald Welted193cb32010-05-17 22:58:03 +0200363{
364 uint32_t id = atoi(argv[0]);
Harald Welte77289c22010-05-18 14:32:29 +0200365 struct sgsn_ggsn_ctx *ggc = sgsn_ggsn_ctx_find_alloc(id);
Harald Welted193cb32010-05-17 22:58:03 +0200366
367 if (atoi(argv[1]))
368 ggc->gtp_version = 1;
369 else
370 ggc->gtp_version = 0;
371
372 return CMD_SUCCESS;
373}
374
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +0800375DEFUN(cfg_ggsn_dynamic_lookup, cfg_ggsn_dynamic_lookup_cmd,
376 "ggsn dynamic",
377 GGSN_STR "Enable dynamic GRX based look-up (requires restart)\n")
378{
379 sgsn->cfg.dynamic_lookup = 1;
380 return CMD_SUCCESS;
381}
382
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +0800383DEFUN(cfg_grx_ggsn, cfg_grx_ggsn_cmd,
384 "grx-dns-add A.B.C.D",
385 "Add DNS server\nIPv4 address\n")
386{
387 struct ares_addr_node *node = talloc_zero(tall_bsc_ctx, struct ares_addr_node);
388 node->family = AF_INET;
389 inet_aton(argv[0], &node->addr.addr4);
390
391 node->next = sgsn->ares_servers;
392 sgsn->ares_servers = node;
393 return CMD_SUCCESS;
394}
395
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100396#define APN_STR "Configure the information per APN\n"
397#define APN_GW_STR "The APN gateway name optionally prefixed by '*' (wildcard)\n"
398
399static int add_apn_ggsn_mapping(struct vty *vty, const char *apn_str,
400 const char *imsi_prefix, int ggsn_id)
401{
402 struct apn_ctx *actx;
403 struct sgsn_ggsn_ctx *ggsn;
404
405 ggsn = sgsn_ggsn_ctx_by_id(ggsn_id);
406 if (ggsn == NULL) {
407 vty_out(vty, "%% a GGSN with id %d has not been defined%s",
408 ggsn_id, VTY_NEWLINE);
409 return CMD_WARNING;
410 }
411
412 actx = sgsn_apn_ctx_find_alloc(apn_str, imsi_prefix);
413 if (!actx) {
414 vty_out(vty, "%% unable to create APN context for %s/%s%s",
415 apn_str, imsi_prefix, VTY_NEWLINE);
416 return CMD_WARNING;
417 }
418
419 actx->ggsn = ggsn;
420
421 return CMD_SUCCESS;
422}
423
Harald Welted193cb32010-05-17 22:58:03 +0200424DEFUN(cfg_apn_ggsn, cfg_apn_ggsn_cmd,
425 "apn APNAME ggsn <0-255>",
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100426 APN_STR APN_GW_STR
427 "Select the GGSN to use when the APN gateway prefix matches\n"
428 "The GGSN id")
Harald Welted193cb32010-05-17 22:58:03 +0200429{
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100430
431 return add_apn_ggsn_mapping(vty, argv[0], "", atoi(argv[1]));
Harald Welted193cb32010-05-17 22:58:03 +0200432}
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +0100433
434DEFUN(cfg_apn_imsi_ggsn, cfg_apn_imsi_ggsn_cmd,
435 "apn APNAME imsi-prefix IMSIPRE ggsn <0-255>",
436 APN_STR APN_GW_STR
437 "Restrict rule to a certain IMSI prefix\n"
438 "An IMSI prefix\n"
439 "Select the GGSN to use when APN gateway and IMSI prefix match\n"
440 "The GGSN id")
441{
442
443 return add_apn_ggsn_mapping(vty, argv[0], argv[1], atoi(argv[2]));
444}
Harald Welted193cb32010-05-17 22:58:03 +0200445
446const struct value_string gprs_mm_st_strs[] = {
447 { GMM_DEREGISTERED, "DEREGISTERED" },
448 { GMM_COMMON_PROC_INIT, "COMMON PROCEDURE (INIT)" },
449 { GMM_REGISTERED_NORMAL, "REGISTERED (NORMAL)" },
Harald Weltebffeff82010-06-09 15:50:45 +0200450 { GMM_REGISTERED_SUSPENDED, "REGISTERED (SUSPENDED)" },
Harald Welted193cb32010-05-17 22:58:03 +0200451 { GMM_DEREGISTERED_INIT, "DEREGISTERED (INIT)" },
452 { 0, NULL }
453};
454
Harald Welte471ac7d2016-12-15 19:48:58 +0100455static char *gtp_ntoa(struct ul16_t *ul)
456{
457 if (ul->l == 4) {
458 struct in_addr *ia = (struct in_addr *) ul;
459 return inet_ntoa(*ia);
460 } else {
461 return "UNKNOWN";
462 }
463}
464
Harald Welted193cb32010-05-17 22:58:03 +0200465static void vty_dump_pdp(struct vty *vty, const char *pfx,
466 struct sgsn_pdp_ctx *pdp)
467{
Jacob Erlbeck99985b52014-10-13 10:32:00 +0200468 const char *imsi = pdp->mm ? pdp->mm->imsi : "(detaching)";
Harald Welte471ac7d2016-12-15 19:48:58 +0100469 vty_out(vty, "%sPDP Context IMSI: %s, SAPI: %u, NSAPI: %u, TI: %u%s",
470 pfx, imsi, pdp->sapi, pdp->nsapi, pdp->ti, VTY_NEWLINE);
Harald Weltec5d4a0c2010-07-02 22:47:59 +0200471 vty_out(vty, "%s APN: %s%s", pfx,
472 gprs_apn2str(pdp->lib->apn_use.v, pdp->lib->apn_use.l),
473 VTY_NEWLINE);
474 vty_out(vty, "%s PDP Address: %s%s", pfx,
475 gprs_pdpaddr2str(pdp->lib->eua.v, pdp->lib->eua.l),
476 VTY_NEWLINE);
Harald Welte471ac7d2016-12-15 19:48:58 +0100477 vty_out(vty, "%s GTP Local Control(%s / TEIC: 0x%08x) ", pfx,
478 gtp_ntoa(&pdp->lib->gsnlc), pdp->lib->teic_own);
479 vty_out(vty, "Data(%s / TEID: 0x%08x)%s",
480 gtp_ntoa(&pdp->lib->gsnlu), pdp->lib->teid_own, VTY_NEWLINE);
481 vty_out(vty, "%s GTP Remote Control(%s / TEIC: 0x%08x) ", pfx,
482 gtp_ntoa(&pdp->lib->gsnrc), pdp->lib->teic_gn);
483 vty_out(vty, "Data(%s / TEID: 0x%08x)%s",
484 gtp_ntoa(&pdp->lib->gsnru), pdp->lib->teid_gn, VTY_NEWLINE);
485
Harald Welteefbdee92010-06-10 00:20:12 +0200486 vty_out_rate_ctr_group(vty, " ", pdp->ctrg);
Harald Welted193cb32010-05-17 22:58:03 +0200487}
488
489static void vty_dump_mmctx(struct vty *vty, const char *pfx,
490 struct sgsn_mm_ctx *mm, int pdp)
491{
492 vty_out(vty, "%sMM Context for IMSI %s, IMEI %s, P-TMSI %08x%s",
493 pfx, mm->imsi, mm->imei, mm->p_tmsi, VTY_NEWLINE);
Holger Hans Peter Freyther8ee13e22015-05-18 10:00:03 +0200494 vty_out(vty, "%s MSISDN: %s, TLLI: %08x%s HLR: %s",
Harald Weltef97ee042015-12-25 19:12:21 +0100495 pfx, mm->msisdn, mm->gb.tlli, mm->hlr, VTY_NEWLINE);
Harald Welted193cb32010-05-17 22:58:03 +0200496 vty_out(vty, "%s MM State: %s, Routeing Area: %u-%u-%u-%u, "
497 "Cell ID: %u%s", pfx,
Alexander Couzens4f8da6d2017-01-31 15:34:26 +0100498 get_value_string(gprs_mm_st_strs, mm->gmm_state),
Harald Welted193cb32010-05-17 22:58:03 +0200499 mm->ra.mcc, mm->ra.mnc, mm->ra.lac, mm->ra.rac,
Harald Weltef97ee042015-12-25 19:12:21 +0100500 mm->gb.cell_id, VTY_NEWLINE);
Harald Welted193cb32010-05-17 22:58:03 +0200501
Harald Welte8acd88f2010-05-18 10:57:45 +0200502 vty_out_rate_ctr_group(vty, " ", mm->ctrg);
503
Harald Welted193cb32010-05-17 22:58:03 +0200504 if (pdp) {
505 struct sgsn_pdp_ctx *pdp;
506
507 llist_for_each_entry(pdp, &mm->pdp_list, list)
508 vty_dump_pdp(vty, " ", pdp);
509 }
510}
511
512DEFUN(show_sgsn, show_sgsn_cmd, "show sgsn",
513 SHOW_STR "Display information about the SGSN")
514{
Jacob Erlbeck80547992014-12-19 19:19:46 +0100515 if (sgsn->gsup_client) {
516 struct ipa_client_conn *link = sgsn->gsup_client->link;
517 vty_out(vty,
518 " Remote authorization: %sconnected to %s:%d via GSUP%s",
519 sgsn->gsup_client->is_connected ? "" : "not ",
520 link->addr, link->port,
521 VTY_NEWLINE);
522 }
Harald Welted193cb32010-05-17 22:58:03 +0200523 /* FIXME: statistics */
524 return CMD_SUCCESS;
525}
526
527#define MMCTX_STR "MM Context\n"
528#define INCLUDE_PDP_STR "Include PDP Context Information\n"
529
530#if 0
531DEFUN(show_mmctx_tlli, show_mmctx_tlli_cmd,
532 "show mm-context tlli HEX [pdp]",
533 SHOW_STR MMCTX_STR "Identify by TLLI\n" "TLLI\n" INCLUDE_PDP_STR)
534{
535 uint32_t tlli;
536 struct sgsn_mm_ctx *mm;
537
538 tlli = strtoul(argv[0], NULL, 16);
539 mm = sgsn_mm_ctx_by_tlli(tlli);
540 if (!mm) {
541 vty_out(vty, "No MM context for TLLI %08x%s",
542 tlli, VTY_NEWLINE);
543 return CMD_WARNING;
544 }
545 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
546 return CMD_SUCCESS;
547}
548#endif
549
550DEFUN(swow_mmctx_imsi, show_mmctx_imsi_cmd,
551 "show mm-context imsi IMSI [pdp]",
552 SHOW_STR MMCTX_STR "Identify by IMSI\n" "IMSI of the MM Context\n"
553 INCLUDE_PDP_STR)
554{
555 struct sgsn_mm_ctx *mm;
556
557 mm = sgsn_mm_ctx_by_imsi(argv[0]);
558 if (!mm) {
559 vty_out(vty, "No MM context for IMSI %s%s",
560 argv[0], VTY_NEWLINE);
561 return CMD_WARNING;
562 }
563 vty_dump_mmctx(vty, "", mm, argv[1] ? 1 : 0);
564 return CMD_SUCCESS;
565}
566
567DEFUN(swow_mmctx_all, show_mmctx_all_cmd,
568 "show mm-context all [pdp]",
569 SHOW_STR MMCTX_STR "All MM Contexts\n" INCLUDE_PDP_STR)
570{
571 struct sgsn_mm_ctx *mm;
572
573 llist_for_each_entry(mm, &sgsn_mm_ctxts, list)
574 vty_dump_mmctx(vty, "", mm, argv[0] ? 1 : 0);
575
576 return CMD_SUCCESS;
577}
578
Harald Welted193cb32010-05-17 22:58:03 +0200579DEFUN(show_pdpctx_all, show_pdpctx_all_cmd,
580 "show pdp-context all",
Holger Hans Peter Freyther1491f2e2011-11-05 15:21:16 +0100581 SHOW_STR "Display information on PDP Context\n" "Show everything\n")
Harald Welted193cb32010-05-17 22:58:03 +0200582{
583 struct sgsn_pdp_ctx *pdp;
584
585 llist_for_each_entry(pdp, &sgsn_pdp_ctxts, g_list)
586 vty_dump_pdp(vty, "", pdp);
587
588 return CMD_SUCCESS;
589}
Harald Welte288be162010-05-01 16:48:27 +0200590
Harald Welte7f6da482013-03-19 11:00:13 +0100591
592DEFUN(imsi_acl, cfg_imsi_acl_cmd,
593 "imsi-acl (add|del) IMSI",
594 "Access Control List of foreign IMSIs\n"
595 "Add IMSI to ACL\n"
596 "Remove IMSI from ACL\n"
597 "IMSI of subscriber\n")
598{
Philipp Maier6ee49d82017-02-28 16:53:07 +0100599 char imsi_sanitized[GSM23003_IMSI_MAX_DIGITS+1];
Harald Welte7f6da482013-03-19 11:00:13 +0100600 const char *op = argv[0];
Philipp Maier6ee49d82017-02-28 16:53:07 +0100601 const char *imsi = imsi_sanitized;
Harald Welte7f6da482013-03-19 11:00:13 +0100602 int rc;
603
Philipp Maier6ee49d82017-02-28 16:53:07 +0100604 /* Sanitize IMSI */
605 if (strlen(argv[1]) > GSM23003_IMSI_MAX_DIGITS) {
606 vty_out(vty, "%% IMSI (%s) too long -- ignored!%s",
607 argv[1], VTY_NEWLINE);
608 return CMD_WARNING;
609 }
610 memset(imsi_sanitized, '0', sizeof(imsi_sanitized));
611 strcpy(imsi_sanitized+GSM23003_IMSI_MAX_DIGITS-strlen(argv[1]),argv[1]);
612
Harald Welte7f6da482013-03-19 11:00:13 +0100613 if (!strcmp(op, "add"))
Jacob Erlbeck3b5d4072014-10-24 15:11:03 +0200614 rc = sgsn_acl_add(imsi, g_cfg);
Harald Welte7f6da482013-03-19 11:00:13 +0100615 else
Jacob Erlbeck3b5d4072014-10-24 15:11:03 +0200616 rc = sgsn_acl_del(imsi, g_cfg);
Harald Welte7f6da482013-03-19 11:00:13 +0100617
618 if (rc < 0) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100619 vty_out(vty, "%% unable to %s ACL%s", op, VTY_NEWLINE);
Harald Welte7f6da482013-03-19 11:00:13 +0100620 return CMD_WARNING;
621 }
622
623 return CMD_SUCCESS;
624}
625
Max93408ae2016-06-28 14:10:16 +0200626DEFUN(cfg_encrypt, cfg_encrypt_cmd,
627 "encryption (GEA0|GEA1|GEA2|GEA3|GEA4)",
628 "Set encryption algorithm for SGSN\n"
629 "Use GEA0 (no encryption)\n"
630 "Use GEA1\nUse GEA2\nUse GEA3\nUse GEA4\n")
631{
Max93408ae2016-06-28 14:10:16 +0200632 enum gprs_ciph_algo c = get_string_value(gprs_cipher_names, argv[0]);
Max086067f2017-05-02 13:03:28 +0200633 if (c != GPRS_ALGO_GEA0) {
634 if (!gprs_cipher_supported(c)) {
635 vty_out(vty, "%% cipher %s is unsupported in current version%s", argv[0], VTY_NEWLINE);
636 return CMD_WARNING;
637 }
638
639 if (!g_cfg->require_authentication) {
640 vty_out(vty, "%% unable to use encryption %s without authentication: please adjust auth-policy%s",
641 argv[0], VTY_NEWLINE);
642 return CMD_WARNING;
643 }
Max93408ae2016-06-28 14:10:16 +0200644 }
645
646 g_cfg->cipher = c;
647
648 return CMD_SUCCESS;
649}
650
Harald Welte3dfb5492013-03-19 11:48:54 +0100651DEFUN(cfg_auth_policy, cfg_auth_policy_cmd,
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100652 "auth-policy (accept-all|closed|acl-only|remote)",
Harald Welte3dfb5492013-03-19 11:48:54 +0100653 "Autorization Policy of SGSN\n"
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100654 "Accept all IMSIs (DANGEROUS)\n"
655 "Accept only home network subscribers or those in the ACL\n"
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100656 "Accept only subscribers in the ACL\n"
657 "Use remote subscription data only (HLR)\n")
Harald Welte3dfb5492013-03-19 11:48:54 +0100658{
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100659 int val = get_string_value(sgsn_auth_pol_strs, argv[0]);
Jacob Erlbeckbe2c8d92014-11-12 10:18:09 +0100660 OSMO_ASSERT(val >= SGSN_AUTH_POLICY_OPEN && val <= SGSN_AUTH_POLICY_REMOTE);
Jacob Erlbeck106f5472014-11-04 10:08:37 +0100661 g_cfg->auth_policy = val;
Jacob Erlbeck9d4f46c2014-12-17 13:20:08 +0100662 g_cfg->require_authentication = (val == SGSN_AUTH_POLICY_REMOTE);
Jacob Erlbeck771573c2014-12-19 18:08:48 +0100663 g_cfg->require_update_location = (val == SGSN_AUTH_POLICY_REMOTE);
Harald Welte3dfb5492013-03-19 11:48:54 +0100664
665 return CMD_SUCCESS;
666}
667
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100668/* Subscriber */
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100669#include <openbsc/gprs_subscriber.h>
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100670
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100671static void subscr_dump_full_vty(struct vty *vty, struct gprs_subscr *gsub, int pending)
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100672{
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100673#if 0
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100674 char expire_time[200];
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100675#endif
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100676 struct gsm_auth_tuple *at;
677 int at_idx;
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100678 struct sgsn_subscriber_pdp_data *pdp;
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100679
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100680 vty_out(vty, " Authorized: %d%s",
681 gsub->authorized, VTY_NEWLINE);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100682 vty_out(vty, " LAC: %d/0x%x%s",
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100683 gsub->lac, gsub->lac, VTY_NEWLINE);
684 vty_out(vty, " IMSI: %s%s", gsub->imsi, VTY_NEWLINE);
685 if (gsub->tmsi != GSM_RESERVED_TMSI)
686 vty_out(vty, " TMSI: %08X%s", gsub->tmsi,
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100687 VTY_NEWLINE);
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100688 if (gsub->sgsn_data->msisdn_len > 0)
Holger Hans Peter Freytherf7b38262015-04-23 16:58:33 -0400689 vty_out(vty, " MSISDN (BCD): %s%s",
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100690 osmo_hexdump(gsub->sgsn_data->msisdn,
691 gsub->sgsn_data->msisdn_len),
Holger Hans Peter Freytherf7b38262015-04-23 16:58:33 -0400692 VTY_NEWLINE);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100693
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100694 if (strlen(gsub->imei) > 0)
695 vty_out(vty, " IMEI: %s%s", gsub->imei, VTY_NEWLINE);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100696
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100697 for (at_idx = 0; at_idx < ARRAY_SIZE(gsub->sgsn_data->auth_triplets);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100698 at_idx++) {
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100699 at = &gsub->sgsn_data->auth_triplets[at_idx];
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100700 if (at->key_seq == GSM_KEY_SEQ_INVAL)
701 continue;
702
703 vty_out(vty, " A3A8 tuple (used %d times): ",
704 at->use_count);
Harald Welte89837d42016-05-06 23:28:11 +0200705 vty_out(vty, " CKSN: %d, ",
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100706 at->key_seq);
Harald Welte89837d42016-05-06 23:28:11 +0200707 if (at->vec.auth_types & OSMO_AUTH_TYPE_GSM) {
708 vty_out(vty, "RAND: %s, ",
709 osmo_hexdump(at->vec.rand,
710 sizeof(at->vec.rand)));
711 vty_out(vty, "SRES: %s, ",
712 osmo_hexdump(at->vec.sres,
713 sizeof(at->vec.sres)));
714 vty_out(vty, "Kc: %s%s",
715 osmo_hexdump(at->vec.kc,
716 sizeof(at->vec.kc)), VTY_NEWLINE);
717 }
718 if (at->vec.auth_types & OSMO_AUTH_TYPE_UMTS) {
719 vty_out(vty, " AUTN: %s, ",
720 osmo_hexdump(at->vec.autn,
721 sizeof(at->vec.autn)));
722 vty_out(vty, "RES: %s, ",
723 osmo_hexdump(at->vec.res, at->vec.res_len));
724 vty_out(vty, "IK: %s, ",
725 osmo_hexdump(at->vec.ik, sizeof(at->vec.ik)));
726 vty_out(vty, "CK: %s, ",
727 osmo_hexdump(at->vec.ck, sizeof(at->vec.ck)));
728 }
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100729 }
730
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100731 llist_for_each_entry(pdp, &gsub->sgsn_data->pdp_list, list) {
Holger Hans Peter Freytherd05e0692015-04-23 16:59:04 -0400732 vty_out(vty, " PDP info: Id: %d, Type: 0x%04x, APN: '%s' QoS: %s%s",
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100733 pdp->context_id, pdp->pdp_type, pdp->apn_str,
Holger Hans Peter Freytherd05e0692015-04-23 16:59:04 -0400734 osmo_hexdump(pdp->qos_subscribed, pdp->qos_subscribed_len),
Jacob Erlbeck0e8add62014-12-17 14:03:35 +0100735 VTY_NEWLINE);
736 }
737
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100738#if 0
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100739 /* print the expiration time of a subscriber */
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100740 if (gsub->expire_lu) {
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100741 strftime(expire_time, sizeof(expire_time),
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100742 "%a, %d %b %Y %T %z", localtime(&gsub->expire_lu));
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100743 expire_time[sizeof(expire_time) - 1] = '\0';
744 vty_out(vty, " Expiration Time: %s%s", expire_time, VTY_NEWLINE);
745 }
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100746#endif
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100747
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100748 if (gsub->flags)
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100749 vty_out(vty, " Flags: %s%s%s%s%s%s",
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100750 gsub->flags & GPRS_SUBSCRIBER_FIRST_CONTACT ?
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100751 "FIRST_CONTACT " : "",
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100752 gsub->flags & GPRS_SUBSCRIBER_CANCELLED ?
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100753 "CANCELLED " : "",
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100754 gsub->flags & GPRS_SUBSCRIBER_UPDATE_LOCATION_PENDING ?
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100755 "UPDATE_LOCATION_PENDING " : "",
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100756 gsub->flags & GPRS_SUBSCRIBER_UPDATE_AUTH_INFO_PENDING ?
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100757 "AUTH_INFO_PENDING " : "",
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100758 gsub->flags & GPRS_SUBSCRIBER_ENABLE_PURGE ?
Jacob Erlbeck65fa3f72015-01-06 16:32:41 +0100759 "ENABLE_PURGE " : "",
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100760 VTY_NEWLINE);
761
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100762 vty_out(vty, " Use count: %u%s", gsub->use_count, VTY_NEWLINE);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100763}
764
765DEFUN(show_subscr_cache,
766 show_subscr_cache_cmd,
767 "show subscriber cache",
768 SHOW_STR "Show information about subscribers\n"
769 "Display contents of subscriber cache\n")
770{
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100771 struct gprs_subscr *subscr;
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100772
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100773 llist_for_each_entry(subscr, gprs_subscribers, entry) {
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100774 vty_out(vty, " Subscriber:%s", VTY_NEWLINE);
775 subscr_dump_full_vty(vty, subscr, 0);
776 }
777
778 return CMD_SUCCESS;
779}
780
781#define UPDATE_SUBSCR_STR "update-subscriber imsi IMSI "
782#define UPDATE_SUBSCR_HELP "Update subscriber list\n" \
783 "Use the IMSI to select the subscriber\n" \
784 "The IMSI\n"
785
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100786#define UPDATE_SUBSCR_INSERT_HELP "Insert data into the subscriber record\n"
787
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100788DEFUN(update_subscr_insert_auth_triplet, update_subscr_insert_auth_triplet_cmd,
789 UPDATE_SUBSCR_STR "insert auth-triplet <1-5> sres SRES rand RAND kc KC",
790 UPDATE_SUBSCR_HELP
791 UPDATE_SUBSCR_INSERT_HELP
792 "Update authentication triplet\n"
793 "Triplet index\n"
794 "Set SRES value\nSRES value (4 byte) in hex\n"
795 "Set RAND value\nRAND value (16 byte) in hex\n"
796 "Set Kc value\nKc value (8 byte) in hex\n")
797{
798 const char *imsi = argv[0];
799 const int cksn = atoi(argv[1]) - 1;
800 const char *sres_str = argv[2];
801 const char *rand_str = argv[3];
802 const char *kc_str = argv[4];
803 struct gsm_auth_tuple at = {0,};
804
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100805 struct gprs_subscr *subscr;
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100806
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100807 subscr = gprs_subscr_get_by_imsi(imsi);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100808 if (!subscr) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100809 vty_out(vty, "%% unable get subscriber record for %s%s",
810 imsi, VTY_NEWLINE);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100811 return CMD_WARNING;
812 }
813
814 OSMO_ASSERT(subscr->sgsn_data);
815
Harald Welte121e9a42016-04-20 13:13:19 +0200816 if (osmo_hexparse(sres_str, &at.vec.sres[0], sizeof(at.vec.sres)) < 0) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100817 vty_out(vty, "%% invalid SRES value '%s'%s",
818 sres_str, VTY_NEWLINE);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100819 goto failed;
820 }
Harald Welte121e9a42016-04-20 13:13:19 +0200821 if (osmo_hexparse(rand_str, &at.vec.rand[0], sizeof(at.vec.rand)) < 0) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100822 vty_out(vty, "%% invalid RAND value '%s'%s",
823 rand_str, VTY_NEWLINE);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100824 goto failed;
825 }
Harald Welte121e9a42016-04-20 13:13:19 +0200826 if (osmo_hexparse(kc_str, &at.vec.kc[0], sizeof(at.vec.kc)) < 0) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100827 vty_out(vty, "%% invalid Kc value '%s'%s",
828 kc_str, VTY_NEWLINE);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100829 goto failed;
830 }
831 at.key_seq = cksn;
832
833 subscr->sgsn_data->auth_triplets[cksn] = at;
834 subscr->sgsn_data->auth_triplets_updated = 1;
835
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100836 gprs_subscr_put(subscr);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100837
838 return CMD_SUCCESS;
839
840failed:
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100841 gprs_subscr_put(subscr);
Jacob Erlbeck7921ab12014-12-08 15:52:00 +0100842 return CMD_SUCCESS;
843}
844
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100845DEFUN(update_subscr_cancel, update_subscr_cancel_cmd,
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100846 UPDATE_SUBSCR_STR "cancel (update-procedure|subscription-withdraw)",
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100847 UPDATE_SUBSCR_HELP
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100848 "Cancel (remove) subscriber record\n"
849 "The MS moved to another SGSN\n"
850 "The subscription is no longer valid\n")
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100851{
852 const char *imsi = argv[0];
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100853 const char *cancel_type = argv[1];
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100854
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100855 struct gprs_subscr *subscr;
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100856
857 subscr = gprs_subscr_get_by_imsi(imsi);
858 if (!subscr) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100859 vty_out(vty, "%% no subscriber record for %s%s",
860 imsi, VTY_NEWLINE);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100861 return CMD_WARNING;
862 }
863
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100864 if (strcmp(cancel_type, "update-procedure") == 0)
865 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
866 else
867 subscr->sgsn_data->error_cause = GMM_CAUSE_IMPL_DETACHED;
868
Jacob Erlbeck37139e52015-01-23 13:52:55 +0100869 gprs_subscr_cancel(subscr);
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100870 gprs_subscr_put(subscr);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100871
872 return CMD_SUCCESS;
873}
874
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100875DEFUN(update_subscr_create, update_subscr_create_cmd,
876 UPDATE_SUBSCR_STR "create",
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100877 UPDATE_SUBSCR_HELP
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100878 "Create a subscriber entry\n")
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100879{
880 const char *imsi = argv[0];
881
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100882 struct gprs_subscr *subscr;
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100883
884 subscr = gprs_subscr_get_by_imsi(imsi);
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100885 if (subscr) {
886 vty_out(vty, "%% subscriber record already exists for %s%s",
887 imsi, VTY_NEWLINE);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100888 return CMD_WARNING;
889 }
890
Jacob Erlbeckd9193432015-01-19 14:11:46 +0100891 subscr = gprs_subscr_get_or_create(imsi);
892 subscr->keep_in_ram = 1;
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100893 gprs_subscr_put(subscr);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +0100894
895 return CMD_SUCCESS;
896}
897
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100898DEFUN(update_subscr_destroy, update_subscr_destroy_cmd,
899 UPDATE_SUBSCR_STR "destroy",
900 UPDATE_SUBSCR_HELP
901 "Destroy a subscriber entry\n")
902{
903 const char *imsi = argv[0];
904
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100905 struct gprs_subscr *subscr;
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100906
907 subscr = gprs_subscr_get_by_imsi(imsi);
908 if (!subscr) {
909 vty_out(vty, "%% subscriber record does not exist for %s%s",
910 imsi, VTY_NEWLINE);
911 return CMD_WARNING;
912 }
913
914 subscr->keep_in_ram = 0;
Jacob Erlbeck8000e0e2015-01-27 14:56:40 +0100915 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100916 gprs_subscr_cancel(subscr);
917 if (subscr->use_count > 1)
918 vty_out(vty, "%% subscriber is still in use%s",
919 VTY_NEWLINE);
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100920 gprs_subscr_put(subscr);
Jacob Erlbecke988ae42015-01-27 12:41:19 +0100921
922 return CMD_SUCCESS;
923}
924
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100925#define UL_ERR_STR "system-failure|data-missing|unexpected-data-value|" \
926 "unknown-subscriber|roaming-not-allowed"
927
928#define UL_ERR_HELP \
929 "Force error code SystemFailure\n" \
930 "Force error code DataMissing\n" \
931 "Force error code UnexpectedDataValue\n" \
932 "Force error code UnknownSubscriber\n" \
933 "Force error code RoamingNotAllowed\n"
934
935DEFUN(update_subscr_update_location_result, update_subscr_update_location_result_cmd,
936 UPDATE_SUBSCR_STR "update-location-result (ok|" UL_ERR_STR ")",
937 UPDATE_SUBSCR_HELP
938 "Complete the update location procedure\n"
939 "The update location request succeeded\n"
940 UL_ERR_HELP)
941{
942 const char *imsi = argv[0];
943 const char *ret_code_str = argv[1];
944
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100945 struct gprs_subscr *subscr;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100946
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100947 const struct value_string cause_mapping[] = {
948 { GMM_CAUSE_NET_FAIL, "system-failure" },
949 { GMM_CAUSE_INV_MAND_INFO, "data-missing" },
950 { GMM_CAUSE_PROTO_ERR_UNSPEC, "unexpected-data-value" },
951 { GMM_CAUSE_IMSI_UNKNOWN, "unknown-subscriber" },
952 { GMM_CAUSE_GPRS_NOTALLOWED, "roaming-not-allowed" },
953 { 0, NULL }
954 };
955
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100956 subscr = gprs_subscr_get_by_imsi(imsi);
957 if (!subscr) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100958 vty_out(vty, "%% unable to get subscriber record for %s%s",
959 imsi, VTY_NEWLINE);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100960 return CMD_WARNING;
961 }
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100962
963 if (strcmp(ret_code_str, "ok") == 0) {
964 subscr->sgsn_data->error_cause = SGSN_ERROR_CAUSE_NONE;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100965 subscr->authorized = 1;
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100966 } else {
967 subscr->sgsn_data->error_cause =
968 get_string_value(cause_mapping, ret_code_str);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100969 subscr->authorized = 0;
Jacob Erlbeckd6267d12015-01-19 11:10:04 +0100970 }
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100971
972 gprs_subscr_update(subscr);
973
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100974 gprs_subscr_put(subscr);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100975
976 return CMD_SUCCESS;
977}
978
979DEFUN(update_subscr_update_auth_info, update_subscr_update_auth_info_cmd,
980 UPDATE_SUBSCR_STR "update-auth-info",
981 UPDATE_SUBSCR_HELP
982 "Complete the send authentication info procedure\n")
983{
984 const char *imsi = argv[0];
985
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100986 struct gprs_subscr *subscr;
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100987
988 subscr = gprs_subscr_get_by_imsi(imsi);
989 if (!subscr) {
Jacob Erlbeck15cc8c82015-01-19 14:29:43 +0100990 vty_out(vty, "%% unable to get subscriber record for %s%s",
991 imsi, VTY_NEWLINE);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100992 return CMD_WARNING;
993 }
994
995 gprs_subscr_update_auth_info(subscr);
996
Neels Hofmeyr0e5d8072017-01-10 00:49:56 +0100997 gprs_subscr_put(subscr);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +0100998
999 return CMD_SUCCESS;
1000}
1001
Jacob Erlbeck39f040d2014-12-18 12:46:47 +01001002DEFUN(cfg_gsup_remote_ip, cfg_gsup_remote_ip_cmd,
1003 "gsup remote-ip A.B.C.D",
1004 "GSUP Parameters\n"
1005 "Set the IP address of the remote GSUP server\n"
1006 "IPv4 Address\n")
1007{
1008 inet_aton(argv[0], &g_cfg->gsup_server_addr.sin_addr);
1009
1010 return CMD_SUCCESS;
1011}
1012
1013DEFUN(cfg_gsup_remote_port, cfg_gsup_remote_port_cmd,
1014 "gsup remote-port <0-65535>",
1015 "GSUP Parameters\n"
1016 "Set the TCP port of the remote GSUP server\n"
1017 "Remote TCP port\n")
1018{
1019 g_cfg->gsup_server_port = atoi(argv[0]);
1020
1021 return CMD_SUCCESS;
1022}
1023
Neels Hofmeyr568a7272015-10-12 11:57:38 +02001024DEFUN(cfg_gsup_oap_id, cfg_gsup_oap_id_cmd,
1025 "gsup oap-id <0-65535>",
1026 "GSUP Parameters\n"
1027 "Set the SGSN's OAP client ID\nOAP client ID (0 == disabled)\n")
1028{
1029 /* VTY ensures range */
1030 g_cfg->oap.client_id = (uint16_t)atoi(argv[0]);
1031 return CMD_SUCCESS;
1032}
1033
1034DEFUN(cfg_gsup_oap_k, cfg_gsup_oap_k_cmd,
1035 "gsup oap-k K",
1036 "GSUP Parameters\n"
1037 "Set the OAP shared secret K\nK value (16 byte) hex\n")
1038{
1039 const char *k = argv[0];
1040
1041 g_cfg->oap.secret_k_present = 0;
1042
1043 if ((!k) || (strlen(k) == 0))
1044 goto disable;
1045
1046 int k_len = osmo_hexparse(k,
1047 g_cfg->oap.secret_k,
1048 sizeof(g_cfg->oap.secret_k));
1049 if (k_len != 16) {
1050 vty_out(vty, "%% need exactly 16 octets for oap-k, got %d.%s",
1051 k_len, VTY_NEWLINE);
1052 goto disable;
1053 }
1054
1055 g_cfg->oap.secret_k_present = 1;
1056 return CMD_SUCCESS;
1057
1058disable:
1059 if (g_cfg->oap.client_id > 0) {
1060 vty_out(vty, "%% OAP client ID set, but invalid oap-k value disables OAP.%s",
1061 VTY_NEWLINE);
1062 return CMD_WARNING;
1063 }
1064 return CMD_SUCCESS;
1065}
1066
1067DEFUN(cfg_gsup_oap_opc, cfg_gsup_oap_opc_cmd,
1068 "gsup oap-opc OPC",
1069 "GSUP Parameters\n"
1070 "Set the OAP shared secret OPC\nOPC value (16 byte) hex\n")
1071{
1072 const char *opc = argv[0];
1073
1074 g_cfg->oap.secret_opc_present = 0;
1075
1076 if ((!opc) || (strlen(opc) == 0))
1077 goto disable;
1078
1079 int opc_len = osmo_hexparse(opc,
1080 g_cfg->oap.secret_opc,
1081 sizeof(g_cfg->oap.secret_opc));
1082 if (opc_len != 16) {
1083 vty_out(vty, "%% need exactly 16 octets for oap-opc, got %d.%s",
1084 opc_len, VTY_NEWLINE);
1085 goto disable;
1086 }
1087
1088 g_cfg->oap.secret_opc_present = 1;
1089 return CMD_SUCCESS;
1090
1091disable:
1092 if (g_cfg->oap.client_id > 0) {
1093 vty_out(vty, "%% OAP client ID set, but invalid oap-opc value disables OAP.%s",
1094 VTY_NEWLINE);
1095 return CMD_WARNING;
1096 }
1097 return CMD_SUCCESS;
1098}
1099
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001100DEFUN(cfg_apn_name, cfg_apn_name_cmd,
1101 "access-point-name NAME",
1102 "Configure a global list of allowed APNs\n"
1103 "Add this NAME to the list\n")
1104{
1105 return add_apn_ggsn_mapping(vty, argv[0], "", 0);
1106}
1107
1108DEFUN(cfg_no_apn_name, cfg_no_apn_name_cmd,
1109 "no access-point-name NAME",
1110 NO_STR "Configure a global list of allowed APNs\n"
1111 "Remove entry with NAME\n")
1112{
1113 struct apn_ctx *apn_ctx = sgsn_apn_ctx_by_name(argv[0], "");
1114 if (!apn_ctx)
1115 return CMD_SUCCESS;
1116
1117 sgsn_apn_ctx_free(apn_ctx);
1118 return CMD_SUCCESS;
1119}
1120
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001121DEFUN(cfg_cdr_filename, cfg_cdr_filename_cmd,
1122 "cdr filename NAME",
1123 "CDR\nSet filename\nname\n")
1124{
1125 talloc_free(g_cfg->cdr.filename);
1126 g_cfg->cdr.filename = talloc_strdup(tall_vty_ctx, argv[0]);
1127 return CMD_SUCCESS;
1128}
1129
1130DEFUN(cfg_no_cdr_filename, cfg_no_cdr_filename_cmd,
1131 "no cdr filename",
1132 NO_STR "CDR\nDisable CDR generation\n")
1133{
1134 talloc_free(g_cfg->cdr.filename);
1135 g_cfg->cdr.filename = NULL;
1136 return CMD_SUCCESS;
1137}
1138
1139DEFUN(cfg_cdr_interval, cfg_cdr_interval_cmd,
1140 "cdr interval <1-2147483647>",
1141 "CDR\nPDP periodic log interval\nSeconds\n")
1142{
1143 g_cfg->cdr.interval = atoi(argv[0]);
1144 return CMD_SUCCESS;
1145}
1146
Philippf1f34362016-08-26 17:00:21 +02001147#define COMPRESSION_STR "Configure compression\n"
1148DEFUN(cfg_no_comp_rfc1144, cfg_no_comp_rfc1144_cmd,
1149 "no compression rfc1144",
1150 NO_STR COMPRESSION_STR "disable rfc1144 TCP/IP header compression\n")
1151{
1152 g_cfg->pcomp_rfc1144.active = 0;
1153 g_cfg->pcomp_rfc1144.passive = 0;
1154 return CMD_SUCCESS;
1155}
1156
1157DEFUN(cfg_comp_rfc1144, cfg_comp_rfc1144_cmd,
1158 "compression rfc1144 active slots <1-256>",
1159 COMPRESSION_STR
1160 "RFC1144 Header compresion scheme\n"
1161 "Compression is actively proposed\n"
1162 "Number of compression state slots\n"
1163 "Number of compression state slots\n")
1164{
1165 g_cfg->pcomp_rfc1144.active = 1;
1166 g_cfg->pcomp_rfc1144.passive = 1;
1167 g_cfg->pcomp_rfc1144.s01 = atoi(argv[0]) - 1;
1168 return CMD_SUCCESS;
1169}
1170
1171DEFUN(cfg_comp_rfc1144p, cfg_comp_rfc1144p_cmd,
1172 "compression rfc1144 passive",
1173 COMPRESSION_STR
1174 "RFC1144 Header compresion scheme\n"
1175 "Compression is available on request\n")
1176{
1177 g_cfg->pcomp_rfc1144.active = 0;
1178 g_cfg->pcomp_rfc1144.passive = 1;
1179 return CMD_SUCCESS;
1180}
1181
Philipp73f83d52016-09-02 13:38:01 +02001182DEFUN(cfg_no_comp_v42bis, cfg_no_comp_v42bis_cmd,
1183 "no compression v42bis",
1184 NO_STR COMPRESSION_STR "disable V.42bis data compression\n")
1185{
1186 g_cfg->dcomp_v42bis.active = 0;
1187 g_cfg->dcomp_v42bis.passive = 0;
1188 return CMD_SUCCESS;
1189}
1190
1191DEFUN(cfg_comp_v42bis, cfg_comp_v42bis_cmd,
1192 "compression v42bis active direction (ms|sgsn|both) codewords <512-65535> strlen <6-250>",
1193 COMPRESSION_STR
1194 "V.42bis data compresion scheme\n"
1195 "Compression is actively proposed\n"
1196 "Direction in which the compression shall be active (p0)\n"
1197 "Compress ms->sgsn direction only\n"
1198 "Compress sgsn->ms direction only\n"
1199 "Both directions\n"
1200 "Number of codewords (p1)\n"
1201 "Number of codewords\n"
1202 "Maximum string length (p2)\n" "Maximum string length\n")
1203{
1204 g_cfg->dcomp_v42bis.active = 1;
1205 g_cfg->dcomp_v42bis.passive = 1;
1206
1207 switch (argv[0][0]) {
1208 case 'm':
1209 g_cfg->dcomp_v42bis.p0 = 1;
1210 break;
1211 case 's':
1212 g_cfg->dcomp_v42bis.p0 = 2;
1213 break;
1214 case 'b':
1215 g_cfg->dcomp_v42bis.p0 = 3;
1216 break;
1217 }
1218
1219 g_cfg->dcomp_v42bis.p1 = atoi(argv[1]);
1220 g_cfg->dcomp_v42bis.p2 = atoi(argv[2]);
1221 return CMD_SUCCESS;
1222}
1223
1224DEFUN(cfg_comp_v42bisp, cfg_comp_v42bisp_cmd,
1225 "compression v42bis passive",
1226 COMPRESSION_STR
1227 "V.42bis data compresion scheme\n"
1228 "Compression is available on request\n")
1229{
1230 g_cfg->dcomp_v42bis.active = 0;
1231 g_cfg->dcomp_v42bis.passive = 1;
1232 return CMD_SUCCESS;
1233}
1234
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +02001235int sgsn_vty_init(struct sgsn_config *cfg)
Harald Welte288be162010-05-01 16:48:27 +02001236{
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +02001237 g_cfg = cfg;
1238
Harald Welted193cb32010-05-17 22:58:03 +02001239 install_element_ve(&show_sgsn_cmd);
1240 //install_element_ve(&show_mmctx_tlli_cmd);
1241 install_element_ve(&show_mmctx_imsi_cmd);
1242 install_element_ve(&show_mmctx_all_cmd);
1243 install_element_ve(&show_pdpctx_all_cmd);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001244 install_element_ve(&show_subscr_cache_cmd);
1245
Jacob Erlbeck7921ab12014-12-08 15:52:00 +01001246 install_element(ENABLE_NODE, &update_subscr_insert_auth_triplet_cmd);
Jacob Erlbeckd9193432015-01-19 14:11:46 +01001247 install_element(ENABLE_NODE, &update_subscr_create_cmd);
Jacob Erlbecke988ae42015-01-27 12:41:19 +01001248 install_element(ENABLE_NODE, &update_subscr_destroy_cmd);
Jacob Erlbeck207f4a52014-11-11 14:01:48 +01001249 install_element(ENABLE_NODE, &update_subscr_cancel_cmd);
Jacob Erlbeck98a95ac2014-11-28 14:55:25 +01001250 install_element(ENABLE_NODE, &update_subscr_update_location_result_cmd);
1251 install_element(ENABLE_NODE, &update_subscr_update_auth_info_cmd);
Harald Welte288be162010-05-01 16:48:27 +02001252
1253 install_element(CONFIG_NODE, &cfg_sgsn_cmd);
1254 install_node(&sgsn_node, config_write_sgsn);
Jacob Erlbeck36722e12013-10-29 09:30:30 +01001255 vty_install_default(SGSN_NODE);
Harald Weltee300d002010-06-02 12:41:34 +02001256 install_element(SGSN_NODE, &cfg_sgsn_bind_addr_cmd);
Harald Welted193cb32010-05-17 22:58:03 +02001257 install_element(SGSN_NODE, &cfg_ggsn_remote_ip_cmd);
1258 //install_element(SGSN_NODE, &cfg_ggsn_remote_port_cmd);
1259 install_element(SGSN_NODE, &cfg_ggsn_gtp_version_cmd);
Harald Welte7f6da482013-03-19 11:00:13 +01001260 install_element(SGSN_NODE, &cfg_imsi_acl_cmd);
Harald Welte3dfb5492013-03-19 11:48:54 +01001261 install_element(SGSN_NODE, &cfg_auth_policy_cmd);
Max93408ae2016-06-28 14:10:16 +02001262 install_element(SGSN_NODE, &cfg_encrypt_cmd);
Jacob Erlbeck39f040d2014-12-18 12:46:47 +01001263 install_element(SGSN_NODE, &cfg_gsup_remote_ip_cmd);
1264 install_element(SGSN_NODE, &cfg_gsup_remote_port_cmd);
Neels Hofmeyr568a7272015-10-12 11:57:38 +02001265 install_element(SGSN_NODE, &cfg_gsup_oap_id_cmd);
1266 install_element(SGSN_NODE, &cfg_gsup_oap_k_cmd);
1267 install_element(SGSN_NODE, &cfg_gsup_oap_opc_cmd);
Jacob Erlbeckcb1db8b2015-02-03 13:47:53 +01001268 install_element(SGSN_NODE, &cfg_apn_ggsn_cmd);
1269 install_element(SGSN_NODE, &cfg_apn_imsi_ggsn_cmd);
Holger Hans Peter Freyther9c20a5f2015-02-06 16:23:29 +01001270 install_element(SGSN_NODE, &cfg_apn_name_cmd);
1271 install_element(SGSN_NODE, &cfg_no_apn_name_cmd);
Holger Hans Peter Freytherc15c61c2015-05-06 17:46:08 +02001272 install_element(SGSN_NODE, &cfg_cdr_filename_cmd);
1273 install_element(SGSN_NODE, &cfg_no_cdr_filename_cmd);
1274 install_element(SGSN_NODE, &cfg_cdr_interval_cmd);
Holger Hans Peter Freyther39c430e2015-05-25 12:26:49 +08001275 install_element(SGSN_NODE, &cfg_ggsn_dynamic_lookup_cmd);
Holger Hans Peter Freythera5a6da42015-05-25 15:20:27 +08001276 install_element(SGSN_NODE, &cfg_grx_ggsn_cmd);
Harald Welte288be162010-05-01 16:48:27 +02001277
Harald Welte94508822015-08-15 19:08:21 +02001278 install_element(SGSN_NODE, &cfg_sgsn_T3312_cmd);
1279 install_element(SGSN_NODE, &cfg_sgsn_T3322_cmd);
1280 install_element(SGSN_NODE, &cfg_sgsn_T3350_cmd);
1281 install_element(SGSN_NODE, &cfg_sgsn_T3360_cmd);
1282 install_element(SGSN_NODE, &cfg_sgsn_T3370_cmd);
1283 install_element(SGSN_NODE, &cfg_sgsn_T3313_cmd);
1284 install_element(SGSN_NODE, &cfg_sgsn_T3314_cmd);
1285 install_element(SGSN_NODE, &cfg_sgsn_T3316_cmd);
1286 install_element(SGSN_NODE, &cfg_sgsn_T3385_cmd);
1287 install_element(SGSN_NODE, &cfg_sgsn_T3386_cmd);
1288 install_element(SGSN_NODE, &cfg_sgsn_T3395_cmd);
1289 install_element(SGSN_NODE, &cfg_sgsn_T3397_cmd);
1290
Philippf1f34362016-08-26 17:00:21 +02001291 install_element(SGSN_NODE, &cfg_no_comp_rfc1144_cmd);
1292 install_element(SGSN_NODE, &cfg_comp_rfc1144_cmd);
1293 install_element(SGSN_NODE, &cfg_comp_rfc1144p_cmd);
Philipp73f83d52016-09-02 13:38:01 +02001294 install_element(SGSN_NODE, &cfg_no_comp_v42bis_cmd);
1295 install_element(SGSN_NODE, &cfg_comp_v42bis_cmd);
1296 install_element(SGSN_NODE, &cfg_comp_v42bisp_cmd);
Neels Hofmeyr2188a772016-05-20 21:59:55 +02001297
1298#ifdef BUILD_IU
1299 iu_vty_init(SGSN_NODE, &g_cfg->iu.rab_assign_addr_enc);
1300#endif
Harald Welte288be162010-05-01 16:48:27 +02001301 return 0;
1302}
1303
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +02001304int sgsn_parse_config(const char *config_file)
Harald Welte288be162010-05-01 16:48:27 +02001305{
1306 int rc;
1307
Neels Hofmeyrc9a352f2017-07-20 14:41:20 +02001308 /* make sure sgsn_vty_init() was called before this */
1309 OSMO_ASSERT(g_cfg);
Harald Welte7f6da482013-03-19 11:00:13 +01001310
Harald Welte94508822015-08-15 19:08:21 +02001311 g_cfg->timers.T3312 = GSM0408_T3312_SECS;
1312 g_cfg->timers.T3322 = GSM0408_T3322_SECS;
1313 g_cfg->timers.T3350 = GSM0408_T3350_SECS;
1314 g_cfg->timers.T3360 = GSM0408_T3360_SECS;
1315 g_cfg->timers.T3370 = GSM0408_T3370_SECS;
1316 g_cfg->timers.T3313 = GSM0408_T3313_SECS;
1317 g_cfg->timers.T3314 = GSM0408_T3314_SECS;
1318 g_cfg->timers.T3316 = GSM0408_T3316_SECS;
1319 g_cfg->timers.T3385 = GSM0408_T3385_SECS;
1320 g_cfg->timers.T3386 = GSM0408_T3386_SECS;
1321 g_cfg->timers.T3395 = GSM0408_T3395_SECS;
1322 g_cfg->timers.T3397 = GSM0408_T3397_SECS;
1323
Harald Weltedcccb182010-05-16 20:52:23 +02001324 rc = vty_read_config_file(config_file, NULL);
Harald Welte288be162010-05-01 16:48:27 +02001325 if (rc < 0) {
1326 fprintf(stderr, "Failed to parse the config file: '%s'\n", config_file);
1327 return rc;
1328 }
1329
Neels Hofmeyr27355c92017-02-24 06:28:31 +01001330 if (g_cfg->auth_policy == SGSN_AUTH_POLICY_REMOTE
1331 && !(g_cfg->gsup_server_addr.sin_addr.s_addr
1332 && g_cfg->gsup_server_port)) {
1333 fprintf(stderr, "Configuration error:"
1334 " 'auth-policy remote' requires both"
1335 " 'gsup remote-ip' and 'gsup remote-port'\n");
1336 return -EINVAL;
1337 }
1338
Harald Welte288be162010-05-01 16:48:27 +02001339 return 0;
1340}