transaction: move cc.codecs.remote -> cc.remote

Move remote out of codecs, as it will be used by CSD code as well.
Otherwise we would need to store it twice (in cc.codecs.remote and
cc.csd.remote).

Related: OS#4394
Change-Id: I5d2e078db3b3437cb6feae40d8955912d7a297e4
diff --git a/include/osmocom/msc/codec_filter.h b/include/osmocom/msc/codec_filter.h
index ca32e3c..c0d8f32 100644
--- a/include/osmocom/msc/codec_filter.h
+++ b/include/osmocom/msc/codec_filter.h
@@ -40,9 +40,6 @@
 	 * Should be ignored if empty. */
 	struct sdp_audio_codecs bss;
 
-	/* SDP as last received from the remote call leg. */
-	struct sdp_msg remote;
-
 	/* After a channel was assigned, this reflects the chosen codec. */
 	struct sdp_audio_codec assignment;
 
@@ -55,10 +52,10 @@
 void codec_filter_set_ran(struct codec_filter *codec_filter, enum osmo_rat_type ran_type);
 void codec_filter_set_bss(struct codec_filter *codec_filter,
 			  const struct gsm0808_speech_codec_list *codec_list_bss_supported);
-int codec_filter_set_remote(struct codec_filter *codec_filter, const char *remote_sdp);
 void codec_filter_set_local_rtp(struct codec_filter *codec_filter, const struct osmo_sockaddr_str *rtp);
-int codec_filter_run(struct codec_filter *codec_filter);
+int codec_filter_run(struct codec_filter *codec_filter, const struct sdp_msg *remote);
 
-int codec_filter_to_str_buf(char *buf, size_t buflen, const struct codec_filter *codec_filter);
-char *codec_filter_to_str_c(void *ctx, const struct codec_filter *codec_filter);
-const char *codec_filter_to_str(const struct codec_filter *codec_filter);
+int codec_filter_to_str_buf(char *buf, size_t buflen, const struct codec_filter *codec_filter,
+			    const struct sdp_msg *remote);
+char *codec_filter_to_str_c(void *ctx, const struct codec_filter *codec_filter, const struct sdp_msg *remote);
+const char *codec_filter_to_str(const struct codec_filter *codec_filter, const struct sdp_msg *remote);
diff --git a/include/osmocom/msc/transaction.h b/include/osmocom/msc/transaction.h
index d886f2a..bfb32ad 100644
--- a/include/osmocom/msc/transaction.h
+++ b/include/osmocom/msc/transaction.h
@@ -105,6 +105,8 @@
 			struct gsm_mncc msg;	/* stores setup/disconnect/release message */
 			bool mncc_initiated;	/* Whether an MNCC Release is necessary on failure */
 			struct osmo_lcls *lcls;
+			/* SDP as last received from the remote call leg. */
+			struct sdp_msg remote;
 			/* Track codec choices from BSS and remote call leg */
 			struct codec_filter codecs;
 		} cc;
diff --git a/src/libmsc/codec_filter.c b/src/libmsc/codec_filter.c
index 99ae7b2..38a1246 100644
--- a/src/libmsc/codec_filter.c
+++ b/src/libmsc/codec_filter.c
@@ -84,11 +84,6 @@
 		sdp_audio_codecs_from_speech_codec_list(&codec_filter->bss, codec_list_bss_supported);
 }
 
