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