| Wireshark 4.7.0 The Wireshark network protocol analyzer

Loading...
Searching...
No Matches
packet-socketcan.h
1/* packet-socketcan.h
2 *
3 * Wireshark - Network traffic analyzer
4 * By Gerald Combs <gerald@wireshark.org>
5 * Copyright 1998 Gerald Combs
6 *
7 * SPDX-License-Identifier: GPL-2.0-or-later
8 */
9
10#ifndef __PACKET_SOCKETCAN_H__
11#define __PACKET_SOCKETCAN_H__
12
13#include <epan/tvbuff.h>
14#include <epan/packet_info.h>
15#include <epan/proto.h>
16
17/*
18 * Flags for CAN FD frames.
19 * They are in the FD Flags field of a CAN FD frame.
20 *
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.
25 */
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 */
29
30/*
31 * Flags for CAN XL frames.
32 * They are in the Flags field of a CAN XL frame.
33 *
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.
38 */
39#define CANXL_XLF 0x80 /* XL flag - if set, this is an XL frame */
40#define CANXL_SEC 0x01 /* Simple Extended Content (security/segmentation) */
41#define CANXL_RRS 0x02 /* Remote Request Substitution */
42
43/*
44 * CAN frame type.
45 *
46 * CAN_TYPE_CAN_CLASSIC is 0, and CAN_TYPE_CAN_FD is 1, so that the
47 * fd field behaves, for CAN classic and CAN FD frames, the same way
48 * that it did when it was a bool field that was false for CAN classic
49 * frames and true for CAN FD frames.
50 */
51#define CAN_TYPE_CAN_CLASSIC 0
52#define CAN_TYPE_CAN_FD 1
53#define CAN_TYPE_CAN_XL 2
54
55/* Structure that gets passed between dissectors. */
56 typedef struct can_info {
57 uint32_t id;
58 uint32_t len;
59 unsigned fd;
60 uint16_t bus_id;
61} can_info_t;
62
63/* controller area network (CAN) kernel definitions
64 * These masks are usually defined within <linux/can.h> but are not
65 * available on non-Linux platforms; that's the reason for the
66 * redefinitions below
67 *
68 * special address description flags for the CAN_ID */
69#define CAN_EFF_FLAG 0x80000000 /* EFF/SFF is set in the MSB */
70#define CAN_RTR_FLAG 0x40000000 /* remote transmission request */
71#define CAN_ERR_FLAG 0x20000000 /* error frame */
72
73#define CAN_FLAG_MASK (CAN_EFF_FLAG | CAN_RTR_FLAG | CAN_ERR_FLAG)
74
75#define CAN_EFF_MASK 0x1FFFFFFF /* extended frame format (EFF) has a 29 bit identifier */
76#define CAN_SFF_MASK 0x000007FF /* standard frame format (SFF) has a 11 bit identifier */
77
78#define CAN_ERR_DLC 8 /* dlc for error message frames */
79
80/* error class (mask) in can_id */
81#define CAN_ERR_TX_TIMEOUT 0x00000001U /* TX timeout (by netdevice driver) */
82#define CAN_ERR_LOSTARB 0x00000002U /* lost arbitration / data[0] */
83#define CAN_ERR_CTRL 0x00000004U /* controller problems / data[1] */
84#define CAN_ERR_PROT 0x00000008U /* protocol violations / data[2..3] */
85#define CAN_ERR_TRX 0x00000010U /* transceiver status / data[4] */
86#define CAN_ERR_ACK 0x00000020U /* received no ACK on transmission */
87#define CAN_ERR_BUSOFF 0x00000040U /* bus off */
88#define CAN_ERR_BUSERROR 0x00000080U /* bus error (may flood!) */
89#define CAN_ERR_RESTARTED 0x00000100U /* controller restarted */
90#define CAN_ERR_RESERVED 0x1FFFFE00U /* reserved bits */
91
92/* error in CAN protocol (type) / data[2] */
93#define CAN_ERR_PROT_UNSPEC 0x00 /* unspecified */
94#define CAN_ERR_PROT_BIT 0x01 /* single bit error */
95#define CAN_ERR_PROT_FORM 0x02 /* frame format error */
96#define CAN_ERR_PROT_STUFF 0x04 /* bit stuffing error */
97#define CAN_ERR_PROT_BIT0 0x08 /* unable to send dominant bit */
98#define CAN_ERR_PROT_BIT1 0x10 /* unable to send recessive bit */
99#define CAN_ERR_PROT_OVERLOAD 0x20 /* bus overload */
100#define CAN_ERR_PROT_ACTIVE 0x40 /* active error announcement */
101#define CAN_ERR_PROT_TX 0x80 /* error occurred on transmission */
102
103/* error in CAN protocol (location) / data[3] */
104#define CAN_ERR_PROT_LOC_UNSPEC 0x00 /* unspecified */
105#define CAN_ERR_PROT_LOC_SOF 0x03 /* start of frame */
106#define CAN_ERR_PROT_LOC_ID28_21 0x02 /* ID bits 28 - 21 (SFF: 10 - 3) */
107#define CAN_ERR_PROT_LOC_ID20_18 0x06 /* ID bits 20 - 18 (SFF: 2 - 0 )*/
108#define CAN_ERR_PROT_LOC_SRTR 0x04 /* substitute RTR (SFF: RTR) */
109#define CAN_ERR_PROT_LOC_IDE 0x05 /* identifier extension */
110#define CAN_ERR_PROT_LOC_ID17_13 0x07 /* ID bits 17-13 */
111#define CAN_ERR_PROT_LOC_ID12_05 0x0F /* ID bits 12-5 */
112#define CAN_ERR_PROT_LOC_ID04_00 0x0E /* ID bits 4-0 */
113#define CAN_ERR_PROT_LOC_RTR 0x0C /* RTR */
114#define CAN_ERR_PROT_LOC_RES1 0x0D /* reserved bit 1 */
115#define CAN_ERR_PROT_LOC_RES0 0x09 /* reserved bit 0 */
116#define CAN_ERR_PROT_LOC_DLC 0x0B /* data length code */
117#define CAN_ERR_PROT_LOC_DATA 0x0A /* data section */
118#define CAN_ERR_PROT_LOC_CRC_SEQ 0x08 /* CRC sequence */
119#define CAN_ERR_PROT_LOC_CRC_DEL 0x18 /* CRC delimiter */
120#define CAN_ERR_PROT_LOC_ACK 0x19 /* ACK slot */
121#define CAN_ERR_PROT_LOC_ACK_DEL 0x1B /* ACK delimiter */
122#define CAN_ERR_PROT_LOC_EOF 0x1A /* end of frame */
123#define CAN_ERR_PROT_LOC_INTERM 0x12 /* intermission */
124
125 unsigned can_get_bus_id_from_interface_name(const char* interface_name);
126 bool socketcan_call_subdissectors(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, struct can_info *can_info, const bool use_heuristics_first);
127 bool socketcan_set_source_and_destination_columns(packet_info* pinfo, can_info_t *caninfo);
128
129/*
130 * CAN XL SDU types from CAN CiA 611-1
131 */
132#define CANXL_SDU_TYPE_CONTENT_BASED_ADDRESSING 0x01
133#define CANXL_SDU_TYPE_CAN_CC_CAN_FD 0x03
134#define CANXL_SDU_TYPE_IEEE_802_3 0x04
135#define CANXL_SDU_TYPE_IEEE_802_3_EXTENDED 0x05
136#define CANXL_SDU_TYPE_CAN_CC 0x06
137#define CANXL_SDU_TYPE_CAN_FD 0x07
138#define CANXL_SDU_TYPE_CIA_611_2 0x08
139#define CANXL_SDU_TYPE_AUTOSAR_MPDU 0x09
140#define CANXL_SDU_TYPE_CIA_613_2 0x0A
141
142 static const value_string canxl_sdu_type_vals[] = {
143 { 0x00, "Reserved" },
144 { CANXL_SDU_TYPE_CONTENT_BASED_ADDRESSING, "Content-based Addressing" },
145 { 0x02, "Reserved for future use" },
146 { CANXL_SDU_TYPE_CAN_CC_CAN_FD, "CAN CC/CAN FD" },
147 { CANXL_SDU_TYPE_IEEE_802_3, "IEEE 802.3 (MAC frame)" },
148 { CANXL_SDU_TYPE_IEEE_802_3_EXTENDED, "IEEE 802.3 (MAC frame) extended" },
149 { CANXL_SDU_TYPE_CAN_CC, "CAN CC" },
150 { CANXL_SDU_TYPE_CAN_FD, "CAN FD" },
151 { CANXL_SDU_TYPE_CIA_611_2, "CiA 611-2 (Multi-PDU)" },
152 { CANXL_SDU_TYPE_AUTOSAR_MPDU, "AUTOSAR Multi-PDU" },
153 { CANXL_SDU_TYPE_CIA_613_2, "CiA 613-2 (CANsec key agreement protocol" },
154 { 0xFF, "Reserved" },
155 { 0, NULL }
156};
157
158#endif /* __PACKET_SOCKETCAN_H__ */
159
160/*
161 * Editor modelines - https://www.wireshark.org/tools/modelines.html
162 *
163 * Local variables:
164 * c-basic-offset: 4
165 * tab-width: 8
166 * indent-tabs-mode: nil
167 * End:
168 *
169 * vi: set shiftwidth=4 tabstop=8 expandtab:
170 * :indentSize=4:tabSize=8:noTabs=true:
171 */
packet_info.h
proto.h
_packet_info
Definition packet_info.h:43
_proto_node
Definition proto.h:905
_value_string
Mapping between a 32-bit integer value and its string representation.
Definition value_string.h:33
can_info
Definition packet-socketcan.h:56
tvbuff
Definition tvbuff-int.h:36
tvbuff.h