From 3911880b68ddd92c9dd89d6ac20c26807e33f905 Mon Sep 17 00:00:00 2001 From: Jacob Erlbeck Date: Fri, 7 Nov 2014 14:07:48 +0100 Subject: bsc: Move gsm_subscriber_base.c to libcommon Since it is planned to use struct gsm_subscriber to manage subscriber data in the SGSN, this file which contains the generic subscriber related methods is moved to libcommon. Sponsored-by: On-Waves ehf --- openbsc/src/libbsc/Makefile.am | 1 - openbsc/src/libbsc/gsm_subscriber_base.c | 156 ---------------------------- openbsc/src/libcommon/Makefile.am | 4 +- openbsc/src/libcommon/gsm_subscriber_base.c | 156 ++++++++++++++++++++++++++++ openbsc/src/osmo-bsc_nat/Makefile.am | 3 +- openbsc/src/utils/Makefile.am | 4 +- 6 files changed, 163 insertions(+), 161 deletions(-) delete mode 100644 openbsc/src/libbsc/gsm_subscriber_base.c create mode 100644 openbsc/src/libcommon/gsm_subscriber_base.c (limited to 'openbsc/src') diff --git a/openbsc/src/libbsc/Makefile.am b/openbsc/src/libbsc/Makefile.am index 3588b6692..8fa5c7c1a 100644 --- a/openbsc/src/libbsc/Makefile.am +++ b/openbsc/src/libbsc/Makefile.am @@ -15,7 +15,6 @@ libbsc_a_SOURCES = abis_nm.c abis_nm_vty.c \ bts_unknown.c \ bts_sysmobts.c \ chan_alloc.c \ - gsm_subscriber_base.c \ handover_decision.c handover_logic.c meas_rep.c \ rest_octets.c system_information.c \ e1_config.c \ diff --git a/openbsc/src/libbsc/gsm_subscriber_base.c b/openbsc/src/libbsc/gsm_subscriber_base.c deleted file mode 100644 index 5e00443c2..000000000 --- a/openbsc/src/libbsc/gsm_subscriber_base.c +++ /dev/null @@ -1,156 +0,0 @@ -/* The concept of a subscriber as seen by the BSC */ - -/* (C) 2008 by Harald Welte - * (C) 2009-2010 by Holger Hans Peter Freyther - * (C) 2010 by On-Waves - * - * All Rights Reserved - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License as published by - * the Free Software Foundation; either version 3 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 Affero General Public License for more details. - * - * You should have received a copy of the GNU Affero General Public License - * along with this program. If not, see . - * - */ - -#include -#include -#include -#include -#include - -#include -#include -#include - -LLIST_HEAD(active_subscribers); -void *tall_subscr_ctx; - -/* for the gsm_subscriber.c */ -struct llist_head *subscr_bsc_active_subscribers(void) -{ - return &active_subscribers; -} - - -char *subscr_name(struct gsm_subscriber *subscr) -{ - if (strlen(subscr->name)) - return subscr->name; - - return subscr->imsi; -} - -struct gsm_subscriber *subscr_alloc(void) -{ - struct gsm_subscriber *s; - - s = talloc_zero(tall_subscr_ctx, struct gsm_subscriber); - if (!s) - return NULL; - - llist_add_tail(&s->entry, &active_subscribers); - s->use_count = 1; - s->tmsi = GSM_RESERVED_TMSI; - - INIT_LLIST_HEAD(&s->requests); - - return s; -} - -static void subscr_free(struct gsm_subscriber *subscr) -{ - llist_del(&subscr->entry); - talloc_free(subscr); -} - -void subscr_direct_free(struct gsm_subscriber *subscr) -{ - OSMO_ASSERT(subscr->use_count == 1); - subscr_free(subscr); -} - -struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr) -{ - subscr->use_count++; - DEBUGP(DREF, "subscr %s usage increases usage to: %d\n", - subscr->extension, subscr->use_count); - return subscr; -} - -struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr) -{ - subscr->use_count--; - DEBUGP(DREF, "subscr %s usage decreased usage to: %d\n", - subscr->extension, subscr->use_count); - if (subscr->use_count <= 0 && !subscr->net->keep_subscr) - subscr_free(subscr); - return NULL; -} - -struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net, - const char *imsi) -{ - struct gsm_subscriber *subscr; - - llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) { - if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net) - return subscr_get(subscr); - } - - subscr = subscr_alloc(); - if (!subscr) - return NULL; - - strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH); - subscr->imsi[GSM_IMSI_LENGTH - 1] = '\0'; - subscr->net = net; - return subscr; -} - -struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_network *net, uint32_t tmsi) -{ - struct gsm_subscriber *subscr; - - llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) { - if (subscr->tmsi == tmsi && subscr->net == net) - return subscr_get(subscr); - } - - return NULL; -} - -struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net, const char *imsi) -{ - struct gsm_subscriber *subscr; - - llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) { - if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net) - return subscr_get(subscr); - } - - return NULL; -} - -int subscr_purge_inactive(struct gsm_network *net) -{ - struct gsm_subscriber *subscr, *tmp; - int purged = 0; - - llist_for_each_entry_safe(subscr, tmp, subscr_bsc_active_subscribers(), entry) { - if (subscr->net == net && subscr->use_count <= 0) { - subscr_free(subscr); - purged += 1; - } - } - - return purged; -} diff --git a/openbsc/src/libcommon/Makefile.am b/openbsc/src/libcommon/Makefile.am index e41326f12..75f40eea7 100644 --- a/openbsc/src/libcommon/Makefile.am +++ b/openbsc/src/libcommon/Makefile.am @@ -4,4 +4,6 @@ AM_CFLAGS=-Wall $(LIBOSMOCORE_CFLAGS) $(LIBOSMOGSM_CFLAGS) \ noinst_LIBRARIES = libcommon.a -libcommon_a_SOURCES = bsc_version.c common_vty.c debug.c gsm_data.c gsm_data_shared.c socket.c talloc_ctx.c +libcommon_a_SOURCES = bsc_version.c common_vty.c debug.c gsm_data.c \ + gsm_data_shared.c socket.c talloc_ctx.c \ + gsm_subscriber_base.c diff --git a/openbsc/src/libcommon/gsm_subscriber_base.c b/openbsc/src/libcommon/gsm_subscriber_base.c new file mode 100644 index 000000000..5e00443c2 --- /dev/null +++ b/openbsc/src/libcommon/gsm_subscriber_base.c @@ -0,0 +1,156 @@ +/* The concept of a subscriber as seen by the BSC */ + +/* (C) 2008 by Harald Welte + * (C) 2009-2010 by Holger Hans Peter Freyther + * (C) 2010 by On-Waves + * + * All Rights Reserved + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU Affero General Public License as published by + * the Free Software Foundation; either version 3 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 Affero General Public License for more details. + * + * You should have received a copy of the GNU Affero General Public License + * along with this program. If not, see . + * + */ + +#include +#include +#include +#include +#include + +#include +#include +#include + +LLIST_HEAD(active_subscribers); +void *tall_subscr_ctx; + +/* for the gsm_subscriber.c */ +struct llist_head *subscr_bsc_active_subscribers(void) +{ + return &active_subscribers; +} + + +char *subscr_name(struct gsm_subscriber *subscr) +{ + if (strlen(subscr->name)) + return subscr->name; + + return subscr->imsi; +} + +struct gsm_subscriber *subscr_alloc(void) +{ + struct gsm_subscriber *s; + + s = talloc_zero(tall_subscr_ctx, struct gsm_subscriber); + if (!s) + return NULL; + + llist_add_tail(&s->entry, &active_subscribers); + s->use_count = 1; + s->tmsi = GSM_RESERVED_TMSI; + + INIT_LLIST_HEAD(&s->requests); + + return s; +} + +static void subscr_free(struct gsm_subscriber *subscr) +{ + llist_del(&subscr->entry); + talloc_free(subscr); +} + +void subscr_direct_free(struct gsm_subscriber *subscr) +{ + OSMO_ASSERT(subscr->use_count == 1); + subscr_free(subscr); +} + +struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr) +{ + subscr->use_count++; + DEBUGP(DREF, "subscr %s usage increases usage to: %d\n", + subscr->extension, subscr->use_count); + return subscr; +} + +struct gsm_subscriber *subscr_put(struct gsm_subscriber *subscr) +{ + subscr->use_count--; + DEBUGP(DREF, "subscr %s usage decreased usage to: %d\n", + subscr->extension, subscr->use_count); + if (subscr->use_count <= 0 && !subscr->net->keep_subscr) + subscr_free(subscr); + return NULL; +} + +struct gsm_subscriber *subscr_get_or_create(struct gsm_network *net, + const char *imsi) +{ + struct gsm_subscriber *subscr; + + llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) { + if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net) + return subscr_get(subscr); + } + + subscr = subscr_alloc(); + if (!subscr) + return NULL; + + strncpy(subscr->imsi, imsi, GSM_IMSI_LENGTH); + subscr->imsi[GSM_IMSI_LENGTH - 1] = '\0'; + subscr->net = net; + return subscr; +} + +struct gsm_subscriber *subscr_active_by_tmsi(struct gsm_network *net, uint32_t tmsi) +{ + struct gsm_subscriber *subscr; + + llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) { + if (subscr->tmsi == tmsi && subscr->net == net) + return subscr_get(subscr); + } + + return NULL; +} + +struct gsm_subscriber *subscr_active_by_imsi(struct gsm_network *net, const char *imsi) +{ + struct gsm_subscriber *subscr; + + llist_for_each_entry(subscr, subscr_bsc_active_subscribers(), entry) { + if (strcmp(subscr->imsi, imsi) == 0 && subscr->net == net) + return subscr_get(subscr); + } + + return NULL; +} + +int subscr_purge_inactive(struct gsm_network *net) +{ + struct gsm_subscriber *subscr, *tmp; + int purged = 0; + + llist_for_each_entry_safe(subscr, tmp, subscr_bsc_active_subscribers(), entry) { + if (subscr->net == net && subscr->use_count <= 0) { + subscr_free(subscr); + purged += 1; + } + } + + return purged; +} diff --git a/openbsc/src/osmo-bsc_nat/Makefile.am b/openbsc/src/osmo-bsc_nat/Makefile.am index a9e81fce7..ca103a4ff 100644 --- a/openbsc/src/osmo-bsc_nat/Makefile.am +++ b/openbsc/src/osmo-bsc_nat/Makefile.am @@ -8,10 +8,11 @@ bin_PROGRAMS = osmo-bsc_nat osmo_bsc_nat_SOURCES = bsc_filter.c bsc_mgcp_utils.c bsc_nat.c bsc_nat_utils.c \ bsc_nat_vty.c bsc_sccp.c bsc_ussd.c bsc_nat_ctrl.c \ bsc_nat_rewrite.c bsc_nat_filter.c bsc_nat_rewrite_trie.c -osmo_bsc_nat_LDADD = $(top_builddir)/src/libcommon/libcommon.a \ +osmo_bsc_nat_LDADD = \ $(top_builddir)/src/libmgcp/libmgcp.a \ $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libtrau/libtrau.a \ + $(top_builddir)/src/libcommon/libcommon.a \ -lrt $(LIBOSMOSCCP_LIBS) $(LIBOSMOCORE_LIBS) \ $(LIBOSMOGSM_LIBS) $(LIBOSMOVTY_LIBS) $(LIBOSMOCTRL_LIBS) \ $(LIBOSMOABIS_LIBS) $(LIBOSMONETIF_LIBS) diff --git a/openbsc/src/utils/Makefile.am b/openbsc/src/utils/Makefile.am index fd1f7aebf..acaa93700 100644 --- a/openbsc/src/utils/Makefile.am +++ b/openbsc/src/utils/Makefile.am @@ -9,9 +9,9 @@ noinst_PROGRAMS = smpp_mirror endif bs11_config_SOURCES = bs11_config.c -bs11_config_LDADD = $(top_builddir)/src/libcommon/libcommon.a \ - $(top_builddir)/src/libbsc/libbsc.a \ +bs11_config_LDADD = $(top_builddir)/src/libbsc/libbsc.a \ $(top_builddir)/src/libtrau/libtrau.a \ + $(top_builddir)/src/libcommon/libcommon.a \ $(LIBOSMOCORE_LIBS) $(LIBOSMOGSM_LIBS) $(LIBOSMOABIS_LIBS) isdnsync_SOURCES = isdnsync.c -- cgit v1.2.3