ASCI: Add transaction type to trans_find_by_callref()

A transaction can be identified by the callref and the type. Because
transactions with different types may share the same callref value,
it is required to include the type in the trans_find_by_callref()
parameters.

E.g. a voice group call may have the same callref as a voice broadcast
call, but they are different calls. They also may not be confused with
other transaction types having eventually equal callref value, like
GSM 04.08 calls, SMS or supplementary services transactions.

By adding the transaction type to trans_find_by_callref(), we
essentially now use the (type, callref) tuple as unique ID for
transactions, instead of just callref.

Change-Id: Ic0b82033a1aa3c3508ad610c690a5f29073006c1
Related: OS#4854, OS#3294
diff --git a/include/osmocom/msc/transaction.h b/include/osmocom/msc/transaction.h
index 63070f7..bc6c316 100644
--- a/include/osmocom/msc/transaction.h
+++ b/include/osmocom/msc/transaction.h
@@ -156,7 +156,7 @@
 struct gsm_trans *trans_find_by_type(const struct msc_a *msc_a, enum trans_type type);
 struct gsm_trans *trans_find_by_id(const struct msc_a *msc_a,
 				   enum trans_type type, uint8_t trans_id);
-struct gsm_trans *trans_find_by_callref(const struct gsm_network *net,
+struct gsm_trans *trans_find_by_callref(const struct gsm_network *net, enum trans_type type,
 					uint32_t callref);
 struct gsm_trans *trans_find_by_sm_rp_mr(const struct gsm_network *net,
 					 const struct vlr_subscr *vsub,
diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c
index 0195b0b..4162944 100644
--- a/src/libmsc/gsm_04_08_cc.c
+++ b/src/libmsc/gsm_04_08_cc.c
@@ -414,8 +414,8 @@
 /* bridge channels of two transactions */
 static int tch_bridge(struct gsm_network *net, const struct gsm_mncc_bridge *bridge)
 {
-	struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[0]);
-	struct gsm_trans *trans2 = trans_find_by_callref(net, bridge->callref[1]);
+	struct gsm_trans *trans1 = trans_find_by_callref(net, TRANS_CC, bridge->callref[0]);
+	struct gsm_trans *trans2 = trans_find_by_callref(net, TRANS_CC, bridge->callref[1]);
 	struct call_leg *cl1;
 	struct call_leg *cl2;
 
@@ -537,8 +537,8 @@
 static inline void disconnect_bridge(struct gsm_network *net,
 				     const struct gsm_mncc_bridge *bridge, int err)
 {
-	struct gsm_trans *trans0 = trans_find_by_callref(net, bridge->callref[0]);
-	struct gsm_trans *trans1 = trans_find_by_callref(net, bridge->callref[1]);
+	struct gsm_trans *trans0 = trans_find_by_callref(net, TRANS_CC, bridge->callref[0]);
+	struct gsm_trans *trans1 = trans_find_by_callref(net, TRANS_CC, bridge->callref[1]);
 	struct gsm_mncc mx_rel;
 	if (!trans0 || !trans1)
 		return;
@@ -1995,7 +1995,7 @@
 	struct gsm_trans *trans;
 
 	/* Find callref */
-	trans = trans_find_by_callref(net, rtp->callref);
+	trans = trans_find_by_callref(net, TRANS_CC, rtp->callref);
 	if (!trans) {
 		LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP create for non-existing trans\n");
 		mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CREATE);
@@ -2120,7 +2120,7 @@
 	struct rtp_stream *rtps;
 
 	/* Find callref */
-	trans = trans_find_by_callref(net, rtp->callref);
+	trans = trans_find_by_callref(net, TRANS_CC, rtp->callref);
 	if (!trans) {
 		LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "RTP connect for non-existing trans\n");
 		mncc_recv_rtp_err(net, trans, rtp->callref, MNCC_RTP_CONNECT);
@@ -2257,7 +2257,7 @@
 	data = &msg->signal;
 
 	/* Find callref */
-	trans = trans_find_by_callref(net, data->callref);
+	trans = trans_find_by_callref(net, TRANS_CC, data->callref);
 
 	/* Callref unknown */
 	if (!trans) {
diff --git a/src/libmsc/gsm_09_11.c b/src/libmsc/gsm_09_11.c
index d94be48..e293890 100644
--- a/src/libmsc/gsm_09_11.c
+++ b/src/libmsc/gsm_09_11.c
@@ -441,7 +441,7 @@
 	log_set_context(LOG_CTX_VLR_SUBSCR, vsub);
 
 	/* Attempt to find DTAP-transaction */
-	trans = trans_find_by_callref(net, gsup_msg->session_id);
+	trans = trans_find_by_callref(net, TRANS_USSD, gsup_msg->session_id);
 
 	/* Handle errors */
 	if (OSMO_GSUP_IS_MSGT_ERROR(gsup_msg->message_type)) {
diff --git a/src/libmsc/transaction.c b/src/libmsc/transaction.c
index 190da29..21f0b8b 100644
--- a/src/libmsc/transaction.c
+++ b/src/libmsc/transaction.c
@@ -73,16 +73,17 @@
 
 /*! Find a transaction by call reference
  * \param[in] net Network in which we should search
+ * \param[in] type Transaction type (e.g. TRANS_CC)
  * \param[in] callref Call Reference of transaction
  * \returns Matching transaction, if any
  */
-struct gsm_trans *trans_find_by_callref(const struct gsm_network *net,
+struct gsm_trans *trans_find_by_callref(const struct gsm_network *net, enum trans_type type,
 					uint32_t callref)
 {
 	struct gsm_trans *trans;
 
 	llist_for_each_entry(trans, &net->trans_list, entry) {
-		if (trans->callref == callref)
+		if (trans->callref == callref && trans->type == type)
 			return trans;
 	}
 	return NULL;