ASCI: Use a unique call-id for RTP streams

The MGCP protocol features the 'C' (call-id) to identify which
connections belong to the same call. They may be used by MGW for
accounting or management procedures.

So far we sent the MNCC callref as call-id. Instead, add a separate
unique call_id number space. Assign a unique call_id to each
transaction.

Change-Id: I36c5f159fa0b54fb576ff8bd279928b895554793
Related: OS#4854
diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c
index 8773db7..0195b0b 100644
--- a/src/libmsc/gsm_04_08_cc.c
+++ b/src/libmsc/gsm_04_08_cc.c
@@ -440,7 +440,7 @@
 	cl1 = trans1->msc_a->cc.call_leg;
 	cl2 = trans2->msc_a->cc.call_leg;
 
-	return call_leg_local_bridge(cl1, trans1->callref, trans1, cl2, trans2->callref, trans2);
+	return call_leg_local_bridge(cl1, trans1->call_id, trans1, cl2, trans2->call_id, trans2);
 }
 
 static int gsm48_cc_rx_status_enq(struct gsm_trans *trans, struct msgb *msg)
diff --git a/src/libmsc/msc_a.c b/src/libmsc/msc_a.c
index 11b242e..b9aaeaa 100644
--- a/src/libmsc/msc_a.c
+++ b/src/libmsc/msc_a.c
@@ -620,7 +620,7 @@
 	 * If no RAN side RTP is established, try to guess a preliminary codec from SDP -- before Assignment, picking a
 	 * codec from the SDP is more politeness/avoiding confusion than necessity. The actual codec to be used would be
 	 * determined later. If no codec could be determined, pass none for the time being. */
-	return call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->callref, cc_trans,
+	return call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->call_id, cc_trans,
 				  rtp_to_ran->codecs_known ? &rtp_to_ran->codecs : NULL, NULL);
 }
 
@@ -690,7 +690,7 @@
 			.osmux_present = msc_a->cc.call_leg->rtp[RTP_TO_RAN]->use_osmux,
 			.osmux_cid = msc_a->cc.call_leg->rtp[RTP_TO_RAN]->local_osmux_cid,
 			.call_id_present = true,
-			.call_id = cc_trans->callref,
+			.call_id = cc_trans->call_id,
 			.lcls = cc_trans->cc.lcls,
 		},
 	};
@@ -1898,7 +1898,7 @@
 	 * osmo_mgcpc_ep_fsm automagically waits for the first CRCX to complete before firing the second CRCX. The one
 	 * issued first here will also be the first CRCX sent to the MGW. Usually both still need to be set up. */
 	if (!cn_rtp_available)
-		call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->callref, cc_trans,
+		call_leg_ensure_ci(cl, RTP_TO_CN, cc_trans->call_id, cc_trans,
 				   &cc_trans->cc.local.audio_codecs, NULL);
 	if (!ran_rtp_available) {
 		struct sdp_audio_codecs *codecs;
@@ -1906,7 +1906,7 @@
 			codecs = &msc_a->c.ran->force_mgw_codecs_to_ran;
 		else
 			codecs = &cc_trans->cc.local.audio_codecs;
-		return call_leg_ensure_ci(cl, RTP_TO_RAN, cc_trans->callref, cc_trans, codecs, NULL);
+		return call_leg_ensure_ci(cl, RTP_TO_RAN, cc_trans->call_id, cc_trans, codecs, NULL);
 	}
 
 	/* Should these already be set up, immediately continue by retriggering the events signalling that the RTP
diff --git a/src/libmsc/msc_ho.c b/src/libmsc/msc_ho.c
index ce3f100..9e4417f 100644
--- a/src/libmsc/msc_ho.c
+++ b/src/libmsc/msc_ho.c
@@ -421,7 +421,7 @@
 		}
 		ran_enc_msg.handover_request.geran.channel_type = &channel_type;
 		ran_enc_msg.handover_request.call_id_present = true;
-		ran_enc_msg.handover_request.call_id = cc_trans->callref;
+		ran_enc_msg.handover_request.call_id = cc_trans->call_id;
 
 		sdp_audio_codecs_to_speech_codec_list(&scl, &cc_trans->cc.local.audio_codecs);
 		if (!scl.len) {
diff --git a/src/libmsc/msc_t.c b/src/libmsc/msc_t.c
index b3429ed..eb6c797 100644
--- a/src/libmsc/msc_t.c
+++ b/src/libmsc/msc_t.c
@@ -160,7 +160,7 @@
 	}
 
 	msc_t->inter_msc.cell_id_target = ran_dec->handover_request.cell_id_target;
-	msc_t->inter_msc.callref = ran_dec->handover_request.call_id;
+	msc_t->inter_msc.call_id = ran_dec->handover_request.call_id;
 
 	/* TODO other parameters...?
 	 * Global Call Reference
@@ -358,8 +358,8 @@
 						   MSC_EV_CALL_LEG_RTP_LOCAL_ADDR_AVAILABLE,
 						   MSC_EV_CALL_LEG_RTP_COMPLETE);
 	if (!msc_t->inter_msc.call_leg
-	    || call_leg_ensure_ci(msc_t->inter_msc.call_leg, RTP_TO_RAN, msc_t->inter_msc.callref, NULL, NULL, NULL)
-	    || call_leg_ensure_ci(msc_t->inter_msc.call_leg, RTP_TO_CN, msc_t->inter_msc.callref, NULL, NULL, NULL)) {
+	    || call_leg_ensure_ci(msc_t->inter_msc.call_leg, RTP_TO_RAN, msc_t->inter_msc.call_id, NULL, NULL, NULL)
+	    || call_leg_ensure_ci(msc_t->inter_msc.call_leg, RTP_TO_CN, msc_t->inter_msc.call_id, NULL, NULL, NULL)) {
 		msc_t_error("Failed to set up call leg\n");
 		return;
 	}
diff --git a/src/libmsc/transaction.c b/src/libmsc/transaction.c
index 6c12409..190da29 100644
--- a/src/libmsc/transaction.c
+++ b/src/libmsc/transaction.c
@@ -181,6 +181,8 @@
 	return get_value_string_or_null(trans_type_names, type) ? : "trans-type-unknown";
 }
 
+static uint32_t new_call_id = 1;
+
 /*! Allocate a new transaction and add it to network list
  *  \param[in] net Netwokr in which we allocate transaction
  *  \param[in] subscr Subscriber for which we allocate transaction
@@ -212,6 +214,7 @@
 		.log_subsys = subsys,
 		.transaction_id = trans_id,
 		.callref = callref,
+		.call_id = new_call_id++,
 		.net = net,
 		/* empty bearer_cap: make sure the speech_ver array is empty */
 		.bearer_cap = {