]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blame - include/uapi/linux/can.h
UBUNTU: Ubuntu-5.11.0-22.23
[mirror_ubuntu-hirsute-kernel.git] / include / uapi / linux / can.h
CommitLineData
3926a3a0 1/* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */
0d66548a
OH
2/*
3 * linux/can.h
4 *
5 * Definitions for CAN network layer (socket addr / CAN frame / CAN filter)
6 *
7 * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
8 * Urs Thuermann <urs.thuermann@volkswagen.de>
9 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
10 * All rights reserved.
11 *
16f6b87a
UKK
12 * Redistribution and use in source and binary forms, with or without
13 * modification, are permitted provided that the following conditions
14 * are met:
15 * 1. Redistributions of source code must retain the above copyright
16 * notice, this list of conditions and the following disclaimer.
17 * 2. Redistributions in binary form must reproduce the above copyright
18 * notice, this list of conditions and the following disclaimer in the
19 * documentation and/or other materials provided with the distribution.
20 * 3. Neither the name of Volkswagen nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
23 *
24 * Alternatively, provided that this notice is retained in full, this
25 * software may be distributed under the terms of the GNU General
26 * Public License ("GPL") version 2, in which case the provisions of the
27 * GPL apply INSTEAD OF those given above.
28 *
29 * The provided data structures and external interfaces from this code
30 * are not restricted to be used by modules with a GPL compatible license.
31 *
32 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
33 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
34 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
35 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
36 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
37 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
38 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
39 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
40 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
41 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
42 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
43 * DAMAGE.
0d66548a
OH
44 */
45
42193e3e
OH
46#ifndef _UAPI_CAN_H
47#define _UAPI_CAN_H
0d66548a
OH
48
49#include <linux/types.h>
50#include <linux/socket.h>
51
52/* controller area network (CAN) kernel definitions */
53
54/* special address description flags for the CAN_ID */
55#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
56#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
d6e640f9 57#define CAN_ERR_FLAG 0x20000000U /* error message frame */
0d66548a
OH
58
59/* valid bits in CAN ID for frame formats */
60#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
61#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
62#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
63
64/*
65 * Controller Area Network Identifier structure
66 *
67 * bit 0-28 : CAN identifier (11/29 bit)
d6e640f9 68 * bit 29 : error message frame flag (0 = data frame, 1 = error message)
0d66548a
OH
69 * bit 30 : remote transmission request flag (1 = rtr frame)
70 * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
71 */
72typedef __u32 canid_t;
73
f057bbb6
RL
74#define CAN_SFF_ID_BITS 11
75#define CAN_EFF_ID_BITS 29
76
0d66548a 77/*
d6e640f9 78 * Controller Area Network Error Message Frame Mask structure
0d66548a 79 *
3570a008 80 * bit 0-28 : error class mask (see include/uapi/linux/can/error.h)
0d66548a
OH
81 * bit 29-31 : set to zero
82 */
83typedef __u32 can_err_mask_t;
84
7c941636
OH
85/* CAN payload length and DLC definitions according to ISO 11898-1 */
86#define CAN_MAX_DLC 8
ea780056 87#define CAN_MAX_RAW_DLC 15
7c941636
OH
88#define CAN_MAX_DLEN 8
89
90/* CAN FD payload length and DLC definitions according to ISO 11898-7 */
91#define CANFD_MAX_DLC 15
92#define CANFD_MAX_DLEN 64
93
0d66548a 94/**
ea780056
OH
95 * struct can_frame - Classical CAN frame structure (aka CAN 2.0B)
96 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
97 * @len: CAN frame payload length in byte (0 .. 8)
98 * @can_dlc: deprecated name for CAN frame payload length in byte (0 .. 8)
99 * @__pad: padding
100 * @__res0: reserved / padding
101 * @len8_dlc: optional DLC value (9 .. 15) at 8 byte payload length
102 * len8_dlc contains values from 9 .. 15 when the payload length is
103 * 8 bytes but the DLC value (see ISO 11898-1) is greater then 8.
104 * CAN_CTRLMODE_CC_LEN8_DLC flag has to be enabled in CAN driver.
105 * @data: CAN frame payload (up to 8 byte)
0d66548a
OH
106 */
107struct can_frame {
108 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
ea780056
OH
109 union {
110 /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN)
111 * was previously named can_dlc so we need to carry that
112 * name for legacy support
113 */
114 __u8 len;
115 __u8 can_dlc; /* deprecated */
08e69778 116 } __attribute__((packed)); /* disable padding added in some ABIs */
ea780056
OH
117 __u8 __pad; /* padding */
118 __u8 __res0; /* reserved / padding */
119 __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */
120 __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8)));
0d66548a
OH
121};
122
7c941636
OH
123/*
124 * defined bits for canfd_frame.flags
125 *
035534ed
OH
126 * The use of struct canfd_frame implies the Extended Data Length (EDL) bit to
127 * be set in the CAN frame bitstream on the wire. The EDL bit switch turns
128 * the CAN controllers bitstream processor into the CAN FD mode which creates
129 * two new options within the CAN FD frame specification:
7c941636 130 *
035534ed
OH
131 * Bit Rate Switch - to indicate a second bitrate is/was used for the payload
132 * Error State Indicator - represents the error state of the transmitting node
133 *
134 * As the CANFD_ESI bit is internally generated by the transmitting CAN
135 * controller only the CANFD_BRS bit is relevant for real CAN controllers when
136 * building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make
137 * sense for virtual CAN interfaces to test applications with echoed frames.
7c941636 138 */
035534ed
OH
139#define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
140#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
7c941636
OH
141
142/**
143 * struct canfd_frame - CAN flexible data rate frame structure
144 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
145 * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN)
146 * @flags: additional flags for CAN FD
147 * @__res0: reserved / padding
148 * @__res1: reserved / padding
149 * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte)
150 */
151struct canfd_frame {
152 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
153 __u8 len; /* frame payload length in byte */
154 __u8 flags; /* additional flags for CAN FD */
155 __u8 __res0; /* reserved / padding */
156 __u8 __res1; /* reserved / padding */
157 __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
158};
159
160#define CAN_MTU (sizeof(struct can_frame))
161#define CANFD_MTU (sizeof(struct canfd_frame))
162
0d66548a
OH
163/* particular protocols of the protocol family PF_CAN */
164#define CAN_RAW 1 /* RAW sockets */
165#define CAN_BCM 2 /* Broadcast Manager */
166#define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
167#define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
168#define CAN_MCNET 5 /* Bosch MCNet */
169#define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
2a0c9aaa
KVD
170#define CAN_J1939 7 /* SAE J1939 */
171#define CAN_NPROTO 8
0d66548a
OH
172
173#define SOL_CAN_BASE 100
174
175/**
176 * struct sockaddr_can - the sockaddr structure for CAN sockets
177 * @can_family: address family number AF_CAN.
178 * @can_ifindex: CAN network interface index.
179 * @can_addr: protocol specific address information
180 */
181struct sockaddr_can {
bcb949b8 182 __kernel_sa_family_t can_family;
0d66548a
OH
183 int can_ifindex;
184 union {
185 /* transport protocol class address information (e.g. ISOTP) */
186 struct { canid_t rx_id, tx_id; } tp;
187
f5223e9e
KVD
188 /* J1939 address information */
189 struct {
190 /* 8 byte name when using dynamic addressing */
191 __u64 name;
192
193 /* pgn:
194 * 8 bit: PS in PDU2 case, else 0
195 * 8 bit: PF
196 * 1 bit: DP
197 * 1 bit: reserved
198 */
199 __u32 pgn;
200
201 /* 1 byte address */
202 __u8 addr;
203 } j1939;
204
0d66548a
OH
205 /* reserved for future CAN protocols address information */
206 } can_addr;
207};
208
209/**
210 * struct can_filter - CAN ID based filter in can_register().
211 * @can_id: relevant bits of CAN ID which are not masked out.
212 * @can_mask: CAN mask (see description)
213 *
214 * Description:
215 * A filter matches, when
216 *
217 * <received_can_id> & mask == can_id & mask
218 *
219 * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
d6e640f9 220 * filter for error message frames (CAN_ERR_FLAG bit set in mask).
0d66548a
OH
221 */
222struct can_filter {
223 canid_t can_id;
224 canid_t can_mask;
225};
226
227#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
332b05ca 228#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
0d66548a 229
42193e3e 230#endif /* !_UAPI_CAN_H */