1 /* packet-coseventcomm.c
2  *
3  * Routines for IDL dissection
4  *
5  * Autogenerated from idl2wrs
6  * Copyright 2001 Frank Singleton <frank.singleton@ericsson.com>
7  */
8 
9 
10 /*
11  * Wireshark - Network traffic analyzer
12  * By Gerald Combs <gerald@wireshark.org>
13  * Copyright 1998 Gerald Combs
14  */
15 
16 /*
17  * SPDX-License-Identifier: GPL-2.0-or-later
18  */
19 
20 
21 #include "config.h"
22 
23 #include <string.h>
24 #include <epan/packet.h>
25 #include <epan/proto.h>
26 #include <epan/dissectors/packet-giop.h>
27 #include <epan/expert.h>
28 
29 #include "ws_diag_control.h"
30 #include "ws_compiler_tests.h"
31 
32 #ifdef _MSC_VER
33 /* disable warning: "unreference local variable" */
34 #pragma warning(disable:4101)
35 #endif
36 
37 /* XXX this should be autogenerated, or the warnings fixed in the generator */
38 DIAG_OFF(unused-function)
39 DIAG_OFF(unused-variable)
40 #if WS_IS_AT_LEAST_GNUC_VERSION(6,0)
41 DIAG_OFF(unused-const-variable)
42 #endif
43 
44 void proto_register_giop_coseventcomm(void);
45 void proto_reg_handoff_giop_coseventcomm(void);
46 
47 /* Initialise the protocol and subtree pointers */
48 static int proto_coseventcomm = -1;
49 static gint ett_coseventcomm = -1;
50 
51 
52 /* Initialise the initial Alignment */
53 static guint32  boundary = GIOP_HEADER_SIZE;  /* initial value */
54 
55 static int hf_operationrequest = -1;/* Request_Operation field */
56 
57         /* Operation filters */
58 static int hf_CosEventComm_PullSupplier_try_pull_has_event = -1;
59         /* User exception filters */
60         /* Expert info filters */
61 static expert_field ei_coseventcomm_unknown_giop_msg = EI_INIT;
62 static expert_field ei_coseventcomm_unknown_exception = EI_INIT;
63 static expert_field ei_coseventcomm_unknown_reply_status = EI_INIT;
64 
65 
66 static proto_tree *start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset);
67 
68 
69 /*  Begin Exception Helper Functions  */
70 
71 
72 
73 /*  End Exception Helper Functions  */
74 
75 /*
76  * Main delegator for exception handling
77  *
78  */
79 static gboolean
80 decode_user_exception(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *ptree _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
81 {
82     proto_tree *tree _U_;
83 
84     if (!header->exception_id)
85         return FALSE;
86 
87 
88     return FALSE;    /* user exception not found */
89 }
90 
91 /*
92  * IDL:omg.org/CosEventComm/PushConsumer/push:1.0
93  */
94 static void
95 decode_CosEventComm_PushConsumer_push(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
96 {
97     switch(header->message_type) {
98     case Request:
99         get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
100 
101         break;
102     case Reply:
103         switch(header->rep_status) {
104         case NO_EXCEPTION:
105             /* Function returns void */
106 
107             break;
108         case USER_EXCEPTION:
109             break;
110         default:
111             /* Unknown Exception */
112             expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_exception, "Unknown exception %d", header->rep_status);
113             break;
114         }   /* switch(header->rep_status) */
115 
116         break;
117     default:
118         /* Unknown GIOP Message */
119         expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);
120         break;
121     } /* switch(header->message_type) */
122 }
123 
124 /*
125  * IDL:omg.org/CosEventComm/PushConsumer/disconnect_push_consumer:1.0
126  */
127 static void
128 decode_CosEventComm_PushConsumer_disconnect_push_consumer(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
129 {
130     switch(header->message_type) {
131     case Request:
132         break;
133     case Reply:
134         switch(header->rep_status) {
135         case NO_EXCEPTION:
136             /* Function returns void */
137 
138             break;
139         case USER_EXCEPTION:
140             break;
141         default:
142             /* Unknown Exception */
143             expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_exception, "Unknown exception %d", header->rep_status);
144             break;
145         }   /* switch(header->rep_status) */
146 
147         break;
148     default:
149         /* Unknown GIOP Message */
150         expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);
151         break;
152     } /* switch(header->message_type) */
153 }
154 
155 /*
156  * IDL:omg.org/CosEventComm/PushSupplier/disconnect_push_supplier:1.0
157  */
158 static void
159 decode_CosEventComm_PushSupplier_disconnect_push_supplier(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
160 {
161     switch(header->message_type) {
162     case Request:
163         break;
164     case Reply:
165         switch(header->rep_status) {
166         case NO_EXCEPTION:
167             /* Function returns void */
168 
169             break;
170         case USER_EXCEPTION:
171             break;
172         default:
173             /* Unknown Exception */
174             expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_exception, "Unknown exception %d", header->rep_status);
175             break;
176         }   /* switch(header->rep_status) */
177 
178         break;
179     default:
180         /* Unknown GIOP Message */
181         expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);
182         break;
183     } /* switch(header->message_type) */
184 }
185 
186 /*
187  * IDL:omg.org/CosEventComm/PullSupplier/pull:1.0
188  */
189 static void
190 decode_CosEventComm_PullSupplier_pull(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
191 {
192     switch(header->message_type) {
193     case Request:
194         break;
195     case Reply:
196         switch(header->rep_status) {
197         case NO_EXCEPTION:
198             get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
199 
200             break;
201         case USER_EXCEPTION:
202             break;
203         default:
204             /* Unknown Exception */
205             expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_exception, "Unknown exception %d", header->rep_status);
206             break;
207         }   /* switch(header->rep_status) */
208 
209         break;
210     default:
211         /* Unknown GIOP Message */
212         expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);
213         break;
214     } /* switch(header->message_type) */
215 }
216 
217 /*
218  * IDL:omg.org/CosEventComm/PullSupplier/try_pull:1.0
219  */
220 static void
221 decode_CosEventComm_PullSupplier_try_pull(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
222 {
223     switch(header->message_type) {
224     case Request:
225         break;
226     case Reply:
227         switch(header->rep_status) {
228         case NO_EXCEPTION:
229             get_CDR_any(tvb, pinfo, tree, item, offset, stream_is_big_endian, boundary, header);
230 
231             proto_tree_add_boolean(tree, hf_CosEventComm_PullSupplier_try_pull_has_event, tvb, *offset-1, 1, get_CDR_boolean(tvb,offset));
232 
233             break;
234         case USER_EXCEPTION:
235             break;
236         default:
237             /* Unknown Exception */
238             expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_exception, "Unknown exception %d", header->rep_status);
239             break;
240         }   /* switch(header->rep_status) */
241 
242         break;
243     default:
244         /* Unknown GIOP Message */
245         expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);
246         break;
247     } /* switch(header->message_type) */
248 }
249 
250 /*
251  * IDL:omg.org/CosEventComm/PullSupplier/disconnect_pull_supplier:1.0
252  */
253 static void
254 decode_CosEventComm_PullSupplier_disconnect_pull_supplier(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
255 {
256     switch(header->message_type) {
257     case Request:
258         break;
259     case Reply:
260         switch(header->rep_status) {
261         case NO_EXCEPTION:
262             /* Function returns void */
263 
264             break;
265         case USER_EXCEPTION:
266             break;
267         default:
268             /* Unknown Exception */
269             expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_exception, "Unknown exception %d", header->rep_status);
270             break;
271         }   /* switch(header->rep_status) */
272 
273         break;
274     default:
275         /* Unknown GIOP Message */
276         expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);
277         break;
278     } /* switch(header->message_type) */
279 }
280 
281 /*
282  * IDL:omg.org/CosEventComm/PullConsumer/disconnect_pull_consumer:1.0
283  */
284 static void
285 decode_CosEventComm_PullConsumer_disconnect_pull_consumer(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, proto_item *item _U_, int *offset _U_, MessageHeader *header, const gchar *operation _U_, gboolean stream_is_big_endian _U_)
286 {
287     switch(header->message_type) {
288     case Request:
289         break;
290     case Reply:
291         switch(header->rep_status) {
292         case NO_EXCEPTION:
293             /* Function returns void */
294 
295             break;
296         case USER_EXCEPTION:
297             break;
298         default:
299             /* Unknown Exception */
300             expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_exception, "Unknown exception %d", header->rep_status);
301             break;
302         }   /* switch(header->rep_status) */
303 
304         break;
305     default:
306         /* Unknown GIOP Message */
307         expert_add_info_format(pinfo, item, &ei_coseventcomm_unknown_giop_msg, "Unknown GIOP message %d", header->message_type);
308         break;
309     } /* switch(header->message_type) */
310 }
311 
312 /*
313  * Called once we accept the packet as being for us; it sets the
314  * Protocol and Info columns and creates the top-level protocol
315  * tree item.
316  */
317 static proto_tree *
318 start_dissecting(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset)
319 {
320 
321     proto_item *ti = NULL;
322     proto_tree *tree = NULL;            /* init later, inside if(tree) */
323 
324     col_set_str(pinfo->cinfo, COL_PROTOCOL, "COSEVENTCOMM");
325 
326     /*
327      * Do not clear COL_INFO, as nothing is being written there by
328      * this dissector yet. So leave it as is from the GIOP dissector.
329      * TODO: add something useful to COL_INFO
330      *     col_clear(pinfo->cinfo, COL_INFO);
331      */
332 
333     if (ptree) {
334         ti = proto_tree_add_item(ptree, proto_coseventcomm, tvb, *offset, tvb_reported_length_remaining(tvb, *offset), ENC_NA);
335         tree = proto_item_add_subtree(ti, ett_coseventcomm);
336     }
337     return tree;
338 }
339 
340 static proto_item*
341 process_RequestOperation(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, MessageHeader *header, const gchar *operation)
342 {
343     proto_item *pi;
344     if(header->message_type == Reply) {
345         /* fill-up info column */
346         col_append_fstr(pinfo->cinfo, COL_INFO, " op = %s",operation);
347     }
348     /* fill-up the field */
349     pi=proto_tree_add_string(ptree, hf_operationrequest, tvb, 0, 0, operation);
350     proto_item_set_generated(pi);
351     return pi;
352 }
353 
354 static gboolean
355 dissect_coseventcomm(tvbuff_t *tvb, packet_info *pinfo, proto_tree *ptree, int *offset, MessageHeader *header, const gchar *operation, gchar *idlname)
356 {
357     proto_item *item _U_;
358     proto_tree *tree _U_;
359     gboolean stream_is_big_endian = is_big_endian(header); /* get endianess */
360 
361     /* If we have a USER Exception, then decode it and return */
362     if ((header->message_type == Reply) && (header->rep_status == USER_EXCEPTION)) {
363        return decode_user_exception(tvb, pinfo, ptree, offset, header, operation, stream_is_big_endian);
364     }
365 
366     switch(header->message_type) {
367 
368     case Request:
369     case Reply:
370 
371         if (strcmp(operation, "push") == 0
372             && (!idlname || strcmp(idlname, "CosEventComm/PushConsumer") == 0)) {
373             item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
374             tree = start_dissecting(tvb, pinfo, ptree, offset);
375             decode_CosEventComm_PushConsumer_push(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
376             return TRUE;
377         }
378 
379         if (strcmp(operation, "disconnect_push_consumer") == 0
380             && (!idlname || strcmp(idlname, "CosEventComm/PushConsumer") == 0)) {
381             item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
382             tree = start_dissecting(tvb, pinfo, ptree, offset);
383             decode_CosEventComm_PushConsumer_disconnect_push_consumer(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
384             return TRUE;
385         }
386 
387         if (strcmp(operation, "disconnect_push_supplier") == 0
388             && (!idlname || strcmp(idlname, "CosEventComm/PushSupplier") == 0)) {
389             item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
390             tree = start_dissecting(tvb, pinfo, ptree, offset);
391             decode_CosEventComm_PushSupplier_disconnect_push_supplier(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
392             return TRUE;
393         }
394 
395         if (strcmp(operation, "pull") == 0
396             && (!idlname || strcmp(idlname, "CosEventComm/PullSupplier") == 0)) {
397             item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
398             tree = start_dissecting(tvb, pinfo, ptree, offset);
399             decode_CosEventComm_PullSupplier_pull(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
400             return TRUE;
401         }
402 
403         if (strcmp(operation, "try_pull") == 0
404             && (!idlname || strcmp(idlname, "CosEventComm/PullSupplier") == 0)) {
405             item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
406             tree = start_dissecting(tvb, pinfo, ptree, offset);
407             decode_CosEventComm_PullSupplier_try_pull(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
408             return TRUE;
409         }
410 
411         if (strcmp(operation, "disconnect_pull_supplier") == 0
412             && (!idlname || strcmp(idlname, "CosEventComm/PullSupplier") == 0)) {
413             item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
414             tree = start_dissecting(tvb, pinfo, ptree, offset);
415             decode_CosEventComm_PullSupplier_disconnect_pull_supplier(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
416             return TRUE;
417         }
418 
419         if (strcmp(operation, "disconnect_pull_consumer") == 0
420             && (!idlname || strcmp(idlname, "CosEventComm/PullConsumer") == 0)) {
421             item = process_RequestOperation(tvb, pinfo, ptree, header, operation);  /* fill-up Request_Operation field & info column */
422             tree = start_dissecting(tvb, pinfo, ptree, offset);
423             decode_CosEventComm_PullConsumer_disconnect_pull_consumer(tvb, pinfo, tree, item, offset, header, operation, stream_is_big_endian);
424             return TRUE;
425         }
426 
427         break;
428 
429     case CancelRequest:
430     case LocateRequest:
431     case LocateReply:
432     case CloseConnection:
433     case MessageError:
434     case Fragment:
435        return FALSE;      /* not handled yet */
436 
437     default:
438        return FALSE;      /* not handled yet */
439 
440     }   /* switch */
441 
442 
443     return FALSE;
444 
445 }  /* End of main dissector  */
446 
447 
448 /* Register the protocol with Wireshark */
449 void proto_register_giop_coseventcomm(void)
450 {
451     /* setup list of header fields */
452     static hf_register_info hf[] = {
453         /* field that indicates the currently ongoing request/reply exchange */
454             {&hf_operationrequest, {"Request_Operation","giop-coseventcomm.Request_Operation",FT_STRING,BASE_NONE,NULL,0x0,NULL,HFILL}},
455         /* Operation filters */
456         {&hf_CosEventComm_PullSupplier_try_pull_has_event, {"has_event","giop-coseventcomm.PullSupplier.try_pull.has_event",FT_BOOLEAN,8,NULL,0x01,NULL,HFILL}},
457         /* Attribute filters */
458         /* Struct filters */
459         /* User exception filters */
460         /* Union filters */
461 
462     };
463 
464     static ei_register_info ei[] = {
465         { &ei_coseventcomm_unknown_giop_msg, { "giop-coseventcomm.unknown_giop_msg", PI_PROTOCOL, PI_WARN, "Unknown GIOP message", EXPFILL }},
466         { &ei_coseventcomm_unknown_exception, { "giop-coseventcomm.unknown_exception", PI_PROTOCOL, PI_WARN, "Unknown exception", EXPFILL }},
467         { &ei_coseventcomm_unknown_reply_status, { "giop-coseventcomm.unknown_reply_status", PI_PROTOCOL, PI_WARN, "Unknown reply status", EXPFILL }},
468     };
469 
470     /* setup protocol subtree array */
471 
472     static gint *ett[] = {
473         &ett_coseventcomm,
474     };
475 
476     expert_module_t* expert_coseventcomm;
477 
478 
479     /* Register the protocol name and description */
480     proto_coseventcomm = proto_register_protocol("Coseventcomm Dissector Using GIOP API" , "COSEVENTCOMM", "giop-coseventcomm" );
481     proto_register_field_array(proto_coseventcomm, hf, array_length(hf));
482     proto_register_subtree_array(ett, array_length(ett));
483 
484     expert_coseventcomm = expert_register_protocol(proto_coseventcomm);
485     expert_register_field_array(expert_coseventcomm, ei, array_length(ei));
486 }
487 
488 /* register me as handler for these interfaces */
489 void proto_reg_handoff_giop_coseventcomm(void)
490 {
491     /* Register for Explicit Dissection */
492     register_giop_user_module(dissect_coseventcomm, "COSEVENTCOMM", "CosEventComm/PullConsumer", proto_coseventcomm );     /* explicit dissector */
493 
494     /* Register for Explicit Dissection */
495     register_giop_user_module(dissect_coseventcomm, "COSEVENTCOMM", "CosEventComm/PullSupplier", proto_coseventcomm );     /* explicit dissector */
496 
497     /* Register for Explicit Dissection */
498     register_giop_user_module(dissect_coseventcomm, "COSEVENTCOMM", "CosEventComm/PushConsumer", proto_coseventcomm );     /* explicit dissector */
499 
500     /* Register for Explicit Dissection */
501     register_giop_user_module(dissect_coseventcomm, "COSEVENTCOMM", "CosEventComm/PushSupplier", proto_coseventcomm );     /* explicit dissector */
502 
503     /* Register for Heuristic Dissection */
504     register_giop_user(dissect_coseventcomm, "COSEVENTCOMM" ,proto_coseventcomm);     /* heuristic dissector */
505 
506 }
507 
508 /*
509  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
510  *
511  * Local Variables:
512  * c-basic-offset: 4
513  * tab-width: 8
514  * indent-tabs-mode: nil
515  * End:
516  *
517  * ex: set shiftwidth=4 tabstop=8 expandtab:
518  * :indentSize=4:tabSize=8:noTabs=true:
519  */
520