remove code dup: add msc_mgcp_try_call_assignment()

Various places in the code check a flag whether assignment was started and
launch it. To fix incoming-call-during-ongoing-call, I will tweak that logic.
To be able to do that only in one place, remove code dup.

Cosmetic preparation for I1f8746e7babfcd3028a4d2c0ba260c608c686c76 and
I0ba216b737909e92080a722db26e3577726c63cb/

Depends: I11b182a03f5ecb6df7cd8f260757d3626c8e945d (libosmocore: LOGPFSMSL)
Change-Id: I11c0b7dc3f1a747028629b48e522bb3b864884ba
diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c
index 5567da9..be9a451 100644
--- a/src/libmsc/gsm_04_08_cc.c
+++ b/src/libmsc/gsm_04_08_cc.c
@@ -736,12 +736,7 @@
 	new_cc_state(trans, GSM_CSTATE_MO_TERM_CALL_CONF);
 
 	/* Assign call (if not done yet) */
-	if (trans->assignment_done == false) {
-		rc = msc_mgcp_call_assignment(trans);
-		trans->assignment_done = true;
-	}
-	else
-		rc = 0;
+	rc = msc_mgcp_try_call_assignment(trans);
 
 	/* don't continue, if there were problems with
 	 * the call assignment. */
@@ -780,14 +775,7 @@
 		return rc;
 
 	/* Assign call (if not done yet) */
-	if (trans->assignment_done == false) {
-		rc = msc_mgcp_call_assignment(trans);
-		trans->assignment_done = true;
-	}
-	else
-		rc = 0;
-
-	return rc;
+	return msc_mgcp_try_call_assignment(trans);
 }
 
 static int gsm48_cc_rx_alerting(struct gsm_trans *trans, struct msgb *msg)
@@ -1706,7 +1694,6 @@
 static int tch_rtp_create(struct gsm_network *net, uint32_t callref)
 {
 	struct gsm_trans *trans;
-	int rc;
 
 	/* Find callref */
 	trans = trans_find_by_callref(net, callref);
@@ -1737,14 +1724,7 @@
 	trans->tch_rtp_create = true;
 
 	/* Assign call (if not done yet) */
-	if (trans->assignment_done == false) {
-		rc = msc_mgcp_call_assignment(trans);
-		trans->assignment_done = true;
-	}
-	else
-		rc = 0;
-
-	return rc;
+	return msc_mgcp_try_call_assignment(trans);
 }
 
 /* Trigger TCH_RTP_CREATE acknowledgement */
diff --git a/src/libmsc/msc_mgcp.c b/src/libmsc/msc_mgcp.c
index 23e68e7..5a8ee79 100644
--- a/src/libmsc/msc_mgcp.c
+++ b/src/libmsc/msc_mgcp.c
@@ -951,6 +951,22 @@
 	.event_names = msc_mgcp_fsm_evt_names,
 };
 
+/* Try to invoke call assignment and set trans->assignment_done flag if invoked.
+ * This is relevant for already ongoing calls -- scenario:
+ *  - subscriber is in an active voice call,
+ *  - another call is coming in.
+ * For the second call coming in, we must wait to establish RTP and assignment until the first call is CC-Disconnected.
+ */
+int msc_mgcp_try_call_assignment(struct gsm_trans *trans)
+{
+	struct ran_conn *conn = trans->conn;
+	if (trans->assignment_done)
+		return 0;
+	LOGPFSMSL(conn->fi, DMGCP, LOGL_INFO, "Starting call assignment\n");
+	trans->assignment_done = true;
+	return msc_mgcp_call_assignment(trans);
+}
+
 /* Notify that a new call begins. This will create a connection for the
  * RAN and the CN on the MGW.
  * Parameter: