SIM-115: update simulator to use latest E2SM KPM version 3
[sim/e2-interface.git] / e2sim / asn1c / OBJECT_IDENTIFIER.h
1 /*
2  * Copyright (c) 2003-2017 Lev Walkin <vlm@lionet.info>. All rights reserved.
3  * Redistribution and modifications are permitted subject to BSD license.
4  */
5 #ifndef _OBJECT_IDENTIFIER_H_
6 #define _OBJECT_IDENTIFIER_H_
7
8 #include <asn_application.h>
9 #include <asn_codecs_prim.h>
10 #include <OCTET_STRING.h>
11
12 #ifdef __cplusplus
13 extern "C" {
14 #endif
15
16 typedef uint32_t asn_oid_arc_t;
17 #define ASN_OID_ARC_MAX (~((asn_oid_arc_t)0))
18
19 typedef ASN__PRIMITIVE_TYPE_t OBJECT_IDENTIFIER_t;
20
21 extern asn_TYPE_descriptor_t asn_DEF_OBJECT_IDENTIFIER;
22 extern asn_TYPE_operation_t asn_OP_OBJECT_IDENTIFIER;
23
24 ssize_t OBJECT_IDENTIFIER__dump_body(const OBJECT_IDENTIFIER_t *st,
25                                      asn_app_consume_bytes_f *cb,
26                                      void *app_key);
27
28 #define OBJECT_IDENTIFIER_free ASN__PRIMITIVE_TYPE_free
29
30 #if !defined(ASN_DISABLE_PRINT_SUPPORT)
31 asn_struct_print_f OBJECT_IDENTIFIER_print;
32 #endif  /* !defined(ASN_DISABLE_PRINT_SUPPORT) */
33
34 #define OBJECT_IDENTIFIER_compare OCTET_STRING_compare
35
36 asn_constr_check_f OBJECT_IDENTIFIER_constraint;
37
38 #if !defined(ASN_DISABLE_BER_SUPPORT)
39 #define OBJECT_IDENTIFIER_decode_ber ber_decode_primitive
40 #define OBJECT_IDENTIFIER_encode_der der_encode_primitive
41 #endif  /* !defined(ASN_DISABLE_BER_SUPPORT) */
42
43 #if !defined(ASN_DISABLE_XER_SUPPORT)
44 xer_type_decoder_f OBJECT_IDENTIFIER_decode_xer;
45 xer_type_encoder_f OBJECT_IDENTIFIER_encode_xer;
46 #endif  /* !defined(ASN_DISABLE_XER_SUPPORT) */
47
48 #if !defined(ASN_DISABLE_JER_SUPPORT)
49 jer_type_encoder_f OBJECT_IDENTIFIER_encode_jer;
50 #endif  /* !defined(ASN_DISABLE_JER_SUPPORT) */
51
52 #if !defined(ASN_DISABLE_OER_SUPPORT)
53 #define OBJECT_IDENTIFIER_decode_oer oer_decode_primitive
54 #define OBJECT_IDENTIFIER_encode_oer oer_encode_primitive
55 #endif  /* !defined(ASN_DISABLE_OER_SUPPORT) */
56
57 #if !defined(ASN_DISABLE_UPER_SUPPORT)
58 #define OBJECT_IDENTIFIER_decode_uper OCTET_STRING_decode_uper
59 #define OBJECT_IDENTIFIER_encode_uper OCTET_STRING_encode_uper
60 #endif  /* !defined(ASN_DISABLE_UPER_SUPPORT) */
61 #if !defined(ASN_DISABLE_APER_SUPPORT)
62 #define OBJECT_IDENTIFIER_decode_aper OCTET_STRING_decode_aper
63 #define OBJECT_IDENTIFIER_encode_aper OCTET_STRING_encode_aper
64 #endif  /* !defined(ASN_DISABLE_APER_SUPPORT) */
65
66 #if !defined(ASN_DISABLE_RFILL_SUPPORT)
67 asn_random_fill_f  OBJECT_IDENTIFIER_random_fill;
68 #endif  /* !defined(ASN_DISABLE_RFILL_SUPPORT) */
69
70 /**********************************
71  * Some handy conversion routines *
72  **********************************/
73
74 /*
75  * This function fills an (arcs) array with OBJECT IDENTIFIER arcs
76  * up to specified (arc_slots) elements.
77  *
78  * EXAMPLE:
79  *      void print_arcs(OBJECT_IDENTIFIER_t *oid) {
80  *              asn_oid_arc_t fixed_arcs[10];   // Try with fixed space first
81  *              asn_oid_arc_t *arcs = fixed_arcs;
82  *              size_t arc_slots = sizeof(fixed_arcs)/sizeof(fixed_arcs[0]); // 10
83  *              ssize_t count;  // Real number of arcs.
84  *              int i;
85  *
86  *              count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);
87  *              // If necessary, reallocate arcs array and try again.
88  *              if(count > arc_slots) {
89  *                      arc_slots = count;
90  *                      arcs = malloc(sizeof(asn_oid_arc_t) * arc_slots);
91  *                      if(!arcs) return;
92  *                      count = OBJECT_IDENTIFIER_get_arcs(oid, arcs, arc_slots);
93  *                      assert(count == arc_slots);
94  *              }
95  *
96  *              // Print the contents of the arcs array.
97  *              for(i = 0; i < count; i++)
98  *                      printf("%"PRIu32"\n", arcs[i]);
99  *
100  *              // Avoid memory leak.
101  *              if(arcs != fixed_arcs) free(arcs);
102  *      }
103  *
104  * RETURN VALUES:
105  * -1/EINVAL:   Invalid arguments (oid is missing)
106  * -1/ERANGE:   One or more arcs have value out of array cell type range.
107  * >=0:         Number of arcs contained in the OBJECT IDENTIFIER
108  *
109  * WARNING: The function always returns the actual number of arcs,
110  * even if there is no sufficient (arc_slots) provided.
111  */
112 ssize_t OBJECT_IDENTIFIER_get_arcs(const OBJECT_IDENTIFIER_t *oid,
113                                    asn_oid_arc_t *arcs, size_t arc_slots);
114
115 /*
116  * This functions initializes the OBJECT IDENTIFIER object with
117  * the given set of arcs.
118  * The minimum of two arcs must be present; some restrictions apply.
119  * RETURN VALUES:
120  * -1/EINVAL:   Invalid arguments
121  * -1/ERANGE:   The first two arcs do not conform to ASN.1 restrictions.
122  * -1/ENOMEM:   Memory allocation failed
123  * 0:           The object was initialized with new arcs.
124  */
125 int OBJECT_IDENTIFIER_set_arcs(OBJECT_IDENTIFIER_t *oid,
126                                const asn_oid_arc_t *arcs, size_t arcs_count);
127
128
129 /*
130  * Parse the OBJECT IDENTIFIER textual representation ("1.3.6.1.4.1.9363").
131  * No arc can exceed the (0..ASN_OID_ARC_MAX, which is the same as UINT32_MAX).
132  * This function is not specific to OBJECT IDENTIFIER, it may be used to parse
133  * the RELATIVE-OID data, or any other data consisting of dot-separated
134  * series of numeric values.
135  *
136  * If (oid_txt_length == -1), the strlen() will be invoked to determine the
137  * size of the (oid_text) string.
138  * 
139  * After return, the optional (opt_oid_text_end) is set to the character after
140  * the last parsed one. (opt_oid_text_end) is never less than (oid_text).
141  * 
142  * RETURN VALUES:
143  *   -1:        Parse error.
144  * >= 0:        Number of arcs contained in the OBJECT IDENTIFIER.
145  * 
146  * WARNING: The function always returns the real number of arcs,
147  * even if there is no sufficient (arc_slots) provided.
148  * This is useful for (arc_slots) value estimation.
149  */
150 ssize_t OBJECT_IDENTIFIER_parse_arcs(const char *oid_text,
151                                      ssize_t oid_txt_length,
152                                      asn_oid_arc_t *arcs, size_t arcs_count,
153                                      const char **opt_oid_text_end);
154
155 /*
156  * Internal functions.
157  * Used by RELATIVE-OID implementation in particular.
158  */
159
160 /*
161  * Retrieve a single arc of size from the (arcbuf) buffer.
162  * RETURN VALUES:
163  *  -1: Failed to retrieve the value from the (arcbuf).
164  *  >0: Number of bytes consumed from the (arcbuf), <= (arcbuf_len).
165  */
166 ssize_t OBJECT_IDENTIFIER_get_single_arc(const uint8_t *arcbuf,
167                                          size_t arcbuf_len,
168                                          asn_oid_arc_t *ret_value);
169
170 /*
171  * Write the unterminated arc value into the (arcbuf) which has the size at
172  * least (arcbuf_len).
173  * RETURN VALUES:
174  *   -1: (arcbuf_len) size is not sufficient to write the value.
175  *  <n>: Number of bytes appended to the arcbuf (<= arcbuf_len).
176  */
177 ssize_t OBJECT_IDENTIFIER_set_single_arc(uint8_t *arcbuf, size_t arcbuf_len,
178                                          asn_oid_arc_t arc_value);
179
180 #ifdef __cplusplus
181 }
182 #endif
183
184 #endif  /* _OBJECT_IDENTIFIER_H_ */