We always HAVE_CONFIG_H so don't bother checking whether we have it or not.
[metze/wireshark/wip.git] / asn1 / s1ap / packet-s1ap-template.c
1 /* packet-s1ap.c
2  * Routines for E-UTRAN S1 Application Protocol (S1AP) packet dissection
3  * Copyright 2007-2010, Anders Broman <anders.broman@ericsson.com>
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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24  *
25  * Based on the RANAP dissector
26  *
27  * References: 3GPP TS 36.413 V9.2.0 (2010-03)
28  */
29
30 #include "config.h"
31
32 #include <glib.h>
33 #include <epan/packet.h>
34
35 #include <ctype.h>
36 #include <epan/strutil.h>
37 #include <epan/asn1.h>
38 #include <epan/prefs.h>
39 #include <epan/sctpppids.h>
40
41 #include "packet-ber.h"
42 #include "packet-per.h"
43 #include "packet-e212.h"
44 #include "packet-sccp.h"
45 #include "packet-lte-rrc.h"
46 #include "packet-ranap.h"
47 #include "packet-bssgp.h"
48 #include "packet-s1ap.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  "S1 Application Protocol"
56 #define PSNAME "S1AP"
57 #define PFNAME "s1ap"
58
59 /* Dissector will use SCTP PPID 18 or SCTP port. IANA assigned port = 36412 */
60 #define SCTP_PORT_S1AP  36412
61
62 static dissector_handle_t nas_eps_handle;
63 static dissector_handle_t lppa_handle;
64 static dissector_handle_t bssgp_handle;
65
66 #include "packet-s1ap-val.h"
67
68 /* Initialize the protocol and registered fields */
69 static int proto_s1ap = -1;
70
71 static int hf_s1ap_transportLayerAddressIPv4 = -1;
72 static int hf_s1ap_transportLayerAddressIPv6 = -1;
73 #include "packet-s1ap-hf.c"
74
75 /* Initialize the subtree pointers */
76 static int ett_s1ap = -1;
77 static int ett_s1ap_TransportLayerAddress = -1;
78 static int ett_s1ap_ToTargetTransparentContainer = -1;
79 static int ett_s1ap_ToSourceTransparentContainer = -1;
80 static int ett_s1ap_RRCContainer = -1;
81 static int ett_s1ap_UERadioCapability = -1;
82 static int ett_s1ap_RIMInformation = -1;
83
84 #include "packet-s1ap-ett.c"
85
86 enum{
87         INITIATING_MESSAGE,
88         SUCCESSFUL_OUTCOME,
89         UNSUCCESSFUL_OUTCOME
90 };
91
92 /* Global variables */
93 static guint32 ProcedureCode;
94 static guint32 ProtocolIE_ID;
95 static guint32 ProtocolExtensionID;
96 static guint gbl_s1apSctpPort=SCTP_PORT_S1AP;
97 static guint32 handover_type_value;
98 static guint32 message_type;
99 static gboolean g_s1ap_dissect_container = TRUE;
100
101 /* Dissector tables */
102 static dissector_table_t s1ap_ies_dissector_table;
103 static dissector_table_t s1ap_ies_p1_dissector_table;
104 static dissector_table_t s1ap_ies_p2_dissector_table;
105 static dissector_table_t s1ap_extension_dissector_table;
106 static dissector_table_t s1ap_proc_imsg_dissector_table;
107 static dissector_table_t s1ap_proc_sout_dissector_table;
108 static dissector_table_t s1ap_proc_uout_dissector_table;
109
110 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
111 /* Currently not used
112 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
113 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
114 */
115 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
116 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
117 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
118 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
119
120 static int dissect_SourceeNB_ToTargeteNB_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
121 static int dissect_TargeteNB_ToSourceeNB_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
122 #if 0
123 static int dissect_SourceRNC_ToTargetRNC_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
124 static int dissect_TargetRNC_ToSourceRNC_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
125 static int dissect_SourceBSS_ToTargetBSS_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
126 static int dissect_TargetBSS_ToSourceBSS_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
127 #endif
128
129 #include "packet-s1ap-fn.c"
130
131 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
132 {
133   return (dissector_try_uint(s1ap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
134 }
135 /* Currently not used
136 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
137 {
138   return (dissector_try_uint(s1ap_ies_p1_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
139 }
140
141 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
142 {
143   return (dissector_try_uint(s1ap_ies_p2_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
144 }
145 */
146
147 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
148 {
149   return (dissector_try_uint(s1ap_extension_dissector_table, ProtocolExtensionID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
150 }
151
152 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
153 {
154   return (dissector_try_uint(s1ap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
155 }
156
157 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
158 {
159   return (dissector_try_uint(s1ap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
160 }
161
162 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
163 {
164   return (dissector_try_uint(s1ap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
165 }
166
167
168 static void
169 dissect_s1ap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
170 {
171         proto_item      *s1ap_item = NULL;
172         proto_tree      *s1ap_tree = NULL;
173
174         /* make entry in the Protocol column on summary display */
175         col_set_str(pinfo->cinfo, COL_PROTOCOL, "S1AP");
176
177         /* create the s1ap protocol tree */
178         s1ap_item = proto_tree_add_item(tree, proto_s1ap, tvb, 0, -1, ENC_NA);
179         s1ap_tree = proto_item_add_subtree(s1ap_item, ett_s1ap);
180
181         dissect_S1AP_PDU_PDU(tvb, pinfo, s1ap_tree, NULL);
182 }
183
184 /*--- proto_reg_handoff_s1ap ---------------------------------------*/
185 void
186 proto_reg_handoff_s1ap(void)
187 {
188         static gboolean Initialized=FALSE;
189         static dissector_handle_t s1ap_handle;
190         static guint SctpPort;
191
192         s1ap_handle = find_dissector("s1ap");
193
194         if (!Initialized) {
195                 nas_eps_handle = find_dissector("nas-eps");
196                 lppa_handle = find_dissector("lppa");
197                 bssgp_handle = find_dissector("bssgp");
198                 dissector_add_handle("sctp.port", s1ap_handle);   /* for "decode-as"  */
199                 dissector_add_uint("sctp.ppi", S1AP_PAYLOAD_PROTOCOL_ID,   s1ap_handle);
200                 Initialized=TRUE;
201 #include "packet-s1ap-dis-tab.c"
202         } else {
203                 if (SctpPort != 0) {
204                         dissector_delete_uint("sctp.port", SctpPort, s1ap_handle);
205                 }
206         }
207
208         SctpPort=gbl_s1apSctpPort;
209         if (SctpPort != 0) {
210                 dissector_add_uint("sctp.port", SctpPort, s1ap_handle);
211         }
212 }
213
214 /*--- proto_register_s1ap -------------------------------------------*/
215 void proto_register_s1ap(void) {
216
217   /* List of fields */
218
219   static hf_register_info hf[] = {
220     { &hf_s1ap_transportLayerAddressIPv4,
221       { "transportLayerAddress(IPv4)", "s1ap.transportLayerAddressIPv4",
222         FT_IPv4, BASE_NONE, NULL, 0,
223         NULL, HFILL }},
224     { &hf_s1ap_transportLayerAddressIPv6,
225       { "transportLayerAddress(IPv6)", "s1ap.transportLayerAddressIPv6",
226         FT_IPv6, BASE_NONE, NULL, 0,
227         NULL, HFILL }},
228
229 #include "packet-s1ap-hfarr.c"
230   };
231
232   /* List of subtrees */
233   static gint *ett[] = {
234                   &ett_s1ap,
235                   &ett_s1ap_TransportLayerAddress,
236                   &ett_s1ap_ToTargetTransparentContainer,
237                   &ett_s1ap_ToSourceTransparentContainer,
238                   &ett_s1ap_RRCContainer,
239                   &ett_s1ap_UERadioCapability,
240                   &ett_s1ap_RIMInformation,
241 #include "packet-s1ap-ettarr.c"
242   };
243
244   module_t *s1ap_module;
245
246   /* Register protocol */
247   proto_s1ap = proto_register_protocol(PNAME, PSNAME, PFNAME);
248   /* Register fields and subtrees */
249   proto_register_field_array(proto_s1ap, hf, array_length(hf));
250   proto_register_subtree_array(ett, array_length(ett));
251
252   /* Register dissector */
253   register_dissector("s1ap", dissect_s1ap, proto_s1ap);
254
255   /* Register dissector tables */
256   s1ap_ies_dissector_table = register_dissector_table("s1ap.ies", "S1AP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
257   s1ap_ies_p1_dissector_table = register_dissector_table("s1ap.ies.pair.first", "S1AP-PROTOCOL-IES-PAIR FirstValue", FT_UINT32, BASE_DEC);
258   s1ap_ies_p2_dissector_table = register_dissector_table("s1ap.ies.pair.second", "S1AP-PROTOCOL-IES-PAIR SecondValue", FT_UINT32, BASE_DEC);
259   s1ap_extension_dissector_table = register_dissector_table("s1ap.extension", "S1AP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
260   s1ap_proc_imsg_dissector_table = register_dissector_table("s1ap.proc.imsg", "S1AP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC);
261   s1ap_proc_sout_dissector_table = register_dissector_table("s1ap.proc.sout", "S1AP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC);
262   s1ap_proc_uout_dissector_table = register_dissector_table("s1ap.proc.uout", "S1AP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC);
263
264   /* Register configuration options for ports */
265   s1ap_module = prefs_register_protocol(proto_s1ap, proto_reg_handoff_s1ap);
266
267   prefs_register_uint_preference(s1ap_module, "sctp.port",
268                                  "S1AP SCTP Port",
269                                  "Set the SCTP port for S1AP messages",
270                                  10,
271                                  &gbl_s1apSctpPort);
272   prefs_register_bool_preference(s1ap_module, "dissect_container", "Dissect TransparentContainer", "Dissect TransparentContainers that are opaque to S1AP", &g_s1ap_dissect_container);
273
274 }
275
276
277
278
279