Change in osmo-bts[master]: Introduce NM operative state Radio Carrier FSM

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

pespin gerrit-no-reply at lists.osmocom.org
Fri Sep 25 17:54:32 UTC 2020


pespin has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-bts/+/20284 )


Change subject: Introduce NM operative state Radio Carrier FSM
......................................................................

Introduce NM operative state Radio Carrier FSM

All the Operative State logic to manage a RadioCarrier NM object is
centralized in this FSM, where other parts of the code simply send
events to it.
This allows keeping state consistent and offloading logic from each bts
backend, since they are only required to submit events now.
The idea in the long run is to also replace other NM objects with
similar FSMs.

This improved logic fixes bug where PHY + RSL link became available before
OPSTART and hence op state changed to Enabled before receiving any OPSTART message.

Change-Id: Ifb249a821c4270918699b6375a72b3a618e8cfbe
---
M include/osmo-bts/Makefile.am
M include/osmo-bts/bts_trx.h
A include/osmo-bts/nm_radio_carrier_fsm.h
M src/common/Makefile.am
M src/common/bts_trx.c
A src/common/nm_radio_carrier_fsm.c
M src/common/phy_link.c
M src/osmo-bts-litecell15/l1_if.c
M src/osmo-bts-litecell15/oml.c
M src/osmo-bts-oc2g/l1_if.c
M src/osmo-bts-oc2g/oml.c
M src/osmo-bts-octphy/l1_if.c
M src/osmo-bts-octphy/l1_oml.c
M src/osmo-bts-omldummy/bts_model.c
M src/osmo-bts-sysmo/l1_if.c
M src/osmo-bts-sysmo/oml.c
M src/osmo-bts-trx/l1_if.c
M src/osmo-bts-virtual/bts_model.c
18 files changed, 354 insertions(+), 44 deletions(-)



  git pull ssh://gerrit.osmocom.org:29418/osmo-bts refs/changes/84/20284/1

diff --git a/include/osmo-bts/Makefile.am b/include/osmo-bts/Makefile.am
index cdbaa4f..0a758c6 100644
--- a/include/osmo-bts/Makefile.am
+++ b/include/osmo-bts/Makefile.am
@@ -27,4 +27,5 @@
 	phy_link.h \
 	dtx_dl_amr_fsm.h \
 	ta_control.h \
+	nm_radio_carrier_fsm.h \
 	$(NULL)
diff --git a/include/osmo-bts/bts_trx.h b/include/osmo-bts/bts_trx.h
index ce2d4d4..a4c2d37 100644
--- a/include/osmo-bts/bts_trx.h
+++ b/include/osmo-bts/bts_trx.h
@@ -16,6 +16,9 @@
 	uint8_t rsl_tei;
 	struct e1inp_sign_link *rsl_link;
 
