2 * Object IDentifier Support
4 * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
16 #include <epan/ftypes/ftypes.h>
17 #include <epan/prefs.h>
18 #include <epan/wmem_scopes.h>
19 #include "ws_symbol_export.h"
23 #endif /* __cplusplus */
28 #define BER_TAG_ANY -1
35 typedef struct _oid_bits_info_t
{
38 struct _oid_bit_t
* data
;
41 typedef enum _oid_key_type_t
{
49 OID_KEY_TYPE_IMPLIED_OID
,
50 OID_KEY_TYPE_IMPLIED_STRING
,
51 OID_KEY_TYPE_IMPLIED_BYTES
,
53 OID_KEY_TYPE_DATE_AND_TIME
56 typedef struct _oid_value_type_t
{
63 oid_key_type_t keytype
;
67 typedef enum _oid_kind_t
{
74 OID_KIND_NOTIFICATION
,
80 typedef struct _oid_key_t
{
83 oid_key_type_t key_type
;
87 struct _oid_key_t
* next
;
90 typedef struct _oid_info_t
{
94 wmem_tree_t
* children
;
95 const oid_value_type_t
* value_type
;
98 oid_bits_info_t
* bits
;
99 struct _oid_info_t
* parent
;
102 /** init function called from prefs.c */
103 WS_DLL_PUBLIC
void oids_init(void);
104 extern void oid_pref_init(module_t
*nameres
);
106 /** init function called from epan.h */
107 WS_DLL_PUBLIC
void oids_cleanup(void);
110 * The objects returned by all these functions are all allocated with a
111 * packet lifetime and do not have to be freed.
112 * However, take into account that when the packet dissection
113 * completes, these buffers will be automatically reclaimed/freed.
114 * If you need the buffer to remain for a longer scope than packet lifetime
115 * you must copy the content to an wmem_file_scope() buffer.
119 * These functions convert through the various formats:
120 * string: is like "0.1.3.4.5.30" (not resolved)
121 * encoded: is BER encoded (as per X.690 section 8.19)
122 * subids: is an array of uint32_t
125 /* return length of encoded buffer */
127 unsigned oid_subid2encoded(wmem_allocator_t
*scope
, unsigned len
, uint32_t* subids
, uint8_t** encoded_p
);
129 unsigned oid_string2encoded(wmem_allocator_t
*scope
, const char *oid_str
, uint8_t** encoded_p
);
131 /* return length of subid array */
133 unsigned oid_encoded2subid(wmem_allocator_t
*scope
, const uint8_t *oid
, int len
, uint32_t** subids_p
);
135 unsigned oid_encoded2subid_sub(wmem_allocator_t
*scope
, const uint8_t *oid_bytes
, int oid_len
, uint32_t** subids_pi
,
138 unsigned oid_string2subid(wmem_allocator_t
*scope
, const char *oid_str
, uint32_t** subids_p
);
140 WS_DLL_PUBLIC
char* oid_encoded2string(wmem_allocator_t
*scope
, const uint8_t* encoded
, unsigned len
);
141 WS_DLL_PUBLIC
char* rel_oid_encoded2string(wmem_allocator_t
*scope
, const uint8_t* encoded
, unsigned len
);
142 WS_DLL_PUBLIC
char* oid_subid2string(wmem_allocator_t
*scope
, uint32_t *subids
, unsigned len
);
143 WS_DLL_PUBLIC
char* rel_oid_subid2string(wmem_allocator_t
*scope
, uint32_t *subids
, unsigned len
, bool is_absolute
);
145 /* these return a formated string as human readable as possible */
146 WS_DLL_PUBLIC
char *oid_resolved(wmem_allocator_t
*scope
, unsigned len
, uint32_t *subids
);
147 WS_DLL_PUBLIC
char *oid_resolved_from_encoded(wmem_allocator_t
*scope
, const uint8_t *oid
, int len
);
148 WS_DLL_PUBLIC
char *rel_oid_resolved_from_encoded(wmem_allocator_t
*scope
, const uint8_t *oid
, int len
);
149 WS_DLL_PUBLIC
char *oid_resolved_from_string(wmem_allocator_t
*scope
, const char *oid_str
);
151 /* these yield two formated strings one resolved and one numeric */
152 WS_DLL_PUBLIC
void oid_both(wmem_allocator_t
*scope
, unsigned oid_len
, uint32_t *subids
, char** resolved_p
, char** numeric_p
);
153 WS_DLL_PUBLIC
void oid_both_from_encoded(wmem_allocator_t
*scope
, const uint8_t *oid
, int oid_len
, char** resolved_p
, char** numeric_p
);
154 WS_DLL_PUBLIC
void oid_both_from_string(wmem_allocator_t
*scope
, const char *oid_str
, char** resolved_p
, char** numeric_p
);
157 * These return the info for the best match.
158 * *matched_p will be set to the number of nodes used by the returned oid
159 * *left_p will be set to the number of remaining unresolved subids
161 WS_DLL_PUBLIC oid_info_t
* oid_get(unsigned oid_len
, uint32_t *subids
, unsigned* matched_p
, unsigned* left_p
);
162 WS_DLL_PUBLIC oid_info_t
* oid_get_from_encoded(wmem_allocator_t
*scope
, const uint8_t *oid
, int oid_len
, uint32_t **subids
, unsigned* matched
, unsigned* left
);
163 WS_DLL_PUBLIC oid_info_t
* oid_get_from_string(wmem_allocator_t
*scope
, const char *oid_str
, uint32_t **subids
, unsigned* matched
, unsigned* left
);
165 /* these are used to add oids to the collection */
166 WS_DLL_PUBLIC
void oid_add(const char* name
, unsigned oid_len
, uint32_t *subids
);
167 WS_DLL_PUBLIC
void oid_add_from_encoded(const char* name
, const uint8_t *oid
, int oid_len
);
168 WS_DLL_PUBLIC
void oid_add_from_string(const char* name
, const char *oid_str
);
171 * Fetch the default MIB/PIB path
173 * @return A string containing the default MIB/PIB path. It must be
174 * g_free()d by the caller.
176 WS_DLL_PUBLIC
char *oid_get_default_mib_path(void);
178 /* macros for legacy oid functions */
179 #define subid_t uint32_t
184 extern char* oid_test_a2b(uint32_t num_subids
, uint32_t* subids
);
185 extern void add_oid_debug_subtree(oid_info_t
* oid_info
, proto_tree
*tree
);
187 #define add_oid_debug_subtree(a,b) ((void)0)
192 #endif /* __cplusplus */
194 #endif /* __OIDS_H__ */
202 * indent-tabs-mode: nil
205 * ex: set shiftwidth=4 tabstop=8 expandtab:
206 * :indentSize=4:tabSize=8:noTabs=true: