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>
35 #include <epan/oid_resolv.h>
36 #include <epan/emem.h>
40 #include "packet-ber.h"
41 #include "packet-tcap.h"
42 #include "epan/tcap-persistentdata.h"
44 #define PNAME "Transaction Capabilities Application Part"
48 /* Initialize the protocol and registered fields */
50 static int hf_tcap_tag = -1;
51 static int hf_tcap_length = -1;
52 static int hf_tcap_data = -1;
53 static int hf_tcap_tid = -1;
55 int hf_tcapsrt_SessionId=-1;
56 int hf_tcapsrt_Duplicate=-1;
57 int hf_tcapsrt_BeginSession=-1;
58 int hf_tcapsrt_EndSession=-1;
59 int hf_tcapsrt_SessionTime=-1;
61 #include "packet-tcap-hf.c"
63 /* Initialize the subtree pointers */
64 static gint ett_tcap = -1;
65 static gint ett_param = -1;
67 static gint ett_otid = -1;
68 static gint ett_dtid = -1;
69 gint ett_tcap_stat = -1;
71 static struct tcapsrt_info_t * gp_tcapsrt_info;
72 static gboolean tcap_subdissector_used=FALSE;
73 static struct tcaphash_context_t * gp_tcap_context=NULL;
75 #include "packet-tcap-ett.c"
78 static range_t *global_ssn_range;
79 static range_t *ssn_range;
80 struct tcap_private_t tcap_private;
82 gboolean gtcap_HandleSRT=FALSE;
83 extern gboolean gtcap_PersistentSRT;
84 extern gboolean gtcap_DisplaySRT;
85 extern guint gtcap_RepetitionTimeout;
86 extern guint gtcap_LostTimeout;
88 static dissector_handle_t tcap_handle = NULL;
89 static dissector_table_t ber_oid_dissector_table=NULL;
90 static const char * cur_oid;
91 static const char * tcapext_oid;
92 static proto_tree * tcap_top_tree=NULL;
93 static proto_tree * tcap_stat_tree=NULL;
94 static proto_item * tcap_stat_item=NULL;
96 static dissector_handle_t data_handle;
98 static dissector_table_t sccp_ssn_table;
100 static void raz_tcap_private(struct tcap_private_t * p_tcap_private);
101 static int dissect_tcap_param(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset);
102 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_);
103 static int dissect_tcap_TheComponent(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_);
104 static int dissect_tcap_TheExternUserInfo(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_);
106 static GHashTable* ansi_sub_dissectors = NULL;
107 static GHashTable* itu_sub_dissectors = NULL;
109 static void dissect_tcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree);
111 extern void add_ansi_tcap_subdissector(guint32 ssn, dissector_handle_t dissector) {
112 g_hash_table_insert(ansi_sub_dissectors,GUINT_TO_POINTER(ssn),dissector);
113 dissector_add("sccp.ssn",ssn,tcap_handle);
116 extern void add_itu_tcap_subdissector(guint32 ssn, dissector_handle_t dissector) {
117 g_hash_table_insert(itu_sub_dissectors,GUINT_TO_POINTER(ssn),dissector);
118 dissector_add("sccp.ssn",ssn,tcap_handle);
121 extern void delete_ansi_tcap_subdissector(guint32 ssn, dissector_handle_t dissector _U_) {
122 g_hash_table_remove(ansi_sub_dissectors,GUINT_TO_POINTER(ssn));
123 dissector_delete("sccp.ssn",ssn,tcap_handle);
125 extern void delete_itu_tcap_subdissector(guint32 ssn, dissector_handle_t dissector _U_) {
126 g_hash_table_remove(itu_sub_dissectors,GUINT_TO_POINTER(ssn));
127 dissector_delete("sccp.ssn", ssn,tcap_handle);
130 dissector_handle_t get_ansi_tcap_subdissector(guint32 ssn) {
131 return g_hash_table_lookup(ansi_sub_dissectors,GUINT_TO_POINTER(ssn));
134 dissector_handle_t get_itu_tcap_subdissector(guint32 ssn) {
135 return g_hash_table_lookup(itu_sub_dissectors,GUINT_TO_POINTER(ssn));
140 #include "packet-tcap-fn.c"
144 const value_string tcap_component_type_str[] = {
145 { TCAP_COMP_INVOKE, "Invoke" },
146 { TCAP_COMP_RRL, "Return Result(L)" },
147 { TCAP_COMP_RE, "Return Error" },
148 { TCAP_COMP_REJECT, "Reject" },
149 { TCAP_COMP_RRN, "Return Result(NL)" },
154 dissect_tcap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree)
156 proto_item *item=NULL;
157 proto_tree *tree=NULL;
158 proto_item *stat_item=NULL;
159 proto_tree *stat_tree=NULL;
160 struct tcaphash_context_t * p_tcap_context;
161 dissector_handle_t subdissector_handle;
163 tcap_top_tree = parent_tree;
164 if (check_col(pinfo->cinfo, COL_PROTOCOL))
166 col_set_str(pinfo->cinfo, COL_PROTOCOL, "TCAP");
169 /* create display subtree for the protocol */
171 item = proto_tree_add_item(parent_tree, proto_tcap, tvb, 0, -1, FALSE);
172 tree = proto_item_add_subtree(item, ett_tcap);
178 raz_tcap_private(&tcap_private);
180 pinfo->private_data = &tcap_private;
181 gp_tcapsrt_info=tcapsrt_razinfo();
182 tcap_subdissector_used=FALSE;
183 gp_tcap_context=NULL;
184 dissect_tcap_MessageType(FALSE, tvb, 0, pinfo, tree, -1);
186 if (gtcap_HandleSRT &&
187 !tcap_subdissector_used ) {
188 if (gtcap_DisplaySRT && tree) {
189 stat_item = proto_tree_add_text(tree, tvb, 0, 0, "Stat");
190 stat_tree = proto_item_add_subtree(stat_item, ett_tcap_stat);
192 p_tcap_context=tcapsrt_call_matching(tvb, pinfo, stat_tree, gp_tcapsrt_info);
193 tcap_private.context=p_tcap_context;
195 /* If the current message is TCAP only,
196 save the Application contexte name for the next messages */
197 if ( p_tcap_context &&
199 !p_tcap_context->oid_present ) {
200 /* Save the application context and the sub dissector */
201 ber_oid_dissector_table = find_dissector_table("ber.oid");
202 strncpy(p_tcap_context->oid,cur_oid, LENGTH_OID);
203 if ( (subdissector_handle
204 = dissector_get_string_handle(ber_oid_dissector_table, cur_oid)) ) {
205 p_tcap_context->subdissector_handle=subdissector_handle;
206 p_tcap_context->oid_present=TRUE;
210 if (gtcap_HandleSRT &&
212 p_tcap_context->callback) {
213 /* Callback fonction for the upper layer */
214 (p_tcap_context->callback)(tvb, pinfo, stat_tree, p_tcap_context);
221 proto_reg_handoff_tcap(void)
224 static gboolean prefs_initialized = FALSE;
226 if (! prefs_initialized) {
227 sccp_ssn_table = find_dissector_table("sccp.ssn");
228 prefs_initialized = TRUE;
231 add_oid_str_name("0.0.17.773.1.1.1",
232 "itu-t(0) recommendation(0) q(17) 773 as(1) dialogue-as(1) version1(1)");
234 data_handle = find_dissector("data");
237 static void init_tcap(void);
240 proto_register_tcap(void)
243 /* Setup list of header fields See Section 1.6.1 for details*/
244 static hf_register_info hf[] = {
246 { "Tag", "tcap.msgtype",
247 FT_UINT8, BASE_HEX, NULL, 0,
251 { "Length", "tcap.len",
252 FT_UINT8, BASE_HEX, NULL, 0,
256 { "Data", "tcap.data",
257 FT_BYTES, BASE_HEX, NULL, 0,
261 { "Transaction Id", "tcap.tid",
262 FT_BYTES, BASE_HEX, NULL, 0,
265 /* Tcap Service Response Time */
266 { &hf_tcapsrt_SessionId,
268 "tcap.srt.session_id",
269 FT_UINT32, BASE_DEC, NULL, 0x0,
272 { &hf_tcapsrt_BeginSession,
275 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
276 "SRT Begin of Session", HFILL }
278 { &hf_tcapsrt_EndSession,
281 FT_FRAMENUM, BASE_NONE, NULL, 0x0,
282 "SRT End of Session", HFILL }
284 { &hf_tcapsrt_SessionTime,
285 { "Session duration",
286 "tcap.srt.sessiontime",
287 FT_RELATIVE_TIME, BASE_NONE, NULL, 0x0,
288 "Duration of the TCAP session", HFILL }
290 { &hf_tcapsrt_Duplicate,
291 { "Request Duplicate",
292 "tcap.srt.duplicate",
293 FT_UINT32, BASE_DEC, NULL, 0x0,
296 #include "packet-tcap-hfarr.c"
299 /* Setup protocol subtree array */
300 static gint *ett[] = {
306 #include "packet-tcap-ettarr.c"
309 /*static enum_val_t tcap_options[] = {
310 { "itu", "ITU", ITU_TCAP_STANDARD },
311 { "ansi", "ANSI", ANSI_TCAP_STANDARD },
315 module_t *tcap_module;
317 /* Register the protocol name and description */
318 proto_tcap = proto_register_protocol(PNAME, PSNAME, PFNAME);
320 /* Required function calls to register the header fields and subtrees used */
321 proto_register_field_array(proto_tcap, hf, array_length(hf));
322 proto_register_subtree_array(ett, array_length(ett));
324 tcap_module = prefs_register_protocol(proto_tcap, proto_reg_handoff_tcap);
327 prefs_register_enum_preference(tcap_module, "standard", "ITU TCAP standard",
328 "The SS7 standard used in ITU TCAP packets",
329 &tcap_standard, tcap_options, FALSE);
331 prefs_register_obsolete_preference(tcap_module, "standard");
335 prefs_register_bool_preference(tcap_module, "lock_info_col", "Lock Info column",
336 "Always show TCAP in Info column",
339 prefs_register_obsolete_preference(tcap_module, "lock_info_col");
342 /* Set default SSNs */
343 range_convert_str(&global_ssn_range, "", MAX_SSN);
344 ssn_range = range_empty();
346 prefs_register_range_preference(tcap_module, "ssn", "SCCP SSNs",
347 "SCCP (and SUA) SSNs to decode as TCAP",
348 &global_ssn_range, MAX_SSN);
350 prefs_register_bool_preference(tcap_module, "srt",
351 "Service Response Time Analyse",
352 "Activate the analyse for Response Time",
355 prefs_register_bool_preference(tcap_module, "persistentsrt",
356 "Persistent stats for SRT",
357 "Statistics for Response Time",
358 >cap_PersistentSRT);
360 prefs_register_uint_preference(tcap_module, "repetitiontimeout",
361 "Repetition timeout",
362 "Maximal delay for message repetion",
363 10, >cap_RepetitionTimeout);
365 prefs_register_uint_preference(tcap_module, "losttimeout",
367 "Maximal delay for message lost",
368 10, >cap_LostTimeout);
370 ansi_sub_dissectors = g_hash_table_new(g_direct_hash,g_direct_equal);
371 itu_sub_dissectors = g_hash_table_new(g_direct_hash,g_direct_equal);
373 /* 'globally' register dissector */
374 register_dissector("tcap", dissect_tcap, proto_tcap);
376 tcap_handle = create_dissector_handle(dissect_tcap, proto_tcap);
378 register_init_routine(&init_tcap);
382 static void range_delete_callback(guint32 ssn)
384 if ( ssn && !get_ansi_tcap_subdissector(ssn) && !get_itu_tcap_subdissector(ssn) ) {
385 dissector_delete("sccp.ssn", ssn, tcap_handle);
389 static void range_add_callback(guint32 ssn)
391 if (ssn && !get_ansi_tcap_subdissector(ssn) && !get_itu_tcap_subdissector(ssn) ) {
392 dissector_add("sccp.ssn", ssn, tcap_handle);
397 static void init_tcap(void) {
399 range_foreach(ssn_range, range_delete_callback);
403 ssn_range = range_copy(global_ssn_range);
404 range_foreach(ssn_range, range_add_callback);
405 tcapsrt_init_routine();
409 dissect_tcap_param(packet_info *pinfo, proto_tree *tree, tvbuff_t *tvb, int offset)
411 gint tag_offset, saved_offset, len_offset;
421 while (tvb_reported_length_remaining(tvb, offset) > 0)
423 saved_offset = offset;
425 offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
427 offset = get_ber_length(tree, tvb, offset, &len, &ind_field);
433 proto_tree_add_text(tree, tvb, saved_offset, len + (len_offset - saved_offset), "CONSTRUCTOR");
434 subtree = proto_item_add_subtree(pi, ett_param);
435 proto_tree_add_uint_format(subtree, hf_tcap_tag, tvb,
436 saved_offset, tag_offset-saved_offset, tag, "CONSTRUCTOR Tag");
437 proto_tree_add_uint(subtree, hf_tcap_tag, tvb,
438 saved_offset, tag_offset-saved_offset, class);
440 proto_tree_add_uint(subtree, hf_tcap_length, tvb,
441 tag_offset, len_offset-tag_offset, len);
442 if (len-(2*ind_field)) /*should always be positive unless we get an empty contructor pointless? */
444 next_tvb = tvb_new_subset(tvb, offset, len-(2*ind_field), len-(2*ind_field));
445 dissect_tcap_param(pinfo, subtree,next_tvb,0);
448 proto_tree_add_text(subtree, tvb, offset+len-2, 2, "CONSTRUCTOR EOC");
453 pi = proto_tree_add_text(tree, tvb,
454 saved_offset, len + (len_offset - saved_offset), "Parameter (0x%.2x)", tag);
456 subtree = proto_item_add_subtree(pi, ett_param);
458 proto_tree_add_uint(subtree, hf_tcap_tag, tvb,
459 saved_offset, 1, tag);
461 proto_tree_add_uint(subtree, hf_tcap_length, tvb,
462 saved_offset+1, 1, len);
463 if (len) /* check for NULLS */
465 next_tvb = tvb_new_subset(tvb, offset, len, len);
466 dissect_ber_octet_string(TRUE, pinfo, tree, next_tvb, 0, hf_tcap_data,
475 static void raz_tcap_private(struct tcap_private_t * p_tcap_private)
477 memset(p_tcap_private,0,sizeof(struct tcap_private_t) );
482 dissect_tcap_TheComponent(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_)
485 dissector_handle_t subdissector_handle;
486 gboolean is_subdissector=FALSE;
487 struct tcaphash_context_t * p_tcap_context=NULL;
492 guint32 len, s_offset;
494 proto_tree * stat_tree=NULL;
495 proto_item * stat_item=NULL;
497 * ok lets look at the oid and ssn and try and find a dissector, otherwise lets decode it.
499 ber_oid_dissector_table = find_dissector_table("ber.oid");
501 offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
502 offset = get_ber_length(tree, tvb, offset, &len, &ind_field);
503 /* we can believe the length now */
504 next_tvb = tvb_new_subset(tvb, s_offset, len+(offset-s_offset), len+(offset-s_offset));
508 dissect_ber_choice(pinfo, tree, next_tvb, 0,
509 Component_choice, hf_index, ett_tcap_Component,NULL);
513 * Handle The TCAP Service Response Time
515 if ( gtcap_HandleSRT ) {
516 if (!tcap_subdissector_used) {
517 /* Create TCAP context and tree for display */
518 if (gtcap_DisplaySRT && tree) {
519 stat_item = proto_tree_add_text(tcap_stat_tree, tvb, offset, -1, "Stat");
520 stat_tree = proto_item_add_subtree(stat_item, ett_tcap_stat);
522 p_tcap_context=tcapsrt_call_matching(tvb, pinfo, stat_tree, gp_tcapsrt_info);
523 tcap_subdissector_used=TRUE;
524 gp_tcap_context=p_tcap_context;
525 tcap_private.context=p_tcap_context;
527 /* Take the last TCAP context */
528 p_tcap_context = gp_tcap_context;
529 tcap_private.context=p_tcap_context;
533 if (p_tcap_context) {
535 if (p_tcap_context->oid_present) {
536 /* We have already an Application Context, check if we have
537 to fallback to a lower version */
538 if ( strncmp(p_tcap_context->oid,cur_oid, LENGTH_OID)!=0) {
539 /* ACN, changed, Fallback to lower version */
540 /* and update the subdissector (purely formal) */
541 strncpy(p_tcap_context->oid,cur_oid, LENGTH_OID);
542 if ( (subdissector_handle
543 = dissector_get_string_handle(ber_oid_dissector_table, cur_oid)) ) {
544 p_tcap_context->subdissector_handle=subdissector_handle;
548 /* We do not have the OID in the TCAP context, so store it */
549 strncpy(p_tcap_context->oid,cur_oid, LENGTH_OID);
550 if ( (subdissector_handle
551 = dissector_get_string_handle(ber_oid_dissector_table, cur_oid)) ) {
552 p_tcap_context->subdissector_handle=subdissector_handle;
553 p_tcap_context->oid_present=TRUE;
557 /* Copy the OID from the TCAP context to the current oid */
558 if (p_tcap_context->oid_present) {
559 tcap_private.oid= (void*) p_tcap_context->oid;
560 tcap_private.acv=TRUE;
563 } /* no TCAP context */
566 && p_tcap_context->oid_present) {
567 /* Take the subdissector from the context */
568 subdissector_handle=p_tcap_context->subdissector_handle;
569 is_subdissector=TRUE;
572 if (!is_subdissector) {
574 * If we do not currently know the subdissector, we have to find it
575 * - first, according to the OID
576 * - then according to the SSN
577 * - and at least, take the default Data handler
579 if (ber_oid_dissector_table && cur_oid) {
580 /* Search if we can find the sub protocol according to the A.C.N */
581 if ( (subdissector_handle
582 = dissector_get_string_handle(ber_oid_dissector_table, cur_oid)) ) {
584 is_subdissector=TRUE;
586 /* Search if we can found the sub protocol according to the SSN table */
587 if ( (subdissector_handle
588 = get_itu_tcap_subdissector(pinfo->match_port))) {
589 /* Found according to SSN */
590 is_subdissector=TRUE;
592 /* Nothing found, take the Data handler */
593 subdissector_handle = data_handle;
594 is_subdissector=TRUE;
598 /* There is no A.C.N for this transaction, so search in the SSN table */
599 if ( (subdissector_handle = get_itu_tcap_subdissector(pinfo->match_port))) {
600 /* Found according to SSN */
601 is_subdissector=TRUE;
603 subdissector_handle = data_handle;
604 is_subdissector=TRUE;
608 /* We have it already */
610 /* Call the sub dissector if present, and not already called */
612 call_dissector(subdissector_handle, next_tvb, pinfo, tcap_top_tree);
619 dissect_tcap_TheExternUserInfo(gboolean implicit_tag _U_, tvbuff_t *tvb, int offset, packet_info *pinfo _U_, proto_tree *tree, int hf_index _U_)
625 guint32 len, start_offset;
629 * ok lets look at the oid and ssn and try and find a dissector, otherwise lets decode it.
631 ber_oid_dissector_table = find_dissector_table("ber.oid");
632 start_offset = offset;
633 offset = get_ber_identifier(tvb, offset, &class, &pc, &tag);
634 offset = get_ber_length(tree, tvb, offset, &len, &ind_field);
636 next_tvb = tvb_new_subset(tvb, start_offset, len +(offset - start_offset), len+(offset - start_offset));
640 if (ber_oid_dissector_table && tcapext_oid){
641 if(!dissector_try_string(ber_oid_dissector_table, tcapext_oid, next_tvb, pinfo, tcap_top_tree))
645 dissect_tcap_param(pinfo,tree,next_tvb,0);