1 /* packet-tcap-template.c
3 * Copyright 2004 - 2005, Tim Endean <endeant@hotmail.com>
4 * Built from the gsm-map dissector Copyright 2004 - 2005, 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.
24 * References: ETSI 300 374
32 #include <epan/packet.h>
33 #include <epan/prefs.h>
34 #include <epan/conversation.h>
38 #include "packet-ber.h"
39 #include "packet-tcap.h"
41 #define PNAME "Transaction Capabilities Application Part"
45 /* Initialize the protocol and registered fields */
47 static int hf_tcap_tag = -1;
48 static int hf_tcap_length = -1;
49 static int hf_tcap_data = -1;
50 static int hf_tcap_tid = -1;
52 #include "packet-tcap-hf.c"
54 /* Initialize the subtree pointers */
55 static gint ett_tcap = -1;
56 static gint ett_param = -1;
58 static gint ett_otid = -1;
59 static gint ett_dtid = -1;
62 #include "packet-tcap-ett.c"
65 static range_t *global_ssn_range;
66 static range_t *ssn_range;
68 dissector_handle_t tcap_handle = NULL;
69 static dissector_table_t ber_oid_dissector_table=NULL;
70 static const char * cur_oid;
71 static const char * tcapext_oid;
72 static proto_tree *tcap_top_tree=NULL;
73 static dissector_handle_t data_handle;
75 static dissector_table_t sccp_ssn_table;
76 static int dissect_tcap_param(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset);
77 static int dissect_tcap_UserInformation(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_);
80 static GHashTable* ansi_sub_dissectors = NULL;
81 static GHashTable* itu_sub_dissectors = NULL;
83 static void dissect_tcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree);
85 extern void add_ansi_tcap_subdissector(guint32 ssn, dissector_handle_t dissector) {
86 g_hash_table_insert(ansi_sub_dissectors,GUINT_TO_POINTER(ssn),dissector);
87 dissector_add("sccp.ssn",ssn,tcap_handle);
90 extern void add_itu_tcap_subdissector(guint32 ssn, dissector_handle_t dissector) {
91 g_hash_table_insert(itu_sub_dissectors,GUINT_TO_POINTER(ssn),dissector);
92 dissector_add("sccp.ssn",ssn,tcap_handle);
95 extern void delete_ansi_tcap_subdissector(guint32 ssn, dissector_handle_t dissector _U_) {
96 g_hash_table_remove(ansi_sub_dissectors,GUINT_TO_POINTER(ssn));
97 dissector_delete("sccp.ssn",ssn,tcap_handle);
99 extern void delete_itu_tcap_subdissector(guint32 ssn, dissector_handle_t dissector _U_) {
100 g_hash_table_remove(itu_sub_dissectors,GUINT_TO_POINTER(ssn));
101 dissector_delete("sccp.ssn", ssn,tcap_handle);
104 static dissector_handle_t get_ansi_tcap_subdissector(guint32 ssn) {
105 return g_hash_table_lookup(ansi_sub_dissectors,GUINT_TO_POINTER(ssn));
108 dissector_handle_t get_itu_tcap_subdissector(guint32 ssn) {
109 return g_hash_table_lookup(itu_sub_dissectors,GUINT_TO_POINTER(ssn));
114 #include "packet-tcap-fn.c"
118 const value_string tcap_component_type_str[] = {
119 { TCAP_COMP_INVOKE, "Invoke" },
120 { TCAP_COMP_RRL, "Return Result(L)" },
121 { TCAP_COMP_RE, "Return Error" },
122 { TCAP_COMP_REJECT, "Reject" },
123 { TCAP_COMP_RRN, "Return Result(NL)" },
128 dissect_tcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
130 proto_item *item=NULL;
131 proto_tree *tree=NULL;
133 tcap_top_tree = parent_tree;
134 if (check_col(pinfo->cinfo, COL_PROTOCOL))
136 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TCAP");
139 /* create display subtree for the protocol */
141 item = proto_tree_add_item(parent_tree, proto_tcap, tvb, 0, -1, FALSE);
142 tree = proto_item_add_subtree(item, ett_tcap);
146 pinfo->private_data = NULL;
147 dissect_tcap_MessageType(FALSE, tvb, 0, pinfo, tree, -1);
154 proto_reg_handoff_tcap(void)
157 static gboolean prefs_initialized = FALSE;
159 if (! prefs_initialized) {
160 sccp_ssn_table = find_dissector_table("sccp.ssn");
161 prefs_initialized = TRUE;
164 register_ber_oid_name("0.0.17.773.1.1.1",
165 "itu-t(0) recommendation(0) q(17) 773 as(1) dialogue-as(1) version1(1)");
167 data_handle = find_dissector("data");
170 static void init_tcap(void);
173 proto_register_tcap(void)
176 /* Setup list of header fields See Section 1.6.1 for details*/
177 static hf_register_info hf[] = {
179 { "Tag", "tcap.msgtype",
180 FT_UINT8, BASE_HEX, NULL, 0,
184 { "Length", "tcap.len",
185 FT_UINT8, BASE_HEX, NULL, 0,
189 { "Data", "tcap.data",
190 FT_BYTES, BASE_HEX, NULL, 0,
194 { "Transaction Id", "tcap.tid",
195 FT_BYTES, BASE_HEX, NULL, 0,
198 #include "packet-tcap-hfarr.c"
201 /* Setup protocol subtree array */
202 static gint *ett[] = {
207 #include "packet-tcap-ettarr.c"
210 /*static enum_val_t tcap_options[] = {
211 { "itu", "ITU", ITU_TCAP_STANDARD },
212 { "ansi", "ANSI", ANSI_TCAP_STANDARD },
216 module_t *tcap_module;
218 /* Register the protocol name and description */
219 proto_tcap = proto_register_protocol(PNAME, PSNAME, PFNAME);
221 /* Required function calls to register the header fields and subtrees used */
222 proto_register_field_array(proto_tcap, hf, array_length(hf));
223 proto_register_subtree_array(ett, array_length(ett));
225 tcap_module = prefs_register_protocol(proto_tcap, proto_reg_handoff_tcap);
228 prefs_register_enum_preference(tcap_module, "standard", "ITU TCAP standard",
229 "The SS7 standard used in ITU TCAP packets",
230 &tcap_standard, tcap_options, FALSE);
232 prefs_register_obsolete_preference(tcap_module, "standard");
236 prefs_register_bool_preference(tcap_module, "lock_info_col", "Lock Info column",
237 "Always show TCAP in Info column",
240 prefs_register_obsolete_preference(tcap_module, "lock_info_col");
243 /* Set default SSNs */
244 range_convert_str(&global_ssn_range, "", MAX_SSN);
245 ssn_range = range_empty();
247 prefs_register_range_preference(tcap_module, "ssn", "SCCP SSNs",
248 "SCCP (and SUA) SSNs to decode as TCAP",
249 &global_ssn_range, MAX_SSN);
251 ansi_sub_dissectors = g_hash_table_new(g_direct_hash,g_direct_equal);
252 itu_sub_dissectors = g_hash_table_new(g_direct_hash,g_direct_equal);
254 /* 'globally' register dissector */
255 register_dissector("tcap", dissect_tcap, proto_tcap);
257 tcap_handle = create_dissector_handle(dissect_tcap, proto_tcap);
259 register_init_routine(&init_tcap);
263 static void range_delete_callback(guint32 ssn)
265 if ( ssn && !get_ansi_tcap_subdissector(ssn) && !get_itu_tcap_subdissector(ssn) ) {
266 dissector_delete("sccp.ssn", ssn, tcap_handle);
270 static void range_add_callback(guint32 ssn)
272 if (ssn && !get_ansi_tcap_subdissector(ssn) && !get_itu_tcap_subdissector(ssn) ) {
273 dissector_add("sccp.ssn", ssn, tcap_handle);
278 static void init_tcap(void) {
280 range_foreach(ssn_range, range_delete_callback);
284 ssn_range = range_copy(global_ssn_range);
285 range_foreach(ssn_range, range_add_callback);
290 dissect_tcap_param(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset)
292 gint tag_offset, saved_offset, len_offset;
302 while (tvb_reported_length_remaining(tvb, offset) > 0)
304 saved_offset = offset;
306 offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
308 offset = get_ber_length(tree, tvb, offset, &len, &ind_field);
314 proto_tree_add_text(tree, tvb, saved_offset, len + (len_offset - saved_offset), "CONSTRUCTOR");
315 subtree = proto_item_add_subtree(pi, ett_param);
316 proto_tree_add_uint_format(subtree, hf_tcap_tag, tvb,
317 saved_offset, tag_offset-saved_offset, tag, "CONSTRUCTOR Tag");
318 proto_tree_add_uint(subtree, hf_tcap_tag, tvb,
319 saved_offset, tag_offset-saved_offset, class);
321 proto_tree_add_uint(subtree, hf_tcap_length, tvb,
322 tag_offset, len_offset-tag_offset, len);
323 if (len-(2*ind_field)) /*should always be positive unless we get an empty contructor pointless? */
325 next_tvb = tvb_new_subset(tvb, offset, len-(2*ind_field), len-(2*ind_field));
326 dissect_tcap_param(pinfo, subtree,next_tvb,0);
329 proto_tree_add_text(subtree, tvb, offset+len-2, 2, "CONSTRUCTOR EOC");
334 pi = proto_tree_add_text(tree, tvb,
335 saved_offset, len + (len_offset - saved_offset), "Parameter (0x%.2x)", tag);
337 subtree = proto_item_add_subtree(pi, ett_param);
339 proto_tree_add_uint(subtree, hf_tcap_tag, tvb,
340 saved_offset, 1, tag);
342 proto_tree_add_uint(subtree, hf_tcap_length, tvb,
343 saved_offset+1, 1, len);
344 if (len) /* check for NULLS */
346 next_tvb = tvb_new_subset(tvb, offset, len, len);
347 dissect_ber_octet_string(TRUE, pinfo, tree, next_tvb, 0, hf_tcap_data,