Fixup: tvb_get_string(z) -> tvb_get_string(z)_enc
[metze/wireshark/wip.git] / epan / dissectors / packet-cdt.c
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 /* ../../tools/asn2wrs.py -b -p cdt -c ./cdt.cnf -s ./packet-cdt-template -D . -O ../../epan/dissectors cdt.asn */
5
6 /* Input file: packet-cdt-template.c */
7
8 #line 1 "../../asn1/cdt/packet-cdt-template.c"
9 /* packet-cdt.c
10  *
11  * Routines for Compressed Data Type packet dissection.
12  *
13  * Copyright 2005, Stig Bjorlykke <stig@bjorlykke.org>, Thales Norway AS
14  *
15  * Wireshark - Network traffic analyzer
16  * By Gerald Combs <gerald@wireshark.org>
17  * Copyright 1998 Gerald Combs
18  *
19  * This program is free software; you can redistribute it and/or
20  * modify it under the terms of the GNU General Public License
21  * as published by the Free Software Foundation; either version 2
22  * of the License, or (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program; if not, write to the Free Software
31  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
32  *
33  * Ref: STANAG 4406 Annex E
34  */
35
36 #include "config.h"
37
38 #include <epan/packet.h>
39 #include <epan/oids.h>
40 #include <epan/expert.h>
41 #include <epan/asn1.h>
42
43 #include "packet-ber.h"
44 #include "packet-p1.h"
45
46 #include "packet-cdt.h"
47
48 #define CDT_UNDEFINED  0
49 #define CDT_EXTERNAL   1
50 #define CDT_P1         2
51 #define CDT_P3         3
52 #define CDT_P7         4
53
54 #define PNAME  "Compressed Data Type"
55 #define PSNAME "CDT"
56 #define PFNAME "cdt"
57
58 void proto_register_cdt(void);
59 void proto_reg_handoff_cdt(void);
60
61 static proto_tree *top_tree = NULL;
62 static proto_item *cdt_item = NULL;
63
64 static guint32 content_type = 0;
65
66 /* Initialize the protocol and registered fields */
67 static int proto_cdt = -1;
68
69 /*--- Included file: packet-cdt-hf.c ---*/
70 #line 1 "../../asn1/cdt/packet-cdt-hf.c"
71 static int hf_cdt_CompressedData_PDU = -1;        /* CompressedData */
72 static int hf_cdt_compressionAlgorithm = -1;      /* CompressionAlgorithmIdentifier */
73 static int hf_cdt_compressedContentInfo = -1;     /* CompressedContentInfo */
74 static int hf_cdt_algorithmID_ShortForm = -1;     /* AlgorithmID_ShortForm */
75 static int hf_cdt_algorithmID_OID = -1;           /* OBJECT_IDENTIFIER */
76 static int hf_cdt_contentType = -1;               /* T_contentType */
77 static int hf_cdt_contentType_ShortForm = -1;     /* ContentType_ShortForm */
78 static int hf_cdt_contentType_OID = -1;           /* T_contentType_OID */
79 static int hf_cdt_compressedContent = -1;         /* CompressedContent */
80
81 /*--- End of included file: packet-cdt-hf.c ---*/
82 #line 61 "../../asn1/cdt/packet-cdt-template.c"
83
84 static dissector_handle_t data_handle = NULL;
85
86 /* Initialize the subtree pointers */
87
88 /*--- Included file: packet-cdt-ett.c ---*/
89 #line 1 "../../asn1/cdt/packet-cdt-ett.c"
90 static gint ett_cdt_CompressedData = -1;
91 static gint ett_cdt_CompressionAlgorithmIdentifier = -1;
92 static gint ett_cdt_CompressedContentInfo = -1;
93 static gint ett_cdt_T_contentType = -1;
94
95 /*--- End of included file: packet-cdt-ett.c ---*/
96 #line 66 "../../asn1/cdt/packet-cdt-template.c"
97
98 static expert_field ei_cdt_unable_compress_content = EI_INIT;
99 static expert_field ei_cdt_unable_uncompress_content = EI_INIT;
100
101
102 /*--- Included file: packet-cdt-fn.c ---*/
103 #line 1 "../../asn1/cdt/packet-cdt-fn.c"
104
105 static const value_string cdt_AlgorithmID_ShortForm_vals[] = {
106   {   0, "zlibCompress" },
107   { 0, NULL }
108 };
109
110
111 static int
112 dissect_cdt_AlgorithmID_ShortForm(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
113 #line 19 "../../asn1/cdt/cdt.cnf"
114   guint32 value;
115
116     offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
117                                                 &value);
118
119   proto_item_append_text (cdt_item, ", %s",
120                           val_to_str (value, cdt_AlgorithmID_ShortForm_vals,
121                                       "unknown"));
122
123   col_append_fstr (actx->pinfo->cinfo, COL_INFO, "%s ",
124                    val_to_str (value, cdt_AlgorithmID_ShortForm_vals,
125                                "unknown"));
126
127
128
129   return offset;
130 }
131
132
133
134 static int
135 dissect_cdt_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_) {
136   offset = dissect_ber_object_identifier(implicit_tag, actx, tree, tvb, offset, hf_index, NULL);
137
138   return offset;
139 }
140
141
142 static const value_string cdt_CompressionAlgorithmIdentifier_vals[] = {
143   {   0, "algorithmID-ShortForm" },
144   {   1, "algorithmID-OID" },
145   { 0, NULL }
146 };
147
148 static const ber_choice_t CompressionAlgorithmIdentifier_choice[] = {
149   {   0, &hf_cdt_algorithmID_ShortForm, BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_cdt_AlgorithmID_ShortForm },
150   {   1, &hf_cdt_algorithmID_OID , BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_cdt_OBJECT_IDENTIFIER },
151   { 0, NULL, 0, 0, 0, NULL }
152 };
153
154 static int
155 dissect_cdt_CompressionAlgorithmIdentifier(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
156   offset = dissect_ber_choice(actx, tree, tvb, offset,
157                                  CompressionAlgorithmIdentifier_choice, hf_index, ett_cdt_CompressionAlgorithmIdentifier,
158                                  NULL);
159
160   return offset;
161 }
162
163
164 static const value_string cdt_ContentType_ShortForm_vals[] = {
165   {   0, "unidentified" },
166   {   1, "external" },
167   {   2, "p1" },
168   {   3, "p3" },
169   {   4, "p7" },
170   { 0, NULL }
171 };
172
173
174 static int
175 dissect_cdt_ContentType_ShortForm(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
176 #line 34 "../../asn1/cdt/cdt.cnf"
177
178     offset = dissect_ber_integer(implicit_tag, actx, tree, tvb, offset, hf_index,
179                                                 &content_type);
180
181   proto_item_append_text (cdt_item, ", %s",
182                           val_to_str (content_type, cdt_ContentType_ShortForm_vals,
183                                       "unknown"));
184
185   col_append_fstr (actx->pinfo->cinfo, COL_INFO, "%s ",
186                    val_to_str (content_type, cdt_ContentType_ShortForm_vals,
187                                "unknown"));
188
189
190
191   return offset;
192 }
193
194
195
196 static int
197 dissect_cdt_T_contentType_OID(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
198 #line 48 "../../asn1/cdt/cdt.cnf"
199   const char *obj_id = NULL;
200
201     offset = dissect_ber_object_identifier_str(implicit_tag, actx, tree, tvb, offset, hf_index, &obj_id);
202
203   if (obj_id) {
204     const char *name = oid_resolved_from_string (obj_id);
205
206     if (!name) {
207       name = obj_id;
208     }
209
210     proto_item_append_text (cdt_item, ", %s", name);
211
212     col_append_fstr (actx->pinfo->cinfo, COL_INFO, "%s ", name);
213   }
214
215
216
217   return offset;
218 }
219
220
221 static const value_string cdt_T_contentType_vals[] = {
222   {   0, "contentType-ShortForm" },
223   {   1, "contentType-OID" },
224   { 0, NULL }
225 };
226
227 static const ber_choice_t T_contentType_choice[] = {
228   {   0, &hf_cdt_contentType_ShortForm, BER_CLASS_CON, 0, BER_FLAGS_IMPLTAG, dissect_cdt_ContentType_ShortForm },
229   {   1, &hf_cdt_contentType_OID , BER_CLASS_CON, 1, BER_FLAGS_IMPLTAG, dissect_cdt_T_contentType_OID },
230   { 0, NULL, 0, 0, 0, NULL }
231 };
232
233 static int
234 dissect_cdt_T_contentType(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
235   offset = dissect_ber_choice(actx, tree, tvb, offset,
236                                  T_contentType_choice, hf_index, ett_cdt_T_contentType,
237                                  NULL);
238
239   return offset;
240 }
241
242
243
244 static int
245 dissect_cdt_CompressedContent(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
246 #line 67 "../../asn1/cdt/cdt.cnf"
247   tvbuff_t   *next_tvb = NULL, *compr_tvb = NULL;
248   int         save_offset = offset;
249
250     offset = dissect_ber_octet_string(implicit_tag, actx, tree, tvb, offset, hf_index,
251                                        &compr_tvb);
252
253   if (compr_tvb == NULL) {
254     proto_tree_add_expert(top_tree, actx->pinfo, &ei_cdt_unable_compress_content,
255                                                         tvb, save_offset, -1);
256     col_append_str (actx->pinfo->cinfo, COL_INFO,
257                     "[Error: Unable to get compressed content]");
258     return offset;
259   }
260
261   next_tvb = tvb_child_uncompress (tvb, compr_tvb, 0, tvb_length (compr_tvb));
262
263   if (next_tvb == NULL) {
264     proto_tree_add_expert(top_tree, actx->pinfo, &ei_cdt_unable_uncompress_content,
265                                                         tvb, save_offset, -1);
266     col_append_str (actx->pinfo->cinfo, COL_INFO,
267                     "[Error: Unable to uncompress content]");
268     return offset;
269   }
270
271   add_new_data_source (actx->pinfo, next_tvb, "Uncompressed Content");
272
273    switch (content_type) {
274    case CDT_UNDEFINED:
275      call_dissector (data_handle, next_tvb, actx->pinfo, top_tree);
276      break;
277    case CDT_EXTERNAL:
278      dissect_unknown_ber (actx->pinfo, next_tvb, 0, top_tree);
279      break;
280    case CDT_P1:
281      dissect_p1_mts_apdu (next_tvb, actx->pinfo, top_tree);
282      break;
283    default:
284      call_dissector (data_handle, next_tvb, actx->pinfo, top_tree);
285      break;
286    }
287
288
289
290   return offset;
291 }
292
293
294 static const ber_sequence_t CompressedContentInfo_sequence[] = {
295   { &hf_cdt_contentType     , BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_cdt_T_contentType },
296   { &hf_cdt_compressedContent, BER_CLASS_CON, 0, 0, dissect_cdt_CompressedContent },
297   { NULL, 0, 0, 0, NULL }
298 };
299
300 static int
301 dissect_cdt_CompressedContentInfo(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
302   offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
303                                    CompressedContentInfo_sequence, hf_index, ett_cdt_CompressedContentInfo);
304
305   return offset;
306 }
307
308
309 static const ber_sequence_t CompressedData_sequence[] = {
310   { &hf_cdt_compressionAlgorithm, BER_CLASS_ANY/*choice*/, -1/*choice*/, BER_FLAGS_NOOWNTAG|BER_FLAGS_NOTCHKTAG, dissect_cdt_CompressionAlgorithmIdentifier },
311   { &hf_cdt_compressedContentInfo, BER_CLASS_UNI, BER_UNI_TAG_SEQUENCE, BER_FLAGS_NOOWNTAG, dissect_cdt_CompressedContentInfo },
312   { NULL, 0, 0, 0, NULL }
313 };
314
315 int
316 dissect_cdt_CompressedData(gboolean implicit_tag _U_, tvbuff_t *tvb _U_, int offset _U_, asn1_ctx_t *actx _U_, proto_tree *tree _U_, int hf_index _U_) {
317 #line 11 "../../asn1/cdt/cdt.cnf"
318   content_type = 0;
319
320     offset = dissect_ber_sequence(implicit_tag, actx, tree, tvb, offset,
321                                    CompressedData_sequence, hf_index, ett_cdt_CompressedData);
322
323
324
325
326   return offset;
327 }
328
329 /*--- PDUs ---*/
330
331 static void dissect_CompressedData_PDU(tvbuff_t *tvb _U_, packet_info *pinfo _U_, proto_tree *tree _U_) {
332   asn1_ctx_t asn1_ctx;
333   asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
334   dissect_cdt_CompressedData(FALSE, tvb, 0, &asn1_ctx, tree, hf_cdt_CompressedData_PDU);
335 }
336
337
338 /*--- End of included file: packet-cdt-fn.c ---*/
339 #line 71 "../../asn1/cdt/packet-cdt-template.c"
340
341
342 /*--- proto_register_cdt -------------------------------------------*/
343
344 /*
345 ** Dissect Compressed Data Type
346 */
347 void dissect_cdt (tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
348 {
349   proto_tree *tree = NULL;
350
351   /* save parent_tree so subdissectors can create new top nodes */
352   top_tree = parent_tree;
353
354   if (parent_tree) {
355     cdt_item = proto_tree_add_item (parent_tree, proto_cdt, tvb, 0, -1, ENC_NA);
356     tree = proto_item_add_subtree (cdt_item, ett_cdt_CompressedData);
357   } else {
358     cdt_item = NULL;
359   }
360
361   col_set_str (pinfo->cinfo, COL_PROTOCOL, "CDT");
362   col_clear (pinfo->cinfo, COL_INFO);
363
364   dissect_CompressedData_PDU (tvb, pinfo, tree);
365 }
366
367 void proto_register_cdt (void) {
368
369   /* List of fields */
370   static hf_register_info hf[] = {
371
372 /*--- Included file: packet-cdt-hfarr.c ---*/
373 #line 1 "../../asn1/cdt/packet-cdt-hfarr.c"
374     { &hf_cdt_CompressedData_PDU,
375       { "CompressedData", "cdt.CompressedData_element",
376         FT_NONE, BASE_NONE, NULL, 0,
377         NULL, HFILL }},
378     { &hf_cdt_compressionAlgorithm,
379       { "compressionAlgorithm", "cdt.compressionAlgorithm",
380         FT_UINT32, BASE_DEC, VALS(cdt_CompressionAlgorithmIdentifier_vals), 0,
381         "CompressionAlgorithmIdentifier", HFILL }},
382     { &hf_cdt_compressedContentInfo,
383       { "compressedContentInfo", "cdt.compressedContentInfo_element",
384         FT_NONE, BASE_NONE, NULL, 0,
385         NULL, HFILL }},
386     { &hf_cdt_algorithmID_ShortForm,
387       { "algorithmID-ShortForm", "cdt.algorithmID_ShortForm",
388         FT_INT32, BASE_DEC, VALS(cdt_AlgorithmID_ShortForm_vals), 0,
389         NULL, HFILL }},
390     { &hf_cdt_algorithmID_OID,
391       { "algorithmID-OID", "cdt.algorithmID_OID",
392         FT_OID, BASE_NONE, NULL, 0,
393         "OBJECT_IDENTIFIER", HFILL }},
394     { &hf_cdt_contentType,
395       { "contentType", "cdt.contentType",
396         FT_UINT32, BASE_DEC, VALS(cdt_T_contentType_vals), 0,
397         NULL, HFILL }},
398     { &hf_cdt_contentType_ShortForm,
399       { "contentType-ShortForm", "cdt.contentType_ShortForm",
400         FT_INT32, BASE_DEC, VALS(cdt_ContentType_ShortForm_vals), 0,
401         NULL, HFILL }},
402     { &hf_cdt_contentType_OID,
403       { "contentType-OID", "cdt.contentType_OID",
404         FT_OID, BASE_NONE, NULL, 0,
405         NULL, HFILL }},
406     { &hf_cdt_compressedContent,
407       { "compressedContent", "cdt.compressedContent",
408         FT_BYTES, BASE_NONE, NULL, 0,
409         NULL, HFILL }},
410
411 /*--- End of included file: packet-cdt-hfarr.c ---*/
412 #line 103 "../../asn1/cdt/packet-cdt-template.c"
413   };
414
415   /* List of subtrees */
416   static gint *ett[] = {
417
418 /*--- Included file: packet-cdt-ettarr.c ---*/
419 #line 1 "../../asn1/cdt/packet-cdt-ettarr.c"
420     &ett_cdt_CompressedData,
421     &ett_cdt_CompressionAlgorithmIdentifier,
422     &ett_cdt_CompressedContentInfo,
423     &ett_cdt_T_contentType,
424
425 /*--- End of included file: packet-cdt-ettarr.c ---*/
426 #line 108 "../../asn1/cdt/packet-cdt-template.c"
427   };
428
429   static ei_register_info ei[] = {
430      { &ei_cdt_unable_compress_content, { "cdt.unable_compress_content", PI_UNDECODED, PI_ERROR, "Unable to get compressed content", EXPFILL }},
431      { &ei_cdt_unable_uncompress_content, { "cdt.unable_uncompress_content", PI_UNDECODED, PI_ERROR, "Unable to get uncompressed content", EXPFILL }},
432   };
433
434   expert_module_t* expert_cdt;
435
436   /* Register protocol */
437   proto_cdt = proto_register_protocol (PNAME, PSNAME, PFNAME);
438
439   /* Register fields and subtrees */
440   proto_register_field_array (proto_cdt, hf, array_length(hf));
441   proto_register_subtree_array (ett, array_length(ett));
442   expert_cdt = expert_register_protocol(proto_cdt);
443   expert_register_field_array(expert_cdt, ei, array_length(ei));
444 }
445
446
447 /*--- proto_reg_handoff_cdt ---------------------------------------*/
448 void proto_reg_handoff_cdt (void) {
449
450 /*--- Included file: packet-cdt-dis-tab.c ---*/
451 #line 1 "../../asn1/cdt/packet-cdt-dis-tab.c"
452   register_ber_oid_dissector("1.3.26.0.4406.0.4.2", dissect_CompressedData_PDU, proto_cdt, "cdt");
453
454
455 /*--- End of included file: packet-cdt-dis-tab.c ---*/
456 #line 131 "../../asn1/cdt/packet-cdt-template.c"
457
458   data_handle = find_dissector ("data");
459 }