SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / uper_support.h
1 /*
2  * Copyright (c) 2005-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 #ifndef _UPER_SUPPORT_H_
6 #define _UPER_SUPPORT_H_
7
8 #include <asn_system.h>         /* Platform-specific types */
9 #include <per_support.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 /*
16  * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
17  * Get the length "n" from the Unaligned PER stream.
18  */
19 ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits,
20                         size_t lower_bound, int *repeat);
21
22 /*
23  * Get the normally small length "n".
24  */
25 ssize_t uper_get_nslength(asn_per_data_t *pd);
26
27 /*
28  * Get the normally small non-negative whole number.
29  */
30 ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
31
32 /* X.691-2008/11, #11.5.6 */
33 int uper_get_constrained_whole_number(asn_per_data_t *pd, uintmax_t *v, int nbits);
34
35 /*
36  * Rebase the given value as an offset into the range specified by the
37  * lower bound (lb) and upper bound (ub).
38  * RETURN VALUES:
39  *  -1: Conversion failed due to range problems.
40  *   0: Conversion was successful.
41  */
42 int per_long_range_rebase(long, intmax_t lb, intmax_t ub, unsigned long *output);
43 int per_imax_range_rebase(intmax_t v, intmax_t lb, intmax_t ub, uintmax_t *output);
44 /* The inverse operation: restores the value by the offset and its bounds. */
45 int per_long_range_unrebase(unsigned long inp, intmax_t lb, intmax_t ub, long *outp);
46 int per_imax_range_unrebase(uintmax_t inp, intmax_t lb, intmax_t ub, intmax_t *outp);
47
48 /* X.691-2008/11, #11.5 */
49 int uper_put_constrained_whole_number_u(asn_per_outp_t *po, uintmax_t v, int nbits);
50
51 /*
52  * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
53  * Put the length "whole_length" to the Unaligned PER stream.
54  * If (opt_need_eom) is given, it will be set to 1 if final 0-length is needed.
55  * In that case, invoke uper_put_length(po, 0, 0) after encoding the last block.
56  * This function returns the number of units which may be flushed
57  * in the next units saving iteration.
58  */
59 ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length,
60                         int *opt_need_eom);
61
62 /*
63  * Put the normally small length "n" to the Unaligned PER stream.
64  * Returns 0 or -1.
65  */
66 int uper_put_nslength(asn_per_outp_t *po, size_t length);
67
68 /*
69  * Put the normally small non-negative whole number.
70  */
71 int uper_put_nsnnwn(asn_per_outp_t *po, int n);
72
73 #ifdef __cplusplus
74 }
75 #endif
76
77 #endif  /* _UPER_SUPPORT_H_ */