Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / packet-cdt.c
blob34eccacdca8b8c0a8e57c93413c4ce77b776ebaa
1 /* Do not modify this file. Changes will be overwritten. */
2 /* Generated automatically by the ASN.1 to Wireshark dissector compiler */
3 /* packet-cdt.c */
4 /* asn2wrs.py -b -q -L -p cdt -c ./cdt.cnf -s ./packet-cdt-template -D . -O ../.. cdt.asn */
6 /* packet-cdt.c
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
21 #include "config.h"
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
35 #define CDT_P1 2
36 #define CDT_P3 3
37 #define CDT_P7 4
39 #define PNAME "Compressed Data Type"
40 #define PSNAME "CDT"
41 #define PFNAME "cdt"
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 */
52 static int proto_cdt;
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" },
75 { 0, NULL }
79 static int
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_) {
81 uint32_t value;
83 offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
84 &value);
86 proto_item_append_text (cdt_item, ", %s",
87 val_to_str (value, cdt_AlgorithmID_ShortForm_vals,
88 "unknown"));
90 col_append_fstr (actx->pinfo->cinfo, COL_INFO, "%s ",
91 val_to_str (value, cdt_AlgorithmID_ShortForm_vals,
92 "unknown"));
95 return offset;
100 static int
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);
104 return offset;
108 static const value_string cdt_CompressionAlgorithmIdentifier_vals[] = {
109 { 0, "algorithmID-ShortForm" },
110 { 1, "algorithmID-OID" },
111 { 0, NULL }
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 }
120 static int
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,
124 NULL);
126 return offset;
130 static const value_string cdt_ContentType_ShortForm_vals[] = {
131 { 0, "unidentified" },
132 { 1, "external" },
133 { 2, "p1" },
134 { 3, "p3" },
135 { 4, "p7" },
136 { 0, NULL }
140 static int
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,
144 &content_type);
146 proto_item_append_text (cdt_item, ", %s",
147 val_to_str (content_type, cdt_ContentType_ShortForm_vals,
148 "unknown"));
150 col_append_fstr (actx->pinfo->cinfo, COL_INFO, "%s ",
151 val_to_str (content_type, cdt_ContentType_ShortForm_vals,
152 "unknown"));
155 return offset;
160 static int
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);
166 if (obj_id) {
167 const char *name = oid_resolved_from_string (actx->pinfo->pool, obj_id);
169 if (!name) {
170 name = obj_id;
173 proto_item_append_text (cdt_item, ", %s", name);
175 col_append_fstr (actx->pinfo->cinfo, COL_INFO, "%s ", name);
179 return offset;
183 static const value_string cdt_T_contentType_vals[] = {
184 { 0, "contentType-ShortForm" },
185 { 1, "contentType-OID" },
186 { 0, NULL }
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 }
195 static int
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,
199 NULL);
201 return offset;
206 static int
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,
212 &compr_tvb);
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]");
219 return offset;
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]");
229 return offset;
232 add_new_data_source (actx->pinfo, next_tvb, "Uncompressed Content");
234 switch (content_type) {
235 case CDT_UNDEFINED:
236 call_data_dissector(next_tvb, actx->pinfo, top_tree);
237 break;
238 case CDT_EXTERNAL:
239 dissect_unknown_ber (actx->pinfo, next_tvb, 0, top_tree);
240 break;
241 case CDT_P1:
242 dissect_p1_mts_apdu (next_tvb, actx->pinfo, top_tree, NULL);
243 break;
244 default:
245 call_data_dissector(next_tvb, actx->pinfo, top_tree);
246 break;
250 return offset;
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 }
260 static int
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);
265 return offset;
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_) {
277 content_type = 0;
279 offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
280 CompressedData_sequence, hf_index, ett_cdt_CompressedData);
284 return offset;
287 /*--- PDUs ---*/
289 static int dissect_CompressedData_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_, void *data _U_) {
290 int offset = 0;
291 asn1_ctx_t asn1_ctx;
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);
294 return offset;
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;
311 if (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);
314 } else {
315 cdt_item = NULL;
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) {
326 /* List of fields */
327 static hf_register_info hf[] = {
328 { &hf_cdt_CompressedData_PDU,
329 { "CompressedData", "cdt.CompressedData_element",
330 FT_NONE, BASE_NONE, NULL, 0,
331 NULL, HFILL }},
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,
339 NULL, HFILL }},
340 { &hf_cdt_algorithmID_ShortForm,
341 { "algorithmID-ShortForm", "cdt.algorithmID_ShortForm",
342 FT_INT32, BASE_DEC, VALS(cdt_AlgorithmID_ShortForm_vals), 0,
343 NULL, HFILL }},
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,
351 NULL, HFILL }},
352 { &hf_cdt_contentType_ShortForm,
353 { "contentType-ShortForm", "cdt.contentType_ShortForm",
354 FT_INT32, BASE_DEC, VALS(cdt_ContentType_ShortForm_vals), 0,
355 NULL, HFILL }},
356 { &hf_cdt_contentType_OID,
357 { "contentType-OID", "cdt.contentType_OID",
358 FT_OID, BASE_NONE, NULL, 0,
359 NULL, HFILL }},
360 { &hf_cdt_compressedContent,
361 { "compressedContent", "cdt.compressedContent",
362 FT_BYTES, BASE_NONE, NULL, 0,
363 NULL, HFILL }},
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");