+	/* NM Radio Carrier and Baseband Transciever FSM */
+	struct osmo_fsm_inst *nm_rcarrier_fi;
+	bool opstart_success; /* OPSTART went OK in lower layers and was acked */
 	struct gsm_abis_mo mo;
 	struct {
 		struct gsm_abis_mo mo;
diff --git a/include/osmo-bts/nm_radio_carrier_fsm.h b/include/osmo-bts/nm_radio_carrier_fsm.h
new file mode 100644
index 0000000..1b4b269
--- /dev/null
+++ b/include/osmo-bts/nm_radio_carrier_fsm.h
@@ -0,0 +1,45 @@
+/* NM Radio Carrier FSM. Following 3GPP TS 12.21 Figure 2/GSM 12.21:
+  GSM 12.21 Objects' Operational state and availability status behaviour during initialization */
+
+/* (C) 2020 by sysmocom - s.m.f.c. GmbH <info at sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * 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 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/>.
+ *
+ */
+
+#pragma once
+
+#include <osmocom/core/fsm.h>
+
+enum nm_rcarrier_op_fsm_states {
+	NM_RCARRIER_ST_OP_DISABLED_NOTINSTALLED,
+	NM_RCARRIER_ST_OP_DISABLED_OFFLINE,
+	NM_RCARRIER_ST_OP_ENABLED,
+};
+
+enum nm_radio_carrier_op_fsm_events {
+	NM_RCARRIER_EV_SW_ACT,
+	NM_RCARRIER_EV_OPSTART_ACK,
+	NM_RCARRIER_EV_OPSTART_NACK,
+	NM_RCARRIER_EV_RSL_UP,
+	NM_RCARRIER_EV_RSL_DOWN,
+	NM_RCARRIER_EV_PHYLINK_UP,
+	NM_RCARRIER_EV_PHYLINK_DOWN,
+	NM_RCARRIER_EV_DISABLE,
+};
+
+extern struct osmo_fsm nm_rcarrier_fsm;
diff --git a/src/common/Makefile.am b/src/common/Makefile.am
index e3a72dc..eea6284 100644
--- a/src/common/Makefile.am
+++ b/src/common/Makefile.am
@@ -37,6 +37,7 @@
 	dtx_dl_amr_fsm.c \
 	scheduler_mframe.c \
 	ta_control.c \
+	nm_radio_carrier_fsm.c \
 	$(NULL)
 
 libl1sched_a_SOURCES = scheduler.c
diff --git a/src/common/bts_trx.c b/src/common/bts_trx.c
index 93e15c3..1c5fb98 100644
--- a/src/common/bts_trx.c
+++ b/src/common/bts_trx.c
@@ -17,6 +17,8 @@
  *
  */
 
+#include <osmocom/core/fsm.h>
+
 #include <osmocom/gsm/abis_nm.h>
 
 #include <osmo-bts/logging.h>
@@ -26,6 +28,7 @@
 #include <osmo-bts/bts_model.h>
 #include <osmo-bts/rsl.h>
 #include <osmo-bts/phy_link.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 struct gsm_bts_trx *gsm_bts_trx_alloc(struct gsm_bts *bts)
 {
@@ -38,6 +41,10 @@
 	trx->bts = bts;
 	trx->nr = bts->num_trx++;
 
+	trx->nm_rcarrier_fi = osmo_fsm_inst_alloc(&nm_rcarrier_fsm, trx, trx,
+						  LOGL_INFO, NULL);
+	osmo_fsm_inst_update_id_f(trx->nm_rcarrier_fi, "bts%d-trx%d", bts->nr, trx->nr);
+
 	gsm_mo_init(&trx->mo, bts, NM_OC_RADIO_CARRIER,
 		    bts->nr, trx->nr, 0xff);
 
@@ -161,7 +168,7 @@
 	LOGPTRX(trx, DSUM, LOGL_INFO, "RSL link %s\n",
 		link ? "up" : "down");
 
-	trx_operability_update(trx);
+	osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, link ? NM_RCARRIER_EV_RSL_UP : NM_RCARRIER_EV_RSL_DOWN, NULL);
 
 	if (link)
 		rc = rsl_tx_rf_res(trx);
@@ -177,22 +184,6 @@
 	return 0;
 }
 
