aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bsc
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2020-10-01 04:23:32 +0200
committerlaforge <laforge@osmocom.org>2020-10-08 07:24:52 +0000
commita33ef3ae2bc6d52f3338328c7d7288b51c755df0 (patch)
tree5ed806f2a484450deb24c73aaff8966ef60983f1 /src/osmo-bsc
parentd3d8e91bda542863ecf5e7596a6930eb7d40ee36 (diff)
LCS: SCCP next conn id: prepare Lb-interface
When adding the Lb interface, it is necessary to determine an unused conn id across *all* SCCP users. Prepare adding Lb by moving conn id creation out of the gscon code and generalizing. Change-Id: I12fcb18f6e4380f72929cfe7681bac05330a8c9a
Diffstat (limited to 'src/osmo-bsc')
-rw-r--r--src/osmo-bsc/Makefile.am1
-rw-r--r--src/osmo-bsc/bsc_sccp.c57
-rw-r--r--src/osmo-bsc/osmo_bsc_sigtran.c25
3 files changed, 59 insertions, 24 deletions
diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am
index c19d01bf7..b0fc181c2 100644
--- a/src/osmo-bsc/Makefile.am
+++ b/src/osmo-bsc/Makefile.am
@@ -40,6 +40,7 @@ osmo_bsc_SOURCES = \
bsc_init.c \
bsc_rf_ctrl.c \
bsc_rll.c \
+ bsc_sccp.c \
bsc_subscr_conn_fsm.c \
bsc_subscriber.c \
bsc_vty.c \
diff --git a/src/osmo-bsc/bsc_sccp.c b/src/osmo-bsc/bsc_sccp.c
new file mode 100644
index 000000000..9d4289f3d
--- /dev/null
+++ b/src/osmo-bsc/bsc_sccp.c
@@ -0,0 +1,57 @@
+/* Generic SCCP handling across all OsmoBSC users */
+/*
+ * (C) 2020 by sysmocom - s.f.m.c. GmbH <info@sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * Author: Neels Hofmeyr <neels@hofmeyr.de>
+ *
+ * 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 <http://www.gnu.org/licenses/>.
+ *
+ */
+
+#include <osmocom/bsc/gsm_data.h>
+#include <osmocom/bsc/bsc_msc_data.h>
+
+/* We need an unused SCCP conn_id across all SCCP users. */
+int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp)
+{
+ static uint32_t next_id = 1;
+ int i;
+
+ /* This looks really suboptimal, but in most cases the static next_id should indicate exactly the next unused
+ * conn_id, and we only iterate all conns once to make super sure that it is not already in use. */
+
+ for (i = 0; i < 0xFFFFFF; i++) {
+ struct gsm_subscriber_connection *conn;
+ uint32_t conn_id = next_id;
+ bool conn_id_already_used = false;
+ next_id = (next_id + 1) & 0xffffff;
+
+ llist_for_each_entry(conn, &bsc_gsmnet->subscr_conns, entry) {
+ if (conn->sccp.msc && conn->sccp.msc->a.sccp == sccp) {
+ if (conn_id == conn->sccp.conn_id) {
+ conn_id_already_used = true;
+ break;
+ }
+ }
+
+ /* Future for LCS: also check Lb-interface conn IDs here */
+ }
+
+ if (!conn_id_already_used)
+ return conn_id;
+ }
+ return -1;
+}
diff --git a/src/osmo-bsc/osmo_bsc_sigtran.c b/src/osmo-bsc/osmo_bsc_sigtran.c
index e0c24eff4..6853fac07 100644
--- a/src/osmo-bsc/osmo_bsc_sigtran.c
+++ b/src/osmo-bsc/osmo_bsc_sigtran.c
@@ -44,11 +44,6 @@ static struct llist_head *msc_list;
#define DEFAULT_ASP_LOCAL_IP "localhost"
#define DEFAULT_ASP_REMOTE_IP "localhost"
-/* The SCCP stack will not assign connection IDs to us automatically, we
- * will do this ourselves using a counter variable, that counts one up
- * for every new connection */
-static uint32_t conn_id_counter;
-
/* Helper function to Check if the given connection id is already assigned */
static struct gsm_subscriber_connection *get_bsc_conn_by_conn_id(int conn_id)
{
@@ -76,24 +71,6 @@ struct gsm_subscriber_connection *bsc_conn_by_bsub(struct bsc_subscr *bsub)
return NULL;
}
-/* Pick a free connection id */
-static int pick_free_conn_id(const struct bsc_msc_data *msc)
-{
- int conn_id = conn_id_counter;
- int i;
-
- for (i = 0; i < 0xFFFFFF; i++) {
- conn_id++;
- conn_id &= 0xFFFFFF;
- if (get_bsc_conn_by_conn_id(conn_id) == false) {
- conn_id_counter = conn_id;
- return conn_id;
- }
- }
-
- return -1;
-}
-
/* Patch regular BSSMAP RESET to add extra T to announce Osmux support (osmocom extension) */
static void _gsm0808_extend_announce_osmux(struct msgb *msg)
{
@@ -353,7 +330,7 @@ int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_connection *conn, struct ms
return -EINVAL;
}
- conn->sccp.conn_id = conn_id = pick_free_conn_id(msc);
+ conn->sccp.conn_id = conn_id = bsc_sccp_inst_next_conn_id(conn->sccp.msc->a.sccp);
if (conn->sccp.conn_id < 0) {
LOGP(DMSC, LOGL_ERROR, "Unable to allocate SCCP Connection ID\n");
return -1;