Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-ber.h
blob7cb109f2cc8d674d3af9b08fd6b8a7cf4789cf1f
1 /* packet-ber.h
2 * Helpers for ASN.1/BER dissection
3 * Ronnie Sahlberg (C) 2004
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
12 #ifndef __PACKET_BER_H__
13 #define __PACKET_BER_H__
15 #include <epan/proto.h>
16 #include <epan/to_str.h>
17 #include <epan/asn1.h>
18 #include "ws_symbol_export.h"
20 /* value for value and size constraints */
21 #ifndef NO_BOUND
22 #define NO_BOUND -1
23 #endif
25 typedef int (*ber_callback)(bool imp_tag, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
26 typedef int (*ber_type_fn)(bool, tvbuff_t*, int, asn1_ctx_t *actx, proto_tree*, int);
27 /* To be removed when the transition to the "New" type is complete */
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 */
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
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
76 /* this function dissects the identifier octer of the BER TLV.
77 * We only handle TAGs (and LENGTHs) that fit inside 32 bit integers.
79 WS_DLL_PUBLIC int get_ber_identifier(tvbuff_t *tvb, int offset, int8_t *ber_class, bool *pc, int32_t *tag);
80 WS_DLL_PUBLIC int dissect_ber_identifier(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, int8_t *ber_class, bool *pc, int32_t *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.
85 WS_DLL_PUBLIC int get_ber_length(tvbuff_t *tvb, int offset, uint32_t *length, bool *ind);
86 WS_DLL_PUBLIC int dissect_ber_length(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, uint32_t *length, bool *ind);
88 WS_DLL_PUBLIC int dissect_ber_tagged_type(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, int8_t tag_cls, int32_t tag_tag, bool tag_impl, ber_type_fn type);
90 extern int dissect_ber_constrained_octet_string(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int32_t min_len, int32_t max_len, int hf_id, tvbuff_t **out_tvb);
91 WS_DLL_PUBLIC int dissect_ber_octet_string(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, tvbuff_t **out_tvb);
92 WS_DLL_PUBLIC int dissect_ber_octet_string_with_encoding(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, tvbuff_t **out_tvb, unsigned encoding);
93 extern int dissect_ber_octet_string_wcb(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, ber_callback func);
95 WS_DLL_PUBLIC int dissect_ber_integer64(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, int64_t *value);
96 extern int dissect_ber_constrained_integer64(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int64_t min_len, int64_t max_len, int hf_id, int64_t *value);
98 WS_DLL_PUBLIC int dissect_ber_integer(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, uint32_t *value);
99 extern int dissect_ber_constrained_integer(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int32_t min_len, int32_t max_len, int hf_id, uint32_t *value);
101 WS_DLL_PUBLIC int dissect_ber_null(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id);
103 WS_DLL_PUBLIC int dissect_ber_boolean(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, bool *value);
104 WS_DLL_PUBLIC int dissect_ber_real(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, double *value);
106 extern int dissect_ber_external_type(bool implicit_tag, proto_tree *parent_tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, int hf_id, ber_callback func);
107 WS_DLL_PUBLIC int dissect_ber_EmbeddedPDV_Type(bool implicit_tag, proto_tree *parent_tree, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, int hf_id, ber_callback func);
109 #define BER_FLAGS_OPTIONAL 0x00000001
110 #define BER_FLAGS_IMPLTAG 0x00000002
111 #define BER_FLAGS_NOOWNTAG 0x00000004
112 #define BER_FLAGS_NOTCHKTAG 0x00000008
113 typedef struct _ber_sequence_t {
114 const int *p_id;
115 int8_t ber_class;
116 int32_t tag;
117 uint32_t flags;
118 ber_callback func;
119 } ber_sequence_t;
122 * This function dissects a BER sequence
124 WS_DLL_PUBLIC int dissect_ber_sequence(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, int hf_id, int ett_id);
125 WS_DLL_PUBLIC int dissect_ber_set(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, int hf_id, int ett_id);
127 typedef struct _ber_choice_t {
128 uint32_t value;
129 const int *p_id;
130 int8_t ber_class;
131 int32_t tag;
132 uint32_t flags;
133 ber_callback func;
134 } ber_choice_t;
137 * This function dissects a BER choice
139 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, int hf_id, int ett_id, int *branch_taken);
140 /* To be removed when the transition to the "New" type is complete */
143 * This function dissects a BER strings
145 extern int dissect_ber_constrained_restricted_string(bool implicit_tag, int32_t type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int32_t min_len, int32_t max_len, int hf_id, tvbuff_t **out_tvb);
146 WS_DLL_PUBLIC int dissect_ber_restricted_string(bool implicit_tag, int32_t type, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, tvbuff_t **out_tvb);
147 extern int dissect_ber_GeneralString(asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, char *name_string, unsigned name_len);
150 /* this function dissects a BER Object Identifier
152 WS_DLL_PUBLIC int dissect_ber_object_identifier(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, tvbuff_t **value_tvb);
153 WS_DLL_PUBLIC int dissect_ber_object_identifier_str(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, const char **value_stringx);
155 /* this function dissects a BER Relative Object Identifier
157 WS_DLL_PUBLIC int dissect_ber_relative_oid(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, tvbuff_t **value_tvb);
158 WS_DLL_PUBLIC int dissect_ber_relative_oid_str(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, const char **value_stringx);
160 /* this function dissects a BER sequence of
162 extern int dissect_ber_constrained_sequence_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, int32_t min_len, int32_t max_len, const ber_sequence_t *seq, int hf_id, int ett_id);
163 WS_DLL_PUBLIC int dissect_ber_sequence_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, int hf_id, int ett_id);
165 extern int dissect_ber_constrained_set_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, int32_t min_len, int32_t max_len, const ber_sequence_t *seq, int hf_id, int ett_id);
166 WS_DLL_PUBLIC int dissect_ber_set_of(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, int hf_id, int ett_id);
168 WS_DLL_PUBLIC int dissect_ber_GeneralizedTime(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id);
170 WS_DLL_PUBLIC int dissect_ber_UTCTime(bool implicit_tag, asn1_ctx_t *actx, proto_tree *tree, tvbuff_t *tvb, int offset, int hf_id, char **datestrptr, uint32_t *tvblen);
172 extern int dissect_ber_constrained_bitstring(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int 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);
173 WS_DLL_PUBLIC int dissect_ber_bitstring(bool implicit_tag, asn1_ctx_t *actx, proto_tree *parent_tree, tvbuff_t *tvb, int offset, int * const *named_bits, int num_named_bits, int hf_id, int ett_id, tvbuff_t **out_tvb);
175 WS_DLL_PUBLIC
176 int call_ber_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, void* data);
177 WS_DLL_PUBLIC
178 void register_ber_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto, const char *name);
179 WS_DLL_PUBLIC
180 void register_ber_oid_dissector(const char *oid, dissector_t dissector, int proto, const char *name);
181 WS_DLL_PUBLIC
182 void register_ber_syntax_dissector(const char *syntax, int proto, dissector_t dissector);
183 void register_ber_oid_name(const char *oid, const char *name);
184 WS_DLL_PUBLIC
185 void register_ber_oid_syntax(const char *oid, const char *name, const char *syntax);
186 int dissect_ber_oid_NULL_callback(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data);
188 WS_DLL_PUBLIC
189 void ber_decode_as_foreach(GHFunc func, void *user_data); /* iterate through known syntaxes */
191 WS_DLL_PUBLIC
192 bool oid_has_dissector(const char *oid);
194 WS_DLL_PUBLIC
195 void add_ber_encoded_label(tvbuff_t* tvb, packet_info* pinfo, proto_tree* tree);
196 #endif /* __PACKET_BER_H__ */