-/* set the availability of the TRX based on internal state (RSL + phy link) */
-void trx_operability_update(struct gsm_bts_trx *trx)
-{
-	enum abis_nm_op_state op_st;
-	enum abis_nm_avail_state avail_st;
-	struct phy_instance *pinst = trx_phy_instance(trx);
-
-	op_st = (trx->rsl_link && phy_link_state_get(pinst->phy_link) == PHY_LINK_CONNECTED) ?
-		NM_OPSTATE_ENABLED : NM_OPSTATE_DISABLED;
-	avail_st = (op_st == NM_OPSTATE_ENABLED) ? NM_AVSTATE_OK : NM_AVSTATE_NOT_INSTALLED;
-
-	LOGPTRX(trx, DSUM, LOGL_INFO, "Setting operative = %s\n", abis_nm_opstate_name(op_st));
-	oml_mo_state_chg(&trx->mo, op_st, avail_st);
-	oml_mo_state_chg(&trx->bb_transc.mo, -1, avail_st);
-}
-
 
 bool trx_ms_pwr_ctrl_is_osmo(const struct gsm_bts_trx *trx)
 {
diff --git a/src/common/nm_radio_carrier_fsm.c b/src/common/nm_radio_carrier_fsm.c
new file mode 100644
index 0000000..f05e9ac
--- /dev/null
+++ b/src/common/nm_radio_carrier_fsm.c
@@ -0,0 +1,215 @@
+/* NM Radio Carrier FSM */
+
+/* (C) 2020 by sysmocom - s.m.f.c. GmbH <info at sysmocom.de>
+ * Author: Pau Espin Pedrol <pespin at sysmocom.de>
+ *
+ * All Rights Reserved
+ *
+ * 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 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 <errno.h>
+#include <unistd.h>
+#include <inttypes.h>
+
+#include <osmocom/core/fsm.h>
+#include <osmocom/core/tdef.h>
+#include <osmocom/gsm/protocol/gsm_12_21.h>
+
+#include <osmo-bts/logging.h>
+#include <osmo-bts/gsm_data.h>
+#include <osmo-bts/bts_model.h>
+#include <osmo-bts/bts.h>
+#include <osmo-bts/rsl.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
+#include <osmo-bts/phy_link.h>
+
+#define X(s) (1 << (s))
+
+#define nm_rcarrier_fsm_state_chg(fi, NEXT_STATE) \
+	osmo_fsm_inst_state_chg(fi, NEXT_STATE, 0, 0)
+
+//////////////////////////
+// FSM STATE ACTIONS
+//////////////////////////
+
+static void st_op_disabled_notinstalled_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct gsm_bts_trx *trx = (struct gsm_bts_trx *)fi->priv;
+	trx->opstart_success = false;
+	oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED);
+	oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_NOT_INSTALLED);
+}
+
+static void st_op_disabled_notinstalled(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+	struct gsm_bts_trx *trx = (struct gsm_bts_trx *)fi->priv;
+
+	switch (event) {
+	case NM_RCARRIER_EV_SW_ACT:
+		oml_mo_tx_sw_act_rep(&trx->mo);
+		nm_rcarrier_fsm_state_chg(fi, NM_RCARRIER_ST_OP_DISABLED_OFFLINE);
+		return;
+	case NM_RCARRIER_EV_RSL_UP:
+		return;
+	case NM_RCARRIER_EV_RSL_DOWN:
+		return;
+	case NM_RCARRIER_EV_PHYLINK_UP:
+		return;
+	case NM_RCARRIER_EV_PHYLINK_DOWN:
+		return;
+	case NM_RCARRIER_EV_DISABLE:
+		return;
+	default:
+		OSMO_ASSERT(0);
+	}
+}
+
+static void st_op_disabled_offline_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct gsm_bts_trx *trx = (struct gsm_bts_trx *)fi->priv;
+	trx->opstart_success = false;
+	oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OFF_LINE);
+	oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OFF_LINE);
+}
+
+static void st_op_disabled_offline(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+	struct gsm_bts_trx *trx = (struct gsm_bts_trx *)fi->priv;
+	struct phy_instance *pinst = trx_phy_instance(trx);
+	struct phy_link *plink = pinst->phy_link;
+
+	switch (event) {
+	case NM_RCARRIER_EV_OPSTART_ACK:
+		trx->opstart_success = true;
+		oml_mo_opstart_ack(&trx->mo);
+		break; /* check statechg below */
+	case NM_RCARRIER_EV_OPSTART_NACK:
+		trx->opstart_success = false;
+		oml_mo_opstart_nack(&trx->mo, (int)(intptr_t)data);
+		return;
+	case NM_RCARRIER_EV_RSL_UP:
+		break; /* check statechg below */
+	case NM_RCARRIER_EV_RSL_DOWN:
+		return;
+	case NM_RCARRIER_EV_PHYLINK_UP:
+		break; /* check statechg below */
+	case NM_RCARRIER_EV_PHYLINK_DOWN:
+		return;
+	case NM_RCARRIER_EV_DISABLE:
+		return;
+	default:
+		OSMO_ASSERT(0);
+	}
+
+	if (trx->rsl_link && (phy_link_state_get(plink) == PHY_LINK_CONNECTED) &&
+	    trx->opstart_success) {
+		nm_rcarrier_fsm_state_chg(fi, NM_RCARRIER_ST_OP_ENABLED);
+	} else {
+		LOGPFSML(fi, LOGL_INFO, "Delay switch to operative state Enabled, wait for:%s%s%s\n",
+			 trx->rsl_link ? "": " rsl",
+			 (phy_link_state_get(plink) == PHY_LINK_CONNECTED) ? "": " phy",
+			 trx->opstart_success ? "": " opstart");
+
+	}
+}
+
+static void st_op_enabled_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state)
+{
+	struct gsm_bts_trx *trx = (struct gsm_bts_trx *)fi->priv;
+	oml_mo_state_chg(&trx->mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
+	oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
+}
+
+static void st_op_enabled(struct osmo_fsm_inst *fi, uint32_t event, void *data)
+{
+	switch (event) {
+	case NM_RCARRIER_EV_RSL_DOWN:
+		break;
+	case NM_RCARRIER_EV_PHYLINK_DOWN:
+		break;
+	case NM_RCARRIER_EV_DISABLE:
+		break;
+	default:
+		OSMO_ASSERT(0);
+	}
+
+	nm_rcarrier_fsm_state_chg(fi, NM_RCARRIER_ST_OP_DISABLED_OFFLINE);
+}
+
+static struct osmo_fsm_state nm_rcarrier_fsm_states[] = {
+	[NM_RCARRIER_ST_OP_DISABLED_NOTINSTALLED] = {
+		.in_event_mask =
+			X(NM_RCARRIER_EV_SW_ACT) |
+			X(NM_RCARRIER_EV_RSL_UP) |
+			X(NM_RCARRIER_EV_RSL_DOWN) |
+			X(NM_RCARRIER_EV_PHYLINK_UP) |
+			X(NM_RCARRIER_EV_PHYLINK_DOWN),
+		.out_state_mask =
+			X(NM_RCARRIER_ST_OP_DISABLED_OFFLINE),
+		.name = "DISABLED_NOTINSTALLED",
+		.onenter = st_op_disabled_notinstalled_on_enter,
+		.action = st_op_disabled_notinstalled,
+	},
+	[NM_RCARRIER_ST_OP_DISABLED_OFFLINE] = {
+		.in_event_mask =
+			X(NM_RCARRIER_EV_OPSTART_ACK) |
+			X(NM_RCARRIER_EV_OPSTART_NACK) |
+			X(NM_RCARRIER_EV_RSL_UP) |
+			X(NM_RCARRIER_EV_RSL_DOWN) |
+			X(NM_RCARRIER_EV_PHYLINK_UP) |
+			X(NM_RCARRIER_EV_PHYLINK_DOWN),
+		.out_state_mask =
+			X(NM_RCARRIER_ST_OP_ENABLED),
+		.name = "DISABLED_OFFLINE",
+		.onenter = st_op_disabled_offline_on_enter,
+		.action = st_op_disabled_offline,
+	},
+	[NM_RCARRIER_ST_OP_ENABLED] = {
+		.in_event_mask =
+			X(NM_RCARRIER_EV_RSL_DOWN) |
+			X(NM_RCARRIER_EV_PHYLINK_DOWN),
+		.out_state_mask =
+			X(NM_RCARRIER_ST_OP_DISABLED_OFFLINE),
+		.name = "ENABLED",
+		.onenter = st_op_enabled_on_enter,
+		.action = st_op_enabled,
+	},
+};
+
+const struct value_string nm_rcarrier_fsm_event_names[] = {
+	{ NM_RCARRIER_EV_SW_ACT, "SW_ACT" },
+	{ NM_RCARRIER_EV_OPSTART_ACK, "OPSTART_ACK" },
+	{ NM_RCARRIER_EV_OPSTART_NACK, "OPSTART_NACK" },
+	{ NM_RCARRIER_EV_RSL_UP, "RSL_UP" },
+	{ NM_RCARRIER_EV_RSL_DOWN, "RSL_DOWN" },
+	{ NM_RCARRIER_EV_PHYLINK_UP, "PHYLINK_UP" },
+	{ NM_RCARRIER_EV_PHYLINK_DOWN, "PHYLINK_DOWN" },
+	{ NM_RCARRIER_EV_DISABLE, "DISABLE" },
+	{ 0, NULL }
+};
+
+struct osmo_fsm nm_rcarrier_fsm = {
+	.name = "NM_RCARRIER_OP",
+	.states = nm_rcarrier_fsm_states,
+	.num_states = ARRAY_SIZE(nm_rcarrier_fsm_states),
+	.event_names = nm_rcarrier_fsm_event_names,
+	.log_subsys = DOML,
+};
+
+static __attribute__((constructor)) void nm_rcarrier_fsm_init(void)
+{
+	OSMO_ASSERT(osmo_fsm_register(&nm_rcarrier_fsm) == 0);
+}
diff --git a/src/common/phy_link.c b/src/common/phy_link.c
index d13d3f1..2616b70 100644
--- a/src/common/phy_link.c
+++ b/src/common/phy_link.c
@@ -2,6 +2,7 @@
 
 #include <osmocom/core/linuxlist.h>
 #include <osmocom/core/talloc.h>
+#include <osmocom/core/fsm.h>
 
 #include <osmo-bts/bts.h>
 #include <osmo-bts/gsm_data.h>
@@ -9,6 +10,7 @@
 #include <osmo-bts/oml.h>
 #include <osmo-bts/logging.h>
 #include <osmo-bts/bts_model.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 static LLIST_HEAD(g_phy_links);
 
@@ -65,7 +67,10 @@
 		if (!trx)
 			continue;
 
-		trx_operability_update(trx);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi,
+				       state == PHY_LINK_CONNECTED ? NM_RCARRIER_EV_PHYLINK_UP :
+				                                     NM_RCARRIER_EV_PHYLINK_DOWN,
+				       NULL);
 	}
 }
 
