1 .\" $NetBSD: bt_dev.3,v 1.1 2009/08/03 15:59:42 plunky Exp $
3 .\" Copyright (c) 2009 The NetBSD Foundation, Inc.
4 .\" All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
15 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
40 .Nm bt_devfilter_pkt_set ,
41 .Nm bt_devfilter_pkt_clr ,
42 .Nm bt_devfilter_pkt_tst ,
43 .Nm bt_devfilter_evt_set ,
44 .Nm bt_devfilter_evt_clr ,
45 .Nm bt_devfilter_evt_tst ,
47 .Nd Bluetooth device access routines
53 .Fn bt_devaddr "const char *name" "bdaddr_t *bdaddr"
55 .Fn bt_devname "char *name" "const bdaddr_t *bdaddr"
57 .Fn bt_devenum "int (*cb)(int, const struct bt_devinfo *, void *)" "void *arg"
59 .Fn bt_devinfo "const char *name" "struct bt_devinfo *info"
61 .Fn bt_devopen "const char *name" "int flags"
63 .Fn bt_devsend "int s" "uint16_t opcode" "void *param" "size_t plen"
65 .Fn bt_devrecv "int s" "void *buf" "size_t size" "time_t timeout"
67 .Fn bt_devreq "int s" "struct bt_devreq *req" "time_t timeout"
69 .Fn bt_devfilter "int s" "const struct bt_devfilter *new" "struct bt_devfilter *old"
71 .Fn bt_devfilter_pkt_set "struct bt_devfilter *filter" "uint8_t type"
73 .Fn bt_devfilter_pkt_clr "struct bt_devfilter *filter" "uint8_t type"
75 .Fn bt_devfilter_pkt_tst "const struct bt_devfilter *filter" "uint8_t type"
77 .Fn bt_devfilter_evt_set "struct bt_devfilter *filter" "uint8_t event"
79 .Fn bt_devfilter_evt_clr "struct bt_devfilter *filter" "uint8_t event"
81 .Fn bt_devfilter_evt_tst "const struct bt_devfilter *filter" "uint8_t event"
83 .Fn bt_devinquiry "const char *name" "time_t timeout" "int max_rsp" "struct bt_devinquiry **iip"
85 These routines are designed to provide access to locally configured Bluetooth
86 devices in an operating system independent manner via a socket providing access
87 to Bluetooth HCI packets.
90 .It Fn bt_devaddr "name" "bdaddr"
91 Return a Bluetooth device address.
93 will return 1 if the NUL-terminated
95 string refers to a Bluetooth device present in the system, otherwise 0.
96 The name may be given as a device name
98 or Bluetooth device address
99 .Pq eg Qo 00:11:22:33:44:55 Qc
100 and the actual device address will be written to
104 .It Fn bt_devname "name" "bdaddr"
105 Return a Bluetooth device name.
109 refers to a Bluetooth device present in the system, otherwise 0.
112 buffer, if given, should have space for at least
114 bytes and the string will be NUL-terminated.
115 .It Fn bt_devenum "cb" "arg"
116 Enumerate Bluetooth devices present in the system.
117 For each device found, the
121 will be called with the
123 argument provided, a fully populated
125 structure and, where the device is enabled, a socket handle as returned by
127 The callback function can halt the enumeration by returning a
130 returns the number of successfully enumerated devices.
131 .It Fn bt_devinfo "name" "info"
132 Obtain information from a Bluetooth device present in the system.
135 argument is a pointer to a
137 structure into which information about device
142 structure contains at least the following members:
144 char devname[HCI_DEVNAME_SIZE];
145 int enabled; /* device is enabled */
147 /* device information */
149 uint8_t features[HCI_FEATURES_SIZE];
150 uint16_t acl_size; /* max ACL data size */
151 uint16_t acl_pkts; /* total ACL packet buffers */
152 uint16_t sco_size; /* max SCO data size */
153 uint16_t sco_pkts; /* total SCO packet buffers */
156 uint16_t cmd_free; /* available CMD packet buffers */
157 uint16_t acl_free; /* available ACL packet buffers */
158 uint16_t sco_free; /* available ACL packet buffers */
170 /* device settings */
171 uint16_t link_policy_info;
172 uint16_t packet_type_info;
173 uint16_t role_switch_info;
176 Because a Bluetooth device must be enabled in order to retrieve
179 flag should be tested to be non-zero before relying on further data.
180 .It Fn bt_devopen "name" "flags"
181 Return a Bluetooth HCI socket handle bound and connected to the
182 named Bluetooth device or, if
186 enabled to receive packets from any device.
187 The socket should be closed using
190 Any combination of the following
192 may be used to pre-set the socket options:
193 .Bl -tag -width ".Dv BTOPT_DIRECTION"
194 .It Dv BTOPT_DIRECTION
195 Enable control messages on each packet indicating the direction of travel.
196 .It Dv BTOPT_TIMESTAMP
197 Enable control messages providing packet timestamps.
200 The default filter on the socket will only allow the HCI Event packets
205 .It Fn bt_devsend "s" "opcode" "param" "plen"
206 Send an HCI command packet on the socket
210 should be in host byte order and the
214 arguments can be used to provide command parameter data.
216 will return the number of bytes successfully written.
217 .It Fn bt_devrecv "s" "buf" "size" "timeout"
218 Receive a single HCI packet on the socket
221 will return the number of bytes successfully received unless the
222 provided buffer could not contain the entire packet, or if a timeout was
223 requested with a non-negative
226 .It Fn bt_devreq "s" "req" "timeout"
227 Make an HCI request on the socket
231 argument is a pointer to a
233 structure, defined as:
234 .Bd -literal -offset indent
246 sends an HCI command packet with the given
248 and command parameters of
254 seconds for the command to return a
257 In the case where the command returns
259 and an additional event, and where the status indicates
260 that the command is in progress,
262 will wait for the additional
264 specified in the request.
265 If required, any response will be copied into the buffer of
271 will be adjusted to indicate the number of bytes stored.
273 temporarily modifies the socket filter.
274 .It Fn bt_devfilter "s" "new" "old"
275 Update or extract the packet filter on HCI socket
277 Filters can be set to indicate packet types
278 .Pq Commands, Events, ACL and SCO data ,
279 and individual event IDs.
282 is given, the currently set filter will be extracted first, then if
284 is given, the filter will be updated.
285 .It Fn bt_devfilter_pkt_set "filter" "type"
290 .It Fn bt_devfilter_pkt_clr "filter" "type"
295 .It Fn bt_devfilter_pkt_tst "filter" "type"
301 .It Fn bt_devfilter_evt_set "filter" "event"
306 .It Fn bt_devfilter_evt_clr "filter" "event"
311 .It Fn bt_devfilter_evt_tst "filter" "event"
317 .It Fn bt_devinquiry "name" "timeout" "max_rsp" "iip"
318 Perform a Bluetooth Inquiry using the device
320 or the first available device if
323 The inquiry length will be
325 seconds, and the number of responses
326 .Pq up to a limit of Fa max_rsp
328 A pointer to an array of
330 structures, defined as:
331 .Bd -literal -offset indent
332 struct bt_devinquiry {
334 uint8_t pscan_rep_mode;
335 uint8_t pscan_period_mode;
336 uint8_t dev_class[3];
337 uint16_t clock_offset;
343 will be stored in the location given by
345 and this should be released after use with
349 These Bluetooth device access routines return \-1 on failure, and
351 will be set to indicate the error.
353 In addition to errors returned by the standard C library IO functions,
354 the following errors may be indicated by device access routines.
355 .Bl -tag -offset indent -width ".Bq Er ETIMEDOUT"
357 A provided function argument was not valid.
359 A device response was not properly understood.
361 An operation exceeded the given time limit.
366 The Bluetooth device access API was created by
368 and first appeared in
370 This implementation written for