can_frame.h 3.0 KB

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