Obscure email addresses and update entries.
[obnox/wireshark/wip.git] / packet-dcerpc.h
1 /* packet-dcerpc.h
2  * Copyright 2001, Todd Sabin <tas@webspan.net>
3  *
4  * $Id: packet-dcerpc.h,v 1.31 2003/02/24 01:22:20 guy Exp $
5  *
6  * Ethereal - Network traffic analyzer
7  * By Gerald Combs <gerald@ethereal.com>
8  * Copyright 1998 Gerald Combs
9  *
10  * This program is free software; you can redistribute it and/or
11  * modify it under the terms of the GNU General Public License
12  * as published by the Free Software Foundation; either version 2
13  * of the License, or (at your option) any later version.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with this program; if not, write to the Free Software
22  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
23  */
24
25 #ifndef __PACKET_DCERPC_H__
26 #define __PACKET_DCERPC_H__
27
28 #include <epan/conversation.h>
29
30 typedef struct _e_uuid_t {
31     guint32 Data1;
32     guint16 Data2;
33     guint16 Data3;
34     guint8 Data4[8];
35 } e_uuid_t;
36
37 /* %08x-%04x-%04x-%02x%02x-%02x%02x%02x%02x%02x%02x */
38 #define DCERPC_UUID_STR_LEN 36+1
39
40 typedef struct _e_ctx_hnd {
41     guint32 Data1;
42     e_uuid_t uuid;
43 } e_ctx_hnd;
44
45 typedef struct _e_dce_cn_common_hdr_t {
46     guint8 rpc_ver;
47     guint8 rpc_ver_minor;
48     guint8 ptype;
49     guint8 flags;
50     guint8 drep[4];
51     guint16 frag_len;
52     guint16 auth_len;
53     guint32 call_id;
54 } e_dce_cn_common_hdr_t;
55
56 typedef struct _e_dce_dg_common_hdr_t {
57     guint8 rpc_ver;
58     guint8 ptype;
59     guint8 flags1;
60     guint8 flags2;
61     guint8 drep[3];
62     guint8 serial_hi;
63     e_uuid_t obj_id;
64     e_uuid_t if_id;
65     e_uuid_t act_id;
66     guint32 server_boot;
67     guint32 if_ver;
68     guint32 seqnum;
69     guint16 opnum;
70     guint16 ihint;
71     guint16 ahint;
72     guint16 frag_len;
73     guint16 frag_num;
74     guint8 auth_proto;
75     guint8 serial_lo;
76 } e_dce_dg_common_hdr_t;
77
78
79
80 #define PDU_REQ         0
81 #define PDU_PING        1
82 #define PDU_RESP        2
83 #define PDU_FAULT       3
84 #define PDU_WORKING     4
85 #define PDU_NOCALL      5
86 #define PDU_REJECT      6
87 #define PDU_ACK         7
88 #define PDU_CL_CANCEL   8
89 #define PDU_FACK        9
90 #define PDU_CANCEL_ACK 10
91 #define PDU_BIND       11
92 #define PDU_BIND_ACK   12
93 #define PDU_BIND_NAK   13
94 #define PDU_ALTER      14
95 #define PDU_ALTER_ACK  15
96 #define PDU_AUTH3      16
97 #define PDU_SHUTDOWN   17
98 #define PDU_CO_CANCEL  18
99 #define PDU_ORPHANED   19
100
101
102 /*
103  * helpers for packet-dcerpc.c and packet-dcerpc-ndr.c
104  * If you're writing a subdissector, you almost certainly want the
105  * NDR functions below.
106  */
107 guint16 dcerpc_tvb_get_ntohs (tvbuff_t *tvb, gint offset, char *drep);
108 guint32 dcerpc_tvb_get_ntohl (tvbuff_t *tvb, gint offset, char *drep);
109 void dcerpc_tvb_get_uuid (tvbuff_t *tvb, gint offset, char *drep, e_uuid_t *uuid);
110 int dissect_dcerpc_uint8 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
111                           proto_tree *tree, char *drep,
112                           int hfindex, guint8 *pdata);
113 int dissect_dcerpc_uint16 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
114                            proto_tree *tree, char *drep,
115                            int hfindex, guint16 *pdata);
116 int dissect_dcerpc_uint32 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
117                            proto_tree *tree, char *drep,
118                            int hfindex, guint32 *pdata);
119 int dissect_dcerpc_uint64 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
120                            proto_tree *tree, char *drep,
121                            int hfindex, unsigned char *pdata);
122 int dissect_dcerpc_float  (tvbuff_t *tvb, gint offset, packet_info *pinfo,
123                            proto_tree *tree, char *drep, 
124                            int hfindex, gfloat *pdata);
125 int dissect_dcerpc_double (tvbuff_t *tvb, gint offset, packet_info *pinfo,
126                            proto_tree *tree, char *drep, 
127                            int hfindex, gdouble *pdata);
128 int dissect_dcerpc_time_t (tvbuff_t *tvb, gint offset, packet_info *pinfo,
129                            proto_tree *tree, char *drep, 
130                            int hfindex, guint32 *pdata);
131 /*
132  * NDR routines for subdissectors.
133  */
134 int dissect_ndr_uint8 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
135                        proto_tree *tree, char *drep,
136                        int hfindex, guint8 *pdata);
137 int dissect_ndr_uint16 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
138                         proto_tree *tree, char *drep,
139                         int hfindex, guint16 *pdata);
140 int dissect_ndr_uint32 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
141                         proto_tree *tree, char *drep,
142                         int hfindex, guint32 *pdata);
143 int dissect_ndr_uint64 (tvbuff_t *tvb, gint offset, packet_info *pinfo,
144                         proto_tree *tree, char *drep,
145                         int hfindex, unsigned char *pdata);
146 int dissect_ndr_float (tvbuff_t *tvb, gint offset, packet_info *pinfo,
147                         proto_tree *tree, char *drep, 
148                         int hfindex, gfloat *pdata);
149 int dissect_ndr_double (tvbuff_t *tvb, gint offset, packet_info *pinfo,
150                         proto_tree *tree, char *drep, 
151                         int hfindex, gdouble *pdata);
152 int dissect_ndr_time_t (tvbuff_t *tvb, gint offset, packet_info *pinfo,
153                         proto_tree *tree, char *drep, 
154                         int hfindex, guint32 *pdata);
155 int dissect_ndr_uuid_t (tvbuff_t *tvb, gint offset, packet_info *pinfo,
156                         proto_tree *tree, char *drep,
157                         int hfindex, e_uuid_t *pdata);
158 int dissect_ndr_ctx_hnd (tvbuff_t *tvb, gint offset, packet_info *pinfo,
159                          proto_tree *tree, char *drep,
160                          int hfindex, e_ctx_hnd *pdata);
161
162 typedef int (dcerpc_dissect_fnct_t)(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree, char *drep);
163
164 typedef void (dcerpc_callback_fnct_t)(packet_info *pinfo, proto_tree *tree, proto_item *item, tvbuff_t *tvb, int start_offset, int end_offset, void *callback_args);
165
166 #define NDR_POINTER_REF         1
167 #define NDR_POINTER_UNIQUE      2
168 #define NDR_POINTER_PTR         3
169
170 int dissect_ndr_pointer_cb(tvbuff_t *tvb, gint offset, packet_info *pinfo,
171                            proto_tree *tree, char *drep,
172                            dcerpc_dissect_fnct_t *fnct, int type, char *text, 
173                            int hf_index, dcerpc_callback_fnct_t *callback,
174                            void *callback_args);
175
176 int dissect_ndr_pointer(tvbuff_t *tvb, gint offset, packet_info *pinfo,
177                         proto_tree *tree, char *drep,
178                         dcerpc_dissect_fnct_t *fnct, int type, char *text, 
179                         int hf_index);
180
181 /* dissect a NDR unidimensional conformant array */
182 int dissect_ndr_ucarray(tvbuff_t *tvb, gint offset, packet_info *pinfo,
183                         proto_tree *tree, char *drep,
184                         dcerpc_dissect_fnct_t *fnct);
185
186 /* dissect a NDR unidimensional conformant and varying array */
187 int dissect_ndr_ucvarray(tvbuff_t *tvb, gint offset, packet_info *pinfo,
188                         proto_tree *tree, char *drep,
189                         dcerpc_dissect_fnct_t *fnct);
190
191 int dissect_ndr_byte_array(tvbuff_t *tvb, int offset, packet_info *pinfo, 
192                            proto_tree *tree, char *drep);
193
194 int dissect_ndr_cvstring(tvbuff_t *tvb, int offset, packet_info *pinfo, 
195                          proto_tree *tree, char *drep, int size_is,
196                          int hfinfo, gboolean add_subtree,
197                          char **data);
198 int dissect_ndr_char_cvstring(tvbuff_t *tvb, int offset, packet_info *pinfo, 
199                            proto_tree *tree, char *drep);
200 int dissect_ndr_wchar_cvstring(tvbuff_t *tvb, int offset, packet_info *pinfo, 
201                             proto_tree *tree, char *drep);
202
203 typedef struct _dcerpc_sub_dissector {
204     guint16 num;
205     gchar   *name;
206     dcerpc_dissect_fnct_t *dissect_rqst;
207     dcerpc_dissect_fnct_t *dissect_resp;
208 } dcerpc_sub_dissector;
209
210 /* registration function for subdissectors */
211 void dcerpc_init_uuid (int proto, int ett, e_uuid_t *uuid, guint16 ver, dcerpc_sub_dissector *procs, int opnum_hf);
212 char *dcerpc_get_proto_name(e_uuid_t *uuid, guint16 ver);
213 dcerpc_sub_dissector *dcerpc_get_proto_sub_dissector(e_uuid_t *uuid, guint16 ver);
214
215
216 /* Private data structure to pass to DCERPC dissector. This is used to
217    pass transport specific information down to the dissector from the
218    dissector that parsed this encapsulated calls. */
219
220 #define DCERPC_TRANSPORT_SMB  1
221
222 typedef struct _dcerpc_private_info {
223     int transport_type;         /* Tag */
224
225     union {
226         struct {                /* DCERPC_TRANSPORT_SMB */
227             guint16 fid;
228         } smb;
229     } data;
230 } dcerpc_private_info;
231
232 /* Private data passed to subdissectors from the main DCERPC dissector. */
233 typedef struct _dcerpc_call_value {
234     e_uuid_t uuid;
235     guint16 ver;
236     guint16 opnum;
237     guint32 req_frame;
238     nstime_t req_time;
239     guint32 rep_frame;
240     guint32 max_ptr;
241     void *private_data;
242 } dcerpc_call_value;
243
244 typedef struct _dcerpc_info {
245         conversation_t *conv;   /* Which TCP stream we are in */
246         guint32 call_id;        /* Context id for this call */
247         guint16 smb_fid;        /* FID for DCERPC over SMB */
248         gboolean request;
249         gboolean conformant_run;
250         gint32 conformant_eaten; /* how many bytes did the conformant run eat?*/
251         guint32 array_max_count;        /* max_count for conformant arrays */
252         guint32 array_max_count_offset;
253         guint32 array_offset;
254         guint32 array_offset_offset;
255         guint32 array_actual_count;
256         guint32 array_actual_count_offset;
257         int hf_index;
258         dcerpc_call_value *call_data;
259         void *private_data;
260 } dcerpc_info;
261
262
263 /* the registered subdissectors */
264 extern GHashTable *dcerpc_uuids;
265
266 typedef struct _dcerpc_uuid_key {
267     e_uuid_t uuid;
268     guint16 ver;
269 } dcerpc_uuid_key;
270
271 typedef struct _dcerpc_uuid_value {
272     int proto;
273     int ett;
274     gchar *name;
275     dcerpc_sub_dissector *procs;
276     int opnum_hf;
277 } dcerpc_uuid_value;
278
279
280 #endif /* packet-dcerpc.h */