2 * Routines for UMTS Node B Application Part(RANAP) packet dissection
3 * Copyright 2005 - 2010, Anders Broman <anders.broman[AT]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 * References: 3GPP TS 25.413 version 6.6.0 Release
33 #include <epan/packet.h>
35 #include <epan/emem.h>
36 #include <epan/strutil.h>
37 #include <epan/asn1.h>
38 #include <epan/prefs.h>
40 #include "packet-ber.h"
41 #include "packet-per.h"
42 #include "packet-gsm_map.h"
43 #include "packet-ranap.h"
44 #include "packet-e212.h"
45 #include "packet-sccp.h"
46 #include "packet-gsm_a_common.h"
49 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
50 #pragma warning(disable:4146)
53 #define SCCP_SSN_RANAP 142
55 #define PNAME "Radio Access Network Application Part"
56 #define PSNAME "RANAP"
57 #define PFNAME "ranap"
59 /* Higest Ranap_ProcedureCode_value, use in heuristics */
60 #define RANAP_MAX_PC 45 /* id_RANAPenhancedRelocation = 45 */
62 #include "packet-ranap-val.h"
64 /* Initialize the protocol and registered fields */
65 static int proto_ranap = -1;
67 /* initialise sub-dissector handles */
68 static dissector_handle_t rrc_s_to_trnc_handle = NULL;
69 static dissector_handle_t rrc_ho_to_utran_cmd = NULL;
71 static int hf_ranap_imsi_digits = -1;
72 static int hf_ranap_transportLayerAddress_ipv4 = -1;
73 static int hf_ranap_transportLayerAddress_ipv6 = -1;
75 #include "packet-ranap-hf.c"
77 /* Initialize the subtree pointers */
78 static int ett_ranap = -1;
79 static int ett_ranap_TransportLayerAddress = -1;
81 #include "packet-ranap-ett.c"
83 /* Global variables */
84 static guint32 ProcedureCode;
85 static guint32 ProtocolIE_ID;
86 static guint32 ProtocolExtensionID;
88 /* Some IE:s identities uses the same value for different IE:s
89 * depending on PDU type:
94 * As a workarond a value is added to the IE:id in the .cnf file.
96 * ResetResourceList N rnsap.ies IMSG||id-IuSigConIdList # no spaces are allowed in value as a space is delimiter
97 * PDU type is stored in a global variable and can is used in the IE decoding section.
100 * &InitiatingMessage ,
101 * &SuccessfulOutcome OPTIONAL,
102 * &UnsuccessfulOutcome OPTIONAL,
105 * Only these two needed currently
109 #define SPECIAL (4<<16)
111 int pdu_type = 0; /* 0 means wildcard */
113 /* Initialise the Preferences */
114 static gint global_ranap_sccp_ssn = SCCP_SSN_RANAP;
116 /* Dissector tables */
117 static dissector_table_t ranap_ies_dissector_table;
118 static dissector_table_t ranap_ies_p1_dissector_table;
119 static dissector_table_t ranap_ies_p2_dissector_table;
120 static dissector_table_t ranap_extension_dissector_table;
121 static dissector_table_t ranap_proc_imsg_dissector_table;
122 static dissector_table_t ranap_proc_sout_dissector_table;
123 static dissector_table_t ranap_proc_uout_dissector_table;
124 static dissector_table_t ranap_proc_out_dissector_table;
125 static dissector_table_t nas_pdu_dissector_table;
127 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
128 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
129 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
130 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
131 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
132 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
133 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
134 static int dissect_OutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
136 static int dissect_ranap_SourceRNC_ToTargetRNC_TransparentContainer(tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
137 static int dissect_ranap_TargetRNC_ToSourceRNC_TransparentContainer(tvbuff_t *tvb, int offset, asn1_ctx_t *actx, proto_tree *tree, int hf_index);
139 void proto_reg_handoff_ranap(void);
141 #include "packet-ranap-fn.c"
143 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
149 /* Special handling, same ID used for different IE's depending on signal */
150 switch(ProcedureCode){
151 case id_RelocationPreparation:
152 if((ProtocolIE_ID == id_Source_ToTarget_TransparentContainer)||(ProtocolIE_ID == id_Target_ToSource_TransparentContainer)){
153 key = SPECIAL | ProtocolIE_ID;
154 ret = (dissector_try_port_new(ranap_ies_dissector_table, key, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
159 /* no special handling */
160 ret = (dissector_try_port_new(ranap_ies_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
162 key = pdu_type | ProtocolIE_ID;
163 ret = (dissector_try_port_new(ranap_ies_dissector_table, key, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
170 static int dissect_ProtocolIEFieldPairFirstValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
172 return (dissector_try_port_new(ranap_ies_p1_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
175 static int dissect_ProtocolIEFieldPairSecondValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
177 return (dissector_try_port_new(ranap_ies_p2_dissector_table, ProtocolIE_ID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
180 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
182 return (dissector_try_port_new(ranap_extension_dissector_table, ProtocolExtensionID, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
185 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
188 return (dissector_try_port_new(ranap_proc_imsg_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
192 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
195 return (dissector_try_port_new(ranap_proc_sout_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
199 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
201 return (dissector_try_port_new(ranap_proc_uout_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
204 static int dissect_OutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
206 return (dissector_try_port_new(ranap_proc_out_dissector_table, ProcedureCode, tvb, pinfo, tree, FALSE)) ? tvb_length(tvb) : 0;
210 dissect_ranap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
212 proto_item *ranap_item = NULL;
213 proto_tree *ranap_tree = NULL;
218 /* make entry in the Protocol column on summary display */
219 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RANAP");
221 /* create the ranap protocol tree */
222 ranap_item = proto_tree_add_item(tree, proto_ranap, tvb, 0, -1, FALSE);
223 ranap_tree = proto_item_add_subtree(ranap_item, ett_ranap);
225 dissect_RANAP_PDU_PDU(tvb, pinfo, ranap_tree);
226 if (pinfo->sccp_info) {
227 sccp_msg_info_t* sccp_msg_lcl = pinfo->sccp_info;
229 if (sccp_msg_lcl->data.co.assoc)
230 sccp_msg_lcl->data.co.assoc->payload = SCCP_PLOAD_RANAP;
232 if (! sccp_msg_lcl->data.co.label && ProcedureCode != 0xFFFFFFFF) {
233 const gchar* str = val_to_str(ProcedureCode, ranap_ProcedureCode_vals,"Unknown RANAP");
234 sccp_msg_lcl->data.co.label = se_strdup(str);
240 dissect_sccp_ranap_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
247 asn1_ctx_init(&asn1_ctx, ASN1_ENC_PER, TRUE, pinfo);
249 /* Is it a ranap packet?
251 * 4th octet should be the length of the rest of the message.
252 * 2nd octet is the message-type e Z[0, 28]
253 * (obviously there must be at least four octets)
255 * If both hold true we'll assume its RANAP
258 #define LENGTH_OFFSET 3
259 #define MSG_TYPE_OFFSET 1
260 if (tvb_length(tvb) < 4) { return FALSE; }
261 /*if (tvb_get_guint8(tvb, LENGTH_OFFSET) != (tvb_length(tvb) - 4)) { return FALSE; }*/
262 /* Read the length NOTE offset in bits */
263 offset = dissect_per_length_determinant(tvb, LENGTH_OFFSET<<3, &asn1_ctx, tree, -1, &length);
265 if (length!= (tvb_length(tvb) - offset)){
269 temp = tvb_get_guint8(tvb, MSG_TYPE_OFFSET);
270 if (temp > RANAP_MAX_PC) { return FALSE; }
272 dissect_ranap(tvb, pinfo, tree);
277 /*--- proto_register_ranap -------------------------------------------*/
278 void proto_register_ranap(void) {
279 module_t *ranap_module;
283 static hf_register_info hf[] = {
284 { &hf_ranap_imsi_digits,
285 { "IMSI digits", "ranap.imsi_digits",
286 FT_STRING, BASE_NONE, NULL, 0,
288 { &hf_ranap_transportLayerAddress_ipv4,
289 { "transportLayerAddress IPv4", "ranap.transportLayerAddress_ipv4",
290 FT_IPv4, BASE_NONE, NULL, 0,
292 { &hf_ranap_transportLayerAddress_ipv6,
293 { "transportLayerAddress IPv6", "ranap.transportLayerAddress_ipv6",
294 FT_IPv6, BASE_NONE, NULL, 0,
298 #include "packet-ranap-hfarr.c"
301 /* List of subtrees */
302 static gint *ett[] = {
304 &ett_ranap_TransportLayerAddress,
305 #include "packet-ranap-ettarr.c"
309 /* Register protocol */
310 proto_ranap = proto_register_protocol(PNAME, PSNAME, PFNAME);
311 /* Register fields and subtrees */
312 proto_register_field_array(proto_ranap, hf, array_length(hf));
313 proto_register_subtree_array(ett, array_length(ett));
315 /* Register dissector */
316 register_dissector("ranap", dissect_ranap, proto_ranap);
318 /* Register dissector tables */
319 ranap_ies_dissector_table = register_dissector_table("ranap.ies", "RANAP-PROTOCOL-IES", FT_UINT32, BASE_DEC);
320 ranap_ies_p1_dissector_table = register_dissector_table("ranap.ies.pair.first", "RANAP-PROTOCOL-IES-PAIR FirstValue", FT_UINT32, BASE_DEC);
321 ranap_ies_p2_dissector_table = register_dissector_table("ranap.ies.pair.second", "RANAP-PROTOCOL-IES-PAIR SecondValue", FT_UINT32, BASE_DEC);
322 ranap_extension_dissector_table = register_dissector_table("ranap.extension", "RANAP-PROTOCOL-EXTENSION", FT_UINT32, BASE_DEC);
323 ranap_proc_imsg_dissector_table = register_dissector_table("ranap.proc.imsg", "RANAP-ELEMENTARY-PROCEDURE InitiatingMessage", FT_UINT32, BASE_DEC);
324 ranap_proc_sout_dissector_table = register_dissector_table("ranap.proc.sout", "RANAP-ELEMENTARY-PROCEDURE SuccessfulOutcome", FT_UINT32, BASE_DEC);
325 ranap_proc_uout_dissector_table = register_dissector_table("ranap.proc.uout", "RANAP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", FT_UINT32, BASE_DEC);
326 ranap_proc_out_dissector_table = register_dissector_table("ranap.proc.out", "RANAP-ELEMENTARY-PROCEDURE Outcome", FT_UINT32, BASE_DEC);
328 nas_pdu_dissector_table = register_dissector_table("ranap.nas_pdu", "RANAP NAS PDU", FT_UINT8, BASE_DEC);
330 ranap_module = prefs_register_protocol(proto_ranap, proto_reg_handoff_ranap);
331 prefs_register_uint_preference(ranap_module, "sccp_ssn", "SCCP SSN for RANAP",
332 "The SCCP SubSystem Number for RANAP (default 142)", 10,
333 &global_ranap_sccp_ssn);
337 /*--- proto_reg_handoff_ranap ---------------------------------------*/
339 proto_reg_handoff_ranap(void)
341 static gboolean initialized = FALSE;
342 static dissector_handle_t ranap_handle;
343 static gint local_ranap_sccp_ssn;
346 ranap_handle = find_dissector("ranap");
347 rrc_s_to_trnc_handle = find_dissector("rrc.s_to_trnc_cont");
348 rrc_ho_to_utran_cmd = find_dissector("rrc.irat.ho_to_utran_cmd");
350 #include "packet-ranap-dis-tab.c"
352 dissector_delete("sccp.ssn", local_ranap_sccp_ssn, ranap_handle);
355 dissector_add("sccp.ssn", global_ranap_sccp_ssn, ranap_handle);
356 local_ranap_sccp_ssn = global_ranap_sccp_ssn;
357 /* Add heuristic dissector
358 * Perhaps we want a preference whether the heuristic dissector
359 * is or isn't enabled
361 heur_dissector_add("sccp", dissect_sccp_ranap_heur, proto_ranap);
362 heur_dissector_add("sua", dissect_sccp_ranap_heur, proto_ranap);