![]() |
|
|||
0001 /* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */ 0002 /* 0003 * linux/can.h 0004 * 0005 * Definitions for CAN network layer (socket addr / CAN frame / CAN filter) 0006 * 0007 * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de> 0008 * Urs Thuermann <urs.thuermann@volkswagen.de> 0009 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research 0010 * All rights reserved. 0011 * 0012 * Redistribution and use in source and binary forms, with or without 0013 * modification, are permitted provided that the following conditions 0014 * are met: 0015 * 1. Redistributions of source code must retain the above copyright 0016 * notice, this list of conditions and the following disclaimer. 0017 * 2. Redistributions in binary form must reproduce the above copyright 0018 * notice, this list of conditions and the following disclaimer in the 0019 * documentation and/or other materials provided with the distribution. 0020 * 3. Neither the name of Volkswagen nor the names of its contributors 0021 * may be used to endorse or promote products derived from this software 0022 * without specific prior written permission. 0023 * 0024 * Alternatively, provided that this notice is retained in full, this 0025 * software may be distributed under the terms of the GNU General 0026 * Public License ("GPL") version 2, in which case the provisions of the 0027 * GPL apply INSTEAD OF those given above. 0028 * 0029 * The provided data structures and external interfaces from this code 0030 * are not restricted to be used by modules with a GPL compatible license. 0031 * 0032 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0033 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0034 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0035 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0036 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0037 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0038 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0039 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0040 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0041 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0042 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 0043 * DAMAGE. 0044 */ 0045 0046 #ifndef _UAPI_CAN_H 0047 #define _UAPI_CAN_H 0048 0049 #include <linux/types.h> 0050 #include <linux/socket.h> 0051 0052 /* controller area network (CAN) kernel definitions */ 0053 0054 /* special address description flags for the CAN_ID */ 0055 #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */ 0056 #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */ 0057 #define CAN_ERR_FLAG 0x20000000U /* error message frame */ 0058 0059 /* valid bits in CAN ID for frame formats */ 0060 #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */ 0061 #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */ 0062 #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */ 0063 0064 /* 0065 * Controller Area Network Identifier structure 0066 * 0067 * bit 0-28 : CAN identifier (11/29 bit) 0068 * bit 29 : error message frame flag (0 = data frame, 1 = error message) 0069 * bit 30 : remote transmission request flag (1 = rtr frame) 0070 * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit) 0071 */ 0072 typedef __u32 canid_t; 0073 0074 #define CAN_SFF_ID_BITS 11 0075 #define CAN_EFF_ID_BITS 29 0076 0077 /* 0078 * Controller Area Network Error Message Frame Mask structure 0079 * 0080 * bit 0-28 : error class mask (see include/uapi/linux/can/error.h) 0081 * bit 29-31 : set to zero 0082 */ 0083 typedef __u32 can_err_mask_t; 0084 0085 /* CAN payload length and DLC definitions according to ISO 11898-1 */ 0086 #define CAN_MAX_DLC 8 0087 #define CAN_MAX_RAW_DLC 15 0088 #define CAN_MAX_DLEN 8 0089 0090 /* CAN FD payload length and DLC definitions according to ISO 11898-7 */ 0091 #define CANFD_MAX_DLC 15 0092 #define CANFD_MAX_DLEN 64 0093 0094 /** 0095 * struct can_frame - Classical CAN frame structure (aka CAN 2.0B) 0096 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 0097 * @len: CAN frame payload length in byte (0 .. 8) 0098 * @can_dlc: deprecated name for CAN frame payload length in byte (0 .. 8) 0099 * @__pad: padding 0100 * @__res0: reserved / padding 0101 * @len8_dlc: optional DLC value (9 .. 15) at 8 byte payload length 0102 * len8_dlc contains values from 9 .. 15 when the payload length is 0103 * 8 bytes but the DLC value (see ISO 11898-1) is greater then 8. 0104 * CAN_CTRLMODE_CC_LEN8_DLC flag has to be enabled in CAN driver. 0105 * @data: CAN frame payload (up to 8 byte) 0106 */ 0107 struct can_frame { 0108 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 0109 union { 0110 /* CAN frame payload length in byte (0 .. CAN_MAX_DLEN) 0111 * was previously named can_dlc so we need to carry that 0112 * name for legacy support 0113 */ 0114 __u8 len; 0115 __u8 can_dlc; /* deprecated */ 0116 } __attribute__((packed)); /* disable padding added in some ABIs */ 0117 __u8 __pad; /* padding */ 0118 __u8 __res0; /* reserved / padding */ 0119 __u8 len8_dlc; /* optional DLC for 8 byte payload length (9 .. 15) */ 0120 __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8))); 0121 }; 0122 0123 /* 0124 * defined bits for canfd_frame.flags 0125 * 0126 * The use of struct canfd_frame implies the FD Frame (FDF) bit to 0127 * be set in the CAN frame bitstream on the wire. The FDF bit switch turns 0128 * the CAN controllers bitstream processor into the CAN FD mode which creates 0129 * two new options within the CAN FD frame specification: 0130 * 0131 * Bit Rate Switch - to indicate a second bitrate is/was used for the payload 0132 * Error State Indicator - represents the error state of the transmitting node 0133 * 0134 * As the CANFD_ESI bit is internally generated by the transmitting CAN 0135 * controller only the CANFD_BRS bit is relevant for real CAN controllers when 0136 * building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make 0137 * sense for virtual CAN interfaces to test applications with echoed frames. 0138 * 0139 * The struct can_frame and struct canfd_frame intentionally share the same 0140 * layout to be able to write CAN frame content into a CAN FD frame structure. 0141 * When this is done the former differentiation via CAN_MTU / CANFD_MTU gets 0142 * lost. CANFD_FDF allows programmers to mark CAN FD frames in the case of 0143 * using struct canfd_frame for mixed CAN / CAN FD content (dual use). 0144 * N.B. the Kernel APIs do NOT provide mixed CAN / CAN FD content inside of 0145 * struct canfd_frame therefore the CANFD_FDF flag is disregarded by Linux. 0146 */ 0147 #define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */ 0148 #define CANFD_ESI 0x02 /* error state indicator of the transmitting node */ 0149 #define CANFD_FDF 0x04 /* mark CAN FD for dual use of struct canfd_frame */ 0150 0151 /** 0152 * struct canfd_frame - CAN flexible data rate frame structure 0153 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition 0154 * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN) 0155 * @flags: additional flags for CAN FD 0156 * @__res0: reserved / padding 0157 * @__res1: reserved / padding 0158 * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte) 0159 */ 0160 struct canfd_frame { 0161 canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */ 0162 __u8 len; /* frame payload length in byte */ 0163 __u8 flags; /* additional flags for CAN FD */ 0164 __u8 __res0; /* reserved / padding */ 0165 __u8 __res1; /* reserved / padding */ 0166 __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8))); 0167 }; 0168 0169 #define CAN_MTU (sizeof(struct can_frame)) 0170 #define CANFD_MTU (sizeof(struct canfd_frame)) 0171 0172 /* particular protocols of the protocol family PF_CAN */ 0173 #define CAN_RAW 1 /* RAW sockets */ 0174 #define CAN_BCM 2 /* Broadcast Manager */ 0175 #define CAN_TP16 3 /* VAG Transport Protocol v1.6 */ 0176 #define CAN_TP20 4 /* VAG Transport Protocol v2.0 */ 0177 #define CAN_MCNET 5 /* Bosch MCNet */ 0178 #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */ 0179 #define CAN_J1939 7 /* SAE J1939 */ 0180 #define CAN_NPROTO 8 0181 0182 #define SOL_CAN_BASE 100 0183 0184 /** 0185 * struct sockaddr_can - the sockaddr structure for CAN sockets 0186 * @can_family: address family number AF_CAN. 0187 * @can_ifindex: CAN network interface index. 0188 * @can_addr: protocol specific address information 0189 */ 0190 struct sockaddr_can { 0191 __kernel_sa_family_t can_family; 0192 int can_ifindex; 0193 union { 0194 /* transport protocol class address information (e.g. ISOTP) */ 0195 struct { canid_t rx_id, tx_id; } tp; 0196 0197 /* J1939 address information */ 0198 struct { 0199 /* 8 byte name when using dynamic addressing */ 0200 __u64 name; 0201 0202 /* pgn: 0203 * 8 bit: PS in PDU2 case, else 0 0204 * 8 bit: PF 0205 * 1 bit: DP 0206 * 1 bit: reserved 0207 */ 0208 __u32 pgn; 0209 0210 /* 1 byte address */ 0211 __u8 addr; 0212 } j1939; 0213 0214 /* reserved for future CAN protocols address information */ 0215 } can_addr; 0216 }; 0217 0218 /** 0219 * struct can_filter - CAN ID based filter in can_register(). 0220 * @can_id: relevant bits of CAN ID which are not masked out. 0221 * @can_mask: CAN mask (see description) 0222 * 0223 * Description: 0224 * A filter matches, when 0225 * 0226 * <received_can_id> & mask == can_id & mask 0227 * 0228 * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can 0229 * filter for error message frames (CAN_ERR_FLAG bit set in mask). 0230 */ 0231 struct can_filter { 0232 canid_t can_id; 0233 canid_t can_mask; 0234 }; 0235 0236 #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */ 0237 #define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */ 0238 0239 #endif /* !_UAPI_CAN_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |