Change version after creation of r2 branch
[ric-plt/resource-status-manager.git] / RSM / asn1codec / e2ap_engine / per_support.h
1
2 /*
3  * Copyright (c) 2005-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
4  * Redistribution and modifications are permitted subject to BSD license.
5  */
6 #ifndef _PER_SUPPORT_H_
7 #define _PER_SUPPORT_H_
8
9 #include <asn_system.h>         /* Platform-specific types */
10 #include <asn_bit_data.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 /*
17  * Pre-computed PER constraints.
18  */
19 typedef struct asn_per_constraint_s {
20         enum asn_per_constraint_flags {
21                 APC_UNCONSTRAINED       = 0x0,  /* No PER visible constraints */
22                 APC_SEMI_CONSTRAINED    = 0x1,  /* Constrained at "lb" */
23                 APC_CONSTRAINED         = 0x2,  /* Fully constrained */
24                 APC_EXTENSIBLE          = 0x4   /* May have extension */
25         } flags;
26         int  range_bits;                /* Full number of bits in the range */
27         int  effective_bits;            /* Effective bits */
28         long lower_bound;               /* "lb" value */
29         long upper_bound;               /* "ub" value */
30 } asn_per_constraint_t;
31 typedef struct asn_per_constraints_s {
32         asn_per_constraint_t value;
33         asn_per_constraint_t size;
34         int (*value2code)(unsigned int value);
35         int (*code2value)(unsigned int code);
36 } asn_per_constraints_t;
37
38 /* Temporary compatibility layer. Will get removed. */
39 typedef struct asn_bit_data_s asn_per_data_t;
40 #define per_get_few_bits(data, bits)   asn_get_few_bits(data, bits)
41 #define per_get_undo(data, bits)   asn_get_undo(data, bits)
42 #define per_get_many_bits(data, dst, align, bits) \
43     asn_get_many_bits(data, dst, align, bits)
44
45 /*
46  * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
47  * Get the length "n" from the Unaligned PER stream.
48  */
49 ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits,
50                         size_t lower_bound, int *repeat);
51
52 ssize_t aper_get_length(asn_per_data_t *pd, int range,
53                         int effective_bound_bits, int *repeat);
54
55 /*
56  * Get the normally small length "n".
57  */
58 ssize_t uper_get_nslength(asn_per_data_t *pd);
59 ssize_t aper_get_nslength(asn_per_data_t *pd);
60
61 /*
62  * Get the normally small non-negative whole number.
63  */
64 ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
65 ssize_t aper_get_nsnnwn(asn_per_data_t *pd, int range);
66
67 /* X.691-2008/11, #11.5.6 */
68 int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *v, int nbits);
69
70
71 /* Temporary compatibility layer. Will get removed. */
72 typedef struct asn_bit_outp_s asn_per_outp_t;
73 #define per_put_few_bits(out, bits, obits) asn_put_few_bits(out, bits, obits)
74 #define per_put_many_bits(out, src, nbits) asn_put_many_bits(out, src, nbits)
75 #define per_put_aligned_flush(out) asn_put_aligned_flush(out)
76
77
78 /*
79  * Rebase the given value as an offset into the range specified by the
80  * lower bound (lb) and upper bound (ub).
81  * RETURN VALUES:
82  *  -1: Conversion failed due to range problems.
83  *   0: Conversion was successful.
84  */
85 int per_long_range_rebase(long v, long lb, long ub, unsigned long *output);
86 /* The inverse operation: restores the value by the offset and its bounds. */
87 int per_long_range_unrebase(unsigned long inp, long lb, long ub, long *outp);
88
89 /* X.691-2008/11, #11.5 */
90 int uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, int nbits);
91
92 /*
93  * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
94  * Put the length "whole_length" to the Unaligned PER stream.
95  * If (opt_need_eom) is given, it will be set to 1 if final 0-length is needed.
96  * In that case, invoke uper_put_length(po, 0, 0) after encoding the last block.
97  * This function returns the number of units which may be flushed
98  * in the next units saving iteration.
99  */
100 ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length,
101                         int *opt_need_eom);
102
103 ssize_t aper_put_length(asn_per_outp_t *po, int range, size_t length);
104
105 /* Align the current bit position to octet bundary */
106 int aper_put_align(asn_per_outp_t *po);
107 int32_t aper_get_align(asn_per_data_t *pd);
108
109 /*
110  * Put the normally small length "n" to the Unaligned PER stream.
111  * Returns 0 or -1.
112  */
113 int uper_put_nslength(asn_per_outp_t *po, size_t length);
114
115 int aper_put_nslength(asn_per_outp_t *po, size_t length);
116
117 /*
118  * Put the normally small non-negative whole number.
119  */
120 int uper_put_nsnnwn(asn_per_outp_t *po, int n);
121
122 int aper_put_nsnnwn(asn_per_outp_t *po, int range, int number);
123
124 #ifdef __cplusplus
125 }
126 #endif
127
128 #endif  /* _PER_SUPPORT_H_ */