aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHolger Hans Peter Freyther <zecke@selfish.org>2009-06-12 07:08:13 +0200
committerHolger Hans Peter Freyther <zecke@selfish.org>2009-08-17 09:52:42 +0200
commit857e5e6e303a329395e2c6d2170e4904afa84d42 (patch)
tree3531eafc5edb4c3773daf6a2f954d7777157a8ee
parent42e327b52f603ee9b0ffa3acf84756e844735eac (diff)
[subscr] Split gsm_subscriber.c in BSC and MSC part
For the BSC part we still assign a gsm_subscriber to lchan but it might only contain the TMSI of this subscriber. For the MSC part we will need the HLR/VLR feature of the gsm_subscriber, specially the lookup's by number... So if libbsc.a/libmsc.a are compiled in one app and used the subscribers will be shared, and if only libbsc.a gets used we will have more empty gsm_subscriber.c..
-rw-r--r--openbsc/src/Makefile.am2
-rw-r--r--openbsc/src/gsm_subscriber.c179
-rw-r--r--openbsc/src/gsm_subscriber_base.c209
-rw-r--r--openbsc/tests/channel/Makefile.am1
-rw-r--r--openbsc/tests/db/Makefile.am2
5 files changed, 218 insertions, 175 deletions
diff --git a/openbsc/src/Makefile.am b/openbsc/src/Makefile.am
index f5febbc46..d90e48372 100644
--- a/openbsc/src/Makefile.am
+++ b/openbsc/src/Makefile.am
@@ -7,7 +7,7 @@ noinst_HEADERS = vty/cardshell.h
libbsc_a_SOURCES = abis_rsl.c abis_nm.c gsm_04_08.c gsm_data.c mncc.c \
msgb.c select.c chan_alloc.c timer.c debug.c \
- gsm_04_11.c subchan_demux.c \
+ gsm_subscriber_base.c gsm_04_11.c subchan_demux.c \
trau_frame.c trau_mux.c paging.c e1_config.c e1_input.c tlv_parser.c \
input/misdn.c input/ipaccess.c signal.c gsm_utils.c talloc.c talloc_ctx.c \
transaction.c rtp_proxy.c bsc_rll.c token_auth.c rrlp.c
diff --git a/openbsc/src/gsm_subscriber.c b/openbsc/src/gsm_subscriber.c
index 297b8c8f6..84e14a0ea 100644
--- a/openbsc/src/gsm_subscriber.c
+++ b/openbsc/src/gsm_subscriber.c
@@ -1,4 +1,4 @@
-/* Dummy implementation of a subscriber database, roghly HLR/VLR functionality */
+/* The concept of a subscriber for the MSC, roughly HLR/VLR functionality */
/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
* (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.org>
@@ -27,101 +27,12 @@
#include <string.h>
#include <assert.h>
-#include <openbsc/talloc.h>
#include <openbsc/gsm_subscriber.h>
-#include <openbsc/paging.h>
#include <openbsc/debug.h>
-#include <openbsc/paging.h>
#include <openbsc/signal.h>
#include <openbsc/db.h>
-LLIST_HEAD(active_subscribers);
-void *tall_subscr_ctx;
-void *tall_sub_req_ctx;
-
-/*
- * Struct for pending channel requests. This is managed in the
- * llist_head requests of each subscriber. The reference counting
- * should work in such a way that a subscriber with a pending request
- * remains in memory.
- */
-struct subscr_request {
- struct llist_head entry;
-
- /* back reference */
- struct gsm_subscriber *subscr;
-
- /* the requested channel type */
- int channel_type;
-
- /* the bts we have decided to use */
- struct gsm_network *network;
-
- /* the callback data */
- gsm_cbfn *cbfn;
- void *param;
-};
-
-/*
- * We got the channel assigned and can now hand this channel
- * over to one of our callbacks.
- */
-static int subscr_paging_cb(unsigned int hooknum, unsigned int event,
- struct msgb *msg, void *data, void *param)
-{
- struct subscr_request *request;
- struct gsm_subscriber *subscr = (struct gsm_subscriber *)param;
-
- assert(!llist_empty(&subscr->requests));
-
- /*
- * FIXME: What to do with paging requests coming during
- * this callback? We must be sure to not start paging when
- * we have an active connection to a subscriber and to make
- * the subscr_put_channel work as required...
- */
- request = (struct subscr_request *)subscr->requests.next;
- llist_del(&request->entry);
- subscr->in_callback = 1;
- request->cbfn(hooknum, event, msg, data, request->param);
- subscr->in_callback = 0;
-
- talloc_free(request);
- return 0;
-}
-
-static void subscr_send_paging_request(struct gsm_subscriber *subscr)
-{
- struct subscr_request *request;
- assert(!llist_empty(&subscr->requests));
-
- request = (struct subscr_request *)subscr->requests.next;
- paging_request(request->network, subscr, request->channel_type,
- subscr_paging_cb, subscr);
-}
-
-struct gsm_subscriber *subscr_alloc(void)
-{
- struct gsm_subscriber *s;
-
- s = talloc(tall_subscr_ctx, struct gsm_subscriber);
- if (!s)
- return NULL;
-
- memset(s, 0, sizeof(*s));
- llist_add_tail(&s->entry, &active_subscribers);
- s->use_count = 1;
-
- INIT_LLIST_HEAD(&s->requests);
-
- return s;
-}
-
-static void subscr_free(struct gsm_subscriber *subscr)
-{
- llist_del(&subscr->entry);
- talloc_free(subscr);
-}
+extern struct llist_head *subscr_bsc_active_subscriber(void);
struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_network *net,
const char *tmsi)
@@ -129,7 +40,7 @@ struct gsm_subscriber *subscr_get_by_tmsi(struct gsm_network *net,
struct gsm_subscriber *subscr;
/* we might have a record in memory already */
- llist_for_each_entry(subscr, &active_subscribers, entry) {
+ llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) {
if (strcmp(subscr->tmsi, tmsi) == 0)
return subscr_get(subscr);
}
@@ -142,7 +53,7 @@ struct gsm_subscriber *subscr_get_by_imsi(struct gsm_network *net,
{
struct gsm_subscriber *subscr;
- llist_for_each_entry(subscr, &active_subscribers, entry) {
+ llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) {
if (strcmp(subscr->imsi, imsi) == 0)
return subscr_get(subscr);
}
@@ -155,7 +66,7 @@ struct gsm_subscriber *subscr_get_by_extension(struct gsm_network *net,
{
struct gsm_subscriber *subscr;
- llist_for_each_entry(subscr, &active_subscribers, entry) {
+ llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) {
if (strcmp(subscr->extension, ext) == 0)
return subscr_get(subscr);
}
@@ -170,7 +81,7 @@ struct gsm_subscriber *subscr_get_by_id(struct gsm_network *net,
char buf[32];
sprintf(buf, "%llu", id);
- llist_for_each_entry(subscr, &active_subscribers, entry) {
+ llist_for_each_entry(subscr, subscr_bsc_active_subscriber(), entry) {
if (subscr->id == id)
return subscr_get(subscr);
}
@@ -203,82 +114,4 @@ int subscr_update(struct gsm_subscriber *s, struct gsm_bts *bts, int reason)
return db_sync_subscriber(s);
}
-struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr)
-{
- subscr->use_count++;
- DEBUGP(DCC, "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(DCC, "subscr %s usage decreased usage to: %d\n",
- subscr->extension, subscr->use_count);
- if (subscr->use_count <= 0)
- subscr_free(subscr);
- return NULL;
-}
-
-void subscr_get_channel(struct gsm_subscriber *subscr,
- struct gsm_network *network, int type,
- gsm_cbfn *cbfn, void *param)
-{
- struct subscr_request *request;
-
- request = talloc(tall_sub_req_ctx, struct subscr_request);
- if (!request) {
- if (cbfn)
- cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_OOM,
- NULL, NULL, param);
- return;
- }
- memset(request, 0, sizeof(*request));
- request->network = network;
- request->subscr = subscr;
- request->channel_type = type;
- request->cbfn = cbfn;
- request->param = param;
-
- /*
- * FIXME: We might be able to assign more than one
- * channel, e.g. voice and SMS submit at the same
- * time.
- */
- if (!subscr->in_callback && llist_empty(&subscr->requests)) {
- /* add to the list, send a request */
- llist_add_tail(&request->entry, &subscr->requests);
- subscr_send_paging_request(subscr);
- } else {
- /* this will be picked up later, from subscr_put_channel */
- llist_add_tail(&request->entry, &subscr->requests);
- }
-}
-
-void subscr_put_channel(struct gsm_lchan *lchan)
-{
- /*
- * FIXME: Continue with other requests now... by checking
- * the gsm_subscriber inside the gsm_lchan. Drop the ref count
- * of the lchan after having asked the next requestee to handle
- * the channel.
- */
- /*
- * FIXME: is the lchan is of a different type we could still
- * issue an immediate assignment for another channel and then
- * close this one.
- */
- /*
- * Currently we will drop the last ref of the lchan which
- * will result in a channel release on RSL and we will start
- * the paging. This should work most of the time as the MS
- * will listen to the paging requests before we timeout
- */
-
- put_lchan(lchan);
-
- if (lchan->subscr && !llist_empty(&lchan->subscr->requests))
- subscr_send_paging_request(lchan->subscr);
-}
diff --git a/openbsc/src/gsm_subscriber_base.c b/openbsc/src/gsm_subscriber_base.c
new file mode 100644
index 000000000..83addd0a8
--- /dev/null
+++ b/openbsc/src/gsm_subscriber_base.c
@@ -0,0 +1,209 @@
+/* The concept of a subscriber as seen by the BSC */
+
+/* (C) 2008 by Harald Welte <laforge@gnumonks.org>
+ * (C) 2009 by Holger Hans Peter Freyther <zecke@selfish.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.
+ *
+ */
+
+#include <unistd.h>
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+#include <assert.h>
+
+#include <openbsc/talloc.h>
+#include <openbsc/gsm_subscriber.h>
+#include <openbsc/paging.h>
+#include <openbsc/debug.h>
+#include <openbsc/paging.h>
+
+LLIST_HEAD(active_subscribers);
+void *tall_subscr_ctx;
+void *tall_sub_req_ctx;
+
+/* for the gsm_subscriber.c */
+struct llist_head *subscr_bsc_active_subscriber(void)
+{
+ return &active_subscribers;
+}
+
+/*
+ * Struct for pending channel requests. This is managed in the
+ * llist_head requests of each subscriber. The reference counting
+ * should work in such a way that a subscriber with a pending request
+ * remains in memory.
+ */
+struct subscr_request {
+ struct llist_head entry;
+
+ /* back reference */
+ struct gsm_subscriber *subscr;
+
+ /* the requested channel type */
+ int channel_type;
+
+ /* the bts we have decided to use */
+ struct gsm_network *network;
+
+ /* the callback data */
+ gsm_cbfn *cbfn;
+ void *param;
+};
+
+/*
+ * We got the channel assigned and can now hand this channel
+ * over to one of our callbacks.
+ */
+static int subscr_paging_cb(unsigned int hooknum, unsigned int event,
+ struct msgb *msg, void *data, void *param)
+{
+ struct subscr_request *request;
+ struct gsm_subscriber *subscr = (struct gsm_subscriber *)param;
+
+ assert(!llist_empty(&subscr->requests));
+
+ /*
+ * FIXME: What to do with paging requests coming during
+ * this callback? We must be sure to not start paging when
+ * we have an active connection to a subscriber and to make
+ * the subscr_put_channel work as required...
+ */
+ request = (struct subscr_request *)subscr->requests.next;
+ llist_del(&request->entry);
+ subscr->in_callback = 1;
+ request->cbfn(hooknum, event, msg, data, request->param);
+ subscr->in_callback = 0;
+
+ talloc_free(request);
+ return 0;
+}
+
+static void subscr_send_paging_request(struct gsm_subscriber *subscr)
+{
+ struct subscr_request *request;
+ assert(!llist_empty(&subscr->requests));
+
+ request = (struct subscr_request *)subscr->requests.next;
+ paging_request(request->network, subscr, request->channel_type,
+ subscr_paging_cb, subscr);
+}
+
+struct gsm_subscriber *subscr_alloc(void)
+{
+ struct gsm_subscriber *s;
+
+ s = talloc(tall_subscr_ctx, struct gsm_subscriber);
+ if (!s)
+ return NULL;
+
+ memset(s, 0, sizeof(*s));
+ llist_add_tail(&s->entry, &active_subscribers);
+ s->use_count = 1;
+
+ INIT_LLIST_HEAD(&s->requests);
+
+ return s;
+}
+
+static void subscr_free(struct gsm_subscriber *subscr)
+{
+ llist_del(&subscr->entry);
+ talloc_free(subscr);
+}
+
+struct gsm_subscriber *subscr_get(struct gsm_subscriber *subscr)
+{
+ subscr->use_count++;
+ DEBUGP(DCC, "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(DCC, "subscr %s usage decreased usage to: %d\n",
+ subscr->extension, subscr->use_count);
+ if (subscr->use_count <= 0)
+ subscr_free(subscr);
+ return NULL;
+}
+
+void subscr_get_channel(struct gsm_subscriber *subscr,
+ struct gsm_network *network, int type,
+ gsm_cbfn *cbfn, void *param)
+{
+ struct subscr_request *request;
+
+ request = talloc(tall_sub_req_ctx, struct subscr_request);
+ if (!request) {
+ if (cbfn)
+ cbfn(GSM_HOOK_RR_PAGING, GSM_PAGING_OOM,
+ NULL, NULL, param);
+ return;
+ }
+
+ memset(request, 0, sizeof(*request));
+ request->network = network;
+ request->subscr = subscr;
+ request->channel_type = type;
+ request->cbfn = cbfn;
+ request->param = param;
+
+ /*
+ * FIXME: We might be able to assign more than one
+ * channel, e.g. voice and SMS submit at the same
+ * time.
+ */
+ if (!subscr->in_callback && llist_empty(&subscr->requests)) {
+ /* add to the list, send a request */
+ llist_add_tail(&request->entry, &subscr->requests);
+ subscr_send_paging_request(subscr);
+ } else {
+ /* this will be picked up later, from subscr_put_channel */
+ llist_add_tail(&request->entry, &subscr->requests);
+ }
+}
+
+void subscr_put_channel(struct gsm_lchan *lchan)
+{
+ /*
+ * FIXME: Continue with other requests now... by checking
+ * the gsm_subscriber inside the gsm_lchan. Drop the ref count
+ * of the lchan after having asked the next requestee to handle
+ * the channel.
+ */
+ /*
+ * FIXME: is the lchan is of a different type we could still
+ * issue an immediate assignment for another channel and then
+ * close this one.
+ */
+ /*
+ * Currently we will drop the last ref of the lchan which
+ * will result in a channel release on RSL and we will start
+ * the paging. This should work most of the time as the MS
+ * will listen to the paging requests before we timeout
+ */
+
+ put_lchan(lchan);
+
+ if (lchan->subscr && !llist_empty(&lchan->subscr->requests))
+ subscr_send_paging_request(lchan->subscr);
+}
+
diff --git a/openbsc/tests/channel/Makefile.am b/openbsc/tests/channel/Makefile.am
index 6b7468c52..50fadc582 100644
--- a/openbsc/tests/channel/Makefile.am
+++ b/openbsc/tests/channel/Makefile.am
@@ -5,6 +5,7 @@ noinst_PROGRAMS = channel_test
channel_test_SOURCES = channel_test.c \
$(top_srcdir)/src/db.c \
+ $(top_srcdir)/src/gsm_subscriber_base.c \
$(top_srcdir)/src/gsm_subscriber.c \
$(top_srcdir)/src/debug.c \
$(top_srcdir)/src/timer.c \
diff --git a/openbsc/tests/db/Makefile.am b/openbsc/tests/db/Makefile.am
index fbd9b9b6c..c8a397000 100644
--- a/openbsc/tests/db/Makefile.am
+++ b/openbsc/tests/db/Makefile.am
@@ -4,5 +4,5 @@ AM_CFLAGS=-Wall -ggdb3
noinst_PROGRAMS = db_test
db_test_SOURCES = db_test.c
-db_test_LDADD = $(top_builddir)/src/libmsc.a $(top_builddir)/src/libbsc.a -ldl -ldbi
+db_test_LDADD = $(top_builddir)/src/libbsc.a $(top_builddir)/src/libmsc.a -ldl -ldbi