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 exppected 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 recevied,
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.
500 command and event packets, and, in addition, on
505 filter (if provided) the function will try to obtain the current filter
508 and place it into the
510 parameter (if provided).
511 The function returns 0 on success, or -1 if an error occurred.
514 .Fn bt_devfilter_pkt_set ,
515 .Fn bt_devfilter_pkt_clr
517 .Fn bt_devfilter_pkt_tst
518 functions can be used to modify and test the
529 .Fn bt_devfilter_evt_set ,
530 .Fn bt_devfilter_evt_clr
532 .Fn bt_devfilter_evt_tst
533 functions can be used to modify and test the
545 function performs Bluetooth inquiry.
548 parameter specifies which local Bluetooth device should perform an inquiry.
549 If not secified, i.e.
551 then first available device will be used.
554 parameters specifies the total length of an inquiry in seconds.
555 If not specified, i.e. 0, default value will be used.
558 parameter specifies the number of responses that can be received before
559 the inquiry is halted.
560 If not specified, i.e. 0, default value will be used.
563 parameter specifies where to place inquiry results.
564 On success, the function will return total number of inquiry results,
568 buffer to store all the inquiry results and
569 will return pointer to the allocated buffer in the
572 It is up to the caller of the function to dispose of the buffer using
575 The function returns -1 if an error has occurred.
578 structure is defined as follows
579 .Bd -literal -offset indent
580 struct bt_devinquiry {
582 uint8_t pscan_rep_mode;
583 uint8_t pscan_period_mode;
584 uint8_t dev_class[3];
585 uint16_t clock_offset;
596 are handy shorthand Bluetooth address utility functions.
599 function will test if two provided BD_ADDRs are the same.
602 function will test if provided BD_ADDR is
607 function will copy provided
609 BD_ADDR into provided
613 .Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
614 .It Pa /etc/bluetooth/hosts
615 .It Pa /etc/bluetooth/protocols
618 Print out the hostname associated with a specific BD_ADDR:
619 .Bd -literal -offset indent
620 const char *bdstr = "00:01:02:03:04:05";
624 if (!bt_aton(bdstr, &bd))
625 errx(1, "can't parse BD_ADDR %s", bdstr);
627 if ((hp = bt_gethostbyaddr((const char *)&bd,
628 sizeof(bd), AF_BLUETOOTH)) == NULL)
629 errx(1, "no name associated with %s", bdstr);
631 printf("name associated with %s is %s\en", bdstr, hp->h_name);
634 Error return status from
639 is indicated by return of a
644 may then be checked to see whether this is a temporary failure
645 or an invalid or unknown host.
648 can be used to print an error message describing the failure.
653 it is printed, followed by a colon and a space.
654 The error message is printed with a trailing newline.
658 can have the following values:
659 .Bl -tag -width ".Dv HOST_NOT_FOUND"
660 .It Dv HOST_NOT_FOUND
661 No such host is known.
663 Some unexpected server failure was encountered.
664 This is a non-recoverable error.
669 .Fn bt_getprotobyname
671 .Fn bt_getprotobynumber
676 .Xr gethostbyaddr 3 ,
677 .Xr gethostbyname 3 ,
678 .Xr getprotobyname 3 ,
679 .Xr getprotobynumber 3 ,
687 function reads the next line of
688 .Pa /etc/bluetooth/hosts ,
689 opening the file if necessary.
693 function opens and/or rewinds the
694 .Pa /etc/bluetooth/hosts
699 function reads the next line of
700 .Pa /etc/bluetooth/protocols ,
701 opening the file if necessary.
705 function opens and/or rewinds the
706 .Pa /etc/bluetooth/protocols
711 function enumerates up to
714 During enumeration the
716 function uses the same
719 The function guarantees that the socket,
720 passed to the callback function,
721 will be bound and connected to the Bluetooth device being enumerated.
723 .An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
725 Some of those functions use static data storage;
726 if the data is needed for future use, it should be
727 copied before any subsequent calls overwrite it.