Change in osmo-bsc[master]: move mgw endpoint FSM to osmo-mgw.git

This is merely a historical archive of years 2008-2021, before the migration to mailman3.

A maintained and still updated list archive can be found at https://lists.osmocom.org/hyperkitty/list/gerrit-log@lists.osmocom.org/.

Harald Welte gerrit-no-reply at lists.osmocom.org
Tue Apr 30 07:17:40 UTC 2019


Harald Welte has submitted this change and it was merged. ( https://gerrit.osmocom.org/13796 )

Change subject: move mgw endpoint FSM to osmo-mgw.git
......................................................................

move mgw endpoint FSM to osmo-mgw.git

osmo-mgw.git also includes fixes of the MGW endpoint FSM, for example
I92a9944acc96398acd6649f9c3c5badec5dd6dcc.

Depends: I9a3effd38e72841529df6c135c077116981dea36 (osmo-mgw)
Change-Id: I03e6b48d9b0a5370310d5f56809259ff7909cf9d
---
M include/osmocom/bsc/Makefile.am
M include/osmocom/bsc/bsc_subscr_conn_fsm.h
M include/osmocom/bsc/gsm_data.h
M include/osmocom/bsc/lchan_rtp_fsm.h
D include/osmocom/bsc/mgw_endpoint_fsm.h
M src/osmo-bsc/Makefile.am
M src/osmo-bsc/assignment_fsm.c
M src/osmo-bsc/bsc_subscr_conn_fsm.c
M src/osmo-bsc/bsc_vty.c
M src/osmo-bsc/codec_pref.c
M src/osmo-bsc/handover_fsm.c
M src/osmo-bsc/lchan_fsm.c
M src/osmo-bsc/lchan_rtp_fsm.c
D src/osmo-bsc/mgw_endpoint_fsm.c
M src/osmo-bsc/net_init.c
M src/osmo-bsc/osmo_bsc_bssap.c
M src/osmo-bsc/osmo_bsc_lcls.c
M src/osmo-bsc/osmo_bsc_main.c
M tests/handover/Makefile.am
M tests/handover/handover_test.c
20 files changed, 187 insertions(+), 939 deletions(-)

Approvals:
  Jenkins Builder: Verified
  Harald Welte: Looks good to me, approved



diff --git a/include/osmocom/bsc/Makefile.am b/include/osmocom/bsc/Makefile.am
index 21e53d7..89323c0 100644
--- a/include/osmocom/bsc/Makefile.am
+++ b/include/osmocom/bsc/Makefile.am
@@ -33,7 +33,6 @@
 	meas_feed.h \
 	meas_rep.h \
 	misdn.h \
-	mgw_endpoint_fsm.h \
 	neighbor_ident.h \
 	network_listen.h \
 	openbscdefines.h \
diff --git a/include/osmocom/bsc/bsc_subscr_conn_fsm.h b/include/osmocom/bsc/bsc_subscr_conn_fsm.h
index f5ed7bd..5475272 100644
--- a/include/osmocom/bsc/bsc_subscr_conn_fsm.h
+++ b/include/osmocom/bsc/bsc_subscr_conn_fsm.h
@@ -43,7 +43,7 @@
 struct gsm_subscriber_connection;
 struct gsm_network;
 struct msgb;
-struct mgwep_ci;
+struct osmo_mgcpc_ep_ci;
 struct assignment_request;
 struct gsm_lchan;
 
@@ -57,15 +57,15 @@
 			   struct msgb *msg, int link_id, int allow_sacch);
 int gscon_sigtran_send(struct gsm_subscriber_connection *conn, struct msgb *msg);
 
-struct mgw_endpoint *gscon_ensure_mgw_endpoint(struct gsm_subscriber_connection *conn,
-					       uint16_t msc_assigned_cic);
+struct osmo_mgcpc_ep *gscon_ensure_mgw_endpoint(struct gsm_subscriber_connection *conn,
+						uint16_t msc_assigned_cic);
 bool gscon_connect_mgw_to_msc(struct gsm_subscriber_connection *conn,
 			      struct gsm_lchan *for_lchan,
 			      const char *addr, uint16_t port,
 			      struct osmo_fsm_inst *notify,
 			      uint32_t event_success, uint32_t event_failure,
 			      void *notify_data,
-			      struct mgwep_ci **created_ci);
+			      struct osmo_mgcpc_ep_ci **created_ci);
 
 void gscon_start_assignment(struct gsm_subscriber_connection *conn,
 			    struct assignment_request *req);
@@ -76,7 +76,7 @@
 void gscon_lchan_releasing(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
 void gscon_forget_lchan(struct gsm_subscriber_connection *conn, struct gsm_lchan *lchan);
 
-void gscon_forget_mgw_endpoint_ci(struct gsm_subscriber_connection *conn, struct mgwep_ci *ci);
+void gscon_forget_mgw_endpoint_ci(struct gsm_subscriber_connection *conn, struct osmo_mgcpc_ep_ci *ci);
 
 bool gscon_is_aoip(struct gsm_subscriber_connection *conn);
 bool gscon_is_sccplite(struct gsm_subscriber_connection *conn);
diff --git a/include/osmocom/bsc/gsm_data.h b/include/osmocom/bsc/gsm_data.h
index 7b813a6..dacc63b 100644
--- a/include/osmocom/bsc/gsm_data.h
+++ b/include/osmocom/bsc/gsm_data.h
@@ -39,7 +39,7 @@
 struct mgcp_client_conf;
 struct mgcp_client;
 struct gsm0808_cell_id;
-struct mgw_endpoint;
+struct osmo_mgcpc_ep;
 
 /** annotations for msgb ownership */
 #define __uses
@@ -136,7 +136,7 @@
 	/* Whether this assignment triggered creation of the MGW endpoint: if the assignment
 	 * fails, we will release that again as soon as possible. (If false, the endpoint already
 	 * existed before or isn't needed at all.)*/
-	struct mgwep_ci *created_ci_for_msc;
+	struct osmo_mgcpc_ep_ci *created_ci_for_msc;
 
 	enum gsm0808_cause failure_cause;
 	enum gsm48_rr_cause rr_cause;
@@ -205,7 +205,7 @@
 	struct gsm_lchan *new_lchan;
 	bool async;
 	struct handover_in_req inter_bsc_in;
-	struct mgwep_ci *created_ci_for_msc;
+	struct osmo_mgcpc_ep_ci *created_ci_for_msc;
 };
 
 /* active radio connection of a mobile subscriber */
@@ -287,11 +287,11 @@
 
 		/* The endpoint at the MGW used to join both BTS and MSC side connections, e.g.
 		 * "rtpbridge/23 at mgw". */
-		struct mgw_endpoint *mgw_endpoint;
+		struct osmo_mgcpc_ep *mgw_endpoint;
 
-		/* The connection identifier of the mgw_endpoint used to transceive RTP towards the MSC.
+		/* The connection identifier of the osmo_mgcpc_ep used to transceive RTP towards the MSC.
 		 * (The BTS side CI is handled by struct gsm_lchan and the lchan_fsm.) */
-		struct mgwep_ci *mgw_endpoint_ci_msc;
+		struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_msc;
 	} user_plane;
 
 	/* LCLS (local call, local switch) related state */
@@ -554,7 +554,7 @@
 
 	struct osmo_fsm_inst *fi;
 	struct osmo_fsm_inst *fi_rtp;
-	struct mgwep_ci *mgw_endpoint_ci_bts;
+	struct osmo_mgcpc_ep_ci *mgw_endpoint_ci_bts;
 
 	struct {
 		struct lchan_activate_info info;
@@ -1535,6 +1535,7 @@
 	struct {
 		struct mgcp_client_conf *conf;
 		struct mgcp_client *client;
+		struct osmo_tdef *tdefs;
 	} mgw;
 
 	/* Remote BSS Cell Identifier Lists */
diff --git a/include/osmocom/bsc/lchan_rtp_fsm.h b/include/osmocom/bsc/lchan_rtp_fsm.h
index fa0e746..6ff8fe3 100644
--- a/include/osmocom/bsc/lchan_rtp_fsm.h
+++ b/include/osmocom/bsc/lchan_rtp_fsm.h
@@ -10,6 +10,7 @@
 	} while(0)
 
 struct gsm_lchan;
+struct mgcp_conn_peer;
 
 enum lchan_rtp_fsm_state {
 	LCHAN_RTP_ST_WAIT_MGW_ENDPOINT_AVAILABLE,
@@ -40,6 +41,8 @@
 };
 
 void lchan_rtp_fsm_start(struct gsm_lchan *lchan);
-struct mgwep_ci *lchan_use_mgw_endpoint_ci_bts(struct gsm_lchan *lchan);
+struct osmo_mgcpc_ep_ci *lchan_use_mgw_endpoint_ci_bts(struct gsm_lchan *lchan);
 bool lchan_rtp_established(struct gsm_lchan *lchan);
 void lchan_forget_mgw_endpoint(struct gsm_lchan *lchan);
