Change in osmo-bsc[master]: lchan_fsm: make rsl mode-modify working again

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/.

dexter gerrit-no-reply at lists.osmocom.org
Fri Aug 21 21:16:00 UTC 2020


dexter has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bsc/+/19792 )


Change subject: lchan_fsm: make rsl mode-modify working again
......................................................................

lchan_fsm: make rsl mode-modify working again

osmo-nitb supports the modification of an lchan if the lchan is
compatible but in the wrong mode. This feature was dropped in the
transition to AoIP/bsc-split. However, osmo-bsc still has code to
generate and parse the messeages, but the FSMs do not support a mode
modify yetm

Lets add handling for mode-modify to the lchan_fsm and assignment_fsm in
order to support mode modify again

Change-Id: I2c5a283b1ee33745cc1fcfcc09a0f9382224e2eb
Related: OS#4549
---
M include/osmocom/bsc/lchan_fsm.h
M src/osmo-bsc/abis_rsl.c
M src/osmo-bsc/assignment_fsm.c
M src/osmo-bsc/gsm_04_08_rr.c
M src/osmo-bsc/lchan_fsm.c
5 files changed, 194 insertions(+), 41 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bsc refs/changes/92/19792/1

diff --git a/include/osmocom/bsc/lchan_fsm.h b/include/osmocom/bsc/lchan_fsm.h
index 55ab024..e5b3707 100644
--- a/include/osmocom/bsc/lchan_fsm.h
+++ b/include/osmocom/bsc/lchan_fsm.h
@@ -18,6 +18,8 @@
 	LCHAN_ST_WAIT_TS_READY,
 	LCHAN_ST_WAIT_ACTIV_ACK, /*< After RSL Chan Act Ack, lchan is active but RTP not configured. */
 	LCHAN_ST_WAIT_RLL_RTP_ESTABLISH,
+	LCHAN_ST_WAIT_CHAN_MODE_MODIF_ACK,
+	LCHAN_ST_WAIT_RSL_MT_MODE_MODIFY_ACK,
 	LCHAN_ST_ESTABLISHED, /*< Active and RTP is fully configured. */
 	LCHAN_ST_WAIT_RLL_RTP_RELEASED,
 	LCHAN_ST_WAIT_BEFORE_RF_RELEASE,
@@ -40,10 +42,10 @@
 	LCHAN_EV_RLL_REL_CONF,
 	LCHAN_EV_RSL_RF_CHAN_REL_ACK,
 	LCHAN_EV_RLL_ERR_IND,
-
-	/* FIXME: not yet implemented: Chan Mode Modify, see assignment_fsm_start(). */
 	LCHAN_EV_CHAN_MODE_MODIF_ACK,
 	LCHAN_EV_CHAN_MODE_MODIF_ERROR,
+	LCHAN_EV_RSL_MT_MODE_MODIFY_ACK,
+	LCHAN_EV_RSL_MT_MODE_MODIFY_NACK,
 };
 
 void lchan_fsm_init();
@@ -55,6 +57,8 @@
 void lchan_activate(struct gsm_lchan *lchan, struct lchan_activate_info *info);
 void lchan_ready_to_switch_rtp(struct gsm_lchan *lchan);
 
+void lchan_modfy(struct gsm_lchan *lchan, struct lchan_activate_info *info);
+
 static inline const char *lchan_state_name(struct gsm_lchan *lchan)
 {
 	return lchan->fi ? osmo_fsm_inst_state_name(lchan->fi) : "NULL";
diff --git a/src/osmo-bsc/abis_rsl.c b/src/osmo-bsc/abis_rsl.c
index 6787511..42f3a42 100644
--- a/src/osmo-bsc/abis_rsl.c
+++ b/src/osmo-bsc/abis_rsl.c
@@ -1186,10 +1186,12 @@
 	case RSL_MT_MODE_MODIFY_ACK:
 		LOG_LCHAN(msg->lchan, LOGL_DEBUG, "CHANNEL MODE MODIFY ACK\n");
 		count_codecs(sign_link->trx->bts, msg->lchan);
+		osmo_fsm_inst_dispatch(msg->lchan->fi, LCHAN_EV_RSL_MT_MODE_MODIFY_ACK, NULL);
 		break;
 	case RSL_MT_MODE_MODIFY_NACK:
 		LOG_LCHAN(msg->lchan, LOGL_DEBUG, "CHANNEL MODE MODIFY NACK\n");
 		rate_ctr_inc(&sign_link->trx->bts->bts_ctrs->ctr[BTS_CTR_MODE_MODIFY_NACK]);
+		osmo_fsm_inst_dispatch(msg->lchan->fi, LCHAN_EV_RSL_MT_MODE_MODIFY_NACK, NULL);
 		break;
 	case RSL_MT_IPAC_PDCH_ACT_ACK:
 		rc = rsl_rx_ipacc_pdch(msg, "ACT ACK", TS_EV_PDCH_ACT_ACK);
diff --git a/src/osmo-bsc/assignment_fsm.c b/src/osmo-bsc/assignment_fsm.c
index ca29daa..7592c2a 100644
--- a/src/osmo-bsc/assignment_fsm.c
+++ b/src/osmo-bsc/assignment_fsm.c
@@ -379,9 +379,8 @@
 	return 0;
 }
 
