You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

202 lines
7.6 KiB

7 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. * linux/can.h
  3. *
  4. * Definitions for CAN network layer (socket addr / CAN frame / CAN filter)
  5. *
  6. * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
  7. * Urs Thuermann <urs.thuermann@volkswagen.de>
  8. * Copyright (c) 2002-2007 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_H
  45. #define CAN_H
  46. #include <linux/types.h>
  47. #include <linux/socket.h>
  48. /* controller area network (CAN) kernel definitions */
  49. /* special address description flags for the CAN_ID */
  50. #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
  51. #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
  52. #define CAN_ERR_FLAG 0x20000000U /* error message frame */
  53. /* valid bits in CAN ID for frame formats */
  54. #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
  55. #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
  56. #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
  57. /*
  58. * Controller Area Network Identifier structure
  59. *
  60. * bit 0-28 : CAN identifier (11/29 bit)
  61. * bit 29 : error message frame flag (0 = data frame, 1 = error message)
  62. * bit 30 : remote transmission request flag (1 = rtr frame)
  63. * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
  64. */
  65. typedef __u32 canid_t;
  66. #define CAN_SFF_ID_BITS 11
  67. #define CAN_EFF_ID_BITS 29
  68. /*
  69. * Controller Area Network Error Message Frame Mask structure
  70. *
  71. * bit 0-28 : error class mask (see include/linux/can/error.h)
  72. * bit 29-31 : set to zero
  73. */
  74. typedef __u32 can_err_mask_t;
  75. /* CAN payload length and DLC definitions according to ISO 11898-1 */
  76. #define CAN_MAX_DLC 8
  77. #define CAN_MAX_DLEN 8
  78. /* CAN FD payload length and DLC definitions according to ISO 11898-7 */
  79. #define CANFD_MAX_DLC 15
  80. #define CANFD_MAX_DLEN 64
  81. /**
  82. * struct can_frame - basic CAN frame structure
  83. * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
  84. * @can_dlc: frame payload length in byte (0 .. 8) aka data length code
  85. * N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1
  86. * mapping of the 'data length code' to the real payload length
  87. * @data: CAN frame payload (up to 8 byte)
  88. */
  89. struct can_frame {
  90. canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
  91. __u8 can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
  92. __u8 data[CAN_MAX_DLEN] __attribute__((aligned(8)));
  93. };
  94. /*
  95. * defined bits for canfd_frame.flags
  96. *
  97. * The use of struct canfd_frame implies the Extended Data Length (EDL) bit to
  98. * be set in the CAN frame bitstream on the wire. The EDL bit switch turns
  99. * the CAN controllers bitstream processor into the CAN FD mode which creates
  100. * two new options within the CAN FD frame specification:
  101. *
  102. * Bit Rate Switch - to indicate a second bitrate is/was used for the payload
  103. * Error State Indicator - represents the error state of the transmitting node
  104. *
  105. * As the CANFD_ESI bit is internally generated by the transmitting CAN
  106. * controller only the CANFD_BRS bit is relevant for real CAN controllers when
  107. * building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make
  108. * sense for virtual CAN interfaces to test applications with echoed frames.
  109. */
  110. #define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
  111. #define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
  112. /**
  113. * struct canfd_frame - CAN flexible data rate frame structure
  114. * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
  115. * @len: frame payload length in byte (0 .. CANFD_MAX_DLEN)
  116. * @flags: additional flags for CAN FD
  117. * @__res0: reserved / padding
  118. * @__res1: reserved / padding
  119. * @data: CAN FD frame payload (up to CANFD_MAX_DLEN byte)
  120. */
  121. struct canfd_frame {
  122. canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
  123. __u8 len; /* frame payload length in byte */
  124. __u8 flags; /* additional flags for CAN FD */
  125. __u8 __res0; /* reserved / padding */
  126. __u8 __res1; /* reserved / padding */
  127. __u8 data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
  128. };
  129. #define CAN_MTU (sizeof(struct can_frame))
  130. #define CANFD_MTU (sizeof(struct canfd_frame))
  131. /* particular protocols of the protocol family PF_CAN */
  132. #define CAN_RAW 1 /* RAW sockets */
  133. #define CAN_BCM 2 /* Broadcast Manager */
  134. #define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
  135. #define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
  136. #define CAN_MCNET 5 /* Bosch MCNet */
  137. #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
  138. #define CAN_NPROTO 7
  139. #define SOL_CAN_BASE 100
  140. /*
  141. * This typedef was introduced in Linux v3.1-rc2
  142. * (commit 6602a4b net: Make userland include of netlink.h more sane)
  143. * in <linux/socket.h>. It must be duplicated here to make the CAN
  144. * headers self-contained.
  145. */
  146. typedef unsigned short __kernel_sa_family_t;
  147. /**
  148. * struct sockaddr_can - the sockaddr structure for CAN sockets
  149. * @can_family: address family number AF_CAN.
  150. * @can_ifindex: CAN network interface index.
  151. * @can_addr: protocol specific address information
  152. */
  153. struct sockaddr_can {
  154. __kernel_sa_family_t can_family;
  155. int can_ifindex;
  156. union {
  157. /* transport protocol class address information (e.g. ISOTP) */
  158. struct { canid_t rx_id, tx_id; } tp;
  159. /* reserved for future CAN protocols address information */
  160. } can_addr;
  161. };
  162. /**
  163. * struct can_filter - CAN ID based filter in can_register().
  164. * @can_id: relevant bits of CAN ID which are not masked out.
  165. * @can_mask: CAN mask (see description)
  166. *
  167. * Description:
  168. * A filter matches, when
  169. *
  170. * <received_can_id> & mask == can_id & mask
  171. *
  172. * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
  173. * filter for error message frames (CAN_ERR_FLAG bit set in mask).
  174. */
  175. struct can_filter {
  176. canid_t can_id;
  177. canid_t can_mask;
  178. };
  179. #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
  180. #endif /* CAN_H */