+
+void mgcp_pick_codec(struct mgcp_conn_peer *verb_info, const struct gsm_lchan *lchan, bool bss_side);
diff --git a/include/osmocom/bsc/mgw_endpoint_fsm.h b/include/osmocom/bsc/mgw_endpoint_fsm.h
deleted file mode 100644
index f86a7cd..0000000
--- a/include/osmocom/bsc/mgw_endpoint_fsm.h
+++ /dev/null
@@ -1,59 +0,0 @@
-/* osmo-bsc API to manage all sides of an MGW endpoint */
-#pragma once
-
-#include <osmocom/mgcp_client/mgcp_client_fsm.h>
-
-#include <osmocom/bsc/debug.h>
-
-/* This macro automatically includes a final \n, if omitted. */
-#define LOG_MGWEP(mgwep, level, fmt, args...) do { \
-	LOGPFSML(mgwep->fi, level, "(%s) " fmt, \
-		 mgw_endpoint_name(mgwep), ## args); \
-	} while(0)
-
-enum mgwep_fsm_state {
-	MGWEP_ST_UNUSED,
-	MGWEP_ST_WAIT_MGW_RESPONSE,
-	MGWEP_ST_IN_USE,
-};
-
-enum mgwep_fsm_event {
-	_MGWEP_EV_LAST,
-	/* and MGW response events are allocated dynamically */
-};
-
-struct mgw_endpoint;
-struct mgwep_ci;
-struct osmo_tdef;
-
-void mgw_endpoint_fsm_init(struct osmo_tdef *T_defs);
-
-struct mgw_endpoint *mgw_endpoint_alloc(struct osmo_fsm_inst *parent, uint32_t parent_term_event,
-					struct mgcp_client *mgcp_client,
-					const char *fsm_id,
-					const char *endpoint_str_fmt, ...);
-
-struct mgwep_ci *mgw_endpoint_ci_add(struct mgw_endpoint *mgwep,
-				     const char *label_fmt, ...);
-const struct mgcp_conn_peer *mgwep_ci_get_rtp_info(const struct mgwep_ci *ci);
-bool mgwep_ci_get_crcx_info_to_sockaddr(const struct mgwep_ci *ci, struct sockaddr_storage *dest);
-
-void mgw_endpoint_ci_request(struct mgwep_ci *ci,
-			     enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
-			     struct osmo_fsm_inst *notify,
-			     uint32_t event_success, uint32_t event_failure,
-			     void *notify_data);
-
-static inline void mgw_endpoint_ci_dlcx(struct mgwep_ci *ci)
-{
-	mgw_endpoint_ci_request(ci, MGCP_VERB_DLCX, NULL, NULL, 0, 0, NULL);
-}
-
-void mgw_endpoint_clear(struct mgw_endpoint *mgwep);
-
-const char *mgw_endpoint_name(const struct mgw_endpoint *mgwep);
-const char *mgwep_ci_name(const struct mgwep_ci *ci);
-const char *mgcp_conn_peer_name(const struct mgcp_conn_peer *info);
-
-enum mgcp_codecs chan_mode_to_mgcp_codec(enum gsm48_chan_mode chan_mode, bool full_rate);
-void mgcp_pick_codec(struct mgcp_conn_peer *verb_info, const struct gsm_lchan *lchan, bool bss_side);
diff --git a/src/osmo-bsc/Makefile.am b/src/osmo-bsc/Makefile.am
index 11803da..e88e614 100644
--- a/src/osmo-bsc/Makefile.am
+++ b/src/osmo-bsc/Makefile.am
@@ -68,7 +68,6 @@
 	lchan_select.c \
 	meas_feed.c \
 	meas_rep.c \
-	mgw_endpoint_fsm.c \
 	neighbor_ident.c \
 	neighbor_ident_vty.c \
 	net_init.c \
diff --git a/src/osmo-bsc/assignment_fsm.c b/src/osmo-bsc/assignment_fsm.c
index 520498f..fdfc080 100644
--- a/src/osmo-bsc/assignment_fsm.c
+++ b/src/osmo-bsc/assignment_fsm.c
@@ -23,12 +23,11 @@
 #include <osmocom/core/tdef.h>
 #include <osmocom/gsm/gsm0808.h>
 
-#include <osmocom/mgcp_client/mgcp_client_fsm.h>
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
 
 #include <osmocom/bsc/debug.h>
 #include <osmocom/bsc/gsm_data.h>
 #include <osmocom/bsc/lchan_fsm.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
 #include <osmocom/bsc/bsc_subscr_conn_fsm.h>
 #include <osmocom/bsc/osmo_bsc_lcls.h>
 #include <osmocom/bsc/bsc_msc_data.h>
@@ -105,7 +104,7 @@
 		gscon_forget_mgw_endpoint_ci(conn, conn->assignment.created_ci_for_msc);
 		/* If this is the last endpoint released, the mgw_endpoint_fsm will terminate and tell
 		 * the gscon about it. */
