Have "dissect_netbios_payload()" take as an argument a tvbuff containing
[obnox/wireshark/wip.git] / packet-giop.h
1 /* packet-giop.h
2  * Declaration of routines for GIOP/IIOP (CDR) dissection
3  * Copyright 2000, Frank Singleton <frank.singleton@ericsson.com>
4  *
5  * Based on CORBAv2.4.2  Chapter 15 GIOP Description.
6  *
7  * $Id: packet-giop.h,v 1.6 2001/08/03 20:51:49 guy Exp $
8  *
9  * Ethereal - Network traffic analyzer
10  * By Gerald Combs <gerald@ethereal.com>
11  * Copyright 1998 Gerald Combs
12  * 
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  * 
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  * 
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  */
27
28 #ifndef PACKET_GIOP_H
29 #define PACKET_GIOP_H
30
31 /*
32  * Useful visible data/structs
33  */
34
35 #define GIOP_HEADER_SIZE    12
36
37 typedef struct Version {
38   guint8 major;
39   guint8 minor;
40 } Version;
41
42
43 /* 
44  * Useful data collected from message header. Note, this
45  * struct encapsulates useful data from GIOP header, as well
46  * as request_id and reply_status for use by sub dissectors.
47  */
48
49 typedef struct MessageHeader {
50
51   /* Common Data */
52
53   guint8 magic[4];
54   Version GIOP_version;
55   guint8 flags;                 /* byte_order in 1.0 */
56   guint8 message_type;
57   guint32 message_size;
58   guint32 req_id;               /* request id in MSG  */
59
60   /* MSG dependant data */
61   
62   guint32 rep_status;           /* reply status in MSG if available */
63   gchar *exception_id;             /* exception string if a USER EXCEPTION occurs  */
64
65 } MessageHeader;
66
67 typedef enum MsgType {
68   Request = 0,
69   Reply,
70   CancelRequest,
71   LocateRequest,
72   LocateReply,
73   CloseConnection,
74   MessageError,
75   Fragment                      /* GIOP 1.1 only */
76
77 } MsgType;
78
79
80
81 /*
82  * Reply Status
83  *
84  */
85
86 typedef enum ReplyStatusType {
87   NO_EXCEPTION = 0,
88   USER_EXCEPTION,
89   SYSTEM_EXCEPTION,
90   LOCATION_FORWARD,
91   LOCATION_FORWARD_PERM,        /* new for GIOP 1.2 */
92   NEEDS_ADDRESSING_MODE         /* new for GIOP 1.2 */
93 } ReplyStatusType;
94
95 /*
96  * Prototype for sub dissector function calls.
97  */
98
99 typedef gboolean (giop_sub_dissector_t)(tvbuff_t *, packet_info *, proto_tree *, int *,
100                                   MessageHeader *, gchar * , gchar *);
101
102 /*
103  * Generic Subdissector handle, wraps user info.
104  */
105
106 typedef struct giop_sub_handle {
107   giop_sub_dissector_t *sub_fn;  /* ptr to sub dissector function */
108   gchar *sub_name;               /* subdissector string name */
109   int sub_proto;                /* proto_XXX value from proto_register_protocol() */
110 } giop_sub_handle_t;
111
112 /* Main GIOP entry point */
113
114 gboolean dissect_giop(tvbuff_t *, packet_info *, proto_tree *); /* new interface */
115
116 /*
117  * GIOP Users register interest via this function.
118  * This is for heuristic dissection
119  */
120
121 void register_giop_user(giop_sub_dissector_t *sub, gchar *name, int sub_proto);
122
123 /*
124  * GIOP Users remove interest via this function.
125  * This is for heuristic dissection
126  */
127
128 void delete_giop_user(giop_sub_dissector_t *sub, gchar *name);
129
130
131 /*
132  * GIOP Users register their module and interface names via this function.
133  * This is for explicit dissection.
134  */
135
136 void register_giop_user_module(giop_sub_dissector_t *sub, gchar *name, gchar *module, int sub_proto);
137
138 /*
139  * GIOP Users remove their module and interface names via this function.
140  * This is for explicit dissection.
141  */
142
143 void delete_giop_user_module(giop_sub_dissector_t *sub, gchar *name, gchar *module);
144
145
146 /*
147  * General CDR accessors start here. They are listed in alphabetical
148  * order. They may however, belong to 1 of 3 distinct CDR data types.
149  *
150  * - Primitive
151  * - OMG IDL Constructed Types
152  * - Pseudo Object Types
153  *
154  *
155  * Altough some of these look redundant, I have separated them
156  * out for all CDR types, to assist in auto generation of
157  * IDL dissectors later, see idl2eth -- FS
158  *
159  */
160
161
162 /*
163  * Gets data of type any. This is encoded as a TypeCode
164  * followed by the encoded value.
165  *
166  * Data is added to tree directly if present.
167  */
168
169 void get_CDR_any(tvbuff_t *tvb, proto_tree *tree, gint *offset, gboolean stream_is_big_endian,
170                  int boundary, MessageHeader * header );
171
172
173 /* Copy a 1 octet sequence from the tvbuff 
174  * which represents a boolean value, and convert
175  * it to a boolean value.
176  * Offset is then incremented by 1, to indicate the 1 octet which
177  * has been processed.
178  */
179
180 gboolean get_CDR_boolean(tvbuff_t *tvb, int *offset);
181
182
183 /* Copy a 1 octet sequence from the tvbuff 
184  * which represents a char, and convert
185  * it to an char value.
186  * offset is then incremented by 1, to indicate the 1 octet which
187  * has been processed.
188  */
189
190 guint8 get_CDR_char(tvbuff_t *tvb, int *offset);
191
192
193
194 /* 
195  * Floating Point Data Type double IEEE 754-1985 
196  *
197  * Copy an 8 octet sequence from the tvbuff 
198  * which represents a double value, and convert
199  * it to a double value, taking into account byte order.
200  * offset is first incremented so that it falls on a proper alignment
201  * boundary for double values.
202  * offset is then incremented by 8, to indicate the 8 octets which
203  * have been processed.
204  */
205
206 gdouble get_CDR_double(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
207
208
209 /* Copy a 4 octet sequence from the tvbuff 
210  * which represents an enum value, and convert
211  * it to an enum value, taking into account byte order.
212  * offset is first incremented so that it falls on a proper alignment
213  * boundary for an enum (4)
214  * offset is then incremented by 4, to indicate the 4 octets which
215  * have been processed.
216  *
217  * Enum values are encoded as unsigned long.
218  */
219
220 guint32 get_CDR_enum(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
221
222
223
224 /*
225  * Copy an octet sequence from the tvbuff
226  * which represents a Fixed point decimal type, and create a string representing
227  * a Fixed point decimal type. There are no alignment restrictions.
228  * Size and scale of fixed decimal type is determined by IDL.
229  * 
230  * digits - IDL specified number of "digits" for this fixed type
231  * scale  - IDL specified "scale" for this fixed type
232  *
233  *
234  * eg: typedef fixed <5,2> fixed_t;
235  *     could represent numbers like 123.45, 789.12, 
236  *
237  *
238  * As the fixed type could be any size, I will not try to fit it into our
239  * simple types like gdouble or glong etc. I will just create a string buffer holding
240  * a  representation (after scale is applied), and with a decimal point or zero padding
241  * inserted at the right place if necessary. The string is null terminated
242  *
243  * so string may look like 
244  *
245  *
246  *  "+1.234" or "-3456.78" or "1234567309475760377365465897891" or "-2789000000" etc
247  *
248  * According to spec, digits <= 31
249  * and scale is positive (except for constants eg: 1000 has digit=1 and implied scale = -3)
250  * or <4,0> ?
251  *
252  * User must remember to free the buffer
253  *
254  */
255
256 void get_CDR_fixed(tvbuff_t *tvb, gchar **seq, gint *offset, guint32 digits, gint32 scale);
257
258
259
260 /*
261  * Floating Point Data Type float IEEE 754-1985 
262  * 
263  * Copy a 4 octet sequence from the tvbuff 
264  * which represents a float value, and convert
265  * it to a float value, taking into account byte order.
266  * offset is first incremented so that it falls on a proper alignment
267  * boundary for float values.
268  * offset is then incremented by 4, to indicate the 4 octets which
269  * have been processed.
270  */
271
272 gfloat get_CDR_float(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
273
274
275 /*
276  * Decode an Interface type, and display it on the tree.
277  */
278
279 void get_CDR_interface(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, 
280                        gboolean stream_is_big_endian, int boundary);
281
282
283 /* Copy a 4 octet sequence from the tvbuff 
284  * which represents a signed long value, and convert
285  * it to an signed long vaule, taking into account byte order.
286  * offset is first incremented so that it falls on a proper alignment
287  * boundary for long values.
288  * offset is then incremented by 4, to indicate the 4 octets which
289  * have been processed.
290  */
291
292 gint32 get_CDR_long(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
293
294
295
296 /* Copy a 16 octet sequence from the tvbuff 
297  * which represents a long double value, and convert
298  * it to a long double value, taking into account byte order.
299  * offset is first incremented so that it falls on a proper alignment
300  * boundary for  long double values.
301  * offset is then incremented by 16, to indicate the 16 octets which
302  * have been processed.
303  */
304
305 #ifdef G_HAVE_GLONG_DOUBLE
306
307 glong_double get_CDR_long_double(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, 
308                                  int boundary);
309 #else
310
311 /* FIX -- Cast long double to gdouble until I figure this out -- FS*/
312
313 gdouble get_CDR_long_double(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, 
314                                  int boundary);
315
316 #endif
317
318
319 /* Copy an 8 octet sequence from the tvbuff 
320  * which represents a signed long long value, and convert
321  * it to a signed long long value, taking into account byte order.
322  * offset is first incremented so that it falls on a proper alignment
323  * boundary for long long values.
324  * offset is then incremented by 8, to indicate the 8 octets which
325  * have been processed.
326  */
327
328 #ifdef G_HAVE_GINT64
329 gint64 get_CDR_long_long(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
330 #endif
331
332 /*
333  * Decode an Object type, and display it on the tree.
334  */
335
336 void get_CDR_object(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, int *offset, 
337                        gboolean stream_is_big_endian, int boundary);
338
339
340 /* Copy a 1 octet sequence from the tvbuff 
341  * which represents a octet, and convert
342  * it to an octet value.
343  * offset is then incremented by 1, to indicate the 1 octet which
344  * has been processed.
345  */
346
347 guint8 get_CDR_octet(tvbuff_t *tvb, int *offset);
348
349
350 /* Copy a sequence of octets from the tvbuff.
351  * Caller of this function must remember to free the 
352  * array pointed to by seq.
353  * This function also increments offset by len. 
354  */
355
356 void get_CDR_octet_seq(tvbuff_t *tvb, gchar **seq, int *offset, int len);
357
358 /* Copy a 2 octet sequence from the tvbuff 
359  * which represents a signed short value, and convert
360  * it to a signed short value, taking into account byte order.
361  * offset is first incremented so that it falls on a proper alignment
362  * boundary for short values.
363  * offset is then incremented by 2, to indicate the 2 octets which
364  * have been processed.
365  */
366
367 gint16 get_CDR_short(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
368
369
370 /* Copy an octet sequence from the tvbuff 
371  * which represents a string, and convert
372  * it to an string value, taking into account byte order.
373  * offset is first incremented so that it falls on a proper alignment
374  * boundary for string values. (begins with an unsigned long LI)
375  *
376  * String sequence is copied to a  buffer "seq". This must
377  * be freed by the calling program.
378  * offset is then incremented  , to indicate the  octets which
379  * have been processed.
380  *
381  * returns number of octets in the sequence
382  *
383  * Note: This function only supports single byte encoding at the
384  *       moment until I get a handle on multibyte encoding etc.
385  *
386  */
387
388 guint32 get_CDR_string(tvbuff_t *tvb, gchar **seq, int *offset, gboolean stream_is_big_endian,
389                        int boundary);
390
391
392 /* Process a sequence of octets that represent the 
393  * Pseudo Object Type "TypeCode". Typecodes are used for example,
394  * by "Any values". 
395  * This function also increments offset to the correct position.
396  *
397  * It will parse the TypeCode and output data to the "tree" provided
398  * by the user
399  *
400  * It returns a guint32 representing a TCKind value. 
401  */
402
403 guint32 get_CDR_typeCode(tvbuff_t *tvb, proto_tree *tree, gint *offset, gboolean stream_is_big_endian,
404                          int boundary, MessageHeader * header );
405
406 /* Copy a 4 octet sequence from the tvbuff 
407  * which represents an unsigned long value, and convert
408  * it to an unsigned long value, taking into account byte order.
409  * offset is first incremented so that it falls on a proper alignment
410  * boundary for unsigned long values.
411  * offset is then incremented by 4, to indicate the 4 octets which
412  * have been processed.
413  */
414
415 guint32 get_CDR_ulong(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
416
417
418 /* Copy an 8 octet sequence from the tvbuff 
419  * which represents an unsigned long long value, and convert
420  * it to an unsigned long long value, taking into account byte order.
421  * offset is first incremented so that it falls on a proper alignment
422  * boundary for unsigned long long values.
423  * offset is then incremented by 8, to indicate the 8 octets which
424  * have been processed.
425  */
426
427 #ifdef G_HAVE_GINT64
428 guint64 get_CDR_ulong_long(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
429 #endif
430
431
432 /* Copy a 2 octet sequence from the tvbuff 
433  * which represents an unsigned short value, and convert
434  * it to an unsigned short value, taking into account byte order.
435  * offset is first incremented so that it falls on a proper alignment
436  * boundary for unsigned short values.
437  * offset is then incremented by 2, to indicate the 2 octets which
438  * have been processed.
439  */
440
441 guint16 get_CDR_ushort(tvbuff_t *tvb, int *offset, gboolean stream_is_big_endian, int boundary);
442
443
444 /* Copy a wchar from the tvbuff.
445  * Caller of this function must remember to free the 
446  * array pointed to by seq.
447  * This function also increments offset according to
448  * the wchar size.
449  *
450  * For GIOP 1.1 read 2 octets and return size -2. The
451  * negation means there is no size element in the packet
452  * and therefore no size to add to the tree.
453  *
454  * For GIOP 1.2 read size of wchar and the size
455  * octets. size is returned as a gint8.
456  *
457  * For both GIOP versions the wchar is returned
458  * as a printable string.
459  *
460  */
461
462 /* NOTE: This is very primitive in that it just reads
463  * the wchar as a series of octets and returns them
464  * to the user. No translation is attempted based on
465  * byte orientation, nor on code set. I.e it only 
466  * really reads past the wchar and increments the offset
467  * by the length of the octet sequence.
468  */
469
470 /* The "decoding" is done according to CORBA chapter 15.
471  * Wchar is not supported for GIOP 1.0.
472  */
473
474 gint8 get_CDR_wchar(tvbuff_t *tvb, gchar **seq, int *offset, MessageHeader * header);
475
476
477 /* Copy a wstring from the tvbuff.
478  * Caller of this function must remember to free the 
479  * array pointed to by seq.
480  * This function also increments offset, according to
481  * wstring length. length is returned as guint32
482  */
483
484 /* NOTE: This is very primitive in that it just reads
485  * the wstring as a series of octets and returns them
486  * to the user. No translation is attempted based on
487  * byte orientation, nor on code set. I.e it only 
488  * really reads past the wstring and increments the offset
489  * by the length of the octet sequence.
490  */
491
492 /* The "decoding" is done according to CORBA chapter 15.
493  * Wstring is not supported for GIOP 1.0.
494  */
495
496 guint32 get_CDR_wstring(tvbuff_t *tvb, gchar **seq, int *offset, gboolean stream_is_big_endian, 
497                         int boundary, MessageHeader * header);
498
499
500
501 /*
502  *
503  * End of get_CDR_xxx accessors.
504  *
505  */
506
507
508
509 /* Determine the byte order from the GIOP MessageHeader */
510
511 gboolean is_big_endian (MessageHeader * header);
512
513 /*
514  * get_encap_info() for any encapsulation  (eg:sequences)
515  * we come across. updates the new boundary and endianess
516  * and *offset, and returns the sequence length.
517  */
518
519 guint32 get_CDR_encap_info(tvbuff_t *tvb, proto_tree *tree, gint *offset, 
520                            gboolean old_stream_is_big_endian, guint32 old_boundary,
521                            gboolean *new_stream_is_big_endian_ptr, guint32 *new_boundary_ptr );
522
523
524
525 /*
526  * Enums for TCkind
527  */
528
529 enum TCKind {
530   tk_null = 0,
531   tk_void,
532   tk_short,
533   tk_long,
534   tk_ushort,
535   tk_ulong,
536   tk_float,
537   tk_double,
538   tk_boolean,
539   tk_char,
540   tk_octet,
541   tk_any,
542   tk_TypeCode,
543   tk_Principal,
544   tk_objref,
545   tk_struct,
546   tk_union,
547   tk_enum,
548   tk_string,
549   tk_sequence,
550   tk_array,
551   tk_alias,
552   tk_except,
553   tk_longlong,
554   tk_ulonglong,
555   tk_longdouble,
556   tk_wchar,
557   tk_wstring,
558   tk_fixed,
559   tk_value,
560   tk_value_box,
561   tk_native,
562   tk_abstract_interface,
563
564   /* - none -   0xffffffff TODO */
565 };
566
567 #define tk_none  0xffffffff
568
569 typedef enum TCKind TCKind_t;
570
571
572 /*
573  * ServiceId's for ServiceContextList
574  *
575  * Chapter 13 Corba 2.4.2
576  */
577
578 #define IOP_ServiceId_TransactionService                0
579 #define IOP_ServiceId_CodeSets                          1
580 #define IOP_ServiceId_ChainBypassCheck                  2
581 #define IOP_ServiceId_ChainBypassInfo                   3
582 #define IOP_ServiceId_LogicalThreadId                   4
583 #define IOP_ServiceId_BI_DIR_IIOP                       5
584 #define IOP_ServiceId_SendingContextRunTime             6
585 #define IOP_ServiceId_INVOCATION_POLICIES               7
586 #define IOP_ServiceId_FORWARD_IDENTITY                  8
587 #define IOP_ServiceId_UnknownExceptionInfo              9
588
589 #endif /* PACKET_GIOP_H */