-/* Check if the conn is already associated with an lchan. If yes, we will check
- * if that lchan is compatible with the preferred rate/codec. If the lchan
- * turns out to be incompatible we try with the alternate rate/codec. */
+/* Decide if we should re-use an existing lchan. For this we check if the
+ * current lchan is compatible with one of the requested modes. */
 static bool reuse_existing_lchan(struct gsm_subscriber_connection *conn)
 {
 	struct assignment_request *req = &conn->assignment.req;
@@ -395,22 +394,10 @@
 	for (i = 0; i < req->n_ch_mode_rate; i++)
 		if (lchan_type_compat_with_mode(conn->lchan->type, &req->ch_mode_rate[i])) {
 			conn->lchan->ch_mode_rate = req->ch_mode_rate[i];
-			break;
+			return true;
 		}
 
-	if (i == req->n_ch_mode_rate)
-		return false;
-
-	if (conn->lchan->tch_mode != conn->lchan->ch_mode_rate.chan_mode) {
-		/* FIXME: send Channel Mode Modify to put the current lchan in the right mode, and kick
-		 * off its RTP stream setup code path. See gsm48_lchan_modify() and
-		 * gsm48_rx_rr_modif_ack(), and see lchan_fsm.h LCHAN_EV_CHAN_MODE_MODIF_* */
-		LOG_ASSIGNMENT(conn, LOGL_DEBUG,
-			       "Current lchan would be compatible, but Channel Mode Modify is not implemented\n");
-		return false;
-	}
-
-	return true;
+	return false;
 }
 
 void assignment_fsm_start(struct gsm_subscriber_connection *conn, struct gsm_bts *bts,
@@ -447,22 +434,60 @@
 		return;
 
 	/* There may be an already existing lchan, if yes, try to work with
-	 * the existing lchan */
+	 * the existing lchan. */
 	if (reuse_existing_lchan(conn)) {
+
+		/* If the requested mode and the current TCH mode matches up, just send the
+		 * assignment complete directly and be done with the assignment procedure.
+		 * however, this will be not the common case. */
+		if (conn->lchan->tch_mode == conn->lchan->ch_mode_rate.chan_mode) {
+			LOG_ASSIGNMENT(conn, LOGL_DEBUG,
+				       "Current lchan mode is compatible with requested chan_mode,"
+				       " sending BSSMAP Assignment Complete directly."
+				       " requested chan_mode=%s; current lchan is %s\n",
+				       gsm48_chan_mode_name(conn->lchan->ch_mode_rate.chan_mode),
+				       gsm_lchan_name(conn->lchan));
+
+			send_assignment_complete(conn);
+			/* If something went wrong during send_assignment_complete(),
+			 * the fi will be gone from error handling in there. */
+			if (conn->assignment.fi) {
+				assignment_count_result(CTR_ASSIGNMENT_COMPLETED);
+				osmo_fsm_inst_term(conn->assignment.fi, OSMO_FSM_TERM_REGULAR, 0);
+			}
+			return;
+		}
+
+		/* The requested mode does not match the current TCH mode but the lchan is
+		 * compatible. We will initiate a mode modify procedure. */
 		LOG_ASSIGNMENT(conn, LOGL_DEBUG,
-			       "Current lchan is compatible with requested chan_mode,"
-			       " sending BSSMAP Assignment Complete directly."
-			       " requested chan_mode=%s; current lchan is %s\n",
+			       "Current lchan mode is not compatible with requested chan_mode,"
+			       " so we will modify it. requested chan_mode=%s; current lchan is %s\n",
 			       gsm48_chan_mode_name(conn->lchan->ch_mode_rate.chan_mode),
 			       gsm_lchan_name(conn->lchan));
 
-		send_assignment_complete(conn);
-		/* If something went wrong during send_assignment_complete(), the fi will be gone from
-		 * error handling in there. */
-		if (conn->assignment.fi) {
-			assignment_count_result(CTR_ASSIGNMENT_COMPLETED);
-			osmo_fsm_inst_term(conn->assignment.fi, OSMO_FSM_TERM_REGULAR, 0);
-		}
+		info = (struct lchan_activate_info){
+			.activ_for = FOR_ASSIGNMENT,
+			.for_conn = conn,
+			.chan_mode = conn->lchan->ch_mode_rate.chan_mode,
+			.encr = conn->lchan->encr,
+			.s15_s0 = conn->lchan->ch_mode_rate.s15_s0,
+			.requires_voice_stream = conn->assignment.requires_voice_stream,
+			.msc_assigned_cic = req->msc_assigned_cic,
+			.re_use_mgw_endpoint_from_lchan = conn->lchan,
+		};
+
+		lchan_modfy(conn->lchan, &info);
+
+		/* Since we opted not to allocate a new lchan, the new lchan is
+		 * still the old lchan. */
+		conn->assignment.new_lchan = conn->lchan;
+
+		/* Also we need to spare the RR assignment, so we jump forward
+		 * and wait for the lchan_fsm until it reaches the established
+		 * state again. */
+		assignment_fsm_state_chg(ASSIGNMENT_ST_WAIT_LCHAN_ESTABLISHED);
+
 		return;
 	}
 
@@ -682,6 +707,7 @@
 		.out_state_mask = 0
 			| S(ASSIGNMENT_ST_WAIT_LCHAN_ACTIVE)
 			| S(ASSIGNMENT_ST_WAIT_RR_ASS_COMPLETE)
+			| S(ASSIGNMENT_ST_WAIT_LCHAN_ESTABLISHED) /* MODE MODIFY */
 			,
 	},
 	[ASSIGNMENT_ST_WAIT_RR_ASS_COMPLETE] = {
diff --git a/src/osmo-bsc/gsm_04_08_rr.c b/src/osmo-bsc/gsm_04_08_rr.c
index 69ec4d3..ef0fb4e 100644
--- a/src/osmo-bsc/gsm_04_08_rr.c
+++ b/src/osmo-bsc/gsm_04_08_rr.c
@@ -654,7 +654,6 @@
 
 int gsm48_rx_rr_modif_ack(struct msgb *msg)
 {
-	int rc;
 	struct gsm48_hdr *gh = msgb_l3(msg);
 	struct gsm48_chan_mode_modify *mod =
 				(struct gsm48_chan_mode_modify *) gh->data;
@@ -688,15 +687,7 @@
 		break;
 	}
 
-	/* We've successfully modified the MS side of the channel,
-	 * now go on to modify the BTS side of the channel */
-	rc = rsl_chan_mode_modify_req(msg->lchan);
-
-	/* FIXME: we not only need to do this after mode modify, but
-	 * also after channel activation */
-	if (is_ipaccess_bts(msg->lchan->ts->trx->bts) && mod->mode != GSM48_CMODE_SIGN)
-		rsl_tx_ipacc_crcx(msg->lchan);
-	return rc;
+	return 0;
 }
 
 int gsm48_parse_meas_rep(struct gsm_meas_rep *rep, struct msgb *msg)
