xref: /netbsd-src/share/man/man4/can.4 (revision a35802ce9a83e199d7e59061721b74ae4382bbe8)
1.\"	$NetBSD: can.4,v 1.3 2017/05/29 08:41:57 wiz Exp $
2.\"
3.\" Copyright (c) 2017 Manuel Bouyer.
4.\" Redistribution and use in source and binary forms, with or without
5.\" modification, are permitted provided that the following conditions
6.\" are met:
7.\" 1. Redistributions of source code must retain the above copyright
8.\"    notice, this list of conditions and the following disclaimer.
9.\" 2. Redistributions in binary form must reproduce the above copyright
10.\"    notice, this list of conditions and the following disclaimer in the
11.\"    documentation and/or other materials provided with the distribution.
12.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
13.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
14.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
15.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
16.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
17.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
18.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
19.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
20.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
21.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
22.\"
23.Dd May 18, 2017
24.Dt CAN 4
25.Os
26.Sh NAME
27.Nm CAN
28.Nd CAN Protocol
29.Sh SYNOPSIS
30.In sys/socket.h
31.In netcan/can.h
32.Ft int
33.Fn socket AF_CAN SOCK_RAW CAN_RAW
34.Sh DESCRIPTION
35.Nm
36is the network layer protocol used on top of CAN bus networks.
37At this time only the
38.Dv SOCK_RAW
39socket type is supported.
40This protocol layer is intended to be compatible with the Linux SocketCAN implementation.
41.Ss ADDRESSING
42A CAN frame consists of a 11 bits (standard frame format) or 29 bits
43(extended frame format) identifier, followed by up to 8 data bytes.
44The interpretation of the identifier is application-dependent, the CAN
45standard itself doesn't define an addressing.
46.Pp
47The
48.Nm
49layer uses a 32bits identifier.
50The 3 upper bits are used as control flags.
51The extended frame format is selected by setting the
52.Dv CAN_EFF_FLAG
53control bit.
54.Pp
55The socket address is defined as
56.Bd -literal
57struct sockaddr_can {
58        u_int8_t        can_len;
59        sa_family_t     can_family;
60        int             can_ifindex;
61        union {
62                /* transport protocol class address information */
63                struct { canid_t rx_id, tx_id; } tp;
64                /* reserved for future CAN protocols address information */
65        } can_addr;
66};
67.Ed
68For CAN raw sockets, the 32bits identifier is part of the message data.
69The can_addr field of the sockaddr structure is not used.
70.Ss MESSAGE
71Raw CAN sockets use fixed-length messages defined as follow:
72.Bd -literal
73struct can_frame {
74        canid_t can_id; /* ID + EFF/RTR/ERR flags */
75        uint8_t can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
76        uint8_t __pad;
77        uint8_t __res0;
78        uint8_t __res1;
79        uint8_t data[CAN_MAX_DLEN] __aligned(8);
80};
81.Ed
82The lower 11 bits (for standard frames) or 29 bits (for extended frames) are
83used as the on-wire identifier.
84The
85.Dv CAN_EFF_FLAG
86bit is set in can_id for extended frames.
87The
88.Dv CAN_RTR_FLAG
89bit is set in can_id for remote transmission request frames.
90.Sh SEE ALSO
91.Xr socket 2 ,
92.Xr canloop 4 ,
93.Xr netintro 4 ,
94.Xr canconfig 8 ,
95.Pa /usr/include/netcan/can.h
96.Pp
97.Lk https://en.wikipedia.org/wiki/SocketCAN "SocketCAN - Wikipedia"
98.Lk https://www.kernel.org/doc/Documentation/networking/can.txt "Readme file for the Controller Area Network Protocol Family"
99.Sh HISTORY
100The
101.Nm
102protocol appeared in
103.Nx 8.0 .
104.Sh BUGS
105.Dv CANFD
106and error frames are not implemented.
107