BSSAP/IPA integration: Wait for SCCPLite to be established

Before this patch, we had some problems related to synchronization
between the IPA transport, SCCP emulation and BSSAP layer in SCCPlite
configurations.

This code ensures that f_bssap_init() will block until the IPA
connection (client or server) is established, and then start the SCCP
and BSSAP emulation components in the right order.

This in turn ensures that the initial BSSMAP RESET that we're sending
from the TTCN-3 side is only sent once the IPA connection is fully
established, and the CCM Identity handshake has happened before.

Change-Id: I483ddd45c1cf631a5a9d8f862b6ca728b38bdc14
Related: OS#2544
diff --git a/library/BSSAP_Adapter.ttcn b/library/BSSAP_Adapter.ttcn
index 1a9fdb4..7404a6f 100644
--- a/library/BSSAP_Adapter.ttcn
+++ b/library/BSSAP_Adapter.ttcn
@@ -28,8 +28,9 @@
 
 type record BSSAP_Adapter {
 	/* component references */
-	M3UA_CT vc_M3UA, /* only in 3GPP AoIP */
-	IPA_Emulation_CT vc_IPA, /* only in SCCPliste */
+	M3UA_CT vc_M3UA,		/* only in 3GPP AoIP */
+	IPA_Emulation_CT vc_IPA,	/* only in SCCPlite */
+	IPA_EventWaiter_CT vc_WAIT,	/* only in SCCPlite */
 	SCCP_CT vc_SCCP,
 
 	MSC_SCCP_MTP3_parameters sccp_pars,
@@ -114,18 +115,32 @@
 		map(ba.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
 		/* connect MTP3 service provider (IPA) to lower side of SCCP */
 		connect(ba.vc_IPA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
+		/* connect waiter to general IPA port (for ASP_IPA_Event) */
+		ba.vc_WAIT := IPA_EventWaiter_CT.create(id & "-IPA-WAIT");
+		connect(ba.vc_IPA:IPA_SP_PORT, ba.vc_WAIT:IPA_SP_PORT);
+		ba.vc_WAIT.start(IPA_Emulation.waiter_main());
 		ba.vc_IPA.start(IPA_Emulation.main_server(cfg.sctp_addr.local_ip_addr,
 							cfg.sctp_addr.local_sctp_port));
+		/* wait until we received an IPA CCM ID_ACK */
+		ba.vc_WAIT.done;
+		disconnect(ba.vc_IPA:IPA_SP_PORT, ba.vc_WAIT:IPA_SP_PORT);
 		}
 	case (BSSAP_TRANSPORT_SCCPlite_CLIENT) {
 		ba.vc_IPA := IPA_Emulation_CT.create(id & "-IPA");
 		map(ba.vc_IPA:IPA_PORT, system:IPA_CODEC_PT);
 		/* connect MTP3 service provider (IPA) to lower side of SCCP */
 		connect(ba.vc_IPA:MTP3_SP_PORT, ba.vc_SCCP:MTP3_SCCP_PORT);
+		/* connect waiter to general IPA port (for ASP_IPA_Event) */
+		ba.vc_WAIT := IPA_EventWaiter_CT.create(id & "-IPA-WAIT");
+		connect(ba.vc_IPA:IPA_SP_PORT, ba.vc_WAIT:IPA_SP_PORT);
+		ba.vc_WAIT.start(IPA_Emulation.waiter_main());
 		ba.vc_IPA.start(IPA_Emulation.main_client(cfg.sctp_addr.remote_ip_addr,
 							cfg.sctp_addr.remote_sctp_port,
 							cfg.sctp_addr.local_ip_addr,
 							cfg.sctp_addr.local_sctp_port));
+		/* wait until we received an IPA CCM ID_ACK */
+		ba.vc_WAIT.done;
+		disconnect(ba.vc_IPA:IPA_SP_PORT, ba.vc_WAIT:IPA_SP_PORT);
 		}
 	case else {
 		setverdict(fail, "Unsuppored BSSAP_Transport");
@@ -133,8 +148,6 @@
 		}
 	}
 
-	ba.vc_SCCP.start(SCCPStart(ba.sccp_pars));
-
 	if (isvalue(ops)) {
 		timer T := 5.0;
 		T.start;
@@ -145,6 +158,9 @@
 		/* start the BSSMAP emulation */
 		ba.vc_BSSMAP.start(BSSMAP_Emulation.main(valueof(ops), ""));
 	}
+
+	ba.vc_SCCP.start(SCCPStart(ba.sccp_pars));
+
 }