module RSL_Types {

/* RSL types defining abstract TTCN-3 data types for the A-bis RSL protocol.
 *
 * RSL is a 3GPP standard protocol used between BTS and BSC in a GSM network.
 *
 * (C) 2017 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 *
 * Released under the terms of GNU General Public License, Version 2 or
 * (at your option) any later version.
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

	import from General_Types all;
	import from Osmocom_Types all;
	import from GSM_RR_Types all;
	import from GSM_Types all;
	import from MobileL3_CommonIE_Types all;
	import from L3_Templates all;

	/* Section 9.1 */
	type enumerated RSL_MessageGroup {
		RSL_MDISC_RESERVED	('0000000'B),
		RSL_MDISC_RLL		('0000001'B),
		RSL_MDISC_DCHAN		('0000100'B),
		RSL_MDISC_CCHAN		('0000110'B),
		RSL_MDISC_TRX_MGMT	('0001000'B),
		RSL_MDISC_LCS		('0010000'B),
		RSL_MDISC_IPACCESS	('0111111'B)
	} with { variant "FIELDLENGTH(7)" };

	/* Section 9.1 */
	type record RSL_MessageDiscriminator {
		RSL_MessageGroup	msg_group,
		boolean			transparent
	} with { variant "FIELDORDER(msb)" };

	template (value) RSL_MessageDiscriminator ts_RSL_MsgDisc(RSL_MessageGroup mg, boolean t := true) := {
		msg_group := mg,
		transparent := t
	}
	template RSL_MessageDiscriminator tr_RSL_MsgDisc(template RSL_MessageGroup mg, boolean t := true) := {
		msg_group := mg,
		transparent := t
	}


	/* Section 9.2 */
	type enumerated RSL_MessageType {
		/* Radio Link Layer Management */
		RSL_MT_DATA_REQ		('00000001'B),
		RSL_MT_DATA_IND		('00000010'B),
		RSL_MT_ERROR_IND	('00000011'B),
		RSL_MT_EST_REQ		('00000100'B),
		RSL_MT_EST_CONF		('00000101'B),
		RSL_MT_EST_IND		('00000110'B),
		RSL_MT_REL_REQ		('00000111'B),
		RSL_MT_REL_CONF		('00001000'B),
		RSL_MT_REL_IND		('00001001'B),
		RSL_MT_UNIT_DATA_REQ	('00001010'B),
		RSL_MT_UNIT_DATA_IND	('00001011'B),

		/* non-standard below */
		RSL_MT_SUSP_REQ		('00001100'B),
		RSL_MT_SUSP_CONF	('00001101'B),
		RSL_MT_RES_REQ		('00001110'B),
		RSL_MT_RECON_REQ	('00001111'B),

		/* Common Channel Management / TRX Management */
		RSL_MT_BCCH_INFO	('00010001'B),
		RSL_MT_CCCH_LOAD_IND	('00010010'B),
		RSL_MT_CHAN_RQD		('00010011'B),
		RSL_MT_DELETE_IND	('00010100'B),
		RSL_MT_PAGING_CMD	('00010101'B),
		RSL_MT_IMMEDIATE_ASSIGN_CMD ('00010110'B),
		RSL_MT_SMS_BC_REQ	('00010111'B),
		RSL_MT_CHAN_CONF	('00011000'B),	/* non-standard element */
		/* empty */
		RSL_MT_RF_RES_IND	('00011001'B),
		RSL_MT_SACCH_FILL	('00011010'B),
		RSL_MT_OVERLOAD		('00011011'B),
		RSL_MT_ERROR_REPORT	('00011100'B),
		RSL_MT_SMS_BC_CMD	('00011101'B),
		RSL_MT_CBCH_LOAD_IND	('00011110'B),
		RSL_MT_NOT_CMD		('00011111'B),

		/* Dedicate Channel Management */
		RSL_MT_CHAN_ACTIV	('00100001'B),
		RSL_MT_CHAN_ACTIV_ACK	('00100010'B),
		RSL_MT_CHAN_ACTIV_NACK	('00100011'B),
		RSL_MT_CONN_FAIL	('00100100'B),
		RSL_MT_DEACTIVATE_SACCH	('00100101'B),
		RSL_MT_ENCR_CMD		('00100110'B),
		RSL_MT_HANDO_DET	('00100111'B),
		RSL_MT_MEAS_RES		('00101000'B),
		RSL_MT_MODE_MODIFY_REQ	('00101001'B),
		RSL_MT_MODE_MODIFY_ACK	('00101010'B),
		RSL_MT_MODE_MODIFY_NACK	('00101011'B),
		RSL_MT_PHY_CONTEXT_REQ	('00101100'B),
		RSL_MT_PHY_CONTEXT_CONF	('00101101'B),
		RSL_MT_RF_CHAN_REL	('00101110'B),
		RSL_MT_MS_POWER_CONTROL ('00101111'B),
		RSL_MT_BS_POWER_CONTROL	('00110000'B),		/* 0x30 */
		RSL_MT_PREPROC_CONFIG	('00110001'B),
		RSL_MT_PREPROC_MEAS_RES	('00110010'B),
		RSL_MT_RF_CHAN_REL_ACK	('00110011'B),
		RSL_MT_SACCH_INFO_MODIFY('00110100'B),
		RSL_MT_TALKER_DET	('00110101'B),
		RSL_MT_LISTENER_DET	('00110110'B),
		RSL_MT_REMOTE_CODEC_CONF_REP ('00110111'B),
		RSL_MT_RTD_REP		('00111000'B),
		RSL_MT_PRE_HANDO_NOTIF	('00111001'B),
		RSL_MT_MR_CODEC_MOD_REQ	('00111010'B),
		RSL_MT_MR_CODEC_MOD_ACK	('00111011'B),
		RSL_MT_MR_CODEC_MOD_NACK ('00111100'B),
		RSL_MT_MR_CODEC_MOD_PER	('00111101'B),
		RSL_MT_TFO_REP		('00111110'B),
		RSL_MT_TFO_MOD_REQ	('00111111'B),		/* 0x3f */

		RSL_MT_LOCATION_INFO		('01000001'B),

		/* ip.access specific RSL message types */
		RSL_MT_IPAC_DIR_RETR_ENQ	('01000000'B),

		RSL_MT_IPAC_PDCH_ACT		('01001000'B),
		RSL_MT_IPAC_PDCH_ACT_ACK	('01001001'B),
		RSL_MT_IPAC_PDCH_ACT_NACK	('01001010'B),
		RSL_MT_IPAC_PDCH_DEACT		('01001011'B),
		RSL_MT_IPAC_PDCH_DEACT_ACK	('01001100'B),
		RSL_MT_IPAC_PDCH_DEACT_NACK	('01001101'B),

		RSL_MT_IPAC_CONNECT_MUX		('01010000'B),
		RSL_MT_IPAC_CONNECT_MUX_ACK	('01010001'B),
		RSL_MT_IPAC_CONNECT_MUX_NACK	('01010010'B),
		RSL_MT_IPAC_BIND_MUX		('01010011'B),
		RSL_MT_IPAC_BIND_MUX_ACK	('01010100'B),
		RSL_MT_IPAC_BIND_MUX_NACK	('01010101'B),
		RSL_MT_IPAC_DISC_MUX		('01010110'B),
		RSL_MT_IPAC_DISC_MUX_ACK	('01010111'B),
		RSL_MT_IPAC_DISC_MUX_NACK	('01011000'B),
		RSL_MT_IPAC_MEAS_PREPROC_DFT 	('01100000'B),
		RSL_MT_IPAC_HO_CAN_ENQ		('01100001'B),
		RSL_MT_IPAC_HO_CAN_RES		('01100010'B),
		RSL_MT_IPAC_CRCX		('01110000'B),
		RSL_MT_IPAC_CRCX_ACK		('01110001'B),
		RSL_MT_IPAC_CRCX_NACK		('01110010'B),
		RSL_MT_IPAC_MDCX		('01110011'B),
		RSL_MT_IPAC_MDCX_ACK		('01110100'B),
		RSL_MT_IPAC_MDCX_NACK		('01110101'B),
		RSL_MT_IPAC_DLCX_IND		('01110110'B),
		RSL_MT_IPAC_DLCX		('01110111'B),
		RSL_MT_IPAC_DLCX_ACK		('01111000'B),
		RSL_MT_IPAC_DLCX_NACK		('01111001'B),

		RSL_MT_OSMO_ETWS_CMD		('01111111'B)
	} with { variant "FIELDLENGTH(8)" };

	/*! RSL Information Element Identifiers (Chapter 9.3) */
	type enumerated RSL_IE_Type {
		RSL_IE_CHAN_NR			('00000001'B),
		RSL_IE_LINK_IDENT		('00000010'B),
		RSL_IE_ACT_TYPE			('00000011'B),
		RSL_IE_BS_POWER			('00000100'B),
		RSL_IE_CHAN_IDENT		('00000101'B),
		RSL_IE_CHAN_MODE		('00000110'B),
		RSL_IE_ENCR_INFO		('00000111'B),
		RSL_IE_FRAME_NUMBER		('00001000'B),
		RSL_IE_HANDO_REF		('00001001'B),
		RSL_IE_L1_INFO			('00001010'B),
		RSL_IE_L3_INFO			('00001011'B),
		RSL_IE_MS_IDENTITY		('00001100'B),
		RSL_IE_MS_POWER			('00001101'B),
		RSL_IE_PAGING_GROUP		('00001110'B),
		RSL_IE_PAGING_LOAD		('00001111'B),
		RSL_IE_PYHS_CONTEXT		('00010000'B),
		RSL_IE_ACCESS_DELAY		('00010001'B),
		RSL_IE_RACH_LOAD		('00010010'B),
		RSL_IE_REQ_REFERENCE		('00010011'B),
		RSL_IE_RELEASE_MODE		('00010100'B),
		RSL_IE_RESOURCE_INFO		('00010101'B),
		RSL_IE_RLM_CAUSE		('00010110'B),
		RSL_IE_STARTNG_TIME		('00010111'B),
		RSL_IE_TIMING_ADVANCE		('00011000'B),
		RSL_IE_UPLINK_MEAS		('00011001'B),
		RSL_IE_CAUSE			('00011010'B),
		RSL_IE_MEAS_RES_NR		('00011011'B),
		RSL_IE_MSG_ID			('00011100'B),
		/* reserved */
		RSL_IE_SYSINFO_TYPE		('00011110'B),
		RSL_IE_MS_POWER_PARAM		('00011111'B),
		RSL_IE_BS_POWER_PARAM		('00100000'B),
		RSL_IE_PREPROC_PARAM		('00100001'B),
		RSL_IE_PREPROC_MEAS		('00100010'B),
		RSL_IE_IMM_ASS_INFO		('00100011'B),/* Phase 1 (3.6.0), later Full below */
		RSL_IE_SMSCB_INFO		('00100100'B),
		RSL_IE_MS_TIMING_OFFSET		('00100101'B),
		RSL_IE_ERR_MSG			('00100110'B),
		RSL_IE_FULL_BCCH_INFO		('00100111'B),
		RSL_IE_CHAN_NEEDED		('00101000'B),
		RSL_IE_CB_CMD_TYPE		('00101001'B),
		RSL_IE_SMSCB_MSG		('00101010'B),
		RSL_IE_FULL_IMM_ASS_INFO	('00101011'B),
		RSL_IE_SACCH_INFO		('00101100'B),
		RSL_IE_CBCH_LOAD_INFO		('00101101'B),
		RSL_IE_SMSCB_CHAN_INDICATOR	('00101110'B),
		RSL_IE_GROUP_CALL_REF		('00101111'B),
		RSL_IE_CHAN_DESC		('00110000'B),
		RSL_IE_NCH_DRX_INFO		('00110001'B),
		RSL_IE_CMD_INDICATOR		('00110010'B),
		RSL_IE_EMLPP_PRIO		('00110011'B),
		RSL_IE_UIC			('00110100'B),
		RSL_IE_MAIN_CHAN_REF		('00110101'B),
		RSL_IE_MR_CONFIG		('00110110'B),
		RSL_IE_MR_CONTROL		('00110111'B),
		RSL_IE_SUP_CODEC_TYPES		('00111000'B),
		RSL_IE_CODEC_CONFIG		('00111001'B),
		RSL_IE_RTD			('00111010'B),
		RSL_IE_TFO_STATUS		('00111011'B),
		RSL_IE_LLP_APDU			('00111100'B),

		RSL_IE_OSMO_REP_ACCH_CAP	('01100000'B),
		RSL_IE_OSMO_TRAINING_SEQUENCE	('01100001'B),
		RSL_IE_OSMO_TOP_ACCH_CAP	('01100010'B),

		/* ip.access */
		RSL_IE_IPAC_SRTP_CONFIG		('11100000'B),
		RSL_IE_IPAC_PROXY_UDP		('11100001'B),
		RSL_IE_IPAC_BSCMPL_TOUT		('11100010'B),

		RSL_IE_IPAC_REMOTE_IP		('11110000'B),
		RSL_IE_IPAC_REMOTE_PORT		('11110001'B),
		RSL_IE_IPAC_RTP_PAYLOAD		('11110010'B),
		RSL_IE_IPAC_LOCAL_PORT		('11110011'B),
		RSL_IE_IPAC_SPEECH_MODE		('11110100'B),
		RSL_IE_IPAC_LOCAL_IP		('11110101'B),
		RSL_IE_IPAC_CONN_STAT		('11110110'B),
		RSL_IE_IPAC_HO_C_PARMS		('11110111'B),
		RSL_IE_IPAC_CONN_ID		('11111000'B),
		RSL_IE_IPAC_RTP_CSD_FMT		('11111001'B),
		RSL_IE_IPAC_RTP_JIT_BUF		('11111010'B),
		RSL_IE_IPAC_RTP_COMPR		('11111011'B),
		RSL_IE_IPAC_RTP_PAYLOAD2	('11111100'B),
		RSL_IE_IPAC_RTP_MPLEX		('11111101'B),
		RSL_IE_IPAC_RTP_MPLEX_ID	('11111110'B)
	} with { variant "FIELDLENGTH(8)" };

