bsc: Add tests for CBSP MESSAGE STATUS QUERY procedure

Change-Id: I124a69c515d634bc054ed35e430af6b3c11ad46e
Related: SYS#5909
diff --git a/bsc/BSC_Tests_CBSP.ttcn b/bsc/BSC_Tests_CBSP.ttcn
index 8119289..25f00d8 100644
--- a/bsc/BSC_Tests_CBSP.ttcn
+++ b/bsc/BSC_Tests_CBSP.ttcn
@@ -380,6 +380,34 @@
 	}
 }
 
+/* send a KILL CBS to the BSC; expect either COMPLETE or FAILURE in response*/
+function f_cbsp_msg_status_query(uint16_t msg_id, uint16_t ser_no, template (value) uint8_t channel_ind := 0,
+		     template (value) BSSMAP_FIELD_CellIdentificationList cell_list := ts_BSSMAP_CIL_BSS,
+		     template CBSP_IE_NumBcastComplList compl_list := ?,
+		     template CBSP_FailureListItems fail_list := omit) runs on cbsp_test_CT
+{
+	var template (value) CBSP_PDU tx;
+	var template CBSP_PDU rx;
+
+	tx := ts_CBSP_MSG_STATUS_QUERY(msg_id, ser_no, cell_list, channel_ind);
+	CBSP[0].send(ts_CBSP_Send(g_cbsp_conn_id[0], tx));
+	if (istemplatekind(fail_list, "omit")) {
+		rx := tr_CBSP_MSG_STATUS_QUERY_COMPL(msg_id, ser_no, compl_list:=compl_list, channel_ind:=channel_ind);
+	} else {
+		rx := tr_CBSP_MSG_STATUS_QUERY_FAIL(msg_id, ser_no, fail_list, channel_ind:=channel_ind,
+						    compl_list:=compl_list);
+	}
+	alt {
+	[] CBSP[0].receive(tr_CBSP_Recv(g_cbsp_conn_id[0], rx)) {
+		setverdict(pass);
+		}
+	[] CBSP[0].receive(tr_CBSP_Recv(g_cbsp_conn_id[0], ?)) {
+		setverdict(fail, "Received unexpected CBSP");
+		mtc.stop;
+		}
+	}
+}
+
 template (present) RSL_IE_CbCommandType
 tr_RslCbCmdType(template (present) uint2_t lblock := ?, template (present) RSL_CbCommand cmd := ?) := {
 	command := cmd,
@@ -858,6 +886,45 @@
 	}
 }
 
+/* Send a MSG STATUS QUERY for an unknown message; expect no completion list and present failure list */
+testcase TC_cbsp_status_q_empty() runs on cbsp_test_CT {
+	g_pars := valueof(ts_CBSP_Pars_default(false, 18001, 18501));
+	f_init();
+
+	f_cbsp_msg_status_query(g_cbsp_msg_id, g_cbsp_ser_no, compl_list := omit, fail_list := ?);
+}
+
+/* Send a SMSCB to entire BSS followed by MSG_STATUS_QUERY; expect completion list and no failure list */
+testcase TC_cbsp_status_q_bts_cgi() runs on cbsp_test_CT {
+	g_pars := valueof(ts_CBSP_Pars_default(false, 19001, 19501));
+	f_init();
+
+	var CBSP_IEs pages := {f_gen_page()};
+	var template (value) BSSMAP_FIELD_CellIdentificationList cell_list;
+	cell_list := ts_BSSMAP_CIL_CGI({bssmap_cgi(mp_cgi_bts0)});
+	/* request 5 transmissions */
+	f_cbsp_write(g_cbsp_msg_id, g_cbsp_ser_no, cell_list, num_bcast_req := 5, content:=pages,
+		     success_list:=cell_list, fail_list:=omit);
+	var template (present) RSL_Message tr := f_page2rsl(pages[0], g_cbsp_msg_id, g_cbsp_ser_no);
+	/* wait for first transmission */
+	IPA_RSL[0].receive(tr_ASP_RSL_UD(tr));
+	var template (present) CBSP_IE_NumBcastComplList compl_list := {
+		len := ?,
+		spare1_4 := ?,
+		cell_id_discr := ?,
+		list := {
+			cI_CGI := {
+				ci := bssmap_cgi(mp_cgi_bts0),
+				num_bcast_compl := (1 .. 5),
+				num_bcast_info := CBSP_NUM_BCAST_INFO_VALID,
+				spare1_4 := '0000'B
+			}
+		}
+	};
+	f_cbsp_msg_status_query(g_cbsp_msg_id, g_cbsp_ser_no, cell_list:=cell_list, compl_list := compl_list, fail_list := omit);
+}
+
+
 
 
 control {
@@ -884,6 +951,9 @@
 	execute( TC_cbsp_write_then_kill() );
 	execute( TC_cbsp_write_then_reset() );
 
+	execute( TC_cbsp_status_q_empty() );
+	execute( TC_cbsp_status_q_bts_cgi() );
+
 	execute( TC_cbsp_emerg_write_bts_cgi_dchan() );
 	execute( TC_cbsp_emerg_write_bts_cgi_cchan() );
 	execute( TC_cbsp_emerg_write_bts_cgi_cchan_disable() );
diff --git a/library/CBSP_Templates.ttcn b/library/CBSP_Templates.ttcn
index 5da2958..f86241e 100644
--- a/library/CBSP_Templates.ttcn
+++ b/library/CBSP_Templates.ttcn
@@ -667,6 +667,85 @@
 	return tr_CBSP(CBSP_MSGT_KILL_FAIL, ies);
 }
 
