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 ,
47 .Nd Bluetooth routines
53 .Fn bt_gethostbyname "const char *name"
55 .Fn bt_gethostbyaddr "const char *addr" "int len" "int type"
57 .Fn bt_gethostent void
59 .Fn bt_sethostent "int stayopen"
61 .Fn bt_endhostent void
63 .Fn bt_getprotobyname "const char *name"
65 .Fn bt_getprotobynumber "int proto"
67 .Fn bt_getprotoent void
69 .Fn bt_setprotoent "int stayopen"
71 .Fn bt_endprotoent void
73 .Fn bt_aton "const char *str" "bdaddr_t *ba"
75 .Fn bt_ntoa "const bdaddr_t *ba" "char *str"
77 .Fn bt_devaddr "const char *devname" "bdaddr_t *addr"
79 .Fn bt_devname "char *devname" "const bdaddr_t *addr"
81 .Fn (bt_devenum_cb_t) "int s" "struct bt_devinfo const *di" "void *arg"
83 .Fn bt_devinfo "struct bt_devinfo *di"
85 .Fn bt_devenum "bt_devenum_cb_t *cb" "void *arg"
87 .Fn bdaddr_same "const bdaddr_t *a" "const bdaddr_t *b"
89 .Fn bdaddr_any "const bdaddr_t *a"
91 .Fn bdaddr_copy "const bdaddr_t *dst" "const bdaddr_t *src"
99 each return a pointer to an object with the
101 structure describing a Bluetooth host
102 referenced by name or by address, respectively.
109 .Dv NUL Ns -terminated
115 should point to an address which is
119 (i.e., not a Bluetooth BD_ADDR in human readable
124 argument specifies the address family of this address and must be set to
127 The structure returned contains the information obtained from a line in
128 .Pa /etc/bluetooth/hosts
133 function controls whether
134 .Pa /etc/bluetooth/hosts
135 file should stay open after each call to
138 .Fn bt_gethostbyaddr .
141 flag is non-zero, the file will not be closed.
146 .Pa /etc/bluetooth/hosts
151 .Fn bt_getprotobyname
153 .Fn bt_getprotobynumber
154 functions each return a pointer to an object with the
156 structure describing a Bluetooth Protocol Service Multiplexor referenced
157 by name or number, respectively.
162 .Fn bt_getprotobyname
164 .Dv NUL Ns -terminated
165 Bluetooth Protocol Service Multiplexor name.
169 .Fn bt_getprotobynumber
170 should have numeric value of the desired Bluetooth Protocol Service Multiplexor.
172 The structure returned contains the information obtained from a line in
173 .Pa /etc/bluetooth/protocols
178 function controls whether
179 .Pa /etc/bluetooth/protocols
180 file should stay open after each call to
181 .Fn bt_getprotobyname
183 .Fn bt_getprotobynumber .
186 flag is non-zero, the file will not be closed.
191 .Pa /etc/bluetooth/protocols
196 routine interprets the specified character string as a Bluetooth address,
197 placing the address into the structure provided.
198 It returns 1 if the string was successfully interpreted,
199 or 0 if the string is invalid.
203 takes a Bluetooth address and places an
205 string representing the address into the buffer provided.
206 It is up to the caller to ensure that provided buffer has enough space.
207 If no buffer was provided then internal static buffer will be used.
211 function interprets the specified
213 string as the address or device name of a Bluetooth device on the local system,
214 and places the device address in the provided
217 The function returns 1 if the string was successfully interpreted,
218 or 0 if the string did not match any local device.
221 function takes a Bluetooth device address and copies the local device
222 name associated with that address into the buffer provided,
224 Caller must ensure that provided buffer is at least
227 The function returns 1 when the device was found,
232 function populates prodivded
234 structure with the information about given Bluetooth device.
235 The caller is expected to pass Bluetooth device name in the
240 The function returns 0 when successful,
244 structure is defined as follows
245 .Bd -literal -offset indent
248 char devname[HCI_DEVNAME_SIZE];
255 uint8_t features[HCI_DEVFEATURES_SIZE];
278 uint16_t link_policy_info;
279 uint16_t packet_type_info;
280 uint16_t role_switch_info;
283 uint8_t _padding[20];
289 function enumerates Bluetooth devices present in the system.
290 For every device found,
291 the function will call provided
293 callback function which should be of
296 The callback function is passed a
306 argument provided to the
308 The callback function can stop enumeration by returning a value
309 that is greater than zero.
310 The function returns number of successfully enumerated devices,
311 or -1 if an error occurred.
318 are handy shorthand Bluetooth address utility functions.
321 function will test if two provided BD_ADDRs are the same.
324 function will test if provided BD_ADDR is
329 function will copy provided
331 BD_ADDR into provided
335 .Bl -tag -width ".Pa /etc/bluetooth/hosts" -compact
336 .It Pa /etc/bluetooth/hosts
337 .It Pa /etc/bluetooth/protocols
340 Print out the hostname associated with a specific BD_ADDR:
341 .Bd -literal -offset indent
342 const char *bdstr = "00:01:02:03:04:05";
346 if (!bt_aton(bdstr, &bd))
347 errx(1, "can't parse BD_ADDR %s", bdstr);
349 if ((hp = bt_gethostbyaddr((const char *)&bd,
350 sizeof(bd), AF_BLUETOOTH)) == NULL)
351 errx(1, "no name associated with %s", bdstr);
353 printf("name associated with %s is %s\en", bdstr, hp->h_name);
356 Error return status from
361 is indicated by return of a
366 may then be checked to see whether this is a temporary failure
367 or an invalid or unknown host.
370 can be used to print an error message describing the failure.
375 it is printed, followed by a colon and a space.
376 The error message is printed with a trailing newline.
380 can have the following values:
381 .Bl -tag -width ".Dv HOST_NOT_FOUND"
382 .It Dv HOST_NOT_FOUND
383 No such host is known.
385 Some unexpected server failure was encountered.
386 This is a non-recoverable error.
391 .Fn bt_getprotobyname
393 .Fn bt_getprotobynumber
398 .Xr gethostbyaddr 3 ,
399 .Xr gethostbyname 3 ,
400 .Xr getprotobyname 3 ,
401 .Xr getprotobynumber 3 ,
409 function reads the next line of
410 .Pa /etc/bluetooth/hosts ,
411 opening the file if necessary.
415 function opens and/or rewinds the
416 .Pa /etc/bluetooth/hosts
421 function reads the next line of
422 .Pa /etc/bluetooth/protocols ,
423 opening the file if necessary.
427 function opens and/or rewinds the
428 .Pa /etc/bluetooth/protocols
433 function enumerates up to
436 During enumeration the
438 function uses the same
441 The function guarantees that the socket,
442 passed to the callback function,
443 will be bound and connected to the Bluetooth device being enumerated.
445 .An Maksim Yevmenkin Aq m_evmenkin@yahoo.com
447 These functions use static data storage;
448 if the data is needed for future use, it should be
449 copied before any subsequent calls overwrite it.