aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPau Espin Pedrol <pespin@sysmocom.de>2023-03-09 12:57:25 +0100
committerPau Espin Pedrol <pespin@sysmocom.de>2023-03-13 11:58:49 +0100
commitc5b7d94e0f4a07b7191efe5182c97e408bca77a3 (patch)
tree2dab56d093d8331335afe4e376a12fc2adeaa6f6
parent6b204ebd668048297ff72e9d85029690d3f04f00 (diff)
Clarify type and values of sccp.conn_id
Currently, the conn_id is allocated in a range 0..0xffffff by bsc_sccp_inst_next_conn_id(), and -1 means it is unset. This means allocation expects "int" to be at least 32 bits integer, in order to fit 24 bits for 0..0xffffff plus the -1. Hence, let's define the variable as uint32_t, as already done in libosmo-sccp. Use last value 0xFFFFFFFF ((uint32_t)-1) and avoid playing with the value being unsigned sometimes and signed only for "unset" value. The value is actually already handled as unsigned (printed with %u) in most places. Change-Id: If019bcbc1e28929fe8d981fef9103835fc6ead2e
-rw-r--r--include/osmocom/bsc/gsm_data.h16
-rw-r--r--src/osmo-bsc/bsc_sccp.c10
-rw-r--r--src/osmo-bsc/bsc_subscr_conn_fsm.c3
-rw-r--r--src/osmo-bsc/lb.c8
-rw-r--r--src/osmo-bsc/osmo_bsc_sigtran.c14
5 files changed, 30 insertions, 21 deletions
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 533be93ca..268aa0cc8 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -51,6 +51,9 @@
* with delta = time between expiration of T3124 and receiving HANDOVER FAILURE by the serving BSC. */
#define GSM_NY1_DEFAULT ((unsigned long)((GSM_T3124_MAX + GSM_NY1_REQ_DELTA)/GSM_T3105_DEFAULT + 1))
+#define SCCP_CONN_ID_UNSET 0xFFFFFFFF
+#define SCCP_CONN_ID_MAX 0x00FFFFFF
+
struct mgcp_client_conf;
struct mgcp_client;
struct gsm0808_cell_id;
@@ -328,8 +331,10 @@ struct gsm_subscriber_connection {
/* SCCP connection related */
struct bsc_msc_data *msc;
- /* Sigtran connection ID */
- int conn_id;
+ /* Sigtran connection ID:
+ * if set: Range (0..SCCP_CONN_ID_MAX) (24 bit)
+ * if unset: SCCP_CONN_ID_UNSET (-1) if unset */
+ uint32_t conn_id;
enum subscr_sccp_state state;
} sccp;
@@ -379,7 +384,10 @@ struct gsm_subscriber_connection {
/* Lb interface to the SMLC: BSSMAP-LE/SCCP connection associated with this subscriber */
struct {
- int conn_id;
+ /* Sigtran connection ID:
+ * if set: Range (0..SCCP_CONN_ID_MAX) (24 bit)
+ * if unset: SCCP_CONN_ID_UNSET (-1) if unset */
+ uint32_t conn_id;
enum subscr_sccp_state state;
} lb;
} lcs;
@@ -1022,7 +1030,7 @@ 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);
+uint32_t bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp);
/* Interference Measurement Parameters */
struct gsm_interf_meas_params {
diff --git a/src/osmo-bsc/bsc_sccp.c b/src/osmo-bsc/bsc_sccp.c
index 0cd1dc9f3..30d4c4c94 100644
--- a/src/osmo-bsc/bsc_sccp.c
+++ b/src/osmo-bsc/bsc_sccp.c
@@ -26,7 +26,7 @@
#include <osmocom/bsc/lb.h>
/* We need an unused SCCP conn_id across all SCCP users. */
-int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp)
+uint32_t bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp)
{
static uint32_t next_id = 1;
int i;
@@ -34,11 +34,13 @@ int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp)
/* 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++) {
+ for (i = 0; i < SCCP_CONN_ID_MAX; i++) {
struct gsm_subscriber_connection *conn;
uint32_t conn_id = next_id;
bool conn_id_already_used = false;
- next_id = (next_id + 1) & 0xffffff;
+
+ /* Optimized modulo operation using bitwise AND: */
+ next_id = (next_id + 1) & SCCP_CONN_ID_MAX;
llist_for_each_entry(conn, &bsc_gsmnet->subscr_conns, entry) {
if (conn->sccp.msc && conn->sccp.msc->a.sccp == sccp) {
@@ -60,5 +62,5 @@ int bsc_sccp_inst_next_conn_id(struct osmo_sccp_instance *sccp)
if (!conn_id_already_used)
return conn_id;
}
- return -1;
+ return SCCP_CONN_ID_UNSET;
}
diff --git a/src/osmo-bsc/bsc_subscr_conn_fsm.c b/src/osmo-bsc/bsc_subscr_conn_fsm.c
index ebfbe82a2..e37f0300e 100644
--- a/src/osmo-bsc/bsc_subscr_conn_fsm.c
+++ b/src/osmo-bsc/bsc_subscr_conn_fsm.c
@@ -1226,8 +1226,7 @@ struct gsm_subscriber_connection *bsc_subscr_con_allocate(struct gsm_network *ne
conn->network = net;
INIT_LLIST_HEAD(&conn->dtap_queue);
INIT_LLIST_HEAD(&conn->hodec2.penalty_timers);
- conn->sccp.conn_id = -1;
-
+ conn->sccp.conn_id = SCCP_CONN_ID_UNSET;
/* Default clear cause (on RR translates to GSM48_RR_CAUSE_ABNORMAL_UNSPEC) */
conn->clear_cause = GSM0808_CAUSE_EQUIPMENT_FAILURE;
diff --git a/src/osmo-bsc/lb.c b/src/osmo-bsc/lb.c
index 6f3cfac7c..c34d88ea3 100644
--- a/src/osmo-bsc/lb.c
+++ b/src/osmo-bsc/lb.c
@@ -32,7 +32,7 @@
#include <osmocom/bsc/lcs_loc_req.h>
#include <osmocom/bsc/bssmap_reset.h>
-static struct gsm_subscriber_connection *get_bsc_conn_by_lb_conn_id(int conn_id)
+static struct gsm_subscriber_connection *get_bsc_conn_by_lb_conn_id(uint32_t conn_id)
{
struct gsm_subscriber_connection *conn;
@@ -229,7 +229,7 @@ static int sccp_sap_up(struct osmo_prim_hdr *oph, void *_scu)
static int lb_open_conn(struct gsm_subscriber_connection *conn, struct msgb *msg)
{
struct osmo_ss7_instance *ss7;
- int conn_id;
+ uint32_t conn_id;
int rc;
OSMO_ASSERT(conn);
@@ -242,14 +242,14 @@ static int lb_open_conn(struct gsm_subscriber_connection *conn, struct msgb *msg
}
conn_id = bsc_sccp_inst_next_conn_id(bsc_gsmnet->smlc->sccp);
- if (conn_id < 0) {
+ if (conn_id == SCCP_CONN_ID_UNSET) {
LOGPFSMSL(conn->fi, DLCS, LOGL_ERROR, "Unable to allocate SCCP Connection ID for BSSMAP-LE to SMLC\n");
return -ENOSPC;
}
conn->lcs.lb.conn_id = conn_id;
ss7 = osmo_ss7_instance_find(bsc_gsmnet->smlc->cs7_instance);
OSMO_ASSERT(ss7);
- LOGPFSMSL(conn->fi, DLCS, LOGL_INFO, "Opening new SCCP connection (id=%i) to SMLC: %s\n", conn_id,
+ LOGPFSMSL(conn->fi, DLCS, LOGL_INFO, "Opening new SCCP connection (id=%u) to SMLC: %s\n", conn_id,
osmo_sccp_addr_name(ss7, &bsc_gsmnet->smlc->smlc_addr));
rc = osmo_sccp_tx_conn_req_msg(bsc_gsmnet->smlc->sccp_user, conn_id, &bsc_gsmnet->smlc->bsc_addr,
diff --git a/src/osmo-bsc/osmo_bsc_sigtran.c b/src/osmo-bsc/osmo_bsc_sigtran.c
index 88ee01c2e..748b3f0b0 100644
--- a/src/osmo-bsc/osmo_bsc_sigtran.c
+++ b/src/osmo-bsc/osmo_bsc_sigtran.c
@@ -46,9 +46,9 @@ static struct llist_head *msc_list;
#define DEFAULT_ASP_REMOTE_IP "localhost"
/* 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)
+static struct gsm_subscriber_connection *get_bsc_conn_by_conn_id(uint32_t conn_id)
{
- conn_id &= 0xFFFFFF;
+ conn_id &= SCCP_CONN_ID_MAX;
struct gsm_subscriber_connection *conn;
llist_for_each_entry(conn, &bsc_gsmnet->subscr_conns, entry) {
@@ -317,13 +317,13 @@ __attribute__((weak)) int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_conne
{
struct osmo_ss7_instance *ss7;
struct bsc_msc_data *msc;
- int conn_id;
+ uint32_t conn_id;
int rc;
OSMO_ASSERT(conn);
OSMO_ASSERT(msg);
OSMO_ASSERT(conn->sccp.msc);
- OSMO_ASSERT(conn->sccp.conn_id == -1);
+ OSMO_ASSERT(conn->sccp.conn_id == SCCP_CONN_ID_UNSET);
msc = conn->sccp.msc;
@@ -333,14 +333,14 @@ __attribute__((weak)) int osmo_bsc_sigtran_open_conn(struct gsm_subscriber_conne
}
conn->sccp.conn_id = conn_id = bsc_sccp_inst_next_conn_id(conn->sccp.msc->a.sccp);
- if (conn->sccp.conn_id < 0) {
+ if (conn->sccp.conn_id == SCCP_CONN_ID_UNSET) {
LOGP(DMSC, LOGL_ERROR, "Unable to allocate SCCP Connection ID\n");
return -1;
}
- LOGP(DMSC, LOGL_DEBUG, "Allocated new connection id: %d\n", conn->sccp.conn_id);
+ LOGP(DMSC, LOGL_DEBUG, "Allocated new connection id: %u\n", conn->sccp.conn_id);
ss7 = osmo_ss7_instance_find(msc->a.cs7_instance);
OSMO_ASSERT(ss7);
- LOGP(DMSC, LOGL_INFO, "Opening new SCCP connection (id=%i) to MSC %d: %s\n", conn_id,
+ LOGP(DMSC, LOGL_INFO, "Opening new SCCP connection (id=%u) to MSC %d: %s\n", conn_id,
msc->nr, osmo_sccp_addr_name(ss7, &msc->a.msc_addr));
rc = osmo_sccp_tx_conn_req_msg(msc->a.sccp_user, conn_id, &msc->a.bsc_addr,