aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2015-04-02 20:16:54 -0400
committerMartin Kaiser <wireshark@kaiser.cx>2015-04-04 09:07:51 +0000
commit37c41d7927d253882fdb97df4692d75306c70c2b (patch)
tree3b2232a3b1327b3df87bc54db366e31949f0da82 /epan/dissectors
parent7253ee7611fb2e62f2a9326689e48f8d2177aed9 (diff)
Add proper "Decode As" mechanism for I2C messages instead of preference.
Change-Id: Ifcf1193f97df6911ca9a0cf5613c9450b8fce1e4 Reviewed-on: https://code.wireshark.org/review/7897 Reviewed-by: Martin Kaiser <wireshark@kaiser.cx>
Diffstat (limited to 'epan/dissectors')
-rw-r--r--epan/dissectors/Makefile.common1
-rw-r--r--epan/dissectors/packet-hdmi.c21
-rw-r--r--epan/dissectors/packet-hdmi.h42
-rw-r--r--epan/dissectors/packet-i2c.c80
-rw-r--r--epan/dissectors/packet-ipmi.c22
5 files changed, 59 insertions, 107 deletions
diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common
index fe8cdd89f8..636923c507 100644
--- a/epan/dissectors/Makefile.common
+++ b/epan/dissectors/Makefile.common
@@ -1514,7 +1514,6 @@ DISSECTOR_INCLUDES = \
packet-h264.h \
packet-h323.h \
packet-h450-ros.h \
- packet-hdmi.h \
packet-hpext.h \
packet-http.h \
packet-i2c.h \
diff --git a/epan/dissectors/packet-hdmi.c b/epan/dissectors/packet-hdmi.c
index 3603264d7a..50c2f407f8 100644
--- a/epan/dissectors/packet-hdmi.c
+++ b/epan/dissectors/packet-hdmi.c
@@ -30,7 +30,6 @@
#include "config.h"
#include <epan/packet.h>
-#include "packet-hdmi.h"
void proto_register_hdmi(void);
void proto_reg_handoff_hdmi(void);
@@ -82,19 +81,6 @@ static const value_string hdmi_addr[] = {
#define CAPITAL_LETTER(x, n) ('A'-1 + (((x) & (0x1F<<n)) >> n))
-gboolean
-sub_check_hdmi(packet_info *pinfo _U_)
-{
- /* by looking at the i2c_phdr only, we can't decide if this packet is HDMI
- this function is called when the user explicitly selected HDMI
- in the preferences
- therefore, we always return TRUE and hand the data to the (new
- style) dissector who sees the 8bit address and the packet content */
-
- return TRUE;
-}
-
-
/* dissect EDID data from the receiver
return the offset after the dissected data */
static gint
@@ -272,15 +258,18 @@ proto_register_hdmi(void)
proto_register_field_array(proto_hdmi, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
-
- new_register_dissector("hdmi", dissect_hdmi, proto_hdmi);
}
void
proto_reg_handoff_hdmi(void)
{
+ dissector_handle_t hdmi_handle;
+
hdcp_handle = find_dissector("hdcp");
+
+ hdmi_handle = new_create_dissector_handle( dissect_hdmi, proto_hdmi );
+ dissector_add_for_decode_as("i2c.message", hdmi_handle );
}
/*
diff --git a/epan/dissectors/packet-hdmi.h b/epan/dissectors/packet-hdmi.h
deleted file mode 100644
index e4b5f608f6..0000000000
--- a/epan/dissectors/packet-hdmi.h
+++ /dev/null
@@ -1,42 +0,0 @@
-/* packet-hdmi.h
- * Routines for HDMI dissection
- * Copyright 2014 Martin Kaiser <martin@kaiser.cx>
- *
- * Wireshark - Network traffic analyzer
- * By Gerald Combs <gerald@wireshark.org>
- * Copyright 1998 Gerald Combs
- *
- * This program is free software; you can redistribute it and/or
- * modify it under the terms of the GNU General Public License
- * as published by the Free Software Foundation; either version 2
- * of the License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
- */
-
-#ifndef __PACKET_HDMI_H__
-#define __PACKET_HDMI_H__
-
-gboolean sub_check_hdmi(packet_info *pinfo _U_);
-
-#endif
-
-/*
- * Editor modelines - http://www.wireshark.org/tools/modelines.html
- *
- * Local variables:
- * c-basic-offset: 4
- * tab-width: 8
- * indent-tabs-mode: nil
- * End:
- *
- * vi: set shiftwidth=4 tabstop=8 expandtab:
- * :indentSize=4:tabSize=8:noTabs=true:
- */
diff --git a/epan/dissectors/packet-i2c.c b/epan/dissectors/packet-i2c.c
index 704ae080fd..d88bdfebfa 100644
--- a/epan/dissectors/packet-i2c.c
+++ b/epan/dissectors/packet-i2c.c
@@ -26,10 +26,10 @@
#include <epan/packet.h>
#include <epan/prefs.h>
+#include <epan/decode_as.h>
#include <wiretap/wtap.h>
#include "packet-i2c.h"
-#include "packet-hdmi.h"
void proto_register_i2c(void);
void proto_reg_handoff_i2c(void);
@@ -43,18 +43,8 @@ static int hf_i2c_addr = -1;
static gint ett_i2c = -1;
-enum {
- SUB_DATA = 0,
- SUB_IPMB,
- SUB_HDMI,
-
- SUB_MAX
-};
-
-typedef gboolean (*sub_checkfunc_t)(packet_info *);
-
-static dissector_handle_t sub_handles[SUB_MAX];
-static gint sub_selected = SUB_IPMB;
+static dissector_handle_t data_handle;
+static dissector_table_t subdissector_table;
/* I2C packet flags. */
#define I2C_FLAG_RD 0x00000001
@@ -85,6 +75,16 @@ static gint sub_selected = SUB_IPMB;
disconnected from the bus */
#define I2C_EVENT_ERR_FAIL (1 << 22) /* Undiagnosed failure */
+static void i2c_prompt(packet_info *pinfo _U_, gchar* result)
+{
+ g_snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "Interpret I2C messages as");
+}
+
+static gpointer i2c_value(packet_info *pinfo _U_)
+{
+ return 0;
+}
+
void
capture_i2c(union wtap_pseudo_header *pseudo_header, packet_counts *ld)
{
@@ -164,23 +164,6 @@ i2c_get_event_desc(guint32 event)
return desc;
}
-static gboolean
-sub_check_ipmb(packet_info *pinfo)
-{
- if (pinfo->pseudo_header->i2c.flags & I2C_FLAG_RD) {
- /* Master-receive transactions are not possible on IPMB */
- return FALSE;
- }
-
- return TRUE;
-}
-
-static sub_checkfunc_t sub_check[SUB_MAX] = {
- NULL, /* raw data */
- sub_check_ipmb, /* IPMI */
- sub_check_hdmi /* HDMI */
-};
-
static void
dissect_i2c(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
{
@@ -229,13 +212,13 @@ dissect_i2c(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
} else {
proto_tree_add_uint_format_value(i2c_tree, hf_i2c_addr, tvb, 0, 1,
addr, "0x%02x%s", addr, addr ? "" : " (General Call)");
- proto_tree_add_uint_format_value(i2c_tree, hf_i2c_flags, tvb, 0, 0,
- flags, "0x%08x", flags);
+ proto_tree_add_uint(i2c_tree, hf_i2c_flags, tvb, 0, 0, flags);
- if (sub_check[sub_selected] && sub_check[sub_selected](pinfo)) {
- call_dissector(sub_handles[sub_selected], tvb, pinfo, tree);
- } else {
- call_dissector(sub_handles[SUB_DATA], tvb, pinfo, tree);
+ /* Functionality for choosing subdissector is controlled through Decode As as I2C doesn't
+ have a unique identifier to determine subdissector */
+ if (!dissector_try_uint(subdissector_table, 0, tvb, pinfo, tree))
+ {
+ call_dissector(data_handle, tvb, pinfo, tree);
}
}
}
@@ -252,22 +235,24 @@ proto_register_i2c(void)
static gint *ett[] = {
&ett_i2c
};
- static const enum_val_t sub_enum_vals[] = {
- { "none", "None (raw I2C)", SUB_DATA },
- { "ipmb", "IPMB", SUB_IPMB },
- { "hdmi", "HDMI (including HDCP)", SUB_HDMI },
- { NULL, NULL, 0 }
- };
module_t *m;
+ /* Decode As handling */
+ static build_valid_func i2c_da_build_value[1] = {i2c_value};
+ static decode_as_value_t i2c_da_values = {i2c_prompt, 1, i2c_da_build_value};
+ static decode_as_t i2c_da = {"i2c", "I2C Message", "i2c.message", 1, 0, &i2c_da_values, NULL, NULL,
+ decode_as_default_populate_list, decode_as_default_reset, decode_as_default_change, NULL};
+
proto_i2c = proto_register_protocol("Inter-Integrated Circuit", "I2C", "i2c");
proto_register_field_array(proto_i2c, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
+ subdissector_table = register_dissector_table("i2c.message", "I2C messages dissector", FT_UINT32, BASE_DEC);
+
m = prefs_register_protocol(proto_i2c, NULL);
- prefs_register_enum_preference(m, "type", "Bus/Data type",
- "How the I2C messages are interpreted",
- &sub_selected, sub_enum_vals, FALSE);
+ prefs_register_obsolete_preference(m, "type");
+
+ register_decode_as(&i2c_da);
}
void
@@ -275,9 +260,8 @@ proto_reg_handoff_i2c(void)
{
dissector_handle_t i2c_handle;
- sub_handles[SUB_DATA] = find_dissector("data");
- sub_handles[SUB_IPMB] = find_dissector("ipmi");
- sub_handles[SUB_HDMI] = find_dissector("hdmi");
+ data_handle = find_dissector("data");
+
i2c_handle = create_dissector_handle(dissect_i2c, proto_i2c);
dissector_add_uint("wtap_encap", WTAP_ENCAP_I2C, i2c_handle);
}
diff --git a/epan/dissectors/packet-ipmi.c b/epan/dissectors/packet-ipmi.c
index 7587eb4d2b..256e6f6279 100644
--- a/epan/dissectors/packet-ipmi.c
+++ b/epan/dissectors/packet-ipmi.c
@@ -33,6 +33,7 @@
#include "packet-ipmi.h"
void proto_register_ipmi(void);
+void proto_reg_handoff_ipmi(void);
/*
* See the IPMI specifications at
@@ -1704,6 +1705,19 @@ dissect_ipmi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
(ipmi_dissect_arg_t *) data);
}
+static int
+dissect_i2c_ipmi(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+{
+ if (pinfo->pseudo_header->i2c.flags & 0x00000001) {
+ /* Master-receive transactions are not possible on IPMB */
+ return 0;
+ }
+
+ return do_dissect_ipmb(tvb, pinfo, tree, proto_ipmb, ett_ipmi,
+ (ipmi_dissect_arg_t *) data);
+}
+
+
/* Register IPMB protocol.
*/
void
@@ -1814,6 +1828,14 @@ proto_register_ipmi(void)
&selected_oem, oemsel_vals, FALSE);
}
+void proto_reg_handoff_ipmi(void)
+{
+ dissector_handle_t ipmi_handle;
+
+ ipmi_handle = new_create_dissector_handle( dissect_i2c_ipmi, proto_ipmi );
+ dissector_add_for_decode_as("i2c.message", ipmi_handle );
+}
+
/*
* Editor modelines - http://www.wireshark.org/tools/modelines.html
*