1 /* Do not modify this file. Changes will be overwritten. */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler */
4 /* asn2wrs.py -b -q -L -p cdt -c ./cdt.cnf -s ./packet-cdt-template -D . -O ../.. cdt.asn */
8 * Routines for Compressed Data Type packet dissection.
10 * Copyright 2005, Stig Bjorlykke <stig@bjorlykke.org>, Thales Norway AS
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * SPDX-License-Identifier: GPL-2.0-or-later
18 * Ref: STANAG 4406 Annex E
23 #include <epan/packet.h>
24 #include <epan/oids.h>
25 #include <epan/expert.h>
26 #include <epan/asn1.h>
27 #include <wsutil/array.h>
28 #include "packet-ber.h"
29 #include "packet-p1.h"
31 #include "packet-cdt.h"
33 #define CDT_UNDEFINED 0
34 #define CDT_EXTERNAL 1
39 #define PNAME "Compressed Data Type"
43 void proto_register_cdt(void);
44 void proto_reg_handoff_cdt(void);
46 static proto_tree
*top_tree
;
47 static proto_item
*cdt_item
;
49 static uint32_t content_type
;
51 /* Initialize the protocol and registered fields */
53 static int hf_cdt_CompressedData_PDU
; /* CompressedData */
54 static int hf_cdt_compressionAlgorithm
; /* CompressionAlgorithmIdentifier */
55 static int hf_cdt_compressedContentInfo
; /* CompressedContentInfo */
56 static int hf_cdt_algorithmID_ShortForm
; /* AlgorithmID_ShortForm */
57 static int hf_cdt_algorithmID_OID
; /* OBJECT_IDENTIFIER */
58 static int hf_cdt_contentType
; /* T_contentType */
59 static int hf_cdt_contentType_ShortForm
; /* ContentType_ShortForm */
60 static int hf_cdt_contentType_OID
; /* T_contentType_OID */
61 static int hf_cdt_compressedContent
; /* CompressedContent */
63 /* Initialize the subtree pointers */
64 static int ett_cdt_CompressedData
;
65 static int ett_cdt_CompressionAlgorithmIdentifier
;
66 static int ett_cdt_CompressedContentInfo
;
67 static int ett_cdt_T_contentType
;
69 static expert_field ei_cdt_unable_compress_content
;
70 static expert_field ei_cdt_unable_uncompress_content
;
73 static const value_string cdt_AlgorithmID_ShortForm_vals
[] = {
74 { 0, "zlibCompress" },
80 dissect_cdt_AlgorithmID_ShortForm(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
83 offset
= dissect_ber_integer(implicit_tag
, actx
, tree
, tvb
, offset
, hf_index
,
86 proto_item_append_text (cdt_item
, ", %s",
87 val_to_str (value
, cdt_AlgorithmID_ShortForm_vals
,
90 col_append_fstr (actx
->pinfo
->cinfo
, COL_INFO
, "%s ",
91 val_to_str (value
, cdt_AlgorithmID_ShortForm_vals
,
101 dissect_cdt_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_
) {
102 offset
= dissect_ber_object_identifier(implicit_tag
, actx
, tree
, tvb
, offset
, hf_index
, NULL
);
108 static const value_string cdt_CompressionAlgorithmIdentifier_vals
[] = {
109 { 0, "algorithmID-ShortForm" },
110 { 1, "algorithmID-OID" },
114 static const ber_choice_t CompressionAlgorithmIdentifier_choice
[] = {
115 { 0, &hf_cdt_algorithmID_ShortForm
, BER_CLASS_CON
, 0, BER_FLAGS_IMPLTAG
, dissect_cdt_AlgorithmID_ShortForm
},
116 { 1, &hf_cdt_algorithmID_OID
, BER_CLASS_CON
, 1, BER_FLAGS_IMPLTAG
, dissect_cdt_OBJECT_IDENTIFIER
},
117 { 0, NULL
, 0, 0, 0, NULL
}
121 dissect_cdt_CompressionAlgorithmIdentifier(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
122 offset
= dissect_ber_choice(actx
, tree
, tvb
, offset
,
123 CompressionAlgorithmIdentifier_choice
, hf_index
, ett_cdt_CompressionAlgorithmIdentifier
,
130 static const value_string cdt_ContentType_ShortForm_vals
[] = {
131 { 0, "unidentified" },
141 dissect_cdt_ContentType_ShortForm(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
143 offset
= dissect_ber_integer(implicit_tag
, actx
, tree
, tvb
, offset
, hf_index
,
146 proto_item_append_text (cdt_item
, ", %s",
147 val_to_str (content_type
, cdt_ContentType_ShortForm_vals
,
150 col_append_fstr (actx
->pinfo
->cinfo
, COL_INFO
, "%s ",
151 val_to_str (content_type
, cdt_ContentType_ShortForm_vals
,
161 dissect_cdt_T_contentType_OID(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
162 const char *obj_id
= NULL
;
164 offset
= dissect_ber_object_identifier_str(implicit_tag
, actx
, tree
, tvb
, offset
, hf_index
, &obj_id
);
167 const char *name
= oid_resolved_from_string (actx
->pinfo
->pool
, obj_id
);
173 proto_item_append_text (cdt_item
, ", %s", name
);
175 col_append_fstr (actx
->pinfo
->cinfo
, COL_INFO
, "%s ", name
);
183 static const value_string cdt_T_contentType_vals
[] = {
184 { 0, "contentType-ShortForm" },
185 { 1, "contentType-OID" },
189 static const ber_choice_t T_contentType_choice
[] = {
190 { 0, &hf_cdt_contentType_ShortForm
, BER_CLASS_CON
, 0, BER_FLAGS_IMPLTAG
, dissect_cdt_ContentType_ShortForm
},
191 { 1, &hf_cdt_contentType_OID
, BER_CLASS_CON
, 1, BER_FLAGS_IMPLTAG
, dissect_cdt_T_contentType_OID
},
192 { 0, NULL
, 0, 0, 0, NULL
}
196 dissect_cdt_T_contentType(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
197 offset
= dissect_ber_choice(actx
, tree
, tvb
, offset
,
198 T_contentType_choice
, hf_index
, ett_cdt_T_contentType
,
207 dissect_cdt_CompressedContent(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
208 tvbuff_t
*next_tvb
= NULL
, *compr_tvb
= NULL
;
209 int save_offset
= offset
;
211 offset
= dissect_ber_octet_string(implicit_tag
, actx
, tree
, tvb
, offset
, hf_index
,
214 if (compr_tvb
== NULL
) {
215 proto_tree_add_expert(top_tree
, actx
->pinfo
, &ei_cdt_unable_compress_content
,
216 tvb
, save_offset
, -1);
217 col_append_str (actx
->pinfo
->cinfo
, COL_INFO
,
218 "[Error: Unable to get compressed content]");
222 next_tvb
= tvb_child_uncompress_zlib(tvb
, compr_tvb
, 0, tvb_reported_length (compr_tvb
));
224 if (next_tvb
== NULL
) {
225 proto_tree_add_expert(top_tree
, actx
->pinfo
, &ei_cdt_unable_uncompress_content
,
226 tvb
, save_offset
, -1);
227 col_append_str (actx
->pinfo
->cinfo
, COL_INFO
,
228 "[Error: Unable to uncompress content]");
232 add_new_data_source (actx
->pinfo
, next_tvb
, "Uncompressed Content");
234 switch (content_type
) {
236 call_data_dissector(next_tvb
, actx
->pinfo
, top_tree
);
239 dissect_unknown_ber (actx
->pinfo
, next_tvb
, 0, top_tree
);
242 dissect_p1_mts_apdu (next_tvb
, actx
->pinfo
, top_tree
, NULL
);
245 call_data_dissector(next_tvb
, actx
->pinfo
, top_tree
);
254 static const ber_sequence_t CompressedContentInfo_sequence
[] = {
255 { &hf_cdt_contentType
, BER_CLASS_ANY
/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG
|BER_FLAGS_NOTCHKTAG
, dissect_cdt_T_contentType
},
256 { &hf_cdt_compressedContent
, BER_CLASS_CON
, 0, 0, dissect_cdt_CompressedContent
},
257 { NULL
, 0, 0, 0, NULL
}
261 dissect_cdt_CompressedContentInfo(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
262 offset
= dissect_ber_sequence(implicit_tag
, actx
, tree
, tvb
, offset
,
263 CompressedContentInfo_sequence
, hf_index
, ett_cdt_CompressedContentInfo
);
269 static const ber_sequence_t CompressedData_sequence
[] = {
270 { &hf_cdt_compressionAlgorithm
, BER_CLASS_ANY
/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG
|BER_FLAGS_NOTCHKTAG
, dissect_cdt_CompressionAlgorithmIdentifier
},
271 { &hf_cdt_compressedContentInfo
, BER_CLASS_UNI
, BER_UNI_TAG_SEQUENCE
, BER_FLAGS_NOOWNTAG
, dissect_cdt_CompressedContentInfo
},
272 { NULL
, 0, 0, 0, NULL
}
276 dissect_cdt_CompressedData(bool implicit_tag _U_
, tvbuff_t
*tvb _U_
, int offset _U_
, asn1_ctx_t
*actx _U_
, proto_tree
*tree _U_
, int hf_index _U_
) {
279 offset
= dissect_ber_sequence(implicit_tag
, actx
, tree
, tvb
, offset
,
280 CompressedData_sequence
, hf_index
, ett_cdt_CompressedData
);
289 static int dissect_CompressedData_PDU(tvbuff_t
*tvb _U_
, packet_info
*pinfo _U_
, proto_tree
*tree _U_
, void *data _U_
) {
292 asn1_ctx_init(&asn1_ctx
, ASN1_ENC_BER
, true, pinfo
);
293 offset
= dissect_cdt_CompressedData(false, tvb
, offset
, &asn1_ctx
, tree
, hf_cdt_CompressedData_PDU
);
299 /*--- proto_register_cdt -------------------------------------------*/
302 ** Dissect Compressed Data Type
304 void dissect_cdt (tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*parent_tree
)
306 proto_tree
*tree
= NULL
;
308 /* save parent_tree so subdissectors can create new top nodes */
309 top_tree
= parent_tree
;
312 cdt_item
= proto_tree_add_item (parent_tree
, proto_cdt
, tvb
, 0, -1, ENC_NA
);
313 tree
= proto_item_add_subtree (cdt_item
, ett_cdt_CompressedData
);
318 col_set_str (pinfo
->cinfo
, COL_PROTOCOL
, "CDT");
319 col_clear (pinfo
->cinfo
, COL_INFO
);
321 dissect_CompressedData_PDU (tvb
, pinfo
, tree
, NULL
);
324 void proto_register_cdt (void) {
327 static hf_register_info hf
[] = {
328 { &hf_cdt_CompressedData_PDU
,
329 { "CompressedData", "cdt.CompressedData_element",
330 FT_NONE
, BASE_NONE
, NULL
, 0,
332 { &hf_cdt_compressionAlgorithm
,
333 { "compressionAlgorithm", "cdt.compressionAlgorithm",
334 FT_UINT32
, BASE_DEC
, VALS(cdt_CompressionAlgorithmIdentifier_vals
), 0,
335 "CompressionAlgorithmIdentifier", HFILL
}},
336 { &hf_cdt_compressedContentInfo
,
337 { "compressedContentInfo", "cdt.compressedContentInfo_element",
338 FT_NONE
, BASE_NONE
, NULL
, 0,
340 { &hf_cdt_algorithmID_ShortForm
,
341 { "algorithmID-ShortForm", "cdt.algorithmID_ShortForm",
342 FT_INT32
, BASE_DEC
, VALS(cdt_AlgorithmID_ShortForm_vals
), 0,
344 { &hf_cdt_algorithmID_OID
,
345 { "algorithmID-OID", "cdt.algorithmID_OID",
346 FT_OID
, BASE_NONE
, NULL
, 0,
347 "OBJECT_IDENTIFIER", HFILL
}},
348 { &hf_cdt_contentType
,
349 { "contentType", "cdt.contentType",
350 FT_UINT32
, BASE_DEC
, VALS(cdt_T_contentType_vals
), 0,
352 { &hf_cdt_contentType_ShortForm
,
353 { "contentType-ShortForm", "cdt.contentType_ShortForm",
354 FT_INT32
, BASE_DEC
, VALS(cdt_ContentType_ShortForm_vals
), 0,
356 { &hf_cdt_contentType_OID
,
357 { "contentType-OID", "cdt.contentType_OID",
358 FT_OID
, BASE_NONE
, NULL
, 0,
360 { &hf_cdt_compressedContent
,
361 { "compressedContent", "cdt.compressedContent",
362 FT_BYTES
, BASE_NONE
, NULL
, 0,
366 /* List of subtrees */
367 static int *ett
[] = {
368 &ett_cdt_CompressedData
,
369 &ett_cdt_CompressionAlgorithmIdentifier
,
370 &ett_cdt_CompressedContentInfo
,
371 &ett_cdt_T_contentType
,
374 static ei_register_info ei
[] = {
375 { &ei_cdt_unable_compress_content
, { "cdt.unable_compress_content", PI_UNDECODED
, PI_ERROR
, "Unable to get compressed content", EXPFILL
}},
376 { &ei_cdt_unable_uncompress_content
, { "cdt.unable_uncompress_content", PI_UNDECODED
, PI_ERROR
, "Unable to get uncompressed content", EXPFILL
}},
379 expert_module_t
* expert_cdt
;
381 /* Register protocol */
382 proto_cdt
= proto_register_protocol (PNAME
, PSNAME
, PFNAME
);
384 /* Register fields and subtrees */
385 proto_register_field_array (proto_cdt
, hf
, array_length(hf
));
386 proto_register_subtree_array (ett
, array_length(ett
));
387 expert_cdt
= expert_register_protocol(proto_cdt
);
388 expert_register_field_array(expert_cdt
, ei
, array_length(ei
));
392 /*--- proto_reg_handoff_cdt ---------------------------------------*/
393 void proto_reg_handoff_cdt (void) {
394 register_ber_oid_dissector("1.3.26.0.4406.0.4.2", dissect_CompressedData_PDU
, proto_cdt
, "cdt");