![]() |
|
|||
0001 /* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */ 0002 /* 0003 * linux/can/gw.h 0004 * 0005 * Definitions for CAN frame Gateway/Router/Bridge 0006 * 0007 * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de> 0008 * Copyright (c) 2011 Volkswagen Group Electronic Research 0009 * All rights reserved. 0010 * 0011 * Redistribution and use in source and binary forms, with or without 0012 * modification, are permitted provided that the following conditions 0013 * are met: 0014 * 1. Redistributions of source code must retain the above copyright 0015 * notice, this list of conditions and the following disclaimer. 0016 * 2. Redistributions in binary form must reproduce the above copyright 0017 * notice, this list of conditions and the following disclaimer in the 0018 * documentation and/or other materials provided with the distribution. 0019 * 3. Neither the name of Volkswagen nor the names of its contributors 0020 * may be used to endorse or promote products derived from this software 0021 * without specific prior written permission. 0022 * 0023 * Alternatively, provided that this notice is retained in full, this 0024 * software may be distributed under the terms of the GNU General 0025 * Public License ("GPL") version 2, in which case the provisions of the 0026 * GPL apply INSTEAD OF those given above. 0027 * 0028 * The provided data structures and external interfaces from this code 0029 * are not restricted to be used by modules with a GPL compatible license. 0030 * 0031 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 0032 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 0033 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 0034 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 0035 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 0036 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 0037 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 0038 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 0039 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 0040 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 0041 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH 0042 * DAMAGE. 0043 */ 0044 0045 #ifndef _UAPI_CAN_GW_H 0046 #define _UAPI_CAN_GW_H 0047 0048 #include <linux/types.h> 0049 #include <linux/can.h> 0050 0051 struct rtcanmsg { 0052 __u8 can_family; 0053 __u8 gwtype; 0054 __u16 flags; 0055 }; 0056 0057 /* CAN gateway types */ 0058 enum { 0059 CGW_TYPE_UNSPEC, 0060 CGW_TYPE_CAN_CAN, /* CAN->CAN routing */ 0061 __CGW_TYPE_MAX 0062 }; 0063 0064 #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1) 0065 0066 /* CAN rtnetlink attribute definitions */ 0067 enum { 0068 CGW_UNSPEC, 0069 CGW_MOD_AND, /* CAN frame modification binary AND */ 0070 CGW_MOD_OR, /* CAN frame modification binary OR */ 0071 CGW_MOD_XOR, /* CAN frame modification binary XOR */ 0072 CGW_MOD_SET, /* CAN frame modification set alternate values */ 0073 CGW_CS_XOR, /* set data[] XOR checksum into data[index] */ 0074 CGW_CS_CRC8, /* set data[] CRC8 checksum into data[index] */ 0075 CGW_HANDLED, /* number of handled CAN frames */ 0076 CGW_DROPPED, /* number of dropped CAN frames */ 0077 CGW_SRC_IF, /* ifindex of source network interface */ 0078 CGW_DST_IF, /* ifindex of destination network interface */ 0079 CGW_FILTER, /* specify struct can_filter on source CAN device */ 0080 CGW_DELETED, /* number of deleted CAN frames (see max_hops param) */ 0081 CGW_LIM_HOPS, /* limit the number of hops of this specific rule */ 0082 CGW_MOD_UID, /* user defined identifier for modification updates */ 0083 CGW_FDMOD_AND, /* CAN FD frame modification binary AND */ 0084 CGW_FDMOD_OR, /* CAN FD frame modification binary OR */ 0085 CGW_FDMOD_XOR, /* CAN FD frame modification binary XOR */ 0086 CGW_FDMOD_SET, /* CAN FD frame modification set alternate values */ 0087 __CGW_MAX 0088 }; 0089 0090 #define CGW_MAX (__CGW_MAX - 1) 0091 0092 #define CGW_FLAGS_CAN_ECHO 0x01 0093 #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02 0094 #define CGW_FLAGS_CAN_IIF_TX_OK 0x04 0095 #define CGW_FLAGS_CAN_FD 0x08 0096 0097 #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */ 0098 0099 /* CAN frame elements that are affected by curr. 3 CAN frame modifications */ 0100 #define CGW_MOD_ID 0x01 0101 #define CGW_MOD_DLC 0x02 /* Classical CAN data length code */ 0102 #define CGW_MOD_LEN CGW_MOD_DLC /* CAN FD (plain) data length */ 0103 #define CGW_MOD_DATA 0x04 0104 #define CGW_MOD_FLAGS 0x08 /* CAN FD flags */ 0105 0106 #define CGW_FRAME_MODS 4 /* ID DLC/LEN DATA FLAGS */ 0107 0108 #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS) 0109 0110 struct cgw_frame_mod { 0111 struct can_frame cf; 0112 __u8 modtype; 0113 } __attribute__((packed)); 0114 0115 struct cgw_fdframe_mod { 0116 struct canfd_frame cf; 0117 __u8 modtype; 0118 } __attribute__((packed)); 0119 0120 #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod) 0121 #define CGW_FDMODATTR_LEN sizeof(struct cgw_fdframe_mod) 0122 0123 struct cgw_csum_xor { 0124 __s8 from_idx; 0125 __s8 to_idx; 0126 __s8 result_idx; 0127 __u8 init_xor_val; 0128 } __attribute__((packed)); 0129 0130 struct cgw_csum_crc8 { 0131 __s8 from_idx; 0132 __s8 to_idx; 0133 __s8 result_idx; 0134 __u8 init_crc_val; 0135 __u8 final_xor_val; 0136 __u8 crctab[256]; 0137 __u8 profile; 0138 __u8 profile_data[20]; 0139 } __attribute__((packed)); 0140 0141 /* length of checksum operation parameters. idx = index in CAN frame data[] */ 0142 #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor) 0143 #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8) 0144 0145 /* CRC8 profiles (compute CRC for additional data elements - see below) */ 0146 enum { 0147 CGW_CRC8PRF_UNSPEC, 0148 CGW_CRC8PRF_1U8, /* compute one additional u8 value */ 0149 CGW_CRC8PRF_16U8, /* u8 value table indexed by data[1] & 0xF */ 0150 CGW_CRC8PRF_SFFID_XOR, /* (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) */ 0151 __CGW_CRC8PRF_MAX 0152 }; 0153 0154 #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1) 0155 0156 /* 0157 * CAN rtnetlink attribute contents in detail 0158 * 0159 * CGW_XXX_IF (length 4 bytes): 0160 * Sets an interface index for source/destination network interfaces. 0161 * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory. 0162 * 0163 * CGW_FILTER (length 8 bytes): 0164 * Sets a CAN receive filter for the gateway job specified by the 0165 * struct can_filter described in include/linux/can.h 0166 * 0167 * CGW_MOD_(AND|OR|XOR|SET) (length 17 bytes): 0168 * Specifies a modification that's done to a received CAN frame before it is 0169 * send out to the destination interface. 0170 * 0171 * <struct can_frame> data used as operator 0172 * <u8> affected CAN frame elements 0173 * 0174 * CGW_LIM_HOPS (length 1 byte): 0175 * Limit the number of hops of this specific rule. Usually the received CAN 0176 * frame can be processed as much as 'max_hops' times (which is given at module 0177 * load time of the can-gw module). This value is used to reduce the number of 0178 * possible hops for this gateway rule to a value smaller then max_hops. 0179 * 0180 * CGW_MOD_UID (length 4 bytes): 0181 * Optional non-zero user defined routing job identifier to alter existing 0182 * modification settings at runtime. 0183 * 0184 * CGW_CS_XOR (length 4 bytes): 0185 * Set a simple XOR checksum starting with an initial value into 0186 * data[result-idx] using data[start-idx] .. data[end-idx] 0187 * 0188 * The XOR checksum is calculated like this: 0189 * 0190 * xor = init_xor_val 0191 * 0192 * for (i = from_idx .. to_idx) 0193 * xor ^= can_frame.data[i] 0194 * 0195 * can_frame.data[ result_idx ] = xor 0196 * 0197 * CGW_CS_CRC8 (length 282 bytes): 0198 * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table, 0199 * a given initial value and a defined input data[start-idx] .. data[end-idx]. 0200 * Finally the result value is XOR'ed with the final_xor_val. 0201 * 0202 * The CRC8 checksum is calculated like this: 0203 * 0204 * crc = init_crc_val 0205 * 0206 * for (i = from_idx .. to_idx) 0207 * crc = crctab[ crc ^ can_frame.data[i] ] 0208 * 0209 * can_frame.data[ result_idx ] = crc ^ final_xor_val 0210 * 0211 * The calculated CRC may contain additional source data elements that can be 0212 * defined in the handling of 'checksum profiles' e.g. shown in AUTOSAR specs 0213 * like http://www.autosar.org/download/R4.0/AUTOSAR_SWS_E2ELibrary.pdf 0214 * E.g. the profile_data[] may contain additional u8 values (called DATA_IDs) 0215 * that are used depending on counter values inside the CAN frame data[]. 0216 * So far only three profiles have been implemented for illustration. 0217 * 0218 * Remark: In general the attribute data is a linear buffer. 0219 * Beware of sending unpacked or aligned structs! 0220 */ 0221 0222 #endif /* !_UAPI_CAN_GW_H */
[ Source navigation ] | [ Diff markup ] | [ Identifier search ] | [ general search ] |
This page was automatically generated by the 2.1.0 LXR engine. The LXR team |
![]() ![]() |