Don't guard col_set_str (COL_PROTOCOL) with col_check
[metze/wireshark/wip.git] / asn1 / ftam / packet-ftam-template.c
1 /* packet-ftam_asn1.c
2  * Routine to dissect OSI ISO 8571 FTAM Protocol packets
3  * based on the ASN.1 specification from http://www.itu.int/ITU-T/asn1/database/iso/8571-4/1988/
4  *
5  * also based on original handwritten dissector by
6  * Yuriy Sidelnikov <YSidelnikov@hotmail.com>
7  *
8  * Anders Broman and Ronnie Sahlberg 2005 - 2006
9  *
10  * $Id$
11  *
12  * Wireshark - Network traffic analyzer
13  * By Gerald Combs <gerald@wireshark.org>
14  * Copyright 1998 Gerald Combs
15  *
16  * This program is free software; you can redistribute it and/or
17  * modify it under the terms of the GNU General Public License
18  * as published by the Free Software Foundation; either version 2
19  * of the License, or (at your option) any later version.
20  *
21  * This program is distributed in the hope that it will be useful,
22  * but WITHOUT ANY WARRANTY; without even the implied warranty of
23  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
24  * GNU General Public License for more details.
25  *
26  * You should have received a copy of the GNU General Public License
27  * along with this program; if not, write to the Free Software
28  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
29  */
30
31 #ifdef HAVE_CONFIG_H
32 # include "config.h"
33 #endif
34
35 #include <glib.h>
36 #include <epan/packet.h>
37 #include <epan/oids.h>
38 #include <epan/asn1.h>
39
40 #include <stdio.h>
41 #include <string.h>
42
43 #include "packet-ber.h"
44 #include "packet-acse.h"
45 #include "packet-ftam.h"
46
47 #define PNAME  "ISO 8571 FTAM"
48 #define PSNAME "FTAM"
49 #define PFNAME "ftam"
50
51 /* Initialize the protocol and registered fields */
52 int proto_ftam = -1;
53
54 static const char *object_identifier_id;
55 /* Declare the function to avoid a compiler warning */
56 static int dissect_ftam_OR_Set(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index _U_);
57
58 static int hf_ftam_unstructured_text = -1;              /* ISO FTAM unstructured text */
59 static int hf_ftam_unstructured_binary = -1;            /* ISO FTAM unstructured binary */
60 #include "packet-ftam-hf.c"
61
62 /* Initialize the subtree pointers */
63 static gint ett_ftam = -1;
64 #include "packet-ftam-ett.c"
65
66 #include "packet-ftam-fn.c"
67
68 /*
69 * Dissect FTAM unstructured text
70 */
71 static void
72 dissect_ftam_unstructured_text(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree)
73 {
74         proto_tree_add_item (parent_tree, hf_ftam_unstructured_text, tvb, 0, tvb_length_remaining(tvb, 0), FALSE); 
75 }
76
77 /*
78 * Dissect FTAM unstructured binary
79 */
80 static void
81 dissect_ftam_unstructured_binary(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *parent_tree)
82 {
83         proto_tree_add_item (parent_tree, hf_ftam_unstructured_binary, tvb, 0, tvb_length_remaining(tvb, 0), FALSE); 
84 }
85
86 /*
87 * Dissect FTAM PDUs inside a PPDU.
88 */
89 static void
90 dissect_ftam(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
91 {
92         int offset = 0;
93         int old_offset;
94         proto_item *item=NULL;
95         proto_tree *tree=NULL;
96         asn1_ctx_t asn1_ctx;
97
98         asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
99
100         if(parent_tree){
101                 item = proto_tree_add_item(parent_tree, proto_ftam, tvb, 0, -1, FALSE);
102                 tree = proto_item_add_subtree(item, ett_ftam);
103         }
104         col_set_str(pinfo->cinfo, COL_PROTOCOL, "FTAM");
105         if (check_col(pinfo->cinfo, COL_INFO))
106                 col_clear(pinfo->cinfo, COL_INFO);
107
108         while (tvb_reported_length_remaining(tvb, offset) > 0){
109                 old_offset=offset;
110                 offset=dissect_ftam_PDU(FALSE, tvb, offset, &asn1_ctx, tree, -1);
111                 if(offset == old_offset){
112                         proto_tree_add_text(tree, tvb, offset, -1,"Internal error, zero-byte FTAM PDU");
113                         break;
114                 }
115         }
116 }
117
118
119 /*--- proto_register_ftam -------------------------------------------*/
120 void proto_register_ftam(void) {
121
122   /* List of fields */
123   static hf_register_info hf[] =
124   {
125      { &hf_ftam_unstructured_text,
126        { "ISO FTAM unstructured text", "ftam.unstructured_text", FT_STRING,
127           BASE_NONE, NULL, 0x0, NULL, HFILL } },
128      { &hf_ftam_unstructured_binary,
129        { "ISO FTAM unstructured binary", "ftam.unstructured_binary", FT_BYTES,
130           BASE_NONE, NULL, 0x0, NULL, HFILL } },
131 #include "packet-ftam-hfarr.c"
132   };
133
134   /* List of subtrees */
135   static gint *ett[] = {
136     &ett_ftam,
137 #include "packet-ftam-ettarr.c"
138   };
139
140   /* Register protocol */
141   proto_ftam = proto_register_protocol(PNAME, PSNAME, PFNAME);
142   register_dissector("ftam", dissect_ftam, proto_ftam);
143   /* Register fields and subtrees */
144   proto_register_field_array(proto_ftam, hf, array_length(hf));
145   proto_register_subtree_array(ett, array_length(ett));
146
147 }
148
149
150 /*--- proto_reg_handoff_ftam --- */
151 void proto_reg_handoff_ftam(void) {
152         register_ber_oid_dissector("1.0.8571.1.1", dissect_ftam, proto_ftam,"iso-ftam(1)");
153         register_ber_oid_dissector("1.0.8571.2.1", dissect_ftam, proto_ftam,"ftam-pci(1)");
154         register_ber_oid_dissector("1.3.14.5.2.2", dissect_ftam, proto_ftam,"NIST file directory entry abstract syntax");
155
156         /* Unstructured text file document type FTAM-1 */
157         register_ber_oid_dissector("1.0.8571.5.1", dissect_ftam_unstructured_text, proto_ftam,"ISO FTAM unstructured text");
158         oid_add_from_string("ISO FTAM sequential text","1.0.8571.5.2");
159         oid_add_from_string("FTAM unstructured text abstract syntax","1.0.8571.2.3");
160         oid_add_from_string("FTAM simple-hierarchy","1.0.8571.2.5");
161         oid_add_from_string("FTAM hierarchical file model","1.0.8571.3.1");
162         oid_add_from_string("FTAM unstructured constraint set","1.0.8571.4.1");
163
164         /* Unstructured binary file document type FTAM-3 */
165         register_ber_oid_dissector("1.0.8571.5.3", dissect_ftam_unstructured_binary, proto_ftam,"ISO FTAM unstructured binary");
166         oid_add_from_string("FTAM unstructured binary abstract syntax","1.0.8571.2.4");
167
168         /* Filedirectory file document type NBS-9 */
169         oid_add_from_string("NBS-9 FTAM file directory file","1.3.14.5.5.9");
170
171         /* Filedirectory file document type NBS-9 (WITH OLD NIST OIDs)*/
172         oid_add_from_string("NBS-9-OLD FTAM file directory file","1.3.9999.1.5.9");
173         oid_add_from_string("NIST file directory entry abstract syntax","1.3.9999.1.2.2");
174 }