Add some GCC warnings to the standard set, and add some others to the
[obnox/wireshark/wip.git] / epan / dissectors / packet-ber.h
1 /* packet-ber.h
2  * Helpers for ASN.1/BER dissection
3  * Ronnie Sahlberg (C) 2004
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifndef __PACKET_BER_H__
27 #define __PACKET_BER_H__
28
29 #include <epan/proto.h>
30 #include <epan/to_str.h>
31
32 #define BER_NOT_DECODED_YET(x) \
33 proto_tree_add_text(tree, tvb, offset, 0, "something unknown here [%s]",x); \
34 fprintf(stderr,"Not decoded yet in packet : %d  [%s]\n", pinfo->fd->num,x); \
35 if (check_col(pinfo->cinfo, COL_INFO)){ \
36         col_append_fstr(pinfo->cinfo, COL_INFO, "[UNKNOWN BER: %s]", x); \
37 } \
38 tvb_get_guint8(tvb, 9999);
39
40 typedef int (*ber_callback)(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset);
41 typedef int (*ber_type_fn)(gboolean, tvbuff_t*, int, packet_info*, proto_tree*, int);
42
43
44 #define BER_CLASS_UNI   0
45 #define BER_CLASS_APP   1
46 #define BER_CLASS_CON   2
47 #define BER_CLASS_PRI   3
48 #define BER_CLASS_ANY   99                      /* dont check class nor tag */
49
50 #define BER_UNI_TAG_EOC                                 0       /* 'end-of-content' */
51 #define BER_UNI_TAG_BOOLEAN                             1
52 #define BER_UNI_TAG_INTEGER                             2
53 #define BER_UNI_TAG_BITSTRING               3
54 #define BER_UNI_TAG_OCTETSTRING             4
55 #define BER_UNI_TAG_NULL                                5
56 #define BER_UNI_TAG_OID                                 6       /* OBJECT IDENTIFIER */
57 #define BER_UNI_TAG_ObjectDescriptor    7
58 #define BER_UNI_TAG_EXTERNAL                    8
59 #define BER_UNI_TAG_REAL                                9
60 #define BER_UNI_TAG_ENUMERATED              10
61 #define BER_UNI_TAG_EMBEDDED_PDV            11
62 #define BER_UNI_TAG_UTF8String              12
63 #define BER_UNI_TAG_RELATIVE_OID            13
64 /* UNIVERSAL 14-15      
65  * Reserved for future editions of this
66  * Recommendation | International Standard
67  */
68 #define BER_UNI_TAG_SEQUENCE                16  /* SEQUENCE, SEQUENCE OF */
69 #define BER_UNI_TAG_SET                                 17      /* SET, SET OF */
70 /* UNIVERSAL 18-22 Character string types */
71 #define BER_UNI_TAG_NumericString           18
72 #define BER_UNI_TAG_PrintableString         19
73 #define BER_UNI_TAG_TeletexString           20  /* TeletextString, T61String */
74 #define BER_UNI_TAG_VideotexString          21
75 #define BER_UNI_TAG_IA5String               22
76 /* UNIVERSAL 23-24 Time types */
77 #define BER_UNI_TAG_UTCTime                             23
78 #define BER_UNI_TAG_GeneralizedTime         24
79 /* UNIVERSAL 25-30 Character string types */
80 #define BER_UNI_TAG_GraphicString           25
81 #define BER_UNI_TAG_VisibleString           26  /* VisibleString, ISO64String */
82 #define BER_UNI_TAG_GeneralString           27
83 #define BER_UNI_TAG_UniversalString         28
84 #define BER_UNI_TAG_CHARACTERSTRING         29
85 #define BER_UNI_TAG_BMPString               30
86 /* UNIVERSAL 31- ...
87  * Reserved for addenda to this Recommendation | International Standard
88  */
89
90
91 /* this function dissects the identifier octer of the BER TLV.
92  * We only handle TAGs (and LENGTHs) that fit inside 32 bit integers.
93  */
94 extern int get_ber_identifier(tvbuff_t *tvb, int offset, gint8 *class, gboolean *pc, gint32 *tag);
95 extern int dissect_ber_identifier(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint8 *class, gboolean *pc, gint32 *tag);
96 extern int dissect_unknown_ber(packet_info *pinfo, tvbuff_t *tvb, int offset, proto_tree *tree);
97 /* this function dissects the identifier octer of the BER TLV.
98  * We only handle (TAGs and) LENGTHs that fit inside 32 bit integers.
99  */
100 extern int get_ber_length(proto_tree *tree, tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind);
101 extern int dissect_ber_length(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, guint32 *length, gboolean *ind);
102
103 extern int dissect_ber_tagged_type(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint8 tag_cls, gint32 tag_tag, gboolean tag_impl, ber_type_fn type);
104
105 extern int dissect_ber_octet_string(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb);
106 extern int dissect_ber_octet_string_wcb(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, ber_callback func);
107
108 extern int dissect_ber_integer64(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gint64 *value);
109
110 extern int dissect_ber_integer(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, guint32 *value);
111
112 extern int dissect_ber_null(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
113
114 extern int dissect_ber_boolean(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
115 extern int dissect_ber_boolean_value(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, gboolean *value);
116
117
118 #define BER_FLAGS_OPTIONAL      0x00000001
119 #define BER_FLAGS_IMPLTAG       0x00000002
120 #define BER_FLAGS_NOOWNTAG      0x00000004
121 #define BER_FLAGS_NOTCHKTAG     0x00000008
122 typedef struct _ber_sequence_t {
123         gint8   class;
124         gint32  tag;
125         guint32 flags;
126         ber_callback    func;
127 } ber_sequence_t;
128
129 /* this function dissects a BER sequence 
130  */
131 extern int dissect_ber_sequence(gboolean implicit_tag, packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id);
132 extern int dissect_ber_set(gboolean implicit_tag, packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id);
133
134
135 typedef struct _ber_choice_t {
136         guint32 value;
137         gint8   class;
138         gint32  tag;
139         guint32 flags;
140         ber_callback    func;
141 } ber_choice_t;
142
143
144 /* this function dissects a BER choice 
145  */
146 extern int dissect_ber_choice(packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_choice_t *ch, gint hf_id, gint ett_id, gint *branch_taken);
147
148
149 /* this function dissects a BER strings
150  */
151 extern int dissect_ber_restricted_string(gboolean implicit_tag, gint32 type, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **out_tvb);
152 extern int dissect_ber_GeneralString(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, char *name_string, guint name_len);
153
154
155 /* this function dissects a BER Object Identifier
156  */
157 extern int dissect_ber_object_identifier(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, tvbuff_t **value_tvb);
158 extern int dissect_ber_object_identifier_str(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id, const char **value_string);
159
160 /* this function dissects a BER sequence of
161  */
162 extern int dissect_ber_sequence_of(gboolean implicit_tag, packet_info *pinfo, 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_set_of(gboolean implicit_tag, packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const ber_sequence_t *seq, gint hf_id, gint ett_id);
165
166
167 extern int dissect_ber_GeneralizedTime(gboolean implicit_tag, packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset, gint hf_id);
168
169 typedef struct _asn_namedbit {
170         guint32 bit;
171         int *p_id;
172         gint32 gb0;  /* the 1st bit of "bit group", -1 = the 1st bit of current byte */
173         gint32 gb1;  /* last bit of "bit group", -1 = last bit of current byte */
174         const gchar *tstr;  /* true string */
175         const gchar *fstr;  /* false string */
176 } asn_namedbit;
177 /* this function dissects a BER BIT-STRING
178  */
179 extern int dissect_ber_bitstring(gboolean implicit_tag, packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, const asn_namedbit *named_bits, gint hf_id, gint ett_id, tvbuff_t **out_tvb);
180 extern int dissect_ber_bitstring32(gboolean implicit_tag, packet_info *pinfo, proto_tree *parent_tree, tvbuff_t *tvb, int offset, int **bit_fields, gint hf_id, gint ett_id, tvbuff_t **out_tvb);
181
182
183 extern proto_item *ber_last_created_item;
184 extern proto_item *get_ber_last_created_item(void);
185
186 int call_ber_oid_callback(const char *oid, tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
187 void register_ber_oid_dissector_handle(const char *oid, dissector_handle_t dissector, int proto, const char *name);
188 void register_ber_oid_dissector(const char *oid, dissector_t dissector, int proto, const char *name);
189 void register_ber_syntax_dissector(const char *oid, int proto, dissector_t dissector);
190 void register_ber_oid_name(const char *oid, const char *name);
191 void register_ber_oid_syntax(const char *oid, const char *name, const char *syntax);
192 void dissect_ber_oid_NULL_callback(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
193
194 void ber_decode_as_foreach(GHFunc func, gpointer user_data); /* iterate through known syntaxes */
195 void ber_decode_as(const gchar *syntax); /* decode the current capture as this syntax */
196 void ber_set_filename(gchar *filename); /* name of current BER-encoded file */
197
198 gboolean oid_has_dissector(const char *oid);
199
200 #endif  /* __PACKET_BER_H__ */
201