]> git.stg.codes - stg.git/blob - libs/smux/include/stg/per_support.h
Regen SMUX support library with more recent ASN1 compiler.
[stg.git] / libs / smux / include / stg / per_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 _PER_SUPPORT_H_
6 #define _PER_SUPPORT_H_
7
8 #include <asn_system.h>         /* Platform-specific types */
9 #include <asn_bit_data.h>
10
11 #ifdef __cplusplus
12 extern "C" {
13 #endif
14
15 /*
16  * Pre-computed PER constraints.
17  */
18 typedef struct asn_per_constraint_s {
19         enum asn_per_constraint_flags {
20                 APC_UNCONSTRAINED       = 0x0,  /* No PER visible constraints */
21                 APC_SEMI_CONSTRAINED    = 0x1,  /* Constrained at "lb" */
22                 APC_CONSTRAINED         = 0x2,  /* Fully constrained */
23                 APC_EXTENSIBLE          = 0x4   /* May have extension */
24         } flags;
25         int  range_bits;                /* Full number of bits in the range */
26         int  effective_bits;            /* Effective bits */
27         long lower_bound;               /* "lb" value */
28         long upper_bound;               /* "ub" value */
29 } asn_per_constraint_t;
30 typedef struct asn_per_constraints_s {
31         asn_per_constraint_t value;
32         asn_per_constraint_t size;
33         int (*value2code)(unsigned int value);
34         int (*code2value)(unsigned int code);
35 } asn_per_constraints_t;
36
37 /* Temporary compatibility layer. Will get removed. */
38 typedef struct asn_bit_data_s asn_per_data_t;
39 #define per_get_few_bits(data, bits)   asn_get_few_bits(data, bits)
40 #define per_get_undo(data, bits)   asn_get_undo(data, bits)
41 #define per_get_many_bits(data, dst, align, bits) \
42     asn_get_many_bits(data, dst, align, bits)
43
44 /*
45  * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
46  * Get the length "n" from the Unaligned PER stream.
47  */
48 ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits,
49                         size_t lower_bound, int *repeat);
50
51 /*
52  * Get the normally small length "n".
53  */
54 ssize_t uper_get_nslength(asn_per_data_t *pd);
55
56 /*
57  * Get the normally small non-negative whole number.
58  */
59 ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
60
61 /* X.691-2008/11, #11.5.6 */
62 int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *v, int nbits);
63
64
65 /* Temporary compatibility layer. Will get removed. */
66 typedef struct asn_bit_outp_s asn_per_outp_t;
67 #define per_put_few_bits(out, bits, obits) asn_put_few_bits(out, bits, obits)
68 #define per_put_many_bits(out, src, nbits) asn_put_many_bits(out, src, nbits)
69 #define per_put_aligned_flush(out) asn_put_aligned_flush(out)
70
71
72 /*
73  * Rebase the given value as an offset into the range specified by the
74  * lower bound (lb) and upper bound (ub).
75  * RETURN VALUES:
76  *  -1: Conversion failed due to range problems.
77  *   0: Conversion was successful.
78  */
79 int per_long_range_rebase(long v, long lb, long ub, unsigned long *output);
80 /* The inverse operation: restores the value by the offset and its bounds. */
81 int per_long_range_unrebase(unsigned long inp, long lb, long ub, long *outp);
82
83 /* X.691-2008/11, #11.5 */
84 int uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, int nbits);
85
86 /*
87  * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
88  * Put the length "whole_length" to the Unaligned PER stream.
89  * If (opt_need_eom) is given, it will be set to 1 if final 0-length is needed.
90  * In that case, invoke uper_put_length(po, 0, 0) after encoding the last block.
91  * This function returns the number of units which may be flushed
92  * in the next units saving iteration.
93  */
94 ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length,
95                         int *opt_need_eom);
96
97 /*
98  * Put the normally small length "n" to the Unaligned PER stream.
99  * Returns 0 or -1.
100  */
101 int uper_put_nslength(asn_per_outp_t *po, size_t length);
102
103 /*
104  * Put the normally small non-negative whole number.
105  */
106 int uper_put_nsnnwn(asn_per_outp_t *po, int n);
107
108 #ifdef __cplusplus
109 }
110 #endif
111
112 #endif  /* _PER_SUPPORT_H_ */