X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?p=sim%2Fe2-interface.git;a=blobdiff_plain;f=e2sim%2Fe2apv1sim%2Fricsim%2FASN1c%2Fasn_random_fill.h;fp=e2sim%2Fe2apv1sim%2Fricsim%2FASN1c%2Fasn_random_fill.h;h=47f9b8af01560d91d29a774571355c424bcb20dc;hp=0000000000000000000000000000000000000000;hb=3ebf932d23dcbec9ed19f4a51f9d00a0a54f5124;hpb=6896318f2b4ff01b4a88b16019c3dc93b0b693f5 diff --git a/e2sim/e2apv1sim/ricsim/ASN1c/asn_random_fill.h b/e2sim/e2apv1sim/ricsim/ASN1c/asn_random_fill.h new file mode 100644 index 0000000..47f9b8a --- /dev/null +++ b/e2sim/e2apv1sim/ricsim/ASN1c/asn_random_fill.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2017 Lev Walkin . All rights reserved. + * Redistribution and modifications are permitted subject to BSD license. + */ +#ifndef ASN_RANDOM_FILL +#define ASN_RANDOM_FILL + +/* Forward declarations */ +struct asn_TYPE_descriptor_s; +struct asn_encoding_constraints_s; + +/* + * Initialize a structure with random data according to the type specification + * and optional member constraints. + * ARGUMENTS: + * (max_length) - See (approx_max_length_limit). + * (memb_constraints) - Member constraints, if exist. + * The type can be constrained differently according + * to PER and OER specifications, so we find a value + * at the intersection of these constraints. + * In case the return differs from ARFILL_OK, the (struct_ptr) contents + * and (current_length) value remain in their original state. + */ +typedef struct asn_random_fill_result_s { + enum { + ARFILL_FAILED = -1, /* System error (memory?) */ + ARFILL_OK = 0, /* Initialization succeeded */ + ARFILL_SKIPPED = 1 /* Not done due to (length?) constraint */ + } code; + size_t length; /* Approximate number of bytes created. */ +} asn_random_fill_result_t; +typedef asn_random_fill_result_t(asn_random_fill_f)( + const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + const struct asn_encoding_constraints_s *memb_constraints, + size_t max_length); + +/* + * Returns 0 if the structure was properly initialized, -1 otherwise. + * The (approx_max_length_limit) specifies the approximate limit of the + * resulting structure in units closely resembling bytes. The actual result + * might be several times larger or smaller than the length limit. + */ +int asn_random_fill(const struct asn_TYPE_descriptor_s *td, void **struct_ptr, + size_t approx_max_length_limit); + +/* + * Returns a random number between min and max. + */ +intmax_t asn_random_between(intmax_t min, intmax_t max); + +#endif /* ASN_RANDOM_FILL */