From 212c0c9bdaf1166e3bcbab85f3ab31dc17162f5b Mon Sep 17 00:00:00 2001 From: Neels Hofmeyr Date: Fri, 7 Dec 2018 14:47:34 +0100 Subject: move ASS-COMPL MGCP handling out of a_iface_bssap.c BSSMAP Assignment Complete: sort MGCP handling upon Assignment Complete to the proper locations. a_iface_bssap.c is not the right place to invoke the MGCP related procedures. - in a_iface_bssap.c only decode the IEs. - call ran_conn_assign_compl() and pass decoded values. - drop msc_assign_compl(), it was dead code; instead: - add ran_conn_assign_compl() - pass on all MGCP related info to msc_mgcp_ass_complete() - move all MGCP ctx related handling from a_iface_bssap.c to msc_mgcp.c. I'm dropping some comments to save some time, because if I adjust them IMHO they would still anyway restate the obvious. ran_conn_assign_compl() is now quite a thin shim, but it makes sense to have it: - This is the place that should tear down the ran_conn in case assignment failed, left for a future patch. - In the light of upcoming inter-MSC handover, ran_conn_assign_compl() will be the place where the Assignment Complete message might be relayed to a remote MSC. Change-Id: I8137215c443239bddf3e69b5715839a365b73b6c --- include/osmocom/msc/msc_mgcp.h | 5 +- include/osmocom/msc/ran_conn.h | 5 ++ src/libmsc/a_iface_bssap.c | 52 +-------------------- src/libmsc/msc_mgcp.c | 102 ++++++++++++++++++++++++++++------------- src/libmsc/osmo_msc.c | 10 ++-- 5 files changed, 87 insertions(+), 87 deletions(-) diff --git a/include/osmocom/msc/msc_mgcp.h b/include/osmocom/msc/msc_mgcp.h index 9d8b01dd1..db8dff24c 100644 --- a/include/osmocom/msc/msc_mgcp.h +++ b/include/osmocom/msc/msc_mgcp.h @@ -24,6 +24,8 @@ #include struct ran_conn; +struct gsm0808_speech_codec; +struct sockaddr_storage; /* MGCP state handler context. This context information stores all information * to handle the direction of the RTP streams via MGCP. There is one instance @@ -58,6 +60,7 @@ struct mgcp_ctx { }; int msc_mgcp_call_assignment(struct gsm_trans *trans); -int msc_mgcp_ass_complete(struct ran_conn *conn, uint16_t port, char *addr); +int msc_mgcp_ass_complete(struct ran_conn *conn, const struct gsm0808_speech_codec *speech_codec_chosen, + const struct sockaddr_storage *aoip_transport_addr); int msc_mgcp_call_complete(struct gsm_trans *trans, uint16_t port, char *addr); int msc_mgcp_call_release(struct gsm_trans *trans); diff --git a/include/osmocom/msc/ran_conn.h b/include/osmocom/msc/ran_conn.h index d71872e8e..3716f865d 100644 --- a/include/osmocom/msc/ran_conn.h +++ b/include/osmocom/msc/ran_conn.h @@ -7,6 +7,9 @@ #include #include +struct gsm0808_speech_codec; +struct sockaddr_storage; + enum ran_type { RAN_UNKNOWN, RAN_GERAN_A, /* 2G / A-interface */ @@ -197,6 +200,8 @@ void ran_conn_rx_sec_mode_compl(struct ran_conn *conn); void ran_conn_classmark_chg(struct ran_conn *conn, const uint8_t *cm2, uint8_t cm2_len, const uint8_t *cm3, uint8_t cm3_len); +void ran_conn_assign_compl(struct ran_conn *conn, const struct gsm0808_speech_codec *speech_codec_chosen, + const struct sockaddr_storage *aoip_transport_addr); void ran_conn_assign_fail(struct ran_conn *conn, uint8_t cause, uint8_t *rr_cause); void ran_conn_init(void); diff --git a/src/libmsc/a_iface_bssap.c b/src/libmsc/a_iface_bssap.c index d84a2346b..4e8b1468d 100644 --- a/src/libmsc/a_iface_bssap.c +++ b/src/libmsc/a_iface_bssap.c @@ -34,7 +34,6 @@ #include #include #include -#include #include @@ -498,51 +497,12 @@ static int bssmap_rx_sapi_n_rej(struct ran_conn *conn, struct msgb *msg, 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 ran_conn *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; LOGPCONN(conn, LOGL_INFO, "Rx BSSMAP ASSIGNMENT COMPLETE message\n"); @@ -567,18 +527,8 @@ static int bssmap_rx_ass_compl(struct ran_conn *conn, struct msgb *msg, 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) { - rtp_addr_in = (struct sockaddr_in *)&rtp_addr; - msc_mgcp_ass_complete(conn, osmo_ntohs(rtp_addr_in->sin_port), inet_ntoa(rtp_addr_in->sin_addr)); - } else { - LOGPCONN(conn, LOGL_ERROR, "Unsopported addressing scheme. (supports only IPV4)\n"); - return -EINVAL; - } + ran_conn_assign_compl(conn, &sc, &rtp_addr); return 0; } diff --git a/src/libmsc/msc_mgcp.c b/src/libmsc/msc_mgcp.c index 1ddec08af..7aeab4ab8 100644 --- a/src/libmsc/msc_mgcp.c +++ b/src/libmsc/msc_mgcp.c @@ -26,6 +26,8 @@ #include #include #include +#include + #include #include #include @@ -1025,51 +1027,89 @@ int msc_mgcp_call_assignment(struct gsm_trans *trans) return 0; } -/* Inform the FSM that the assignment (RAN connection) is now complete. - * Parameter: - * conn: RAN connection context. - * port: port number of the remote leg. - * addr: IP-address of the remote leg. - * Returns -EINVAL on error, 0 on success. */ -int msc_mgcp_ass_complete(struct ran_conn *conn, uint16_t port, char *addr) +static enum mgcp_codecs mgcp_codec_from_sc(const struct gsm0808_speech_codec *sc) { - struct mgcp_ctx *mgcp_ctx; + 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; + } +} - OSMO_ASSERT(conn); +int msc_mgcp_ass_complete(struct ran_conn *conn, const struct gsm0808_speech_codec *speech_codec_chosen, + const struct sockaddr_storage *aoip_transport_addr) +{ + struct sockaddr_in *rtp_addr_in; + const char *addr; + uint16_t port; + struct mgcp_ctx *mgcp_ctx = conn->rtp.mgcp_ctx; + struct osmo_fsm_inst *fi; - if (port == 0) { - LOGP(DMGCP, LOGL_ERROR, "(subscriber:%s) invalid remote call leg port, assignment completion failed\n", - vlr_subscr_name(conn->vsub)); + if (!mgcp_ctx || !mgcp_ctx->fsm) { + LOGPCONN(conn, LOGL_ERROR, "Invalid MGCP context, Assignment Complete failed.\n"); return -EINVAL; } - if (!addr || strlen(addr) <= 0) { - LOGP(DMGCP, LOGL_ERROR, "(subscriber:%s) missing remote call leg address, assignment completion failed\n", - vlr_subscr_name(conn->vsub)); + + fi = mgcp_ctx->fsm; + + if (fi->state != ST_MDCX_RAN) { + LOGPFSML(fi, LOGL_ERROR, "Assignment Complete not allowed in this state\n"); + return -ENOTSUP; + } + + /* use address / port supplied with the AoIP transport address element */ + if (aoip_transport_addr->ss_family != AF_INET) { + LOGPCONN(conn, LOGL_ERROR, "Assignment Complete: Unsupported addressing scheme (only IPV4 supported)\n"); return -EINVAL; } - mgcp_ctx = conn->rtp.mgcp_ctx; - if (!mgcp_ctx) { - LOGP(DMGCP, LOGL_ERROR, "(subscriber:%s) invalid mgcp context, assignment completion failed.\n", - vlr_subscr_name(conn->vsub)); + rtp_addr_in = (struct sockaddr_in *)&aoip_transport_addr; + addr = inet_ntoa(rtp_addr_in->sin_addr); + port = osmo_ntohs(rtp_addr_in->sin_port); + + if (port == 0) { + LOGPCONN(conn, LOGL_ERROR, "Assignment Complete: invalid remote call leg port (0)\n"); + return -EINVAL; + } + if (!addr || strlen(addr) <= 0) { + LOGPCONN(conn, LOGL_ERROR, "Assignment Complete: invalid remote call leg address (empty)\n"); return -EINVAL; } - /* Memorize port and IP-Address of the remote RAN call leg. We need this - * information at latest when we enter the MDCX phase for the RAN side. */ - conn->rtp.remote_port_ran = port; + conn->rtp.codec_ran = mgcp_codec_from_sc(speech_codec_chosen); osmo_strlcpy(conn->rtp.remote_addr_ran, addr, sizeof(conn->rtp.remote_addr_ran)); + conn->rtp.remote_port_ran = port; - LOGP(DMGCP, LOGL_DEBUG, "(subscriber:%s) assignment completed, rtp %s:%d.\n", - vlr_subscr_name(conn->vsub), conn->rtp.remote_addr_ran, port); - - /* Note: We only dispatch the event if we are really waiting for the - * assignment, if we are not yet waiting, there is no need to loudly - * broadcast an event that the all other states do not understand anyway */ - if (mgcp_ctx->fsm->state == ST_MDCX_RAN) - osmo_fsm_inst_dispatch(mgcp_ctx->fsm, EV_ASSIGN, mgcp_ctx); + LOGPCONN(conn, LOGL_DEBUG, "Assignment Complete: rtp %s:%u\n", addr, port); - return 0; + return osmo_fsm_inst_dispatch(fi, EV_ASSIGN, mgcp_ctx); } /* Make the connection of a previously assigned call complete diff --git a/src/libmsc/osmo_msc.c b/src/libmsc/osmo_msc.c index 37c1d15a4..8cc5ee772 100644 --- a/src/libmsc/osmo_msc.c +++ b/src/libmsc/osmo_msc.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "../../bscconfig.h" #ifdef BUILD_IU @@ -113,17 +114,18 @@ void ran_conn_dtap(struct ran_conn *conn, struct msgb *msg) } /* Receive an ASSIGNMENT COMPLETE from BSC */ -void msc_assign_compl(struct ran_conn *conn, - uint8_t rr_cause, uint8_t chosen_channel, - uint8_t encr_alg_id, uint8_t speec) +void ran_conn_assign_compl(struct ran_conn *conn, const struct gsm0808_speech_codec *speech_codec_chosen, + const struct sockaddr_storage *aoip_transport_addr) { - LOGP(DRR, LOGL_DEBUG, "MSC assign complete (do nothing).\n"); + msc_mgcp_ass_complete(conn, speech_codec_chosen, aoip_transport_addr); + /* FIXME: tear down conn upon failure */ } /* Receive an ASSIGNMENT FAILURE from BSC */ void ran_conn_assign_fail(struct ran_conn *conn, uint8_t cause, uint8_t *rr_cause) { LOGP(DRR, LOGL_DEBUG, "MSC assign failure (do nothing).\n"); + /* FIXME: tear down conn upon failure */ } /* Receive a CLASSMARK CHANGE from BSC */ -- cgit v1.2.3