aboutsummaryrefslogtreecommitdiffstats
path: root/src/osmo-bsc/bsc_api.c
diff options
context:
space:
mode:
authorNeels Hofmeyr <neels@hofmeyr.de>2018-05-14 18:14:15 +0200
committerNeels Hofmeyr <neels@hofmeyr.de>2018-06-27 04:02:50 +0200
commit9ed5939a475f64209c4bc72109b084e85e7190d1 (patch)
tree80d1fe40e70a196493ea273ff84a14e65b4415c7 /src/osmo-bsc/bsc_api.c
parent7a93d0712abfa25e369c4272a65402d455dab78d (diff)
large refactoring: use FSMs for lchans; add inter-BSC HOpespin/tester
Add FSMs: - timeslot_fsm: handle dynamic timeslots and OML+RSL availability. - lchan_fsm: handle an individual lchan activation, RTP stream and release, signal the appropriate calling FSMs on success, failure, release. - mgw_endpoint_fsm: handle one entire endpoint with several CI. - assignment_fsm: BSSMAP Assignment Request. - handover_fsm: all of intra, inter-MO and inter-MT handover. Above FSMs absorb large parts of the gscon FSM. The gscon FSM was surpassing the maximum amount events (32), and it is more logical to treat assignment, handover and MGW procedures in separate FSMs. - Add logging macros for each FSM type: - LOG_TS() - LOG_LCHAN() - LOG_MGWEP(), LOG_CI() - LOG_ASSIGNMENT() - LOG_HO() These log with the osmo_fsm_inst where present. New style decision: logging without a final newline char is awkward, especially for gsmtap logging and when other logs interleave LOGPC() calls; we have various cases where the final \n goes missing, and also this invokes the log category checking N times instead of once. So I decided to make these macros *always* append a newline, but only if there is no final newline yet. I hope that the compiler optimizes the strlen() of the constant format strings away. Thus I can log with or without typing "\n" and always get an \n termination anyway. General: - replace osmo_timers, state enums and program-wide osmo_signal_dispatch() with dedicated FSM timeouts, states and events. - introduce a common way to handle Tnnn timers: gsm_timers.h/.c: struct T_def. These can be used (with some macro magic) to define a state's timeout once, and not make mistakes for each osmo_fsm_inst_state_chg(). Details: bsc_subscr_conn_fsm.c: - move most states of this FSM to lchan_fsm, assignment_fsm, handover_fsm and mgw_endpoint_fsm. - There is exactly one state for an ongoing Assignment, with all details handled in conn->assignment.fi. The state relies on the assignment_fsm's timeout. - There is one state for an ongoing Handover; except for an incoming Handover from a remote BSS, the gscon remains in ST_INIT until the new lchan and conn are both established. - move bssmap_add_lcls_status() to osmo_bsc_lcls.c abis_rsl.c: - move all dynamic timeslot logic away into timeslot_fsm. Only keep plain send/receive functions in abis_rsl.c - reduce some rsl functions to merely send a message, rename to "_tx_". - rsl_ipacc_mdcx(): add '_tx_' in the name; move parts that change the lchan state out into the lchan_fsm, the lchan->abis_ip.* are now set there prior to invoking this function. - move all timers and error/release handling away into various FSMs. - tweak ipa_smod_s_for_lchan() and ipa_rtp_pt_for_lchan() to not require an lchan passed, but just mode,type that they require. Rename to ipacc_speech_mode*() and ipacc_payload_type(). - add rsl_forward_layer3_info, used for inter-BSC HO MO, to just send the RR message received during BSSMAP Handover Command. - move various logging to LOG_LCHAN() in order to log with the lchan FSM instance. One drawback is that the lchan FSM is limited to one logging category, i.e. this moves some logging from DRR to DRSL. It might actually make sense to combine those categories. - lose LOGP...LOGPC logging cascades: they are bad for gsmtap logging and for performance. - handle_classmark_chg(): change logging, move cm2 len check out of the cm3 condition (I hope that's correct). - gsm48_send_ho_cmd(): split off gsm48_make_ho_cmd() which doesn't send right away, so that during inter-bsc HO we can make an RR Handover Command to send via the MSC to the remote BSS. assignment_fsm.c: - the Chan Mode Modify in case of re-using the same lchan is not implemented yet, because this was also missing in the previous implementation. Depends: I03ee7ce840ecfa0b6a33358e7385528aabd4873f Change-Id: I82e3f918295daa83274a4cf803f046979f284366
Diffstat (limited to 'src/osmo-bsc/bsc_api.c')
-rw-r--r--src/osmo-bsc/bsc_api.c249
1 files changed, 1 insertions, 248 deletions
diff --git a/src/osmo-bsc/bsc_api.c b/src/osmo-bsc/bsc_api.c
index eed475b34..a6ecbc9a4 100644
--- a/src/osmo-bsc/bsc_api.c
+++ b/src/osmo-bsc/bsc_api.c
@@ -22,7 +22,6 @@
*/
#include <osmocom/bsc/bsc_api.h>
-#include <osmocom/bsc/bsc_rll.h>
#include <osmocom/bsc/gsm_data.h>
#include <osmocom/bsc/signal.h>
#include <osmocom/bsc/abis_rsl.h>
@@ -34,161 +33,13 @@
#include <osmocom/bsc/penalty_timers.h>
#include <osmocom/bsc/osmo_bsc_sigtran.h>
#include <osmocom/bsc/bsc_subscr_conn_fsm.h>
+#include <osmocom/bsc/lchan_fsm.h>
#include <osmocom/gsm/protocol/gsm_08_08.h>
#include <osmocom/gsm/gsm48.h>
#include <osmocom/core/talloc.h>
-#define GSM0808_T10_VALUE 6, 0
-
-static void handle_release(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
-static void handle_chan_ack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
-static void handle_chan_nack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
-
-/*
- * Start a new assignment and make sure that it is completed within T10 either
- * positively, negatively or by the timeout.
- *
- * 1.) allocate a new lchan
- * 2.) copy the encryption key and other data from the
- * old to the new channel.
- * 3.) RSL Channel Activate this channel and wait
- *
- * -> Signal handler for the LCHAN
- * 4.) Send GSM 04.08 assignment command to the MS
- *
- * -> Assignment Complete/Assignment Failure
- * 5.) Release the SDCCH, continue signalling on the new link
- */
-static int handle_new_assignment(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate)
-{
- struct gsm_lchan *new_lchan;
- enum gsm_chan_t chan_type;
-
- chan_type = full_rate ? GSM_LCHAN_TCH_F : GSM_LCHAN_TCH_H;
-
- new_lchan = lchan_alloc(conn_get_bts(conn), chan_type, 0);
-
- if (!new_lchan) {
- LOGP(DMSC, LOGL_NOTICE, "%s No free channel for %s\n",
- bsc_subscr_name(conn->bsub), gsm_lchant_name(chan_type));
- return -1;
- }
-
- /* check if we are on TCH/F and requested TCH/H, but got TCH/F */
- if (conn->lchan->type == new_lchan->type
- && chan_type != new_lchan->type) {
- LOGPLCHAN(conn->lchan, DHO, LOGL_NOTICE,
- "-> %s Will not re-assign to identical channel type, %s was requested\n",
- gsm_lchan_name(new_lchan), gsm_lchant_name(chan_type));
- lchan_free(new_lchan);
- return -1;
- }
-
- /* copy old data to the new channel */
- memcpy(&new_lchan->encr, &conn->lchan->encr, sizeof(new_lchan->encr));
- new_lchan->ms_power = conn->lchan->ms_power;
- new_lchan->bs_power = conn->lchan->bs_power;
- new_lchan->rqd_ta = conn->lchan->rqd_ta;
-
- /* copy new data to it */
- new_lchan->tch_mode = chan_mode;
- new_lchan->rsl_cmode = (chan_mode == GSM48_CMODE_SIGN) ?
- RSL_CMOD_SPD_SIGN : RSL_CMOD_SPD_SPEECH;
-
- /* handle AMR correctly */
- if (chan_mode == GSM48_CMODE_SPEECH_AMR)
- bsc_mr_config(conn, new_lchan, full_rate);
-
- if (rsl_chan_activate_lchan(new_lchan, RSL_ACT_INTRA_NORM_ASS, 0) < 0) {
- LOGPLCHAN(new_lchan, DHO, LOGL_ERROR, "could not activate channel\n");
- lchan_free(new_lchan);
- return -1;
- }
-
- /* remember that we have the channel */
- conn->secondary_lchan = new_lchan;
- new_lchan->conn = conn;
- return 0;
-}
-
-/*
- * \brief Check if the given channel is compatible with the mode/fullrate
- */
-static int chan_compat_with_mode(struct gsm_lchan *lchan, int chan_mode, int full_rate)
-{
- switch (chan_mode) {
- case GSM48_CMODE_SIGN:
- switch (lchan->type) {
- case GSM_LCHAN_TCH_F:
- case GSM_LCHAN_TCH_H:
- case GSM_LCHAN_SDCCH:
- return 1;
- default:
- return 0;
- }
- case GSM48_CMODE_SPEECH_V1:
- case GSM48_CMODE_SPEECH_AMR:
- case GSM48_CMODE_DATA_3k6:
- case GSM48_CMODE_DATA_6k0:
- /* these services can all run on TCH/H, but we may have
- * an explicit override by the 'full_rate' argument */
- switch (lchan->type) {
- case GSM_LCHAN_TCH_F:
- return full_rate ? 1 : 0;
- case GSM_LCHAN_TCH_H:
- return full_rate ? 0 : 1;
- default:
- return 0;
- }
- case GSM48_CMODE_DATA_12k0:
- case GSM48_CMODE_DATA_14k5:
- case GSM48_CMODE_SPEECH_EFR:
- /* these services all explicitly require a TCH/F */
- return (lchan->type == GSM_LCHAN_TCH_F) ? 1 : 0;
- default:
- return 0;
- }
-}
-
-/*! Send a GSM08.08 Assignment Request. Right now this does not contain the
- * audio codec type or the allowed rates for the config. In case the current
- * channel does not allow the selected mode a new one will be allocated.
- * \param[out] conn related subscriber connection
- * \param[in] chan_mode mode of the channel (see enum gsm48_chan_mode)
- * \param[in] full_rate select full rate or half rate channel
- * \returns 0 on success, 1 when no operation is neccessary, -1 on failure */
-int gsm0808_assign_req(struct gsm_subscriber_connection *conn, int chan_mode, int full_rate)
-{
- /* TODO: Add multirate configuration, make it work for more than audio. */
-
- if (!chan_compat_with_mode(conn->lchan, chan_mode, full_rate)) {
- if (handle_new_assignment(conn, chan_mode, full_rate) != 0)
- goto error;
- } else {
- /* Check if the channel is already in the requested mode, if
- * yes, we skip unnecessary channel mode modify operations. */
- if (conn->lchan->tch_mode == chan_mode)
- return 1;
-
- if (chan_mode == GSM48_CMODE_SPEECH_AMR)
- bsc_mr_config(conn, conn->lchan, full_rate);
-
- LOGPLCHAN(conn->lchan, DMSC, LOGL_NOTICE,
- "Sending ChanModify for speech: %s\n",
- get_value_string(gsm48_chan_mode_names, chan_mode));
- gsm48_lchan_modify(conn->lchan, chan_mode);
- }
-
- /* we expect the caller will manage T10 */
- return 0;
-
-error:
- bsc_assign_fail(conn, 0, NULL);
- return -1;
-}
-
int gsm0808_page(struct gsm_bts *bts, unsigned int page_group, unsigned int mi_len,
uint8_t *mi, int chan_type)
{
@@ -222,101 +73,3 @@ int gsm0808_cipher_mode(struct gsm_subscriber_connection *conn, int cipher,
return gsm48_send_rr_ciph_mode(conn->lchan, include_imeisv);
}
-
-/*
- * Release all occupied RF Channels but stay around for more.
- */
-int gsm0808_clear(struct gsm_subscriber_connection *conn)
-{
- if (conn->ho)
- bsc_clear_handover(conn, 1);
-
- if (conn->secondary_lchan)
- lchan_release(conn->secondary_lchan, 0, RSL_REL_LOCAL_END);
-
- if (conn->lchan)
- lchan_release(conn->lchan, 1, RSL_REL_NORMAL);
-
- conn->lchan = NULL;
- conn->secondary_lchan = NULL;
-
- return 0;
-}
-
-static int bsc_handle_lchan_signal(unsigned int subsys, unsigned int signal,
- void *handler_data, void *signal_data)
-{
- struct gsm_lchan *lchan;
- struct lchan_signal_data *lchan_data;
-
- if (subsys != SS_LCHAN)
- return 0;
-
-
- lchan_data = signal_data;
- if (!lchan_data->lchan || !lchan_data->lchan->conn)
- return 0;
-
- lchan = lchan_data->lchan;
-
- switch (signal) {
- case S_LCHAN_UNEXPECTED_RELEASE:
- LOGPLCHAN(lchan, DMSC, LOGL_NOTICE, "S_LCHAN_UNEXPECTED_RELEASE\n");
- handle_release(lchan->conn, lchan);
- break;
- case S_LCHAN_ACTIVATE_ACK:
- handle_chan_ack(lchan->conn, lchan);
- break;
- case S_LCHAN_ACTIVATE_NACK:
- handle_chan_nack(lchan->conn, lchan);
- break;
- }
-
- return 0;
-}
-
-static void handle_release(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan)
-{
- if (conn->secondary_lchan == lchan) {
- LOGPLCHAN(lchan, DMSC, LOGL_NOTICE,
- "lchan release on new lchan, Assignment failed\n");
- conn->secondary_lchan = NULL;
-
- bsc_assign_fail(conn, GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, NULL);
- }
-
- /* clear the connection now */
- bsc_clear_request(conn, 0);
-
- /* now give up all channels */
- if (conn->lchan == lchan)
- conn->lchan = NULL;
- if (conn->ho && conn->ho->new_lchan == lchan)
- bsc_clear_handover(conn, 0);
- lchan->conn = NULL;
-}
-
-static void handle_chan_ack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan)
-{
- if (conn->secondary_lchan != lchan)
- return;
-
- LOGPLCHAN(lchan, DMSC, LOGL_NOTICE, "Sending RR Assignment\n");
- gsm48_send_rr_ass_cmd(conn->lchan, lchan, lchan->ms_power);
-}
-
-static void handle_chan_nack(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan)
-{
- if (conn->secondary_lchan != lchan)
- return;
-
- LOGPLCHAN(lchan, DMSC, LOGL_ERROR, "Channel activation failed.\n");
- conn->secondary_lchan->conn = NULL;
- conn->secondary_lchan = NULL;
- bsc_assign_fail(conn, GSM0808_CAUSE_RADIO_INTERFACE_FAILURE, NULL);
-}
-
-static __attribute__((constructor)) void on_dso_load_bsc(void)
-{
- osmo_signal_register_handler(SS_LCHAN, bsc_handle_lchan_signal, NULL);
-}