]> CyberLeo.Net >> Repos - FreeBSD/releng/8.1.git/blob - lib/libbluetooth/bluetooth.h
Copy stable/8 to releng/8.1 in preparation for 8.1-RC1.
[FreeBSD/releng/8.1.git] / lib / libbluetooth / bluetooth.h
1 /*
2  * bluetooth.h
3  */
4
5 /*-
6  * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin@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.5 2003/09/14 23:28:42 max Exp $
31  * $FreeBSD$
32  */
33
34 #ifndef _BLUETOOTH_H_
35 #define _BLUETOOTH_H_
36
37 #include <sys/types.h>
38 #include <sys/bitstring.h>
39 #include <sys/endian.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
42 #include <sys/uio.h>
43 #include <sys/un.h>
44 #include <errno.h>
45 #include <netdb.h>
46 #include <netgraph/ng_message.h>
47 #include <netgraph/bluetooth/include/ng_hci.h>
48 #include <netgraph/bluetooth/include/ng_l2cap.h>
49 #include <netgraph/bluetooth/include/ng_btsocket.h>
50 #include <time.h>
51
52 __BEGIN_DECLS
53
54 /*
55  * Linux BlueZ compatibility
56  */
57
58 #define bacmp(ba1, ba2) memcmp((ba1), (ba2), sizeof(bdaddr_t))
59 #define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t))
60 #define ba2str(ba, str) bt_ntoa((ba), (str))
61 #define str2ba(str, ba) (bt_aton((str), (ba)) == 1? 0 : -1)
62
63 /*
64  * Interface to the outside world
65  */
66
67 struct hostent *  bt_gethostbyname    (char const *name);
68 struct hostent *  bt_gethostbyaddr    (char const *addr, int len, int type);
69 struct hostent *  bt_gethostent       (void);
70 void              bt_sethostent       (int stayopen);
71 void              bt_endhostent       (void);
72
73 struct protoent * bt_getprotobyname   (char const *name);
74 struct protoent * bt_getprotobynumber (int proto);
75 struct protoent * bt_getprotoent      (void);
76 void              bt_setprotoent      (int stayopen);
77 void              bt_endprotoent      (void);
78
79 char const *      bt_ntoa             (bdaddr_t const *ba, char *str);
80 int               bt_aton             (char const *str, bdaddr_t *ba);
81
82 /* bt_devXXXX() functions (inspired by NetBSD) */
83 int               bt_devaddr          (char const *devname, bdaddr_t *addr);
84 int               bt_devname          (char *devname, bdaddr_t const *addr);
85
86 /* 
87  * Bluetooth HCI functions
88  */
89
90 #define HCI_DEVMAX                      32              /* arbitrary */
91 #define HCI_DEVNAME_SIZE                NG_NODESIZ
92 #define HCI_DEVFEATURES_SIZE            NG_HCI_FEATURES_SIZE
93
94 struct bt_devinfo
95 {
96         char            devname[HCI_DEVNAME_SIZE];
97
98         uint32_t        state;          /* device/implementation specific */
99
100         bdaddr_t        bdaddr;
101         uint16_t        _reserved0;
102
103         uint8_t         features[HCI_DEVFEATURES_SIZE];
104
105         /* buffer info */
106         uint16_t        _reserved1;
107         uint16_t        cmd_free;
108         uint16_t        sco_size;
109         uint16_t        sco_pkts;
110         uint16_t        sco_free;
111         uint16_t        acl_size;
112         uint16_t        acl_pkts;
113         uint16_t        acl_free;
114
115         /* stats */
116         uint32_t        cmd_sent;
117         uint32_t        evnt_recv;
118         uint32_t        acl_recv;
119         uint32_t        acl_sent;
120         uint32_t        sco_recv;
121         uint32_t        sco_sent;
122         uint32_t        bytes_recv;
123         uint32_t        bytes_sent;
124
125         /* misc/specific */
126         uint16_t        link_policy_info;
127         uint16_t        packet_type_info;
128         uint16_t        role_switch_info;
129         uint16_t        debug;
130
131         uint8_t         _padding[20];   /* leave space for future additions */
132 };
133
134 struct bt_devreq
135 {
136         uint16_t        opcode;
137         uint8_t         event;
138         void            *cparam;
139         size_t          clen;
140         void            *rparam;
141         size_t          rlen;
142 };
143
144 struct bt_devfilter {
145         bitstr_t        bit_decl(packet_mask, 8);
146         bitstr_t        bit_decl(event_mask, 256);
147 };
148
149 struct bt_devinquiry {
150         bdaddr_t        bdaddr;
151         uint8_t         pscan_rep_mode;
152         uint8_t         pscan_period_mode;
153         uint8_t         dev_class[3];
154         uint16_t        clock_offset;
155         int8_t          rssi;
156         uint8_t         data[240];
157 };
158
159 typedef int     (bt_devenum_cb_t)(int, struct bt_devinfo const *, void *);
160
161 int             bt_devopen (char const *devname);
162 int             bt_devclose(int s);
163 int             bt_devsend (int s, uint16_t opcode, void *param, size_t plen);
164 ssize_t         bt_devrecv (int s, void *buf, size_t size, time_t to);
165 int             bt_devreq  (int s, struct bt_devreq *r, time_t to);
166 int             bt_devfilter(int s, struct bt_devfilter const *newp,
167                              struct bt_devfilter *oldp);
168 void            bt_devfilter_pkt_set(struct bt_devfilter *filter, uint8_t type);
169 void            bt_devfilter_pkt_clr(struct bt_devfilter *filter, uint8_t type);
170 int             bt_devfilter_pkt_tst(struct bt_devfilter const *filter, uint8_t type);
171 void            bt_devfilter_evt_set(struct bt_devfilter *filter, uint8_t event);
172 void            bt_devfilter_evt_clr(struct bt_devfilter *filter, uint8_t event);
173 int             bt_devfilter_evt_tst(struct bt_devfilter const *filter, uint8_t event);
174 int             bt_devinquiry(char const *devname, time_t length, int num_rsp,
175                               struct bt_devinquiry **ii);
176 int             bt_devinfo (struct bt_devinfo *di);
177 int             bt_devenum (bt_devenum_cb_t *cb, void *arg);
178
179 /*
180  * bdaddr utility functions (from NetBSD)
181  */
182
183 static __inline int
184 bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
185 {
186         return (a->b[0] == b->b[0] && a->b[1] == b->b[1] &&
187                 a->b[2] == b->b[2] && a->b[3] == b->b[3] &&
188                 a->b[4] == b->b[4] && a->b[5] == b->b[5]);
189 }
190
191 static __inline int
192 bdaddr_any(const bdaddr_t *a)
193 {
194         return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0 &&
195                 a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
196 }
197
198 static __inline void
199 bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
200 {
201         d->b[0] = s->b[0];
202         d->b[1] = s->b[1];
203         d->b[2] = s->b[2];
204         d->b[3] = s->b[3];
205         d->b[4] = s->b[4];
206         d->b[5] = s->b[5];
207 }
208
209 __END_DECLS
210
211 #endif /* ndef _BLUETOOTH_H_ */
212