4 * Definitions for CAN frame Gateway/Router/Bridge
8 * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
9 * Copyright (c) 2002-2010 Volkswagen Group Electronic Research
10 * All rights reserved.
12 * Send feedback to <socketcan-users@lists.berlios.de>
19 #include <socketcan/can.h>
27 /* CAN gateway types */
30 CGW_TYPE_CAN_CAN, /* CAN->CAN routing */
34 #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1)
36 /* CAN rtnetlink attribute definitions */
39 CGW_MOD_AND, /* CAN frame modification binary AND */
40 CGW_MOD_OR, /* CAN frame modification binary OR */
41 CGW_MOD_XOR, /* CAN frame modification binary XOR */
42 CGW_MOD_SET, /* CAN frame modification set alternate values */
43 CGW_CS_XOR, /* set data[] XOR checksum into data[index] */
44 CGW_CS_CRC8, /* set data[] CRC8 checksum into data[index] */
45 CGW_HANDLED, /* number of handled CAN frames */
46 CGW_DROPPED, /* number of dropped CAN frames */
47 CGW_SRC_IF, /* ifindex of source network interface */
48 CGW_DST_IF, /* ifindex of destination network interface */
49 CGW_FILTER, /* specify struct can_filter on source CAN device */
53 #define CGW_MAX (__CGW_MAX - 1)
55 #define CGW_FLAGS_CAN_ECHO 0x01
56 #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02
58 #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */
60 /* CAN frame elements that are affected by curr. 3 CAN frame modifications */
61 #define CGW_MOD_ID 0x01
62 #define CGW_MOD_DLC 0x02
63 #define CGW_MOD_DATA 0x04
65 #define CGW_FRAME_MODS 3 /* ID DLC DATA */
67 #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS)
69 struct cgw_frame_mod {
72 } __attribute__((packed));
74 #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod)
81 } __attribute__ ((packed));
83 struct cgw_csum_crc8 {
90 } __attribute__ ((packed));
92 /* length of checksum operation parameters. idx = index in CAN frame data[] */
93 #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor)
94 #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8)
97 * CAN rtnetlink attribute contents in detail
99 * CGW_XXX_IF (length 4 bytes):
100 * Sets an interface index for source/destination network interfaces.
101 * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory.
103 * CGW_FILTER (length 8 bytes):
104 * Sets a CAN receive filter for the gateway job specified by the
105 * struct can_filter described in include/linux/can.h
107 * CGW_MOD_XXX (length 17 bytes):
108 * Specifies a modification that's done to a received CAN frame before it is
109 * send out to the destination interface.
111 * <struct can_frame> data used as operator
112 * <u8> affected CAN frame elements
114 * CGW_CS_XOR (length 4 bytes):
115 * Set a simple XOR checksum starting with an initial value into
116 * data[result-idx] using data[start-idx] .. data[end-idx]
118 * The XOR checksum is calculated like this:
122 * for (i = from_idx .. to_idx)
123 * xor ^= can_frame.data[i]
125 * can_frame.data[ result_idx ] = xor
127 * CGW_CS_CRC8 (length 261 bytes):
128 * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table,
129 * a given initial value and a defined input data[start-idx] .. data[end-idx].
130 * Finally the result value is XOR'ed with the final_xor_val.
132 * The CRC8 checksum is calculated like this:
136 * for (i = from_idx .. to_idx)
137 * crc = crctab[ crc ^ can_frame.data[i] ]
139 * can_frame.data[ result_idx ] = crc ^ final_xor_val
141 * Remark: In general the attribute data is a linear buffer.
142 * Beware of sending unpacked or aligned structs!