module Osmocom_Gb_Types {

	/* This module contains additional definitions and templates that we use on top of the
	 * TITAN NS + BSSGP modules */

	import from General_Types all;
	import from Osmocom_Types all;
	import from Misc_Helpers all;
	import from GSM_Types all;
	import from BSSGP_Types all
	import from NS_Types all
	import from Native_Functions all;

	type uint16_t Nsvci;
	type uint16_t Nsei;
	type uint16_t BssgpBvci;

	template (present) BssgpBvci t_BssgpBvciUser := complement (0);

	type enumerated OsmoNsDialect {
		NS2_DIALECT_UNDEF		('00'H),
		NS2_DIALECT_STATIC_ALIVE	('01'H),
		NS2_DIALECT_STATIC_RESETBLOCK	('02'H),
		NS2_DIALECT_IPACCESS		('03'H),
		NS2_DIALECT_SNS			('04'H)
	};

	/* TS 48.016 10.3.7 */
	type enumerated NsPduType {
		NS_PDUT_NS_UNITDATA	('00000000'B),
		NS_PDUT_NS_RESET	('00000010'B),
		NS_PDUT_NS_RESET_ACK	('00000011'B),
		NS_PDUT_NS_BLOCK	('00000100'B),
		NS_PDUT_NS_BLOCK_ACK	('00000101'B),
		NS_PDUT_NS_UNBLOCK	('00000110'B),
		NS_PDUT_NS_UNBLOCK_ACK	('00000111'B),
		NS_PDUT_NS_STATUS	('00001000'B),
		NS_PDUT_NS_ALIVE	('00001010'B),
		NS_PDUT_NS_ALIVE_ACK	('00001011'B)
		/* FIXME: SNS */
	} with { variant "FIELDLENGTH(8)" };

	/* TS 48.016 10.3 */
	type enumerated NsIEI {
		NS_IEI_CAUSE		('00000000'B),
		NS_IEI_NSVCI		('00000001'B),
		NS_IEI_NS_PDU		('00000010'B),
		NS_IEI_BVCI		('00000011'B),
		NS_IEI_NSEI		('00000100'B),
		NS_IEI_LIST_IPv4	('00000101'B),
		NS_IEI_LIST_IPv6	('00000110'B),
		NS_IEI_MAX_NUM_NSVC	('00000111'B),
		NS_IEI_NUM_IPv4_EP	('00001000'B),
		NS_IEI_NUM_IPv6_EP	('00001001'B),
		NS_IEI_RESET_FLAG	('00001010'B),
		NS_IEI_IP_ADDRESS	('00001011'B)
	} with { variant "FIELDLENGTH(8)" };

	/* TS 48.016 10.3.2 */
	type enumerated NsCause {
		NS_CAUSE_TRANSIT_NETWORK_FAILURE		('00000000'B),
		NS_CAUSE_OM_INTERVENTION			('00000001'B),
		NS_CAUSE_EQUIPMENT_FAILURE			('00000010'B),
		NS_CAUSE_NSVC_BLOCKED				('00000011'B),
		NS_CAUSE_NSVC_UNKNOWN				('00000100'B),
		NS_CAUSE_BVCI_UNKNOWN_AT_NSE			('00000101'B),
		NS_CAUSE_SEMANTICALLY_INCORRECT_PDU		('00001000'B),
		NS_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE	('00001010'B),
		NS_CAUSE_PROTOCOL_ERROR_UNSPECIFIED		('00001011'B),
		NS_CAUSE_INVALID_ESSENTIAL_IE			('00001100'B),
		NS_CAUSE_MISSING_ESSENTIAL_IE			('00001101'B),
		NS_CAUSE_INVALID_NR_OF_IPv4_ENDPOINTS		('00001110'B),
		NS_CAUSE_INVALID_NR_OF_IPv6_ENDPOINTS		('00001111'B),
		NS_CAUSE_INVALID_NR_OF_NSVCS			('00010000'B),
		NS_CAUSE_INVALID_WEIGHTS			('00010001'B),
		NS_CAUSE_UNKNOWN_IP_ENDPOINT			('00010010'B),
		NS_CAUSE_UNKNOWN_IP_ADDRESS			('00010011'B),
		NS_CAUSE_IP_TEST_FAILEDA			('00010100'B)
	} with { variant "FIELDLENGTH(8)" };

	template (value) NS_SDU_ControlBits t_SduCtrlB := {
		rBit := '0'B,
		cBit := '0'B,
		spare := '000000'B
	}

	template (value) CauseNS ts_NS_IE_CAUSE(NsCause cause) := {
		iEI := '00'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		cause := int2oct(enum2int(valueof(cause)), 1)
	}
	function ts_NS_IE_CAUSE_omit(template (omit) NsCause cause) return template (omit) CauseNS {
		var template (omit) CauseNS ret;
		if (istemplatekind(cause, "omit")) {
			return omit;
		} else {
			ret := {
				iEI := '00'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				cause := int2oct(enum2int(valueof(cause)), 1)
			}
			return ret;
		}
	}

	function tr_NS_IE_CAUSE(template NsCause cause) return template CauseNS {
		var template CauseNS ret;
		ret.iEI := '00'O;
		ret.ext := '1'B;
		ret.lengthIndicator := { length1 := 1 };
		if (istemplatekind(cause, "omit")) {
			return omit;
		} else if (istemplatekind(cause, "*")) {
			return *;
		} else if (istemplatekind(cause, "?")) {
			ret.cause := ?
		} else {
			ret.cause := int2oct(enum2int(valueof(cause)), 1);
		}
		return ret;
	}

	function ts_SNS_IP_ADDR(template (omit) IPAddress ip) return template (omit) IP_Address_NS {
		var template (omit) IP_Address_NS ret;
		if (istemplatekind(ip, "omit")) {
			return omit;
		} else {
			ret.iEI := '0B'O;
			ret.ipAddress := ip;
			if (ischosen(ip.ip4Address)) {
				ret.addressType := '01'O;
			} else {
				ret.addressType := '02'O;
			}
		}
		return ret;
	}
	function tr_SNS_IP_ADDR(template IPAddress ip) return template IP_Address_NS {
		var template IP_Address_NS ret;
		ret.iEI := '0B'O;
		if (istemplatekind(ip, "omit")) {
			return omit;
		} else if (istemplatekind(ip, "*")) {
			return *;
		} else if (istemplatekind(ip, "?")) {
			return ?;
		} else {
			ret.ipAddress := ip;
			if (ischosen(ip.ip4Address)) {
				ret.addressType := '01'O;
			} else {
				ret.addressType := '02'O;
			}
		}
		return ret;
	}

	private function f_oct_or_wc(template integer inp, integer len) return template octetstring {
		if (istemplatekind(inp, "omit")) {
			return omit;
		} else if (istemplatekind(inp, "*")) {
			return *;
		} else if (istemplatekind(inp, "?")) {
			return ?;
		}
		return int2oct(valueof(inp), len);
	}

	private function f_hex_or_wc(template integer inp, integer len) return template hexstring {
		if (istemplatekind(inp, "omit")) {
			return omit;
		} else if (istemplatekind(inp, "*")) {
			return *;
		} else if (istemplatekind(inp, "?")) {
			return ?;
		}
		return int2hex(valueof(inp), len);
	}

	template (value) NS_VCI ts_NS_IE_NSVCI(Nsvci nsvci) := {
		iEI := '01'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		nS_VCI := int2oct(nsvci, 2)
	}
	template NS_VCI tr_NS_IE_NSVCI(template Nsvci nsvci) := {
		iEI := '01'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		nS_VCI := f_oct_or_wc(nsvci, 2)
	}

	template (value) NSEI_NS ts_NS_IE_NSEI(Nsei nsei) := {
		iEI:= '04'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		nSEI := int2oct(nsei, 2)
	}
	template NSEI_NS tr_NS_IE_NSEI(template Nsei nsei) := {
		iEI:= '04'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		nSEI := f_oct_or_wc(nsei, 2)
	}

	template (value) IP4_Element ts_SNS_IPv4(charstring ip, integer udp_port,
						 uint8_t sig_weight := 1, uint8_t data_weight := 1) := {
		ipAddress := f_inet_addr(ip),
		uDP_Port := int2oct(udp_port, 2),
		signallingWeight := int2oct(sig_weight, 1),
		dataWeight := int2oct(data_weight, 1)
	}
	function tr_SNS_IPv4(template charstring ip, template integer udp_port,
				template uint8_t sig_weight := ?, template uint8_t data_weight := ?)
	return template IP4_Element {
		var template IP4_Element e;
		if (istemplatekind(ip, "?")) {
			e.ipAddress := ?;
		} else {
			e.ipAddress := f_inet_addr(valueof(ip));
		}
		if (istemplatekind(udp_port, "?")) {
			e.uDP_Port := ?;
		} else {
			e.uDP_Port := int2oct(valueof(udp_port), 2);
		}
		if (istemplatekind(sig_weight, "?")) {
			e.signallingWeight := ?;
		} else {
			e.signallingWeight := int2oct(valueof(sig_weight), 1);
		}
		if (istemplatekind(data_weight, "?")) {
			e.dataWeight := ?;
		} else {
			e.dataWeight := int2oct(valueof(data_weight), 1);
		}
		return e;
	}

	template (value) IP6_Element ts_SNS_IPv6(charstring ip, integer udp_port,
						 uint8_t sig_weight := 1, uint8_t data_weight := 1) := {
		ipAddress := f_inet6_addr(ip),
		uDP_Port := int2oct(udp_port, 2),
		signallingWeight := int2oct(sig_weight, 1),
		dataWeight := int2oct(data_weight, 1)
	}
	function tr_SNS_IPv6(template charstring ip, template integer udp_port,
				template uint8_t sig_weight := ?, template uint8_t data_weight := ?)
	return template IP6_Element {
		var template IP6_Element e;
		if (istemplatekind(ip, "?")) {
			e.ipAddress := ?;
		} else {
			e.ipAddress := f_inet6_addr(valueof(ip));
		}
		if (istemplatekind(udp_port, "?")) {
			e.uDP_Port := ?;
		} else {
			e.uDP_Port := int2oct(valueof(udp_port), 2);
		}
		if (istemplatekind(sig_weight, "?")) {
			e.signallingWeight := ?;
		} else {
			e.signallingWeight := int2oct(valueof(sig_weight), 1);
		}
		if (istemplatekind(data_weight, "?")) {
			e.dataWeight := ?;
		} else {
			e.dataWeight := int2oct(valueof(data_weight), 1);
		}
		return e;
	}


	template (value) PDU_NS ts_NS_RESET(NsCause cause, Nsvci nsvci, Nsei nsei) := {
		pDU_NS_Reset := {
			nsPduType := '02'O,
			causeNS := ts_NS_IE_CAUSE(cause),
			nS_VCI := ts_NS_IE_NSVCI(nsvci),
			nSEI_NS := ts_NS_IE_NSEI(nsei)
		}
	}
	template PDU_NS tr_NS_RESET(template NsCause cause, template Nsvci nsvci, template Nsei nsei) := {
		pDU_NS_Reset := {
			nsPduType := '02'O,
			causeNS := tr_NS_IE_CAUSE(cause),
			nS_VCI := tr_NS_IE_NSVCI(nsvci),
			nSEI_NS := tr_NS_IE_NSEI(nsei)
		}
	}

	template (value) PDU_NS ts_NS_RESET_ACK(Nsvci nsvci, Nsei nsei) := {
		pDU_NS_Reset_Ack := {
			nsPduType := '03'O,
			nS_VCI := ts_NS_IE_NSVCI(nsvci),
			nSEI_NS := ts_NS_IE_NSEI(nsei)
		}
	}
	template PDU_NS tr_NS_RESET_ACK(template Nsvci nsvci, template Nsei nsei) := {
		pDU_NS_Reset_Ack := {
			nsPduType := '03'O,
			nS_VCI := tr_NS_IE_NSVCI(nsvci),
			nSEI_NS := tr_NS_IE_NSEI(nsei)
		}
	}

	template (value) PDU_NS ts_NS_BLOCK(NsCause cause, Nsvci nsvci) := {
		pDU_NS_Block := {
			nsPduType := '04'O,
			causeNS := ts_NS_IE_CAUSE(cause),
			nS_VCI := ts_NS_IE_NSVCI(nsvci)
		}
	}
	template PDU_NS tr_NS_BLOCK(template NsCause cause, template Nsvci nsvci) := {
		pDU_NS_Block := {
			nsPduType := '04'O,
			causeNS := tr_NS_IE_CAUSE(cause),
			nS_VCI := tr_NS_IE_NSVCI(nsvci)
		}
	}

	template (value) PDU_NS ts_NS_BLOCK_ACK(Nsvci nsvci) := {
		pDU_NS_Block_Ack := {
			nsPduType := '05'O,
			nS_VCI := ts_NS_IE_NSVCI(nsvci)
		}
	}
	template PDU_NS tr_NS_BLOCK_ACK(template Nsvci nsvci) := {
		pDU_NS_Block_Ack := {
			nsPduType := '05'O,
			nS_VCI := tr_NS_IE_NSVCI(nsvci)
		}
	}

	template PDU_NS t_NS_UNBLOCK := {
		pDU_NS_Unblock := {
			nsPduType := '06'O
		}
	}

	template PDU_NS t_NS_UNBLOCK_ACK := {
		pDU_NS_Unblock_Ack := {
			nsPduType := '07'O
		}
	}

	template PDU_NS t_NS_ALIVE := {
		pDU_NS_Alive := {
			nsPduType := '0A'O
		}
	}

	template PDU_NS t_NS_ALIVE_ACK := {
		pDU_NS_Alive_Ack := {
			nsPduType := '0B'O
		}
	}

