diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c index 269fd5709..f0aca9cc3 100644 --- a/src/libmsc/gsm_04_08_cc.c +++ b/src/libmsc/gsm_04_08_cc.c @@ -695,6 +695,7 @@ static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) struct gsm48_hdr *gh; struct gsm_mncc *setup = arg; int rc, trans_id; + struct gsm_mncc_bearer_cap bearer_cap; gh = (struct gsm48_hdr *) msgb_put(msg, sizeof(*gh)); @@ -759,15 +760,42 @@ static int gsm48_cc_tx_setup(struct gsm_trans *trans, void *arg) codec_filter_run(&trans->cc.codecs); LOG_TRANS(trans, LOGL_DEBUG, "codecs: %s\n", codec_filter_to_str(&trans->cc.codecs)); - /* NEAR FUTURE: upcoming patch will use the codecs filter to determine the Bearer Cap to send to the MS. - * So far just gathering information in the new codecs filter. */ - /* bearer capability */ - if (setup->fields & MNCC_F_BEARER_CAP) { - /* Create a copy of the bearer capability in the transaction struct, so we - * can use this information later */ - memcpy(&trans->bearer_cap, &setup->bearer_cap, sizeof(trans->bearer_cap)); - gsm48_encode_bearer_cap(msg, 0, &setup->bearer_cap); + /* Compose Bearer Capability information that reflects only the codecs (Speech Versions) remaining after + * intersecting MS, BSS and remote call leg restrictions. To store in trans for later use, and to include in + * the outgoing CC Setup message. */ + bearer_cap = (struct gsm_mncc_bearer_cap){ + .speech_ver = { -1 }, + }; + sdp_audio_codecs_to_bearer_cap(&bearer_cap, &trans->cc.codecs.result.audio_codecs); + rc = bearer_cap_set_radio(&bearer_cap); + if (rc) { + LOG_TRANS(trans, LOGL_ERROR, "Error composing Bearer Capability for CC Setup\n"); + trans_free(trans); + msgb_free(msg); + return rc; } + /* Create a copy of the bearer capability in the transaction struct, so we can use this information later */ + /* TODO: we should be able to drop trans->bearer_cap, replaced by the codecs filter. Verify this. + * So far let's just store it there like previous code did. */ + trans->bearer_cap = bearer_cap; + /* If no resulting codecs remain, error out. We cannot find a codec that matches both call legs. If the MGW were + * able to transcode, we could use non-identical codecs on each conn of the MGW endpoint, but we are aiming for + * finding a matching codec. */ + if (bearer_cap.speech_ver[0] == -1) { + LOG_TRANS(trans, LOGL_ERROR, "%s: no codec match possible: %s\n", + get_mncc_name(setup->msg_type), codec_filter_to_str(&trans->cc.codecs)); + + /* incompatible codecs */ + rc = mncc_release_ind(trans->net, trans, trans->callref, + GSM48_CAUSE_LOC_PRN_S_LU, + GSM48_CC_CAUSE_INCOMPAT_DEST /* TODO: correct cause code? */); + trans->callref = 0; + trans_free(trans); + msgb_free(msg); + return rc; + } + gsm48_encode_bearer_cap(msg, 0, &bearer_cap); + /* facility */ if (setup->fields & MNCC_F_FACILITY) gsm48_encode_facility(msg, 0, &setup->facility); diff --git a/tests/msc_vlr/msc_vlr_test_call.c b/tests/msc_vlr/msc_vlr_test_call.c index 06602f7bc..6c7a8ad4e 100644 --- a/tests/msc_vlr/msc_vlr_test_call.c +++ b/tests/msc_vlr/msc_vlr_test_call.c @@ -316,7 +316,7 @@ static void test_call_mt() VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup"); - dtap_expect_tx("0305" /* CC: Setup */); + dtap_expect_tx("0305" /* CC: Setup */ "04 07 60 04 05 0b 06 08 87" /* Bearer Cap */); ms_sends_security_mode_complete(1); btw("MS confirms call, we create a RAN-side RTP and forward MNCC_CALL_CONF_IND"); @@ -419,7 +419,7 @@ static void test_call_mt2() VERBOSE_ASSERT(security_mode_ctrl_sent, == true, "%d"); btw("MS sends SecurityModeControl acceptance, VLR accepts, sends CC Setup"); - dtap_expect_tx("0305" /* CC: Setup */); + dtap_expect_tx("0305" /* CC: Setup */ "04 07 60 04 05 0b 06 08 87" /* Bearer Cap */); ms_sends_security_mode_complete(1); btw("MS confirms call, we create a RAN-side RTP and forward MNCC_CALL_CONF_IND"); diff --git a/tests/msc_vlr/msc_vlr_test_call.err b/tests/msc_vlr/msc_vlr_test_call.err index d97806d5d..e1d2f4df6 100644 --- a/tests/msc_vlr/msc_vlr_test_call.err +++ b/tests/msc_vlr/msc_vlr_test_call.err @@ -761,7 +761,7 @@ DCC trans(CC:NULL IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAG DCC trans(CC:NULL IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP callref-0x423 tid-0) new state NULL -> CALL_PRESENT DIUCS msc_a(IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP){MSC_A_ST_COMMUNICATING}: Sending DTAP: CC GSM48_MT_CC_SETUP DMSC msc_a(IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP){MSC_A_ST_COMMUNICATING}: RAN encode: DTAP on UTRAN-Iu -- DTAP --UTRAN-Iu--> MS: GSM48_MT_CC_SETUP: 0305 +- DTAP --UTRAN-Iu--> MS: GSM48_MT_CC_SETUP: 030504076004050b060887 - DTAP matches expected message DMSC dummy_msc_i(IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP){0}: Received Event MSC_I_EV_FROM_A_FORWARD_ACCESS_SIGNALLING_REQUEST DREF VLR subscr IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100 - Paging: now used by 3 (attached,CC,active-conn) @@ -1230,7 +1230,7 @@ DCC trans(CC:NULL IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAG DCC trans(CC:NULL IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP callref-0x423 tid-0) new state NULL -> CALL_PRESENT DIUCS msc_a(IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP){MSC_A_ST_COMMUNICATING}: Sending DTAP: CC GSM48_MT_CC_SETUP DMSC msc_a(IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP){MSC_A_ST_COMMUNICATING}: RAN encode: DTAP on UTRAN-Iu -- DTAP --UTRAN-Iu--> MS: GSM48_MT_CC_SETUP: 0305 +- DTAP --UTRAN-Iu--> MS: GSM48_MT_CC_SETUP: 030504076004050b060887 - DTAP matches expected message DMSC dummy_msc_i(IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100:UTRAN-Iu:PAGING_RESP){0}: Received Event MSC_I_EV_FROM_A_FORWARD_ACCESS_SIGNALLING_REQUEST DREF VLR subscr IMSI-901700000010650:MSISDN-42342:TMSI-0x03020100 - Paging: now used by 3 (attached,CC,active-conn)