logo

oasis-root

Compiled tree of Oasis Linux based on own branch at <https://hacktivis.me/git/oasis/> git clone https://anongit.hacktivis.me/git/oasis-root.git

gw.h (8026B)


  1. /* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */
  2. /*
  3. * linux/can/gw.h
  4. *
  5. * Definitions for CAN frame Gateway/Router/Bridge
  6. *
  7. * Author: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
  8. * Copyright (c) 2011 Volkswagen Group Electronic Research
  9. * All rights reserved.
  10. *
  11. * Redistribution and use in source and binary forms, with or without
  12. * modification, are permitted provided that the following conditions
  13. * are met:
  14. * 1. Redistributions of source code must retain the above copyright
  15. * notice, this list of conditions and the following disclaimer.
  16. * 2. Redistributions in binary form must reproduce the above copyright
  17. * notice, this list of conditions and the following disclaimer in the
  18. * documentation and/or other materials provided with the distribution.
  19. * 3. Neither the name of Volkswagen nor the names of its contributors
  20. * may be used to endorse or promote products derived from this software
  21. * without specific prior written permission.
  22. *
  23. * Alternatively, provided that this notice is retained in full, this
  24. * software may be distributed under the terms of the GNU General
  25. * Public License ("GPL") version 2, in which case the provisions of the
  26. * GPL apply INSTEAD OF those given above.
  27. *
  28. * The provided data structures and external interfaces from this code
  29. * are not restricted to be used by modules with a GPL compatible license.
  30. *
  31. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  32. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  33. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  34. * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  35. * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  36. * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  37. * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  38. * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  39. * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  40. * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  41. * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
  42. * DAMAGE.
  43. */
  44. #ifndef _CAN_GW_H
  45. #define _CAN_GW_H
  46. #include <linux/types.h>
  47. #include <linux/can.h>
  48. struct rtcanmsg {
  49. __u8 can_family;
  50. __u8 gwtype;
  51. __u16 flags;
  52. };
  53. /* CAN gateway types */
  54. enum {
  55. CGW_TYPE_UNSPEC,
  56. CGW_TYPE_CAN_CAN, /* CAN->CAN routing */
  57. __CGW_TYPE_MAX
  58. };
  59. #define CGW_TYPE_MAX (__CGW_TYPE_MAX - 1)
  60. /* CAN rtnetlink attribute definitions */
  61. enum {
  62. CGW_UNSPEC,
  63. CGW_MOD_AND, /* CAN frame modification binary AND */
  64. CGW_MOD_OR, /* CAN frame modification binary OR */
  65. CGW_MOD_XOR, /* CAN frame modification binary XOR */
  66. CGW_MOD_SET, /* CAN frame modification set alternate values */
  67. CGW_CS_XOR, /* set data[] XOR checksum into data[index] */
  68. CGW_CS_CRC8, /* set data[] CRC8 checksum into data[index] */
  69. CGW_HANDLED, /* number of handled CAN frames */
  70. CGW_DROPPED, /* number of dropped CAN frames */
  71. CGW_SRC_IF, /* ifindex of source network interface */
  72. CGW_DST_IF, /* ifindex of destination network interface */
  73. CGW_FILTER, /* specify struct can_filter on source CAN device */
  74. CGW_DELETED, /* number of deleted CAN frames (see max_hops param) */
  75. CGW_LIM_HOPS, /* limit the number of hops of this specific rule */
  76. CGW_MOD_UID, /* user defined identifier for modification updates */
  77. CGW_FDMOD_AND, /* CAN FD frame modification binary AND */
  78. CGW_FDMOD_OR, /* CAN FD frame modification binary OR */
  79. CGW_FDMOD_XOR, /* CAN FD frame modification binary XOR */
  80. CGW_FDMOD_SET, /* CAN FD frame modification set alternate values */
  81. __CGW_MAX
  82. };
  83. #define CGW_MAX (__CGW_MAX - 1)
  84. #define CGW_FLAGS_CAN_ECHO 0x01
  85. #define CGW_FLAGS_CAN_SRC_TSTAMP 0x02
  86. #define CGW_FLAGS_CAN_IIF_TX_OK 0x04
  87. #define CGW_FLAGS_CAN_FD 0x08
  88. #define CGW_MOD_FUNCS 4 /* AND OR XOR SET */
  89. /* CAN frame elements that are affected by curr. 3 CAN frame modifications */
  90. #define CGW_MOD_ID 0x01
  91. #define CGW_MOD_DLC 0x02 /* Classical CAN data length code */
  92. #define CGW_MOD_LEN CGW_MOD_DLC /* CAN FD (plain) data length */
  93. #define CGW_MOD_DATA 0x04
  94. #define CGW_MOD_FLAGS 0x08 /* CAN FD flags */
  95. #define CGW_FRAME_MODS 4 /* ID DLC/LEN DATA FLAGS */
  96. #define MAX_MODFUNCTIONS (CGW_MOD_FUNCS * CGW_FRAME_MODS)
  97. struct cgw_frame_mod {
  98. struct can_frame cf;
  99. __u8 modtype;
  100. } __attribute__((packed));
  101. struct cgw_fdframe_mod {
  102. struct canfd_frame cf;
  103. __u8 modtype;
  104. } __attribute__((packed));
  105. #define CGW_MODATTR_LEN sizeof(struct cgw_frame_mod)
  106. #define CGW_FDMODATTR_LEN sizeof(struct cgw_fdframe_mod)
  107. struct cgw_csum_xor {
  108. __s8 from_idx;
  109. __s8 to_idx;
  110. __s8 result_idx;
  111. __u8 init_xor_val;
  112. } __attribute__((packed));
  113. struct cgw_csum_crc8 {
  114. __s8 from_idx;
  115. __s8 to_idx;
  116. __s8 result_idx;
  117. __u8 init_crc_val;
  118. __u8 final_xor_val;
  119. __u8 crctab[256];
  120. __u8 profile;
  121. __u8 profile_data[20];
  122. } __attribute__((packed));
  123. /* length of checksum operation parameters. idx = index in CAN frame data[] */
  124. #define CGW_CS_XOR_LEN sizeof(struct cgw_csum_xor)
  125. #define CGW_CS_CRC8_LEN sizeof(struct cgw_csum_crc8)
  126. /* CRC8 profiles (compute CRC for additional data elements - see below) */
  127. enum {
  128. CGW_CRC8PRF_UNSPEC,
  129. CGW_CRC8PRF_1U8, /* compute one additional u8 value */
  130. CGW_CRC8PRF_16U8, /* u8 value table indexed by data[1] & 0xF */
  131. CGW_CRC8PRF_SFFID_XOR, /* (can_id & 0xFF) ^ (can_id >> 8 & 0xFF) */
  132. __CGW_CRC8PRF_MAX
  133. };
  134. #define CGW_CRC8PRF_MAX (__CGW_CRC8PRF_MAX - 1)
  135. /*
  136. * CAN rtnetlink attribute contents in detail
  137. *
  138. * CGW_XXX_IF (length 4 bytes):
  139. * Sets an interface index for source/destination network interfaces.
  140. * For the CAN->CAN gwtype the indices of _two_ CAN interfaces are mandatory.
  141. *
  142. * CGW_FILTER (length 8 bytes):
  143. * Sets a CAN receive filter for the gateway job specified by the
  144. * struct can_filter described in include/linux/can.h
  145. *
  146. * CGW_MOD_(AND|OR|XOR|SET) (length 17 bytes):
  147. * Specifies a modification that's done to a received CAN frame before it is
  148. * send out to the destination interface.
  149. *
  150. * <struct can_frame> data used as operator
  151. * <u8> affected CAN frame elements
  152. *
  153. * CGW_LIM_HOPS (length 1 byte):
  154. * Limit the number of hops of this specific rule. Usually the received CAN
  155. * frame can be processed as much as 'max_hops' times (which is given at module
  156. * load time of the can-gw module). This value is used to reduce the number of
  157. * possible hops for this gateway rule to a value smaller then max_hops.
  158. *
  159. * CGW_MOD_UID (length 4 bytes):
  160. * Optional non-zero user defined routing job identifier to alter existing
  161. * modification settings at runtime.
  162. *
  163. * CGW_CS_XOR (length 4 bytes):
  164. * Set a simple XOR checksum starting with an initial value into
  165. * data[result-idx] using data[start-idx] .. data[end-idx]
  166. *
  167. * The XOR checksum is calculated like this:
  168. *
  169. * xor = init_xor_val
  170. *
  171. * for (i = from_idx .. to_idx)
  172. * xor ^= can_frame.data[i]
  173. *
  174. * can_frame.data[ result_idx ] = xor
  175. *
  176. * CGW_CS_CRC8 (length 282 bytes):
  177. * Set a CRC8 value into data[result-idx] using a given 256 byte CRC8 table,
  178. * a given initial value and a defined input data[start-idx] .. data[end-idx].
  179. * Finally the result value is XOR'ed with the final_xor_val.
  180. *
  181. * The CRC8 checksum is calculated like this:
  182. *
  183. * crc = init_crc_val
  184. *
  185. * for (i = from_idx .. to_idx)
  186. * crc = crctab[ crc ^ can_frame.data[i] ]
  187. *
  188. * can_frame.data[ result_idx ] = crc ^ final_xor_val
  189. *
  190. * The calculated CRC may contain additional source data elements that can be
  191. * defined in the handling of 'checksum profiles' e.g. shown in AUTOSAR specs
  192. * like http://www.autosar.org/download/R4.0/AUTOSAR_SWS_E2ELibrary.pdf
  193. * E.g. the profile_data[] may contain additional u8 values (called DATA_IDs)
  194. * that are used depending on counter values inside the CAN frame data[].
  195. * So far only three profiles have been implemented for illustration.
  196. *
  197. * Remark: In general the attribute data is a linear buffer.
  198. * Beware of sending unpacked or aligned structs!
  199. */
  200. #endif /* !_UAPI_CAN_GW_H */