diff --git a/src/osmo-bts-litecell15/l1_if.c b/src/osmo-bts-litecell15/l1_if.c
index 23f7c3d..60293aa 100644
--- a/src/osmo-bts-litecell15/l1_if.c
+++ b/src/osmo-bts-litecell15/l1_if.c
@@ -54,6 +54,7 @@
 #include <osmo-bts/l1sap.h>
 #include <osmo-bts/msg_utils.h>
 #include <osmo-bts/dtx_dl_amr_fsm.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 #include <nrw/litecell15/litecell15.h>
 #include <nrw/litecell15/gsml1prim.h>
@@ -1271,7 +1272,7 @@
 
 		/* signal availability */
 		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
-		oml_mo_tx_sw_act_rep(&trx->mo);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_SW_ACT, NULL);
 		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
 		oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
 
diff --git a/src/osmo-bts-litecell15/oml.c b/src/osmo-bts-litecell15/oml.c
index f14f808..e5f6404 100644
--- a/src/osmo-bts-litecell15/oml.c
+++ b/src/osmo-bts-litecell15/oml.c
@@ -268,17 +268,26 @@
 {
 	GsmL1_Prim_t *l1p = msgb_l1prim(l1_msg);
 	GsmL1_Status_t status = prim_status(l1p);
+	struct gsm_bts_trx *trx = gsm_bts_trx_num(mo->bts, mo->obj_inst.trx_nr);
 
 	if (status != GsmL1_Status_Success) {
 		LOGP(DL1C, LOGL_ERROR, "Rx %s, status: %s\n",
 			get_value_string(lc15bts_l1prim_names, l1p->id),
 			get_value_string(lc15bts_l1status_names, status));
 		msgb_free(l1_msg);
-		return oml_mo_opstart_nack(mo, NM_NACK_CANT_PERFORM);
+		if (mo->obj_class == NM_OC_RADIO_CARRIER)
+			return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_NACK,
+						      (void*)(intptr_t)NM_NACK_CANT_PERFORM);
+		else
+			return oml_mo_opstart_nack(mo, NM_NACK_CANT_PERFORM);
 	}
 
 	msgb_free(l1_msg);
 
