xref: /netbsd-src/external/bsd/libpcap/dist/pcap/can_socketcan.h (revision f73a5f05f638a81353839a8e4bfc90d1189181e7)
1a40cc363Schristos /*-
2a40cc363Schristos  * Copyright (c) 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
3a40cc363Schristos  *	The Regents of the University of California.  All rights reserved.
4a40cc363Schristos  *
5a40cc363Schristos  * This code is derived from the Stanford/CMU enet packet filter,
6a40cc363Schristos  * (net/enet.c) distributed as part of 4.3BSD, and code contributed
7a40cc363Schristos  * to Berkeley by Steven McCanne and Van Jacobson both of Lawrence
8a40cc363Schristos  * Berkeley Laboratory.
9a40cc363Schristos  *
10a40cc363Schristos  * Redistribution and use in source and binary forms, with or without
11a40cc363Schristos  * modification, are permitted provided that the following conditions
12a40cc363Schristos  * are met:
13a40cc363Schristos  * 1. Redistributions of source code must retain the above copyright
14a40cc363Schristos  *    notice, this list of conditions and the following disclaimer.
15a40cc363Schristos  * 2. Redistributions in binary form must reproduce the above copyright
16a40cc363Schristos  *    notice, this list of conditions and the following disclaimer in the
17a40cc363Schristos  *    documentation and/or other materials provided with the distribution.
18a40cc363Schristos  * 3. All advertising materials mentioning features or use of this software
19a40cc363Schristos  *    must display the following acknowledgement:
20a40cc363Schristos  *      This product includes software developed by the University of
21a40cc363Schristos  *      California, Berkeley and its contributors.
22a40cc363Schristos  * 4. Neither the name of the University nor the names of its contributors
23a40cc363Schristos  *    may be used to endorse or promote products derived from this software
24a40cc363Schristos  *    without specific prior written permission.
25a40cc363Schristos  *
26a40cc363Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27a40cc363Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28a40cc363Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29a40cc363Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30a40cc363Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31a40cc363Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32a40cc363Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33a40cc363Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34a40cc363Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35a40cc363Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36a40cc363Schristos  * SUCH DAMAGE.
37a40cc363Schristos  */
38a40cc363Schristos 
39a40cc363Schristos #ifndef lib_pcap_can_socketcan_h
40a40cc363Schristos #define lib_pcap_can_socketcan_h
41a40cc363Schristos 
429185e895Schristos #include <pcap/pcap-inttypes.h>
439185e895Schristos 
44a40cc363Schristos /*
45*f73a5f05Schristos  * SocketCAN header for CAN and CAN FD frames, as per
46*f73a5f05Schristos  * Documentation/networking/can.rst in the Linux source.
47a40cc363Schristos  */
48a40cc363Schristos typedef struct {
499185e895Schristos 	uint32_t can_id;
509185e895Schristos 	uint8_t payload_length;
51748408edSchristos 	uint8_t fd_flags;
529185e895Schristos 	uint8_t reserved1;
539185e895Schristos 	uint8_t reserved2;
54a40cc363Schristos } pcap_can_socketcan_hdr;
55a40cc363Schristos 
56748408edSchristos /* Bits in the fd_flags field */
57748408edSchristos #define CANFD_BRS   0x01 /* bit rate switch (second bitrate for payload data) */
58748408edSchristos #define CANFD_ESI   0x02 /* error state indicator of the transmitting node */
59748408edSchristos #define CANFD_FDF   0x04 /* mark CAN FD for dual use of CAN format */
60748408edSchristos 
61*f73a5f05Schristos /*
62*f73a5f05Schristos  * SocketCAN header for CAN XL frames, as per Linux's can.h header.
63*f73a5f05Schristos  * This is different from pcap_can_socketcan_hdr; the flags field
64*f73a5f05Schristos  * overlaps with the payload_length field in pcap_can_socketcan_hdr -
65*f73a5f05Schristos  * the payload_length field in a CAN or CAN FD frame never has the
66*f73a5f05Schristos  * 0x80 bit set, and the flags field in a CAN XL frame always has
67*f73a5f05Schristos  * it set, allowing code reading the frame to determine whether
68*f73a5f05Schristos  * it's CAN XL or not.
69*f73a5f05Schristos  */
70*f73a5f05Schristos typedef struct {
71*f73a5f05Schristos 	uint32_t priority_vcid;
72*f73a5f05Schristos 	uint8_t flags;
73*f73a5f05Schristos 	uint8_t sdu_type;
74*f73a5f05Schristos 	uint16_t payload_length;
75*f73a5f05Schristos 	uint32_t acceptance_field;
76*f73a5f05Schristos } pcap_can_socketcan_xl_hdr;
77*f73a5f05Schristos 
78*f73a5f05Schristos /* Bits in the flags field */
79*f73a5f05Schristos #define CANXL_SEC   0x01 /* Simple Extended Context */
80*f73a5f05Schristos #define CANXL_XLF   0x80 /* mark to distinguish CAN XL from CAN/CAN FD frames */
81*f73a5f05Schristos 
82a40cc363Schristos #endif
83