module GSMTAP_Types {
	import from Osmocom_Types all;

	const uint8_t GSMTAP_VERSION	:= 2;

	const uint16_t GSMTAP_PORT	:= 4729;

	type enumerated GsmtapMsgType {
		GSMTAP_TYPE_UM (1),
		GSMTAP_TYPE_ABIS (2),
		GSMTAP_TYPE_UM_BURST (3),
		GSMTAP_TYPE_SIM	(4),
		GSMTAP_TYPE_TETRA_I1 (5),
		GSMTAP_TYPE_TETRA_I1_BURST (6),
		GSMTAP_TYPE_WMX_BURST (7),
		GSMTAP_TYPE_GB_LLC (8),
		GSMTAP_TYPE_GB_SNDCP (9),
		GSMTAP_TYPE_GMR1_UM (10),
		GSMTAP_TYPE_UMTS_RLC_MAC (11),
		GSMTAP_TYPE_UMTS_RRC (12),
		GSMTAP_TYPE_LTE_RRC (13),
		GSMTAP_TYPE_LTE_MAC (14),
		GSMTAP_TYPE_LTE_MAC_FRAMED (15),
		GSMTAP_TYPE_OSMOCORE_LOG (16),
		GSMTAP_TYPE_QC_DIAG (17)
	} with { variant "FIELDLENGTH(8)" };

	type enumerated GsmtapChannel {
		GSMTAP_CHANNEL_UNKNOWN		(0),
		GSMTAP_CHANNEL_BCCH		(1),
		GSMTAP_CHANNEL_CCCH		(2),
		GSMTAP_CHANNEL_RACH		(3),
		GSMTAP_CHANNEL_AGCH		(4),
		GSMTAP_CHANNEL_PCH		(5),
		GSMTAP_CHANNEL_SDCCH		(6),
		GSMTAP_CHANNEL_SDCCH4		(7),
		GSMTAP_CHANNEL_SDCCH8		(8),
		GSMTAP_CHANNEL_TCH_F		(9),
		GSMTAP_CHANNEL_TCH_H		(10),
		GSMTAP_CHANNEL_PACCH		(11),
		GSMTAP_CHANNEL_CBCH52		(12),
		GSMTAP_CHANNEL_PDCH		(13),
		GSMTAP_CHANNEL_PTCCH		(14),
		GSMTAP_CHANNEL_CBCH51		(15)
	} with { variant "FIELDLENGTH(8)" };

	type record GsmtapHeader {
		uint8_t		version,
		uint8_t		hdr_len,
		GsmtapMsgType	msg_type,
		uint8_t		timeslot,
		Arfcn		arfcn,
		int8_t		signal_dbm,
		int8_t		snr_db,
		uint32_t	frame_number,
		GsmtapChannel	sub_type,
		uint8_t		antenna_nr,
		uint8_t		sub_slot,
		uint8_t		res
	} with { variant (hdr_len) "LENGTHTO(version, hdr_len, msg_type, timeslot, arfcn, signal_dbm, snr_db, frame_number, sub_type, antenna_nr, sub_slot, res), UNIT(dword32)" }

	external function enc_GsmtapHeader(in GsmtapHeader si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_GsmtapHeader(in octetstring stream) return GsmtapHeader
		with { extension "prototype(convert) decode(RAW)" };

	type record GsmtapMessage {
		GsmtapHeader	header,
		octetstring	payload optional
	} with { variant "" };

	external function enc_GsmtapMessage(in GsmtapMessage si) return octetstring
		with { extension "prototype(convert) encode(RAW)" };
	external function dec_GsmtapMessage(in octetstring stream) return GsmtapMessage
		with { extension "prototype(convert) decode(RAW)" };

} with { encode "RAW" };
