bluetooth.h revision 1.1 1 /* $NetBSD: bluetooth.h,v 1.1 2006/06/19 15:44:36 gdamore Exp $ */
2
3 /*
4 * bluetooth.h
5 *
6 * Copyright (c) 2001-2003 Maksim Yevmenkin <m_evmenkin (at) yahoo.com>
7 * All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28 * SUCH DAMAGE.
29 *
30 * $Id: bluetooth.h,v 1.1 2006/06/19 15:44:36 gdamore Exp $
31 * $FreeBSD: src/lib/libbluetooth/bluetooth.h,v 1.2 2005/03/17 21:39:44 emax Exp $
32 */
33
34 #ifndef _BLUETOOTH_H_
35 #define _BLUETOOTH_H_
36
37 #include <sys/types.h>
38 #include <sys/endian.h>
39 #include <sys/socket.h>
40 #include <netdb.h>
41 #include <netbt/bluetooth.h>
42 #include <netbt/hci.h>
43 #include <netbt/l2cap.h>
44 #include <stdio.h>
45
46 /*
47 * Bluetooth remote device config information.
48 *
49 * Entries will be empty if no value was specified
50 * in the configuration file.
51 */
52 typedef struct {
53 bdaddr_t bdaddr; /* device address */
54 int type; /* device type */
55 char *name; /* NUL terminated string */
56 uint8_t *pin; /* uint8_t[HCI_PIN_SIZE] */
57 uint8_t *key; /* uint8_t[HCI_KEY_SIZE] */
58 uint8_t *hid_descriptor; /* uint8_t[hid_length] */
59 int hid_length;
60 uint16_t control_psm;
61 uint8_t control_channel;
62 uint16_t interrupt_psm;
63 uint8_t reconnect_initiate;
64 uint8_t normally_connectable;
65 uint8_t battery_power;
66 } bt_cfgentry_t;
67
68 __BEGIN_DECLS
69
70 /*
71 * Interface to the outside world
72 */
73
74 struct hostent * bt_gethostbyname (char const *);
75 struct hostent * bt_gethostbyaddr (char const *, socklen_t, int);
76 struct hostent * bt_gethostent (void);
77 void bt_sethostent (int);
78 void bt_endhostent (void);
79
80 struct protoent * bt_getprotobyname (char const *);
81 struct protoent * bt_getprotobynumber (int);
82 struct protoent * bt_getprotoent (void);
83 void bt_setprotoent (int);
84 void bt_endprotoent (void);
85
86 char const * bt_ntoa (bdaddr_t const *, char *);
87 int bt_aton (char const *, bdaddr_t *);
88
89 int bt_devaddr (const char *, bdaddr_t *);
90 int bt_devname (char *, const bdaddr_t *);
91
92 typedef struct bt_handle *bt_handle_t;
93
94 bt_handle_t bt_openconfig (const char *);
95 bt_cfgentry_t * bt_getconfig (bt_handle_t, const bdaddr_t *);
96 int bt_eachconfig (bt_handle_t, void (*func)(bt_cfgentry_t *, void *), void *);
97 void bt_freeconfig (bt_cfgentry_t *);
98 int bt_closeconfig (bt_handle_t);
99 int bt_printconfig (FILE *, bt_cfgentry_t *);
100
101 #ifdef COMPAT_BLUEZ
102 /*
103 * Linux BlueZ compatibility
104 */
105
106 #define bacmp(ba1, ba2) memcmp((ba1), (ba2), sizeof(bdaddr_t))
107 #define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t))
108 #define ba2str(ba, str) bt_ntoa((ba), (str))
109 #define str2ba(str, ba) (bt_aton((str), (ba)) == 1 ? 0 : -1)
110
111 #define htobs(x) htole16(x)
112 #define htobl(x) htole32(x)
113 #define btohs(x) le16toh(x)
114 #define btohl(x) le32toh(x)
115
116 #define bt_malloc(n) malloc(n)
117 #define bt_free(p) free(p)
118
119 #endif /* COMPAT_BLUEZ */
120
121 __END_DECLS
122
123 #endif /* ndef _BLUETOOTH_H_ */
124