GSM_Types: More 44.018 + 24.008 definitions for RR
diff --git a/sysinfo/GSM_SystemInformation.ttcn b/sysinfo/GSM_SystemInformation.ttcn
index 4a7bfd5..8001dd9 100644
--- a/sysinfo/GSM_SystemInformation.ttcn
+++ b/sysinfo/GSM_SystemInformation.ttcn
@@ -9,57 +9,14 @@
 	import from GSM_Types all;
 	import from Osmocom_Types all;
 
-	type record L2PseudoLength {
-		uint6_t		l2_plen,
-		BIT2		zero_one
-	} with { variant "" };
-
-	template L2PseudoLength t_L2Pseudolength(template uint6_t len) := {
-		l2_plen := len,
-		zero_one := '01'B
-	};
-
-	type octetstring RestOctets  with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" };
-
-	type record MaioHsn {
-	} with { variant "" };
-
 	type union ArfcnOrMaio {
 		uint12_t	arfcn,
 		MaioHsn		maio_hsn
 	} with { variant "" };
 
-	type record SystemInformationHeader {
-		L2PseudoLength	l2_plen,
-		uint4_t		skip_indicator,
-		uint4_t		rr_protocol_discriminator,
-		RrMessageType	message_type
-	} with { variant "" };
-
-	template SystemInformationHeader t_SiHeader(RrMessageType msg_type, template uint6_t len) := {
-		l2_plen := t_L2Pseudolength(len),
-		skip_indicator := 0,
-		rr_protocol_discriminator := 6,
-		message_type := msg_type
-	};
-
-	external function enc_SystemInformationHeader(in SystemInformationHeader si) return octetstring
-		with { extension "prototype(convert) encode(RAW)" };
-	external function dec_SystemInformationHeader(in octetstring stream) return SystemInformationHeader
-		with { extension "prototype(convert) decode(RAW)" };
-
-	type hexstring GsmBcdString with { variant "HEXORDER(low)" };
-	type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" };
-
 	/* 24.008 10.5.1.1 */
 	type uint16_t CellIdentity;
 
-	/* 24.008 10.5.1.3 */
-	type record LocationAreaIdentification {
-		BcdMccMnc	mcc_mnc,
-		uint16_t	lac
-	} with { variant "" };
-
 	/* 44.018 10.5.2.1b */
 	type octetstring CellChannelDescription with { variant "FIELDLENGTH(16)" };
 
@@ -88,18 +45,6 @@
 		uint6_t		rxlev_access_min
 	} with { variant "" };
 
