can.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  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. */
  12. #ifndef CAN_H
  13. #define CAN_H
  14. #include <linux/types.h>
  15. #include <linux/socket.h>
  16. /* controller area network (CAN) kernel definitions */
  17. /* special address description flags for the CAN_ID */
  18. #define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
  19. #define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
  20. #define CAN_ERR_FLAG 0x20000000U /* error frame */
  21. /* valid bits in CAN ID for frame formats */
  22. #define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
  23. #define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
  24. #define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
  25. /*
  26. * Controller Area Network Identifier structure
  27. *
  28. * bit 0-28 : CAN identifier (11/29 bit)
  29. * bit 29 : error frame flag (0 = data frame, 1 = error frame)
  30. * bit 30 : remote transmission request flag (1 = rtr frame)
  31. * bit 31 : frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
  32. */
  33. typedef __u32 canid_t;
  34. /*
  35. * Controller Area Network Error Frame Mask structure
  36. *
  37. * bit 0-28 : error class mask (see include/linux/can/error.h)
  38. * bit 29-31 : set to zero
  39. */
  40. typedef __u32 can_err_mask_t;
  41. /**
  42. * struct can_frame - basic CAN frame structure
  43. * @can_id: the CAN ID of the frame and CAN_*_FLAG flags, see above.
  44. * @can_dlc: the data length field of the CAN frame
  45. * @data: the CAN frame payload.
  46. */
  47. struct can_frame {
  48. canid_t can_id; /* 32 bit CAN_ID + EFF/RTR/ERR flags */
  49. __u8 can_dlc; /* data length code: 0 .. 8 */
  50. __u8 data[8] __attribute__((aligned(8)));
  51. };
  52. /* particular protocols of the protocol family PF_CAN */
  53. #define CAN_RAW 1 /* RAW sockets */
  54. #define CAN_BCM 2 /* Broadcast Manager */
  55. #define CAN_TP16 3 /* VAG Transport Protocol v1.6 */
  56. #define CAN_TP20 4 /* VAG Transport Protocol v2.0 */
  57. #define CAN_MCNET 5 /* Bosch MCNet */
  58. #define CAN_ISOTP 6 /* ISO 15765-2 Transport Protocol */
  59. #define CAN_NPROTO 7
  60. #define SOL_CAN_BASE 100
  61. /**
  62. * struct sockaddr_can - the sockaddr structure for CAN sockets
  63. * @can_family: address family number AF_CAN.
  64. * @can_ifindex: CAN network interface index.
  65. * @can_addr: protocol specific address information
  66. */
  67. struct sockaddr_can {
  68. __kernel_sa_family_t can_family;
  69. int can_ifindex;
  70. union {
  71. /* transport protocol class address information (e.g. ISOTP) */
  72. struct { canid_t rx_id, tx_id; } tp;
  73. /* reserved for future CAN protocols address information */
  74. } can_addr;
  75. };
  76. /**
  77. * struct can_filter - CAN ID based filter in can_register().
  78. * @can_id: relevant bits of CAN ID which are not masked out.
  79. * @can_mask: CAN mask (see description)
  80. *
  81. * Description:
  82. * A filter matches, when
  83. *
  84. * <received_can_id> & mask == can_id & mask
  85. *
  86. * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
  87. * filter for error frames (CAN_ERR_FLAG bit set in mask).
  88. */
  89. struct can_filter {
  90. canid_t can_id;
  91. canid_t can_mask;
  92. };
  93. #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
  94. #endif /* CAN_H */