Update for missing const for object identifier string and marking tree as unused.
[obnox/wireshark/wip.git] / epan / dissectors / packet-idmp.c
1 /* Do not modify this file.                                                   */
2 /* It is created automatically by the ASN.1 to Wireshark dissector compiler   */
3 /* packet-idmp.c                                                              */
4 /* ../../tools/asn2wrs.py -b -e -L -k -p idmp -c ./idmp.cnf -s ./packet-idmp-template -D . IDMProtocolSpecification.asn CommonProtocolSpecification.asn */
5
6 /* Input file: packet-idmp-template.c */
7
8 #line 1 "packet-idmp-template.c"
9 /* packet-idmp.c
10  * Routines for X.519 Internet Directly Mapped Procotol (IDMP) packet dissection
11  * Graeme Lunt 2020
12  *
13  * $Id$
14  *
15  * Wireshark - Network traffic analyzer
16  * By Gerald Combs <gerald@wireshark.org>
17  * Copyright 1998 Gerald Combs
18  *
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version 2
22  * of the License, or (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
32  */
33
34 #ifdef HAVE_CONFIG_H
35 # include "config.h"
36 #endif
37
38 #include <glib.h>
39 #include <epan/packet.h>
40 #include <epan/prefs.h>
41 #include <epan/reassemble.h>
42 #include <epan/conversation.h>
43 #include <epan/oids.h>
44 #include <epan/asn1.h>
45 #include <epan/ipproto.h>
46
47 #include <epan/dissectors/packet-tcp.h>
48
49 #include "packet-ber.h"
50 #include "packet-ros.h"
51 #include "packet-x509ce.h"
52
53 #include <epan/strutil.h>
54
55 #define PNAME  "X.519 Internet Directly Mapped Protocol"
56 #define PSNAME "IDMP"
57 #define PFNAME "idmp"
58
59 static gboolean idmp_desegment = TRUE;
60 static guint global_idmp_tcp_port = 1102; /* made up for now */
61 static gboolean idmp_reassemble = TRUE;
62 static guint tcp_port = 0;
63 static dissector_handle_t idmp_handle = NULL;
64
65 static proto_tree *top_tree = NULL;
66 static struct SESSION_DATA_STRUCTURE* session = NULL;
67 static const char *protocolID = NULL;
68 static const char *saved_protocolID = NULL;
69 static guint32 opcode = -1;
70
71 void prefs_register_idmp(void); /* forward declaration for use in preferences registration */
72
73 /* Initialize the protocol and registered fields */
74 int proto_idmp = -1;
75
76 static int hf_idmp_version = -1;
77 static int hf_idmp_final = -1;
78 static int hf_idmp_length = -1;
79 static int hf_idmp_PDU = -1;
80
81 static GHashTable *idmp_segment_table = NULL;
82 static GHashTable *idmp_reassembled_table = NULL;
83  
84 static int hf_idmp_fragments = -1;
85 static int hf_idmp_fragment = -1;
86 static int hf_idmp_fragment_overlap = -1;
87 static int hf_idmp_fragment_overlap_conflicts = -1;
88 static int hf_idmp_fragment_multiple_tails = -1;
89 static int hf_idmp_fragment_too_long_fragment = -1;
90 static int hf_idmp_fragment_error = -1;
91 static int hf_idmp_reassembled_in = -1;
92 static int hf_idmp_reassembled_length = -1;
93
94 static gint ett_idmp_fragment = -1;
95 static gint ett_idmp_fragments = -1;
96
97 static const fragment_items idmp_frag_items = {
98         /* Fragment subtrees */
99         &ett_idmp_fragment,
100         &ett_idmp_fragments,
101         /* Fragment fields */
102         &hf_idmp_fragments,
103         &hf_idmp_fragment,
104         &hf_idmp_fragment_overlap,
105         &hf_idmp_fragment_overlap_conflicts,
106         &hf_idmp_fragment_multiple_tails,
107         &hf_idmp_fragment_too_long_fragment,
108         &hf_idmp_fragment_error,
109         /* Reassembled in field */
110         &hf_idmp_reassembled_in,
111         /* Reassembled length field */
112         &hf_idmp_reassembled_length,
113         /* Tag */
114         "IDMP fragments"
115 };
116
117
118 static int call_idmp_oid_callback(tvbuff_t *tvb, int offset, packet_info *pinfo, int op, proto_tree *tree _U_)  
119 {
120         struct SESSION_DATA_STRUCTURE *session;
121         
122         if((session = (struct SESSION_DATA_STRUCTURE*)pinfo->private_data) != NULL) {
123
124                 if((!saved_protocolID) && (op == (ROS_OP_BIND | ROS_OP_RESULT))) {
125                         /* save for subsequent operations - should be into session data */
126                         saved_protocolID = se_strdup(protocolID);
127                 }
128
129                 /* mimic ROS! */
130                 session->ros_op = op;
131                 offset = call_ros_oid_callback(saved_protocolID ? saved_protocolID : protocolID, tvb, offset, pinfo, top_tree);
132         }
133
134         return offset;
135
136 }
137
138
139 /*--- Included file: packet-idmp-hf.c ---*/
140 #line 1 "packet-idmp-hf.c"
141 static int hf_idmp_bind = -1;                     /* IdmBind */
142 static int hf_idmp_bindResult = -1;               /* IdmBindResult */
143 static int hf_idmp_bindError = -1;                /* IdmBindError */
144 static int hf_idmp_request = -1;                  /* Request */
145 static int hf_idmp_idm_result = -1;               /* IdmResult */
146 static int hf_idmp_idm_error = -1;                /* Error */
147 static int hf_idmp_reject = -1;                   /* IdmReject */
148 static int hf_idmp_unbind = -1;                   /* Unbind */
149 static int hf_idmp_abort = -1;                    /* Abort */
150 static int hf_idmp_startTLS = -1;                 /* StartTLS */
151 static int hf_idmp_tLSResponse = -1;              /* TLSResponse */
152 static int hf_idmp_protocolID = -1;               /* OBJECT_IDENTIFIER */
153 static int hf_idmp_callingAETitle = -1;           /* GeneralName */
154 static int hf_idmp_calledAETitle = -1;            /* GeneralName */
155 static int hf_idmp_bind_argument = -1;            /* Bind_argument */
156 static int hf_idmp_respondingAETitle = -1;        /* GeneralName */
157 static int hf_idmp_bind_result = -1;              /* Bind_result */
158 static int hf_idmp_bind_errcode = -1;             /* Bind_errcode */
159 static int hf_idmp_aETitleError = -1;             /* T_aETitleError */
160 static int hf_idmp_bind_error = -1;               /* Bind_error */
161 static int hf_idmp_invokeID = -1;                 /* INTEGER */
162 static int hf_idmp_opcode = -1;                   /* Code */
163 static int hf_idmp_argument = -1;                 /* T_argument */
164 static int hf_idmp_idm_invokeID = -1;             /* InvokeId */
165 static int hf_idmp_result = -1;                   /* T_result */
166 static int hf_idmp_errcode = -1;                  /* T_errcode */
167 static int hf_idmp_error = -1;                    /* T_error */
168 static int hf_idmp_reason = -1;                   /* T_reason */
169 static int hf_idmp_local = -1;                    /* T_local */
170 static int hf_idmp_global = -1;                   /* OBJECT_IDENTIFIER */
171 static int hf_idmp_present = -1;                  /* INTEGER */
172 static int hf_idmp_absent = -1;                   /* NULL */
173
174 /*--- End of included file: packet-idmp-hf.c ---*/
175 #line 131 "packet-idmp-template.c"
176
177 /* Initialize the subtree pointers */
178 static gint ett_idmp = -1;
179
180 /*--- Included file: packet-idmp-ett.c ---*/
181 #line 1 "packet-idmp-ett.c"
182 static gint ett_idmp_IDM_PDU = -1;
183 static gint ett_idmp_IdmBind = -1;
184 static gint ett_idmp_IdmBindResult = -1;
185 static gint ett_idmp_IdmBindError = -1;
186 static gint ett_idmp_Request = -1;
187 static gint ett_idmp_IdmResult = -1;
188 static gint ett_idmp_Error = -1;
189 static gint ett_idmp_IdmReject = -1;
190 static gint ett_idmp_Code = -1;
191 static gint ett_idmp_InvokeId = -1;
192
193 /*--- End of included file: packet-idmp-ett.c ---*/
194 #line 135 "packet-idmp-template.c"
195
196
197 /*--- Included file: packet-idmp-fn.c ---*/
198 #line 1 "packet-idmp-fn.c"
199
200
201 static int
202 dissect_idmp_OBJECT_IDENTIFIER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
203   offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &protocolID);
204
205   return offset;
206 }
207
208
209
210 static int
211 dissect_idmp_Bind_argument(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
212
213         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND | ROS_OP_ARGUMENT), top_tree);
214
215
216   return offset;
217 }
218
219
220 static const ber_sequence_t IdmBind_sequence[] = {
221   { &hf_idmp_protocolID     , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
222   { &hf_idmp_callingAETitle , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
223   { &hf_idmp_calledAETitle  , BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
224   { &hf_idmp_bind_argument  , BER_CLASS_CON, 2, 0, dissect_idmp_Bind_argument },
225   { NULL, 0, 0, 0, NULL }
226 };
227
228 static int
229 dissect_idmp_IdmBind(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
230   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
231                                    IdmBind_sequence, hf_index, ett_idmp_IdmBind);
232
233   return offset;
234 }
235
236
237
238 static int
239 dissect_idmp_Bind_result(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
240
241         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND | ROS_OP_RESULT), top_tree);
242
243
244   return offset;
245 }
246
247
248 static const ber_sequence_t IdmBindResult_sequence[] = {
249   { &hf_idmp_protocolID     , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
250   { &hf_idmp_respondingAETitle, BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
251   { &hf_idmp_bind_result    , BER_CLASS_CON, 1, 0, dissect_idmp_Bind_result },
252   { NULL, 0, 0, 0, NULL }
253 };
254
255 static int
256 dissect_idmp_IdmBindResult(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
257   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
258                                    IdmBindResult_sequence, hf_index, ett_idmp_IdmBindResult);
259
260   return offset;
261 }
262
263
264
265 static int
266 dissect_idmp_Bind_errcode(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
267
268
269   return offset;
270 }
271
272
273 static const value_string idmp_T_aETitleError_vals[] = {
274   {   0, "callingAETitleNotAccepted" },
275   {   1, "calledAETitleNotRecognized" },
276   { 0, NULL }
277 };
278
279
280 static int
281 dissect_idmp_T_aETitleError(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
282   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
283                                   NULL);
284
285   return offset;
286 }
287
288
289
290 static int
291 dissect_idmp_Bind_error(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
292
293         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND| ROS_OP_ERROR), top_tree);
294
295
296   return offset;
297 }
298
299
300 static const ber_sequence_t IdmBindError_sequence[] = {
301   { &hf_idmp_protocolID     , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
302   { &hf_idmp_bind_errcode   , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_Bind_errcode },
303   { &hf_idmp_respondingAETitle, BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
304   { &hf_idmp_aETitleError   , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_idmp_T_aETitleError },
305   { &hf_idmp_bind_error     , BER_CLASS_CON, 1, 0, dissect_idmp_Bind_error },
306   { NULL, 0, 0, 0, NULL }
307 };
308
309 static int
310 dissect_idmp_IdmBindError(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
311   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
312                                    IdmBindError_sequence, hf_index, ett_idmp_IdmBindError);
313
314   return offset;
315 }
316
317
318
319 static int
320 dissect_idmp_INTEGER(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
321   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
322                                                 NULL);
323
324   return offset;
325 }
326
327
328
329 static int
330 dissect_idmp_T_local(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
331   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
332                                                 &opcode);
333
334   return offset;
335 }
336
337
338 static const value_string idmp_Code_vals[] = {
339   {   0, "local" },
340   {   1, "global" },
341   { 0, NULL }
342 };
343
344 static const ber_choice_t Code_choice[] = {
345   {   0, &hf_idmp_local          , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_T_local },
346   {   1, &hf_idmp_global         , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
347   { 0, NULL, 0, 0, 0, NULL }
348 };
349
350 static int
351 dissect_idmp_Code(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
352   offset = dissect_ber_choice(actx, tree, tvb, offset,
353                                  Code_choice, hf_index, ett_idmp_Code,
354                                  NULL);
355
356   return offset;
357 }
358
359
360
361 static int
362 dissect_idmp_T_argument(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
363
364         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_INVOKE | ROS_OP_ARGUMENT | opcode), top_tree);
365
366
367   return offset;
368 }
369
370
371 static const ber_sequence_t Request_sequence[] = {
372   { &hf_idmp_invokeID       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
373   { &hf_idmp_opcode         , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_Code },
374   { &hf_idmp_argument       , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_argument },
375   { NULL, 0, 0, 0, NULL }
376 };
377
378 static int
379 dissect_idmp_Request(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
380   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
381                                    Request_sequence, hf_index, ett_idmp_Request);
382
383   return offset;
384 }
385
386
387
388 static int
389 dissect_idmp_NULL(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
390   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
391
392   return offset;
393 }
394
395
396 static const value_string idmp_InvokeId_vals[] = {
397   {   0, "present" },
398   {   1, "absent" },
399   { 0, NULL }
400 };
401
402 static const ber_choice_t InvokeId_choice[] = {
403   {   0, &hf_idmp_present        , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
404   {   1, &hf_idmp_absent         , BER_CLASS_UNI, BER_UNI_TAG_NULL, BER_FLAGS_NOOWNTAG, dissect_idmp_NULL },
405   { 0, NULL, 0, 0, 0, NULL }
406 };
407
408 static int
409 dissect_idmp_InvokeId(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
410   offset = dissect_ber_choice(actx, tree, tvb, offset,
411                                  InvokeId_choice, hf_index, ett_idmp_InvokeId,
412                                  NULL);
413
414   return offset;
415 }
416
417
418
419 static int
420 dissect_idmp_T_result(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
421
422         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_INVOKE | ROS_OP_RESULT | opcode), top_tree);
423
424
425
426   return offset;
427 }
428
429
430 static const ber_sequence_t IdmResult_sequence[] = {
431   { &hf_idmp_idm_invokeID   , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_InvokeId },
432   { &hf_idmp_opcode         , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_Code },
433   { &hf_idmp_result         , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_result },
434   { NULL, 0, 0, 0, NULL }
435 };
436
437 static int
438 dissect_idmp_IdmResult(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
439   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
440                                    IdmResult_sequence, hf_index, ett_idmp_IdmResult);
441
442   return offset;
443 }
444
445
446
447 static int
448 dissect_idmp_T_errcode(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
449
450
451   return offset;
452 }
453
454
455
456 static int
457 dissect_idmp_T_error(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
458
459
460   return offset;
461 }
462
463
464 static const ber_sequence_t Error_sequence[] = {
465   { &hf_idmp_invokeID       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
466   { &hf_idmp_errcode        , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_errcode },
467   { &hf_idmp_error          , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_error },
468   { NULL, 0, 0, 0, NULL }
469 };
470
471 static int
472 dissect_idmp_Error(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
473   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
474                                    Error_sequence, hf_index, ett_idmp_Error);
475
476   return offset;
477 }
478
479
480 static const value_string idmp_T_reason_vals[] = {
481   {   0, "mistypedPDU" },
482   {   1, "duplicateInvokeIDRequest" },
483   {   2, "unsupportedOperationRequest" },
484   {   3, "unknownOperationRequest" },
485   {   4, "mistypedArgumentRequest" },
486   {   5, "resourceLimitationRequest" },
487   {   6, "unknownInvokeIDResult" },
488   {   7, "mistypedResultRequest" },
489   {   8, "unknownInvokeIDError" },
490   {   9, "unknownError" },
491   {  10, "mistypedParameterError" },
492   { 0, NULL }
493 };
494
495
496 static int
497 dissect_idmp_T_reason(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
498   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
499                                   NULL);
500
501   return offset;
502 }
503
504
505 static const ber_sequence_t IdmReject_sequence[] = {
506   { &hf_idmp_invokeID       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
507   { &hf_idmp_reason         , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_idmp_T_reason },
508   { NULL, 0, 0, 0, NULL }
509 };
510
511 static int
512 dissect_idmp_IdmReject(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
513   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
514                                    IdmReject_sequence, hf_index, ett_idmp_IdmReject);
515
516   return offset;
517 }
518
519
520
521 static int
522 dissect_idmp_Unbind(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
523   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
524
525   return offset;
526 }
527
528
529 static const value_string idmp_Abort_vals[] = {
530   {   0, "mistypedPDU" },
531   {   1, "unboundRequest" },
532   {   2, "invalidPDU" },
533   {   3, "resourceLimitation" },
534   {   4, "connectionFailed" },
535   {   5, "invalidProtocol" },
536   {   6, "reasonNotSpecified" },
537   { 0, NULL }
538 };
539
540
541 static int
542 dissect_idmp_Abort(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
543   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
544                                   NULL);
545
546   return offset;
547 }
548
549
550
551 static int
552 dissect_idmp_StartTLS(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
553   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
554
555   return offset;
556 }
557
558
559 static const value_string idmp_TLSResponse_vals[] = {
560   {   0, "success" },
561   {   1, "operationsError" },
562   {   2, "protocolError" },
563   {   3, "unavailable" },
564   { 0, NULL }
565 };
566
567
568 static int
569 dissect_idmp_TLSResponse(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
570   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
571                                   NULL);
572
573   return offset;
574 }
575
576
577 static const value_string idmp_IDM_PDU_vals[] = {
578   {   0, "bind" },
579   {   1, "bindResult" },
580   {   2, "bindError" },
581   {   3, "request" },
582   {   4, "result" },
583   {   5, "error" },
584   {   6, "reject" },
585   {   7, "unbind" },
586   {   8, "abort" },
587   {   9, "startTLS" },
588   {  10, "tLSResponse" },
589   { 0, NULL }
590 };
591
592 static const ber_choice_t IDM_PDU_choice[] = {
593   {   0, &hf_idmp_bind           , BER_CLASS_CON, 0, 0, dissect_idmp_IdmBind },
594   {   1, &hf_idmp_bindResult     , BER_CLASS_CON, 1, 0, dissect_idmp_IdmBindResult },
595   {   2, &hf_idmp_bindError      , BER_CLASS_CON, 2, 0, dissect_idmp_IdmBindError },
596   {   3, &hf_idmp_request        , BER_CLASS_CON, 3, 0, dissect_idmp_Request },
597   {   4, &hf_idmp_idm_result     , BER_CLASS_CON, 4, 0, dissect_idmp_IdmResult },
598   {   5, &hf_idmp_idm_error      , BER_CLASS_CON, 5, 0, dissect_idmp_Error },
599   {   6, &hf_idmp_reject         , BER_CLASS_CON, 6, 0, dissect_idmp_IdmReject },
600   {   7, &hf_idmp_unbind         , BER_CLASS_CON, 7, 0, dissect_idmp_Unbind },
601   {   8, &hf_idmp_abort          , BER_CLASS_CON, 8, 0, dissect_idmp_Abort },
602   {   9, &hf_idmp_startTLS       , BER_CLASS_CON, 9, 0, dissect_idmp_StartTLS },
603   {  10, &hf_idmp_tLSResponse    , BER_CLASS_CON, 10, 0, dissect_idmp_TLSResponse },
604   { 0, NULL, 0, 0, 0, NULL }
605 };
606
607 static int
608 dissect_idmp_IDM_PDU(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
609   offset = dissect_ber_choice(actx, tree, tvb, offset,
610                                  IDM_PDU_choice, hf_index, ett_idmp_IDM_PDU,
611                                  NULL);
612
613   return offset;
614 }
615
616
617 /*--- End of included file: packet-idmp-fn.c ---*/
618 #line 137 "packet-idmp-template.c"
619
620 void
621 register_idmp_protocol_info(const char *oid, const ros_info_t *rinfo, int proto _U_, const char *name)
622 {
623         /* just register with ROS for now */
624         register_ros_protocol_info(oid, rinfo, proto, name, FALSE);
625 }
626
627
628 static int dissect_idmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
629 {
630         int offset = 0;
631
632         proto_item *item=NULL;
633         proto_tree *tree=NULL;
634         asn1_ctx_t asn1_ctx;
635         void *save_private_data;
636         struct SESSION_DATA_STRUCTURE session;
637         gboolean        idmp_final;
638         guint32         idmp_length;
639         fragment_data *fd_head;
640         conversation_t *conv;
641         guint32         dst_ref;
642
643         asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
644
645     conv = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst,
646                                 pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
647     if (conv) {
648        /* Found a conversation, also use index for the generated dst_ref */
649        dst_ref = conv->index;
650     }
651
652         /* save parent_tree so subdissectors can create new top nodes */
653         top_tree=parent_tree;
654
655         if(parent_tree){
656                 item = proto_tree_add_item(parent_tree, proto_idmp, tvb, 0, -1, FALSE);
657                 tree = proto_item_add_subtree(item, ett_idmp);
658         }
659
660         col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDMP");
661
662         /* now check the segment fields */
663
664         proto_tree_add_item(tree, hf_idmp_version, tvb, offset, 1, FALSE); offset++;
665         proto_tree_add_item(tree, hf_idmp_final, tvb, offset, 1, FALSE); 
666         idmp_final = tvb_get_guint8(tvb, offset); offset++;
667         proto_tree_add_item(tree, hf_idmp_length, tvb, offset, 4, FALSE); 
668         idmp_length = tvb_get_ntohl(tvb, offset); offset += 4;
669
670         if(idmp_reassemble) {
671
672                 pinfo->fragmented = !idmp_final;
673
674                 if (check_col(pinfo->cinfo, COL_INFO))
675                         col_append_fstr(pinfo->cinfo, COL_INFO, " [%sIDMP fragment, %u byte%s]", 
676                                 idmp_final ? "Final " : "" ,
677                                 idmp_length, plurality(idmp_length, "", "s"));
678
679                 fd_head = fragment_add_seq_next(tvb, offset, pinfo, dst_ref,
680                         idmp_segment_table, idmp_reassembled_table,
681                         idmp_length, !idmp_final);
682
683                 if(fd_head && fd_head->next) {
684                         proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0,
685                           "IDMP segment data (%u byte%s)", idmp_length,
686                           plurality(idmp_length, "", "s"));     
687
688                         if (idmp_final) {
689                         /* This is the last segment */
690                                 tvb = process_reassembled_data (tvb, offset, pinfo,
691                                 "Reassembled IDMP", fd_head, &idmp_frag_items, NULL, tree);
692                                 offset = 0;
693                         } else if (pinfo->fd->num != fd_head->reassembled_in) {
694                                 /* Add a "Reassembled in" link if not reassembled in this frame */
695                                 proto_tree_add_uint (tree, hf_idmp_reassembled_in,
696                                 tvb, 0, 0, fd_head->reassembled_in);
697                         }
698                 }
699         
700         } else { 
701                 if(!idmp_final) {
702
703                         if (check_col(pinfo->cinfo, COL_INFO))
704                                 col_append_fstr(pinfo->cinfo, COL_INFO, " [IDMP fragment, %u byte%s, IDMP reassembly not enabled]", 
705                                         idmp_length, plurality(idmp_length, "", "s"));
706
707                         proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0,
708                                 "IDMP segment data (%u byte%s) (IDMP reassembly not enabled)", idmp_length,
709                                 plurality(idmp_length, "", "s"));               
710                 }
711         }
712         /* not reassembling - just dissect */
713         if(idmp_final) {
714                 save_private_data = pinfo->private_data;
715                 pinfo->private_data = &session;
716
717                 offset = dissect_idmp_IDM_PDU(FALSE, tvb, offset, &asn1_ctx, tree, hf_idmp_PDU);
718
719                 pinfo->private_data = save_private_data;
720         } else {
721                 offset = tvb_length(tvb);
722         }
723
724         return offset;
725 }
726
727 static guint get_idmp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
728 {
729         guint32 len;
730
731         len = tvb_get_ntohl(tvb, offset + 2);
732
733         return len + 6;
734 }
735
736 static void dissect_idmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
737 {
738
739         tcp_dissect_pdus(tvb, pinfo, parent_tree, idmp_desegment, 0, get_idmp_pdu_len, dissect_idmp);
740
741 }
742
743 static void idmp_reassemble_init (void)
744 {
745         fragment_table_init (&idmp_segment_table);
746         reassembled_table_init (&idmp_reassembled_table);
747
748         saved_protocolID = NULL;
749 }
750
751 /*--- proto_register_idmp -------------------------------------------*/
752 void proto_register_idmp(void) {
753
754   /* List of fields */
755   static hf_register_info hf[] =
756   {
757         { &hf_idmp_version,
758       { "version", "idmp.version",
759         FT_INT8, BASE_DEC, NULL, 0,
760         "idmp.INTEGER", HFILL }},
761         { &hf_idmp_final,
762       { "final", "idmp.final",
763         FT_BOOLEAN, 8, NULL, 0,
764         "idmp.BOOLEAN", HFILL }},
765         { &hf_idmp_length,
766       { "length", "idmp.length",
767         FT_INT32, BASE_DEC, NULL, 0,
768         "idmp.INTEGER", HFILL }},
769         { &hf_idmp_PDU,
770       { "IDM-PDU", "idmp.pdu",
771         FT_UINT32, BASE_DEC, VALS(idmp_IDM_PDU_vals), 0,
772         "idmp.PDU", HFILL }},
773     /* Fragment entries */
774     { &hf_idmp_fragments,
775       { "IDMP fragments", "idmp.fragments", FT_NONE, BASE_NONE,
776         NULL, 0x00, "Message fragments", HFILL } },
777     { &hf_idmp_fragment,
778       { "IDMP fragment", "idmp.fragment", FT_FRAMENUM, BASE_NONE,
779         NULL, 0x00, "Message fragment", HFILL } },
780     { &hf_idmp_fragment_overlap,
781       { "IDMP fragment overlap", "idmp.fragment.overlap", FT_BOOLEAN,
782         BASE_NONE, NULL, 0x00, "Message fragment overlap", HFILL } },
783     { &hf_idmp_fragment_overlap_conflicts,
784       { "IDMP fragment overlapping with conflicting data",
785         "idmp.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE, NULL,
786         0x00, "Message fragment overlapping with conflicting data", HFILL } },
787     { &hf_idmp_fragment_multiple_tails,
788       { "IDMP has multiple tail fragments",
789         "idmp.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE,
790         NULL, 0x00, "Message has multiple tail fragments", HFILL } },
791     { &hf_idmp_fragment_too_long_fragment,
792       { "IDMP fragment too long", "idmp.fragment.too_long_fragment",
793         FT_BOOLEAN, BASE_NONE, NULL, 0x00, "Message fragment too long",
794         HFILL } },
795     { &hf_idmp_fragment_error,
796       { "IDMP defragmentation error", "idmp.fragment.error", FT_FRAMENUM,
797         BASE_NONE, NULL, 0x00, "Message defragmentation error", HFILL } },
798     { &hf_idmp_reassembled_in,
799       { "Reassembled IDMP in frame", "idmp.reassembled.in", FT_FRAMENUM, BASE_NONE,
800         NULL, 0x00, "This IDMP packet is reassembled in this frame", HFILL } },
801     { &hf_idmp_reassembled_length,
802       { "Reassembled IDMP length", "idmp.reassembled.length", FT_UINT32, BASE_DEC,
803         NULL, 0x00, "The total length of the reassembled payload", HFILL } },
804
805
806 /*--- Included file: packet-idmp-hfarr.c ---*/
807 #line 1 "packet-idmp-hfarr.c"
808     { &hf_idmp_bind,
809       { "bind", "idmp.bind",
810         FT_NONE, BASE_NONE, NULL, 0,
811         "IdmBind", HFILL }},
812     { &hf_idmp_bindResult,
813       { "bindResult", "idmp.bindResult",
814         FT_NONE, BASE_NONE, NULL, 0,
815         "IdmBindResult", HFILL }},
816     { &hf_idmp_bindError,
817       { "bindError", "idmp.bindError",
818         FT_NONE, BASE_NONE, NULL, 0,
819         "IdmBindError", HFILL }},
820     { &hf_idmp_request,
821       { "request", "idmp.request",
822         FT_NONE, BASE_NONE, NULL, 0,
823         NULL, HFILL }},
824     { &hf_idmp_idm_result,
825       { "result", "idmp.result",
826         FT_NONE, BASE_NONE, NULL, 0,
827         "IdmResult", HFILL }},
828     { &hf_idmp_idm_error,
829       { "error", "idmp.error",
830         FT_NONE, BASE_NONE, NULL, 0,
831         NULL, HFILL }},
832     { &hf_idmp_reject,
833       { "reject", "idmp.reject",
834         FT_NONE, BASE_NONE, NULL, 0,
835         "IdmReject", HFILL }},
836     { &hf_idmp_unbind,
837       { "unbind", "idmp.unbind",
838         FT_NONE, BASE_NONE, NULL, 0,
839         NULL, HFILL }},
840     { &hf_idmp_abort,
841       { "abort", "idmp.abort",
842         FT_UINT32, BASE_DEC, VALS(idmp_Abort_vals), 0,
843         NULL, HFILL }},
844     { &hf_idmp_startTLS,
845       { "startTLS", "idmp.startTLS",
846         FT_NONE, BASE_NONE, NULL, 0,
847         NULL, HFILL }},
848     { &hf_idmp_tLSResponse,
849       { "tLSResponse", "idmp.tLSResponse",
850         FT_UINT32, BASE_DEC, VALS(idmp_TLSResponse_vals), 0,
851         NULL, HFILL }},
852     { &hf_idmp_protocolID,
853       { "protocolID", "idmp.protocolID",
854         FT_OID, BASE_NONE, NULL, 0,
855         "OBJECT_IDENTIFIER", HFILL }},
856     { &hf_idmp_callingAETitle,
857       { "callingAETitle", "idmp.callingAETitle",
858         FT_UINT32, BASE_DEC, VALS(x509ce_GeneralName_vals), 0,
859         "GeneralName", HFILL }},
860     { &hf_idmp_calledAETitle,
861       { "calledAETitle", "idmp.calledAETitle",
862         FT_UINT32, BASE_DEC, VALS(x509ce_GeneralName_vals), 0,
863         "GeneralName", HFILL }},
864     { &hf_idmp_bind_argument,
865       { "argument", "idmp.argument",
866         FT_NONE, BASE_NONE, NULL, 0,
867         "Bind_argument", HFILL }},
868     { &hf_idmp_respondingAETitle,
869       { "respondingAETitle", "idmp.respondingAETitle",
870         FT_UINT32, BASE_DEC, VALS(x509ce_GeneralName_vals), 0,
871         "GeneralName", HFILL }},
872     { &hf_idmp_bind_result,
873       { "result", "idmp.result",
874         FT_NONE, BASE_NONE, NULL, 0,
875         "Bind_result", HFILL }},
876     { &hf_idmp_bind_errcode,
877       { "errcode", "idmp.errcode",
878         FT_NONE, BASE_NONE, NULL, 0,
879         "Bind_errcode", HFILL }},
880     { &hf_idmp_aETitleError,
881       { "aETitleError", "idmp.aETitleError",
882         FT_UINT32, BASE_DEC, VALS(idmp_T_aETitleError_vals), 0,
883         NULL, HFILL }},
884     { &hf_idmp_bind_error,
885       { "error", "idmp.error",
886         FT_NONE, BASE_NONE, NULL, 0,
887         "Bind_error", HFILL }},
888     { &hf_idmp_invokeID,
889       { "invokeID", "idmp.invokeID",
890         FT_INT32, BASE_DEC, NULL, 0,
891         "INTEGER", HFILL }},
892     { &hf_idmp_opcode,
893       { "opcode", "idmp.opcode",
894         FT_UINT32, BASE_DEC, VALS(idmp_Code_vals), 0,
895         "Code", HFILL }},
896     { &hf_idmp_argument,
897       { "argument", "idmp.argument",
898         FT_NONE, BASE_NONE, NULL, 0,
899         NULL, HFILL }},
900     { &hf_idmp_idm_invokeID,
901       { "invokeID", "idmp.invokeID",
902         FT_UINT32, BASE_DEC, VALS(idmp_InvokeId_vals), 0,
903         NULL, HFILL }},
904     { &hf_idmp_result,
905       { "result", "idmp.result",
906         FT_NONE, BASE_NONE, NULL, 0,
907         NULL, HFILL }},
908     { &hf_idmp_errcode,
909       { "errcode", "idmp.errcode",
910         FT_NONE, BASE_NONE, NULL, 0,
911         NULL, HFILL }},
912     { &hf_idmp_error,
913       { "error", "idmp.error",
914         FT_NONE, BASE_NONE, NULL, 0,
915         NULL, HFILL }},
916     { &hf_idmp_reason,
917       { "reason", "idmp.reason",
918         FT_UINT32, BASE_DEC, VALS(idmp_T_reason_vals), 0,
919         NULL, HFILL }},
920     { &hf_idmp_local,
921       { "local", "idmp.local",
922         FT_INT32, BASE_DEC, NULL, 0,
923         NULL, HFILL }},
924     { &hf_idmp_global,
925       { "global", "idmp.global",
926         FT_OID, BASE_NONE, NULL, 0,
927         "OBJECT_IDENTIFIER", HFILL }},
928     { &hf_idmp_present,
929       { "present", "idmp.present",
930         FT_INT32, BASE_DEC, NULL, 0,
931         "INTEGER", HFILL }},
932     { &hf_idmp_absent,
933       { "absent", "idmp.absent",
934         FT_NONE, BASE_NONE, NULL, 0,
935         NULL, HFILL }},
936
937 /*--- End of included file: packet-idmp-hfarr.c ---*/
938 #line 324 "packet-idmp-template.c"
939   };
940
941   /* List of subtrees */
942   static gint *ett[] = {
943     &ett_idmp,
944         &ett_idmp_fragment,
945     &ett_idmp_fragments,
946
947 /*--- Included file: packet-idmp-ettarr.c ---*/
948 #line 1 "packet-idmp-ettarr.c"
949     &ett_idmp_IDM_PDU,
950     &ett_idmp_IdmBind,
951     &ett_idmp_IdmBindResult,
952     &ett_idmp_IdmBindError,
953     &ett_idmp_Request,
954     &ett_idmp_IdmResult,
955     &ett_idmp_Error,
956     &ett_idmp_IdmReject,
957     &ett_idmp_Code,
958     &ett_idmp_InvokeId,
959
960 /*--- End of included file: packet-idmp-ettarr.c ---*/
961 #line 332 "packet-idmp-template.c"
962   };
963   module_t *idmp_module;
964
965   /* Register protocol */
966   proto_idmp = proto_register_protocol(PNAME, PSNAME, PFNAME);
967
968   /* Register fields and subtrees */
969   proto_register_field_array(proto_idmp, hf, array_length(hf));
970   proto_register_subtree_array(ett, array_length(ett));
971
972   register_dissector("idmp", dissect_idmp_tcp, proto_idmp);
973
974   register_init_routine (&idmp_reassemble_init);
975
976   /* Register our configuration options for IDMP, particularly our port */
977
978   idmp_module = prefs_register_protocol_subtree("OSI/X.500", proto_idmp, prefs_register_idmp);
979
980   prefs_register_bool_preference(idmp_module, "desegment_idmp_messages",
981     "Reassemble IDMP messages spanning multiple TCP segments",
982     "Whether the IDMP dissector should reassemble messages spanning multiple TCP segments."
983     " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
984     &idmp_desegment);
985
986     prefs_register_bool_preference(idmp_module, "reassemble",
987                                  "Reassemble segmented IDMP datagrams",
988                                  "Whether segmented IDMP datagrams should be reassembled."
989                                  " To use this option, you must also enable"
990                                  " \"Allow subdissectors to reassemble TCP streams\""
991                                  " in the TCP protocol settings.", &idmp_reassemble);
992   
993   prefs_register_uint_preference(idmp_module, "tcp.port", "IDMP TCP Port",
994                                  "Set the port for Internet Directly Mapped Protocol requests/responses",
995                                  10, &global_idmp_tcp_port);
996
997 }
998
999
1000 /*--- proto_reg_handoff_idm --- */
1001 void proto_reg_handoff_idm(void) {
1002
1003  /* remember the idm handler for change in preferences */
1004   idmp_handle = find_dissector(PFNAME);
1005
1006 }
1007
1008
1009 void prefs_register_idmp(void) {
1010
1011   /* de-register the old port */
1012   /* port 102 is registered by TPKT - don't undo this! */
1013   if(idmp_handle)
1014     dissector_delete("tcp.port", tcp_port, idmp_handle);
1015
1016   /* Set our port number for future use */
1017   tcp_port = global_idmp_tcp_port;
1018
1019   if((tcp_port > 0) && idmp_handle)
1020     dissector_add("tcp.port", global_idmp_tcp_port, idmp_handle);
1021
1022 }