blob: 420bb83c58d081ba3949951b67709e3200e7192a [file] [log] [blame]
Harald Welte92c45f32010-06-12 18:59:38 +02001/*
2 * Copyright (c) 2005, 2006 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
10#ifdef __cplusplus
11extern "C" {
12#endif
13
14/*
15 * Pre-computed PER constraints.
16 */
17typedef struct asn_per_constraint_s {
18 enum asn_per_constraint_flags {
19 APC_UNCONSTRAINED = 0x0, /* No PER visible constraints */
20 APC_SEMI_CONSTRAINED = 0x1, /* Constrained at "lb" */
21 APC_CONSTRAINED = 0x2, /* Fully constrained */
22 APC_EXTENSIBLE = 0x4 /* May have extension */
23 } flags;
24 int range_bits; /* Full number of bits in the range */
25 int effective_bits; /* Effective bits */
26 long lower_bound; /* "lb" value */
27 long upper_bound; /* "ub" value */
28} asn_per_constraint_t;
29typedef struct asn_per_constraints_s {
30 asn_per_constraint_t value;
31 asn_per_constraint_t size;
32} asn_per_constraints_t;
33
34/*
35 * This structure describes a position inside an incoming PER bit stream.
36 */
37typedef struct asn_per_data_s {
38 const uint8_t *buffer; /* Pointer to the octet stream */
39 size_t nboff; /* Bit offset to the meaningful bit */
40 size_t nbits; /* Number of bits in the stream */
41} asn_per_data_t;
42
43/*
44 * Extract a small number of bits (<= 31) from the specified PER data pointer.
45 * This function returns -1 if the specified number of bits could not be
46 * extracted due to EOD or other conditions.
47 */
48int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits);
49
50/*
51 * Extract a large number of bits from the specified PER data pointer.
52 * This function returns -1 if the specified number of bits could not be
53 * extracted due to EOD or other conditions.
54 */
55int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align,
56 int get_nbits);
57
58/*
59 * Get the length "n" from the Unaligned PER stream.
60 */
61ssize_t uper_get_length(asn_per_data_t *pd,
62 int effective_bound_bits,
63 int *repeat);
64
65/*
66 * Get the normally small non-negative whole number.
67 */
68ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
69
70/*
71 * This structure supports forming PER output.
72 */
73typedef struct asn_per_outp_s {
74 uint8_t *buffer; /* Pointer into the (tmpspace) */
75 size_t nboff; /* Bit offset to the meaningful bit */
76 size_t nbits; /* Number of bits left in (tmpspace) */
77 uint8_t tmpspace[32]; /* Preliminary storage to hold data */
78 int (*outper)(const void *data, size_t size, void *op_key);
79 void *op_key; /* Key for (outper) data callback */
80 size_t flushed_bytes; /* Bytes already flushed through (outper) */
81} asn_per_outp_t;
82
83/* Output a small number of bits (<= 31) */
84int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits);
85
86/* Output a large number of bits */
87int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits);
88
89/*
90 * Put the length "n" to the Unaligned PER stream.
91 * This function returns the number of units which may be flushed
92 * in the next units saving iteration.
93 */
94ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length);
95
96/*
97 * Put the normally small non-negative whole number.
98 */
99int uper_put_nsnnwn(asn_per_outp_t *po, int n);
100
101#ifdef __cplusplus
102}
103#endif
104
105#endif /* _PER_SUPPORT_H_ */