6 * SPDX-License-Identifier: BSD-2-Clause
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 $
38 #include <sys/types.h>
39 #include <sys/endian.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
47 #include <bitstring.h>
49 #include <netgraph/ng_message.h>
50 #include <netgraph/bluetooth/include/ng_bluetooth.h>
51 #include <netgraph/bluetooth/include/ng_hci.h>
52 #include <netgraph/bluetooth/include/ng_l2cap.h>
53 #include <netgraph/bluetooth/include/ng_btsocket.h>
59 * Linux BlueZ compatibility
62 #define bacmp(ba1, ba2) memcmp((ba1), (ba2), sizeof(bdaddr_t))
63 #define bacpy(dst, src) memcpy((dst), (src), sizeof(bdaddr_t))
64 #define ba2str(ba, str) bt_ntoa((ba), (str))
65 #define str2ba(str, ba) (bt_aton((str), (ba)) == 1? 0 : -1)
66 #define htobs(d) htole16(d)
67 #define htobl(d) htole32(d)
68 #define btohs(d) le16toh(d)
69 #define btohl(d) le32toh(d)
72 * Interface to the outside world
75 struct hostent * bt_gethostbyname (char const *name);
76 struct hostent * bt_gethostbyaddr (char const *addr, int len, int type);
77 struct hostent * bt_gethostent (void);
78 void bt_sethostent (int stayopen);
79 void bt_endhostent (void);
81 struct protoent * bt_getprotobyname (char const *name);
82 struct protoent * bt_getprotobynumber (int proto);
83 struct protoent * bt_getprotoent (void);
84 void bt_setprotoent (int stayopen);
85 void bt_endprotoent (void);
87 char const * bt_ntoa (bdaddr_t const *ba, char *str);
88 int bt_aton (char const *str, bdaddr_t *ba);
90 /* bt_devXXXX() functions (inspired by NetBSD) */
91 int bt_devaddr (char const *devname, bdaddr_t *addr);
92 int bt_devname (char *devname, bdaddr_t const *addr);
95 * Bluetooth HCI functions
98 #define HCI_DEVMAX 32 /* arbitrary */
99 #define HCI_DEVNAME_SIZE NG_NODESIZ
100 #define HCI_DEVFEATURES_SIZE NG_HCI_FEATURES_SIZE
104 char devname[HCI_DEVNAME_SIZE];
106 uint32_t state; /* device/implementation specific */
111 uint8_t features[HCI_DEVFEATURES_SIZE];
134 uint16_t link_policy_info;
135 uint16_t packet_type_info;
136 uint16_t role_switch_info;
139 uint8_t _padding[20]; /* leave space for future additions */
152 struct bt_devfilter {
153 bitstr_t bit_decl(packet_mask, 8);
154 bitstr_t bit_decl(event_mask, 256);
157 struct bt_devinquiry {
159 uint8_t pscan_rep_mode;
160 uint8_t pscan_period_mode;
161 uint8_t dev_class[3];
162 uint16_t clock_offset;
167 typedef int (bt_devenum_cb_t)(int, struct bt_devinfo const *, void *);
169 int bt_devopen (char const *devname);
170 int bt_devclose(int s);
171 int bt_devsend (int s, uint16_t opcode, void *param, size_t plen);
172 ssize_t bt_devrecv (int s, void *buf, size_t size, time_t to);
173 int bt_devreq (int s, struct bt_devreq *r, time_t to);
174 int bt_devfilter(int s, struct bt_devfilter const *newp,
175 struct bt_devfilter *oldp);
176 void bt_devfilter_pkt_set(struct bt_devfilter *filter, uint8_t type);
177 void bt_devfilter_pkt_clr(struct bt_devfilter *filter, uint8_t type);
178 int bt_devfilter_pkt_tst(struct bt_devfilter const *filter, uint8_t type);
179 void bt_devfilter_evt_set(struct bt_devfilter *filter, uint8_t event);
180 void bt_devfilter_evt_clr(struct bt_devfilter *filter, uint8_t event);
181 int bt_devfilter_evt_tst(struct bt_devfilter const *filter, uint8_t event);
182 int bt_devinquiry(char const *devname, time_t length, int num_rsp,
183 struct bt_devinquiry **ii);
184 char * bt_devremote_name(char const *devname, const bdaddr_t *remote,
185 time_t to, uint16_t clk_off,
186 uint8_t ps_rep_mode, uint8_t ps_mode);
187 int bt_devinfo (struct bt_devinfo *di);
188 int bt_devenum (bt_devenum_cb_t cb, void *arg);
190 static __inline char *
191 bt_devremote_name_gen(char const *btooth_devname, const bdaddr_t *remote)
193 return (bt_devremote_name(btooth_devname, remote, 0, 0x0000,
194 NG_HCI_SCAN_REP_MODE0, NG_HCI_MANDATORY_PAGE_SCAN_MODE));
198 * bdaddr utility functions (from NetBSD)
202 bdaddr_same(const bdaddr_t *a, const bdaddr_t *b)
204 return (a->b[0] == b->b[0] && a->b[1] == b->b[1] &&
205 a->b[2] == b->b[2] && a->b[3] == b->b[3] &&
206 a->b[4] == b->b[4] && a->b[5] == b->b[5]);
210 bdaddr_any(const bdaddr_t *a)
212 return (a->b[0] == 0 && a->b[1] == 0 && a->b[2] == 0 &&
213 a->b[3] == 0 && a->b[4] == 0 && a->b[5] == 0);
217 bdaddr_copy(bdaddr_t *d, const bdaddr_t *s)
229 #endif /* ndef _BLUETOOTH_H_ */