Wireshark 2.9.0-477-g68ec514b The Wireshark network protocol analyzer

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

packet-ber.h
1 /* packet-ber.h
2 * Helpers for ASN.1/BER dissection
3 * Ronnie Sahlberg (C) 2004
4 *
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
8 *
9 * SPDX-License-Identifier: GPL-2.0-or-later
10 */
11
12 #ifndef __PACKET_BER_H__
13 #define __PACKET_BER_H__
14
15 #include <epan/proto.h>
16 #include <epan/to_str.h>
17 #include <epan/asn1.h>
18 #include "ws_symbol_export.h"
19
20 /* value for value and size constraints */
21 #ifndef NO_BOUND
22 #define NO_BOUND -1
23 #endif
24
25 typedef int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
26 typedef int (*ber_type_fn)(gboolean, tvbuff_t*, int, asn1_ctx_t *actx, proto_tree*, int);
27 /* To be removed when the transition to the "New" type is complete */
28
29 #define BER_CLASS_UNI 0
30 #define BER_CLASS_APP 1
31 #define BER_CLASS_CON 2
32 #define BER_CLASS_PRI 3
33 #define BER_CLASS_ANY 99 /* don't check class nor tag */
34
35 #define BER_UNI_TAG_EOC 0 /* 'end-of-content' */
36 #define BER_UNI_TAG_BOOLEAN 1
37 #define BER_UNI_TAG_INTEGER 2
38 #define BER_UNI_TAG_BITSTRING 3
39 #define BER_UNI_TAG_OCTETSTRING 4
40 #define BER_UNI_TAG_NULL 5
41 #define BER_UNI_TAG_OID 6 /* OBJECT IDENTIFIER */
42 #define BER_UNI_TAG_ObjectDescriptor 7
43 #define BER_UNI_TAG_EXTERNAL 8
44 #define BER_UNI_TAG_REAL 9
45 #define BER_UNI_TAG_ENUMERATED 10
46 #define BER_UNI_TAG_EMBEDDED_PDV 11
47 #define BER_UNI_TAG_UTF8String 12
48 #define BER_UNI_TAG_RELATIVE_OID 13
49 /* UNIVERSAL 14-15
50 * Reserved for future editions of this
51 * Recommendation | International Standard
52 */
53 #define BER_UNI_TAG_SEQUENCE 16 /* SEQUENCE, SEQUENCE OF */
54 #define BER_UNI_TAG_SET 17 /* SET, SET OF */
55 /* UNIVERSAL 18-22 Character string types */
56 #define BER_UNI_TAG_NumericString 18
57 #define BER_UNI_TAG_PrintableString 19
58 #define BER_UNI_TAG_TeletexString 20 /* TeletextString, T61String */
59 #define BER_UNI_TAG_VideotexString 21
60 #define BER_UNI_TAG_IA5String 22
61 /* UNIVERSAL 23-24 Time types */
62 #define BER_UNI_TAG_UTCTime 23
63 #define BER_UNI_TAG_GeneralizedTime 24
64 /* UNIVERSAL 25-30 Character string types */
65 #define BER_UNI_TAG_GraphicString 25
66 #define BER_UNI_TAG_VisibleString 26 /* VisibleString, ISO64String */
67 #define BER_UNI_TAG_GeneralString 27
68 #define BER_UNI_TAG_UniversalString 28
69 #define BER_UNI_TAG_CHARACTERSTRING 29
70 #define BER_UNI_TAG_BMPString 30
71 /* UNIVERSAL 31- ...
72 * Reserved for addenda to this Recommendation | International Standard
73 */
74
75
76 /* this function dissects the identifier octer of the BER TLV.
77 * We only handle TAGs (and LENGTHs) that fit inside 32 bit integers.
78 */
79 WS_DLL_PUBLIC int get_ber_identifier(tvbuff_t *tvb, int offset, gint8 *ber_class, gboolean *pc, gint32 *tag);
80 WS_DLL_PUBLIC int dissect_ber_identifier(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint8 *ber_class, gboolean *pc, gint32 *tag);
81 WS_DLL_PUBLIC int dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tree *tree);
82 /* this function dissects the identifier octer of the BER TLV.
83 * We only handle (TAGs and) LENGTHs that fit inside 32 bit integers.
84 */
85 WS_DLL_PUBLIC int get_ber_length(tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind);
86 WS_DLL_PUBLIC int dissect_ber_length(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind);
87
88 WS_DLL_PUBLIC int dissect_ber_tagged_type(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint8 tag_cls, gint32 tag_tag, gboolean tag_impl, ber_type_fn type);
89
90 extern int dissect_ber_constrained_octet_string(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, tvbuff_t **out_tvb);
91 WS_DLL_PUBLIC int dissect_ber_octet_string(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb);
92 extern int dissect_ber_octet_string_wcb(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, ber_callback func);
93
94 WS_DLL_PUBLIC int dissect_ber_integer64(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint64 *value);
95 extern int dissect_ber_constrained_integer64(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint64 min_len, gint64 max_len, gint hf_id, gint64 *value);
96
97 WS_DLL_PUBLIC int dissect_ber_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, guint32 *value);
98 extern int dissect_ber_constrained_integer(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, guint32 *value);
99
100 WS_DLL_PUBLIC int dissect_ber_null(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
101
102 WS_DLL_PUBLIC int dissect_ber_boolean(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gboolean *value);
103 WS_DLL_PUBLIC int dissect_ber_real(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, double *value);
104
105 extern int dissect_ber_external_type(gboolean implicit_tag, proto_tree *parent_tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, gint hf_id, ber_callback func);
106 WS_DLL_PUBLIC int dissect_ber_EmbeddedPDV_Type(gboolean implicit_tag, proto_tree *parent_tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, gint hf_id, ber_callback func);
107
108 #define BER_FLAGS_OPTIONAL 0x00000001
109 #define BER_FLAGS_IMPLTAG 0x00000002
110 #define BER_FLAGS_NOOWNTAG 0x00000004
111 #define BER_FLAGS_NOTCHKTAG 0x00000008
112 typedef struct _ber_sequence_t {
113 const int *p_id;
114 gint8 ber_class;
115 gint32 tag;
116 guint32 flags;
117 ber_callback func;
118 } ber_sequence_t;
119
120 /*
121 * This function dissects a BER sequence
122 */
123 WS_DLL_PUBLIC int dissect_ber_sequence(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id);
124 WS_DLL_PUBLIC int dissect_ber_set(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id);
125
126 typedef struct _ber_choice_t {
127 guint32 value;
128 const int *p_id;
129 gint8 ber_class;
130 gint32 tag;
131 guint32 flags;
132 ber_callback func;
133 } ber_choice_t;
134
135 /*
136 * This function dissects a BER choice
137 */
138 WS_DLL_PUBLIC int dissect_ber_choice(asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_choice_t *ch, gint hf_id, gint ett_id, gint *branch_taken);
139 /* To be removed when the transition to the "New" type is complete */
140
141 /*
142 * This function dissects a BER strings
143 */
144 extern int dissect_ber_constrained_restricted_string(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, gint hf_id, tvbuff_t **out_tvb);
145 WS_DLL_PUBLIC int dissect_ber_restricted_string(gboolean implicit_tag, gint32 type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb);
146 extern int dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, char *name_string, guint name_len);
147
148
149 /* this function dissects a BER Object Identifier
150 */
151 WS_DLL_PUBLIC int dissect_ber_object_identifier(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **value_tvb);
152 WS_DLL_PUBLIC int dissect_ber_object_identifier_str(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, const char **value_stringx);
153
154 /* this function dissects a BER Relative Object Identifier
155 */
156 WS_DLL_PUBLIC int dissect_ber_relative_oid(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **value_tvb);
157 WS_DLL_PUBLIC int dissect_ber_relative_oid_str(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, const char **value_stringx);
158
159 /* this function dissects a BER sequence of
160 */
161 extern int dissect_ber_constrained_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id);
162 WS_DLL_PUBLIC int dissect_ber_sequence_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id);
163
164 extern int dissect_ber_constrained_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const ber_sequence_t *seq, gint hf_id, gint ett_id);
165 WS_DLL_PUBLIC int dissect_ber_set_of(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id);
166
167 WS_DLL_PUBLIC int dissect_ber_GeneralizedTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
168
169 WS_DLL_PUBLIC int dissect_ber_UTCTime(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
170
171 typedef struct _asn_namedbit {
172 guint32 bit;
173 int *p_id;
174 gint32 gb0; /* the 1st bit of "bit group", -1 = the 1st bit of current byte */
175 gint32 gb1; /* last bit of "bit group", -1 = last bit of current byte */
176 const gchar *tstr; /* true string */
177 const gchar *fstr; /* false string */
178 } asn_namedbit;
179 /* this function dissects a BER BIT-STRING
180 */
181 extern int dissect_ber_constrained_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, gint32 min_len, gint32 max_len, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb);
182 WS_DLL_PUBLIC int dissect_ber_bitstring(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb);
183 extern int dissect_ber_bitstring32(gboolean implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, int **bit_fields, gint hf_id, gint ett_id, tvbuff_t **out_tvb);
184
185 WS_DLL_PUBLIC
186 int call_ber_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, void* data);
187 WS_DLL_PUBLIC
188 void register_ber_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto, const char *name);
189 WS_DLL_PUBLIC
190 void register_ber_oid_dissector(const char *oid, dissector_t dissector, int proto, const char *name);
191 WS_DLL_PUBLIC
192 void register_ber_syntax_dissector(const char *syntax, int proto, dissector_t dissector);
193 void register_ber_oid_name(const char *oid, const char *name);
194 WS_DLL_PUBLIC
195 void register_ber_oid_syntax(const char *oid, const char *name, const char *syntax);
196 int dissect_ber_oid_NULL_callback(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data);
197
198 WS_DLL_PUBLIC
199 void ber_decode_as_foreach(GHFunc func, gpointer user_data); /* iterate through known syntaxes */
200 WS_DLL_PUBLIC
201 void ber_decode_as(const gchar *syntax); /* decode the current capture as this syntax */
202 WS_DLL_PUBLIC
203 void ber_set_filename(gchar *filename); /* name of current BER-encoded file */
204
205 WS_DLL_PUBLIC
206 gboolean oid_has_dissector(const char *oid);
207
208 #endif /* __PACKET_BER_H__ */
209
_asn_namedbit
Definition: packet-ber.h:171
_ber_sequence_t
Definition: packet-ber.h:112
_packet_info
Definition: packet_info.h:44
_ber_choice_t
Definition: packet-ber.h:126
tvbuff
Definition: tvbuff-int.h:35
dissector_handle
Definition: packet.c:659
proto.h
_asn1_ctx_t
Definition: asn1.h:63
_proto_node
Definition: proto.h:759