+	/* We already have a FSM for Radio Carrier, handle it there */
+	if (mo->obj_class == NM_OC_RADIO_CARRIER)
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+
 	/* Set to Operational State: Enabled */
 	oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
 
@@ -390,8 +399,9 @@
 				    ARRAY_SIZE(trx_rqd_attr))) {
 		/* HACK: spec says we need to decline, but openbsc
 		 * doesn't deal with this very well */
-		return oml_mo_opstart_ack(&trx->mo);
-		//return oml_mo_opstart_nack(&trx->mo, NM_NACK_CANT_PERFORM);
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+		//return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_NACK,
+		//				(void*)(intptr_t)NM_NACK_CANT_PERFORM);
 	}
 
 	/* Update TRX band */
diff --git a/src/osmo-bts-oc2g/l1_if.c b/src/osmo-bts-oc2g/l1_if.c
index 8e48674..be044b9 100644
--- a/src/osmo-bts-oc2g/l1_if.c
+++ b/src/osmo-bts-oc2g/l1_if.c
@@ -1324,8 +1324,7 @@
 			bts_update_status(BTS_STATUS_RF_ACTIVE, 1);
 
 		/* signal availability */
-		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
-		oml_mo_tx_sw_act_rep(&trx->mo);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_SW_ACT, NULL);
 		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
 		oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
 
diff --git a/src/osmo-bts-oc2g/oml.c b/src/osmo-bts-oc2g/oml.c
index f9faacf..13a4ed2 100644
--- a/src/osmo-bts-oc2g/oml.c
+++ b/src/osmo-bts-oc2g/oml.c
@@ -274,11 +274,19 @@
 			get_value_string(oc2gbts_l1prim_names, l1p->id),
 			get_value_string(oc2gbts_l1status_names, status));
 		msgb_free(l1_msg);