	type record RSL_LV {
		uint8_t		len,
		octetstring	payload
	} with { variant (len) "LENGTHTO(payload)" }

	template (value) RSL_LV ts_RSL_LV(template (value) octetstring pl) := {
		len := 0,
		payload := pl
	}

	template RSL_LV tr_RSL_LV(template octetstring pl) := {
		len := ?,
		payload := pl
	}

	type record RSL_L16V {
		uint16_t	len,
		octetstring	payload
	} with { variant (len) "LENGTHTO(payload)" }

	template (value) RSL_L16V ts_RSL_L16V(template (value) octetstring pl) := {
		len := 0,
		payload := pl
	}

	template RSL_L16V tr_RSL_L16V(template octetstring pl) := {
		len := ?,
		payload := pl
	}

	type record RSL_IE_V {
		uint8_t		val
	}

	/* 9.3.3 */
	type record RSL_IE_ActivationType {
		boolean		reactivation,
		uint4_t		reserved,
		RSL_ActivationAbits a_bits
	};
	type enumerated RSL_ActivationAbits {
		ACT_REL_TO_IMM_ASSIGN		('000'B),
		ACT_REL_TO_NORM_ASSIGN		('001'B),
		ACT_REL_TO_ASYNC_HANDOVER	('010'B),
		ACT_REL_TO_SYNC_HANDOVER	('011'B),
		ACT_REL_TO_ADDL_ASSIGN		('100'B),
		ACT_REL_TO_MSLOT_CONFIG		('101'B),
		ACT_REL_TO_OSMO_PDCH		('111'B)
	} with { variant "FIELDLENGTH(3)" };

	const RSL_IE_ActivationType t_RSL_IE_ActType_IA := {
		reactivation := false,
		reserved := 0,
		a_bits := ACT_REL_TO_IMM_ASSIGN
	}
	const RSL_IE_ActivationType t_RSL_IE_ActType_ASS := {
		reactivation := false,
		reserved := 0,
		a_bits := ACT_REL_TO_NORM_ASSIGN
	}
	const RSL_IE_ActivationType t_RSL_IE_ActType_HO_ASYNC := {
		reactivation := false,
		reserved := 0,
		a_bits := ACT_REL_TO_ASYNC_HANDOVER
	}
	const RSL_IE_ActivationType t_RSL_IE_ActType_HO_SYNC := {
		reactivation := false,
		reserved := 0,
		a_bits := ACT_REL_TO_SYNC_HANDOVER
	}

	/* osmocom-style dynamic PDCH */
	const RSL_IE_ActivationType c_RSL_IE_ActType_PDCH := {
		reactivation := false,
		reserved := 1,
		a_bits := ACT_REL_TO_OSMO_PDCH
	}

	/* 9.3.5 */
	type record RSL_IE_ChannelIdent {
		uint8_t			len,
		/* 3GPP TS 44.018 Channel Description IE (TV) */
		ChannelDescriptionTV	ch_desc,
		/* 3GPP TS 44.018 Mobile Allocation IE (shall be empty) */
		MobileAllocationTLV	ma
	} with { variant (len) "LENGTHTO(ch_desc,ma)" };

	template (value) RSL_IE_ChannelIdent
	ts_RSL_ChannelIdent(template (value) ChannelDescription ch_desc) := {
		len := 0, /* overwritten */
		ch_desc := {
			iei := '64'O,
			v := ch_desc
		},
		/* Shall be included but empty */
		ma := {
			iei := '72'O,
			v := {
				len := 0,
				ma := ''B
			}
		}
	};

	template RSL_IE_ChannelIdent
	tr_RSL_ChannelIdent(template (present) ChannelDescription ch_desc := ?,
			    template (present) MobileAllocationLV ma := ?) := {
		len := ?,
		ch_desc := {
			iei := '64'O,
			v := ch_desc
		},
		/* Shall be included but empty */
		ma := {
			iei := '72'O,
			v := ma
		}
	};

	/* 9.3.6 */
	type enumerated RSL_SpeechDataInd {
		RSL_SPDI_SPEECH		('00000001'B),
		RSL_SPDI_DATA		('00000010'B),
		RSL_SPDI_SIGN		('00000011'B)
	} with { variant "FIELDLENGTH(8)" };
	type enumerated RSL_ChanRateType {
		RSL_CHRT_SDCCH		('00000001'B),
		RSL_CHRT_TCH_F		('00001000'B),
		RSL_CHRT_TCH_H		('00001001'B),
		RSL_CHRT_TCH_F_BD_MSLOT	('00001010'B),
		RSL_CHRT_TCH_F_DL_MSLOT	('00011010'B),
		RSL_CHRT_TCH_F_GROUP	('00011000'B),
		RSL_CHRT_TCH_H_GROUP	('00011001'B),
		RSL_CHRT_TCH_F_BCAST	('00101000'B),
		RSL_CHRT_TCH_H_BCAST	('00101001'B),
		RSL_CHRT_OSMO_TCH_F_VAMOS	('10001000'B),
		RSL_CHRT_OSMO_TCH_H_VAMOS	('10001001'B)
	} with { variant "FIELDLENGTH(8)" };
	type enumerated RSL_SpeechAlgo {
		RSL_CMOD_NO_RESOURCE	('00000000'B),
		RSL_CMOD_SP_GSM1	('00000001'B),
		RSL_CMOD_SP_GSM2	('00010001'B),
		RSL_CMOD_SP_GSM3	('00100001'B),
		RSL_CMOD_SP_GSM4	('00110001'B),
		RSL_CMOD_SP_GSM5	('00001001'B),
		RSL_CMOD_SP_GSM6	('00001101'B)
	} with { variant "FIELDLENGTH(8)" };
	type record RSL_IE_ChannelMode {
		uint8_t		len,
		BIT6		reserved,
		boolean		dtx_d,
		boolean		dtx_u,
		RSL_SpeechDataInd spd_ind,
		RSL_ChanRateType  ch_rate_type,
		RSL_SpeechAlgo	coding_alg_rate
	} with { variant (len) "LENGTHTO(reserved,dtx_d,dtx_u,spd_ind,ch_rate_type,coding_alg_rate)" }

	template (value) RSL_IE_ChannelMode ts_RSL_ChanMode_SIGN(RSL_ChanRateType t := RSL_CHRT_SDCCH,
								 boolean dtx_downlink := false) := {
		len := 0,	/* overwritten */
		reserved := '000000'B,
		dtx_d := dtx_downlink,
		dtx_u := false,
		spd_ind := RSL_SPDI_SIGN,
		ch_rate_type := t,
		coding_alg_rate := RSL_CMOD_NO_RESOURCE
	}

	template (value) RSL_IE_ChannelMode ts_RSL_ChanMode(RSL_ChanRateType t, RSL_SpeechAlgo alg,
							    boolean dtx_downlink := false) := {
		len := 0,	/* overwritten */
		reserved := '000000'B,
		dtx_d := dtx_downlink,
		dtx_u := false,
		spd_ind := RSL_SPDI_SPEECH,
		ch_rate_type := t,
		coding_alg_rate := alg
	}
	template RSL_IE_ChannelMode tr_RSL_ChanMode(template RSL_ChanRateType t,
						    template RSL_SpeechAlgo alg) := {
		len := ?,
		reserved := '000000'B,
		dtx_d := ?,
		dtx_u := ?,
		spd_ind := RSL_SPDI_SPEECH,
		ch_rate_type := t,
		coding_alg_rate := alg
	}

	/* 9.3.4 BS Power IE */
	type record RSL_IE_BS_Power {
		uint2_t 	reserved,
		boolean		epc,
		boolean		fpc,
		uint4_t		power_level
	}

	template (value) RSL_IE_BS_Power ts_RSL_IE_BS_Power(uint4_t power_level,
							    boolean epc := false, boolean fpc := false) := {
		reserved := 0,
		epc := epc,
		fpc := fpc,
		power_level := power_level
	}
	template RSL_IE_BS_Power
	tr_RSL_IE_BS_Power(template (present) uint4_t power_level,
			   template (present) boolean epc := ?,
			   template (present) boolean fpc := ?) := {
		reserved := ?,
		epc := epc,
		fpc := fpc,
		power_level := power_level
	}

	/* 9.3.7 */
	type enumerated RSL_AlgId {
		RSL_ALG_ID_A5_0 ('00000001'B),
		RSL_ALG_ID_A5_1 ('00000010'B),
		RSL_ALG_ID_A5_2 ('00000011'B),
		RSL_ALG_ID_A5_3 ('00000100'B),
		RSL_ALG_ID_A5_4 ('00000101'B),
		RSL_ALG_ID_A5_5 ('00000110'B),
		RSL_ALG_ID_A5_6 ('00000111'B),
		RSL_ALG_ID_A5_7 ('00001000'B)
	} with { variant "FIELDLENGTH(8)" };
	type record RSL_IE_EncryptionInfo {
		uint8_t		len,
		RSL_AlgId	alg_id,
		octetstring	key
	} with { variant (len) "LENGTHTO(alg_id,key)" };

