2010-03-14 07:45:01 +00:00
|
|
|
/* GPRS SGSN functionality */
|
|
|
|
|
|
|
|
/* (C) 2009 by Harald Welte <laforge@gnumonks.org>
|
|
|
|
*
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2010-05-02 09:26:34 +00:00
|
|
|
#include <stdint.h>
|
2010-03-14 07:45:01 +00:00
|
|
|
|
|
|
|
#include <osmocore/linuxlist.h>
|
|
|
|
#include <osmocore/talloc.h>
|
|
|
|
#include <osmocore/timer.h>
|
|
|
|
#include <openbsc/gsm_subscriber.h>
|
2010-04-26 17:18:54 +00:00
|
|
|
#include <openbsc/debug.h>
|
2010-03-14 07:45:01 +00:00
|
|
|
#include <openbsc/gprs_sgsn.h>
|
2010-04-26 17:18:54 +00:00
|
|
|
#include <openbsc/gprs_ns.h>
|
|
|
|
#include <openbsc/gprs_bssgp.h>
|
2010-03-14 07:45:01 +00:00
|
|
|
|
|
|
|
static LLIST_HEAD(sgsn_mm_ctxts);
|
|
|
|
|
|
|
|
static int ra_id_equals(const struct gprs_ra_id *id1,
|
|
|
|
const struct gprs_ra_id *id2)
|
|
|
|
{
|
|
|
|
return (id1->mcc == id2->mcc && id1->mnc == id2->mnc &&
|
|
|
|
id1->lac == id2->lac && id1->rac == id2->rac);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* look-up a SGSN MM context based on TLLI + RAI */
|
2010-05-02 09:26:34 +00:00
|
|
|
struct sgsn_mm_ctx *sgsn_mm_ctx_by_tlli(uint32_t tlli,
|
2010-03-14 07:45:01 +00:00
|
|
|
const struct gprs_ra_id *raid)
|
|
|
|
{
|
|
|
|
struct sgsn_mm_ctx *ctx;
|
|
|
|
|
|
|
|
llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
|
|
|
|
if (tlli == ctx->tlli &&
|
|
|
|
ra_id_equals(raid, &ctx->ra))
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2010-05-02 09:26:34 +00:00
|
|
|
struct sgsn_mm_ctx *sgsn_mm_ctx_by_ptmsi(uint32_t p_tmsi)
|
2010-03-14 07:45:01 +00:00
|
|
|
{
|
|
|
|
struct sgsn_mm_ctx *ctx;
|
|
|
|
|
|
|
|
llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
|
|
|
|
if (p_tmsi == ctx->p_tmsi)
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct sgsn_mm_ctx *sgsn_mm_ctx_by_imsi(const char *imsi)
|
|
|
|
{
|
|
|
|
struct sgsn_mm_ctx *ctx;
|
|
|
|
|
|
|
|
llist_for_each_entry(ctx, &sgsn_mm_ctxts, list) {
|
|
|
|
if (!strcmp(imsi, ctx->imsi))
|
|
|
|
return ctx;
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Allocate a new SGSN MM context */
|
2010-05-02 09:26:34 +00:00
|
|
|
struct sgsn_mm_ctx *sgsn_mm_ctx_alloc(uint32_t tlli,
|
2010-03-14 07:45:01 +00:00
|
|
|
const struct gprs_ra_id *raid)
|
|
|
|
{
|
2010-05-16 22:44:57 +00:00
|
|
|
struct sgsn_mm_ctx *ctx;
|
2010-03-14 07:45:01 +00:00
|
|
|
|
2010-05-16 22:44:57 +00:00
|
|
|
ctx = talloc_zero(tall_bsc_ctx, struct sgsn_mm_ctx);
|
2010-03-14 07:45:01 +00:00
|
|
|
if (!ctx)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memcpy(&ctx->ra, raid, sizeof(ctx->ra));
|
|
|
|
ctx->tlli = tlli;
|
|
|
|
ctx->mm_state = GMM_DEREGISTERED;
|
|
|
|
|
|
|
|
llist_add(&ctx->list, &sgsn_mm_ctxts);
|
|
|
|
|
|
|
|
return ctx;
|
|
|
|
}
|