aboutsummaryrefslogtreecommitdiffstats
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
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
-rw-r--r--include/osmocom/bsc/gsm_data.h3
-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
4 files changed, 62 insertions, 24 deletions
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 8d07fb193..7021fa4b8 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -51,6 +51,7 @@ struct gsm_bts_trx;
struct bsc_subscr;
struct gprs_ra_id;
struct handover;
+struct osmo_sccp_instance;
#define OBSC_LINKID_CB(__msgb) (__msgb)->cb[3]
@@ -1245,4 +1246,6 @@ enum gsm_phys_chan_config gsm_pchan_by_lchan_type(enum gsm_chan_t type);
enum gsm48_rr_cause bsc_gsm48_rr_cause_from_gsm0808_cause(enum gsm0808_cause c);
enum gsm48_rr_cause bsc_gsm48_rr_cause_from_rsl_cause(uint8_t c);
+int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp);
+
#endif /* _GSM_DATA_H */
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;