	template RSL_IE_EncryptionInfo tr_RSL_IE_EncrInfo(template RSL_AlgId alg,
							  template octetstring key) := {
		len := ?,
		alg_id := alg,
		key := key
	}
	template (value) RSL_IE_EncryptionInfo ts_RSL_IE_EncrInfo(template (value) RSL_AlgId alg,
								  octetstring key) := {
		len := 0, /* overwritten */
		alg_id := alg,
		key := key
	}



	/* 9.3.8 */
	type record RSL_IE_FrameNumber {
		uint5_t		t1_p,
		uint6_t		t3,
		uint5_t		t2
	}
	type RSL_IE_FrameNumber RSL_IE_StartingTime;

	/* 9.3.10 */
	type record RSL_IE_L1Info {
		uint5_t		ms_power_lvl,
		boolean		fpc,
		uint2_t		reserved,
		uint8_t		actual_ta
	}

	template (value) RSL_IE_L1Info ts_RSL_IE_L1Info := {
		ms_power_lvl := 0,
		fpc := false,
		reserved := 0,
		actual_ta := 0
	};

	/* 9.3.13 */
	type record RSL_IE_MS_Power {
		uint2_t		reserved,
		boolean		fpc_epc,
		uint5_t		power_level
	}
	template RSL_IE_MS_Power tr_RSL_IE_MS_Power(template uint5_t power_level := ?,
							    template boolean fpc_epc := false) := {
		reserved := 0,
		fpc_epc := fpc_epc,
		power_level := power_level
	}
	template (value) RSL_IE_MS_Power ts_RSL_IE_MS_Power(uint5_t power_level,
							    boolean fpc_epc := false) := {
		reserved := 0,
		fpc_epc := fpc_epc,
		power_level := power_level
	}

	/* 9.3.18 */
	type record RSL_IE_RachLoad {
		uint8_t		len,
		uint16_t	slot_count,
		uint16_t	busy_count,
		uint16_t	access_count
	} with { variant (len) "LENGTHTO(slot_count,busy_count,access_count)" }

	template (value) RSL_IE_RachLoad ts_RSL_IE_RachLoad(uint16_t slot, uint16_t busy, uint16_t acc) := {
		len := 0, /* overwritten */
		slot_count := slot,
		busy_count := busy,
		access_count := acc
	}

	template RSL_IE_RachLoad tr_RSL_IE_RachLoad(template uint16_t slot,
						    template uint16_t busy,
						    template uint16_t acc) := {
		len := ?, /* overwritten */
		slot_count := slot,
		busy_count := busy,
		access_count := acc
	}

	/* 9.3.19 */
	type record RSL_IE_RequestRef {
		OCT1		ra,
		RSL_IE_FrameNumber frame_nr
	}

	/* 3GPP TS 44.018 / 10.5.2.38 Starting Time */
	template (value) RSL_IE_FrameNumber ts_RSL_IE_FrameNumber(GsmFrameNumber fn) := {
		t1_p := (fn / 1326) mod 32,
		t3 := fn mod 51,
		t2 := fn mod 26
	}

	function tr_RSL_IE_FrameNumber(template GsmFrameNumber fn) return template RSL_IE_FrameNumber {
		if (istemplatekind(fn, "?")) {
			return ?;
		} else {
			return ts_RSL_IE_FrameNumber(valueof(fn));
		}
	}

	template (value) RSL_IE_RequestRef ts_RSL_IE_ReqRef(OCT1 ra, GsmFrameNumber frame_nr) := {
		ra := ra,
		frame_nr := ts_RSL_IE_FrameNumber(frame_nr)
	}

	template RSL_IE_RequestRef tr_RSL_IE_ReqRef(template OCT1 ra, template GsmFrameNumber frame_nr) := {
		ra := ra,
		frame_nr := tr_RSL_IE_FrameNumber(frame_nr)
	}

	/* 9.3.21 Resource Information */
	type record RSL_IE_ResourceInfo {
		uint8_t len,
		RSL_ResourceInfo info
	} with { variant (len) "LENGTHTO(info)" };

	type record of RSL_ResourceInfoItem RSL_ResourceInfo;
	type record RSL_ResourceInfoItem {
		RslChannelNr chan_nr,
		uint3_t interf_band,
		BIT5 rfu ('00000'B)
	};

	template (value) RSL_ResourceInfoItem
	ts_RSL_ResourceInfoItem(template (value) RslChannelNr chan_nr,
				template (value) uint3_t interf_band := 0) := {
		chan_nr := chan_nr,
		interf_band := interf_band,
		rfu := '00000'B
	}
	template RSL_ResourceInfoItem
	tr_RSL_ResourceInfoItem(template (present) RslChannelNr chan_nr := ?,
				template (present) uint3_t interf_band := ?) := {
		chan_nr := chan_nr,
		interf_band := interf_band,
		rfu := ? /* Tolerate unknown values */
	}

	/* Osmocom Extension */
	type record RSL_IE_UplinkMeasSuppMeasInfo {
		int16_t toa256_mean,
		int16_t toa256_min,
		int16_t toa256_max,
		uint16_t toa256_std_dev
	};

	/* 9.3.25 */
	type record RSL_IE_UplinkMeas {
		uint8_t len,
		BIT1 rfu,
		boolean dtx_d,
		uint6_t rxlev_f_u,
		BIT2 reserved1,
		uint6_t rxlev_s_u,
		BIT2 reserved2,
		uint3_t rxq_f_u,
		uint3_t rxq_s_u,
		RSL_IE_UplinkMeasSuppMeasInfo supp_meas_info optional
	} with { variant (len) "LENGTHTO(rfu,dtx_d,rxlev_f_u,reserved1,rxlev_s_u,reserved2,rxq_f_u,rxq_s_u,supp_meas_info)" };

	template (value) RSL_IE_UplinkMeas ts_RSL_IE_UplinkMeas(uint6_t rxlev := 12, uint3_t rxqual := 0) := {
		len := 0, /* overwritten */
		rfu := '0'B,
		dtx_d := false,
		rxlev_f_u := rxlev,
		reserved1 := '00'B,
		rxlev_s_u := rxlev,
		reserved2 := '00'B,
		rxq_f_u := rxqual,
		rxq_s_u := rxqual,
		supp_meas_info := omit
	};

	/* 9.3.26 */
	type enumerated RSL_Cause {
		/* normal event */
		RSL_ERR_RADIO_IF_FAIL		('00'O),
		RSL_ERR_RADIO_LINK_FAIL		('01'O),
		RSL_ERR_HANDOVER_ACC_FAIL	('02'O),
		RSL_ERR_TALKER_ACC_FAIL		('03'O),
		RSL_ERR_OM_INTERVENTION		('07'O),
		RSL_ERR_NORMAL_UNSPEC		('0f'O),
		RSL_ERR_T_MSRFPCI_EXP		('18'O),
		/* resource unavailable */
		RSL_ERR_EQUIPMENT_FAIL		('20'O),
		RSL_ERR_RR_UNAVAIL		('21'O),
		RSL_ERR_TERR_CH_FAIL		('22'O),
		RSL_ERR_CCCH_OVERLOAD		('23'O),
		RSL_ERR_ACCH_OVERLOAD		('24'O),
		RSL_ERR_PROCESSOR_OVERLOAD	('25'O),
		RSL_ERR_BTS_NOT_EQUIPPED	('27'O),
		RSL_ERR_REMOTE_TRAU_FAILURE	('28'O),
		RSL_ERR_NOTIF_OVERFLOW		('29'O),
		RSL_ERR_RES_UNAVAIL		('2f'O),
		/* service or option not available */
		RSL_ERR_TRANSC_UNAVAIL		('30'O),
		RSL_ERR_SERV_OPT_UNAVAIL	('3f'O),
		/* service or option not implemented */
		RSL_ERR_ENCR_UNIMPL		('40'O),
		RSL_ERR_SERV_OPT_UNIMPL		('4f'O),
		/* invalid message */
		RSL_ERR_RCH_ALR_ACTV_ALLOC	('50'O),
		RSL_ERR_IPA_RCH_NOT_ACTV_ALLOC	('51'O),
		RSL_ERR_IPA_CONN_INVALID	('52'O),
		RSL_ERR_IPA_CONN_IN_USE		('53'O),
		RSL_ERR_IPA_CONN_ALREADY_EXISTS	('54'O),
		RSL_ERR_INVALID_MESSAGE		('5f'O),
		/* protocol error */
		RSL_ERR_MSG_DISCR		('60'O),
		RSL_ERR_MSG_TYPE		('61'O),
		RSL_ERR_MSG_SEQ			('62'O),
		RSL_ERR_IE_ERROR		('63'O),
		RSL_ERR_MAND_IE_ERROR		('64'O),
		RSL_ERR_OPT_IE_ERROR		('65'O),
		RSL_ERR_IE_NONEXIST		('66'O),
		RSL_ERR_IE_LENGTH		('67'O),
		RSL_ERR_IE_CONTENT		('68'O),
		RSL_ERR_PROTO			('6f'O),
		/* interworking */
		RSL_ERR_INTERWORKING		('7f'O)
	};
	type record RSL_IE_Cause {
		uint8_t		len,
		uint1_t		e,
		RSL_Cause	cause,
		octetstring	cause_ext optional
	} with { variant (len) "LENGTHTO(e,cause,cause_ext)" }

	template (value) RSL_IE_Cause ts_RSL_IE_Cause(RSL_Cause cause) := {
		len := 0, /* overwritten */
		e := 0,
		cause := cause,
		cause_ext := omit
	}

	template RSL_IE_Cause tr_RSL_IE_Cause(template RSL_Cause cause) := {
		len := ?,
		e := 0,
		cause := cause,
		cause_ext := omit
	}

	/* 9.3.29 */
	type record RSL_SacchInfo {
		uint8_t len,
		uint8_t num_msgs,
		RSL_SacchInfoElements elems
	} with {
		variant (len) "LENGTHTO(num_msgs,elems)";
		variant (num_msgs) "LENGTHTO(elems)";
		variant (num_msgs) "UNIT(elements)"
	};
	type record RSL_SacchInfoElement {
		RSL_IE_SysinfoType si_type,
		uint8_t len,
		octetstring msg
	} with {
		variant (len) "LENGTHTO(msg)";
	};
	type record of RSL_SacchInfoElement RSL_SacchInfoElements;
	template (value) RSL_SacchInfo ts_RSL_SacchInfo(template (value) RSL_SacchInfoElements elems) := {
		len := 0, /* overwritten */
		num_msgs := 0, /* overwritten */
		elems := elems
	}
	template (value) RSL_SacchInfoElement ts_RSL_SacchInfoElem(RSL_IE_SysinfoType tp, octetstring msg) := {
		si_type := tp,
		len := lengthof(msg),
		msg := msg
	}

	/* 9.3.31 */
	type record RSL_IE_MS_Power_Parameters {
		uint8_t len,
		octetstring params
	} with {
		variant (len) "LENGTHTO(params)";
	};
	template (value) RSL_IE_MS_Power_Parameters ts_RSL_IE_MS_Power_Parameters(octetstring params) := {
		len := 0, /* overwritten */
		params := params
	}

	/* 9.3.40 */
	type enumerated RSL_ChanNeeded {
		RSL_CHANNEED_ANY	('00'B),
		RSL_CHANNEED_SDCCH	('01'B),
		RSL_CHANNEED_TCH_F	('10'B),
		RSL_CHANNEED_TCH_ForH	('11'B)
	} with { variant "FIELDLENGTH(2)" };
	type record RSL_IE_ChanNeeded {
		uint6_t		reserved,
		RSL_ChanNeeded	chan_needed
	}

