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