More header_field_info cleanup.
[obnox/wireshark/wip.git] / asn1 / cmip / packet-cmip-template.c
1 /* packet-cmip.c
2  * Routines for X.711 CMIP packet dissection
3  *   Ronnie Sahlberg 2004
4  *
5  * $Id$
6  *
7  * Wireshark - Network traffic analyzer
8  * By Gerald Combs <gerald@wireshark.org>
9  * Copyright 1998 Gerald Combs
10  *
11  * This program is free software; you can redistribute it and/or
12  * modify it under the terms of the GNU General Public License
13  * as published by the Free Software Foundation; either version 2
14  * of the License, or (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program; if not, write to the Free Software
23  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24  */
25
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
29
30 #include <glib.h>
31 #include <epan/packet.h>
32 #include <epan/oids.h>
33 #include <epan/asn1.h>
34
35 #include <stdio.h>
36 #include <string.h>
37
38 #include "packet-ber.h"
39 #include "packet-acse.h"
40 #include "packet-x509if.h"
41 #include "packet-cmip.h"
42
43 #define PNAME  "X711 CMIP"
44 #define PSNAME "CMIP"
45 #define PFNAME "cmip"
46
47 /* XXX some stuff we need until we can get rid of it */
48 #include "packet-ses.h"
49 #include "packet-pres.h"
50
51 /* Initialize the protocol and registered fields */
52 int proto_cmip = -1;
53 static int hf_cmip_actionType_OID = -1;
54 static int hf_cmip_eventType_OID = -1;
55 static int hf_cmip_attributeId_OID = -1;
56 static int hf_cmip_errorId_OID = -1;
57 static int hf_DiscriminatorConstruct = -1;
58 static int hf_Destination = -1;
59 static int hf_NameBinding = -1;
60 static int hf_ObjectClass = -1;
61 #include "packet-cmip-hf.c"
62
63 /* Initialize the subtree pointers */
64 static gint ett_cmip = -1;
65 #include "packet-cmip-ett.c"
66
67 static guint32 opcode;
68
69 #include "packet-cmip-table.c"
70
71 static int opcode_type;
72 #define OPCODE_INVOKE        1
73 #define OPCODE_RETURN_RESULT 2
74 #define OPCODE_RETURN_ERROR  3
75 #define OPCODE_REJECT        4
76
77 static int attributeform;
78 #define ATTRIBUTE_LOCAL_FORM  0
79 #define ATTRIBUTE_GLOBAL_FORM 1
80 static const char *attribute_identifier_id;
81
82 static const char *attributevalueassertion_id;
83
84 static const char *object_identifier_id;
85
86 static int objectclassform;
87 #define OBJECTCLASS_LOCAL_FORM  0
88 #define OBJECTCLASS_GLOBAL_FORM 1
89 static const char *objectclass_identifier_id;
90
91 #include "packet-cmip-val.h"
92 #include "packet-cmip-fn.c"
93
94
95
96
97 /* XXX this one should be broken out later and moved into the conformance file */
98 static void
99 dissect_cmip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
100 {
101         static struct SESSION_DATA_STRUCTURE* session = NULL;
102         proto_item *item = NULL;
103         proto_tree *tree = NULL;
104         asn1_ctx_t asn1_ctx;
105         asn1_ctx_init(&asn1_ctx, ASN1_ENC_BER, TRUE, pinfo);
106
107
108         /* do we have spdu type from the session dissector?  */
109         if( !pinfo->private_data ){
110                 if(tree){
111                         proto_tree_add_text(tree, tvb, 0, -1,
112                                 "Internal error:can't get spdu type from session dissector.");
113                         return;
114                 }
115         } else {
116                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
117                 if(session->spdu_type == 0 ){
118                         if(tree){
119                                 proto_tree_add_text(tree, tvb, 0, -1,
120                                         "Internal error:wrong spdu type %x from session dissector.",session->spdu_type);
121                                 return;
122                         }
123                 }
124         }
125
126         if(parent_tree){
127                 item = proto_tree_add_item(parent_tree, proto_cmip, tvb, 0, -1, FALSE);
128                 tree = proto_item_add_subtree(item, ett_cmip);
129         }
130
131         if (check_col(pinfo->cinfo, COL_PROTOCOL))
132                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMIP");
133         if (check_col(pinfo->cinfo, COL_INFO))
134                 col_clear(pinfo->cinfo, COL_INFO);
135         switch(session->spdu_type){
136                 case SES_CONNECTION_REQUEST:
137                 case SES_CONNECTION_ACCEPT:
138                 case SES_DISCONNECT:
139                 case SES_FINISH:
140                 case SES_REFUSE:
141                         dissect_cmip_CMIPUserInfo(FALSE,tvb,0,&asn1_ctx,tree,-1);
142                         break;
143                 case SES_ABORT:
144                         dissect_cmip_CMIPAbortInfo(FALSE,tvb,0,&asn1_ctx,tree,-1);
145                         break;
146                 case SES_DATA_TRANSFER:
147                         dissect_cmip_ROS(FALSE,tvb,0,&asn1_ctx,tree,-1);
148                         break;
149                 default:
150                         ;
151         }
152 }
153
154 /*--- proto_register_cmip ----------------------------------------------*/
155 void proto_register_cmip(void) {
156
157   /* List of fields */
158   static hf_register_info hf[] = {
159     { &hf_cmip_actionType_OID,
160       { "actionType", "cmip.actionType_OID",
161         FT_STRING, BASE_NONE, NULL, 0,
162         NULL, HFILL }},
163     { &hf_cmip_eventType_OID,
164       { "eventType", "cmip.eventType_OID",
165         FT_STRING, BASE_NONE, NULL, 0,
166         NULL, HFILL }},
167     { &hf_cmip_attributeId_OID,
168       { "attributeId", "cmip.attributeId_OID",
169         FT_STRING, BASE_NONE, NULL, 0,
170         NULL, HFILL }},
171     { &hf_cmip_errorId_OID,
172       { "errorId", "cmip.errorId_OID",
173         FT_STRING, BASE_NONE, NULL, 0,
174         NULL, HFILL }},
175    { &hf_DiscriminatorConstruct,
176       { "DiscriminatorConstruct", "cmip.DiscriminatorConstruct",
177         FT_UINT32, BASE_DEC, NULL, 0,
178         NULL, HFILL }},
179     { &hf_Destination,
180       { "Destination", "cmip.Destination",
181         FT_UINT32, BASE_DEC, NULL, 0,
182         NULL, HFILL }},
183     { &hf_NameBinding,
184       { "NameBinding", "cmip.NameBinding",
185         FT_STRING, BASE_NONE, NULL, 0,
186         NULL, HFILL }},
187     { &hf_ObjectClass,
188       { "ObjectClass", "cmip.ObjectClass",
189         FT_UINT32, BASE_DEC, VALS(cmip_ObjectClass_vals), 0,
190         NULL, HFILL }},
191
192 #include "packet-cmip-hfarr.c"
193   };
194
195   /* List of subtrees */
196   static gint *ett[] = {
197     &ett_cmip,
198 #include "packet-cmip-ettarr.c"
199   };
200
201   /* Register protocol */
202   proto_cmip = proto_register_protocol(PNAME, PSNAME, PFNAME);
203
204   /* Register fields and subtrees */
205   proto_register_field_array(proto_cmip, hf, array_length(hf));
206   proto_register_subtree_array(ett, array_length(ett));
207 #include "packet-cmip-dis-tab.c"
208     oid_add_from_string("discriminatorId(1)","2.9.3.2.7.1");
209
210 }
211
212
213 /*--- proto_reg_handoff_cmip -------------------------------------------*/
214 void proto_reg_handoff_cmip(void) {
215         register_ber_oid_dissector("2.9.0.0.2", dissect_cmip, proto_cmip, "cmip");
216         register_ber_oid_dissector("2.9.1.1.4", dissect_cmip, proto_cmip, "joint-iso-itu-t(2) ms(9) cmip(1) cmip-pci(1) abstractSyntax(4)");
217
218         oid_add_from_string("2.9.3.2.3.1","managedObjectClass(3) alarmRecord(1)");  
219         oid_add_from_string("2.9.3.2.3.2","managedObjectClass(3) attributeValueChangeRecord(2)");
220         oid_add_from_string("2.9.3.2.3.3","managedObjectClass(3) discriminator(3)");
221         oid_add_from_string("2.9.3.2.3.4","managedObjectClass(3) eventForwardingDiscriminator(4)");
222         oid_add_from_string("2.9.3.2.3.5","managedObjectClass(3) eventLogRecord(5)");
223         oid_add_from_string("2.9.3.2.3.6","managedObjectClass(3) log(6)");
224         oid_add_from_string("2.9.3.2.3.7","managedObjectClass(3) logRecord(7)");
225         oid_add_from_string("2.9.3.2.3.8","managedObjectClass(3) objectCreationRecord(8)");
226         oid_add_from_string("2.9.3.2.3.9","managedObjectClass(3) objectDeletionRecord(9)");
227         oid_add_from_string("2.9.3.2.3.10","managedObjectClass(3) relationshipChangeRecord(10)");
228         oid_add_from_string("2.9.3.2.3.11","managedObjectClass(3) securityAlarmReportRecord(11)");
229         oid_add_from_string("2.9.3.2.3.12","managedObjectClass(3) stateChangeRecord(12)");
230         oid_add_from_string("2.9.3.2.3.13","managedObjectClass(3) system(13)");
231         oid_add_from_string("2.9.3.2.3.14","managedObjectClass(3) top(14)");
232         oid_add_from_string("2.9.3.2.4.14","administrativeStatePackage(14)");
233         oid_add_from_string("2.9.1.1.4","joint-iso-itu-t(2) ms(9) cmip(1) cmip-pci(1) abstractSyntax(4)");
234
235 /*#include "packet-cmip-dis-tab.c" */
236 }
237