	/* 9.3.41 CB Command Type */
	type enumerated RSL_CbCommand {
		RSL_CB_CMD_NORMAL	('0000'B),
		RSL_CB_CMD_SCHEDULE	('1000'B),
		RSL_CB_CMD_DEFAULT	('1110'B),
		RSL_CB_CMD_NULL		('1111'B)
	} with { variant "FIELDLENGTH(4)" };
	type record RSL_IE_CbCommandType {
		RSL_CbCommand	command,
		boolean		default_bcast_null,
		BIT1		spare,
		uint2_t		last_block
	};
	template (value) RSL_IE_CbCommandType ts_RSL_IE_CbCmdType(RSL_CbCommand cmd := RSL_CB_CMD_NORMAL,
								  uint2_t last_block := 1,
								  boolean def_bcast_null := true) := {
		command := cmd,
		default_bcast_null := def_bcast_null,
		spare := '0'B,
		last_block := last_block
	}

	/* 9.4.43 CBCH Load Information */
	type record RSL_IE_CbchLoadInfo {
		boolean		overflow,
		BIT3		spare,
		uint4_t		slot_count
	};
	template RSL_IE_CbchLoadInfo tr_CbchLoadInfo(template boolean overflow,
					    template uint4_t slot_count) := {
		overflow := overflow,
		spare := ?,
		slot_count := slot_count
	}
	template (value) RSL_IE_CbchLoadInfo ts_CbchLoadInfo(boolean overflow, uint4_t slot_count) := {
		overflow := overflow,
		spare := '000'B,
		slot_count := slot_count
	}

	/* 9.3.53 */
	type record RSL_IE_MultirateCtrl {
		uint3_t		spare,
		boolean		od,
		boolean		pre,
		uint2_t		rae,
		boolean		tfo
	}

	type enumerated RSL_IE_SysinfoType {
		RSL_SYSTEM_INFO_8	('00000000'B),
		RSL_SYSTEM_INFO_1	('00000001'B),
		RSL_SYSTEM_INFO_2	('00000010'B),
		RSL_SYSTEM_INFO_3	('00000011'B),
		RSL_SYSTEM_INFO_4	('00000100'B),
		RSL_SYSTEM_INFO_5	('00000101'B),
		RSL_SYSTEM_INFO_6	('00000110'B),
		RSL_SYSTEM_INFO_7	('00000111'B),
		RSL_SYSTEM_INFO_16	('00001000'B),
		RSL_SYSTEM_INFO_17	('00001001'B),
		RSL_SYSTEM_INFO_2bis	('00001010'B),
		RSL_SYSTEM_INFO_2ter	('00001011'B),
		RSL_SYSTEM_INFO_5bis	('00001101'B),
		RSL_SYSTEM_INFO_5ter	('00001110'B),
		RSL_SYSTEM_INFO_10	('00001111'B),
		RSL_EXT_MEAS_ORDER	('01000111'B),
		RSL_MEAS_INFO		('01001000'B),
		RSL_SYSTEM_INFO_13	('00101000'B),
		RSL_ERIC_SYSTEM_INFO_13 ('00001100'B),
		RSL_SYSTEM_INFO_2quater ('00101001'B),
		RSL_SYSTEM_INFO_9	('00101010'B),
		RSL_SYSTEM_INFO_18	('00101011'B),
		RSL_SYSTEM_INFO_19	('00101100'B),
		RSL_SYSTEM_INFO_20	('00101101'B)
	} with { variant "FIELDLENGTH(8)" }

	type record RSL_IE_IPA_ConnectionStats {
		uint8_t			len,
		uint32_t		tx_packets,
		uint32_t		tx_octets,
		uint32_t		rx_packets,
		uint32_t		rx_octets,
		uint32_t		lost_packets,
		uint32_t		jitter,
		uint32_t		avg_delay
	} with { variant (len) "LENGTHTO(tx_packets,tx_octets,rx_packets,rx_octets,lost_packets,jitter,avg_delay)" }

	type enumerated RSL_IPA_SpeechMode {
		RSL_IPA_SPM_SENDRECV	('00'B),
		RSL_IPA_SPM_RECVONLY	('01'B),
		RSL_IPA_SPM_SENDONLY	('10'B),
		RSL_IPA_SPM_RESERVED	('11'B)
	} with { variant "FIELDLENGTH(2)" }

	type enumerated RSL_IPA_Codec {
		RSL_IPA_CODEC_FR	('0000'B),
		RSL_IPA_CODEC_EFR	('0001'B),
		RSL_IPA_CODEC_AMR_F	('0010'B),
		RSL_IPA_CODEC_HR	('0011'B),
		RSL_IPA_CODEC_AMR_H	('0101'B),
		RSL_IPA_CODEC_RTP_PT	('1111'B)
	} with { variant "FIELDLENGTH(4)" }

	type record RSL_IE_IPA_SpeechMode {
		BIT2			reserved,
		RSL_IPA_SpeechMode	mode,
		RSL_IPA_Codec		codec
	}

	/* 9.3.20 */
	type enumerated RSL_IE_ReleaseMode {
		RSL_REL_MODE_NORMAL	('00'B),
		REL_REL_MODE_LOCAL	('01'B)
	}

	type record RSL_IE_OSMO_TrainingSequence {
		uint8_t			len,
		uint8_t			tsc_set,
		uint8_t			tsc
	} with { variant (len) "LENGTHTO(tsc_set,tsc)" }

	type record RSL_IE_OSMO_RepAcchCap {
		uint8_t			len,
		BIT1			rfu ('0'B),
		uint3_t			rxqual,
		boolean			ul_sacch,
		boolean			dl_sacch,
		boolean			dl_facch_all,
		boolean			dl_facch_cmd
	} with { variant (len) "LENGTHTO(rfu,rxqual,ul_sacch,dl_sacch,dl_facch_all,dl_facch_cmd)" }

	type record RSL_IE_OSMO_TopAcchCap {
		uint8_t			len,
		boolean			sacch_enable,
		boolean			facch_enable,
		uint3_t			rxqual,
		uint3_t			overpower_db
	} with { variant (len) "LENGTHTO(sacch_enable,facch_enable,rxqual,overpower_db)" }

	template (value) RSL_IE_OSMO_TopAcchCap
	ts_RSL_IE_OSMO_TopAcchCap(template (value) uint3_t overpower := 2,
				  template (value) uint3_t rxqual := 4,
				  boolean facch_enable := true,
				  boolean sacch_enable := true) := {
		len := 0, /* overwritten */
		sacch_enable := sacch_enable,
		facch_enable := facch_enable,
		rxqual := rxqual,
		overpower_db := overpower
	};
	template RSL_IE_OSMO_TopAcchCap
	tr_RSL_IE_OSMO_TopAcchCap(template (present) uint3_t overpower := ?,
				  template (present) uint3_t rxqual := ?,
				  template (present) boolean facch_enable := ?,
				  template (present) boolean sacch_enable := ?) := {
		len := ?, /* overwritten */
		sacch_enable := sacch_enable,
		facch_enable := facch_enable,
		rxqual := rxqual,
		overpower_db := overpower
	};

	/* union of all IE bodies */
	type union RSL_IE_Body {
		RslChannelNr		chan_nr,
		RslLinkId		link_id,
		RSL_L16V		l3_info,
		RSL_LV			rlm_cause,
		RSL_IE_ReleaseMode	release_mode,
		RSL_IE_ActivationType	act_type,
		RSL_IE_ChannelIdent	chan_ident,
		RSL_IE_ChannelMode	chan_mode,
		uint8_t			handover_ref,
		RSL_IE_BS_Power		bs_power,
		RSL_LV			bs_power_params,
		RSL_IE_MS_Power		ms_power,
		RSL_IE_MS_Power_Parameters ms_power_params,
		uint8_t			timing_adv,
		RSL_IE_MultirateCtrl	multirate_ctrl,
		uint8_t			msg_id,
		RSL_IE_FrameNumber	frame_nr,
		RSL_IE_Cause		cause,
		uint8_t			access_delay,
		RSL_IE_RachLoad		rach_load,
		uint8_t			meas_res_nr,
		uint8_t			ms_timing_offset,
		RSL_IE_UplinkMeas	uplink_meas,
		RSL_IE_L1Info		l1_info,
		RSL_IE_SysinfoType	sysinfo_type,
		uint16_t		paging_load,
		uint8_t			paging_group,
		RSL_IE_ChanNeeded	chan_needed,
		RSL_IE_CbCommandType	cb_cmd_type,
		RSL_LV			smscb_message,
		RSL_IE_CbchLoadInfo	cbch_load_info,
		RSL_IE_ResourceInfo	resource_info,
		RSL_SacchInfo		sacch_info,

		RSL_IE_StartingTime	starting_time,
		RSL_IE_EncryptionInfo	encr_info,
		uint8_t			smscb_chan_ind,
		RSL_IE_RequestRef	req_ref,
		RSL_LV			full_imm_ass_info,
		MobileIdentityLV	ms_identity,

		uint16_t		ipa_conn_id,
		uint16_t		ipa_local_port,
		uint16_t		ipa_remote_port,
		OCT4			ipa_local_ip,
		OCT4			ipa_remote_ip,
		uint8_t			ipa_rtp_pt,
		uint8_t			ipa_rtp_pt2,
		RSL_IE_IPA_ConnectionStats ipa_stats,
		RSL_IE_IPA_SpeechMode	ipa_speech_mode,

		RSL_IE_OSMO_TrainingSequence osmo_training_sequence,
		RSL_IE_OSMO_RepAcchCap	rep_acch_cap,
		RSL_IE_OSMO_TopAcchCap	top_acch_cap,

		RSL_LV		other
	}

	type record RSL_IE {
		RSL_IE_Type	iei,
		RSL_IE_Body	body
	} with { variant (body) "CROSSTAG(
					chan_nr, iei = RSL_IE_CHAN_NR;
					link_id, iei = RSL_IE_LINK_IDENT;
					l3_info, iei = RSL_IE_L3_INFO;
					rlm_cause, iei = RSL_IE_RLM_CAUSE;
					release_mode, iei = RSL_IE_RELEASE_MODE;
					act_type, iei = RSL_IE_ACT_TYPE;
					chan_ident, iei = RSL_IE_CHAN_IDENT;
					chan_mode, iei = RSL_IE_CHAN_MODE;
					handover_ref, iei = RSL_IE_HANDO_REF;
					bs_power, iei = RSL_IE_BS_POWER;
					bs_power_params, iei = RSL_IE_BS_POWER_PARAM;
					ms_power, iei = RSL_IE_MS_POWER;
					ms_power_params, iei = RSL_IE_MS_POWER_PARAM;
					timing_adv, iei = RSL_IE_TIMING_ADVANCE;
					multirate_ctrl, iei = RSL_IE_MR_CONTROL;
					msg_id, iei = RSL_IE_MSG_ID;

					frame_nr, iei = RSL_IE_FRAME_NUMBER;
					cause, iei = RSL_IE_CAUSE;
					access_delay, iei = RSL_IE_ACCESS_DELAY;
					rach_load, iei = RSL_IE_RACH_LOAD;
					meas_res_nr, iei = RSL_IE_MEAS_RES_NR;
					ms_timing_offset, iei = RSL_IE_MS_TIMING_OFFSET;
					uplink_meas, iei = RSL_IE_UPLINK_MEAS;
					l1_info, iei = RSL_IE_L1_INFO;
					sysinfo_type, iei = RSL_IE_SYSINFO_TYPE;
					paging_load, iei = RSL_IE_PAGING_LOAD;
					paging_group, iei = RSL_IE_PAGING_GROUP;
					chan_needed, iei = RSL_IE_CHAN_NEEDED;
					cb_cmd_type, iei = RSL_IE_CB_CMD_TYPE;
					smscb_message, iei = RSL_IE_SMSCB_MSG;
					cbch_load_info, iei = RSL_IE_CBCH_LOAD_INFO;
					resource_info, iei = RSL_IE_RESOURCE_INFO;
					sacch_info, iei = RSL_IE_SACCH_INFO;
					starting_time, iei = RSL_IE_STARTNG_TIME;
					encr_info, iei = RSL_IE_ENCR_INFO;
					smscb_chan_ind, iei = RSL_IE_SMSCB_CHAN_INDICATOR;

					req_ref, iei = RSL_IE_REQ_REFERENCE;
					full_imm_ass_info, iei = RSL_IE_FULL_IMM_ASS_INFO;
					ms_identity, iei =  RSL_IE_MS_IDENTITY;
					other, iei = RSL_IE_FULL_BCCH_INFO;

					ipa_conn_id, iei = RSL_IE_IPAC_CONN_ID;
					ipa_remote_ip, iei = RSL_IE_IPAC_REMOTE_IP;
					ipa_remote_port, iei = RSL_IE_IPAC_REMOTE_PORT;
					ipa_local_ip, iei = RSL_IE_IPAC_LOCAL_IP;
					ipa_local_port, iei = RSL_IE_IPAC_LOCAL_PORT;
					ipa_rtp_pt, iei = RSL_IE_IPAC_RTP_PAYLOAD;
					ipa_rtp_pt2, iei = RSL_IE_IPAC_RTP_PAYLOAD2;
					ipa_stats, iei = RSL_IE_IPAC_CONN_STAT;
					ipa_speech_mode, iei = RSL_IE_IPAC_SPEECH_MODE;

					osmo_training_sequence, iei = RSL_IE_OSMO_TRAINING_SEQUENCE;
					rep_acch_cap, iei = RSL_IE_OSMO_REP_ACCH_CAP;
					top_acch_cap, iei = RSL_IE_OSMO_TOP_ACCH_CAP;

					other, OTHERWISE;
		)" };

