Home | History | Annotate | Download | only in linux
      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 (at) volkswagen.de>
      7  *          Urs Thuermann   <urs.thuermann (at) 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 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 frame flag (0 = data frame, 1 = error frame)
     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  */
     39 typedef __u32 canid_t;
     40 
     41 /*
     42  * Controller Area Network Error Frame Mask structure
     43  *
     44  * bit 0-28	: error class mask (see include/linux/can/error.h)
     45  * bit 29-31	: set to zero
     46  */
     47 typedef __u32 can_err_mask_t;
     48 
     49 /**
     50  * struct can_frame - basic CAN frame structure
     51  * @can_id:  the CAN ID of the frame and CAN_*_FLAG flags, see above.
     52  * @can_dlc: the data length field of the CAN frame
     53  * @data:    the CAN frame payload.
     54  */
     55 struct can_frame {
     56 	canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
     57 	__u8    can_dlc; /* data length code: 0 .. 8 */
     58 	__u8    data[8] __attribute__((aligned(8)));
     59 };
     60 
     61 /* particular protocols of the protocol family PF_CAN */
     62 #define CAN_RAW		1 /* RAW sockets */
     63 #define CAN_BCM		2 /* Broadcast Manager */
     64 #define CAN_TP16	3 /* VAG Transport Protocol v1.6 */
     65 #define CAN_TP20	4 /* VAG Transport Protocol v2.0 */
     66 #define CAN_MCNET	5 /* Bosch MCNet */
     67 #define CAN_ISOTP	6 /* ISO 15765-2 Transport Protocol */
     68 #define CAN_NPROTO	7
     69 
     70 #define SOL_CAN_BASE 100
     71 
     72 /**
     73  * struct sockaddr_can - the sockaddr structure for CAN sockets
     74  * @can_family:  address family number AF_CAN.
     75  * @can_ifindex: CAN network interface index.
     76  * @can_addr:    protocol specific address information
     77  */
     78 struct sockaddr_can {
     79 	__kernel_sa_family_t can_family;
     80 	int         can_ifindex;
     81 	union {
     82 		/* transport protocol class address information (e.g. ISOTP) */
     83 		struct { canid_t rx_id, tx_id; } tp;
     84 
     85 		/* reserved for future CAN protocols address information */
     86 	} can_addr;
     87 };
     88 
     89 /**
     90  * struct can_filter - CAN ID based filter in can_register().
     91  * @can_id:   relevant bits of CAN ID which are not masked out.
     92  * @can_mask: CAN mask (see description)
     93  *
     94  * Description:
     95  * A filter matches, when
     96  *
     97  *          <received_can_id> & mask == can_id & mask
     98  *
     99  * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
    100  * filter for error frames (CAN_ERR_FLAG bit set in mask).
    101  */
    102 struct can_filter {
    103 	canid_t can_id;
    104 	canid_t can_mask;
    105 };
    106 
    107 #define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
    108 
    109 #endif /* CAN_H */
    110