-		return oml_mo_opstart_nack(mo, NM_NACK_CANT_PERFORM);
+		if (mo->obj_class == NM_OC_RADIO_CARRIER)
+			return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_NACK,
+						      (void*)(intptr_t)NM_NACK_CANT_PERFORM);
+		else
+			return oml_mo_opstart_nack(mo, NM_NACK_CANT_PERFORM);
 	}
 
 	msgb_free(l1_msg);
 
+	/* We already have a FSM for Radio Carrier, handle it there */
+	if (mo->obj_class == NM_OC_RADIO_CARRIER)
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+
 	/* Set to Operational State: Enabled */
 	oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
 
diff --git a/src/osmo-bts-octphy/l1_if.c b/src/osmo-bts-octphy/l1_if.c
index c03b411..d8ba899 100644
--- a/src/osmo-bts-octphy/l1_if.c
+++ b/src/osmo-bts-octphy/l1_if.c
@@ -36,6 +36,7 @@
 
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/socket.h>
+#include <osmocom/core/fsm.h>
 
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/bts_model.h>
@@ -44,6 +45,7 @@
 #include <osmo-bts/l1sap.h>
 #include <osmo-bts/handover.h>
 #include <osmo-bts/bts.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 #include "l1_if.h"
 #include "l1_oml.h"
@@ -311,8 +313,7 @@
 	int i;
 	if (on) {
 		/* signal availability */
-		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
-		oml_mo_tx_sw_act_rep(&trx->mo);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_SW_ACT, NULL);
 		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
 		oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
 
diff --git a/src/osmo-bts-octphy/l1_oml.c b/src/osmo-bts-octphy/l1_oml.c
index 300d618..6aabdc7 100644
--- a/src/osmo-bts-octphy/l1_oml.c
+++ b/src/osmo-bts-octphy/l1_oml.c
@@ -28,6 +28,7 @@
 
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/utils.h>
+#include <osmocom/core/fsm.h>
 
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/logging.h>
@@ -38,6 +39,7 @@
 #include <osmo-bts/bts.h>
 #include <osmo-bts/bts_model.h>
 #include <osmo-bts/l1sap.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 #include "l1_if.h"
 #include "l1_oml.h"
@@ -186,6 +188,11 @@
 static int opstart_compl(struct gsm_abis_mo *mo)
 {
 	/* TODO: Send NACK in case of error! */
+	struct gsm_bts_trx *trx = gsm_bts_trx_num(mo->bts, mo->obj_inst.trx_nr);
+
+	/* We already have a FSM for Radio Carrier, handle it there */
+	if (mo->obj_class == NM_OC_RADIO_CARRIER)
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
 
 	/* Set to Operational State: Enabled */
 	oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
@@ -1437,8 +1444,9 @@
 				    ARRAY_SIZE(trx_rqd_attr))) {
 		/* HACK: spec says we need to decline, but openbsc
 		 * doesn't deal with this very well */
-		return oml_mo_opstart_ack(&trx->mo);
-		/* return oml_mo_opstart_nack(&trx->mo, NM_NACK_CANT_PERFORM); */
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+		//return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_NACK,
+		//				(void*)(intptr_t)NM_NACK_CANT_PERFORM);
 	}
 
 	l1if_check_app_version(trx);
diff --git a/src/osmo-bts-omldummy/bts_model.c b/src/osmo-bts-omldummy/bts_model.c
index 311b640..5b18775 100644
--- a/src/osmo-bts-omldummy/bts_model.c
+++ b/src/osmo-bts-omldummy/bts_model.c
@@ -23,6 +23,7 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/utils.h>
 #include <osmocom/codec/codec.h>
+#include <osmocom/core/fsm.h>
 
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/phy_link.h>
@@ -34,6 +35,7 @@
 #include <osmo-bts/bts_model.h>
 #include <osmo-bts/handover.h>
 #include <osmo-bts/l1sap.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 /* TODO: check if dummy method is sufficient, else implement */
 int bts_model_lchan_deactivate(struct gsm_lchan *lchan)
@@ -77,14 +79,13 @@
 	uint8_t tn;
 
 	llist_for_each_entry(trx, &bts->trx_list, list) {
-		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
 		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
 
 		for (tn = 0; tn < TRX_NR_TS; tn++)
 			oml_mo_state_chg(&trx->ts[tn].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_DEPENDENCY);
 
 		/* report availability of trx to the bts. this will trigger the rsl connection */
-		oml_mo_tx_sw_act_rep(&trx->mo);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_SW_ACT, NULL);
 		oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
 	}
 	return 0;
