cbc: Test ETWS msg over SBc-AP

So far only non-emergency CBS messages were tested, which require a
slighlty idfferent encoding on the protocol side.

Related: OS#4945
Change-Id: I506322fc8a664716db8cd79217c2091b0b926836
diff --git a/cbc/CBC_Tests.ttcn b/cbc/CBC_Tests.ttcn
index 581298a..83cf07d 100644
--- a/cbc/CBC_Tests.ttcn
+++ b/cbc/CBC_Tests.ttcn
@@ -653,7 +653,7 @@
 	f_shutdown_helper();
 }
 
-/* Test ETWS message. TS 23.041 9.4.1.2.2 */
+/* Test ETWS message over CBSP. TS 23.041 9.4.1.2.2 */
 testcase TC_ecbe_create_delete_etws_bsc() runs on test_CT {
 	f_init(num_bsc := 1);
 	var template (value) BSSMAP_FIELD_CellIdentificationList cell_list_success;
@@ -672,6 +672,19 @@
 	f_shutdown_helper();
 }
 
+/* Test ETWS message over SBc-AP. TS 23.041 9.4.1.2.2 */
+testcase TC_ecbe_create_delete_etws_mme() runs on test_CT {
+	f_init(num_mme := 1);
+	var template (value) CBS_Message msg := t_CBSmsg(4352 /* Earthquake */, 16753);
+	msg.channel_ind := omit;
+
+	g_pars_MME[0].start_fn := refers(f_mme_create_and_delete);
+	g_pars_MME[0].exp_cbs_msg := valueof(msg);
+	f_start();
+	f_create_and_delete(valueof(msg));
+	f_shutdown_helper();
+}
+
 control {
 	execute( TC_rx_keepalive() );
 	execute( TC_rx_keepalive_timeout() );
@@ -688,6 +701,7 @@
 	execute( TC_concurrent_cbs_msg_mme() );
 
 	execute( TC_ecbe_create_delete_etws_bsc() );
+	execute( TC_ecbe_create_delete_etws_mme() );
 }
 
 }
