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