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