mgcp: Synchronize conn mode bits and output enabled flags

This patch changes implementation and the mgcp_connection_mode enum
in a way that net_end.output_enabled (bts_end.output_enabled) flag
always matches the MGCP_CONN_SEND_ONLY (MGCP_CONN_RECV_ONLY) bit of
conn_mode.

Based on this, the conn_mode bits are then used instead of the
output_enabled fields within mgcp_protocol.c.

Sponsored-by: On-Waves ehf
diff --git a/openbsc/tests/mgcp/mgcp_test.c b/openbsc/tests/mgcp/mgcp_test.c
index 7eeef99..1f11b1d 100644
--- a/openbsc/tests/mgcp/mgcp_test.c
+++ b/openbsc/tests/mgcp/mgcp_test.c
@@ -321,6 +321,19 @@
 	return real_sendto(sockfd, buf, len, flags, dest_addr, addrlen);
 }
 
+#define CONN_UNMODIFIED (0x1000)
+
+static void test_values(void)
+{
+	/* Check that NONE disables all output */
+	OSMO_ASSERT((MGCP_CONN_NONE & MGCP_CONN_RECV_SEND) == 0)
+
+	/* Check that LOOPBACK enables all output */
+	OSMO_ASSERT((MGCP_CONN_LOOPBACK & MGCP_CONN_RECV_SEND) ==
+		    MGCP_CONN_RECV_SEND)
+}
+
+
 static void test_messages(void)
 {
 	struct mgcp_config *cfg;
@@ -341,9 +354,9 @@
 		endp = &cfg->trunk.endpoints[i];
 		endp->net_end.payload_type = PTYPE_NONE;
 		endp->net_end.packet_duration_ms = -1;
-		endp->bts_end.output_enabled = 0;
-		endp->net_end.output_enabled = 0;
-		endp->conn_mode = -1;
+
+		OSMO_ASSERT(endp->conn_mode == MGCP_CONN_NONE);
+		endp->conn_mode |= CONN_UNMODIFIED;
 	}
 
 	for (i = 0; i < ARRAY_SIZE(tests); i++) {
@@ -386,7 +399,7 @@
 			else
 				printf("Requested packetization period not set\n");
 
-			if (endp->conn_mode != -1)
+			if ((endp->conn_mode & CONN_UNMODIFIED) == 0)
 				printf("Connection mode: %d, "
 				       "BTS output %sabled, NET output %sabled\n",
 				       endp->conn_mode,
@@ -395,12 +408,17 @@
 			else
 				printf("Connection mode not set\n");
 
+			OSMO_ASSERT(endp->net_end.output_enabled ==
+				    (endp->conn_mode & MGCP_CONN_SEND_ONLY ? 1 : 0));
+			OSMO_ASSERT(endp->bts_end.output_enabled ==
+				    (endp->conn_mode & MGCP_CONN_RECV_ONLY ? 1 : 0));
+
 			endp->net_end.packet_duration_ms = -1;
-			endp->bts_end.output_enabled = 0;
-			endp->net_end.output_enabled = 0;
 			endp->local_options.pkt_period_min = 0;
 			endp->local_options.pkt_period_max = 0;
-			endp->conn_mode = -1;
+			endp->conn_mode = MGCP_CONN_NONE | CONN_UNMODIFIED;
+			endp->net_end.output_enabled = 0;
+			endp->bts_end.output_enabled = 0;
 		}
 
 
@@ -784,6 +802,7 @@
 	osmo_init_logging(&log_info);
 
 	test_strline();
+	test_values();
 	test_messages();
 	test_retransmission();
 	test_packet_loss_calc();