]> git.stg.codes - stg.git/blobdiff - 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
index 420bb83c58d081ba3949951b67709e3200e7192a..3e905a8b971babae81e9afc3b8dd728f68b36d05 100644 (file)
@@ -1,11 +1,12 @@
 /*
- * Copyright (c) 2005, 2006 Lev Walkin <vlm@lionet.info>. All rights reserved.
+ * Copyright (c) 2005-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
  * Redistribution and modifications are permitted subject to BSD license.
  */
 #ifndef        _PER_SUPPORT_H_
 #define        _PER_SUPPORT_H_
 
 #include <asn_system.h>                /* Platform-specific types */
+#include <asn_bit_data.h>
 
 #ifdef __cplusplus
 extern "C" {
@@ -29,69 +30,75 @@ typedef struct asn_per_constraint_s {
 typedef struct asn_per_constraints_s {
        asn_per_constraint_t value;
        asn_per_constraint_t size;
+       int (*value2code)(unsigned int value);
+       int (*code2value)(unsigned int code);
 } asn_per_constraints_t;
 
-/*
- * This structure describes a position inside an incoming PER bit stream.
- */
-typedef struct asn_per_data_s {
- const uint8_t *buffer;        /* Pointer to the octet stream */
-        size_t  nboff; /* Bit offset to the meaningful bit */
-        size_t  nbits; /* Number of bits in the stream */
-} asn_per_data_t;
-
-/*
- * Extract a small number of bits (<= 31) from the specified PER data pointer.
- * This function returns -1 if the specified number of bits could not be
- * extracted due to EOD or other conditions.
- */
-int32_t per_get_few_bits(asn_per_data_t *per_data, int get_nbits);
+/* Temporary compatibility layer. Will get removed. */
+typedef struct asn_bit_data_s asn_per_data_t;
+#define per_get_few_bits(data, bits)   asn_get_few_bits(data, bits)
+#define per_get_undo(data, bits)   asn_get_undo(data, bits)
+#define per_get_many_bits(data, dst, align, bits) \
+    asn_get_many_bits(data, dst, align, bits)
 
 /*
- * Extract a large number of bits from the specified PER data pointer.
- * This function returns -1 if the specified number of bits could not be
- * extracted due to EOD or other conditions.
+ * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
+ * Get the length "n" from the Unaligned PER stream.
  */
-int per_get_many_bits(asn_per_data_t *pd, uint8_t *dst, int right_align,
-                       int get_nbits);
+ssize_t uper_get_length(asn_per_data_t *pd, int effective_bound_bits,
+                        size_t lower_bound, int *repeat);
 
 /*
- * Get the length "n" from the Unaligned PER stream.
+ * Get the normally small length "n".
  */
-ssize_t uper_get_length(asn_per_data_t *pd,
-                       int effective_bound_bits,
-                       int *repeat);
+ssize_t uper_get_nslength(asn_per_data_t *pd);
 
 /*
  * Get the normally small non-negative whole number.
  */
 ssize_t uper_get_nsnnwn(asn_per_data_t *pd);
 
+/* X.691-2008/11, #11.5.6 */
+int uper_get_constrained_whole_number(asn_per_data_t *pd, unsigned long *v, int nbits);
+
+
+/* Temporary compatibility layer. Will get removed. */
+typedef struct asn_bit_outp_s asn_per_outp_t;
+#define per_put_few_bits(out, bits, obits) asn_put_few_bits(out, bits, obits)
+#define per_put_many_bits(out, src, nbits) asn_put_many_bits(out, src, nbits)
+#define per_put_aligned_flush(out) asn_put_aligned_flush(out)
+
+
 /*
- * This structure supports forming PER output.
+ * Rebase the given value as an offset into the range specified by the
+ * lower bound (lb) and upper bound (ub).
+ * RETURN VALUES:
+ *  -1: Conversion failed due to range problems.
+ *   0: Conversion was successful.
  */
-typedef struct asn_per_outp_s {
-       uint8_t *buffer;        /* Pointer into the (tmpspace) */
-       size_t nboff;           /* Bit offset to the meaningful bit */
-       size_t nbits;           /* Number of bits left in (tmpspace) */
-       uint8_t tmpspace[32];   /* Preliminary storage to hold data */
-       int (*outper)(const void *data, size_t size, void *op_key);
-       void *op_key;           /* Key for (outper) data callback */
-       size_t flushed_bytes;   /* Bytes already flushed through (outper) */
-} asn_per_outp_t;
-
-/* Output a small number of bits (<= 31) */
-int per_put_few_bits(asn_per_outp_t *per_data, uint32_t bits, int obits);
-
-/* Output a large number of bits */
-int per_put_many_bits(asn_per_outp_t *po, const uint8_t *src, int put_nbits);
+int per_long_range_rebase(long v, long lb, long ub, unsigned long *output);
+/* The inverse operation: restores the value by the offset and its bounds. */
+int per_long_range_unrebase(unsigned long inp, long lb, long ub, long *outp);
+
+/* X.691-2008/11, #11.5 */
+int uper_put_constrained_whole_number_u(asn_per_outp_t *po, unsigned long v, int nbits);
 
 /*
- * Put the length "n" to the Unaligned PER stream.
+ * X.691 (08/2015) #11.9 "General rules for encoding a length determinant"
+ * Put the length "whole_length" to the Unaligned PER stream.
+ * If (opt_need_eom) is given, it will be set to 1 if final 0-length is needed.
+ * In that case, invoke uper_put_length(po, 0, 0) after encoding the last block.
  * This function returns the number of units which may be flushed
  * in the next units saving iteration.
  */
-ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length);
+ssize_t uper_put_length(asn_per_outp_t *po, size_t whole_length,
+                        int *opt_need_eom);
+
+/*
+ * Put the normally small length "n" to the Unaligned PER stream.
+ * Returns 0 or -1.
+ */
+int uper_put_nslength(asn_per_outp_t *po, size_t length);
 
 /*
  * Put the normally small non-negative whole number.