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