2008-12-23 20:25:15 +00:00
|
|
|
/* Dummy implementation of a subscriber database, roghly HLR/VLR functionality */
|
|
|
|
|
|
|
|
/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
|
2009-01-01 18:02:05 +00:00
|
|
|
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
|
2008-12-25 23:28:35 +00:00
|
|
|
*
|
2008-12-23 20:25:15 +00:00
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2008-12-27 21:34:06 +00:00
|
|
|
#include <unistd.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <string.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2008-12-25 23:28:35 +00:00
|
|
|
#include <openbsc/gsm_subscriber.h>
|
2008-12-27 21:34:06 +00:00
|
|
|
#include <openbsc/db.h>
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
|
|
|
|
LLIST_HEAD(active_subscribers);
|
|
|
|
|
2008-12-27 21:34:06 +00:00
|
|
|
struct gsm_subscriber *subscr_alloc(void)
|
|
|
|
{
|
|
|
|
struct gsm_subscriber *s;
|
|
|
|
|
|
|
|
s = malloc(sizeof(struct gsm_subscriber));
|
|
|
|
if (!s)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
memset(s, 0, sizeof(*s));
|
2009-01-01 18:02:05 +00:00
|
|
|
llist_add_tail(&s->entry, &active_subscribers);
|
|
|
|
s->use_count = 1;
|
2008-12-27 21:34:06 +00:00
|
|
|
|
|
|
|
return s;
|
|
|
|
}
|
2008-12-23 20:25:15 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
static void subscr_free(struct gsm_subscriber *subscr)
|
2008-12-23 20:25:15 +00:00
|
|
|
{
|
2009-01-01 18:02:05 +00:00
|
|
|
llist_del(&subscr->entry);
|
2008-12-27 21:34:06 +00:00
|
|
|
free(subscr);
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|
2008-12-27 21:34:06 +00:00
|
|
|
|
2009-01-04 03:47:05 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_tmsi(const char *tmsi)
|
2008-12-23 20:25:15 +00:00
|
|
|
{
|
2009-01-01 18:02:05 +00:00
|
|
|
struct gsm_subscriber *subscr;
|
2008-12-27 21:34:06 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
/* we might have a record in memory already */
|
|
|
|
llist_for_each_entry(subscr, &active_subscribers, entry) {
|
|
|
|
if (strcmp(subscr->tmsi, tmsi) == 0)
|
|
|
|
return subscr_get(subscr);
|
2008-12-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
return db_get_subscriber(GSM_SUBSCRIBER_TMSI, tmsi);
|
2008-12-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-04 03:47:05 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_imsi(const char *imsi)
|
2008-12-27 21:34:06 +00:00
|
|
|
{
|
2009-01-01 18:02:05 +00:00
|
|
|
struct gsm_subscriber *subscr;
|
2008-12-27 21:34:06 +00:00
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
llist_for_each_entry(subscr, &active_subscribers, entry) {
|
|
|
|
if (strcmp(subscr->imsi, imsi) == 0)
|
|
|
|
return subscr_get(subscr);
|
2008-12-27 21:34:06 +00:00
|
|
|
}
|
|
|
|
|
2009-01-01 18:02:05 +00:00
|
|
|
return db_get_subscriber(GSM_SUBSCRIBER_IMSI, imsi);
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|
|
|
|
|
2009-02-09 23:39:20 +00:00
|
|
|
struct gsm_subscriber *subscr_get_by_extension(const char *ext)
|
|
|
|
{
|
|
|
|
struct gsm_subscriber *subscr;
|
|
|
|
|
|
|
|
llist_for_each_entry(subscr, &active_subscribers, entry) {
|
|
|
|
if (strcmp(subscr->extension, ext) == 0)
|
|
|
|
return subscr_get(subscr);
|
|
|
|
}
|
|
|
|
|
|
|
|
return db_get_subscriber(GSM_SUBSCRIBER_EXTENSION, ext);
|
|
|
|
}
|
|
|
|
|
2008-12-23 20:25:15 +00:00
|
|
|
int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts)
|
|
|
|
{
|
2009-01-01 18:02:05 +00:00
|
|
|
return db_sync_subscriber(s);
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr)
|
|
|
|
{
|
|
|
|
subscr->use_count++;
|
|
|
|
return subscr;
|
|
|
|
}
|
|
|
|
|
|
|
|
struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr)
|
|
|
|
{
|
|
|
|
if (--subscr->use_count <= 0)
|
|
|
|
subscr_free(subscr);
|
|
|
|
return NULL;
|
2008-12-23 20:25:15 +00:00
|
|
|
}
|