blob: dd7e008b1d84604e8da17d6863fc98388d6939d3 [file] [log] [blame]
Harald Welte75bb8202010-03-14 15:45:01 +08001/* GPRS SGSN functionality */
2
3/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
4 *
5 * All Rights Reserved
6 *
7 * This program is free software; you can redistribute it and/or modify
Harald Welte0e3e88e2011-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 Welte75bb8202010-03-14 15:45:01 +080010 * (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 Welte0e3e88e2011-01-01 15:25:50 +010015 * GNU Affero General Public License for more details.
Harald Welte75bb8202010-03-14 15:45:01 +080016 *
Harald Welte0e3e88e2011-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 Welte75bb8202010-03-14 15:45:01 +080019 *
20 */
21
Harald Welted85d9a92010-05-02 11:26:34 +020022#include <stdint.h>
Harald Welte75bb8202010-03-14 15:45:01 +080023
Pablo Neira Ayusodd5fff42011-03-22 16:47:59 +010024#include <osmocom/core/linuxlist.h>
25#include <osmocom/core/talloc.h>
26#include <osmocom/core/timer.h>
27#include <osmocom/core/rate_ctr.h>
Jacob Erlbeckd31596b2015-11-02 15:15:38 +010028#include <osmocom/core/stats.h>
Harald Welte095b3de2012-07-14 12:15:19 +020029#include <osmocom/core/backtrace.h>
Harald Weltecfb6b282012-06-16 14:59:56 +080030#include <osmocom/gprs/gprs_ns.h>
31#include <osmocom/gprs/gprs_bssgp.h>
Harald Welte35ade5e2016-04-20 17:11:43 +020032#include <osmocom/gsm/protocol/gsm_04_08_gprs.h>
Harald Weltecfb6b282012-06-16 14:59:56 +080033
Harald Welte75bb8202010-03-14 15:45:01 +080034#include <openbsc/gsm_subscriber.h>
Harald Weltef67a5f92010-04-26 19:18:54 +020035#include <openbsc/debug.h>
Harald Welte75bb8202010-03-14 15:45:01 +080036#include <openbsc/gprs_sgsn.h>
Harald Welteebe8a6d2010-05-18 19:58:38 +020037#include <openbsc/sgsn.h>
Harald Welte94ecef32010-12-24 21:13:26 +010038#include <openbsc/gprs_gmm.h>
Jacob Erlbeck3400f112015-02-02 18:03:05 +010039#include <openbsc/gprs_utils.h>
Holger Hans Peter Freytherf14098a2015-05-02 19:55:38 +020040#include <openbsc/signal.h>
Jacob Erlbeckd781c7a2014-10-13 10:32:00 +020041#include "openbsc/gprs_llc.h"
Daniel Willmann945f6082016-05-21 17:35:57 +020042#include <openbsc/iu.h>
Harald Welteebe8a6d2010-05-18 19:58:38 +020043
Neels Hofmeyraef31f72016-05-21 00:44:50 +020044#include <pdp.h>
45
Jacob Erlbecke6140d02015-01-23 11:33:51 +010046#include <time.h>
47
Daniel Willmannd7f6cdf2015-10-12 19:36:33 +020048#include <openssl/rand.h>
49
Jacob Erlbecke6140d02015-01-23 11:33:51 +010050#define GPRS_LLME_CHECK_TICK 30
51
Harald Welteebe8a6d2010-05-18 19:58:38 +020052extern struct sgsn_instance *sgsn;
Harald Welte75bb8202010-03-14 15:45:01 +080053
Harald Weltec1f6bfe2010-05-17 22:58:03 +020054LLIST_HEAD(sgsn_mm_ctxts);
55LLIST_HEAD(sgsn_ggsn_ctxts);
56LLIST_HEAD(sgsn_apn_ctxts);
57LLIST_HEAD(sgsn_pdp_ctxts);
Harald Welte75bb8202010-03-14 15:45:01 +080058
Harald Welte8a035af2010-05-18 10:57:45 +020059static const struct rate_ctr_desc mmctx_ctr_description[] = {
60 { "sign.packets.in", "Signalling Messages ( In)" },
61 { "sign.packets.out", "Signalling Messages (Out)" },
62 { "udata.packets.in", "User Data Messages ( In)" },
63 { "udata.packets.out", "User Data Messages (Out)" },
64 { "udata.bytes.in", "User Data Bytes ( In)" },
65 { "udata.bytes.out", "User Data Bytes (Out)" },
66 { "pdp_ctx_act", "PDP Context Activations " },
67 { "suspend", "SUSPEND Count " },
68 { "paging.ps", "Paging Packet Switched " },
69 { "paging.cs", "Paging Circuit Switched " },
70 { "ra_update", "Routing Area Update " },
71};
72
73static const struct rate_ctr_group_desc mmctx_ctrg_desc = {
74 .group_name_prefix = "sgsn.mmctx",
75 .group_description = "SGSN MM Context Statistics",
76 .num_ctr = ARRAY_SIZE(mmctx_ctr_description),
77 .ctr_desc = mmctx_ctr_description,
Jacob Erlbeckd31596b2015-11-02 15:15:38 +010078 .class_id = OSMO_STATS_CLASS_SUBSCRIBER,
Harald Welte8a035af2010-05-18 10:57:45 +020079};
80
Harald Welte0fe506b2010-06-10 00:20:12 +020081static const struct rate_ctr_desc pdpctx_ctr_description[] = {
82 { "udata.packets.in", "User Data Messages ( In)" },
83 { "udata.packets.out", "User Data Messages (Out)" },
84 { "udata.bytes.in", "User Data Bytes ( In)" },
85 { "udata.bytes.out", "User Data Bytes (Out)" },
86};
87
88static const struct rate_ctr_group_desc pdpctx_ctrg_desc = {
89 .group_name_prefix = "sgsn.pdpctx",
90 .group_description = "SGSN PDP Context Statistics",
91 .num_ctr = ARRAY_SIZE(pdpctx_ctr_description),
92 .ctr_desc = pdpctx_ctr_description,
Jacob Erlbeckd31596b2015-11-02 15:15:38 +010093 .class_id = OSMO_STATS_CLASS_SUBSCRIBER,
Harald Welte0fe506b2010-06-10 00:20:12 +020094};
95
Alexander Couzens32fdba02016-07-05 09:52:52 +020096static const struct rate_ctr_desc sgsn_ctr_description[] = {
Alexander Couzensb7d11e32016-07-05 11:04:27 +020097 { "llc.dl_bytes", "Count sent LLC bytes before giving it to the bssgp layer" },
98 { "llc.ul_bytes", "Count sucessful received LLC bytes (encrypt & fcs correct)" },
99 { "llc.dl_packets", "Count sucessful sent LLC packets before giving it to the bssgp layer" },
100 { "llc.ul_packets", "Count sucessful received LLC packets (encrypt & fcs correct)" },
Alexander Couzens32fdba02016-07-05 09:52:52 +0200101 { "gprs.attach_requested", "Received attach requests" },
102 { "gprs.attach_accepted", "Sent attach accepts" },
103 { "gprs.attach_rejected", "Sent attach rejects" },
104 { "gprs.detach_requested", "Received detach requests" },
105 { "gprs.detach_acked", "Sent detach acks" },
106 { "gprs.routing_area_requested", "Received routing area requests" },
107 { "gprs.routing_area_requested", "Sent routing area acks" },
108 { "gprs.routing_area_requested", "Sent routing area rejects" },
109 { "pdp.activate_requested", "Received activate requests" },
110 { "pdp.activate_rejected", "Sent activate rejects" },
111 { "pdp.activate_accepted", "Sent activate accepts" },
112 { "pdp.request_activated", "unused" },
113 { "pdp.request_activate_rejected", "unused" },
114 { "pdp.modify_requested", "unused" },
115 { "pdp.modify_accepted", "unused" },
116 { "pdp.dl_deactivate_requested", "Sent deactivate requests" },
117 { "pdp.dl_deactivate_accepted", "Sent deactivate accepted" },
118 { "pdp.ul_deactivate_requested", "Received deactivate requests" },
119 { "pdp.ul_deactivate_accepted", "Received deactivate accepts" },
120};
121
122static const struct rate_ctr_group_desc sgsn_ctrg_desc = {
123 "sgsn",
124 "SGSN Overall Statistics",
125 OSMO_STATS_CLASS_GLOBAL,
126 ARRAY_SIZE(sgsn_ctr_description),
127 sgsn_ctr_description,
128};
129
130void sgsn_rate_ctr_init() {
131 sgsn->rate_ctrs = rate_ctr_group_alloc(tall_bsc_ctx, &sgsn_ctrg_desc, 0);
132}
133
Daniel Willmann945f6082016-05-21 17:35:57 +0200134/* look-up an SGSN MM context based on Iu UE context (struct ue_conn_ctx)*/
135struct sgsn_mm_ctx *sgsn_mm_ctx_by_ue_ctx(const void *uectx)
136{
137 struct sgsn_mm_ctx *ctx;
138
139 llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
140 if (ctx->ran_type == MM_CTX_T_UTRAN_Iu
141 && uectx == ctx->iu.ue_ctx)
142 return ctx;
143 }
144
145 return NULL;
146}
147
Harald Welte75bb8202010-03-14 15:45:01 +0800148/* look-up a SGSN MM context based on TLLI + RAI */
Harald Welted85d9a92010-05-02 11:26:34 +0200149struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli,
Harald Welte75bb8202010-03-14 15:45:01 +0800150 const struct gprs_ra_id *raid)
151{
152 struct sgsn_mm_ctx *ctx;
153
154 llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
Harald Weltec28dc2f2015-12-25 19:12:21 +0100155 if ((tlli == ctx->gb.tlli || tlli == ctx->gb.tlli_new) &&
Jacob Erlbeckd6466c92016-01-04 18:43:34 +0100156 gprs_ra_id_equals(raid, &ctx->ra))
Harald Welte75bb8202010-03-14 15:45:01 +0800157 return ctx;
158 }
Harald Welteebe8a6d2010-05-18 19:58:38 +0200159
Harald Welte75bb8202010-03-14 15:45:01 +0800160 return NULL;
161}
162
Jacob Erlbeck556aa912016-01-04 18:43:38 +0100163struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli_and_ptmsi(uint32_t tlli,
164 const struct gprs_ra_id *raid)
165{
166 struct sgsn_mm_ctx *ctx;
167 int tlli_type;
168
169 /* TODO: Also check the P_TMSI signature to be safe. That signature
170 * should be different (at least with a sufficiently high probability)
171 * after SGSN restarts and for multiple SGSN instances.
172 */
173
174 tlli_type = gprs_tlli_type(tlli);
175 if (tlli_type != TLLI_FOREIGN && tlli_type != TLLI_LOCAL)
176 return NULL;
177
178 llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
179 if ((gprs_tmsi2tlli(ctx->p_tmsi, tlli_type) == tlli ||
180 gprs_tmsi2tlli(ctx->p_tmsi_old, tlli_type) == tlli) &&
181 gprs_ra_id_equals(raid, &ctx->ra))
182 return ctx;
183 }
184
185 return NULL;
186}
187
Harald Welted85d9a92010-05-02 11:26:34 +0200188struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t p_tmsi)
Harald Welte75bb8202010-03-14 15:45:01 +0800189{
190 struct sgsn_mm_ctx *ctx;
191
192 llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
Harald Welte7e01d8e2010-05-31 20:23:38 +0200193 if (p_tmsi == ctx->p_tmsi ||
194 (ctx->p_tmsi_old && ctx->p_tmsi_old == p_tmsi))
Harald Welte75bb8202010-03-14 15:45:01 +0800195 return ctx;
196 }
197 return NULL;
198}
199
200struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi)
201{
202 struct sgsn_mm_ctx *ctx;
203
204 llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
205 if (!strcmp(imsi, ctx->imsi))
206 return ctx;
207 }
208 return NULL;
209
210}
211
212/* Allocate a new SGSN MM context */
Harald Welted85d9a92010-05-02 11:26:34 +0200213struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t tlli,
Harald Welte75bb8202010-03-14 15:45:01 +0800214 const struct gprs_ra_id *raid)
215{
Harald Welte8f77f192010-05-17 00:44:57 +0200216 struct sgsn_mm_ctx *ctx;
Harald Welte75bb8202010-03-14 15:45:01 +0800217
Harald Welte8f77f192010-05-17 00:44:57 +0200218 ctx = talloc_zero(tall_bsc_ctx, struct sgsn_mm_ctx);
Harald Welte75bb8202010-03-14 15:45:01 +0800219 if (!ctx)
220 return NULL;
221
222 memcpy(&ctx->ra, raid, sizeof(ctx->ra));
Harald Weltec28dc2f2015-12-25 19:12:21 +0100223 ctx->ran_type = MM_CTX_T_GERAN_Gb;
224 ctx->gb.tlli = tlli;
Harald Welte75bb8202010-03-14 15:45:01 +0800225 ctx->mm_state = GMM_DEREGISTERED;
Jacob Erlbeck4d127672014-12-01 12:33:33 +0100226 ctx->auth_triplet.key_seq = GSM_KEY_SEQ_INVAL;
Max6d999582016-07-06 15:57:01 +0200227 ctx->ciph_algo = sgsn->cfg.cipher;
Harald Welte8a035af2010-05-18 10:57:45 +0200228 ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, tlli);
Harald Welteded83ec2010-05-18 12:44:45 +0200229 INIT_LLIST_HEAD(&ctx->pdp_list);
Harald Welte75bb8202010-03-14 15:45:01 +0800230
231 llist_add(&ctx->list, &sgsn_mm_ctxts);
232
233 return ctx;
234}
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200235
Daniel Willmann945f6082016-05-21 17:35:57 +0200236/* Allocate a new SGSN MM context */
237struct sgsn_mm_ctx *sgsn_mm_ctx_alloc_iu(void *uectx)
238{
239 struct sgsn_mm_ctx *ctx;
240
241 ctx = talloc_zero(tall_bsc_ctx, struct sgsn_mm_ctx);
242 if (!ctx)
243 return NULL;
244
245 ctx->ran_type = MM_CTX_T_UTRAN_Iu;
246 ctx->iu.ue_ctx = uectx;
Daniel Willmann522fee82016-05-21 00:16:55 +0200247 ctx->iu.new_key = 1;
Daniel Willmann945f6082016-05-21 17:35:57 +0200248 ctx->mm_state = GMM_DEREGISTERED;
249 ctx->auth_triplet.key_seq = GSM_KEY_SEQ_INVAL;
250 ctx->ctrg = rate_ctr_group_alloc(ctx, &mmctx_ctrg_desc, 0);
251
252 /* Need to get RAID from IU conn */
253 ctx->ra = ctx->iu.ue_ctx->ra_id;
254
255 INIT_LLIST_HEAD(&ctx->pdp_list);
256
257 llist_add(&ctx->list, &sgsn_mm_ctxts);
258
259 return ctx;
260}
261
262
Harald Welted8765b92012-07-14 12:04:04 +0200263/* this is a hard _free_ function, it doesn't clean up the PDP contexts
264 * in libgtp! */
Holger Hans Peter Freytherea2825a2015-05-03 11:46:58 +0200265static void sgsn_mm_ctx_free(struct sgsn_mm_ctx *mm)
Harald Weltec6e196f2010-12-24 23:07:18 +0100266{
267 struct sgsn_pdp_ctx *pdp, *pdp2;
268
Jacob Erlbeck70c177a2015-01-26 14:43:07 +0100269 /* Unlink from global list of MM contexts */
270 llist_del(&mm->list);
271
272 /* Free all PDP contexts */
273 llist_for_each_entry_safe(pdp, pdp2, &mm->pdp_list, list)
274 sgsn_pdp_ctx_free(pdp);
275
276 rate_ctr_group_free(mm->ctrg);
277
278 talloc_free(mm);
279}
280
281void sgsn_mm_ctx_cleanup_free(struct sgsn_mm_ctx *mm)
282{
Daniel Willmann8ddce122016-05-21 00:48:49 +0200283 struct gprs_llc_llme *llme = NULL;
Harald Weltec28dc2f2015-12-25 19:12:21 +0100284 uint32_t tlli = mm->gb.tlli;
Jacob Erlbeck70c177a2015-01-26 14:43:07 +0100285 struct sgsn_pdp_ctx *pdp, *pdp2;
Holger Hans Peter Freytherf14098a2015-05-02 19:55:38 +0200286 struct sgsn_signal_data sig_data;
Jacob Erlbeck70c177a2015-01-26 14:43:07 +0100287
Daniel Willmann8ddce122016-05-21 00:48:49 +0200288 if (mm->ran_type == MM_CTX_T_GERAN_Gb)
289 llme = mm->gb.llme;
290 else
291 OSMO_ASSERT(mm->gb.llme == NULL);
292
Holger Hans Peter Freyther2b1d49a2015-05-25 12:26:49 +0800293 /* Forget about ongoing look-ups */
294 if (mm->ggsn_lookup) {
295 LOGMMCTXP(LOGL_NOTICE, mm,
296 "Cleaning mmctx with on-going query.\n");
297 mm->ggsn_lookup->mmctx = NULL;
298 mm->ggsn_lookup = NULL;
299 }
300
Jacob Erlbeck70c177a2015-01-26 14:43:07 +0100301 /* delete all existing PDP contexts for this MS */
302 llist_for_each_entry_safe(pdp, pdp2, &mm->pdp_list, list) {
303 LOGMMCTXP(LOGL_NOTICE, mm,
304 "Dropping PDP context for NSAPI=%u\n", pdp->nsapi);
305 sgsn_pdp_ctx_terminate(pdp);
306 }
307
Jacob Erlbeck11493a22014-10-20 16:05:55 +0200308 if (osmo_timer_pending(&mm->timer)) {
309 LOGMMCTXP(LOGL_INFO, mm, "Cancelling MM timer %u\n", mm->T);
310 osmo_timer_del(&mm->timer);
311 }
312
Holger Hans Peter Freytherf14098a2015-05-02 19:55:38 +0200313 memset(&sig_data, 0, sizeof(sig_data));
314 sig_data.mm = mm;
315 osmo_signal_dispatch(SS_SGSN, S_SGSN_MM_FREE, &sig_data);
316
317
Jacob Erlbeckd04f7cc2014-11-12 10:18:09 +0100318 /* Detach from subscriber which is possibly freed then */
319 if (mm->subscr) {
Jacob Erlbeck480e8202015-01-26 13:41:11 +0100320 struct gsm_subscriber *subscr = subscr_get(mm->subscr);
Jacob Erlbecke71ab2f2015-01-26 11:07:24 +0100321 gprs_subscr_cleanup(subscr);
Jacob Erlbeck7a7d8812015-01-23 13:52:55 +0100322 subscr_put(subscr);
Jacob Erlbeckd04f7cc2014-11-12 10:18:09 +0100323 }
324
Jacob Erlbeck70c177a2015-01-26 14:43:07 +0100325 sgsn_mm_ctx_free(mm);
326 mm = NULL;
Harald Weltec6e196f2010-12-24 23:07:18 +0100327
Daniel Willmann8ddce122016-05-21 00:48:49 +0200328 if (llme) {
329 /* TLLI unassignment, must be called after sgsn_mm_ctx_free */
Maxeb64e3f2016-07-06 11:33:04 +0200330 gprs_llgmm_assign(llme, tlli, 0xffffffff);
Daniel Willmann8ddce122016-05-21 00:48:49 +0200331 }
Harald Weltec6e196f2010-12-24 23:07:18 +0100332}
Harald Welteeb471c92010-05-18 14:32:29 +0200333
Jacob Erlbeck70c177a2015-01-26 14:43:07 +0100334
Harald Welteff70e0e2010-06-03 06:37:26 +0200335/* look up PDP context by MM context and NSAPI */
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200336struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_nsapi(const struct sgsn_mm_ctx *mm,
337 uint8_t nsapi)
338{
339 struct sgsn_pdp_ctx *pdp;
340
341 llist_for_each_entry(pdp, &mm->pdp_list, list) {
342 if (pdp->nsapi == nsapi)
343 return pdp;
344 }
345 return NULL;
346}
347
Harald Welteff70e0e2010-06-03 06:37:26 +0200348/* look up PDP context by MM context and transaction ID */
Harald Welteeb471c92010-05-18 14:32:29 +0200349struct sgsn_pdp_ctx *sgsn_pdp_ctx_by_tid(const struct sgsn_mm_ctx *mm,
350 uint8_t tid)
351{
352 struct sgsn_pdp_ctx *pdp;
353
354 llist_for_each_entry(pdp, &mm->pdp_list, list) {
355 if (pdp->ti == tid)
356 return pdp;
357 }
358 return NULL;
359}
360
Harald Welted8765b92012-07-14 12:04:04 +0200361/* you don't want to use this directly, call sgsn_create_pdp_ctx() */
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200362struct sgsn_pdp_ctx *sgsn_pdp_ctx_alloc(struct sgsn_mm_ctx *mm,
363 uint8_t nsapi)
364{
365 struct sgsn_pdp_ctx *pdp;
366
367 pdp = sgsn_pdp_ctx_by_nsapi(mm, nsapi);
368 if (pdp)
369 return NULL;
370
371 pdp = talloc_zero(tall_bsc_ctx, struct sgsn_pdp_ctx);
372 if (!pdp)
373 return NULL;
374
375 pdp->mm = mm;
376 pdp->nsapi = nsapi;
Harald Welte0fe506b2010-06-10 00:20:12 +0200377 pdp->ctrg = rate_ctr_group_alloc(pdp, &pdpctx_ctrg_desc, nsapi);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200378 llist_add(&pdp->list, &mm->pdp_list);
379 llist_add(&pdp->g_list, &sgsn_pdp_ctxts);
380
381 return pdp;
382}
383
Jacob Erlbeckd781c7a2014-10-13 10:32:00 +0200384/*
385 * This function will not trigger any GSM DEACT PDP ACK messages, so you
386 * probably want to call sgsn_delete_pdp_ctx() instead if the connection
387 * isn't detached already.
388 */
389void sgsn_pdp_ctx_terminate(struct sgsn_pdp_ctx *pdp)
390{
Holger Hans Peter Freytherf14098a2015-05-02 19:55:38 +0200391 struct sgsn_signal_data sig_data;
392
Jacob Erlbeckd781c7a2014-10-13 10:32:00 +0200393 OSMO_ASSERT(pdp->mm != NULL);
394
395 /* There might still be pending callbacks in libgtp. So the parts of
396 * this object relevant to GTP need to remain intact in this case. */
397
398 LOGPDPCTXP(LOGL_INFO, pdp, "Forcing release of PDP context\n");
399
Daniel Willmann711adc22016-05-20 22:36:23 +0200400 if (pdp->mm->ran_type == MM_CTX_T_GERAN_Gb) {
401 /* Force the deactivation of the SNDCP layer */
402 sndcp_sm_deactivate_ind(&pdp->mm->gb.llme->lle[pdp->sapi], pdp->nsapi);
403 }
Jacob Erlbeckd781c7a2014-10-13 10:32:00 +0200404
Holger Hans Peter Freytherf14098a2015-05-02 19:55:38 +0200405 memset(&sig_data, 0, sizeof(sig_data));
406 sig_data.pdp = pdp;
407 osmo_signal_dispatch(SS_SGSN, S_SGSN_PDP_TERMINATE, &sig_data);
408
Jacob Erlbeckd781c7a2014-10-13 10:32:00 +0200409 /* Detach from MM context */
410 llist_del(&pdp->list);
411 pdp->mm = NULL;
412
413 sgsn_delete_pdp_ctx(pdp);
414}
415
416/*
417 * Don't call this function directly unless you know what you are doing.
418 * In normal conditions use sgsn_delete_pdp_ctx and in unspecified or
419 * implementation dependent abnormal ones sgsn_pdp_ctx_terminate.
420 */
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200421void sgsn_pdp_ctx_free(struct sgsn_pdp_ctx *pdp)
422{
Holger Hans Peter Freytherf14098a2015-05-02 19:55:38 +0200423 struct sgsn_signal_data sig_data;
424
425 memset(&sig_data, 0, sizeof(sig_data));
426 sig_data.pdp = pdp;
427 osmo_signal_dispatch(SS_SGSN, S_SGSN_PDP_FREE, &sig_data);
428
Harald Welte17a40a62010-06-28 18:57:21 +0200429 rate_ctr_group_free(pdp->ctrg);
Jacob Erlbeckd781c7a2014-10-13 10:32:00 +0200430 if (pdp->mm)
431 llist_del(&pdp->list);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200432 llist_del(&pdp->g_list);
Harald Welte095b3de2012-07-14 12:15:19 +0200433
434 /* _if_ we still have a library handle, at least set it to NULL
435 * to avoid any dereferences of the now-deleted PDP context from
436 * sgsn_libgtp:cb_data_ind() */
437 if (pdp->lib) {
438 struct pdp_t *lib = pdp->lib;
Daniel Willmannc9ac9732014-09-03 17:46:44 +0200439 LOGPDPCTXP(LOGL_NOTICE, pdp, "freeing PDP context that still "
Harald Welte095b3de2012-07-14 12:15:19 +0200440 "has a libgtp handle attached to it, this shouldn't "
441 "happen!\n");
442 osmo_generate_backtrace();
443 lib->priv = NULL;
444 }
445
Holger Hans Peter Freyther2b1d49a2015-05-25 12:26:49 +0800446 if (pdp->destroy_ggsn)
447 sgsn_ggsn_ctx_free(pdp->ggsn);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200448 talloc_free(pdp);
449}
450
451/* GGSN contexts */
452
Harald Welteeb471c92010-05-18 14:32:29 +0200453struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_alloc(uint32_t id)
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200454{
Harald Welteeb471c92010-05-18 14:32:29 +0200455 struct sgsn_ggsn_ctx *ggc;
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200456
Harald Welteeb471c92010-05-18 14:32:29 +0200457 ggc = talloc_zero(tall_bsc_ctx, struct sgsn_ggsn_ctx);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200458 if (!ggc)
459 return NULL;
460
461 ggc->id = id;
462 ggc->gtp_version = 1;
Harald Welte94ecef32010-12-24 21:13:26 +0100463 ggc->remote_restart_ctr = -1;
Harald Welteebe8a6d2010-05-18 19:58:38 +0200464 /* if we are called from config file parse, this gsn doesn't exist yet */
465 ggc->gsn = sgsn->gsn;
Harald Weltee58eee52010-05-18 18:39:00 +0200466 llist_add(&ggc->list, &sgsn_ggsn_ctxts);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200467
468 return ggc;
469}
470
Jacob Erlbecke3c935d2015-02-03 19:53:15 +0100471void sgsn_ggsn_ctx_free(struct sgsn_ggsn_ctx *ggc)
472{
473 llist_del(&ggc->list);
474 talloc_free(ggc);
475}
476
Harald Welteeb471c92010-05-18 14:32:29 +0200477struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_id(uint32_t id)
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200478{
Harald Welteeb471c92010-05-18 14:32:29 +0200479 struct sgsn_ggsn_ctx *ggc;
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200480
481 llist_for_each_entry(ggc, &sgsn_ggsn_ctxts, list) {
482 if (id == ggc->id)
483 return ggc;
484 }
485 return NULL;
486}
487
Harald Welte94ecef32010-12-24 21:13:26 +0100488struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_by_addr(struct in_addr *addr)
489{
490 struct sgsn_ggsn_ctx *ggc;
491
492 llist_for_each_entry(ggc, &sgsn_ggsn_ctxts, list) {
493 if (!memcmp(addr, &ggc->remote_addr, sizeof(*addr)))
494 return ggc;
495 }
496 return NULL;
497}
498
499
Harald Welteeb471c92010-05-18 14:32:29 +0200500struct sgsn_ggsn_ctx *sgsn_ggsn_ctx_find_alloc(uint32_t id)
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200501{
Harald Welteeb471c92010-05-18 14:32:29 +0200502 struct sgsn_ggsn_ctx *ggc;
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200503
Harald Welteeb471c92010-05-18 14:32:29 +0200504 ggc = sgsn_ggsn_ctx_by_id(id);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200505 if (!ggc)
Harald Welteeb471c92010-05-18 14:32:29 +0200506 ggc = sgsn_ggsn_ctx_alloc(id);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200507 return ggc;
508}
509
510/* APN contexts */
511
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100512static struct apn_ctx *sgsn_apn_ctx_alloc(const char *ap_name, const char *imsi_prefix)
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200513{
514 struct apn_ctx *actx;
515
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100516 actx = talloc_zero(tall_bsc_ctx, struct apn_ctx);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200517 if (!actx)
518 return NULL;
519 actx->name = talloc_strdup(actx, ap_name);
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100520 actx->imsi_prefix = talloc_strdup(actx, imsi_prefix);
521
522 llist_add_tail(&actx->list, &sgsn_apn_ctxts);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200523
524 return actx;
525}
526
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100527void sgsn_apn_ctx_free(struct apn_ctx *actx)
528{
529 llist_del(&actx->list);
530 talloc_free(actx);
531}
532
533struct apn_ctx *sgsn_apn_ctx_match(const char *name, const char *imsi)
534{
535 struct apn_ctx *actx;
536 struct apn_ctx *found_actx = NULL;
537 size_t imsi_prio = 0;
538 size_t name_prio = 0;
539 size_t name_req_len = strlen(name);
540
541 llist_for_each_entry(actx, &sgsn_apn_ctxts, list) {
542 size_t name_ref_len, imsi_ref_len;
543 const char *name_ref_start, *name_match_start;
544
545 imsi_ref_len = strlen(actx->imsi_prefix);
546 if (strncmp(actx->imsi_prefix, imsi, imsi_ref_len) != 0)
547 continue;
548
549 if (imsi_ref_len < imsi_prio)
550 continue;
551
552 /* IMSI matches */
553
554 name_ref_start = &actx->name[0];
555 if (name_ref_start[0] == '*') {
556 /* Suffix match */
557 name_ref_start += 1;
558 name_ref_len = strlen(name_ref_start);
559 if (name_ref_len > name_req_len)
560 continue;
561 } else {
562 name_ref_len = strlen(name_ref_start);
563 if (name_ref_len != name_req_len)
564 continue;
565 }
566
567 name_match_start = name + (name_req_len - name_ref_len);
568 if (strcasecmp(name_match_start, name_ref_start) != 0)
569 continue;
570
571 /* IMSI and name match */
572
573 if (imsi_ref_len == imsi_prio && name_ref_len < name_prio)
574 /* Lower priority, skip */
575 continue;
576
577 imsi_prio = imsi_ref_len;
578 name_prio = name_ref_len;
579 found_actx = actx;
580 }
581 return found_actx;
582}
583
584struct apn_ctx *sgsn_apn_ctx_by_name(const char *name, const char *imsi_prefix)
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200585{
586 struct apn_ctx *actx;
587
588 llist_for_each_entry(actx, &sgsn_apn_ctxts, list) {
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100589 if (strcasecmp(name, actx->name) == 0 &&
590 strcasecmp(imsi_prefix, actx->imsi_prefix) == 0)
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200591 return actx;
592 }
593 return NULL;
594}
595
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100596struct apn_ctx *sgsn_apn_ctx_find_alloc(const char *name, const char *imsi_prefix)
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200597{
598 struct apn_ctx *actx;
599
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100600 actx = sgsn_apn_ctx_by_name(name, imsi_prefix);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200601 if (!actx)
Jacob Erlbeck9b3ca642015-02-03 13:47:53 +0100602 actx = sgsn_apn_ctx_alloc(name, imsi_prefix);
Harald Weltec1f6bfe2010-05-17 22:58:03 +0200603
604 return actx;
605}
Harald Welte64df8ed2010-05-18 17:04:55 +0200606
607uint32_t sgsn_alloc_ptmsi(void)
608{
609 struct sgsn_mm_ctx *mm;
610 uint32_t ptmsi;
Jacob Erlbecke3aeb1e2015-01-15 18:51:31 +0100611 int max_retries = 100;
Harald Welte64df8ed2010-05-18 17:04:55 +0200612
613restart:
Daniel Willmannd7f6cdf2015-10-12 19:36:33 +0200614 if (RAND_bytes((uint8_t *) &ptmsi, sizeof(ptmsi)) != 1)
615 goto failed;
616
Jacob Erlbecke3aeb1e2015-01-15 18:51:31 +0100617 /* Enforce that the 2 MSB are set without loosing the distance between
618 * identical values. Since rand() has no duplicate values within a
619 * period (because the size of the state is the same like the size of
620 * the random value), this leads to a distance of period/4 when the
621 * distribution of the 2 MSB is uniform. This approach fails with a
622 * probability of (3/4)^max_retries, only 1% of the approaches will
623 * need more than 16 numbers (even distribution assumed).
624 *
625 * Alternatively, a freeze list could be used if another PRNG is used
626 * or when this approach proves to be not sufficient.
627 */
628 if (ptmsi >= 0xC0000000) {
629 if (!max_retries--)
630 goto failed;
631 goto restart;
632 }
633 ptmsi |= 0xC0000000;
634
635 if (ptmsi == GSM_RESERVED_TMSI) {
636 if (!max_retries--)
637 goto failed;
638 goto restart;
639 }
640
Harald Welte64df8ed2010-05-18 17:04:55 +0200641 llist_for_each_entry(mm, &sgsn_mm_ctxts, list) {
Jacob Erlbeck788de3e2014-09-19 09:28:42 +0200642 if (mm->p_tmsi == ptmsi) {
643 if (!max_retries--)
644 goto failed;
Harald Welte64df8ed2010-05-18 17:04:55 +0200645 goto restart;
Jacob Erlbeck788de3e2014-09-19 09:28:42 +0200646 }
Harald Welte64df8ed2010-05-18 17:04:55 +0200647 }
648
649 return ptmsi;
Jacob Erlbeck788de3e2014-09-19 09:28:42 +0200650
651failed:
652 LOGP(DGPRS, LOGL_ERROR, "Failed to allocate a P-TMSI\n");
653 return GSM_RESERVED_TMSI;
Harald Welte64df8ed2010-05-18 17:04:55 +0200654}
Harald Welte94ecef32010-12-24 21:13:26 +0100655
656static void drop_one_pdp(struct sgsn_pdp_ctx *pdp)
657{
658 if (pdp->mm->mm_state == GMM_REGISTERED_NORMAL)
659 gsm48_tx_gsm_deact_pdp_req(pdp, GSM_CAUSE_NET_FAIL);
660 else {
661 /* FIXME: GPRS paging in case MS is SUSPENDED */
Daniel Willmannc9ac9732014-09-03 17:46:44 +0200662 LOGPDPCTXP(LOGL_NOTICE, pdp, "Hard-dropping PDP ctx due to GGSN "
Harald Welte94ecef32010-12-24 21:13:26 +0100663 "recovery\n");
Harald Welted8765b92012-07-14 12:04:04 +0200664 /* FIXME: how to tell this to libgtp? */
Harald Welte94ecef32010-12-24 21:13:26 +0100665 sgsn_pdp_ctx_free(pdp);
666 }
667}
668
669/* High-level function to be called in case a GGSN has disappeared or
Holger Hans Peter Freytheredcefd52014-10-27 10:24:37 +0100670 * otherwise lost state (recovery procedure) */
Harald Welte94ecef32010-12-24 21:13:26 +0100671int drop_all_pdp_for_ggsn(struct sgsn_ggsn_ctx *ggsn)
672{
673 struct sgsn_mm_ctx *mm;
674 int num = 0;
675
676 llist_for_each_entry(mm, &sgsn_mm_ctxts, list) {
677 struct sgsn_pdp_ctx *pdp;
678 llist_for_each_entry(pdp, &mm->pdp_list, list) {
679 if (pdp->ggsn == ggsn) {
680 drop_one_pdp(pdp);
681 num++;
682 }
683 }
684 }
685
686 return num;
687}
Jacob Erlbeckccaa22a2014-09-05 14:32:36 +0200688
Jacob Erlbeck428f1ec2015-01-26 13:52:42 +0100689void sgsn_update_subscriber_data(struct sgsn_mm_ctx *mmctx)
Jacob Erlbeckc64af7a2014-10-24 18:09:54 +0200690{
Jacob Erlbeck428f1ec2015-01-26 13:52:42 +0100691 OSMO_ASSERT(mmctx != NULL);
Jacob Erlbeck0939c0f2014-12-18 09:53:07 +0100692 LOGMMCTXP(LOGL_INFO, mmctx, "Subscriber data update\n");
Jacob Erlbeckd04f7cc2014-11-12 10:18:09 +0100693
Jacob Erlbeckb2acd742014-11-13 10:48:39 +0100694 sgsn_auth_update(mmctx);
Jacob Erlbeckc64af7a2014-10-24 18:09:54 +0200695}
Jacob Erlbecke6140d02015-01-23 11:33:51 +0100696
Holger Hans Peter Freyther532b09d2015-04-23 11:33:35 -0400697static void insert_qos(struct tlv_parsed *tp, struct sgsn_subscriber_pdp_data *pdp)
698{
699 tp->lv[OSMO_IE_GSM_SUB_QOS].len = pdp->qos_subscribed_len;
700 tp->lv[OSMO_IE_GSM_SUB_QOS].val = pdp->qos_subscribed;
701}
702
703/**
704 * The tlv_parsed tp parameter will be modified to insert a
705 * OSMO_IE_GSM_SUB_QOS in case the data is available in the
706 * PDP context handling.
707 */
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100708struct sgsn_ggsn_ctx *sgsn_mm_ctx_find_ggsn_ctx(struct sgsn_mm_ctx *mmctx,
709 struct tlv_parsed *tp,
Holger Hans Peter Freyther2b1d49a2015-05-25 12:26:49 +0800710 enum gsm48_gsm_cause *gsm_cause,
711 char *out_apn_str)
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100712{
713 char req_apn_str[GSM_APN_LENGTH] = {0};
714 const struct apn_ctx *apn_ctx = NULL;
715 const char *selected_apn_str = NULL;
716 struct sgsn_subscriber_pdp_data *pdp;
717 struct sgsn_ggsn_ctx *ggsn = NULL;
718 int allow_any_apn = 0;
719
Holger Hans Peter Freyther2b1d49a2015-05-25 12:26:49 +0800720 out_apn_str[0] = '\0';
721
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100722 if (TLVP_PRESENT(tp, GSM48_IE_GSM_APN)) {
723 if (TLVP_LEN(tp, GSM48_IE_GSM_APN) >= GSM_APN_LENGTH - 1) {
724 LOGMMCTXP(LOGL_ERROR, mmctx, "APN IE too long\n");
725 *gsm_cause = GSM_CAUSE_INV_MAND_INFO;
726 return NULL;
727 }
728
729 gprs_apn_to_str(req_apn_str,
730 TLVP_VAL(tp, GSM48_IE_GSM_APN),
731 TLVP_LEN(tp, GSM48_IE_GSM_APN));
732
733 if (strcmp(req_apn_str, "*") == 0)
734 req_apn_str[0] = 0;
735 }
736
Holger Hans Peter Freytherab9422e2015-05-24 20:51:17 +0800737 if (mmctx->subscr == NULL)
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100738 allow_any_apn = 1;
739
740 if (strlen(req_apn_str) == 0 && !allow_any_apn) {
741 /* No specific APN requested, check for an APN that is both
742 * granted and configured */
743
744 llist_for_each_entry(pdp, &mmctx->subscr->sgsn_data->pdp_list, list) {
745 if (strcmp(pdp->apn_str, "*") == 0)
746 {
747 allow_any_apn = 1;
748 selected_apn_str = "";
Holger Hans Peter Freyther532b09d2015-04-23 11:33:35 -0400749 insert_qos(tp, pdp);
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100750 continue;
751 }
752 if (!llist_empty(&sgsn_apn_ctxts)) {
753 apn_ctx = sgsn_apn_ctx_match(req_apn_str, mmctx->imsi);
754 /* Not configured */
755 if (apn_ctx == NULL)
756 continue;
757 }
Holger Hans Peter Freyther532b09d2015-04-23 11:33:35 -0400758 insert_qos(tp, pdp);
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100759 selected_apn_str = pdp->apn_str;
760 break;
761 }
762 } else if (!allow_any_apn) {
763 /* Check whether the given APN is granted */
764 llist_for_each_entry(pdp, &mmctx->subscr->sgsn_data->pdp_list, list) {
765 if (strcmp(pdp->apn_str, "*") == 0) {
Holger Hans Peter Freyther532b09d2015-04-23 11:33:35 -0400766 insert_qos(tp, pdp);
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100767 selected_apn_str = req_apn_str;
768 allow_any_apn = 1;
769 continue;
770 }
771 if (strcasecmp(pdp->apn_str, req_apn_str) == 0) {
Holger Hans Peter Freyther532b09d2015-04-23 11:33:35 -0400772 insert_qos(tp, pdp);
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100773 selected_apn_str = req_apn_str;
774 break;
775 }
776 }
777 } else if (strlen(req_apn_str) != 0) {
778 /* Any APN is allowed */
779 selected_apn_str = req_apn_str;
780 } else {
781 /* Prefer the GGSN associated with the wildcard APN */
782 selected_apn_str = "";
783 }
784
785 if (!allow_any_apn && selected_apn_str == NULL) {
786 /* Access not granted */
787 LOGMMCTXP(LOGL_NOTICE, mmctx,
788 "The requested APN '%s' is not allowed\n",
789 req_apn_str);
790 *gsm_cause = GSM_CAUSE_REQ_SERV_OPT_NOTSUB;
791 return NULL;
792 }
793
Holger Hans Peter Freyther2b1d49a2015-05-25 12:26:49 +0800794 /* copy the selected apn_str */
Holger Hans Peter Freyther3332d0c2015-06-02 09:33:31 +0200795 if (selected_apn_str)
796 strcpy(out_apn_str, selected_apn_str);
797 else
798 out_apn_str[0] = '\0';
Holger Hans Peter Freyther2b1d49a2015-05-25 12:26:49 +0800799
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100800 if (apn_ctx == NULL && selected_apn_str)
801 apn_ctx = sgsn_apn_ctx_match(selected_apn_str, mmctx->imsi);
802
803 if (apn_ctx != NULL) {
804 ggsn = apn_ctx->ggsn;
805 } else if (llist_empty(&sgsn_apn_ctxts)) {
806 /* No configuration -> use GGSN 0 */
807 ggsn = sgsn_ggsn_ctx_by_id(0);
808 } else if (allow_any_apn &&
809 (selected_apn_str == NULL || strlen(selected_apn_str) == 0)) {
810 /* No APN given and no default configuration -> Use GGSN 0 */
811 ggsn = sgsn_ggsn_ctx_by_id(0);
812 } else {
813 /* No matching configuration found */
814 LOGMMCTXP(LOGL_NOTICE, mmctx,
815 "The selected APN '%s' has not been configured\n",
816 selected_apn_str);
817 *gsm_cause = GSM_CAUSE_MISSING_APN;
818 return NULL;
819 }
820
Holger Hans Peter Freythereaa58512015-05-25 14:35:10 +0800821 if (!ggsn) {
822 LOGMMCTXP(LOGL_NOTICE, mmctx,
823 "No static GGSN configured. Selected APN '%s'\n",
824 selected_apn_str);
825 return NULL;
826 }
827
Jacob Erlbeck3400f112015-02-02 18:03:05 +0100828 LOGMMCTXP(LOGL_INFO, mmctx,
829 "Found GGSN %d for APN '%s' (requested '%s')\n",
830 ggsn->id, selected_apn_str ? selected_apn_str : "---",
831 req_apn_str);
832
833 return ggsn;
834}
835
Jacob Erlbecke6140d02015-01-23 11:33:51 +0100836static void sgsn_llme_cleanup_free(struct gprs_llc_llme *llme)
837{
838 struct sgsn_mm_ctx *mmctx = NULL;
839
840 llist_for_each_entry(mmctx, &sgsn_mm_ctxts, list) {
Harald Weltec28dc2f2015-12-25 19:12:21 +0100841 if (llme == mmctx->gb.llme) {
Jacob Erlbecke6140d02015-01-23 11:33:51 +0100842 gsm0408_gprs_access_cancelled(mmctx, SGSN_ERROR_CAUSE_NONE);
843 return;
844 }
845 }
846
847 /* No MM context found */
848 LOGP(DGPRS, LOGL_INFO, "Deleting orphaned LLME, TLLI 0x%08x\n",
849 llme->tlli);
Maxa86f5c02016-06-28 17:39:20 +0200850 gprs_llgmm_unassign(llme);
Jacob Erlbecke6140d02015-01-23 11:33:51 +0100851}
852
853static void sgsn_llme_check_cb(void *data_)
854{
855 struct gprs_llc_llme *llme, *llme_tmp;
856 struct timespec now_tp;
857 time_t now, age;
858 time_t max_age = gprs_max_time_to_idle();
859
860 int rc;
861
862 rc = clock_gettime(CLOCK_MONOTONIC, &now_tp);
863 OSMO_ASSERT(rc >= 0);
864 now = now_tp.tv_sec;
865
866 LOGP(DGPRS, LOGL_DEBUG,
867 "Checking for inactive LLMEs, time = %u\n", (unsigned)now);
868
869 llist_for_each_entry_safe(llme, llme_tmp, &gprs_llc_llmes, list) {
870 if (llme->age_timestamp == GPRS_LLME_RESET_AGE)
871 llme->age_timestamp = now;
872
873 age = now - llme->age_timestamp;
874
875 if (age > max_age || age < 0) {
876 LOGP(DGPRS, LOGL_INFO,
877 "Inactivity timeout for TLLI 0x%08x, age %d\n",
878 llme->tlli, (int)age);
879 sgsn_llme_cleanup_free(llme);
880 }
881 }
882
883 osmo_timer_schedule(&sgsn->llme_timer, GPRS_LLME_CHECK_TICK, 0);
884}
885
886void sgsn_inst_init()
887{
888 sgsn->llme_timer.cb = sgsn_llme_check_cb;
889 sgsn->llme_timer.data = NULL;
890
891 osmo_timer_schedule(&sgsn->llme_timer, GPRS_LLME_CHECK_TICK, 0);
892}
893