2 * Routines for E-UTRAN S1 Application Protocol (S1AP) packet dissection
3 * Copyright 2007-2010, Anders Broman <anders.broman@ericsson.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
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.
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.
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.
23 * Based on the RANAP dissector
25 * References: 3GPP TS 36.413 V9.2.0 (2010-03)
30 #include <epan/packet.h>
32 #include <epan/strutil.h>
33 #include <epan/asn1.h>
34 #include <epan/prefs.h>
35 #include <epan/sctpppids.h>
37 #include "packet-ber.h"
38 #include "packet-per.h"
39 #include "packet-e212.h"
40 #include "packet-sccp.h"
41 #include "packet-lte-rrc.h"
42 #include "packet-ranap.h"
43 #include "packet-bssgp.h"
44 #include "packet-s1ap.h"
45 #include "packet-a21.h"
48 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
49 #pragma warning(disable:4146)
52 #define PNAME "S1 Application Protocol"
56 /* Dissector will use SCTP PPID 18 or SCTP port. IANA assigned port = 36412 */
57 #define SCTP_PORT_S1AP 36412
59 void proto_register_s1ap(void);
60 void proto_reg_handoff_s1ap(void);
62 static dissector_handle_t nas_eps_handle;
63 static dissector_handle_t lppa_handle;
64 static dissector_handle_t bssgp_handle;
66 #include "packet-s1ap-val.h"
68 /* Initialize the protocol and registered fields */
69 static int proto_s1ap = -1;
71 static int hf_s1ap_transportLayerAddressIPv4 = -1;
72 static int hf_s1ap_transportLayerAddressIPv6 = -1;
73 #include "packet-s1ap-hf.c"
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 static int ett_s1ap_Cdma2000PDU = -1;
84 static int ett_s1ap_Cdma2000SectorID = -1;
86 #include "packet-s1ap-ett.c"
95 /* Global variables */
96 static guint32 ProcedureCode;
97 static guint32 ProtocolIE_ID;
98 static guint32 ProtocolExtensionID;
99 static guint gbl_s1apSctpPort=SCTP_PORT_S1AP;
100 static guint32 handover_type_value;
101 static guint32 message_type;
102 static gboolean g_s1ap_dissect_container = TRUE;
103 static const char *obj_id = NULL;
105 static dissector_handle_t gcsna_handle = NULL;
107 /* Dissector tables */
108 static dissector_table_t s1ap_ies_dissector_table;
109 static dissector_table_t s1ap_ies_p1_dissector_table;
110 static dissector_table_t s1ap_ies_p2_dissector_table;
111 static dissector_table_t s1ap_extension_dissector_table;
112 static dissector_table_t s1ap_proc_imsg_dissector_table;
113 static dissector_table_t s1ap_proc_sout_dissector_table;
114 static dissector_table_t s1ap_proc_uout_dissector_table;
116 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
117 /* Currently not used
118 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
119 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
121 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
122 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
123 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
124 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
126 static int dissect_SourceeNB_ToTargeteNB_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
127 static int dissect_TargeteNB_ToSourceeNB_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
129 static int dissect_SourceRNC_ToTargetRNC_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
130 static int dissect_TargetRNC_ToSourceRNC_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
131 static int dissect_SourceBSS_ToTargetBSS_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
132 static int dissect_TargetBSS_ToSourceBSS_TransparentContainer_PDU(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
135 #include "packet-s1ap-fn.c"
137 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
141 s1ap_ctx.message_type = message_type;
142 s1ap_ctx.ProcedureCode = ProcedureCode;
143 s1ap_ctx.ProtocolIE_ID = ProtocolIE_ID;
144 s1ap_ctx.ProtocolExtensionID = ProtocolExtensionID;
146 return (dissector_try_uint_new(s1ap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, TRUE, &s1ap_ctx)) ? tvb_captured_length(tvb) : 0;
148 /* Currently not used
149 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
151 return (dissector_try_uint(s1ap_ies_p1_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
154 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
156 return (dissector_try_uint(s1ap_ies_p2_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
160 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
164 s1ap_ctx.message_type = message_type;
165 s1ap_ctx.ProcedureCode = ProcedureCode;
166 s1ap_ctx.ProtocolIE_ID = ProtocolIE_ID;
167 s1ap_ctx.ProtocolExtensionID = ProtocolExtensionID;
169 return (dissector_try_uint_new(s1ap_extension_dissector_table, ProtocolExtensionID, tvb, pinfo, tree, TRUE, &s1ap_ctx)) ? tvb_captured_length(tvb) : 0;
172 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
174 return (dissector_try_uint_new(s1ap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree, TRUE, data)) ? tvb_captured_length(tvb) : 0;
177 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
179 return (dissector_try_uint_new(s1ap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree, TRUE, data)) ? tvb_captured_length(tvb) : 0;
182 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
184 return (dissector_try_uint_new(s1ap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree, TRUE, data)) ? tvb_captured_length(tvb) : 0;
189 dissect_s1ap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
191 proto_item *s1ap_item = NULL;
192 proto_tree *s1ap_tree = NULL;
194 /* make entry in the Protocol column on summary display */
195 col_set_str(pinfo->cinfo, COL_PROTOCOL, "S1AP");
197 /* create the s1ap protocol tree */
198 s1ap_item = proto_tree_add_item(tree, proto_s1ap, tvb, 0, -1, ENC_NA);
199 s1ap_tree = proto_item_add_subtree(s1ap_item, ett_s1ap);
201 dissect_S1AP_PDU_PDU(tvb, pinfo, s1ap_tree, NULL);
202 return tvb_captured_length(tvb);
205 /*--- proto_reg_handoff_s1ap ---------------------------------------*/
207 proto_reg_handoff_s1ap(void)
209 static gboolean Initialized=FALSE;
210 static dissector_handle_t s1ap_handle;
211 static guint SctpPort;
213 s1ap_handle = find_dissector("s1ap");
214 gcsna_handle = find_dissector("gcsna");
217 nas_eps_handle = find_dissector("nas-eps");
218 lppa_handle = find_dissector("lppa");
219 bssgp_handle = find_dissector("bssgp");
220 dissector_add_for_decode_as("sctp.port", s1ap_handle);
221 dissector_add_uint("sctp.ppi", S1AP_PAYLOAD_PROTOCOL_ID, s1ap_handle);
223 #include "packet-s1ap-dis-tab.c"
226 dissector_delete_uint("sctp.port", SctpPort, s1ap_handle);
230 SctpPort=gbl_s1apSctpPort;
232 dissector_add_uint("sctp.port", SctpPort, s1ap_handle);
236 /*--- proto_register_s1ap -------------------------------------------*/
237 void proto_register_s1ap(void) {
241 static hf_register_info hf[] = {
242 { &hf_s1ap_transportLayerAddressIPv4,
243 { "transportLayerAddress(IPv4)", "s1ap.transportLayerAddressIPv4",
244 FT_IPv4, BASE_NONE, NULL, 0,
246 { &hf_s1ap_transportLayerAddressIPv6,
247 { "transportLayerAddress(IPv6)", "s1ap.transportLayerAddressIPv6",
248 FT_IPv6, BASE_NONE, NULL, 0,
251 #include "packet-s1ap-hfarr.c"
254 /* List of subtrees */
255 static gint *ett[] = {
257 &ett_s1ap_TransportLayerAddress,
258 &ett_s1ap_ToTargetTransparentContainer,
259 &ett_s1ap_ToSourceTransparentContainer,
260 &ett_s1ap_RRCContainer,
261 &ett_s1ap_UERadioCapability,
262 &ett_s1ap_RIMInformation,
263 &ett_s1ap_Cdma2000PDU,
264 &ett_s1ap_Cdma2000SectorID,
265 #include "packet-s1ap-ettarr.c"
268 module_t *s1ap_module;
270 /* Register protocol */
271 proto_s1ap = proto_register_protocol(PNAME, PSNAME, PFNAME);
272 /* Register fields and subtrees */
273 proto_register_field_array(proto_s1ap, hf, array_length(hf));
274 proto_register_subtree_array(ett, array_length(ett));
276 /* Register dissector */
277 register_dissector("s1ap", dissect_s1ap, proto_s1ap);
279 /* Register dissector tables */
280 s1ap_ies_dissector_table = register_dissector_table("s1ap.ies", "S1AP-PROTOCOL-IES", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
281 s1ap_ies_p1_dissector_table = register_dissector_table("s1ap.ies.pair.first", "S1AP-PROTOCOL-IES-PAIR FirstValue", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
282 s1ap_ies_p2_dissector_table = register_dissector_table("s1ap.ies.pair.second", "S1AP-PROTOCOL-IES-PAIR SecondValue", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
283 s1ap_extension_dissector_table = register_dissector_table("s1ap.extension", "S1AP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
284 s1ap_proc_imsg_dissector_table = register_dissector_table("s1ap.proc.imsg", "S1AP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
285 s1ap_proc_sout_dissector_table = register_dissector_table("s1ap.proc.sout", "S1AP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
286 s1ap_proc_uout_dissector_table = register_dissector_table("s1ap.proc.uout", "S1AP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC, DISSECTOR_TABLE_ALLOW_DUPLICATE);
288 /* Register configuration options for ports */
289 s1ap_module = prefs_register_protocol(proto_s1ap, proto_reg_handoff_s1ap);
291 prefs_register_uint_preference(s1ap_module, "sctp.port",
293 "Set the SCTP port for S1AP messages",
296 prefs_register_bool_preference(s1ap_module, "dissect_container", "Dissect TransparentContainer", "Dissect TransparentContainers that are opaque to S1AP", &g_s1ap_dissect_container);