MAX_MCS_INDEX is a valid array index.
[metze/wireshark/wip.git] / epan / oids.h
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  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
23  */
24
25 #ifndef __OIDS_H__
26 #define __OIDS_H__
27
28 #ifdef __cplusplus
29 extern "C" {
30 #endif /* __cplusplus */
31
32 #include <epan/ftypes/ftypes.h>
33 #include <epan/prefs.h>
34 #include <epan/wmem/wmem.h>
35 #include "ws_symbol_export.h"
36
37 /**
38  *@file
39  */
40 #define BER_TAG_ANY -1
41
42 struct _oid_bit_t {
43     guint offset;
44     int hfid;
45 };
46
47 typedef struct _oid_bits_info_t {
48     guint num;
49     gint ett;
50     struct _oid_bit_t* data;
51 } oid_bits_info_t;
52
53 typedef enum _oid_key_type_t {
54     OID_KEY_TYPE_WRONG,
55     OID_KEY_TYPE_INTEGER,
56     OID_KEY_TYPE_OID,
57     OID_KEY_TYPE_STRING,
58     OID_KEY_TYPE_BYTES,
59     OID_KEY_TYPE_NSAP,
60     OID_KEY_TYPE_IPADDR,
61     OID_KEY_TYPE_IMPLIED_OID,
62     OID_KEY_TYPE_IMPLIED_STRING,
63     OID_KEY_TYPE_IMPLIED_BYTES,
64     OID_KEY_TYPE_ETHER,
65     OID_KEY_TYPE_DATE_AND_TIME
66 } oid_key_type_t;
67
68 typedef struct _oid_value_type_t {
69     enum ftenum ft_type;
70     int display;
71     gint8 ber_class;
72     gint32 ber_tag;
73     int min_len;
74     int max_len;
75     oid_key_type_t keytype;
76     int keysize;
77 } oid_value_type_t;
78
79 typedef enum _oid_kind_t {
80     OID_KIND_UNKNOWN = 0,
81     OID_KIND_NODE,
82     OID_KIND_SCALAR,
83     OID_KIND_TABLE,
84     OID_KIND_ROW,
85     OID_KIND_COLUMN,
86     OID_KIND_NOTIFICATION,
87     OID_KIND_GROUP,
88     OID_KIND_COMPLIANCE,
89     OID_KIND_CAPABILITIES
90 } oid_kind_t;
91
92 typedef struct _oid_key_t {
93     char* name;
94     guint32 num_subids;
95     oid_key_type_t key_type;
96     int hfid;
97     enum ftenum ft_type;
98     int display;
99     struct _oid_key_t* next;
100 } oid_key_t;
101
102 typedef struct _oid_info_t {
103     guint32 subid;
104     char* name;
105     oid_kind_t kind;
106     wmem_tree_t* children;
107     const oid_value_type_t* value_type;
108     int value_hfid;
109     oid_key_t* key;
110     oid_bits_info_t* bits;
111     struct _oid_info_t* parent;
112 } oid_info_t;
113
114 /** init function called from prefs.c */
115 WS_DLL_PUBLIC void oids_init(void);
116 extern void oid_pref_init(module_t *nameres);
117
118 /** init function called from epan.h */
119 WS_DLL_PUBLIC void oids_cleanup(void);
120
121 /*
122  * The objects returned by all these functions are all allocated with a
123  * packet lifetime and does not have have to be freed.
124  * However, take into account that when the packet dissection
125  * completes, these buffers will be automatically reclaimed/freed.
126  * If you need the buffer to remain for a longer scope than packet lifetime
127  * you must copy the content to an wmem_file_scope() buffer.
128  */
129
130 /*
131  * These functions convert through the various formats:
132  * string: is  like "0.1.3.4.5.30" (not resolved)
133  * encoded: is BER encoded (as per X.690 section 8.19)
134  * subids: is an array of guint32s
135  */
136
137 /* return length of encoded buffer */
138 WS_DLL_PUBLIC
139 guint oid_subid2encoded(wmem_allocator_t *scope, guint len, guint32* subids, guint8** encoded_p);
140 WS_DLL_PUBLIC
141 guint oid_string2encoded(wmem_allocator_t *scope, const gchar *oid_str, guint8** encoded_p);
142
143 /* return length of subid array */
144 WS_DLL_PUBLIC
145 guint oid_encoded2subid(wmem_allocator_t *scope, const guint8 *oid, gint len, guint32** subids_p);
146 WS_DLL_PUBLIC
147 guint oid_encoded2subid_sub(wmem_allocator_t *scope, const guint8 *oid_bytes, gint oid_len, guint32** subids_pi,
148                 gboolean is_first);
149 WS_DLL_PUBLIC
150 guint oid_string2subid(wmem_allocator_t *scope, const gchar *oid_str, guint32** subids_p);
151
152 WS_DLL_PUBLIC gchar* oid_encoded2string(wmem_allocator_t *scope, const guint8* encoded, guint len);
153 WS_DLL_PUBLIC gchar* rel_oid_encoded2string(wmem_allocator_t *scope, const guint8* encoded, guint len);
154 WS_DLL_PUBLIC gchar* oid_subid2string(wmem_allocator_t *scope, guint32 *subids, guint len);
155 WS_DLL_PUBLIC gchar* rel_oid_subid2string(wmem_allocator_t *scope, guint32 *subids, guint len, gboolean is_absolute);
156
157 /* these return a formated string as human readable as posible */
158 WS_DLL_PUBLIC gchar *oid_resolved(wmem_allocator_t *scope, guint len, guint32 *subids);
159 WS_DLL_PUBLIC gchar *oid_resolved_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint len);
160 WS_DLL_PUBLIC gchar *rel_oid_resolved_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint len);
161 WS_DLL_PUBLIC gchar *oid_resolved_from_string(wmem_allocator_t *scope, const gchar *oid_str);
162
163 /* these yield two formated strings one resolved and one numeric */
164 WS_DLL_PUBLIC void oid_both(wmem_allocator_t *scope, guint oid_len, guint32 *subids, gchar** resolved_p, gchar** numeric_p);
165 WS_DLL_PUBLIC void oid_both_from_encoded(wmem_allocator_t *scope, const guint8 *oid, gint oid_len, gchar** resolved_p, gchar** numeric_p);
166 WS_DLL_PUBLIC void oid_both_from_string(wmem_allocator_t *scope, const gchar *oid_str, gchar** resolved_p, gchar** numeric_p);
167
168 /*
169  * These return the info for the best match.
170  *  *matched_p will be set to the number of nodes used by the returned oid
171  *  *left_p will be set to the number of remaining unresolved subids
172  */
173 WS_DLL_PUBLIC oid_info_t* oid_get(guint oid_len, guint32 *subids, guint* matched_p, guint* left_p);
174 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);
175 WS_DLL_PUBLIC oid_info_t* oid_get_from_string(wmem_allocator_t *scope, const gchar *oid_str, guint32 **subids, guint* matched, guint* left);
176
177 /* these are used to add oids to the collection */
178 WS_DLL_PUBLIC void oid_add(const char* name, guint oid_len, guint32 *subids);
179 WS_DLL_PUBLIC void oid_add_from_encoded(const char* name, const guint8 *oid, gint oid_len);
180 WS_DLL_PUBLIC void oid_add_from_string(const char* name, const gchar *oid_str);
181
182 /**
183  * Fetch the default MIB/PIB path
184  *
185  * @return A string containing the default MIB/PIB path.  It must be
186  * g_free()d by the caller.
187  */
188 WS_DLL_PUBLIC gchar *oid_get_default_mib_path(void);
189
190 /* macros for legacy oid functions */
191 #define subid_t guint32
192
193
194
195 #ifdef DEBUG_OIDS
196 extern char* oid_test_a2b(guint32 num_subids, guint32* subids);
197 extern void add_oid_debug_subtree(oid_info_t* oid_info, proto_tree *tree);
198 #else
199 #define add_oid_debug_subtree(a,b) ((void)0)
200 #endif
201
202 #ifdef __cplusplus
203 }
204 #endif /* __cplusplus */
205
206 #endif  /* __OIDS_H__ */
207
208 /*
209  * Editor modelines
210  *
211  * Local Variables:
212  * c-basic-offset: 4
213  * tab-width: 8
214  * indent-tabs-mode: nil
215  * End:
216  *
217  * ex: set shiftwidth=4 tabstop=8 expandtab:
218  * :indentSize=4:tabSize=8:noTabs=true:
219  */