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