[PATCH] openbsc[master]: move to libxsc: net init 3: actual move

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Neels Hofmeyr gerrit-no-reply at lists.osmocom.org
Fri Oct 21 00:01:10 UTC 2016


Review at  https://gerrit.osmocom.org/1127

move to libxsc: net init 3: actual move

Reincarnate gsm_network_init() as the parts not specific to libbsc.
Move from bsc_network_init() those bits that are not BSC specific (and useful
for upcoming osmo-cscn).

Add libxsc to all linkages that use gsm_network_init().

Note: the only requirement to allow linking gsm_network_init() without libbsc
is to keep the call to gsm_net_update_ctype() out of libxsc. The other items
are kept out of libxsc because it makes sense semantically. But the separation
is not strong in that the BSC specific data members are of course still
omnipresent in struct gsm_network. If bsc_network_init() is not called, these
are not initialized properly -- for now no users of uninitialized members
exist.

So this is just a first step towards a sensible split of the BSC and MSC
gsm_network structs. The long term aim should be to have entirely separate
structs with some common general items.

Change-Id: If06316b97002390dc9a434686750cb96193ea63b
---
M openbsc/include/openbsc/xsc.h
M openbsc/src/ipaccess/Makefile.am
M openbsc/src/libbsc/net_init.c
M openbsc/src/libxsc/xsc.c
M openbsc/src/osmo-bsc/Makefile.am
M openbsc/src/osmo-bsc_nat/Makefile.am
M openbsc/src/osmo-nitb/Makefile.am
M openbsc/src/utils/Makefile.am
M openbsc/tests/bsc-nat/Makefile.am
M openbsc/tests/bsc/Makefile.am
M openbsc/tests/channel/Makefile.am
M openbsc/tests/db/Makefile.am
M openbsc/tests/gsm0408/Makefile.am
M openbsc/tests/subscr/Makefile.am
M openbsc/tests/trau/Makefile.am
15 files changed, 85 insertions(+), 36 deletions(-)


  git pull ssh://gerrit.osmocom.org:29418/openbsc refs/changes/27/1127/1

diff --git a/openbsc/include/openbsc/xsc.h b/openbsc/include/openbsc/xsc.h
index 612d754..8549a83 100644
--- a/openbsc/include/openbsc/xsc.h
+++ b/openbsc/include/openbsc/xsc.h
@@ -1,6 +1,13 @@
 #pragma once
 
+#include <stdint.h>
+
 struct msgb;
 struct gsm_network;
 
 typedef int (*mncc_recv_cb_t)(struct gsm_network *, struct msgb *);
+
+struct gsm_network *gsm_network_init(void *ctx,
+				     uint16_t country_code,
+				     uint16_t network_code,
+				     mncc_recv_cb_t mncc_recv);
diff --git a/openbsc/src/ipaccess/Makefile.am b/openbsc/src/ipaccess/Makefile.am
index 784a578..16f3337 100644
--- a/openbsc/src/ipaccess/Makefile.am
+++ b/openbsc/src/ipaccess/Makefile.am
@@ -48,6 +48,7 @@
 # FIXME: resolve the bogus dependencies patched around here:
 ipaccess_config_LDADD = \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(LIBCRYPT) \
diff --git a/openbsc/src/libbsc/net_init.c b/openbsc/src/libbsc/net_init.c
index 07a4423..d58dd16 100644
--- a/openbsc/src/libbsc/net_init.c
+++ b/openbsc/src/libbsc/net_init.c
@@ -17,12 +17,9 @@
  *
  */
 
+#include <openbsc/xsc.h>
 #include <openbsc/osmo_bsc.h>
-#include <openbsc/gsm_data.h>
 #include <openbsc/osmo_msc_data.h>
-#include <openbsc/gsm_subscriber.h>
-
-#include <stdbool.h>
 
 struct gsm_network *bsc_network_init(void *ctx,
 				     uint16_t country_code,
@@ -30,11 +27,8 @@
 				     mncc_recv_cb_t mncc_recv)
 {
 	struct gsm_network *net;
-	const char *default_regexp = ".*";
-
-	net = talloc_zero(ctx, struct gsm_network);
-	if (!net)
-		return NULL;
+	
+	net = gsm_network_init(ctx, country_code, network_code, mncc_recv);
 
 	net->bsc_data = talloc_zero(net, struct osmo_bsc_data);
 	if (!net->bsc_data) {
@@ -42,27 +36,11 @@
 		return NULL;
 	}
 
-	net->subscr_group = talloc_zero(net, struct gsm_subscriber_group);
-	if (!net->subscr_group) {
-		talloc_free(net);
-		return NULL;
-	}
-
-	if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1,
-			  &default_regexp) != 0)
-		return NULL;
-
 	/* Init back pointer */
 	net->bsc_data->auto_off_timeout = -1;
 	net->bsc_data->network = net;
 	INIT_LLIST_HEAD(&net->bsc_data->mscs);
 
