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 $
31 .Nm bt_gethostbyname ,
32 .Nm bt_gethostbyaddr ,
36 .Nm bt_getprotobyname ,
37 .Nm bt_getprotobynumber ,
53 .Nm bt_devfilter_pkt_set ,
54 .Nm bt_devfilter_pkt_clr ,
55 .Nm bt_devfilter_pkt_tst ,
56 .Nm bt_devfilter_evt_set ,
57 .Nm bt_devfilter_evt_clr ,
58 .Nm bt_devfilter_evt_tst ,
60 .Nm bt_devremote_name ,
61 .Nm bt_devremote_name_gen ,
65 .Nd Bluetooth routines
71 .Fn bt_gethostbyname "const char *name"
73 .Fn bt_gethostbyaddr "const char *addr" "int len" "int type"
75 .Fn bt_gethostent void
77 .Fn bt_sethostent "int stayopen"
79 .Fn bt_endhostent void
81 .Fn bt_getprotobyname "const char *name"
83 .Fn bt_getprotobynumber "int proto"
85 .Fn bt_getprotoent void
87 .Fn bt_setprotoent "int stayopen"
89 .Fn bt_endprotoent void
91 .Fn bt_aton "const char *str" "bdaddr_t *ba"
93 .Fn bt_ntoa "const bdaddr_t *ba" "char *str"
95 .Fn bt_devaddr "const char *devname" "bdaddr_t *addr"
97 .Fn bt_devname "char *devname" "const bdaddr_t *addr"
99 .Fn (bt_devenum_cb_t) "int s" "struct bt_devinfo const *di" "void *arg"
101 .Fn bt_devinfo "struct bt_devinfo *di"
103 .Fn bt_devenum "bt_devenum_cb_t *cb" "void *arg"
105 .Fn bt_devopen "char const *devname"
107 .Fn bt_devclose "int s"
109 .Fn bt_devsend "int s" "uint16_t opcode" "void *param" "size_t plen"
111 .Fn bt_devrecv "int s" "void *buf" "size_t size" "time_t to"
113 .Fn bt_devreq "int s" "struct bt_devreq *r" "time_t to"
115 .Fn bt_devfilter "int s" "struct bt_devfilter const *new" "struct bt_devfilter *old"
117 .Fn bt_devfilter_pkt_set "struct bt_devfilter *filter" "uint8_t type"
119 .Fn bt_devfilter_pkt_clt "struct bt_devfilter *filter" "uint8_t type"
121 .Fn bt_devfilter_pkt_tst "struct bt_devfilter const *filter" "uint8_t type"
123 .Fn bt_devfilter_evt_set "struct bt_devfilter *filter" "uint8_t event"
125 .Fn bt_devfilter_evt_clt "struct bt_devfilter *filter" "uint8_t event"
127 .Fn bt_devfilter_evt_tst "struct bt_devfilter const *filter" "uint8_t event"
129 .Fn bt_devinquiry "char const *devname" "time_t length" "int num_rsp" "struct bt_devinquiry **ii"
131 .Fn bt_devremote_name "char const *devname" "const bdaddr_t *remote" \
132 "time_t to" "uint16_t clk_off" "uint8_t ps_rep_mode" "uint8_t ps_mode"
134 .Fn bt_devremote_name_gen "char const *btooth_devname" "const bdaddr_t *remote"
136 .Fn bdaddr_same "const bdaddr_t *a" "const bdaddr_t *b"
138 .Fn bdaddr_any "const bdaddr_t *a"
140 .Fn bdaddr_copy "const bdaddr_t *dst" "const bdaddr_t *src"
148 each return a pointer to an object with the
150 structure describing a Bluetooth host
151 referenced by name or by address, respectively.
158 .Dv NUL Ns -terminated
164 should point to an address which is
168 (i.e., not a Bluetooth BD_ADDR in human readable
173 argument specifies the address family of this address and must be set to
176 The structure returned contains the information obtained from a line in
177 .Pa /etc/bluetooth/hosts
182 function controls whether
183 .Pa /etc/bluetooth/hosts
184 file should stay open after each call to
187 .Fn bt_gethostbyaddr .
190 flag is non-zero, the file will not be closed.
195 .Pa /etc/bluetooth/hosts
200 .Fn bt_getprotobyname
202 .Fn bt_getprotobynumber
203 functions each return a pointer to an object with the
205 structure describing a Bluetooth Protocol Service Multiplexor referenced
206 by name or number, respectively.
211 .Fn bt_getprotobyname
213 .Dv NUL Ns -terminated
214 Bluetooth Protocol Service Multiplexor name.
218 .Fn bt_getprotobynumber
219 should have numeric value of the desired Bluetooth Protocol Service Multiplexor.
221 The structure returned contains the information obtained from a line in
222 .Pa /etc/bluetooth/protocols
227 function controls whether
228 .Pa /etc/bluetooth/protocols
229 file should stay open after each call to
230 .Fn bt_getprotobyname
232 .Fn bt_getprotobynumber .
235 flag is non-zero, the file will not be closed.
240 .Pa /etc/bluetooth/protocols
245 routine interprets the specified character string as a Bluetooth address,
246 placing the address into the structure provided.
247 It returns 1 if the string was successfully interpreted,
248 or 0 if the string is invalid.
252 takes a Bluetooth address and places an
254 string representing the address into the buffer provided.
255 It is up to the caller to ensure that provided buffer has enough space.
256 If no buffer was provided then internal static buffer will be used.
260 function interprets the specified
262 string as the address or device name of a Bluetooth device on the local system,
263 and places the device address in the provided
266 The function returns 1 if the string was successfully interpreted,
267 or 0 if the string did not match any local device.
270 function takes a Bluetooth device address and copies the local device
271 name associated with that address into the buffer provided,
273 Caller must ensure that provided buffer is at least
276 The function returns 1 when the device was found,
281 function populates provided
283 structure with the information about given Bluetooth device.
284 The caller is expected to pass Bluetooth device name in the
289 The function returns 0 when successful,
293 structure is defined as follows
294 .Bd -literal -offset indent
297 char devname[HCI_DEVNAME_SIZE];
304 uint8_t features[HCI_DEVFEATURES_SIZE];
327 uint16_t link_policy_info;
328 uint16_t packet_type_info;
329 uint16_t role_switch_info;
332 uint8_t _padding[20];
338 function enumerates Bluetooth devices present in the system.
339 For every device found,
340 the function will call provided
342 callback function which should be of
345 The callback function is passed a
355 argument provided to the
357 The callback function can stop enumeration by returning a value
358 that is greater than zero.
359 The function returns number of successfully enumerated devices,
360 or -1 if an error occurred.
364 function opens a Bluetooth device with the given
366 and returns a connected and bound
369 The function returns -1 if an error has occurred.
377 previously obtained with
382 function sends a Bluetooth
384 command with the given
386 to the provided socket
388 previously obtained with
392 parameter is expected to be in the host byte order.
397 parameters specify command parameters.
400 function does not modify the
402 filter on the provided socket
404 The function returns 0 on success,
405 or -1 if an error occurred.
409 function receives one Bluetooth
411 packet from the socket
413 previously obtained with
415 The packet is placed into the provided buffer
421 parameter specifies receive timeout in seconds.
422 Infinite timeout can be specified by passing negative value in the
427 function does not modify the
429 filter on the provided socket
431 The function returns total number of bytes received,
432 or -1 if an error occurred.
436 function makes a Bluetooth
438 request to the socket
440 previously obtained with
442 The function will send the specified command and will wait for the specified
449 structure is defined as follows
450 .Bd -literal -offset indent
464 field specifies the command and is expected to be in the host byte order.
469 fields specify command parameters data and command parameters data size
473 field specifies which Bluetooth
475 event ID the function should wait for, otherwise it should be set to zero.
478 Command Complete and Command Status events are enabled by default.
483 parameters specify buffer and buffer size respectively where return
484 parameters should be placed.
487 function temporarily modifies filter on the provided
491 The function returns 0 on success, or -1 if an error occurred.
497 filter associated with the socket
499 previously obtained with
501 Filtering can be done on packet types, i.e.
506 command and event packets, and, in addition, on
511 filter (if provided) the function will try to obtain the current filter
514 and place it into the
516 parameter (if provided).
517 The function returns 0 on success, or -1 if an error occurred.
520 .Fn bt_devfilter_pkt_set ,
521 .Fn bt_devfilter_pkt_clr
523 .Fn bt_devfilter_pkt_tst
524 functions can be used to modify and test the
535 .Fn bt_devfilter_evt_set ,
536 .Fn bt_devfilter_evt_clr
538 .Fn bt_devfilter_evt_tst
539 functions can be used to modify and test the
551 function performs Bluetooth inquiry.
554 parameter specifies which local Bluetooth device should perform an inquiry.
555 If not specified, i.e.
557 then first available device will be used.
560 parameters specifies the total length of an inquiry in seconds.
561 If not specified, i.e. 0, default value will be used.
564 parameter specifies the number of responses that can be received before
565 the inquiry is halted.
566 If not specified, i.e. 0, default value will be used.
569 parameter specifies where to place inquiry results.
570 On success, the function will return total number of inquiry results,
574 buffer to store all the inquiry results and
575 will return pointer to the allocated buffer in the
578 It is up to the caller of the function to dispose of the buffer using
581 The function returns -1 if an error has occurred.
584 structure is defined as follows
585 .Bd -literal -offset indent
586 struct bt_devinquiry {
588 uint8_t pscan_rep_mode;
589 uint8_t pscan_period_mode;
590 uint8_t dev_class[3];
591 uint16_t clock_offset;
598 .Fn bt_devremote_name
599 function performs Bluetooth Remote Name Request procedure to obtain the
600 user-friendly name of another Bluetooth unit.
603 parameter specifies which local Bluetooth device should perform the request.
606 the first available device is used.
609 parameter specifies the Bluetooth BD_ADDR of the remote device to query.
612 parameter specifies response timeout in seconds.
613 If not specified (0), the default value is taken from the
614 net.bluetooth.hci.command_timeout
622 parameters specify Clock_Offset, Page_Scan_Repetition_Mode, and Page_Scan_Mode
623 fields of HCI_Remote_Name_Request respectively.
624 On success, the function returns a pointer to dynamically allocated
625 NUL-terminated string or
627 if an error occurred.
628 It is up to the caller to release returned string using
632 .Fn bt_devremote_name_gen
633 function is a shortcut to
634 .Fn bt_devremote_name
635 that passes generic defaults for
648 are handy shorthand Bluetooth address utility functions.
651 function will test if two provided BD_ADDRs are the same.
654 function will test if provided BD_ADDR is
659 function will copy provided
661 BD_ADDR into provided
665 .Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
666 .It Pa /etc/bluetooth/hosts
667 .It Pa /etc/bluetooth/protocols
670 Print out the hostname associated with a specific BD_ADDR:
671 .Bd -literal -offset indent
672 const char *bdstr = "00:01:02:03:04:05";
676 if (!bt_aton(bdstr, &bd))
677 errx(1, "can't parse BD_ADDR %s", bdstr);
679 if ((hp = bt_gethostbyaddr((const char *)&bd,
680 sizeof(bd), AF_BLUETOOTH)) == NULL)
681 errx(1, "no name associated with %s", bdstr);
683 printf("name associated with %s is %s\en", bdstr, hp->h_name);
686 Error return status from
691 is indicated by return of a
696 may then be checked to see whether this is a temporary failure
697 or an invalid or unknown host.
700 can be used to print an error message describing the failure.
705 it is printed, followed by a colon and a space.
706 The error message is printed with a trailing newline.
710 can have the following values:
711 .Bl -tag -width ".Dv HOST_NOT_FOUND"
712 .It Dv HOST_NOT_FOUND
713 No such host is known.
715 Some unexpected server failure was encountered.
716 This is a non-recoverable error.
721 .Fn bt_getprotobyname
723 .Fn bt_getprotobynumber
728 .Xr gethostbyaddr 3 ,
729 .Xr gethostbyname 3 ,
730 .Xr getprotobyname 3 ,
731 .Xr getprotobynumber 3 ,
739 function reads the next line of
740 .Pa /etc/bluetooth/hosts ,
741 opening the file if necessary.
745 function opens and/or rewinds the
746 .Pa /etc/bluetooth/hosts
751 function reads the next line of
752 .Pa /etc/bluetooth/protocols ,
753 opening the file if necessary.
757 function opens and/or rewinds the
758 .Pa /etc/bluetooth/protocols
763 function enumerates up to
766 During enumeration the
768 function uses the same
771 The function guarantees that the socket,
772 passed to the callback function,
773 will be bound and connected to the Bluetooth device being enumerated.
775 .An Maksim Yevmenkin Aq Mt m_evmenkin@yahoo.com
777 Some of those functions use static data storage;
778 if the data is needed for future use, it should be
779 copied before any subsequent calls overwrite it.