module ECBE_Types {

/* Type definitions for the ECBE (External Cell Broadcast Entity) protocol of OsmoCBC */
/* (C) 2021 by Harald Welte <laforge@gnumonks.org>
 * All rights reserved.
 */

/***********************************************************************
 * smscb.schema.json
 ***********************************************************************/

type charstring EcbeLanguageCode length(2);

type integer EcbeMessageId (0..65535);

type enumerated EcbeGeographicScope {
	cell_wide_immediate,
	plmn_wide,
	lac_sac_tac_wide,
	cell_wide
};

type integer EcbeMessageCode (0..1023);

type integer EcbeUpdateNumber (0..15);

type integer EcbeSerialNrEncoded (0..65535);

type record EcbeSerialNrDecoded {
	EcbeGeographicScope	geo_scope,
	EcbeMessageCode		msg_code,
	EcbeUpdateNumber	update_nr
};

type union EcbeSerialNr {
	EcbeSerialNrEncoded	serial_nr_encoded,
	EcbeSerialNrDecoded	serial_nr_decoded
};

type integer EcbeDcsEncoded (0..255);

type enumerated EcbeCharacterSet {
	gsm,
	eight_bit,
	ucs2
};

type integer EcbeDcsClass (0..3);

type record EcbePayloadDecoded {
	EcbeCharacterSet	character_set optional,
	EcbeLanguageCode	Language optional,
	EcbeDcsClass		dcs_class optional,
	charstring		data_utf8
};

type charstring EcbePage;
type record of EcbePage EcbePages;

type record EcbePayloadEncoded {
	EcbeDcsEncoded		dcs,
	EcbePages		pages
};

type integer EcbeWarningTypeEncoded (0..127);

type enumerated EcbeWarningTypeDecoded {
	earthquake,
	tsunami,
	earthquake_and_tsunami,
	test,
	other,
	rfu
};

type union EcbeWarningType {
	EcbeWarningTypeEncoded	warning_type_encoded,
	EcbeWarningTypeDecoded	warning_type_decoded
};

type record EcbePayloadEtws {
	EcbeWarningType		warning_type,
	boolean			emergency_user_alert optional,
	boolean			popup_on_display optional,
	charstring		warning_sec_info optional
};

type union EcbePayload {
	EcbePayloadEncoded	payload_encoded,
	EcbePayloadDecoded	payload_decoded,
	EcbePayloadEtws		payload_etws
};

type record EcbeSmscbMessage {
	EcbeSerialNr	serial_nr,
	EcbeMessageId	message_id,
	EcbePayload	payload
};

external function enc_EcbeSmscbMessage(in EcbeSmscbMessage inp) return octetstring
	with { extension "prototype(convert) encode(JSON)" }
external function dec_EcbeSmscbMessage(in octetstring inp) return EcbeSmscbMessage
	with { extension "prototype(convert) decode(JSON)" }

/***********************************************************************
 * cbc.schema.json
 ***********************************************************************/

type enumerated EcbeCategory {
	normal,
	high_priority,
	background
};

type integer EcbeRepetitionPeriod (1..4095);

type enumerated EcbeChannelIndicator {
	basic,
	extended
};

type integer EcbeWarningPeriodSec (0..3600);

type integer EcbeNumberOfBroadcasts (0..65535);

type record EcbeScopePlmn {
};

type union EcbeScope {
	EcbeScopePlmn	scope_plmn
};

type record EcbeCbcMessage {
	charstring		cbe_name optional,
	EcbeCategory		category optional,
	EcbeRepetitionPeriod	repetition_period optional,
	EcbeNumberOfBroadcasts	num_of_bcast optional,
	EcbeScope		scope,
	EcbeSmscbMessage	smscb_message
};

external function enc_EcbeCbcMessage(in EcbeCbcMessage inp) return octetstring
	with { extension "prototype(convert) encode(JSON)" }
external function dec_EcbeCbcMessage(in octetstring inp) return EcbeCbcMessage
	with { extension "prototype(convert) decode(JSON)" }

} with { encode "JSON" }