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