Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-idmp.c
blob8e2a2040d45dcbfe99cb0ab855a016e716649c9a
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 /* asn2wrs.py -b -q -L -p idmp -c ./idmp.cnf -s ./packet-idmp-template -D . -O ../.. IDMProtocolSpecification.asn CommonProtocolSpecification.asn */
6 /* packet-idmp.c
7 * Routines for X.519 Internet Directly Mapped Procotol (IDMP) packet dissection
8 * Graeme Lunt 2010
10 * Wireshark - Network traffic analyzer
11 * By Gerald Combs <gerald@wireshark.org>
12 * Copyright 1998 Gerald Combs
14 * SPDX-License-Identifier: GPL-2.0-or-later
17 #include "config.h"
19 #include <epan/packet.h>
20 #include <epan/prefs.h>
21 #include <epan/reassemble.h>
22 #include <epan/conversation.h>
23 #include <epan/oids.h>
24 #include <epan/asn1.h>
25 #include <epan/ipproto.h>
26 #include <epan/strutil.h>
28 #include <wsutil/str_util.h>
29 #include <wsutil/array.h>
31 #include "packet-tcp.h"
33 #include "packet-ber.h"
34 #include "packet-ros.h"
35 #include "packet-x509ce.h"
38 #define PNAME "X.519 Internet Directly Mapped Protocol"
39 #define PSNAME "IDMP"
40 #define PFNAME "idmp"
42 void proto_register_idmp(void);
43 void proto_reg_handoff_idm(void);
44 void register_idmp_protocol_info(const char *oid, const ros_info_t *rinfo, int proto _U_, const char *name);
46 static bool idmp_desegment = true;
47 #define IDMP_TCP_PORT 1102 /* made up for now - not IANA registered */
48 static bool idmp_reassemble = true;
49 static dissector_handle_t idmp_handle;
51 static proto_tree *top_tree;
52 static const char *protocolID;
53 static const char *saved_protocolID;
54 static uint32_t opcode = -1;
56 /* Initialize the protocol and registered fields */
57 int proto_idmp;
59 static int hf_idmp_version;
60 static int hf_idmp_final;
61 static int hf_idmp_length;
62 static int hf_idmp_PDU;
64 static reassembly_table idmp_reassembly_table;
66 static int hf_idmp_fragments;
67 static int hf_idmp_fragment;
68 static int hf_idmp_fragment_overlap;
69 static int hf_idmp_fragment_overlap_conflicts;
70 static int hf_idmp_fragment_multiple_tails;
71 static int hf_idmp_fragment_too_long_fragment;
72 static int hf_idmp_fragment_error;
73 static int hf_idmp_fragment_count;
74 static int hf_idmp_reassembled_in;
75 static int hf_idmp_reassembled_length;
76 static int hf_idmp_segment_data;
78 static int ett_idmp_fragment;
79 static int ett_idmp_fragments;
81 static const fragment_items idmp_frag_items = {
82 /* Fragment subtrees */
83 &ett_idmp_fragment,
84 &ett_idmp_fragments,
85 /* Fragment fields */
86 &hf_idmp_fragments,
87 &hf_idmp_fragment,
88 &hf_idmp_fragment_overlap,
89 &hf_idmp_fragment_overlap_conflicts,
90 &hf_idmp_fragment_multiple_tails,
91 &hf_idmp_fragment_too_long_fragment,
92 &hf_idmp_fragment_error,
93 &hf_idmp_fragment_count,
94 /* Reassembled in field */
95 &hf_idmp_reassembled_in,
96 /* Reassembled length field */
97 &hf_idmp_reassembled_length,
98 /* Reassembled data field */
99 NULL,
100 /* Tag */
101 "IDMP fragments"
105 static int call_idmp_oid_callback(tvbuff_t *tvb, int offset, packet_info *pinfo, int op, proto_tree *tree, struct SESSION_DATA_STRUCTURE *session)
107 if(session != NULL) {
109 /* XXX saved_protocolID should be part of session data */
110 if (!saved_protocolID) {
111 saved_protocolID = "[ unknown ]";
114 /* mimic ROS! */
115 session->ros_op = op;
116 offset = call_ros_oid_callback(saved_protocolID, tvb, offset, pinfo, tree, session);
119 return offset;
123 static int hf_idmp_bind; /* IdmBind */
124 static int hf_idmp_bindResult; /* IdmBindResult */
125 static int hf_idmp_bindError; /* IdmBindError */
126 static int hf_idmp_request; /* Request */
127 static int hf_idmp_idm_result; /* IdmResult */
128 static int hf_idmp_idm_error; /* Error */
129 static int hf_idmp_reject; /* IdmReject */
130 static int hf_idmp_unbind; /* Unbind */
131 static int hf_idmp_abort; /* Abort */
132 static int hf_idmp_startTLS; /* StartTLS */
133 static int hf_idmp_tLSResponse; /* TLSResponse */
134 static int hf_idmp_protocolID; /* OBJECT_IDENTIFIER */
135 static int hf_idmp_callingAETitle; /* GeneralName */
136 static int hf_idmp_calledAETitle; /* GeneralName */
137 static int hf_idmp_bind_argument; /* Bind_argument */
138 static int hf_idmp_respondingAETitle; /* GeneralName */
139 static int hf_idmp_bind_result; /* Bind_result */
140 static int hf_idmp_bind_errcode; /* Bind_errcode */
141 static int hf_idmp_aETitleError; /* T_aETitleError */
142 static int hf_idmp_bind_error; /* Bind_error */
143 static int hf_idmp_invokeID; /* INTEGER */
144 static int hf_idmp_opcode; /* Code */
145 static int hf_idmp_argument; /* T_argument */
146 static int hf_idmp_idm_invokeID; /* InvokeId */
147 static int hf_idmp_result; /* T_result */
148 static int hf_idmp_errcode; /* T_errcode */
149 static int hf_idmp_error; /* T_error */
150 static int hf_idmp_reason; /* T_reason */
151 static int hf_idmp_local; /* T_local */
152 static int hf_idmp_global; /* OBJECT_IDENTIFIER */
153 static int hf_idmp_present; /* INTEGER */
154 static int hf_idmp_absent; /* NULL */
156 /* Initialize the subtree pointers */
157 static int ett_idmp;
158 static int ett_idmp_IDM_PDU;
159 static int ett_idmp_IdmBind;
160 static int ett_idmp_IdmBindResult;
161 static int ett_idmp_IdmBindError;
162 static int ett_idmp_Request;
163 static int ett_idmp_IdmResult;
164 static int ett_idmp_Error;
165 static int ett_idmp_IdmReject;
166 static int ett_idmp_Code;
167 static int ett_idmp_InvokeId;
171 static int
172 dissect_idmp_OBJECT_IDENTIFIER(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
173 offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &protocolID);
175 return offset;
180 static int
181 dissect_idmp_Bind_argument(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
182 struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
183 offset = call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND | ROS_OP_ARGUMENT), top_tree, session);
186 return offset;
190 static const ber_sequence_t IdmBind_sequence[] = {
191 { &hf_idmp_protocolID , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
192 { &hf_idmp_callingAETitle , BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
193 { &hf_idmp_calledAETitle , BER_CLASS_CON, 1, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
194 { &hf_idmp_bind_argument , BER_CLASS_CON, 2, 0, dissect_idmp_Bind_argument },
195 { NULL, 0, 0, 0, NULL }
198 static int
199 dissect_idmp_IdmBind(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
200 protocolID = saved_protocolID = NULL;
201 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
202 IdmBind_sequence, hf_index, ett_idmp_IdmBind);
204 if (protocolID) {
205 saved_protocolID = wmem_strdup(wmem_epan_scope(), protocolID);
207 return offset;
212 static int
213 dissect_idmp_Bind_result(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
214 struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
215 offset = call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND | ROS_OP_RESULT), top_tree, session);
218 return offset;
222 static const ber_sequence_t IdmBindResult_sequence[] = {
223 { &hf_idmp_protocolID , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
224 { &hf_idmp_respondingAETitle, BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
225 { &hf_idmp_bind_result , BER_CLASS_CON, 1, 0, dissect_idmp_Bind_result },
226 { NULL, 0, 0, 0, NULL }
229 static int
230 dissect_idmp_IdmBindResult(bool 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 IdmBindResult_sequence, hf_index, ett_idmp_IdmBindResult);
234 return offset;
239 static int
240 dissect_idmp_Bind_errcode(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
243 return offset;
247 static const value_string idmp_T_aETitleError_vals[] = {
248 { 0, "callingAETitleNotAccepted" },
249 { 1, "calledAETitleNotRecognized" },
250 { 0, NULL }
254 static int
255 dissect_idmp_T_aETitleError(bool 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_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
257 NULL);
259 return offset;
264 static int
265 dissect_idmp_Bind_error(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
266 struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
267 offset = call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_BIND| ROS_OP_ERROR), top_tree, session);
270 return offset;
274 static const ber_sequence_t IdmBindError_sequence[] = {
275 { &hf_idmp_protocolID , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
276 { &hf_idmp_bind_errcode , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_Bind_errcode },
277 { &hf_idmp_respondingAETitle, BER_CLASS_CON, 0, BER_FLAGS_OPTIONAL, dissect_x509ce_GeneralName },
278 { &hf_idmp_aETitleError , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_OPTIONAL|BER_FLAGS_NOOWNTAG, dissect_idmp_T_aETitleError },
279 { &hf_idmp_bind_error , BER_CLASS_CON, 1, 0, dissect_idmp_Bind_error },
280 { NULL, 0, 0, 0, NULL }
283 static int
284 dissect_idmp_IdmBindError(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
285 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
286 IdmBindError_sequence, hf_index, ett_idmp_IdmBindError);
288 return offset;
293 static int
294 dissect_idmp_INTEGER(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
295 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
296 NULL);
298 return offset;
303 static int
304 dissect_idmp_T_local(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
305 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
306 &opcode);
308 return offset;
312 static const value_string idmp_Code_vals[] = {
313 { 0, "local" },
314 { 1, "global" },
315 { 0, NULL }
318 static const ber_choice_t Code_choice[] = {
319 { 0, &hf_idmp_local , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_T_local },
320 { 1, &hf_idmp_global , BER_CLASS_UNI, BER_UNI_TAG_OID, BER_FLAGS_NOOWNTAG, dissect_idmp_OBJECT_IDENTIFIER },
321 { 0, NULL, 0, 0, 0, NULL }
324 static int
325 dissect_idmp_Code(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
326 offset = dissect_ber_choice(actx, tree, tvb, offset,
327 Code_choice, hf_index, ett_idmp_Code,
328 NULL);
330 return offset;
335 static int
336 dissect_idmp_T_argument(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
337 struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
338 offset = call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_INVOKE | ROS_OP_ARGUMENT | opcode), top_tree, session);
341 return offset;
345 static const ber_sequence_t Request_sequence[] = {
346 { &hf_idmp_invokeID , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
347 { &hf_idmp_opcode , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_Code },
348 { &hf_idmp_argument , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_argument },
349 { NULL, 0, 0, 0, NULL }
352 static int
353 dissect_idmp_Request(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
354 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
355 Request_sequence, hf_index, ett_idmp_Request);
357 return offset;
362 static int
363 dissect_idmp_NULL(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
364 offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
366 return offset;
370 static const value_string idmp_InvokeId_vals[] = {
371 { 0, "present" },
372 { 1, "absent" },
373 { 0, NULL }
376 static const ber_choice_t InvokeId_choice[] = {
377 { 0, &hf_idmp_present , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
378 { 1, &hf_idmp_absent , BER_CLASS_UNI, BER_UNI_TAG_NULL, BER_FLAGS_NOOWNTAG, dissect_idmp_NULL },
379 { 0, NULL, 0, 0, 0, NULL }
382 static int
383 dissect_idmp_InvokeId(bool 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_choice(actx, tree, tvb, offset,
385 InvokeId_choice, hf_index, ett_idmp_InvokeId,
386 NULL);
388 return offset;
393 static int
394 dissect_idmp_T_result(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
395 struct SESSION_DATA_STRUCTURE *session = (struct SESSION_DATA_STRUCTURE*)actx->private_data;
396 offset = call_idmp_oid_callback(tvb, offset, actx->pinfo, (ROS_OP_INVOKE | ROS_OP_RESULT | opcode), top_tree, session);
399 return offset;
403 static const ber_sequence_t IdmResult_sequence[] = {
404 { &hf_idmp_idm_invokeID , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_InvokeId },
405 { &hf_idmp_opcode , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_idmp_Code },
406 { &hf_idmp_result , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_result },
407 { NULL, 0, 0, 0, NULL }
410 static int
411 dissect_idmp_IdmResult(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
412 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
413 IdmResult_sequence, hf_index, ett_idmp_IdmResult);
415 return offset;
420 static int
421 dissect_idmp_T_errcode(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
424 return offset;
429 static int
430 dissect_idmp_T_error(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
433 return offset;
437 static const ber_sequence_t Error_sequence[] = {
438 { &hf_idmp_invokeID , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
439 { &hf_idmp_errcode , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_errcode },
440 { &hf_idmp_error , BER_CLASS_ANY, 0, BER_FLAGS_NOOWNTAG, dissect_idmp_T_error },
441 { NULL, 0, 0, 0, NULL }
444 static int
445 dissect_idmp_Error(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
446 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
447 Error_sequence, hf_index, ett_idmp_Error);
449 return offset;
453 static const value_string idmp_T_reason_vals[] = {
454 { 0, "mistypedPDU" },
455 { 1, "duplicateInvokeIDRequest" },
456 { 2, "unsupportedOperationRequest" },
457 { 3, "unknownOperationRequest" },
458 { 4, "mistypedArgumentRequest" },
459 { 5, "resourceLimitationRequest" },
460 { 6, "unknownInvokeIDResult" },
461 { 7, "mistypedResultRequest" },
462 { 8, "unknownInvokeIDError" },
463 { 9, "unknownError" },
464 { 10, "mistypedParameterError" },
465 { 0, NULL }
469 static int
470 dissect_idmp_T_reason(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
471 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
472 NULL);
474 return offset;
478 static const ber_sequence_t IdmReject_sequence[] = {
479 { &hf_idmp_invokeID , BER_CLASS_UNI, BER_UNI_TAG_INTEGER, BER_FLAGS_NOOWNTAG, dissect_idmp_INTEGER },
480 { &hf_idmp_reason , BER_CLASS_UNI, BER_UNI_TAG_ENUMERATED, BER_FLAGS_NOOWNTAG, dissect_idmp_T_reason },
481 { NULL, 0, 0, 0, NULL }
484 static int
485 dissect_idmp_IdmReject(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
486 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
487 IdmReject_sequence, hf_index, ett_idmp_IdmReject);
489 return offset;
494 static int
495 dissect_idmp_Unbind(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
496 offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
498 return offset;
502 static const value_string idmp_Abort_vals[] = {
503 { 0, "mistypedPDU" },
504 { 1, "unboundRequest" },
505 { 2, "invalidPDU" },
506 { 3, "resourceLimitation" },
507 { 4, "connectionFailed" },
508 { 5, "invalidProtocol" },
509 { 6, "reasonNotSpecified" },
510 { 0, NULL }
514 static int
515 dissect_idmp_Abort(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
516 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
517 NULL);
519 return offset;
524 static int
525 dissect_idmp_StartTLS(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
526 offset = dissect_ber_null(implicit_tag, actx, tree, tvb, offset, hf_index);
528 return offset;
532 static const value_string idmp_TLSResponse_vals[] = {
533 { 0, "success" },
534 { 1, "operationsError" },
535 { 2, "protocolError" },
536 { 3, "unavailable" },
537 { 0, NULL }
541 static int
542 dissect_idmp_TLSResponse(bool 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);
546 return offset;
550 static const value_string idmp_IDM_PDU_vals[] = {
551 { 0, "bind" },
552 { 1, "bindResult" },
553 { 2, "bindError" },
554 { 3, "request" },
555 { 4, "result" },
556 { 5, "error" },
557 { 6, "reject" },
558 { 7, "unbind" },
559 { 8, "abort" },
560 { 9, "startTLS" },
561 { 10, "tLSResponse" },
562 { 0, NULL }
565 static const ber_choice_t IDM_PDU_choice[] = {
566 { 0, &hf_idmp_bind , BER_CLASS_CON, 0, 0, dissect_idmp_IdmBind },
567 { 1, &hf_idmp_bindResult , BER_CLASS_CON, 1, 0, dissect_idmp_IdmBindResult },
568 { 2, &hf_idmp_bindError , BER_CLASS_CON, 2, 0, dissect_idmp_IdmBindError },
569 { 3, &hf_idmp_request , BER_CLASS_CON, 3, 0, dissect_idmp_Request },
570 { 4, &hf_idmp_idm_result , BER_CLASS_CON, 4, 0, dissect_idmp_IdmResult },
571 { 5, &hf_idmp_idm_error , BER_CLASS_CON, 5, 0, dissect_idmp_Error },
572 { 6, &hf_idmp_reject , BER_CLASS_CON, 6, 0, dissect_idmp_IdmReject },
573 { 7, &hf_idmp_unbind , BER_CLASS_CON, 7, 0, dissect_idmp_Unbind },
574 { 8, &hf_idmp_abort , BER_CLASS_CON, 8, 0, dissect_idmp_Abort },
575 { 9, &hf_idmp_startTLS , BER_CLASS_CON, 9, 0, dissect_idmp_StartTLS },
576 { 10, &hf_idmp_tLSResponse , BER_CLASS_CON, 10, 0, dissect_idmp_TLSResponse },
577 { 0, NULL, 0, 0, 0, NULL }
580 static int
581 dissect_idmp_IDM_PDU(bool implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
582 offset = dissect_ber_choice(actx, tree, tvb, offset,
583 IDM_PDU_choice, hf_index, ett_idmp_IDM_PDU,
584 NULL);
586 return offset;
590 void
591 register_idmp_protocol_info(const char *oid, const ros_info_t *rinfo, int proto _U_, const char *name)
593 /* just register with ROS for now */
594 register_ros_protocol_info(oid, rinfo, proto, name, false);
598 static int dissect_idmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
600 int offset = 0;
602 proto_item *item;
603 proto_tree *tree;
604 asn1_ctx_t asn1_ctx;
605 struct SESSION_DATA_STRUCTURE session;
606 bool idmp_final;
607 uint32_t idmp_length;
608 fragment_head *fd_head;
609 conversation_t *conv;
610 uint32_t dst_ref = 0;
612 asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, true, pinfo);
614 conv = find_conversation_pinfo(pinfo, 0);
615 if (conv) {
616 /* Found a conversation, also use index for the generated dst_ref */
617 dst_ref = conv->conv_index;
620 /* save parent_tree so subdissectors can create new top nodes */
621 top_tree=parent_tree;
623 item = proto_tree_add_item(parent_tree, proto_idmp, tvb, 0, -1, ENC_NA);
624 tree = proto_item_add_subtree(item, ett_idmp);
626 col_set_str(pinfo->cinfo, COL_PROTOCOL, "IDMP");
628 /* now check the segment fields */
630 proto_tree_add_item(tree, hf_idmp_version, tvb, offset, 1, ENC_BIG_ENDIAN); offset++;
631 proto_tree_add_item(tree, hf_idmp_final, tvb, offset, 1, ENC_BIG_ENDIAN);
632 idmp_final = tvb_get_uint8(tvb, offset); offset++;
633 proto_tree_add_item(tree, hf_idmp_length, tvb, offset, 4, ENC_BIG_ENDIAN);
634 idmp_length = tvb_get_ntohl(tvb, offset); offset += 4;
636 asn1_ctx.private_data = &session;
638 if(idmp_reassemble) {
640 pinfo->fragmented = !idmp_final;
642 col_append_fstr(pinfo->cinfo, COL_INFO, " [%sIDMP fragment, %u byte%s]",
643 idmp_final ? "Final " : "" ,
644 idmp_length, plurality(idmp_length, "", "s"));
646 fd_head = fragment_add_seq_next(&idmp_reassembly_table, tvb, offset,
647 pinfo, dst_ref, NULL,
648 idmp_length, !idmp_final);
650 if(fd_head && fd_head->next) {
651 proto_tree_add_item(tree, hf_idmp_segment_data, tvb, offset, (idmp_length) ? -1 : 0, ENC_NA);
653 if (idmp_final) {
654 /* This is the last segment */
655 tvb = process_reassembled_data (tvb, offset, pinfo,
656 "Reassembled IDMP", fd_head, &idmp_frag_items, NULL, tree);
657 offset = 0;
658 } else if (pinfo->num != fd_head->reassembled_in) {
659 /* Add a "Reassembled in" link if not reassembled in this frame */
660 proto_tree_add_uint (tree, hf_idmp_reassembled_in,
661 tvb, 0, 0, fd_head->reassembled_in);
665 } else {
666 if(!idmp_final) {
668 col_append_fstr(pinfo->cinfo, COL_INFO, " [IDMP fragment, %u byte%s, IDMP reassembly not enabled]",
669 idmp_length, plurality(idmp_length, "", "s"));
671 proto_tree_add_bytes_format_value(tree, hf_idmp_segment_data, tvb, offset, (idmp_length) ? -1 : 0,
672 NULL, "(IDMP reassembly not enabled)");
675 /* not reassembling - just dissect */
676 if(idmp_final) {
677 asn1_ctx.private_data = &session;
678 dissect_idmp_IDM_PDU(false, tvb, offset, &asn1_ctx, tree, hf_idmp_PDU);
681 return tvb_captured_length(tvb);
684 static unsigned get_idmp_pdu_len(packet_info *pinfo _U_, tvbuff_t *tvb,
685 int offset, void *data _U_)
687 uint32_t len;
689 len = tvb_get_ntohl(tvb, offset + 2);
691 return len + 6;
694 static int dissect_idmp_tcp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data)
696 tcp_dissect_pdus(tvb, pinfo, parent_tree, idmp_desegment, 0, get_idmp_pdu_len, dissect_idmp, data);
697 return tvb_captured_length(tvb);
700 static void idmp_reassemble_cleanup(void)
702 protocolID = NULL; // packet scoped
703 saved_protocolID = NULL; // epan scoped copy of protocolID
704 opcode = -1;
707 /*--- proto_register_idmp -------------------------------------------*/
708 void proto_register_idmp(void)
710 /* List of fields */
711 static hf_register_info hf[] = {
712 { &hf_idmp_version,
713 { "version", "idmp.version",
714 FT_INT8, BASE_DEC, NULL, 0,
715 "idmp.INTEGER", HFILL }},
716 { &hf_idmp_final,
717 { "final", "idmp.final",
718 FT_BOOLEAN, BASE_NONE, NULL, 0,
719 "idmp.BOOLEAN", HFILL }},
720 { &hf_idmp_length,
721 { "length", "idmp.length",
722 FT_INT32, BASE_DEC, NULL, 0,
723 "idmp.INTEGER", HFILL }},
724 { &hf_idmp_PDU,
725 { "IDM-PDU", "idmp.pdu",
726 FT_UINT32, BASE_DEC, VALS(idmp_IDM_PDU_vals), 0,
727 "idmp.PDU", HFILL }},
728 /* Fragment entries */
729 { &hf_idmp_fragments,
730 { "IDMP fragments", "idmp.fragments", FT_NONE, BASE_NONE,
731 NULL, 0x00, NULL, HFILL } },
732 { &hf_idmp_fragment,
733 { "IDMP fragment", "idmp.fragment", FT_FRAMENUM, BASE_NONE,
734 NULL, 0x00, NULL, HFILL } },
735 { &hf_idmp_fragment_overlap,
736 { "IDMP fragment overlap", "idmp.fragment.overlap", FT_BOOLEAN,
737 BASE_NONE, NULL, 0x00, NULL, HFILL } },
738 { &hf_idmp_fragment_overlap_conflicts,
739 { "IDMP fragment overlapping with conflicting data",
740 "idmp.fragment.overlap.conflicts", FT_BOOLEAN, BASE_NONE,
741 NULL, 0x00, NULL, HFILL } },
742 { &hf_idmp_fragment_multiple_tails,
743 { "IDMP has multiple tail fragments",
744 "idmp.fragment.multiple_tails", FT_BOOLEAN, BASE_NONE,
745 NULL, 0x00, NULL, HFILL } },
746 { &hf_idmp_fragment_too_long_fragment,
747 { "IDMP fragment too long", "idmp.fragment.too_long_fragment",
748 FT_BOOLEAN, BASE_NONE, NULL, 0x00, NULL, HFILL } },
749 { &hf_idmp_fragment_error,
750 { "IDMP defragmentation error", "idmp.fragment.error", FT_FRAMENUM,
751 BASE_NONE, NULL, 0x00, NULL, HFILL } },
752 { &hf_idmp_fragment_count,
753 { "IDMP fragment count", "idmp.fragment.count", FT_UINT32, BASE_DEC,
754 NULL, 0x00, NULL, HFILL } },
755 { &hf_idmp_reassembled_in,
756 { "Reassembled IDMP in frame", "idmp.reassembled.in", FT_FRAMENUM, BASE_NONE,
757 NULL, 0x00, "This IDMP packet is reassembled in this frame", HFILL } },
758 { &hf_idmp_reassembled_length,
759 { "Reassembled IDMP length", "idmp.reassembled.length", FT_UINT32, BASE_DEC,
760 NULL, 0x00, "The total length of the reassembled payload", HFILL } },
761 { &hf_idmp_segment_data,
762 { "IDMP segment data", "idmp.segment_data", FT_BYTES, BASE_NONE,
763 NULL, 0x00, NULL, HFILL } },
765 { &hf_idmp_bind,
766 { "bind", "idmp.bind_element",
767 FT_NONE, BASE_NONE, NULL, 0,
768 "IdmBind", HFILL }},
769 { &hf_idmp_bindResult,
770 { "bindResult", "idmp.bindResult_element",
771 FT_NONE, BASE_NONE, NULL, 0,
772 "IdmBindResult", HFILL }},
773 { &hf_idmp_bindError,
774 { "bindError", "idmp.bindError_element",
775 FT_NONE, BASE_NONE, NULL, 0,
776 "IdmBindError", HFILL }},
777 { &hf_idmp_request,
778 { "request", "idmp.request_element",
779 FT_NONE, BASE_NONE, NULL, 0,
780 NULL, HFILL }},
781 { &hf_idmp_idm_result,
782 { "result", "idmp.result_element",
783 FT_NONE, BASE_NONE, NULL, 0,
784 "IdmResult", HFILL }},
785 { &hf_idmp_idm_error,
786 { "error", "idmp.error_element",
787 FT_NONE, BASE_NONE, NULL, 0,
788 NULL, HFILL }},
789 { &hf_idmp_reject,
790 { "reject", "idmp.reject_element",
791 FT_NONE, BASE_NONE, NULL, 0,
792 "IdmReject", HFILL }},
793 { &hf_idmp_unbind,
794 { "unbind", "idmp.unbind_element",
795 FT_NONE, BASE_NONE, NULL, 0,
796 NULL, HFILL }},
797 { &hf_idmp_abort,
798 { "abort", "idmp.abort",
799 FT_UINT32, BASE_DEC, VALS(idmp_Abort_vals), 0,
800 NULL, HFILL }},
801 { &hf_idmp_startTLS,
802 { "startTLS", "idmp.startTLS_element",
803 FT_NONE, BASE_NONE, NULL, 0,
804 NULL, HFILL }},
805 { &hf_idmp_tLSResponse,
806 { "tLSResponse", "idmp.tLSResponse",
807 FT_UINT32, BASE_DEC, VALS(idmp_TLSResponse_vals), 0,
808 NULL, HFILL }},
809 { &hf_idmp_protocolID,
810 { "protocolID", "idmp.protocolID",
811 FT_OID, BASE_NONE, NULL, 0,
812 "OBJECT_IDENTIFIER", HFILL }},
813 { &hf_idmp_callingAETitle,
814 { "callingAETitle", "idmp.callingAETitle",
815 FT_UINT32, BASE_DEC, VALS(x509ce_GeneralName_vals), 0,
816 "GeneralName", HFILL }},
817 { &hf_idmp_calledAETitle,
818 { "calledAETitle", "idmp.calledAETitle",
819 FT_UINT32, BASE_DEC, VALS(x509ce_GeneralName_vals), 0,
820 "GeneralName", HFILL }},
821 { &hf_idmp_bind_argument,
822 { "argument", "idmp.argument_element",
823 FT_NONE, BASE_NONE, NULL, 0,
824 "Bind_argument", HFILL }},
825 { &hf_idmp_respondingAETitle,
826 { "respondingAETitle", "idmp.respondingAETitle",
827 FT_UINT32, BASE_DEC, VALS(x509ce_GeneralName_vals), 0,
828 "GeneralName", HFILL }},
829 { &hf_idmp_bind_result,
830 { "result", "idmp.result_element",
831 FT_NONE, BASE_NONE, NULL, 0,
832 "Bind_result", HFILL }},
833 { &hf_idmp_bind_errcode,
834 { "errcode", "idmp.errcode_element",
835 FT_NONE, BASE_NONE, NULL, 0,
836 "Bind_errcode", HFILL }},
837 { &hf_idmp_aETitleError,
838 { "aETitleError", "idmp.aETitleError",
839 FT_UINT32, BASE_DEC, VALS(idmp_T_aETitleError_vals), 0,
840 NULL, HFILL }},
841 { &hf_idmp_bind_error,
842 { "error", "idmp.error_element",
843 FT_NONE, BASE_NONE, NULL, 0,
844 "Bind_error", HFILL }},
845 { &hf_idmp_invokeID,
846 { "invokeID", "idmp.invokeID",
847 FT_INT32, BASE_DEC, NULL, 0,
848 "INTEGER", HFILL }},
849 { &hf_idmp_opcode,
850 { "opcode", "idmp.opcode",
851 FT_UINT32, BASE_DEC, VALS(idmp_Code_vals), 0,
852 "Code", HFILL }},
853 { &hf_idmp_argument,
854 { "argument", "idmp.argument_element",
855 FT_NONE, BASE_NONE, NULL, 0,
856 NULL, HFILL }},
857 { &hf_idmp_idm_invokeID,
858 { "invokeID", "idmp.idmResult.invokeID",
859 FT_UINT32, BASE_DEC, VALS(idmp_InvokeId_vals), 0,
860 NULL, HFILL }},
861 { &hf_idmp_result,
862 { "result", "idmp.result_element",
863 FT_NONE, BASE_NONE, NULL, 0,
864 NULL, HFILL }},
865 { &hf_idmp_errcode,
866 { "errcode", "idmp.errcode_element",
867 FT_NONE, BASE_NONE, NULL, 0,
868 NULL, HFILL }},
869 { &hf_idmp_error,
870 { "error", "idmp.error_element",
871 FT_NONE, BASE_NONE, NULL, 0,
872 NULL, HFILL }},
873 { &hf_idmp_reason,
874 { "reason", "idmp.reason",
875 FT_UINT32, BASE_DEC, VALS(idmp_T_reason_vals), 0,
876 NULL, HFILL }},
877 { &hf_idmp_local,
878 { "local", "idmp.local",
879 FT_INT32, BASE_DEC, NULL, 0,
880 NULL, HFILL }},
881 { &hf_idmp_global,
882 { "global", "idmp.global",
883 FT_OID, BASE_NONE, NULL, 0,
884 "OBJECT_IDENTIFIER", HFILL }},
885 { &hf_idmp_present,
886 { "present", "idmp.present",
887 FT_INT32, BASE_DEC, NULL, 0,
888 "INTEGER", HFILL }},
889 { &hf_idmp_absent,
890 { "absent", "idmp.absent_element",
891 FT_NONE, BASE_NONE, NULL, 0,
892 NULL, HFILL }},
895 /* List of subtrees */
896 static int *ett[] = {
897 &ett_idmp,
898 &ett_idmp_fragment,
899 &ett_idmp_fragments,
900 &ett_idmp_IDM_PDU,
901 &ett_idmp_IdmBind,
902 &ett_idmp_IdmBindResult,
903 &ett_idmp_IdmBindError,
904 &ett_idmp_Request,
905 &ett_idmp_IdmResult,
906 &ett_idmp_Error,
907 &ett_idmp_IdmReject,
908 &ett_idmp_Code,
909 &ett_idmp_InvokeId,
911 module_t *idmp_module;
913 /* Register protocol */
914 proto_idmp = proto_register_protocol(PNAME, PSNAME, PFNAME);
916 /* Register fields and subtrees */
917 proto_register_field_array(proto_idmp, hf, array_length(hf));
918 proto_register_subtree_array(ett, array_length(ett));
920 idmp_handle = register_dissector("idmp", dissect_idmp_tcp, proto_idmp);
922 register_cleanup_routine (&idmp_reassemble_cleanup);
923 reassembly_table_register (&idmp_reassembly_table,
924 &addresses_reassembly_table_functions);
927 /* Register our configuration options for IDMP, particularly our port */
929 idmp_module = prefs_register_protocol_subtree("OSI/X.500", proto_idmp, NULL);
931 prefs_register_bool_preference(idmp_module, "desegment_idmp_messages",
932 "Reassemble IDMP messages spanning multiple TCP segments",
933 "Whether the IDMP dissector should reassemble messages spanning multiple TCP segments."
934 " To use this option, you must also enable \"Allow subdissectors to reassemble TCP streams\" in the TCP protocol settings.",
935 &idmp_desegment);
937 prefs_register_bool_preference(idmp_module, "reassemble",
938 "Reassemble segmented IDMP datagrams",
939 "Whether segmented IDMP datagrams should be reassembled."
940 " To use this option, you must also enable"
941 " \"Allow subdissectors to reassemble TCP streams\""
942 " in the TCP protocol settings.", &idmp_reassemble);
946 /*--- proto_reg_handoff_idm --- */
947 void proto_reg_handoff_idm(void) {
948 dissector_add_uint_with_preference("tcp.port", IDMP_TCP_PORT, idmp_handle);