@@ -125,9 +126,13 @@
 int bts_model_opstart(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj)
 {
 	int rc;
+	struct gsm_bts_trx* trx;
 
 	switch (mo->obj_class) {
 	case NM_OC_RADIO_CARRIER:
+		trx = (struct gsm_bts_trx*) obj;
+		rc = osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+		break;
 	case NM_OC_CHANNEL:
 	case NM_OC_SITE_MANAGER:
 	case NM_OC_BASEB_TRANSC:
diff --git a/src/osmo-bts-sysmo/l1_if.c b/src/osmo-bts-sysmo/l1_if.c
index 2e5e5b6..4040bc9 100644
--- a/src/osmo-bts-sysmo/l1_if.c
+++ b/src/osmo-bts-sysmo/l1_if.c
@@ -51,6 +51,7 @@
 #include <osmo-bts/msg_utils.h>
 #include <osmo-bts/dtx_dl_amr_fsm.h>
 #include <osmo-bts/tx_power.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 #include <sysmocom/femtobts/superfemto.h>
 #include <sysmocom/femtobts/gsml1prim.h>
@@ -1240,8 +1241,7 @@
 			bts_update_status(BTS_STATUS_RF_ACTIVE, 1);
 
 		/* signal availability */
-		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
-		oml_mo_tx_sw_act_rep(&trx->mo);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_SW_ACT, NULL);
 		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
 		oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
 
diff --git a/src/osmo-bts-sysmo/oml.c b/src/osmo-bts-sysmo/oml.c
index 472a7ae..0a5c8b5 100644
--- a/src/osmo-bts-sysmo/oml.c
+++ b/src/osmo-bts-sysmo/oml.c
@@ -23,6 +23,7 @@
 
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/utils.h>
+#include <osmocom/core/fsm.h>
 
 #include <sysmocom/femtobts/gsml1prim.h>
 #include <sysmocom/femtobts/gsml1const.h>
@@ -39,6 +40,7 @@
 #include <osmo-bts/phy_link.h>
 #include <osmo-bts/handover.h>
 #include <osmo-bts/l1sap.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 #include "l1_if.h"
 #include "femtobts.h"
@@ -267,17 +269,26 @@
 {
 	GsmL1_Prim_t *l1p = msgb_l1prim(l1_msg);
 	GsmL1_Status_t status = prim_status(l1p);
+	struct gsm_bts_trx *trx = gsm_bts_trx_num(mo->bts, mo->obj_inst.trx_nr);
 
 	if (status != GsmL1_Status_Success) {
 		LOGP(DL1C, LOGL_ERROR, "Rx %s, status: %s\n",
 			get_value_string(femtobts_l1prim_names, l1p->id),
 			get_value_string(femtobts_l1status_names, status));
 		msgb_free(l1_msg);
-		return oml_mo_opstart_nack(mo, NM_NACK_CANT_PERFORM);
+		if (mo->obj_class == NM_OC_RADIO_CARRIER)
+			return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_NACK,
+						      (void*)(intptr_t)NM_NACK_CANT_PERFORM);
+		else
+			return oml_mo_opstart_nack(mo, NM_NACK_CANT_PERFORM);
 	}
 
 	msgb_free(l1_msg);
 
+	/* We already have a FSM for Radio Carrier, handle it there */
+	if (mo->obj_class == NM_OC_RADIO_CARRIER)
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+
 	/* Set to Operational State: Enabled */
 	oml_mo_state_chg(mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK);
 
@@ -394,8 +405,9 @@
 				    ARRAY_SIZE(trx_rqd_attr))) {
 		/* HACK: spec says we need to decline, but openbsc
 		 * doesn't deal with this very well */
-		return oml_mo_opstart_ack(&trx->mo);
-		//return oml_mo_opstart_nack(&trx->mo, NM_NACK_CANT_PERFORM);
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+		//return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_NACK,
+		//				(void*)(intptr_t)NM_NACK_CANT_PERFORM);
 	}
 
 	femto_band = sysmobts_select_femto_band(trx, trx->arfcn);
diff --git a/src/osmo-bts-trx/l1_if.c b/src/osmo-bts-trx/l1_if.c
index bd3661c..575b5ba 100644
--- a/src/osmo-bts-trx/l1_if.c
+++ b/src/osmo-bts-trx/l1_if.c
@@ -44,6 +44,7 @@
 #include <osmo-bts/abis.h>
 #include <osmo-bts/scheduler.h>
 #include <osmo-bts/pcu_if.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 #include "l1_if.h"
 #include "trx_if.h"