-		mgw_endpoint_ci_dlcx(conn->assignment.created_ci_for_msc);
+		osmo_mgcpc_ep_ci_dlcx(conn->assignment.created_ci_for_msc);
 	}
 
 	conn->assignment = (struct assignment_fsm_data){
@@ -156,8 +155,8 @@
 		perm_spch = gsm0808_permitted_speech(lchan->type, lchan->tch_mode);
 
 		if (gscon_is_aoip(conn)) {
-			if (!mgwep_ci_get_crcx_info_to_sockaddr(conn->user_plane.mgw_endpoint_ci_msc,
-								&addr_local)) {
+			if (!osmo_mgcpc_ep_ci_get_crcx_info_to_sockaddr(conn->user_plane.mgw_endpoint_ci_msc,
+									&addr_local)) {
 				assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
 						"Unable to compose RTP address of MGW -> MSC");
 				return;
@@ -626,7 +625,7 @@
 		/* For AoIP, we created the MGW endpoint. Ensure it is really there, and log it. */
 		if (gscon_is_aoip(conn)) {
 			const struct mgcp_conn_peer *mgw_info;
-			mgw_info = mgwep_ci_get_rtp_info(conn->user_plane.mgw_endpoint_ci_msc);
+			mgw_info = osmo_mgcpc_ep_ci_get_rtp_info(conn->user_plane.mgw_endpoint_ci_msc);
 			if (!mgw_info) {
 				assignment_fail(GSM0808_CAUSE_EQUIPMENT_FAILURE,
 						"Unable to retrieve RTP port info allocated by MGW for"
diff --git a/src/osmo-bsc/bsc_subscr_conn_fsm.c b/src/osmo-bsc/bsc_subscr_conn_fsm.c
index 4466404..f944431 100644
--- a/src/osmo-bsc/bsc_subscr_conn_fsm.c
+++ b/src/osmo-bsc/bsc_subscr_conn_fsm.c
@@ -39,9 +39,9 @@
 #include <osmocom/bsc/abis_rsl.h>
 #include <osmocom/core/tdef.h>
 #include <osmocom/bsc/gsm_04_08_rr.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
 #include <osmocom/bsc/assignment_fsm.h>
-#include <osmocom/mgcp_client/mgcp_client_fsm.h>
+#include <osmocom/bsc/codec_pref.h>
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
 #include <osmocom/core/byteswap.h>
 
 #define S(x)	(1 << (x))
@@ -457,8 +457,8 @@
 /* Make sure a conn->user_plane.mgw_endpoint is allocated with the proper mgw endpoint name.  For
  * SCCPlite, pass in msc_assigned_cic the CIC received upon BSSMAP Assignment Command or BSSMAP Handover
  * Request form the MSC (which is only stored in conn->user_plane after success). Ignored for AoIP. */
-struct mgw_endpoint *gscon_ensure_mgw_endpoint(struct gsm_subscriber_connection *conn,
-					       uint16_t msc_assigned_cic)
+struct osmo_mgcpc_ep *gscon_ensure_mgw_endpoint(struct gsm_subscriber_connection *conn,
+						uint16_t msc_assigned_cic)
 {
 	if (conn->user_plane.mgw_endpoint)
 		return conn->user_plane.mgw_endpoint;
@@ -466,19 +466,23 @@
 	if (gscon_is_sccplite(conn)) {
 		/* derive endpoint name from CIC on A interface side */
 		conn->user_plane.mgw_endpoint =
-			mgw_endpoint_alloc(conn->fi, GSCON_EV_FORGET_MGW_ENDPOINT,
-					   conn->network->mgw.client, conn->fi->id,
-					   "%x@%s", msc_assigned_cic,
-					   mgcp_client_endpoint_domain(conn->network->mgw.client));
+			osmo_mgcpc_ep_alloc(conn->fi, GSCON_EV_FORGET_MGW_ENDPOINT,
+					    conn->network->mgw.client,
+					    conn->network->mgw.tdefs,
+					    conn->fi->id,
+					    "%x@%s", msc_assigned_cic,
+					    mgcp_client_endpoint_domain(conn->network->mgw.client));
 		LOGPFSML(conn->fi, LOGL_DEBUG, "MGW endpoint name derived from CIC 0x%x: %s\n",
-			 msc_assigned_cic, mgw_endpoint_name(conn->user_plane.mgw_endpoint));
+			 msc_assigned_cic, osmo_mgcpc_ep_name(conn->user_plane.mgw_endpoint));
 
 	} else if (gscon_is_aoip(conn)) {
 		/* use dynamic RTPBRIDGE endpoint allocation in MGW */
 		conn->user_plane.mgw_endpoint =
-			mgw_endpoint_alloc(conn->fi, GSCON_EV_FORGET_MGW_ENDPOINT,
-					   conn->network->mgw.client, conn->fi->id,
-					   "%s", mgcp_client_rtpbridge_wildcard(conn->network->mgw.client));
+			osmo_mgcpc_ep_alloc(conn->fi, GSCON_EV_FORGET_MGW_ENDPOINT,
+					    conn->network->mgw.client,
+					    conn->network->mgw.tdefs,
+					    conn->fi->id,
+					    "%s", mgcp_client_rtpbridge_wildcard(conn->network->mgw.client));
 	} else {
 		LOGPFSML(conn->fi, LOGL_ERROR, "Conn is neither SCCPlite nor AoIP!?\n");
 		return NULL;
@@ -493,10 +497,10 @@
 			      struct osmo_fsm_inst *notify,
 			      uint32_t event_success, uint32_t event_failure,
 			      void *notify_data,
-			      struct mgwep_ci **created_ci)
+			      struct osmo_mgcpc_ep_ci **created_ci)
 {
 	int rc;
-	struct mgwep_ci *ci;
+	struct osmo_mgcpc_ep_ci *ci;
 	struct mgcp_conn_peer mgw_info;
 	enum mgcp_verb verb;
 
@@ -526,7 +530,7 @@
 
 	ci = conn->user_plane.mgw_endpoint_ci_msc;
 	if (ci) {
-		const struct mgcp_conn_peer *prev_crcx_info = mgwep_ci_get_rtp_info(ci);
+		const struct mgcp_conn_peer *prev_crcx_info = osmo_mgcpc_ep_ci_get_rtp_info(ci);
 
 		if (!conn->user_plane.mgw_endpoint) {
 			LOGPFSML(conn->fi, LOGL_ERROR, "Internal error: conn has a CI but no endoint\n");
@@ -536,14 +540,14 @@
 		if (!prev_crcx_info) {
 			LOGPFSML(conn->fi, LOGL_ERROR, "There already is an MGW connection for the MSC side,"
 				 " but it seems to be broken. Will not CRCX another one (%s)\n",
-				 mgwep_ci_name(ci));
+				 osmo_mgcpc_ep_ci_name(ci));
 			return false;
 		}
 
 		if (same_mgw_info(&mgw_info, prev_crcx_info)) {
 			LOGPFSML(conn->fi, LOGL_DEBUG,
 				 "MSC side MGW endpoint ci is already configured to %s\n",
-				 mgwep_ci_name(ci));
+				 osmo_mgcpc_ep_ci_name(ci));
 			return true;
 		}
 
@@ -559,7 +563,7 @@
 	}
 
 	if (!ci) {
-		ci = mgw_endpoint_ci_add(conn->user_plane.mgw_endpoint, "to-MSC");
+		ci = osmo_mgcpc_ep_ci_add(conn->user_plane.mgw_endpoint, "to-MSC");
 		if (created_ci)
 			*created_ci = ci;
 		conn->user_plane.mgw_endpoint_ci_msc = ci;
@@ -569,7 +573,7 @@
 		return false;
 	}
 
-	mgw_endpoint_ci_request(ci, verb, &mgw_info, notify, event_success, event_failure, notify_data);
+	osmo_mgcpc_ep_ci_request(ci, verb, &mgw_info, notify, event_success, event_failure, notify_data);
 	return true;
 }
 
@@ -705,7 +709,7 @@
 	lchan_forget_mgw_endpoint(conn->ho.new_lchan);
 }
 
-void gscon_forget_mgw_endpoint_ci(struct gsm_subscriber_connection *conn, struct mgwep_ci *ci)
+void gscon_forget_mgw_endpoint_ci(struct gsm_subscriber_connection *conn, struct osmo_mgcpc_ep_ci *ci)
 {
 	if (conn->ho.created_ci_for_msc == ci)
 		conn->ho.created_ci_for_msc = NULL;
@@ -734,7 +738,7 @@
 		 * CLEAR COMPLETE message" */
 
 		/* Close MGCP connections */
-		mgw_endpoint_clear(conn->user_plane.mgw_endpoint);
+		osmo_mgcpc_ep_clear(conn->user_plane.mgw_endpoint);
 
 		gscon_sigtran_send(conn, gsm0808_create_clear_complete());
 		break;
@@ -794,7 +798,7 @@
 {
 	struct gsm_subscriber_connection *conn = fi->priv;
 
-	mgw_endpoint_clear(conn->user_plane.mgw_endpoint);
+	osmo_mgcpc_ep_clear(conn->user_plane.mgw_endpoint);
 
 	if (conn->lcls.fi) {
 		/* request termination of LCLS FSM */
diff --git a/src/osmo-bsc/bsc_vty.c b/src/osmo-bsc/bsc_vty.c
index 3a6ddd4..dc97d12 100644
--- a/src/osmo-bsc/bsc_vty.c
+++ b/src/osmo-bsc/bsc_vty.c
@@ -70,7 +70,7 @@
 #include <osmocom/bsc/timeslot_fsm.h>
 #include <osmocom/bsc/lchan_fsm.h>
 #include <osmocom/bsc/lchan_select.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
 
 #include <inttypes.h>
 
@@ -1584,7 +1584,7 @@
 {
 	vty_out(vty, "conn ID=%u, MSC=%u, hodec2_fail=%d, mgw_ep=%s%s",
 		conn->sccp.conn_id, conn->sccp.msc->nr, conn->hodec2.failures,
-		mgw_endpoint_name(conn->user_plane.mgw_endpoint), VTY_NEWLINE);
+		osmo_mgcpc_ep_name(conn->user_plane.mgw_endpoint), VTY_NEWLINE);
 	if (conn->lcls.global_call_ref_len) {
 		vty_out(vty, " LCLS GCR: %s%s",
 			osmo_hexdump_nospc(conn->lcls.global_call_ref, conn->lcls.global_call_ref_len),
diff --git a/src/osmo-bsc/codec_pref.c b/src/osmo-bsc/codec_pref.c
index 412ed9a..3e06114 100644
--- a/src/osmo-bsc/codec_pref.c
+++ b/src/osmo-bsc/codec_pref.c
@@ -20,6 +20,8 @@
  */
 
 #include <osmocom/core/msgb.h>
+#include <osmocom/mgcp_client/mgcp_client_fsm.h>
+#include <osmocom/netif/rtp.h>
 #include <osmocom/gsm/protocol/gsm_08_08.h>
 #include <osmocom/gsm/gsm0808_utils.h>
 #include <osmocom/bsc/bsc_msc_data.h>
diff --git a/src/osmo-bsc/handover_fsm.c b/src/osmo-bsc/handover_fsm.c
index fe3b8b2..0d1449f 100644
--- a/src/osmo-bsc/handover_fsm.c
+++ b/src/osmo-bsc/handover_fsm.c
@@ -25,6 +25,8 @@
 #include <osmocom/gsm/rsl.h>
 #include <osmocom/gsm/gsm0808.h>
 
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
+
 #include <osmocom/bsc/debug.h>
 #include <osmocom/bsc/bsc_subscriber.h>
 
@@ -38,7 +40,6 @@
 #include <osmocom/bsc/bsc_msc_data.h>
 #include <osmocom/bsc/osmo_bsc.h>
 #include <osmocom/bsc/osmo_bsc_lcls.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
 #include <osmocom/bsc/codec_pref.h>
 #include <osmocom/bsc/gsm_08_08.h>
 
@@ -240,7 +241,7 @@
 
 static void handover_reset(struct gsm_subscriber_connection *conn)
 {
-	struct mgwep_ci *ci;
+	struct osmo_mgcpc_ep_ci *ci;
 	if (conn->ho.new_lchan)
 		/* New lchan was activated but never passed to a conn */
 		lchan_release(conn->ho.new_lchan, false, true, RSL_ERR_EQUIPMENT_FAIL);
@@ -250,7 +251,7 @@
 		gscon_forget_mgw_endpoint_ci(conn, ci);
 		/* If this is the last endpoint released, the mgw_endpoint_fsm will terminate and tell
 		 * the gscon about it. */
-		mgw_endpoint_ci_dlcx(ci);
+		osmo_mgcpc_ep_ci_dlcx(ci);
 	}
 
 	conn->ho = (struct handover){
@@ -1074,7 +1075,7 @@
 		/* For AoIP, we created the MGW endpoint. Ensure it is really there, and log it. */
 		if (gscon_is_aoip(conn)) {
 			const struct mgcp_conn_peer *mgw_info;
-			mgw_info = mgwep_ci_get_rtp_info(conn->user_plane.mgw_endpoint_ci_msc);
+			mgw_info = osmo_mgcpc_ep_ci_get_rtp_info(conn->user_plane.mgw_endpoint_ci_msc);
 			if (!mgw_info) {
 				ho_fail(HO_RESULT_ERROR,
 					"Unable to retrieve RTP port info allocated by MGW for"
diff --git a/src/osmo-bsc/lchan_fsm.c b/src/osmo-bsc/lchan_fsm.c
index 33abb1f..f2fef99 100644
--- a/src/osmo-bsc/lchan_fsm.c
+++ b/src/osmo-bsc/lchan_fsm.c
@@ -24,11 +24,12 @@
 #include <osmocom/core/byteswap.h>
 #include <osmocom/gsm/protocol/gsm_08_08.h>
 
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
+
 #include <osmocom/bsc/debug.h>
 #include <osmocom/bsc/lchan_fsm.h>
 #include <osmocom/bsc/lchan_rtp_fsm.h>
 #include <osmocom/bsc/timeslot_fsm.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
 #include <osmocom/bsc/bsc_subscr_conn_fsm.h>
 #include <osmocom/bsc/handover.h>
 #include <osmocom/bsc/abis_rsl.h>
@@ -387,7 +388,7 @@
 	if (lchan->fi_rtp)
 		osmo_fsm_inst_term(lchan->fi_rtp, OSMO_FSM_TERM_REQUEST, 0);
 	if (lchan->mgw_endpoint_ci_bts) {
-		mgw_endpoint_ci_dlcx(lchan->mgw_endpoint_ci_bts);
+		osmo_mgcpc_ep_ci_dlcx(lchan->mgw_endpoint_ci_bts);
 		lchan->mgw_endpoint_ci_bts = NULL;
 	}
 
@@ -507,7 +508,7 @@
 	struct gsm_lchan *lchan = lchan_fi_lchan(fi);
 	struct gsm48_multi_rate_conf mr_conf;
 	struct gsm_bts *bts = lchan->ts->trx->bts;
-	struct mgwep_ci *use_mgwep_ci;
+	struct osmo_mgcpc_ep_ci *use_mgwep_ci;
 	struct gsm_lchan *old_lchan = lchan->activate.info.re_use_mgw_endpoint_from_lchan;
 	struct lchan_activate_info *info = &lchan->activate.info;
 
@@ -581,7 +582,7 @@
 		  lchan_activate_mode_name(lchan->activate.info.activ_for),
 		  lchan->activate.info.requires_voice_stream ? "yes" : "no",
 		  lchan->activate.info.requires_voice_stream ?
-			(use_mgwep_ci ? mgwep_ci_name(use_mgwep_ci) : "new")
+			(use_mgwep_ci ? osmo_mgcpc_ep_ci_name(use_mgwep_ci) : "new")
 			: "none",
 		  gsm_lchant_name(lchan->type),
 		  gsm48_chan_mode_name(lchan->tch_mode),
diff --git a/src/osmo-bsc/lchan_rtp_fsm.c b/src/osmo-bsc/lchan_rtp_fsm.c
index 5e2d758..a5efa3d 100644
--- a/src/osmo-bsc/lchan_rtp_fsm.c
+++ b/src/osmo-bsc/lchan_rtp_fsm.c
@@ -21,11 +21,12 @@
  */
 
 #include <osmocom/core/fsm.h>
+#include <osmocom/netif/rtp.h>
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
 
 #include <osmocom/bsc/gsm_data.h>
 #include <osmocom/bsc/lchan_fsm.h>
 #include <osmocom/bsc/lchan_rtp_fsm.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
 #include <osmocom/bsc/bsc_subscr_conn_fsm.h>
 #include <osmocom/bsc/abis_rsl.h>
 #include <osmocom/bsc/bsc_msc_data.h>
@@ -120,7 +121,7 @@
 /* While activating an lchan, for example for Handover, we may want to re-use another lchan's MGW
  * endpoint CI. If Handover fails half way, the old lchan must keep its MGW endpoint CI, and we must not
  * clean it up. Hence keep another lchan's mgw_endpoint_ci_bts out of lchan until all is done. */
-struct mgwep_ci *lchan_use_mgw_endpoint_ci_bts(struct gsm_lchan *lchan)
+struct osmo_mgcpc_ep_ci *lchan_use_mgw_endpoint_ci_bts(struct gsm_lchan *lchan)
 {
 	if (lchan->mgw_endpoint_ci_bts)
 		return lchan->mgw_endpoint_ci_bts;
@@ -135,13 +136,13 @@
 							      uint32_t prev_state)
 {
 	struct gsm_lchan *lchan = lchan_rtp_fi_lchan(fi);
-	struct mgw_endpoint *mgwep;
-	struct mgwep_ci *use_mgwep_ci = lchan_use_mgw_endpoint_ci_bts(lchan);
+	struct osmo_mgcpc_ep *mgwep;
+	struct osmo_mgcpc_ep_ci *use_mgwep_ci = lchan_use_mgw_endpoint_ci_bts(lchan);
 	struct mgcp_conn_peer crcx_info = {};
 
 	if (use_mgwep_ci) {
 		LOG_LCHAN_RTP(lchan, LOGL_DEBUG, "MGW endpoint already available: %s\n",
-			      mgwep_ci_name(use_mgwep_ci));
+			      osmo_mgcpc_ep_ci_name(use_mgwep_ci));
 		lchan_rtp_fsm_state_chg(LCHAN_RTP_ST_WAIT_LCHAN_READY);
 		return;
 	}
@@ -152,7 +153,7 @@
 		return;
 	}
 
-	lchan->mgw_endpoint_ci_bts = mgw_endpoint_ci_add(mgwep, "to-BTS");
+	lchan->mgw_endpoint_ci_bts = osmo_mgcpc_ep_ci_add(mgwep, "to-BTS");
 
 	if (lchan->conn) {
 		crcx_info.call_id = lchan->conn->sccp.conn_id;
@@ -162,7 +163,7 @@
 	crcx_info.ptime = 20;
 	mgcp_pick_codec(&crcx_info, lchan, true);
 
-	mgw_endpoint_ci_request(lchan->mgw_endpoint_ci_bts, MGCP_VERB_CRCX, &crcx_info,
+	osmo_mgcpc_ep_ci_request(lchan->mgw_endpoint_ci_bts, MGCP_VERB_CRCX, &crcx_info,
 				fi, LCHAN_RTP_EV_MGW_ENDPOINT_AVAILABLE, LCHAN_RTP_EV_MGW_ENDPOINT_ERROR,
 				0);
 }
@@ -174,7 +175,7 @@
 
 	case LCHAN_RTP_EV_MGW_ENDPOINT_AVAILABLE:
 		LOG_LCHAN_RTP(lchan, LOGL_DEBUG, "MGW endpoint: %s\n",
-			      mgwep_ci_name(lchan_use_mgw_endpoint_ci_bts(lchan)));
+			      osmo_mgcpc_ep_ci_name(lchan_use_mgw_endpoint_ci_bts(lchan)));
 		lchan_rtp_fsm_state_chg(LCHAN_RTP_ST_WAIT_LCHAN_READY);
 		return;
 
@@ -328,7 +329,7 @@
 		return;
 	}
 
-	mgw_rtp = mgwep_ci_get_rtp_info(lchan_use_mgw_endpoint_ci_bts(lchan));
+	mgw_rtp = osmo_mgcpc_ep_ci_get_rtp_info(lchan_use_mgw_endpoint_ci_bts(lchan));
 
 	if (!mgw_rtp) {
 		lchan_rtp_fail("Cannot send IPACC MDCX to BTS:"
@@ -396,7 +397,7 @@
 }
 
 static void connect_mgw_endpoint_to_lchan(struct osmo_fsm_inst *fi,
-					  struct mgwep_ci *ci,
+					  struct osmo_mgcpc_ep_ci *ci,
 					  struct gsm_lchan *to_lchan)
 {
 	int rc;
@@ -426,8 +427,8 @@
 	}
 
 	LOG_LCHAN_RTP(lchan, LOGL_DEBUG, "Sending BTS side RTP port info %s:%u to MGW %s\n",
-		      mdcx_info.addr, mdcx_info.port, mgwep_ci_name(ci));
-	mgw_endpoint_ci_request(ci, MGCP_VERB_MDCX, &mdcx_info,
+		      mdcx_info.addr, mdcx_info.port, osmo_mgcpc_ep_ci_name(ci));
+	osmo_mgcpc_ep_ci_request(ci, MGCP_VERB_MDCX, &mdcx_info,
 				fi, LCHAN_RTP_EV_MGW_ENDPOINT_CONFIGURED,
 				LCHAN_RTP_EV_MGW_ENDPOINT_ERROR, 0);
 }
@@ -539,7 +540,7 @@
 		LOG_LCHAN_RTP(lchan, LOGL_ERROR,
 			      "Error while connecting the MGW back to the old lchan's RTP port:"
 			      " %s %s\n",
-			      mgwep_ci_name(lchan->mgw_endpoint_ci_bts),
+			      osmo_mgcpc_ep_ci_name(lchan->mgw_endpoint_ci_bts),
 			      gsm_lchan_name(old_lchan));
 		osmo_fsm_inst_term(fi, OSMO_FSM_TERM_ERROR, 0);
 		return;
@@ -575,7 +576,7 @@
 	case LCHAN_RTP_EV_IPACC_MDCX_ACK:
 		LOG_LCHAN_RTP(lchan, LOGL_NOTICE,
 			      "Received MDCX ACK on established lchan's RTP port: %s\n",
-			      mgwep_ci_name(lchan->mgw_endpoint_ci_bts));
+			      osmo_mgcpc_ep_ci_name(lchan->mgw_endpoint_ci_bts));
 		return;
 	default:
 		OSMO_ASSERT(false);
@@ -740,7 +741,7 @@
 {
 	struct gsm_lchan *lchan = lchan_rtp_fi_lchan(fi);
 	if (lchan->mgw_endpoint_ci_bts) {
-		mgw_endpoint_ci_dlcx(lchan->mgw_endpoint_ci_bts);
+		osmo_mgcpc_ep_ci_dlcx(lchan->mgw_endpoint_ci_bts);
 		lchan->mgw_endpoint_ci_bts = NULL;
 	}
 	lchan->fi_rtp = NULL;
@@ -769,3 +770,86 @@
 	.timer_cb = lchan_rtp_fsm_timer_cb,
 	.cleanup = lchan_rtp_fsm_cleanup,
 };
+
+/* Depending on the channel mode and rate, return the codec type that is signalled towards the MGW. */
+static enum mgcp_codecs chan_mode_to_mgcp_codec(enum gsm48_chan_mode chan_mode, bool full_rate)
+{
+	switch (chan_mode) {
+	case GSM48_CMODE_SPEECH_V1:
+		if (full_rate)
+			return CODEC_GSM_8000_1;
+		return CODEC_GSMHR_8000_1;
+
+	case GSM48_CMODE_SPEECH_EFR:
+		return CODEC_GSMEFR_8000_1;
+
+	case GSM48_CMODE_SPEECH_AMR:
+		return CODEC_AMR_8000_1;
+
+	default:
+		return -1;
+	}
+}
+
+static int chan_mode_to_mgcp_bss_pt(enum mgcp_codecs codec)
+{
+	switch (codec) {
+	case CODEC_GSMHR_8000_1:
+		return RTP_PT_GSM_HALF;
+
+	case CODEC_GSMEFR_8000_1:
+		return RTP_PT_GSM_EFR;
+
+	case CODEC_AMR_8000_1:
+		return RTP_PT_AMR;
+
+	default:
+		/* Not an error, we just leave it to libosmo-mgcp-client to
+		 * decide over the PT. */
+		return -1;
+	}
+}
+
+void mgcp_pick_codec(struct mgcp_conn_peer *verb_info, const struct gsm_lchan *lchan, bool bss_side)
+{
+	enum mgcp_codecs codec = chan_mode_to_mgcp_codec(lchan->tch_mode,
+							 lchan->type == GSM_LCHAN_TCH_H? false : true);
+	int custom_pt;
+
+	if (codec < 0) {
+		LOG_LCHAN(lchan, LOGL_ERROR,
+			  "Unable to determine MGCP codec type for %s in chan-mode %s\n",
+			  gsm_lchant_name(lchan->type), gsm48_chan_mode_name(lchan->tch_mode));
+		verb_info->codecs_len = 0;
+		return;
+	}
+
+	verb_info->codecs[0] = codec;
+	verb_info->codecs_len = 1;
+
+	/* Setup custom payload types (only for BSS side and when required) */
+	custom_pt = chan_mode_to_mgcp_bss_pt(codec);
+	if (bss_side && custom_pt > 0) {
+		verb_info->ptmap[0].codec = codec;
+	        verb_info->ptmap[0].pt = custom_pt;
+	        verb_info->ptmap_len = 1;
+	}
+
+	/* AMR requires additional parameters to be set up (framing mode) */
+	if (verb_info->codecs[0] == CODEC_AMR_8000_1) {
+		verb_info->param_present = true;
+		verb_info->param.amr_octet_aligned_present = true;
+	}
+
+	if (bss_side && verb_info->codecs[0] == CODEC_AMR_8000_1) {
+		/* FIXME: At the moment all BTSs we support are using the
+		 * octet-aligned payload format. However, in the future
+		 * we may support BTSs that are using bandwith-efficient
+		 * format. In this case we will have to add functionality
+		 * that distinguishes by the BTS model which mode to use. */
+		verb_info->param.amr_octet_aligned = true;
+	}
+	else if (!bss_side && verb_info->codecs[0] == CODEC_AMR_8000_1) {
+		verb_info->param.amr_octet_aligned = lchan->conn->sccp.msc->amr_octet_aligned;
+	}
+}
diff --git a/src/osmo-bsc/mgw_endpoint_fsm.c b/src/osmo-bsc/mgw_endpoint_fsm.c
deleted file mode 100644
index fa65166..0000000
--- a/src/osmo-bsc/mgw_endpoint_fsm.c
+++ /dev/null
@@ -1,795 +0,0 @@
-/* osmo-bsc API to manage all sides of an MGW endpoint
- *
- * (C) 2018 by sysmocom - s.f.m.c. GmbH <info at sysmocom.de>
- * All Rights Reserved
- *
- * Author: Neels Hofmeyr <neels at hofmeyr.de>
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as published by
- * the Free Software Foundation; either version 3 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program.  If not, see <http://www.gnu.org/licenses/>.
- *
- */
-
-#include <sys/socket.h>
-#include <netinet/in.h>
-#include <arpa/inet.h>
-
-#include <osmocom/core/fsm.h>
-#include <osmocom/core/byteswap.h>
-#include <osmocom/netif/rtp.h>
-
-#include <osmocom/bsc/debug.h>
-
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
-#include <osmocom/bsc/lchan_fsm.h>
-#include <osmocom/bsc/gsm_data.h>
-#include <osmocom/bsc/bsc_msc_data.h>
-
-#define LOG_CI(ci, level, fmt, args...) do { \
-	if (!ci || !ci->mgwep) \
-		LOGP(DLGLOBAL, level, "(unknown MGW endpoint) " fmt, ## args); \
-	else \
-		LOG_MGWEP(ci->mgwep, level, "CI[%d] %s%s%s: " fmt, \
-			(int)(ci - ci->mgwep->ci), \
-			ci->label ? : "-", \
-			ci->mgcp_ci_str[0] ? " CI=" : "", \
-			ci->mgcp_ci_str[0] ? ci->mgcp_ci_str : "", \
-			## args); \
-	} while(0)
-
-#define LOG_CI_VERB(ci, level, fmt, args...) do { \
-	if (ci->verb_info.addr) \
-		LOG_CI(ci, level, "%s %s:%u: " fmt, \
-			mgcp_verb_name(ci->verb), ci->verb_info.addr, ci->verb_info.port, \
-			## args); \
-	else \
-		LOG_CI(ci, level, "%s: " fmt, \
-			mgcp_verb_name(ci->verb), \
-			## args); \
-	} while(0)
-
-#define FIRST_CI_EVENT (_MGWEP_EV_LAST + (_MGWEP_EV_LAST & 1)) /* rounded up to even nr */
-#define USABLE_CI ((32 - FIRST_CI_EVENT)/2)
-#define EV_TO_CI_IDX(event) ((event - FIRST_CI_EVENT) / 2)
-
-#define CI_EV_SUCCESS(ci) (FIRST_CI_EVENT + (((ci) - ci->mgwep->ci) * 2))
-#define CI_EV_FAILURE(ci) (CI_EV_SUCCESS(ci) + 1)
-
-static struct osmo_fsm mgwep_fsm;
-
-struct mgwep_ci {
-	struct mgw_endpoint *mgwep;
-
-	bool occupied;
-	char label[64];
-	struct osmo_fsm_inst *mgcp_client_fi;
-
-	bool pending;
-	bool sent;
-	enum mgcp_verb verb;
-	struct mgcp_conn_peer verb_info;
-	struct osmo_fsm_inst *notify;
-	uint32_t notify_success;
-	uint32_t notify_failure;
-	void *notify_data;
-
-	bool got_port_info;
-	struct mgcp_conn_peer rtp_info;
-	char mgcp_ci_str[MGCP_CONN_ID_LENGTH];
-};
-
-struct mgw_endpoint {
-	struct mgcp_client *mgcp_client;
-	struct osmo_fsm_inst *fi;
-	char endpoint[MGCP_ENDPOINT_MAXLEN];
-
-	struct mgwep_ci ci[USABLE_CI];
-};
-
-static const struct value_string mgcp_verb_names[] = {
-	{ MGCP_VERB_CRCX, "CRCX" },
-	{ MGCP_VERB_MDCX, "MDCX" },
-	{ MGCP_VERB_DLCX, "DLCX" },
-	{ MGCP_VERB_AUEP, "AUEP" },
-	{ MGCP_VERB_RSIP, "RSIP" },
-	{}
-};
-
-static inline const char *mgcp_verb_name(enum mgcp_verb val)
-{ return get_value_string(mgcp_verb_names, val); }
-
-static struct mgwep_ci *mgwep_check_ci(struct mgwep_ci *ci)
-{
-	if (!ci)
-		return NULL;
-	if (!ci->mgwep)
-		return NULL;
-	if (ci < ci->mgwep->ci || ci >= &ci->mgwep->ci[USABLE_CI])
-		return NULL;
-	return ci;
-}
-
-static struct mgwep_ci *mgwep_ci_for_event(struct mgw_endpoint *mgwep, uint32_t event)
-{
-	int idx;
-	if (event < FIRST_CI_EVENT)
-		return NULL;
-	idx = EV_TO_CI_IDX(event);
-	if (idx >= sizeof(mgwep->ci))
-		return NULL;
-	return mgwep_check_ci(&mgwep->ci[idx]);
-}
-
-const char *mgw_endpoint_name(const struct mgw_endpoint *mgwep)
-{
-	if (!mgwep)
-		return "NULL";
-	if (mgwep->endpoint[0])
-		return mgwep->endpoint;
-	return osmo_fsm_inst_name(mgwep->fi);
-}
-
-const char *mgcp_conn_peer_name(const struct mgcp_conn_peer *info)
-{
-	/* I'd be fine with a smaller buffer and accept truncation, but gcc possibly refuses to build if
-	 * this buffer is too small. */
-	static char buf[1024];
-
-	if (!info)
-		return "NULL";
-
-	if (info->endpoint[0]
-	    && info->addr[0])
-		snprintf(buf, sizeof(buf), "%s:%s:%u",
-			 info->endpoint, info->addr, info->port);
-	else if (info->endpoint[0])
-		snprintf(buf, sizeof(buf), "%s", info->endpoint);
-	else if (info->addr[0])
-		snprintf(buf, sizeof(buf), "%s:%u", info->addr, info->port);
-	else
-		return "empty";
-	return buf;
-}
-
-const char *mgwep_ci_name(const struct mgwep_ci *ci)
-{
-	const struct mgcp_conn_peer *rtp_info;
-
-	if (!ci)
-		return "NULL";
-
-	rtp_info = mgwep_ci_get_rtp_info(ci);
-
-	if (rtp_info)
-		return mgcp_conn_peer_name(rtp_info);
-	return mgw_endpoint_name(ci->mgwep);
-}
-
-static struct value_string mgwep_fsm_event_names[33] = {};
-
-static char mgwep_fsm_event_name_bufs[32][32] = {};
-
-static void fill_event_names()
-{
-	int i;
-	for (i = 0; i < (ARRAY_SIZE(mgwep_fsm_event_names) - 1); i++) {
-		if (i < _MGWEP_EV_LAST)
-			continue;
-		if (i < FIRST_CI_EVENT || EV_TO_CI_IDX(i) > USABLE_CI) {
-			mgwep_fsm_event_names[i] = (struct value_string){i, "Unused"};
-			continue;
-		}
-		snprintf(mgwep_fsm_event_name_bufs[i], sizeof(mgwep_fsm_event_name_bufs[i]),
-			 "MGW Response for CI #%d", EV_TO_CI_IDX(i));
-		mgwep_fsm_event_names[i] = (struct value_string){i, mgwep_fsm_event_name_bufs[i]};
-	}
-}
-
-static struct osmo_tdef *g_T_defs = NULL;
-
-void mgw_endpoint_fsm_init(struct osmo_tdef *T_defs)
-{
-	g_T_defs = T_defs;
-	OSMO_ASSERT(osmo_fsm_register(&mgwep_fsm) == 0);
-	fill_event_names();
-}
-
-struct mgw_endpoint *mgwep_fi_mgwep(struct osmo_fsm_inst *fi)
-{
-	OSMO_ASSERT(fi);
-	OSMO_ASSERT(fi->fsm == &mgwep_fsm);
-	OSMO_ASSERT(fi->priv);
-	return fi->priv;
-}
-
-struct mgw_endpoint *mgw_endpoint_alloc(struct osmo_fsm_inst *parent, uint32_t parent_term_event,
-					struct mgcp_client *mgcp_client,
-					const char *fsm_id,
-					const char *endpoint_str_fmt, ...)
-{
-	va_list ap;
-	struct osmo_fsm_inst *fi;
-	struct mgw_endpoint *mgwep;
-	int rc;
-
-	if (!mgcp_client)
-		return NULL;
-
-	/* use mgcp_client as talloc ctx, so that the conn, lchan, ts can deallocate while MGCP DLCX are
-	 * still going on. */
-	fi = osmo_fsm_inst_alloc_child(&mgwep_fsm, parent, parent_term_event);
-	OSMO_ASSERT(fi);
-
-	osmo_fsm_inst_update_id(fi, fsm_id);
-
-	mgwep = talloc_zero(fi, struct mgw_endpoint);
-	OSMO_ASSERT(mgwep);
-
-	mgwep->mgcp_client = mgcp_client;
-	mgwep->fi = fi;
-	mgwep->fi->priv = mgwep;
-
-	va_start(ap, endpoint_str_fmt);
-	rc = vsnprintf(mgwep->endpoint, sizeof(mgwep->endpoint), endpoint_str_fmt, ap);
-	va_end(ap);
-
-	if (rc <= 0 || rc >= sizeof(mgwep->endpoint)) {
-		LOG_MGWEP(mgwep, LOGL_ERROR, "Endpoint name too long or too short: %s\n",
-			  mgwep->endpoint);
-		osmo_fsm_inst_term(mgwep->fi, OSMO_FSM_TERM_ERROR, 0);
-		return NULL;
-	}
-
-	return mgwep;
-}
-
-struct mgwep_ci *mgw_endpoint_ci_add(struct mgw_endpoint *mgwep,
-				     const char *label_fmt, ...)
-{
-	va_list ap;
-	int i;
-	struct mgwep_ci *ci;
-
-	for (i = 0; i < USABLE_CI; i++) {
-		ci = &mgwep->ci[i];
-
-		if (ci->occupied || ci->mgcp_client_fi)
-			continue;
-
-		*ci = (struct mgwep_ci){
-			.mgwep = mgwep,
-			.occupied = true,
-		};
-		if (label_fmt) {
-			va_start(ap, label_fmt);
-			vsnprintf(ci->label, sizeof(ci->label), label_fmt, ap);
-			va_end(ap);
-		}
-		return ci;
-	}
-
-	LOG_MGWEP(mgwep, LOGL_ERROR,
-		  "Cannot allocate another endpoint, all "
-		  OSMO_STRINGIFY_VAL(USABLE_CI) " are in use\n");
-
-	return NULL;
-}
-
-static void mgwep_fsm_check_state_chg_after_response(struct osmo_fsm_inst *fi);
-
-static void on_failure(struct mgwep_ci *ci)
-{
-	if (!ci->occupied)
-		return;
-
-	if (ci->notify)
-		osmo_fsm_inst_dispatch(ci->notify, ci->notify_failure, ci->notify_data);
-
-	*ci = (struct mgwep_ci){
-		.mgwep = ci->mgwep,
-	};
-
-
-	mgwep_fsm_check_state_chg_after_response(ci->mgwep->fi);
-}
-
-static void on_success(struct mgwep_ci *ci, void *data)
-{
-	struct mgcp_conn_peer *rtp_info;
-
-	if (!ci->occupied)
-		return;
-
-	ci->pending = false;
-
-	switch (ci->verb) {
-	case MGCP_VERB_CRCX:
-		/* If we sent a wildcarded endpoint name on CRCX, we need to store the resulting endpoint
-		 * name here. Also, we receive the MGW's RTP port information. */
-		rtp_info = data;
-		OSMO_ASSERT(rtp_info);
-		ci->got_port_info = true;
-		ci->rtp_info = *rtp_info;
-		osmo_strlcpy(ci->mgcp_ci_str, mgcp_conn_get_ci(ci->mgcp_client_fi),
-			sizeof(ci->mgcp_ci_str));
-		if (rtp_info->endpoint[0]) {
-			int rc;
-			rc = osmo_strlcpy(ci->mgwep->endpoint, rtp_info->endpoint,
-					  sizeof(ci->mgwep->endpoint));
-			if (rc <= 0 || rc >= sizeof(ci->mgwep->endpoint)) {
-				LOG_CI(ci, LOGL_ERROR, "Unable to copy endpoint name '%s'\n",
-				       rtp_info->endpoint);
-				mgw_endpoint_ci_dlcx(ci);
-				on_failure(ci);
-				return;
-			}
-		}
-		break;
-
-	default:
-		break;
-	}
-
-	LOG_CI(ci, LOGL_DEBUG, "received successful response to %s RTP=%s%s\n",
-	       mgcp_verb_name(ci->verb),
-	       mgcp_conn_peer_name(ci->got_port_info? &ci->rtp_info : NULL),
-	       ci->notify ? "" : " (not sending a notification)");
-
-	if (ci->notify)
-		osmo_fsm_inst_dispatch(ci->notify, ci->notify_success, ci->notify_data);
-
-	mgwep_fsm_check_state_chg_after_response(ci->mgwep->fi);
-}
-
-const struct mgcp_conn_peer *mgwep_ci_get_rtp_info(const struct mgwep_ci *ci)
-{
-	ci = mgwep_check_ci((struct mgwep_ci*)ci);
-	if (!ci)
-		return NULL;
-	if (!ci->got_port_info)
-		return NULL;
-	return &ci->rtp_info;
-}
-
-bool mgwep_ci_get_crcx_info_to_sockaddr(const struct mgwep_ci *ci, struct sockaddr_storage *dest)
-{
-	const struct mgcp_conn_peer *rtp_info;
-	struct sockaddr_in *sin;
-
-	rtp_info = mgwep_ci_get_rtp_info(ci);
-	if (!rtp_info)
-		return false;
-
-        sin = (struct sockaddr_in *)dest;
-
-        sin->sin_family = AF_INET;
-        sin->sin_addr.s_addr = inet_addr(rtp_info->addr);
-        sin->sin_port = osmo_ntohs(rtp_info->port);
-	return true;
-}
-
-
-static const struct osmo_tdef_state_timeout mgwep_fsm_timeouts[32] = {
-	[MGWEP_ST_WAIT_MGW_RESPONSE] = { .T=23042 },
-};
-
-/* Transition to a state, using the T timer defined in assignment_fsm_timeouts.
- * The actual timeout value is in turn obtained from g_T_defs.
- * Assumes local variable fi exists. */
-#define mgwep_fsm_state_chg(state) \
-	osmo_tdef_fsm_inst_state_chg(fi, state, mgwep_fsm_timeouts, g_T_defs, 5)
-
-void mgw_endpoint_ci_request(struct mgwep_ci *ci,
-			     enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
-			     struct osmo_fsm_inst *notify,
-			     uint32_t event_success, uint32_t event_failure,
-			     void *notify_data)
-{
-	struct mgw_endpoint *mgwep;
-	struct osmo_fsm_inst *fi;
-	struct mgwep_ci cleared_ci;
-	ci = mgwep_check_ci(ci);
-
-	if (!ci) {
-		LOGP(DLGLOBAL, LOGL_ERROR, "Invalid MGW endpoint request: no ci\n");
-		goto dispatch_error;
-	}
-	if (!verb_info && verb != MGCP_VERB_DLCX) {
-		LOG_CI(ci, LOGL_ERROR, "Invalid MGW endpoint request: missing verb details for %s\n",
-		       mgcp_verb_name(verb));
-		goto dispatch_error;
-	}
-	if ((verb < 0) || (verb > MGCP_VERB_RSIP)) {
-		LOG_CI(ci, LOGL_ERROR, "Invalid MGW endpoint request: unknown verb: %s\n",
-		       mgcp_verb_name(verb));
-		goto dispatch_error;
-	}
-
-	mgwep = ci->mgwep;
-	fi = mgwep->fi;
-
-	/* Clear volatile state by explicitly keeping those that should remain. Because we can't assign
-	 * the char[] directly, dance through cleared_ci and copy back. */
-	cleared_ci = (struct mgwep_ci){
-		.mgwep = mgwep,
-		.mgcp_client_fi = ci->mgcp_client_fi,
-		.got_port_info = ci->got_port_info,
-		.rtp_info = ci->rtp_info,
-
-		.occupied = true,
-		/* .pending = true follows below */
-		.verb = verb,
-		.notify = notify,
-		.notify_success = event_success,
-		.notify_failure = event_failure,
-		.notify_data = notify_data,
-	};
-	osmo_strlcpy(cleared_ci.label, ci->label, sizeof(cleared_ci.label));
-	osmo_strlcpy(cleared_ci.mgcp_ci_str, ci->mgcp_ci_str, sizeof(cleared_ci.mgcp_ci_str));
-	*ci = cleared_ci;
-
-	LOG_CI_VERB(ci, LOGL_DEBUG, "notify=%s\n", osmo_fsm_inst_name(ci->notify));
-
-	if (verb_info)
-		ci->verb_info = *verb_info;
-
-	if (mgwep->endpoint[0]) {
-		if (ci->verb_info.endpoint[0] && strcmp(ci->verb_info.endpoint, mgwep->endpoint))
-			LOG_CI(ci, LOGL_ERROR,
-			       "Warning: Requested %s on endpoint %s, but this CI is on endpoint %s."
-			       " Using the proper endpoint instead.\n",
-			       mgcp_verb_name(verb), ci->verb_info.endpoint, mgwep->endpoint);
-		osmo_strlcpy(ci->verb_info.endpoint, mgwep->endpoint, sizeof(ci->verb_info.endpoint));
-	}
-
-	switch (ci->verb) {
-	case MGCP_VERB_CRCX:
-		if (ci->mgcp_client_fi) {
-			LOG_CI(ci, LOGL_ERROR, "CRCX can be called only once per MGW endpoint CI\n");
-			on_failure(ci);
-			return;
-		}
-		break;
-
-	case MGCP_VERB_MDCX:
-	case MGCP_VERB_DLCX:
-		if (!ci->mgcp_client_fi) {
-			LOG_CI_VERB(ci, LOGL_ERROR, "The first verb on an unused MGW endpoint CI must be CRCX, not %s\n",
-				    mgcp_verb_name(ci->verb));
-			on_failure(ci);
-			return;
-		}
-		break;
-
-	default:
-		LOG_CI(ci, LOGL_ERROR, "This verb is not supported: %s\n", mgcp_verb_name(ci->verb));
-		on_failure(ci);
-		return;
-	}
-
-	ci->pending = true;
-
-	LOG_CI_VERB(ci, LOGL_DEBUG, "Scheduling\n");
-
-	if (mgwep->fi->state != MGWEP_ST_WAIT_MGW_RESPONSE)
-		mgwep_fsm_state_chg(MGWEP_ST_WAIT_MGW_RESPONSE);
-
-	return;
-dispatch_error:
-	if (notify)
-		osmo_fsm_inst_dispatch(notify, event_failure, notify_data);
-}
-
-static int send_verb(struct mgwep_ci *ci)
-{
-	int rc;
-	struct mgw_endpoint *mgwep = ci->mgwep;
-
-	if (!ci->occupied || !ci->pending || ci->sent)
-		return 0;
-
-	switch (ci->verb) {
-
-	case MGCP_VERB_CRCX:
-		OSMO_ASSERT(!ci->mgcp_client_fi);
-		LOG_CI_VERB(ci, LOGL_DEBUG, "Sending\n");
-		ci->mgcp_client_fi = mgcp_conn_create(mgwep->mgcp_client, mgwep->fi,
-						      CI_EV_FAILURE(ci), CI_EV_SUCCESS(ci),
-						      &ci->verb_info);
-		ci->sent = true;
-		if (!ci->mgcp_client_fi){
-			LOG_CI_VERB(ci, LOGL_ERROR, "Cannot send\n");
-			on_failure(ci);
-		}
-		osmo_fsm_inst_update_id(ci->mgcp_client_fi, ci->label);
-		break;
-
-	case MGCP_VERB_MDCX:
-		OSMO_ASSERT(ci->mgcp_client_fi);
-		LOG_CI_VERB(ci, LOGL_DEBUG, "Sending\n");
-		rc = mgcp_conn_modify(ci->mgcp_client_fi, CI_EV_SUCCESS(ci), &ci->verb_info);
-		ci->sent = true;
-		if (rc) {
-			LOG_CI_VERB(ci, LOGL_ERROR, "Cannot send (rc=%d %s)\n", rc, strerror(-rc));
-			on_failure(ci);
-		}
-		break;
-
-	case MGCP_VERB_DLCX:
-		LOG_CI(ci, LOGL_DEBUG, "Sending MGCP: %s %s\n",
-		       mgcp_verb_name(ci->verb), ci->mgcp_ci_str);
-		/* The way this is designed, we actually need to forget all about the ci right away. */
-		mgcp_conn_delete(ci->mgcp_client_fi);
-		if (ci->notify)
-			osmo_fsm_inst_dispatch(ci->notify, ci->notify_success, ci->notify_data);
-		*ci = (struct mgwep_ci){
-			.mgwep = mgwep,
-		};
-		break;
-
-	default:
-		OSMO_ASSERT(false);
-	}
-
-	return 1;
-}
-
-void mgw_endpoint_clear(struct mgw_endpoint *mgwep)
-{
-	if (!mgwep)
-		return;
-	osmo_fsm_inst_term(mgwep->fi, OSMO_FSM_TERM_REGULAR, 0);
-}
-
-static void mgwep_count(struct mgw_endpoint *mgwep, int *occupied, int *pending_not_sent,
-			int *waiting_for_response)
-{
-	int i;
-
-	if (occupied)
-		*occupied = 0;
-
-	if (pending_not_sent)
-		*pending_not_sent = 0;
-
-	if (waiting_for_response)
-		*waiting_for_response = 0;
-
-	for (i = 0; i < ARRAY_SIZE(mgwep->ci); i++) {
-		struct mgwep_ci *ci = &mgwep->ci[i];
-		if (ci->occupied) {
-			if (occupied)
-				(*occupied)++;
-		} else
-			continue;
-
-		if (ci->pending)
-			LOG_CI_VERB(ci, LOGL_DEBUG, "%s\n",
-				    ci->sent ? "waiting for response" : "waiting to be sent");
-		else
-			LOG_CI_VERB(ci, LOGL_DEBUG, "%s\n", mgcp_conn_peer_name(mgwep_ci_get_rtp_info(ci)));
-
-		if (ci->pending && ci->sent)
-			if (waiting_for_response)
-				(*waiting_for_response)++;
-		if (ci->pending && !ci->sent)
-			if (pending_not_sent)
-				(*pending_not_sent)++;
-	}
-}
-
-static void mgwep_fsm_check_state_chg_after_response(struct osmo_fsm_inst *fi)
-{
-	int waiting_for_response;
-	int occupied;
-	struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
-
-	mgwep_count(mgwep, &occupied, NULL, &waiting_for_response);
-	LOG_MGWEP(mgwep, LOGL_DEBUG, "CI in use: %d, waiting for response: %d\n", occupied, waiting_for_response);
-
-	if (!occupied)  {
-		/* All CI have been released. The endpoint no longer exists. Notify the parent FSM, by
-		 * terminating. */
-		osmo_fsm_inst_term(fi, OSMO_FSM_TERM_REGULAR, 0);
-		return;
-	}
-
-	if (!waiting_for_response) {
-		if (fi->state != MGWEP_ST_IN_USE)
-			mgwep_fsm_state_chg(MGWEP_ST_IN_USE);
-		return;
-	}
-
-}
-
-static void mgwep_fsm_wait_mgw_response_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
-{
-	int count = 0;
-	int i;
-	struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
-
-	for (i = 0; i < ARRAY_SIZE(mgwep->ci); i++) {
-		count += send_verb(&mgwep->ci[i]);
-	}
-
-	LOG_MGWEP(mgwep, LOGL_DEBUG, "Sent messages: %d\n", count);
-	mgwep_fsm_check_state_chg_after_response(fi);
-
-}
-
-static void mgwep_fsm_handle_ci_events(struct osmo_fsm_inst *fi, uint32_t event, void *data)
-{
-	struct mgwep_ci *ci;
-	struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
-	ci = mgwep_ci_for_event(mgwep, event);
-	if (ci) {
-		if (event == CI_EV_SUCCESS(ci))
-			on_success(ci, data);
-		else
-			on_failure(ci);
-	}
-}
-
-static void mgwep_fsm_in_use_onenter(struct osmo_fsm_inst *fi, uint32_t prev_state)
-{
-	int pending_not_sent;
-	struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
-
-	mgwep_count(mgwep, NULL, &pending_not_sent, NULL);
-	if (pending_not_sent)
-		mgwep_fsm_state_chg(MGWEP_ST_WAIT_MGW_RESPONSE);
-}
-
-#define S(x)	(1 << (x))
-
-static const struct osmo_fsm_state mgwep_fsm_states[] = {
-	[MGWEP_ST_UNUSED] = {
-		.name = "UNUSED",
-		.in_event_mask = 0,
-		.out_state_mask = 0
-			| S(MGWEP_ST_WAIT_MGW_RESPONSE)
-			,
-	},
-	[MGWEP_ST_WAIT_MGW_RESPONSE] = {
-		.name = "WAIT_MGW_RESPONSE",
-		.onenter = mgwep_fsm_wait_mgw_response_onenter,
-		.action = mgwep_fsm_handle_ci_events,
-		.in_event_mask = 0xffffffff,
-		.out_state_mask = 0
-			| S(MGWEP_ST_IN_USE)
-			,
-	},
-	[MGWEP_ST_IN_USE] = {
-		.name = "IN_USE",
-		.onenter = mgwep_fsm_in_use_onenter,
-		.action = mgwep_fsm_handle_ci_events,
-		.in_event_mask = 0xffffffff, /* mgcp_client_fsm may send parent term anytime */
-		.out_state_mask = 0
-			| S(MGWEP_ST_WAIT_MGW_RESPONSE)
-			,
-	},
-};
-
-static int mgwep_fsm_timer_cb(struct osmo_fsm_inst *fi)
-{
-	int i;
-	struct mgw_endpoint *mgwep = mgwep_fi_mgwep(fi);
-
-	switch (fi->T) {
-	default:
-		for (i = 0; i < ARRAY_SIZE(mgwep->ci); i++) {
-			struct mgwep_ci *ci = &mgwep->ci[i];
-			if (!ci->occupied)
-				continue;
-			if (!(ci->pending && ci->sent))
-				continue;
-			on_failure(ci);
-		}
-		return 0;
-	}
-
-	return 0;
-}
-
-static struct osmo_fsm mgwep_fsm = {
-	.name = "mgw-endpoint",
-	.states = mgwep_fsm_states,
-	.num_states = ARRAY_SIZE(mgwep_fsm_states),
-	.log_subsys = DRSL,
-	.event_names = mgwep_fsm_event_names,
-	.timer_cb = mgwep_fsm_timer_cb,
-	/* The FSM termination will automatically trigger any mgcp_client_fsm instances to DLCX. */
-};
-
-/* Depending on the channel mode and rate, return the codec type that is signalled towards the MGW. */
-enum mgcp_codecs chan_mode_to_mgcp_codec(enum gsm48_chan_mode chan_mode, bool full_rate)
-{
-	switch (chan_mode) {
-	case GSM48_CMODE_SPEECH_V1:
-		if (full_rate)
-			return CODEC_GSM_8000_1;
-		return CODEC_GSMHR_8000_1;
-
-	case GSM48_CMODE_SPEECH_EFR:
-		return CODEC_GSMEFR_8000_1;
-
-	case GSM48_CMODE_SPEECH_AMR:
-		return CODEC_AMR_8000_1;
-
-	default:
-		return -1;
-	}
-}
-
-int chan_mode_to_mgcp_bss_pt(enum mgcp_codecs codec)
-{
-	switch (codec) {
-	case CODEC_GSMHR_8000_1:
-		return RTP_PT_GSM_HALF;
-
-	case CODEC_GSMEFR_8000_1:
-		return RTP_PT_GSM_EFR;
-
-	case CODEC_AMR_8000_1:
-		return RTP_PT_AMR;
-
-	default:
-		/* Not an error, we just leave it to libosmo-mgcp-client to
-		 * decide over the PT. */
-		return -1;
-	}
-}
-
-void mgcp_pick_codec(struct mgcp_conn_peer *verb_info, const struct gsm_lchan *lchan, bool bss_side)
-{
-	enum mgcp_codecs codec = chan_mode_to_mgcp_codec(lchan->tch_mode,
-							 lchan->type == GSM_LCHAN_TCH_H? false : true);
-	int custom_pt;
-
-	if (codec < 0) {
-		LOG_LCHAN(lchan, LOGL_ERROR,
-			  "Unable to determine MGCP codec type for %s in chan-mode %s\n",
-			  gsm_lchant_name(lchan->type), gsm48_chan_mode_name(lchan->tch_mode));
-		verb_info->codecs_len = 0;
-		return;
-	}
-
-	verb_info->codecs[0] = codec;
-	verb_info->codecs_len = 1;
-
-	/* Setup custom payload types (only for BSS side and when required) */
-	custom_pt = chan_mode_to_mgcp_bss_pt(codec);
-	if (bss_side && custom_pt > 0) {
-		verb_info->ptmap[0].codec = codec;
-	        verb_info->ptmap[0].pt = custom_pt;
-	        verb_info->ptmap_len = 1;
-	}
-
-	/* AMR requires additional parameters to be set up (framing mode) */
-	if (verb_info->codecs[0] == CODEC_AMR_8000_1) {
-		verb_info->param_present = true;
-		verb_info->param.amr_octet_aligned_present = true;
-	}
-
-	if (bss_side && verb_info->codecs[0] == CODEC_AMR_8000_1) {
-		/* FIXME: At the moment all BTSs we support are using the
-		 * octet-aligned payload format. However, in the future
-		 * we may support BTSs that are using bandwith-efficient
-		 * format. In this case we will have to add functionality
-		 * that distinguishes by the BTS model which mode to use. */
-		verb_info->param.amr_octet_aligned = true;
-	}
-	else if (!bss_side && verb_info->codecs[0] == CODEC_AMR_8000_1) {
-		verb_info->param.amr_octet_aligned = lchan->conn->sccp.msc->amr_octet_aligned;
-	}
-}
diff --git a/src/osmo-bsc/net_init.c b/src/osmo-bsc/net_init.c
index c2a38bc..1ef9bd5 100644
--- a/src/osmo-bsc/net_init.c
+++ b/src/osmo-bsc/net_init.c
@@ -51,6 +51,12 @@
 	{}
 };
 
+struct osmo_tdef g_mgw_tdefs[] = {
+	{ .T=-1, .default_val=4, .desc="MGCP response timeout" },
+	{ .T=-2, .default_val=30, .desc="RTP stream establishing timeout" },
+	{}
+};
+
 /* Initialize the bare minimum of struct gsm_network, minimizing required dependencies.
  * This part is shared among the thin programs in osmo-bsc/src/utils/.
  * osmo-bsc requires further initialization that pulls in more dependencies (see bsc_network_init()). */
@@ -81,5 +87,8 @@
 	net->T_defs = gsm_network_T_defs;
 	osmo_tdefs_reset(net->T_defs);
 
+	net->mgw.tdefs = g_mgw_tdefs;
+	osmo_tdefs_reset(net->mgw.tdefs);
+
 	return net;
 }
diff --git a/src/osmo-bsc/osmo_bsc_bssap.c b/src/osmo-bsc/osmo_bsc_bssap.c
index 65618fd..2d5d4ae 100644
--- a/src/osmo-bsc/osmo_bsc_bssap.c
+++ b/src/osmo-bsc/osmo_bsc_bssap.c
@@ -19,7 +19,8 @@
  *
  */
 
-#include <osmocom/mgcp_client/mgcp_client_fsm.h>
+#include <osmocom/core/sockaddr_str.h>
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
 
 #include <osmocom/bsc/osmo_bsc.h>
 #include <osmocom/bsc/osmo_bsc_grace.h>
diff --git a/src/osmo-bsc/osmo_bsc_lcls.c b/src/osmo-bsc/osmo_bsc_lcls.c
index 98c74c7..a01c02e 100644
--- a/src/osmo-bsc/osmo_bsc_lcls.c
+++ b/src/osmo-bsc/osmo_bsc_lcls.c
@@ -29,8 +29,8 @@
 #include <osmocom/bsc/bsc_subscr_conn_fsm.h>
 #include <osmocom/bsc/gsm_data.h>
 #include <osmocom/bsc/osmo_bsc_lcls.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
-#include <osmocom/mgcp_client/mgcp_client_fsm.h>
+#include <osmocom/bsc/lchan_rtp_fsm.h>
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
 
 struct value_string lcls_event_names[] = {
 	{ LCLS_EV_UPDATE_CFG_CSC,	"UPDATE_CFG_CSC" },
@@ -277,7 +277,7 @@
 {
 	mgcp_pick_codec(mdcx_info, conn->lchan, false);
 
-	mgw_endpoint_ci_request(conn->user_plane.mgw_endpoint_ci_msc, MGCP_VERB_MDCX, mdcx_info,
+	osmo_mgcpc_ep_ci_request(conn->user_plane.mgw_endpoint_ci_msc, MGCP_VERB_MDCX, mdcx_info,
 				NULL, 0, 0, NULL);
 }
 
@@ -647,7 +647,7 @@
 		return;
 	}
 
-	other_mgw_info = mgwep_ci_get_rtp_info(conn_other->user_plane.mgw_endpoint_ci_msc);
+	other_mgw_info = osmo_mgcpc_ep_ci_get_rtp_info(conn_other->user_plane.mgw_endpoint_ci_msc);
 	if (!other_mgw_info) {
 		LOGPFSML(fi, LOGL_ERROR, "Cannot enable LCLS without RTP port info of MSC-side"
 			 " -- missing CRCX?\n");
diff --git a/src/osmo-bsc/osmo_bsc_main.c b/src/osmo-bsc/osmo_bsc_main.c
index 08bb40d..0e0e8ca 100644
--- a/src/osmo-bsc/osmo_bsc_main.c
+++ b/src/osmo-bsc/osmo_bsc_main.c
@@ -33,7 +33,6 @@
 #include <osmocom/bsc/handover_decision_2.h>
 #include <osmocom/bsc/timeslot_fsm.h>
 #include <osmocom/bsc/lchan_fsm.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
 #include <osmocom/bsc/bsc_subscr_conn_fsm.h>
 #include <osmocom/bsc/bsc_subscriber.h>
 #include <osmocom/bsc/assignment_fsm.h>
@@ -54,6 +53,8 @@
 #include <osmocom/vty/logging.h>
 #include <osmocom/vty/command.h>
 
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
+
 #include <osmocom/abis/abis.h>
 #include <osmocom/bsc/abis_om2000.h>
 #include <osmocom/bsc/abis_nm.h>
@@ -849,7 +850,6 @@
 	lchan_fsm_init();
 	bsc_subscr_conn_fsm_init();
 	assignment_fsm_init();
-	mgw_endpoint_fsm_init(bsc_gsmnet->T_defs);
 	handover_fsm_init();
 
 	/* Read the config */
diff --git a/tests/handover/Makefile.am b/tests/handover/Makefile.am
index 40ecf54..56aea50 100644
--- a/tests/handover/Makefile.am
+++ b/tests/handover/Makefile.am
@@ -34,7 +34,7 @@
 
 handover_test_LDFLAGS = \
 	-Wl,--wrap=abis_rsl_sendmsg \
-	-Wl,--wrap=mgw_endpoint_ci_request \
+	-Wl,--wrap=osmo_mgcpc_ep_ci_request \
 	$(NULL)
 
 handover_test_LDADD = \
@@ -64,7 +64,6 @@
 	$(top_builddir)/src/osmo-bsc/lchan_rtp_fsm.o \
 	$(top_builddir)/src/osmo-bsc/lchan_select.o \
 	$(top_builddir)/src/osmo-bsc/meas_rep.o \
-	$(top_builddir)/src/osmo-bsc/mgw_endpoint_fsm.o \
 	$(top_builddir)/src/osmo-bsc/neighbor_ident.o \
 	$(top_builddir)/src/osmo-bsc/net_init.o \
 	$(top_builddir)/src/osmo-bsc/osmo_bsc_lcls.o \
diff --git a/tests/handover/handover_test.c b/tests/handover/handover_test.c
index cd3b749..a8a77be 100644
--- a/tests/handover/handover_test.c
+++ b/tests/handover/handover_test.c
@@ -27,7 +27,7 @@
 #include <osmocom/core/select.h>
 #include <osmocom/core/talloc.h>
 
-#include <osmocom/mgcp_client/mgcp_client_fsm.h>
+#include <osmocom/mgcp_client/mgcp_client_endpoint_fsm.h>
 
 #include <osmocom/bsc/abis_rsl.h>
 #include <osmocom/bsc/debug.h>
@@ -45,7 +45,6 @@
 #include <osmocom/bsc/bsc_subscr_conn_fsm.h>
 #include <osmocom/bsc/timeslot_fsm.h>
 #include <osmocom/bsc/lchan_fsm.h>
-#include <osmocom/bsc/mgw_endpoint_fsm.h>
 #include <osmocom/bsc/handover_fsm.h>
 #include <osmocom/bsc/bsc_msc_data.h>
 
@@ -53,14 +52,14 @@
 
 struct gsm_network *bsc_gsmnet;
 
-/* override, requires '-Wl,--wrap=mgw_endpoint_ci_request'.
+/* override, requires '-Wl,--wrap=osmo_mgcpc_ep_ci_request'.
  * Catch modification of an MGCP connection. */
-void __real_mgw_endpoint_ci_request(struct mgwep_ci *ci,
+void __real_osmo_mgcpc_ep_ci_request(struct osmo_mgcpc_ep_ci *ci,
 				    enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
 				    struct osmo_fsm_inst *notify,
 				    uint32_t event_success, uint32_t event_failure,
 				    void *notify_data);
-void __wrap_mgw_endpoint_ci_request(struct mgwep_ci *ci,
+void __wrap_osmo_mgcpc_ep_ci_request(struct osmo_mgcpc_ep_ci *ci,
 				    enum mgcp_verb verb, const struct mgcp_conn_peer *verb_info,
 				    struct osmo_fsm_inst *notify,
 				    uint32_t event_success, uint32_t event_failure,
@@ -234,9 +233,11 @@
 
 	conn = bsc_subscr_con_allocate(net);
 
-	conn->user_plane.mgw_endpoint = mgw_endpoint_alloc(conn->fi,
+	conn->user_plane.mgw_endpoint = osmo_mgcpc_ep_alloc(conn->fi,
 							   GSCON_EV_FORGET_MGW_ENDPOINT,
-							   fake_mgcp_client, "test",
+							   fake_mgcp_client,
+							   net->mgw.tdefs,
+							   "test",
 							   "fake endpoint");
 	conn->sccp.msc = &fake_msc_data;
 
@@ -1432,7 +1433,6 @@
 
 	ts_fsm_init();
 	lchan_fsm_init();
-	mgw_endpoint_fsm_init(bsc_gsmnet->T_defs);
 	bsc_subscr_conn_fsm_init();
 	handover_fsm_init();
 

-- 
To view, visit https://gerrit.osmocom.org/13796
To unsubscribe, or for help writing mail filters, visit https://gerrit.osmocom.org/settings

Gerrit-Project: osmo-bsc
Gerrit-Branch: master
Gerrit-MessageType: merged
Gerrit-Change-Id: I03e6b48d9b0a5370310d5f56809259ff7909cf9d
Gerrit-Change-Number: 13796
Gerrit-PatchSet: 2
Gerrit-Owner: Neels Hofmeyr <nhofmeyr at sysmocom.de>
Gerrit-Reviewer: Harald Welte <laforge at gnumonks.org>
Gerrit-Reviewer: Jenkins Builder (1000002)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.osmocom.org/pipermail/gerrit-log/attachments/20190430/44ecab55/attachment.htm>


More information about the gerrit-log mailing list