summaryrefslogtreecommitdiff
path: root/share/man/man4/bluetooth.4
blob: cbdb3de0ebd5a672e90e5466b8e5c53fa176961a (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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
.\"	$OpenBSD: bluetooth.4,v 1.3 2007/09/12 14:12:03 jmc Exp $
.\"	$NetBSD: bluetooth.4,v 1.5 2007/04/21 06:15:22 plunky Exp $
.\"
.\" Copyright (c) 2006 Itronix Inc.
.\" All rights reserved.
.\"
.\" Written by Iain Hibbert for Itronix Inc.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\"    notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\"    notice, this list of conditions and the following disclaimer in the
.\"    documentation and/or other materials provided with the distribution.
.\" 3. The name of Itronix Inc. may not be used to endorse
.\"    or promote products derived from this software without specific
.\"    prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
.\" PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
.\" DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
.\" (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
.\" LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
.\" ON ANY THEORY OF LIABILITY, WHETHER IN
.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
.\" POSSIBILITY OF SUCH DAMAGE.
.\"
.\"
.Dd $Mdocdate: September 12 2007 $
.Dt BLUETOOTH 4
.Os
.Sh NAME
.Nm bluetooth
.Nd Bluetooth protocol family
.Sh SYNOPSIS
.In netbt/bluetooth.h
.In netbt/hci.h
.In netbt/l2cap.h
.In netbt/rfcomm.h
.Sh DESCRIPTION
Bluetooth protocol family sockets all use a
.Ar sockaddr_bt
structure which contains a Bluetooth Device Address (BDADDR).
This consists of a six byte string in least significant byte
first order.
.Bd -literal -offset -indent
struct sockaddr_bt {
	uint8_t		bt_len;
	sa_family_t	bt_family;
	bdaddr_t	bt_bdaddr;
	uint16_t	bt_psm;
	uint8_t		bt_channel;
};
.Ed
.Pp
The local address used by the socket can be set with
.Xr bind 2 .
.Sh PROTOCOLS
Protocols included are:
.Bl -tag -width XX
.It Cm BTPROTO_HCI
This gives raw access to the Host Controller Interface of local devices
using the HCI protocol as described in the Bluetooth Core Specification.
Any user may open an HCI socket but there are limitations on what
unprivileged users can send and receive.
The local address specified by
.Xr bind 2
may be used to select the device that the socket will receive packets from.
If
.Dv BDADDR_ANY
is specified then the socket will receive packets from all
devices on the system.
.Xr connect 2
may be used to create connections such that packets sent with
.Xr send 2
will be delivered to the specified device, otherwise
.Xr sendto 2
should be used.
.Pp
The
.Ar bt_psm
and
.Ar bt_channel
fields in the sockaddr_bt structure are ignored by HCI protocol code
and should be set to zero.
.Pp
HCI socket options:
.Bl -tag -width XX
.It Dv SO_HCI_EVT_FILTER Op Ar struct hci_filter
This filter controls which events will be recieved at the socket.
See
.Aq Pa netbt/hci.h
for available events.
By default, only Command_Complete and Command_Status
events are enabled.
.It Dv SO_HCI_PKT_FILTER Op Ar struct hci_filter
This filter controls the type of packets that will be received at the
socket.
By default, only Event packets are enabled.
.It Dv SO_HCI_DIRECTION Op Ar int
When set, this enables control messages on packets received at the socket
indicating the direction of travel of the packet.
.El
.Pp
HCI
.Xr sysctl 8
controls:
.Bl -tag -width XXX
.It Dv net.bluetooth.hci.sendspace
Default send buffer size for HCI sockets.
.It Dv net.bluetooth.hci.recvspace
Default receive buffer size for HCI sockets.
.It Dv net.bluetooth.hci.acl_expiry
If set, this is the time in seconds after which unused ACL data connections
will be expired.
If zero, connections will not be closed.
.It Dv net.bluetooth.hci.memo_expiry
Time, in seconds, that the system will keep records of Bluetooth devices
in the vicinity after an Inquiry Response packet has been recieved.
This information is used for routing purposes.
.It Dv net.bluetooth.hci.eventq_max
The maximum number of packets on the low level Event queue.
.It Dv net.bluetooth.hci.aclrxq_max
The maximum number of packets on the low level ACL queue.
.It Dv net.bluetooth.hci.scorxq_max
The maximum number of packets on the low level SCO queue.
.El
.It Cm BTPROTO_L2CAP
L2CAP sockets give sequential packet access over channels to other Bluetooth
devices and make use of the
.Ar bt_psm
field in the
.Ar sockaddr_bt
structure to select the Protocol/Service Multiplexer to specify when making
connections.
.Pp
L2CAP socket options:
.Bl -tag -width XXX
.It Dv SO_L2CAP_IMTU Op Ar uint16_t
Incoming MTU.
.It Dv SO_L2CAP_OMTU Op Ar uint16_t
Outgoing MTU (read-only).
.It Dv SO_L2CAP_LM Op Ar int
Link Mode.
The following bits may be set:
.Pp
.Bl -tag -compact -width ".Dv L2CAP_LM_ENCRYPT"
.It Dv L2CAP_LM_AUTH
Request authentication
.Pq pairing .
.It Dv L2CAP_LM_ENCRYPT
Request encryption
.Pq includes auth .
.It Dv L2CAP_LM_SECURE
Request secured link
.Pq encryption, plus change link key .
.El
.Pp
Link mode settings will be applied to the baseband link during L2CAP
connection establishment.
If the L2CAP connection is already established,
.Dv EINPROGRESS
may be returned, and it is not possible to guarantee that data already queued
.Pq from either end
will not be delivered.
If the mode change fails, the L2CAP connection will be aborted.
.El
.Pp
L2CAP
.Xr sysctl 8
controls:
.Bl -tag -width XXX
.It Dv net.bluetooth.l2cap.sendspace
Default send buffer size for L2CAP sockets.
.It Dv net.bluetooth.l2cap.recvspace
Default receive buffer size for L2CAP sockets.
.It Dv net.bluetooth.l2cap.rtx
Response Timeout eXpiry for L2CAP signals.
.It Dv net.bluetooth.l2cap.ertx
Extended Response Timeout eXpiry for L2CAP signals.
.El
.It Cm BTPROTO_RFCOMM
RFCOMM sockets provide streamed data over Bluetooth connections
and make use of the
.Ar bt_psm
and
.Ar bt_channel
fields in the
.Ar sockaddr_bt
structure.
The channel number must be between 1 and 30 inclusive.
If no PSM is specified, a default value of
.Dv L2CAP_PSM_RFCOMM
(0x0003) will be used.
.Pp
RFCOMM socket options:
.Bl -tag -width XXX
.It Dv SO_RFCOMM_MTU Op Ar uint16_t
Maximum Frame Size to use for this link.
.It Dv SO_RFCOMM_LM Op Ar int
Link Mode.
The following bits may be set at any time:
.Pp
.Bl -tag -compact -width ".Dv RFCOMM_LM_ENCRYPT"
.It Dv RFCOMM_LM_AUTH
Request authentication
.Pq pairing .
.It Dv RFCOMM_LM_ENCRYPT
Request encryption
.Pq includes auth .
.It Dv RFCOMM_LM_SECURE
Request secured link
.Pq encryption, plus change link key .
.El
.Pp
Link mode settings will be applied to the baseband link during RFCOMM
connection establishment.
If the RFCOMM connection is already established,
.Dv EINPROGRESS
may be returned, and it is not possible to guarantee that data already queued
.Pq from either end
will not be delivered.
If the mode change fails, the RFCOMM connection will be aborted.
.El
.Pp
RFCOMM
.Xr sysctl 8
controls:
.Bl -tag -width XXX
.It Dv net.bluetooth.rfcomm.sendspace
Default send buffer size for RFCOMM sockets.
.It Dv net.bluetooth.rfcomm.recvspace
Default receive buffer size for RFCOMM sockets.
.It Dv net.bluetooth.rfcomm.default_mtu
Maximum Frame Size (N1).
.It Dv net.bluetooth.ack_timeout
Acknowledgement Timer (T1).
.It Dv net.bluetooth.mcc_timeout
Response Timer for Multiplexer Control Channel (T2).
.El
.It Cm BTPROTO_SCO
SCO sockets provide sequential packet access to time sensitive data
channels over Bluetooth connections, typically used for audio data.
.Pp
SCO socket options:
.Bl -tag -width XXX
.It Dv SO_SCO_MTU Op Ar uint16_t
Maximum packet size for use on this link.
This is read-only and will be set by the protocol code when a connection is made.
Currently, due to limitations in the
.Xr ubt 4
driver, the SCO protocol code will only accept packets with
exactly this size.
.It Dv SO_SCO_HANDLE Op Ar uint16_t
Connection handle for this link.
This is read-only and provided for informational purposes only.
.El
.Pp
SCO
.Xr sysctl 8
controls:
.Bl -tag -width XXX
.It Dv net.bluetooth.sco.sendspace
Default send buffer size for SCO sockets.
.It Dv net.bluetooth.sco.recvspace
Default receive buffer size for SCO sockets.
.El
.El
.Sh INFORMATION
The following
.Xr ioctl 2
calls may be used to manipulate Bluetooth devices.
The
.Xr ioctl 2
must be made on
.Cm BTPROTO_HCI
sockets.
All of the requests take a
.Ar btreq
structure defined as follows as their parameter and unless otherwise
specified, use the
.Ar btr_name
field to identify the device.
.Bd -literal -offset
struct btreq {
    char btr_name[HCI_DEVNAME_SIZE];	/* device name */

    union {
	struct {
	    bdaddr_t btri_bdaddr;	/* device bdaddr */
	    uint16_t btri_flags;	/* flags */
	    uint16_t btri_num_cmd;	/* # of free cmd buffers */
	    uint16_t btri_num_acl;	/* # of free ACL buffers */
	    uint16_t btri_num_sco;	/* # of free SCO buffers */
	    uint16_t btri_acl_mtu;	/* ACL mtu */
	    uint16_t btri_sco_mtu;	/* SCO mtu */
	    uint16_t btri_link_policy;	/* Link Policy */
	    uint16_t btri_packet_type;	/* Packet Type */
	} btri;
	struct bt_stats btrs;   /* unit stats */
    } btru;
};

#define btr_flags	btru.btri.btri_flags
#define btr_bdaddr	btru.btri.btri_bdaddr
#define btr_num_cmd	btru.btri.btri_num_cmd
#define btr_num_acl	btru.btri.btri_num_acl
#define btr_num_sco	btru.btri.btri_num_sco
#define btr_acl_mtu	btru.btri.btri_acl_mtu
#define btr_sco_mtu	btru.btri.btri_sco_mtu
#define btr_link_policy btru.btri.btri_link_policy
#define btr_packet_type btru.btri.btri_packet_type
#define btr_stats	btru.btrs

/* btr_flags */
#define BTF_UP			(1\*[Lt]\*[Lt]0)	/* unit is up */
#define BTF_RUNNING		(1\*[Lt]\*[Lt]1)	/* unit is running */
#define BTF_XMIT_CMD		(1\*[Lt]\*[Lt]2)	/* transmitting CMD packets */
#define BTF_XMIT_ACL		(1\*[Lt]\*[Lt]3)	/* transmitting ACL packets */
#define BTF_XMIT_SCO		(1\*[Lt]\*[Lt]4)	/* transmitting SCO packets */
#define BTF_INIT_BDADDR		(1\*[Lt]\*[Lt]5)	/* waiting for bdaddr */
#define BTF_INIT_BUFFER_SIZE	(1\*[Lt]\*[Lt]6)	/* waiting for buffer size */
#define BTF_INIT_FEATURES	(1\*[Lt]\*[Lt]7)	/* waiting for features */

struct bt_stats {
	uint32_t	err_tx;
	uint32_t	err_rx;
	uint32_t	cmd_tx;
	uint32_t	evt_rx;
	uint32_t	acl_tx;
	uint32_t	acl_rx;
	uint32_t	sco_tx;
	uint32_t	sco_rx;
	uint32_t	byte_tx;
	uint32_t	byte_rx;
};

.Ed
.Bl -tag -width SIOCGBTPOLICY
.It Dv SIOCGBTINFO
Get Bluetooth device info.
Given the device name, fill in the
btreq structure including the address field for use with socket addressing
as above.
.It Dv SIOCGBTINFOA
Get Bluetooth device info from address.
Given the device address, fill in the
btreq structure including the name field.
.It Dv SIOCNBTINFO
Next Bluetooth device info.
If the name field is empty, the first device
will be returned.
Otherwise, the next device will be returned.
This can be used to
cycle through all devices in the system.
.It Dv SIOCSBTFLAGS
Set Bluetooth device flags.
Not all flags can be set.
.It Dv SIOCSBTPOLICY
Set Bluetooth device link policy.
Link policy bits are defined in
.Aq Pa netbt/hci.h ,
though bits can only be set if the device supports it.
.It Dv SIOCSBTPTYPE
Set Bluetooth device packet types.
Only packet types
that the device supports
can be set.
.It Dv SIOCGBTSTATS
Read device statistics.
.It Dv SIOCZBTSTATS
Read device statistics, and zero them.
.El
.Pp
Only the super-user may change device configurations.
.Sh SEE ALSO
.Xr bind 2 ,
.Xr getsockname 2 ,
.Xr options 4 ,
.Xr ubt 4
.Sh HISTORY
The Bluetooth protocol stack was written for
.Nx 4.0
by
.An Iain Hibbert
under the sponsorship of Itronix, Inc. and
ported to
.Ox 4.2
by
.An Uwe Stuehler Aq uwe@openbsd.org .