Wireshark  4.3.0
The Wireshark network protocol analyzer
oids.h
Go to the documentation of this file.
1 /* oids.h
2  * Object IDentifier Support
3  *
4  * (c) 2007, Luis E. Garcia Ontanon <luis@ontanon.org>
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12 
13 #ifndef __OIDS_H__
14 #define __OIDS_H__
15 
16 #include <epan/ftypes/ftypes.h>
17 #include <epan/prefs.h>
18 #include <epan/wmem_scopes.h>
19 #include "ws_symbol_export.h"
20 
21 #ifdef __cplusplus
22 extern "C" {
23 #endif /* __cplusplus */
24 
28 #define BER_TAG_ANY -1
29 
30 struct _oid_bit_t {
31  guint offset;
32  int hfid;
33 };
34 
35 typedef struct _oid_bits_info_t {
36  guint num;
37  gint ett;
38  struct _oid_bit_t* data;
40 
41 typedef enum _oid_key_type_t {
42  OID_KEY_TYPE_WRONG,
43  OID_KEY_TYPE_INTEGER,
44  OID_KEY_TYPE_OID,
45  OID_KEY_TYPE_STRING,
46  OID_KEY_TYPE_BYTES,
47  OID_KEY_TYPE_NSAP,
48  OID_KEY_TYPE_IPADDR,
49  OID_KEY_TYPE_IMPLIED_OID,
50  OID_KEY_TYPE_IMPLIED_STRING,
51  OID_KEY_TYPE_IMPLIED_BYTES,
52  OID_KEY_TYPE_ETHER,
53  OID_KEY_TYPE_DATE_AND_TIME
54 } oid_key_type_t;
55 
56 typedef struct _oid_value_type_t {
57  enum ftenum ft_type;
58  int display;
59  gint8 ber_class;
60  gint32 ber_tag;
61  int min_len;
62  int max_len;
63  oid_key_type_t keytype;
64  int keysize;
66 
67 typedef enum _oid_kind_t {
68  OID_KIND_UNKNOWN = 0,
69  OID_KIND_NODE,
70  OID_KIND_SCALAR,
71  OID_KIND_TABLE,
72  OID_KIND_ROW,
73  OID_KIND_COLUMN,
74  OID_KIND_NOTIFICATION,
75  OID_KIND_GROUP,
76  OID_KIND_COMPLIANCE,
77  OID_KIND_CAPABILITIES
78 } oid_kind_t;
79 
80 typedef struct _oid_key_t {
81  char* name;
82  guint32 num_subids;
83  oid_key_type_t key_type;
84  int hfid;
85  enum ftenum ft_type;
86  int display;
87  struct _oid_key_t* next;
88 } oid_key_t;
89 
90 typedef struct _oid_info_t {
91  guint32 subid;
92  char* name;
93  oid_kind_t kind;
94  wmem_tree_t* children;
95  const oid_value_type_t* value_type;
96  int value_hfid;
97  oid_key_t* key;
98  oid_bits_info_t* bits;
99  struct _oid_info_t* parent;
100 } oid_info_t;
101 
103 WS_DLL_PUBLIC void oids_init(void);
104 extern void oid_pref_init(module_t *nameres);
105 
107 WS_DLL_PUBLIC void oids_cleanup(void);
108 
109 /*
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.
116  */
117 
118 /*
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 guint32s
123  */
124 
125 /* return length of encoded buffer */
126 WS_DLL_PUBLIC
127 guint oid_subid2encoded(wmem_allocator_t *scope, guint len, guint32* subids, guint8** encoded_p);
128 WS_DLL_PUBLIC
129 guint oid_string2encoded(wmem_allocator_t *scope, const gchar *oid_str, guint8** encoded_p);
130 
131 /* return length of subid array */
132 WS_DLL_PUBLIC
133 guint oid_encoded2subid(wmem_allocator_t *scope, const guint8 *oid, gint len, guint32** subids_p);
134 WS_DLL_PUBLIC
135 guint oid_encoded2subid_sub(wmem_allocator_t *scope, const guint8 *oid_bytes, gint oid_len, guint32** subids_pi,
136  gboolean is_first);
137 WS_DLL_PUBLIC
138 guint oid_string2subid(wmem_allocator_t *scope, const gchar *oid_str, guint32** subids_p);
139 
140 WS_DLL_PUBLIC gchar* oid_encoded2string(wmem_allocator_t *scope, const guint8* encoded, guint len);
141 WS_DLL_PUBLIC gchar* rel_oid_encoded2string(wmem_allocator_t *scope, const guint8* encoded, guint len);
142 WS_DLL_PUBLIC gchar* oid_subid2string(wmem_allocator_t *scope, guint32 *subids, guint len);
143 WS_DLL_PUBLIC gchar* rel_oid_subid2string(wmem_allocator_t *scope, guint32 *subids, guint len, gboolean is_absolute);
144 
145 /* these return a formated string as human readable as posible */
146 WS_DLL_PUBLIC gchar *oid_resolved(wmem_allocator_t *scope, guint len, guint32 *subids);
147 WS_DLL_PUBLIC gchar *oid_resolved_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint len);
148 WS_DLL_PUBLIC gchar *rel_oid_resolved_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint len);
149 WS_DLL_PUBLIC gchar *oid_resolved_from_string(wmem_allocator_t *scope, const gchar *oid_str);
150 
151 /* these yield two formated strings one resolved and one numeric */
152 WS_DLL_PUBLIC void oid_both(wmem_allocator_t *scope, guint oid_len, guint32 *subids, gchar** resolved_p, gchar** numeric_p);
153 WS_DLL_PUBLIC void oid_both_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint oid_len, gchar** resolved_p, gchar** numeric_p);
154 WS_DLL_PUBLIC void oid_both_from_string(wmem_allocator_t *scope, const gchar *oid_str, gchar** resolved_p, gchar** numeric_p);
155 
156 /*
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
160  */
161 WS_DLL_PUBLIC oid_info_t* oid_get(guint oid_len, guint32 *subids, guint* matched_p, guint* left_p);
162 WS_DLL_PUBLIC oid_info_t* oid_get_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint oid_len, guint32 **subids, guint* matched, guint* left);
163 WS_DLL_PUBLIC oid_info_t* oid_get_from_string(wmem_allocator_t *scope, const gchar *oid_str, guint32 **subids, guint* matched, guint* left);
164 
165 /* these are used to add oids to the collection */
166 WS_DLL_PUBLIC void oid_add(const char* name, guint oid_len, guint32 *subids);
167 WS_DLL_PUBLIC void oid_add_from_encoded(const char* name, const guint8 *oid, gint oid_len);
168 WS_DLL_PUBLIC void oid_add_from_string(const char* name, const gchar *oid_str);
169 
176 WS_DLL_PUBLIC gchar *oid_get_default_mib_path(void);
177 
178 /* macros for legacy oid functions */
179 #define subid_t guint32
180 
181 
182 
183 #ifdef DEBUG_OIDS
184 extern char* oid_test_a2b(guint32 num_subids, guint32* subids);
185 extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
186 #else
187 #define add_oid_debug_subtree(a,b) ((void)0)
188 #endif
189 
190 #ifdef __cplusplus
191 }
192 #endif /* __cplusplus */
193 
194 #endif /* __OIDS_H__ */
195 
196 /*
197  * Editor modelines
198  *
199  * Local Variables:
200  * c-basic-offset: 4
201  * tab-width: 8
202  * indent-tabs-mode: nil
203  * End:
204  *
205  * ex: set shiftwidth=4 tabstop=8 expandtab:
206  * :indentSize=4:tabSize=8:noTabs=true:
207  */
WS_DLL_PUBLIC void oids_init(void)
Definition: oids.c:860
WS_DLL_PUBLIC gchar * oid_get_default_mib_path(void)
Definition: oids.c:1279
WS_DLL_PUBLIC void oids_cleanup(void)
Definition: oids.c:869
Definition: oids.h:30
Definition: oids.h:35
Definition: oids.h:90
Definition: oids.h:80
Definition: oids.h:56
Definition: proto.h:904
Definition: wmem_allocator.h:27
Definition: wmem_tree-int.h:48
Definition: prefs-int.h:27