aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Mann <mmann78@netscape.net>2013-12-06 04:33:58 +0000
committerMichael Mann <mmann78@netscape.net>2013-12-06 04:33:58 +0000
commit643f9efce238971298e1979d9433dd5a88d863a3 (patch)
tree982e845d42b8b5e337708d8e72a1dbbeec4637c3
parentb2be51c76d4b79c5350f40643f6c861b75b2ad13 (diff)
Add DeviceNet and J1939 dissectors. Both run on top of CAN (not necessarily always SocketCAN, but it did provide a good test environment)
svn path=/trunk/; revision=53802
-rw-r--r--epan/CMakeLists.txt2
-rw-r--r--epan/address.h4
-rw-r--r--epan/address_to_str.c8
-rw-r--r--epan/dissectors/Makefile.common2
-rw-r--r--epan/dissectors/packet-cip.c66
-rw-r--r--epan/dissectors/packet-cip.h4
-rw-r--r--epan/dissectors/packet-devicenet.c1033
-rw-r--r--epan/dissectors/packet-j1939.c321
-rw-r--r--epan/dissectors/packet-socketcan.c20
9 files changed, 1424 insertions, 36 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt
index 21dd8d2605..6d16eb9db9 100644
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -548,6 +548,7 @@ set(DISSECTOR_SRC
dissectors/packet-dec-bpdu.c
dissectors/packet-dec-dnart.c
dissectors/packet-dect.c
+ dissectors/packet-devicenet.c
dissectors/packet-dhcp-failover.c
dissectors/packet-dhcpv6.c
dissectors/packet-diameter.c
@@ -825,6 +826,7 @@ set(DISSECTOR_SRC
dissectors/packet-iwarp-mpa.c
dissectors/packet-ixiatrailer.c
dissectors/packet-ixveriwave.c
+ dissectors/packet-j1939.c
dissectors/packet-jmirror.c
dissectors/packet-jpeg.c
dissectors/packet-json.c
diff --git a/epan/address.h b/epan/address.h
index 27152f3fe1..e9e105e284 100644
--- a/epan/address.h
+++ b/epan/address.h
@@ -57,8 +57,10 @@ typedef enum {
AT_USB, /* USB Device address
* (0xffffffff represents the host) */
AT_AX25, /* AX.25 */
- AT_IEEE_802_15_4_SHORT /* IEEE 802.15.4 16-bit short address */
+ AT_IEEE_802_15_4_SHORT,/* IEEE 802.15.4 16-bit short address */
/* (the long addresses are EUI-64's */
+ AT_J1939, /* J1939 */
+ AT_DEVICENET, /* DeviceNet */
} address_type;
typedef struct _address {
diff --git a/epan/address_to_str.c b/epan/address_to_str.c
index cd012e8429..1ebd0ace4c 100644
--- a/epan/address_to_str.c
+++ b/epan/address_to_str.c
@@ -627,6 +627,14 @@ address_to_str_buf(const address *addr, gchar *buf, int buf_len)
else
g_snprintf(buf, buf_len, "0x%04x", ieee_802_15_4_short_addr);
break;
+ case AT_J1939:
+ addrdata = (const guint8 *)addr->data;
+ g_snprintf(buf, buf_len, "%d", addrdata[0]);
+ break;
+ case AT_DEVICENET:
+ addrdata = (const guint8 *)addr->data;
+ g_snprintf(buf, buf_len, "%d", addrdata[0] & 0x3f);
+ break;
default:
g_assert_not_reached();
}
diff --git a/epan/dissectors/Makefile.common b/epan/dissectors/Makefile.common
index 107ff5331b..2932c8aae2 100644
--- a/epan/dissectors/Makefile.common
+++ b/epan/dissectors/Makefile.common
@@ -469,6 +469,7 @@ DISSECTOR_SRC = \
packet-dec-bpdu.c \
packet-dec-dnart.c \
packet-dect.c \
+ packet-devicenet.c \
packet-dhcp-failover.c \
packet-dhcpv6.c \
packet-diameter.c \
@@ -747,6 +748,7 @@ DISSECTOR_SRC = \
packet-iwarp-mpa.c \
packet-ixiatrailer.c \
packet-ixveriwave.c \
+ packet-j1939.c \
packet-jmirror.c \
packet-jpeg.c \
packet-json.c \
diff --git a/epan/dissectors/packet-cip.c b/epan/dissectors/packet-cip.c
index 8b0e92dc22..4e8ccc9ce5 100644
--- a/epan/dissectors/packet-cip.c
+++ b/epan/dissectors/packet-cip.c
@@ -2541,14 +2541,14 @@ static void add_cip_service_to_info_column(packet_info *pinfo, guint8 service, c
{
/* Add service to info column */
col_append_sep_fstr(pinfo->cinfo, COL_INFO, " | ", "%s",
- val_to_str( service & 0x7F,
+ val_to_str( service & CIP_SC_MASK,
service_vals, "Unknown Service (0x%02x)") );
col_set_fence(pinfo->cinfo, COL_INFO);
}
else
{
col_append_str( pinfo->cinfo, COL_INFO,
- val_to_str(service & 0x7F,
+ val_to_str(service & CIP_SC_MASK,
service_vals, "Unknown Service (0x%02x)") );
col_set_fence(pinfo->cinfo, COL_INFO);
/* Make sure it's only set once */
@@ -3120,7 +3120,7 @@ static attribute_val_array_t all_attribute_vals[] = {
static void
dissect_cip_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, packet_info *pinfo, cip_req_info_t *preq_info );
-static attribute_info_t* cip_get_attribute(guint class_id, guint instance, guint attribute)
+attribute_info_t* cip_get_attribute(guint class_id, guint instance, guint attribute)
{
size_t i, j;
attribute_val_array_t* att_array;
@@ -4096,7 +4096,7 @@ dissect_cip_generic_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int
unsigned char add_stat_size;
guint8 service = tvb_get_guint8( tvb, offset );
- if (service & 0x80)
+ if (service & CIP_SC_RESPONSE_MASK)
{
/* Response message */
add_stat_size = tvb_get_guint8( tvb, offset+3 ) * 2;
@@ -4381,7 +4381,7 @@ dissect_cip_generic_service_req(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
int req_path_size,
offset = 0;
proto_tree *cmd_data_tree;
- guint8 service = tvb_get_guint8( tvb, offset ) & 0x7F;
+ guint8 service = tvb_get_guint8( tvb, offset ) & CIP_SC_MASK;
add_cip_service_to_info_column(pinfo, service, cip_sc_vals);
@@ -4728,7 +4728,7 @@ dissect_cip_generic_service_rsp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *t
cip_simple_request_info_t req_data;
int offset = 0,
item_length = tvb_length(tvb);
- guint8 service = tvb_get_guint8( tvb, offset ) & 0x7F,
+ guint8 service = tvb_get_guint8( tvb, offset ) & CIP_SC_MASK,
add_stat_size = tvb_get_guint8( tvb, offset+3 ) * 2;
/* If there is any command specific data create a sub-tree for it */
@@ -5089,7 +5089,7 @@ dissect_cip_cm_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item_
/* Special handling for Unconnected send response. If successful, embedded service code is sent.
* If failed, it can be either an Unconnected send response or the embedded service code response. */
preq_info = (cip_req_info_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cip, 0 );
- if ( preq_info != NULL && ( service & 0x80 )
+ if ( preq_info != NULL && ( service & CIP_SC_RESPONSE_MASK )
&& preq_info->bService == SC_CM_UNCON_SEND
)
{
@@ -5100,7 +5100,7 @@ dissect_cip_cm_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item_
else
add_status = 0;
if( gen_status == 0 /* success response ) */
- || ( ( service & 0x7F ) != SC_CM_UNCON_SEND )
+ || ( ( service & CIP_SC_MASK ) != SC_CM_UNCON_SEND )
|| !( ( gen_status == CI_GRC_FAILURE && (add_status == CM_ES_UNCONNECTED_REQUEST_TIMED_OUT ||
add_status == CM_ES_PORT_NOT_AVAILABLE ||
add_status == CM_ES_LINK_ADDRESS_NOT_VALID ||
@@ -5146,15 +5146,15 @@ dissect_cip_cm_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item_
/* watch for service collisions */
proto_item_append_text( rrsc_item, "%s (%s)",
- val_to_str( ( service & 0x7F ),
+ val_to_str( ( service & CIP_SC_MASK ),
cip_sc_vals_cm , "Unknown Service (0x%02x)"),
- val_to_str_const( ( service & 0x80 )>>7,
+ val_to_str_const( ( service & CIP_SC_RESPONSE_MASK )>>7,
cip_sc_rr, "") );
/* Add Service code */
proto_tree_add_item(rrsc_tree, hf_cip_cm_sc, tvb, offset, 1, ENC_LITTLE_ENDIAN );
- if( service & 0x80 )
+ if( service & CIP_SC_RESPONSE_MASK )
{
/* Response message */
gen_status = tvb_get_guint8( tvb, offset+2 );
@@ -5251,7 +5251,7 @@ dissect_cip_cm_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item_
if( gen_status == CI_GRC_SUCCESS || gen_status == CI_GRC_SERVICE_ERROR )
{
/* Success responses */
- switch (service & 0x7F)
+ switch (service & CIP_SC_MASK)
{
case SC_CM_FWD_OPEN:
case SC_CM_LARGE_FWD_OPEN:
@@ -5315,7 +5315,7 @@ dissect_cip_cm_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item_
else
{
/* Error responses */
- switch (service & 0x7F)
+ switch (service & CIP_SC_MASK)
{
case SC_CM_FWD_OPEN:
case SC_CM_LARGE_FWD_OPEN:
@@ -5525,15 +5525,15 @@ dissect_cip_mb_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item_
proto_tree_add_item( rrsc_tree, hf_cip_reqrsp, tvb, offset, 1, ENC_LITTLE_ENDIAN );
proto_item_append_text( rrsc_item, "%s (%s)",
- val_to_str( ( service & 0x7F ),
+ val_to_str( ( service & CIP_SC_MASK ),
cip_sc_vals_mb , "Unknown Service (0x%02x)"),
- val_to_str_const( ( service & 0x80 )>>7,
+ val_to_str_const( ( service & CIP_SC_RESPONSE_MASK )>>7,
cip_sc_rr, "") );
/* Add Service code */
proto_tree_add_item(rrsc_tree, hf_cip_mb_sc, tvb, offset, 1, ENC_LITTLE_ENDIAN );
- if( service & 0x80 )
+ if( service & CIP_SC_RESPONSE_MASK )
{
/* Response message */
gen_status = tvb_get_guint8( tvb, offset+2 );
@@ -5548,7 +5548,7 @@ dissect_cip_mb_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item_
if( gen_status == CI_GRC_SUCCESS || gen_status == CI_GRC_SERVICE_ERROR )
{
/* Success responses */
- switch (service & 0x7F)
+ switch (service & CIP_SC_MASK)
{
case SC_MB_READ_DISCRETE_INPUTS:
proto_tree_add_item(cmd_data_tree, hf_cip_mb_read_discrete_inputs_data, tvb, offset+4+add_stat_size, item_length-4-add_stat_size, ENC_NA);
@@ -5910,9 +5910,9 @@ dissect_cip_cco_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item
proto_tree_add_item( rrsc_tree, hf_cip_reqrsp, tvb, offset, 1, ENC_LITTLE_ENDIAN );
proto_item_append_text( rrsc_item, "%s (%s)",
- val_to_str( ( service & 0x7F ),
+ val_to_str( ( service & CIP_SC_MASK ),
cip_sc_vals_cco , "Unknown Service (0x%02x)"),
- val_to_str_const( ( service & 0x80 )>>7,
+ val_to_str_const( ( service & CIP_SC_RESPONSE_MASK )>>7,
cip_sc_rr, "") );
/* Add Service code */
@@ -5932,7 +5932,7 @@ dissect_cip_cco_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item
req_data.iMember = (guint32)-1;
}
- if(service & 0x80 )
+ if(service & CIP_SC_RESPONSE_MASK )
{
/* Response message */
@@ -5949,7 +5949,7 @@ dissect_cip_cco_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, int item
if( gen_status == CI_GRC_SUCCESS || gen_status == CI_GRC_SERVICE_ERROR )
{
/* Success responses */
- if (((service & 0x7F) == SC_GET_ATT_ALL) &&
+ if (((service & CIP_SC_MASK) == SC_GET_ATT_ALL) &&
(req_data.iInstance != (guint32)-1))
{
if (req_data.iInstance == 0)
@@ -6070,13 +6070,13 @@ dissect_class_cco_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void
int offset = 0;
service = tvb_get_guint8( tvb, offset );
- service_code = service & 0x7F;
+ service_code = service & CIP_SC_MASK;
/* Handle GetAttributeAll and SetAttributeAll in CCO class */
if ((service_code == SC_GET_ATT_ALL) ||
(service_code == SC_SET_ATT_ALL))
{
- if (service & 0x80)
+ if (service & CIP_SC_RESPONSE_MASK)
{
/* Service response */
preq_info = (cip_req_info_t*)p_get_proto_data(wmem_file_scope(), pinfo, proto_cip, 0);
@@ -6163,15 +6163,15 @@ dissect_cip_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, packet_info
/* Add Service code & Request/Response tree */
rrsc_item = proto_tree_add_uint_format_value(cip_tree, hf_cip_service,
tvb, offset, 1, service, "%s (%s)",
- val_to_str( ( service & 0x7F ), cip_sc_vals , "Unknown Service (0x%02x)"),
- val_to_str_const( ( service & 0x80 )>>7, cip_sc_rr, ""));
+ val_to_str( ( service & CIP_SC_MASK ), cip_sc_vals , "Unknown Service (0x%02x)"),
+ val_to_str_const( ( service & CIP_SC_RESPONSE_MASK )>>7, cip_sc_rr, ""));
rrsc_tree = proto_item_add_subtree( rrsc_item, ett_rrsc );
proto_tree_add_item( rrsc_tree, hf_cip_reqrsp, tvb, offset, 1, ENC_LITTLE_ENDIAN);
proto_tree_add_item(rrsc_tree, hf_cip_service_code, tvb, offset, 1, ENC_LITTLE_ENDIAN);
- if( service & 0x80 )
+ if( service & CIP_SC_RESPONSE_MASK )
{
/* Response message */
status_item = proto_tree_add_text( cip_tree, tvb, offset+2, 1, "Status: " );
@@ -6207,7 +6207,7 @@ dissect_cip_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, packet_info
if( preq_info
- && !( preq_info->bService == ( service & 0x7F )
+ && !( preq_info->bService == ( service & CIP_SC_MASK )
|| ( preq_info->bService == SC_CM_UNCON_SEND && preq_info->dissector == cip_class_cm_handle )
)
)
@@ -6237,7 +6237,7 @@ dissect_cip_data( proto_tree *item_tree, tvbuff_t *tvb, int offset, packet_info
}
/* Check to see if service is 'generic' */
- try_val_to_str_idx((service & 0x7F), cip_sc_vals, &service_index);
+ try_val_to_str_idx((service & CIP_SC_MASK), cip_sc_vals, &service_index);
if (service_index >= 0)
{
/* See if object dissector wants to override generic service handling */
@@ -6381,8 +6381,8 @@ proto_register_cip(void)
static hf_register_info hf[] = {
{ &hf_cip_service, { "Service", "cip.service", FT_UINT8, BASE_HEX, NULL, 0, "Service Code + Request/Response", HFILL }},
- { &hf_cip_reqrsp, { "Request/Response", "cip.rr", FT_UINT8, BASE_HEX, VALS(cip_sc_rr), 0x80, "Request or Response message", HFILL }},
- { &hf_cip_service_code, { "Service", "cip.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals), 0x7F, "Service Code", HFILL }},
+ { &hf_cip_reqrsp, { "Request/Response", "cip.rr", FT_UINT8, BASE_HEX, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK, "Request or Response message", HFILL }},
+ { &hf_cip_service_code, { "Service", "cip.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals), CIP_SC_MASK, "Service Code", HFILL }},
{ &hf_cip_epath, { "EPath", "cip.epath", FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
{ &hf_cip_genstat, { "General Status", "cip.genstat", FT_UINT8, BASE_HEX|BASE_EXT_STRING, &cip_gs_vals_ext, 0, NULL, HFILL }},
{ &hf_cip_addstat_size, { "Additional Status Size", "cip.addstat_size", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
@@ -6626,7 +6626,7 @@ proto_register_cip(void)
};
static hf_register_info hf_cm[] = {
- { &hf_cip_cm_sc, { "Service", "cip.cm.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals_cm), 0x7F, NULL, HFILL }},
+ { &hf_cip_cm_sc, { "Service", "cip.cm.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals_cm), CIP_SC_MASK, NULL, HFILL }},
{ &hf_cip_cm_genstat, { "General Status", "cip.cm.genstat", FT_UINT8, BASE_HEX|BASE_EXT_STRING, &cip_gs_vals_ext, 0, NULL, HFILL }},
{ &hf_cip_cm_addstat_size, { "Additional Status Size", "cip.cm.addstat_size", FT_UINT8, BASE_DEC, NULL, 0, NULL, HFILL }},
{ &hf_cip_cm_ext_status, { "Extended Status", "cip.cm.ext_status", FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_cm_ext_st_vals_ext, 0, NULL, HFILL }},
@@ -6689,7 +6689,7 @@ proto_register_cip(void)
};
static hf_register_info hf_mb[] = {
- { &hf_cip_mb_sc, { "Service", "cip.mb.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals_mb), 0x7F, NULL, HFILL }},
+ { &hf_cip_mb_sc, { "Service", "cip.mb.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals_mb), CIP_SC_MASK, NULL, HFILL }},
{ &hf_cip_mb_read_coils_start_addr, { "Starting Address", "cip.mb.read_coils.start_addr", FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
{ &hf_cip_mb_read_coils_num_coils, { "Quantity of Coils", "cip.mb.read_coils.num_coils", FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
{ &hf_cip_mb_read_coils_data, { "Data", "cip.mb.read_coils.data", FT_BYTES, BASE_NONE, NULL, 0, NULL, HFILL }},
@@ -6714,7 +6714,7 @@ proto_register_cip(void)
};
static hf_register_info hf_cco[] = {
- { &hf_cip_cco_sc, { "Service", "cip.cco.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals_cco), 0x7F, NULL, HFILL }},
+ { &hf_cip_cco_sc, { "Service", "cip.cco.sc", FT_UINT8, BASE_HEX, VALS(cip_sc_vals_cco), CIP_SC_MASK, NULL, HFILL }},
{ &hf_cip_cco_format_number, { "Format Number", "cip.cco.format_number", FT_UINT16, BASE_DEC, NULL, 0, NULL, HFILL }},
{ &hf_cip_cco_edit_signature, { "Edit Signature", "cip.cco.edit_signature", FT_UINT32, BASE_HEX, NULL, 0, NULL, HFILL }},
{ &hf_cip_cco_con_flags, { "Connection Flags", "cip.cco.connflags", FT_UINT16, BASE_HEX, NULL, 0, NULL, HFILL }},
diff --git a/epan/dissectors/packet-cip.h b/epan/dissectors/packet-cip.h
index 2d48562442..bc3a437cef 100644
--- a/epan/dissectors/packet-cip.h
+++ b/epan/dissectors/packet-cip.h
@@ -54,6 +54,9 @@
#define SC_REMOVE_MEMBER 0x1B
#define SC_GROUP_SYNC 0x1C
+#define CIP_SC_MASK 0x7F
+#define CIP_SC_RESPONSE_MASK 0x80
+
/* Classes that have class-specfic dissectors */
#define CI_CLS_MR 0x02 /* Message Router */
#define CI_CLS_CM 0x06 /* Connection Manager */
@@ -311,6 +314,7 @@ typedef struct cip_req_info {
extern void dissect_epath( tvbuff_t *tvb, packet_info *pinfo, proto_item *epath_item, int offset, int path_length,
gboolean generate, gboolean packed, cip_simple_request_info_t* req_data, cip_safety_epath_info_t* safety);
extern void dissect_cip_date_and_time(proto_tree *tree, tvbuff_t *tvb, int offset, int hf_datetime);
+extern attribute_info_t* cip_get_attribute(guint class_id, guint instance, guint attribute);
/*
** Exported variables
diff --git a/epan/dissectors/packet-devicenet.c b/epan/dissectors/packet-devicenet.c
new file mode 100644
index 0000000000..97c5b03019
--- /dev/null
+++ b/epan/dissectors/packet-devicenet.c
@@ -0,0 +1,1033 @@
+/* packet-devicenet.c
+ * Routines for dissection of DeviceNet
+ *
+ * Michael Mann
+ * Erik Ivarsson <eriki@student.chalmers.se>
+ * Hans-Jorgen Gunnarsson <hag@hms.se>
+ * Copyright 2012
+ *
+ * $Id: packet-devicenet.c 39503 2011-10-21 02:10:19Z wmeier $
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#include "config.h"
+
+#include <glib.h>
+
+#include <epan/packet.h>
+#include <epan/uat.h>
+#include <epan/prefs.h>
+#include <epan/expert.h>
+#include <epan/reassemble.h>
+#include "packet-cip.h"
+
+#define DEVICENET_CANID_MASK 0x7FF
+#define MESSAGE_GROUP_1_ID 0x3FF
+#define MESSAGE_GROUP_1_MSG_MASK 0x3C0
+#define MESSAGE_GROUP_1_MAC_ID_MASK 0x03F
+
+#define MESSAGE_GROUP_2_ID 0x5FF
+#define MESSAGE_GROUP_2_MSG_MASK 0x007
+#define MESSAGE_GROUP_2_MAC_ID_MASK 0x1F8
+
+#define MESSAGE_GROUP_3_ID 0x7BF
+#define MESSAGE_GROUP_3_MSG_MASK 0x1C0
+#define MESSAGE_GROUP_3_MAC_ID_MASK 0x03F
+#define MESSAGE_GROUP_3_FRAG_MASK 0x80
+#define MESSAGE_GROUP_3_XID_MASK 0x40
+
+#define MESSAGE_GROUP_4_ID 0x7EF
+#define MESSAGE_GROUP_4_MSG_MASK 0x03F
+
+static int proto_devicenet = -1;
+
+static int hf_devicenet_can_id = -1;
+static int hf_devicenet_src_mac_id = -1;
+static int hf_devicenet_data = -1;
+static int hf_devicenet_grp_msg1_id = -1;
+static int hf_devicenet_grp_msg2_id = -1;
+static int hf_devicenet_grp_msg3_id = -1;
+static int hf_devicenet_grp_msg3_frag = -1;
+static int hf_devicenet_grp_msg3_xid = -1;
+static int hf_devicenet_grp_msg3_dest_mac_id = -1;
+static int hf_devicenet_grp_msg4_id = -1;
+static int hf_devicenet_rr_bit = -1;
+static int hf_devicenet_service_code = -1;
+static int hf_devicenet_connection_id = -1;
+static int hf_devicenet_open_exp_src_message_id = -1;
+static int hf_devicenet_open_exp_dest_message_id = -1;
+static int hf_devicenet_open_exp_msg_req_body_format = -1;
+static int hf_devicenet_open_exp_msg_actual_body_format = -1;
+static int hf_devicenet_open_exp_group_select = -1;
+static int hf_devicenet_open_exp_msg_reserved = -1;
+static int hf_devicenet_dup_mac_id_rr_bit = -1;
+static int hf_devicenet_dup_mac_id_physical_port_number = -1;
+static int hf_devicenet_dup_mac_id_serial_number = -1;
+static int hf_devicenet_dup_mac_id_vendor = -1;
+static int hf_devicenet_comm_fault_rsv = -1;
+static int hf_devicenet_comm_fault_match = -1;
+static int hf_devicenet_comm_fault_value = -1;
+static int hf_devicenet_offline_ownership_reserved = -1;
+static int hf_devicenet_offline_ownership_client_mac_id = -1;
+static int hf_devicenet_offline_ownership_allocate = -1;
+static int hf_devicenet_vendor = -1;
+static int hf_devicenet_serial_number = -1;
+static int hf_devicenet_class8 = -1;
+static int hf_devicenet_class16 = -1;
+static int hf_devicenet_instance8 = -1;
+static int hf_devicenet_instance16 = -1;
+static int hf_devicenet_fragment_type = -1;
+static int hf_devicenet_fragment_count = -1;
+
+static gint ett_devicenet = -1;
+static gint ett_devicenet_can = -1;
+static gint ett_devicenet_contents = -1;
+static gint ett_devicenet_8_8 = -1;
+static gint ett_devicenet_8_16 = -1;
+static gint ett_devicenet_16_8 = -1;
+static gint ett_devicenet_16_16 = -1;
+
+static expert_field ei_devicenet_invalid_service = EI_INIT;
+static expert_field ei_devicenet_invalid_can_id = EI_INIT;
+static expert_field ei_devicenet_invalid_msg_id = EI_INIT;
+static expert_field ei_devicenet_frag_not_supported = EI_INIT;
+
+enum node_behavior {
+ NODE_BEHAVIOR_8_8 = 0,
+ NODE_BEHAVIOR_8_16 = 1,
+ NODE_BEHAVIOR_16_8 = 2,
+ NODE_BEHAVIOR_16_16 = 3
+};
+
+/* UAT entry structure. */
+typedef struct {
+ guint mac_id;
+ enum node_behavior behavior;
+
+} uat_devicenet_record_t;
+
+static uat_devicenet_record_t *uat_devicenet_records = NULL;
+static uat_t *devicenet_uat = NULL;
+static guint num_devicenet_records_uat = 0;
+
+static void uat_devicenet_record_update_cb(void* r, const char** err) {
+ uat_devicenet_record_t* rec = (uat_devicenet_record_t *)r;
+
+ if (rec->mac_id > 63)
+ *err = g_strdup_printf("MAC ID must be between 0-63");
+}
+
+UAT_DEC_CB_DEF(uat_devicenet_records, mac_id, uat_devicenet_record_t)
+UAT_VS_DEF(uat_devicenet_records, behavior, uat_devicenet_record_t, enum node_behavior, NODE_BEHAVIOR_8_8, "string")
+
+static const enum_val_t bodytype_devicenet_protocol_options[] = {
+ { "eightovereight", "8/8", 0 },
+ { "eightoversixten", "8/16", 1 },
+ { "sixteenovereight", "16/8", 2 },
+ { "sixteenoversixteen", "16/16", 3 },
+ { NULL, NULL, 0 }
+};
+
+#define SC_OPEN_EXPLICIT_MESSAGE 0x4B
+#define SC_CLOSE_EXPLICIT_MESSAGE 0x4C
+#define SC_DEVICE_HEARTBEAT_MESSAGE 0x4D
+#define SC_DEVICE_SHUTOWN_MESSAGE 0x4E
+
+static const value_string devicenet_service_code_vals[] = {
+ GENERIC_SC_LIST
+
+ { SC_OPEN_EXPLICIT_MESSAGE, "Open Explicit Message Connection Request" },
+ { SC_CLOSE_EXPLICIT_MESSAGE, "Close Connection Request" },
+ { SC_DEVICE_HEARTBEAT_MESSAGE, "Device Heartbeat Message" },
+ { SC_DEVICE_SHUTOWN_MESSAGE, "Device Shutdown Message" },
+ { 0, NULL }
+};
+
+static const value_string devicenet_grp_msg1_vals[] = {
+ { 0x0300, "Slave's I/O Multicast Poll Response" },
+ { 0x0340, "Slave's I/O Change of State or Cyclic Message" },
+ { 0x0380, "Slave's I/O Bit-Strobe Response Message" },
+ { 0x03C0, "Slave's I/O Poll Response or COS/Cyclic Ack Message" },
+ { 0, NULL }
+};
+
+static const value_string devicenet_grp_msg2_vals[] = {
+ { 0x00, "Master's I/O Bit-Strobe Command Message" },
+ { 0x01, "Master's I/O Multicast Poll Group ID" },
+ { 0x02, "Master's Change of State or Cyclic Acknowledge Message" },
+ { 0x03, "Slave's Explicit/Unconnected Response Messages" },
+ { 0x04, "Master's Explicit Request Messages" },
+ { 0x05, "Master's I/O Poll Command/COS/Cyclic Messages" },
+ { 0x06, "Group 2 Only Unconnected Explicit Request Messages" },
+ { 0x07, "Duplicate MAC ID Check Messages" },
+ { 0, NULL }
+};
+
+static const value_string devicenet_grp_msg3_vals[] = {
+ { 0x000, "Group 3 Message" },
+ { 0x040, "Group 3 Message" },
+ { 0x080, "Group 3 Message" },
+ { 0x0C0, "Group 3 Message" },
+ { 0x100, "Group 3 Message" },
+ { 0x140, "Unconnected Explicit Response Message" },
+ { 0x180, "Unconnected Explicit Request Message" },
+ { 0x1C0, "Invalid Group 3 Message" },
+ { 0, NULL }
+};
+
+#define GRP4_COMM_FAULT_RESPONSE 0x2C
+#define GRP4_COMM_FAULT_REQUEST 0x2D
+#define GRP4_OFFLINE_OWNER_RESPONSE 0x2E
+#define GRP4_OFFLINE_OWNER_REQUEST 0x2F
+
+static const value_string devicenet_grp_msg4_vals[] = {
+ { GRP4_COMM_FAULT_RESPONSE, "Communication Faulted Response Message" },
+ { GRP4_COMM_FAULT_REQUEST, "Communication Faulted Request Message" },
+ { GRP4_OFFLINE_OWNER_RESPONSE, "Offline Ownership Response Message" },
+ { GRP4_OFFLINE_OWNER_REQUEST, "Offline Ownership Request Message" },
+ { 0, NULL }
+};
+
+static const value_string devicenet_message_body_format_vals[] = {
+ { 0x00, "DeviceNet 8/8. Class ID = 8 bit integer, Instance ID = 8 bit integer" },
+ { 0x01, "DeviceNet 8/16. Class ID = 8 bit integer, Instance ID = 16 bit integer" },
+ { 0x02, "DeviceNet 16/16. Class ID = 16 bit integer. Instance ID = 16 bit integer" },
+ { 0x03, "DeviceNet 16/8. Class ID = 16 bit integer. Instance ID = 8 bit integer" },
+ { 0x04, "CIP Path. The addressing size is variable and is provided as a Packed EPATH on each request" },
+ { 0x05, "Reserved by DeviceNet" },
+ { 0x06, "Reserved by DeviceNet" },
+ { 0x07, "Reserved by DeviceNet" },
+ { 0x08, "Reserved by DeviceNet" },
+ { 0x09, "Reserved by DeviceNet" },
+ { 0x0A, "Reserved by DeviceNet" },
+ { 0x0B, "Reserved by DeviceNet" },
+ { 0x0C, "Reserved by DeviceNet" },
+ { 0x0D, "Reserved by DeviceNet" },
+ { 0x0E, "Reserved by DeviceNet" },
+ { 0x0F, "Reserved by DeviceNet" },
+ { 0, NULL }
+};
+
+static const value_string devicenet_group_select_vals[] = {
+ { 0x00, "Message Group 1" },
+ { 0x01, "Message Group 2" },
+ { 0x02, "Reserved" },
+ { 0x03, "Message Group 3" },
+ { 0x04, "Reserved by DeviceNet" },
+ { 0x05, "Reserved by DeviceNet" },
+ { 0x06, "Reserved by DeviceNet" },
+ { 0x07, "Reserved by DeviceNet" },
+ { 0x08, "Reserved by DeviceNet" },
+ { 0x09, "Reserved by DeviceNet" },
+ { 0x0A, "Reserved by DeviceNet" },
+ { 0x0B, "Reserved by DeviceNet" },
+ { 0x0C, "Reserved by DeviceNet" },
+ { 0x0D, "Reserved by DeviceNet" },
+ { 0x0E, "Reserved by DeviceNet" },
+ { 0x0F, "Reserved by Node Ping" },
+ { 0, NULL }
+};
+
+static const value_string devicenet_fragmented_message_type_vals[] = {
+ { 0, "First Fragment" },
+ { 0x40, "Middle fragment" },
+ { 0x80, "Last fragment" },
+ { 0xC0, "Fragment Acknowledge" },
+ { 0, NULL }
+};
+
+static const value_string devicenet_io_attribute_vals[] = {
+ {0x01, "Vendor ID"},
+ {0x02, "Device Type"},
+ {0x03, "Product Code"},
+ {0x04, "Revision"},
+ {0x05, "Status"},
+ {0x06, "Serial Number"},
+ {0x07, "Product Name"},
+ { 0, NULL }
+};
+
+static gint body_type_8_over_8_dissection(guint8 data_length, proto_tree *devicenet_tree,
+ tvbuff_t *tvb, packet_info *pinfo, gint offset)
+{
+ proto_item *devicenet_8_8;
+ guint16 class_id, instance, attribute;
+ attribute_info_t* att_info;
+ gint start_offset = offset, length;
+
+ devicenet_8_8 = proto_tree_add_text(devicenet_tree, tvb, offset, -1, "DeviceNet 8/8");
+ devicenet_tree = proto_item_add_subtree(devicenet_8_8, ett_devicenet_8_8);
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_class8, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+ class_id = tvb_get_guint8(tvb, offset);
+ offset++;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_instance8, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+ instance = tvb_get_guint8(tvb, offset);
+
+ offset++;
+ if (data_length > 3)
+ {
+ attribute = tvb_get_guint8(tvb, offset);
+ att_info = cip_get_attribute(class_id, instance, attribute);
+
+ if (att_info != NULL)
+ proto_tree_add_text(devicenet_tree, tvb, offset, 1, "Instance Attribute: %s", att_info->text);
+
+ offset++;
+ }
+
+ if (data_length > 4)
+ {
+ length = offset-start_offset;
+ proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, length,
+ NULL, "%s", tvb_bytes_to_str_punct(tvb, offset, length, ' '));
+ offset += length;
+ }
+ return offset;
+}
+
+static gint body_type_8_over_16_dissection(guint8 data_length, proto_tree *devicenet_tree,
+ tvbuff_t *tvb, packet_info *pinfo, gint offset)
+{
+ proto_item *devicenet_8_16;
+ guint16 class_id, instance, attribute;
+ attribute_info_t* att_info;
+
+ devicenet_8_16 = proto_tree_add_text(devicenet_tree, tvb, offset, -1, "DeviceNet 8/16");
+ devicenet_tree = proto_item_add_subtree(devicenet_8_16, ett_devicenet_8_16);
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_class8, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+ class_id = tvb_get_guint8(tvb, offset);
+ offset++;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_instance16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ instance = tvb_get_letohs(tvb, offset);
+
+ if (data_length > 4)
+ {
+ attribute = tvb_get_guint8(tvb, offset);
+ att_info = cip_get_attribute(class_id, instance, attribute);
+
+ if (att_info != NULL)
+ proto_tree_add_text(devicenet_tree, tvb, offset, 1, "Instance Attribute: %s", att_info->text);
+
+ offset++;
+ }
+
+ return offset;
+}
+
+static gint body_type_16_over_8_dissection(guint8 data_length, proto_tree *devicenet_tree, tvbuff_t *tvb,
+ packet_info *pinfo, gint offset)
+{
+ proto_item *devicenet_16_8;
+ guint16 class_id, instance, attribute;
+ attribute_info_t* att_info;
+
+ devicenet_16_8 = proto_tree_add_text(devicenet_tree, tvb, offset, -1, "DeviceNet 16/8");
+ devicenet_tree = proto_item_add_subtree(devicenet_16_8, ett_devicenet_16_8);
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_class16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ class_id = tvb_get_letohs(tvb, offset);
+ offset += 2;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_instance8, tvb, offset, 1, ENC_LITTLE_ENDIAN);
+ instance = tvb_get_guint8(tvb, offset);
+ offset++;
+
+ if (data_length > 4)
+ {
+ attribute = tvb_get_guint8(tvb, offset);
+ att_info = cip_get_attribute(class_id, instance, attribute);
+
+ if (att_info != NULL)
+ proto_tree_add_text(devicenet_tree, tvb, offset, 1, "Instance Attribute: %s" ,att_info->text);
+
+ offset++;
+ }
+
+ return offset;
+}
+
+static gint body_type_16_over_16_dissection(guint8 data_length, proto_tree *devicenet_tree, tvbuff_t *tvb,
+ packet_info *pinfo, gint offset)
+{
+ proto_item *devicenet_16_16;
+
+ guint16 class_id, instance, attribute;
+ attribute_info_t* att_info;
+
+ devicenet_16_16 = proto_tree_add_text(devicenet_tree, tvb, offset, 4, "DeviceNet 16/16");
+ devicenet_tree = proto_item_add_subtree(devicenet_16_16, ett_devicenet_16_16);
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_class16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ class_id = tvb_get_letohs(tvb, offset);
+ offset += 2;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_instance16, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ instance = tvb_get_letohs(tvb, offset);
+ offset+=2;
+
+ if (data_length > 5)
+ {
+ attribute = tvb_get_guint8(tvb, offset);
+ att_info = cip_get_attribute(class_id, instance, attribute);
+
+ if (att_info != NULL)
+ proto_tree_add_text(devicenet_tree, tvb, offset, 1, "Instance Attribute: %s" ,att_info->text);
+
+ offset++;
+ }
+
+ return offset;
+}
+
+struct can_identifier
+{
+ guint32 id;
+};
+
+static int dissect_devicenet(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
+{
+ proto_item *ti, *can_id_item, *devicenet_contents,
+ *msg_id_item, *service_item;
+ proto_tree *devicenet_tree, *can_tree, *content_tree;
+
+ gint offset = 0;
+ guint16 message_id;
+ guint32 data_length = tvb_reported_length(tvb);
+ guint8 source_mac;
+ struct can_identifier can_id;
+ guint8 service_rr;
+ guint8 *src_address, *dest_address;
+
+ DISSECTOR_ASSERT(data);
+ can_id = *((struct can_identifier*)data);
+
+ if (can_id.id & (~DEVICENET_CANID_MASK))
+ {
+ /* Not for us */
+ return 0;
+ }
+
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "DeviceNet");
+
+ ti = proto_tree_add_item(tree, proto_devicenet, tvb, offset, -1, ENC_NA);
+ devicenet_tree = proto_item_add_subtree(ti, ett_devicenet);
+
+ ti = proto_tree_add_text(devicenet_tree, tvb, 0, 0, "CAN Identifier: 0x%04x", can_id.id);
+ can_tree = proto_item_add_subtree(ti, ett_devicenet_can);
+ can_id_item = proto_tree_add_uint(can_tree, hf_devicenet_can_id, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(can_id_item);
+
+ /*
+ * Message group 1
+ */
+ if ( can_id.id <= MESSAGE_GROUP_1_ID )
+ {
+ ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg1_id, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_id.id & MESSAGE_GROUP_1_MAC_ID_MASK);
+ PROTO_ITEM_SET_GENERATED(ti);
+
+ /* Set source address */
+ src_address = (guint8*)wmem_alloc(pinfo->pool, 1);
+ *src_address = (guint8)(can_id.id & MESSAGE_GROUP_1_MAC_ID_MASK);
+ SET_ADDRESS(&pinfo->src, AT_DEVICENET, 1, (const void*)src_address);
+
+ message_id = can_id.id & MESSAGE_GROUP_1_MSG_MASK;
+ col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg1_vals, "Other Group 1 Message"));
+
+ proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, data_length,
+ NULL, "%s", tvb_bytes_to_str_punct(tvb, offset, data_length, ' '));
+ }
+ /*
+ * Message group 2
+ */
+ else if (can_id.id <= MESSAGE_GROUP_2_ID )
+ {
+ ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg2_id, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+
+ /* create display subtree for the protocol */
+ message_id = can_id.id & MESSAGE_GROUP_2_MSG_MASK;
+ col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg2_vals, "Unknown"));
+
+ ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, (can_id.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3);
+ PROTO_ITEM_SET_GENERATED(ti);
+
+ /* Set source address */
+ src_address = (guint8*)wmem_alloc(pinfo->pool, 1);
+ *src_address = (guint8)((can_id.id & MESSAGE_GROUP_2_MAC_ID_MASK) >> 3);
+ SET_ADDRESS(&pinfo->src, AT_DEVICENET, 1, (const void*)src_address);
+
+ devicenet_contents = proto_tree_add_text(devicenet_tree, tvb, offset, -1, "Contents");
+ content_tree = proto_item_add_subtree(devicenet_contents, ett_devicenet_contents);
+
+ switch (message_id)
+ {
+ case 0x0:
+ case 0x1:
+ case 0x2:
+ case 0x3:
+ case 0x4:
+ case 0x5:
+ proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length,
+ NULL, "%s", tvb_bytes_to_str_punct(tvb, offset, data_length, ' '));
+ break;
+
+ case 0x6:
+ proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length,
+ NULL, "%s", tvb_bytes_to_str_punct(tvb, offset, data_length, ' '));
+ break;
+
+ case 0x7:
+ proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_rr_bit, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_physical_port_number, tvb, offset, 1, ENC_NA);
+ offset ++;
+
+ proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ offset+=2;
+
+ proto_tree_add_item(content_tree, hf_devicenet_dup_mac_id_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+ break;
+ }
+ }
+ /*
+ * Message group 3
+ */
+ else if (can_id.id <= MESSAGE_GROUP_3_ID )
+ {
+ guint8 byte1;
+
+ msg_id_item = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg3_id, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(msg_id_item);
+ ti = proto_tree_add_uint(can_tree, hf_devicenet_src_mac_id, tvb, 0, 0, can_id.id & MESSAGE_GROUP_3_MAC_ID_MASK);
+ PROTO_ITEM_SET_GENERATED(ti);
+
+ /* Set source address */
+ src_address = (guint8*)wmem_alloc(pinfo->pool, 1);
+ *src_address = (guint8)(can_id.id & MESSAGE_GROUP_3_MAC_ID_MASK);
+ SET_ADDRESS(&pinfo->src, AT_DEVICENET, 1, (const void*)src_address);
+
+ message_id = can_id.id & MESSAGE_GROUP_3_MSG_MASK;
+ col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg3_vals, "Unknown"));
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_frag, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_xid, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(devicenet_tree, hf_devicenet_grp_msg3_dest_mac_id, tvb, offset, 1, ENC_NA);
+ byte1 = tvb_get_guint8(tvb, offset);
+ source_mac = byte1 & MESSAGE_GROUP_3_MAC_ID_MASK;
+
+ /* Set destination address */
+ /* XXX - This may be source address depending on message type. Need to adjust accordingly) */
+ dest_address = (guint8*)wmem_alloc(pinfo->pool, 1);
+ *dest_address = (guint8)source_mac;
+ SET_ADDRESS(&pinfo->dst, AT_DEVICENET, 1, (const void*)dest_address);
+ offset++;
+
+ if (byte1 & MESSAGE_GROUP_3_FRAG_MASK)
+ {
+ col_set_str(pinfo->cinfo, COL_INFO, "Group 3 Message Fragment");
+
+ devicenet_contents = proto_tree_add_text(devicenet_tree, tvb, offset, -1, "Fragmentation");
+ content_tree = proto_item_add_subtree(devicenet_contents, ett_devicenet_contents);
+
+ proto_tree_add_item(content_tree, hf_devicenet_fragment_type, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(content_tree, hf_devicenet_fragment_count, tvb, offset, 1, ENC_NA);
+
+ /* TODO: Handle fragmentation */
+ proto_tree_add_expert(content_tree, pinfo, &ei_devicenet_frag_not_supported, tvb, offset, -1);
+
+ col_set_str(pinfo->cinfo, COL_INFO, try_val_to_str((tvb_get_guint8(tvb, offset) & 0xC0) >> 6, devicenet_fragmented_message_type_vals));
+ }
+ else
+ {
+ service_rr = tvb_get_guint8(tvb, offset);
+
+ devicenet_contents = proto_tree_add_text(devicenet_tree, tvb, offset, -1, "Service: %s (%s)",
+ val_to_str_const(service_rr & CIP_SC_MASK, devicenet_service_code_vals, "Unknown"),
+ service_rr & CIP_SC_RESPONSE_MASK ? "Response" : "Request");
+ content_tree = proto_item_add_subtree(devicenet_contents, ett_devicenet_contents);
+
+ proto_tree_add_item(content_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_NA);
+ service_item = proto_tree_add_item(content_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_NA);
+ offset++;
+
+ col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(service_rr & CIP_SC_MASK, devicenet_service_code_vals, "Unknown Service Code"));
+ if (service_rr & CIP_SC_RESPONSE_MASK)
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Response");
+ }
+ else
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Request");
+ }
+
+ switch(message_id)
+ {
+ case 0x140:
+ switch(service_rr & CIP_SC_MASK)
+ {
+ case SC_OPEN_EXPLICIT_MESSAGE:
+ case SC_CLOSE_EXPLICIT_MESSAGE:
+ case SC_DEVICE_HEARTBEAT_MESSAGE:
+ case SC_DEVICE_SHUTOWN_MESSAGE:
+ /* XXX - ERROR RESPONSE? */
+ break;
+ default:
+ expert_add_info_format(pinfo, service_item, &ei_devicenet_invalid_service,
+ "Invalid service code (0x%x) for Group 3 Messsage ID 5", service_rr & CIP_SC_MASK);
+ break;
+ }
+ break;
+ case 0x180:
+ switch(service_rr & CIP_SC_MASK)
+ {
+ case SC_OPEN_EXPLICIT_MESSAGE:
+ case SC_CLOSE_EXPLICIT_MESSAGE:
+ break;
+ default:
+ expert_add_info_format(pinfo, service_item, &ei_devicenet_invalid_service,
+ "Invalid service code (0x%x) for Group 3 Messsage ID 6", service_rr & CIP_SC_MASK);
+ break;
+ }
+ break;
+ break;
+ case 0x1C0:
+ expert_add_info_format(pinfo, msg_id_item, &ei_devicenet_invalid_msg_id,
+ "Invalid Group 3 Messsage ID (%d)", message_id);
+ break;
+ }
+
+ switch(service_rr & CIP_SC_MASK)
+ {
+ case SC_OPEN_EXPLICIT_MESSAGE:
+ /* XXX - Create conversation to track connections */
+ if (service_rr & CIP_SC_RESPONSE_MASK)
+ {
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_reserved, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_actual_body_format, tvb, offset, 1, ENC_NA);
+ offset++;
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_dest_message_id, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_src_message_id, tvb, offset, 1, ENC_NA);
+ offset++;
+ proto_tree_add_item(content_tree, hf_devicenet_connection_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ }
+ else
+ {
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_reserved, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_msg_req_body_format, tvb, offset, 1, ENC_NA);
+ offset++;
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_group_select, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(content_tree, hf_devicenet_open_exp_src_message_id, tvb, offset, 1, ENC_NA);
+ }
+ break;
+ case SC_CLOSE_EXPLICIT_MESSAGE:
+ /* XXX - Use conversation to track connections */
+ if ((service_rr & CIP_SC_RESPONSE_MASK) == 0)
+ {
+ proto_tree_add_item(content_tree, hf_devicenet_connection_id, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ }
+ break;
+ default:
+ if(service_rr & CIP_SC_MASK)
+ {
+ proto_tree_add_bytes_format_value(devicenet_tree, hf_devicenet_data, tvb, offset, data_length - 2,
+ NULL, "%s", tvb_bytes_to_str_punct(tvb, offset, data_length - 2, ' '));
+ }
+ else
+ {
+ guint channel;
+
+ for (channel = 0; channel < num_devicenet_records_uat; channel++)
+ {
+ if (uat_devicenet_records[channel].mac_id == source_mac)
+ {
+ switch(uat_devicenet_records[channel].behavior)
+ {
+ case 0:
+ body_type_8_over_8_dissection(data_length, content_tree, tvb, pinfo, offset);
+ break;
+ case 1:
+ body_type_8_over_16_dissection(data_length, content_tree, tvb, pinfo, offset);
+ break;
+ case 2:
+ body_type_16_over_8_dissection(data_length, content_tree, tvb, pinfo, offset);
+ break;
+ case 3:
+ body_type_16_over_16_dissection(data_length, content_tree, tvb, pinfo, offset);
+ break;
+ default:
+ proto_tree_add_bytes_format_value(content_tree, hf_devicenet_data, tvb, offset, data_length,
+ NULL, "%s", tvb_bytes_to_str_punct(tvb, offset, data_length, ' '));
+ }
+ }
+ break;
+ }
+
+ /* Don't have a behavior defined for this address, default to 8 over 8 */
+ if (channel >= num_devicenet_records_uat)
+ {
+ body_type_8_over_8_dissection(data_length, content_tree, tvb, pinfo, offset);
+ }
+ }
+ break;
+ }
+ }
+ }
+ /*Message group 4*/
+ else if (can_id.id <= MESSAGE_GROUP_4_ID )
+ {
+ ti = proto_tree_add_uint(can_tree, hf_devicenet_grp_msg4_id, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+
+ message_id = can_id.id & MESSAGE_GROUP_4_MSG_MASK;
+ col_set_str(pinfo->cinfo, COL_INFO, val_to_str_const(message_id, devicenet_grp_msg4_vals, "Reserved Group 4 Message"));
+
+ switch(message_id)
+ {
+ case GRP4_COMM_FAULT_RESPONSE:
+ case GRP4_COMM_FAULT_REQUEST:
+ if(data_length == 2)
+ {
+ proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_rsv, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_match, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_value, tvb, offset, 1, ENC_NA);
+ offset++;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(devicenet_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_NA);
+
+ if( tvb_get_guint8(tvb, offset) & CIP_SC_RESPONSE_MASK)
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Response");
+ }
+ else
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Request");
+ }
+ }
+ else if(data_length == 8)
+ {
+ proto_tree_add_item(devicenet_tree, hf_devicenet_comm_fault_rsv, tvb, offset, 1, ENC_NA);
+ offset++;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(devicenet_tree, hf_devicenet_service_code, tvb, offset, 1, ENC_NA);
+
+ if( tvb_get_guint8(tvb, offset) & CIP_SC_RESPONSE_MASK)
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Response");
+ }
+ else
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Request");
+ }
+ offset++;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ offset +=2;
+ proto_tree_add_item(devicenet_tree, hf_devicenet_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+ }
+ break;
+ case GRP4_OFFLINE_OWNER_REQUEST:
+ case GRP4_OFFLINE_OWNER_RESPONSE:
+ proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_reserved, tvb, offset, 1, ENC_NA);
+ proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_client_mac_id, tvb, offset, 1, ENC_NA);
+ offset++;
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_rr_bit, tvb, offset, 1, ENC_NA);
+
+ if( tvb_get_guint8(tvb, offset) & CIP_SC_RESPONSE_MASK)
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Response");
+ }
+ else
+ {
+ col_append_str(pinfo->cinfo, COL_INFO, " - Request");
+ }
+
+ proto_tree_add_item(devicenet_tree, hf_devicenet_offline_ownership_allocate, tvb, offset, 1, ENC_NA);
+ offset++;
+ proto_tree_add_item(devicenet_tree, hf_devicenet_vendor, tvb, offset, 2, ENC_LITTLE_ENDIAN);
+ offset +=2;
+ proto_tree_add_item(devicenet_tree, hf_devicenet_serial_number, tvb, offset, 4, ENC_LITTLE_ENDIAN);
+ break;
+ }
+ }
+ /*Invalid CAN message*/
+ else
+ {
+ col_add_fstr(pinfo->cinfo, COL_INFO, "Invalid CAN Message 0x%06X", can_id.id);
+ expert_add_info_format(pinfo, can_id_item, &ei_devicenet_invalid_can_id,
+ "Invalid CAN Message 0x%04X", can_id.id);
+ }
+
+ return tvb_length(tvb);
+}
+
+void proto_register_devicenet(void)
+{
+ module_t *devicenet_module;
+ expert_module_t*expert_devicenet;
+
+ static hf_register_info hf[] = {
+ { &hf_devicenet_can_id,
+ {"CAN Identifier", "devicenet.can_id",
+ FT_UINT16, BASE_HEX, NULL, DEVICENET_CANID_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_src_mac_id,
+ { "Source MAC ID", "devicenet.src_mac_id",
+ FT_UINT8, BASE_DEC, NULL, 0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_connection_id,
+ { "Connection ID", "devicenet.connection_id",
+ FT_UINT16, BASE_DEC, NULL, 0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_data,
+ { "Data", "devicenet.data",
+ FT_BYTES, BASE_NONE, NULL, 0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_grp_msg1_id,
+ { "Group 1 message ID", "devicenet.grp_msg1.id",
+ FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_1_MSG_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_grp_msg2_id,
+ { "Group 2 message ID", "devicenet.grp_msg2.id",
+ FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_2_MSG_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_grp_msg3_id,
+ { "Group 3 message ID", "devicenet.grp_msg3.id",
+ FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_3_MSG_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_grp_msg3_dest_mac_id,
+ { "Destination MAC ID", "devicenet.dest_mac_id",
+ FT_UINT8, BASE_DEC, NULL, 0x3F,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_grp_msg3_frag,
+ { "Frag", "devicenet.grp_msg3.frag",
+ FT_BOOLEAN, 8, NULL, MESSAGE_GROUP_3_FRAG_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_grp_msg3_xid,
+ { "XID", "devicenet.grp_msg3.xid",
+ FT_BOOLEAN, 8, NULL, MESSAGE_GROUP_3_XID_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_grp_msg4_id,
+ { "Group 4 message ID", "devicenet.grp_msg4.id",
+ FT_UINT16, BASE_DEC, NULL, MESSAGE_GROUP_4_MSG_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_rr_bit,
+ { "Request/Response", "devicenet.rr",
+ FT_UINT8, BASE_DEC, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK,
+ "Request or Response message", HFILL }
+ },
+ { &hf_devicenet_service_code,
+ { "Service Code", "devicenet.service",
+ FT_UINT8, BASE_DEC, &devicenet_service_code_vals, CIP_SC_MASK,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_open_exp_src_message_id,
+ { "Source Message ID", "devicenet.open_message.src_message_id",
+ FT_UINT8, BASE_DEC, NULL, 0x0F,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_open_exp_dest_message_id,
+ { "Destination Message ID", "devicenet.open_message.dest_message_id",
+ FT_UINT8, BASE_DEC, NULL, 0xF0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_open_exp_msg_reserved,
+ { "Reserved", "devicenet.open_message.reserved",
+ FT_UINT8, BASE_DEC, NULL, 0xF0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_open_exp_msg_req_body_format,
+ { "Requested Message Body Format", "devicenet.open_message.req_body_format",
+ FT_UINT8, BASE_DEC, VALS(devicenet_message_body_format_vals), 0x0F,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_open_exp_msg_actual_body_format,
+ { "Actual Message Body Format", "devicenet.open_message.actual_body_format",
+ FT_UINT8, BASE_DEC, VALS(devicenet_message_body_format_vals), 0x0F,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_open_exp_group_select,
+ { "Group Select", "devicenet.open_message.group_select",
+ FT_UINT8, BASE_DEC, VALS(devicenet_group_select_vals), 0xF0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_dup_mac_id_rr_bit,
+ { "Request/Response", "devicenet.dup_mac_id.rr",
+ FT_UINT8, BASE_DEC, VALS(cip_sc_rr), CIP_SC_RESPONSE_MASK,
+ "Duplicate MAC ID Request or Response message", HFILL }
+ },
+ { &hf_devicenet_dup_mac_id_physical_port_number,
+ { "Physical port number", "devicenet.dup_mac_id.physical_port_number",
+ FT_UINT8, BASE_DEC, NULL, 0x7F,
+ "Duplicate MAC ID check message physical port number", HFILL }
+ },
+ { &hf_devicenet_dup_mac_id_vendor,
+ { "Vendor ID", "devicenet.dup_mac_id.vendor",
+ FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_vendor_vals_ext, 0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_dup_mac_id_serial_number,
+ { "Serial Number", "devicenet.dup_mac_id.serial_number",
+ FT_UINT32, BASE_HEX, NULL, 0x00,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_vendor,
+ { "Vendor ID", "devicenet.vendor",
+ FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_vendor_vals_ext, 0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_serial_number,
+ { "Serial Number", "devicenet.serial_number",
+ FT_UINT32, BASE_HEX, NULL, 0x00,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_instance8,
+ { "Instance", "devicenet.instance",
+ FT_UINT8, BASE_HEX, NULL, 0x00,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_instance16,
+ { "Instance", "devicenet.instance",
+ FT_UINT16, BASE_HEX, NULL, 0x00,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_fragment_type,
+ { "Fragment Type", "devicenet.fragment_type",
+ FT_UINT8, BASE_HEX, VALS(devicenet_fragmented_message_type_vals), 0xC0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_fragment_count,
+ { "Fragment Count", "devicenet.fragment_count",
+ FT_UINT8, BASE_HEX_DEC, NULL, 0x3F,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_class8,
+ { "Class", "devicenet.class",
+ FT_UINT8, BASE_HEX|BASE_EXT_STRING, &cip_class_names_vals_ext, 0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_class16,
+ { "Class", "devicenet.class",
+ FT_UINT16, BASE_HEX|BASE_EXT_STRING, &cip_class_names_vals_ext, 0,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_comm_fault_rsv,
+ { "Reserved", "devicenet.comm_fault.reserved",
+ FT_UINT8, BASE_HEX, NULL, 0x80,
+ NULL, HFILL }
+ },
+ { &hf_devicenet_comm_fault_match,
+ { "Match", "devicenet.comm_fault.match",
+ FT_UINT8, BASE_HEX, NULL, 0x40,
+ NULL, HFILL }
+ },
+ {&hf_devicenet_comm_fault_value,
+ { "Value", "devicenet.comm_fault.value",
+ FT_UINT8, BASE_HEX, NULL, 0x3F,
+ "Comm Fault Value", HFILL }
+ },
+ {&hf_devicenet_offline_ownership_reserved,
+ { "Reserved", "devicenet.offline_ownership.reserved",
+ FT_UINT8, BASE_HEX, NULL, 0xC0,
+ "Offline ownership Response Message Reserved", HFILL }
+ },
+ {&hf_devicenet_offline_ownership_client_mac_id,
+ { "Client MAC ID", "devicenet.offline_ownership.client_mac_id",
+ FT_UINT8, BASE_HEX, NULL, MESSAGE_GROUP_4_MSG_MASK,
+ "Offline ownership message client MAC ID", HFILL }
+ },
+ {&hf_devicenet_offline_ownership_allocate,
+ { "Allocate", "devicenet.offline_ownership.allocate",
+ FT_UINT8, BASE_HEX, NULL, CIP_SC_MASK,
+ "Offline ownership response message allocate", HFILL }
+ },
+ };
+
+ static gint *ett[] = {
+ &ett_devicenet,
+ &ett_devicenet_can,
+ &ett_devicenet_contents,
+ &ett_devicenet_8_8,
+ &ett_devicenet_8_16,
+ &ett_devicenet_16_8,
+ &ett_devicenet_16_16
+ };
+
+ static ei_register_info ei[] = {
+ { &ei_devicenet_invalid_service, { "devicenet.invalid_service", PI_PROTOCOL, PI_WARN, "Invalid service", EXPFILL }},
+ { &ei_devicenet_invalid_can_id, { "devicenet.invalid_can_id", PI_PROTOCOL, PI_WARN, "Invalid CAN ID", EXPFILL }},
+ { &ei_devicenet_invalid_msg_id, { "devicenet.invalid_msg_id", PI_PROTOCOL, PI_WARN, "Invalid Message ID", EXPFILL }},
+ { &ei_devicenet_frag_not_supported, { "devicenet.frag_not_supported", PI_UNDECODED, PI_WARN, "Fragmentation not currently supported", EXPFILL }},
+ };
+
+ static uat_field_t devicenet_uat_flds[] = {
+ UAT_FLD_DEC(uat_devicenet_records, mac_id, "Option number", "Custom Option Number"),
+ UAT_FLD_VS(uat_devicenet_records, behavior, "Option type", devicenet_message_body_format_vals, "Option datatype"),
+ UAT_END_FIELDS
+ };
+
+ proto_devicenet = proto_register_protocol("DeviceNet Protocol", "DeviceNet", "devicenet");
+
+ proto_register_field_array(proto_devicenet, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+ expert_devicenet = expert_register_protocol(proto_devicenet);
+ expert_register_field_array(expert_devicenet, ei, array_length(ei));
+
+ new_register_dissector("devicenet", dissect_devicenet, proto_devicenet);
+
+ devicenet_module = prefs_register_protocol(proto_devicenet, NULL);
+
+ devicenet_uat = uat_new("Node bodytypes",
+ sizeof(uat_devicenet_record_t), /* record size */
+ "devicenet_bodytypes", /* filename */
+ TRUE, /* from_profile */
+ (void**) &uat_devicenet_records,/* data_ptr */
+ &num_devicenet_records_uat, /* numitems_ptr */
+ UAT_AFFECTS_DISSECTION, /* affects dissection of packets, but not set of named fields */
+ NULL, /* help */
+ NULL, /* copy callback */
+ uat_devicenet_record_update_cb, /* update callback */
+ NULL, /* free callback */
+ NULL, /* post update callback */
+ devicenet_uat_flds); /* UAT field definitions */
+
+ prefs_register_uat_preference(devicenet_module,
+ "bodytype_table",
+ "Node bodytypes",
+ "Node bodytypes",
+ devicenet_uat);
+}
diff --git a/epan/dissectors/packet-j1939.c b/epan/dissectors/packet-j1939.c
new file mode 100644
index 0000000000..f0fdb5a451
--- /dev/null
+++ b/epan/dissectors/packet-j1939.c
@@ -0,0 +1,321 @@
+/* packet-j1939.c
+ * Routines for dissection of SAE J1939
+ *
+ * Michael Mann
+ * Copyright 2013
+ *
+ * $Id: $
+ *
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+#include "config.h"
+
+#include <glib.h>
+#include <epan/packet.h>
+
+#define J1939_CANID_MASK 0x1FFFFFFF
+#define J1939_11BIT_ID 0x000003FF
+
+static int proto_j1939 = -1;
+
+static int hf_j1939_can_id = -1;
+static int hf_j1939_priority = -1;
+static int hf_j1939_pgn = -1;
+static int hf_j1939_data_page = -1;
+static int hf_j1939_extended_data_page = -1;
+static int hf_j1939_pdu_format = -1;
+static int hf_j1939_pdu_specific = -1;
+static int hf_j1939_src_addr = -1;
+static int hf_j1939_dst_addr = -1;
+static int hf_j1939_group_extension = -1;
+static int hf_j1939_data = -1;
+
+static gint ett_j1939 = -1;
+static gint ett_j1939_can = -1;
+static gint ett_j1939_message = -1;
+
+static dissector_table_t subdissector_pgn_table;
+
+static const value_string j1939_address_vals[] = {
+ {0,"Engine #1"},
+ {1,"Engine #2"},
+ {2,"Turbocharger"},
+ {3,"Transmission #1"},
+ {4,"Transmission #2"},
+ {5,"Shift Console - Primary"},
+ {6,"Shift Console - Secondary"},
+ {7,"Power TakeOff - (Main or Rear)"},
+ {8,"Axle - Steering"},
+ {9,"Axle - Drive #1"},
+ {10,"Axle - Drive #2"},
+ {11,"Brakes - System Controller"},
+ {12,"Brakes - Steer Axle"},
+ {13,"Brakes - Drive axle #1"},
+ {14,"Brakes - Drive Axle #2"},
+ {15,"Retarder - Engine"},
+ {16,"Retarder - Driveline"},
+ {17,"Cruise Control"},
+ {18,"Fuel System"},
+ {19,"Steering Controller"},
+ {20,"Suspension - Steer Axle"},
+ {21,"Suspension - Drive Axle #1"},
+ {22,"Suspension - Drive Axle #2"},
+ {23,"Instrument Cluster #1"},
+ {24,"Trip Recorder"},
+ {25,"Passenger-Operator Climate Control #1"},
+ {26,"Alternator/Electrical Charging System"},
+ {27,"Aerodynamic Control"},
+ {28,"Vehicle Navigation"},
+ {29,"Vehicle Security"},
+ {30,"Electrical System"},
+ {31,"Starter System"},
+ {32,"Tractor-Trailer Bridge #1"},
+ {33,"Body Controller"},
+ {34,"Auxiliary Valve Control or Engine Air System Valve Control"},
+ {35,"Hitch Control"},
+ {36,"Power TakeOff (Front or Secondary)"},
+ {37,"Off Vehicle Gateway"},
+ {38,"Virtual Terminal (in cab)"},
+ {39,"Management Computer #1"},
+ {40,"Cab Display #1"},
+ {41,"Retarder, Exhaust, Engine #1"},
+ {42,"Headway Controller"},
+ {43,"On-Board Diagnostic Unit"},
+ {44,"Retarder, Exhaust, Engine #2"},
+ {45,"Endurance Braking System"},
+ {46,"Hydraulic Pump Controller"},
+ {47,"Suspension - System Controller #1"},
+ {48,"Pneumatic - System Controller"},
+ {49,"Cab Controller - Primary"},
+ {50,"Cab Controller - Secondary"},
+ {51,"Tire Pressure Controller"},
+ {52,"Ignition Control Module #1"},
+ {53,"Ignition Control Module #2"},
+ {54,"Seat Control #1"},
+ {55,"Lighting - Operator Controls"},
+ {56,"Rear Axle Steering Controller #1"},
+ {57,"Water Pump Controller"},
+ {58,"Passenger-Operator Climate Control #2"},
+ {59,"Transmission Display - Primary"},
+ {60,"Transmission Display - Secondary"},
+ {61,"Exhaust Emission Controller"},
+ {62,"Vehicle Dynamic Stability Controller"},
+ {63,"Oil Sensor"},
+ {64,"Suspension - System Controller #2"},
+ {65,"Information System Controller #1"},
+ {66,"Ramp Control"},
+ {67,"Clutch/Converter Unit"},
+ {68,"Auxiliary Heater #1"},
+ {69,"Auxiliary Heater #2"},
+ {70,"Engine Valve Controller"},
+ {71,"Chassis Controller #1"},
+ {72,"Chassis Controller #2"},
+ {73,"Propulsion Battery Charger"},
+ {74,"Communications Unit, Cellular"},
+ {75,"Communications Unit, Satellite"},
+ {76,"Communications Unit, Radio"},
+ {77,"Steering Column Unit"},
+ {78,"Fan Drive Controller"},
+ {79,"Seat Control #2"},
+ {80,"Parking brake controller"},
+ {81,"Aftertreatment #1 system gas intake"},
+ {82,"Aftertreatment #1 system gas outlet"},
+ {83,"Safety Restraint System"},
+ {84,"Cab Display #2"},
+ {85,"Diesel Particulate Filter Controller"},
+ {86,"Aftertreatment #2 system gas intake"},
+ {87,"Aftertreatment #2 system gas outlet"},
+ {88,"Safety Restraint System #2"},
+ {89,"Atmospheric Sensor"},
+ {248,"File Server / Printer"},
+ {249,"Off Board Diagnostic-Service Tool #1"},
+ {250,"Off Board Diagnostic-Service Tool #2"},
+ {251,"On-Board Data Logger"},
+ {252,"Reserved for Experimental Use"},
+ {253,"Reserved for OEM"},
+ {254,"Null Address"},
+ {255,"GLOBAL"},
+ { 0, NULL }
+};
+
+value_string_ext j1939_address_vals_ext = VALUE_STRING_EXT_INIT(j1939_address_vals);
+
+static void
+j1939_fmt_address(gchar *result, guint32 address )
+{
+ if ((address < 128) || (address > 247))
+ g_snprintf(result, ITEM_LABEL_LENGTH, "%d (%s)", address, val_to_str_ext_const(address, &j1939_address_vals_ext, "Reserved"));
+ else
+ g_snprintf(result, ITEM_LABEL_LENGTH, "%d (Arbitrary)", address);
+}
+
+struct can_identifier
+{
+ guint32 id;
+};
+
+static int dissect_j1939(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
+{
+ proto_item *ti, *can_id_item;
+ proto_tree *j1939_tree, *can_tree, *msg_tree;
+
+ gint offset = 0;
+ struct can_identifier can_id;
+ guint32 data_length = tvb_reported_length(tvb);
+ guint32 pgn;
+ guint8 *src_addr, *dest_addr;
+
+ DISSECTOR_ASSERT(data);
+ can_id = *((struct can_identifier*)data);
+
+ if (can_id.id & (~J1939_CANID_MASK))
+ {
+ /* Not for us */
+ return 0;
+ }
+
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "J1939");
+ col_clear(pinfo->cinfo, COL_INFO);
+
+ ti = proto_tree_add_item(tree, proto_j1939, tvb, offset, -1, ENC_NA);
+ j1939_tree = proto_item_add_subtree(ti, ett_j1939);
+
+ ti = proto_tree_add_text(j1939_tree, tvb, 0, 0, "CAN Identifier: 0x%08x", can_id.id);
+ can_tree = proto_item_add_subtree(ti, ett_j1939_can);
+ can_id_item = proto_tree_add_uint(can_tree, hf_j1939_can_id, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(can_id_item);
+
+ ti = proto_tree_add_uint(can_tree, hf_j1939_priority, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_uint(can_tree, hf_j1939_pgn, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_uint(can_tree, hf_j1939_extended_data_page, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_uint(can_tree, hf_j1939_data_page, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_uint(can_tree, hf_j1939_pdu_format, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_uint(can_tree, hf_j1939_pdu_specific, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ ti = proto_tree_add_uint(can_tree, hf_j1939_src_addr, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+
+ /* Set source address */
+ src_addr = (guint8*)wmem_alloc(pinfo->pool, 1);
+ *src_addr = (guint8)(can_id.id & 0xFF);
+ SET_ADDRESS(&pinfo->src, AT_J1939, 1, (const void*)src_addr);
+
+ /* If PF < 240, PS is destination address */
+ if (!(can_id.id & 0x000F00000))
+ {
+ ti = proto_tree_add_uint(can_tree, hf_j1939_dst_addr, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ }
+ else
+ {
+ ti = proto_tree_add_uint(can_tree, hf_j1939_group_extension, tvb, 0, 0, can_id.id);
+ PROTO_ITEM_SET_GENERATED(ti);
+ }
+
+ /* Fill in "destination" address even if its "broadcast" */
+ dest_addr = (guint8*)wmem_alloc(pinfo->pool, 1);
+ *dest_addr = (guint8)((can_id.id & 0xFF00) >> 8);
+ SET_ADDRESS(&pinfo->dst, AT_J1939, 1, (const void*)dest_addr);
+
+ pgn = (can_id.id & 0x3FFFF00) >> 8;
+ col_add_fstr(pinfo->cinfo, COL_INFO, "PGN: %d", pgn);
+
+ /* For now just include raw bytes */
+ col_append_fstr(pinfo->cinfo, COL_INFO, " %s", tvb_bytes_to_str_punct(tvb, 0, data_length, ' '));
+
+
+ ti = proto_tree_add_text(j1939_tree, tvb, 0, -1, "Message");
+ msg_tree = proto_item_add_subtree(ti, ett_j1939_message);
+ if (!dissector_try_uint_new(subdissector_pgn_table, pgn, tvb, pinfo, msg_tree, TRUE, data))
+ {
+ proto_tree_add_item(msg_tree, hf_j1939_data, tvb, 0, -1, ENC_NA);
+ }
+
+ return tvb_length(tvb);
+}
+
+void proto_register_devicenet(void)
+{
+ static hf_register_info hf[] = {
+ { &hf_j1939_can_id,
+ {"CAN Identifier", "j1939.can_id",
+ FT_UINT32, BASE_HEX, NULL, J1939_CANID_MASK, NULL, HFILL }
+ },
+ { &hf_j1939_priority,
+ {"Priority", "j1939.priority",
+ FT_UINT32, BASE_DEC, NULL, 0x1C000000, NULL, HFILL }
+ },
+ { &hf_j1939_pgn,
+ {"PGN", "j1939.pgn",
+ FT_UINT32, BASE_DEC, NULL, 0x03FFFF00, NULL, HFILL }
+ },
+ { &hf_j1939_extended_data_page,
+ {"Extended Data Page", "j1939.ex_data_page",
+ FT_UINT32, BASE_DEC, NULL, 0x02000000, NULL, HFILL }
+ },
+ { &hf_j1939_data_page,
+ {"Data Page", "j1939.data_page",
+ FT_UINT32, BASE_DEC, NULL, 0x01000000, NULL, HFILL }
+ },
+ { &hf_j1939_pdu_format,
+ {"PDU Format", "j1939.pdu_format",
+ FT_UINT32, BASE_DEC, NULL, 0x00FF0000, NULL, HFILL }
+ },
+ { &hf_j1939_pdu_specific,
+ {"PDU Specific", "j1939.pdu_specific",
+ FT_UINT32, BASE_DEC, NULL, 0x0000FF00, NULL, HFILL }
+ },
+ { &hf_j1939_src_addr,
+ {"Source Address", "j1939.src_addr",
+ FT_UINT32, BASE_CUSTOM, j1939_fmt_address, 0x000000FF, NULL, HFILL }
+ },
+ { &hf_j1939_dst_addr,
+ {"Destination Address", "j1939.dst_addr",
+ FT_UINT32, BASE_CUSTOM, j1939_fmt_address, 0x0000FF00, NULL, HFILL }
+ },
+ { &hf_j1939_group_extension,
+ {"Group Extension", "j1939.group_extension",
+ FT_UINT32, BASE_DEC, NULL, 0x0000FF00, NULL, HFILL }
+ },
+ { &hf_j1939_data,
+ {"Data", "j1939.data",
+ FT_BYTES, BASE_NONE, NULL, 0x0, NULL, HFILL }
+ },
+ };
+
+ static gint *ett[] = {
+ &ett_j1939,
+ &ett_j1939_can,
+ &ett_j1939_message
+ };
+
+ proto_j1939 = proto_register_protocol("SAE J1939", "J1939", "j1939");
+
+ proto_register_field_array(proto_j1939, hf, array_length(hf));
+ proto_register_subtree_array(ett, array_length(ett));
+
+ new_register_dissector("j1939", dissect_j1939, proto_j1939);
+
+ subdissector_pgn_table = register_dissector_table("j1939.pgn", "PGN Handle", FT_UINT32, BASE_DEC);
+}
diff --git a/epan/dissectors/packet-socketcan.c b/epan/dissectors/packet-socketcan.c
index 5c4f750d12..941202b096 100644
--- a/epan/dissectors/packet-socketcan.c
+++ b/epan/dissectors/packet-socketcan.c
@@ -59,6 +59,8 @@ static int proto_can = -1;
static dissector_handle_t data_handle;
static dissector_handle_t canopen_handle;
+static dissector_handle_t devicenet_handle;
+static dissector_handle_t j1939_handle;
#define LINUX_CAN_STD 0
#define LINUX_CAN_EXT 1
@@ -71,7 +73,8 @@ static dissector_handle_t canopen_handle;
typedef enum {
CAN_DATA_DISSECTOR = 1,
CAN_CANOPEN_DISSECTOR = 2,
- CAN_DEVICENET_DISSECTOR = 3
+ CAN_DEVICENET_DISSECTOR = 3,
+ CAN_J1939_DISSECTOR = 4,
} Dissector_Option;
/* Structure that gets passed between dissectors. Since it's just a simple 32-bit
@@ -84,9 +87,10 @@ struct can_identifier
};
static const enum_val_t can_high_level_protocol_dissector_options[] = {
- { "raw", "Raw data (no further dissection)", CAN_DATA_DISSECTOR },
+ { "raw", "Raw data (no further dissection)", CAN_DATA_DISSECTOR },
{ "CANopen", "CANopen protocol", CAN_CANOPEN_DISSECTOR },
{ "DeviceNet", "DeviceNet protocol", CAN_DEVICENET_DISSECTOR },
+ { "J1939", "J1939 protocol", CAN_J1939_DISSECTOR },
{ NULL, NULL, 0 }
};
@@ -161,6 +165,16 @@ dissect_socketcan(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
case CAN_CANOPEN_DISSECTOR:
call_dissector_with_data(canopen_handle, next_tvb, pinfo, tree, &can_id);
break;
+ case CAN_DEVICENET_DISSECTOR:
+ /* XXX - Not sure this is correct. But the capture provided in
+ * bug 8564 provides CAN ID in little endian format, so this makes it work */
+ can_id.id = GUINT32_SWAP_LE_BE(can_id.id);
+
+ call_dissector_with_data(devicenet_handle, next_tvb, pinfo, tree, &can_id);
+ break;
+ case CAN_J1939_DISSECTOR:
+ call_dissector_with_data(j1939_handle, next_tvb, pinfo, tree, &can_id);
+ break;
}
}
@@ -254,5 +268,7 @@ proto_reg_handoff_socketcan(void)
dissector_add_uint("sll.ltype", LINUX_SLL_P_CAN, can_handle);
canopen_handle = find_dissector("canopen");
+ devicenet_handle = find_dissector("devicenet");
+ j1939_handle = find_dissector("j1939");
data_handle = find_dissector("data");
}