xref: /linux/include/uapi/linux/can/isotp.h (revision a1ff5a7d78a036d6c2178ee5acd6ba4946243800)
1e057dd3fSOliver Hartkopp /* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */
2e057dd3fSOliver Hartkopp /*
3e057dd3fSOliver Hartkopp  * linux/can/isotp.h
4e057dd3fSOliver Hartkopp  *
5*ba63a7e0SOliver Hartkopp  * Definitions for ISO 15765-2 CAN transport protocol sockets
6e057dd3fSOliver Hartkopp  *
7e057dd3fSOliver Hartkopp  * Copyright (c) 2020 Volkswagen Group Electronic Research
8e057dd3fSOliver Hartkopp  * All rights reserved.
9e057dd3fSOliver Hartkopp  *
10e057dd3fSOliver Hartkopp  * Redistribution and use in source and binary forms, with or without
11e057dd3fSOliver Hartkopp  * modification, are permitted provided that the following conditions
12e057dd3fSOliver Hartkopp  * are met:
13e057dd3fSOliver Hartkopp  * 1. Redistributions of source code must retain the above copyright
14e057dd3fSOliver Hartkopp  *    notice, this list of conditions and the following disclaimer.
15e057dd3fSOliver Hartkopp  * 2. Redistributions in binary form must reproduce the above copyright
16e057dd3fSOliver Hartkopp  *    notice, this list of conditions and the following disclaimer in the
17e057dd3fSOliver Hartkopp  *    documentation and/or other materials provided with the distribution.
18e057dd3fSOliver Hartkopp  * 3. Neither the name of Volkswagen nor the names of its contributors
19e057dd3fSOliver Hartkopp  *    may be used to endorse or promote products derived from this software
20e057dd3fSOliver Hartkopp  *    without specific prior written permission.
21e057dd3fSOliver Hartkopp  *
22e057dd3fSOliver Hartkopp  * Alternatively, provided that this notice is retained in full, this
23e057dd3fSOliver Hartkopp  * software may be distributed under the terms of the GNU General
24e057dd3fSOliver Hartkopp  * Public License ("GPL") version 2, in which case the provisions of the
25e057dd3fSOliver Hartkopp  * GPL apply INSTEAD OF those given above.
26e057dd3fSOliver Hartkopp  *
27e057dd3fSOliver Hartkopp  * The provided data structures and external interfaces from this code
28e057dd3fSOliver Hartkopp  * are not restricted to be used by modules with a GPL compatible license.
29e057dd3fSOliver Hartkopp  *
30e057dd3fSOliver Hartkopp  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
31e057dd3fSOliver Hartkopp  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
32e057dd3fSOliver Hartkopp  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
33e057dd3fSOliver Hartkopp  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
34e057dd3fSOliver Hartkopp  * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
35e057dd3fSOliver Hartkopp  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
36e057dd3fSOliver Hartkopp  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
37e057dd3fSOliver Hartkopp  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
38e057dd3fSOliver Hartkopp  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
39e057dd3fSOliver Hartkopp  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
40e057dd3fSOliver Hartkopp  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
41e057dd3fSOliver Hartkopp  * DAMAGE.
42e057dd3fSOliver Hartkopp  */
43e057dd3fSOliver Hartkopp 
44e057dd3fSOliver Hartkopp #ifndef _UAPI_CAN_ISOTP_H
45e057dd3fSOliver Hartkopp #define _UAPI_CAN_ISOTP_H
46e057dd3fSOliver Hartkopp 
47e057dd3fSOliver Hartkopp #include <linux/types.h>
48e057dd3fSOliver Hartkopp #include <linux/can.h>
49e057dd3fSOliver Hartkopp 
50e057dd3fSOliver Hartkopp #define SOL_CAN_ISOTP (SOL_CAN_BASE + CAN_ISOTP)
51e057dd3fSOliver Hartkopp 
52e057dd3fSOliver Hartkopp /* for socket options affecting the socket (not the global system) */
53e057dd3fSOliver Hartkopp 
54e057dd3fSOliver Hartkopp #define CAN_ISOTP_OPTS		1	/* pass struct can_isotp_options */
55e057dd3fSOliver Hartkopp 
56e057dd3fSOliver Hartkopp #define CAN_ISOTP_RECV_FC	2	/* pass struct can_isotp_fc_options */
57e057dd3fSOliver Hartkopp 
58e057dd3fSOliver Hartkopp /* sockopts to force stmin timer values for protocol regression tests */
59e057dd3fSOliver Hartkopp 
60e057dd3fSOliver Hartkopp #define CAN_ISOTP_TX_STMIN	3	/* pass __u32 value in nano secs    */
61e057dd3fSOliver Hartkopp 					/* use this time instead of value   */
62e057dd3fSOliver Hartkopp 					/* provided in FC from the receiver */
63e057dd3fSOliver Hartkopp 
64e057dd3fSOliver Hartkopp #define CAN_ISOTP_RX_STMIN	4	/* pass __u32 value in nano secs   */
65e057dd3fSOliver Hartkopp 					/* ignore received CF frames which */
66e057dd3fSOliver Hartkopp 					/* timestamps differ less than val */
67e057dd3fSOliver Hartkopp 
68e057dd3fSOliver Hartkopp #define CAN_ISOTP_LL_OPTS	5	/* pass struct can_isotp_ll_options */
69e057dd3fSOliver Hartkopp 
70e057dd3fSOliver Hartkopp struct can_isotp_options {
71e057dd3fSOliver Hartkopp 
72e057dd3fSOliver Hartkopp 	__u32 flags;		/* set flags for isotp behaviour.	*/
73e057dd3fSOliver Hartkopp 				/* __u32 value : flags see below	*/
74e057dd3fSOliver Hartkopp 
75e057dd3fSOliver Hartkopp 	__u32 frame_txtime;	/* frame transmission time (N_As/N_Ar)	*/
76e057dd3fSOliver Hartkopp 				/* __u32 value : time in nano secs	*/
77e057dd3fSOliver Hartkopp 
78e057dd3fSOliver Hartkopp 	__u8  ext_address;	/* set address for extended addressing	*/
79e057dd3fSOliver Hartkopp 				/* __u8 value : extended address	*/
80e057dd3fSOliver Hartkopp 
81e057dd3fSOliver Hartkopp 	__u8  txpad_content;	/* set content of padding byte (tx)	*/
82e057dd3fSOliver Hartkopp 				/* __u8 value : content	on tx path	*/
83e057dd3fSOliver Hartkopp 
84e057dd3fSOliver Hartkopp 	__u8  rxpad_content;	/* set content of padding byte (rx)	*/
85e057dd3fSOliver Hartkopp 				/* __u8 value : content	on rx path	*/
86e057dd3fSOliver Hartkopp 
87e057dd3fSOliver Hartkopp 	__u8  rx_ext_address;	/* set address for extended addressing	*/
88e057dd3fSOliver Hartkopp 				/* __u8 value : extended address (rx)	*/
89e057dd3fSOliver Hartkopp };
90e057dd3fSOliver Hartkopp 
91e057dd3fSOliver Hartkopp struct can_isotp_fc_options {
92e057dd3fSOliver Hartkopp 
93e057dd3fSOliver Hartkopp 	__u8  bs;		/* blocksize provided in FC frame	*/
94e057dd3fSOliver Hartkopp 				/* __u8 value : blocksize. 0 = off	*/
95e057dd3fSOliver Hartkopp 
96e057dd3fSOliver Hartkopp 	__u8  stmin;		/* separation time provided in FC frame	*/
97e057dd3fSOliver Hartkopp 				/* __u8 value :				*/
98e057dd3fSOliver Hartkopp 				/* 0x00 - 0x7F : 0 - 127 ms		*/
99e057dd3fSOliver Hartkopp 				/* 0x80 - 0xF0 : reserved		*/
100e057dd3fSOliver Hartkopp 				/* 0xF1 - 0xF9 : 100 us - 900 us	*/
101e057dd3fSOliver Hartkopp 				/* 0xFA - 0xFF : reserved		*/
102e057dd3fSOliver Hartkopp 
103e057dd3fSOliver Hartkopp 	__u8  wftmax;		/* max. number of wait frame transmiss.	*/
104e057dd3fSOliver Hartkopp 				/* __u8 value : 0 = omit FC N_PDU WT	*/
105e057dd3fSOliver Hartkopp };
106e057dd3fSOliver Hartkopp 
107e057dd3fSOliver Hartkopp struct can_isotp_ll_options {
108e057dd3fSOliver Hartkopp 
109e057dd3fSOliver Hartkopp 	__u8  mtu;		/* generated & accepted CAN frame type	*/
110e057dd3fSOliver Hartkopp 				/* __u8 value :				*/
111e057dd3fSOliver Hartkopp 				/* CAN_MTU   (16) -> standard CAN 2.0	*/
112e057dd3fSOliver Hartkopp 				/* CANFD_MTU (72) -> CAN FD frame	*/
113e057dd3fSOliver Hartkopp 
114e057dd3fSOliver Hartkopp 	__u8  tx_dl;		/* tx link layer data length in bytes	*/
115e057dd3fSOliver Hartkopp 				/* (configured maximum payload length)	*/
116e057dd3fSOliver Hartkopp 				/* __u8 value : 8,12,16,20,24,32,48,64	*/
117e057dd3fSOliver Hartkopp 				/* => rx path supports all LL_DL values */
118e057dd3fSOliver Hartkopp 
119e057dd3fSOliver Hartkopp 	__u8  tx_flags;		/* set into struct canfd_frame.flags	*/
120e057dd3fSOliver Hartkopp 				/* at frame creation: e.g. CANFD_BRS	*/
121e057dd3fSOliver Hartkopp 				/* Obsolete when the BRS flag is fixed	*/
122e057dd3fSOliver Hartkopp 				/* by the CAN netdriver configuration	*/
123e057dd3fSOliver Hartkopp };
124e057dd3fSOliver Hartkopp 
125e057dd3fSOliver Hartkopp /* flags for isotp behaviour */
126e057dd3fSOliver Hartkopp 
1279f39d365SOliver Hartkopp #define CAN_ISOTP_LISTEN_MODE	0x0001	/* listen only (do not send FC) */
1289f39d365SOliver Hartkopp #define CAN_ISOTP_EXTEND_ADDR	0x0002	/* enable extended addressing */
1299f39d365SOliver Hartkopp #define CAN_ISOTP_TX_PADDING	0x0004	/* enable CAN frame padding tx path */
1309f39d365SOliver Hartkopp #define CAN_ISOTP_RX_PADDING	0x0008	/* enable CAN frame padding rx path */
1319f39d365SOliver Hartkopp #define CAN_ISOTP_CHK_PAD_LEN	0x0010	/* check received CAN frame padding */
1329f39d365SOliver Hartkopp #define CAN_ISOTP_CHK_PAD_DATA	0x0020	/* check received CAN frame padding */
1339f39d365SOliver Hartkopp #define CAN_ISOTP_HALF_DUPLEX	0x0040	/* half duplex error state handling */
1349f39d365SOliver Hartkopp #define CAN_ISOTP_FORCE_TXSTMIN	0x0080	/* ignore stmin from received FC */
1359f39d365SOliver Hartkopp #define CAN_ISOTP_FORCE_RXSTMIN	0x0100	/* ignore CFs depending on rx stmin */
1369f39d365SOliver Hartkopp #define CAN_ISOTP_RX_EXT_ADDR	0x0200	/* different rx extended addressing */
1379f39d365SOliver Hartkopp #define CAN_ISOTP_WAIT_TX_DONE	0x0400	/* wait for tx completion */
1389f39d365SOliver Hartkopp #define CAN_ISOTP_SF_BROADCAST	0x0800	/* 1-to-N functional addressing */
1399f39d365SOliver Hartkopp #define CAN_ISOTP_CF_BROADCAST	0x1000	/* 1-to-N transmission w/o FC */
140e1aa35e1SOliver Hartkopp #define CAN_ISOTP_DYN_FC_PARMS	0x2000	/* dynamic FC parameters BS/STmin */
141e057dd3fSOliver Hartkopp 
142530e0d46SOliver Hartkopp /* protocol machine default values */
143e057dd3fSOliver Hartkopp 
144e057dd3fSOliver Hartkopp #define CAN_ISOTP_DEFAULT_FLAGS		0
145e057dd3fSOliver Hartkopp #define CAN_ISOTP_DEFAULT_EXT_ADDRESS	0x00
146e057dd3fSOliver Hartkopp #define CAN_ISOTP_DEFAULT_PAD_CONTENT	0xCC /* prevent bit-stuffing */
147530e0d46SOliver Hartkopp #define CAN_ISOTP_DEFAULT_FRAME_TXTIME	50000 /* 50 micro seconds */
148e057dd3fSOliver Hartkopp #define CAN_ISOTP_DEFAULT_RECV_BS	0
149e057dd3fSOliver Hartkopp #define CAN_ISOTP_DEFAULT_RECV_STMIN	0x00
150e057dd3fSOliver Hartkopp #define CAN_ISOTP_DEFAULT_RECV_WFTMAX	0
151e057dd3fSOliver Hartkopp 
152e057dd3fSOliver Hartkopp /*
153e057dd3fSOliver Hartkopp  * Remark on CAN_ISOTP_DEFAULT_RECV_* values:
154e057dd3fSOliver Hartkopp  *
155e057dd3fSOliver Hartkopp  * We can strongly assume, that the Linux Kernel implementation of
156e057dd3fSOliver Hartkopp  * CAN_ISOTP is capable to run with BS=0, STmin=0 and WFTmax=0.
157e057dd3fSOliver Hartkopp  * But as we like to be able to behave as a commonly available ECU,
158e057dd3fSOliver Hartkopp  * these default settings can be changed via sockopts.
159e057dd3fSOliver Hartkopp  * For that reason the STmin value is intentionally _not_ checked for
160e057dd3fSOliver Hartkopp  * consistency and copied directly into the flow control (FC) frame.
161e057dd3fSOliver Hartkopp  */
162e057dd3fSOliver Hartkopp 
163530e0d46SOliver Hartkopp /* link layer default values => make use of Classical CAN frames */
164530e0d46SOliver Hartkopp 
165530e0d46SOliver Hartkopp #define CAN_ISOTP_DEFAULT_LL_MTU	CAN_MTU
166530e0d46SOliver Hartkopp #define CAN_ISOTP_DEFAULT_LL_TX_DL	CAN_MAX_DLEN
167530e0d46SOliver Hartkopp #define CAN_ISOTP_DEFAULT_LL_TX_FLAGS	0
168530e0d46SOliver Hartkopp 
169530e0d46SOliver Hartkopp /*
170530e0d46SOliver Hartkopp  * The CAN_ISOTP_DEFAULT_FRAME_TXTIME has become a non-zero value as
171530e0d46SOliver Hartkopp  * it only makes sense for isotp implementation tests to run without
172530e0d46SOliver Hartkopp  * a N_As value. As user space applications usually do not set the
173530e0d46SOliver Hartkopp  * frame_txtime element of struct can_isotp_options the new in-kernel
174530e0d46SOliver Hartkopp  * default is very likely overwritten with zero when the sockopt()
175530e0d46SOliver Hartkopp  * CAN_ISOTP_OPTS is invoked.
176530e0d46SOliver Hartkopp  * To make sure that a N_As value of zero is only set intentional the
177530e0d46SOliver Hartkopp  * value '0' is now interpreted as 'do not change the current value'.
178530e0d46SOliver Hartkopp  * When a frame_txtime of zero is required for testing purposes this
179530e0d46SOliver Hartkopp  * CAN_ISOTP_FRAME_TXTIME_ZERO u32 value has to be set in frame_txtime.
180530e0d46SOliver Hartkopp  */
181530e0d46SOliver Hartkopp #define CAN_ISOTP_FRAME_TXTIME_ZERO	0xFFFFFFFF
182530e0d46SOliver Hartkopp 
183e057dd3fSOliver Hartkopp #endif /* !_UAPI_CAN_ISOTP_H */
184