	template (value) PDU_NS ts_NS_STATUS(NsCause cause, PDU_NS pdu) := {
		pDU_NS_Status := {
			nsPduType := '08'O,
			causeNS := ts_NS_IE_CAUSE(cause),
			nS_VCI := omit,
			nS_PDU := {
				iEI := '02'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 0 /* overwritten */
				},
				ns_PDU := enc_PDU_NS(pdu)
			},
			bVCI_NS := omit,
			listofIP4Elements := omit,
			listofIP6Elements := omit
		}
	}

	template PDU_NS tr_NS_STATUS(template NsCause cause) := {
		pDU_NS_Status := {
			nsPduType := '08'O,
			causeNS := tr_NS_IE_CAUSE(cause),
			nS_VCI := *,
			nS_PDU := *,
			bVCI_NS := *,
			listofIP4Elements := *,
			listofIP6Elements := *
		}
	}

	template (value) PDU_NS ts_NS_UNITDATA(template (value) NS_SDU_ControlBits bits, BssgpBvci bvci, octetstring sdu) := {
		pDU_NS_Unitdata := {
			nsPduType := '00'O,
			nS_SDU_ControlBits := bits,
			bVCI := int2oct(bvci, 2),
			nS_SDU := sdu
		}
	}
	template PDU_NS tr_NS_UNITDATA(template NS_SDU_ControlBits bits, template BssgpBvci bvci, template
octetstring sdu) := {
		pDU_NS_Unitdata := {
			nsPduType := '00'O,
			nS_SDU_ControlBits := bits,
			bVCI := f_oct_or_wc(bvci, 2),
			nS_SDU := sdu
		}
	}
	template PDU_NS tr_NS_UNITDATA_User(template NS_SDU_ControlBits bits, template octetstring sdu) := {
		pDU_NS_Unitdata := {
			nsPduType := '00'O,
			nS_SDU_ControlBits := bits,
			bVCI := complement ('0000'O),
			nS_SDU := sdu
		}
	}



	private function ts_num_of_ep(OCT1 iei, template (omit) uint16_t num_ep)
	return template (omit) NumberOfIP_Endpoints {
		var template (omit) NumberOfIP_Endpoints t;
		if (istemplatekind(num_ep, "omit")) {
			return omit;
		} else {
			t.iEI := iei;
			t.numberOfIP_Endpoints := int2oct(valueof(num_ep), 2);
			return t;
		}
	}
	private function tr_num_of_ep(OCT1 iei, template uint16_t num_ep)
	return template NumberOfIP_Endpoints {
		var template NumberOfIP_Endpoints t;
		if (istemplatekind(num_ep, "omit")) {
			return omit;
		} else if (istemplatekind(num_ep, "*")) {
			return *;
		} else if (istemplatekind(num_ep, "?")) {
			return ?;
		} else {
			t.iEI := iei;
			t.numberOfIP_Endpoints := int2oct(valueof(num_ep), 2);
			return t;
		}
	}


	template (value) ResetFlag ts_SNS_IE_ResetFlag(boolean rst) := {
		iEI := '0A'O,
		resetBIT := bool2bit(rst),
		spare := '0000000'B
	}
	template ResetFlag tr_SNS_IE_ResetFlag(template boolean rst) := {
		iEI := '0A'O,
		resetBIT := bool2bit_tmpl(rst),
		spare := '0000000'B
	}

	template (value) EndFlag ts_SNS_IE_EndFlag(boolean end) := {
		eBIT := bool2bit(end),
		spare := '0000000'B
	}
	template EndFlag tr_SNS_IE_EndFlag(template boolean end) := {
		eBIT := bool2bit_tmpl(end),
		spare := '0000000'B
	}

	template (value) MaxNumberOfNSVCs ts_SNS_IE_MaxNumOfNSVCs(uint16_t num) := {
		iEI := '07'O,
		maxNumberOfNSVCs := int2oct(num, 2)
	}
	template MaxNumberOfNSVCs tr_SNS_IE_MaxNumOfNSVCs(template uint16_t num) := {
		iEI := '07'O,
		maxNumberOfNSVCs := f_oct_or_wc(num, 2)
	}

	template (value) PDU_NS ts_SNS_SIZE(Nsei nsei, boolean rst_flag := true,
				uint16_t max_nsvcs := 2,
				template (omit) uint16_t num_v4 := 1,
				template (omit) uint16_t num_v6 := omit) := {
		pDU_SNS_Size := {
			nsPduType := '12'O,
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			resetFlag := ts_SNS_IE_ResetFlag(rst_flag),
			maxNumberOfNSVCs := ts_SNS_IE_MaxNumOfNSVCs(max_nsvcs),
			numberOfIP4_Endpoints := ts_num_of_ep('08'O, num_v4),
			numberOfIP6_Endpoints := ts_num_of_ep('09'O, num_v6)
		}
	}
	template PDU_NS tr_SNS_SIZE(template Nsei nsei, template boolean rst_flag := ?,
				template uint16_t max_nsvcs := ?,
				template uint16_t num_v4 := ?,
				template uint16_t num_v6 := *) := {
		pDU_SNS_Size := {
			nsPduType := '12'O,
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			resetFlag := tr_SNS_IE_ResetFlag(rst_flag),
			maxNumberOfNSVCs := tr_SNS_IE_MaxNumOfNSVCs(max_nsvcs),
			numberOfIP4_Endpoints := tr_num_of_ep('08'O, num_v4),
			numberOfIP6_Endpoints := tr_num_of_ep('09'O, num_v6)
		}
	}

	template PDU_NS ts_SNS_SIZE_ACK(Nsei nsei, template (omit) NsCause cause) := {
		pDU_SNS_Size_Ack := {
			nsPduType := '13'O,
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			causeNS := ts_NS_IE_CAUSE_omit(cause)
		}
	}
	template PDU_NS tr_SNS_SIZE_ACK(template Nsei nsei, template NsCause cause) := {
		pDU_SNS_Size_Ack := {
			nsPduType := '13'O,
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			causeNS := tr_NS_IE_CAUSE(cause)
		}
	}

	private function ts_SNS_IE_ListIP4(template (omit) IP4_Elements elem)
	return template (omit) ListofIP4Elements {
		var template (omit) ListofIP4Elements r;
		if (istemplatekind(elem, "omit")) {
			return omit;
		} else {
			r := {
				iEI := '05'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 0 /* overwritten */
				},
				iP4_Elements := elem
			}
			return r;
		}
	}
	private function tr_SNS_IE_ListIP4(template IP4_Elements elem)
	return template ListofIP4Elements {
		var template ListofIP4Elements r;
		if (istemplatekind(elem, "omit")) {
			return omit;
		} else if (istemplatekind(elem, "*")) {
			return *;
		} else if (istemplatekind(elem, "?")) {
			return ?;
		} else {
			r := {
				iEI := '05'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := ? /* overwritten */
				},
				iP4_Elements := elem
			}
			return r;
		}
	}

	private function ts_SNS_IE_ListIP6(template (omit) IP6_Elements elem)
	return template (omit) ListofIP6Elements {
		var template (omit) ListofIP6Elements r;
		if (istemplatekind(elem, "omit")) {
			return omit;
		} else {
			r := {
				iEI := '06'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 0 /* overwritten */
				},
				iP6_Elements := elem
			}
			return r;
		}
	}
	private function tr_SNS_IE_ListIP6(template IP6_Elements elem)
	return template ListofIP6Elements {
		var template ListofIP6Elements r;
		if (istemplatekind(elem, "omit")) {
			return omit;
		} else if (istemplatekind(elem, "*")) {
			return *;
		} else if (istemplatekind(elem, "?")) {
			return ?;
		} else {
			r := {
				iEI := '06'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := ? /* overwritten */
				},
				iP6_Elements := elem
			}
			return r;
		}
	}

	template (value) PDU_NS ts_SNS_CONFIG(Nsei nsei, boolean end_flag,
					template (omit) IP4_Elements v4 := omit,
					template (omit) IP6_Elements v6 := omit) := {
		pDU_SNS_Config := {
			nsPduType := '0F'O,
			endFlag := ts_SNS_IE_EndFlag(end_flag),
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			listofIP4Elements := ts_SNS_IE_ListIP4(v4),
			listofIP6Elements := ts_SNS_IE_ListIP6(v6)
		}
	}
	template PDU_NS tr_SNS_CONFIG(template Nsei nsei, template boolean end_flag,
					template IP4_Elements v4 := omit,
					template IP6_Elements v6 := omit) := {
		pDU_SNS_Config := {
			nsPduType := '0F'O,
			endFlag := tr_SNS_IE_EndFlag(end_flag),
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			listofIP4Elements := tr_SNS_IE_ListIP4(v4),
			listofIP6Elements := tr_SNS_IE_ListIP6(v6)
		}
	}

	template (value) PDU_NS ts_SNS_CONFIG_ACK(Nsei nsei, template (omit) NsCause cause) := {
		pDU_SNS_Config_Ack := {
			nsPduType := '10'O,
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			causeNS := ts_NS_IE_CAUSE_omit(cause)
		}
	}
	template PDU_NS tr_SNS_CONFIG_ACK(template Nsei nsei, template NsCause cause) := {
		pDU_SNS_Config_Ack := {
			nsPduType := '10'O,
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			causeNS := tr_NS_IE_CAUSE(cause)
		}
	}

	template (value) PDU_NS ts_SNS_ADD(Nsei nsei, uint8_t trans_id,
					   template (omit) IP4_Elements v4,
					   template (omit) IP6_Elements v6 := omit) := {
		pDU_SNS_Add := {
			nsPduType := '0D'O,
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			listofIP4Elements := ts_SNS_IE_ListIP4(v4),
			listofIP6Elements := ts_SNS_IE_ListIP6(v6)
		}
	}
	template PDU_NS tr_SNS_ADD(template Nsei nsei, template uint8_t trans_id,
				   template IP4_Elements v4,
				   template IP6_Elements v6 := omit) := {
		pDU_SNS_Add := {
			nsPduType := '0D'O,
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			listofIP4Elements := tr_SNS_IE_ListIP4(v4),
			listofIP6Elements := tr_SNS_IE_ListIP6(v6)
		}
	}

	template (value) PDU_NS ts_SNS_DEL(Nsei nsei, uint8_t trans_id,
					   template (omit) IPAddress ip_sns,
					   template (omit) IP4_Elements v4,
					   template (omit) IP6_Elements v6 := omit) := {
		pDU_SNS_Delete := {
			nsPduType := '11'O,
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			iP_Address_NS := ts_SNS_IP_ADDR(ip_sns),
			listofIP4Elements := ts_SNS_IE_ListIP4(v4),
			listofIP6Elements := ts_SNS_IE_ListIP6(v6)
		}
	}
	template PDU_NS tr_SNS_DEL(template Nsei nsei, template uint8_t trans_id,
				   template IPAddress ip_sns,
				   template IP4_Elements v4,
				   template IP6_Elements v6 := omit) := {
		pDU_SNS_Delete := {
			nsPduType := '11'O,
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			iP_Address_NS := tr_SNS_IP_ADDR(ip_sns),
			listofIP4Elements := tr_SNS_IE_ListIP4(v4),
			listofIP6Elements := tr_SNS_IE_ListIP6(v6)
		}
	}

	template (value) PDU_NS ts_SNS_CHG_WEIGHT(Nsei nsei, uint8_t trans_id,
						  template (omit) IP4_Elements v4,
						  template (omit) IP6_Elements v6 := omit) := {
		pDU_SNS_ChangeWeight := {
			nsPduType := '0E'O,
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			listofIP4Elements := ts_SNS_IE_ListIP4(v4),
			listofIP6Elements := ts_SNS_IE_ListIP6(v6)
		}
	}
	template PDU_NS tr_SNS_CHG_WEIGHT(template Nsei nsei, template uint8_t trans_id,
					  template IP4_Elements v4,
					  template IP6_Elements v6 := omit) := {
		pDU_SNS_ChangeWeight := {
			nsPduType := '0E'O,
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			listofIP4Elements := tr_SNS_IE_ListIP4(v4),
			listofIP6Elements := tr_SNS_IE_ListIP6(v6)
		}
	}


	template (value) PDU_NS ts_SNS_ACK(Nsei nsei, uint8_t trans_id,
					   template (omit) NsCause cause := omit,
					   template (omit) IP4_Elements v4 := omit,
					   template (omit) IP6_Elements v6 := omit) := {
		pDU_SNS_Ack := {
			nsPduType := '0C'O,
			nSEI_NS := ts_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			causeNS := ts_NS_IE_CAUSE_omit(cause),
			iP_Address_NS := omit,
			listofIP4Elements := ts_SNS_IE_ListIP4(v4),
			listofIP6Elements := ts_SNS_IE_ListIP6(v6)
		}
	}
	template PDU_NS tr_SNS_ACK(template Nsei nsei, template uint8_t trans_id := ?,
					   template NsCause cause := omit,
					   template IP4_Elements v4 := *,
					   template IP6_Elements v6 := *) := {
		pDU_SNS_Ack := {
			nsPduType := '0C'O,
			nSEI_NS := tr_NS_IE_NSEI(nsei),
			transactionID := trans_id,
			causeNS := tr_NS_IE_CAUSE(cause),
			iP_Address_NS := omit,
			listofIP4Elements := tr_SNS_IE_ListIP4(v4),
			listofIP6Elements := tr_SNS_IE_ListIP6(v6)
		}
	}

	template PDU_NS tr_SNS(template Nsei nsei) := ( tr_SNS_SIZE(nsei),
							tr_SNS_SIZE_ACK(nsei, *),
							tr_SNS_CONFIG(nsei, ?, *, *),
							tr_SNS_CONFIG_ACK(nsei, *),
							tr_SNS_ADD(nsei, ?, *, *),
							tr_SNS_DEL(nsei, ?, *, *),
							tr_SNS_CHG_WEIGHT(nsei, ?, *, *),
							tr_SNS_ACK(nsei, ?, *, *, *) )






	type record BssgpCellId {
		RoutingAreaIdentification	ra_id,
		CellIdentity			cell_id
	} with { variant "" };

	template (value) BssgpCellId ts_BssgpCellId(template (value) RoutingAreaIdentification rai, CellIdentity cell_id) := {
		ra_id := rai,
		cell_id := cell_id
	};

	type enumerated BssgpCause {
		BSSGP_CAUSE_PROC_OVERLOAD			('00'H),
		BSSGP_CAUSE_EQUIMENT_FAILURE			('01'H),
		BSSGP_CAUSE_TRANSIT_NETWORK_FAILURE		('02'H),
		BSSGP_CAUSE_NET_SV_CAP_MOD_GT_ZERO_KBPS		('03'H),
		BSSGP_CAUSE_UNKNOWN_MS				('04'H),
		BSSGP_CAUSE_BVCI_UNKNOWN			('05'H),
		BSSGP_CAUSE_CELL_TRAFFIC_CONGESTION		('06'H),
		BSSGP_CAUSE_SGSN_CONGESTION			('07'H),
		BSSGP_CAUSE_OM_INTERVENTION			('08'H),
		BSSGP_CAUSE_BVCI_BLOCKED			('09'H),
		BSSGP_CAUSE_PFC_CREATE_FAILURE			('0a'H),
		BSSGP_CAUSE_PFC_PREEMPTED			('0b'H),
		BSSGP_CAUSE_ABQP_NO_MORE_SUPPORTED		('0c'H),
		BSSGP_CAUSE_SEMANTICALLY_INCORRECT_PDU		('20'H),
		BSSGP_CAUSE_INVALID_MANDATORY_IE		('21'H),
		BSSGP_CAUSE_MISSING_MANDATORY_IE		('22'H),
		BSSGP_CAUSE_MISSING_CONDITIONAL_IE		('23'H),
		BSSGP_CAUSE_UNEXPECTED_CONDITIONAL_IE		('24'H),
		BSSGP_CAUSE_CONDITIONAL_IE_ERROR		('25'H),
		BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_PROTOCOL_STATE ('26'H),
		BSSGP_CAUSE_PROTOCOL_ERROR_UNSPECIFIED		('27'H),
		BSSGP_CAUSE_PDU_NOT_COMPATIBLE_WITH_FEATURE_SET	('28'H),
		BSSGP_CAUSE_REQUESTED_INFO_NOT_AVAILABLE	('29'H),
		BSSGP_CAUSE_UNKNOWN_DESTINATION_ADDRESS		('2a'H),
		BSSGP_CAUSE_UNKNOWN_RIM_APP_IDENTITY		('2b'H),
		BSSGP_CAUSE_INVALID_CONTAINER_UNIT_INFO		('2c'H),
		BSSGP_CAUSE_PFC_QUEUING				('2d'H),
		BSSGP_CAUSE_PFC_CREATED_SUCCESSFULLY		('2e'H),
		BSSGP_CAUSE_T12_EXPIRY				('2f'H),
		BSSGP_CAUSE_MS_UNDER_PS_HANDOVER_TREATMENT	('30'H),
		BSSGP_CAUSE_UPLINK_QUALITY			('31'H),
		BSSGP_CAUSE_UPLINK_STRENGTH			('32'H),
		BSSGP_CAUSE_DOWNLINK_QUALITY			('33'H),
		BSSGP_CAUSE_DOWNLINK_STRENGTH			('34'H),
		BSSGP_CAUSE_DISTANCE				('35'H),
		BSSGP_CAUSE_BETTER_CELL				('36'H),
		BSSGP_CAUSE_TRAFFIC				('37'H),
		BSSGP_CAUSE_OM_INTERVENTION2			('38'H),
		BSSGP_CAUSE_MS_BACK_ON_OLD_CHANNEL		('39'H),
		BSSGP_CAUSE_T13_EXPIRY				('3a'H),
		BSSGP_CAUSE_T14_EXPIRY				('3b'H),
		BSSGP_CAUSE_NOT_ALL_REQUESTED_PFC_CREATED	('3c'H)
	} with { variant "FIELDLENGTH(8)" };

	private function tr_FLUSH_ACTION(template OCT1 act)
	return template Flush_Action {
		var template Flush_Action r;
		if (istemplatekind(act, "omit")) {
			return omit;
		} else if (istemplatekind(act, "*")) {
			return *;
		} else {
			r := {
				iEI := '0C'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				actionValue := act
			}
			return r;
		}
	}
	template (value) Flush_Action ts_FLUSH_ACTION(template (value) OCT1 act) := {
		iEI := '0C'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		actionValue := act
	}

	private function tr_NO_OCT_AFF(template integer oct_aff)
	return template Number_of_octets_affected {
		var template Number_of_octets_affected r;
		if (istemplatekind(oct_aff, "omit")) {
			return omit;
		} else if (istemplatekind(oct_aff, "*")) {
			return *;
		} else {
			r := {
				iEI := '25'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 3
				},
				number_of_octets_transfered_or_deleted := f_oct_or_wc(oct_aff, 3)
			}
			return r;
		}
	}
	template (value) Number_of_octets_affected ts_NO_OCT_AFF(template (value) integer oct_aff) := {
		iEI := '25'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 3
		},
		number_of_octets_transfered_or_deleted :=  int2oct(valueof(oct_aff), 3)
	}

	private function tr_LLC_FRAMES_DISCARDED(template integer frames_discarded)
	return template LLC_Frames_Discarded {
		var template LLC_Frames_Discarded r;
		if (istemplatekind(frames_discarded, "omit")) {
			return omit;
		} else if (istemplatekind(frames_discarded, "*")) {
			return *;
		} else {
			r := {
				iEI := '0F'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				number_of_frames_discarded := f_hex_or_wc(frames_discarded, 2)
			}
			return r;
		}
	}
	template (value) LLC_Frames_Discarded ts_LLC_FRAMES_DISCARDED(template (value) integer frames_discarded) := {
		iEI := '0F'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		number_of_frames_discarded := int2hex(valueof(frames_discarded), 2)
	}


	private function tr_BSSGP_BVCI(template BssgpBvci bvci)
	return template BVCI {
		var template BVCI r;
		if (istemplatekind(bvci, "omit")) {
			return omit;
		} else if (istemplatekind(bvci, "*")) {
			return *;
		} else {
			r := {
				iEI := '04'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				unstructured_value := f_oct_or_wc(bvci, 2)
			}
			return r;
		}
	}
	template (value) BVCI ts_BSSGP_BVCI(template (value) BssgpBvci bvci) := {
		iEI := '04'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		unstructured_value := int2oct(valueof(bvci), 2)
	}
	private function f_ts_BSSGP_BVCI(template (omit) BssgpBvci bvci)
	return template (omit) BVCI {
		if (istemplatekind(bvci, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_BVCI(valueof(bvci));
		}
	}

	private function t_BSSGP_NSEI(template Nsei nsei)
	return template NSEI_BSSGP {
		var template NSEI_BSSGP r;
		if (istemplatekind(nsei, "omit")) {
			return omit;
		} else if (istemplatekind(nsei, "*")) {
			return *;
		} else {
			r := {
				iEI:= '3E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				nSEI := f_oct_or_wc(nsei, 2)
			}
			return r;
		}
	}
	template (value) NSEI_BSSGP ts_BSSGP_NSEI(template (value) Nsei nsei) := {
		iEI:= '3E'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		nSEI := int2oct(valueof(nsei), 2)
	}
	private function f_ts_BSSGP_NSEI(template (omit) Nsei nsei)
	return template (omit) NSEI_BSSGP {
		if (istemplatekind(nsei, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_NSEI(valueof(nsei));
		}
	}

	template (value) TLLI_BSSGP ts_BSSGP_TLLI(template (value) GprsTlli tlli) := {
		iEI := '1F'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 4
		},
		tLLI_Value := tlli
	}
	template (present) TLLI_BSSGP tr_BSSGP_TLLI(template (present) GprsTlli tlli) := {
		iEI := '1F'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 4
		},
		tLLI_Value := tlli
	}
	private function f_ts_BSSGP_TLLI(template (omit) GprsTlli tlli) return template (omit) TLLI_BSSGP {
		if (istemplatekind(tlli, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_TLLI(valueof(tlli));
		}
	}
	private function f_tr_BSSGP_TLLI(template GprsTlli tlli) return template TLLI_BSSGP {
		if (istemplatekind(tlli, "omit")) {
			return omit;
		} else if (istemplatekind(tlli, "*")) {
			return *;
		} else {
			return tr_BSSGP_TLLI(valueof(tlli));
		}
	}

	template (value) Suspend_Reference_Number ts_BSSGP_SUSP_REF(template (value) OCT1 susp_ref) := {
		iEI := '1D'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		suspend_Reference_Number_value := susp_ref
	}
	template Suspend_Reference_Number tr_BSSGP_SUSP_REF(template OCT1 susp_ref) := {
		iEI := '1D'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		suspend_Reference_Number_value := susp_ref
	}

	template (present) IMSI_BSSGP tr_BSSGP_IMSI(template (present) hexstring imsi) := {
		iEI := '0D'O,
		ext := '1'B,
		lengthIndicator := ?,
		type_of_Identity := '001'B,
		oddevenIndicator := ?,
		digits := imsi
	}

	template (value) IMSI_BSSGP ts_BSSGP_IMSI(hexstring imsi) := {
		iEI := '0D'O,
		ext := '1'B,
		lengthIndicator := { length1 := 0 /* overwritten */ },
		type_of_Identity := '001'B,
		oddevenIndicator := f_hex_is_odd_length(imsi),
		digits := imsi
	}
	private function f_ts_BSSGP_IMSI(template (omit) hexstring imsi) return template (omit) IMSI_BSSGP {
		if (istemplatekind(imsi, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_IMSI(valueof(imsi));
		}
	}
	private function f_tr_BSSGP_IMSI(template hexstring imsi) return template IMSI_BSSGP {
		if (istemplatekind(imsi, "omit")) {
			return omit;
		} else if (istemplatekind(imsi, "*")) {
			return *;
		} else {
			return tr_BSSGP_IMSI(imsi);
		}
	}

	template (present) TMSI_BSSGP tr_BSSGP_TMSI(GsmTmsi tmsi) := {
		iEI := '20'O,
		ext := '1'B,
		lengthIndicator := { length1 := 4 },
		tMSI_Value := int2oct(tmsi, 4)
	}

	template TMSI_BSSGP ts_BSSGP_TMSI(GsmTmsi tmsi) := {
		iEI := '20'O,
		ext := '1'B,
		lengthIndicator := { length1 := 4 },
		tMSI_Value := int2oct(tmsi, 4)
	}
	private function f_ts_BSSGP_TMSI(template (omit) GsmTmsi tmsi) return template (omit) TMSI_BSSGP {
		if (istemplatekind(tmsi, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_TMSI(valueof(tmsi));
		}
	}
	private function f_tr_BSSGP_TMSI(template GsmTmsi tmsi) return template TMSI_BSSGP {
		if (istemplatekind(tmsi, "omit")) {
			return omit;
		} else if (istemplatekind(tmsi, "*")) {
			return *;
		} else if (istemplatekind(tmsi, "?")) {
			return ?;
		} else {
			return tr_BSSGP_TMSI(valueof(tmsi));
		}
	}

	function f_bssgp_length_ind(integer len) return LIN2_2a {
		var LIN2_2a ret;
		if (len > 255) {
			ret := { length2 := len };
		} else {
			ret := { length1 := len };
		}
		return ret;
	}

	template LLC_PDU ts_BSSGP_LLC_PDU(octetstring pdu) := {
		iEI := '0D'O,
		ext := '1'B,
		lengthIndicator := f_bssgp_length_ind(lengthof(pdu)),
		lLC_PDU := pdu
	}

	template LLC_PDU tr_BSSGP_LLC_PDU(template octetstring pdu := ?) := {
		iEI := '0E'O,
		ext := ?,
		lengthIndicator := ?,
		lLC_PDU := pdu
	}

	function ts_BSSGP_CAUSE(template (omit) BssgpCause cause) return template (omit) Cause_BSSGP {
		var template (omit) Cause_BSSGP ret;
		if (istemplatekind(cause, "omit")) {
			ret := omit;
		} else {
			ret.iEI := '07'O;
			ret.ext := '1'B;
			ret.lengthIndicator := { length1 := 1 };
			ret.cause_Value := int2oct(enum2int(valueof(cause)), 1);
		}
		return ret;
	}
	function tr_BSSGP_CAUSE(template BssgpCause cause) return template Cause_BSSGP {
		var template Cause_BSSGP ret;
		ret.iEI := '07'O;
		ret.ext := '1'B;
		ret.lengthIndicator := { length1 := 1 };
		if (isvalue(cause)) {
			ret.cause_Value := int2oct(enum2int(valueof(cause)), 1);
		} else {
			ret.cause_Value := ?
		}
		return ret;
	}

	function tr_BSSGP_IE_CellId(template BssgpCellId cid) return template Cell_Identifier {
		var template Cell_Identifier ret := {
			iEI := '08'O,
			ext := '1'B,
			lengthIndicator := { length1 := 8 },
			mccDigit1 := ?,
			mccDigit2 := ?,
			mccDigit3 := ?,
			mncDigit3 := ?,
			mncDigit1 := ?,
			mncDigit2 := ?,
			lac := ?,
			rac := ?,
			cI_value := ?
		}
		if (istemplatekind(cid, "omit")) {
			return omit;
		} else if (istemplatekind(cid, "*")) {
			return *;
		} else if (istemplatekind(cid, "?")) {
			return ?;
		}
		if (isvalue(cid) and isvalue(cid.ra_id) and isvalue(cid.ra_id.lai)) {
			if (isvalue(cid.ra_id.lai.mcc_mnc)) {
				ret.mccDigit1 := cid.ra_id.lai.mcc_mnc[0];
				ret.mccDigit2 := cid.ra_id.lai.mcc_mnc[1];
				ret.mccDigit3 := cid.ra_id.lai.mcc_mnc[2];
				ret.mncDigit3 := cid.ra_id.lai.mcc_mnc[3];
				ret.mncDigit1 := cid.ra_id.lai.mcc_mnc[4];
				ret.mncDigit2 := cid.ra_id.lai.mcc_mnc[5];
			}
			if (isvalue(cid.ra_id.lai.lac)) {
				ret.lac := f_oct_or_wc(cid.ra_id.lai.lac, 2);
			}
		}
		if (isvalue(cid) and isvalue(cid.ra_id)) {
			ret.rac := f_oct_or_wc(cid.ra_id.rac, 1);
		}
		if (isvalue(cid)) {
			ret.cI_value := f_oct_or_wc(cid.cell_id, 2);
		}
		return ret;
	}
	template (value) Cell_Identifier ts_BSSGP_IE_CellId(template (value) BssgpCellId cid) := {
		iEI := '08'O,
		ext := '1'B,
		lengthIndicator := { length1 := 8 },
		mccDigit1 := cid.ra_id.lai.mcc_mnc[0],
		mccDigit2 := cid.ra_id.lai.mcc_mnc[1],
		mccDigit3 := cid.ra_id.lai.mcc_mnc[2],
		mncDigit3 := cid.ra_id.lai.mcc_mnc[3],
		mncDigit1 := cid.ra_id.lai.mcc_mnc[4],
		mncDigit2 := cid.ra_id.lai.mcc_mnc[5],
		lac := int2oct(valueof(cid.ra_id.lai.lac), 2),
		rac := int2oct(valueof(cid.ra_id.rac), 1),
		cI_value := int2oct(valueof(cid.cell_id), 2)
	}
	function f_ts_BSSGP_IE_CellId(template (omit) BssgpCellId cid) return template (omit) Cell_Identifier {
		if (istemplatekind(cid, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_IE_CellId(valueof(cid));
		}
	}

	template (value) Tag ts_BSSGP_IE_Tag(OCT1 tag) := {
		iEI := '1E'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		unstructured_Value := tag
	}

	template (present) Tag tr_BSSGP_IE_Tag(template (present) OCT1 tag) := {
		iEI := '1E'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		unstructured_Value := tag
	}

	template (value) RA_Cap_UPD_CAUSE ts_BSSGP_IE_RACU_Cause(template (value) OCT1 cause) := {
		iEI := '1A'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		rA_CAP_UPD_Cause_value := cause
	}

	template (present) RA_Cap_UPD_CAUSE tr_BSSGP_IE_RACU_Cause(template (present) OCT1 cause) := {
		iEI := '1A'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 1
		},
		rA_CAP_UPD_Cause_value := cause
	}

	/* 10.4.12 */
	template PDU_BSSGP ts_BVC_RESET(BssgpCause cause, BssgpBvci bvci,
					template (omit) BssgpCellId cell_id) := {
		pDU_BSSGP_BVC_RESET := {
			bssgpPduType := '22'O,
			bVCI := ts_BSSGP_BVCI(bvci),
			cause := ts_BSSGP_CAUSE(cause),
			cell_Identifier := f_ts_BSSGP_IE_CellId(cell_id),
			feature_bitmap := omit,
			extended_Feature_Bitmap := omit
		}
	}
	template PDU_BSSGP tr_BVC_RESET(template BssgpCause cause, template BssgpBvci bvci,
					template BssgpCellId cell_id) := {
		pDU_BSSGP_BVC_RESET := {
			bssgpPduType := '22'O,
			bVCI := tr_BSSGP_BVCI(bvci),
			cause := tr_BSSGP_CAUSE(cause),
			cell_Identifier := tr_BSSGP_IE_CellId(cell_id),
			feature_bitmap := *,
			extended_Feature_Bitmap := *
		}
	}

	/* 10.4.13 */
	template PDU_BSSGP ts_BVC_RESET_ACK(BssgpBvci bvci, template (omit) BssgpCellId cell_id) := {
		pDU_BSSGP_BVC_RESET_ACK := {
			bssgpPduType := '23'O,
			bVCI := ts_BSSGP_BVCI(bvci),
			cell_Identifier := f_ts_BSSGP_IE_CellId(cell_id),
			feature_bitmap := omit,
			extended_Feature_Bitmap := omit
		}
	}
	template PDU_BSSGP tr_BVC_RESET_ACK(template BssgpBvci bvci, template BssgpCellId cell_id) := {
		pDU_BSSGP_BVC_RESET_ACK := {
			bssgpPduType := '23'O,
			bVCI := tr_BSSGP_BVCI(bvci),
			cell_Identifier := tr_BSSGP_IE_CellId(cell_id),
			feature_bitmap := *,
			extended_Feature_Bitmap := *
		}
	}


	/* 10.4.10 */
	template (present) PDU_BSSGP tr_BVC_UNBLOCK(template (present) BssgpBvci bvci) := {
		pDU_BSSGP_BVC_UNBLOCK := {
			bssgpPduType := '24'O,
			bVCI := tr_BSSGP_BVCI(bvci)
		}
	}
	template (value) PDU_BSSGP ts_BVC_UNBLOCK(template (value) BssgpBvci bvci) := {
		pDU_BSSGP_BVC_UNBLOCK := {
			bssgpPduType := '24'O,
			bVCI := ts_BSSGP_BVCI(bvci)
		}
	}

	/* 10.4.11 */
	template (present) PDU_BSSGP tr_BVC_UNBLOCK_ACK(template (present) BssgpBvci bvci) := {
		pDU_BSSGP_BVC_UNBLOCK_ACK := {
			bssgpPduType := '25'O,
			bVCI := tr_BSSGP_BVCI(bvci)
		}
	}
	template (value) PDU_BSSGP ts_BVC_UNBLOCK_ACK(template (value) BssgpBvci bvci) := {
		pDU_BSSGP_BVC_UNBLOCK_ACK := {
			bssgpPduType := '25'O,
			bVCI := ts_BSSGP_BVCI(bvci)
		}
	}

	/* 10.4.8 */
	template (present) PDU_BSSGP tr_BVC_BLOCK(template (present) BssgpBvci bvci,
						  template (present) BssgpCause cause) := {
		pDU_BSSGP_BVC_BLOCK := {
			bssgpPduType := '20'O,
			bVCI := tr_BSSGP_BVCI(bvci),
			cause := tr_BSSGP_CAUSE(cause)
		}
	}
	template (value) PDU_BSSGP ts_BVC_BLOCK(template (value) BssgpBvci bvci,
						template (value) BssgpCause cause) := {
		pDU_BSSGP_BVC_BLOCK := {
			bssgpPduType := '20'O,
			bVCI := ts_BSSGP_BVCI(bvci),
			cause := ts_BSSGP_CAUSE(cause)
		}
	}

	/* 10.4.9 */
	template (present) PDU_BSSGP tr_BVC_BLOCK_ACK(template (present) BssgpBvci bvci) := {
		pDU_BSSGP_BVC_BLOCK_ACK := {
			bssgpPduType := '21'O,
			bVCI := tr_BSSGP_BVCI(bvci)
		}
	}
	template (value) PDU_BSSGP ts_BVC_BLOCK_ACK(template (value) BssgpBvci bvci) := {
		pDU_BSSGP_BVC_BLOCK_ACK := {
			bssgpPduType := '21'O,
			bVCI := ts_BSSGP_BVCI(bvci)
		}
	}

	/* 10.4.4 */
	template (value) PDU_BSSGP ts_BVC_FC_BVC(uint16_t bmax, uint16_t bucket_leak_rate,
					uint16_t bmax_default_ms, uint16_t r_default_ms, OCT1 tag) := {
		pDU_BSSGP_FLOW_CONTROL_BVC := {
			bssgpPduType := '26'O,
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			},
			bVC_Bucket_Size := {
				iEI := '05'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				bmax := int2oct(bmax, 2)
			},
			bucket_Leak_Rate := {
				iEI := '03'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				r_Value := int2oct(bucket_leak_rate, 2)
			},
			bmax_default_MS := {
				iEI := '01'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				bmax := int2oct(bmax_default_ms, 2)
			},
			r_default_MS := {
				iEI := '1C'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				r_default_MS_value := int2oct(r_default_ms, 2)
			},
			bucket_Full_Ratio := omit,
			bVC_Measurement := omit,
			flow_Control_Granularity := omit
		}
	}
	template PDU_BSSGP tr_BVC_FC_BVC(template uint16_t bmax := ?,
					 template uint16_t bucket_leak_rate := ?,
					 template uint16_t bmax_default_ms := ?,
					 template uint16_t r_default_ms := ?,
					 template OCT1 tag := ?) := {
		pDU_BSSGP_FLOW_CONTROL_BVC := {
			bssgpPduType := '26'O,
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			},
			bVC_Bucket_Size := {
				iEI := '05'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				bmax := f_oct_or_wc(bmax, 2)
			},
			bucket_Leak_Rate := {
				iEI := '03'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				r_Value := f_oct_or_wc(bucket_leak_rate, 2)
			},
			bmax_default_MS := {
				iEI := '01'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				bmax := f_oct_or_wc(bmax_default_ms, 2)
			},
			r_default_MS := {
				iEI := '1C'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				r_default_MS_value := f_oct_or_wc(r_default_ms, 2)
			},
			bucket_Full_Ratio := *,
			bVC_Measurement := *,
			flow_Control_Granularity := *
		}
	}

	/* 10.4.5 */
	template (present) PDU_BSSGP tr_BVC_FC_BVC_ACK(template (present) OCT1 tag) := {
		pDU_BSSGP_FLOW_CONTROL_BVC_ACK := {
			bssgpPduType := '27'O,
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			}
		}
	}
	template (value) PDU_BSSGP ts_BVC_FC_BVC_ACK(template (value) OCT1 tag) := {
		pDU_BSSGP_FLOW_CONTROL_BVC_ACK := {
			bssgpPduType := '27'O,
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			}
		}
	}

	/* 10.4.6 */
	template (value) PDU_BSSGP ts_BVC_FC_MS(GprsTlli tlli, uint16_t bmax, uint16_t bucket_leak_rate,
						OCT1 tag) := {
		pDU_BSSGP_FLOW_CONTROL_MS := {
			bssgpPduType := '28'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			},
			mS_Bucket_Size := {
				iEI := '12'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				bmax := int2oct(bmax, 2)
			},
			bucket_Leak_Rate := {
				iEI := '03'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				r_Value := int2oct(bucket_leak_rate, 2)
			},
			bucket_Full_Ratio := omit,
			flow_Control_Granularity := omit
		}
	}
	template (present) PDU_BSSGP tr_BVC_FC_MS(template (present) GprsTlli tlli := ?,
						  template (present) uint16_t bmax := ?,
						  template (present) uint16_t bucket_leak_rate := ?,
						  template (present) OCT1 tag := ?) := {
		pDU_BSSGP_FLOW_CONTROL_MS := {
			bssgpPduType := '28'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			},
			mS_Bucket_Size := {
				iEI := '12'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				bmax := f_oct_or_wc(bmax, 2)
			},
			bucket_Leak_Rate := {
				iEI := '03'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				r_Value := f_oct_or_wc(bucket_leak_rate, 2)
			},
			bucket_Full_Ratio := *,
			flow_Control_Granularity := *
		}
	}

	/* 10.4.7 */
	template (value) PDU_BSSGP ts_BVC_FC_MS_ACK(template (value) GprsTlli tlli,
						    template (value) OCT1 tag) := {

		pDU_BSSGP_FLOW_CONTROL_MS_ACK := {
			bssgpPduType := '29'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			}
		}
	}
	template (present) PDU_BSSGP tr_BVC_FC_MS_ACK(template (present) GprsTlli tlli,
						      template (present) OCT1 tag := ?) := {

		pDU_BSSGP_FLOW_CONTROL_MS_ACK := {
			bssgpPduType := '29'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			tag := {
				iEI := '1E'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				unstructured_Value := tag
			}
		}
	}

	/* 10.4.14 */
	template (value) PDU_BSSGP ts_BSSGP_STATUS(template (omit) BssgpBvci bvci,
						   template (value) BssgpCause cause,
						   PDU_BSSGP pdu) := {
		pDU_BSSGP_STATUS := {
			bssgpPduType := '41'O,
			cause := ts_BSSGP_CAUSE(cause),
			bVCI := f_ts_BSSGP_BVCI(bvci),
			pDU_in_Error := {
				iEI := '15'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 0 /* overwritten */
				},
				erroneous_BSSGP_PDU := enc_PDU_BSSGP(pdu)
			}
		}
	}
	template PDU_BSSGP tr_BSSGP_STATUS(template BssgpBvci bvci := ?, template BssgpCause cause := ?,
					   template octetstring pdu := ?) := {
		pDU_BSSGP_STATUS := {
			bssgpPduType := '41'O,
			cause := tr_BSSGP_CAUSE(cause),
			bVCI := tr_BSSGP_BVCI(bvci),
			pDU_in_Error := {
				iEI := '15'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := ?
				},
				erroneous_BSSGP_PDU := pdu
			}
		}
	}

	private function f_presence_bit_MultislotCap_GPRS_BSSGP(template (omit) MultislotCap_GPRS_BSSGP mscap_gprs) return BIT1 {
		if (istemplatekind(mscap_gprs, "omit")) {
			return '0'B;
		}
		return '1'B;
	}
	private function f_presence_bit_MultislotCap_EGPRS_BSSGP(template (omit) MultislotCap_EGPRS_BSSGP mscap_egprs) return BIT1 {
		if (istemplatekind(mscap_egprs, "omit")) {
			return '0'B;
		}
		return '1'B;
	}
	template (value) MSRACapabilityValuesRecord_BSSGP ts_RaCapRec_BSSGP(BIT4 att := '0001'B /* E-GSM */, template (omit) MultislotCap_GPRS_BSSGP mscap_gprs := omit, template (omit) MultislotCap_EGPRS_BSSGP mscap_egprs := omit) := {
		mSRACapabilityValues := {
			mSRACapabilityValuesExclude1111 := {
				accessTechnType := att, /* E-GSM */
				accessCapabilities := {
					lengthIndicator := 0, /* overwritten */
					accessCapabilities := {
						rfPowerCapability := '001'B, /* FIXME */
						presenceBitA5 := '0'B,
						a5bits := omit,
						esind := '1'B,
						psbit := '0'B,
						vgcs := '0'B,
						vbs := '0'B,
						presenceBitMultislot := '1'B,
						multislotcap := {
							presenceBitHscsd := '0'B,
							hscsdmultislotclass := omit,
							presenceBitGprs := f_presence_bit_MultislotCap_GPRS_BSSGP(mscap_gprs),
							gprsmultislot := mscap_gprs,
							presenceBitSms := '0'B,
							multislotCap_SMS := omit,
							multislotCapAdditionsAfterRel97 := {
								presenceBitEcsdmulti := '0'B,
								ecsdmultislotclass := omit,
								presenceBitEgprsmulti := f_presence_bit_MultislotCap_EGPRS_BSSGP(mscap_egprs),
								multislotCap_EGPRS := mscap_egprs,
								presenceBitDtmGprsmulti := '0'B,
								multislotCapdtmgprsmultislotsubclass := omit
							}
						},
						accessCapAdditionsAfterRel97 := omit
					},
					spare_bits := omit
				}
			}
		},
		presenceBitMSRACap := '0'B
	};
	template (present) MSRACapabilityValuesRecord_BSSGP
	tr_RaCapRec_BSSGP(template (present) BIT4 att := '0001'B /* E-GSM */, template MultislotCap_GPRS_BSSGP mscap_gprs := *,
			  template MultislotCap_EGPRS_BSSGP mscap_egprs := *) := {
		mSRACapabilityValues := {
			mSRACapabilityValuesExclude1111 := {
				accessTechnType := att, /* E-GSM */
				accessCapabilities := {
					lengthIndicator := ?, /* overwritten */
					accessCapabilities := {
						rfPowerCapability := '001'B, /* FIXME */
						presenceBitA5 := ?,
						a5bits := *,
						esind := '1'B,
						psbit := '0'B,
						vgcs := '0'B,
						vbs := '0'B,
						presenceBitMultislot := '1'B,
						multislotcap := {
							presenceBitHscsd := '0'B,
							hscsdmultislotclass := omit,
							presenceBitGprs := ?,
							gprsmultislot := mscap_gprs,
							presenceBitSms := '0'B,
							multislotCap_SMS := omit,
							multislotCapAdditionsAfterRel97 := {
								presenceBitEcsdmulti := '0'B,
								ecsdmultislotclass := *,
								presenceBitEgprsmulti := ?,
								multislotCap_EGPRS := mscap_egprs,
								presenceBitDtmGprsmulti := ?,
								multislotCapdtmgprsmultislotsubclass := *
							}
						},
						accessCapAdditionsAfterRel97 := *
					},
					spare_bits := *
				}
			}
		},
		presenceBitMSRACap := '0'B
	};


	template QoS_Profile_V t_defaultQos := {
		peak_Bit_Rate := int2oct(80, 2),
		precedence := '000'B,
		a_bit := '0'B,
		t_bit := '0'B,
		c_r_bit := '0'B,
		peakBitRateGranularity := '00'B
	}

	template (value) QoS_Profile ts_QoS_TLV(template (value) QoS_Profile_V qos) := {
		iEI := '18'O,
		ext := '1'B,
		lengthIndicator := { length1 := 3 },
		peak_Bit_Rate := qos.peak_Bit_Rate,
		precedence := qos.precedence,
		a_bit := qos.a_bit,
		t_bit := qos.t_bit,
		c_r_bit := qos.c_r_bit,
		peakBitRateGranularity := qos.peakBitRateGranularity
	}

	template (value) PDU_Lifetime t_DefaultLifetime(uint16_t delay := 65535) := {
		iEI := '16'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		delay_Value := int2oct(delay, 2)
	}

	template DRX_Parameters t_defaultDRXparam := {
		iEI := '0A'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		splitPG_CycleCode := '00'O,
		nonDRXTimer := '000'B,
		splitOnCCCH := '0'B,
		cnSpecificDRXCycleLength := '0000'B
	}

	function ts_BSSGP_IE_MSRAcap_omit(template (omit) MSRadioAccessCapabilityV_BSSGP racap) return template (omit) MS_Radio_Access_Capability {
		var template (omit) MS_Radio_Access_Capability ret;
		if (istemplatekind(racap, "omit")) {
			return omit;
		} else {
			ret := {
				iEI := '13'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				mSRadioAccessCapabilityV_BSSGP := racap
			}
			return ret;
		}
	}

	function tr_BSSGP_IE_MSRAcap(template MSRadioAccessCapabilityV_BSSGP racap) return template MS_Radio_Access_Capability {
		var template MS_Radio_Access_Capability ret;
		if (istemplatekind(racap, "omit")) {
			return omit;
		} else {
			ret := {
				iEI := '13'O,
				ext := ?,
				lengthIndicator := ?,
				mSRadioAccessCapabilityV_BSSGP := racap
			}
			return ret;
		}
	}

	/* 10.2.1 */
	template (value) PDU_BSSGP ts_BSSGP_DL_UD(GprsTlli tlli, octetstring pdu,
					  template (omit) MSRadioAccessCapabilityV_BSSGP racap := omit,
					  template (omit) IMSI_BSSGP imsi := omit) := {
		pDU_BSSGP_DL_UNITDATA := {
			bssgpPduType := '00'O,
			tLLI_current := tlli,
			qoS_Profile := t_defaultQos,
			pDU_Lifetime := t_DefaultLifetime(65535),
			mS_Radio_Access_Capability := ts_BSSGP_IE_MSRAcap_omit(racap),
			priority := omit,
			dRX_Parameters := omit,
			iMSI := imsi,
			tLLI_old := omit,
			pFI := omit,
			lSA_Information := omit,
			service_UTRAN_CCO := omit,
			service_Class_Indicator := omit,
			subscriber_Profile_ID_For_RAT_Priority := omit,
			redirection_Indication := omit,
			redirection_Completed := omit,
			unconfirmed_Send_State_Variable := omit,
			sCI := omit,
			gGSN_PGW_Location := omit,
			eDRX_Paremeters := omit,
			old_Routing_Area_Identification := omit,
			attach_Indicator := omit,
			alignment_octets := omit,
			lLC_PDU := ts_BSSGP_LLC_PDU(pdu),
			initialLLC_PDU := omit
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_DL_UD(template (present) GprsTlli tlli, template (present) octetstring pdu,
					  template IMSI_BSSGP imsi := omit) := {
		pDU_BSSGP_DL_UNITDATA := {
			bssgpPduType := '00'O,
			tLLI_current := tlli,
			qoS_Profile := ?,
			pDU_Lifetime := ?,
			mS_Radio_Access_Capability := *,
			priority := *,
			dRX_Parameters := *,
			iMSI := imsi,
			tLLI_old := *,
			pFI := *,
			lSA_Information := *,
			service_UTRAN_CCO := *,
			service_Class_Indicator := *,
			subscriber_Profile_ID_For_RAT_Priority := *,
			redirection_Indication := *,
			redirection_Completed := *,
			unconfirmed_Send_State_Variable := *,
			sCI := *,
			gGSN_PGW_Location := *,
			eDRX_Paremeters := *,
			old_Routing_Area_Identification := *,
			attach_Indicator := *,
			alignment_octets := *,
			lLC_PDU := tr_BSSGP_LLC_PDU(pdu),
			initialLLC_PDU := *
		}
	}

	/* 10.2.2 */
	template (value) PDU_BSSGP ts_BSSGP_UL_UD(GprsTlli tlli, BssgpCellId cell_id, octetstring payload) := {
		pDU_BSSGP_UL_UNITDATA := {
			bssgpPduType := '01'O,
			tLLI := tlli,
			qoS_Profile := t_defaultQos,
			cell_Identifier := ts_BSSGP_IE_CellId(cell_id),
			pFI := omit,
			lSA_Identifier_List := omit,
			redirect_Attempt_Flag := omit,
			iMSI_BSSGP := omit,
			unconfirmed_Send_State_Variable := omit,
			selected_PLMN_ID := omit,
			selected_Operator := omit,
			cS_Registered_Operator := omit,
			alignment_octets := omit,
			lLC_PDU := ts_BSSGP_LLC_PDU(payload)
		}
	}
	template PDU_BSSGP tr_BSSGP_UL_UD(template GprsTlli tlli := ?, template BssgpCellId cell_id := ?,
					  template octetstring payload := ?) := {
		pDU_BSSGP_UL_UNITDATA := {
			bssgpPduType := '01'O,
			tLLI := tlli,
			qoS_Profile := ?,
			cell_Identifier := tr_BSSGP_IE_CellId(cell_id),
			pFI := *,
			lSA_Identifier_List := *,
			redirect_Attempt_Flag := *,
			iMSI_BSSGP := *,
			unconfirmed_Send_State_Variable := *,
			selected_PLMN_ID := *,
			selected_Operator := *,
			cS_Registered_Operator := *,
			alignment_octets := *,
			lLC_PDU := tr_BSSGP_LLC_PDU(payload)
		}
	}

	/* 10.3.2 */
	template PDU_BSSGP tr_BSSGP_CS_PAGING(BssgpBvci bvci) := {
		pDU_BSSGP_PAGING_CS := {
			bssgpPduType := '07'O,
			iMSI := ?,
			dRX_Parameters := ?,
			paging_Field4 := {
				bVCI := ts_BSSGP_BVCI(bvci)
			},
			tLLI := *,
			channel_needed := *,
			eMLPP_Priority := *,
			tMSI := *,
			global_CN_Id := *
		}
	}
	template (value) PDU_BSSGP ts_BSSGP_CS_PAGING_IMSI(BssgpBvci bvci, hexstring imsi) := {
		pDU_BSSGP_PAGING_CS := {
			bssgpPduType := '07'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			dRX_Parameters := t_defaultDRXparam,
			paging_Field4 := {
				bVCI := ts_BSSGP_BVCI(bvci)
			},
			tLLI := omit,
			channel_needed := omit,
			eMLPP_Priority := omit,
			tMSI := omit,
			global_CN_Id := omit
		}
	}
	template (value) PDU_BSSGP ts_BSSGP_CS_PAGING_PTMSI(BssgpBvci bvci, hexstring imsi, GsmTmsi tmsi) := {
		pDU_BSSGP_PAGING_CS := {
			bssgpPduType := '07'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			dRX_Parameters := t_defaultDRXparam,
			paging_Field4 := {
				bVCI := ts_BSSGP_BVCI(bvci)
			},
			tLLI := omit,
			channel_needed := omit,
			eMLPP_Priority := omit,
			tMSI := ts_BSSGP_TMSI(tmsi),
			global_CN_Id := omit
		}
	}

	/* 10.3.1 */
	template PDU_BSSGP tr_BSSGP_PS_PAGING(template BssgpBvci bvci) := {
		pDU_BSSGP_PAGING_PS := {
			bssgpPduType := '06'O,
			iMSI := ?,
			dRX_Parameters := *,
			paging_Field4 := {
				bVCI := tr_BSSGP_BVCI(bvci)
			},
			pFI := *,
			aBQP := *,
			qoS_Profile := ?,
			pTMSI := *,
			eDRX_Paremeters := *
		}
	}
	template (value) PDU_BSSGP ts_BSSGP_PS_PAGING_IMSI(BssgpBvci bvci, hexstring imsi) := {
		pDU_BSSGP_PAGING_PS := {
			bssgpPduType := '06'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			dRX_Parameters := omit,
			paging_Field4 := {
				bVCI := ts_BSSGP_BVCI(bvci)
			},
			pFI := omit,
			aBQP := omit,
			qoS_Profile := ts_QoS_TLV(t_defaultQos),
			pTMSI := omit,
			eDRX_Paremeters := omit
		}
	}
	template (value) PDU_BSSGP ts_BSSGP_PS_PAGING_PTMSI(BssgpBvci bvci, hexstring imsi, GsmTmsi tmsi) := {
		pDU_BSSGP_PAGING_PS := {
			bssgpPduType := '06'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			dRX_Parameters := omit,
			paging_Field4 := {
				bVCI := ts_BSSGP_BVCI(bvci)
			},
			pFI := omit,
			aBQP := omit,
			qoS_Profile := ts_QoS_TLV(t_defaultQos),
			pTMSI := ts_BSSGP_TMSI(tmsi),
			eDRX_Paremeters := omit
		}
	}

	template (value) Paging_Field4 ts_BssgpP4BssArea := {
		bSS_Area_Indication := {
			iEI := '02'O,
			ext := '1'B,
			lengthIndicator := {
				length1 := 1
			},
			bSS_indicator := '00'O
		}
	}

	template (value) Paging_Field4 ts_BssgpP4LAC(GSM_Types.LocationAreaIdentification lai) := {
		location_Area := ts_BSSGP_LA_ID(lai)
	}

	template (value) Paging_Field4 ts_BssgpP4RAC(GSM_Types.RoutingAreaIdentification rai) := {
		routeing_Area := ts_BSSGP_RA_ID(rai)
	}

	template (value) Paging_Field4 ts_BssgpP4Bvci(BssgpBvci bvci) := {
		bVCI := ts_BSSGP_BVCI(bvci)
	}

	template (value) Location_Area ts_BSSGP_LA_ID(GSM_Types.LocationAreaIdentification input) := {
		iEI := '10'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 5
		},
		mccDigit1 := input.mcc_mnc[0],
		mccDigit2 := input.mcc_mnc[1],
		mccDigit3 := input.mcc_mnc[2],
		mncDigit3 := input.mcc_mnc[3],
		mncDigit1 := input.mcc_mnc[4],
		mncDigit2 := input.mcc_mnc[5],
		lac := int2oct(input.lac, 2)
	}

	template (value) Routeing_Area ts_BSSGP_RA_ID(GSM_Types.RoutingAreaIdentification input) := {
		iEI := '1B'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 6
		},
		mccDigit1 := input.lai.mcc_mnc[0],
		mccDigit2 := input.lai.mcc_mnc[1],
		mccDigit3 := input.lai.mcc_mnc[2],
		mncDigit3 := input.lai.mcc_mnc[3],
		mncDigit1 := input.lai.mcc_mnc[4],
		mncDigit2 := input.lai.mcc_mnc[5],
		lac := int2oct(input.lai.lac, 2),
		rac := int2oct(input.rac, 1)
	}

	private function f_ts_BSSGP_RA_ID(template (omit) GSM_Types.RoutingAreaIdentification input)
	return template (omit) Routeing_Area {
		if (istemplatekind(input, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_RA_ID(valueof(input));
		}
	}

	private function f_tr_BSSGP_RA_ID(template GSM_Types.RoutingAreaIdentification input)
	return template Routeing_Area {
		if (istemplatekind(input, "omit")) {
			return omit;
		} else if (istemplatekind(input, "*")) {
			return *;
		} else if (istemplatekind(input, "?")) {
			return ?;
		} else {
			return ts_BSSGP_RA_ID(valueof(input));
		}
	}

	/* 10.3.6 */
	template (value) PDU_BSSGP ts_BSSGP_SUSPEND(GprsTlli tlli, RoutingAreaIdentification ra_id) := {
		pDU_BSSGP_SUSPEND := {
			bssgpPduType := '0B'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id)
		}
	}
	template PDU_BSSGP tr_BSSGP_SUSPEND(template (present) GprsTlli tlli, RoutingAreaIdentification ra_id) := {
		pDU_BSSGP_SUSPEND := {
			bssgpPduType := '0B'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id)
		}
	}

	/* 10.3.7 */
	template (value) PDU_BSSGP ts_BSSGP_SUSPEND_ACK(GprsTlli tlli, RoutingAreaIdentification ra_id,
							template (value) OCT1 susp_ref) := {
		pDU_BSSGP_SUSPEND_ACK := {
			bssgpPduType := '0C'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			suspend_Reference_Number := ts_BSSGP_SUSP_REF(susp_ref)
		}
	}
	template PDU_BSSGP tr_BSSGP_SUSPEND_ACK(GprsTlli tlli, RoutingAreaIdentification ra_id,
						template OCT1 susp_ref) := {
		pDU_BSSGP_SUSPEND_ACK := {
			bssgpPduType := '0C'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			suspend_Reference_Number := tr_BSSGP_SUSP_REF(susp_ref)
		}
	}

	/* 10.3.8 */
	template (value) PDU_BSSGP ts_BSSGP_SUSPEND_NACK(GprsTlli tlli, RoutingAreaIdentification ra_id,
							 template (omit) BssgpCause cause) := {
		pDU_BSSGP_SUSPEND_NACK := {
			bssgpPduType := '0D'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			cause := ts_BSSGP_CAUSE(cause)
		}
	}
	template PDU_BSSGP tr_BSSGP_SUSPEND_NACK(GprsTlli tlli, RoutingAreaIdentification ra_id,
						template BssgpCause cause) := {
		pDU_BSSGP_SUSPEND_NACK := {
			bssgpPduType := '0D'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			cause := tr_BSSGP_CAUSE(cause)
		}
	}


	/* 10.3.9 */
	template (value) PDU_BSSGP ts_BSSGP_RESUME(GprsTlli tlli, RoutingAreaIdentification ra_id,
						   OCT1 susp_ref) := {
		pDU_BSSGP_RESUME := {
			bssgpPduType := '0E'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			suspend_Reference_Number := ts_BSSGP_SUSP_REF(susp_ref)
		}
	}
	template PDU_BSSGP tr_BSSGP_RESUME(template (present) GprsTlli tlli, RoutingAreaIdentification ra_id,
					   template OCT1 susp_ref) := {
		pDU_BSSGP_RESUME := {
			bssgpPduType := '0E'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			suspend_Reference_Number := tr_BSSGP_SUSP_REF(susp_ref)
		}
	}

	/* 10.3.10 */
	template (value) PDU_BSSGP ts_BSSGP_RESUME_ACK(GprsTlli tlli, RoutingAreaIdentification ra_id)
		:= {
		pDU_BSSGP_RESUME_ACK := {
			bssgpPduType := '0F'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id)
		}
	}
	template PDU_BSSGP tr_BSSGP_RESUME_ACK(template (present) GprsTlli tlli,
						RoutingAreaIdentification ra_id) := {
		pDU_BSSGP_RESUME_ACK := {
			bssgpPduType := '0F'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id)
		}
	}

	/* 10.3.11 */
	template (value) PDU_BSSGP ts_BSSGP_RESUME_NACK(GprsTlli tlli, RoutingAreaIdentification ra_id,
						template (omit) BssgpCause cause) := {
		pDU_BSSGP_RESUME_NACK := {
			bssgpPduType := '10'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			cause := ts_BSSGP_CAUSE(cause)
		}
	}
	template PDU_BSSGP tr_BSSGP_RESUME_NACK(template (present) GprsTlli tlli,
						RoutingAreaIdentification ra_id,
						template BssgpCause cause) := {
		pDU_BSSGP_RESUME_NACK := {
			bssgpPduType := '10'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			routeing_Area := ts_BSSGP_RA_ID(ra_id),
			cause := tr_BSSGP_CAUSE(cause)
		}
	}

	/* 10.3.12 */
	template (value) PDU_BSSGP ts_BSSGP_DUMMY_PAGING_PS(hexstring imsi,
							    template (omit) RoutingAreaIdentification ra) := {
		pDU_BSSGP_DUMMY_PAGING_PS := {
			bssgpPduType := '12'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			routeing_Area := f_ts_BSSGP_RA_ID(ra),
			eDRX_Paremeters := omit
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_DUMMY_PAGING_PS(hexstring imsi,
							      template RoutingAreaIdentification ra) := {
		pDU_BSSGP_DUMMY_PAGING_PS := {
			bssgpPduType := '12'O,
			iMSI := tr_BSSGP_IMSI(imsi),
			routeing_Area := f_tr_BSSGP_RA_ID(ra),
			eDRX_Paremeters := omit
		}
	}

	template (value) Time_Until_Next_Paging_Occasion ts_TimeNextPag(uint8_t mins, uint8_t secs) := {
		iEI := '93'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		minutes := mins,
		spare := '00'B,
		seconds := secs,
		spare2 := '00'B
	}
	template (present) Time_Until_Next_Paging_Occasion tr_TimeNextPag(template (present) uint8_t mins,
									  template (present) uint8_t secs) := {
		iEI := '93'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		minutes := mins,
		spare := ?,
		seconds := secs,
		spare2 := ?
	}

	/* 10.3.13 */
	template (value) PDU_BSSGP ts_BSSGP_DUMMY_PAGING_PS_RESP(hexstring imsi, uint8_t mins, uint8_t secs) := {
		pDU_BSSGP_DUMMY_PAGING_PS_RESPONSE := {
			bssgpPduType := '13'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			time_Until_Next_Paging_Occasion := ts_TimeNextPag(mins, secs)
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_DUMMY_PAGING_PS_RESP(hexstring imsi,
								   template (present) uint8_t mins,
								   template (present) uint8_t secs) := {
		pDU_BSSGP_DUMMY_PAGING_PS_RESPONSE := {
			bssgpPduType := '13'O,
			iMSI := tr_BSSGP_IMSI(imsi),
			time_Until_Next_Paging_Occasion := tr_TimeNextPag(mins, secs)
		}
	}

	/* 10.3.14 */
	template (value) PDU_BSSGP ts_BSSGP_PAGING_PS_REJ(hexstring imsi, uint8_t mins, uint8_t secs,
							  template (omit) GsmTmsi tmsi) := {
		pDU_BSSGP_PAGING_PS_REJECT := {
			bssgpPduType := '11'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			pTMSI := f_ts_BSSGP_TMSI(tmsi),
			time_Until_Next_Paging_Occasion := ts_TimeNextPag(mins, secs)
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_PAGING_PS_REJ(hexstring imsi,
							    template (present) uint8_t mins,
							    template (present) uint8_t secs,
							    template GsmTmsi tmsi) := {
		pDU_BSSGP_PAGING_PS_REJECT := {
			bssgpPduType := '11'O,
			iMSI := tr_BSSGP_IMSI(imsi),
			pTMSI := f_tr_BSSGP_TMSI(tmsi),
			time_Until_Next_Paging_Occasion := tr_TimeNextPag(mins, secs)
		}
	}

	/* 10.3.15 */
	template (value) PDU_BSSGP ts_BSSGP_MS_REG_ENQ(hexstring imsi) := {
		pDU_BSSGP_MS_REGISTRATION_ENQUIRY := {
			bssgpPduType := '14'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			mME_Query := omit
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_MS_REG_ENQ(hexstring imsi) := {
		pDU_BSSGP_MS_REGISTRATION_ENQUIRY := {
			bssgpPduType := '14'O,
			iMSI := tr_BSSGP_IMSI(imsi),
			mME_Query := *
		}
	}

	/* 11.3.126 */
	template (value) PLMN_Identity ts_BSSGP_PlmnId(template (value) BcdMccMnc mccmnc) := {
		iEI := '96'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 3
		},
		mccDigit1 := mccmnc[0],
		mccDigit2 := mccmnc[1],
		mccDigit3 := mccmnc[2],
		mncDigit3 := mccmnc[5],
		mncDigit1 := mccmnc[3],
		mncDigit2 := mccmnc[4]
	}
	template (present) PLMN_Identity tr_BSSGP_PlmnId(template (present) BcdMccMnc mccmnc) := {
		iEI := '96'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 3
		},
		mccDigit1 := mccmnc[0],
		mccDigit2 := mccmnc[1],
		mccDigit3 := mccmnc[2],
		mncDigit3 := mccmnc[5],
		mncDigit1 := mccmnc[3],
		mncDigit2 := mccmnc[4]
	}
	private function f_ts_BSSGP_PlmnId(template (omit) BcdMccMnc mccmnc)
	return template (omit) PLMN_Identity {
		if (istemplatekind(mccmnc, "omit")) {
			return omit;
		} else {
			return ts_BSSGP_PlmnId(valueof(mccmnc));
		}
	}
	private function f_tr_BSSGP_PlmnId(template BcdMccMnc mccmnc)
	return template PLMN_Identity {
		if (istemplatekind(mccmnc, "omit")) {
			return omit;
		} else if (istemplatekind(mccmnc, "*")) {
			return *;
		} else if (istemplatekind(mccmnc, "?")) {
			return ?;
		} else {
			return ts_BSSGP_PlmnId(valueof(mccmnc));
		}
	}

	/* 10.3.16 */
	template (value) PDU_BSSGP ts_BSSGP_MS_REW_ENQ_RESP(hexstring imsi, template (omit) BcdMccMnc mccmnc) := {
		pDU_BSSGP_MS_REGISTRATION_ENQUIRY_RESPONSE := {
			bssgpPduType := '15'O,
			iMSI := ts_BSSGP_IMSI(imsi),
			pS_Registered_Operator := f_ts_BSSGP_PlmnId(mccmnc)
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_MS_REW_ENQ_RESP(hexstring imsi, template BcdMccMnc mccmnc) := {
		pDU_BSSGP_MS_REGISTRATION_ENQUIRY_RESPONSE := {
			bssgpPduType := '15'O,
			iMSI := tr_BSSGP_IMSI(imsi),
			pS_Registered_Operator := f_tr_BSSGP_PlmnId(mccmnc)
		}
	}

	/* 10.4.1 */
	template (value) PDU_BSSGP ts_BSSGP_FLUSH_LL(GprsTlli tlli, template (value) BssgpBvci bvci_old,
						     template (omit) BssgpBvci bvci_new := omit,
						     template (omit) Nsei nsei := omit) := {
		pDU_BSSGP_FLUSH_LL := {
			bssgpPduType := '2A'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			bVCI_old := ts_BSSGP_BVCI(bvci_old),
			bVCI_new := f_ts_BSSGP_BVCI(bvci_new),
			nSEI := f_ts_BSSGP_NSEI(nsei)
		}
	}
	template PDU_BSSGP tr_BSSGP_FLUSH_LL(template (present) GprsTlli tlli, template BssgpBvci bvci_old,
					     template (omit) BssgpBvci bvci_new := omit,
					     template (omit) Nsei nsei := omit) := {
		pDU_BSSGP_FLUSH_LL := {
			bssgpPduType := '2A'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			bVCI_old := tr_BSSGP_BVCI(bvci_old),
			bVCI_new := f_ts_BSSGP_BVCI(bvci_new),
			nSEI := f_ts_BSSGP_NSEI(nsei)
		}
	}

	/* 10.4.2 */
	template (value) PDU_BSSGP ts_BSSGP_FLUSH_LL_ACK(GprsTlli tlli, template (value) OCT1 act,
							 template (value) integer oct_affected,
							 template (omit) BssgpBvci bvci_new := omit,
							 template (omit) Nsei nsei := omit) := {
		pDU_BSSGP_FLUSH_LL_ACK := {
			bssgpPduType := '2B'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			flush_Action := ts_FLUSH_ACTION(act),
			bVCI_new := f_ts_BSSGP_BVCI(bvci_new),
			number_of_octets_affected := ts_NO_OCT_AFF(oct_affected),
			nSEI := f_ts_BSSGP_NSEI(nsei)
		}
	}
	template PDU_BSSGP tr_BSSGP_FLUSH_LL_ACK(template (present) GprsTlli tlli, template OCT1 act,
						 template integer oct_affected,
						 template (omit) BssgpBvci bvci_new := omit,
						 template (omit) Nsei nsei := omit) := {
		pDU_BSSGP_FLUSH_LL_ACK := {
			bssgpPduType := '2B'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			flush_Action := tr_FLUSH_ACTION(act),
			bVCI_new := f_ts_BSSGP_BVCI(bvci_new),
			number_of_octets_affected := tr_NO_OCT_AFF(oct_affected),
			nSEI := f_ts_BSSGP_NSEI(nsei)
		}
	}

	/* 10.4.3 */
	template (value) PDU_BSSGP ts_BSSGP_LLC_DISCARDED(GprsTlli tlli, template (value) integer frames_discarded,
							 template (value) BssgpBvci bvci,
							 template (value) integer oct_deleted) := {
		pDU_BSSGP_LLC_DISCARDED := {
			bssgpPduType := '2C'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			lLC_Frames_Discarded := ts_LLC_FRAMES_DISCARDED(frames_discarded),
			bVCI := ts_BSSGP_BVCI(bvci),
			number_of_octets_deleted := ts_NO_OCT_AFF(oct_deleted),
			pFI := omit
		}
	}
	template PDU_BSSGP tr_BSSGP_LLC_DISCARDED(template (present) GprsTlli tlli, template integer frames_discarded,
						 template BssgpBvci bvci,
						 template integer oct_deleted) := {
		pDU_BSSGP_LLC_DISCARDED := {
			bssgpPduType := '2C'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			lLC_Frames_Discarded := tr_LLC_FRAMES_DISCARDED(frames_discarded),
			bVCI := tr_BSSGP_BVCI(bvci),
			number_of_octets_deleted := tr_NO_OCT_AFF(oct_deleted),
			pFI := *
		}
	}

	/* 10.2.3 */
	template (value) PDU_BSSGP ts_BSSGP_RA_CAP(GprsTlli tlli,
						   template (omit) MSRadioAccessCapabilityV_BSSGP racap := omit) := {
		pDU_BSSGP_RA_CAPABILITY := {
			bssgpPduType := '02'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			mS_Radio_Access_Capability := ts_BSSGP_IE_MSRAcap_omit(racap)
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_RA_CAP(template (present) GprsTlli tlli,
						     template MSRadioAccessCapabilityV_BSSGP racap) := {
		pDU_BSSGP_RA_CAPABILITY := {
			bssgpPduType := '02'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			mS_Radio_Access_Capability := tr_BSSGP_IE_MSRAcap(racap)
		}
	}


	/* 10.3.3 */
	template (value) PDU_BSSGP ts_BSSGP_RA_CAP_UPD(GprsTlli tlli, OCT1 tag) := {
		pDU_BSSGP_RA_CAPABILITY_UPDATE := {
			bssgpPduType := '08'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			tag := ts_BSSGP_IE_Tag(tag)
		}
	}
	template (present) PDU_BSSGP tr_BSSGP_RA_CAP_UPD(template (present) GprsTlli tlli,
						     template (present) OCT1 tag) := {
		pDU_BSSGP_RA_CAPABILITY_UPDATE := {
			bssgpPduType := '08'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			tag := tr_BSSGP_IE_Tag(tag)
		}
	}


	/* 10.3.4 */
	template (value) PDU_BSSGP
	ts_BSSGP_RA_CAP_UPD_ACK(GprsTlli tlli, OCT1 tag, template (value) OCT1 cause,
			        template (omit) MSRadioAccessCapabilityV_BSSGP racap := omit) := {
		pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK := {
			bssgpPduType := '09'O,
			tLLI := ts_BSSGP_TLLI(tlli),
			tag := ts_BSSGP_IE_Tag(tag),
			iMSI := omit,
			rA_Cap_UPDATE_CAUSE := ts_BSSGP_IE_RACU_Cause(cause),
			mS_Radio_Access_Capability := ts_BSSGP_IE_MSRAcap_omit(racap)
		}
	}
	template (present) PDU_BSSGP
	tr_BSSGP_RA_CAP_UPD_ACK(template (present) GprsTlli tlli, template (present) OCT1 tag, template (present) OCT1 cause,
			        template MSRadioAccessCapabilityV_BSSGP racap := omit) := {
		pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK := {
			bssgpPduType := '09'O,
			tLLI := tr_BSSGP_TLLI(tlli),
			tag := tr_BSSGP_IE_Tag(tag),
			iMSI := omit,
			rA_Cap_UPDATE_CAUSE := tr_BSSGP_IE_RACU_Cause(cause),
			mS_Radio_Access_Capability := tr_BSSGP_IE_MSRAcap(racap)
		}
	}

	type enumerated BssgpRadioCause {
		BSSGP_RADIO_CAUSE_CONTACT_LOST		('00'H),
		BSSGP_RADIO_CAUSE_LINK_QUAL_INSUFF	('01'H),
		BSSGP_RADIO_CAUSE_CELL_RESEL_ORDERED	('02'H),
		BSSGP_RADIO_CAUSE_CELL_RESEL_PREPARE	('03'H),
		BSSGP_RADIO_CAUSE_CELL_RESEL_FAILURE 	('04'H)
	} with { variant "FIELDLENGTH(8)" };

        function ts_BSSGP_RADIO_CAUSE(template (omit) BssgpRadioCause cause) return template (omit) Radio_Cause {
		var template (omit) Radio_Cause ret;
		if (istemplatekind(cause, "omit")) {
			ret := omit;
		} else {
			ret.iEI := '19'O;
			ret.ext := '1'B;
			ret.lengthIndicator := { length1 := 1 };
			ret.radio_Cause_Value := int2oct(enum2int(valueof(cause)), 1);
		}
		return ret;
	}
	function tr_BSSGP_RADIO_CAUSE(template BssgpRadioCause cause) return template (present) Radio_Cause {
		var template (present) Radio_Cause ret;
		ret.iEI := '19'O;
		ret.ext := '1'B;
		ret.lengthIndicator := { length1 := 1 };
		if (isvalue(cause)) {
			ret.radio_Cause_Value := int2oct(enum2int(valueof(cause)), 1);
		} else {
			ret.radio_Cause_Value := ?
		}
		return ret;
	}

	/* 10.3.5 */
	template (value) PDU_BSSGP
	ts_BSSGP_RADIO_STATUS(template (omit) GprsTlli tlli, template (value) BssgpRadioCause cause,
			      template (omit) GsmTmsi tmsi := omit,
			      template (omit) hexstring imsi := omit) := {
		pDU_BSSGP_RADIO_STATUS := {
			bssgpPduType := '0a'O,
			tLLI := f_ts_BSSGP_TLLI(tlli),
			tMSI := f_ts_BSSGP_TMSI(tmsi),
			iMSI := f_ts_BSSGP_IMSI(imsi),
			radio_Cause := ts_BSSGP_RADIO_CAUSE(cause)
		}
	}
	template (present) PDU_BSSGP
	tr_BSSGP_RADIO_STATUS(template GprsTlli tlli, template (present) BssgpRadioCause cause,
			      template GsmTmsi tmsi := *, template hexstring imsi := *) := {
		pDU_BSSGP_RADIO_STATUS := {
			bssgpPduType := '0a'O,
			tLLI := f_tr_BSSGP_TLLI(tlli),
			tMSI := f_tr_BSSGP_TMSI(tmsi),
			iMSI := f_tr_BSSGP_IMSI(imsi),
			radio_Cause := tr_BSSGP_RADIO_CAUSE(cause)
		}
	}

	/* 10.4.15 */
	template (value) PDU_BSSGP
	ts_BSSGP_INVOKE_TRACE(OCT1 eq_trace, OCT2 ref) := {
		pDU_BSSGP_SGSN_INVOKE_TRACE := {
			bssgpPduType := '40'O,
			traceType := {
				iEI := '22'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				equipment_Trace := eq_trace
			},
			traceReference := {
				iEI := '21'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				trace_Reference := ref
			},
			triggerId := omit,
			mobileId := omit,
			omcId := omit,
			transactionId := omit
		}
	}
	template (present) PDU_BSSGP
	tr_BSSGP_INVOKE_TRACE(template (present) OCT1 eq_trace, template (present) OCT2 ref) := {
		pDU_BSSGP_SGSN_INVOKE_TRACE := {
			bssgpPduType := '40'O,
			traceType := {
				iEI := '22'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				equipment_Trace := eq_trace
			},
			traceReference := {
				iEI := '21'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 2
				},
				trace_Reference := ref
			},
			triggerId := *,
			mobileId := *,
			omcId := *,
			transactionId := *
		}
	}

	/* 10.4.36 */
	template (value) PDU_BSSGP
	ts_OVERLOAD(template (value) BIT1 priority_class) := {
		pDU_BSSGP_OVERLOAD := {
			bssgpPduType := '42'O,
			priority_Class_Indicator := {
				iEI := '8f'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				priority_Class_Indicator_Value := priority_class,
				spare := '0000000'B
			}
		}
	}
	template (present) PDU_BSSGP
	tr_OVERLOAD(template (present) BIT1 priority_class) := {
		pDU_BSSGP_OVERLOAD := {
			bssgpPduType := '42'O,
			priority_Class_Indicator := {
				iEI := '8f'O,
				ext := '1'B,
				lengthIndicator := {
					length1 := 1
				},
				priority_Class_Indicator_Value := priority_class,
				spare := '0000000'B
			}
		}
	}

	/* 3GPP TS 48.018 11.3.61 */
	const OCT1 RIM_APP_ID_NACC := '01'O;
	const OCT1 RIM_APP_ID_SI3 := '02'O;
	const OCT1 RIM_APP_ID_MBMS_DATA_CH := '03'O;
	const OCT1 RIM_APP_ID_SON_TRANSF := '04'O;
	const OCT1 RIM_APP_ID_UTRA_SI := '05'O;
	template (value) RIM_Application_Identity ts_RIM_Application_Identity(OCT1 app_id) := {
		 iEI := '4B'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 1
		 },
		 rIMApplicationIdentity := app_id
	}
	template RIM_Application_Identity tr_RIM_Application_Identity(template OCT1 app_id := ?) := {
		 iEI := '4B'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 1
		 },
		 rIMApplicationIdentity := app_id
	}

	/* 3GPP TS 48.018 11.3.62 */
	template (value) RIM_Sequence_Number ts_RIM_Sequence_Number(integer seq) := {
		 iEI := '4C'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 4
		 },
		 rIMSequenceNumber := int2oct(seq, 4)
	}
	function tr_RIM_Sequence_Number(template integer seq := ?) return template RIM_Sequence_Number {
		 var template RIM_Sequence_Number ret;
		 ret.iEI := '4C'O;
		 ret.ext := '1'B;
		 ret.lengthIndicator := { length1 := 4 };
		 if (istemplatekind(seq, "*")) {
			ret.rIMSequenceNumber := *;
		 } else if (istemplatekind(seq, "?")) {
			ret.rIMSequenceNumber := ?;
		 } else {
			ret.rIMSequenceNumber := int2oct(valueof(seq), 4);
		 }
		 return ret;
	}

	/* 3GPP TS 48.018 11.3.62a.1 */
	template (value) RAN_Information_Request_RIM_Container
	ts_RAN_Information_Request_RIM_Container(template (value) RIM_Application_Identity app_id,
						 template (value) RIM_Sequence_Number seq,
						 template (value) RIM_PDU_Indications ind,
						 template (omit) RIM_Protocol_Version_Number ver := omit,
						 template (omit) RAN_Information_Request_Application_Container app_cont := omit,
						 template (omit) SON_Transfer_Application_Identity_TLV son_app_id := omit) := {
		 iEI := '57'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_PDU_Indications := ind,
		 rIM_Protocol_Version_Number := ver,
		 application_Container := app_cont,
		 sON_Transfer_Application_Identity_TLV := son_app_id
	}
	template RAN_Information_Request_RIM_Container
	tr_RAN_Information_Request_RIM_Container(template RIM_Application_Identity app_id := ?,
						 template RIM_Sequence_Number seq := ?,
						 template RIM_PDU_Indications ind := ?,
						 template RIM_Protocol_Version_Number ver := *,
						 template RAN_Information_Request_Application_Container app_cont := *,
						 template SON_Transfer_Application_Identity_TLV son_app_id := *) := {
		 iEI := '57'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := ?
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_PDU_Indications := ind,
		 rIM_Protocol_Version_Number := ver,
		 application_Container := app_cont,
		 sON_Transfer_Application_Identity_TLV := son_app_id
	}


	/* 3GPP TS 48.018 11.3.62a.2 */
	template (value) RAN_Information_RIM_Container
	ts_RAN_Information_RIM_Container(template (value) RIM_Application_Identity app_id,
					 template (value) RIM_Sequence_Number seq,
					 template (value) RIM_PDU_Indications ind,
					 template (omit) RIM_Protocol_Version_Number ver := omit,
					 template (omit) ApplContainer_or_ApplErrContainer app_cont_or_app_err := omit,
					 template (omit) SON_Transfer_Application_Identity_TLV son_app_id := omit) := {

		 iEI := '58'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_PDU_Indications := ind,
		 rIM_Protocol_Version_Number := ver,
		 applContainer_or_ApplErrContainer := app_cont_or_app_err,
		 sON_Transfer_Application_Identity := son_app_id
	}
	template RAN_Information_RIM_Container
	tr_RAN_Information_RIM_Container(template RIM_Application_Identity app_id := ?,
					 template RIM_Sequence_Number seq := ?,
					 template RIM_PDU_Indications ind := ?,
					 template RIM_Protocol_Version_Number ver := omit,
					 template ApplContainer_or_ApplErrContainer app_cont_or_app_err := omit,
					 template SON_Transfer_Application_Identity_TLV son_app_id := omit) := {

		 iEI := '58'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := ?
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_PDU_Indications := ind,
		 rIM_Protocol_Version_Number := ver,
		 applContainer_or_ApplErrContainer := app_cont_or_app_err,
		 sON_Transfer_Application_Identity := son_app_id
	}
	template (value) ApplContainer_or_ApplErrContainer
	tsu_ApplContainer_or_ApplErrContainer_NACC(template (value) ApplContainer_or_ApplErrContainer_NACC cont) := {
		nacc := cont
	}
	template ApplContainer_or_ApplErrContainer
	tru_ApplContainer_or_ApplErrContainer_NACC(template ApplContainer_or_ApplErrContainer_NACC cont := ?) := {
		nacc := cont
	}
	template (value) ApplContainer_or_ApplErrContainer
	tsu_ApplContainer_or_ApplErrContainer_SI3(template (value) ApplContainer_or_ApplErrContainer_SI3 cont) := {
		si3 := cont
	}
	template (value) ApplContainer_or_ApplErrContainer
	tsu_ApplContainer_or_ApplErrContainer_MBMS_data_channel(template (value) ApplContainer_or_ApplErrContainer_MBMS_data_channel cont) := {
		mBMS_data_channel := cont
	}
	template (value) ApplContainer_or_ApplErrContainer_NACC
	tsu_ApplContainer_NACC(template (value) BssgpCellId cid, boolean psi_type, integer si_psi_num, octetstring si_psi) := {
		application_Container := ts_RAN_Information_Application_Container_NACC(cid, psi_type, si_psi_num, si_psi)
	}
	template ApplContainer_or_ApplErrContainer_NACC
	tru_ApplContainer_NACC(template BssgpCellId cid := ?, template boolean psi_type := ?, template integer si_psi_num := ?, template octetstring si_psi := ?) := {
		application_Container := tr_RAN_Information_Application_Container_NACC(cid, psi_type, si_psi_num, si_psi)
	}
	template (value) ApplContainer_or_ApplErrContainer_NACC
	tsu_ApplErrContainer_NACC(template (value) BssgpCellId cid,
				  integer cause,
				  template (value) Application_Container_IE_NACC app_cont) := {
		application_Error_Container := ts_Application_Error_Container_NACC(cid, cause, app_cont)
	}
	template (value) ApplContainer_or_ApplErrContainer_SI3
	tsu_ApplContainer_SI3(template (value) BssgpCellId cid, template (value) SI3 si3) := {
		application_Container := ts_RAN_Information_Application_Container_SI3(cid, si3)
	}
	template (value) ApplContainer_or_ApplErrContainer_SI3
	tsu_ApplErrContainer_SI3(template (value) BssgpCellId cid,
				 integer cause,
				 template (value) Application_Container_IE_SI3 app_cont) := {
		application_Error_Container := ts_Application_Error_Container_SI3(cid, cause, app_cont)
	}
	template (value) ApplContainer_or_ApplErrContainer_MBMS_data_channel
	tsu_ApplContainer_MBMS_data_channel(template (value) BssgpCellId cid, octetstring data_ch_report) := {
		application_Container := ts_RAN_Information_Application_Container_MBMS_data_channel(cid, data_ch_report)
	}
	template (value) ApplContainer_or_ApplErrContainer_MBMS_data_channel
	tsu_ApplErrContainer_MBMS_data_channel(template (value) BssgpCellId cid,
					       integer cause,
					       template (value) Application_Container_IE_MBMS_data_channel app_cont) := {
		application_Error_Container := ts_Application_Error_Container_MBMS_data_channel(cid, cause, app_cont)
	}

	/* 3GPP TS 48.018 11.3.62a.3 */
	template (value) RAN_Information_Ack_RIM_Container
	ts_RAN_Information_Ack_RIM_Container(template (value) RIM_Application_Identity app_id,
					     template (value) RIM_Sequence_Number seq,
					     template (omit) RIM_Protocol_Version_Number ver := omit,
					     template (omit) SON_Transfer_Application_Identity_TLV son_app_id := omit) := {
		 iEI := '5A'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_Protocol_Version_Number := ver,
		 sON_Transfer_Application_Identity := son_app_id
	}
	template RAN_Information_Ack_RIM_Container
	tr_RAN_Information_Ack_RIM_Container(template RIM_Application_Identity app_id := ?,
					     template RIM_Sequence_Number seq := ?,
					     template RIM_Protocol_Version_Number ver := omit,
					     template SON_Transfer_Application_Identity_TLV son_app_id := omit) := {
		 iEI := '5A'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := ?
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_Protocol_Version_Number := ver,
		 sON_Transfer_Application_Identity := son_app_id
	}

	/* 3GPP TS 48.018 11.3.62a.4 */
	template (value) RAN_Information_Error_RIM_Container
	ts_RAN_Information_Error_RIM_Container(template (value) RIM_Application_Identity app_id,
					       template (value) Cause_BSSGP cause,
					       template (omit) RIM_Protocol_Version_Number ver := omit,
					       PDU_BSSGP pdu,
					       template (omit) SON_Transfer_Application_Identity_TLV son_app_id := omit) := {
		 iEI := '5B'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 rIM_Application_Identity := app_id,
		 rIM_cause := cause,
		 rIM_Protocol_Version_Number := ver,
		 pDU_in_Error:= {
			iEI := '15'O,
			ext := '1'B,
			lengthIndicator := {
				length1 := 0 /* overwritten */
			},
			erroneous_BSSGP_PDU := enc_PDU_BSSGP(pdu)
		 },
		 sON_Transfer_Application_Identity := son_app_id
	}
	template RAN_Information_Error_RIM_Container
	tr_RAN_Information_Error_RIM_Container(template RIM_Application_Identity app_id := ?,
					       template Cause_BSSGP cause := ?,
					       template RIM_Protocol_Version_Number ver := omit,
					       template octetstring pdu := ?,
					       template SON_Transfer_Application_Identity_TLV son_app_id := omit) := {
		 iEI := '5B'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := ?
		 },
		 rIM_Application_Identity := app_id,
		 rIM_cause := cause,
		 rIM_Protocol_Version_Number := ver,
		 pDU_in_Error:= {
			iEI := '15'O,
			ext := '1'B,
			lengthIndicator := {
				length1 := ?
			},
			erroneous_BSSGP_PDU := pdu
		 },
		 sON_Transfer_Application_Identity := son_app_id
	}

	/* 3GPP TS 48.018 11.3.62a.5 */
	template (value) RAN_Information_Application_Error_RIM_Container
	ts_RAN_Information_Application_Error_RIM_Container(template (value) RIM_Application_Identity app_id,
							   template (value) RIM_Sequence_Number seq,
							   template (value) RIM_PDU_Indications ind,
							   template (omit) RIM_Protocol_Version_Number ver := omit,
							   template (value) Application_Error_Container cont,
							   template (omit) SON_Transfer_Application_Identity_TLV son_app_id := omit) := {
		 iEI := '59'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_PDU_Indications := ind,
		 rIM_Protocol_Version_Number := ver,
		 application_Error_Container := cont,
		 sON_Transfer_Application_Identity := son_app_id
	}
	template RAN_Information_Application_Error_RIM_Container
	tr_RAN_Information_Application_Error_RIM_Container(template RIM_Application_Identity app_id := ?,
							   template RIM_Sequence_Number seq := ?,
							   template RIM_PDU_Indications ind := ?,
							   template RIM_Protocol_Version_Number ver := omit,
							   template Application_Error_Container cont := ?,
							   template SON_Transfer_Application_Identity_TLV son_app_id := omit) := {
		 iEI := '59'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := ?
		 },
		 rIM_Application_Identity := app_id,
		 rIM_Sequence_Number := seq,
		 rIM_PDU_Indications := ind,
		 rIM_Protocol_Version_Number := ver,
		 application_Error_Container := cont,
		 sON_Transfer_Application_Identity := son_app_id
	}


	/* 3GPP TS 48.018 11.3.63.1 */
	template (value) RAN_Information_Request_Application_Container
	tsu_RAN_Information_Request_Application_Container_NACC(template (value) BssgpCellId cid) := {
		nacc := ts_RAN_Information_Request_Application_Container_NACC(cid)
	}
	template (value) RAN_Information_Request_Application_Container
	tsu_RAN_Information_Request_Application_Container_SI3(template (value) BssgpCellId cid) := {
		si3 := ts_RAN_Information_Request_Application_Container_SI3(cid)
	}
	template (value) RAN_Information_Request_Application_Container
	tsu_RAN_Information_Request_Application_Container_MBMS_data_channel(template (value) BssgpCellId cid) := {
		mBMS_data_channel := ts_RAN_Information_Request_Application_Container_MBMS_data_channel(cid)
	}

	/* NOTE: The type description of reporting_Cell_Identifier in chapter 11.3.63.1, version V10.6.0 (2012-07) of
	 * 3GPP TS 48.018 clearly states: "Reporting Cell Identifier: This field is encoded as the Cell Identifier
	 * defined in sub-clause 11.3.9". However this seems to be an error in the specification, because the
	 * specifiction in Table 11.3.63.1.1 already has a length field an an IEI defined. Keeping the IEI and lenght
	 * of the BSSGP cell identifier in addition would no make sense. Also in the chapters below the specifiction
	 * of the IEs are similar and there it says "Reporting Cell Identifier: This field is encoded as the value
	 * part of the Cell Identifier IE defined in sub-clause 11.3.9, not including IEI and Length Indicator.",
	 * which actually makes sense. */

	/* 3GPP TS 48.018 11.3.63.1.1 */
	template (value) RAN_Information_Request_Application_Container_NACC
	ts_RAN_Information_Request_Application_Container_NACC(template (value) BssgpCellId cid) := {
		 iEI := '4D'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 reporting_Cell_Identifier := ts_Cell_Identifier_V(cid)
	}
	template RAN_Information_Request_Application_Container_NACC
	tr_RAN_Information_Request_Application_Container_NACC(template BssgpCellId cid := ?) := {
		 iEI := '4D'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := ?
		 },
		 reporting_Cell_Identifier := tr_Cell_Identifier_V(cid)
	}

	/* 3GPP TS 48.018 11.3.63.1.2 */
	template (value) RAN_Information_Request_Application_Container_SI3
	ts_RAN_Information_Request_Application_Container_SI3(template (value) BssgpCellId cid) := {
		 iEI := '4D'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 reporting_Cell_Identifier := ts_Cell_Identifier_V(cid)
	}

	/* 3GPP TS 48.018 11.3.63.1.3 */
	template (value) RAN_Information_Request_Application_Container_MBMS_data_channel
	ts_RAN_Information_Request_Application_Container_MBMS_data_channel(template (value) BssgpCellId cid) := {
		 iEI := '4D'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 reporting_Cell_Identifier := ts_Cell_Identifier_V(cid)
	}

	/* 3GPP TS 48.018 11.3.63.2.1 */
	template (value) RAN_Information_Application_Container_NACC
	ts_RAN_Information_Application_Container_NACC(template (value) BssgpCellId cid, boolean psi_type, integer si_psi_num, octetstring si_psi) := {
		 iEI := '4E'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 reporting_Cell_Identifier := ts_Cell_Identifier_V(cid),
		 typeBit := bool2bit(psi_type),
		 number_of_SI_PSI := int2bit(si_psi_num, 7),
		 sI_PSI := si_psi
	}
	function tr_RAN_Information_Application_Container_NACC(template BssgpCellId cid := ?, template boolean psi_type := ?,
							       template integer si_psi_num := ?, template octetstring si_psi := ?)
							       return template RAN_Information_Application_Container_NACC {
		 var template RAN_Information_Application_Container_NACC ret;
		 ret.iEI := '4E'O;
		 ret.ext := '1'B;
		 ret.lengthIndicator := { length1 := ? };
		 ret.reporting_Cell_Identifier := tr_Cell_Identifier_V(cid);
		 if (istemplatekind(psi_type, "*")) {
			ret.typeBit := *;
		 } else if (istemplatekind(psi_type, "?")) {
			ret.typeBit := ?;
		 } else {
			ret.typeBit := bool2bit(valueof(psi_type));
		 }
		 if (istemplatekind(si_psi_num, "*")) {
			ret.number_of_SI_PSI := *;
		 } else if (istemplatekind(si_psi_num, "?")) {
			ret.number_of_SI_PSI := ?;
		 } else {
			ret.number_of_SI_PSI := int2bit(valueof(si_psi_num), 7);
		 }
		 ret.sI_PSI := si_psi;
		 return ret;
	}

	/* 3GPP TS 48.018 11.3.63.2.2 */
	template (value) RAN_Information_Application_Container_SI3
	ts_RAN_Information_Application_Container_SI3(template (value) BssgpCellId cid, template (value) SI3 si3) := {
		 iEI := '4E'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 reporting_Cell_Identifier := ts_Cell_Identifier_V(cid),
		 sI3 := si3
	}

	/* 3GPP TS 48.018 11.3.63.2.3 */
	template (value) RAN_Information_Application_Container_MBMS_data_channel
	ts_RAN_Information_Application_Container_MBMS_data_channel(template (value) BssgpCellId cid, octetstring data_ch_report) := {
		 iEI := '4E'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 reporting_Cell_Identifier := ts_Cell_Identifier_V(cid),
		 mBMS_data_channel_report := data_ch_report
	}


	/* 3GPP TS 48.018 11.3.64 */
	template (value) Application_Error_Container
	tsu_Application_Error_Container_NACC(template (value) BssgpCellId cid,
					     integer cause,
					     template (value) Application_Container_IE_NACC app_cont) := {
		nacc := ts_Application_Error_Container_NACC(cid, cause, app_cont)
	}
	template Application_Error_Container
	rsu_Application_Error_Container_NACC(template BssgpCellId cid := ?,
					     template integer cause := ?,
					     template Application_Container_IE_NACC app_cont := ?) := {
		nacc := tr_Application_Error_Container_NACC(cid, cause, app_cont)
	}
	template (value) Application_Error_Container
	tsu_Application_Error_Container_SI3(template (value) BssgpCellId cid,
					    integer cause,
					    template (value) Application_Container_IE_SI3 app_cont) := {
		si3 := ts_Application_Error_Container_SI3(cid, cause, app_cont)
	}
	template (value) Application_Error_Container
	tsu_Application_Error_Container_MBMS_data_channel(template (value) BssgpCellId cid,
							  integer cause,
							  template (value) Application_Container_IE_MBMS_data_channel app_cont) := {
		mBMS_data_channel := ts_Application_Error_Container_MBMS_data_channel(cid, cause, app_cont)
	}

	/* 3GPP TS 48.018 11.3.64.1  */
	template (value) Application_Error_Container_NACC
	ts_Application_Error_Container_NACC(template (value) BssgpCellId cid,
					    integer cause,
					    template (value) Application_Container_IE_NACC app_cont) := {
		 iEI := '56'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 nACC_cause := int2oct(cause, 1),
		 erroneousApplicationContainer := app_cont
	}
	function tr_Application_Error_Container_NACC(template BssgpCellId cid := ?,
						     template integer cause := ?,
						     template Application_Container_IE_NACC app_cont := ?)
						     return template Application_Error_Container_NACC {
		 var template Application_Error_Container_NACC ret;
		 ret.iEI := '56'O;
		 ret.ext := '1'B;
		 ret.lengthIndicator := { length1 := ? };
		 ret.erroneousApplicationContainer := app_cont;
		 if (istemplatekind(cause, "*")) {
			ret.nACC_cause := *;
		 } else if (istemplatekind(cause, "?")) {
			ret.nACC_cause := ?;
		 } else {
			ret.nACC_cause := int2oct(valueof(cause), 1);
		 }
		 return ret;
	}

	template (value) Application_Container_IE_NACC
	tsu_Application_Container_IE_NACC_req(template (value) BssgpCellId cid) := {
		rAN_Information_Request_Application_Container := ts_RAN_Information_Request_Application_Container_NACC(cid)
	}
	template Application_Container_IE_NACC
	rsu_Application_Container_IE_NACC_req(template BssgpCellId cid := ?) := {
		rAN_Information_Request_Application_Container := tr_RAN_Information_Request_Application_Container_NACC(cid)
	}
	template (value) Application_Container_IE_NACC
	tsu_Application_Container_IE_NACC(template (value) BssgpCellId cid, boolean psi_type, integer si_psi_num, octetstring si_psi) := {
		rAN_Information_Application_Container := ts_RAN_Information_Application_Container_NACC(cid, psi_type, si_psi_num, si_psi)
	}

	/* 3GPP TS 48.018 11.3.64.2 */
	template (value) Application_Error_Container_SI3
	ts_Application_Error_Container_SI3(template (value) BssgpCellId cid,
					   integer cause,
					   template (value) Application_Container_IE_SI3 app_cont) := {
		 iEI := '56'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 sI3_cause := int2oct(cause, 1),
		 erroneousApplicationContainer := app_cont
	}
	template (value) Application_Container_IE_SI3
	tsu_Application_Container_IE_SI3_req(template (value) BssgpCellId cid) := {
		rAN_Information_Request_Application_Container := ts_RAN_Information_Request_Application_Container_SI3(cid)
	}
	template (value) Application_Container_IE_SI3
	tsu_Application_Container_IE_SI3(template (value) BssgpCellId cid, template (value) SI3 si3) := {
		rAN_Information_Application_Container := ts_RAN_Information_Application_Container_SI3(cid, si3)
	}

	/* 3GPP TS 48.018 11.3.64.3 */
	template (value) Application_Error_Container_MBMS_data_channel
	ts_Application_Error_Container_MBMS_data_channel(template (value) BssgpCellId cid,
							 integer cause,
							 template (value) Application_Container_IE_MBMS_data_channel app_cont) := {
		 iEI := '56'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 mBMS_data_channel_cause := int2oct(cause, 1),
		 erroneousApplicationContainer := app_cont
	}
	template (value) Application_Container_IE_MBMS_data_channel
	tsu_Application_Container_IE_MBMS_data_channel_req(template (value) BssgpCellId cid) := {
		rAN_Information_Request_Application_Container := ts_RAN_Information_Request_Application_Container_MBMS_data_channel(cid)
	}
	template (value) Application_Container_IE_MBMS_data_channel
	tsu_Application_Container_IE_MBMS_data_channel(template (value) BssgpCellId cid, octetstring data_ch_report) := {
		rAN_Information_Application_Container := ts_RAN_Information_Application_Container_MBMS_data_channel(cid, data_ch_report)
	}


	/* 3GPP TS 44.018 10.5.1.3 -> 3GPP TS 24.008 10.5.1.3 */
	function t_LocationAreaIdentification(template BssgpCellId cid) return template BSSGP_Types.LocationAreaIdentification {
		var template BSSGP_Types.LocationAreaIdentification ret := {
			mccDigit1 := ?,
			mccDigit2 := ?,
			mccDigit3 := ?,
			mncDigit3 := ?,
			mncDigit1 := ?,
			mncDigit2 := ?,
			lac := ?
		}
		if (istemplatekind(cid, "omit")) {
			return omit;
		} else if (istemplatekind(cid, "*")) {
			return *;
		} else if (istemplatekind(cid, "?")) {
			return ?;
		}
		if (isvalue(cid) and isvalue(cid.ra_id) and isvalue(cid.ra_id.lai)) {
			if (isvalue(cid.ra_id.lai.mcc_mnc)) {
				ret.mccDigit1 := cid.ra_id.lai.mcc_mnc[0];
				ret.mccDigit2 := cid.ra_id.lai.mcc_mnc[1];
				ret.mccDigit3 := cid.ra_id.lai.mcc_mnc[2];
				ret.mncDigit3 := cid.ra_id.lai.mcc_mnc[3];
				ret.mncDigit1 := cid.ra_id.lai.mcc_mnc[4];
				ret.mncDigit2 := cid.ra_id.lai.mcc_mnc[5];
			}
			if (isvalue(cid.ra_id.lai.lac)) {
				ret.lac := f_oct_or_wc(cid.ra_id.lai.lac, 2);
			}
		}
		return ret;
	}

	/* 3GPP TS 44.018 10.5.2.11 */
	template (value) ControlChannelDescription ts_ControlChannelDescription(integer ccch_conf,
										integer bs_ag_blks_res,
										boolean att,
										boolean mscr,
										integer bs_pa_mfrms,
										BIT2 cbq3,
										integer t3212) := {
		 cCCH_Conf := int2bit(ccch_conf, 3),
		 bS_AG_BLKS_RES := int2bit(bs_ag_blks_res, 3),
		 aTT := bool2bit(att),
		 mSCR := bool2bit(mscr),
		 bS_PA_MFRMS := int2bit(bs_pa_mfrms, 3),
		 spare1 := '00'B,
		 cBQ3 := cbq3,
		 spare2 := '0'B,
		 t3212 := int2oct(t3212, 1)
	}

	/* 3GPP TS 44.018 10.5.2.3 */
	template (value) CellOptions ts_CellOptions(integer radio_link_timeout,
						    BIT3 dtx,
						    boolean pwrc) := {
		radioLinkTimeout := int2bit(radio_link_timeout, 4),
		dTX1 := dtx[0] & dtx[1],
		pWRC := bool2bit(pwrc),
		dtx2 := dtx[2]
	}

	/* 3GPP TS 44.018 10.5.2.4 */
	template (value) CellSelectionParameters ts_CellSelectionParameters(integer ms_txpwr_max_cch,
									    integer cell_reselection_hysteresis,
									    integer rxlev_access_min,
									    boolean neci,
									    boolean acs) := {
		mS_TXPWR_MAX_CCH := int2bit(ms_txpwr_max_cch, 5),
		cellReselectHysterisis := int2bit(cell_reselection_hysteresis, 3),
		rXLEV_Access_Min := int2bit(rxlev_access_min, 6),
		nECI := bool2bit(neci),
		aCS := bool2bit(acs)
	}

	/* 3GPP TS 44.018 10.5.2.29 */
	template (value) RACHControlParameters ts_RACHControlParameters(boolean re,
									boolean cell_barr_access,
									integer tx_integer,
									integer max_retrans,
									integer ac_15_to_8,
									integer ac_7_to_0) := {
		rE := bool2bit(re),
		cellBarrAccess := bool2bit(cell_barr_access),
		tX_Integer := int2bit(tx_integer, 4),
		maxRetrans := int2bit(max_retrans, 2),
		aC_15_to_8 := int2oct(ac_15_to_8, 1),
		aC_7_to_0 := int2oct(ac_7_to_0, 1)
	}

	/* 3GPP TS 44.018 9.1.35 */
	template (value) SI3 ts_SI3(integer cell_id,
				    template (value) BSSGP_Types.LocationAreaIdentification lai,
				    template (value) ControlChannelDescription cch_descr,
				    template (value) CellOptions cell_opt,
				    template (value) CellSelectionParameters cell_sel_par,
				    template (value) RACHControlParameters rach_ctrl_par,
				    OCT4 rest_octets) := {
		sI3MessageType := '1B'O,
		cellIdentity := int2oct(cell_id, 2),
		locationAreaIdentification := lai,
		controlChannelDescription := cch_descr,
		cellOptions := cell_opt,
		cellSelectionParameters := cell_sel_par,
		rACHControlParameters := rach_ctrl_par,
		sI3RestOctets := rest_octets
	}


	/* 3GPP TS 48.018 11.3.65 */
	const BIT3 RIM_PDU_TYPE_STOP := '000'B;
	const BIT3 RIM_PDU_TYPE_SING_REP := '001'B;
	const BIT3 RIM_PDU_TYPE_MULT_REP := '010'B;
	template (value) RIM_PDU_Indications ts_RIM_PDU_Indications(boolean ack, BIT3 type_ext) := {
		 iEI := '4F'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 1
		 },
		 ack := bool2bit(ack),
		 pDU_Type_Extension := type_ext,
		 reserved := '0000'B
	}
	function tr_RIM_PDU_Indications(template boolean ack := ?, template BIT3 type_ext := ?) return template RIM_PDU_Indications {
		 var template RIM_PDU_Indications ret;
		 ret.iEI := '4F'O;
		 ret.ext := '1'B;
		 ret.lengthIndicator := { length1 := 1 };
		 if (istemplatekind(ack, "*")) {
			ret.ack := *;
		 } else if (istemplatekind(ack, "?")) {
			ret.ack := ?;
		 } else {
			ret.ack := bool2bit(valueof(ack));
		 }
		 if (istemplatekind(type_ext, "*")) {
			ret.pDU_Type_Extension := *;
		 } else if (istemplatekind(type_ext, "?")) {
			ret.pDU_Type_Extension := ?;
		 } else {
			ret.pDU_Type_Extension := valueof(type_ext);
		 }
		 ret.reserved := '0000'B;
		 return ret;
	}

	/* 3GPP TS 48.018 11.3.67 */
	template (value) RIM_Protocol_Version_Number ts_RIM_Protocol_Version_Number(integer ver) := {
		 iEI := '55'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 1
		 },
		 rIMProtocolVersionNumber := int2oct(ver, 1)
	}
	function tr_RIM_Protocol_Version_Number(template integer ver := ?) return template RIM_Protocol_Version_Number {
		 var template RIM_Protocol_Version_Number ret;
		 ret.iEI := '55'O;
		 ret.ext := '1'B;
		 ret.lengthIndicator := { length1 := 1 };
		 if (istemplatekind(ver, "*")) {
			ret.rIMProtocolVersionNumber := *;
		 } else if (istemplatekind(ver, "?")) {
			ret.rIMProtocolVersionNumber := ?;
		 } else {
			ret.rIMProtocolVersionNumber := int2oct(valueof(ver), 1);
		 }
		 return ret;
	}

	/* 3GPP TS 48.018 11.3.70 */
	const HEX1 RIM_ADDR_GERAN_CELL_ID := '0'H;
	const HEX1 RIM_ADDR_UTRAN_RNC_ID := '1'H;
	const HEX1 RIM_ADDR_EUTRAN_NODEB_ID := '2'H;
	const HEX1 RIM_ADDR_EHRPD_SECTOR_ID := '3'H;
	template (value) RIM_Routing_Information ts_RIM_Routing_Information(HEX1 addr_discr, template (value) RIM_Routing_Address addr) := {
		 iEI := '54'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 rIMRoutingAddressDiscriminator := addr_discr,
		 spare := '0'H,
		 rIM_Routing_Address := addr
	}
	template RIM_Routing_Information tr_RIM_Routing_Information(template HEX1 addr_discr := ?, template RIM_Routing_Address addr := ?) := {
		 iEI := '54'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := ?
		 },
		 rIMRoutingAddressDiscriminator := addr_discr,
		 spare := '0'H,
		 rIM_Routing_Address := addr
	}

	template RIM_Routing_Address t_RIM_Routing_Address_cid(template BssgpCellId cid := ?) := {
		 cell_Identifier := tr_Cell_Identifier_V(cid)
	}
	template RIM_Routing_Address t_RIM_Routing_Address_rncid(template BssgpCellId cid := ?, template integer rnc_id := ?) := {
		 globalRNCID := t_GlobalRNC_ID_BSSGP(cid, rnc_id)
	}
	template RIM_Routing_Address t_RIM_Routing_Address_enbid(template BssgpCellId cid := ?, template integer tac := ?, template octetstring gnbid := ?) := {
		 eNB_Identifier := t_ENB_Identifier_V(cid, tac, gnbid)
	}
	template RIM_Routing_Address t_RIM_Routing_Address_sector(template octetstring sector := ?) := {
		 eHRPD_SectorID := sector
	}

	function tr_Cell_Identifier_V(template BssgpCellId cid) return template Cell_Identifier_V {
		var template Cell_Identifier_V ret := {
			mccDigit1 := ?,
			mccDigit2 := ?,
			mccDigit3 := ?,
			mncDigit3 := ?,
			mncDigit1 := ?,
			mncDigit2 := ?,
			lac := ?,
			rac := ?,
			cI_value := ?
		}
		if (istemplatekind(cid, "omit")) {
			return omit;
		} else if (istemplatekind(cid, "*")) {
			return *;
		} else if (istemplatekind(cid, "?")) {
			return ?;
		}
		if (isvalue(cid) and isvalue(cid.ra_id) and isvalue(cid.ra_id.lai)) {
			if (isvalue(cid.ra_id.lai.mcc_mnc)) {
				ret.mccDigit1 := cid.ra_id.lai.mcc_mnc[0];
				ret.mccDigit2 := cid.ra_id.lai.mcc_mnc[1];
				ret.mccDigit3 := cid.ra_id.lai.mcc_mnc[2];
				ret.mncDigit3 := cid.ra_id.lai.mcc_mnc[3];
				ret.mncDigit1 := cid.ra_id.lai.mcc_mnc[4];
				ret.mncDigit2 := cid.ra_id.lai.mcc_mnc[5];
			}
			if (isvalue(cid.ra_id.lai.lac)) {
				ret.lac := f_oct_or_wc(cid.ra_id.lai.lac, 2);
			}
		}
		if (isvalue(cid) and isvalue(cid.ra_id)) {
			ret.rac := f_oct_or_wc(cid.ra_id.rac, 1);
		}
		if (isvalue(cid)) {
			ret.cI_value := f_oct_or_wc(cid.cell_id, 2);
		}
		return ret;
	}
	template (value) Cell_Identifier_V ts_Cell_Identifier_V(template (value) BssgpCellId cid) := {
		mccDigit1 := cid.ra_id.lai.mcc_mnc[0],
		mccDigit2 := cid.ra_id.lai.mcc_mnc[1],
		mccDigit3 := cid.ra_id.lai.mcc_mnc[2],
		mncDigit3 := cid.ra_id.lai.mcc_mnc[3],
		mncDigit1 := cid.ra_id.lai.mcc_mnc[4],
		mncDigit2 := cid.ra_id.lai.mcc_mnc[5],
		lac := int2oct(valueof(cid.ra_id.lai.lac), 2),
		rac := int2oct(valueof(cid.ra_id.rac), 1),
		cI_value := int2oct(valueof(cid.cell_id), 2)
	}

	function t_GlobalRNC_ID_BSSGP(template BssgpCellId cid, template integer rnc_id) return template GlobalRNC_ID_BSSGP {
		var template GlobalRNC_ID_BSSGP ret := {
			mccDigit1 := ?,
			mccDigit2 := ?,
			mccDigit3 := ?,
			mncDigit3 := ?,
			mncDigit1 := ?,
			mncDigit2 := ?,
			lac := ?,
			rac := ?,
			spare := ?,
			rNC_ID := ?
		}
		if (istemplatekind(cid, "omit") and istemplatekind(rnc_id, "omit")) {
			return omit;
		} else if (istemplatekind(cid, "*") and istemplatekind(rnc_id, "*")) {
			return *;
		} else if (istemplatekind(cid, "?") and istemplatekind(rnc_id, "?")) {
			return ?;
		}
		if (isvalue(cid) and isvalue(cid.ra_id) and isvalue(cid.ra_id.lai)) {
			if (isvalue(cid.ra_id.lai.mcc_mnc)) {
				ret.mccDigit1 := cid.ra_id.lai.mcc_mnc[0];
				ret.mccDigit2 := cid.ra_id.lai.mcc_mnc[1];
				ret.mccDigit3 := cid.ra_id.lai.mcc_mnc[2];
				ret.mncDigit3 := cid.ra_id.lai.mcc_mnc[3];
				ret.mncDigit1 := cid.ra_id.lai.mcc_mnc[4];
				ret.mncDigit2 := cid.ra_id.lai.mcc_mnc[5];
			}
			if (isvalue(cid.ra_id.lai.lac)) {
				ret.lac := f_oct_or_wc(cid.ra_id.lai.lac, 2);
			}
		}
		if (isvalue(cid) and isvalue(cid.ra_id)) {
			ret.rac := f_oct_or_wc(cid.ra_id.rac, 1);
		}
		if (isvalue(rnc_id)) {
			ret.spare := '0'H;
			ret.rNC_ID := rnc_id;
		}

		return ret;
	}

	function t_ENB_Identifier_V(template BssgpCellId cid, template integer tac, template octetstring gnbid) return template ENB_Identifier_V {
		var template ENB_Identifier_V ret := {
			mccDigit1 := ?,
			mccDigit2 := ?,
			mccDigit3 := ?,
			mncDigit3 := ?,
			mncDigit1 := ?,
			mncDigit2 := ?,
			tac := ?,
			globaleNBID := ?
		}
		if (istemplatekind(cid, "omit") and istemplatekind(tac, "omit") and istemplatekind(gnbid, "omit")) {
			return omit;
		} else if (istemplatekind(cid, "*") and istemplatekind(tac, "*") and istemplatekind(gnbid, "*")) {
			return *;
		} else if (istemplatekind(cid, "?") and istemplatekind(tac, "?") and istemplatekind(gnbid, "?")) {
			return ?;
		}
		if (isvalue(cid) and isvalue(cid.ra_id) and isvalue(cid.ra_id.lai)) {
			if (isvalue(cid.ra_id.lai.mcc_mnc)) {
				ret.mccDigit1 := cid.ra_id.lai.mcc_mnc[0];
				ret.mccDigit2 := cid.ra_id.lai.mcc_mnc[1];
				ret.mccDigit3 := cid.ra_id.lai.mcc_mnc[2];
				ret.mncDigit3 := cid.ra_id.lai.mcc_mnc[3];
				ret.mncDigit1 := cid.ra_id.lai.mcc_mnc[4];
				ret.mncDigit2 := cid.ra_id.lai.mcc_mnc[5];
			}
		}
		if (isvalue(tac)) {
			ret.tac := int2oct(valueof(tac), 2);
		}
		if (isvalue(gnbid)) {
			ret.globaleNBID := gnbid;
		}

		return ret;
	}

	/* 3GPP TS 48.018 11.3.108 */
	template (value) SON_Transfer_Application_Identity_TLV ts_SON_Transfer_Application_Identity_TLV(template (value) octetstring app_id) := {
		 iEI := '84'O,
		 ext := '1'B,
		 lengthIndicator := {
			length1 := 0 /* overwritten */
		 },
		 sON_Transfer_Application_Identity := app_id
	}


	/* 3GPP TS 48.018 10.6.1 */
	template (value) PDU_BSSGP
	ts_RAN_INFORMATION_REQUEST(template (value) RIM_Routing_Information dst,
				   template (value) RIM_Routing_Information src,
				   template (value) RAN_Information_Request_RIM_Container cont) := {
		pDU_BSSGP_RAN_INFORMATION_REQUEST := {
			bssgpPduType := '71'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}
	template PDU_BSSGP
	tr_RAN_INFORMATION_REQUEST(template RIM_Routing_Information dst := ?,
				   template RIM_Routing_Information src := ?,
				   template RAN_Information_Request_RIM_Container cont := ?) := {
		pDU_BSSGP_RAN_INFORMATION_REQUEST := {
			bssgpPduType := '71'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}

	/* 3GPP TS 48.018 10.6.2 */
	template (value) PDU_BSSGP
	ts_PDU_BSSGP_RAN_INFORMATION(template (value) RIM_Routing_Information dst,
				     template (value) RIM_Routing_Information src,
				     template (value) RAN_Information_RIM_Container cont) := {
		pDU_BSSGP_RAN_INFORMATION := {
			bssgpPduType := '70'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}
	template PDU_BSSGP
	tr_PDU_BSSGP_RAN_INFORMATION(template RIM_Routing_Information dst := ?,
				     template RIM_Routing_Information src := ?,
				     template RAN_Information_RIM_Container cont := ?) := {
		pDU_BSSGP_RAN_INFORMATION := {
			bssgpPduType := '70'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}

	/* 3GPP TS 48.018 10.6.3 */
	template (value) PDU_BSSGP
	ts_PDU_BSSGP_RAN_INFORMATION_ACK(template (value) RIM_Routing_Information dst,
					 template (value) RIM_Routing_Information src,
					 template (value) RAN_Information_Ack_RIM_Container cont) := {
		pDU_BSSGP_RAN_INFORMATION_ACK := {
			bssgpPduType := '72'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}
	template PDU_BSSGP
	tr_PDU_BSSGP_RAN_INFORMATION_ACK(template RIM_Routing_Information dst := ?,
					 template RIM_Routing_Information src := ?,
					 template RAN_Information_Ack_RIM_Container cont := ?) := {
		pDU_BSSGP_RAN_INFORMATION_ACK := {
			bssgpPduType := '72'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}

	/* 3GPP TS 48.018 10.6.4 */
	template (value) PDU_BSSGP
	ts_PDU_BSSGP_RAN_INFORMATION_ERROR(template (value) RIM_Routing_Information dst,
					   template (value) RIM_Routing_Information src,
					   template (value) RAN_Information_Error_RIM_Container cont) := {
		pDU_BSSGP_RAN_INFORMATION_ERROR := {
			bssgpPduType := '73'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}
	template PDU_BSSGP
	tr_PDU_BSSGP_RAN_INFORMATION_ERROR(template RIM_Routing_Information dst := ?,
					   template RIM_Routing_Information src := ?,
					   template RAN_Information_Error_RIM_Container cont := ?) := {
		pDU_BSSGP_RAN_INFORMATION_ERROR := {
			bssgpPduType := '73'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}

	/* 3GPP TS 48.018 10.6.5 */
	template (value) PDU_BSSGP
	ts_PDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR(template (value) RIM_Routing_Information dst,
						       template (value) RIM_Routing_Information src,
						       template (value) RAN_Information_Application_Error_RIM_Container cont) := {
		pDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR := {
			bssgpPduType := '74'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}
	template PDU_BSSGP
	tr_PDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR(template RIM_Routing_Information dst := ?,
						       template RIM_Routing_Information src := ?,
						       template RAN_Information_Application_Error_RIM_Container cont := ?) := {
		pDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR := {
			bssgpPduType := '74'O,
			destination_Cell_Identifier := dst,
			source_Cell_Identifier := src,
			rIM_Container := cont
		}
	}

	/* PDU permitted on PTP BVC only (TS 48.018 Section 5.4.1) */
	template (present) PDU_BSSGP tr_BSSGP_PERMITTED_PTP_ONLY := (
		{pDU_BSSGP_DL_UNITDATA := ?},
		{pDU_BSSGP_UL_UNITDATA := ?},
		{pDU_BSSGP_RA_CAPABILITY := ?},
		{pDU_BSSGP_RA_CAPABILITY_UPDATE := ?},
		{pDU_BSSGP_RA_CAPABILITY_UPDATE_ACK := ?},
		{pDU_BSSGP_RADIO_STATUS := ?},
		{pDU_BSSGP_FLOW_CONTROL_BVC := ?},
		{pDU_BSSGP_FLOW_CONTROL_BVC_ACK := ?},
		{pDU_BSSGP_FLOW_CONTROL_MS := ?},
		{pDU_BSSGP_FLOW_CONTROL_MS_ACK := ?},
		{pDU_BSSGP_FLOW_CONTROL_PFC := ?},
		{pDU_BSSGP_FLOW_CONTROL_PFC_ACK := ?},
		{pDU_BSSGP_DOWNLOAD_BSS_PFC := ?},
		{pDU_BSSGP_CREATE_BSS_PFC := ?},
		{pDU_BSSGP_CREATE_BSS_PFC_ACK := ?},
		{pDU_BSSGP_CREATE_BSS_PFC_NACK := ?},
		{pDU_BSSGP_MODIFY_BSS_PFC := ?},
		{pDU_BSSGP_MODIFY_BSS_PFC_ACK := ?},
		{pDU_BSSGP_DELETE_BSS_PFC := ?},
		{pDU_BSSGP_DELETE_BSS_PFC_ACK := ?},
		{pDU_BSSGP_DELETE_BSS_PFC_REQ := ?},
		{pDU_BSSGP_PS_HANDOVER_REQUIRED := ?},
		{pDU_BSSGP_PS_HANDOVER_REQUIRED_ACK := ?},
		{pDU_BSSGP_PS_HANDOVER_REQUIRED_NACK := ?},
		{pDU_BSSGP_PS_HANDOVER_REQUEST := ?},
		{pDU_BSSGP_PS_HANDOVER_REQUEST_ACK := ?},
		{pDU_BSSGP_PS_HANDOVER_REQUEST_NACK := ?},
		{pDU_BSSGP_PS_HANDOVER_COMPLETE := ?},
		{pDU_BSSGP_PS_HANDOVER_COMPLETE_ACK := ?},
		{pDU_BSSGP_PS_HANDOVER_CANCEL := ?}
	);

	template (present) PDU_BSSGP tr_BSSGP_PERMITTED_PTP := (
		tr_BSSGP_PERMITTED_PTP_ONLY,
		{pDU_BSSGP_PAGING_PS := ?},
		{pDU_BSSGP_PAGING_CS := ?},
		{pDU_BSSGP_STATUS := ?}
	);

	/* PDU permitted on Signaling BVC only (TS 48.018 Section 5.4.1) */
	template (present) PDU_BSSGP tr_BSSGP_PERMITTED_SIGN_ONLY := (
		{pDU_BSSGP_SUSPEND := ?},
		{pDU_BSSGP_SUSPEND_ACK := ?},
		{pDU_BSSGP_SUSPEND_NACK := ?},
		{pDU_BSSGP_RESUME := ?},
		{pDU_BSSGP_RESUME_ACK := ?},
		{pDU_BSSGP_RESUME_NACK := ?},
		{pDU_BSSGP_FLUSH_LL := ?},
		{pDU_BSSGP_FLUSH_LL_ACK := ?},
		{pDU_BSSGP_LLC_DISCARDED := ?},
		{pDU_BSSGP_BVC_BLOCK := ?},
		{pDU_BSSGP_BVC_BLOCK_ACK := ?},
		{pDU_BSSGP_BVC_UNBLOCK := ?},
		{pDU_BSSGP_BVC_UNBLOCK_ACK := ?},
		{pDU_BSSGP_BVC_RESET := ?},
		{pDU_BSSGP_BVC_RESET_ACK := ?},
		{pDU_BSSGP_SGSN_INVOKE_TRACE := ?},
		{pDU_BSSGP_PERFORM_LOCATION_REQUEST := ?},
		{pDU_BSSGP_PERFORM_LOCATION_RESPONSE := ?},
		{pDU_BSSGP_PERFORM_LOCATION_ABORT := ?},
		{pDU_BSSGP_POSITION_COMMAND := ?},
		{pDU_BSSGP_POSITION_RESPONSE := ?},
		{pDU_BSSGP_RAN_INFORMATION := ?},
		{pDU_BSSGP_RAN_INFORMATION_REQUEST := ?},
		{pDU_BSSGP_RAN_INFORMATION_ACK := ?},
		{pDU_BSSGP_RAN_INFORMATION_ERROR := ?},
		{pDU_BSSGP_RAN_INFORMATION_APPLICATION_ERROR := ?},
		{pDU_BSSGP_MBMS_SESSION_START_REQUEST := ?},
		{pDU_BSSGP_MBMS_SESSION_START_RESPONSE := ?},
		{pDU_BSSGP_MBMS_SESSION_STOP_REQUEST := ?},
		{pDU_BSSGP_MBMS_STOP_RESPONSE := ?},
		{pDU_BSSGP_SESSION_UPDATE_REQUEST := ?},
		{pDU_BSSGP_SESSION_UPDATE_RESPONSE := ?}
	);

	template (present) PDU_BSSGP tr_BSSGP_PERMITTED_SIGN := (
		tr_BSSGP_PERMITTED_SIGN_ONLY,
		{pDU_BSSGP_PAGING_PS := ?},
		{pDU_BSSGP_PAGING_CS := ?},
		{pDU_BSSGP_SUSPEND := ?},
		{pDU_BSSGP_STATUS := ?}
	);

	/* PDU permitted on PTM BVC only (TS 48.018 Section 5.4.1) */
	template (present) PDU_BSSGP tr_BSSGP_PERMITTED_PTM_ONLY := (
		{pDU_BSSGP_DL_MBMS_UNITDATA := ?},
		{pDU_BSSGP_UL_MBMS_UNITDATA := ?}
	);

	template (present) PDU_BSSGP tr_BSSGP_PERMITTED_PTM := (
		tr_BSSGP_PERMITTED_PTM_ONLY,
		{pDU_BSSGP_STATUS := ?}
	);


	/* Template for any PTP BVCI IE */
	template (present) BVCI tr_BSSGP_IE_PtpBvci := {
		iEI := '04'O,
		ext := '1'B,
		lengthIndicator := {
			length1 := 2
		},
		unstructured_value := complement ('0000'O, '0001'O)
	}

	/* message on signaling PTP but containing a ptp BVC */
	/*
	template PDU_BSSGP tr_BSSGP_SIG_FOR_PTP(template Bvci bvci) := (
		{pDU_BSSGP_FLUSH_LL:{?,?,tr_BSSGP_IE_PtpBvci, *, *}},
		{pDU_BSSGP_FLUSH_LL_ACK:{?,?,?,tr_BSSGP_IE_PtpBvci, ?, *}},
		{pDU_BSSGP_LLC_DISCARDED:{?,?,?,tr_BSSGP_IE_PtpBvci, ?, *}},
		{pDU_BSSGP_BVC_BLOCK:{?,tr_BSSGP_IE_PtpBvci, ?}},
		{pDU_BSSGP_BVC_BLOCK_ACK:{?,tr_BSSGP_IE_PtpBvci}},
		{pDU_BSSGP_BVC_UNBLOCK:{?,tr_BSSGP_IE_PtpBvci}},
		{pDU_BSSGP_BVC_UNBLOCK_ACK:{?,tr_BSSGP_IE_PtpBvci}},
		{pDU_BSSGP_BVC_RESET:{?,tr_BSSGP_IE_PtpBvci,?,*,*,*}},
		{pDU_BSSGP_BVC_RESET_ACK:{?,tr_BSSGP_IE_PtpBvci,*,*,*}},
		{pDU_BSSGP_STATUS:{?,?,tr_BSSGP_IE_PtpBvci,*}},
		{pDU_BSSGP_PERFORM_LOCATION_REQUEST:{?,?,?,*,tr_BSSGP_IE_PtpBvci,?,?,?,*,*,*,*,*,*,*,*,*}},
		{pDU_BSSGP_PERFORM_LOCATION_RESPONSE:{?,?,tr_BSSGP_IE_PtpBvci,*,*,*,*,*,*}},
		{pDU_BSSGP_PERFORM_LOCATION_ABORT:{?,?,tr_BSSGP_IE_PtpBvci,?}},
		{pDU_BSSGP_POSITION_COMMAND:{
	);
	*/

	/* extract the BVCI IE of given PDU + return it */
	function f_BSSGP_BVCI_IE_get(PDU_BSSGP pdu) return template (omit) BVCI {
		select (pdu) {
		case (PDU_BSSGP:{pDU_BSSGP_FLUSH_LL:=?}) {
			return pdu.pDU_BSSGP_FLUSH_LL.bVCI_old;
			}
		case (PDU_BSSGP:{pDU_BSSGP_FLUSH_LL_ACK:=?}) {
			return pdu.pDU_BSSGP_FLUSH_LL_ACK.bVCI_new;
			}
		case (PDU_BSSGP:{pDU_BSSGP_LLC_DISCARDED:=?}) {
			return pdu.pDU_BSSGP_LLC_DISCARDED.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_BVC_BLOCK:=?}) {
			return pdu.pDU_BSSGP_BVC_BLOCK.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_BVC_BLOCK_ACK:=?}) {
			return pdu.pDU_BSSGP_BVC_BLOCK_ACK.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_BVC_UNBLOCK:=?}) {
			return pdu.pDU_BSSGP_BVC_UNBLOCK.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_BVC_UNBLOCK_ACK:=?}) {
			return pdu.pDU_BSSGP_BVC_UNBLOCK_ACK.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_BVC_RESET:=?}) {
			return pdu.pDU_BSSGP_BVC_RESET.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_BVC_RESET_ACK:=?}) {
			return pdu.pDU_BSSGP_BVC_RESET_ACK.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_STATUS:=?}) {
			return pdu.pDU_BSSGP_STATUS.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_PERFORM_LOCATION_REQUEST:=?}) {
			return pdu.pDU_BSSGP_PERFORM_LOCATION_REQUEST.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_PERFORM_LOCATION_RESPONSE:=?}) {
			return pdu.pDU_BSSGP_PERFORM_LOCATION_RESPONSE.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_PERFORM_LOCATION_ABORT:=?}) {
			return pdu.pDU_BSSGP_PERFORM_LOCATION_ABORT.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_POSITION_COMMAND:=?}) {
			return pdu.pDU_BSSGP_POSITION_COMMAND.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_POSITION_RESPONSE:=?}) {
			return pdu.pDU_BSSGP_POSITION_RESPONSE.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_PAGING_PS:={?,?,*,{bVCI:=?},*,*,?,*,*}}) {
			return pdu.pDU_BSSGP_PAGING_PS.paging_Field4.bVCI;
			}
		case (PDU_BSSGP:{pDU_BSSGP_PAGING_CS:={?,?,?,{bVCI:=?},*,*,*,*,*}}) {
			return pdu.pDU_BSSGP_PAGING_CS.paging_Field4.bVCI;
			}
		}
		return omit;
	}

	/* extract the BVCI IE of given PDU + convert it to integer value */
	function f_BSSGP_BVCI_get(PDU_BSSGP pdu) return template (omit) BssgpBvci {
		var template (omit) BVCI bvci_raw := f_BSSGP_BVCI_IE_get(pdu);
		if (istemplatekind(bvci_raw, "omit")) {
			return omit;
		}
		return oct2int(valueof(bvci_raw.unstructured_value));
	}

	/* 3GPP TS 23.003 2.6 */
	type enumerated TlliType {
		TLLI_LOCAL,
		TLLI_FOREIGN,
		TLLI_RANDOM,
		TLLI_AUXILIARY,
		TLLI_RESERVED,
		TLLI_G_RNTI,
		TLLI_RAND_G_RNTI
	}

	/* 3GPP TS 23.003 2.6 */
	function f_gprs_tlli_type(OCT4 tlli) return TlliType {
		var bitstring tllib := oct2bit(tlli);
		if (substr(tllib, 0, 2) == '11'B) {
			return TLLI_LOCAL;
		} else if (substr(tllib, 0, 2) == '10'B) {
			return TLLI_FOREIGN;
		} else if (substr(tllib, 0, 5) == '01111'B) {
			return TLLI_RANDOM;
		} else if (substr(tllib, 0, 4) == '0110'B) {
			return TLLI_RESERVED;
		} else if (substr(tllib, 0, 3) == '010'B) {
			return TLLI_RESERVED;
		} else if (substr(tllib, 0, 4) == '0000'B) {
			return TLLI_G_RNTI;
		} else if (substr(tllib, 0, 4) == '0001'B) {
			return TLLI_RAND_G_RNTI;
		} else {
			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
						log2str("Unknonw TLLI Type ", tllib));
			return TLLI_LOCAL;
		}
	}

	/* build a TLLI of specified type from the given (P)TMSI */
	function f_gprs_tlli_from_tmsi(OCT4 tmsi, TlliType tlli_type) return OCT4 {
		var bitstring tmsi_bits := oct2bit(tmsi);
		var bitstring prefix;
		select (tlli_type) {
		case (TLLI_LOCAL)	{ prefix := '11'B }
		case (TLLI_FOREIGN)	{ prefix := '01111'B }
		case (TLLI_RANDOM)	{ prefix := '0110'B }
		case (TLLI_RESERVED)	{ prefix := '010'B }
		case (TLLI_G_RNTI)	{ prefix := '0000'B }
		case (TLLI_RAND_G_RNTI)	{ prefix := '0001'B }
		case else {
			Misc_Helpers.f_shutdown(__BFILE__, __LINE__, fail,
						log2str("Unknonw TLLI Type ", tlli_type));
			return '00000000'O;
			}
		}
		return bit2oct(prefix & substr(tmsi_bits, lengthof(prefix), 32-lengthof(prefix)));
	}

	function f_gprs_tlli_random() return OCT4 {
		var OCT4 tlli := f_rnd_octstring(4);
		return tlli or4b 'c0000000'O;
	}

} with { encode "RAW" };
