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 ,
61 .Nm bt_devremote_name ,
62 .Nm bt_devremote_name_gen ,
66 .Nd Bluetooth routines
72 .Fn bt_gethostbyname "const char *name"
74 .Fn bt_gethostbyaddr "const char *addr" "int len" "int type"
76 .Fn bt_gethostent void
78 .Fn bt_sethostent "int stayopen"
80 .Fn bt_endhostent void
82 .Fn bt_getprotobyname "const char *name"
84 .Fn bt_getprotobynumber "int proto"
86 .Fn bt_getprotoent void
88 .Fn bt_setprotoent "int stayopen"
90 .Fn bt_endprotoent void
92 .Fn bt_aton "const char *str" "bdaddr_t *ba"
94 .Fn bt_ntoa "const bdaddr_t *ba" "char *str"
96 .Fn bt_devaddr "const char *devname" "bdaddr_t *addr"
98 .Fn bt_devname "char *devname" "const bdaddr_t *addr"
100 .Fn (bt_devenum_cb_t) "int s" "struct bt_devinfo const *di" "void *arg"
102 .Fn bt_devinfo "struct bt_devinfo *di"
104 .Fn bt_devenum "bt_devenum_cb_t *cb" "void *arg"
106 .Fn bt_devopen "char const *devname"
108 .Fn bt_devclose "int s"
110 .Fn bt_devsend "int s" "uint16_t opcode" "void *param" "size_t plen"
112 .Fn bt_devrecv "int s" "void *buf" "size_t size" "time_t to"
114 .Fn bt_devreq "int s" "struct bt_devreq *r" "time_t to"
116 .Fn bt_devfilter "int s" "struct bt_devfilter const *new" "struct bt_devfilter *old"
118 .Fn bt_devfilter_pkt_set "struct bt_devfilter *filter" "uint8_t type"
120 .Fn bt_devfilter_pkt_clt "struct bt_devfilter *filter" "uint8_t type"
122 .Fn bt_devfilter_pkt_tst "struct bt_devfilter const *filter" "uint8_t type"
124 .Fn bt_devfilter_evt_set "struct bt_devfilter *filter" "uint8_t event"
126 .Fn bt_devfilter_evt_clt "struct bt_devfilter *filter" "uint8_t event"
128 .Fn bt_devfilter_evt_tst "struct bt_devfilter const *filter" "uint8_t event"
130 .Fn bt_devinquiry "char const *devname" "time_t length" "int num_rsp" "struct bt_devinquiry **ii"
132 .Fn bt_devremote_name "char const *devname" "const bdaddr_t *remote" \
133 "time_t to" "uint16_t clk_off" "uint8_t ps_rep_mode" "uint8_t ps_mode"
135 .Fn bt_devremote_name_gen "char const *btooth_devname" "const bdaddr_t *remote"
137 .Fn bdaddr_same "const bdaddr_t *a" "const bdaddr_t *b"
139 .Fn bdaddr_any "const bdaddr_t *a"
141 .Fn bdaddr_copy "const bdaddr_t *dst" "const bdaddr_t *src"
149 each return a pointer to an object with the
151 structure describing a Bluetooth host
152 referenced by name or by address, respectively.
159 .Dv NUL Ns -terminated
165 should point to an address which is
169 (i.e., not a Bluetooth BD_ADDR in human readable
174 argument specifies the address family of this address and must be set to
177 The structure returned contains the information obtained from a line in
178 .Pa /etc/bluetooth/hosts
183 function controls whether
184 .Pa /etc/bluetooth/hosts
185 file should stay open after each call to
188 .Fn bt_gethostbyaddr .
191 flag is non-zero, the file will not be closed.
196 .Pa /etc/bluetooth/hosts
201 .Fn bt_getprotobyname
203 .Fn bt_getprotobynumber
204 functions each return a pointer to an object with the
206 structure describing a Bluetooth Protocol Service Multiplexor referenced
207 by name or number, respectively.
212 .Fn bt_getprotobyname
214 .Dv NUL Ns -terminated
215 Bluetooth Protocol Service Multiplexor name.
219 .Fn bt_getprotobynumber
220 should have numeric value of the desired Bluetooth Protocol Service Multiplexor.
222 The structure returned contains the information obtained from a line in
223 .Pa /etc/bluetooth/protocols
228 function controls whether
229 .Pa /etc/bluetooth/protocols
230 file should stay open after each call to
231 .Fn bt_getprotobyname
233 .Fn bt_getprotobynumber .
236 flag is non-zero, the file will not be closed.
241 .Pa /etc/bluetooth/protocols
246 routine interprets the specified character string as a Bluetooth address,
247 placing the address into the structure provided.
248 It returns 1 if the string was successfully interpreted,
249 or 0 if the string is invalid.
253 takes a Bluetooth address and places an
255 string representing the address into the buffer provided.
256 It is up to the caller to ensure that provided buffer has enough space.
257 If no buffer was provided then internal static buffer will be used.
261 function interprets the specified
263 string as the address or device name of a Bluetooth device on the local system,
264 and places the device address in the provided
267 The function returns 1 if the string was successfully interpreted,
268 or 0 if the string did not match any local device.
271 function takes a Bluetooth device address and copies the local device
272 name associated with that address into the buffer provided,
274 Caller must ensure that provided buffer is at least
277 The function returns 1 when the device was found,
282 function populates provided
284 structure with the information about given Bluetooth device.
285 The caller is expected to pass Bluetooth device name in the
290 The function returns 0 when successful,
294 structure is defined as follows
295 .Bd -literal -offset indent
298 char devname[HCI_DEVNAME_SIZE];
305 uint8_t features[HCI_DEVFEATURES_SIZE];
328 uint16_t link_policy_info;
329 uint16_t packet_type_info;
330 uint16_t role_switch_info;
333 uint8_t _padding[20];
339 function enumerates Bluetooth devices present in the system.
340 For every device found,
341 the function will call provided
343 callback function which should be of
346 The callback function is passed a
356 argument provided to the
358 The callback function can stop enumeration by returning a value
359 that is greater than zero.
360 The function returns number of successfully enumerated devices,
361 or -1 if an error occurred.
365 function opens a Bluetooth device with the given
367 and returns a connected and bound
370 The function returns -1 if an error has occurred.
378 previously obtained with
383 function sends a Bluetooth
385 command with the given
387 to the provided socket
389 previously obtained with
393 parameter is expected to be in the host byte order.
398 parameters specify command parameters.
401 function does not modify the
403 filter on the provided socket
405 The function returns 0 on success,
406 or -1 if an error occurred.
410 function receives one Bluetooth
412 packet from the socket
414 previously obtained with
416 The packet is placed into the provided buffer
422 parameter specifies receive timeout in seconds.
423 Infinite timeout can be specified by passing negative value in the
428 function does not modify the
430 filter on the provided socket
432 The function returns total number of bytes received,
433 or -1 if an error occurred.
437 function makes a Bluetooth
439 request to the socket
441 previously obtained with
443 The function will send the specified command and will wait for the specified
450 structure is defined as follows
451 .Bd -literal -offset indent
465 field specifies the command and is expected to be in the host byte order.
470 fields specify command parameters data and command parameters data size
474 field specifies which Bluetooth
476 event ID the function should wait for, otherwise it should be set to zero.
479 Command Complete and Command Status events are enabled by default.
484 parameters specify buffer and buffer size respectively where return
485 parameters should be placed.
488 function temporarily modifies filter on the provided
492 The function returns 0 on success, or -1 if an error occurred.
498 filter associated with the socket
500 previously obtained with
502 Filtering can be done on packet types, i.e.
507 command and event packets, and, in addition, on
512 filter (if provided) the function will try to obtain the current filter
515 and place it into the
517 parameter (if provided).
518 The function returns 0 on success, or -1 if an error occurred.
521 .Fn bt_devfilter_pkt_set ,
522 .Fn bt_devfilter_pkt_clr
524 .Fn bt_devfilter_pkt_tst
525 functions can be used to modify and test the
536 .Fn bt_devfilter_evt_set ,
537 .Fn bt_devfilter_evt_clr
539 .Fn bt_devfilter_evt_tst
540 functions can be used to modify and test the
552 function performs Bluetooth inquiry.
555 parameter specifies which local Bluetooth device should perform an inquiry.
556 If not specified, i.e.
558 then first available device will be used.
561 parameters specifies the total length of an inquiry in seconds.
562 If not specified, i.e. 0, default value will be used.
565 parameter specifies the number of responses that can be received before
566 the inquiry is halted.
567 If not specified, i.e. 0, default value will be used.
570 parameter specifies where to place inquiry results.
571 On success, the function will return total number of inquiry results,
575 buffer to store all the inquiry results and
576 will return pointer to the allocated buffer in the
579 It is up to the caller of the function to dispose of the buffer using
582 The function returns -1 if an error has occurred.
585 structure is defined as follows
586 .Bd -literal -offset indent
587 struct bt_devinquiry {
589 uint8_t pscan_rep_mode;
590 uint8_t pscan_period_mode;
591 uint8_t dev_class[3];
592 uint16_t clock_offset;
599 .Fn bt_devremote_name
600 function performs Bluetooth Remote Name Request procedure to obtain the
601 user-friendly name of another Bluetooth unit.
604 parameter specifies which local Bluetooth device should perform the request.
607 the first available device is used.
610 parameter specifies the Bluetooth BD_ADDR of the remote device to query.
613 parameter specifies response timeout in seconds.
614 If not specified (0), the default value is taken from the
615 net.bluetooth.hci.command_timeout
623 parameters specify Clock_Offset, Page_Scan_Repetition_Mode, and Page_Scan_Mode
624 fields of HCI_Remote_Name_Request respectively.
625 On success, the function returns a pointer to dynamically allocated
626 NUL-terminated string or
628 if an error occurred.
629 It is up to the caller to release returned string using
633 .Fn bt_devremote_name_gen
634 function is a shortcut to
635 .Fn bt_devremote_name
636 that passes generic defaults for
649 are handy shorthand Bluetooth address utility functions.
652 function will test if two provided BD_ADDRs are the same.
655 function will test if provided BD_ADDR is
660 function will copy provided
662 BD_ADDR into provided
666 .Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
667 .It Pa /etc/bluetooth/hosts
668 .It Pa /etc/bluetooth/protocols
671 Print out the hostname associated with a specific BD_ADDR:
672 .Bd -literal -offset indent
673 const char *bdstr = "00:01:02:03:04:05";
677 if (!bt_aton(bdstr, &bd))
678 errx(1, "can't parse BD_ADDR %s", bdstr);
680 if ((hp = bt_gethostbyaddr((const char *)&bd,
681 sizeof(bd), AF_BLUETOOTH)) == NULL)
682 errx(1, "no name associated with %s", bdstr);
684 printf("name associated with %s is %s\en", bdstr, hp->h_name);
687 Error return status from
692 is indicated by return of a
697 may then be checked to see whether this is a temporary failure
698 or an invalid or unknown host.
701 can be used to print an error message describing the failure.
706 it is printed, followed by a colon and a space.
707 The error message is printed with a trailing newline.
711 can have the following values:
712 .Bl -tag -width ".Dv HOST_NOT_FOUND"
713 .It Dv HOST_NOT_FOUND
714 No such host is known.
716 Some unexpected server failure was encountered.
717 This is a non-recoverable error.
722 .Fn bt_getprotobyname
724 .Fn bt_getprotobynumber
729 .Xr gethostbyaddr 3 ,
730 .Xr gethostbyname 3 ,
731 .Xr getprotobyname 3 ,
732 .Xr getprotobynumber 3 ,
740 function reads the next line of
741 .Pa /etc/bluetooth/hosts ,
742 opening the file if necessary.
746 function opens and/or rewinds the
747 .Pa /etc/bluetooth/hosts
752 function reads the next line of
753 .Pa /etc/bluetooth/protocols ,
754 opening the file if necessary.
758 function opens and/or rewinds the
759 .Pa /etc/bluetooth/protocols
764 function enumerates up to
767 During enumeration the
769 function uses the same
772 The function guarantees that the socket,
773 passed to the callback function,
774 will be bound and connected to the Bluetooth device being enumerated.
776 .An Maksim Yevmenkin Aq Mt m_evmenkin@yahoo.com
778 Some of those functions use static data storage;
779 if the data is needed for future use, it should be
780 copied before any subsequent calls overwrite it.