	/* For some reason the TTCN-3 RAW codec cannot automatically figure out the IEI
	 * that it needs to set for a given union-choice (body).  So we have to explicitly
	 * specify the IEI by the caller :( */
	template (value) RSL_IE t_RSL_IE(RSL_IE_Type iei, template (value) RSL_IE_Body body) := {
		iei := iei,
		body := body
	}

	template RSL_IE tr_RSL_IE(template RSL_IE_Body body) := {
		iei := ?, /* overwritten? */
		body := body
	}


	type record of RSL_IE RSL_IE_List;

	type record RSL_Message {
		RSL_MessageDiscriminator	msg_disc,
		RSL_MessageType			msg_type,
		RSL_IE_List			ies optional
	}

	external function enc_RSL_Message(in RSL_Message msg) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_RSL_Message(in octetstring stream) return RSL_Message
		with { extension "prototype(convert) decode(RAW)" };

	template RSL_Message tr_RSL_MsgDiscType(template RSL_MessageDiscriminator m_disc,
				RSL_MessageType m_type) := {
		msg_disc := m_disc,
		msg_type := m_type,
		ies := *
	}

	template (value) RSL_Message ts_RSL_MsgDiscType(template (value) RSL_MessageDiscriminator m_disc,
							template (value) RSL_MessageType msg_type,
							template (omit) RSL_IE_List ies := omit) := {
		msg_disc := m_disc,
		msg_type := msg_type,
		ies := ies
	}

template RSL_Message tr_RSL_MsgType(template RSL_MessageType msg_type) := {
	msg_disc := ?,
	msg_type := msg_type,
	ies := *
}

/* Common Channel Management */
template RSL_Message tr_RSL_MsgTypeC(template RSL_MessageType msg_type) modifies tr_RSL_MsgType := {
	msg_disc := { RSL_MDISC_CCHAN, ? }
}

/* RLL */
template RSL_Message tr_RSL_MsgTypeR(template RSL_MessageType msg_type) modifies tr_RSL_MsgType := {
	msg_disc := { RSL_MDISC_RLL, true }
}

/* Dedicated Channel Management */
template RSL_Message tr_RSL_MsgTypeD(template RSL_MessageType msg_type) modifies tr_RSL_MsgType := {
	msg_disc := { RSL_MDISC_DCHAN, ? }
}

/* Dedicated Channel Management */
template RSL_Message tr_RSL_MsgTypeT(template RSL_MessageType msg_type) modifies tr_RSL_MsgType := {
	msg_disc := { RSL_MDISC_TRX_MGMT, ? }
}


/* dedicated channel or RLL */
template RSL_Message tr_RSL_MsgTypeDR(template RSL_MessageType msg_type) modifies tr_RSL_MsgType := {
	msg_disc := ({RSL_MDISC_DCHAN,?}, {RSL_MDISC_RLL,?}, {RSL_MDISC_IPACCESS,false})
}


