6 * SPDX-License-Identifier: BSD-2-Clause-FreeBSD
8 * Copyright (c) 2001-2009 Maksim Yevmenkin <m_evmenkin@yahoo.com>
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32 * $Id: bluetooth.h,v 1.5 2003/09/14 23:28:42 max Exp $
39 #include <sys/types.h>
40 #include <sys/endian.h>
41 #include <sys/ioctl.h>
42 #include <sys/socket.h>
48 #include <bitstring.h>
50 #include <netgraph/ng_message.h>
51 #include <netgraph/bluetooth/include/ng_bluetooth.h>
52 #include <netgraph/bluetooth/include/ng_hci.h>
53 #include <netgraph/bluetooth/include/ng_l2cap.h>
54 #include <netgraph/bluetooth/include/ng_btsocket.h>
60 * Linux BlueZ compatibility
63 #define bacmp(ba1, ba2) memcmp((ba1), (ba2), sizeof(bdaddr_t))
64 #define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t))
65 #define ba2str(ba, str) bt_ntoa((ba), (str))
66 #define str2ba(str, ba) (bt_aton((str), (ba)) == 1? 0 : -1)
67 #define htobs(d) htole16(d)
68 #define htobl(d) htole32(d)
69 #define btohs(d) le16toh(d)
70 #define btohl(d) le32toh(d)
73 * Interface to the outside world
76 struct hostent * bt_gethostbyname (char const *name);
77 struct hostent * bt_gethostbyaddr (char const *addr, int len, int type);
78 struct hostent * bt_gethostent (void);
79 void bt_sethostent (int stayopen);
80 void bt_endhostent (void);
82 struct protoent * bt_getprotobyname (char const *name);
83 struct protoent * bt_getprotobynumber (int proto);
84 struct protoent * bt_getprotoent (void);
85 void bt_setprotoent (int stayopen);
86 void bt_endprotoent (void);
88 char const * bt_ntoa (bdaddr_t const *ba, char *str);
89 int bt_aton (char const *str, bdaddr_t *ba);
91 /* bt_devXXXX() functions (inspired by NetBSD) */
92 int bt_devaddr (char const *devname, bdaddr_t *addr);
93 int bt_devname (char *devname, bdaddr_t const *addr);
96 * Bluetooth HCI functions
99 #define HCI_DEVMAX 32 /* arbitrary */
100 #define HCI_DEVNAME_SIZE NG_NODESIZ
101 #define HCI_DEVFEATURES_SIZE NG_HCI_FEATURES_SIZE
105 char devname[HCI_DEVNAME_SIZE];
107 uint32_t state; /* device/implementation specific */
112 uint8_t features[HCI_DEVFEATURES_SIZE];
135 uint16_t link_policy_info;
136 uint16_t packet_type_info;
137 uint16_t role_switch_info;
140 uint8_t _padding[20]; /* leave space for future additions */
153 struct bt_devfilter {
154 bitstr_t bit_decl(packet_mask, 8);
155 bitstr_t bit_decl(event_mask, 256);
158 struct bt_devinquiry {
160 uint8_t pscan_rep_mode;
161 uint8_t pscan_period_mode;
162 uint8_t dev_class[3];
163 uint16_t clock_offset;
168 typedef int (bt_devenum_cb_t)(int, struct bt_devinfo const *, void *);
170 int bt_devopen (char const *devname);
171 int bt_devclose(int s);
172 int bt_devsend (int s, uint16_t opcode, void *param, size_t plen);
173 ssize_t bt_devrecv (int s, void *buf, size_t size, time_t to);
174 int bt_devreq (int s, struct bt_devreq *r, time_t to);
175 int bt_devfilter(int s, struct bt_devfilter const *newp,
176 struct bt_devfilter *oldp);
177 void bt_devfilter_pkt_set(struct bt_devfilter *filter, uint8_t type);
178 void bt_devfilter_pkt_clr(struct bt_devfilter *filter, uint8_t type);
179 int bt_devfilter_pkt_tst(struct bt_devfilter const *filter, uint8_t type);
180 void bt_devfilter_evt_set(struct bt_devfilter *filter, uint8_t event);
181 void bt_devfilter_evt_clr(struct bt_devfilter *filter, uint8_t event);
182 int bt_devfilter_evt_tst(struct bt_devfilter const *filter, uint8_t event);
183 int bt_devinquiry(char const *devname, time_t length, int num_rsp,
184 struct bt_devinquiry **ii);
185 int bt_devinfo (struct bt_devinfo *di);
186 int bt_devenum (bt_devenum_cb_t cb, void *arg);
189 * bdaddr utility functions (from NetBSD)
193 bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
195 return (a->b[0] == b->b[0] && a->b[1] == b->b[1] &&
196 a->b[2] == b->b[2] && a->b[3] == b->b[3] &&
197 a->b[4] == b->b[4] && a->b[5] == b->b[5]);
201 bdaddr_any(const bdaddr_t *a)
203 return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0 &&
204 a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
208 bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
220 #endif /* ndef _BLUETOOTH_H_ */