mgcp: use codec information returned with ASSIGNMENT COMPL.

When the assignment completes a choosen codec is returned. At the
moment we do not use this information.

- add struct members for codec info (both, RAN and CN)
- parse codec info in BSSMAP ASSIGNMENT COMPLETE
- use codec info on mgcp

Since the MNCC API is not complete yet, we currently only use the
codec info only on the internal MNCC yet.

Change-Id: I9d5b1cd016d9a058b22a367d0e5e9f2ef447931a
Related: OS#2728
This commit is contained in:
Philipp Maier 2018-08-07 13:00:14 +02:00 committed by Harald Welte
parent 6cc377d359
commit 8ad3dacebb
4 changed files with 76 additions and 14 deletions

View File

@ -143,10 +143,13 @@ struct gsm_subscriber_connection {
char local_addr_ran[INET_ADDRSTRLEN];
uint16_t remote_port_ran;
char remote_addr_ran[INET_ADDRSTRLEN];
enum mgcp_codecs codec_ran;
uint16_t local_port_cn;
char local_addr_cn[INET_ADDRSTRLEN];
uint16_t remote_port_cn;
char remote_addr_cn[INET_ADDRSTRLEN];
enum mgcp_codecs codec_cn;
} rtp;
/* which Iu-CS connection, if any. */

View File