diff --git a/cbc/MME_ConnectionHandler.ttcn b/cbc/MME_ConnectionHandler.ttcn
index 4bcc853..c49461a 100644
--- a/cbc/MME_ConnectionHandler.ttcn
+++ b/cbc/MME_ConnectionHandler.ttcn
@@ -102,10 +102,15 @@
 runs on MME_ConnHdlr {
 	var template (present) SBC_AP_PDU rx_templ;
 	var SBC_AP_RecvFrom rf;
-	rx_templ := tr_SBCAP_WRITE_WARNING(int2bit(msg.msg_id, 16),
-					   int2bit(msg.ser_nr, 16),
-					   msg.rep_period,
-					   msg.num_bcast_req);
+	if (msg_id_is_etws(msg.msg_id)) {
+		rx_templ := tr_SBCAP_WRITE_WARNING_REQ_ETWS(
+				int2bit(msg.msg_id, 16), int2bit(msg.ser_nr, 16),
+				msg.rep_period, msg.num_bcast_req, hex2oct('018'H & int2hex(msg.msg_id - 4352, 1)));
+	} else {
+		rx_templ := tr_SBCAP_WRITE_WARNING_REQ_CBS(
+				int2bit(msg.msg_id, 16), int2bit(msg.ser_nr, 16),
+				msg.rep_period, msg.num_bcast_req);
+	}
 	alt {
 	[] SBC_AP[idx].receive(tr_SBC_AP_Recv(g_SBC_AP_conn_id[idx], rx_templ)) -> value rf {
 		log ("received expected req:", rf);
diff --git a/library/sbcap/SBC_AP_Templates.ttcn b/library/sbcap/SBC_AP_Templates.ttcn
index 0071056..4ca714c 100644
--- a/library/sbcap/SBC_AP_Templates.ttcn
+++ b/library/sbcap/SBC_AP_Templates.ttcn
@@ -153,15 +153,16 @@
 	}
 }
 
+/* 4.3.4.2.1 WRITE-REPLACE WARNING REQUEST */
 template (present) SBC_AP_PDU
-tr_SBCAP_WRITE_WARNING(template (present) BIT16 p_msg_id, template (present) BIT16 p_ser_nr,
-		       template (present) uint12_t p_rep_per,
-		       template (present) uint16_t p_num_bcast,
-		       template (present) BIT8 dcs := ?,
-		       template (present) octetstring p_msg_content := ?,
-		       template (present) Send_Write_Replace_Warning_Indication send_ind := ?,
-		       template (present) Concurrent_Warning_Message_Indicator concurrent_ind := ?
-		       ) := {
+tr_SBCAP_WRITE_WARNING_REQ_CBS(template (present) BIT16 p_msg_id, template (present) BIT16 p_ser_nr,
+			template (present) uint12_t p_rep_per,
+			template (present) uint16_t p_num_bcast,
+			template (present) BIT8 dcs := ?,
+			template (present) octetstring p_msg_content := ?,
+			template (present) Send_Write_Replace_Warning_Indication send_ind := ?,
+			template (present) Concurrent_Warning_Message_Indicator concurrent_ind := ?
+			) := {
 	initiatingMessage := {
 		procedureCode := id_Write_Replace_Warning,
 		criticality := reject,
@@ -187,15 +188,7 @@
 						id := SBC_AP_Constants.id_Number_of_Broadcasts_Requested,
 						criticality := reject,
 						value_ := { Number_of_Broadcasts_Requested := p_num_bcast }
-					}/*, {
-						id := SBC_AP_Constants.id_Warning_Type,
-						criticality := ignore,
-						value_ := { Warning_Type := warn_type }
 					}, {
-						id := SBC_AP_Constants.id_Warning_Security_Information,
-						criticality := reject,
-						value_ := { Warning_Security_Information := ? }
-					}*/, {
 						id := SBC_AP_Constants.id_Data_Coding_Scheme,
 						criticality := ignore,
 						value_ := { Data_Coding_Scheme := dcs }
@@ -224,6 +217,60 @@
 	}
 }
 
+template (present) SBC_AP_PDU
+tr_SBCAP_WRITE_WARNING_REQ_ETWS(template (present) BIT16 p_msg_id, template (present) BIT16 p_ser_nr,
+			template (present) uint12_t p_rep_per,
+			template (present) uint16_t p_num_bcast,
+			template (present) Warning_Type warn_type := ?,
+			template (present) Send_Write_Replace_Warning_Indication send_ind := ?
+			) := {
+	initiatingMessage := {
+		procedureCode := id_Write_Replace_Warning,
+		criticality := reject,
+		value_ := {
+			write_Replace_Warning_Request := {
+				protocolIEs := {
+					{
+						id := SBC_AP_Constants.id_Message_Identifier,
+						criticality := reject,
+						value_ := { Message_Identifier := p_msg_id }
+					}, {
+						id := SBC_AP_Constants.id_Serial_Number,
+						criticality := reject,
+						value_ := { Serial_Number := p_ser_nr }
+						/* List of TAIs */
+						/* Warning Area List */
+					}, {
+						id := SBC_AP_Constants.id_Repetition_Period,
+						criticality := reject,
+						value_ := { Repetition_Period := p_rep_per }
+						/* Extended Repetition Period */
+					}, {
+						id := SBC_AP_Constants.id_Number_of_Broadcasts_Requested,
+						criticality := reject,
+						value_ := { Number_of_Broadcasts_Requested := p_num_bcast }
+					}, {
+						id := SBC_AP_Constants.id_Warning_Type,
+						criticality := ignore,
+						value_ := { Warning_Type := warn_type }
+					}, {
+						id := SBC_AP_Constants.id_Warning_Security_Information,
+						criticality := ignore,
+						value_ := { Warning_Security_Information := ? }
+					}, {
+						id := SBC_AP_Constants.id_Send_Write_Replace_Warning_Indication,
+						criticality := ignore,
+						value_ := { Send_Write_Replace_Warning_Indication := send_ind }
+					}
+						/* Global eNB ID */
+						/* Warning Area Coordinates */
+				},
+				protocolExtensions := omit
+			}
+		}
+	}
+}
+
 /* 4.3.4.2.5 WRITE REPLACE WARNING INDICATION */
 template (value) SBC_AP_PDU
 ts_SBCAP_WRITE_WARNING_IND(template (value) BIT16 p_msg_id, template (value) BIT16 p_ser_nr,