| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
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 unsigned (*ber_callback)(bool imp_tag, tvbuff_t *tvb, unsigned offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
26 typedef unsigned (*ber_type_fn)(bool, tvbuff_t*, unsigned offset, asn1_ctx_t *actx, proto_tree*, int);
27
28#define BER_CLASS_UNI 0
29#define BER_CLASS_APP 1
30#define BER_CLASS_CON 2
31#define BER_CLASS_PRI 3
32#define BER_CLASS_ANY 99 /* don't check class nor tag */
33
34#define BER_UNI_TAG_EOC 0 /* 'end-of-content' */
35#define BER_UNI_TAG_BOOLEAN 1
36#define BER_UNI_TAG_INTEGER 2
37#define BER_UNI_TAG_BITSTRING 3
38#define BER_UNI_TAG_OCTETSTRING 4
39#define BER_UNI_TAG_NULL 5
40#define BER_UNI_TAG_OID 6 /* OBJECT IDENTIFIER */
41#define BER_UNI_TAG_ObjectDescriptor 7
42#define BER_UNI_TAG_EXTERNAL 8
43#define BER_UNI_TAG_REAL 9
44#define BER_UNI_TAG_ENUMERATED 10
45#define BER_UNI_TAG_EMBEDDED_PDV 11
46#define BER_UNI_TAG_UTF8String 12
47#define BER_UNI_TAG_RELATIVE_OID 13
48/* UNIVERSAL 14-15
49 * Reserved for future editions of this
50 * Recommendation | International Standard
51 */
52#define BER_UNI_TAG_SEQUENCE 16 /* SEQUENCE, SEQUENCE OF */
53#define BER_UNI_TAG_SET 17 /* SET, SET OF */
54/* UNIVERSAL 18-22 Character string types */
55#define BER_UNI_TAG_NumericString 18
56#define BER_UNI_TAG_PrintableString 19
57#define BER_UNI_TAG_TeletexString 20 /* TeletextString, T61String */
58#define BER_UNI_TAG_VideotexString 21
59#define BER_UNI_TAG_IA5String 22
60/* UNIVERSAL 23-24 Time types */
61#define BER_UNI_TAG_UTCTime 23
62#define BER_UNI_TAG_GeneralizedTime 24
63/* UNIVERSAL 25-30 Character string types */
64#define BER_UNI_TAG_GraphicString 25
65#define BER_UNI_TAG_VisibleString 26 /* VisibleString, ISO64String */
66#define BER_UNI_TAG_GeneralString 27
67#define BER_UNI_TAG_UniversalString 28
68#define BER_UNI_TAG_CHARACTERSTRING 29
69#define BER_UNI_TAG_BMPString 30
70/* UNIVERSAL 31- ...
71 * Reserved for addenda to this Recommendation | International Standard
72 */
73
74
75/* this function dissects the identifier octet of the BER TLV.
76 * We only handle TAGs (and LENGTHs) that fit inside 32 bit integers.
77 */
78WS_DLL_PUBLIC unsigned get_ber_identifier(tvbuff_t *tvb, unsigned offset, int8_t *ber_class, bool *pc, int32_t *tag);
79WS_DLL_PUBLIC unsigned dissect_ber_identifier(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int8_t *ber_class, bool *pc, int32_t *tag);
80WS_DLL_PUBLIC unsigned dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, unsigned offset, proto_tree *tree);
81/* this function dissects the identifier octet of the BER TLV.
82 * We only handle (TAGs and) LENGTHs that fit inside 32 bit integers.
83 */
84WS_DLL_PUBLIC unsigned get_ber_length(tvbuff_t *tvb, unsigned offset, uint32_t *length, bool *ind);
85WS_DLL_PUBLIC unsigned dissect_ber_length(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, unsigned offset, uint32_t *length, bool *ind);
86
87WS_DLL_PUBLIC unsigned dissect_ber_tagged_type(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, int8_t tag_cls, int32_t tag_tag, bool tag_impl, ber_type_fn type);
88
89WS_DLL_PUBLIC unsigned dissect_ber_constrained_octet_string(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int32_t min_len, int32_t max_len, int hf_id, tvbuff_t **out_tvb);
90WS_DLL_PUBLIC unsigned dissect_ber_octet_string(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, tvbuff_t **out_tvb);
91WS_DLL_PUBLIC unsigned dissect_ber_octet_string_with_encoding(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, tvbuff_t **out_tvb, unsigned encoding);
92 extern unsigned dissect_ber_octet_string_wcb(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, ber_callback func);
93
94WS_DLL_PUBLIC unsigned dissect_ber_integer64(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, int64_t *value);
95WS_DLL_PUBLIC unsigned dissect_ber_constrained_integer64(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int64_t min_len, int64_t max_len, int hf_id, int64_t *value);
96
97WS_DLL_PUBLIC unsigned dissect_ber_integer(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, uint32_t *value);
98WS_DLL_PUBLIC unsigned dissect_ber_constrained_integer(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int32_t min_len, int32_t max_len, int hf_id, uint32_t *value);
99
100WS_DLL_PUBLIC unsigned dissect_ber_null(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id);
101
102WS_DLL_PUBLIC unsigned dissect_ber_boolean(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, bool *value);
103WS_DLL_PUBLIC unsigned dissect_ber_real(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, double *value);
104
105 extern unsigned dissect_ber_external_type(bool implicit_tag, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, asn1_ctx_t *actx, int hf_id, ber_callback func);
106WS_DLL_PUBLIC unsigned dissect_ber_EmbeddedPDV_Type(bool implicit_tag, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, asn1_ctx_t *actx, int 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 int8_t ber_class;
115 int32_t tag;
116 uint32_t flags;
117 ber_callback func;
118} ber_sequence_t;
119
120/*
121 * This function dissects a BER sequence
122 */
123WS_DLL_PUBLIC unsigned dissect_ber_sequence(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, const ber_sequence_t *seq, int hf_id, int ett_id);
124WS_DLL_PUBLIC unsigned dissect_ber_set(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, const ber_sequence_t *seq, int hf_id, int ett_id);
125
126 typedef struct _ber_choice_t {
127 uint32_t value;
128 const int *p_id;
129 int8_t ber_class;
130 int32_t tag;
131 uint32_t flags;
132 ber_callback func;
133} ber_choice_t;
134
135/*
136 * @brief Dissects a BER choice
137 *
138 * @attention
139 * The return value of branch_taken (which can be mapped to a variable via
140 * VAL_PTR in a conformance file) is not (necessarily) the tag number, but
141 * the ordinal number of the alternative chosen. These can be different,
142 * particularly when automatic tagging is not in effect (and the tags do not
143 * begin at 0 and increment by 1.)
144 *
145 * This is *not* the same usage as dissect_per_choice and dissect_oer_choice,
146 * which return the tag value in their VAL_PTR.
147 *
148 * @note
149 * The return value of branch_taken can be -1 if no alternative was selected.
150 * This is not necessarily an error if the choice was OPTIONAL. (The function
151 * does not have a way to distinguish between a CHOICE which is OPTIONAL and
152 * one which is not, and does not add an expert info for non optional choices
153 * which are missing, but rather treats them as optional.)
154 *
155 * The safest and correct way to obtain the tag number and identifier chosen is
156 * in a manner thus:
157 * ```c
158 * if (branch_taken >= 0) {
159 * uint32_t tag = ChoiceType_choice[branch_taken].value;
160 * char* identifier = val_to_str_const(tag, proto_ChoiceType_vals, "Unknown");
161 * }
162 * ```
163 * Using the branch_taken as the value will happen to work with some choice
164 * types but is deprecated.
165 */
166WS_DLL_PUBLIC unsigned dissect_ber_choice(asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, const ber_choice_t *ch, int hf_id, int ett_id, int *branch_taken);
167
168/*
169 * This function dissects a BER strings
170 */
171WS_DLL_PUBLIC unsigned dissect_ber_constrained_restricted_string(bool implicit_tag, int32_t type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int32_t min_len, int32_t max_len, int hf_id, tvbuff_t **out_tvb);
172WS_DLL_PUBLIC unsigned dissect_ber_restricted_string(bool implicit_tag, int32_t type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, tvbuff_t **out_tvb);
173 extern unsigned dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, char *name_string, unsigned name_len);
174
175
176/* this function dissects a BER Object Identifier
177 */
178WS_DLL_PUBLIC unsigned dissect_ber_object_identifier(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, tvbuff_t **value_tvb);
179WS_DLL_PUBLIC unsigned dissect_ber_object_identifier_str(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, const char **value_stringx);
180
181/* this function dissects a BER Relative Object Identifier
182 */
183WS_DLL_PUBLIC unsigned dissect_ber_relative_oid(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, tvbuff_t **value_tvb);
184WS_DLL_PUBLIC unsigned dissect_ber_relative_oid_str(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, const char **value_stringx);
185
186/* this function dissects a BER sequence of
187 */
188WS_DLL_PUBLIC unsigned dissect_ber_constrained_sequence_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, int32_t min_len, int32_t max_len, const ber_sequence_t *seq, int hf_id, int ett_id);
189WS_DLL_PUBLIC unsigned dissect_ber_sequence_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, const ber_sequence_t *seq, int hf_id, int ett_id);
190
191WS_DLL_PUBLIC unsigned dissect_ber_constrained_set_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, int32_t min_len, int32_t max_len, const ber_sequence_t *seq, int hf_id, int ett_id);
192WS_DLL_PUBLIC unsigned dissect_ber_set_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, const ber_sequence_t *seq, int hf_id, int ett_id);
193
194WS_DLL_PUBLIC unsigned dissect_ber_GeneralizedTime(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id);
195
196WS_DLL_PUBLIC unsigned dissect_ber_UTCTime(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, unsigned offset, int hf_id, char **datestrptr, uint32_t *tvblen);
197
198WS_DLL_PUBLIC unsigned dissect_ber_constrained_bitstring(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, int32_t min_len, int32_t max_len, int * const *named_bits, int num_named_bits, int hf_id, int ett_id, tvbuff_t **out_tvb);
199WS_DLL_PUBLIC unsigned dissect_ber_bitstring(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, unsigned offset, int * const *named_bits, int num_named_bits, int hf_id, int ett_id, tvbuff_t **out_tvb);
200
201WS_DLL_PUBLIC
202 unsigned call_ber_oid_callback(const char *oid, tvbuff_t *tvb, unsigned offset, packet_info *pinfo, proto_tree *tree, void* data);
203WS_DLL_PUBLIC
204 void register_ber_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto, const char *name);
205WS_DLL_PUBLIC
206 void register_ber_oid_dissector(const char *oid, dissector_t dissector, int proto, const char *name);
207WS_DLL_PUBLIC
208 void register_ber_syntax_dissector(const char *syntax, int proto, dissector_t dissector);
209 void register_ber_oid_name(const char *oid, const char *name);
210WS_DLL_PUBLIC
211 void register_ber_oid_syntax(const char *oid, const char *name, const char *syntax);
212 int dissect_ber_oid_NULL_callback(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data);
213
214WS_DLL_PUBLIC
215 void ber_decode_as_foreach(GHFunc func, void *user_data); /* iterate through known syntaxes */
216
217WS_DLL_PUBLIC
218 bool oid_has_dissector(const char *oid);
219
220WS_DLL_PUBLIC
221 void add_ber_encoded_label(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree);
222#endif /* __PACKET_BER_H__ */
223
asn1.h
to_str.h
proto.h
_asn1_ctx_t
Definition asn1.h:66
_ber_choice_t
Definition packet-ber.h:126
_ber_sequence_t
Definition packet-ber.h:112
_packet_info
Definition packet_info.h:43
_proto_node
Definition proto.h:905
dissector_handle
Definition packet.c:852
tvbuff
Definition tvbuff-int.h:36