@ -502,11 +502,50 @@ static int bssmap_rx_sapi_n_rej(struct gsm_subscriber_connection *conn, struct m
return 0;
}
/* Use the speech codec info we go with the assignment complete to dtermine
* which codec we will signal to the MGW */
static enum mgcp_codecs mgcp_codec_from_sc(struct gsm0808_speech_codec *sc)
{
switch (sc->type) {
case GSM0808_SCT_FR1:
return CODEC_GSM_8000_1;
break;
case GSM0808_SCT_FR2:
return CODEC_GSMEFR_8000_1;
break;
case GSM0808_SCT_FR3:
return CODEC_AMR_8000_1;
break;
case GSM0808_SCT_FR4:
return CODEC_AMRWB_16000_1;
break;
case GSM0808_SCT_FR5:
return CODEC_AMRWB_16000_1;
break;
case GSM0808_SCT_HR1:
return CODEC_GSMHR_8000_1;
break;
case GSM0808_SCT_HR3:
return CODEC_AMR_8000_1;
break;
case GSM0808_SCT_HR4:
return CODEC_AMRWB_16000_1;
break;
case GSM0808_SCT_HR6:
return CODEC_AMRWB_16000_1;
break;
default:
return CODEC_PCMU_8000_1;
break;
}
}
/* Endpoint to handle assignment complete */
static int bssmap_rx_ass_compl(struct gsm_subscriber_connection *conn, struct msgb *msg,
struct tlv_parsed *tp)
{
struct sockaddr_storage rtp_addr;
struct gsm0808_speech_codec sc;
struct sockaddr_in *rtp_addr_in;
int rc;
@ -525,6 +564,15 @@ static int bssmap_rx_ass_compl(struct gsm_subscriber_connection *conn, struct ms
return -EINVAL;
}
/* Decode speech codec (choosen) element */
rc = gsm0808_dec_speech_codec(&sc, TLVP_VAL(tp, GSM0808_IE_SPEECH_CODEC),
TLVP_LEN(tp, GSM0808_IE_SPEECH_CODEC));
if (rc < 0) {
LOGPCONN(conn, LOGL_ERROR, "Unable to decode speech codec (choosen).\n");
return -EINVAL;
}
conn->rtp.codec_ran = mgcp_codec_from_sc(&sc);
/* use address / port supplied with the AoIP
* transport address element */
if (rtp_addr.ss_family == AF_INET) {

View File

@ -319,6 +319,15 @@ static int tch_bridge(struct gsm_network *net, struct gsm_mncc_bridge *bridge)
/* Which subscriber do we want to track trans1 or trans2? */
log_set_context(LOG_CTX_VLR_SUBSCR, trans1->vsub);
/* This call briding mechanism is only used with the internal MNCC.
* functionality (with external MNCC briding would be done by the PBX)
* This means we may just copy the codec info we have for the RAN side
* of the first leg to the CN side of both legs. This also means that
* if both legs use different codecs the MGW must perform transcoding
* on the second leg. */
trans1->conn->rtp.codec_cn = trans1->conn->rtp.codec_ran;
trans2->conn->rtp.codec_cn = trans1->conn->rtp.codec_ran;
/* Bridge RTP streams */
rc = msc_mgcp_call_complete(trans1, trans2->conn->rtp.local_port_cn,
trans2->conn->rtp.local_addr_cn);
@ -1716,6 +1725,16 @@ static int tch_rtp_connect(struct gsm_network *net, void *arg)
struct gsm_mncc_rtp *rtp = arg;
struct in_addr addr;
/* FIXME: in *rtp we should get the codec information of the remote
* leg. We will have to populate trans->conn->rtp.codec_cn with a
* meaningful value based on this information but unfortunately we
* can't do that yet because the mncc API can not signal dynamic
* payload types yet. This must be fixed first. Also there may be
* additional members necessary in trans->conn->rtp because we
* somehow need to deal with dynamic payload types that do not
* comply to 3gpp's assumptions of payload type numbers on the A
* interface. See also related tickets: OS#3399 and OS1683 */
/* Find callref */
trans = trans_find_by_callref(net, rtp->callref);
if (!trans) {

View File

@ -277,22 +277,16 @@ static void fsm_crcx_ran_cb(struct osmo_fsm_inst *fi, uint32_t event, void *data
struct mgcp_msg mgcp_msg;
struct msgb *msg;
int rc;
#ifdef BUILD_IU
struct gsm_trans *trans;
struct gsm_subscriber_connection *conn;
#endif
OSMO_ASSERT(mgcp_ctx);
mgcp = mgcp_ctx->mgcp;
OSMO_ASSERT(mgcp);
#ifdef BUILD_IU
trans = mgcp_ctx->trans;
OSMO_ASSERT(trans);
conn = trans->conn;
OSMO_ASSERT(conn);
#endif
/* NOTE: In case of error, we will not be able to perform any DLCX
* operation because until this point we do not have requested any
@ -396,22 +390,16 @@ static void fsm_crcx_cn_cb(struct osmo_fsm_inst *fi, uint32_t event, void *data)
struct mgcp_msg mgcp_msg;
struct msgb *msg;
int rc;
#ifdef BUILD_IU
struct gsm_trans *trans;
struct gsm_subscriber_connection *conn;
#endif
OSMO_ASSERT(mgcp_ctx);
mgcp = mgcp_ctx->mgcp;
OSMO_ASSERT(mgcp);
#ifdef BUILD_IU
trans = mgcp_ctx->trans;
OSMO_ASSERT(trans);
conn = trans->conn;
OSMO_ASSERT(conn);
#endif
switch (event) {
case EV_CRCX_RAN_RESP:
@ -593,7 +581,9 @@ static void fsm_mdcx_cn_cb(struct osmo_fsm_inst *fi, uint32_t event, void *data)
.conn_id = mgcp_ctx->conn_id_cn,
.conn_mode = MGCP_CONN_RECV_SEND,
.audio_ip = conn->rtp.remote_addr_cn,
.audio_port = conn->rtp.remote_port_cn
.audio_port = conn->rtp.remote_port_cn,
.codecs[0] = conn->rtp.codec_cn,
.codecs_len = 1
};
if (osmo_strlcpy(mgcp_msg.endpoint, mgcp_ctx->rtp_endpoint, sizeof(mgcp_msg.endpoint)) >=
MGCP_ENDPOINT_MAXLEN) {
@ -710,7 +700,9 @@ static void fsm_mdcx_ran_cb(struct osmo_fsm_inst *fi, uint32_t event, void *data
.conn_id = mgcp_ctx->conn_id_ran,
.conn_mode = MGCP_CONN_RECV_SEND,
.audio_ip = conn->rtp.remote_addr_ran,
.audio_port = conn->rtp.remote_port_ran
.audio_port = conn->rtp.remote_port_ran,
.codecs[0] = conn->rtp.codec_ran,
.codecs_len = 1
};
if (osmo_strlcpy(mgcp_msg.endpoint, mgcp_ctx->rtp_endpoint, sizeof(mgcp_msg.endpoint)) >=
MGCP_ENDPOINT_MAXLEN) {