-	net->subscr_group->net = net;
-	net->auto_create_subscr = true;
-	net->auto_assign_exten = true;
-
-	net->country_code = country_code;
-	net->network_code = network_code;
 	net->num_bts = 0;
 	net->reject_cause = GSM48_REJECT_ROAMING_NOT_ALLOWED;
 	net->T3101 = GSM_T3101_DEFAULT;
@@ -79,22 +57,12 @@
 	net->handover.pwr_hysteresis = 3;
 	net->handover.max_distance = 9999;
 
-	INIT_LLIST_HEAD(&net->trans_list);
-	INIT_LLIST_HEAD(&net->upqueue);
 	INIT_LLIST_HEAD(&net->bts_list);
-	INIT_LLIST_HEAD(&net->subscr_conns);
 
 	/* init statistics */
 	net->bsc_ctrs = rate_ctr_group_alloc(net, &bsc_ctrg_desc, 0);
-	net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0);
-	net->active_calls = osmo_counter_alloc("msc.active_calls");
 
-	net->mncc_recv = mncc_recv;
-	net->ext_min = GSM_MIN_EXTEN;
-	net->ext_max = GSM_MAX_EXTEN;
 	gsm_net_update_ctype(net);
-
-	net->dyn_ts_allow_tch_f = true;
 
 	return net;
 }
diff --git a/openbsc/src/libxsc/xsc.c b/openbsc/src/libxsc/xsc.c
index 141179b..acb40ec 100644
--- a/openbsc/src/libxsc/xsc.c
+++ b/openbsc/src/libxsc/xsc.c
@@ -1,6 +1,8 @@
 /* Code used by both libbsc and libmsc (xsc means "BSC or MSC").
  *
  * (C) 2016 by sysmocom s.m.f.c. <info at sysmocom.de>
+ * (C) 2008-2010 by Harald Welte <laforge at gnumonks.org>
+ * (C) 2014 by Holger Hans Peter Freyther
  * All Rights Reserved
  *
  * This program is free software; you can redistribute it and/or modify
@@ -17,3 +19,64 @@
  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
  *
  */
+
+#include <stdbool.h>
+
+#include <osmocom/gsm/gsm0480.h>
+
+#include <openbsc/xsc.h>
+#include <openbsc/gsm_data.h>
+#include <openbsc/gsm_subscriber.h>
+
+/* Warning: if bsc_network_init() is not called, some of the members of
+ * gsm_network are not initialized properly and must not be used! (In
+ * particular the llist heads and stats counters.)
+ * The long term aim should be to have entirely separate structs for libbsc and
+ * libmsc with some common general items.
+ */
+struct gsm_network *gsm_network_init(void *ctx,
+				     uint16_t country_code,
+				     uint16_t network_code,
+				     mncc_recv_cb_t mncc_recv)
+{
+	struct gsm_network *net;
+
+	const char *default_regexp = ".*";
+
+	net = talloc_zero(ctx, struct gsm_network);
+	if (!net)
+		return NULL;
+
+	net->subscr_group = talloc_zero(net, struct gsm_subscriber_group);
+	if (!net->subscr_group) {
+		talloc_free(net);
+		return NULL;
+	}
+
+	if (gsm_parse_reg(net, &net->authorized_regexp, &net->authorized_reg_str, 1,
+			  &default_regexp) != 0)
+		return NULL;
+
+	net->subscr_group->net = net;
+	net->auto_create_subscr = true;
+	net->auto_assign_exten = true;
+
+	net->country_code = country_code;
+	net->network_code = network_code;
+
+	INIT_LLIST_HEAD(&net->trans_list);
+	INIT_LLIST_HEAD(&net->upqueue);
+	INIT_LLIST_HEAD(&net->subscr_conns);
+
+	/* init statistics */
+	net->msc_ctrs = rate_ctr_group_alloc(net, &msc_ctrg_desc, 0);
+	net->active_calls = osmo_counter_alloc("msc.active_calls");
+
+	net->mncc_recv = mncc_recv;
+	net->ext_min = GSM_MIN_EXTEN;
+	net->ext_max = GSM_MAX_EXTEN;
+
+	net->dyn_ts_allow_tch_f = true;
+
+	return net;
+}
diff --git a/openbsc/src/osmo-bsc/Makefile.am b/openbsc/src/osmo-bsc/Makefile.am
index 2dbfeb8..7d38999 100644
--- a/openbsc/src/osmo-bsc/Makefile.am
+++ b/openbsc/src/osmo-bsc/Makefile.am
@@ -41,6 +41,7 @@
 osmo_bsc_LDADD = \
 	$(top_builddir)/src/libfilter/libfilter.a \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
 	$(top_builddir)/src/libbsc/libbsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
diff --git a/openbsc/src/osmo-bsc_nat/Makefile.am b/openbsc/src/osmo-bsc_nat/Makefile.am
index 6027f27..667cd86 100644
--- a/openbsc/src/osmo-bsc_nat/Makefile.am
+++ b/openbsc/src/osmo-bsc_nat/Makefile.am
@@ -42,6 +42,7 @@
 osmo_bsc_nat_LDADD = \
 	$(top_builddir)/src/libmgcp/libmgcp.a \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(top_builddir)/src/libfilter/libfilter.a \
