2 * Routines for E-UTRAN S1 Application Protocol (S1AP) packet dissection
3 * Copyright 2007-2009, Anders Broman <anders.broman@ericsson.com>
7 * Wireshark - Network traffic analyzer
8 * By Gerald Combs <gerald@wireshark.org>
9 * Copyright 1998 Gerald Combs
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.
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.
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
25 * Based on the RANAP dissector
27 * References: 3GPP TS 36.413 V8.5.0 (2009-03)
35 #include <epan/packet.h>
40 #include <epan/strutil.h>
41 #include <epan/asn1.h>
42 #include <epan/prefs.h>
43 #include <epan/sctpppids.h>
45 #include "packet-ber.h"
46 #include "packet-per.h"
47 #include "packet-e212.h"
48 #include "packet-sccp.h"
51 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
52 #pragma warning(disable:4146)
55 #define PNAME "S1 Application Protocol "
59 /* No SCTP port registered with IANA for S1AP yet */
60 #define SCTP_PORT_S1AP 0
62 static dissector_handle_t nas_eps_handle;
64 #include "packet-s1ap-val.h"
66 /* Initialize the protocol and registered fields */
67 static int proto_s1ap = -1;
69 static int hf_s1ap_transportLayerAddressIPv4 = -1;
70 static int hf_s1ap_transportLayerAddressIPv6 = -1;
71 #include "packet-s1ap-hf.c"
73 /* Initialize the subtree pointers */
74 static int ett_s1ap = -1;
75 static int ett_s1ap_TransportLayerAddress = -1;
77 #include "packet-s1ap-ett.c"
79 /* Global variables */
80 static guint32 ProcedureCode;
81 static guint32 ProtocolIE_ID;
82 static guint32 ProtocolExtensionID;
83 static guint gbl_s1apSctpPort=SCTP_PORT_S1AP;
85 /* Dissector tables */
86 static dissector_table_t s1ap_ies_dissector_table;
87 static dissector_table_t s1ap_ies_p1_dissector_table;
88 static dissector_table_t s1ap_ies_p2_dissector_table;
89 static dissector_table_t s1ap_extension_dissector_table;
90 static dissector_table_t s1ap_proc_imsg_dissector_table;
91 static dissector_table_t s1ap_proc_sout_dissector_table;
92 static dissector_table_t s1ap_proc_uout_dissector_table;
94 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
96 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
97 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
99 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
100 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
101 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
102 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
104 #include "packet-s1ap-fn.c"
106 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
108 return (dissector_try_port(s1ap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
110 /* Currently not used
111 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
113 return (dissector_try_port(s1ap_ies_p1_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
116 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
118 return (dissector_try_port(s1ap_ies_p2_dissector_table, ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
122 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
124 return (dissector_try_port(s1ap_extension_dissector_table, ProtocolExtensionID, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
127 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
129 return (dissector_try_port(s1ap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
132 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
134 return (dissector_try_port(s1ap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
137 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
139 return (dissector_try_port(s1ap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree)) ? tvb_length(tvb) : 0;
144 dissect_s1ap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
146 proto_item *s1ap_item = NULL;
147 proto_tree *s1ap_tree = NULL;
149 /* make entry in the Protocol column on summary display */
150 if (check_col(pinfo->cinfo, COL_PROTOCOL))
151 col_set_str(pinfo->cinfo, COL_PROTOCOL, "S1AP");
153 /* create the s1ap protocol tree */
154 s1ap_item = proto_tree_add_item(tree, proto_s1ap, tvb, 0, -1, FALSE);
155 s1ap_tree = proto_item_add_subtree(s1ap_item, ett_s1ap);
157 dissect_S1AP_PDU_PDU(tvb, pinfo, s1ap_tree);
160 /*--- proto_reg_handoff_s1ap ---------------------------------------*/
162 proto_reg_handoff_s1ap(void)
164 static gboolean Initialized=FALSE;
165 static dissector_handle_t s1ap_handle;
166 static guint SctpPort;
169 s1ap_handle = find_dissector("s1ap");
170 nas_eps_handle = find_dissector("nas-eps");
171 dissector_add_handle("sctp.port", s1ap_handle); /* for "decode-as" */
172 dissector_add("sctp.ppi", S1AP_PAYLOAD_PROTOCOL_ID, s1ap_handle);
174 #include "packet-s1ap-dis-tab.c"
177 dissector_delete("sctp.port", SctpPort, s1ap_handle);
181 SctpPort=gbl_s1apSctpPort;
183 dissector_add("sctp.port", SctpPort, s1ap_handle);
187 /*--- proto_register_s1ap -------------------------------------------*/
188 void proto_register_s1ap(void) {
192 static hf_register_info hf[] = {
193 { &hf_s1ap_transportLayerAddressIPv4,
194 { "transportLayerAddress(IPv4)", "s1ap.transportLayerAddressIPv4",
195 FT_IPv4, BASE_NONE, NULL, 0,
197 { &hf_s1ap_transportLayerAddressIPv6,
198 { "transportLayerAddress(IPv6)", "s1ap.transportLayerAddressIPv6",
199 FT_IPv4, BASE_NONE, NULL, 0,
202 #include "packet-s1ap-hfarr.c"
205 /* List of subtrees */
206 static gint *ett[] = {
208 &ett_s1ap_TransportLayerAddress,
209 #include "packet-s1ap-ettarr.c"
212 module_t *s1ap_module;
214 /* Register protocol */
215 proto_s1ap = proto_register_protocol(PNAME, PSNAME, PFNAME);
216 /* Register fields and subtrees */
217 proto_register_field_array(proto_s1ap, hf, array_length(hf));
218 proto_register_subtree_array(ett, array_length(ett));
220 /* Register dissector */
221 register_dissector("s1ap", dissect_s1ap, proto_s1ap);
223 /* Register dissector tables */
224 s1ap_ies_dissector_table = register_dissector_table("s1ap.ies", "S1AP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
225 s1ap_ies_p1_dissector_table = register_dissector_table("s1ap.ies.pair.first", "S1AP-PROTOCOL-IES-PAIR FirstValue", FT_UINT32, BASE_DEC);
226 s1ap_ies_p2_dissector_table = register_dissector_table("s1ap.ies.pair.second", "S1AP-PROTOCOL-IES-PAIR SecondValue", FT_UINT32, BASE_DEC);
227 s1ap_extension_dissector_table = register_dissector_table("s1ap.extension", "S1AP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
228 s1ap_proc_imsg_dissector_table = register_dissector_table("s1ap.proc.imsg", "S1AP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC);
229 s1ap_proc_sout_dissector_table = register_dissector_table("s1ap.proc.sout", "S1AP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC);
230 s1ap_proc_uout_dissector_table = register_dissector_table("s1ap.proc.uout", "S1AP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC);
232 /* Register configuration options for ports */
233 s1ap_module = prefs_register_protocol(proto_s1ap, proto_reg_handoff_s1ap);
235 prefs_register_uint_preference(s1ap_module, "sctp.port",
237 "Set the SCTP port for S1AP messages",