@@ -96,10 +97,9 @@
 	 * transceiver */
 	if (avail) {
 		/* signal availability */
-		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
 		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
 		if (!pinst->u.osmotrx.sw_act_reported) {
-			oml_mo_tx_sw_act_rep(&trx->mo);
+			osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_SW_ACT, NULL);
 			oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
 			pinst->u.osmotrx.sw_act_reported = true;
 		}
@@ -110,8 +110,7 @@
 					NM_AVSTATE_DEPENDENCY :
 					NM_AVSTATE_NOT_INSTALLED);
 	} else {
-		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED,
-			NM_AVSTATE_OFF_LINE);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_DISABLE, NULL);
 		oml_mo_state_chg(&trx->bb_transc.mo, NM_OPSTATE_DISABLED,
 			NM_AVSTATE_OFF_LINE);
 
@@ -202,13 +201,14 @@
 
 	rc = osmo_fsm_inst_dispatch(l1h->provision_fi, TRX_PROV_EV_CFG_ENABLE, (void*)(intptr_t)true);
 	if (rc != 0)
-		return oml_mo_opstart_nack(&trx->mo, NM_NACK_CANT_PERFORM);
+		return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_NACK,
+					      (void*)(intptr_t)NM_NACK_CANT_PERFORM);
 
 	if (trx == trx->bts->c0)
 		lchan_init_lapdm(&trx->ts[0].lchan[CCCH_LCHAN]);
 
 	/* Send OPSTART ack */
-	return oml_mo_opstart_ack(&trx->mo);
+	return osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
 }
 
 /* Deact RF on transceiver */
diff --git a/src/osmo-bts-virtual/bts_model.c b/src/osmo-bts-virtual/bts_model.c
index dfce81f..1c80eca 100644
--- a/src/osmo-bts-virtual/bts_model.c
+++ b/src/osmo-bts-virtual/bts_model.c
@@ -23,6 +23,7 @@
 #include <osmocom/core/talloc.h>
 #include <osmocom/core/utils.h>
 #include <osmocom/codec/codec.h>
+#include <osmocom/core/fsm.h>
 
 #include <osmo-bts/gsm_data.h>
 #include <osmo-bts/phy_link.h>
@@ -34,6 +35,7 @@
 #include <osmo-bts/bts_model.h>
 #include <osmo-bts/handover.h>
 #include <osmo-bts/l1sap.h>
+#include <osmo-bts/nm_radio_carrier_fsm.h>
 
 #include "virtual_um.h"
 
@@ -84,14 +86,13 @@
 	uint8_t tn;
 
 	llist_for_each_entry(trx, &bts->trx_list, list) {
-		oml_mo_state_chg(&trx->mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OK);
 		oml_mo_state_chg(&trx->bb_transc.mo, -1, NM_AVSTATE_OK);
 
 		for (tn = 0; tn < TRX_NR_TS; tn++)
 			oml_mo_state_chg(&trx->ts[tn].mo, NM_OPSTATE_DISABLED, NM_AVSTATE_DEPENDENCY);
 
 		/* report availability of trx to the bts. this will trigger the rsl connection */
-		oml_mo_tx_sw_act_rep(&trx->mo);
+		osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_SW_ACT, NULL);
 		oml_mo_tx_sw_act_rep(&trx->bb_transc.mo);
 	}
 	return 0;
@@ -139,9 +140,13 @@
 int bts_model_opstart(struct gsm_bts *bts, struct gsm_abis_mo *mo, void *obj)
 {
 	int rc;
+	struct gsm_bts_trx* trx;
 
 	switch (mo->obj_class) {
 	case NM_OC_RADIO_CARRIER:
+		trx = (struct gsm_bts_trx*) obj;
+		rc = osmo_fsm_inst_dispatch(trx->nm_rcarrier_fi, NM_RCARRIER_EV_OPSTART_ACK, NULL);
+		break;
 	case NM_OC_CHANNEL:
 	case NM_OC_SITE_MANAGER:
 	case NM_OC_BASEB_TRANSC:

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

Gerrit-Project: osmo-bts
Gerrit-Branch: master
Gerrit-Change-Id: Ifb249a821c4270918699b6375a72b3a618e8cfbe
Gerrit-Change-Number: 20284
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin at sysmocom.de>
Gerrit-MessageType: newchange
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20200925/38b19dc4/attachment.htm>


More information about the gerrit-log mailing list