diff --git a/src/osmo-bsc/lchan_fsm.c b/src/osmo-bsc/lchan_fsm.c
index 26bfd29..db72651 100644
--- a/src/osmo-bsc/lchan_fsm.c
+++ b/src/osmo-bsc/lchan_fsm.c
@@ -59,6 +59,7 @@
 	switch (lchan->fi->state) {
 	case LCHAN_ST_WAIT_RLL_RTP_ESTABLISH:
 	case LCHAN_ST_ESTABLISHED:
+	case LCHAN_ST_WAIT_CHAN_MODE_MODIF_ACK:
 		return true;
 	default:
 		return false;
@@ -249,7 +250,7 @@
 	} while(0)
 
 /* Which state to transition to when lchan_fail() is called in a given state. */
-uint32_t lchan_fsm_on_error[32] = {
+uint32_t lchan_fsm_on_error[34] = {
 	[LCHAN_ST_UNUSED] 			= LCHAN_ST_UNUSED,
 	[LCHAN_ST_WAIT_TS_READY] 		= LCHAN_ST_UNUSED,
 	[LCHAN_ST_WAIT_ACTIV_ACK] 		= LCHAN_ST_BORKEN,
@@ -260,6 +261,8 @@
 	[LCHAN_ST_WAIT_RF_RELEASE_ACK] 		= LCHAN_ST_BORKEN,
 	[LCHAN_ST_WAIT_AFTER_ERROR] 		= LCHAN_ST_UNUSED,
 	[LCHAN_ST_BORKEN] 			= LCHAN_ST_BORKEN,
+	[LCHAN_ST_WAIT_CHAN_MODE_MODIF_ACK] 	= LCHAN_ST_BORKEN,
+	[LCHAN_ST_WAIT_RSL_MT_MODE_MODIFY_ACK] 	= LCHAN_ST_BORKEN,
 };
 
 #define lchan_fail(fmt, args...) lchan_fail_to(lchan_fsm_on_error[fi->state], fmt, ## args)
@@ -523,6 +526,53 @@
 	}
 }
 
