From b3a339b86f813fb9268039c643e11e6d92273ee7 Mon Sep 17 00:00:00 2001 From: Roland Knall Date: Thu, 27 Apr 2017 17:23:03 +0200 Subject: openSAFETY: Set filter list for nodes To enhance the possibility for dissections, add a list of nodes, you explicitly want to see and print an info text in the node list for all nodes filtered Change-Id: I08e8a7ddcfd7b78fee24431ffdae75124a8ecddd Reviewed-on: https://code.wireshark.org/review/21383 Reviewed-by: Roland Knall --- epan/dissectors/packet-opensafety.c | 48 ++++++++++++++++++++++++++++++++++++- 1 file changed, 47 insertions(+), 1 deletion(-) (limited to 'epan/dissectors/packet-opensafety.c') diff --git a/epan/dissectors/packet-opensafety.c b/epan/dissectors/packet-opensafety.c index 0fb098da71..ffa20bf289 100644 --- a/epan/dissectors/packet-opensafety.c +++ b/epan/dissectors/packet-opensafety.c @@ -274,6 +274,10 @@ static gboolean global_enable_mbtcp = TRUE; static gboolean global_opensafety_debug_verbose = FALSE; +static const char * global_filter_nodes = ""; +static gboolean global_show_only_node_in_filter = TRUE; +static wmem_list_t * global_filter_list = NULL; + static gboolean heuristic_siii_dissection_enabled = TRUE; static heur_dissector_list_t heur_opensafety_spdo_subdissector_list; @@ -297,6 +301,17 @@ setup_dissector(void) { heur_dtbl_entry_t * heur_entry = NULL; + /* create list if it does not exist, but clean existing elements anyway, + * as options might have changed */ + global_filter_list = wmem_list_new(wmem_file_scope()); + + gchar ** vector = wmem_strsplit(wmem_file_scope(), global_filter_nodes, ",", -1); + for (; NULL != *vector; vector++ ) + { + if ( *vector && g_ascii_strtoll(*vector, NULL, 10) > 0 ) + wmem_list_append(global_filter_list, GINT_TO_POINTER(g_ascii_strtoll(*vector, NULL, 10))); + } + heur_entry = find_heur_dissector_by_unique_short_name("opensafety_sercosiii"); if ( heur_entry != NULL ) heuristic_siii_dissection_enabled = heur_entry->enabled; @@ -306,6 +321,12 @@ static void cleanup_dissector(void) { local_scm_udid = NULL; + + if ( global_filter_list ) + { + wmem_destroy_list(global_filter_list); + global_filter_list = NULL; + } } void proto_register_opensafety(void); @@ -2161,6 +2182,23 @@ opensafety_package_dissector(const gchar *protocolName, const gchar *sub_diss_ha } } + /* Filter node list */ + gint addr = OSS_FRAME_ADDR_T(message_tvb, byte_offset + frameStart1); + if ( global_filter_list && wmem_list_count ( global_filter_list ) > 0 ) + { + gboolean found_in_list = wmem_list_find(global_filter_list, GINT_TO_POINTER( addr )) ? TRUE : FALSE; + + if ( ( ! global_show_only_node_in_filter && found_in_list ) || + ( global_show_only_node_in_filter && ! found_in_list ) ) + { + opensafety_item = proto_tree_add_item(tree, proto_opensafety, message_tvb, frameOffset, frameLength, ENC_NA); + proto_item_append_text(opensafety_item, ", Filtered Node: 0x%03X (%d)", addr, addr); + frameOffset += 2; + found--; + continue; + } + } + /* From here on, the package should be correct. Even if it is not correct, it will be dissected * anyway and marked as malformed. Therefore it can be assumed, that a gap will end here. */ @@ -2431,7 +2469,6 @@ apply_prefs ( void ) /* Preference names to specific to use "auto" preference */ dissector_add_uint("udp.port", opensafety_udp_port_number, opensafety_udpdata_handle); dissector_add_uint("udp.port", opensafety_udp_siii_port_number, opensafety_udpdata_handle); - } void @@ -2811,6 +2848,15 @@ proto_register_opensafety(void) "Automatically assign a detected SCM UDID (by reading SNMT->SNTM_assign_UDID_SCM) and set it for the file", &global_scm_udid_autoset); + prefs_register_string_preference(opensafety_module, "filter_nodes", + "Filter openSAFETY Nodes", + "A comma-separated list of nodes to be filtered during dissection", + &global_filter_nodes); + prefs_register_bool_preference(opensafety_module, "filter_show_nodes_in_filterlist", + "Show nodes in filter, hide otherwise", + "If set to true, only nodes in the list will be shown, otherwise they will be hidden", + &global_show_only_node_in_filter); + prefs_register_uint_preference(opensafety_module, "network_udp_port", "Port used for Generic UDP", "Port used by any UDP demo implementation to transport data", 10, -- cgit v1.2.3