-int codec_filter_set_remote(struct codec_filter *codec_filter, const char *remote_sdp)
-{
-	return sdp_msg_from_sdp_str(&codec_filter->remote, remote_sdp);
-}
-
 void codec_filter_set_local_rtp(struct codec_filter *codec_filter, const struct osmo_sockaddr_str *rtp)
 {
 	if (!rtp)
@@ -99,7 +94,7 @@
 
 /* Render intersections of all known audio codec constraints to reach a resulting choice of favorite audio codec, plus
  * possible set of alternative audio codecs, in codec_filter->result. (The result.rtp address remains unchanged.) */
-int codec_filter_run(struct codec_filter *codec_filter)
+int codec_filter_run(struct codec_filter *codec_filter, const struct sdp_msg *remote)
 {
 	struct sdp_audio_codecs *r = &codec_filter->result.audio_codecs;
 	struct sdp_audio_codec *a = &codec_filter->assignment;
@@ -108,8 +103,8 @@
 		sdp_audio_codecs_intersection(r, &codec_filter->ms, false);
 	if (codec_filter->bss.count)
 		sdp_audio_codecs_intersection(r, &codec_filter->bss, false);
-	if (codec_filter->remote.audio_codecs.count)
-		sdp_audio_codecs_intersection(r, &codec_filter->remote.audio_codecs, true);
+	if (remote->audio_codecs.count)
+		sdp_audio_codecs_intersection(r, &remote->audio_codecs, true);
 
 #if 0
 	/* Future: If osmo-msc were able to trigger a re-assignment after the remote side has picked a codec mismatching
@@ -154,7 +149,8 @@
 	return 0;
 }
 
-int codec_filter_to_str_buf(char *buf, size_t buflen, const struct codec_filter *codec_filter)
+int codec_filter_to_str_buf(char *buf, size_t buflen, const struct codec_filter *codec_filter,
+			    const struct sdp_msg *remote)
 {
 	struct osmo_strbuf sb = { .buf = buf, .len = buflen };
 	OSMO_STRBUF_APPEND(sb, sdp_msg_to_str_buf, &codec_filter->result);
@@ -165,10 +161,10 @@
 		OSMO_STRBUF_APPEND(sb, sdp_audio_codec_to_str_buf, &codec_filter->assignment);
 	}
 
-	if (codec_filter->remote.audio_codecs.count
-	    || osmo_sockaddr_str_is_nonzero(&codec_filter->remote.rtp)) {
+	if (remote->audio_codecs.count
+	    || osmo_sockaddr_str_is_nonzero(&remote->rtp)) {
 		OSMO_STRBUF_PRINTF(sb, " remote=");
-		OSMO_STRBUF_APPEND(sb, sdp_msg_to_str_buf, &codec_filter->remote);
+		OSMO_STRBUF_APPEND(sb, sdp_msg_to_str_buf, remote);
 	}
 
 	if (codec_filter->ms.count) {
@@ -192,12 +188,12 @@
 	return sb.chars_needed;
 }
 
-char *codec_filter_to_str_c(void *ctx, const struct codec_filter *codec_filter)
+char *codec_filter_to_str_c(void *ctx, const struct codec_filter *codec_filter, const struct sdp_msg *remote)
 {
-	OSMO_NAME_C_IMPL(ctx, 128, "codec_filter_to_str_c-ERROR", codec_filter_to_str_buf, codec_filter)
+	OSMO_NAME_C_IMPL(ctx, 128, "codec_filter_to_str_c-ERROR", codec_filter_to_str_buf, codec_filter, remote)
 }
 
-const char *codec_filter_to_str(const struct codec_filter *codec_filter)
+const char *codec_filter_to_str(const struct codec_filter *codec_filter, const struct sdp_msg *remote)
 {
-	return codec_filter_to_str_c(OTC_SELECT, codec_filter);
+	return codec_filter_to_str_c(OTC_SELECT, codec_filter, remote);
 }
diff --git a/src/libmsc/gsm_04_08_cc.c b/src/libmsc/gsm_04_08_cc.c
index 5f54a58..70a0b77 100644
--- a/src/libmsc/gsm_04_08_cc.c
+++ b/src/libmsc/gsm_04_08_cc.c
@@ -750,7 +750,7 @@
 	int rc;
 	if (!sdp[0])
 		return;
-	rc = sdp_msg_from_sdp_str(&trans->cc.codecs.remote, sdp);
+	rc = sdp_msg_from_sdp_str(&trans->cc.remote, sdp);
 	if (rc)
 		LOG_TRANS_CAT(trans, DMNCC, LOGL_ERROR, "rx %s: Failed to parse SDP: %d\n",
 			      get_mncc_name(mncc_msg_type), rc);
@@ -810,14 +810,14 @@
 	rx_mncc_sdp(trans, setup->msg_type, setup->sdp);
 	/* sdp.remote: if there is no SDP information or we failed to parse it, try using the Bearer Capability from
 	 * MNCC, if any. */
-	if (!trans->cc.codecs.remote.audio_codecs.count && (setup->fields & MNCC_F_BEARER_CAP)) {
-		trans->cc.codecs.remote = (struct sdp_msg){};
-		sdp_audio_codecs_from_bearer_cap(&trans->cc.codecs.remote.audio_codecs,
+	if (!trans->cc.remote.audio_codecs.count && (setup->fields & MNCC_F_BEARER_CAP)) {
+		trans->cc.remote = (struct sdp_msg){};
+		sdp_audio_codecs_from_bearer_cap(&trans->cc.remote.audio_codecs,
 						 &setup->bearer_cap);
 		LOG_TRANS_CAT(trans, DMNCC, LOGL_DEBUG, "rx %s Bearer Cap: remote=%s\n",
-			      get_mncc_name(setup->msg_type), sdp_msg_to_str(&trans->cc.codecs.remote));
+			      get_mncc_name(setup->msg_type), sdp_msg_to_str(&trans->cc.remote));
 	}
-	if (!trans->cc.codecs.remote.audio_codecs.count)
+	if (!trans->cc.remote.audio_codecs.count)
 		LOG_TRANS(trans, LOGL_INFO,
 			  "Got no information of remote audio codecs: neither SDP nor Bearer Capability. Trying anyway.\n");
 
@@ -844,7 +844,7 @@
 	 * finding a matching codec. */
 	if (bearer_cap.speech_ver[0] == -1) {
 		LOG_TRANS(trans, LOGL_ERROR, "%s: no codec match possible: %s\n",
-			  get_mncc_name(setup->msg_type), codec_filter_to_str(&trans->cc.codecs));
+			  get_mncc_name(setup->msg_type), codec_filter_to_str(&trans->cc.codecs, &trans->cc.remote));
 
 		/* incompatible codecs */
 		rc = mncc_release_ind(trans->net, trans, trans->callref,
@@ -1095,11 +1095,11 @@
 	if (alerting->sdp[0]) {
 		struct call_leg *cl = trans->msc_a->cc.call_leg;
 		struct rtp_stream *rtp_cn = cl ? cl->rtp[RTP_TO_CN] : NULL;
-		codec_filter_set_remote(&trans->cc.codecs, alerting->sdp);
+		sdp_msg_from_sdp_str(&trans->cc.remote, alerting->sdp);
 		trans_cc_filter_run(trans);
 		LOG_TRANS(trans, LOGL_DEBUG, "msg_type=%s\n", get_mncc_name(alerting->msg_type));
 		if (rtp_cn) {
-			rtp_stream_set_remote_addr_and_codecs(rtp_cn, &trans->cc.codecs.remote);
+			rtp_stream_set_remote_addr_and_codecs(rtp_cn, &trans->cc.remote);
 			rtp_stream_commit(rtp_cn);
 		}
 	}
@@ -1158,7 +1158,7 @@
 		trans_cc_filter_run(trans);
 		LOG_TRANS(trans, LOGL_DEBUG, "msg_type=%s\n", get_mncc_name(connect->msg_type));
 		if (rtp_cn) {
-			rtp_stream_set_remote_addr_and_codecs(rtp_cn, &trans->cc.codecs.remote);
+			rtp_stream_set_remote_addr_and_codecs(rtp_cn, &trans->cc.remote);
 			rtp_stream_commit(rtp_cn);
 		}
 	}
@@ -2098,7 +2098,7 @@
 	}
 
 	rx_mncc_sdp(trans, rtp->msg_type, rtp->sdp);
-	rtp_stream_set_remote_addr_and_codecs(rtps, &trans->cc.codecs.remote);
+	rtp_stream_set_remote_addr_and_codecs(rtps, &trans->cc.remote);
 
 	if (!osmo_sockaddr_str_is_nonzero(&rtps->remote)) {
 		/* Didn't get an IP address from SDP. Try legacy MNCC IP address */
diff --git a/src/libmsc/msc_a.c b/src/libmsc/msc_a.c
index d53404f..b8a5de1 100644
--- a/src/libmsc/msc_a.c
+++ b/src/libmsc/msc_a.c
@@ -642,7 +642,7 @@
 
 	if (!cc_trans->cc.codecs.result.audio_codecs.count) {
 		LOG_TRANS(cc_trans, LOGL_ERROR, "Assignment not possible, no matching codec: %s\n",
-			  codec_filter_to_str(&cc_trans->cc.codecs));
+			  codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.remote));
 		call_leg_release(msc_a->cc.call_leg);
 		return;
 	}
@@ -651,7 +651,7 @@
 	 * capabilities. */
 	if (sdp_audio_codecs_to_gsm0808_channel_type(&channel_type, &cc_trans->cc.codecs.result.audio_codecs)) {
 		LOG_MSC_A(msc_a, LOGL_ERROR, "Cannot compose Channel Type (Permitted Speech) from codecs: %s\n",
-			  codec_filter_to_str(&cc_trans->cc.codecs));
+			  codec_filter_to_str(&cc_trans->cc.codecs, &cc_trans->cc.remote));
 		trans_free(cc_trans);
 		return;
 	}
diff --git a/src/libmsc/transaction_cc.c b/src/libmsc/transaction_cc.c
index 96087b8..4c30f84 100644
--- a/src/libmsc/transaction_cc.c
+++ b/src/libmsc/transaction_cc.c
@@ -42,8 +42,8 @@
 
 void trans_cc_filter_run(struct gsm_trans *trans)
 {
-	codec_filter_run(&trans->cc.codecs);
-	LOG_TRANS(trans, LOGL_DEBUG, "codecs: %s\n", codec_filter_to_str(&trans->cc.codecs));
+	codec_filter_run(&trans->cc.codecs, &trans->cc.remote);
+	LOG_TRANS(trans, LOGL_DEBUG, "codecs: %s\n", codec_filter_to_str(&trans->cc.codecs, &trans->cc.remote));
 }
 
 void trans_cc_filter_set_ms_from_bc(struct gsm_trans *trans, const struct gsm_mncc_bearer_cap *bcap)