diff --git a/openbsc/src/osmo-nitb/Makefile.am b/openbsc/src/osmo-nitb/Makefile.am
index 60514c0..5063423 100644
--- a/openbsc/src/osmo-nitb/Makefile.am
+++ b/openbsc/src/osmo-nitb/Makefile.am
@@ -29,6 +29,7 @@
 
 osmo_nitb_LDADD = \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
diff --git a/openbsc/src/utils/Makefile.am b/openbsc/src/utils/Makefile.am
index 7fcc4e3..0228202 100644
--- a/openbsc/src/utils/Makefile.am
+++ b/openbsc/src/utils/Makefile.am
@@ -50,6 +50,7 @@
 
 bs11_config_LDADD = \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(LIBOSMOCORE_LIBS) \
diff --git a/openbsc/tests/bsc-nat/Makefile.am b/openbsc/tests/bsc-nat/Makefile.am
index fa55d27..2d00af9 100644
--- a/openbsc/tests/bsc-nat/Makefile.am
+++ b/openbsc/tests/bsc-nat/Makefile.am
@@ -44,6 +44,7 @@
 bsc_nat_test_LDADD = \
 	$(top_builddir)/src/libfilter/libfilter.a \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libmgcp/libmgcp.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
diff --git a/openbsc/tests/bsc/Makefile.am b/openbsc/tests/bsc/Makefile.am
index ddfa437..fdc0b87 100644
--- a/openbsc/tests/bsc/Makefile.am
+++ b/openbsc/tests/bsc/Makefile.am
@@ -33,6 +33,7 @@
 bsc_test_LDADD = \
 	$(top_builddir)/src/libbsc/libbsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libmgcp/libmgcp.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
diff --git a/openbsc/tests/channel/Makefile.am b/openbsc/tests/channel/Makefile.am
index 5654572..50db62f 100644
--- a/openbsc/tests/channel/Makefile.am
+++ b/openbsc/tests/channel/Makefile.am
@@ -26,6 +26,7 @@
 channel_test_LDADD = \
 	$(top_builddir)/src/libbsc/libbsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(LIBOSMOCORE_LIBS) \
 	$(LIBOSMOGSM_LIBS) \
diff --git a/openbsc/tests/db/Makefile.am b/openbsc/tests/db/Makefile.am
index c4da31c..2f04d5b 100644
--- a/openbsc/tests/db/Makefile.am
+++ b/openbsc/tests/db/Makefile.am
@@ -35,6 +35,7 @@
 	$(top_builddir)/src/libbsc/libbsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(LIBOSMOCORE_LIBS) \
@@ -45,4 +46,3 @@
 	$(LIBCRYPTO_LIBS) \
 	-ldbi \
 	$(NULL)
-
diff --git a/openbsc/tests/gsm0408/Makefile.am b/openbsc/tests/gsm0408/Makefile.am
index 11fa6b9..57e6798 100644
--- a/openbsc/tests/gsm0408/Makefile.am
+++ b/openbsc/tests/gsm0408/Makefile.am
@@ -25,6 +25,7 @@
 gsm0408_test_LDADD = \
 	$(top_builddir)/src/libbsc/libbsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(LIBOSMOCORE_LIBS) \
diff --git a/openbsc/tests/subscr/Makefile.am b/openbsc/tests/subscr/Makefile.am
index fb863d8..367d516 100644
--- a/openbsc/tests/subscr/Makefile.am
+++ b/openbsc/tests/subscr/Makefile.am
@@ -33,6 +33,7 @@
 	$(top_builddir)/src/libbsc/libbsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(LIBOSMOCORE_LIBS) \
diff --git a/openbsc/tests/trau/Makefile.am b/openbsc/tests/trau/Makefile.am
index 93ce88e..c5fdf7a 100644
--- a/openbsc/tests/trau/Makefile.am
+++ b/openbsc/tests/trau/Makefile.am
@@ -33,6 +33,7 @@
 	$(top_builddir)/src/libbsc/libbsc.a \
 	$(top_builddir)/src/libmsc/libmsc.a \
 	$(top_builddir)/src/libbsc/libbsc.a \
+	$(top_builddir)/src/libxsc/libxsc.a \
 	$(top_builddir)/src/libtrau/libtrau.a \
 	$(top_builddir)/src/libcommon/libcommon.a \
 	$(LIBOSMOCORE_LIBS) \

-- 
To view, visit https://gerrit.osmocom.org/1127
To unsubscribe, visit https://gerrit.osmocom.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: If06316b97002390dc9a434686750cb96193ea63b
Gerrit-PatchSet: 1
Gerrit-Project: openbsc
Gerrit-Branch: master
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>



More information about the gerrit-log mailing list