f_channel_needs_modify(): ask actual TCH lchan mode via VTY

I am introducing a BSC test case that runs through a assigning a TCH
channel for signalling, and then using Channel Mode Modify to change its
mode from signalling to speech. For this to work,
f_channel_needs_modify() needs to actually look up the channel mode of
the TCH and not assume that a TCH is always in speech mode.

Related: SYS#4895
Change-Id: If30e2cec65da91cb5899ee29e2afb6696437a4c9
diff --git a/bsc/MSC_ConnectionHandler.ttcn b/bsc/MSC_ConnectionHandler.ttcn
index 245528f..aa9f395 100644
--- a/bsc/MSC_ConnectionHandler.ttcn
+++ b/bsc/MSC_ConnectionHandler.ttcn
@@ -45,6 +45,7 @@
 
 import from TELNETasp_PortType all;
 import from Osmocom_VTY_Functions all;
+import from TCCConversion_Functions all;
 
 
 /***********************************************************************
@@ -955,21 +956,30 @@
 /* Determine if the channel mode specified within rsl_chan_nr requires a
  * MODE MODIFY in to match the channel mode specified by given BSSMAP
  * ChannelType */
-function f_channel_needs_modify(BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
+function f_channel_needs_modify(TELNETasp_PT vty, BSSMAP_IE_ChannelType bssmap, RslChannelNr rsl_chan_nr)
 return boolean {
 
-	/* FIXME: This tests the rsl_chan_nr to determine if we are on a
-	 * signalling channel or not. Unfortunately this may lead to false
-	 * results if we are on a TCH. The problem is that a TCH may be also
-	 * used in signalling mode, but this function assumes that only SDCCH4
-	 * and SDCCH8 are used as signalling channels at all. */
-
 	var boolean current_signalling := false;
 	var boolean desired_signalling := false;
 
 	select (rsl_chan_nr) {
 	       case (t_RslChanNr_SDCCH4(?, ?)) { current_signalling := true; }
 	       case (t_RslChanNr_SDCCH8(?, ?)) { current_signalling := true; }
+	       case (t_RslChanNr_Bm(?)) {
+			/* TCH/F, always subslot 0 */
+			var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn) & " 0");
+			if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) {
+				current_signalling := true;
+			}
+	       }
+	       case (t_RslChanNr_Lm(?, ?)) {
+			/* TCH/H */
+			var charstring res := f_vty_transceive_ret(vty, "show lchan 0 0 " & int2str(rsl_chan_nr.tn)
+								   & " " & int2str(rsl_chan_nr.u.lm.sub_chan));
+			if (f_strstr(res, "Channel Mode / Codec: SIGNALLING", 0) >= 0) {
+				current_signalling := true;
+			}
+	       }
 	}
 
 	if (bssmap.speechOrDataIndicator == '0011'B) {
@@ -1134,7 +1144,7 @@
 		 * channel, we must now check if the mode of the current
 		 * channel is compatible. If not we expect the BSC to modify
 		 * the mode */
-		exp_modify := f_channel_needs_modify(ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr);
+		exp_modify := f_channel_needs_modify(BSCVTY, ass_cmd.pdu.bssmap.assignmentRequest.channelType, g_chan_nr);
 	}
 
 	/* Some test situations will involve MGCP transactions on a media