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