1 .\" Copyright (c) 2003-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com>
2 .\" All rights reserved.
4 .\" Redistribution and use in source and binary forms, with or without
5 .\" modification, are permitted provided that the following conditions
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.
13 .\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 .\" $Id: bluetooth.3,v 1.5 2003/05/20 23:04:30 max Exp $
32 .Nm bt_gethostbyname ,
33 .Nm bt_gethostbyaddr ,
37 .Nm bt_getprotobyname ,
38 .Nm bt_getprotobynumber ,
54 .Nm bt_devfilter_pkt_set ,
55 .Nm bt_devfilter_pkt_clr ,
56 .Nm bt_devfilter_pkt_tst ,
57 .Nm bt_devfilter_evt_set ,
58 .Nm bt_devfilter_evt_clr ,
59 .Nm bt_devfilter_evt_tst ,
64 .Nd Bluetooth routines
70 .Fn bt_gethostbyname "const char *name"
72 .Fn bt_gethostbyaddr "const char *addr" "int len" "int type"
74 .Fn bt_gethostent void
76 .Fn bt_sethostent "int stayopen"
78 .Fn bt_endhostent void
80 .Fn bt_getprotobyname "const char *name"
82 .Fn bt_getprotobynumber "int proto"
84 .Fn bt_getprotoent void
86 .Fn bt_setprotoent "int stayopen"
88 .Fn bt_endprotoent void
90 .Fn bt_aton "const char *str" "bdaddr_t *ba"
92 .Fn bt_ntoa "const bdaddr_t *ba" "char *str"
94 .Fn bt_devaddr "const char *devname" "bdaddr_t *addr"
96 .Fn bt_devname "char *devname" "const bdaddr_t *addr"
98 .Fn (bt_devenum_cb_t) "int s" "struct bt_devinfo const *di" "void *arg"
100 .Fn bt_devinfo "struct bt_devinfo *di"
102 .Fn bt_devenum "bt_devenum_cb_t *cb" "void *arg"
104 .Fn bt_devopen "char const *devname"
106 .Fn bt_devclose "int s"
108 .Fn bt_devsend "int s" "uint16_t opcode" "void *param" "size_t plen"
110 .Fn bt_devrecv "int s" "void *buf" "size_t size" "time_t to"
112 .Fn bt_devreq "int s" "struct bt_devreq *r" "time_t to"
114 .Fn bt_devfilter "int s" "struct bt_devfilter const *new" "struct bt_devfilter *old"
116 .Fn bt_devfilter_pkt_set "struct bt_devfilter *filter" "uint8_t type"
118 .Fn bt_devfilter_pkt_clt "struct bt_devfilter *filter" "uint8_t type"
120 .Fn bt_devfilter_pkt_tst "struct bt_devfilter const *filter" "uint8_t type"
122 .Fn bt_devfilter_evt_set "struct bt_devfilter *filter" "uint8_t event"
124 .Fn bt_devfilter_evt_clt "struct bt_devfilter *filter" "uint8_t event"
126 .Fn bt_devfilter_evt_tst "struct bt_devfilter const *filter" "uint8_t event"
128 .Fn bt_devinquiry "char const *devname" "time_t length" "int num_rsp" "struct bt_devinquiry **ii"
130 .Fn bdaddr_same "const bdaddr_t *a" "const bdaddr_t *b"
132 .Fn bdaddr_any "const bdaddr_t *a"
134 .Fn bdaddr_copy "const bdaddr_t *dst" "const bdaddr_t *src"
142 each return a pointer to an object with the
144 structure describing a Bluetooth host
145 referenced by name or by address, respectively.
152 .Dv NUL Ns -terminated
158 should point to an address which is
162 (i.e., not a Bluetooth BD_ADDR in human readable
167 argument specifies the address family of this address and must be set to
170 The structure returned contains the information obtained from a line in
171 .Pa /etc/bluetooth/hosts
176 function controls whether
177 .Pa /etc/bluetooth/hosts
178 file should stay open after each call to
181 .Fn bt_gethostbyaddr .
184 flag is non-zero, the file will not be closed.
189 .Pa /etc/bluetooth/hosts
194 .Fn bt_getprotobyname
196 .Fn bt_getprotobynumber
197 functions each return a pointer to an object with the
199 structure describing a Bluetooth Protocol Service Multiplexor referenced
200 by name or number, respectively.
205 .Fn bt_getprotobyname
207 .Dv NUL Ns -terminated
208 Bluetooth Protocol Service Multiplexor name.
212 .Fn bt_getprotobynumber
213 should have numeric value of the desired Bluetooth Protocol Service Multiplexor.
215 The structure returned contains the information obtained from a line in
216 .Pa /etc/bluetooth/protocols
221 function controls whether
222 .Pa /etc/bluetooth/protocols
223 file should stay open after each call to
224 .Fn bt_getprotobyname
226 .Fn bt_getprotobynumber .
229 flag is non-zero, the file will not be closed.
234 .Pa /etc/bluetooth/protocols
239 routine interprets the specified character string as a Bluetooth address,
240 placing the address into the structure provided.
241 It returns 1 if the string was successfully interpreted,
242 or 0 if the string is invalid.
246 takes a Bluetooth address and places an
248 string representing the address into the buffer provided.
249 It is up to the caller to ensure that provided buffer has enough space.
250 If no buffer was provided then internal static buffer will be used.
254 function interprets the specified
256 string as the address or device name of a Bluetooth device on the local system,
257 and places the device address in the provided
260 The function returns 1 if the string was successfully interpreted,
261 or 0 if the string did not match any local device.
264 function takes a Bluetooth device address and copies the local device
265 name associated with that address into the buffer provided,
267 Caller must ensure that provided buffer is at least
270 The function returns 1 when the device was found,
275 function populates provided
277 structure with the information about given Bluetooth device.
278 The caller is expected to pass Bluetooth device name in the
283 The function returns 0 when successful,
287 structure is defined as follows
288 .Bd -literal -offset indent
291 char devname[HCI_DEVNAME_SIZE];
298 uint8_t features[HCI_DEVFEATURES_SIZE];
321 uint16_t link_policy_info;
322 uint16_t packet_type_info;
323 uint16_t role_switch_info;
326 uint8_t _padding[20];
332 function enumerates Bluetooth devices present in the system.
333 For every device found,
334 the function will call provided
336 callback function which should be of
339 The callback function is passed a
349 argument provided to the
351 The callback function can stop enumeration by returning a value
352 that is greater than zero.
353 The function returns number of successfully enumerated devices,
354 or -1 if an error occurred.
358 function opens a Bluetooth device with the given
360 and returns a connected and bound
363 The function returns -1 if an error has occurred.
371 previously obtained with
376 function sends a Bluetooth
378 command with the given
380 to the provided socket
382 previously obtained with
386 parameter is expected to be in the host byte order.
391 parameters specify command parameters.
394 function does not modify the
396 filter on the provided socket
398 The function returns 0 on success,
399 or -1 if an error occurred.
403 function receives one Bluetooth
405 packet from the socket
407 previously obtained with
409 The packet is placed into the provided buffer
415 parameter specifies receive timeout in seconds.
416 Infinite timeout can be specified by passing negative value in the
421 function does not modify the
423 filter on the provided socket
425 The function returns total number of bytes received,
426 or -1 if an error occurred.
430 function makes a Bluetooth
432 request to the socket
434 previously obtained with
436 The function will send the specified command and will wait for the specified
443 structure is defined as follows
444 .Bd -literal -offset indent
458 field specifies the command and is expected to be in the host byte order.
463 fields specify command parameters data and command parameters data size
467 field specifies which Bluetooth
469 event ID the function should wait for, otherwise it should be set to zero.
472 Command Complete and Command Status events are enabled by default.
477 parameters specify buffer and buffer size respectively where return
478 parameters should be placed.
481 function temporarily modifies filter on the provided
485 The function returns 0 on success, or -1 if an error occurred.
491 filter associated with the socket
493 previously obtained with
495 Filtering can be done on packet types, i.e.
499 command and event packets, and, in addition, on
504 filter (if provided) the function will try to obtain the current filter
507 and place it into the
509 parameter (if provided).
510 The function returns 0 on success, or -1 if an error occurred.
513 .Fn bt_devfilter_pkt_set ,
514 .Fn bt_devfilter_pkt_clr
516 .Fn bt_devfilter_pkt_tst
517 functions can be used to modify and test the
528 .Fn bt_devfilter_evt_set ,
529 .Fn bt_devfilter_evt_clr
531 .Fn bt_devfilter_evt_tst
532 functions can be used to modify and test the
544 function performs Bluetooth inquiry.
547 parameter specifies which local Bluetooth device should perform an inquiry.
548 If not specified, i.e.
550 then first available device will be used.
553 parameters specifies the total length of an inquiry in seconds.
554 If not specified, i.e. 0, default value will be used.
557 parameter specifies the number of responses that can be received before
558 the inquiry is halted.
559 If not specified, i.e. 0, default value will be used.
562 parameter specifies where to place inquiry results.
563 On success, the function will return total number of inquiry results,
567 buffer to store all the inquiry results and
568 will return pointer to the allocated buffer in the
571 It is up to the caller of the function to dispose of the buffer using
574 The function returns -1 if an error has occurred.
577 structure is defined as follows
578 .Bd -literal -offset indent
579 struct bt_devinquiry {
581 uint8_t pscan_rep_mode;
582 uint8_t pscan_period_mode;
583 uint8_t dev_class[3];
584 uint16_t clock_offset;
595 are handy shorthand Bluetooth address utility functions.
598 function will test if two provided BD_ADDRs are the same.
601 function will test if provided BD_ADDR is
606 function will copy provided
608 BD_ADDR into provided
612 .Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
613 .It Pa /etc/bluetooth/hosts
614 .It Pa /etc/bluetooth/protocols
617 Print out the hostname associated with a specific BD_ADDR:
618 .Bd -literal -offset indent
619 const char *bdstr = "00:01:02:03:04:05";
623 if (!bt_aton(bdstr, &bd))
624 errx(1, "can't parse BD_ADDR %s", bdstr);
626 if ((hp = bt_gethostbyaddr((const char *)&bd,
627 sizeof(bd), AF_BLUETOOTH)) == NULL)
628 errx(1, "no name associated with %s", bdstr);
630 printf("name associated with %s is %s\en", bdstr, hp->h_name);
633 Error return status from
638 is indicated by return of a
643 may then be checked to see whether this is a temporary failure
644 or an invalid or unknown host.
647 can be used to print an error message describing the failure.
652 it is printed, followed by a colon and a space.
653 The error message is printed with a trailing newline.
657 can have the following values:
658 .Bl -tag -width ".Dv HOST_NOT_FOUND"
659 .It Dv HOST_NOT_FOUND
660 No such host is known.
662 Some unexpected server failure was encountered.
663 This is a non-recoverable error.
668 .Fn bt_getprotobyname
670 .Fn bt_getprotobynumber
675 .Xr gethostbyaddr 3 ,
676 .Xr gethostbyname 3 ,
677 .Xr getprotobyname 3 ,
678 .Xr getprotobynumber 3 ,
686 function reads the next line of
687 .Pa /etc/bluetooth/hosts ,
688 opening the file if necessary.
692 function opens and/or rewinds the
693 .Pa /etc/bluetooth/hosts
698 function reads the next line of
699 .Pa /etc/bluetooth/protocols ,
700 opening the file if necessary.
704 function opens and/or rewinds the
705 .Pa /etc/bluetooth/protocols
710 function enumerates up to
713 During enumeration the
715 function uses the same
718 The function guarantees that the socket,
719 passed to the callback function,
720 will be bound and connected to the Bluetooth device being enumerated.
722 .An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
724 Some of those functions use static data storage;
725 if the data is needed for future use, it should be
726 copied before any subsequent calls overwrite it.