	/* 8.3.1 BSC -> BTS */
	template (value) RSL_Message ts_RSL_DATA_REQ(template (value) RslChannelNr chan_nr,
						     template (value) RslLinkId link_id,
						     octetstring l3_info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, true),
		msg_type := RSL_MT_DATA_REQ,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id}),
			t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := ts_RSL_L16V(l3_info)})
		}
	}

	template RSL_Message tr_RSL_DATA_REQ(template RslChannelNr chan_nr :=?,
					     template RslLinkId link_id := ?,
					     template octetstring l3_info := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, true),
		msg_type := RSL_MT_DATA_REQ,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
		}
	}


	/* 8.3.2 BTS -> BSC */
	template (value) RSL_Message ts_RSL_DATA_IND(template (value) RslChannelNr chan_nr,
						     template (value) RslLinkId link_id,
						     octetstring l3_info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, true),
		msg_type := RSL_MT_DATA_IND,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id}),
			t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := ts_RSL_L16V(l3_info)})
		}
	}
	template RSL_Message tr_RSL_DATA_IND(template RslChannelNr chan_nr, template RslLinkId link_id,
					     template octetstring l3_info := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, true),
		msg_type := RSL_MT_DATA_IND,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
		}
	}

	/* 8.3.3 BTS -> BSC */
	template (value) RSL_Message ts_RSL_ERROR_IND(template (value) RslChannelNr chan_nr,
						      template (value) RslLinkId link_id,
						      template (value) octetstring rlm_cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_ERROR_IND,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{rlm_cause := ts_RSL_LV(rlm_cause)})
		}
	}
	template RSL_Message tr_RSL_ERROR_IND(template RslChannelNr chan_nr, template RslLinkId link_id,
					      template octetstring rlm_cause := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_ERROR_IND,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
			tr_RSL_IE(RSL_IE_Body:{rlm_cause := tr_RSL_LV(rlm_cause)})
		}
	}

	/* 8.3.4 BTS <- BSC */
	template (value) RSL_Message ts_RSL_EST_REQ(template (value) RslChannelNr chan_nr,
						    template (value) RslLinkId link_id) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_EST_REQ,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id})
		}
	}
	template RSL_Message tr_RSL_EST_REQ(template RslChannelNr chan_nr, template RslLinkId link_id) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_EST_REQ,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id})
		}
	}

	/* 8.3.5 BTS -> BSC */
	template (value) RSL_Message ts_RSL_EST_CONF(template (value) RslChannelNr chan_nr,
						     template (value) RslLinkId link_id) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_EST_CONF,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id})
		}
	}
	template RSL_Message tr_RSL_EST_CONF(template RslChannelNr chan_nr, template RslLinkId link_id) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_EST_CONF,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id})
		}
	}

	/* 8.3.6 BTS -> BSC */
	template (value) RSL_Message ts_RSL_EST_IND(template (value) RslChannelNr chan_nr,
						    template (value) RslLinkId link_id,
						    octetstring l3_info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_EST_IND,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id}),
			t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := ts_RSL_L16V(l3_info)})
		}
	}
	template RSL_Message tr_RSL_EST_IND(template RslChannelNr chan_nr, template RslLinkId link_id,
						template octetstring l3_info := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_EST_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
		}
	}
	template RSL_Message tr_RSL_EST_IND_NOL3(template RslChannelNr chan_nr, template RslLinkId link_id) :=
{
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_EST_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id})
		}
	}


	/* 8.3.7 BSC -> BTS */
	template (value) RSL_Message ts_RSL_REL_REQ(template (value) RslChannelNr chan_nr,
						    template (value) RslLinkId link_id,
						    template (value) RSL_IE_ReleaseMode rel_mode := RSL_REL_MODE_NORMAL) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_REL_REQ,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id}),
			t_RSL_IE(RSL_IE_RELEASE_MODE, RSL_IE_Body:{release_mode := rel_mode})
		}
	}
	template RSL_Message tr_RSL_REL_REQ(template RslChannelNr chan_nr,
					    template RslLinkId link_id,
					    template RSL_IE_ReleaseMode rel_mode := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_REL_REQ,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
			tr_RSL_IE(RSL_IE_Body:{release_mode := rel_mode})
		}
	}

	/* 8.3.8 BTS -> BSC */
	template (value) RSL_Message ts_RSL_REL_CONF(template (value) RslChannelNr chan_nr,
						     template (value) RslLinkId link_id) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_REL_CONF,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id})
		}
	}
	template RSL_Message tr_RSL_REL_CONF(template RslChannelNr chan_nr, template RslLinkId link_id) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_REL_CONF,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id})
		}
	}

	/* 8.3.9 BTS -> BSC */
	template (value) RSL_Message ts_RSL_REL_IND(template (value) RslChannelNr chan_nr,
						    template (value) RslLinkId link_id) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_REL_IND,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id})
		}
	}
	template RSL_Message tr_RSL_REL_IND(template RslChannelNr chan_nr, template RslLinkId link_id) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_RLL, false),
		msg_type := RSL_MT_REL_IND,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id})
		}
	}

	/* 8.3.10 BSC -> BTS */
	template (value) RSL_Message ts_RSL_UNITDATA_REQ(template (value) RslChannelNr chan_nr,
							 template (value) RslLinkId link_id,
							 octetstring l3_info)
	modifies ts_RSL_DATA_REQ := {
		msg_type := RSL_MT_UNIT_DATA_REQ
	}
	template RSL_Message tr_RSL_UNITDATA_REQ(template RslChannelNr chan_nr,
						 template RslLinkId link_id,
						 template octetstring l3_info := ?)
	modifies tr_RSL_DATA_REQ := {
		msg_type := RSL_MT_UNIT_DATA_REQ
	}


	/* 8.3.11 BTS -> BSC */
	template (value) RSL_Message ts_RSL_UNITDATA_IND(template (value) RslChannelNr chan_nr,
							 template (value) RslLinkId link_id,
							 octetstring l3_info)
	modifies ts_RSL_DATA_IND := {
		msg_type := RSL_MT_UNIT_DATA_IND
	}
	template RSL_Message tr_RSL_UNITDATA_IND(template RslChannelNr chan_nr,
						 template RslLinkId link_id,
						 template octetstring l3_info := ?)
	modifies tr_RSL_DATA_IND := {
		msg_type := RSL_MT_UNIT_DATA_IND
	}




	/* DEDICATED CANNEL MANAGEMENT MESSAGES */

	/* 8.4.1 BSC -> BTS */
	template (value) RSL_Message ts_RSL_CHAN_ACT(template (value) RslChannelNr chan_nr,
						     template (value) RSL_IE_ChannelMode mode,
						     template (value) RSL_IE_ActivationType at := t_RSL_IE_ActType_IA) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_ACT_TYPE, RSL_IE_Body:{act_type := at}),
			t_RSL_IE(RSL_IE_CHAN_MODE, RSL_IE_Body:{chan_mode := mode})
			/* lots of optional IEs */
		}
	}
	template RSL_Message tr_RSL_CHAN_ACT(template RslChannelNr chan_nr,
					     template RSL_IE_ChannelMode mode,
					     template (value) RSL_IE_ActivationType at := t_RSL_IE_ActType_IA) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{act_type := at}),
			tr_RSL_IE(RSL_IE_Body:{chan_mode := mode}),
			/* lots of optional IEs */
			*
		}
	}

	template (value) RSL_Message
	ts_RSL_CHAN_ACT_PDCH(template (value) RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_ACT_TYPE, RSL_IE_Body:{act_type := c_RSL_IE_ActType_PDCH})
		}
	}
	template RSL_Message
	tr_RSL_CHAN_ACT_PDCH(template (present) RslChannelNr chan_nr) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{act_type := c_RSL_IE_ActType_PDCH}),
			/* lots of optional IEs */
			*
		}
	}


	/* 8.4.2 BTS -> BSC */
	template (value) RSL_Message ts_RSL_CHAN_ACT_ACK(template (value) RslChannelNr chan_nr,
							 GsmFrameNumber fn) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV_ACK,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_FRAME_NUMBER, RSL_IE_Body:{frame_nr := ts_RSL_IE_FrameNumber(fn)})
		}
	}
	template RSL_Message tr_RSL_CHAN_ACT_ACK(template RslChannelNr chan_nr) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{frame_nr := ?})
		}
	}

	/* 8.4.3 BTS -> BSC */
	template (value) RSL_Message ts_RSL_CHAN_ACT_NACK(template (value) RslChannelNr chan_nr,
							  RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV_NACK,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_CHAN_ACT_NACK(template RslChannelNr chan_nr,
						  template RSL_Cause cause := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CHAN_ACTIV_NACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cause := ?})
		}
	}

	/* 8.4.4 BTS -> BSC */
	template (value) RSL_Message ts_RSL_CONN_FAIL_IND(RslChannelNr chan_nr, RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CONN_FAIL,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_CONN_FAIL_IND(template RslChannelNr chan_nr,
						  template RSL_Cause cause := ?) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_CONN_FAIL,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
		}
	}

	/* 8.4.5 BSC -> BTS */
	template RSL_Message tr_RSL_DEACT_SACCH(template RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_DEACTIVATE_SACCH,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr})
		}
	}
	template (value) RSL_Message ts_RSL_DEACT_SACCH(template (value) RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_DEACTIVATE_SACCH,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr})
		}
	}


	/* 8.4.6 BSC ->BTS */
	template RSL_Message tr_RSL_ENCR_CMD(template RslChannelNr chan_nr,
					     template RslLinkId link_id := ?,
					     template RSL_AlgId alg := ?,
					     template octetstring key := ?,
					     template octetstring l3_info := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_ENCR_CMD,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{encr_info := tr_RSL_IE_EncrInfo(alg, key)}),
			tr_RSL_IE(RSL_IE_Body:{link_id := link_id}),
			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)})
		}
	}
	template (value) RSL_Message ts_RSL_ENCR_CMD(template (value) RslChannelNr chan_nr,
						     template (value) RslLinkId link_id,
						     template (value) RSL_AlgId alg, octetstring key,
						     octetstring l3_info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_ENCR_CMD,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_ENCR_INFO, RSL_IE_Body:{encr_info := ts_RSL_IE_EncrInfo(alg, key)}),
			t_RSL_IE(RSL_IE_LINK_IDENT, RSL_IE_Body:{link_id := link_id}),
			t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := ts_RSL_L16V(l3_info)})
		}
	}

	template RSL_Message tr_RSL_MEAS_RES(template RslChannelNr chan_nr,
					     template uint8_t meas_res_nr := ?,
					     template RSL_IE_UplinkMeas ul_meas := ?,
					     template RSL_IE_BS_Power bs_power := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MEAS_RES,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{meas_res_nr := meas_res_nr}),
			tr_RSL_IE(RSL_IE_Body:{uplink_meas := ul_meas}),
			tr_RSL_IE(RSL_IE_Body:{bs_power := bs_power}),
			*
		}
	}

	/* Receive template for a measurement report that lacks the measurement report
	 * from the MS (l1_info, l3_info and ms timing offset */
	template RSL_Message tr_RSL_MEAS_RES_EMPTY(template RslChannelNr chan_nr,
					     template uint8_t meas_res_nr := ?,
					     template RSL_IE_UplinkMeas ul_meas := ?,
					     template RSL_IE_BS_Power bs_power := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MEAS_RES,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{meas_res_nr := meas_res_nr}),
			tr_RSL_IE(RSL_IE_Body:{uplink_meas := ul_meas}),
			tr_RSL_IE(RSL_IE_Body:{bs_power := bs_power})
		}
	}

	/* Osmocom specific template, require lots of optional fields to be present */
	template RSL_Message tr_RSL_MEAS_RES_OSMO(template RslChannelNr chan_nr,
					     template uint8_t meas_res_nr := ?,
					     template RSL_IE_UplinkMeas ul_meas := ?,
					     template RSL_IE_BS_Power bs_power := ?,
					     template RSL_IE_L1Info l1_info := ?,
					     template octetstring l3_info := ?,
					     template uint8_t ms_to := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MEAS_RES,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{meas_res_nr := meas_res_nr}),
			tr_RSL_IE(RSL_IE_Body:{uplink_meas := ul_meas}),
			tr_RSL_IE(RSL_IE_Body:{bs_power := bs_power}),
			tr_RSL_IE(RSL_IE_Body:{l1_info := l1_info}),
			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)}),
			tr_RSL_IE(RSL_IE_Body:{ms_timing_offset := ms_to})
		}
	}

	template (value) RSL_Message ts_RSL_MEAS_RES(template (value) RslChannelNr chan_nr,
					     uint8_t meas_res_nr,
					     template (value) RSL_IE_UplinkMeas ul_meas,
					     template (value) RSL_IE_BS_Power bs_power,
					     template (value) RSL_IE_L1Info l1_info,
					     octetstring l3_info,
					     uint8_t ms_to) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MEAS_RES,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_MEAS_RES_NR, RSL_IE_Body:{meas_res_nr := meas_res_nr}),
			t_RSL_IE(RSL_IE_UPLINK_MEAS, RSL_IE_Body:{uplink_meas := ul_meas}),
			t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power}),
			t_RSL_IE(RSL_IE_L1_INFO, RSL_IE_Body:{l1_info := l1_info}),
			t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := ts_RSL_L16V(l3_info)}),
			t_RSL_IE(RSL_IE_MS_TIMING_OFFSET, RSL_IE_Body:{ms_timing_offset := ms_to})
		}
	}

	/* 8.4.9 BSC -> BTS */
	template (value) RSL_Message ts_RSL_MODE_MODIFY_REQ(template (value) RslChannelNr chan_nr,
						     template (value) RSL_IE_ChannelMode mode) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MODE_MODIFY_REQ,
		ies :={
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CHAN_MODE, RSL_IE_Body:{chan_mode := mode})
			/* lots of optional IEs */
		}
	}
	template RSL_Message tr_RSL_MODE_MODIFY_REQ(template RslChannelNr chan_nr,
					     template RSL_IE_ChannelMode mode) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MODE_MODIFY_REQ,
		ies :={
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{chan_mode := mode}),
			/* lots of optional IEs */
			*
		}
	}

	template RSL_Message tr_RSL_MODE_MODIFY_REQ_with_OSMO_TSC(template RslChannelNr chan_nr,
								  template RSL_IE_ChannelMode mode,
								  template uint8_t tsc_set := ?,
								  template uint8_t tsc := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MODE_MODIFY_REQ,
		ies := {
		    tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
		    tr_RSL_IE(RSL_IE_Body:{chan_mode := mode}),
		    tr_RSL_IE(RSL_IE_Body:{osmo_training_sequence := {
							len := ?,
							tsc_set := tsc_set,
							tsc := tsc
						  }
					  })
		}
	};
	
	/* 8.4.10 BTS -> BSC */
	template (value) RSL_Message ts_RSL_MODE_MODIFY_ACK(template (value) RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MODE_MODIFY_ACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr})
		}
	}
	template RSL_Message tr_RSL_MODE_MODIFY_ACK(template RslChannelNr chan_nr) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MODE_MODIFY_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr})
		}
	}

	/* 8.4.11 BTS -> BSC */
	template (value) RSL_Message ts_RSL_MODE_MODIFY_NACK(template (value) RslChannelNr chan_nr,
							     RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MODE_MODIFY_NACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_MODE_MODIFY_NACK(template RslChannelNr chan_nr,
							template RSL_Cause cause) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MODE_MODIFY_NACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
		}
	}


	/* 8.4.14: BTS <- BSC */
	template RSL_Message tr_RSL_RF_CHAN_REL(template RslChannelNr chan_nr) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_RF_CHAN_REL,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr})
		}
	}
	template (value) RSL_Message ts_RSL_RF_CHAN_REL(template (value) RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_RF_CHAN_REL,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr})
		}
	}

	/* 8.4.15: BTS <- BSC */
	template (value) RSL_Message ts_RSL_MS_PWR_CTRL(template (value) RslChannelNr chan_nr,
							template (value) RSL_IE_MS_Power ms_power) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MS_POWER_CONTROL,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ms_power})
			/* One optional IE: MS POWER PARAMETERS */
		}
	}

	template (value) RSL_Message ts_RSL_MS_PWR_CTRL_with_pp(template (value) RslChannelNr chan_nr,
							integer pwr_level) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_MS_POWER_CONTROL,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_MS_POWER, RSL_IE_Body:{ms_power := ts_RSL_IE_MS_Power(pwr_level)}),
			t_RSL_IE(RSL_IE_MS_POWER_PARAM, RSL_IE_Body:{ms_power_params :=
			ts_RSL_IE_MS_Power_Parameters(''O)})
		}
	}

	/* 8.4.16: BTS <- BSC */
	template (value) RSL_Message ts_RSL_BS_PWR_CTRL(template (value) RslChannelNr chan_nr,
							template (value) RSL_IE_BS_Power bs_power) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_BS_POWER_CONTROL,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_BS_POWER, RSL_IE_Body:{bs_power := bs_power})
			/* One optional IE: BS POWER PARAMETERS */
		}
	}
	template RSL_Message tr_RSL_BS_PWR_CTRL(template (present) RslChannelNr chan_nr,
						template (present) RSL_IE_BS_Power bs_power) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_BS_POWER_CONTROL,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{bs_power := bs_power})
			/* One optional IE: BS POWER PARAMETERS */
		}
	}

	/* 8.4.19 BTS -> BSC */
	template (value) RSL_Message ts_RSL_RF_CHAN_REL_ACK(template (value) RslChannelNr chan_nr) :=
		ts_RSL_MsgDiscType(ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
				   RSL_MT_RF_CHAN_REL_ACK,
				   { t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}) });

	template RSL_Message tr_RSL_RF_CHAN_REL_ACK(template RslChannelNr chan_nr) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_RF_CHAN_REL_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr})
		}
	}

	/* 8.6.20 BTS <- BSC */
	template (value) RSL_Message ts_RSL_SACCH_INF_MOD(template (value) RslChannelNr chan_nr,
							  RSL_IE_SysinfoType si_type,
							  octetstring l3_info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_SACCH_INFO_MODIFY,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_SYSINFO_TYPE, RSL_IE_Body:{sysinfo_type := si_type}),
			t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := ts_RSL_L16V(l3_info)})
		}
	}

	/* 8.4.7 BTS -> BSC */
	template (value) RSL_Message ts_RSL_HANDO_DET(template (value) RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_HANDO_DET,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr})
		}
	}
	template RSL_Message tr_RSL_HANDO_DET(template RslChannelNr chan_nr,
					      template uint8_t acc_delay := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_HANDO_DET,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{access_delay := acc_delay})
		}
	}


	/* COMMON CHANNEL MANAGEMENT MESSAGES */

	/* 8.5.1 BTS <- BSC */
	template (value) RSL_Message ts_RSL_BCCH_INFO(RSL_IE_SysinfoType si_type,
						      octetstring full_bcch_info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_BCCH_INFO,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := ts_RslChanNr_BCCH(0)}),
			t_RSL_IE(RSL_IE_SYSINFO_TYPE, RSL_IE_Body:{sysinfo_type := si_type}),
			t_RSL_IE(RSL_IE_FULL_BCCH_INFO, RSL_IE_Body:{other := ts_RSL_LV(full_bcch_info)})
		}
	}
	template RSL_Message tr_RSL_NO_BCCH_INFO(template RSL_IE_SysinfoType si_type := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_BCCH_INFO,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := ts_RslChanNr_BCCH(0)}),
			tr_RSL_IE(RSL_IE_Body:{sysinfo_type := si_type})
		}
	}
	template RSL_Message tr_RSL_BCCH_INFO(template RSL_IE_SysinfoType si_type := ?,
					      template octetstring full_bcch_info := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_BCCH_INFO,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := ts_RslChanNr_BCCH(0)}),
			tr_RSL_IE(RSL_IE_Body:{sysinfo_type := si_type}),
			tr_RSL_IE(RSL_IE_Body:{other := tr_RSL_LV(full_bcch_info)}),
			*
		}
	}

	/* 8.5.2 BTS -> BSC */
	template (value) RSL_Message ts_RSL_RACH_LOAD_IND(uint16_t slot_ct, uint16_t busy_ct,
							  uint16_t acc_ct) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CCCH_LOAD_IND,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := ts_RslChanNr_RACH(0)}),
			t_RSL_IE(RSL_IE_RACH_LOAD, RSL_IE_Body:{rach_load := ts_RSL_IE_RachLoad(slot_ct, busy_ct, acc_ct)})
		}
	}
	template RSL_Message tr_RSL_RACH_LOAD_IND(template uint16_t slot_ct := ?,
						  template uint16_t busy_ct := ?,
						  template uint16_t acc_ct := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CCCH_LOAD_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := t_RslChanNr_RACH(0)}),
			tr_RSL_IE(RSL_IE_Body:{rach_load := tr_RSL_IE_RachLoad(slot_ct, busy_ct, acc_ct)})
		}
	}

	template (value) RSL_Message ts_RSL_PAGING_LOAD_IND(uint16_t buffer_space) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CCCH_LOAD_IND,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := ts_RslChanNr_PCH_AGCH(0)}),
			t_RSL_IE(RSL_IE_PAGING_LOAD, RSL_IE_Body:{paging_load := buffer_space})
		}
	}
	template RSL_Message tr_RSL_PAGING_LOAD_IND(template uint16_t buffer_space := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CCCH_LOAD_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := t_RslChanNr_PCH_AGCH(0)}),
			tr_RSL_IE(RSL_IE_Body:{paging_load := buffer_space})
		}
	}


	/* 8.5.3 BTS -> BSC */
	template (value) RSL_Message ts_RSL_CHAN_RQD(OCT1 ra, GsmFrameNumber fn,
						     template (value) RslChannelNr chan_nr := ts_RslChanNr_RACH(0),
						     uint8_t acc_del := 0) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CHAN_RQD,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			/* TODO: we may need to have optional RSL_IE_LINK_IDENT IE here */
			t_RSL_IE(RSL_IE_REQ_REFERENCE, RSL_IE_Body:{req_ref := ts_RSL_IE_ReqRef(ra, fn)}),
			t_RSL_IE(RSL_IE_ACCESS_DELAY, RSL_IE_Body:{access_delay := acc_del})
		}
	}
	template RSL_Message tr_RSL_CHAN_RQD(template OCT1 ra, template GsmFrameNumber fn := ?,
					     template RslChannelNr chan_nr := ts_RslChanNr_RACH(0),
					     template uint8_t acc_del := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CHAN_RQD,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			/* TODO: we may need to have optional RSL_IE_LINK_IDENT IE here */
			tr_RSL_IE(RSL_IE_Body:{req_ref := tr_RSL_IE_ReqRef(ra, fn)}),
			tr_RSL_IE(RSL_IE_Body:{access_delay := acc_del})
		}
	}

	/* 8.5.4 BTS -> BSC */
	template (value) RSL_Message ts_DELETE_IND(template (value) RslChannelNr chan_nr,
						   octetstring imm_ass) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_DELETE_IND,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_FULL_IMM_ASS_INFO, RSL_IE_Body:{full_imm_ass_info := ts_RSL_LV(imm_ass)})
		}
	}
	template RSL_Message tr_RSL_DELETE_IND(template octetstring imm_ass := ?, template uint3_t tn) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_DELETE_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := t_RslChanNr_PCH_AGCH(tn)}),
			tr_RSL_IE(RSL_IE_Body:{full_imm_ass_info := tr_RSL_LV(imm_ass)}),
			*
		}
	}

	/* 8.5.5 BSC -> BTS */
	template RSL_Message tr_RSL_PAGING_CMD(template MobileIdentityV mi, template uint3_t tn := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_PAGING_CMD,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := t_RslChanNr_PCH_AGCH(tn)}),
			tr_RSL_IE(RSL_IE_Body:{paging_group := ?}),
			tr_RSL_IE(RSL_IE_Body:{ms_identity := tr_MI_LV(mi)}),
			* /* opt: channel needed, eMLPP prio */
		}
	}
	template (value) RSL_Message ts_RSL_PAGING_CMD(MobileIdentityV mi, uint8_t pg, uint3_t tn := 0) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_PAGING_CMD,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := ts_RslChanNr_PCH_AGCH(tn)}),
			t_RSL_IE(RSL_IE_PAGING_GROUP, RSL_IE_Body:{paging_group := pg}),
			t_RSL_IE(RSL_IE_MS_IDENTITY, RSL_IE_Body:{ms_identity := ts_MI_LV(mi)})
		}
	}

	/* 8.5.6 BSC -> BTS */
	template RSL_Message tr_RSL_IMM_ASSIGN(template uint3_t tn := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_IMMEDIATE_ASSIGN_CMD,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := t_RslChanNr_PCH_AGCH(tn)}),
			tr_RSL_IE(RSL_IE_Body:{full_imm_ass_info := ?})
		}
	}
	template (value) RSL_Message ts_RSL_IMM_ASSIGN(octetstring f_ass_inf, uint3_t tn := 0) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_IMMEDIATE_ASSIGN_CMD,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := ts_RslChanNr_PCH_AGCH(tn)}),
			t_RSL_IE(RSL_IE_FULL_IMM_ASS_INFO, RSL_IE_Body:{full_imm_ass_info := ts_RSL_LV(f_ass_inf)})
		}
	}

	/* 8.5.8 BTS <- BSC SMS BROADCAST COMMAND */
	template RSL_Message tr_RSL_SMSCB_CMD(template RSL_IE_CbCommandType cb_cmd := ?,
					      template octetstring msg := ?,
					      template RslChannelNr chan_nr := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_SMS_BC_CMD,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cb_cmd_type := cb_cmd}),
			tr_RSL_IE(RSL_IE_Body:{smscb_message := tr_RSL_LV(msg)}),
			*
		}
	}
	template (value) RSL_Message ts_RSL_SMSCB_CMD(template (value) RSL_IE_CbCommandType cb_cmd,
						      template (value) octetstring msg,
						      template (value) RslChannelNr chan_nr :=
									ts_RslChanNr_SDCCH4(0, 2)) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_SMS_BC_CMD,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CB_CMD_TYPE, RSL_IE_Body:{cb_cmd_type := cb_cmd}),
			t_RSL_IE(RSL_IE_SMSCB_MSG, RSL_IE_Body:{smscb_message := ts_RSL_LV(msg)})
			/* optional channel type for extended CBCH */
		}
	}

	/* 8.5.9 BTS -> BSC CBCH LOAD INDICATION */
	template RSL_Message tr_RSL_CBCH_LOAD_IND_BASIC(template boolean overflow := ?,
							template uint4_t slot_count := ?,
							template RslChannelNr chan_nr := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CBCH_LOAD_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cbch_load_info := tr_CbchLoadInfo(overflow, slot_count)})
		}
	}
	template (value) RSL_Message ts_RSL_CBCH_LOAD_IND_BASIC(boolean overflow, uint4_t slot_count,
								template (value) RslChannelNr chan_nr :=
									ts_RslChanNr_SDCCH4(0, 2)) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CBCH_LOAD_IND,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CBCH_LOAD_INFO, RSL_IE_Body:{cbch_load_info := ts_CbchLoadInfo(overflow, slot_count)})
		}
	}
	template RSL_Message tr_RSL_CBCH_LOAD_IND_EXTD(template boolean overflow := ?,
							template uint4_t slot_count := ?,
							template RslChannelNr chan_nr := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CBCH_LOAD_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cbch_load_info := tr_CbchLoadInfo(overflow, slot_count)}),
			tr_RSL_IE(RSL_IE_Body:{smscb_chan_ind := 1})
		}
	}
	template (value) RSL_Message ts_RSL_CBCH_LOAD_IND_EXTD(boolean overflow, uint4_t slot_count,
								template (value) RslChannelNr chan_nr :=
									ts_RslChanNr_SDCCH4(0, 2)) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_CBCH_LOAD_IND,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CBCH_LOAD_INFO, RSL_IE_Body:{cbch_load_info := ts_CbchLoadInfo(overflow, slot_count)}),
			t_RSL_IE(RSL_IE_SMSCB_CHAN_INDICATOR, RSL_IE_Body:{smscb_chan_ind := 1})
		}
	}


	/* 8.6.1 BTS -> BSC */
	template (value) RSL_Message
	ts_RSL_RF_RES_IND(template (value) RSL_ResourceInfo info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_TRX_MGMT, false),
		msg_type := RSL_MT_RF_RES_IND,
		ies := {
			t_RSL_IE(RSL_IE_RESOURCE_INFO, RSL_IE_Body:{
				resource_info := {
					len := 0, /* overwritten */
					info := info
				}
			})
		}
	}
	template RSL_Message
	tr_RSL_RF_RES_IND(template (present) RSL_ResourceInfo info := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_TRX_MGMT, false),
		msg_type := RSL_MT_RF_RES_IND,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{
				resource_info := {
					len := ?,
					info := info
				}
			})
		}
	}


	/* 8.6.2 BTS <- BSC */
	template (value) RSL_Message ts_RSL_SACCH_FILL(RSL_IE_SysinfoType si_type, octetstring l3_info) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_TRX_MGMT, false),
		msg_type := RSL_MT_SACCH_FILL,
		ies := {
			t_RSL_IE(RSL_IE_SYSINFO_TYPE, RSL_IE_Body:{sysinfo_type := si_type}),
			t_RSL_IE(RSL_IE_L3_INFO, RSL_IE_Body:{l3_info := ts_RSL_L16V(l3_info)})
		}
	}
	template RSL_Message tr_RSL_NO_SACCH_FILL(template RSL_IE_SysinfoType si_type := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_TRX_MGMT, false),
		msg_type := RSL_MT_SACCH_FILL,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{sysinfo_type := si_type})
		}
	}
	template RSL_Message tr_RSL_SACCH_FILL(template RSL_IE_SysinfoType si_type := ?,
						template octetstring l3_info := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_TRX_MGMT, false),
		msg_type := RSL_MT_SACCH_FILL,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{sysinfo_type := si_type}),
			tr_RSL_IE(RSL_IE_Body:{l3_info := tr_RSL_L16V(l3_info)}),
			*
		}
	}


	/* 8.6.4 BTS -> BSC */
	template (value) RSL_Message ts_RSL_ERROR_REPORT(RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_TRX_MGMT, false),
		msg_type := RSL_MT_ERROR_REPORT,
		ies := {
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_ERROR_REPORT(template RSL_Cause cause := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_TRX_MGMT, false),
		msg_type := RSL_MT_ERROR_REPORT,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)}),
			*
		}
	}



	/* Abis/IP specific messages */

	template RSL_Message tr_RSL_IPA_CRCX(template RslChannelNr chan_nr) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_CRCX,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			*
		}
	}
	template (value) RSL_Message
	ts_RSL_IPA_CRCX(template (value) RslChannelNr chan_nr,
			template (value) OCT4 remote_ip := '7F000001'O,
			template (value) uint16_t remote_port := 6766) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_CRCX,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_IPAC_REMOTE_IP, RSL_IE_Body:{ipa_remote_ip := remote_ip}),
			t_RSL_IE(RSL_IE_IPAC_REMOTE_PORT, RSL_IE_Body:{ipa_remote_port := remote_port})
		}
	}


	template (value) RSL_Message ts_RSL_IPA_CRCX_ACK(template (value) RslChannelNr chan_nr,
							 uint16_t ipa_conn_id, OCT4 local_ip,
							 uint16_t local_port, uint7_t rtp_pt2) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_CRCX_ACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			t_RSL_IE(RSL_IE_IPAC_LOCAL_IP, RSL_IE_Body:{ipa_local_ip := local_ip}),
			t_RSL_IE(RSL_IE_IPAC_LOCAL_PORT, RSL_IE_Body:{ipa_local_port := local_port}),
			t_RSL_IE(RSL_IE_IPAC_RTP_PAYLOAD2, RSL_IE_Body:{ipa_rtp_pt2 := rtp_pt2})
		}
	}
	template RSL_Message tr_RSL_IPA_CRCX_ACK(template RslChannelNr chan_nr,
						 template uint16_t ipa_conn_id,
						 template OCT4 local_ip,
						 template uint16_t local_port) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_CRCX_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			tr_RSL_IE(RSL_IE_Body:{ipa_local_ip := local_ip}),
			tr_RSL_IE(RSL_IE_Body:{ipa_local_port := local_port})
			/* Optional: RTP Payload Type 2 IE */
		}
	}

	template (value) RSL_Message ts_RSL_IPA_CRCX_NACK(template (value) RslChannelNr chan_nr,
							  RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_CRCX_NACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_IPA_CRCX_NACK(template RslChannelNr chan_nr,
						  template RSL_Cause cause := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_CRCX_NACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
		}
	}

	template (value) RSL_Message ts_RSL_IPA_MDCX(template (value) RslChannelNr chan_nr,
						     uint16_t ipa_conn_id,
						     OCT4 remote_ip, uint16_t remote_port,
						     uint7_t rtp_pt2) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_MDCX,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			t_RSL_IE(RSL_IE_IPAC_REMOTE_IP, RSL_IE_Body:{ipa_remote_ip := remote_ip}),
			t_RSL_IE(RSL_IE_IPAC_REMOTE_PORT, RSL_IE_Body:{ipa_remote_port := remote_port}),
			/* optional: RTP Payload Type */
			t_RSL_IE(RSL_IE_IPAC_RTP_PAYLOAD2, RSL_IE_Body:{ipa_rtp_pt2 := rtp_pt2})
		}
	}
	template RSL_Message tr_RSL_IPA_MDCX(template RslChannelNr chan_nr,
					     template uint16_t ipa_conn_id) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_MDCX,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			*
		}
	}

	template (value) RSL_Message ts_RSL_IPA_MDCX_ACK(template (value) RslChannelNr chan_nr,
							 uint16_t ipa_conn_id,
							 OCT4 local_ip, uint16_t local_port,
							 uint7_t rtp_pt2) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_MDCX_ACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			/* optional */
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			t_RSL_IE(RSL_IE_IPAC_LOCAL_IP, RSL_IE_Body:{ipa_local_ip := local_ip}),
			t_RSL_IE(RSL_IE_IPAC_LOCAL_PORT, RSL_IE_Body:{ipa_local_port := local_port}),
			/* optional: RTP Payload Type */
			t_RSL_IE(RSL_IE_IPAC_RTP_PAYLOAD2, RSL_IE_Body:{ipa_rtp_pt2 := rtp_pt2})
		}
	}
	template RSL_Message tr_RSL_IPA_MDCX_ACK(template RslChannelNr chan_nr,
						 template uint16_t ipa_conn_id,
						 template OCT4 local_ip,
						 template uint16_t local_port,
						 template uint7_t rtp_pt2) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_MDCX_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			/* optional */
			tr_RSL_IE(RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			tr_RSL_IE(RSL_IE_Body:{ipa_local_ip := local_ip}),
			tr_RSL_IE(RSL_IE_Body:{ipa_local_port := local_port}),
			/* optional: RTP Payload Type */
			tr_RSL_IE(RSL_IE_Body:{ipa_rtp_pt2 := rtp_pt2})
		}
	}

	template (value) RSL_Message ts_RSL_IPA_MDCX_NACK(template (value) RslChannelNr chan_nr,
							  RSL_Cause cause,
							  template (value) uint16_t ipa_conn_id) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_MDCX_NACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			/* optional connection ID */
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_IPA_MDCX_NACK(template RslChannelNr chan_nr,
						  template RSL_Cause cause,
						  template uint16_t ipa_conn_id) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_MDCX_NACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			/* optional connection ID */
			tr_RSL_IE(RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
		}
	}


	template (value) RSL_Message ts_RSL_IPA_DLCX_IND(template (value) RslChannelNr chan_nr,
							 uint16_t ipa_conn_id,
							 template (value) RSL_IE_IPA_ConnectionStats stats,
							 RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_DLCX_IND,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			t_RSL_IE(RSL_IE_IPAC_CONN_STAT, RSL_IE_Body:{ipa_stats := stats}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}

	template (value) RSL_Message ts_RSL_IPA_DLCX(template (value) RslChannelNr chan_nr,
						     uint16_t ipa_conn_id) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_DLCX,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id})
		}
	}
	template RSL_Message tr_RSL_IPA_DLCX(template RslChannelNr chan_nr,
					     template uint16_t ipa_conn_id := omit) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_DLCX,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			/* FIXME: optional conn_id */
			*
		}
	}

	template (value) RSL_Message ts_RSL_IPA_DLCX_ACK(template (value) RslChannelNr chan_nr,
							 uint16_t ipa_conn_id,
							 RSL_IE_IPA_ConnectionStats stats) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_DLCX_ACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			t_RSL_IE(RSL_IE_IPAC_CONN_STAT, RSL_IE_Body:{ipa_stats := stats})
		}
	}
	template RSL_Message tr_RSL_IPA_DLCX_ACK(template RslChannelNr chan_nr,
						 template uint16_t ipa_conn_id,
						 template RSL_IE_IPA_ConnectionStats stats) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_DLCX_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			tr_RSL_IE(RSL_IE_Body:{ipa_stats := stats})
		}
	}



	template (value) RSL_Message ts_RSL_IPA_DLCX_NACK(template (value) RslChannelNr chan_nr,
							  RSL_Cause cause, uint16_t ipa_conn_id) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_DLCX_NACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			/* optional connection ID */
			t_RSL_IE(RSL_IE_IPAC_CONN_ID, RSL_IE_Body:{ipa_conn_id := ipa_conn_id}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_IPA_DLCX_NACK(template RslChannelNr chan_nr,
						  template RSL_Cause cause) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_IPACCESS, false),
		msg_type := RSL_MT_IPAC_DLCX_NACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			/* optional connection ID */
			*,
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
		}
	}


	template (value) RSL_Message
	ts_RSL_IPA_PDCH_ACT(template (value) RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_ACT,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr})
		}
	}
	template RSL_Message
	tr_RSL_IPA_PDCH_ACT(template (present) RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_ACT,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr})
		}
	}


	template RSL_Message ts_RSL_IPA_PDCH_ACT_ACK(RslChannelNr chan_nr,
						     template (value) RSL_IE_FrameNumber fn) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_ACT_ACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_FRAME_NUMBER, RSL_IE_Body:{frame_nr := fn})
		}
	}
	template RSL_Message tr_RSL_IPA_PDCH_ACT_ACK(template RslChannelNr chan_nr,
						     template RSL_IE_FrameNumber fn) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_ACT_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{frame_nr := fn})
		}
	}

	template RSL_Message ts_RSL_IPA_PDCH_ACT_NACK(RslChannelNr chan_nr, RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_ACT_NACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_IPA_PDCH_ACT_NACK(template RslChannelNr chan_nr,
						      template RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_ACT_NACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
		}
	}

	template RSL_Message ts_RSL_IPA_PDCH_DEACT(RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_DEACT,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr})
		}
	}
	template RSL_Message tr_RSL_IPA_PDCH_DEACT(template RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_DEACT,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr})
		}
	}

	template RSL_Message ts_RSL_IPA_PDCH_DEACT_ACK(RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_DEACT_ACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr})
		}
	}
	template RSL_Message tr_RSL_IPA_PDCH_DEACT_ACK(template RslChannelNr chan_nr) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_DEACT_ACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr})
		}
	}

	template RSL_Message ts_RSL_IPA_PDCH_DEACT_NACK(RslChannelNr chan_nr, RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_DEACT_NACK,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_CAUSE, RSL_IE_Body:{cause := ts_RSL_IE_Cause(cause)})
		}
	}
	template RSL_Message tr_RSL_IPA_PDCH_DEACT_NACK(template RslChannelNr chan_nr,
							template RSL_Cause cause) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_DCHAN, false),
		msg_type := RSL_MT_IPAC_PDCH_DEACT_NACK,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{cause := tr_RSL_IE_Cause(cause)})
		}
	}

	template (value) RSL_Message ts_RSL_OSMO_ETWS_CMD(template (value) octetstring msg,
							  template (value) RslChannelNr chan_nr := ts_RslChanNr_PCH_AGCH(0)) := {
		msg_disc := ts_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_OSMO_ETWS_CMD,
		ies := {
			t_RSL_IE(RSL_IE_CHAN_NR, RSL_IE_Body:{chan_nr := chan_nr}),
			t_RSL_IE(RSL_IE_SMSCB_MSG, RSL_IE_Body:{smscb_message := ts_RSL_LV(msg)})
		}
	}
	template RSL_Message tr_RSL_OSMO_ETWS_CMD(template RslChannelNr chan_nr := ?,
						  template octetstring msg := ?) := {
		msg_disc := tr_RSL_MsgDisc(RSL_MDISC_CCHAN, false),
		msg_type := RSL_MT_OSMO_ETWS_CMD,
		ies := {
			tr_RSL_IE(RSL_IE_Body:{chan_nr := chan_nr}),
			tr_RSL_IE(RSL_IE_Body:{smscb_message := tr_RSL_LV(msg)})
		}
	}



	function f_rsl_find_ie(RSL_Message msg, RSL_IE_Type iei, out RSL_IE_Body ret) return boolean {
		for (var integer i := 0; i < sizeof(msg.ies); i := i+1) {
			if (msg.ies[i].iei == iei) {
				ret := msg.ies[i].body;
				return true;
			}
		}
		return false;
	}



} with { encode "RAW" ; variant "FIELDORDER(msb)" }
