3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
7 * SPDX-License-Identifier: GPL-2.0-or-later
10 #ifndef __PACKET_SOCKETCAN_H__
11 #define __PACKET_SOCKETCAN_H__
13 #include <epan/tvbuff.h>
14 #include <epan/packet_info.h>
15 #include <epan/proto.h>
18 * Flags for CAN FD frames.
19 * They are in the FD Flags field of a CAN FD frame.
21 * CANFD_FDF is in that field. and always set, as well as being present
22 * but *never* set in what's at the location corresponding to that field
23 * in a CAN classic frame, so we can distinguish between CAN classic and
24 * CAN FD frames by testing that bit.
26 #define CANFD_BRS 0x01 /* Bit Rate Switch (second bitrate for payload data) */
27 #define CANFD_ESI 0x02 /* Error State Indicator of the transmitting node */
28 #define CANFD_FDF 0x04 /* FD flag - if set, this is an FD frame */
31 * Flags for CAN XL frames.
32 * They are in the Flags field of a CAN XL frame.
34 * CANXL_XLF is in that field, and always set. as well as being present
35 * but *never* set in what's the location corresponding to that field
36 * in a CAN classic or CAN FD frame, so we can distinguish between CAN
37 * XL and CAN classic/CAN FD frames by testing that bit.
39 #define CANXL_XLF 0x80 /* XL flag - if set, this is an XL frame */
40 #define CANXL_SEC 0x01 /* Simple Extended Content */
45 * CAN_TYPE_CAN_CLASSIC is 0, and CAN_TYPE_CAN_FD is 1, so that the
46 * fd field behaves, for CAN classic and CAN FD frames, the same way
47 * that it did when it was a bool field that was false for CAN classic
48 * frames and true for CAN FD frames.
50 #define CAN_TYPE_CAN_CLASSIC 0
51 #define CAN_TYPE_CAN_FD 1
52 #define CAN_TYPE_CAN_XL 2
54 /* Structure that gets passed between dissectors. */
55 typedef struct can_info
{
62 /* controller area network (CAN) kernel definitions
63 * These masks are usually defined within <linux/can.h> but are not
64 * available on non-Linux platforms; that's the reason for the
67 * special address description flags for the CAN_ID */
68 #define CAN_EFF_FLAG 0x80000000 /* EFF/SFF is set in the MSB */
69 #define CAN_RTR_FLAG 0x40000000 /* remote transmission request */
70 #define CAN_ERR_FLAG 0x20000000 /* error frame */
72 #define CAN_FLAG_MASK (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_ERR_FLAG)
74 #define CAN_EFF_MASK 0x1FFFFFFF /* extended frame format (EFF) has a 29 bit identifier */
75 #define CAN_SFF_MASK 0x000007FF /* standard frame format (SFF) has a 11 bit identifier */
77 #define CAN_ERR_DLC 8 /* dlc for error message frames */
79 /* error class (mask) in can_id */
80 #define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */
81 #define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */
82 #define CAN_ERR_CTRL 0x00000004U /* controller problems / data[1] */
83 #define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */
84 #define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */
85 #define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */
86 #define CAN_ERR_BUSOFF 0x00000040U /* bus off */
87 #define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
88 #define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
89 #define CAN_ERR_RESERVED 0x1FFFFE00U /* reserved bits */
91 /* error in CAN protocol (type) / data[2] */
92 #define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */
93 #define CAN_ERR_PROT_BIT 0x01 /* single bit error */
94 #define CAN_ERR_PROT_FORM 0x02 /* frame format error */
95 #define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */
96 #define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */
97 #define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */
98 #define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */
99 #define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */
100 #define CAN_ERR_PROT_TX 0x80 /* error occurred on transmission */
102 /* error in CAN protocol (location) / data[3] */
103 #define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */
104 #define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */
105 #define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */
106 #define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/
107 #define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */
108 #define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */
109 #define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */
110 #define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */
111 #define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */
112 #define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */
113 #define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */
114 #define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */
115 #define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */
116 #define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */
117 #define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */
118 #define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */
119 #define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */
120 #define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */
121 #define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */
122 #define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */
124 bool socketcan_call_subdissectors(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, struct can_info
*can_info
, const bool use_heuristics_first
);
125 bool socketcan_set_source_and_destination_columns(packet_info
* pinfo
, can_info_t
*caninfo
);
128 * CAN XL SDU types from CAN CiA 611-1
130 #define CANXL_SDU_TYPE_CONTENT_BASED_ADDRESSING 0x01
131 #define CANXL_SDU_TYPE_CAN_CC_CAN_FD 0x03
132 #define CANXL_SDU_TYPE_IEEE_802_3 0x04
133 #define CANXL_SDU_TYPE_IEEE_802_3_EXTENDED 0x05
134 #define CANXL_SDU_TYPE_CAN_CC 0x06
135 #define CANXL_SDU_TYPE_CAN_FD 0x07
136 #define CANXL_SDU_TYPE_CIA_611_2 0x08
137 #define CANXL_SDU_TYPE_AUTOSAR_MPDU 0x09
138 #define CANXL_SDU_TYPE_CIA_613_2 0x0A
140 #endif /* __PACKET_SOCKETCAN_H__ */
143 * Editor modelines - https://www.wireshark.org/tools/modelines.html
148 * indent-tabs-mode: nil
151 * vi: set shiftwidth=4 tabstop=8 expandtab:
152 * :indentSize=4:tabSize=8:noTabs=true: