summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-socketcan.c
diff options
context:
space:
mode:
Diffstat (limited to 'epan/dissectors/packet-socketcan.c')
-rw-r--r--epan/dissectors/packet-socketcan.c413
1 files changed, 292 insertions, 121 deletions
diff --git a/epan/dissectors/packet-socketcan.c b/epan/dissectors/packet-socketcan.c
index 90cf2bf..fc450d6 100644
--- a/epan/dissectors/packet-socketcan.c
+++ b/epan/dissectors/packet-socketcan.c
@@ -74,6 +74,13 @@ static int hf_can_err_trx_canl = -1;
static int hf_can_err_ctrl_specific = -1;
+static int hf_canxl_priority = -1;
+static int hf_canxl_vcid = -1;
+static int hf_canxl_secflag = -1;
+static int hf_canxl_sdu_type = -1;
+static int hf_canxl_len = -1;
+static int hf_canxl_acceptance_field = -1;
+
static expert_field ei_can_err_dlc_mismatch = EI_INIT;
static int hf_canfd_brsflag = -1;
@@ -81,9 +88,11 @@ static int hf_canfd_esiflag = -1;
static gint ett_can = -1;
static gint ett_can_fd = -1;
+static gint ett_can_xl = -1;
static int proto_can = -1;
static int proto_canfd = -1;
+static int proto_canxl = -1;
static gboolean byte_swap = FALSE;
static gboolean heuristic_first = FALSE;
@@ -103,11 +112,16 @@ static heur_dtbl_entry_t *heur_dtbl_entry;
#define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
+#define CANXL_LEN_OFFSET 6
+#define CANXL_DATA_OFFSET 12
+
static dissector_table_t can_id_dissector_table = NULL;
static dissector_table_t can_extended_id_dissector_table = NULL;
static dissector_table_t subdissector_table = NULL;
+static dissector_table_t canxl_sdu_type_dissector_table = NULL;
static dissector_handle_t socketcan_classic_handle;
static dissector_handle_t socketcan_fd_handle;
+static dissector_handle_t socketcan_xl_handle;
static dissector_handle_t socketcan_bigendian_handle;
@@ -154,6 +168,19 @@ static const value_string can_err_trx_canl_vals[] = {
{ 0, NULL }
};
+static const value_string canxl_sdu_type_vals[] = {
+ { 0x00, "Reserved" },
+ { CANXL_SDU_TYPE_CONTENT_BASED_ADDRESSING, "Content-based Addressing" },
+ { 0x02, "Reserved for future use" },
+ { CANXL_SDU_TYPE_CLASSICAL_CAN_AND_CAN_FD_MAPPED_TUNNELING, "Classical CAN/CAN FD mapped tunneling" },
+ { CANXL_SDU_TYPE_IEEE_802_3_MAC_FRAME_TUNNELLING, "IEEE 802.3 (MAC frame) tunneling" },
+ { CANXL_SDU_TYPE_IEEE_802_3_MAC_FRAME_MAPPED_TUNNELING, "IEEE 802.3 (MAC frame) mapped tunneling" },
+ { CANXL_SDU_TYPE_CLASSICAL_CAN_MAPPED_TUNNELING, "Classical CAN mapped tunneling" },
+ { CANXL_SDU_TYPE_CAN_FD_MAPPED_TUNNELING, "CAN FD mapped tunneling" },
+ { 0xFF, "Reserved" },
+ { 0, NULL }
+};
+
/********* UATs *********/
/* Interface Config UAT */
@@ -486,45 +513,50 @@ socketcan_call_subdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree
* 2) a given SocketCAN frame is known to contain a CAN FD
* packet based on information outside the SocketCAN header;
*
- * 3) we don't know whether the given SocketCAN frame is a
- * classic CAN packet or a CAN FD packet, and will have
- * to check the CANFD_FDF bit in the "FD flags" field of
- * the SocketCAN header to determine that.
+ * 3) a given SocketCAN frame is known to contain a CAN XL
+ * packet based on information outside the SocketCAN header;
+ *
+ * 4) we don't know whether the given SocketCAN frame is a
+ * classic CAN packet, a CAN FD packet, or a CAN XL packet,
+ * and will have to check the CANXL_XLF bit in the "Frame Length"
+ * field and the CANFD_FDF bit in the "FD flags" field of the
+ * SocketCAN header to determine that.
*/
typedef enum {
PACKET_TYPE_CAN,
PACKET_TYPE_CAN_FD,
+ PACKET_TYPE_CAN_XL,
PACKET_TYPE_UNKNOWN
} can_packet_type_t;
static int
-dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint encoding, can_packet_type_t can_packet_type) {
+dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint encoding, guint xl_encoding, can_packet_type_t can_packet_type) {
proto_tree *can_tree;
proto_item *ti;
guint8 frame_type;
can_info_t can_info;
- int * const *can_flags;
+ int * const *can_flags_id;
- static int * const can_std_flags[] = {
+ static int * const can_std_flags_id[] = {
&hf_can_infoent_std,
&hf_can_extflag,
&hf_can_rtrflag,
&hf_can_errflag,
NULL,
};
- static int * const can_ext_flags[] = {
+ static int * const can_ext_flags_id[] = {
&hf_can_infoent_ext,
&hf_can_extflag,
&hf_can_rtrflag,
&hf_can_errflag,
NULL,
};
- static int * const can_std_flags_fd[] = {
+ static int * const canfd_std_flags_id[] = {
&hf_can_infoent_std,
&hf_can_extflag,
NULL,
};
- static int * const can_ext_flags_fd[] = {
+ static int * const canfd_ext_flags_id[] = {
&hf_can_infoent_ext,
&hf_can_extflag,
NULL,
@@ -548,9 +580,15 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gu
&hf_can_err_reserved,
NULL,
};
-
- can_info.id = tvb_get_guint32(tvb, 0, encoding);
- can_info.len = tvb_get_guint8(tvb, CAN_LEN_OFFSET);
+ static int * const canxl_prio_vcid_fields[] = {
+ &hf_canxl_priority,
+ &hf_canxl_vcid,
+ NULL,
+ };
+ static int * const canxl_flag_fields[] = {
+ &hf_canxl_secflag,
+ NULL,
+ };
/*
* If we weren't told the type of this frame, check
@@ -573,141 +611,236 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gu
* the code is older code that didn't support CAN FD.
*/
if (can_packet_type == PACKET_TYPE_UNKNOWN) {
+ guint8 frame_length;
guint8 fd_flags;
- fd_flags = tvb_get_guint8(tvb, CANFD_FLAG_OFFSET);
-
- if ((fd_flags & CANFD_FDF) && ((fd_flags & ~(CANFD_BRS | CANFD_ESI | CANFD_FDF)) == 0) &&
- tvb_get_guint8(tvb, CANFD_FLAG_OFFSET + 1) == 0 &&
- tvb_get_guint8(tvb, CANFD_FLAG_OFFSET + 2) == 0) {
- can_packet_type = PACKET_TYPE_CAN_FD;
+ /*
+ * Check whether the frame has the CANXL_XLF flag set in what
+ * is in the location of the frame length field of a CAN classic
+ * or CAN FD frame; if so, then it's a CAN XL frame (and that
+ * field is the flags field of that frame).
+ */
+ frame_length = tvb_get_guint8(tvb, CAN_LEN_OFFSET);
+ if (frame_length & CANXL_XLF) {
+ can_packet_type = PACKET_TYPE_CAN_XL;
} else {
- can_packet_type = PACKET_TYPE_CAN;
+ /*
+ * This is a CAN classic or CAN FD frame.
+ * Check whether the flags field has the CANFD_FDF
+ * flag set, has no unknown flag bits set, and has
+ * no bits set in the two reserved fields. If so,
+ * it's a CAN FD frame; otherwise, it's either a
+ * CAN classic frame, or a frame where the CANFD_FDF
+ * flag is set but where that might just be because
+ * that field contains uninitialized junk rather
+ * than because it's a CAN FD frame, so we treat it
+ * as a CAN classic frame.
+ */
+ fd_flags = tvb_get_guint8(tvb, CANFD_FLAG_OFFSET);
+
+ if ((fd_flags & CANFD_FDF) &&
+ ((fd_flags & ~(CANFD_BRS | CANFD_ESI | CANFD_FDF)) == 0) &&
+ tvb_get_guint8(tvb, CANFD_FLAG_OFFSET + 1) == 0 &&
+ tvb_get_guint8(tvb, CANFD_FLAG_OFFSET + 2) == 0) {
+ can_packet_type = PACKET_TYPE_CAN_FD;
+ } else {
+ if (tvb_reported_length(tvb) == 72)
+ can_packet_type = PACKET_TYPE_CAN_FD;
+ else
+ can_packet_type = PACKET_TYPE_CAN;
+ }
}
}
- can_info.fd = (can_packet_type == PACKET_TYPE_CAN_FD);
can_info.bus_id = get_bus_id(pinfo);
- /* Error Message Frames are only encapsulated in Classic CAN frames */
- if (can_packet_type == PACKET_TYPE_CAN && (can_info.id & CAN_ERR_FLAG)) {
- frame_type = LINUX_CAN_ERR;
- can_flags = can_err_flags;
- } else if (can_info.id & CAN_EFF_FLAG) {
- frame_type = LINUX_CAN_EXT;
- can_info.id &= (CAN_EFF_MASK | CAN_FLAG_MASK);
- can_flags = (can_packet_type == PACKET_TYPE_CAN_FD) ? can_ext_flags_fd : can_ext_flags;
- } else {
- frame_type = LINUX_CAN_STD;
- can_info.id &= (CAN_SFF_MASK | CAN_FLAG_MASK);
- can_flags = (can_packet_type == PACKET_TYPE_CAN_FD) ? can_std_flags_fd : can_std_flags;
- }
+ if (can_packet_type == PACKET_TYPE_CAN_XL) {
+ can_info.fd = CAN_TYPE_CAN_XL;
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "CANXL");
+ col_clear(pinfo->cinfo, COL_INFO);
+
+ can_info.id = 0; /* XXX - is there an "ID" for XL frames? */
+
+ ti = proto_tree_add_item(tree, proto_can, tvb, 0, -1, ENC_NA);
+ proto_item_set_hidden(ti);
+ ti = proto_tree_add_item(tree, proto_canxl, tvb, 0, -1, ENC_NA);
+ can_tree = proto_item_add_subtree(ti, ett_can_xl);
+
+ guint32 proto_vcid;
+
+ /*
+ * The priority/VCID field is big-endian in LINKTYPE_CAN_SOCKETCAN
+ * captures, for historical reasons. It's host-endian in
+ * Linux cooked captures. This means we use the non-XL encoding.
+ */
+ proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, canxl_prio_vcid_fields, encoding);
+ proto_vcid = tvb_get_guint32(tvb, 0, encoding);
+ col_add_fstr(pinfo->cinfo, COL_INFO, "Priority: %u (0x%03x), VCID: %u (0x%02X)", proto_vcid & 0x7FF, proto_vcid & 0x7FF, (proto_vcid >> 16) & 0xFF, (proto_vcid >> 16) & 0xFF);
+ proto_item_append_text(can_tree, ", Priority: %u (0x%03x), VCID: %u (0x%02X)", proto_vcid & 0x7FF, proto_vcid & 0x7FF, (proto_vcid >> 16) & 0xFF, (proto_vcid >> 16) & 0xFF);
+ proto_tree_add_bitmask_list(can_tree, tvb, 4, 1, canxl_flag_fields, xl_encoding);
+
+ socketcan_set_source_and_destination_columns(pinfo, &can_info);
+
+ guint32 sdu_type;
+
+ /*
+ * These fields are, if multi-byte, little-endian in
+ * LINKTYPE_CAN_SOCKETCAN captures, so use xl_encoding.
+ */
+ proto_tree_add_item_ret_uint(can_tree, hf_canxl_sdu_type, tvb, 5, 1, ENC_NA, &sdu_type);
+ proto_tree_add_item_ret_uint(can_tree, hf_canxl_len, tvb, CANXL_LEN_OFFSET, 2, xl_encoding, &can_info.len);
+ col_append_fstr(pinfo->cinfo, COL_INFO, ", Length: %u", can_info.len);
+ proto_item_append_text(can_tree, ", Length: %u", can_info.len);
+ proto_tree_add_item(can_tree, hf_canxl_acceptance_field, tvb, CANXL_LEN_OFFSET+2, 4, xl_encoding);
- col_set_str(pinfo->cinfo, COL_PROTOCOL, (can_packet_type == PACKET_TYPE_CAN_FD) ? "CANFD" : "CAN");
- col_clear(pinfo->cinfo, COL_INFO);
+ tvbuff_t *next_tvb;
- guint32 effective_can_id = (can_info.id & CAN_EFF_FLAG) ? can_info.id & CAN_EFF_MASK : can_info.id & CAN_SFF_MASK;
- char *id_name = (can_info.id & CAN_EFF_FLAG) ? "Ext. ID" : "ID";
- col_add_fstr(pinfo->cinfo, COL_INFO, "%s: %d (0x%" PRIx32 "), Length: %d", id_name, effective_can_id, effective_can_id, can_info.len);
+ next_tvb = tvb_new_subset_length(tvb, CANXL_DATA_OFFSET, can_info.len);
- socketcan_set_source_and_destination_columns(pinfo, &can_info);
+ if (!dissector_try_uint_new(canxl_sdu_type_dissector_table, sdu_type, next_tvb, pinfo, tree, TRUE, &can_info)) {
+ call_data_dissector(next_tvb, pinfo, tree);
+ }
- ti = proto_tree_add_item(tree, (can_packet_type == PACKET_TYPE_CAN_FD) ? proto_canfd : proto_can, tvb, 0, -1, ENC_NA);
- can_tree = proto_item_add_subtree(ti, (can_packet_type == PACKET_TYPE_CAN_FD) ? ett_can_fd : ett_can);
+ if (tvb_captured_length_remaining(tvb, CANXL_DATA_OFFSET+can_info.len) > 0) {
+ proto_tree_add_item(can_tree, hf_can_padding, tvb, CANXL_DATA_OFFSET+can_info.len, -1, ENC_NA);
+ }
+ } else {
+ if (can_packet_type == PACKET_TYPE_CAN_FD) {
+ can_info.fd = CAN_TYPE_CAN_FD;
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "CANFD");
+ } else {
+ can_info.fd = CAN_TYPE_CAN_CLASSIC;
+ col_set_str(pinfo->cinfo, COL_PROTOCOL, "CAN");
+ }
+ col_clear(pinfo->cinfo, COL_INFO);
- proto_item_append_text(can_tree, ", %s: %d (0x%" PRIx32 "), Length: %d", id_name, effective_can_id, effective_can_id, can_info.len);
+ ti = proto_tree_add_item(tree, proto_can, tvb, 0, -1, ENC_NA);
+ if (can_packet_type == PACKET_TYPE_CAN_FD) {
+ proto_item_set_hidden(ti);
+ ti = proto_tree_add_item(tree, proto_canfd, tvb, 0, -1, ENC_NA);
+ }
+ can_tree = proto_item_add_subtree(ti, (can_packet_type == PACKET_TYPE_CAN_FD) ? ett_can_fd : ett_can);
+
+ /* Get the ID and flags field */
+ can_info.id = tvb_get_guint32(tvb, 0, encoding);
+
+ /* Error Message Frames are only encapsulated in Classic CAN frames */
+ if (can_packet_type == PACKET_TYPE_CAN && (can_info.id & CAN_ERR_FLAG)) {
+ frame_type = LINUX_CAN_ERR;
+ can_flags_id = can_err_flags;
+ } else if (can_info.id & CAN_EFF_FLAG) {
+ frame_type = LINUX_CAN_EXT;
+ can_info.id &= (CAN_EFF_MASK | CAN_FLAG_MASK);
+ can_flags_id = (can_packet_type == PACKET_TYPE_CAN_FD) ? canfd_ext_flags_id : can_ext_flags_id;
+ } else {
+ frame_type = LINUX_CAN_STD;
+ can_info.id &= (CAN_SFF_MASK | CAN_FLAG_MASK);
+ can_flags_id = (can_packet_type == PACKET_TYPE_CAN_FD) ? canfd_std_flags_id : can_std_flags_id;
+ }
- proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, can_flags, encoding);
- proto_tree_add_item(can_tree, hf_can_len, tvb, CAN_LEN_OFFSET, 1, ENC_NA);
+ socketcan_set_source_and_destination_columns(pinfo, &can_info);
- if (frame_type == LINUX_CAN_ERR && can_info.len != CAN_ERR_DLC) {
- proto_tree_add_expert(tree, pinfo, &ei_can_err_dlc_mismatch, tvb, CAN_LEN_OFFSET, 1);
- }
+ proto_tree_add_bitmask_list(can_tree, tvb, 0, 4, can_flags_id, encoding);
+ if (can_info.id & CAN_EFF_FLAG) {
+ col_add_fstr(pinfo->cinfo, COL_INFO, "Ext. ID: %u (0x%08x)", can_info.id & CAN_EFF_MASK, can_info.id & CAN_EFF_MASK);
+ proto_item_append_text(can_tree, ", Ext. ID: %u (0x%08x)", can_info.id & CAN_EFF_MASK, can_info.id & CAN_EFF_MASK);
+ } else {
+ col_add_fstr(pinfo->cinfo, COL_INFO, "ID: %u (0x%03x)", can_info.id & CAN_SFF_MASK, can_info.id & CAN_SFF_MASK);
+ proto_item_append_text(can_tree, ", ID: %u (0x%03x)", can_info.id & CAN_SFF_MASK, can_info.id & CAN_SFF_MASK);
+ }
+ proto_tree_add_item_ret_uint(can_tree, hf_can_len, tvb, CAN_LEN_OFFSET, 1, ENC_NA, &can_info.len);
+ col_append_fstr(pinfo->cinfo, COL_INFO, ", Length: %u", can_info.len);
+ proto_item_append_text(can_tree, ", Length: %u", can_info.len);
- if (can_packet_type == PACKET_TYPE_CAN_FD) {
- proto_tree_add_bitmask_list(can_tree, tvb, CANFD_FLAG_OFFSET, 1, canfd_flag_fields, ENC_NA);
- proto_tree_add_item(can_tree, hf_can_reserved, tvb, CANFD_FLAG_OFFSET+1, 2, ENC_NA);
- } else {
- proto_tree_add_item(can_tree, hf_can_reserved, tvb, CANFD_FLAG_OFFSET, 3, ENC_NA);
- }
+ if (frame_type == LINUX_CAN_ERR && can_info.len != CAN_ERR_DLC) {
+ proto_tree_add_expert(tree, pinfo, &ei_can_err_dlc_mismatch, tvb, CAN_LEN_OFFSET, 1);
+ }
- if (frame_type == LINUX_CAN_ERR) {
- int * const *flag;
- const char *sepa = ": ";
+ if (can_packet_type == PACKET_TYPE_CAN_FD) {
+ proto_tree_add_bitmask_list(can_tree, tvb, CANFD_FLAG_OFFSET, 1, canfd_flag_fields, ENC_NA);
+ proto_tree_add_item(can_tree, hf_can_reserved, tvb, CANFD_FLAG_OFFSET+1, 2, ENC_NA);
+ } else {
+ proto_tree_add_item(can_tree, hf_can_reserved, tvb, CANFD_FLAG_OFFSET, 3, ENC_NA);
+ }
- col_set_str(pinfo->cinfo, COL_INFO, "ERR");
+ if (frame_type == LINUX_CAN_ERR) {
+ int * const *flag;
+ const char *sepa = ": ";
- for (flag = can_err_flags; *flag; flag++) {
- header_field_info *hfi;
+ col_set_str(pinfo->cinfo, COL_INFO, "ERR");
- hfi = proto_registrar_get_nth(**flag);
- if (!hfi)
- continue;
+ for (flag = can_err_flags; *flag; flag++) {
+ header_field_info *hfi;
- if ((can_info.id & hfi->bitmask & ~CAN_FLAG_MASK) == 0)
- continue;
+ hfi = proto_registrar_get_nth(**flag);
+ if (!hfi)
+ continue;
- col_append_sep_str(pinfo->cinfo, COL_INFO, sepa, hfi->name);
- sepa = ", ";
- }
+ if ((can_info.id & hfi->bitmask & ~CAN_FLAG_MASK) == 0)
+ continue;
- if (can_info.id & CAN_ERR_LOSTARB) {
- proto_tree_add_item(can_tree, hf_can_err_lostarb_bit_number, tvb, CAN_DATA_OFFSET + 0, 1, ENC_NA);
- }
+ col_append_sep_str(pinfo->cinfo, COL_INFO, sepa, hfi->name);
+ sepa = ", ";
+ }
- if (can_info.id & CAN_ERR_CTRL) {
- static int * const can_err_ctrl_flags[] = {
- &hf_can_err_ctrl_rx_overflow,
- &hf_can_err_ctrl_tx_overflow,
- &hf_can_err_ctrl_rx_warning,
- &hf_can_err_ctrl_tx_warning,
- &hf_can_err_ctrl_rx_passive,
- &hf_can_err_ctrl_tx_passive,
- &hf_can_err_ctrl_active,
- NULL,
- };
-
- proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+1, 1, can_err_ctrl_flags, ENC_NA);
- }
+ if (can_info.id & CAN_ERR_LOSTARB) {
+ proto_tree_add_item(can_tree, hf_can_err_lostarb_bit_number, tvb, CAN_DATA_OFFSET + 0, 1, ENC_NA);
+ }
- if (can_info.id & CAN_ERR_PROT) {
- static int * const can_err_prot_error_type_flags[] = {
- &hf_can_err_prot_error_type_bit,
- &hf_can_err_prot_error_type_form,
- &hf_can_err_prot_error_type_stuff,
- &hf_can_err_prot_error_type_bit0,
- &hf_can_err_prot_error_type_bit1,
- &hf_can_err_prot_error_type_overload,
- &hf_can_err_prot_error_type_active,
- &hf_can_err_prot_error_type_tx,
- NULL
- };
- proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+2, 1, can_err_prot_error_type_flags, ENC_NA);
- proto_tree_add_item(can_tree, hf_can_err_prot_error_location, tvb, CAN_DATA_OFFSET+3, 1, ENC_NA);
- }
+ if (can_info.id & CAN_ERR_CTRL) {
+ static int * const can_err_ctrl_flags[] = {
+ &hf_can_err_ctrl_rx_overflow,
+ &hf_can_err_ctrl_tx_overflow,
+ &hf_can_err_ctrl_rx_warning,
+ &hf_can_err_ctrl_tx_warning,
+ &hf_can_err_ctrl_rx_passive,
+ &hf_can_err_ctrl_tx_passive,
+ &hf_can_err_ctrl_active,
+ NULL,
+ };
+
+ proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+1, 1, can_err_ctrl_flags, ENC_NA);
+ }
+
+ if (can_info.id & CAN_ERR_PROT) {
+ static int * const can_err_prot_error_type_flags[] = {
+ &hf_can_err_prot_error_type_bit,
+ &hf_can_err_prot_error_type_form,
+ &hf_can_err_prot_error_type_stuff,
+ &hf_can_err_prot_error_type_bit0,
+ &hf_can_err_prot_error_type_bit1,
+ &hf_can_err_prot_error_type_overload,
+ &hf_can_err_prot_error_type_active,
+ &hf_can_err_prot_error_type_tx,
+ NULL
+ };
+ proto_tree_add_bitmask_list(can_tree, tvb, CAN_DATA_OFFSET+2, 1, can_err_prot_error_type_flags, ENC_NA);
+ proto_tree_add_item(can_tree, hf_can_err_prot_error_location, tvb, CAN_DATA_OFFSET+3, 1, ENC_NA);
+ }
- if (can_info.id & CAN_ERR_TRX) {
- proto_tree_add_item(can_tree, hf_can_err_trx_canh, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA);
- proto_tree_add_item(can_tree, hf_can_err_trx_canl, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA);
- }
+ if (can_info.id & CAN_ERR_TRX) {
+ proto_tree_add_item(can_tree, hf_can_err_trx_canh, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA);
+ proto_tree_add_item(can_tree, hf_can_err_trx_canl, tvb, CAN_DATA_OFFSET+4, 1, ENC_NA);
+ }
- proto_tree_add_item(can_tree, hf_can_err_ctrl_specific, tvb, CAN_DATA_OFFSET+5, 3, ENC_NA);
- } else {
- tvbuff_t *next_tvb;
+ proto_tree_add_item(can_tree, hf_can_err_ctrl_specific, tvb, CAN_DATA_OFFSET+5, 3, ENC_NA);
+ } else {
+ tvbuff_t *next_tvb;
- if (can_info.id & CAN_RTR_FLAG) {
- col_append_str(pinfo->cinfo, COL_INFO, "(Remote Transmission Request)");
- }
+ if (can_info.id & CAN_RTR_FLAG) {
+ col_append_str(pinfo->cinfo, COL_INFO, "(Remote Transmission Request)");
+ }
- next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, can_info.len);
+ next_tvb = tvb_new_subset_length(tvb, CAN_DATA_OFFSET, can_info.len);
- if (!socketcan_call_subdissectors(next_tvb, pinfo, tree, &can_info, heuristic_first)) {
- call_data_dissector(next_tvb, pinfo, tree);
+ if (!socketcan_call_subdissectors(next_tvb, pinfo, tree, &can_info, heuristic_first)) {
+ call_data_dissector(next_tvb, pinfo, tree);
+ }
}
- }
- if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET+can_info.len) > 0) {
- proto_tree_add_item(can_tree, hf_can_padding, tvb, CAN_DATA_OFFSET+can_info.len, -1, ENC_NA);
+ if (tvb_captured_length_remaining(tvb, CAN_DATA_OFFSET+can_info.len) > 0) {
+ proto_tree_add_item(can_tree, hf_can_padding, tvb, CAN_DATA_OFFSET+can_info.len, -1, ENC_NA);
+ }
}
return tvb_captured_length(tvb);
@@ -716,19 +849,33 @@ dissect_socketcan_common(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, gu
static int
dissect_socketcan_bigendian(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
return dissect_socketcan_common(tvb, pinfo, tree,
- byte_swap ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN, PACKET_TYPE_UNKNOWN);
+ byte_swap ? ENC_LITTLE_ENDIAN : ENC_BIG_ENDIAN,
+ ENC_LITTLE_ENDIAN,
+ PACKET_TYPE_UNKNOWN);
}
static int
dissect_socketcan_classic(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
return dissect_socketcan_common(tvb, pinfo, tree,
- byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN, PACKET_TYPE_CAN);
+ byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN,
+ ENC_HOST_ENDIAN, /* Not used, as this is CAN classic, not CAN XL */
+ PACKET_TYPE_CAN);
}
static int
dissect_socketcan_fd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
return dissect_socketcan_common(tvb, pinfo, tree,
- byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN, PACKET_TYPE_CAN_FD);
+ byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN,
+ ENC_HOST_ENDIAN, /* Not used, as this is CAN FD, not CAN XL */
+ PACKET_TYPE_CAN_FD);
+}
+
+static int
+dissect_socketcan_xl(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
+ return dissect_socketcan_common(tvb, pinfo, tree,
+ byte_swap ? ENC_ANTI_HOST_ENDIAN : ENC_HOST_ENDIAN,
+ ENC_HOST_ENDIAN,
+ PACKET_TYPE_CAN_XL);
}
void
@@ -814,6 +961,18 @@ proto_register_socketcan(void) {
"Transceiver CANL status", "can.err.trx.canl", FT_UINT8, BASE_DEC, VALS(can_err_trx_canl_vals), 0xF0, NULL, HFILL } },
{ &hf_can_err_ctrl_specific, {
"Controller specific data", "can.err.ctrl_specific", FT_BYTES, SEP_SPACE, NULL, 0, NULL, HFILL } },
+ { &hf_canxl_priority, {
+ "Priority", "canxl.priority", FT_UINT32, BASE_DEC, NULL, 0x0000FFFF, NULL, HFILL } },
+ { &hf_canxl_vcid, {
+ "VCID", "canxl.vcid", FT_UINT32, BASE_DEC, NULL, 0x00FF0000, NULL, HFILL } },
+ { &hf_canxl_secflag, {
+ "Simple Extended Context", "canxl.flags.sec", FT_BOOLEAN, 8, NULL, CANXL_SEC, NULL, HFILL } },
+ { &hf_canxl_sdu_type, {
+ "SDU type", "canxl.sdu_type", FT_UINT8, BASE_HEX, VALS(canxl_sdu_type_vals), 0, NULL, HFILL } },
+ { &hf_canxl_len, {
+ "Frame-Length", "canxl.len", FT_UINT16, BASE_DEC, NULL, 0x0, NULL, HFILL } },
+ { &hf_canxl_acceptance_field, {
+ "Acceptance field", "canxl.acceptance_field", FT_UINT32, BASE_DEC_HEX, NULL, 0, NULL, HFILL } },
};
uat_t *can_interface_uat = NULL;
@@ -822,7 +981,8 @@ proto_register_socketcan(void) {
/* Setup protocol subtree array */
static gint *ett[] = {
&ett_can,
- &ett_can_fd
+ &ett_can_fd,
+ &ett_can_xl
};
static ei_register_info ei[] = {
@@ -841,6 +1001,11 @@ proto_register_socketcan(void) {
* or Busmaster capture that was saved as a pcap or pcapng file,
* as those use a linktype of LINKTYPE_WIRESHARK_UPPER_PDU with
* "can-hostendian" as the dissector name.
+ *
+ * "can-bigendian" is also a legacy name (fpr CAN XL frames, the
+ * fields in the header are in *little-endian* order); we keep it
+ * around for the same reason. It's used for the dissector for
+ * LINKTYPE_CAN_SOCKETCAN.
*/
socketcan_classic_handle = register_dissector("can-hostendian", dissect_socketcan_classic, proto_can);
socketcan_bigendian_handle = register_dissector("can-bigendian", dissect_socketcan_bigendian, proto_can);
@@ -848,6 +1013,9 @@ proto_register_socketcan(void) {
proto_canfd = proto_register_protocol("Controller Area Network FD", "CANFD", "canfd");
socketcan_fd_handle = register_dissector("canfd", dissect_socketcan_fd, proto_canfd);
+ proto_canxl = proto_register_protocol("Controller Area Network XL", "CANXL", "canxl");
+ socketcan_xl_handle = register_dissector("canxl", dissect_socketcan_xl, proto_canxl);
+
proto_register_field_array(proto_can, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
@@ -858,7 +1026,7 @@ proto_register_socketcan(void) {
prefs_register_obsolete_preference(can_module, "protocol");
prefs_register_bool_preference(can_module, "byte_swap", "Byte-swap the CAN ID/flags field",
- "Whether the CAN ID/flags field should be byte-swapped",
+ "Whether the CAN ID/flags field should be byte-swapped in CAN classic and CAN FD packets",
&byte_swap);
prefs_register_bool_preference(can_module, "try_heuristic_first", "Try heuristic sub-dissectors first",
@@ -871,6 +1039,8 @@ proto_register_socketcan(void) {
subdissector_table = register_decode_as_next_proto(proto_can, "can.subdissector", "CAN next level dissector", NULL);
+ canxl_sdu_type_dissector_table = register_dissector_table("canxl.sdu_type", "CAN XL SDU type", proto_canxl, FT_UINT8, BASE_HEX);
+
heur_subdissector_list = register_heur_dissector_list("can", proto_can);
static uat_field_t can_interface_mapping_uat_fields[] = {
@@ -933,6 +1103,7 @@ proto_reg_handoff_socketcan(void) {
dissector_add_uint("sll.ltype", LINUX_SLL_P_CAN, socketcan_classic_handle);
dissector_add_uint("sll.ltype", LINUX_SLL_P_CANFD, socketcan_fd_handle);
+ dissector_add_uint("sll.ltype", LINUX_SLL_P_CANXL, socketcan_xl_handle);
}
/*