smb2-dissector: learn the "REPLAY_OPERATION" flag
[obnox/wireshark/wip.git] / epan / asn1.h
1 /* asn1.h
2  * Common data for ASN.1
3  * 2007  Anders Broman
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 __ASN1_H__
27 #define __ASN1_H__
28
29 typedef enum {
30   ASN1_ENC_BER,  /* X.690 - BER, CER, DER */
31   ASN1_ENC_PER,  /* X.691 - PER */
32   ASN1_ENC_ECN,  /* X.692 - ECN */
33   ASN1_ENC_XER   /* X.693 - XER */
34 } asn1_enc_e;
35
36 typedef enum {
37   CB_ASN1_ENC,
38   CB_DISSECTOR,
39   CB_NEW_DISSECTOR,
40   CB_DISSECTOR_HANDLE
41 } asn1_cb_variant;
42
43 typedef enum {
44   ASN1_PAR_IRR, /* irrelevant parameter */
45   /* value */
46   ASN1_PAR_BOOLEAN,
47   ASN1_PAR_INTEGER,
48   /* type */
49   ASN1_PAR_TYPE
50 } asn1_par_type;
51
52 typedef struct _asn1_par_def_t {
53   const gchar *name;
54   asn1_par_type ptype;
55 } asn1_par_def_t;
56
57 typedef struct _asn1_par_t {
58   const gchar *name;
59   asn1_par_type ptype;
60   union {
61     gboolean v_boolean;
62     gint32 v_integer;
63     void *v_type;
64   } value;
65   struct _asn1_par_t *next;
66 } asn1_par_t;
67
68 typedef struct _asn1_stack_frame_t {
69   const gchar *name;
70   struct _asn1_par_t *par;
71   struct _asn1_stack_frame_t *next;
72 } asn1_stack_frame_t;
73
74 #define ASN1_CTX_SIGNATURE 0x41435458  /* "ACTX" */
75
76 typedef struct _asn1_ctx_t {
77   guint32 signature;
78   asn1_enc_e encoding;
79   gboolean aligned;
80   packet_info *pinfo;
81   proto_item *created_item;
82   struct _asn1_stack_frame_t *stack;
83   void *value_ptr;
84   void *private_data;
85   struct {
86     int hf_index;
87     gboolean data_value_descr_present;
88     gboolean direct_ref_present;
89     gboolean indirect_ref_present;
90     tvbuff_t *data_value_descriptor;
91     const char *direct_reference;
92     gint32 indirect_reference;
93     gint encoding;  
94       /* 
95          0 : single-ASN1-type, 
96          1 : octet-aligned, 
97          2 : arbitrary 
98       */
99     tvbuff_t *single_asn1_type;
100     tvbuff_t *octet_aligned;
101     tvbuff_t *arbitrary;
102     union {
103       struct {
104         int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index );
105       } ber;
106       struct {
107         int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int);
108       } per;
109     } u;
110   } external;
111   struct {
112     int hf_index;
113     gboolean data_value_descr_present;
114     tvbuff_t *data_value_descriptor;
115     gint identification;
116       /* 
117          0 : syntaxes, 
118          1 : syntax, 
119          2 : presentation-context-id,
120          3 : context-negotiation,
121          4 : transfer-syntax,
122          5 : fixed
123       */
124     gint32 presentation_context_id;
125     const char *abstract_syntax;
126     const char *transfer_syntax;
127     tvbuff_t *data_value;
128     union {
129       struct {
130         int (*ber_callback)(gboolean imp_tag, tvbuff_t *tvb, int offset, struct _asn1_ctx_t* ,proto_tree *tree, int hf_index );
131       } ber;
132       struct {
133         int (*type_cb)(tvbuff_t*, int, struct _asn1_ctx_t*, proto_tree*, int);
134       } per;
135     } u;
136   } embedded_pdv;
137   struct _rose_ctx_t *rose_ctx;
138 } asn1_ctx_t;
139
140 #define ROSE_CTX_SIGNATURE 0x524F5345  /* "ROSE" */
141
142 typedef struct _rose_ctx_t {
143   guint32 signature;
144   dissector_table_t arg_global_dissector_table;
145   dissector_table_t arg_local_dissector_table; 
146   dissector_table_t res_global_dissector_table;
147   dissector_table_t res_local_dissector_table; 
148   dissector_table_t err_global_dissector_table;
149   dissector_table_t err_local_dissector_table; 
150   /* filling in description into tree, info column, any buffer */
151   int apdu_depth;
152   gboolean fillin_info;
153   gchar *fillin_ptr;
154   gsize fillin_buf_size;
155   struct {  /* "dynamic" data */
156     gint pdu;
157       /* 
158          1 : invoke, 
159          2 : returnResult, 
160          3 : returnError,
161          4 : reject
162       */
163     gint code;  
164       /* 
165         -1 : none (optional in ReturnResult)
166          0 : local, 
167          1 : global 
168       */
169     gint32 code_local;
170     const char *code_global;
171     proto_item *code_item;
172   } d;
173   void *private_data;
174 } rose_ctx_t;
175
176 extern void asn1_ctx_init(asn1_ctx_t *actx, asn1_enc_e encoding, gboolean aligned, packet_info *pinfo);
177 extern gboolean asn1_ctx_check_signature(asn1_ctx_t *actx);
178 extern void asn1_ctx_clean_external(asn1_ctx_t *actx);
179 extern void asn1_ctx_clean_epdv(asn1_ctx_t *actx);
180
181 extern void asn1_stack_frame_push(asn1_ctx_t *actx, const gchar *name);
182 extern void asn1_stack_frame_pop(asn1_ctx_t *actx, const gchar *name);
183 extern void asn1_stack_frame_check(asn1_ctx_t *actx, const gchar *name, const asn1_par_def_t *par_def);
184
185 extern void asn1_param_push_boolean(asn1_ctx_t *actx, gboolean value);
186 extern void asn1_param_push_integer(asn1_ctx_t *actx, gint32 value);
187 extern gboolean asn1_param_get_boolean(asn1_ctx_t *actx, const gchar *name);
188 extern gint32 asn1_param_get_integer(asn1_ctx_t *actx, const gchar *name);
189
190 extern void rose_ctx_init(rose_ctx_t *rctx);
191 extern gboolean rose_ctx_check_signature(rose_ctx_t *rctx);
192 extern void rose_ctx_clean_data(rose_ctx_t *rctx);
193
194 extern asn1_ctx_t *get_asn1_ctx(void *ptr);
195 extern rose_ctx_t *get_rose_ctx(void *ptr);
196
197 extern double asn1_get_real(const guint8 *real_ptr, gint real_len);
198
199 /* flags */
200 #define ASN1_EXT_ROOT 0x01
201 #define ASN1_EXT_EXT  0x02
202 #define ASN1_OPT      0x04
203 #define ASN1_DFLT     0x08
204
205 #define ASN1_HAS_EXT(f) ((f)&(ASN1_EXT_ROOT|ASN1_EXT_EXT))
206
207
208 #endif  /* __ASN1_H__ */