Minor cleanup mostly related to proto_reg_handoff
[obnox/wireshark/wip.git] / asn1 / x2ap / packet-x2ap-template.c
1 /* packet-x2ap.c
2  * Routines for dissecting Evolved Universal Terrestrial Radio Access Network (EUTRAN);
3  * X2 Application Protocol (X2AP);
4  * 3GPP TS 36.423 packet dissection
5  * Copyright 2007-2008, Anders Broman <anders.broman@ericsson.com>
6  *
7  * $Id$
8  *
9  * Wireshark - Network traffic analyzer
10  * By Gerald Combs <gerald@wireshark.org>
11  * Copyright 1998 Gerald Combs
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software
25  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
26  *
27  * Ref: 
28  * 3GPP TS 36.423 V8.0.0 (2007-12)
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/conversation.h>
38
39 #include <stdio.h>
40 #include <string.h>
41
42 #include <epan/asn1.h>
43
44 #include "packet-per.h"
45
46 #ifdef _MSC_VER
47 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
48 #pragma warning(disable:4146)
49 #endif
50
51 #define PNAME  "EUTRAN X2 Application Protocol (X2AP)"
52 #define PSNAME "X2AP"
53 #define PFNAME "x2ap"
54
55 #define SCCP_SSN_X2AP 143
56
57 #include "packet-x2ap-val.h"
58
59 /* Initialize the protocol and registered fields */
60 static int proto_x2ap = -1;
61
62 #include "packet-x2ap-hf.c"
63
64 /* Initialize the subtree pointers */
65 static int ett_x2ap = -1;
66
67 #include "packet-x2ap-ett.c"
68
69 /* Global variables */
70 static guint32 ProcedureCode;
71 static guint32 ProtocolIE_ID;
72 static const gchar *ProcedureID;
73
74 /* Dissector tables */
75 static dissector_table_t x2ap_ies_dissector_table;
76 static dissector_table_t x2ap_extension_dissector_table;
77 static dissector_table_t x2ap_proc_imsg_dissector_table;
78 static dissector_table_t x2ap_proc_sout_dissector_table;
79 static dissector_table_t x2ap_proc_uout_dissector_table;
80
81 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
82 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
83 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
84 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
85 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
86
87 #include "packet-x2ap-fn.c"
88
89 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
90 {
91   return (dissector_try_port(x2ap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
92 }
93
94 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
95 {
96   return (dissector_try_port(x2ap_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
97 }
98
99 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
100 {
101   if (!ProcedureID) return 0;
102   return (dissector_try_string(x2ap_proc_imsg_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
103 }
104
105 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
106 {
107   if (!ProcedureID) return 0;
108   return (dissector_try_string(x2ap_proc_sout_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
109 }
110
111 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
112 {
113   if (!ProcedureID) return 0;
114   return (dissector_try_string(x2ap_proc_uout_dissector_table, ProcedureID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
115 }
116
117 static void
118 dissect_x2ap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
119 {
120         proto_item      *x2ap_item = NULL;
121         proto_tree      *x2ap_tree = NULL;
122
123         /* make entry in the Protocol column on summary display */
124         if (check_col(pinfo->cinfo, COL_PROTOCOL))
125                 col_set_str(pinfo->cinfo, COL_PROTOCOL, "X2AP");
126
127         /* create the x2ap protocol tree */
128         x2ap_item = proto_tree_add_item(tree, proto_x2ap, tvb, 0, -1, FALSE);
129         x2ap_tree = proto_item_add_subtree(x2ap_item, ett_x2ap);
130         
131         dissect_X2AP_PDU_PDU(tvb, pinfo, x2ap_tree);
132 }
133
134 /*--- proto_register_x2ap -------------------------------------------*/
135 void proto_register_x2ap(void) {
136
137   /* List of fields */
138
139   static hf_register_info hf[] = {
140 #include "packet-x2ap-hfarr.c"
141   };
142
143   /* List of subtrees */
144   static gint *ett[] = {
145                   &ett_x2ap,
146 #include "packet-x2ap-ettarr.c"
147   };
148
149
150   /* Register protocol */
151   proto_x2ap = proto_register_protocol(PNAME, PSNAME, PFNAME);
152   /* Register fields and subtrees */
153   proto_register_field_array(proto_x2ap, hf, array_length(hf));
154   proto_register_subtree_array(ett, array_length(ett));
155  
156   /* Register dissector */
157   register_dissector("x2ap", dissect_x2ap, proto_x2ap);
158
159   /* Register dissector tables */
160   x2ap_ies_dissector_table = register_dissector_table("x2ap.ies", "X2AP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
161   x2ap_extension_dissector_table = register_dissector_table("x2ap.extension", "X2AP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
162   x2ap_proc_imsg_dissector_table = register_dissector_table("x2ap.proc.imsg", "X2AP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_STRING, BASE_NONE);
163   x2ap_proc_sout_dissector_table = register_dissector_table("x2ap.proc.sout", "X2AP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_STRING, BASE_NONE);
164   x2ap_proc_uout_dissector_table = register_dissector_table("x2ap.proc.uout", "X2AP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_STRING, BASE_NONE);
165
166 }
167
168
169 /*--- proto_reg_handoff_x2ap ---------------------------------------*/
170 void
171 proto_reg_handoff_x2ap(void)
172 {
173         dissector_handle_t x2ap_handle;
174
175         x2ap_handle = find_dissector("x2ap");
176         dissector_add("sctp.port", 0, x2ap_handle);
177
178 #include "packet-x2ap-dis-tab.c"
179 }
180
181