/*
 * Generated by asn1c-0.9.29 (http://lionet.info/asn1c)
 * From ASN.1 module "X2AP-IEs"
 * 	found in "Spec/e2_and_x2-combined-and-minimized.asn1"
 * 	`asn1c -pdu=auto -fincludes-quoted -fcompound-names -fno-include-deps -gen-PER -no-gen-OER -no-gen-example`
 */

#include "RadioframeAllocationOffset.h"

int
RadioframeAllocationOffset_constraint(const asn_TYPE_descriptor_t *td, const void *sptr,
			asn_app_constraint_failed_f *ctfailcb, void *app_key) {
	long value;
	
	if(!sptr) {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: value not given (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
	
	value = *(const long *)sptr;
	
	if((value >= 0 && value <= 7)) {
		/* Constraint check succeeded */
		return 0;
	} else {
		ASN__CTFAIL(app_key, td, sptr,
			"%s: constraint failed (%s:%d)",
			td->name, __FILE__, __LINE__);
		return -1;
	}
}

/*
 * This type is implemented using NativeInteger,
 * so here we adjust the DEF accordingly.
 */
asn_per_constraints_t asn_PER_type_RadioframeAllocationOffset_constr_1 CC_NOTUSED = {
	{ APC_CONSTRAINED | APC_EXTENSIBLE,  3,  3,  0,  7 }	/* (0..7,...) */,
	{ APC_UNCONSTRAINED,	-1, -1,  0,  0 },
	0, 0	/* No PER value map */
};
static const ber_tlv_tag_t asn_DEF_RadioframeAllocationOffset_tags_1[] = {
	(ASN_TAG_CLASS_UNIVERSAL | (2 << 2))
};
asn_TYPE_descriptor_t asn_DEF_RadioframeAllocationOffset = {
	"RadioframeAllocationOffset",
	"RadioframeAllocationOffset",
	&asn_OP_NativeInteger,
	asn_DEF_RadioframeAllocationOffset_tags_1,
	sizeof(asn_DEF_RadioframeAllocationOffset_tags_1)
		/sizeof(asn_DEF_RadioframeAllocationOffset_tags_1[0]), /* 1 */
	asn_DEF_RadioframeAllocationOffset_tags_1,	/* Same as above */
	sizeof(asn_DEF_RadioframeAllocationOffset_tags_1)
		/sizeof(asn_DEF_RadioframeAllocationOffset_tags_1[0]), /* 1 */
	{ 0, &asn_PER_type_RadioframeAllocationOffset_constr_1, RadioframeAllocationOffset_constraint },
	0, 0,	/* No members */
	0	/* No specifics */
};