+void lchan_modfy(struct gsm_lchan *lchan, struct lchan_activate_info *info)
+{
+	struct osmo_fsm_inst *fi;
+	struct osmo_mgcpc_ep_ci *use_mgwep_ci;
+
+	OSMO_ASSERT(lchan && info);
+	fi = lchan->fi;
+
+	/* It is only possible to modify already established lchans. */
+	if (!lchan_state_is(lchan, LCHAN_ST_ESTABLISHED))
+		goto abort;
+
+	lchan->activate.info = *info;
+	use_mgwep_ci = lchan_use_mgw_endpoint_ci_bts(lchan);
+
+	if (info->chan_mode == GSM48_CMODE_SPEECH_AMR) {
+		if (lchan_mr_config(lchan, info->s15_s0) < 0) {
+			lchan_fail("Can not generate multirate configuration IE\n");
+			return;
+		}
+	}
+
+	LOG_LCHAN(lchan, LOGL_INFO,
+		  "Modification requested: %s voice=%s MGW-ci=%s type=%s tch-mode=%s encr-alg=A5/%u ck=%s\n",
+		  lchan_activate_mode_name(lchan->activate.info.activ_for),
+		  lchan->activate.info.requires_voice_stream ? "yes" : "no",
+		  lchan->activate.info.requires_voice_stream ?
+		  (use_mgwep_ci ? osmo_mgcpc_ep_ci_name(use_mgwep_ci) : "new")
+		  : "none",
+		  gsm_lchant_name(lchan->type),
+		  gsm48_chan_mode_name(lchan->tch_mode),
+		  (lchan->activate.info.encr.alg_id ? : 1) - 1,
+		  lchan->activate.info.encr.key_len ? osmo_hexdump_nospc(lchan->activate.info.encr.key,
+									 lchan->activate.info.encr.key_len) : "none");
+
+	/* While the mode is changed the lchan is virtually "not activated", at least
+	 * from the FSM implementations perspective */
+	lchan->activate.concluded = false;
+
+	/* Initiate mode modfication, start with the MS side (RR) */
+	lchan_fsm_state_chg(LCHAN_ST_WAIT_CHAN_MODE_MODIF_ACK);
+	gsm48_lchan_modify(lchan, info->chan_mode);
+	return;
+abort:
+	lchan_release(lchan, !!(lchan->conn), true, RSL_ERR_EQUIPMENT_FAIL);
+}
+
 static void lchan_fsm_wait_ts_ready_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
 {
 	struct gsm_lchan *lchan = lchan_fi_lchan(fi);
@@ -833,6 +883,59 @@
 	}
 }
 
