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