bts: Pass AMR codec info over L1CTL and RSL

Related: SYS#5987
Depends: osmocom-bb.git Change-Id Ia20bc96e39726a919a556c83c8be48cb31af7331
Change-Id: I3db7f6a4b7819b16ada83862f2a5409db4fa21f9
diff --git a/bts/BTS_Tests.ttcn b/bts/BTS_Tests.ttcn
index f9361a0..646e5bf 100644
--- a/bts/BTS_Tests.ttcn
+++ b/bts/BTS_Tests.ttcn
@@ -307,6 +307,7 @@
 	uint8_t trx_nr,
 	RslChannelNr chan_nr,
 	RSL_IE_ChannelMode chan_mode,
+	RSL_IE_MultirateCfg mr_conf optional,
 	float t_guard,
 	ConnL1Pars l1_pars,
 	TestSpecUnion spec optional,
@@ -853,6 +854,10 @@
 		ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info :=
 encr_info})) };
 	}
+	if (mode.coding_alg_rate == RSL_CMOD_SP_GSM3) {
+		ch_act.ies := ch_act.ies & { valueof(t_RSL_IE(RSL_IE_MR_CONFIG,
+							      RSL_IE_Body:{multirate_cfg := g_pars.mr_conf})) };
+	}
 	ch_act.ies := ch_act.ies & more_ies;
 	f_rsl_transceive(ch_act, tr_RSL_CHAN_ACT_ACK(g_chan_nr), "RSL CHAN ACT");
 }
@@ -869,6 +874,7 @@
 	trx_nr := trx_nr,
 	chan_nr := valueof(chan_nr),
 	chan_mode := valueof(chan_mode),
+	mr_conf := omit,
 	t_guard := t_guard,
 	l1_pars := {
 		dtx_enabled := false,
@@ -2510,12 +2516,16 @@
 	/* Send TCH Mode Request to the L1 if needed */
 	if (match(g_pars.chan_mode.spd_ind, (RSL_SPDI_SPEECH, RSL_SPDI_DATA))) {
 		var L1ctlTchMode tch_mode;
+		var uint8_t amr_start_codec := 0;
+		var BIT8 amr_codecs_bitmask := '00000000'B;
 
 		select (g_pars.chan_mode.coding_alg_rate) {
 		case (RSL_CMOD_NO_RESOURCE) { tch_mode := L1CTL_CHAN_MODE_SIGN; }
 		case (RSL_CMOD_SP_GSM1) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V1; }
 		case (RSL_CMOD_SP_GSM2) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V2; }
-		case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3; }
+		case (RSL_CMOD_SP_GSM3) { tch_mode := L1CTL_CHAN_MODE_SPEECH_V3;
+					  amr_codecs_bitmask := g_pars.mr_conf.amr_codec_modes;
+					}
 		case else {
 			log("RSL channel mode := ", g_pars.chan_mode.coding_alg_rate,
 			    " is not supported by the L1, falling back to signalling");
@@ -2523,7 +2533,10 @@
 			}
 		}
 
-		f_L1CTL_TCH_MODE(L1CTL, tch_mode);
+		f_L1CTL_TCH_MODE(L1CTL,
+				 ts_L1CTL_TCH_MODE_REQ(tch_mode,
+						       amr_start_codec := amr_start_codec,
+						       amr_codecs_bitmask := amr_codecs_bitmask));
 	}
 
 	g_first_meas_res := true;
diff --git a/library/L1CTL_PortType.ttcn b/library/L1CTL_PortType.ttcn
index ed235d3..80fa074 100644
--- a/library/L1CTL_PortType.ttcn
+++ b/library/L1CTL_PortType.ttcn
@@ -106,9 +106,10 @@
 		}
 	}
 
-	function f_L1CTL_TCH_MODE(L1CTL_PT pt, L1ctlTchMode tch_mode) {
+	function f_L1CTL_TCH_MODE(L1CTL_PT pt,
+				  template (value) L1ctlUlMessage tch_mode_req_tmpl := ts_L1CTL_TCH_MODE_REQ) {
 		timer T := 2.0;
-		pt.send(ts_L1CTL_TCH_MODE_REQ(tch_mode));
+		pt.send(tch_mode_req_tmpl);
 		T.start;
 		alt {
 		[] pt.receive(tr_L1CTL_MsgType(L1CTL_TCH_MODE_CONF)) { }
diff --git a/library/L1CTL_Types.ttcn b/library/L1CTL_Types.ttcn
index 6bfebb3..1b50703 100644
--- a/library/L1CTL_Types.ttcn
+++ b/library/L1CTL_Types.ttcn
@@ -181,7 +181,10 @@
 	type record L1ctlTchModeConf {
 		L1ctlTchMode	tch_mode,
 		L1ctlAudioMode	audio_mode,
-		OCT2		padding
+		record {
+			uint8_t	start_codec,
+			BIT8	codecs_bitmask
+		} amr
 	} with { variant "" };
 
 	type record L1ctlDataInd {
@@ -284,7 +287,10 @@
 		L1ctlTchMode	tch_mode,
 		L1ctlAudioMode	audio_mode,
 		L1ctlLoopMode	loop_mode,
-		OCT1		padding
+		record {
+			uint8_t	start_codec,
+			BIT8	codecs_bitmask
+		} amr
 	} with { variant "" };
 
 	type record L1ctlRachReq {
@@ -532,7 +538,9 @@
 	template (value) L1ctlUlMessage
 	ts_L1CTL_TCH_MODE_REQ(template (value) L1ctlTchMode tch_mode := L1CTL_CHAN_MODE_SIGN,
 			      template (value) L1ctlAudioMode audio_mode := t_L1CTL_AudioModeFwd,
-			      template (value) L1ctlLoopMode loop_mode := L1CTL_LOOP_MODE_OPEN) := {
+			      template (value) L1ctlLoopMode loop_mode := L1CTL_LOOP_MODE_OPEN,
+			      template (value) uint8_t amr_start_codec := 0,
+			      template (value) BIT8 amr_codecs_bitmask := '00000000'B) := {
 		header := ts_L1ctlHeader(L1CTL_TCH_MODE_REQ),
 		ul_info := omit,
 		ul_info_tbf := omit,
@@ -542,7 +550,10 @@
 				tch_mode := tch_mode,
 				audio_mode := audio_mode,
 				loop_mode := loop_mode,
-				padding := '00'O
+				amr := {
+					start_codec := amr_start_codec,
+					codecs_bitmask := amr_codecs_bitmask
+				}
 			}
 		}
 	};