aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bsc/bsc_sccp.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2020-10-01 04:23:32 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2020-10-07 11:40:12 +0000
commit5c18ae95b49756128a7674e656aff61962e39d0f (patch)
treeaa77e40935061a1a599a61fc43ea0d837b06e781 /src/osmo-bsc/bsc_sccp.c
parent1ae1826245f7b2148a086e39f9feb8af9679426d (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/bsc_sccp.c')
-rw-r--r--src/osmo-bsc/bsc_sccp.c57
1 files changed, 57 insertions, 0 deletions
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;
+}