From KATAOKA Toshihiro:
[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
38 #include <stdio.h>
39 #include <string.h>
40
41 #include <epan/asn1.h>
42 #include <epan/prefs.h>
43 #include <epan/sctpppids.h>
44
45 #include "packet-per.h"
46 #include "packet-e212.h"
47 #include "packet-frame.h"
48 #include "packet-lte-rrc.h"
49
50 #ifdef _MSC_VER
51 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
52 #pragma warning(disable:4146)
53 #endif
54
55 #define PNAME  "EUTRAN X2 Application Protocol (X2AP)"
56 #define PSNAME "X2AP"
57 #define PFNAME "x2ap"
58
59 /* Dissector will use SCTP PPID 27 or SCTP port. IANA assigned port = 36422 */
60 #define SCTP_PORT_X2AP  36422
61
62 #include "packet-x2ap-val.h"
63
64 /* Initialize the protocol and registered fields */
65 static int proto_x2ap = -1;
66 static int hf_x2ap_transportLayerAddressIPv4 = -1;
67 static int hf_x2ap_transportLayerAddressIPv6 = -1;
68 #include "packet-x2ap-hf.c"
69
70 /* Initialize the subtree pointers */
71 static int ett_x2ap = -1;
72 static int ett_x2ap_TransportLayerAddress = -1;
73 #include "packet-x2ap-ett.c"
74
75 /* Global variables */
76 static guint32 ProcedureCode;
77 static guint32 ProtocolIE_ID;
78 static guint gbl_x2apSctpPort=SCTP_PORT_X2AP;
79
80 /* Dissector tables */
81 static dissector_table_t x2ap_ies_dissector_table;
82 static dissector_table_t x2ap_extension_dissector_table;
83 static dissector_table_t x2ap_proc_imsg_dissector_table;
84 static dissector_table_t x2ap_proc_sout_dissector_table;
85 static dissector_table_t x2ap_proc_uout_dissector_table;
86
87 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
88 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
89 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
90 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
91 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
92 void proto_reg_handoff_x2ap(void);
93
94 #include "packet-x2ap-fn.c"
95
96 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
97 {
98   return (dissector_try_port(x2ap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
99 }
100
101 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
102 {
103   return (dissector_try_port(x2ap_extension_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
104 }
105
106 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
107 {
108   return (dissector_try_port(x2ap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
109 }
110
111 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
112 {
113   return (dissector_try_port(x2ap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
114 }
115
116 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
117 {
118   return (dissector_try_port(x2ap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
119 }
120
121 static void
122 dissect_x2ap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
123 {
124         proto_item      *x2ap_item = NULL;
125         proto_tree      *x2ap_tree = NULL;
126
127         /* make entry in the Protocol column on summary display */
128         col_set_str(pinfo->cinfo, COL_PROTOCOL, "X2AP");
129
130         /* create the x2ap protocol tree */
131         x2ap_item = proto_tree_add_item(tree, proto_x2ap, tvb, 0, -1, FALSE);
132         x2ap_tree = proto_item_add_subtree(x2ap_item, ett_x2ap);
133         
134         dissect_X2AP_PDU_PDU(tvb, pinfo, x2ap_tree);
135 }
136
137 /*--- proto_register_x2ap -------------------------------------------*/
138 void proto_register_x2ap(void) {
139
140   /* List of fields */
141
142   static hf_register_info hf[] = {
143     { &hf_x2ap_transportLayerAddressIPv4,
144       { "transportLayerAddress(IPv4)", "x2ap.transportLayerAddressIPv4",
145         FT_IPv4, BASE_NONE, NULL, 0,
146         NULL, HFILL }},
147     { &hf_x2ap_transportLayerAddressIPv6,
148       { "transportLayerAddress(IPv6)", "x2ap.transportLayerAddressIPv6",
149         FT_IPv4, BASE_NONE, NULL, 0,
150         NULL, HFILL }},
151
152 #include "packet-x2ap-hfarr.c"
153   };
154
155   /* List of subtrees */
156   static gint *ett[] = {
157                   &ett_x2ap,
158                   &ett_x2ap_TransportLayerAddress,
159 #include "packet-x2ap-ettarr.c"
160   };
161
162   module_t *x2ap_module;
163
164   /* Register protocol */
165   proto_x2ap = proto_register_protocol(PNAME, PSNAME, PFNAME);
166   /* Register fields and subtrees */
167   proto_register_field_array(proto_x2ap, hf, array_length(hf));
168   proto_register_subtree_array(ett, array_length(ett));
169  
170   /* Register dissector */
171   register_dissector("x2ap", dissect_x2ap, proto_x2ap);
172
173   /* Register dissector tables */
174   x2ap_ies_dissector_table = register_dissector_table("x2ap.ies", "X2AP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
175   x2ap_extension_dissector_table = register_dissector_table("x2ap.extension", "X2AP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
176   x2ap_proc_imsg_dissector_table = register_dissector_table("x2ap.proc.imsg", "X2AP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC);
177   x2ap_proc_sout_dissector_table = register_dissector_table("x2ap.proc.sout", "X2AP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC);
178   x2ap_proc_uout_dissector_table = register_dissector_table("x2ap.proc.uout", "X2AP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC);
179
180   /* Register configuration options for ports */
181   x2ap_module = prefs_register_protocol(proto_x2ap, proto_reg_handoff_x2ap);
182
183   prefs_register_uint_preference(x2ap_module, "sctp.port",
184                                  "X2AP SCTP Port",
185                                  "Set the SCTP port for X2AP messages",
186                                  10,
187                                  &gbl_x2apSctpPort);
188
189 }
190
191
192 /*--- proto_reg_handoff_x2ap ---------------------------------------*/
193 void
194 proto_reg_handoff_x2ap(void)
195 {
196         dissector_handle_t x2ap_handle;
197         static gboolean Initialized=FALSE;
198         static guint SctpPort;
199
200         x2ap_handle = find_dissector("x2ap");
201         if (!Initialized) {
202                 dissector_add_handle("sctp.port", x2ap_handle);  /* for "decode-as" */
203                 dissector_add("sctp.ppi", X2AP_PAYLOAD_PROTOCOL_ID, x2ap_handle);
204                 Initialized=TRUE;
205 #include "packet-x2ap-dis-tab.c"
206         } else {
207                 if (SctpPort != 0) {
208                         dissector_delete("sctp.port", SctpPort, x2ap_handle);
209                 }
210         }
211
212         SctpPort=gbl_x2apSctpPort;
213         if (SctpPort != 0) {
214                 dissector_add("sctp.port", SctpPort, x2ap_handle);
215         }
216
217 }
218
219