Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 1 | /* |
Lev Walkin | 6c52784 | 2014-02-09 04:34:54 -0800 | [diff] [blame] | 2 | * Copyright (c) 2005-2014 Lev Walkin <vlm@lionet.info>. |
Lev Walkin | 9218bc1 | 2007-06-27 04:09:37 +0000 | [diff] [blame] | 3 | * All rights reserved. |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 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 */ |
Lev Walkin | 6cd0d56 | 2017-08-25 11:57:01 -0700 | [diff] [blame] | 10 | #include <asn_bit_data.h> |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 11 | |
| 12 | #ifdef __cplusplus |
| 13 | extern "C" { |
| 14 | #endif |
| 15 | |
| 16 | /* |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 17 | * Pre-computed PER constraints. |
| 18 | */ |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 19 | typedef struct asn_per_constraint_s { |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 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; |
Lev Walkin | 494fb70 | 2017-08-07 20:07:00 -0700 | [diff] [blame] | 31 | typedef struct asn_per_constraints_s { |
| 32 | asn_per_constraint_t value; |
| 33 | asn_per_constraint_t size; |
Lev Walkin | 725883b | 2006-10-09 12:07:58 +0000 | [diff] [blame] | 34 | int (*value2code)(unsigned int value); |
| 35 | int (*code2value)(unsigned int code); |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 36 | } asn_per_constraints_t; |
| 37 | |
Lev Walkin | 6cd0d56 | 2017-08-25 11:57:01 -0700 | [diff] [blame] | 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) |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 44 | |
| 45 | /* |
Lev Walkin | 9d1b45f | 2017-10-01 17:04:48 -0700 | [diff] [blame] | 46 | * X.691 (08/2015) #11.9 "General rules for encoding a length determinant" |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 47 | * Get the length "n" from the Unaligned PER stream. |
| 48 | */ |
Lev Walkin | 9d1b45f | 2017-10-01 17:04:48 -0700 | [diff] [blame] | 49 | ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits, |
| 50 | size_t lower_bound, int *repeat); |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 51 | |
| 52 | /* |
Lev Walkin | 5b78e1c | 2007-06-24 06:26:47 +0000 | [diff] [blame] | 53 | * Get the normally small length "n". |
| 54 | */ |
| 55 | ssize_t uper_get_nslength(asn_per_data_t *pd); |
| 56 | |
| 57 | /* |
Lev Walkin | c46b7cb | 2006-08-18 02:27:55 +0000 | [diff] [blame] | 58 | * Get the normally small non-negative whole number. |
| 59 | */ |
| 60 | ssize_t uper_get_nsnnwn(asn_per_data_t *pd); |
| 61 | |
Lev Walkin | 6c52784 | 2014-02-09 04:34:54 -0800 | [diff] [blame] | 62 | /* X.691-2008/11, #11.5.6 */ |
| 63 | int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *v, int nbits); |
| 64 | |
Lev Walkin | 11944f1 | 2007-06-29 02:28:10 +0000 | [diff] [blame] | 65 | |
Lev Walkin | 6cd0d56 | 2017-08-25 11:57:01 -0700 | [diff] [blame] | 66 | /* Temporary compatibility layer. Will get removed. */ |
| 67 | typedef struct asn_bit_outp_s asn_per_outp_t; |
| 68 | #define per_put_few_bits(out, bits, obits) asn_put_few_bits(out, bits, obits) |
| 69 | #define per_put_many_bits(out, src, nbits) asn_put_many_bits(out, src, nbits) |
| 70 | #define per_put_aligned_flush(out) asn_put_aligned_flush(out) |
Lev Walkin | 3fd85d8 | 2017-07-24 00:30:06 +0400 | [diff] [blame] | 71 | |
Lev Walkin | 6c52784 | 2014-02-09 04:34:54 -0800 | [diff] [blame] | 72 | /* X.691-2008/11, #11.5 */ |
| 73 | int uper_put_constrained_whole_number_s(asn_per_outp_t *po, long v, int nbits); |
| 74 | int uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, int nbits); |
| 75 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 76 | /* |
Lev Walkin | 9d1b45f | 2017-10-01 17:04:48 -0700 | [diff] [blame] | 77 | * X.691 (08/2015) #11.9 "General rules for encoding a length determinant" |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 78 | * Put the length "n" to the Unaligned PER stream. |
| 79 | * This function returns the number of units which may be flushed |
| 80 | * in the next units saving iteration. |
| 81 | */ |
| 82 | ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length); |
| 83 | |
| 84 | /* |
Lev Walkin | 62258e2 | 2007-06-23 23:50:25 +0000 | [diff] [blame] | 85 | * Put the normally small length "n" to the Unaligned PER stream. |
| 86 | * Returns 0 or -1. |
| 87 | */ |
| 88 | int uper_put_nslength(asn_per_outp_t *po, size_t length); |
| 89 | |
| 90 | /* |
Lev Walkin | 523de9e | 2006-08-18 01:34:18 +0000 | [diff] [blame] | 91 | * Put the normally small non-negative whole number. |
| 92 | */ |
| 93 | int uper_put_nsnnwn(asn_per_outp_t *po, int n); |
| 94 | |
Lev Walkin | 59b176e | 2005-11-26 11:25:14 +0000 | [diff] [blame] | 95 | #ifdef __cplusplus |
| 96 | } |
| 97 | #endif |
| 98 | |
| 99 | #endif /* _PER_SUPPORT_H_ */ |