diff options
Diffstat (limited to 'src/common/nm_bts_fsm.c')
-rw-r--r-- | src/common/nm_bts_fsm.c | 152 |
1 files changed, 152 insertions, 0 deletions
diff --git a/src/common/nm_bts_fsm.c b/src/common/nm_bts_fsm.c new file mode 100644 index 00000000..1343fb38 --- /dev/null +++ b/src/common/nm_bts_fsm.c @@ -0,0 +1,152 @@ +/* NM BTS FSM */ + +/* (C) 2020 by sysmocom - s.m.f.c. GmbH <info@sysmocom.de> + * Author: Pau Espin Pedrol <pespin@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_bts_fsm.h> +#include <osmo-bts/phy_link.h> + +#define X(s) (1 << (s)) + +#define nm_bts_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 *bts = (struct gsm_bts *)fi->priv; + bts->nm.opstart_success = false; + oml_mo_state_chg(&bts->nm.mo, NM_OPSTATE_DISABLED, NM_AVSTATE_NOT_INSTALLED); +} + +static void st_op_disabled_notinstalled(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct gsm_bts *bts = (struct gsm_bts *)fi->priv; + + switch (event) { + case NM_BTS_EV_SW_ACT: + oml_mo_tx_sw_act_rep(&bts->nm.mo); + nm_bts_fsm_state_chg(fi, NM_BTS_ST_OP_DISABLED_OFFLINE); + 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 *bts = (struct gsm_bts *)fi->priv; + bts->nm.opstart_success = false; + oml_mo_state_chg(&bts->nm.mo, NM_OPSTATE_DISABLED, NM_AVSTATE_OFF_LINE); +} + +static void st_op_disabled_offline(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ + struct gsm_bts *bts = (struct gsm_bts *)fi->priv; + + switch (event) { + case NM_BTS_EV_OPSTART_ACK: + bts->nm.opstart_success = true; + oml_mo_opstart_ack(&bts->nm.mo); + nm_bts_fsm_state_chg(fi, NM_BTS_ST_OP_ENABLED); + break; /* check statechg below */ + case NM_BTS_EV_OPSTART_NACK: + bts->nm.opstart_success = false; + oml_mo_opstart_nack(&bts->nm.mo, (int)(intptr_t)data); + return; + default: + OSMO_ASSERT(0); + } +} + +static void st_op_enabled_on_enter(struct osmo_fsm_inst *fi, uint32_t prev_state) +{ + struct gsm_bts *bts = (struct gsm_bts *)fi->priv; + oml_mo_state_chg(&bts->nm.mo, NM_OPSTATE_ENABLED, NM_AVSTATE_OK); +} + +static void st_op_enabled(struct osmo_fsm_inst *fi, uint32_t event, void *data) +{ +} + +static struct osmo_fsm_state nm_bts_fsm_states[] = { + [NM_BTS_ST_OP_DISABLED_NOTINSTALLED] = { + .in_event_mask = + X(NM_BTS_EV_SW_ACT), + .out_state_mask = + X(NM_BTS_ST_OP_DISABLED_OFFLINE), + .name = "DISABLED_NOTINSTALLED", + .onenter = st_op_disabled_notinstalled_on_enter, + .action = st_op_disabled_notinstalled, + }, + [NM_BTS_ST_OP_DISABLED_OFFLINE] = { + .in_event_mask = + X(NM_BTS_EV_OPSTART_ACK) | + X(NM_BTS_EV_OPSTART_NACK), + .out_state_mask = + X(NM_BTS_ST_OP_ENABLED), + .name = "DISABLED_OFFLINE", + .onenter = st_op_disabled_offline_on_enter, + .action = st_op_disabled_offline, + }, + [NM_BTS_ST_OP_ENABLED] = { + .in_event_mask = 0, + .out_state_mask = 0, + .name = "ENABLED", + .onenter = st_op_enabled_on_enter, + .action = st_op_enabled, + }, +}; + +const struct value_string nm_bts_fsm_event_names[] = { + { NM_BTS_EV_SW_ACT, "SW_ACT" }, + { NM_BTS_EV_OPSTART_ACK, "OPSTART_ACK" }, + { NM_BTS_EV_OPSTART_NACK, "OPSTART_NACK" }, + { 0, NULL } +}; + +struct osmo_fsm nm_bts_fsm = { + .name = "NM_BTS_OP", + .states = nm_bts_fsm_states, + .num_states = ARRAY_SIZE(nm_bts_fsm_states), + .event_names = nm_bts_fsm_event_names, + .log_subsys = DOML, +}; + +static __attribute__((constructor)) void nm_bts_fsm_init(void) +{ + OSMO_ASSERT(osmo_fsm_register(&nm_bts_fsm) == 0); +} |