]> rtime.felk.cvut.cz Git - socketcan-devel.git/blob - kernel/2.6/include/socketcan/can/gw.h
Added missing inclusion of linux/types.h
[socketcan-devel.git] / kernel / 2.6 / include / socketcan / can / gw.h
1 /*
2  * socketcan/can/gw.h
3  *
4  * Definitions for CAN frame Gateway/Router/Bridge
5  *
6  * $Id$
7  *
8  * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
9  * Copyright (c) 2011 Volkswagen Group Electronic Research
10  * All rights reserved.
11  *
12  * Send feedback to <socketcan-users@lists.berlios.de>
13  *
14  */
15
16 #ifndef CAN_GW_H
17 #define CAN_GW_H
18
19 #include <linux/types.h>
20 #include <socketcan/can.h>
21
22 struct rtcanmsg {
23         __u8  can_family;
24         __u8  gwtype;
25         __u16 flags;
26 };
27
28 /* CAN gateway types */
29 enum {
30         CGW_TYPE_UNSPEC,
31         CGW_TYPE_CAN_CAN,       /* CAN->CAN routing */
32         __CGW_TYPE_MAX
33 };
34
35 #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1)
36
37 /* CAN rtnetlink attribute definitions */
38 enum {
39         CGW_UNSPEC,
40         CGW_MOD_AND,    /* CAN frame modification binary AND */
41         CGW_MOD_OR,     /* CAN frame modification binary OR */
42         CGW_MOD_XOR,    /* CAN frame modification binary XOR */
43         CGW_MOD_SET,    /* CAN frame modification set alternate values */
44         CGW_CS_XOR,     /* set data[] XOR checksum into data[index] */
45         CGW_CS_CRC8,    /* set data[] CRC8 checksum into data[index] */
46         CGW_HANDLED,    /* number of handled CAN frames */
47         CGW_DROPPED,    /* number of dropped CAN frames */
48         CGW_SRC_IF,     /* ifindex of source network interface */
49         CGW_DST_IF,     /* ifindex of destination network interface */
50         CGW_FILTER,     /* specify struct can_filter on source CAN device */
51         __CGW_MAX
52 };
53
54 #define CGW_MAX (__CGW_MAX - 1)
55
56 #define CGW_FLAGS_CAN_ECHO 0x01
57 #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02
58
59 #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */
60
61 /* CAN frame elements that are affected by curr. 3 CAN frame modifications */
62 #define CGW_MOD_ID      0x01
63 #define CGW_MOD_DLC     0x02
64 #define CGW_MOD_DATA    0x04
65
66 #define CGW_FRAME_MODS 3 /* ID DLC DATA */
67
68 #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS)
69
70 struct cgw_frame_mod {
71         struct can_frame cf;
72         __u8 modtype;
73 } __attribute__((packed));
74
75 #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod)
76
77 struct cgw_csum_xor {
78         __s8 from_idx;
79         __s8 to_idx;
80         __s8 result_idx;
81         __u8 init_xor_val;
82 } __attribute__((packed));
83
84 struct cgw_csum_crc8 {
85         __s8 from_idx;
86         __s8 to_idx;
87         __s8 result_idx;
88         __u8 init_crc_val;
89         __u8 final_xor_val;
90         __u8 crctab[256];
91         __u8 profile;
92         __u8 profile_data[20];
93 } __attribute__((packed));
94
95 /* length of checksum operation parameters. idx = index in CAN frame data[] */
96 #define CGW_CS_XOR_LEN  sizeof(struct cgw_csum_xor)
97 #define CGW_CS_CRC8_LEN  sizeof(struct cgw_csum_crc8)
98
99 /* CRC8 profiles (compute CRC for additional data elements - see below) */
100 enum {
101         CGW_CRC8PRF_UNSPEC,
102         CGW_CRC8PRF_1U8,        /* compute one additional u8 value */
103         CGW_CRC8PRF_16U8,       /* u8 value table indexed by data[1] & 0xF */
104         CGW_CRC8PRF_SFFID_XOR,  /* (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) */
105         __CGW_CRC8PRF_MAX
106 };
107
108 #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1)
109
110 /*
111  * CAN rtnetlink attribute contents in detail
112  *
113  * CGW_XXX_IF (length 4 bytes):
114  * Sets an interface index for source/destination network interfaces.
115  * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory.
116  *
117  * CGW_FILTER (length 8 bytes):
118  * Sets a CAN receive filter for the gateway job specified by the
119  * struct can_filter described in include/linux/can.h
120  *
121  * CGW_MOD_XXX (length 17 bytes):
122  * Specifies a modification that's done to a received CAN frame before it is
123  * send out to the destination interface.
124  *
125  * <struct can_frame> data used as operator
126  * <u8> affected CAN frame elements
127  *
128  * CGW_CS_XOR (length 4 bytes):
129  * Set a simple XOR checksum starting with an initial value into
130  * data[result-idx] using data[start-idx] .. data[end-idx]
131  *
132  * The XOR checksum is calculated like this:
133  *
134  * xor = init_xor_val
135  *
136  * for (i = from_idx .. to_idx)
137  *      xor ^= can_frame.data[i]
138  *
139  * can_frame.data[ result_idx ] = xor
140  *
141  * CGW_CS_CRC8 (length 282 bytes):
142  * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table,
143  * a given initial value and a defined input data[start-idx] .. data[end-idx].
144  * Finally the result value is XOR'ed with the final_xor_val.
145  *
146  * The CRC8 checksum is calculated like this:
147  *
148  * crc = init_crc_val
149  *
150  * for (i = from_idx .. to_idx)
151  *      crc = crctab[ crc ^ can_frame.data[i] ]
152  *
153  * can_frame.data[ result_idx ] = crc ^ final_xor_val
154  *
155  * The calculated CRC may contain additional source data elements that can be
156  * defined in the handling of 'checksum profiles' e.g. shown in AUTOSAR specs
157  * like http://www.autosar.org/download/R4.0/AUTOSAR_SWS_E2ELibrary.pdf
158  * E.g. the profile_data[] may contain additional u8 values (called DATA_IDs)
159  * that are used depending on counter values inside the CAN frame data[].
160  * So far only three profiles have been implemented for illustration.
161  *
162  * Remark: In general the attribute data is a linear buffer.
163  *         Beware of sending unpacked or aligned structs!
164  */
165
166 #endif