- dissect_ber_object_identifier() returns value as tvb
[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  * Ethereal - Network traffic analyzer
8  * By Gerald Combs <gerald@ethereal.com>
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/conversation.h>
33
34 #include <stdio.h>
35 #include <string.h>
36
37 #include "packet-ber.h"
38 #include "packet-acse.h"
39 #include "packet-x509if.h"
40 #include "packet-cmip.h"
41
42 #define PNAME  "X711 CMIP"
43 #define PSNAME "CMIP"
44 #define PFNAME "cmip"
45
46 /* XXX some stuff we need until we can get rid of it */
47 #include "packet-ses.h"
48 #include "packet-pres.h"
49
50 /* Initialize the protocol and registered fields */
51 int proto_cmip = -1;
52 static int hf_cmip_actionType_OID = -1;
53 static int hf_cmip_eventType_OID = -1;
54 static int hf_cmip_attributeId_OID = -1;
55 static int hf_cmip_errorId_OID = -1;
56 static int hf_DiscriminatorConstruct = -1;
57 static int hf_Destination = -1;
58 static int hf_NameBinding = -1;
59 static int hf_ObjectClass = -1;
60 static int hf_OperationalState = -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 static int opcode_type;
70 #define OPCODE_INVOKE        1
71 #define OPCODE_RETURN_RESULT 2
72 #define OPCODE_RETURN_ERROR  3
73 #define OPCODE_REJECT        4
74
75 static int attributeform;
76 #define ATTRIBUTE_LOCAL_FORM  0
77 #define ATTRIBUTE_GLOBAL_FORM 1
78 static const char *attribute_identifier_id;
79
80 static const char *attributevalueassertion_id;
81
82 static const char *object_identifier_id;
83
84 static int objectclassform;
85 #define OBJECTCLASS_LOCAL_FORM  0
86 #define OBJECTCLASS_GLOBAL_FORM 1
87 static const char *objectclass_identifier_id;
88
89 #include "packet-cmip-fn.c"
90
91
92 static void
93 dissect_cmip_attribute_35(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
94 {
95
96         dissect_cmip_OperationalState(FALSE, tvb, 0, pinfo, parent_tree, hf_OperationalState);
97
98 }
99
100 static void
101 dissect_cmip_attribute_55(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
102 {
103
104         dissect_cmip_Destination(FALSE, tvb, 0, pinfo, parent_tree,hf_Destination);
105
106 }
107
108 static void
109 dissect_cmip_attribute_56(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
110 {
111
112         dissect_cmip_DiscriminatorConstruct(FALSE, tvb, 0, pinfo, parent_tree, hf_DiscriminatorConstruct);
113
114 }
115
116 static void
117 dissect_cmip_attribute_63(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
118 {
119
120         dissect_cmip_NameBinding(FALSE, tvb, 0, pinfo, parent_tree, hf_NameBinding);
121
122 }
123
124 static void
125 dissect_cmip_attribute_65(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
126 {
127
128         dissect_cmip_ObjectClass(FALSE, tvb, 0, pinfo, parent_tree, hf_ObjectClass);
129
130 }
131
132
133 /* XXX this one should be broken out later and moved into the conformance file */
134 static void
135 dissect_cmip(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
136 {
137         static struct SESSION_DATA_STRUCTURE* session = NULL;
138         proto_item *item = NULL;
139         proto_tree *tree = NULL;
140
141
142         /* do we have spdu type from the session dissector?  */
143         if( !pinfo->private_data ){
144                 if(tree){
145                         proto_tree_add_text(tree, tvb, 0, -1,
146                                 "Internal error:can't get spdu type from session dissector.");
147                         return;
148                 }
149         } else {
150                 session  = ( (struct SESSION_DATA_STRUCTURE*)(pinfo->private_data) );
151                 if(session->spdu_type == 0 ){
152                         if(tree){
153                                 proto_tree_add_text(tree, tvb, 0, -1,
154                                         "Internal error:wrong spdu type %x from session dissector.",session->spdu_type);
155                                 return;
156                         }
157                 }
158         }
159
160         if(parent_tree){
161                 item = proto_tree_add_item(parent_tree, proto_cmip, tvb, 0, -1, FALSE);
162                 tree = proto_item_add_subtree(item, ett_cmip);
163         }
164
165         if (check_col(pinfo->cinfo, COL_PROTOCOL))
166                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "CMIP");
167         if (check_col(pinfo->cinfo, COL_INFO))
168                 col_clear(pinfo->cinfo, COL_INFO);
169         switch(session->spdu_type){
170                 case SES_CONNECTION_REQUEST:
171                 case SES_CONNECTION_ACCEPT:
172                 case SES_DISCONNECT:
173                 case SES_FINISH:
174                 case SES_REFUSE:
175                         dissect_cmip_CMIPUserInfo(FALSE,tvb,0,pinfo,tree,-1);
176                         break;
177                 case SES_ABORT:
178                         dissect_cmip_CMIPAbortInfo(FALSE,tvb,0,pinfo,tree,-1);
179                         break;
180                 case SES_DATA_TRANSFER:
181                         dissect_cmip_ROS(FALSE,tvb,0,pinfo,tree,-1);
182                         break;
183                 default:
184                         ;
185         }
186 }
187
188 /*--- proto_register_cmip ----------------------------------------------*/
189 void proto_register_cmip(void) {
190
191   /* List of fields */
192   static hf_register_info hf[] = {
193     { &hf_cmip_actionType_OID,
194       { "actionType", "cmip.actionType_OID",
195         FT_STRING, BASE_NONE, NULL, 0,
196         "actionType", HFILL }},
197     { &hf_cmip_eventType_OID,
198       { "eventType", "cmip.eventType_OID",
199         FT_STRING, BASE_NONE, NULL, 0,
200         "eventType", HFILL }},
201     { &hf_cmip_attributeId_OID,
202       { "attributeId", "cmip.attributeId_OID",
203         FT_STRING, BASE_NONE, NULL, 0,
204         "attributeId", HFILL }},
205     { &hf_cmip_errorId_OID,
206       { "errorId", "cmip.errorId_OID",
207         FT_STRING, BASE_NONE, NULL, 0,
208         "errorId", HFILL }},
209    { &hf_DiscriminatorConstruct,
210       { "DiscriminatorConstruct", "cmip.DiscriminatorConstruct",
211         FT_UINT32, BASE_DEC, NULL, 0,
212         "", HFILL }},
213     { &hf_Destination,
214       { "Destination", "cmip.Destination",
215         FT_UINT32, BASE_DEC, NULL, 0,
216         "", HFILL }},
217     { &hf_NameBinding,
218       { "NameBinding", "cmip.NameBinding",
219         FT_STRING, BASE_NONE, NULL, 0,
220         "", HFILL }},
221     { &hf_ObjectClass,
222       { "ObjectClass", "cmip.ObjectClass",
223         FT_UINT32, BASE_DEC, VALS(cmip_ObjectClass_vals), 0,
224         "", HFILL }},
225     { &hf_OperationalState,
226       { "OperationalState", "cmip.OperationalState",
227         FT_UINT32, BASE_DEC, VALS(cmip_OperationalState_vals), 0,
228         "", HFILL }},
229
230 #include "packet-cmip-hfarr.c"
231   };
232
233   /* List of subtrees */
234   static gint *ett[] = {
235     &ett_cmip,
236 #include "packet-cmip-ettarr.c"
237   };
238
239   /* Register protocol */
240   proto_cmip = proto_register_protocol(PNAME, PSNAME, PFNAME);
241
242   /* Register fields and subtrees */
243   proto_register_field_array(proto_cmip, hf, array_length(hf));
244   proto_register_subtree_array(ett, array_length(ett));
245
246 }
247
248
249 /*--- proto_reg_handoff_cmip -------------------------------------------*/
250 void proto_reg_handoff_cmip(void) {
251         register_ber_oid_dissector("2.9.0.0.2", dissect_cmip, proto_cmip, "cmip");
252         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)");
253         register_ber_oid_dissector("2.9.3.2.7.35", dissect_cmip_attribute_35, proto_cmip, "smi2AttributeID (7) operationalState(35)");
254         register_ber_oid_dissector("2.9.3.2.7.55", dissect_cmip_attribute_55, proto_cmip, "smi2AttributeID (7) destination(55)");
255         register_ber_oid_dissector("2.9.3.2.7.56", dissect_cmip_attribute_56, proto_cmip, "smi2AttributeID (7) discriminatorConstruct(56)");
256         register_ber_oid_dissector("2.9.3.2.7.63", dissect_cmip_attribute_63, proto_cmip, "smi2AttributeID (7) nameBinding(63)");
257         register_ber_oid_dissector("2.9.3.2.7.65", dissect_cmip_attribute_65, proto_cmip, "smi2AttributeID (7) objectClass(65)");
258
259         register_ber_oid_name("2.9.3.2.3.4","eventForwardingDiscriminator(4)");
260         register_ber_oid_name("2.9.1.1.4","joint-iso-itu-t(2) ms(9) cmip(1) cmip-pci(1) abstractSyntax(4)");
261
262 }
263