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