-	/* 44.018 10.5.2.5 */
-	type record ChannelDescription {
-		OCT1		iei,
-		BIT5		chan_type_tdma_offset,
-		uint3_t		tn,
-		uint3_t		tsc,
-		boolean		h,
-		uint12_t	arfcn optional,
-		MaioHsn		maio_hsn optional
-	} with { variant (arfcn) "PRESENCE(h = true)"
-		 variant (maio_hsn) "PRESENCE(h = false)" };
-
 	/* 44.018 10.5.2.11 */
 	type record ControlChannelDescription {
 		boolean		mscrr,
@@ -116,7 +61,7 @@
 	template ControlChannelDescription t_ControlChannelDescription := { ?, ?, ?, ?, ?, ?, '00'B, ?, ? };
 
 	/* 44.018 10.5.2.21 */
-	type record MobileAllocation {
+	type record MobileAllocationT {
 		OCT1		iei,
 		uint8_t		len,
 		bitstring	ma
@@ -145,7 +90,6 @@
 
 	/* 44.018 9.1.31 */
 	type record SystemInformationType1 {
-		//SystemInformationHeader	header,
 		CellChannelDescription	cell_chan_desc,
 		RachControlParameters	rach_control,
 		Si1RestOctets		rest_octets
@@ -153,7 +97,6 @@
 
 	/* 44.018 9.1.32 */
 	type record SystemInformationType2 {
-		//SystemInformationHeader	header,
 		NeighbourCellDescription bcch_freq_list,
 		BIT8			ncc_permitted,
 		RachControlParameters	rach_control
@@ -161,7 +104,6 @@
 
 	/* 44.018 9.1.33 */
 	type record SystemInformationType2bis {
-		//SystemInformationHeader		header,
 		NeighbourCellDescription	extd_bcch_freq_list,
 		RachControlParameters		rach_control,
 		OCT1				rest_octets
@@ -169,14 +111,12 @@
 
 	/* 44.018 9.1.34 */
 	type record SystemInformationType2ter {
-		//SystemInformationHeader		header,
 		NeighbourCellDescription2	extd_bcch_freq_list,
 		OCT4				rest_octets
 	} with { variant "" };
 
 	/* 44.018 9.1.35 */
 	type record SystemInformationType3 {
-		//SystemInformationHeader		header,
 		CellIdentity			cell_id,
 		LocationAreaIdentification	lai,
 		ControlChannelDescription	ctrl_chan_desc,
@@ -199,36 +139,31 @@
 
 	/* 44.018 9.1.36 */
 	type record SystemInformationType4 {
-		//SystemInformationHeader		header,
 		LocationAreaIdentification	lai,
 		CellSelectionParameters		cell_sel_par,
 		RachControlParameters		rach_control,
 		ChannelDescription		cbch_chan_desc optional,
-		MobileAllocation		cbch_mobile_alloc optional,
+		MobileAllocationT		cbch_mobile_alloc optional,
 		RestOctets			rest_octets
 	} with { variant "TAG(cbch_chan_desc, iei = '64'O; cbch_mobile_alloc, iei = '72'O)" };
 
 	/* 44.018 9.1.37 */
 	type record SystemInformationType5 {
-		SystemInformationHeader		header,
 		NeighbourCellDescription	bcch_freq_list
 	} with { variant "" };
 
 	/* 44.018 9.1.38 */
 	type record SystemInformationType5bis {
-		//SystemInformationHeader		header,
 		NeighbourCellDescription	extd_bcch_freq_list
 	} with { variant "" };
 
 	/* 44.018 9.1.39 */
 	type record SystemInformationType5ter {
-		//SystemInformationHeader		header,
 		NeighbourCellDescription2	extd_bcch_freq_list
 	} with { variant "" };
 
 	/* 44.018 9.1.40 */
 	type record SystemInformationType6 {
-		//SystemInformationHeader		header,
 		CellIdentity			cell_id,
 		LocationAreaIdentification	lai,
 		CellOptionsSacch		cell_options,
@@ -251,7 +186,7 @@
 	} with { variant "" };
 
 	type record SystemInformation {
-		SystemInformationHeader		header,
+		RrHeader			header,
 		SystemInformationUnion		payload
 	} with { variant (payload) "CROSSTAG(si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
 			      si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
diff --git a/sysinfo/GSM_Types.ttcn b/sysinfo/GSM_Types.ttcn
index 9098e1e..55548c6 100644
--- a/sysinfo/GSM_Types.ttcn
+++ b/sysinfo/GSM_Types.ttcn
@@ -11,6 +11,11 @@
 	type integer GsmArfcn (0..1023);
 	type integer UmtsArfcn (0..16383);
 	type integer UmtsScramblingCode (0..511);
+	const integer GsmMaxFrameNumber := 26*51*2048;
+	type integer GsmFrameNumber (0..GsmMaxFrameNumber);
+	type integer GsmRxLev (0..63);
+	type integer GsmTsc (0..7) with { variant "FIELDLENGTH(8)" };
+	type uint32_t GsmTmsi;
 
 	/* Table 10.4.1 of Section 10.4 / 3GPP TS 44.018 */
 	type enumerated RrMessageType {
@@ -107,4 +112,329 @@
 		INTERSYS_TO_EUTRAN_HO_CMD	('01100110'B)
 	} with { variant "FIELDLENGTH(8)" };
 
+	type octetstring RestOctets  with { variant "PADDING(yes), PADDING_PATTERN('00101011'B)" };
+	type hexstring GsmBcdString with { variant "HEXORDER(low)" };
+	type GsmBcdString BcdMccMnc with { variant "FIELDLENGTH(6)" };
+
+	type record L2PseudoLength {
+		uint6_t		l2_plen,
+		BIT2		zero_one
+	} with { variant "" };
+
+	template L2PseudoLength t_L2Pseudolength(template uint6_t len) := {
+		l2_plen := len,
+		zero_one := '01'B
+	};
+
+	type record RrHeader {
+		L2PseudoLength	l2_plen,
+		uint4_t		skip_indicator,
+		uint4_t		rr_protocol_discriminator,
+		RrMessageType	message_type
+	} with { variant "" };
+
+	template RrHeader t_RrHeader(RrMessageType msg_type, template uint6_t len) := {
+		l2_plen := t_L2Pseudolength(len),
+		skip_indicator := 0,
+		rr_protocol_discriminator := 6,
+		message_type := msg_type
+	};
+
+	type record RrL3Header {
+		uint4_t		skip_indicator,
+		uint4_t		rr_protocol_discriminator,
+		RrMessageType	message_type
+	} with { variant "" };
+
+	type record MaioHsn {
+	} with { variant "" };
+
+	/* TS 24.008 10.5.1.2 */
+	type uint4_t CipheringKeySeqNr (0..7);
+
+	/* 24.008 10.5.1.3 */
+	type record LocationAreaIdentification {
+		BcdMccMnc	mcc_mnc,
+		uint16_t	lac
+	} with { variant "" };
+
+	/* TS 24.008 10.5.1.4 */
+	type enumerated MobileIdentityType {
+		MI_TYPE_NONE	(0),
+		MI_TYPE_IMSI,
+		MI_TYPE_IMEI,
+		MI_TYPE_IMEISV,
+		MI_TYPE_TMSI,
+		MI_TYPE_TMGI
+	} with { variant "FIELDLENGTH(3)" };
+
+	type record MobileIdentityBCD {
+		MobileIdentityType	mi_type (MI_TYPE_IMSI, MI_TYPE_IMEI, MI_TYPE_IMEISV),
+		boolean			odd,
+		hexstring		digits
+	} with { variant "" };
+
+	type record MobileIdentityTMSI {
+		MobileIdentityType	mi_type (MI_TYPE_TMSI),
+		boolean			odd (false),
+		BIT4			pad ('1111'B),
+		GsmTmsi			tmsi
+	} with { variant "" };
+
+	type union MobileIdentity {
+		MobileIdentityBCD	bcd,
+		MobileIdentityTMSI	tmsi
+	} with { variant "TAG(bcd, mi_type = MI_TYPE_IMSI;
+			      bcd, mi_type = MI_TYPE_IMEI;
+			      bcd, mi_type = MI_TYPE_IMEISV;
+			      tmsi, mi_type = MI_TYPE_TMSI)" };
+
+	type record MobileIdentityLV {
+		uint8_t		len,
+		MobileIdentity	mi
+	} with { variant (len) "LENGTHTO(mi)" };
+
+	type record MobileIdentityTLV {
+		uint8_t		tag,
+		uint8_t		len,
+		MobileIdentity	mi
+	} with { variant (len) "LENGTHTO(mi)" };
+
+	/* TS 24.008 10.5.1.5 */
+	type record MsClassmark1 {
+		BIT1		spare,
+		uint2_t		rev_level,
+		boolean		es_ind,
+		boolean		a51,
+		uint3_t		rf_pwr_cap
+	} with { variant "" };
+
+	/* TS 24.008 10.5.1.6 */
+	type record MsClassmark2 {
+		BIT1		spare,
+		uint2_t		rev_level,
+		boolean		es_ind,
+		boolean		a51,
+		uint3_t		rf_pwr_cap,
+		BIT1		spare1,
+		boolean		ps_cap,
+		uint2_t		ss_screen_ind,
+		boolean		sm_cap,
+		boolean		vbs,
+		boolean		vgcs,
+		boolean		fc,
+		boolean		cm3,
+		BIT1		spare2,
+		boolean		lcsva_cap,
+		boolean		ucs2,
+		boolean		solsa,
+		boolean		cmsp,
+		boolean		a53,
+		boolean		a52
+	} with { variant "" };
+	type record MsClassmark2LV {
+		uint8_t		len,
+		MsClassmark2	cm2
+	} with { variant (len) "LENGTHTO(cm2)" };
+
+
+
+
+	/* 44.018 10.5.2.5 */
+	type record ChannelDescription {
+		OCT1		iei,
+		BIT5		chan_type_tdma_offset,
+		uint3_t		tn,
+		uint3_t		tsc,
+		boolean		h,
+		uint12_t	arfcn optional,
+		MaioHsn		maio_hsn optional
+	} with { variant (arfcn) "PRESENCE(h = true)"
+		 variant (maio_hsn) "PRESENCE(h = false)" };
+
+	/* 10.5.2.8 */
+	type enumerated ChannelNeeded {
+		CHAN_NEED_ANY	(0),
+		CHAN_NEED_SDCCH	(1),
+		CHAN_NEED_TCH_F	(2),
+		CHAN_NEED_TCH_H	(3)
+	} with { variant "FIELDLENGTH(2)" };
+	type record ChannelNeeded12 {
+		ChannelNeeded	second,
+		ChannelNeeded	first
+	} with { variant "" };
+
+	/* 10.5.2.21 */
+	type record MobileAllocation {
+		uint8_t 	len,
+		bitstring	ma
+	} with { variant (len) "LENGTHTO(ma)" };
+
+	/* 10.5.2.25a */
+	type OCT3 PacketChannelDescription;
+
+	/* 10.5.2.25b */
+	type record DedicatedModeOrTbf {
+		BIT1	spare,
+		boolean	tma,
+		boolean	downlink,
+		boolean tbf
+	} with { variant "" };
+
+	/* 10.5.2.26 */
+	type enumerated PageMode {
+		PAGE_MODE_NORMAL,
+		PAGE_MODE_EXTENDED,
+		PAGE_MODE_REORGANIZATION,
+		PAGE_MODE_SAME_AS_BEFORE
+	} with { variant "FIELDLENGTH(4)" };
+
+	/* 10.5.2.30 */
+	type record RequestReference {
+		bitstring	ra length(8),
+		uint5_t 	t1p,
+		uint6_t 	t3,
+		uint5_t		t1
+	} with { variant "" };
+
+	/* 10.5.2.40 */
+	type integer TimingAdvance (0..219);
+
+	/* 10.5.2.43 */
+	type uint8_t WaitIndication;
+
+	/* 10.5.2.76 */
+	type record FeatureIndicator {
+		BIT2	spare,
+		boolean	cs_ir,
+		boolean	ps_ir
+	} with { variant "" };
+
+
+	/* 9.1.18 */
+	type record ImmediateAssignment {
+		DedicatedModeOrTbf		ded_or_tbf,
+		PageMode			page_mode,
+		ChannelDescription		chan_desc optional,
+		PacketChannelDescription	pkt_chan_desc optional,
+		RequestReference		req_ref,
+		TimingAdvance			timing_advance,
+		MobileAllocation		mobile_allocation
+	} with { variant (chan_desc) "PRESENCE(ded_or_tbf.tbf = false)"
+		 variant (pkt_chan_desc) "PRESENCE(ded_or_tbf.tbf = true)" };
+
+	/* 9.1.20 */
+	type record ReqRefWaitInd {
+		RequestReference		req_ref,
+		WaitIndication			wait_ind
+	} with { variant "" };
+	type record length(4) of ReqRefWaitInd ReqRefWaitInd4;
+	type record ImmediateAssignmentReject {
+		FeatureIndicator		feature_ind,
+		PageMode			page_mode,
+		ReqRefWaitInd4			payload
+	} with { variant "" };
+
+	/* 9.1.22 */
+	type record PagingRequestType1 {
+		ChannelNeeded12			chan_needed,
+		PageMode			page_mode,
+		MobileIdentityLV		mi1,
+		MobileIdentityTLV		mi2 optional,
+		RestOctets			rest_octets
+	} with { variant "TAG(mi2, tag = 23)" };
+
+	/* 9.1.23 */
+	type record PagingRequestType2 {
+		ChannelNeeded12			chan_needed,
+		PageMode			page_mode,
+		GsmTmsi				mi1,
+		GsmTmsi				mi2,
+		MobileIdentityTLV		mi3 optional,
+		RestOctets			rest_octets
+	} with { variant "TAG(mi3, tag = 23)" };
+
+	/* 9.1.24 */
+	type record length(4) of GsmTmsi GsmTmsi4;
+	type record PagingRequestType3 {
+		ChannelNeeded12			chan_needed,
+		PageMode			page_mode,
+		GsmTmsi4			mi,
+		RestOctets			rest_octets
+	} with { variant "" };
+
+
+	type union RrUnion {
+/*
+		SystemInformationType1		si1,
+		SystemInformationType2		si2,
+		SystemInformationType2bis	si2bis,
+		SystemInformationType2ter	si2ter,
+		SystemInformationType3		si3,
+		SystemInformationType4		si4,
+		SystemInformationType5		si5,
+		SystemInformationType5bis	si5bis,
+		SystemInformationType5ter	si5ter,
+		SystemInformationType6		si6,
+*/
+		ImmediateAssignment		imm_ass,
+		ImmediateAssignmentReject	imm_ass_rej,
+		PagingRequestType1		pag_req_1,
+		PagingRequestType2		pag_req_2,
+		PagingRequestType3		pag_req_3,
+		octetstring			other
+	} with { variant "" };
+
+	/* Special RR Message on BCCH / CCCH Dowlink */
+
+	type record GsmRrMessage {
+		RrHeader	header,
+		RrUnion		payload
+	} with { variant (payload) "CROSSTAG(
+/*
+			      si1, header.message_type = SYSTEM_INFORMATION_TYPE_1;
+			      si2, header.message_type = SYSTEM_INFORMATION_TYPE_2;
+			      si2bis, header.message_type = SYSTEM_INFORMATION_TYPE_2bis;
+			      si2ter, header.message_type = SYSTEM_INFORMATION_TYPE_2ter;
+			      si3, header.message_type = SYSTEM_INFORMATION_TYPE_3;
+			      si4, header.message_type = SYSTEM_INFORMATION_TYPE_4;
+			      si5, header.message_type = SYSTEM_INFORMATION_TYPE_5;
+			      si5bis, header.message_type = SYSTEM_INFORMATION_TYPE_5bis;
+			      si5ter, header.message_type = SYSTEM_INFORMATION_TYPE_5ter;
+			      si6, header.message_type = SYSTEM_INFORMATION_TYPE_6;
+*/
+				imm_ass, header.message_type = IMMEDIATE_ASSIGNMENT;
+				imm_ass_rej, header.message_type = IMMEDIATE_ASSIGNMENT_REJECT;
+				pag_req_1, header.message_type = PAGING_REQUEST_TYPE_1;
+				pag_req_2, header.message_type = PAGING_REQUEST_TYPE_2;
+				pag_req_3, header.message_type = PAGING_REQUEST_TYPE_3;
+			      other, OTHERWISE;
+			)" };
+
+	/* Normal L3 Message on Dedicated Channel */
+
+	/* 9.1.25 Paging Response */
+	type record PagingResponse {
+		uint4_t			spare_half_octet,
+		CipheringKeySeqNr	cksn,
+		MsClassmark2LV		cm2,
+		MobileIdentityLV	mi,
+		uint8_t			addl_upd_par optional
+	} with { variant "" };
+
+	type union RrL3Union {
+		PagingResponse	paging_response,
+		octetstring	other
+	};
+
+	type record GsmRrL3Message {
+		RrL3Header	header,
+		RrL3Union	payload
+	} with { variant (payload) "CROSSTAG(
+				paging_response, header.message_type = PAGING_RESPONSE;
+
+				other, OTHERWISE;
+		)" }
+
+
 } with { encode "RAW"; variant "FIELDORDER(msb)" }
diff --git a/sysinfo/Test.ttcn b/sysinfo/Test.ttcn
index 6bd69fe..b9bb62d 100644
--- a/sysinfo/Test.ttcn
+++ b/sysinfo/Test.ttcn
@@ -797,7 +797,7 @@
 	}
 
 	template SystemInformation t_SI_SI3 := {
-		header := t_SiHeader(SYSTEM_INFORMATION_TYPE_3, ?),
+		header := t_RrHeader(SYSTEM_INFORMATION_TYPE_3, ?),
 		payload := { si3 := t_SI3 }
 	}