Blame include/uapi/linux/can.h

Packit Service 3880ab
/* SPDX-License-Identifier: ((GPL-2.0-only WITH Linux-syscall-note) OR BSD-3-Clause) */
Packit Service 3880ab
/*
Packit Service 3880ab
 * linux/can.h
Packit Service 3880ab
 *
Packit Service 3880ab
 * Definitions for CAN network layer (socket addr / CAN frame / CAN filter)
Packit Service 3880ab
 *
Packit Service 3880ab
 * Authors: Oliver Hartkopp <oliver.hartkopp@volkswagen.de>
Packit Service 3880ab
 *          Urs Thuermann   <urs.thuermann@volkswagen.de>
Packit Service 3880ab
 * Copyright (c) 2002-2007 Volkswagen Group Electronic Research
Packit Service 3880ab
 * All rights reserved.
Packit Service 3880ab
 *
Packit Service 3880ab
 * Redistribution and use in source and binary forms, with or without
Packit Service 3880ab
 * modification, are permitted provided that the following conditions
Packit Service 3880ab
 * are met:
Packit Service 3880ab
 * 1. Redistributions of source code must retain the above copyright
Packit Service 3880ab
 *    notice, this list of conditions and the following disclaimer.
Packit Service 3880ab
 * 2. Redistributions in binary form must reproduce the above copyright
Packit Service 3880ab
 *    notice, this list of conditions and the following disclaimer in the
Packit Service 3880ab
 *    documentation and/or other materials provided with the distribution.
Packit Service 3880ab
 * 3. Neither the name of Volkswagen nor the names of its contributors
Packit Service 3880ab
 *    may be used to endorse or promote products derived from this software
Packit Service 3880ab
 *    without specific prior written permission.
Packit Service 3880ab
 *
Packit Service 3880ab
 * Alternatively, provided that this notice is retained in full, this
Packit Service 3880ab
 * software may be distributed under the terms of the GNU General
Packit Service 3880ab
 * Public License ("GPL") version 2, in which case the provisions of the
Packit Service 3880ab
 * GPL apply INSTEAD OF those given above.
Packit Service 3880ab
 *
Packit Service 3880ab
 * The provided data structures and external interfaces from this code
Packit Service 3880ab
 * are not restricted to be used by modules with a GPL compatible license.
Packit Service 3880ab
 *
Packit Service 3880ab
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
Packit Service 3880ab
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
Packit Service 3880ab
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
Packit Service 3880ab
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
Packit Service 3880ab
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
Packit Service 3880ab
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
Packit Service 3880ab
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
Packit Service 3880ab
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
Packit Service 3880ab
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
Packit Service 3880ab
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Packit Service 3880ab
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
Packit Service 3880ab
 * DAMAGE.
Packit Service 3880ab
 */
Packit Service 3880ab
Packit Service 3880ab
#ifndef _CAN_H
Packit Service 3880ab
#define _CAN_H
Packit Service 3880ab
Packit Service 3880ab
#include <linux/types.h>
Packit Service 3880ab
#include <linux/socket.h>
Packit Service 3880ab
Packit Service 3880ab
/* controller area network (CAN) kernel definitions */
Packit Service 3880ab
Packit Service 3880ab
/* special address description flags for the CAN_ID */
Packit Service 3880ab
#define CAN_EFF_FLAG 0x80000000U /* EFF/SFF is set in the MSB */
Packit Service 3880ab
#define CAN_RTR_FLAG 0x40000000U /* remote transmission request */
Packit Service 3880ab
#define CAN_ERR_FLAG 0x20000000U /* error message frame */
Packit Service 3880ab
Packit Service 3880ab
/* valid bits in CAN ID for frame formats */
Packit Service 3880ab
#define CAN_SFF_MASK 0x000007FFU /* standard frame format (SFF) */
Packit Service 3880ab
#define CAN_EFF_MASK 0x1FFFFFFFU /* extended frame format (EFF) */
Packit Service 3880ab
#define CAN_ERR_MASK 0x1FFFFFFFU /* omit EFF, RTR, ERR flags */
Packit Service 3880ab
Packit Service 3880ab
/*
Packit Service 3880ab
 * Controller Area Network Identifier structure
Packit Service 3880ab
 *
Packit Service 3880ab
 * bit 0-28	: CAN identifier (11/29 bit)
Packit Service 3880ab
 * bit 29	: error message frame flag (0 = data frame, 1 = error message)
Packit Service 3880ab
 * bit 30	: remote transmission request flag (1 = rtr frame)
Packit Service 3880ab
 * bit 31	: frame format flag (0 = standard 11 bit, 1 = extended 29 bit)
Packit Service 3880ab
 */
