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