From 31f525e7560ad13e32cfc5e0b5f1862c0efcb991 Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Mon, 14 May 2018 18:14:15 +0200 Subject: large refactoring: use FSMs for lchans; add inter-BSC HO 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 (OS#3357). osmo_bsc_api.c: - simplify bsc_mr_config() and move to lchan_fsm.c, the only caller; rename to lchan_mr_config(). (bsc_mr_config() used to copy the values to mr_bts_lv twice, once by member assignment and then again with a memcpy.) - During handover, we used to copy the MR config from the old lchan. Since we may handover between FR and HR, rather set the MR Config anew every time, so that FR rates are always available on FR lchans, and never on HR lchans. Depends: I03ee7ce840ecfa0b6a33358e7385528aabd4873f (libosmocore), I1f2918418c38918c5ac70acaa51a47adfca12b5e (libosmocore) Change-Id: I82e3f918295daa83274a4cf803f046979f284366 --- src/osmo-bsc/osmo_bsc_filter.c | 205 ----------------------------------------- 1 file changed, 205 deletions(-) (limited to 'src/osmo-bsc/osmo_bsc_filter.c') diff --git a/src/osmo-bsc/osmo_bsc_filter.c b/src/osmo-bsc/osmo_bsc_filter.c index 773a14699..332ba6b83 100644 --- a/src/osmo-bsc/osmo_bsc_filter.c +++ b/src/osmo-bsc/osmo_bsc_filter.c @@ -30,203 +30,6 @@ #include -static void handle_lu_request(struct gsm_subscriber_connection *conn, - struct msgb *msg) -{ - struct gsm48_hdr *gh; - struct gsm48_loc_upd_req *lu; - struct gsm48_loc_area_id lai; - - if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*lu)) { - LOGP(DMSC, LOGL_ERROR, "LU too small to look at: %u\n", msgb_l3len(msg)); - return; - } - - gh = msgb_l3(msg); - lu = (struct gsm48_loc_upd_req *) gh->data; - - gsm48_generate_lai2(&lai, bts_lai(conn_get_bts(conn))); - - if (memcmp(&lai, &lu->lai, sizeof(lai)) != 0) { - LOGP(DMSC, LOGL_DEBUG, "Marking con for welcome USSD.\n"); - conn->new_subscriber = 1; - } -} - -/* extract a subscriber from the paging response */ -static struct bsc_subscr *extract_sub(struct gsm_subscriber_connection *conn, - struct msgb *msg) -{ - uint8_t mi_type; - char mi_string[GSM48_MI_SIZE]; - struct gsm48_hdr *gh; - struct gsm48_pag_resp *resp; - struct bsc_subscr *subscr; - - if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*resp)) { - LOGP(DMSC, LOGL_ERROR, "PagingResponse too small: %u\n", msgb_l3len(msg)); - return NULL; - } - - gh = msgb_l3(msg); - resp = (struct gsm48_pag_resp *) &gh->data[0]; - - gsm48_paging_extract_mi(resp, msgb_l3len(msg) - sizeof(*gh), - mi_string, &mi_type); - DEBUGP(DRR, "PAGING RESPONSE: MI(%s)=%s\n", - gsm48_mi_type_name(mi_type), mi_string); - - switch (mi_type) { - case GSM_MI_TYPE_TMSI: - subscr = bsc_subscr_find_by_tmsi(conn->network->bsc_subscribers, - tmsi_from_string(mi_string)); - break; - case GSM_MI_TYPE_IMSI: - subscr = bsc_subscr_find_by_imsi(conn->network->bsc_subscribers, - mi_string); - break; - default: - subscr = NULL; - break; - } - - return subscr; -} - -/* we will need to stop the paging request */ -static int handle_page_resp(struct gsm_subscriber_connection *conn, struct msgb *msg) -{ - struct bsc_subscr *subscr = extract_sub(conn, msg); - - if (!subscr) { - LOGP(DMSC, LOGL_ERROR, "Non active subscriber got paged.\n"); - return -1; - } - - paging_request_stop(&conn->network->bts_list, conn_get_bts(conn), subscr, conn, - msg); - bsc_subscr_put(subscr); - return 0; -} - -static int is_cm_service_for_emerg(struct msgb *msg) -{ - struct gsm48_service_request *cm; - struct gsm48_hdr *gh = msgb_l3(msg); - - if (msgb_l3len(msg) < sizeof(*gh) + sizeof(*cm)) { - LOGP(DMSC, LOGL_ERROR, "CM ServiceRequest does not fit.\n"); - return 0; - } - - cm = (struct gsm48_service_request *) &gh->data[0]; - return cm->cm_service_type == GSM48_CMSERV_EMERGENCY; -} - -struct bsc_msc_data *bsc_find_msc(struct gsm_subscriber_connection *conn, - struct msgb *msg) -{ - struct gsm48_hdr *gh; - int8_t pdisc; - uint8_t mtype; - struct osmo_bsc_data *bsc; - struct bsc_msc_data *msc, *pag_msc; - struct bsc_subscr *subscr; - int is_emerg = 0; - - bsc = conn->network->bsc_data; - - if (msgb_l3len(msg) < sizeof(*gh)) { - LOGP(DMSC, LOGL_ERROR, "There is no GSM48 header here.\n"); - return NULL; - } - - gh = msgb_l3(msg); - pdisc = gsm48_hdr_pdisc(gh); - mtype = gsm48_hdr_msg_type(gh); - - /* - * We are asked to select a MSC here but they are not equal. We - * want to respond to a paging request on the MSC where we got the - * request from. This is where we need to decide where this connection - * will go. - */ - if (pdisc == GSM48_PDISC_RR && mtype == GSM48_MT_RR_PAG_RESP) - goto paging; - else if (pdisc == GSM48_PDISC_MM && mtype == GSM48_MT_MM_CM_SERV_REQ) { - is_emerg = is_cm_service_for_emerg(msg); - goto round_robin; - } else - goto round_robin; - -round_robin: - llist_for_each_entry(msc, &bsc->mscs, entry) { - if (!msc->is_authenticated) - continue; - if (!is_emerg && msc->type != MSC_CON_TYPE_NORMAL) - continue; - if (is_emerg && !msc->allow_emerg) - continue; - - /* force round robin by moving it to the end */ - llist_move_tail(&msc->entry, &bsc->mscs); - return msc; - } - - return NULL; - -paging: - subscr = extract_sub(conn, msg); - - if (!subscr) { - LOGP(DMSC, LOGL_ERROR, "Got paged but no subscriber found.\n"); - return NULL; - } - - pag_msc = paging_get_msc(conn_get_bts(conn), subscr); - bsc_subscr_put(subscr); - - llist_for_each_entry(msc, &bsc->mscs, entry) { - if (msc != pag_msc) - continue; - - /* - * We don't check if the MSC is connected. In case it - * is not the connection will be dropped. - */ - - /* force round robin by moving it to the end */ - llist_move_tail(&msc->entry, &bsc->mscs); - return msc; - } - - LOGP(DMSC, LOGL_ERROR, "Got paged but no request found.\n"); - return NULL; -} - - -/** - * This is used to scan a message for extra functionality of the BSC. This - * includes scanning for location updating requests/acceptd and then send - * a welcome USSD message to the subscriber. - */ -int bsc_scan_bts_msg(struct gsm_subscriber_connection *conn, struct msgb *msg) -{ - struct gsm48_hdr *gh = msgb_l3(msg); - uint8_t pdisc = gsm48_hdr_pdisc(gh); - uint8_t mtype = gsm48_hdr_msg_type(gh); - - if (pdisc == GSM48_PDISC_MM) { - if (mtype == GSM48_MT_MM_LOC_UPD_REQUEST) - handle_lu_request(conn, msg); - } else if (pdisc == GSM48_PDISC_RR) { - if (mtype == GSM48_MT_RR_PAG_RESP) - handle_page_resp(conn, msg); - } - - return 0; -} - static int send_welcome_ussd(struct gsm_subscriber_connection *conn) { if (!conn->sccp.msc->ussd_welcome_txt) { @@ -237,14 +40,6 @@ static int send_welcome_ussd(struct gsm_subscriber_connection *conn) return BSS_SEND_USSD; } -int bsc_send_welcome_ussd(struct gsm_subscriber_connection *conn) -{ - bsc_send_ussd_notify(conn, 1, conn->sccp.msc->ussd_welcome_txt); - bsc_send_ussd_release_complete(conn); - - return 0; -} - static int bsc_patch_mm_info(struct gsm_subscriber_connection *conn, uint8_t *data, unsigned int length) { -- cgit v1.2.3