Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-idmp.c
1 /* Do not modify this file. Changes will be overwritten.                      */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler       */
3 /* packet-idmp.c                                                              */
4 /* ../../tools/asn2wrs.py -b -L -p idmp -c ./idmp.cnf -s ./packet-idmp-template -D . -O ../../epan/dissectors IDMProtocolSpecification.asn CommonProtocolSpecification.asn */
5
6 /* Input file: packet-idmp-template.c */
7
8 #line 1 "../../asn1/idmp/packet-idmp-template.c"
9 /* packet-idmp.c
10  * Routines for X.519 Internet Directly Mapped Procotol (IDMP) packet dissection
11  * Graeme Lunt 2010
12  *
13  * Wireshark - Network traffic analyzer
14  * By Gerald Combs <gerald@wireshark.org>
15  * Copyright 1998 Gerald Combs
16  *
17  * This program is free software; you can redistribute it and/or
18  * modify it under the terms of the GNU General Public License
19  * as published by the Free Software Foundation; either version 2
20  * of the License, or (at your option) any later version.
21  *
22  * This program is distributed in the hope that it will be useful,
23  * but WITHOUT ANY WARRANTY; without even the implied warranty of
24  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
25  * GNU General Public License for more details.
26  *
27  * You should have received a copy of the GNU General Public License
28  * along with this program; if not, write to the Free Software
29  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
30  */
31
32 #include "config.h"
33
34 #include <glib.h>
35 #include <epan/packet.h>
36 #include <epan/prefs.h>
37 #include <epan/wmem/wmem.h>
38 #include <epan/reassemble.h>
39 #include <epan/conversation.h>
40 #include <epan/oids.h>
41 #include <epan/asn1.h>
42 #include <epan/ipproto.h>
43
44 #include <epan/dissectors/packet-tcp.h>
45
46 #include "packet-ber.h"
47 #include "packet-ros.h"
48 #include "packet-x509ce.h"
49
50 #include <epan/strutil.h>
51
52 #define PNAME  "X.519 Internet Directly Mapped Protocol"
53 #define PSNAME "IDMP"
54 #define PFNAME "idmp"
55
56 void proto_register_idmp(void);
57 void proto_reg_handoff_idm(void);
58 static void prefs_register_idmp(void); /* forward declaration for use in preferences registration */
59 void register_idmp_protocol_info(const char *oid, const ros_info_t *rinfo, int proto _U_, const char *name);
60
61 static gboolean           idmp_desegment       = TRUE;
62 static guint              global_idmp_tcp_port = 1102; /* made up for now */
63 static gboolean           idmp_reassemble      = TRUE;
64 static guint              tcp_port             = 0;
65 static dissector_handle_t idmp_handle          = NULL;
66
67 static proto_tree *top_tree         = NULL;
68 static const char *protocolID       = NULL;
69 static const char *saved_protocolID = NULL;
70 static guint32     opcode           = -1;
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 reassembly_table idmp_reassembly_table;
81
82 static int hf_idmp_fragments = -1;
83 static int hf_idmp_fragment = -1;
84 static int hf_idmp_fragment_overlap = -1;
85 static int hf_idmp_fragment_overlap_conflicts = -1;
86 static int hf_idmp_fragment_multiple_tails = -1;
87 static int hf_idmp_fragment_too_long_fragment = -1;
88 static int hf_idmp_fragment_error = -1;
89 static int hf_idmp_fragment_count = -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     &hf_idmp_fragment_count,
109     /* Reassembled in field */
110     &hf_idmp_reassembled_in,
111     /* Reassembled length field */
112     &hf_idmp_reassembled_length,
113     /* Reassembled data field */
114     NULL,
115     /* Tag */
116     "IDMP fragments"
117 };
118
119
120 static int call_idmp_oid_callback(tvbuff_t *tvb, int offset, packet_info *pinfo, int op, proto_tree *tree, struct SESSION_DATA_STRUCTURE *session)
121 {
122     if(session != 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 = wmem_strdup(wmem_file_scope(), 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, tree, session);
132     }
133
134     return offset;
135
136 }
137
138
139 /*--- Included file: packet-idmp-hf.c ---*/
140 #line 1 "../../asn1/idmp/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 "../../asn1/idmp/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 "../../asn1/idmp/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 "../../asn1/idmp/packet-idmp-template.c"
195
196
197 /*--- Included file: packet-idmp-fn.c ---*/
198 #line 1 "../../asn1/idmp/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         struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
213
214         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND | ROS_OP_ARGUMENT), top_tree, session);
215
216
217   return offset;
218 }
219
220
221 static const ber_sequence_t IdmBind_sequence[] = {
222   { &hf_idmp_protocolID     , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
223   { &hf_idmp_callingAETitle , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
224   { &hf_idmp_calledAETitle  , BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
225   { &hf_idmp_bind_argument  , BER_CLASS_CON, 2, 0, dissect_idmp_Bind_argument },
226   { NULL, 0, 0, 0, NULL }
227 };
228
229 static int
230 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_) {
231   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
232                                    IdmBind_sequence, hf_index, ett_idmp_IdmBind);
233
234   return offset;
235 }
236
237
238
239 static int
240 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_) {
241         struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
242
243         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND | ROS_OP_RESULT), top_tree, session);
244
245
246   return offset;
247 }
248
249
250 static const ber_sequence_t IdmBindResult_sequence[] = {
251   { &hf_idmp_protocolID     , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
252   { &hf_idmp_respondingAETitle, BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
253   { &hf_idmp_bind_result    , BER_CLASS_CON, 1, 0, dissect_idmp_Bind_result },
254   { NULL, 0, 0, 0, NULL }
255 };
256
257 static int
258 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_) {
259   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
260                                    IdmBindResult_sequence, hf_index, ett_idmp_IdmBindResult);
261
262   return offset;
263 }
264
265
266
267 static int
268 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_) {
269
270
271   return offset;
272 }
273
274
275 static const value_string idmp_T_aETitleError_vals[] = {
276   {   0, "callingAETitleNotAccepted" },
277   {   1, "calledAETitleNotRecognized" },
278   { 0, NULL }
279 };
280
281
282 static int
283 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_) {
284   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
285                                   NULL);
286
287   return offset;
288 }
289
290
291
292 static int
293 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_) {
294         struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
295
296         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND| ROS_OP_ERROR), top_tree, session);
297
298
299   return offset;
300 }
301
302
303 static const ber_sequence_t IdmBindError_sequence[] = {
304   { &hf_idmp_protocolID     , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
305   { &hf_idmp_bind_errcode   , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_Bind_errcode },
306   { &hf_idmp_respondingAETitle, BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
307   { &hf_idmp_aETitleError   , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_idmp_T_aETitleError },
308   { &hf_idmp_bind_error     , BER_CLASS_CON, 1, 0, dissect_idmp_Bind_error },
309   { NULL, 0, 0, 0, NULL }
310 };
311
312 static int
313 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_) {
314   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
315                                    IdmBindError_sequence, hf_index, ett_idmp_IdmBindError);
316
317   return offset;
318 }
319
320
321
322 static int
323 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_) {
324   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
325                                                 NULL);
326
327   return offset;
328 }
329
330
331
332 static int
333 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_) {
334   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
335                                                 &opcode);
336
337   return offset;
338 }
339
340
341 static const value_string idmp_Code_vals[] = {
342   {   0, "local" },
343   {   1, "global" },
344   { 0, NULL }
345 };
346
347 static const ber_choice_t Code_choice[] = {
348   {   0, &hf_idmp_local          , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_T_local },
349   {   1, &hf_idmp_global         , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
350   { 0, NULL, 0, 0, 0, NULL }
351 };
352
353 static int
354 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_) {
355   offset = dissect_ber_choice(actx, tree, tvb, offset,
356                                  Code_choice, hf_index, ett_idmp_Code,
357                                  NULL);
358
359   return offset;
360 }
361
362
363
364 static int
365 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_) {
366         struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
367
368         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_INVOKE | ROS_OP_ARGUMENT | opcode), top_tree, session);
369
370
371   return offset;
372 }
373
374
375 static const ber_sequence_t Request_sequence[] = {
376   { &hf_idmp_invokeID       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
377   { &hf_idmp_opcode         , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_Code },
378   { &hf_idmp_argument       , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_argument },
379   { NULL, 0, 0, 0, NULL }
380 };
381
382 static int
383 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_) {
384   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
385                                    Request_sequence, hf_index, ett_idmp_Request);
386
387   return offset;
388 }
389
390
391
392 static int
393 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_) {
394   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
395
396   return offset;
397 }
398
399
400 static const value_string idmp_InvokeId_vals[] = {
401   {   0, "present" },
402   {   1, "absent" },
403   { 0, NULL }
404 };
405
406 static const ber_choice_t InvokeId_choice[] = {
407   {   0, &hf_idmp_present        , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
408   {   1, &hf_idmp_absent         , BER_CLASS_UNI, BER_UNI_TAG_NULL, BER_FLAGS_NOOWNTAG, dissect_idmp_NULL },
409   { 0, NULL, 0, 0, 0, NULL }
410 };
411
412 static int
413 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_) {
414   offset = dissect_ber_choice(actx, tree, tvb, offset,
415                                  InvokeId_choice, hf_index, ett_idmp_InvokeId,
416                                  NULL);
417
418   return offset;
419 }
420
421
422
423 static int
424 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_) {
425         struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
426
427         return call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_INVOKE | ROS_OP_RESULT | opcode), top_tree, session);
428
429
430   return offset;
431 }
432
433
434 static const ber_sequence_t IdmResult_sequence[] = {
435   { &hf_idmp_idm_invokeID   , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_InvokeId },
436   { &hf_idmp_opcode         , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_Code },
437   { &hf_idmp_result         , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_result },
438   { NULL, 0, 0, 0, NULL }
439 };
440
441 static int
442 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_) {
443   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
444                                    IdmResult_sequence, hf_index, ett_idmp_IdmResult);
445
446   return offset;
447 }
448
449
450
451 static int
452 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_) {
453
454
455   return offset;
456 }
457
458
459
460 static int
461 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_) {
462
463
464   return offset;
465 }
466
467
468 static const ber_sequence_t Error_sequence[] = {
469   { &hf_idmp_invokeID       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
470   { &hf_idmp_errcode        , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_errcode },
471   { &hf_idmp_error          , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_error },
472   { NULL, 0, 0, 0, NULL }
473 };
474
475 static int
476 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_) {
477   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
478                                    Error_sequence, hf_index, ett_idmp_Error);
479
480   return offset;
481 }
482
483
484 static const value_string idmp_T_reason_vals[] = {
485   {   0, "mistypedPDU" },
486   {   1, "duplicateInvokeIDRequest" },
487   {   2, "unsupportedOperationRequest" },
488   {   3, "unknownOperationRequest" },
489   {   4, "mistypedArgumentRequest" },
490   {   5, "resourceLimitationRequest" },
491   {   6, "unknownInvokeIDResult" },
492   {   7, "mistypedResultRequest" },
493   {   8, "unknownInvokeIDError" },
494   {   9, "unknownError" },
495   {  10, "mistypedParameterError" },
496   { 0, NULL }
497 };
498
499
500 static int
501 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_) {
502   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
503                                   NULL);
504
505   return offset;
506 }
507
508
509 static const ber_sequence_t IdmReject_sequence[] = {
510   { &hf_idmp_invokeID       , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
511   { &hf_idmp_reason         , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_idmp_T_reason },
512   { NULL, 0, 0, 0, NULL }
513 };
514
515 static int
516 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_) {
517   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
518                                    IdmReject_sequence, hf_index, ett_idmp_IdmReject);
519
520   return offset;
521 }
522
523
524
525 static int
526 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_) {
527   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
528
529   return offset;
530 }
531
532
533 static const value_string idmp_Abort_vals[] = {
534   {   0, "mistypedPDU" },
535   {   1, "unboundRequest" },
536   {   2, "invalidPDU" },
537   {   3, "resourceLimitation" },
538   {   4, "connectionFailed" },
539   {   5, "invalidProtocol" },
540   {   6, "reasonNotSpecified" },
541   { 0, NULL }
542 };
543
544
545 static int
546 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_) {
547   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
548                                   NULL);
549
550   return offset;
551 }
552
553
554
555 static int
556 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_) {
557   offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
558
559   return offset;
560 }
561
562
563 static const value_string idmp_TLSResponse_vals[] = {
564   {   0, "success" },
565   {   1, "operationsError" },
566   {   2, "protocolError" },
567   {   3, "unavailable" },
568   { 0, NULL }
569 };
570
571
572 static int
573 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_) {
574   offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
575                                   NULL);
576
577   return offset;
578 }
579
580
581 static const value_string idmp_IDM_PDU_vals[] = {
582   {   0, "bind" },
583   {   1, "bindResult" },
584   {   2, "bindError" },
585   {   3, "request" },
586   {   4, "result" },
587   {   5, "error" },
588   {   6, "reject" },
589   {   7, "unbind" },
590   {   8, "abort" },
591   {   9, "startTLS" },
592   {  10, "tLSResponse" },
593   { 0, NULL }
594 };
595
596 static const ber_choice_t IDM_PDU_choice[] = {
597   {   0, &hf_idmp_bind           , BER_CLASS_CON, 0, 0, dissect_idmp_IdmBind },
598   {   1, &hf_idmp_bindResult     , BER_CLASS_CON, 1, 0, dissect_idmp_IdmBindResult },
599   {   2, &hf_idmp_bindError      , BER_CLASS_CON, 2, 0, dissect_idmp_IdmBindError },
600   {   3, &hf_idmp_request        , BER_CLASS_CON, 3, 0, dissect_idmp_Request },
601   {   4, &hf_idmp_idm_result     , BER_CLASS_CON, 4, 0, dissect_idmp_IdmResult },
602   {   5, &hf_idmp_idm_error      , BER_CLASS_CON, 5, 0, dissect_idmp_Error },
603   {   6, &hf_idmp_reject         , BER_CLASS_CON, 6, 0, dissect_idmp_IdmReject },
604   {   7, &hf_idmp_unbind         , BER_CLASS_CON, 7, 0, dissect_idmp_Unbind },
605   {   8, &hf_idmp_abort          , BER_CLASS_CON, 8, 0, dissect_idmp_Abort },
606   {   9, &hf_idmp_startTLS       , BER_CLASS_CON, 9, 0, dissect_idmp_StartTLS },
607   {  10, &hf_idmp_tLSResponse    , BER_CLASS_CON, 10, 0, dissect_idmp_TLSResponse },
608   { 0, NULL, 0, 0, 0, NULL }
609 };
610
611 static int
612 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_) {
613   offset = dissect_ber_choice(actx, tree, tvb, offset,
614                                  IDM_PDU_choice, hf_index, ett_idmp_IDM_PDU,
615                                  NULL);
616
617   return offset;
618 }
619
620
621 /*--- End of included file: packet-idmp-fn.c ---*/
622 #line 137 "../../asn1/idmp/packet-idmp-template.c"
623
624 void
625 register_idmp_protocol_info(const char *oid, const ros_info_t *rinfo, int proto _U_, const char *name)
626 {
627     /* just register with ROS for now */
628     register_ros_protocol_info(oid, rinfo, proto, name, FALSE);
629 }
630
631
632 static int dissect_idmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
633 {
634     int offset = 0;
635
636     proto_item                    *item;
637     proto_tree                    *tree;
638     asn1_ctx_t                     asn1_ctx;
639     struct SESSION_DATA_STRUCTURE  session;
640     gboolean                       idmp_final;
641     guint32                        idmp_length;
642     fragment_head                 *fd_head;
643     conversation_t                *conv;
644     guint32                        dst_ref = 0;
645
646     asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
647
648     conv = find_conversation (pinfo->fd->num, &pinfo->src, &pinfo->dst,
649                               pinfo->ptype, pinfo->srcport, pinfo->destport, 0);
650     if (conv) {
651         /* Found a conversation, also use index for the generated dst_ref */
652         dst_ref = conv->index;
653     }
654
655     /* save parent_tree so subdissectors can create new top nodes */
656     top_tree=parent_tree;
657
658     item = proto_tree_add_item(parent_tree, proto_idmp, tvb, 0, -1, ENC_NA);
659     tree = proto_item_add_subtree(item, ett_idmp);
660
661     col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDMP");
662
663     /* now check the segment fields */
664
665     proto_tree_add_item(tree, hf_idmp_version, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
666     proto_tree_add_item(tree, hf_idmp_final, tvb, offset, 1, ENC_BIG_ENDIAN);
667     idmp_final = tvb_get_guint8(tvb, offset); offset++;
668     proto_tree_add_item(tree, hf_idmp_length, tvb, offset, 4, ENC_BIG_ENDIAN);
669     idmp_length = tvb_get_ntohl(tvb, offset); offset += 4;
670
671     asn1_ctx.private_data = &session;
672
673     if(idmp_reassemble) {
674
675         pinfo->fragmented = !idmp_final;
676
677         col_append_fstr(pinfo->cinfo, COL_INFO, " [%sIDMP fragment, %u byte%s]",
678                             idmp_final ? "Final " : "" ,
679                             idmp_length, plurality(idmp_length, "", "s"));
680
681         fd_head = fragment_add_seq_next(&idmp_reassembly_table, tvb, offset,
682                                         pinfo, dst_ref, NULL,
683                                         idmp_length, !idmp_final);
684
685         if(fd_head && fd_head->next) {
686             proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0,
687                                 "IDMP segment data (%u byte%s)", idmp_length,
688                                 plurality(idmp_length, "", "s"));
689
690             if (idmp_final) {
691                 /* This is the last segment */
692                 tvb = process_reassembled_data (tvb, offset, pinfo,
693                                                 "Reassembled IDMP", fd_head, &idmp_frag_items, NULL, tree);
694                 offset = 0;
695             } else if (pinfo->fd->num != fd_head->reassembled_in) {
696                 /* Add a "Reassembled in" link if not reassembled in this frame */
697                 proto_tree_add_uint (tree, hf_idmp_reassembled_in,
698                                      tvb, 0, 0, fd_head->reassembled_in);
699             }
700         }
701
702     } else {
703         if(!idmp_final) {
704
705             col_append_fstr(pinfo->cinfo, COL_INFO, " [IDMP fragment, %u byte%s, IDMP reassembly not enabled]",
706                                 idmp_length, plurality(idmp_length, "", "s"));
707
708             proto_tree_add_text(tree, tvb, offset, (idmp_length) ? -1 : 0,
709                                 "IDMP segment data (%u byte%s) (IDMP reassembly not enabled)", idmp_length,
710                                 plurality(idmp_length, "", "s"));
711         }
712     }
713     /* not reassembling - just dissect */
714     if(idmp_final) {
715         asn1_ctx.private_data = &session;
716         dissect_idmp_IDM_PDU(FALSE, tvb, offset, &asn1_ctx, tree, hf_idmp_PDU);
717     }
718
719     return tvb_length(tvb);
720 }
721
722 static guint get_idmp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset)
723 {
724     guint32 len;
725
726     len = tvb_get_ntohl(tvb, offset + 2);
727
728     return len + 6;
729 }
730
731 static int dissect_idmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data)
732 {
733     tcp_dissect_pdus(tvb, pinfo, parent_tree, idmp_desegment, 0, get_idmp_pdu_len, dissect_idmp, data);
734         return tvb_length(tvb);
735 }
736
737 static void idmp_reassemble_init (void)
738 {
739     reassembly_table_init (&idmp_reassembly_table,
740                            &addresses_reassembly_table_functions);
741
742     saved_protocolID = NULL;
743 }
744
745 /*--- proto_register_idmp -------------------------------------------*/
746 void proto_register_idmp(void)
747 {
748     /* List of fields */
749     static hf_register_info hf[] = {
750         { &hf_idmp_version,
751           { "version", "idmp.version",
752             FT_INT8, BASE_DEC, NULL, 0,
753             "idmp.INTEGER", HFILL }},
754         { &hf_idmp_final,
755           { "final", "idmp.final",
756             FT_BOOLEAN, BASE_NONE, NULL, 0,
757             "idmp.BOOLEAN", HFILL }},
758         { &hf_idmp_length,
759           { "length", "idmp.length",
760             FT_INT32, BASE_DEC, NULL, 0,
761             "idmp.INTEGER", HFILL }},
762         { &hf_idmp_PDU,
763           { "IDM-PDU", "idmp.pdu",
764             FT_UINT32, BASE_DEC, VALS(idmp_IDM_PDU_vals), 0,
765             "idmp.PDU", HFILL }},
766         /* Fragment entries */
767         { &hf_idmp_fragments,
768           { "IDMP fragments", "idmp.fragments", FT_NONE, BASE_NONE,
769             NULL, 0x00, NULL, HFILL } },
770         { &hf_idmp_fragment,
771           { "IDMP fragment", "idmp.fragment", FT_FRAMENUM, BASE_NONE,
772             NULL, 0x00, NULL, HFILL } },
773         { &hf_idmp_fragment_overlap,
774           { "IDMP fragment overlap", "idmp.fragment.overlap", FT_BOOLEAN,
775             BASE_NONE, NULL, 0x00, NULL, HFILL } },
776         { &hf_idmp_fragment_overlap_conflicts,
777           { "IDMP fragment overlapping with conflicting data",
778             "idmp.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE,
779             NULL, 0x00, NULL, HFILL } },
780         { &hf_idmp_fragment_multiple_tails,
781           { "IDMP has multiple tail fragments",
782             "idmp.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE,
783             NULL, 0x00, NULL, HFILL } },
784         { &hf_idmp_fragment_too_long_fragment,
785           { "IDMP fragment too long", "idmp.fragment.too_long_fragment",
786             FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } },
787         { &hf_idmp_fragment_error,
788           { "IDMP defragmentation error", "idmp.fragment.error", FT_FRAMENUM,
789             BASE_NONE, NULL, 0x00, NULL, HFILL } },
790         { &hf_idmp_fragment_count,
791           { "IDMP fragment count", "idmp.fragment.count", FT_UINT32, BASE_DEC,
792             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 "../../asn1/idmp/packet-idmp-hfarr.c"
803     { &hf_idmp_bind,
804       { "bind", "idmp.bind_element",
805         FT_NONE, BASE_NONE, NULL, 0,
806         "IdmBind", HFILL }},
807     { &hf_idmp_bindResult,
808       { "bindResult", "idmp.bindResult_element",
809         FT_NONE, BASE_NONE, NULL, 0,
810         "IdmBindResult", HFILL }},
811     { &hf_idmp_bindError,
812       { "bindError", "idmp.bindError_element",
813         FT_NONE, BASE_NONE, NULL, 0,
814         "IdmBindError", HFILL }},
815     { &hf_idmp_request,
816       { "request", "idmp.request_element",
817         FT_NONE, BASE_NONE, NULL, 0,
818         NULL, HFILL }},
819     { &hf_idmp_idm_result,
820       { "result", "idmp.result_element",
821         FT_NONE, BASE_NONE, NULL, 0,
822         "IdmResult", HFILL }},
823     { &hf_idmp_idm_error,
824       { "error", "idmp.error_element",
825         FT_NONE, BASE_NONE, NULL, 0,
826         NULL, HFILL }},
827     { &hf_idmp_reject,
828       { "reject", "idmp.reject_element",
829         FT_NONE, BASE_NONE, NULL, 0,
830         "IdmReject", HFILL }},
831     { &hf_idmp_unbind,
832       { "unbind", "idmp.unbind_element",
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_element",
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_element",
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_element",
869         FT_NONE, BASE_NONE, NULL, 0,
870         "Bind_result", HFILL }},
871     { &hf_idmp_bind_errcode,
872       { "errcode", "idmp.errcode_element",
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_element",
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_element",
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_element",
901         FT_NONE, BASE_NONE, NULL, 0,
902         NULL, HFILL }},
903     { &hf_idmp_errcode,
904       { "errcode", "idmp.errcode_element",
905         FT_NONE, BASE_NONE, NULL, 0,
906         NULL, HFILL }},
907     { &hf_idmp_error,
908       { "error", "idmp.error_element",
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_element",
929         FT_NONE, BASE_NONE, NULL, 0,
930         NULL, HFILL }},
931
932 /*--- End of included file: packet-idmp-hfarr.c ---*/
933 #line 315 "../../asn1/idmp/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 "../../asn1/idmp/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 323 "../../asn1/idmp/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     new_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 }