falconia has uploaded this change for review. ( https://gerrit.osmocom.org/c/osmo-msc/+/44044?usp=email ) Change subject: MNCC: add raw Assign & Connect operation ...................................................................... MNCC: add raw Assign & Connect operation Standard OsmoMSC behavior with respect to voice and CSD calls is to make internal interpretation of the bearer capability IE sent by the MS on MO calls, internally generate the same on MT calls, apply built-in codec filter logic for codec and bearer service selection, and make internal decisions as to when to execute Assignment or reassignment procedures and what Channel Type to ask for. External MNCC can exchange SDP with OsmoMSC and thus exercise some control over the CN side of the MSC-controlled MGW, but it still cannot suppress or override any of the other listed decision-making logic in OsmoMSC. The next patch in this series introduces a vty-selected raw mode for MNCC in which most CC messages are simply passed to and from external MNCC in raw form, without any application of intelligent logic (codec filter etc) by OsmoMSC. Furthermore, OsmoMSC in that raw MNCC mode will never execute Assignment on its own - hence an explicit command is required for external MNCC to request Assignment, specify the desired GSM 08.08 Channel Type and configure the CN side of OsmoMSC-controlled MGW. Add this part first. The present WIP state of this patch is experimental and NOT for merging yet. The code compiles and matches the author's mental model for the desired logic, but it is otherwise untested. The external MNCC code with which these OsmoMSC extensions are intended to operate remains to be written, and this code will reach tested status only then. In the meantime, Osmocom maintainers are invited to review this proposed patch for any phisophical issues that would need to be addressed irrespective of the working state. Related: OS#6652 Change-Id: I37f0bf24976cd5df01b34d113474a050eb826bb7 --- M include/osmocom/msc/gsm_04_08.h M include/osmocom/msc/mncc.h M include/osmocom/msc/msc_a.h M include/osmocom/msc/transaction.h M src/libmsc/gsm_04_08_cc.c M src/libmsc/mncc.c M src/libmsc/msc_a.c 7 files changed, 470 insertions(+), 68 deletions(-) git pull ssh://gerrit.osmocom.org:29418/osmo-msc refs/changes/44/44044/1 diff --git a/include/osmocom/msc/gsm_04_08.h b/include/osmocom/msc/gsm_04_08.h index cd5074e..1c17af7 100644 --- a/include/osmocom/msc/gsm_04_08.h +++ b/include/osmocom/msc/gsm_04_08.h @@ -49,6 +49,8 @@ void gsm48_cc_rx_call_conf_cn_local_rtp_port_known(struct gsm_trans *trans); int cc_on_cn_local_rtp_port_known(struct gsm_trans *trans); int cc_on_assignment_done(struct gsm_trans *trans); +int cc_asscon_busy_other_call(struct gsm_trans *trans, bool asscon_in_progress); +int cc_asscon_network_failure(struct gsm_trans *trans); int mncc_tx_to_cc(struct gsm_network *net, void *arg); diff --git a/include/osmocom/msc/mncc.h b/include/osmocom/msc/mncc.h index d258630..b835643 100644 --- a/include/osmocom/msc/mncc.h +++ b/include/osmocom/msc/mncc.h @@ -97,6 +97,9 @@ #define MNCC_RTP_CREATE 0x0204 #define MNCC_RTP_CONNECT 0x0205 #define MNCC_RTP_FREE 0x0206 +#define MNCC_ASSCON_REQ 0x0207 +#define MNCC_ASSCON_CNF 0x0208 +#define MNCC_ASSCON_REJ 0x0209 #define GSM_TCHF_FRAME 0x0300 #define GSM_TCHF_FRAME_EFR 0x0301 @@ -227,6 +230,44 @@ uint32_t callref[2]; }; +enum mncc_asscon_rej_cause { + /* The request is invalid in some way */ + MNCC_ASSCON_REJ_INVALID_REQ, + /* Request is premature: no subscriber connection exists yet */ + MNCC_ASSCON_REJ_PREMATURE, + /* Another AssCon is outstanding on the same CC trans */ + MNCC_ASSCON_REJ_BUSY_SAME_CALL, + /* A different CC trans has an AssCon in progress */ + MNCC_ASSCON_REJ_BUSY_ANOTHER_CALL, + /* User plane is held by another call, no switch permission given */ + MNCC_ASSCON_REJ_NOT_SWITCHING, + /* Internal failure of some kind, such as talloc failure */ + MNCC_ASSCON_REJ_NETWORK_FAIL, +}; + +struct gsm_mncc_asscon { + /* common part for Assign & Connect requests and responses */ + uint32_t msg_type; + uint32_t callref; + uint32_t flags; + /* GSM 08.08 channel type IE (section 3.2.2.11) only for requests */ + uint8_t ct_len; + uint8_t ct_body[11]; + /* Connection mode is also used only for requests; values follow + * enum mgcp_connection_mode of libosmo-mgcp-client. */ + uint8_t conn_mode; + /* error reason for MNCC_ASSCON_REJ */ + enum mncc_asscon_rej_cause rej_cause; + /* Put SDP at the end like it is in gsm_mncc and gsm_mncc_rtp, + * used to preen incoming MNCC messages for basic validity. */ + char sdp[1024]; +}; + +/* MNCC_ASSCON_REQ flag: if set, this operation may switch the user plane + * channel to the MS to the present call, taking it away from another call + * that held it previously. */ +#define MNCC_ASSCON_F_SWITCH 0x0001 + union mncc_msg { uint32_t msg_type; struct gsm_mncc signal; @@ -234,6 +275,7 @@ struct gsm_data_frame data_frame; struct gsm_mncc_rtp rtp; struct gsm_mncc_bridge bridge; + struct gsm_mncc_asscon asscon; }; const char *get_mncc_name(int value); diff --git a/include/osmocom/msc/msc_a.h b/include/osmocom/msc/msc_a.h index d180e38..497e30c 100644 --- a/include/osmocom/msc/msc_a.h +++ b/include/osmocom/msc/msc_a.h @@ -134,6 +134,14 @@ struct call_leg *call_leg; struct mncc_call *mncc_forwarding_to_remote_ran; + /* Channel Type corresponding to the most recently executed + * Assignment procedure to this subscriber. When we process + * AssCon (Assign & Connect) requests from MNCC, we compare + * the newly requested Channel Type against the already + * established one - and if they match, we skip the step of + * reassignment. */ + struct gsm0808_channel_type channel_type; + /* There may be up to 7 incoming calls for this subscriber. This is the currently serviced voice call, * as in, the other person the subscriber is currently talking to. */ struct gsm_trans *active_trans; @@ -221,6 +229,7 @@ int msc_a_ensure_cn_local_rtp(struct msc_a *msc_a, struct gsm_trans *cc_trans); int msc_a_try_call_assignment(struct gsm_trans *cc_trans); +int msc_a_perform_asscon(struct gsm_trans *cc_trans); void msc_a_tx_assignment_cmd(struct msc_a *msc_a); const char *msc_a_cm_service_type_to_use(struct msc_a *msc_a, enum osmo_cm_service_type cm_service_type); diff --git a/include/osmocom/msc/transaction.h b/include/osmocom/msc/transaction.h index f891d2c..2675eff 100644 --- a/include/osmocom/msc/transaction.h +++ b/include/osmocom/msc/transaction.h @@ -57,6 +57,21 @@ uint8_t trans_type_to_gsm48_proto(enum trans_type type); +/* MNCC AssCon operation being attempted or in progress: this struct + * is allocated when MNCC_ASSCON_REQ is received, and is freed upon + * completion or failure of the operation. This temporary state + * structure is always a slave to a particular CC trans. */ +struct asscon_op { + /* information from the request */ + struct gsm0808_channel_type channel_type; + struct sdp_msg remote; + enum mgcp_connection_mode conn_mode; + bool allow_switch; + /* state of operation in progress */ + bool assignment_done; + bool got_cn_rtp_addr; +}; + /* One transaction */ struct gsm_trans { /* Entry in list of all transactions */ @@ -138,6 +153,8 @@ /* Resulting choice from codecs/bearer services and the * local RTP address to be sent to the remote call leg. */ struct sdp_msg local; + /* any MNCC AssCon operation in progress? */ + struct asscon_op *asscon; } cc; struct { struct gsm411_smc_inst smc_inst; diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c index 9ac018e..71400ba 100644 --- a/src/libmsc/gsm_04_08_cc.c +++ b/src/libmsc/gsm_04_08_cc.c @@ -62,6 +62,7 @@ #include <osmocom/gsm/gsm48.h> #include <osmocom/gsm/gsm0480.h> #include <osmocom/gsm/gsm_utils.h> +#include <osmocom/gsm/gsm0808_utils.h> #include <osmocom/gsm/protocol/gsm_04_08.h> #include <osmocom/core/msgb.h> #include <osmocom/core/talloc.h> @@ -266,6 +267,11 @@ sdp = mncc->signal.sdp; break; + case MNCC_ASSCON_REQ: + case MNCC_ASSCON_CNF: + sdp = mncc->asscon.sdp; + break; + default: break; } @@ -323,6 +329,33 @@ return 0; } +#define mncc_recvmsg_asscon(ARGS...) _mncc_recvmsg_asscon(__FILE__, __LINE__, ##ARGS) +static int _mncc_recvmsg_asscon(const char *file, int line, + struct gsm_network *net, + struct gsm_trans *trans, int msg_type, + struct gsm_mncc_asscon *mncc_ac) +{ + struct msgb *msg; + unsigned char *data; + + mncc_ac->msg_type = msg_type; + _log_mncc_rx_tx(file, line, trans, "tx", (union mncc_msg *)mncc_ac); + + msg = msgb_alloc(sizeof(struct gsm_mncc_asscon), "MNCC"); + if (!msg) + return -ENOMEM; + + data = msgb_put(msg, sizeof(struct gsm_mncc_asscon)); + memcpy(data, mncc_ac, sizeof(struct gsm_mncc_asscon)); + + cc_tx_to_mncc(net, msg); + /* trans may be NULL when sending an MNCC error reply upon an invalid MNCC request */ + if (trans) + trans->cc.mncc_initiated = true; + + return 0; +} + int mncc_release_ind(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref, int location, int value) { @@ -2099,6 +2132,182 @@ return mncc_recvmsg(trans->net, trans, MNCC_USERINFO_IND, &user); } +static int send_asscon_rej(struct gsm_network *net, struct gsm_trans *trans, + uint32_t callref, enum mncc_asscon_rej_cause cause) +{ + struct gsm_mncc_asscon mncc_ac; + + memset(&mncc_ac, 0, sizeof(mncc_ac)); + mncc_ac.callref = callref; + mncc_ac.rej_cause = cause; + return mncc_recvmsg_asscon(net, trans, MNCC_ASSCON_REJ, &mncc_ac); +} + +static int handle_asscon_req(struct gsm_network *net, + const struct gsm_mncc_asscon *mncc_ac) +{ + struct gsm_trans *trans; + struct asscon_op *ac_op; + int rc; + + /* Find callref */ + trans = trans_find_by_callref(net, TRANS_CC, mncc_ac->callref); + if (!trans) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "AssCon REQ for non-existing trans\n"); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_INVALID_REQ); + } + log_set_context(LOG_CTX_VLR_SUBSCR, trans->vsub); + log_mncc_rx_tx(trans, "rx", (const union mncc_msg *)mncc_ac); + if (!trans->msc_a) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "AssCon REQ for trans without conn\n"); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_PREMATURE); + } + + /* It is naturally impossible to have more than one AssCon + * in progress at the same time. */ + if (trans->cc.asscon) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "repeated AssCon REQ on the same trans\n"); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_BUSY_SAME_CALL); + } + + /* now we can get to work */ + ac_op = talloc_zero(trans, struct asscon_op); + if (!ac_op) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "talloc failed for struct asscon_op\n"); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_NETWORK_FAIL); + } + rc = gsm0808_dec_channel_type(&ac_op->channel_type, mncc_ac->ct_body, + mncc_ac->ct_len); + if (rc < 0) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "AssCon REQ: invalid Channel Type IE\n"); + talloc_free(ac_op); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_INVALID_REQ); + } + rc = sdp_msg_from_sdp_str(&ac_op->remote, mncc_ac->sdp); + if (rc < 0) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "AssCon REQ: invalid SDP\n"); + talloc_free(ac_op); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_INVALID_REQ); + } + if (!osmo_sockaddr_str_is_nonzero(&ac_op->remote.rtp)) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "AssCon REQ: SDP failed to specify RTP addr\n"); + talloc_free(ac_op); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_INVALID_REQ); + } + if (!ac_op->remote.audio_codecs.count) { + LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, + "AssCon REQ: SDP failed to specify codec(s)\n"); + talloc_free(ac_op); + return send_asscon_rej(net, trans, mncc_ac->callref, + MNCC_ASSCON_REJ_INVALID_REQ); + } + ac_op->conn_mode = mncc_ac->conn_mode; + if (mncc_ac->flags & MNCC_ASSCON_F_SWITCH) + ac_op->allow_switch = true; + + /* at this point we hand the work off to MSC-A */ + trans->cc.asscon = ac_op; + return msc_a_perform_asscon(trans); +} + +int cc_asscon_busy_other_call(struct gsm_trans *trans, bool asscon_in_progress) +{ + enum mncc_asscon_rej_cause cause; + + if (trans->cc.asscon) { + talloc_free(trans->cc.asscon); + trans->cc.asscon = NULL; + } + if (asscon_in_progress) + cause = MNCC_ASSCON_REJ_BUSY_ANOTHER_CALL; + else + cause = MNCC_ASSCON_REJ_NOT_SWITCHING; + return send_asscon_rej(trans->net, trans, trans->callref, cause); +} + +int cc_asscon_network_failure(struct gsm_trans *trans) +{ + if (trans->cc.asscon) { + talloc_free(trans->cc.asscon); + trans->cc.asscon = NULL; + } + return send_asscon_rej(trans->net, trans, trans->callref, + MNCC_ASSCON_REJ_NETWORK_FAIL); +} + +static int check_asscon_complete(struct gsm_trans *trans) +{ + struct msc_a *msc_a = trans->msc_a; + struct asscon_op *ac_op = trans->cc.asscon; + struct gsm_mncc_asscon mncc_ac; + struct sdp_msg sdp; + + if (!ac_op->assignment_done) + return 0; + if (!ac_op->got_cn_rtp_addr) + return 0; + + /* All done - send MNCC_ASSCON_CNF! */ + memset(&mncc_ac, 0, sizeof(mncc_ac)); + mncc_ac.callref = trans->callref; + + /* We have to include SDP in our MNCC_ASSCON_CNF response. Ideally + * we would simply pass through the SDP block we received in MGCP, + * but the existing libosmo-mgcp-client API offers no such support. + * We could implement logic to parse the ptmap array which + * libosmo-mgcp-client constructs from the MGCP response and turn it + * back into SDP ourselves, but it would be completely wasted work + * as the external MNCC sw only cares about RTP IP:port address + * and won't look at any of the codec info. But we still have to + * generate a valid SDP... Our solution: we simply echo back + * the codec info we got with SDP in MNCC_ASSCON_REQ. + */ + memset(&sdp, 0, sizeof(sdp)); + memcpy(&sdp.rtp, &msc_a->cc.call_leg->rtp[RTP_TO_CN]->local, + sizeof(struct osmo_sockaddr_str)); + memcpy(&sdp.audio_codecs, &ac_op->remote.audio_codecs, + sizeof(struct sdp_audio_codecs)); + sdp_msg_to_sdp_str_buf(mncc_ac.sdp, sizeof(mncc_ac.sdp), &sdp); + + /* We can finally dispose of the finished AssCon state structure. */ + talloc_free(ac_op); + trans->cc.asscon = NULL; + + /* ... and send off the response! */ + return mncc_recvmsg_asscon(trans->net, trans, MNCC_ASSCON_CNF, + &mncc_ac); +} + +static int asscon_assignment_done(struct gsm_trans *trans) +{ + struct asscon_op *ac_op = trans->cc.asscon; + + ac_op->assignment_done = true; + return check_asscon_complete(trans); +} + +static int asscon_got_cn_rtp_addr(struct gsm_trans *trans) +{ + struct asscon_op *ac_op = trans->cc.asscon; + + ac_op->got_cn_rtp_addr = true; + return check_asscon_complete(trans); +} + static int mncc_recv_rtp(struct gsm_network *net, struct gsm_trans *trans, uint32_t callref, int cmd, struct osmo_sockaddr_str *rtp_addr, uint32_t payload_type, uint32_t payload_msg_type, const struct sdp_msg *sdp) @@ -2152,6 +2361,9 @@ int cc_on_cn_local_rtp_port_known(struct gsm_trans *cc_trans) { + if (cc_trans->cc.asscon) + return asscon_got_cn_rtp_addr(cc_trans); + /* Depending on MO or MT call, dispatch the event differently */ switch (cc_trans->cc.state) { case GSM_CSTATE_INITIATED: @@ -2178,6 +2390,9 @@ { struct msc_a *msc_a = trans->msc_a; + if (trans->cc.asscon) + return asscon_assignment_done(trans); + switch (trans->cc.state) { case GSM_CSTATE_INITIATED: case GSM_CSTATE_MO_CALL_PROC: @@ -2376,6 +2591,14 @@ case MNCC_RTP_FREE: /* unused right now */ return -EIO; + case MNCC_ASSCON_REQ: + return handle_asscon_req(net, &msg->asscon); + case MNCC_ASSCON_CNF: + case MNCC_ASSCON_REJ: + /* These messages are responses from CC to MNCC, hence + * they should never appear in MNCC->CC request direction. + */ + return -EINVAL; case MNCC_FRAME_DROP: case MNCC_FRAME_RECV: @@ -2581,6 +2804,11 @@ case MNCC_RTP_CONNECT: callref = msg->rtp.callref; break; + case MNCC_ASSCON_REQ: + case MNCC_ASSCON_CNF: + case MNCC_ASSCON_REJ: + callref = msg->asscon.callref; + break; case MNCC_RTP_FREE: case MNCC_FRAME_DROP: diff --git a/src/libmsc/mncc.c b/src/libmsc/mncc.c index 026dae0..180566a 100644 --- a/src/libmsc/mncc.c +++ b/src/libmsc/mncc.c @@ -84,6 +84,9 @@ { MNCC_RTP_CREATE, "MNCC_RTP_CREATE" }, { MNCC_RTP_CONNECT, "MNCC_RTP_CONNECT" }, { MNCC_RTP_FREE, "MNCC_RTP_FREE" }, + { MNCC_ASSCON_REQ, "MNCC_ASSCON_REQ" }, + { MNCC_ASSCON_CNF, "MNCC_ASSCON_CNF" }, + { MNCC_ASSCON_REJ, "MNCC_ASSCON_REJ" }, { GSM_TCHF_FRAME, "GSM_TCHF_FRAME" }, { GSM_TCHF_FRAME_EFR, "GSM_TCHF_FRAME_EFR" }, { GSM_TCHH_FRAME, "GSM_TCHH_FRAME" }, @@ -289,6 +292,11 @@ case MNCC_RTP_CONNECT: case MNCC_RTP_CREATE: return mncc_check_sdp_termination("MNCC RTP", mncc_prim, len, ((struct gsm_mncc_rtp*)mncc_prim)->sdp); + case MNCC_ASSCON_REQ: + case MNCC_ASSCON_CNF: + case MNCC_ASSCON_REJ: + return mncc_check_sdp_termination("MNCC AssCon", mncc_prim, len, + ((struct gsm_mncc_asscon*)mncc_prim)->sdp); case MNCC_LCHAN_MODIFY: case MNCC_FRAME_DROP: case MNCC_FRAME_RECV: diff --git a/src/libmsc/msc_a.c b/src/libmsc/msc_a.c index fca749c..f986a47 100644 --- a/src/libmsc/msc_a.c +++ b/src/libmsc/msc_a.c @@ -676,6 +676,63 @@ static void assignment_request_timeout_cb(void *data); +/* The standard path for generation of Assignment Request, i.e., the path + * that is used in standard Osmocom network configurations, as opposed to + * Osmocom+ThemWi hybrid networks that use MNCC raw mode with AssCon commands. + */ +static int tx_assignment_std_path(struct msc_a *msc_a, + struct gsm_trans *cc_trans, + struct gsm0808_channel_type *channel_type) +{ + trans_cc_filter_run(cc_trans); + LOG_TRANS(cc_trans, LOGL_DEBUG, "Sending Assignment Command\n"); + + switch (cc_trans->bearer_cap.transfer) { + case GSM48_BCAP_ITCAP_SPEECH: + if (!cc_trans->cc.local.audio_codecs.count) { + LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible, no matching codec: %s\n", + codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.local, &cc_trans->cc.remote)); + call_leg_release(msc_a->cc.call_leg); + return -EINVAL; + } + + /* Compose 48.008 Channel Type from the current set of codecs + * determined from both local and remote codec capabilities. */ + if (sdp_audio_codecs_to_gsm0808_channel_type(channel_type, &cc_trans->cc.local.audio_codecs)) { + LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose Channel Type (Permitted Speech) from codecs: %s\n", + codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.local, &cc_trans->cc.remote)); + trans_free(cc_trans); + return -EINVAL; + } + break; + case GSM48_BCAP_ITCAP_3k1_AUDIO: + case GSM48_BCAP_ITCAP_FAX_G3: + case GSM48_BCAP_ITCAP_UNR_DIG_INF: + if (!cc_trans->cc.local.bearer_services.count) { + LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible, no matching bearer service: %s\n", + csd_filter_to_str(&cc_trans->cc.csd, &cc_trans->cc.local, &cc_trans->cc.remote)); + call_leg_release(msc_a->cc.call_leg); + return -EINVAL; + } + + /* Compose 48.008 Channel Type from the current set of bearer + * services determined from local and remote capabilities. */ + if (csd_bs_list_to_gsm0808_channel_type(channel_type, &cc_trans->cc.local.bearer_services)) { + LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose channel type from: %s\n", + csd_filter_to_str(&cc_trans->cc.csd, &cc_trans->cc.local, &cc_trans->cc.remote)); + return -EINVAL; + } + break; + default: + LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible for information transfer capability %d\n", + cc_trans->bearer_cap.transfer); + call_leg_release(msc_a->cc.call_leg); + return -EINVAL; + } + + return 0; +} + /* The MGW has given us a local IP address for the RAN side. Ready to start the Assignment of a voice channel. */ void msc_a_tx_assignment_cmd(struct msc_a *msc_a) { @@ -683,6 +740,7 @@ struct gsm_trans *cc_trans = msc_a->cc.active_trans; struct gsm0808_channel_type channel_type; struct gsm_network *net = msc_a_net(msc_a); + int rc; /* Do not dispatch another Assignment Command before an earlier assignment is completed. This is a sanity * safeguard, ideally callers should not even invoke this function when an Assignment is already ongoing. @@ -703,50 +761,13 @@ return; } - trans_cc_filter_run(cc_trans); - LOG_TRANS(cc_trans, LOGL_DEBUG, "Sending Assignment Command\n"); - - switch (cc_trans->bearer_cap.transfer) { - case GSM48_BCAP_ITCAP_SPEECH: - if (!cc_trans->cc.local.audio_codecs.count) { - LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible, no matching codec: %s\n", - codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.local, &cc_trans->cc.remote)); - call_leg_release(msc_a->cc.call_leg); + if (cc_trans->cc.asscon) { + memcpy(&channel_type, &cc_trans->cc.asscon->channel_type, + sizeof(channel_type)); + } else { + rc = tx_assignment_std_path(msc_a, cc_trans, &channel_type); + if (rc) return; - } - - /* Compose 48.008 Channel Type from the current set of codecs - * determined from both local and remote codec capabilities. */ - if (sdp_audio_codecs_to_gsm0808_channel_type(&channel_type, &cc_trans->cc.local.audio_codecs)) { - LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose Channel Type (Permitted Speech) from codecs: %s\n", - codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.local, &cc_trans->cc.remote)); - trans_free(cc_trans); - return; - } - break; - case GSM48_BCAP_ITCAP_3k1_AUDIO: - case GSM48_BCAP_ITCAP_FAX_G3: - case GSM48_BCAP_ITCAP_UNR_DIG_INF: - if (!cc_trans->cc.local.bearer_services.count) { - LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible, no matching bearer service: %s\n", - csd_filter_to_str(&cc_trans->cc.csd, &cc_trans->cc.local, &cc_trans->cc.remote)); - call_leg_release(msc_a->cc.call_leg); - return; - } - - /* Compose 48.008 Channel Type from the current set of bearer - * services determined from local and remote capabilities. */ - if (csd_bs_list_to_gsm0808_channel_type(&channel_type, &cc_trans->cc.local.bearer_services)) { - LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose channel type from: %s\n", - csd_filter_to_str(&cc_trans->cc.csd, &cc_trans->cc.local, &cc_trans->cc.remote)); - return; - } - break; - default: - LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible for information transfer capability %d\n", - cc_trans->bearer_cap.transfer); - call_leg_release(msc_a->cc.call_leg); - return; } /* The RAN side RTP address is known, so the voice/CSD Assignment can commence. */ @@ -768,6 +789,10 @@ trans_free(cc_trans); return; } + + /* Save the channel type we just requested of the BSS, to assist + * future MNCC AssCon operations. */ + memcpy(&msc_a->cc.channel_type, &channel_type, sizeof(struct gsm0808_channel_type)); } static struct gsm_trans *find_waiting_call(struct msc_a *msc_a) @@ -1574,19 +1599,24 @@ if (codec_if_known) { const struct codec_mapping *codec_assigned; - /* Check for unexpected codec with CSD */ - switch (cc_trans->bearer_cap.transfer) { - case GSM48_BCAP_ITCAP_FAX_G3: - case GSM48_BCAP_ITCAP_3k1_AUDIO: - case GSM48_BCAP_ITCAP_UNR_DIG_INF: - if (codec_if_known->type == GSM0808_SCT_CSD) - break; /* we're good */ - LOG_TRANS(cc_trans, LOGL_ERROR, "Unexpected codec in Assignment Complete for CSD: %s\n", - gsm0808_speech_codec_type_name(codec_if_known->type)); - call_leg_release(msc_a->cc.call_leg); - return; - default: - break; + /* Check for unexpected codec with CSD - but not if we are + * executing as a result of AssCon, as there will be no + * OsmoMSC-interpreted BC-IE with MNCC raw mode. */ + if (!cc_trans->cc.asscon) { + switch (cc_trans->bearer_cap.transfer) { + case GSM48_BCAP_ITCAP_FAX_G3: + case GSM48_BCAP_ITCAP_3k1_AUDIO: + case GSM48_BCAP_ITCAP_UNR_DIG_INF: + if (codec_if_known->type == GSM0808_SCT_CSD) + break; /* we're good */ + LOG_TRANS(cc_trans, LOGL_ERROR, + "Unexpected codec in Assignment Complete for CSD: %s\n", + gsm0808_speech_codec_type_name(codec_if_known->type)); + call_leg_release(msc_a->cc.call_leg); + return; + default: + break; + } } /* For 2G: @@ -1630,14 +1660,17 @@ ac->assignment_complete.osmux_cid); rtp_stream_commit(rtps_to_ran); - /* Remember the Codec List (BSS Supported) */ - if (ac->assignment_complete.codec_list_bss_supported) - codec_filter_set_bss(&cc_trans->cc.codecs, ac->assignment_complete.codec_list_bss_supported); - - trans_cc_filter_run(cc_trans); - LOG_TRANS(cc_trans, LOGL_INFO, "Assignment Complete: RAN: %s, CN: %s\n", - sdp_audio_codecs_to_str(&rtps_to_ran->codecs), - sdp_audio_codecs_to_str(&cc_trans->cc.local.audio_codecs)); + /* Remember the Codec List (BSS Supported) - but once again all of this + * codec filter logic has to be suppressed for MNCC raw mode AssCon + * operations. */ + if (!cc_trans->cc.asscon) { + if (ac->assignment_complete.codec_list_bss_supported) + codec_filter_set_bss(&cc_trans->cc.codecs, ac->assignment_complete.codec_list_bss_supported); + trans_cc_filter_run(cc_trans); + LOG_TRANS(cc_trans, LOGL_INFO, "Assignment Complete: RAN: %s, CN: %s\n", + sdp_audio_codecs_to_str(&rtps_to_ran->codecs), + sdp_audio_codecs_to_str(&cc_trans->cc.local.audio_codecs)); + } if (cc_on_assignment_done(cc_trans)) { /* If an error occurred, it was logged in cc_assignment_done() */ @@ -2198,8 +2231,11 @@ if (!cl) return -EINVAL; - /* See if we can set a preliminary codec. If not, pass none for the time being. */ - trans_cc_filter_run(cc_trans); + /* See if we can set a preliminary codec. If not, pass none for the + * time being. And if we executing as a result of MNCC AssCon, then + * suppress all codecs business. */ + if (!cc_trans->cc.asscon) + trans_cc_filter_run(cc_trans); cn_rtp_available = call_leg_local_ip(cl, RTP_TO_CN); ran_rtp_available = call_leg_local_ip(cl, RTP_TO_RAN); @@ -2207,13 +2243,23 @@ /* Set up RTP ports for both RAN and CN side. Even though we ask for both at the same time, the * osmo_mgcpc_ep_fsm automagically waits for the first CRCX to complete before firing the second CRCX. The one * issued first here will also be the first CRCX sent to the MGW. Usually both still need to be set up. */ - if (!cn_rtp_available) + if (!cn_rtp_available) { + struct sdp_audio_codecs *codecs; + /* If we are executing via AssCon path, then all usual OsmoMSC + * intelligence about codecs needs to be suppressed. */ + if (cc_trans->cc.asscon) + codecs = NULL; + else + codecs = &cc_trans->cc.local.audio_codecs; call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->call_id, cc_trans, - &cc_trans->cc.local.audio_codecs, NULL); + codecs, NULL); + } if (!ran_rtp_available) { struct sdp_audio_codecs *codecs; if (msc_a->c.ran->force_mgw_codecs_to_ran.count) codecs = &msc_a->c.ran->force_mgw_codecs_to_ran; + else if (cc_trans->cc.asscon) + codecs = NULL; else codecs = &cc_trans->cc.local.audio_codecs; return call_leg_ensure_ci(cl, RTP_TO_RAN, cc_trans->call_id, cc_trans, codecs, NULL); @@ -2248,6 +2294,56 @@ return msc_a_start_assignment(msc_a, cc_trans); } +/* Alternative way of doing assignment: instead of osmo-msc deciding on its + * own, using its codec filter logic, when to perform assignment, what channel + * type to ask for and what codecs should be indicated to the MSC-associated + * MGW, the external MNCC software makes all of these decisions and sends us + * an Assign & Connect request when it is ready to roll. */ +int msc_a_perform_asscon(struct gsm_trans *cc_trans) +{ + struct msc_a *msc_a = cc_trans->msc_a; + struct asscon_op *ac_op = cc_trans->cc.asscon; + struct call_leg *cl; + + OSMO_ASSERT(cc_trans->type == TRANS_CC); + + if (msc_a->cc.active_trans && msc_a->cc.active_trans != cc_trans) { + if (msc_a->cc.active_trans->cc.asscon) + return cc_asscon_busy_other_call(cc_trans, true); + if (!ac_op->allow_switch) + return cc_asscon_busy_other_call(cc_trans, false); + /* The other call is not in the middle of assignment, + * and we are allowed to switch - hence we take ownership + * of the user plane channel to the MS. */ + msc_a->cc.active_trans = cc_trans; + } + + /* perform the Connect part of AssCon: CN side of our MGW */ + cl = msc_a_ensure_call_leg(msc_a, cc_trans); + if (!cl) + return cc_asscon_network_failure(cc_trans); + cl->crcx_conn_mode[RTP_TO_CN] = ac_op->conn_mode; + call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->call_id, cc_trans, + &ac_op->remote.audio_codecs, &ac_op->remote.rtp); + if (call_leg_local_ip(cl, RTP_TO_CN)) + ac_op->got_cn_rtp_addr = true; + + /* Assignment part: we may be doing initial assignment or a reassignment + * for changing Channel Type, but if the AssCon is asking for the same + * CT which we've already assigned, then don't reassign, i.e., AssCon + * proceeds without BSS involvement. */ + if (memcmp(&ac_op->channel_type, &msc_a->cc.channel_type, + sizeof(struct gsm0808_channel_type)) == 0) + return cc_on_assignment_done(cc_trans); + + /* We are doing (re)assignment for real. A quirk in the existing + * OsmoMSC code requires active_trans to be NULL as we enter that + * code path. */ + msc_a->cc.active_trans = NULL; + LOG_MSC_A(msc_a, LOGL_DEBUG, "Starting call assignment via AssCon\n"); + return msc_a_start_assignment(msc_a, cc_trans); +} + /* Map CM Service type to use token. * Given a CM Service type, return a matching token intended for osmo_use_count. * For unknown service type, return NULL. -- To view, visit https://gerrit.osmocom.org/c/osmo-msc/+/44044?usp=email To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings?usp=email Gerrit-MessageType: newchange Gerrit-Project: osmo-msc Gerrit-Branch: master Gerrit-Change-Id: I37f0bf24976cd5df01b34d113474a050eb826bb7 Gerrit-Change-Number: 44044 Gerrit-PatchSet: 1 Gerrit-Owner: falconia <falcon@freecalypso.org>