June 2025 | ||||||
Mo | Tu | We | Th | Fr | Sa | Su |
26 | 27 | 28 | 29 | 30 | 31 | 1 |
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 | 29 |
30 | 1 | 2 | 3 | 4 | 5 | 6 |
001: /* 002: * linux/can/gw.h 003: * 004: * Definitions for CAN frame Gateway/Router/Bridge 005: * 006: * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de> 007: * Copyright (c) 2011 Volkswagen Group Electronic Research 008: * All rights reserved. 009: * 010: */ 011: 012: #ifndef CAN_GW_H 013: #define CAN_GW_H 014: 015: #include <linux/types.h> 016: #include <linux/can.h> 017: 018: struct rtcanmsg { 019: __u8 can_family; 020: __u8 gwtype; 021: __u16 flags; 022: }; 023: 024: /* CAN gateway types */ 025: enum { 026: CGW_TYPE_UNSPEC, 027: CGW_TYPE_CAN_CAN, /* CAN->CAN routing */ 028: __CGW_TYPE_MAX 029: }; 030: 031: #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1) 032: 033: /* CAN rtnetlink attribute definitions */ 034: enum { 035: CGW_UNSPEC, 036: CGW_MOD_AND, /* CAN frame modification binary AND */ 037: CGW_MOD_OR, /* CAN frame modification binary OR */ 038: CGW_MOD_XOR, /* CAN frame modification binary XOR */ 039: CGW_MOD_SET, /* CAN frame modification set alternate values */ 040: CGW_CS_XOR, /* set data[] XOR checksum into data[index] */ 041: CGW_CS_CRC8, /* set data[] CRC8 checksum into data[index] */ 042: CGW_HANDLED, /* number of handled CAN frames */ 043: CGW_DROPPED, /* number of dropped CAN frames */ 044: CGW_SRC_IF, /* ifindex of source network interface */ 045: CGW_DST_IF, /* ifindex of destination network interface */ 046: CGW_FILTER, /* specify struct can_filter on source CAN device */ 047: __CGW_MAX 048: }; 049: 050: #define CGW_MAX (__CGW_MAX - 1) 051: 052: #define CGW_FLAGS_CAN_ECHO 0x01 053: #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02 054: 055: #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */ 056: 057: /* CAN frame elements that are affected by curr. 3 CAN frame modifications */ 058: #define CGW_MOD_ID 0x01 059: #define CGW_MOD_DLC 0x02 060: #define CGW_MOD_DATA 0x04 061: 062: #define CGW_FRAME_MODS 3 /* ID DLC DATA */ 063: 064: #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS) 065: 066: struct cgw_frame_mod { 067: struct can_frame cf; 068: __u8 modtype; 069: } __attribute__((packed)); 070: 071: #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod) 072: 073: struct cgw_csum_xor { 074: __s8 from_idx; 075: __s8 to_idx; 076: __s8 result_idx; 077: __u8 init_xor_val; 078: } __attribute__((packed)); 079: 080: struct cgw_csum_crc8 { 081: __s8 from_idx; 082: __s8 to_idx; 083: __s8 result_idx; 084: __u8 init_crc_val; 085: __u8 final_xor_val; 086: __u8 crctab[256]; 087: __u8 profile; 088: __u8 profile_data[20]; 089: } __attribute__((packed)); 090: 091: /* length of checksum operation parameters. idx = index in CAN frame data[] */ 092: #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor) 093: #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8) 094: 095: /* CRC8 profiles (compute CRC for additional data elements - see below) */ 096: enum { 097: CGW_CRC8PRF_UNSPEC, 098: CGW_CRC8PRF_1U8, /* compute one additional u8 value */ 099: CGW_CRC8PRF_16U8, /* u8 value table indexed by data[1] & 0xF */ 100: CGW_CRC8PRF_SFFID_XOR, /* (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) */ 101: __CGW_CRC8PRF_MAX 102: }; 103: 104: #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1) 105: 106: /* 107: * CAN rtnetlink attribute contents in detail 108: * 109: * CGW_XXX_IF (length 4 bytes): 110: * Sets an interface index for source/destination network interfaces. 111: * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory. 112: * 113: * CGW_FILTER (length 8 bytes): 114: * Sets a CAN receive filter for the gateway job specified by the 115: * struct can_filter described in include/linux/can.h 116: * 117: * CGW_MOD_XXX (length 17 bytes): 118: * Specifies a modification that's done to a received CAN frame before it is 119: * send out to the destination interface. 120: * 121: * <struct can_frame> data used as operator 122: * <u8> affected CAN frame elements 123: * 124: * CGW_CS_XOR (length 4 bytes): 125: * Set a simple XOR checksum starting with an initial value into 126: * data[result-idx] using data[start-idx] .. data[end-idx] 127: * 128: * The XOR checksum is calculated like this: 129: * 130: * xor = init_xor_val 131: * 132: * for (i = from_idx .. to_idx) 133: * xor ^= can_frame.data[i] 134: * 135: * can_frame.data[ result_idx ] = xor 136: * 137: * CGW_CS_CRC8 (length 282 bytes): 138: * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table, 139: * a given initial value and a defined input data[start-idx] .. data[end-idx]. 140: * Finally the result value is XOR'ed with the final_xor_val. 141: * 142: * The CRC8 checksum is calculated like this: 143: * 144: * crc = init_crc_val 145: * 146: * for (i = from_idx .. to_idx) 147: * crc = crctab[ crc ^ can_frame.data[i] ] 148: * 149: * can_frame.data[ result_idx ] = crc ^ final_xor_val 150: * 151: * The calculated CRC may contain additional source data elements that can be 152: * defined in the handling of 'checksum profiles' e.g. shown in AUTOSAR specs 153: * like http://www.autosar.org/download/R4.0/AUTOSAR_SWS_E2ELibrary.pdf 154: * E.g. the profile_data[] may contain additional u8 values (called DATA_IDs) 155: * that are used depending on counter values inside the CAN frame data[]. 156: * So far only three profiles have been implemented for illustration. 157: * 158: * Remark: In general the attribute data is a linear buffer. 159: * Beware of sending unpacked or aligned structs! 160: */ 161: 162: #endif 163: