mgcp: Introduce trans_bts and send BTS packets from this port

Introduce the trans_bts. Right now only a port is allocated
and the packets from the BTS are sent from this socket.
diff --git a/openbsc/src/mgcp/mgcp_protocol.c b/openbsc/src/mgcp/mgcp_protocol.c
index ddcbfaf..84fd155 100644
--- a/openbsc/src/mgcp/mgcp_protocol.c
+++ b/openbsc/src/mgcp/mgcp_protocol.c
@@ -423,12 +423,21 @@
 	if (endp->cfg->transcoder_ip) {
 		if (allocate_port(endp, &endp->trans_net,
 				  &endp->cfg->transcoder_ports,
-				  mgcp_bind_transcoder_rtp_port) != 0) {
+				  mgcp_bind_trans_net_rtp_port) != 0) {
 			mgcp_rtp_end_reset(&endp->net_end);
 			mgcp_rtp_end_reset(&endp->bts_end);
 			return -1;
 		}
 
+		if (allocate_port(endp, &endp->trans_bts,
+				  &endp->cfg->transcoder_ports,
+				  mgcp_bind_trans_bts_rtp_port) != 0) {
+			mgcp_rtp_end_reset(&endp->net_end);
+			mgcp_rtp_end_reset(&endp->bts_end);
+			mgcp_rtp_end_reset(&endp->trans_net);
+			return -1;
+		}
+
 		/* remember that we have set up transcoding */
 		endp->is_transcoded = 1;
 	}
@@ -830,6 +839,7 @@
 		mgcp_rtp_end_init(&cfg->endpoints[i].net_end);
 		mgcp_rtp_end_init(&cfg->endpoints[i].bts_end);
 		mgcp_rtp_end_init(&cfg->endpoints[i].trans_net);
+		mgcp_rtp_end_init(&cfg->endpoints[i].trans_bts);
 	}
 
 	return 0;
@@ -854,6 +864,7 @@
 	mgcp_rtp_end_reset(&endp->bts_end);
 	mgcp_rtp_end_reset(&endp->net_end);
 	mgcp_rtp_end_reset(&endp->trans_net);
+	mgcp_rtp_end_reset(&endp->trans_bts);
 	endp->is_transcoded = 0;
 
 	memset(&endp->net_state, 0, sizeof(endp->net_state));
@@ -865,12 +876,6 @@
 	memset(&endp->taps, 0, sizeof(endp->taps));
 }
 
-/* For transcoding we need to manage an in and an output that are connected */
-static int back_channel(int endpoint)
-{
-	return endpoint + 60;
-}
-
 static int send_trans(struct mgcp_config *cfg, const char *buf, int len)
 {
 	struct sockaddr_in addr;
@@ -932,16 +937,20 @@
 {
 	int port;
 	int in_endp = ENDPOINT_NUMBER(endp);
-	int out_endp = back_channel(in_endp);
+	int out_endp = endp_back_channel(in_endp);
 
 	if (!endp->is_transcoded)
 		return;
 
-	send_msg(endp, in_endp, endp->bts_end.local_port, "CRCX", "recvonly");
-	send_msg(endp, in_endp, endp->bts_end.local_port, "MDCX", "recvonly");
+	send_msg(endp, in_endp, endp->trans_bts.local_port, "CRCX", "recvonly");
+	send_msg(endp, in_endp, endp->trans_bts.local_port, "MDCX", "recvonly");
 	send_msg(endp, out_endp, endp->trans_net.local_port, "CRCX", "sendrecv");
 	send_msg(endp, out_endp, endp->trans_net.local_port, "MDCX", "sendrecv");
 
+	port = rtp_calculate_port(in_endp, endp->cfg->transcoder_remote_base);
+	endp->trans_bts.rtp_port = htons(port);
+	endp->trans_bts.rtcp_port = htons(port + 1);
+
 	port = rtp_calculate_port(out_endp, endp->cfg->transcoder_remote_base);
 	endp->trans_net.rtp_port = htons(port);
 	endp->trans_net.rtcp_port = htons(port + 1);
@@ -950,7 +959,7 @@
 static void delete_transcoder(struct mgcp_endpoint *endp)
 {
 	int in_endp = ENDPOINT_NUMBER(endp);
-	int out_endp = back_channel(in_endp);
+	int out_endp = endp_back_channel(in_endp);
 
 	if (!endp->is_transcoded)
 		return;