aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorLazar Sumar <bugzilla@lazar.co.nz>2018-01-23 02:33:14 +0000
committerMichael Mann <mmann78@netscape.net>2018-01-26 03:19:50 +0000
commit0d5cbc7303dec4c7239b1df8fd152b58ce99a098 (patch)
treeadd7075ec1b22a1204e345fcfa9e4f79f3160103 /epan
parentfb2fa4d7769c025c9328562bf51cf9fa44d1dce5 (diff)
Added the Proconx CAN-ETH protocol dissector
Change-Id: I306341c7cddf8facb4a9ca62254a465a1da22174 Reviewed-on: https://code.wireshark.org/review/25423 Petri-Dish: Michael Mann <mmann78@netscape.net> Tested-by: Petri Dish Buildbot Reviewed-by: Michael Mann <mmann78@netscape.net>
Diffstat (limited to 'epan')
-rw-r--r--epan/dissectors/CMakeLists.txt1
-rw-r--r--epan/dissectors/Makefile.am1
-rw-r--r--epan/dissectors/packet-caneth.c301
-rw-r--r--epan/dissectors/packet-socketcan.c2
-rw-r--r--epan/dissectors/packet-socketcan.h3
5 files changed, 306 insertions, 2 deletions
diff --git a/epan/dissectors/CMakeLists.txt b/epan/dissectors/CMakeLists.txt
index e43e60dab7..93f1615c8d 100644
--- a/epan/dissectors/CMakeLists.txt
+++ b/epan/dissectors/CMakeLists.txt
@@ -748,6 +748,7 @@ set(DISSECTOR_SRC
${CMAKE_CURRENT_SOURCE_DIR}/packet-bzr.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-c15ch.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-calcappprotocol.c
+ ${CMAKE_CURRENT_SOURCE_DIR}/packet-caneth.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-canopen.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-capwap.c
${CMAKE_CURRENT_SOURCE_DIR}/packet-carp.c
diff --git a/epan/dissectors/Makefile.am b/epan/dissectors/Makefile.am
index 8002df4508..f7d9e85a24 100644
--- a/epan/dissectors/Makefile.am
+++ b/epan/dissectors/Makefile.am
@@ -371,6 +371,7 @@ DISSECTOR_SRC = \
packet-bzr.c \
packet-c15ch.c \
packet-calcappprotocol.c \
+ packet-caneth.c \
packet-canopen.c \
packet-capwap.c \
packet-carp.c \
diff --git a/epan/dissectors/packet-caneth.c b/epan/dissectors/packet-caneth.c
new file mode 100644
index 0000000000..4208cbe5ae
--- /dev/null
+++ b/epan/dissectors/packet-caneth.c
@@ -0,0 +1,301 @@
+/* packet-caneth.c
+ * Routines for Controller Area Network over Ethernet dissection
+ * Copyright 2018, Lazar Sumar <bugzilla@lazar.co.nz>
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * SPDX-License-Identifier: GPL-2.0+
+ */
+
+/*
+ * The CAN-ETH protocol is used for transmitting the Controller Area Network
+ * (CAN) protocol over UDP.
+ *
+ * The protocol definition can be found at http://www.proconx.com/assets/files/products/caneth/canframe.pdf
+ */
+
+#include <config.h>
+
+#include <epan/packet.h>
+#include <epan/dissectors/packet-udp.h>
+#include <epan/dissectors/packet-socketcan.h>
+
+#define CAN_FRAME_LEN 15
+#define CAN_DATA_OFFSET 5
+
+static const gchar magic[] = "ISO11898";
+
+void proto_reg_handoff_caneth(void);
+void proto_register_caneth(void);
+
+static int proto_caneth = -1;
+static int hf_caneth_magic = -1;
+static int hf_caneth_version = -1;
+static int hf_caneth_frames = -1;
+static int hf_caneth_options = -1;
+
+static int hf_caneth_can_ident_ext = -1;
+static int hf_caneth_can_ident_std = -1;
+static int hf_caneth_can_extflag = -1;
+static int hf_caneth_can_rtrflag = -1;
+static int hf_caneth_can_len = -1;
+static int hf_caneth_can_padding = -1;
+
+#define CANETH_UDP_PORT 11898
+
+static gint ett_caneth = -1;
+static gint ett_caneth_frames = -1;
+static gint ett_caneth_can = -1;
+
+static int proto_can = -1; // use CAN protocol for consistent filtering
+
+static dissector_table_t can_subdissector_table;
+/* A sample #define of the minimum length (in bytes) of the protocol data.
+ * If data is received with fewer than this many bytes it is rejected by
+ * the current dissector. */
+#define CANETH_MIN_LENGTH 10
+
+static gboolean
+test_caneth(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
+{
+ /* Check that we have enough length for the Magic, Version, and Length */
+ if (tvb_reported_length(tvb) < CANETH_MIN_LENGTH)
+ return FALSE;
+ /* Check that the magic id matches */
+ if (tvb_strneql(tvb, offset, magic, 8) != 0)
+ return FALSE;
+ /* Check that the version is 1 as that is the only supported version */
+ if (tvb_get_guint8(tvb, offset+8) != 1)
+ return FALSE;
+ /* Check that the version 1 limit of 16 can frames is respected */
+ if (tvb_get_guint8(tvb, offset+9) > 16)
+ return FALSE;
+ return TRUE;
+}
+
+static guint
+get_caneth_len(packet_info *pinfo _U_, tvbuff_t *tvb, int offset, void *data _U_)
+{
+ return (guint) tvb_get_ntohs(tvb, offset+3);
+}
+
+static int
+dissect_caneth_can(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+ proto_tree *can_tree;
+ proto_item *ti;
+ guint32 data_len;
+ guint32 raw_can_id;
+ gint8 ext_flag = 1;
+ tvbuff_t* next_tvb;
+ struct can_identifier can_id;
+
+ ti = proto_tree_add_item(tree, proto_can, tvb, 0, -1, ENC_NA);
+ can_tree = proto_item_add_subtree(ti, ett_caneth_can);
+
+ ext_flag = tvb_get_guint8(tvb, 13);
+ if (ext_flag)
+ {
+ proto_tree_add_item_ret_uint(can_tree, hf_caneth_can_ident_ext, tvb, 0, 4, ENC_NA, &raw_can_id);
+ can_id.id = raw_can_id & CAN_EFF_MASK;
+ }
+ else
+ {
+ proto_tree_add_item_ret_uint(can_tree, hf_caneth_can_ident_std, tvb, 0, 4, ENC_NA, &raw_can_id);
+ can_id.id = raw_can_id & CAN_SFF_MASK;
+ }
+
+ proto_tree_add_item_ret_uint(can_tree, hf_caneth_can_len, tvb, 4, 1, ENC_NA, &data_len);
+ proto_tree_add_item(can_tree, hf_caneth_can_extflag, tvb, 13, 1, ENC_NA);
+ proto_tree_add_item(can_tree, hf_caneth_can_rtrflag, tvb, 14, 1, ENC_NA);
+
+ next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, data_len);
+
+ if (!dissector_try_payload_new(can_subdissector_table, next_tvb, pinfo, tree, TRUE, &can_id))
+ {
+ call_data_dissector(next_tvb, pinfo, tree);
+ }
+
+ if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET + data_len) > 0)
+ {
+ proto_tree_add_item(can_tree, hf_caneth_can_padding, tvb, CAN_DATA_OFFSET + data_len, -1, ENC_NA);
+ }
+ return tvb_captured_length(tvb);
+}
+
+static int
+dissect_caneth(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+{
+ proto_tree *caneth_tree;
+ proto_item *ti;
+ guint32 frame_count, offset;
+ tvbuff_t* next_tvb;
+
+ if (!test_caneth(pinfo, tvb, 0, data))
+ return 0;
+
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "CAN-ETH");
+ col_clear(pinfo->cinfo, COL_INFO);
+
+ ti = proto_tree_add_item(tree, proto_caneth, tvb, 0, -1, ENC_NA);
+ caneth_tree = proto_item_add_subtree(ti, ett_caneth);
+
+ proto_tree_add_item(caneth_tree, hf_caneth_magic, tvb, 0, 8, ENC_ASCII|ENC_NA);
+ proto_tree_add_item(caneth_tree, hf_caneth_version, tvb, 8, 1, ENC_NA);
+ proto_tree_add_item_ret_uint(caneth_tree, hf_caneth_frames, tvb, 9, 1, ENC_NA, &frame_count);
+
+ for (offset = 10; frame_count-- > 0; offset += CAN_FRAME_LEN)
+ {
+ next_tvb = tvb_new_subset_length(tvb, offset, CAN_FRAME_LEN);
+ dissect_caneth_can(next_tvb, pinfo, tree, data);
+ }
+
+ if (tvb_captured_length_remaining(tvb, offset) > 0)
+ {
+ proto_tree_add_item(caneth_tree, hf_caneth_options, tvb, offset, -1, ENC_NA);
+ }
+
+ return tvb_captured_length(tvb);
+}
+
+static gboolean
+dissect_caneth_heur_udp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+{
+ return (udp_dissect_pdus(tvb, pinfo, tree, CANETH_MIN_LENGTH, test_caneth,
+ get_caneth_len, dissect_caneth, data) != 0);
+}
+
+void
+proto_register_caneth(void)
+{
+ static hf_register_info hf[] = {
+ {
+ &hf_caneth_magic,
+ {
+ "Magic", "caneth.magic",
+ FT_STRING, STR_ASCII,
+ NULL, 0x0,
+ "The magic identifier used to denote the start of a CAN-ETH packet", HFILL
+ }
+ },
+ {
+ &hf_caneth_version,
+ {
+ "Version", "caneth.version",
+ FT_UINT8, BASE_DEC,
+ NULL, 0x0,
+ NULL, HFILL
+ }
+ },
+ {
+ &hf_caneth_frames,
+ {
+ "CAN Frames", "caneth.frames",
+ FT_UINT8, BASE_DEC,
+ NULL, 0x0,
+ "Number of enclosed CAN frames", HFILL
+ }
+ },
+ {
+ &hf_caneth_options,
+ {
+ "Options (Reserved)", "caneth.options",
+ FT_BYTES, BASE_NONE,
+ NULL, 0x0,
+ "Options field, reserved for future use, should be empty", HFILL
+ }
+ },
+ {
+ &hf_caneth_can_ident_ext,
+ {
+ "Identifier", "can.id",
+ FT_UINT32, BASE_HEX,
+ NULL, CAN_EFF_MASK,
+ NULL, HFILL
+ }
+ },
+ {
+ &hf_caneth_can_ident_std,
+ {
+ "Identifier", "can.id",
+ FT_UINT32, BASE_HEX,
+ NULL, CAN_SFF_MASK,
+ NULL, HFILL
+ }
+ },
+ {
+ &hf_caneth_can_extflag,
+ {
+ "Extended Flag", "can.flags.xtd",
+ FT_BOOLEAN, BASE_NONE,
+ NULL, 0,
+ NULL, HFILL
+ }
+ },
+ {
+ &hf_caneth_can_rtrflag,
+ {
+ "Remote Transmission Request Flag", "can.flags.rtr",
+ FT_BOOLEAN, BASE_NONE,
+ NULL, 0,
+ NULL, HFILL
+ }
+ },
+ {
+ &hf_caneth_can_len,
+ {
+ "Frame-Length", "can.len",
+ FT_UINT8, BASE_DEC,
+ NULL, 0x0,
+ NULL, HFILL
+ }
+ },
+ {
+ &hf_caneth_can_padding,
+ {
+ "Padding", "caneth.can.padding",
+ FT_BYTES, BASE_NONE,
+ NULL, 0x0,
+ NULL, HFILL
+ }
+ },
+ };
+
+ static gint *ett[] = {
+ &ett_caneth,
+ &ett_caneth_frames,
+ &ett_caneth_can,
+ };
+
+ proto_caneth = proto_register_protocol("Controller Area Network over Ethernet", "CAN-ETH", "caneth");
+
+ proto_register_field_array(proto_caneth, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+}
+
+void
+proto_reg_handoff_caneth(void)
+{
+ dissector_handle_t caneth_handle = create_dissector_handle(dissect_caneth, proto_caneth);
+ dissector_add_uint_with_preference("udp.port", CANETH_UDP_PORT, caneth_handle);
+
+ heur_dissector_add("udp", dissect_caneth_heur_udp, "CAN-ETH over UDP", "caneth_udp", proto_caneth, HEURISTIC_ENABLE);
+
+ can_subdissector_table = find_dissector_table("can.subdissector");
+ proto_can = proto_get_id_by_filter_name("can");
+}
+
+/*
+ * Editor modelines - https://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-socketcan.c b/epan/dissectors/packet-socketcan.c
index 5cabab4fdf..c00bd56063 100644
--- a/epan/dissectors/packet-socketcan.c
+++ b/epan/dissectors/packet-socketcan.c
@@ -44,8 +44,6 @@
#define CAN_EFF_FLAG 0x80000000 /* EFF/SFF is set in the MSB */
#define CAN_RTR_FLAG 0x40000000 /* remote transmission request */
#define CAN_ERR_FLAG 0x20000000 /* error frame */
-#define CAN_EFF_MASK 0x1FFFFFFF /* extended frame format (EFF) */
-#define CAN_SFF_MASK 0x000007FF /* standard frame format (SFF) */
void proto_register_socketcan(void);
void proto_reg_handoff_socketcan(void);
diff --git a/epan/dissectors/packet-socketcan.h b/epan/dissectors/packet-socketcan.h
index 64757cab64..4947d58ff8 100644
--- a/epan/dissectors/packet-socketcan.h
+++ b/epan/dissectors/packet-socketcan.h
@@ -30,6 +30,9 @@ struct can_identifier
typedef struct can_identifier can_identifier_t;
+#define CAN_EFF_MASK 0x1FFFFFFF /* extended frame format (EFF) has a 29 bit identifier */
+#define CAN_SFF_MASK 0x000007FF /* standard frame format (SFF) has a 11 bit identifier */
+
#endif /* __PACKET_SOCKETCAN_H__ */
/*