+/* 8.1.3.10 MESSAGE STATUS QUERY */
+template (value) CBSP_PDU
+ts_CBSP_MSG_STATUS_QUERY(template (value) uint16_t msg_id,
+			 template (value) uint16_t old_ser_nr,
+			 template (value) BSSMAP_FIELD_CellIdentificationList cell_list,
+			 template (value) uint8_t channel_ind) :=
+	ts_CBSP(CBSP_MSGT_MSG_STATUS_QUERY, {
+			ts_CbspMsgId(msg_id),
+			ts_OldSerNo(old_ser_nr),
+			ts_CbspCellList(cell_list),
+			ts_CbspChannelInd(channel_ind)});
+template (present) CBSP_PDU
+tr_CBSP_MSG_STATUS_QUERY(template (present) uint16_t msg_id := ?,
+			 template (present) uint16_t old_ser_nr := ?,
+			 template (present) BSSMAP_FIELD_CellIdentificationList cell_list := ?,
+			 template (present) uint8_t channel_ind := ?) :=
+	ts_CBSP(CBSP_MSGT_MSG_STATUS_QUERY, {
+			ts_CbspMsgId(msg_id),
+			ts_OldSerNo(old_ser_nr),
+			ts_CbspCellList(cell_list),
+			ts_CbspChannelInd(channel_ind)});
+
+/* 8.1.3.11 MESSAGE STATUS QUERY COMPLETE */
+template (value) CBSP_PDU
+ts_CBSP_MSG_STATUS_QUERY_COMPL(template (value) uint16_t msg_id, template (value) uint16_t old_ser_nr,
+			       template (value) CBSP_IE_NumBcastComplList compl_list,
+			       template (value) uint8_t channel_ind) :=
+	ts_CBSP(CBSP_MSGT_MSG_STATUS_QUERY_COMPL, {
+		ts_CbspMsgId(msg_id),
+		ts_OldSerNo(old_ser_nr),
+		ts_CbspNumComplList(valueof(compl_list)),
+		ts_CbspChannelInd(channel_ind)});
+template (present) CBSP_PDU
+tr_CBSP_MSG_STATUS_QUERY_COMPL(template (present) uint16_t msg_id, template (present) uint16_t old_ser_nr,
+				template (present) CBSP_IE_NumBcastComplList compl_list,
+				template (present) uint8_t channel_ind) :=
+	tr_CBSP(CBSP_MSGT_MSG_STATUS_QUERY_COMPL, {
+		tr_CbspMsgId(msg_id),
+		tr_OldSerNo(old_ser_nr),
+		tr_CbspNumComplList(compl_list),
+		tr_CbspChannelInd(channel_ind)});
+
+/* 8.1.3.12 MESSAGE STATUS QUERY FAILURE */
+function ts_CBSP_MSG_STATUS_QUERY_FAIL(template (value) uint16_t msg_id, template (value) uint16_t old_ser_nr,
+				       template (value) CBSP_FailureListItems fail_list,
+				       template (value) uint8_t channel_ind,
+				       template (omit) CBSP_IE_NumBcastComplList compl_list)
+return template (value) CBSP_PDU {
+	var template (value) CBSP_IEs ies := {
+		ts_CbspMsgId(msg_id),
+		ts_OldSerNo(old_ser_nr),
+		ts_CbspFailList(fail_list),
+		ts_CbspChannelInd(channel_ind)
+	};
+	if (not istemplatekind(compl_list, "omit")) {
+		ies[lengthof(ies)] := ts_CbspNumComplList(valueof(compl_list));
+	}
+	return ts_CBSP(CBSP_MSGT_MSG_STATUS_QUERY_FAIL, ies);
+}
+function tr_CBSP_MSG_STATUS_QUERY_FAIL(template (present) uint16_t msg_id := ?, template (present) uint16_t old_ser_nr := ?,
+				       template (present) CBSP_FailureListItems fail_list := ?,
+				       template (present) uint8_t channel_ind := ?,
+				       template CBSP_IE_NumBcastComplList compl_list := *)
+return template (present) CBSP_PDU {
+	var template (present) CBSP_IEs ies := {
+		tr_CbspMsgId(msg_id),
+		tr_OldSerNo(old_ser_nr),
+		tr_CbspFailList(fail_list),
+		tr_CbspChannelInd(channel_ind)
+	};
+	if (istemplatekind(compl_list, "*")) {
+		testcase.stop("TITAN > 6.5.0 doesn't support this");
+		//ies[lengthof(ies)] := ts_CbspNumComplList(valueof(compl_list));
+	} else if (not istemplatekind(compl_list, "omit")) {
+		ies[lengthof(ies)] := tr_CbspNumComplList(compl_list);
+	}
+	return tr_CBSP(CBSP_MSGT_MSG_STATUS_QUERY_FAIL, ies);
+}
+
 
 /* 8.1.3.16 RESET */
 template (value) CBSP_PDU ts_CBSP_RESET(template (value) BSSMAP_FIELD_CellIdentificationList cell_list) :=