blob: 29b0047b4b648a58a3d7ac3ab08b0fa8c09a8bc3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
<table class="head">
<tr>
<td class="head-ltitle">CAN(4)</td>
<td class="head-vol">Device Drivers Manual</td>
<td class="head-rtitle">CAN(4)</td>
</tr>
</table>
<div class="manual-text">
<section class="Sh">
<h1 class="Sh" id="NAME"><a class="permalink" href="#NAME">NAME</a></h1>
<p class="Pp"><code class="Nm">CAN</code> — <span class="Nd">CAN
Protocol</span></p>
</section>
<section class="Sh">
<h1 class="Sh" id="SYNOPSIS"><a class="permalink" href="#SYNOPSIS">SYNOPSIS</a></h1>
<p class="Pp"><code class="In">#include
<<a class="In">sys/socket.h</a>></code>
<br/>
<code class="In">#include <<a class="In">netcan/can.h</a>></code></p>
<p class="Pp"><var class="Ft">int</var>
<br/>
<code class="Fn">socket</code>(<var class="Fa" style="white-space: nowrap;">AF_CAN</var>,
<var class="Fa" style="white-space: nowrap;">SOCK_RAW</var>,
<var class="Fa" style="white-space: nowrap;">CAN_RAW</var>);</p>
</section>
<section class="Sh">
<h1 class="Sh" id="DESCRIPTION"><a class="permalink" href="#DESCRIPTION">DESCRIPTION</a></h1>
<p class="Pp"><code class="Nm">CAN</code> is the network layer protocol used on
top of CAN bus networks. At this time only the
<code class="Dv">SOCK_RAW</code> socket type is supported. This protocol
layer is intended to be compatible with the Linux SocketCAN
implementation.</p>
<section class="Ss">
<h2 class="Ss" id="ADDRESSING"><a class="permalink" href="#ADDRESSING">ADDRESSING</a></h2>
<p class="Pp">A CAN frame consists of a 11 bits (standard frame format) or 29
bits (extended frame format) identifier, followed by up to 8 data bytes. The
interpretation of the identifier is application-dependent, the CAN standard
itself doesn't define an addressing.</p>
<p class="Pp">The <code class="Nm">CAN</code> layer uses a 32bits identifier.
The 3 upper bits are used as control flags. The extended frame format is
selected by setting the <code class="Dv">CAN_EFF_FLAG</code> control
bit.</p>
<p class="Pp">The socket address is defined as</p>
<div class="Bd Pp Li">
<pre>struct sockaddr_can {
u_int8_t can_len;
sa_family_t can_family;
int can_ifindex;
union {
/* transport protocol class address information */
struct { canid_t rx_id, tx_id; } tp;
/* reserved for future CAN protocols address information */
} can_addr;
};</pre>
</div>
For CAN raw sockets, the 32bits identifier is part of the message data. The
can_addr field of the sockaddr structure is not used.
</section>
<section class="Ss">
<h2 class="Ss" id="MESSAGE"><a class="permalink" href="#MESSAGE">MESSAGE</a></h2>
<p class="Pp">Raw CAN sockets use fixed-length messages defined as follow:</p>
<div class="Bd Pp Li">
<pre>struct can_frame {
canid_t can_id; /* ID + EFF/RTR/ERR flags */
uint8_t can_dlc; /* frame payload length in byte (0 .. CAN_MAX_DLEN) */
uint8_t __pad;
uint8_t __res0;
uint8_t __res1;
uint8_t data[CAN_MAX_DLEN] __aligned(8);
};</pre>
</div>
The lower 11 bits (for standard frames) or 29 bits (for extended frames) are
used as the on-wire identifier. The <code class="Dv">CAN_EFF_FLAG</code> bit
is set in can_id for extended frames. The <code class="Dv">CAN_RTR_FLAG</code>
bit is set in can_id for remote transmission request frames.
</section>
</section>
<section class="Sh">
<h1 class="Sh" id="SEE_ALSO"><a class="permalink" href="#SEE_ALSO">SEE
ALSO</a></h1>
<p class="Pp"><a class="Xr">socket(2)</a>, <a class="Xr">canloop(4)</a>,
<a class="Xr">netintro(4)</a>, <a class="Xr">canconfig(8)</a>,
<span class="Pa">/usr/include/netcan/can.h</span></p>
<p class="Pp"><a class="Lk" href="https://en.wikipedia.org/wiki/SocketCAN">SocketCAN
- Wikipedia</a>
<a class="Lk" href="https://www.kernel.org/doc/Documentation/networking/can.txt">Readme
file for the Controller Area Network Protocol Family</a></p>
</section>
<section class="Sh">
<h1 class="Sh" id="HISTORY"><a class="permalink" href="#HISTORY">HISTORY</a></h1>
<p class="Pp">The <code class="Nm">CAN</code> protocol appeared in
<span class="Ux">NetBSD 8.0</span>.</p>
</section>
<section class="Sh">
<h1 class="Sh" id="BUGS"><a class="permalink" href="#BUGS">BUGS</a></h1>
<p class="Pp"><code class="Dv">CANFD</code> and error frames are not
implemented.</p>
</section>
</div>
<table class="foot">
<tr>
<td class="foot-date">May 18, 2017</td>
<td class="foot-os">NetBSD 10.1</td>
</tr>
</table>
|