aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-hilscher.c
diff options
context:
space:
mode:
authorJeff Morriss <jeff.morriss@ulticom.com>2008-02-27 23:39:25 +0000
committerJeff Morriss <jeff.morriss@ulticom.com>2008-02-27 23:39:25 +0000
commitf5f636db9ea892d80c2d8ac792b9f0d093d5f775 (patch)
tree0121cee05369813e6f89a9e27438b18f66a29371 /epan/dissectors/packet-hilscher.c
parent6e0297dc86c3cf0905e361aa9baf3b586bf9b367 (diff)
From Holger Pfrommer via http://bugs.wireshark.org/bugzilla/show_bug.cgi?id=2205
This is a new dissector plugin for Hilscher analyzer frames. These frames are generated by Hilscher analyzer products and are identified via their unique source MAC address (this is a reserved MAC from Hilscher-range and will never be used by another network device). Most likely these frames are only generated on a virtual network interface or the generating device is attached directly via patch cable to a real network interface, but not routed through a network. The Ethernet-header (destination MAC, source MAC and Length/Type) is not displayed in the protocol tree for these frames as this is overhead-information which has no practical use in this case. Note: This is a heuristic Ethernet dissector which means it gets called for every Ethernet frame. So as to not cause a performance hit for most Wireshark users it has a preference which, by default, disables the dissector. svn path=/trunk/; revision=24495
Diffstat (limited to 'epan/dissectors/packet-hilscher.c')
-rw-r--r--epan/dissectors/packet-hilscher.c234
1 files changed, 234 insertions, 0 deletions
diff --git a/epan/dissectors/packet-hilscher.c b/epan/dissectors/packet-hilscher.c
new file mode 100644
index 0000000000..c51a490455
--- /dev/null
+++ b/epan/dissectors/packet-hilscher.c
@@ -0,0 +1,234 @@
+/* packet-hilscher.c
+ * Dissector for Hilscher analyzer protocols.
+ * Copyright 2008, Hilscher GmbH, Holger Pfrommer hpfrommer[AT]hilscher.com
+ *
+ * $Id$
+ *
+ * This is a new dissector plugin for Hilscher analyzer frames.
+ * These frames are generated by Hilscher analyzer products and are identified via
+ * their unique source MAC address (this is a reserved MAC from Hilscher-range and
+ * will never be used by another network device). Most likely these frames are
+ * only generated on a virtual network interface or the generating device is
+ * attached directly via patch cable to a real network interface, but not routed
+ * through a network. The Ethernet-header (destination MAC, source MAC and
+ * Length/Type) is not displayed in the protocol tree for these frames as this is
+ * overhead-information which has no practical use in this case.
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald[AT]wireshark.org>
+ * Copyright 1999 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include <glib.h>
+#include <epan/packet.h>
+#include <epan/prefs.h>
+
+
+static int proto_hilscher = -1;
+static module_t *hilscher_module;
+
+/* Ethernet heuristic dissectors (such as this one) get called for
+ * every Ethernet frame Wireshark handles. In order to not impose that
+ * performance penalty on everyone this dissector disables itself by
+ * default.
+ *
+ * This is done separately from the disabled protocols list mainly so
+ * we can disable it by default. XXX Maybe there's a better way.
+ */
+static int hilscher_enable_dissector = FALSE;
+
+void proto_reg_handoff_hilscher(void);
+
+static gint ett_information_type = -1;
+static gint ett_gpio_number = -1;
+static gint ett_gpio_edge = -1;
+
+static int hf_information_type = -1;
+static int hf_gpio_number = -1;
+static int hf_gpio_edge = -1;
+
+#define INFO_TYPE_OFFSET 14
+
+static const value_string information_type[] = {
+ { 0x0, "netANALYZER GPIO event" },
+ { 0, NULL }
+};
+
+static const value_string gpio_number[] = {
+ { 0x0, "GPIO 0" },
+ { 0x1, "GPIO 1" },
+ { 0x2, "GPIO 2" },
+ { 0x3, "GPIO 3" },
+ { 0, NULL }
+};
+
+static const value_string gpio_edge[] = {
+ { 0x0, "positive edge" },
+ { 0x1, "negative edge" },
+ { 0, NULL }
+};
+
+/* netANAYLZER dissector */
+static void
+dissect_hilscher_netanalyzer(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset)
+{
+ proto_item *ti = NULL;
+ guint gpio_num;
+ guint gpio_edge;
+ guchar *szInfo = NULL;
+
+ #define MAX_BUFFER 60
+ szInfo=ep_alloc(MAX_BUFFER);
+ szInfo[0]=0;
+
+ if (check_col(pinfo->cinfo, COL_PROTOCOL))
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "netANALYZER");
+
+ if (tree)
+ ti = proto_tree_add_item(tree, hf_information_type, tvb, offset, 1, FALSE);
+
+ /* GPIO NUMBER */
+ offset++;
+ if (tree)
+ ti = proto_tree_add_item (tree, hf_gpio_number, tvb, offset, 1, FALSE);
+ gpio_num = (tvb_get_guint8(tvb, offset) & 0x03);
+
+ /* GPIO EDGE */
+ offset++;
+ if (tree)
+ ti = proto_tree_add_item (tree, hf_gpio_edge, tvb, offset, 1, FALSE);
+ gpio_edge = (tvb_get_guint8(tvb, offset) & 0x01);
+
+ if (gpio_edge == 0x00)
+ g_snprintf(szInfo, MAX_BUFFER, "netANALYZER event on GPIO %d (positive edge)", gpio_num);
+ else
+ g_snprintf(szInfo, MAX_BUFFER, "netANALYZER event on GPIO %d (negative edge)", gpio_num);
+
+ if (check_col(pinfo->cinfo, COL_INFO))
+ col_add_str(pinfo->cinfo, COL_INFO, szInfo);
+}
+
+
+/* General Hilscher analyzer dissector */
+static gboolean
+dissect_hilscher_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+{
+ guint info_type;
+ gint offset;
+
+ /* Check that there's enough data */
+ if (tvb_length(tvb) < 14)
+ return FALSE;
+
+ /* check for Hilscher frame, this has a unique source MAC from Hilscher range and ethertype 0x88ff
+ First 14 bytes must be: xx xx xx xx xx xx 00 02 a2 ff ff ff 88 ff */
+ if ((tvb_get_guint8(tvb, 6) == 0x00) &&
+ (tvb_get_guint8(tvb, 7) == 0x02) &&
+ (tvb_get_guint8(tvb, 8) == 0xa2) &&
+ (tvb_get_guint8(tvb, 9) == 0xff) &&
+ (tvb_get_guint8(tvb, 10) == 0xff) &&
+ (tvb_get_guint8(tvb, 11) == 0xff) &&
+ (tvb_get_guint8(tvb, 12) == 0x88) &&
+ (tvb_get_guint8(tvb, 13) == 0xff) )
+ {
+
+ /* determine type of analyzer */
+ offset = INFO_TYPE_OFFSET;
+ info_type = tvb_get_guint8(tvb, offset);
+
+ switch (info_type)
+ {
+ /* this is a netANALYZER frame */
+ case 0x00:
+ dissect_hilscher_netanalyzer(tvb, pinfo, tree, offset);
+ break;
+
+ /* this is no Hilscher analyzer frame */
+ default:
+ return FALSE;
+ break;
+ }
+
+ }
+ else
+ {
+ /* this is no Hilscher analyzer frame */
+ return FALSE;
+ }
+
+ return TRUE;
+}
+
+
+
+void proto_register_hilscher(void)
+{
+ static hf_register_info hf[] = {
+ { &hf_information_type,
+ { "Hilscher information block type", "hilscher.information_type",
+ FT_UINT8, BASE_HEX, VALS(information_type), 0x0, "", HFILL }
+ },
+ { &hf_gpio_number,
+ { "Event on", "hilscher.net_analyzer.gpio_number", FT_UINT8,
+ BASE_HEX, VALS(gpio_number), 0x0, "", HFILL }
+ },
+ { &hf_gpio_edge,
+ { "Event type", "hilscher.net_analyzer.gpio_edge", FT_UINT8,
+ BASE_HEX, VALS(gpio_edge), 0x0, "", HFILL }
+ },
+ };
+
+ static gint *ett[] = {
+ &ett_information_type,
+ &ett_gpio_number,
+ &ett_gpio_edge,
+ };
+
+ if (proto_hilscher == -1)
+ {
+ proto_hilscher = proto_register_protocol ("Hilscher analyzer dissector", /* name */
+ "Hilscher", /* short name */
+ "Hilscher"); /* abbrev */
+ }
+
+ hilscher_module = prefs_register_protocol(proto_hilscher, proto_reg_handoff_hilscher);
+
+ prefs_register_bool_preference(hilscher_module, "enable", "Enable dissector",
+ "Enable this dissector (default is false)",
+ &hilscher_enable_dissector);
+
+ proto_register_field_array(proto_hilscher, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+
+}
+
+void proto_reg_handoff_hilscher(void)
+{
+ static int prefs_initialized = FALSE;
+
+ if (!prefs_initialized) {
+ /* add heuristic dissector */
+ heur_dissector_add("eth", dissect_hilscher_heur, proto_hilscher);
+ }
+
+ proto_set_decoding(proto_hilscher, hilscher_enable_dissector);
+}