+static void lchan_fsm_wait_chan_mode_modif_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+	struct gsm_lchan *lchan = lchan_fi_lchan(fi);
+	int rc;
+
+	switch (event) {
+
+	case LCHAN_EV_CHAN_MODE_MODIF_ACK:
+		lchan_fsm_state_chg(LCHAN_ST_WAIT_RSL_MT_MODE_MODIFY_ACK);
+		rc = rsl_chan_mode_modify_req(lchan);
+		if (rc < 0) {
+			lchan_fail("Failed to send rsl message to change the channel mode on the BTS side: %s in state %s\n",
+				   osmo_fsm_event_name(fi->fsm, event),
+				   osmo_fsm_inst_state_name(fi));
+		}
+		return;
+
+	case LCHAN_EV_CHAN_MODE_MODIF_ERROR:
+		lchan_fail("Failed to change channel mode on the MS side: %s in state %s\n",
+			   osmo_fsm_event_name(fi->fsm, event),
+			   osmo_fsm_inst_state_name(fi));
+		return;
+
+	default:
+		OSMO_ASSERT(false);
+	}
+}
+
+static void lchan_fsm_wait_rsl_mt_mode_modify_ack(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+	struct gsm_lchan *lchan = lchan_fi_lchan(fi);
+	switch (event) {
+
+	case LCHAN_EV_RSL_MT_MODE_MODIFY_ACK:
+		/* Prepare an MGW endpoint CI if appropriate. */
+		if (lchan->activate.info.requires_voice_stream) {
+			lchan_fsm_state_chg(LCHAN_ST_WAIT_RLL_RTP_ESTABLISH);
+			lchan_rtp_fsm_start(lchan);
+		} else
+			lchan_fsm_state_chg(LCHAN_ST_ESTABLISHED);
+		return;
+
+	case LCHAN_EV_RSL_MT_MODE_MODIFY_NACK:
+		lchan_fail("Failed to change channel mode on the BTS side: %s in state %s\n",
+			   osmo_fsm_event_name(fi->fsm, event),
+			   osmo_fsm_inst_state_name(fi));
+		return;
+
+	default:
+		OSMO_ASSERT(false);
+	}
+}
+
 static void lchan_fsm_established_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
 {
 	struct gsm_lchan *lchan = lchan_fi_lchan(fi);
@@ -1223,6 +1326,30 @@
 			| S(LCHAN_ST_WAIT_RLL_RTP_RELEASED)
 			,
 	},
+	[LCHAN_ST_WAIT_CHAN_MODE_MODIF_ACK] = {
+		.name = "WAIT_CHAN_MODE_MODIF_ACK",
+		.action = lchan_fsm_wait_chan_mode_modif_ack,
+		.in_event_mask = 0
+			| S(LCHAN_EV_CHAN_MODE_MODIF_ACK)
+			| S(LCHAN_EV_CHAN_MODE_MODIF_ERROR)
+			,
+		.out_state_mask = 0
+			| S(LCHAN_ST_BORKEN)
+			| S(LCHAN_ST_WAIT_RSL_MT_MODE_MODIFY_ACK)
+			,
+	},
+	[LCHAN_ST_WAIT_RSL_MT_MODE_MODIFY_ACK] = {
+		.name = "WAIT_RSL_MT_MODE_MODIFY_ACK",
+		.action = lchan_fsm_wait_rsl_mt_mode_modify_ack,
+		.in_event_mask = 0
+			| S(LCHAN_EV_RSL_MT_MODE_MODIFY_ACK)
+			| S(LCHAN_EV_RSL_MT_MODE_MODIFY_NACK)
+			,
+		.out_state_mask = 0
+			| S(LCHAN_ST_BORKEN)
+			| S(LCHAN_ST_WAIT_RLL_RTP_ESTABLISH)
+			,
+	},
 	[LCHAN_ST_ESTABLISHED] = {
 		.name = "ESTABLISHED",
 		.onenter = lchan_fsm_established_onenter,
@@ -1239,6 +1366,7 @@
 			| S(LCHAN_ST_WAIT_RLL_RTP_RELEASED)
 			| S(LCHAN_ST_WAIT_BEFORE_RF_RELEASE)
 			| S(LCHAN_ST_WAIT_RF_RELEASE_ACK)
+			| S(LCHAN_ST_WAIT_CHAN_MODE_MODIF_ACK)
 			,
 	},
 	[LCHAN_ST_WAIT_RLL_RTP_RELEASED] = {
@@ -1326,6 +1454,8 @@
 	OSMO_VALUE_STRING(LCHAN_EV_RLL_ERR_IND),
 	OSMO_VALUE_STRING(LCHAN_EV_CHAN_MODE_MODIF_ACK),
 	OSMO_VALUE_STRING(LCHAN_EV_CHAN_MODE_MODIF_ERROR),
+	OSMO_VALUE_STRING(LCHAN_EV_RSL_MT_MODE_MODIFY_ACK),
+	OSMO_VALUE_STRING(LCHAN_EV_RSL_MT_MODE_MODIFY_NACK),
 	{}
 };
 

-- 
To view, visit https://gerrit.osmocom.org/c/osmo-bsc/+/19792
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-Change-Id: I2c5a283b1ee33745cc1fcfcc09a0f9382224e2eb
Gerrit-Change-Number: 19792
Gerrit-PatchSet: 1
Gerrit-Owner: dexter <pmaier at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200821/9956f9f3/attachment.htm>


More information about the gerrit-log mailing list