Revert "TODO epan/dissectors/asn1/kerberos/packet-kerberos-template.c new GSS flags"
[wireshark-sm.git] / epan / dissectors / asn1 / rnsap / packet-rnsap-template.c
blob78119aa92e8e823e7fc789587a3741e6fe108711
1 /* packet-rnsap.c
2 * Routines for dissecting Universal Mobile Telecommunications System (UMTS);
3 * UTRAN Iur interface Radio Network Subsystem
4 * Application Part (RNSAP) signalling
5 * (3GPP TS 25.423 version 6.7.0 Release 6) packet dissection
6 * Copyright 2005 - 2006, Anders Broman <anders.broman@ericsson.com>
8 * Wireshark - Network traffic analyzer
9 * By Gerald Combs <gerald@wireshark.org>
10 * Copyright 1998 Gerald Combs
12 * SPDX-License-Identifier: GPL-2.0-or-later
14 * Ref: 3GPP TS 25.423 version 6.7.0 Release 6
17 #include "config.h"
19 #include <epan/packet.h>
20 #include <epan/asn1.h>
21 #include <epan/proto_data.h>
22 #include <wsutil/array.h>
24 #include "packet-isup.h"
25 #include "packet-per.h"
26 #include "packet-ber.h"
27 #include "packet-e212.h"
29 #ifdef _MSC_VER
30 /* disable: "warning C4146: unary minus operator applied to unsigned type, result still unsigned" */
31 #pragma warning(disable:4146)
32 #endif
34 #define PNAME "UTRAN Iur interface Radio Network Subsystem Application Part"
35 #define PSNAME "RNSAP"
36 #define PFNAME "rnsap"
38 #define SCCP_SSN_RNSAP 143
40 #include "packet-rnsap-val.h"
42 void proto_register_rnsap(void);
43 void proto_reg_handoff_rnsap(void);
45 typedef struct {
46 uint32_t ProcedureCode;
47 uint32_t ProtocolIE_ID;
48 uint32_t ddMode;
49 const char *ProcedureID;
50 const char *obj_id;
51 } rnsap_private_data_t;
53 static dissector_handle_t ranap_handle;
54 static dissector_handle_t rrc_dl_ccch_handle;
55 static dissector_handle_t rrc_ul_ccch_handle;
57 /* Initialize the protocol and registered fields */
58 static int proto_rnsap;
60 static int hf_rnsap_transportLayerAddress_ipv4;
61 static int hf_rnsap_transportLayerAddress_ipv6;
62 static int hf_rnsap_transportLayerAddress_nsap;
63 #include "packet-rnsap-hf.c"
65 /* Initialize the subtree pointers */
66 static int ett_rnsap;
67 static int ett_rnsap_transportLayerAddress;
68 static int ett_rnsap_transportLayerAddress_nsap;
69 static int ett_rnsap_IMSI;
71 #include "packet-rnsap-ett.c"
74 /* Dissector tables */
75 static dissector_table_t rnsap_ies_dissector_table;
76 static dissector_table_t rnsap_extension_dissector_table;
77 static dissector_table_t rnsap_proc_imsg_dissector_table;
78 static dissector_table_t rnsap_proc_sout_dissector_table;
79 static dissector_table_t rnsap_proc_uout_dissector_table;
81 static dissector_handle_t rnsap_handle;
83 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
84 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
85 static int dissect_PrivateIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
86 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
87 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
88 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *);
90 static rnsap_private_data_t *
91 rnsap_get_private_data(packet_info *pinfo)
94 rnsap_private_data_t *pdata = (rnsap_private_data_t *)p_get_proto_data(pinfo->pool, pinfo, proto_rnsap, 0);
95 if (!pdata) {
96 pdata = wmem_new0(pinfo->pool, rnsap_private_data_t);
97 pdata->ProcedureCode = 0xFFFF;
98 pdata->ddMode = 0xFFFF;
99 p_add_proto_data(pinfo->pool, pinfo, proto_rnsap, 0, pdata);
101 return pdata;
104 #include "packet-rnsap-fn.c"
106 static int dissect_ProtocolIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
108 rnsap_private_data_t *pdata = rnsap_get_private_data(pinfo);
109 return (dissector_try_uint(rnsap_ies_dissector_table, pdata->ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
112 static int dissect_ProtocolExtensionFieldExtensionValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
114 rnsap_private_data_t *pdata = rnsap_get_private_data(pinfo);
115 return (dissector_try_uint(rnsap_extension_dissector_table, pdata->ProtocolIE_ID, tvb, pinfo, tree)) ? tvb_captured_length(tvb) : 0;
118 static int dissect_PrivateIEFieldValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
120 rnsap_private_data_t *pdata = rnsap_get_private_data(pinfo);
121 return (call_ber_oid_callback(pdata->obj_id, tvb, 0, pinfo, tree, NULL)) ? tvb_captured_length(tvb) : 0;
124 static int dissect_InitiatingMessageValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
126 rnsap_private_data_t *pdata = rnsap_get_private_data(pinfo);
127 if (!pdata->ProcedureID) return 0;
128 return (dissector_try_string_with_data(rnsap_proc_imsg_dissector_table, pdata->ProcedureID, tvb, pinfo, tree, true, NULL)) ? tvb_captured_length(tvb) : 0;
131 static int dissect_SuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
133 rnsap_private_data_t *pdata = rnsap_get_private_data(pinfo);
134 if (!pdata->ProcedureID) return 0;
135 return (dissector_try_string_with_data(rnsap_proc_sout_dissector_table, pdata->ProcedureID, tvb, pinfo, tree, true, NULL)) ? tvb_captured_length(tvb) : 0;
138 static int dissect_UnsuccessfulOutcomeValue(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
140 rnsap_private_data_t *pdata = rnsap_get_private_data(pinfo);
141 if (!pdata->ProcedureID) return 0;
142 return (dissector_try_string_with_data(rnsap_proc_uout_dissector_table, pdata->ProcedureID, tvb, pinfo, tree, true, NULL)) ? tvb_captured_length(tvb) : 0;
145 static int
146 dissect_rnsap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
148 proto_item *rnsap_item = NULL;
149 proto_tree *rnsap_tree = NULL;
151 /* make entry in the Protocol column on summary display */
152 col_set_str(pinfo->cinfo, COL_PROTOCOL, "RNSAP");
154 /* create the rnsap protocol tree */
155 rnsap_item = proto_tree_add_item(tree, proto_rnsap, tvb, 0, -1, ENC_NA);
156 rnsap_tree = proto_item_add_subtree(rnsap_item, ett_rnsap);
158 /* remove any rnsap_private_data_t state from previous PDUs in this packet. */
159 p_remove_proto_data(pinfo->pool, pinfo, proto_rnsap, 0);
161 return dissect_RNSAP_PDU_PDU(tvb, pinfo, rnsap_tree, data);
164 /* Highest ProcedureCode value, used in heuristics */
165 #define RNSAP_MAX_PC 61 /* id-enhancedRelocationResourceRelease = 61*/
166 #define RNSAP_MSG_MIN_LENGTH 7
167 static bool
168 dissect_sccp_rnsap_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
170 uint8_t pdu_type;
171 uint8_t procedure_id;
172 uint8_t dd_mode;
173 uint8_t criticality;
174 uint8_t transaction_id_type;
175 unsigned length;
176 int length_field_offset;
178 #define PDU_TYPE_OFFSET 0
179 #define PROC_CODE_OFFSET 1
180 #define DD_CRIT_OFFSET 2
181 if (tvb_captured_length(tvb) < RNSAP_MSG_MIN_LENGTH) {
182 return false;
185 pdu_type = tvb_get_uint8(tvb, PDU_TYPE_OFFSET);
186 if (pdu_type & 0x1F) {
187 /* pdu_type is not 0x00 (initiatingMessage), 0x20 (succesfulOutcome),
188 0x40 (unsuccesfulOutcome) or 0x60 (outcome), ignore extension bit (0x80) */
189 return false;
192 procedure_id = tvb_get_uint8(tvb, PROC_CODE_OFFSET);
193 if (procedure_id > RNSAP_MAX_PC) {
194 return false;
197 dd_mode = tvb_get_uint8(tvb, DD_CRIT_OFFSET) >> 5;
198 if (dd_mode >= 0x03) {
199 /* dd_mode is not 0x00 (tdd), 0x01 (fdd) or 0x02 (common) */
200 return false;
203 criticality = (tvb_get_uint8(tvb, DD_CRIT_OFFSET) & 0x18) >> 3;
204 if (criticality == 0x03) {
205 /* criticality is not 0x00 (reject), 0x01 (ignore) or 0x02 (notify) */
206 return false;
209 /* Finding the offset for the length field - depends on wether the transaction id is long or short */
210 transaction_id_type = (tvb_get_uint8(tvb, DD_CRIT_OFFSET) & 0x04) >> 2;
211 if(transaction_id_type == 0x00) { /* Short transaction id - 1 byte*/
212 length_field_offset = 4;
214 else { /* Long transaction id - 2 bytes*/
215 length_field_offset = 5;
218 /* compute aligned PER length determinant without calling dissect_per_length_determinant()
219 to avoid exceptions and info added to tree, info column and expert info */
220 length = tvb_get_uint8(tvb, length_field_offset);
221 length_field_offset += 1;
222 if (length & 0x80) {
223 if ((length & 0xc0) == 0x80) {
224 length &= 0x3f;
225 length <<= 8;
226 length += tvb_get_uint8(tvb, length_field_offset);
227 length_field_offset += 1;
228 } else {
229 length = 0;
232 if (length!= (tvb_reported_length(tvb) - length_field_offset)){
233 return false;
236 dissect_rnsap(tvb, pinfo, tree, data);
238 return true;
242 /*--- proto_register_rnsap -------------------------------------------*/
243 void proto_register_rnsap(void) {
245 /* List of fields */
246 static hf_register_info hf[] = {
247 { &hf_rnsap_transportLayerAddress_ipv4,
248 { "transportLayerAddress IPv4", "rnsap.transportLayerAddress_ipv4",
249 FT_IPv4, BASE_NONE, NULL, 0,
250 NULL, HFILL }},
251 { &hf_rnsap_transportLayerAddress_ipv6,
252 { "transportLayerAddress IPv6", "rnsap.transportLayerAddress_ipv6",
253 FT_IPv6, BASE_NONE, NULL, 0,
254 NULL, HFILL }},
255 { &hf_rnsap_transportLayerAddress_nsap,
256 { "transportLayerAddress NSAP", "rnsap.transportLayerAddress_NSAP",
257 FT_BYTES, BASE_NONE, NULL, 0,
258 NULL, HFILL }},
259 #include "packet-rnsap-hfarr.c"
262 /* List of subtrees */
263 static int *ett[] = {
264 &ett_rnsap,
265 &ett_rnsap_transportLayerAddress,
266 &ett_rnsap_transportLayerAddress_nsap,
267 &ett_rnsap_IMSI,
268 #include "packet-rnsap-ettarr.c"
272 /* Register protocol */
273 proto_rnsap = proto_register_protocol(PNAME, PSNAME, PFNAME);
274 /* Register fields and subtrees */
275 proto_register_field_array(proto_rnsap, hf, array_length(hf));
276 proto_register_subtree_array(ett, array_length(ett));
278 /* Register dissector */
279 rnsap_handle = register_dissector("rnsap", dissect_rnsap, proto_rnsap);
281 /* Register dissector tables */
282 rnsap_ies_dissector_table = register_dissector_table("rnsap.ies", "RNSAP-PROTOCOL-IES", proto_rnsap, FT_UINT32, BASE_DEC);
283 rnsap_extension_dissector_table = register_dissector_table("rnsap.extension", "RNSAP-PROTOCOL-EXTENSION", proto_rnsap, FT_UINT32, BASE_DEC);
284 rnsap_proc_imsg_dissector_table = register_dissector_table("rnsap.proc.imsg", "RNSAP-ELEMENTARY-PROCEDURE InitiatingMessage", proto_rnsap, FT_STRING, STRING_CASE_SENSITIVE);
285 rnsap_proc_sout_dissector_table = register_dissector_table("rnsap.proc.sout", "RNSAP-ELEMENTARY-PROCEDURE SuccessfulOutcome", proto_rnsap, FT_STRING, STRING_CASE_SENSITIVE);
286 rnsap_proc_uout_dissector_table = register_dissector_table("rnsap.proc.uout", "RNSAP-ELEMENTARY-PROCEDURE UnsuccessfulOutcome", proto_rnsap, FT_STRING, STRING_CASE_SENSITIVE);
291 /*--- proto_reg_handoff_rnsap ---------------------------------------*/
292 void
293 proto_reg_handoff_rnsap(void)
295 ranap_handle = find_dissector("ranap");
296 rrc_dl_ccch_handle = find_dissector_add_dependency("rrc.dl.ccch", proto_rnsap);
297 rrc_ul_ccch_handle = find_dissector_add_dependency("rrc.ul.ccch", proto_rnsap);
299 dissector_add_uint("sccp.ssn", SCCP_SSN_RNSAP, rnsap_handle);
300 heur_dissector_add("sccp", dissect_sccp_rnsap_heur, "RNSAP over SCCP", "rnsap_sccp", proto_rnsap, HEURISTIC_ENABLE);
302 #include "packet-rnsap-dis-tab.c"