Packit Service 3880ab
typedef __u32 canid_t;
Packit Service 3880ab
Packit Service 3880ab
#define CAN_SFF_ID_BITS		11
Packit Service 3880ab
#define CAN_EFF_ID_BITS		29
Packit Service 3880ab
Packit Service 3880ab
/*
Packit Service 3880ab
 * Controller Area Network Error Message Frame Mask structure
Packit Service 3880ab
 *
Packit Service 3880ab
 * bit 0-28	: error class mask (see include/uapi/linux/can/error.h)
Packit Service 3880ab
 * bit 29-31	: set to zero
Packit Service 3880ab
 */
Packit Service 3880ab
typedef __u32 can_err_mask_t;
Packit Service 3880ab
Packit Service 3880ab
/* CAN payload length and DLC definitions according to ISO 11898-1 */
Packit Service 3880ab
#define CAN_MAX_DLC 8
Packit Service 3880ab
#define CAN_MAX_DLEN 8
Packit Service 3880ab
Packit Service 3880ab
/* CAN FD payload length and DLC definitions according to ISO 11898-7 */
Packit Service 3880ab
#define CANFD_MAX_DLC 15
Packit Service 3880ab
#define CANFD_MAX_DLEN 64
Packit Service 3880ab
Packit Service 3880ab
/**
Packit Service 3880ab
 * struct can_frame - basic CAN frame structure
Packit Service 3880ab
 * @can_id:  CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
Packit Service 3880ab
 * @can_dlc: frame payload length in byte (0 .. 8) aka data length code
Packit Service 3880ab
 *           N.B. the DLC field from ISO 11898-1 Chapter 8.4.2.3 has a 1:1
Packit Service 3880ab
 *           mapping of the 'data length code' to the real payload length
Packit Service 3880ab
 * @__pad:   padding
Packit Service 3880ab
 * @__res0:  reserved / padding
Packit Service 3880ab
 * @__res1:  reserved / padding
Packit Service 3880ab
 * @data:    CAN frame payload (up to 8 byte)
Packit Service 3880ab
 */
