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