2017-04-09 10:32:51 +00:00
|
|
|
/* (C) 2017 by sysmocom s.f.m.c. GmbH
|
|
|
|
* All Rights Reserved
|
|
|
|
*
|
|
|
|
* Author: Philipp Maier
|
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
2020-08-25 16:10:42 +00:00
|
|
|
#include <osmocom/core/signal.h>
|
2020-10-04 19:32:52 +00:00
|
|
|
#include <osmocom/bsc/signal.h>
|
|
|
|
|
2017-09-04 13:15:32 +00:00
|
|
|
#include <osmocom/bsc/debug.h>
|
|
|
|
#include <osmocom/bsc/bsc_msc_data.h>
|
|
|
|
#include <osmocom/bsc/osmo_bsc_sigtran.h>
|
2020-10-04 19:32:52 +00:00
|
|
|
#include <osmocom/bsc/bssmap_reset.h>
|
2021-08-19 17:04:14 +00:00
|
|
|
#include <osmocom/bsc/bsc_stats.h>
|
2017-04-09 10:32:51 +00:00
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
static void a_reset_tx_reset(void *data)
|
2020-05-07 13:41:26 +00:00
|
|
|
{
|
2020-10-04 19:32:52 +00:00
|
|
|
struct bsc_msc_data *msc = data;
|
|
|
|
osmo_bsc_sigtran_tx_reset(msc);
|
2020-05-07 13:41:26 +00:00
|
|
|
}
|
|
|
|
|
2020-10-09 15:18:29 +00:00
|
|
|
static void a_reset_tx_reset_ack(void *data)
|
|
|
|
{
|
|
|
|
struct bsc_msc_data *msc = data;
|
|
|
|
osmo_bsc_sigtran_tx_reset_ack(msc);
|
|
|
|
}
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
static void a_reset_link_up(void *data)
|
2017-04-09 10:32:51 +00:00
|
|
|
{
|
2020-10-04 19:32:52 +00:00
|
|
|
struct bsc_msc_data *msc = data;
|
2023-07-11 10:47:29 +00:00
|
|
|
LOGP(DMSC, LOGL_NOTICE, "(msc%d) BSSMAP association is up\n", msc->nr);
|
2021-06-04 15:30:21 +00:00
|
|
|
osmo_stat_item_inc(osmo_stat_item_group_get_item(msc->msc_statg, MSC_STAT_MSC_LINKS_ACTIVE), 1);
|
2021-08-19 17:04:14 +00:00
|
|
|
osmo_stat_item_inc(osmo_stat_item_group_get_item(msc->network->bsc_statg, BSC_STAT_NUM_MSC_CONNECTED), 1);
|
2020-10-04 19:32:52 +00:00
|
|
|
osmo_signal_dispatch(SS_MSC, S_MSC_CONNECTED, msc);
|
2017-04-09 10:32:51 +00:00
|
|
|
}
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
static void a_reset_link_lost(void *data)
|
2020-05-07 13:41:26 +00:00
|
|
|
{
|
2020-10-04 19:32:52 +00:00
|
|
|
struct bsc_msc_data *msc = data;
|
2023-07-11 10:47:29 +00:00
|
|
|
LOGP(DMSC, LOGL_NOTICE, "(msc%d) BSSMAP association is down\n", msc->nr);
|
2021-06-04 15:30:21 +00:00
|
|
|
osmo_stat_item_dec(osmo_stat_item_group_get_item(msc->msc_statg, MSC_STAT_MSC_LINKS_ACTIVE), 1);
|
2021-08-19 17:04:14 +00:00
|
|
|
osmo_stat_item_dec(osmo_stat_item_group_get_item(msc->network->bsc_statg, BSC_STAT_NUM_MSC_CONNECTED), 1);
|
2020-10-04 19:32:52 +00:00
|
|
|
osmo_signal_dispatch(SS_MSC, S_MSC_LOST, msc);
|
|
|
|
osmo_bsc_sigtran_reset(msc);
|
2020-05-07 13:41:26 +00:00
|
|
|
}
|
|
|
|
|
2017-04-09 10:32:51 +00:00
|
|
|
/* Create and start state machine which handles the reset/reset-ack procedure */
|
2020-10-04 19:32:52 +00:00
|
|
|
void a_reset_alloc(struct bsc_msc_data *msc, const char *name)
|
2017-04-09 10:32:51 +00:00
|
|
|
{
|
2020-10-04 19:32:52 +00:00
|
|
|
struct bssmap_reset_cfg cfg = {
|
|
|
|
.conn_cfm_failure_threshold = 3,
|
|
|
|
.ops = {
|
|
|
|
.tx_reset = a_reset_tx_reset,
|
2020-10-09 15:18:29 +00:00
|
|
|
.tx_reset_ack = a_reset_tx_reset_ack,
|
2020-10-04 19:32:52 +00:00
|
|
|
.link_up = a_reset_link_up,
|
|
|
|
.link_lost = a_reset_link_lost,
|
|
|
|
},
|
|
|
|
.data = msc,
|
|
|
|
};
|
2018-08-07 09:31:51 +00:00
|
|
|
|
|
|
|
/* There must not be any double allocation! */
|
2020-10-04 19:32:52 +00:00
|
|
|
if (msc->a.bssmap_reset) {
|
|
|
|
LOGP(DMSC, LOGL_ERROR, "(msc%d) will not allocate a second reset FSM for this MSC\n", msc->nr);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
msc->a.bssmap_reset = bssmap_reset_alloc(msc, name, &cfg);
|
2021-08-19 17:04:14 +00:00
|
|
|
osmo_stat_item_inc(osmo_stat_item_group_get_item(msc->network->bsc_statg, BSC_STAT_NUM_MSC_TOTAL), 1);
|
2017-04-09 10:32:51 +00:00
|
|
|
}
|
|
|
|
|
2019-11-13 21:10:41 +00:00
|
|
|
/* Confirm that we successfully received a reset acknowledge message */
|
2018-08-07 09:31:51 +00:00
|
|
|
void a_reset_ack_confirm(struct bsc_msc_data *msc)
|
2017-04-09 10:32:51 +00:00
|
|
|
{
|
2018-08-07 09:31:51 +00:00
|
|
|
if (!msc)
|
|
|
|
return;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
if (!msc->a.bssmap_reset)
|
2018-08-07 09:31:51 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
osmo_fsm_inst_dispatch(msc->a.bssmap_reset->fi, BSSMAP_RESET_EV_RX_RESET_ACK, NULL);
|
2017-04-09 10:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Report a failed connection */
|
2018-08-07 09:31:51 +00:00
|
|
|
void a_reset_conn_fail(struct bsc_msc_data *msc)
|
2017-04-09 10:32:51 +00:00
|
|
|
{
|
2018-08-07 09:31:51 +00:00
|
|
|
if (!msc)
|
|
|
|
return;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
if (!msc->a.bssmap_reset)
|
2017-04-09 10:32:51 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
osmo_fsm_inst_dispatch(msc->a.bssmap_reset->fi, BSSMAP_RESET_EV_CONN_CFM_FAILURE, NULL);
|
2017-04-09 10:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Report a successful connection */
|
2018-08-07 09:31:51 +00:00
|
|
|
void a_reset_conn_success(struct bsc_msc_data *msc)
|
2017-04-09 10:32:51 +00:00
|
|
|
{
|
2018-08-07 09:31:51 +00:00
|
|
|
if (!msc)
|
2017-04-09 10:32:51 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
if (!msc->a.bssmap_reset)
|
2018-08-07 09:31:51 +00:00
|
|
|
return;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
osmo_fsm_inst_dispatch(msc->a.bssmap_reset->fi, BSSMAP_RESET_EV_CONN_CFM_SUCCESS, NULL);
|
2017-04-09 10:32:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Check if we have a connection to a specified msc */
|
2018-08-07 09:31:51 +00:00
|
|
|
bool a_reset_conn_ready(struct bsc_msc_data *msc)
|
2017-04-09 10:32:51 +00:00
|
|
|
{
|
2018-08-07 09:31:51 +00:00
|
|
|
if (!msc)
|
|
|
|
return false;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
if (!msc->a.bssmap_reset)
|
2017-04-09 10:32:51 +00:00
|
|
|
return false;
|
|
|
|
|
2020-10-04 19:32:52 +00:00
|
|
|
return bssmap_reset_is_conn_ready(msc->a.bssmap_reset);
|
2019-12-01 14:43:40 +00:00
|
|
|
}
|