Packit Service 3880ab
struct can_frame {
Packit Service 3880ab
	canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
Packit Service 3880ab
	__u8    can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
Packit Service 3880ab
	__u8    __pad;   /* padding */
Packit Service 3880ab
	__u8    __res0;  /* reserved / padding */
Packit Service 3880ab
	__u8    __res1;  /* reserved / padding */
Packit Service 3880ab
	__u8    data[CAN_MAX_DLEN] __attribute__((aligned(8)));
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/*
Packit Service 3880ab
 * defined bits for canfd_frame.flags
Packit Service 3880ab
 *
Packit Service 3880ab
 * The use of struct canfd_frame implies the Extended Data Length (EDL) bit to
Packit Service 3880ab
 * be set in the CAN frame bitstream on the wire. The EDL bit switch turns
Packit Service 3880ab
 * the CAN controllers bitstream processor into the CAN FD mode which creates
Packit Service 3880ab
 * two new options within the CAN FD frame specification:
Packit Service 3880ab
 *
Packit Service 3880ab
 * Bit Rate Switch - to indicate a second bitrate is/was used for the payload
Packit Service 3880ab
 * Error State Indicator - represents the error state of the transmitting node
Packit Service 3880ab
 *
Packit Service 3880ab
 * As the CANFD_ESI bit is internally generated by the transmitting CAN
Packit Service 3880ab
 * controller only the CANFD_BRS bit is relevant for real CAN controllers when
Packit Service 3880ab
 * building a CAN FD frame for transmission. Setting the CANFD_ESI bit can make
Packit Service 3880ab
 * sense for virtual CAN interfaces to test applications with echoed frames.
Packit Service 3880ab
 */
Packit Service 3880ab
#define CANFD_BRS 0x01 /* bit rate switch (second bitrate for payload data) */
Packit Service 3880ab
#define CANFD_ESI 0x02 /* error state indicator of the transmitting node */
Packit Service 3880ab
Packit Service 3880ab
/**
Packit Service 3880ab
 * struct canfd_frame - CAN flexible data rate frame structure
Packit Service 3880ab
 * @can_id: CAN ID of the frame and CAN_*_FLAG flags, see canid_t definition
Packit Service 3880ab
 * @len:    frame payload length in byte (0 .. CANFD_MAX_DLEN)
Packit Service 3880ab
 * @flags:  additional flags for CAN FD
Packit Service 3880ab
 * @__res0: reserved / padding
Packit Service 3880ab
 * @__res1: reserved / padding
Packit Service 3880ab
 * @data:   CAN FD frame payload (up to CANFD_MAX_DLEN byte)
Packit Service 3880ab
 */
Packit Service 3880ab
struct canfd_frame {
Packit Service 3880ab
	canid_t can_id;  /* 32 bit CAN_ID + EFF/RTR/ERR flags */
Packit Service 3880ab
	__u8    len;     /* frame payload length in byte */
Packit Service 3880ab
	__u8    flags;   /* additional flags for CAN FD */
Packit Service 3880ab
	__u8    __res0;  /* reserved / padding */
Packit Service 3880ab
	__u8    __res1;  /* reserved / padding */
Packit Service 3880ab
	__u8    data[CANFD_MAX_DLEN] __attribute__((aligned(8)));
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
#define CAN_MTU		(sizeof(struct can_frame))
Packit Service 3880ab
#define CANFD_MTU	(sizeof(struct canfd_frame))
Packit Service 3880ab
Packit Service 3880ab
/* particular protocols of the protocol family PF_CAN */
Packit Service 3880ab
#define CAN_RAW		1 /* RAW sockets */
Packit Service 3880ab
#define CAN_BCM		2 /* Broadcast Manager */
Packit Service 3880ab
#define CAN_TP16	3 /* VAG Transport Protocol v1.6 */
Packit Service 3880ab
#define CAN_TP20	4 /* VAG Transport Protocol v2.0 */
Packit Service 3880ab
#define CAN_MCNET	5 /* Bosch MCNet */
Packit Service 3880ab
#define CAN_ISOTP	6 /* ISO 15765-2 Transport Protocol */
Packit Service 3880ab
#define CAN_J1939	7 /* SAE J1939 */
Packit Service 3880ab
#define CAN_NPROTO	8
Packit Service 3880ab
Packit Service 3880ab
#define SOL_CAN_BASE 100
Packit Service 3880ab
Packit Service 3880ab
/**
Packit Service 3880ab
 * struct sockaddr_can - the sockaddr structure for CAN sockets
Packit Service 3880ab
 * @can_family:  address family number AF_CAN.
Packit Service 3880ab
 * @can_ifindex: CAN network interface index.
Packit Service 3880ab
 * @can_addr:    protocol specific address information
Packit Service 3880ab
 */
Packit Service 3880ab
struct sockaddr_can {
Packit Service 3880ab
	__kernel_sa_family_t can_family;
Packit Service 3880ab
	int         can_ifindex;
Packit Service 3880ab
	union {
Packit Service 3880ab
		/* transport protocol class address information (e.g. ISOTP) */
Packit Service 3880ab
		struct { canid_t rx_id, tx_id; } tp;
Packit Service 3880ab
Packit Service 3880ab
		/* J1939 address information */
Packit Service 3880ab
		struct {
Packit Service 3880ab
			/* 8 byte name when using dynamic addressing */
Packit Service 3880ab
			__u64 name;
Packit Service 3880ab
Packit Service 3880ab
			/* pgn:
Packit Service 3880ab
			 * 8 bit: PS in PDU2 case, else 0
Packit Service 3880ab
			 * 8 bit: PF
Packit Service 3880ab
			 * 1 bit: DP
Packit Service 3880ab
			 * 1 bit: reserved
Packit Service 3880ab
			 */
Packit Service 3880ab
			__u32 pgn;
Packit Service 3880ab
Packit Service 3880ab
			/* 1 byte address */
Packit Service 3880ab
			__u8 addr;
Packit Service 3880ab
		} j1939;
Packit Service 3880ab
Packit Service 3880ab
		/* reserved for future CAN protocols address information */
Packit Service 3880ab
	} can_addr;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
/**
Packit Service 3880ab
 * struct can_filter - CAN ID based filter in can_register().
Packit Service 3880ab
 * @can_id:   relevant bits of CAN ID which are not masked out.
Packit Service 3880ab
 * @can_mask: CAN mask (see description)
Packit Service 3880ab
 *
Packit Service 3880ab
 * Description:
Packit Service 3880ab
 * A filter matches, when
Packit Service 3880ab
 *
Packit Service 3880ab
 *          <received_can_id> & mask == can_id & mask
Packit Service 3880ab
 *
Packit Service 3880ab
 * The filter can be inverted (CAN_INV_FILTER bit set in can_id) or it can
Packit Service 3880ab
 * filter for error message frames (CAN_ERR_FLAG bit set in mask).
Packit Service 3880ab
 */
Packit Service 3880ab
struct can_filter {
Packit Service 3880ab
	canid_t can_id;
Packit Service 3880ab
	canid_t can_mask;
Packit Service 3880ab
};
Packit Service 3880ab
Packit Service 3880ab
#define CAN_INV_FILTER 0x20000000U /* to be set in can_filter.can_id */
Packit Service 3880ab
#define CAN_RAW_FILTER_MAX 512 /* maximum number of can_filter set via setsockopt() */
Packit Service 3880ab
Packit Service 3880ab
#endif /* !_UAPI_CAN_H */