xref: /netbsd-src/sys/netbt/hci.h (revision 404fbe5fb94ca1e054339640cabb2801ce52dd30)
1 /*	$NetBSD: hci.h,v 1.28 2008/09/08 23:36:55 gmcgarry Exp $	*/
2 
3 /*-
4  * Copyright (c) 2005 Iain Hibbert.
5  * Copyright (c) 2006 Itronix Inc.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. The name of Itronix Inc. may not be used to endorse
17  *    or promote products derived from this software without specific
18  *    prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY ITRONIX INC. ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
22  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
23  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL ITRONIX INC. BE LIABLE FOR ANY
24  * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
25  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
26  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
27  * ON ANY THEORY OF LIABILITY, WHETHER IN
28  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30  * POSSIBILITY OF SUCH DAMAGE.
31  */
32 /*-
33  * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com>
34  * All rights reserved.
35  *
36  * Redistribution and use in source and binary forms, with or without
37  * modification, are permitted provided that the following conditions
38  * are met:
39  * 1. Redistributions of source code must retain the above copyright
40  *    notice, this list of conditions and the following disclaimer.
41  * 2. Redistributions in binary form must reproduce the above copyright
42  *    notice, this list of conditions and the following disclaimer in the
43  *    documentation and/or other materials provided with the distribution.
44  *
45  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
46  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
47  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
49  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
50  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
51  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
54  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
55  * SUCH DAMAGE.
56  *
57  * $Id: hci.h,v 1.28 2008/09/08 23:36:55 gmcgarry Exp $
58  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.6 2005/01/07 01:45:43 imp Exp $
59  */
60 
61 /*
62  * This file contains everything that applications need to know from
63  * Host Controller Interface (HCI). Information taken from Bluetooth
64  * Core Specifications (v1.1, v2.0 and v2.1)
65  *
66  * This file can be included by both kernel and userland applications.
67  *
68  * NOTE: Here and after Bluetooth device is called a "unit". Bluetooth
69  *       specification refers to both devices and units. They are the
70  *       same thing (I think), so to be consistent word "unit" will be
71  *       used.
72  */
73 
74 #ifndef _NETBT_HCI_H_
75 #define _NETBT_HCI_H_
76 
77 #include <netbt/bluetooth.h>
78 
79 /**************************************************************************
80  **************************************************************************
81  **                   Common defines and types (HCI)
82  **************************************************************************
83  **************************************************************************/
84 
85 #define HCI_LAP_SIZE			3   /* unit LAP */
86 #define HCI_KEY_SIZE			16  /* link key */
87 #define HCI_PIN_SIZE			16  /* link PIN */
88 #define HCI_EVENT_MASK_SIZE		8   /* event mask */
89 #define HCI_CLASS_SIZE			3   /* unit class */
90 #define HCI_FEATURES_SIZE		8   /* LMP features */
91 #define HCI_UNIT_NAME_SIZE		248 /* unit name size */
92 #define HCI_DEVNAME_SIZE		16  /* same as dv_xname */
93 #define HCI_COMMANDS_SIZE		64  /* supported commands mask */
94 
95 /* HCI specification */
96 #define HCI_SPEC_V10			0x00 /* v1.0 */
97 #define HCI_SPEC_V11			0x01 /* v1.1 */
98 #define HCI_SPEC_V12			0x02 /* v1.2 */
99 #define HCI_SPEC_V20			0x03 /* v2.0 */
100 #define HCI_SPEC_V21			0x04 /* v2.1 */
101 /* 0x05 - 0xFF - reserved for future use */
102 
103 /* LMP features (and page 0 of extended features) */
104 /* ------------------- byte 0 --------------------*/
105 #define HCI_LMP_3SLOT			0x01
106 #define HCI_LMP_5SLOT			0x02
107 #define HCI_LMP_ENCRYPTION		0x04
108 #define HCI_LMP_SLOT_OFFSET		0x08
109 #define HCI_LMP_TIMIACCURACY		0x10
110 #define HCI_LMP_ROLE_SWITCH		0x20
111 #define HCI_LMP_HOLD_MODE		0x40
112 #define HCI_LMP_SNIFF_MODE		0x80
113 /* ------------------- byte 1 --------------------*/
114 #define HCI_LMP_PARK_MODE		0x01
115 #define HCI_LMP_RSSI			0x02
116 #define HCI_LMP_CHANNEL_QUALITY		0x04
117 #define HCI_LMP_SCO_LINK		0x08
118 #define HCI_LMP_HV2_PKT			0x10
119 #define HCI_LMP_HV3_PKT			0x20
120 #define HCI_LMP_ULAW_LOG		0x40
121 #define HCI_LMP_ALAW_LOG		0x80
122 /* ------------------- byte 2 --------------------*/
123 #define HCI_LMP_CVSD			0x01
124 #define HCI_LMP_PAGISCHEME		0x02
125 #define HCI_LMP_POWER_CONTROL		0x04
126 #define HCI_LMP_TRANSPARENT_SCO		0x08
127 #define HCI_LMP_FLOW_CONTROL_LAG0	0x10
128 #define HCI_LMP_FLOW_CONTROL_LAG1	0x20
129 #define HCI_LMP_FLOW_CONTROL_LAG2	0x40
130 #define HCI_LMP_BC_ENCRYPTION		0x80
131 /* ------------------- byte 3 --------------------*/
132 /* reserved				0x01 */
133 #define HCI_LMP_EDR_ACL_2MBPS		0x02
134 #define HCI_LMP_EDR_ACL_3MBPS		0x04
135 #define HCI_LMP_ENHANCED_ISCAN		0x08
136 #define HCI_LMP_INTERLACED_ISCAN	0x10
137 #define HCI_LMP_INTERLACED_PSCAN	0x20
138 #define HCI_LMP_RSSI_INQUIRY		0x40
139 #define HCI_LMP_EV3_PKT			0x80
140 /* ------------------- byte 4 --------------------*/
141 #define HCI_LMP_EV4_PKT			0x01
142 #define HCI_LMP_EV5_PKT			0x02
143 /* reserved				0x04 */
144 #define HCI_LMP_AFH_CAPABLE_SLAVE	0x08
145 #define HCI_LMP_AFH_CLASS_SLAVE		0x10
146 /* reserved				0x20 */
147 /* reserved				0x40 */
148 #define HCI_LMP_3SLOT_EDR_ACL		0x80
149 /* ------------------- byte 5 --------------------*/
150 #define HCI_LMP_5SLOT_EDR_ACL		0x01
151 #define HCI_LMP_SNIFF_SUBRATING		0x02
152 #define HCI_LMP_PAUSE_ENCRYPTION	0x04
153 #define HCI_LMP_AFH_CAPABLE_MASTER	0x08
154 #define HCI_LMP_AFH_CLASS_MASTER	0x10
155 #define HCI_LMP_EDR_eSCO_2MBPS		0x20
156 #define HCI_LMP_EDR_eSCO_3MBPS		0x40
157 #define HCI_LMP_3SLOT_EDR_eSCO		0x80
158 /* ------------------- byte 6 --------------------*/
159 #define HCI_LMP_EXTENDED_INQUIRY	0x01
160 /* reserved				0x02 */
161 /* reserved				0x04 */
162 #define HCI_LMP_SIMPLE_PAIRING		0x08
163 #define HCI_LMP_ENCAPSULATED_PDU	0x10
164 #define HCI_LMP_ERRDATA_REPORTING	0x20
165 #define HCI_LMP_NOFLUSH_PB_FLAG		0x40
166 /* reserved				0x80 */
167 /* ------------------- byte 7 --------------------*/
168 #define HCI_LMP_LINK_SUPERVISION_TO	0x01
169 #define HCI_LMP_INQ_RSP_TX_POWER	0x02
170 #define HCI_LMP_EXTENDED_FEATURES	0x80
171 
172 /* Link types */
173 #define HCI_LINK_SCO			0x00 /* Voice */
174 #define HCI_LINK_ACL			0x01 /* Data */
175 #define HCI_LINK_eSCO			0x02 /* eSCO */
176 /* 0x03 - 0xFF - reserved for future use */
177 
178 /*
179  * ACL/SCO packet type bits are set to enable the
180  * packet type, except for 2MBPS and 3MBPS when they
181  * are unset to enable the packet type.
182  */
183 /* ACL Packet types for "Create Connection" */
184 #define HCI_PKT_2MBPS_DH1	0x0002
185 #define HCI_PKT_3MBPS_DH1	0x0004
186 #define HCI_PKT_DM1		0x0008
187 #define HCI_PKT_DH1		0x0010
188 #define HCI_PKT_2MBPS_DH3	0x0100
189 #define HCI_PKT_3MBPS_DH3	0x0200
190 #define HCI_PKT_DM3		0x0400
191 #define HCI_PKT_DH3		0x0800
192 #define HCI_PKT_2MBPS_DH5	0x1000
193 #define HCI_PKT_3MBPS_DH5	0x2000
194 #define HCI_PKT_DM5		0x4000
195 #define HCI_PKT_DH5		0x8000
196 
197 /* SCO Packet types for "Setup Synchronous Connection" */
198 #define HCI_PKT_HV1		0x0001
199 #define HCI_PKT_HV2		0x0002
200 #define HCI_PKT_HV3		0x0004
201 #define HCI_PKT_EV3		0x0008
202 #define HCI_PKT_EV4		0x0010
203 #define HCI_PKT_EV5		0x0020
204 #define HCI_PKT_2MBPS_EV3	0x0040
205 #define HCI_PKT_3MBPS_EV3	0x0080
206 #define HCI_PKT_2MBPS_EV5	0x0100
207 #define HCI_PKT_3MBPS_EV5	0x0200
208 
209 /*
210  * Connection modes/Unit modes
211  *
212  * This is confusing. It means that one of the units change its mode
213  * for the specific connection. For example one connection was put on
214  * hold (but i could be wrong :)
215  */
216 
217 /* Page scan modes (are deprecated) */
218 #define HCI_MANDATORY_PAGE_SCAN_MODE		0x00
219 #define HCI_OPTIONAL_PAGE_SCAN_MODE1		0x01
220 #define HCI_OPTIONAL_PAGE_SCAN_MODE2		0x02
221 #define HCI_OPTIONAL_PAGE_SCAN_MODE3		0x03
222 /* 0x04 - 0xFF - reserved for future use */
223 
224 /* Page scan repetition modes */
225 #define HCI_SCAN_REP_MODE0			0x00
226 #define HCI_SCAN_REP_MODE1			0x01
227 #define HCI_SCAN_REP_MODE2			0x02
228 /* 0x03 - 0xFF - reserved for future use */
229 
230 /* Page scan period modes */
231 #define HCI_PAGE_SCAN_PERIOD_MODE0		0x00
232 #define HCI_PAGE_SCAN_PERIOD_MODE1		0x01
233 #define HCI_PAGE_SCAN_PERIOD_MODE2		0x02
234 /* 0x03 - 0xFF - reserved for future use */
235 
236 /* Scan enable */
237 #define HCI_NO_SCAN_ENABLE			0x00
238 #define HCI_INQUIRY_SCAN_ENABLE			0x01
239 #define HCI_PAGE_SCAN_ENABLE			0x02
240 /* 0x04 - 0xFF - reserved for future use */
241 
242 /* Hold mode activities */
243 #define HCI_HOLD_MODE_NO_CHANGE			0x00
244 #define HCI_HOLD_MODE_SUSPEND_PAGE_SCAN		0x01
245 #define HCI_HOLD_MODE_SUSPEND_INQUIRY_SCAN	0x02
246 #define HCI_HOLD_MODE_SUSPEND_PERIOD_INQUIRY	0x04
247 /* 0x08 - 0x80 - reserved for future use */
248 
249 /* Connection roles */
250 #define HCI_ROLE_MASTER				0x00
251 #define HCI_ROLE_SLAVE				0x01
252 /* 0x02 - 0xFF - reserved for future use */
253 
254 /* Key flags */
255 #define HCI_USE_SEMI_PERMANENT_LINK_KEYS	0x00
256 #define HCI_USE_TEMPORARY_LINK_KEY		0x01
257 /* 0x02 - 0xFF - reserved for future use */
258 
259 /* Pin types */
260 #define HCI_PIN_TYPE_VARIABLE			0x00
261 #define HCI_PIN_TYPE_FIXED			0x01
262 
263 /* Link key types */
264 #define HCI_LINK_KEY_TYPE_COMBINATION_KEY	0x00
265 #define HCI_LINK_KEY_TYPE_LOCAL_UNIT_KEY	0x01
266 #define HCI_LINK_KEY_TYPE_REMOTE_UNIT_KEY	0x02
267 /* 0x03 - 0xFF - reserved for future use */
268 
269 /* Encryption modes */
270 #define HCI_ENCRYPTION_MODE_NONE		0x00
271 #define HCI_ENCRYPTION_MODE_P2P			0x01
272 #define HCI_ENCRYPTION_MODE_ALL			0x02
273 /* 0x03 - 0xFF - reserved for future use */
274 
275 /* Quality of service types */
276 #define HCI_SERVICE_TYPE_NO_TRAFFIC		0x00
277 #define HCI_SERVICE_TYPE_BEST_EFFORT		0x01
278 #define HCI_SERVICE_TYPE_GUARANTEED		0x02
279 /* 0x03 - 0xFF - reserved for future use */
280 
281 /* Link policy settings */
282 #define HCI_LINK_POLICY_DISABLE_ALL_LM_MODES	0x0000
283 #define HCI_LINK_POLICY_ENABLE_ROLE_SWITCH	0x0001 /* Master/Slave switch */
284 #define HCI_LINK_POLICY_ENABLE_HOLD_MODE	0x0002
285 #define HCI_LINK_POLICY_ENABLE_SNIFF_MODE	0x0004
286 #define HCI_LINK_POLICY_ENABLE_PARK_MODE	0x0008
287 /* 0x0010 - 0x8000 - reserved for future use */
288 
289 /* Event masks */
290 #define HCI_EVMSK_ALL				0x00000000ffffffff
291 #define HCI_EVMSK_NONE				0x0000000000000000
292 #define HCI_EVMSK_INQUIRY_COMPL			0x0000000000000001
293 #define HCI_EVMSK_INQUIRY_RESULT		0x0000000000000002
294 #define HCI_EVMSK_CON_COMPL			0x0000000000000004
295 #define HCI_EVMSK_CON_REQ			0x0000000000000008
296 #define HCI_EVMSK_DISCON_COMPL			0x0000000000000010
297 #define HCI_EVMSK_AUTH_COMPL			0x0000000000000020
298 #define HCI_EVMSK_REMOTE_NAME_REQ_COMPL		0x0000000000000040
299 #define HCI_EVMSK_ENCRYPTION_CHANGE		0x0000000000000080
300 #define HCI_EVMSK_CHANGE_CON_LINK_KEY_COMPL	0x0000000000000100
301 #define HCI_EVMSK_MASTER_LINK_KEY_COMPL		0x0000000000000200
302 #define HCI_EVMSK_READ_REMOTE_FEATURES_COMPL	0x0000000000000400
303 #define HCI_EVMSK_READ_REMOTE_VER_INFO_COMPL	0x0000000000000800
304 #define HCI_EVMSK_QOS_SETUP_COMPL		0x0000000000001000
305 #define HCI_EVMSK_COMMAND_COMPL			0x0000000000002000
306 #define HCI_EVMSK_COMMAND_STATUS		0x0000000000004000
307 #define HCI_EVMSK_HARDWARE_ERROR		0x0000000000008000
308 #define HCI_EVMSK_FLUSH_OCCUR			0x0000000000010000
309 #define HCI_EVMSK_ROLE_CHANGE			0x0000000000020000
310 #define HCI_EVMSK_NUM_COMPL_PKTS		0x0000000000040000
311 #define HCI_EVMSK_MODE_CHANGE			0x0000000000080000
312 #define HCI_EVMSK_RETURN_LINK_KEYS		0x0000000000100000
313 #define HCI_EVMSK_PIN_CODE_REQ			0x0000000000200000
314 #define HCI_EVMSK_LINK_KEY_REQ			0x0000000000400000
315 #define HCI_EVMSK_LINK_KEY_NOTIFICATION		0x0000000000800000
316 #define HCI_EVMSK_LOOPBACK_COMMAND		0x0000000001000000
317 #define HCI_EVMSK_DATA_BUFFER_OVERFLOW		0x0000000002000000
318 #define HCI_EVMSK_MAX_SLOT_CHANGE		0x0000000004000000
319 #define HCI_EVMSK_READ_CLOCK_OFFSET_COMLETE	0x0000000008000000
320 #define HCI_EVMSK_CON_PKT_TYPE_CHANGED		0x0000000010000000
321 #define HCI_EVMSK_QOS_VIOLATION			0x0000000020000000
322 #define HCI_EVMSK_PAGE_SCAN_MODE_CHANGE		0x0000000040000000
323 #define HCI_EVMSK_PAGE_SCAN_REP_MODE_CHANGE	0x0000000080000000
324 /* 0x0000000100000000 - 0x8000000000000000 - reserved for future use */
325 
326 /* Filter types */
327 #define HCI_FILTER_TYPE_NONE			0x00
328 #define HCI_FILTER_TYPE_INQUIRY_RESULT		0x01
329 #define HCI_FILTER_TYPE_CON_SETUP		0x02
330 /* 0x03 - 0xFF - reserved for future use */
331 
332 /* Filter condition types for HCI_FILTER_TYPE_INQUIRY_RESULT */
333 #define HCI_FILTER_COND_INQUIRY_NEW_UNIT	0x00
334 #define HCI_FILTER_COND_INQUIRY_UNIT_CLASS	0x01
335 #define HCI_FILTER_COND_INQUIRY_BDADDR		0x02
336 /* 0x03 - 0xFF - reserved for future use */
337 
338 /* Filter condition types for HCI_FILTER_TYPE_CON_SETUP */
339 #define HCI_FILTER_COND_CON_ANY_UNIT		0x00
340 #define HCI_FILTER_COND_CON_UNIT_CLASS		0x01
341 #define HCI_FILTER_COND_CON_BDADDR		0x02
342 /* 0x03 - 0xFF - reserved for future use */
343 
344 /* Xmit level types */
345 #define HCI_XMIT_LEVEL_CURRENT			0x00
346 #define HCI_XMIT_LEVEL_MAXIMUM			0x01
347 /* 0x02 - 0xFF - reserved for future use */
348 
349 /* Host Controller to Host flow control */
350 #define HCI_HC2H_FLOW_CONTROL_NONE		0x00
351 #define HCI_HC2H_FLOW_CONTROL_ACL		0x01
352 #define HCI_HC2H_FLOW_CONTROL_SCO		0x02
353 #define HCI_HC2H_FLOW_CONTROL_BOTH		0x03
354 /* 0x04 - 0xFF - reserved future use */
355 
356 /* Loopback modes */
357 #define HCI_LOOPBACK_NONE			0x00
358 #define HCI_LOOPBACK_LOCAL			0x01
359 #define HCI_LOOPBACK_REMOTE			0x02
360 /* 0x03 - 0xFF - reserved future use */
361 
362 /**************************************************************************
363  **************************************************************************
364  **                 Link level defines, headers and types
365  **************************************************************************
366  **************************************************************************/
367 
368 /*
369  * Macro(s) to combine OpCode and extract OGF (OpCode Group Field)
370  * and OCF (OpCode Command Field) from OpCode.
371  */
372 
373 #define HCI_OPCODE(gf,cf)		((((gf) & 0x3f) << 10) | ((cf) & 0x3ff))
374 #define HCI_OCF(op)			((op) & 0x3ff)
375 #define HCI_OGF(op)			(((op) >> 10) & 0x3f)
376 
377 /*
378  * Macro(s) to extract/combine connection handle, BC (Broadcast) and
379  * PB (Packet boundary) flags.
380  */
381 
382 #define HCI_CON_HANDLE(h)		((h) & 0x0fff)
383 #define HCI_PB_FLAG(h)			(((h) & 0x3000) >> 12)
384 #define HCI_BC_FLAG(h)			(((h) & 0xc000) >> 14)
385 #define HCI_MK_CON_HANDLE(h, pb, bc) \
386 	(((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14))
387 
388 /* PB flag values */
389 					/* 00 - reserved for future use */
390 #define	HCI_PACKET_FRAGMENT		0x1
391 #define	HCI_PACKET_START		0x2
392 					/* 11 - reserved for future use */
393 
394 /* BC flag values */
395 #define HCI_POINT2POINT			0x0 /* only Host controller to Host */
396 #define HCI_BROADCAST_ACTIVE		0x1 /* both directions */
397 #define HCI_BROADCAST_PICONET		0x2 /* both directions */
398 					/* 11 - reserved for future use */
399 
400 /* HCI command packet header */
401 typedef struct {
402 	uint8_t		type;	/* MUST be 0x01 */
403 	uint16_t	opcode; /* OpCode */
404 	uint8_t		length; /* parameter(s) length in bytes */
405 } __packed hci_cmd_hdr_t;
406 
407 #define HCI_CMD_PKT			0x01
408 #define HCI_CMD_PKT_SIZE		(sizeof(hci_cmd_hdr_t) + 0xff)
409 
410 /* ACL data packet header */
411 typedef struct {
412 	uint8_t		type;	     /* MUST be 0x02 */
413 	uint16_t	con_handle;  /* connection handle + PB + BC flags */
414 	uint16_t	length;      /* payload length in bytes */
415 } __packed hci_acldata_hdr_t;
416 
417 #define HCI_ACL_DATA_PKT		0x02
418 #define HCI_ACL_PKT_SIZE		(sizeof(hci_acldata_hdr_t) + 0xffff)
419 
420 /* SCO data packet header */
421 typedef struct {
422 	uint8_t		type;	    /* MUST be 0x03 */
423 	uint16_t	con_handle; /* connection handle + reserved bits */
424 	uint8_t		length;     /* payload length in bytes */
425 } __packed hci_scodata_hdr_t;
426 
427 #define HCI_SCO_DATA_PKT		0x03
428 #define HCI_SCO_PKT_SIZE		(sizeof(hci_scodata_hdr_t) + 0xff)
429 
430 /* HCI event packet header */
431 typedef struct {
432 	uint8_t		type;	/* MUST be 0x04 */
433 	uint8_t		event;  /* event */
434 	uint8_t		length; /* parameter(s) length in bytes */
435 } __packed hci_event_hdr_t;
436 
437 #define HCI_EVENT_PKT			0x04
438 #define HCI_EVENT_PKT_SIZE		(sizeof(hci_event_hdr_t) + 0xff)
439 
440 /* HCI status return parameter */
441 typedef struct {
442 	uint8_t		status; /* 0x00 - success */
443 } __packed hci_status_rp;
444 
445 /**************************************************************************
446  **************************************************************************
447  ** OGF 0x01	Link control commands and return parameters
448  **************************************************************************
449  **************************************************************************/
450 
451 #define HCI_OGF_LINK_CONTROL			0x01
452 
453 #define HCI_OCF_INQUIRY					0x0001
454 #define HCI_CMD_INQUIRY					0x0401
455 typedef struct {
456 	uint8_t		lap[HCI_LAP_SIZE]; /* LAP */
457 	uint8_t		inquiry_length;    /* (N x 1.28) sec */
458 	uint8_t		num_responses;     /* Max. # of responses */
459 } __packed hci_inquiry_cp;
460 /* No return parameter(s) */
461 
462 #define HCI_OCF_INQUIRY_CANCEL				0x0002
463 #define HCI_CMD_INQUIRY_CANCEL				0x0402
464 /* No command parameter(s) */
465 typedef hci_status_rp	hci_inquiry_cancel_rp;
466 
467 #define HCI_OCF_PERIODIC_INQUIRY			0x0003
468 #define HCI_CMD_PERIODIC_INQUIRY			0x0403
469 typedef struct {
470 	uint16_t	max_period_length; /* Max. and min. amount of time */
471 	uint16_t	min_period_length; /* between consecutive inquiries */
472 	uint8_t		lap[HCI_LAP_SIZE]; /* LAP */
473 	uint8_t		inquiry_length;    /* (inquiry_length * 1.28) sec */
474 	uint8_t		num_responses;     /* Max. # of responses */
475 } __packed hci_periodic_inquiry_cp;
476 
477 typedef hci_status_rp	hci_periodic_inquiry_rp;
478 
479 #define HCI_OCF_EXIT_PERIODIC_INQUIRY			0x0004
480 #define HCI_CMD_EXIT_PERIODIC_INQUIRY			0x0404
481 /* No command parameter(s) */
482 typedef hci_status_rp	hci_exit_periodic_inquiry_rp;
483 
484 #define HCI_OCF_CREATE_CON				0x0005
485 #define HCI_CMD_CREATE_CON				0x0405
486 typedef struct {
487 	bdaddr_t	bdaddr;             /* destination address */
488 	uint16_t	pkt_type;           /* packet type */
489 	uint8_t		page_scan_rep_mode; /* page scan repetition mode */
490 	uint8_t		page_scan_mode;     /* reserved - set to 0x00 */
491 	uint16_t	clock_offset;       /* clock offset */
492 	uint8_t		accept_role_switch; /* accept role switch? 0x00 == No */
493 } __packed hci_create_con_cp;
494 /* No return parameter(s) */
495 
496 #define HCI_OCF_DISCONNECT				0x0006
497 #define HCI_CMD_DISCONNECT				0x0406
498 typedef struct {
499 	uint16_t	con_handle; /* connection handle */
500 	uint8_t		reason;     /* reason to disconnect */
501 } __packed hci_discon_cp;
502 /* No return parameter(s) */
503 
504 /* Add SCO Connection is deprecated */
505 #define HCI_OCF_ADD_SCO_CON				0x0007
506 #define HCI_CMD_ADD_SCO_CON				0x0407
507 typedef struct {
508 	uint16_t	con_handle; /* connection handle */
509 	uint16_t	pkt_type;   /* packet type */
510 } __packed hci_add_sco_con_cp;
511 /* No return parameter(s) */
512 
513 #define HCI_OCF_CREATE_CON_CANCEL			0x0008
514 #define HCI_CMD_CREATE_CON_CANCEL			0x0408
515 typedef struct {
516 	bdaddr_t	bdaddr;		/* destination address */
517 } __packed hci_create_con_cancel_cp;
518 
519 typedef struct {
520 	uint8_t		status;		/* 0x00 - success */
521 	bdaddr_t	bdaddr;		/* destination address */
522 } __packed hci_create_con_cancel_rp;
523 
524 #define HCI_OCF_ACCEPT_CON				0x0009
525 #define HCI_CMD_ACCEPT_CON				0x0409
526 typedef struct {
527 	bdaddr_t	bdaddr; /* address of unit to be connected */
528 	uint8_t		role;   /* connection role */
529 } __packed hci_accept_con_cp;
530 /* No return parameter(s) */
531 
532 #define HCI_OCF_REJECT_CON				0x000a
533 #define HCI_CMD_REJECT_CON				0x040A
534 typedef struct {
535 	bdaddr_t	bdaddr; /* remote address */
536 	uint8_t		reason; /* reason to reject */
537 } __packed hci_reject_con_cp;
538 /* No return parameter(s) */
539 
540 #define HCI_OCF_LINK_KEY_REP				0x000b
541 #define HCI_CMD_LINK_KEY_REP				0x040B
542 typedef struct {
543 	bdaddr_t	bdaddr;            /* remote address */
544 	uint8_t		key[HCI_KEY_SIZE]; /* key */
545 } __packed hci_link_key_rep_cp;
546 
547 typedef struct {
548 	uint8_t		status; /* 0x00 - success */
549 	bdaddr_t	bdaddr; /* unit address */
550 } __packed hci_link_key_rep_rp;
551 
552 #define HCI_OCF_LINK_KEY_NEG_REP			0x000c
553 #define HCI_CMD_LINK_KEY_NEG_REP			0x040C
554 typedef struct {
555 	bdaddr_t	bdaddr; /* remote address */
556 } __packed hci_link_key_neg_rep_cp;
557 
558 typedef struct {
559 	uint8_t		status; /* 0x00 - success */
560 	bdaddr_t	bdaddr; /* unit address */
561 } __packed hci_link_key_neg_rep_rp;
562 
563 #define HCI_OCF_PIN_CODE_REP				0x000d
564 #define HCI_CMD_PIN_CODE_REP				0x040D
565 typedef struct {
566 	bdaddr_t	bdaddr;               /* remote address */
567 	uint8_t		pin_size;             /* pin code length (in bytes) */
568 	uint8_t		pin[HCI_PIN_SIZE];    /* pin code */
569 } __packed hci_pin_code_rep_cp;
570 
571 typedef struct {
572 	uint8_t		status; /* 0x00 - success */
573 	bdaddr_t	bdaddr; /* unit address */
574 } __packed hci_pin_code_rep_rp;
575 
576 #define HCI_OCF_PIN_CODE_NEG_REP			0x000e
577 #define HCI_CMD_PIN_CODE_NEG_REP			0x040E
578 typedef struct {
579 	bdaddr_t	bdaddr; /* remote address */
580 } __packed hci_pin_code_neg_rep_cp;
581 
582 typedef struct {
583 	uint8_t		status; /* 0x00 - success */
584 	bdaddr_t	bdaddr; /* unit address */
585 } __packed hci_pin_code_neg_rep_rp;
586 
587 #define HCI_OCF_CHANGE_CON_PACKET_TYPE			0x000f
588 #define HCI_CMD_CHANGE_CON_PACKET_TYPE			0x040F
589 typedef struct {
590 	uint16_t	con_handle; /* connection handle */
591 	uint16_t	pkt_type;   /* packet type */
592 } __packed hci_change_con_pkt_type_cp;
593 /* No return parameter(s) */
594 
595 #define HCI_OCF_AUTH_REQ				0x0011
596 #define HCI_CMD_AUTH_REQ				0x0411
597 typedef struct {
598 	uint16_t	con_handle; /* connection handle */
599 } __packed hci_auth_req_cp;
600 /* No return parameter(s) */
601 
602 #define HCI_OCF_SET_CON_ENCRYPTION			0x0013
603 #define HCI_CMD_SET_CON_ENCRYPTION			0x0413
604 typedef struct {
605 	uint16_t	con_handle;        /* connection handle */
606 	uint8_t		encryption_enable; /* 0x00 - disable, 0x01 - enable */
607 } __packed hci_set_con_encryption_cp;
608 /* No return parameter(s) */
609 
610 #define HCI_OCF_CHANGE_CON_LINK_KEY			0x0015
611 #define HCI_CMD_CHANGE_CON_LINK_KEY			0x0415
612 typedef struct {
613 	uint16_t	con_handle; /* connection handle */
614 } __packed hci_change_con_link_key_cp;
615 /* No return parameter(s) */
616 
617 #define HCI_OCF_MASTER_LINK_KEY				0x0017
618 #define HCI_CMD_MASTER_LINK_KEY				0x0417
619 typedef struct {
620 	uint8_t		key_flag; /* key flag */
621 } __packed hci_master_link_key_cp;
622 /* No return parameter(s) */
623 
624 #define HCI_OCF_REMOTE_NAME_REQ				0x0019
625 #define HCI_CMD_REMOTE_NAME_REQ				0x0419
626 typedef struct {
627 	bdaddr_t	bdaddr;             /* remote address */
628 	uint8_t		page_scan_rep_mode; /* page scan repetition mode */
629 	uint8_t		page_scan_mode;     /* page scan mode */
630 	uint16_t	clock_offset;       /* clock offset */
631 } __packed hci_remote_name_req_cp;
632 /* No return parameter(s) */
633 
634 #define HCI_OCF_REMOTE_NAME_REQ_CANCEL			0x001a
635 #define HCI_CMD_REMOTE_NAME_REQ_CANCEL			0x041A
636 typedef struct {
637 	bdaddr_t	bdaddr;             /* remote address */
638 } __packed hci_remote_name_req_cancel_cp;
639 
640 typedef struct {
641 	uint8_t		status;		/* 0x00 - success */
642 	bdaddr_t	bdaddr;         /* remote address */
643 } __packed hci_remote_name_req_cancel_rp;
644 
645 #define HCI_OCF_READ_REMOTE_FEATURES			0x001b
646 #define HCI_CMD_READ_REMOTE_FEATURES			0x041B
647 typedef struct {
648 	uint16_t	con_handle; /* connection handle */
649 } __packed hci_read_remote_features_cp;
650 /* No return parameter(s) */
651 
652 #define HCI_OCF_READ_REMOTE_EXTENDED_FEATURES		0x001c
653 #define HCI_CMD_READ_REMOTE_EXTENDED_FEATURES		0x041C
654 typedef struct {
655 	uint16_t	con_handle;	/* connection handle */
656 	uint8_t		page;		/* page number */
657 } __packed hci_read_remote_extended_features_cp;
658 /* No return parameter(s) */
659 
660 #define HCI_OCF_READ_REMOTE_VER_INFO			0x001d
661 #define HCI_CMD_READ_REMOTE_VER_INFO			0x041D
662 typedef struct {
663 	uint16_t	con_handle; /* connection handle */
664 } __packed hci_read_remote_ver_info_cp;
665 /* No return parameter(s) */
666 
667 #define HCI_OCF_READ_CLOCK_OFFSET			0x001f
668 #define HCI_CMD_READ_CLOCK_OFFSET			0x041F
669 typedef struct {
670 	uint16_t	con_handle; /* connection handle */
671 } __packed hci_read_clock_offset_cp;
672 /* No return parameter(s) */
673 
674 #define HCI_OCF_READ_LMP_HANDLE				0x0020
675 #define HCI_CMD_READ_LMP_HANDLE				0x0420
676 typedef struct {
677 	uint16_t	con_handle; /* connection handle */
678 } __packed hci_read_lmp_handle_cp;
679 
680 typedef struct {
681 	uint8_t		status;	    /* 0x00 - success */
682 	uint16_t	con_handle; /* connection handle */
683 	uint8_t		lmp_handle; /* LMP handle */
684 	uint32_t	reserved;   /* reserved */
685 } __packed hci_read_lmp_handle_rp;
686 
687 #define HCI_OCF_SETUP_SCO_CON				0x0028
688 #define HCI_CMD_SETUP_SCO_CON				0x0428
689 typedef struct {
690 	uint16_t	con_handle;	/* connection handle */
691 	uint32_t	tx_bandwidth;	/* transmit bandwidth */
692 	uint32_t	rx_bandwidth;	/* receive bandwidth */
693 	uint16_t	latency;	/* maximum latency */
694 	uint16_t	voice;		/* voice setting */
695 	uint8_t		rt_effort;	/* retransmission effort */
696 	uint16_t	pkt_type;	/* packet types */
697 } __packed hci_setup_sco_con_cp;
698 /* No return parameter(s) */
699 
700 #define HCI_OCF_ACCEPT_SCO_CON_REQ			0x0029
701 #define HCI_CMD_ACCEPT_SCO_CON_REQ			0x0429
702 typedef struct {
703 	bdaddr_t	bdaddr;		/* remote address */
704 	uint32_t	tx_bandwidth;	/* transmit bandwidth */
705 	uint32_t	rx_bandwidth;	/* receive bandwidth */
706 	uint16_t	latency;	/* maximum latency */
707 	uint16_t	content;	/* voice setting */
708 	uint8_t		rt_effort;	/* retransmission effort */
709 	uint16_t	pkt_type;	/* packet types */
710 } __packed hci_accept_sco_con_req_cp;
711 /* No return parameter(s) */
712 
713 #define HCI_OCF_REJECT_SCO_CON_REQ			0x002a
714 #define HCI_CMD_REJECT_SCO_CON_REQ			0x042a
715 typedef struct {
716 	bdaddr_t	bdaddr;		/* remote address */
717 	uint8_t		reason;		/* reject error code */
718 } __packed hci_reject_sco_con_req_cp;
719 /* No return parameter(s) */
720 
721 #define HCI_OCF_IO_CAPABILITY_REP			0x002b
722 #define HCI_CMD_IO_CAPABILITY_REP			0x042a
723 typedef struct {
724 	bdaddr_t	bdaddr;		/* remote address */
725 	uint8_t		io_cap;		/* IO capability */
726 	uint8_t		oob_data;	/* OOB data present */
727 	uint8_t		auth_req;	/* auth requirements */
728 } __packed hci_io_capability_rep_cp;
729 
730 typedef struct {
731 	uint8_t		status;		/* 0x00 - success */
732 	bdaddr_t	bdaddr;		/* remote address */
733 } __packed hci_io_capability_rep_rp;
734 
735 #define HCI_OCF_USER_CONFIRM_REP			0x002c
736 #define HCI_CMD_USER_CONFIRM_REP			0x042c
737 typedef struct {
738 	bdaddr_t	bdaddr;		/* remote address */
739 } __packed hci_user_confirm_rep_cp;
740 
741 typedef struct {
742 	uint8_t		status;		/* 0x00 - success */
743 	bdaddr_t	bdaddr;		/* remote address */
744 } __packed hci_user_confirm_rep_rp;
745 
746 #define HCI_OCF_USER_CONFIRM_NEG_REP			0x002d
747 #define HCI_CMD_USER_CONFIRM_NEG_REP			0x042d
748 typedef struct {
749 	bdaddr_t	bdaddr;		/* remote address */
750 } __packed hci_user_confirm_neg_rep_cp;
751 
752 typedef struct {
753 	uint8_t		status;		/* 0x00 - success */
754 	bdaddr_t	bdaddr;		/* remote address */
755 } __packed hci_user_confirm_neg_rep_rp;
756 
757 #define HCI_OCF_USER_PASSKEY_REP			0x002e
758 #define HCI_CMD_USER_PASSKEY_REP			0x042e
759 typedef struct {
760 	bdaddr_t	bdaddr;		/* remote address */
761 	uint32_t	value;		/* 000000 - 999999 */
762 } __packed hci_user_passkey_rep_cp;
763 
764 typedef struct {
765 	uint8_t		status;		/* 0x00 - success */
766 	bdaddr_t	bdaddr;		/* remote address */
767 } __packed hci_user_passkey_rep_rp;
768 
769 #define HCI_OCF_USER_PASSKEY_NEG_REP			0x002f
770 #define HCI_CMD_USER_PASSKEY_NEG_REP			0x042f
771 typedef struct {
772 	bdaddr_t	bdaddr;		/* remote address */
773 } __packed hci_user_passkey_neg_rep_cp;
774 
775 typedef struct {
776 	uint8_t		status;		/* 0x00 - success */
777 	bdaddr_t	bdaddr;		/* remote address */
778 } __packed hci_user_passkey_neg_rep_rp;
779 
780 #define HCI_OCF_OOB_DATA_REP				0x0030
781 #define HCI_CMD_OOB_DATA_REP				0x0430
782 typedef struct {
783 	bdaddr_t	bdaddr;		/* remote address */
784 	uint8_t		c[16];		/* pairing hash */
785 	uint8_t		r[16];		/* pairing randomizer */
786 } __packed hci_user_oob_data_rep_cp;
787 
788 typedef struct {
789 	uint8_t		status;		/* 0x00 - success */
790 	bdaddr_t	bdaddr;		/* remote address */
791 } __packed hci_user_oob_data_rep_rp;
792 
793 #define HCI_OCF_OOB_DATA_NEG_REP			0x0033
794 #define HCI_CMD_OOB_DATA_NEG_REP			0x0433
795 typedef struct {
796 	bdaddr_t	bdaddr;		/* remote address */
797 } __packed hci_user_oob_data_neg_rep_cp;
798 
799 typedef struct {
800 	uint8_t		status;		/* 0x00 - success */
801 	bdaddr_t	bdaddr;		/* remote address */
802 } __packed hci_user_oob_data_neg_rep_rp;
803 
804 #define HCI_OCF_IO_CAPABILITY_NEG_REP			0x0034
805 #define HCI_CMD_IO_CAPABILITY_NEG_REP			0x0434
806 typedef struct {
807 	bdaddr_t	bdaddr;		/* remote address */
808 	uint8_t		reason;		/* error code */
809 } __packed hci_io_capability_neg_rep_cp;
810 
811 typedef struct {
812 	uint8_t		status;		/* 0x00 - success */
813 	bdaddr_t	bdaddr;		/* remote address */
814 } __packed hci_io_capability_neg_rep_rp;
815 
816 /**************************************************************************
817  **************************************************************************
818  ** OGF 0x02	Link policy commands and return parameters
819  **************************************************************************
820  **************************************************************************/
821 
822 #define HCI_OGF_LINK_POLICY			0x02
823 
824 #define HCI_OCF_HOLD_MODE				0x0001
825 #define HCI_CMD_HOLD_MODE				0x0801
826 typedef struct {
827 	uint16_t	con_handle;   /* connection handle */
828 	uint16_t	max_interval; /* (max_interval * 0.625) msec */
829 	uint16_t	min_interval; /* (max_interval * 0.625) msec */
830 } __packed hci_hold_mode_cp;
831 /* No return parameter(s) */
832 
833 #define HCI_OCF_SNIFF_MODE				0x0003
834 #define HCI_CMD_SNIFF_MODE				0x0803
835 typedef struct {
836 	uint16_t	con_handle;   /* connection handle */
837 	uint16_t	max_interval; /* (max_interval * 0.625) msec */
838 	uint16_t	min_interval; /* (max_interval * 0.625) msec */
839 	uint16_t	attempt;      /* (2 * attempt - 1) * 0.625 msec */
840 	uint16_t	timeout;      /* (2 * attempt - 1) * 0.625 msec */
841 } __packed hci_sniff_mode_cp;
842 /* No return parameter(s) */
843 
844 #define HCI_OCF_EXIT_SNIFF_MODE				0x0004
845 #define HCI_CMD_EXIT_SNIFF_MODE				0x0804
846 typedef struct {
847 	uint16_t	con_handle; /* connection handle */
848 } __packed hci_exit_sniff_mode_cp;
849 /* No return parameter(s) */
850 
851 #define HCI_OCF_PARK_MODE				0x0005
852 #define HCI_CMD_PARK_MODE				0x0805
853 typedef struct {
854 	uint16_t	con_handle;   /* connection handle */
855 	uint16_t	max_interval; /* (max_interval * 0.625) msec */
856 	uint16_t	min_interval; /* (max_interval * 0.625) msec */
857 } __packed hci_park_mode_cp;
858 /* No return parameter(s) */
859 
860 #define HCI_OCF_EXIT_PARK_MODE				0x0006
861 #define HCI_CMD_EXIT_PARK_MODE				0x0806
862 typedef struct {
863 	uint16_t	con_handle; /* connection handle */
864 } __packed hci_exit_park_mode_cp;
865 /* No return parameter(s) */
866 
867 #define HCI_OCF_QOS_SETUP				0x0007
868 #define HCI_CMD_QOS_SETUP				0x0807
869 typedef struct {
870 	uint16_t	con_handle;      /* connection handle */
871 	uint8_t		flags;           /* reserved for future use */
872 	uint8_t		service_type;    /* service type */
873 	uint32_t	token_rate;      /* bytes per second */
874 	uint32_t	peak_bandwidth;  /* bytes per second */
875 	uint32_t	latency;         /* microseconds */
876 	uint32_t	delay_variation; /* microseconds */
877 } __packed hci_qos_setup_cp;
878 /* No return parameter(s) */
879 
880 #define HCI_OCF_ROLE_DISCOVERY				0x0009
881 #define HCI_CMD_ROLE_DISCOVERY				0x0809
882 typedef struct {
883 	uint16_t	con_handle; /* connection handle */
884 } __packed hci_role_discovery_cp;
885 
886 typedef struct {
887 	uint8_t		status;     /* 0x00 - success */
888 	uint16_t	con_handle; /* connection handle */
889 	uint8_t		role;       /* role for the connection handle */
890 } __packed hci_role_discovery_rp;
891 
892 #define HCI_OCF_SWITCH_ROLE				0x000b
893 #define HCI_CMD_SWITCH_ROLE				0x080B
894 typedef struct {
895 	bdaddr_t	bdaddr; /* remote address */
896 	uint8_t		role;   /* new local role */
897 } __packed hci_switch_role_cp;
898 /* No return parameter(s) */
899 
900 #define HCI_OCF_READ_LINK_POLICY_SETTINGS		0x000c
901 #define HCI_CMD_READ_LINK_POLICY_SETTINGS		0x080C
902 typedef struct {
903 	uint16_t	con_handle; /* connection handle */
904 } __packed hci_read_link_policy_settings_cp;
905 
906 typedef struct {
907 	uint8_t		status;     /* 0x00 - success */
908 	uint16_t	con_handle; /* connection handle */
909 	uint16_t	settings;   /* link policy settings */
910 } __packed hci_read_link_policy_settings_rp;
911 
912 #define HCI_OCF_WRITE_LINK_POLICY_SETTINGS		0x000d
913 #define HCI_CMD_WRITE_LINK_POLICY_SETTINGS		0x080D
914 typedef struct {
915 	uint16_t	con_handle; /* connection handle */
916 	uint16_t	settings;   /* link policy settings */
917 } __packed hci_write_link_policy_settings_cp;
918 
919 typedef struct {
920 	uint8_t		status;     /* 0x00 - success */
921 	uint16_t	con_handle; /* connection handle */
922 } __packed hci_write_link_policy_settings_rp;
923 
924 #define HCI_OCF_READ_DEFAULT_LINK_POLICY_SETTINGS	0x000e
925 #define HCI_CMD_READ_DEFAULT_LINK_POLICY_SETTINGS	0x080E
926 /* No command parameter(s) */
927 typedef struct {
928 	uint8_t		status;     /* 0x00 - success */
929 	uint16_t	settings;   /* link policy settings */
930 } __packed hci_read_default_link_policy_settings_rp;
931 
932 #define HCI_OCF_WRITE_DEFAULT_LINK_POLICY_SETTINGS	0x000f
933 #define HCI_CMD_WRITE_DEFAULT_LINK_POLICY_SETTINGS	0x080F
934 typedef struct {
935 	uint16_t	settings;   /* link policy settings */
936 } __packed hci_write_default_link_policy_settings_cp;
937 
938 typedef hci_status_rp	hci_write_default_link_policy_settings_rp;
939 
940 #define HCI_OCF_FLOW_SPECIFICATION			0x0010
941 #define HCI_CMD_FLOW_SPECIFICATION			0x0810
942 typedef struct {
943 	uint16_t	con_handle;	/* connection handle */
944 	uint8_t		flags;		/* reserved */
945 	uint8_t		flow_direction;
946 	uint8_t		service_type;
947 	uint32_t	token_rate;
948 	uint32_t	token_bucket;
949 	uint32_t	peak_bandwidth;
950 	uint32_t	latency;
951 } __packed hci_flow_specification_cp;
952 /* No return parameter(s) */
953 
954 #define HCI_OCF_SNIFF_SUBRATING				0x0011
955 #define HCI_CMD_SNIFF_SUBRATING				0x0810
956 typedef struct {
957 	uint16_t	con_handle;	/* connection handle */
958 	uint16_t	max_latency;
959 	uint16_t	max_timeout;	/* max remote timeout */
960 	uint16_t	min_timeout;	/* min local timeout */
961 } __packed hci_sniff_subrating_cp;
962 
963 typedef struct {
964 	uint8_t		status;		/* 0x00 - success */
965 	uint16_t	con_handle;	/* connection handle */
966 } __packed hci_sniff_subrating_rp;
967 
968 /**************************************************************************
969  **************************************************************************
970  ** OGF 0x03	Host Controller and Baseband commands and return parameters
971  **************************************************************************
972  **************************************************************************/
973 
974 #define HCI_OGF_HC_BASEBAND			0x03
975 
976 #define HCI_OCF_SET_EVENT_MASK				0x0001
977 #define HCI_CMD_SET_EVENT_MASK				0x0C01
978 typedef struct {
979 	uint8_t		event_mask[HCI_EVENT_MASK_SIZE]; /* event_mask */
980 } __packed hci_set_event_mask_cp;
981 
982 typedef hci_status_rp	hci_set_event_mask_rp;
983 
984 #define HCI_OCF_RESET					0x0003
985 #define HCI_CMD_RESET					0x0C03
986 /* No command parameter(s) */
987 typedef hci_status_rp	hci_reset_rp;
988 
989 #define HCI_OCF_SET_EVENT_FILTER			0x0005
990 #define HCI_CMD_SET_EVENT_FILTER			0x0C05
991 typedef struct {
992 	uint8_t		filter_type;           /* filter type */
993 	uint8_t		filter_condition_type; /* filter condition type */
994 /* variable size condition
995 	uint8_t		condition[]; -- conditions */
996 } __packed hci_set_event_filter_cp;
997 
998 typedef hci_status_rp	hci_set_event_filter_rp;
999 
1000 #define HCI_OCF_FLUSH					0x0008
1001 #define HCI_CMD_FLUSH					0x0C08
1002 typedef struct {
1003 	uint16_t	con_handle; /* connection handle */
1004 } __packed hci_flush_cp;
1005 
1006 typedef struct {
1007 	uint8_t		status;     /* 0x00 - success */
1008 	uint16_t	con_handle; /* connection handle */
1009 } __packed hci_flush_rp;
1010 
1011 #define HCI_OCF_READ_PIN_TYPE				0x0009
1012 #define HCI_CMD_READ_PIN_TYPE				0x0C09
1013 /* No command parameter(s) */
1014 typedef struct {
1015 	uint8_t		status;   /* 0x00 - success */
1016 	uint8_t		pin_type; /* PIN type */
1017 } __packed hci_read_pin_type_rp;
1018 
1019 #define HCI_OCF_WRITE_PIN_TYPE				0x000a
1020 #define HCI_CMD_WRITE_PIN_TYPE				0x0C0A
1021 typedef struct {
1022 	uint8_t		pin_type; /* PIN type */
1023 } __packed hci_write_pin_type_cp;
1024 
1025 typedef hci_status_rp	hci_write_pin_type_rp;
1026 
1027 #define HCI_OCF_CREATE_NEW_UNIT_KEY			0x000b
1028 #define HCI_CMD_CREATE_NEW_UNIT_KEY			0x0C0B
1029 /* No command parameter(s) */
1030 typedef hci_status_rp	hci_create_new_unit_key_rp;
1031 
1032 #define HCI_OCF_READ_STORED_LINK_KEY			0x000d
1033 #define HCI_CMD_READ_STORED_LINK_KEY			0x0C0D
1034 typedef struct {
1035 	bdaddr_t	bdaddr;   /* address */
1036 	uint8_t		read_all; /* read all keys? 0x01 - yes */
1037 } __packed hci_read_stored_link_key_cp;
1038 
1039 typedef struct {
1040 	uint8_t		status;        /* 0x00 - success */
1041 	uint16_t	max_num_keys;  /* Max. number of keys */
1042 	uint16_t	num_keys_read; /* Number of stored keys */
1043 } __packed hci_read_stored_link_key_rp;
1044 
1045 #define HCI_OCF_WRITE_STORED_LINK_KEY			0x0011
1046 #define HCI_CMD_WRITE_STORED_LINK_KEY			0x0C11
1047 typedef struct {
1048 	uint8_t		num_keys_write; /* # of keys to write */
1049 /* these are repeated "num_keys_write" times
1050 	bdaddr_t	bdaddr;             --- remote address(es)
1051 	uint8_t		key[HCI_KEY_SIZE];  --- key(s) */
1052 } __packed hci_write_stored_link_key_cp;
1053 
1054 typedef struct {
1055 	uint8_t		status;           /* 0x00 - success */
1056 	uint8_t		num_keys_written; /* # of keys successfully written */
1057 } __packed hci_write_stored_link_key_rp;
1058 
1059 #define HCI_OCF_DELETE_STORED_LINK_KEY			0x0012
1060 #define HCI_CMD_DELETE_STORED_LINK_KEY			0x0C12
1061 typedef struct {
1062 	bdaddr_t	bdaddr;     /* address */
1063 	uint8_t		delete_all; /* delete all keys? 0x01 - yes */
1064 } __packed hci_delete_stored_link_key_cp;
1065 
1066 typedef struct {
1067 	uint8_t		status;           /* 0x00 - success */
1068 	uint16_t	num_keys_deleted; /* Number of keys deleted */
1069 } __packed hci_delete_stored_link_key_rp;
1070 
1071 #define HCI_OCF_WRITE_LOCAL_NAME			0x0013
1072 #define HCI_CMD_WRITE_LOCAL_NAME			0x0C13
1073 typedef struct {
1074 	char		name[HCI_UNIT_NAME_SIZE]; /* new unit name */
1075 } __packed hci_write_local_name_cp;
1076 
1077 typedef hci_status_rp	hci_write_local_name_rp;
1078 
1079 #define HCI_OCF_READ_LOCAL_NAME				0x0014
1080 #define HCI_CMD_READ_LOCAL_NAME				0x0C14
1081 /* No command parameter(s) */
1082 typedef struct {
1083 	uint8_t		status;                   /* 0x00 - success */
1084 	char		name[HCI_UNIT_NAME_SIZE]; /* unit name */
1085 } __packed hci_read_local_name_rp;
1086 
1087 #define HCI_OCF_READ_CON_ACCEPT_TIMEOUT			0x0015
1088 #define HCI_CMD_READ_CON_ACCEPT_TIMEOUT			0x0C15
1089 /* No command parameter(s) */
1090 typedef struct {
1091 	uint8_t		status;  /* 0x00 - success */
1092 	uint16_t	timeout; /* (timeout * 0.625) msec */
1093 } __packed hci_read_con_accept_timeout_rp;
1094 
1095 #define HCI_OCF_WRITE_CON_ACCEPT_TIMEOUT		0x0016
1096 #define HCI_CMD_WRITE_CON_ACCEPT_TIMEOUT		0x0C16
1097 typedef struct {
1098 	uint16_t	timeout; /* (timeout * 0.625) msec */
1099 } __packed hci_write_con_accept_timeout_cp;
1100 
1101 typedef hci_status_rp	hci_write_con_accept_timeout_rp;
1102 
1103 #define HCI_OCF_READ_PAGE_TIMEOUT			0x0017
1104 #define HCI_CMD_READ_PAGE_TIMEOUT			0x0C17
1105 /* No command parameter(s) */
1106 typedef struct {
1107 	uint8_t		status;  /* 0x00 - success */
1108 	uint16_t	timeout; /* (timeout * 0.625) msec */
1109 } __packed hci_read_page_timeout_rp;
1110 
1111 #define HCI_OCF_WRITE_PAGE_TIMEOUT			0x0018
1112 #define HCI_CMD_WRITE_PAGE_TIMEOUT			0x0C18
1113 typedef struct {
1114 	uint16_t	timeout; /* (timeout * 0.625) msec */
1115 } __packed hci_write_page_timeout_cp;
1116 
1117 typedef hci_status_rp	hci_write_page_timeout_rp;
1118 
1119 #define HCI_OCF_READ_SCAN_ENABLE			0x0019
1120 #define HCI_CMD_READ_SCAN_ENABLE			0x0C19
1121 /* No command parameter(s) */
1122 typedef struct {
1123 	uint8_t		status;      /* 0x00 - success */
1124 	uint8_t		scan_enable; /* Scan enable */
1125 } __packed hci_read_scan_enable_rp;
1126 
1127 #define HCI_OCF_WRITE_SCAN_ENABLE			0x001a
1128 #define HCI_CMD_WRITE_SCAN_ENABLE			0x0C1A
1129 typedef struct {
1130 	uint8_t		scan_enable; /* Scan enable */
1131 } __packed hci_write_scan_enable_cp;
1132 
1133 typedef hci_status_rp	hci_write_scan_enable_rp;
1134 
1135 #define HCI_OCF_READ_PAGE_SCAN_ACTIVITY			0x001b
1136 #define HCI_CMD_READ_PAGE_SCAN_ACTIVITY			0x0C1B
1137 /* No command parameter(s) */
1138 typedef struct {
1139 	uint8_t		status;             /* 0x00 - success */
1140 	uint16_t	page_scan_interval; /* interval * 0.625 msec */
1141 	uint16_t	page_scan_window;   /* window * 0.625 msec */
1142 } __packed hci_read_page_scan_activity_rp;
1143 
1144 #define HCI_OCF_WRITE_PAGE_SCAN_ACTIVITY		0x001c
1145 #define HCI_CMD_WRITE_PAGE_SCAN_ACTIVITY		0x0C1C
1146 typedef struct {
1147 	uint16_t	page_scan_interval; /* interval * 0.625 msec */
1148 	uint16_t	page_scan_window;   /* window * 0.625 msec */
1149 } __packed hci_write_page_scan_activity_cp;
1150 
1151 typedef hci_status_rp	hci_write_page_scan_activity_rp;
1152 
1153 #define HCI_OCF_READ_INQUIRY_SCAN_ACTIVITY		0x001d
1154 #define HCI_CMD_READ_INQUIRY_SCAN_ACTIVITY		0x0C1D
1155 /* No command parameter(s) */
1156 typedef struct {
1157 	uint8_t		status;                /* 0x00 - success */
1158 	uint16_t	inquiry_scan_interval; /* interval * 0.625 msec */
1159 	uint16_t	inquiry_scan_window;   /* window * 0.625 msec */
1160 } __packed hci_read_inquiry_scan_activity_rp;
1161 
1162 #define HCI_OCF_WRITE_INQUIRY_SCAN_ACTIVITY		0x001e
1163 #define HCI_CMD_WRITE_INQUIRY_SCAN_ACTIVITY		0x0C1E
1164 typedef struct {
1165 	uint16_t	inquiry_scan_interval; /* interval * 0.625 msec */
1166 	uint16_t	inquiry_scan_window;   /* window * 0.625 msec */
1167 } __packed hci_write_inquiry_scan_activity_cp;
1168 
1169 typedef hci_status_rp	hci_write_inquiry_scan_activity_rp;
1170 
1171 #define HCI_OCF_READ_AUTH_ENABLE			0x001f
1172 #define HCI_CMD_READ_AUTH_ENABLE			0x0C1F
1173 /* No command parameter(s) */
1174 typedef struct {
1175 	uint8_t		status;      /* 0x00 - success */
1176 	uint8_t		auth_enable; /* 0x01 - enabled */
1177 } __packed hci_read_auth_enable_rp;
1178 
1179 #define HCI_OCF_WRITE_AUTH_ENABLE			0x0020
1180 #define HCI_CMD_WRITE_AUTH_ENABLE			0x0C20
1181 typedef struct {
1182 	uint8_t		auth_enable; /* 0x01 - enabled */
1183 } __packed hci_write_auth_enable_cp;
1184 
1185 typedef hci_status_rp	hci_write_auth_enable_rp;
1186 
1187 /* Read Encryption Mode is deprecated */
1188 #define HCI_OCF_READ_ENCRYPTION_MODE			0x0021
1189 #define HCI_CMD_READ_ENCRYPTION_MODE			0x0C21
1190 /* No command parameter(s) */
1191 typedef struct {
1192 	uint8_t		status;          /* 0x00 - success */
1193 	uint8_t		encryption_mode; /* encryption mode */
1194 } __packed hci_read_encryption_mode_rp;
1195 
1196 /* Write Encryption Mode is deprecated */
1197 #define HCI_OCF_WRITE_ENCRYPTION_MODE			0x0022
1198 #define HCI_CMD_WRITE_ENCRYPTION_MODE			0x0C22
1199 typedef struct {
1200 	uint8_t		encryption_mode; /* encryption mode */
1201 } __packed hci_write_encryption_mode_cp;
1202 
1203 typedef hci_status_rp	hci_write_encryption_mode_rp;
1204 
1205 #define HCI_OCF_READ_UNIT_CLASS				0x0023
1206 #define HCI_CMD_READ_UNIT_CLASS				0x0C23
1207 /* No command parameter(s) */
1208 typedef struct {
1209 	uint8_t		status;                 /* 0x00 - success */
1210 	uint8_t		uclass[HCI_CLASS_SIZE]; /* unit class */
1211 } __packed hci_read_unit_class_rp;
1212 
1213 #define HCI_OCF_WRITE_UNIT_CLASS			0x0024
1214 #define HCI_CMD_WRITE_UNIT_CLASS			0x0C24
1215 typedef struct {
1216 	uint8_t		uclass[HCI_CLASS_SIZE]; /* unit class */
1217 } __packed hci_write_unit_class_cp;
1218 
1219 typedef hci_status_rp	hci_write_unit_class_rp;
1220 
1221 #define HCI_OCF_READ_VOICE_SETTING			0x0025
1222 #define HCI_CMD_READ_VOICE_SETTING			0x0C25
1223 /* No command parameter(s) */
1224 typedef struct {
1225 	uint8_t		status;   /* 0x00 - success */
1226 	uint16_t	settings; /* voice settings */
1227 } __packed hci_read_voice_setting_rp;
1228 
1229 #define HCI_OCF_WRITE_VOICE_SETTING			0x0026
1230 #define HCI_CMD_WRITE_VOICE_SETTING			0x0C26
1231 typedef struct {
1232 	uint16_t	settings; /* voice settings */
1233 } __packed hci_write_voice_setting_cp;
1234 
1235 typedef hci_status_rp	hci_write_voice_setting_rp;
1236 
1237 #define HCI_OCF_READ_AUTO_FLUSH_TIMEOUT			0x0027
1238 #define HCI_CMD_READ_AUTO_FLUSH_TIMEOUT			0x0C27
1239 typedef struct {
1240 	uint16_t	con_handle; /* connection handle */
1241 } __packed hci_read_auto_flush_timeout_cp;
1242 
1243 typedef struct {
1244 	uint8_t		status;     /* 0x00 - success */
1245 	uint16_t	con_handle; /* connection handle */
1246 	uint16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
1247 } __packed hci_read_auto_flush_timeout_rp;
1248 
1249 #define HCI_OCF_WRITE_AUTO_FLUSH_TIMEOUT		0x0028
1250 #define HCI_CMD_WRITE_AUTO_FLUSH_TIMEOUT		0x0C28
1251 typedef struct {
1252 	uint16_t	con_handle; /* connection handle */
1253 	uint16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
1254 } __packed hci_write_auto_flush_timeout_cp;
1255 
1256 typedef struct {
1257 	uint8_t		status;     /* 0x00 - success */
1258 	uint16_t	con_handle; /* connection handle */
1259 } __packed hci_write_auto_flush_timeout_rp;
1260 
1261 #define HCI_OCF_READ_NUM_BROADCAST_RETRANS		0x0029
1262 #define HCI_CMD_READ_NUM_BROADCAST_RETRANS		0x0C29
1263 /* No command parameter(s) */
1264 typedef struct {
1265 	uint8_t		status;  /* 0x00 - success */
1266 	uint8_t		counter; /* number of broadcast retransmissions */
1267 } __packed hci_read_num_broadcast_retrans_rp;
1268 
1269 #define HCI_OCF_WRITE_NUM_BROADCAST_RETRANS		0x002a
1270 #define HCI_CMD_WRITE_NUM_BROADCAST_RETRANS		0x0C2A
1271 typedef struct {
1272 	uint8_t		counter; /* number of broadcast retransmissions */
1273 } __packed hci_write_num_broadcast_retrans_cp;
1274 
1275 typedef hci_status_rp	hci_write_num_broadcast_retrans_rp;
1276 
1277 #define HCI_OCF_READ_HOLD_MODE_ACTIVITY			0x002b
1278 #define HCI_CMD_READ_HOLD_MODE_ACTIVITY			0x0C2B
1279 /* No command parameter(s) */
1280 typedef struct {
1281 	uint8_t		status;             /* 0x00 - success */
1282 	uint8_t		hold_mode_activity; /* Hold mode activities */
1283 } __packed hci_read_hold_mode_activity_rp;
1284 
1285 #define HCI_OCF_WRITE_HOLD_MODE_ACTIVITY		0x002c
1286 #define HCI_CMD_WRITE_HOLD_MODE_ACTIVITY		0x0C2C
1287 typedef struct {
1288 	uint8_t		hold_mode_activity; /* Hold mode activities */
1289 } __packed hci_write_hold_mode_activity_cp;
1290 
1291 typedef hci_status_rp	hci_write_hold_mode_activity_rp;
1292 
1293 #define HCI_OCF_READ_XMIT_LEVEL				0x002d
1294 #define HCI_CMD_READ_XMIT_LEVEL				0x0C2D
1295 typedef struct {
1296 	uint16_t	con_handle; /* connection handle */
1297 	uint8_t		type;       /* Xmit level type */
1298 } __packed hci_read_xmit_level_cp;
1299 
1300 typedef struct {
1301 	uint8_t		status;     /* 0x00 - success */
1302 	uint16_t	con_handle; /* connection handle */
1303 	char		level;      /* -30 <= level <= 30 dBm */
1304 } __packed hci_read_xmit_level_rp;
1305 
1306 #define HCI_OCF_READ_SCO_FLOW_CONTROL			0x002e
1307 #define HCI_CMD_READ_SCO_FLOW_CONTROL			0x0C2E
1308 /* No command parameter(s) */
1309 typedef struct {
1310 	uint8_t		status;       /* 0x00 - success */
1311 	uint8_t		flow_control; /* 0x00 - disabled */
1312 } __packed hci_read_sco_flow_control_rp;
1313 
1314 #define HCI_OCF_WRITE_SCO_FLOW_CONTROL			0x002f
1315 #define HCI_CMD_WRITE_SCO_FLOW_CONTROL			0x0C2F
1316 typedef struct {
1317 	uint8_t		flow_control; /* 0x00 - disabled */
1318 } __packed hci_write_sco_flow_control_cp;
1319 
1320 typedef hci_status_rp	hci_write_sco_flow_control_rp;
1321 
1322 #define HCI_OCF_HC2H_FLOW_CONTROL			0x0031
1323 #define HCI_CMD_HC2H_FLOW_CONTROL			0x0C31
1324 typedef struct {
1325 	uint8_t		hc2h_flow; /* Host Controller to Host flow control */
1326 } __packed hci_hc2h_flow_control_cp;
1327 
1328 typedef hci_status_rp	hci_h2hc_flow_control_rp;
1329 
1330 #define HCI_OCF_HOST_BUFFER_SIZE			0x0033
1331 #define HCI_CMD_HOST_BUFFER_SIZE			0x0C33
1332 typedef struct {
1333 	uint16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
1334 	uint8_t		max_sco_size; /* Max. size of SCO packet (bytes) */
1335 	uint16_t	num_acl_pkts;  /* Max. number of ACL packets */
1336 	uint16_t	num_sco_pkts;  /* Max. number of SCO packets */
1337 } __packed hci_host_buffer_size_cp;
1338 
1339 typedef hci_status_rp	hci_host_buffer_size_rp;
1340 
1341 #define HCI_OCF_HOST_NUM_COMPL_PKTS			0x0035
1342 #define HCI_CMD_HOST_NUM_COMPL_PKTS			0x0C35
1343 typedef struct {
1344 	uint8_t		nu_con_handles; /* # of connection handles */
1345 /* these are repeated "num_con_handles" times
1346 	uint16_t	con_handle;    --- connection handle(s)
1347 	uint16_t	compl_pkts;    --- # of completed packets */
1348 } __packed hci_host_num_compl_pkts_cp;
1349 /* No return parameter(s) */
1350 
1351 #define HCI_OCF_READ_LINK_SUPERVISION_TIMEOUT		0x0036
1352 #define HCI_CMD_READ_LINK_SUPERVISION_TIMEOUT		0x0C36
1353 typedef struct {
1354 	uint16_t	con_handle; /* connection handle */
1355 } __packed hci_read_link_supervision_timeout_cp;
1356 
1357 typedef struct {
1358 	uint8_t		status;     /* 0x00 - success */
1359 	uint16_t	con_handle; /* connection handle */
1360 	uint16_t	timeout;    /* Link supervision timeout * 0.625 msec */
1361 } __packed hci_read_link_supervision_timeout_rp;
1362 
1363 #define HCI_OCF_WRITE_LINK_SUPERVISION_TIMEOUT		0x0037
1364 #define HCI_CMD_WRITE_LINK_SUPERVISION_TIMEOUT		0x0C37
1365 typedef struct {
1366 	uint16_t	con_handle; /* connection handle */
1367 	uint16_t	timeout;    /* Link supervision timeout * 0.625 msec */
1368 } __packed hci_write_link_supervision_timeout_cp;
1369 
1370 typedef struct {
1371 	uint8_t		status;     /* 0x00 - success */
1372 	uint16_t	con_handle; /* connection handle */
1373 } __packed hci_write_link_supervision_timeout_rp;
1374 
1375 #define HCI_OCF_READ_NUM_SUPPORTED_IAC			0x0038
1376 #define HCI_CMD_READ_NUM_SUPPORTED_IAC			0x0C38
1377 /* No command parameter(s) */
1378 typedef struct {
1379 	uint8_t		status;  /* 0x00 - success */
1380 	uint8_t		num_iac; /* # of supported IAC during scan */
1381 } __packed hci_read_num_supported_iac_rp;
1382 
1383 #define HCI_OCF_READ_IAC_LAP				0x0039
1384 #define HCI_CMD_READ_IAC_LAP				0x0C39
1385 /* No command parameter(s) */
1386 typedef struct {
1387 	uint8_t		status;  /* 0x00 - success */
1388 	uint8_t		num_iac; /* # of IAC */
1389 /* these are repeated "num_iac" times
1390 	uint8_t		laps[HCI_LAP_SIZE]; --- LAPs */
1391 } __packed hci_read_iac_lap_rp;
1392 
1393 #define HCI_OCF_WRITE_IAC_LAP				0x003a
1394 #define HCI_CMD_WRITE_IAC_LAP				0x0C3A
1395 typedef struct {
1396 	uint8_t		num_iac; /* # of IAC */
1397 /* these are repeated "num_iac" times
1398 	uint8_t		laps[HCI_LAP_SIZE]; --- LAPs */
1399 } __packed hci_write_iac_lap_cp;
1400 
1401 typedef hci_status_rp	hci_write_iac_lap_rp;
1402 
1403 /* Read Page Scan Period Mode is deprecated */
1404 #define HCI_OCF_READ_PAGE_SCAN_PERIOD			0x003b
1405 #define HCI_CMD_READ_PAGE_SCAN_PERIOD			0x0C3B
1406 /* No command parameter(s) */
1407 typedef struct {
1408 	uint8_t		status;                /* 0x00 - success */
1409 	uint8_t		page_scan_period_mode; /* Page scan period mode */
1410 } __packed hci_read_page_scan_period_rp;
1411 
1412 /* Write Page Scan Period Mode is deprecated */
1413 #define HCI_OCF_WRITE_PAGE_SCAN_PERIOD			0x003c
1414 #define HCI_CMD_WRITE_PAGE_SCAN_PERIOD			0x0C3C
1415 typedef struct {
1416 	uint8_t		page_scan_period_mode; /* Page scan period mode */
1417 } __packed hci_write_page_scan_period_cp;
1418 
1419 typedef hci_status_rp	hci_write_page_scan_period_rp;
1420 
1421 /* Read Page Scan Mode is deprecated */
1422 #define HCI_OCF_READ_PAGE_SCAN				0x003d
1423 #define HCI_CMD_READ_PAGE_SCAN				0x0C3D
1424 /* No command parameter(s) */
1425 typedef struct {
1426 	uint8_t		status;         /* 0x00 - success */
1427 	uint8_t		page_scan_mode; /* Page scan mode */
1428 } __packed hci_read_page_scan_rp;
1429 
1430 /* Write Page Scan Mode is deprecated */
1431 #define HCI_OCF_WRITE_PAGE_SCAN				0x003e
1432 #define HCI_CMD_WRITE_PAGE_SCAN				0x0C3E
1433 typedef struct {
1434 	uint8_t		page_scan_mode; /* Page scan mode */
1435 } __packed hci_write_page_scan_cp;
1436 
1437 typedef hci_status_rp	hci_write_page_scan_rp;
1438 
1439 #define HCI_OCF_SET_AFH_CLASSIFICATION			0x003f
1440 #define HCI_CMD_SET_AFH_CLASSIFICATION			0x0C3F
1441 typedef struct {
1442 	uint8_t		classification[10];
1443 } __packed hci_set_afh_classification_cp;
1444 
1445 typedef hci_status_rp	hci_set_afh_classification_rp;
1446 
1447 #define HCI_OCF_READ_INQUIRY_SCAN_TYPE			0x0042
1448 #define HCI_CMD_READ_INQUIRY_SCAN_TYPE			0x0C42
1449 /* No command parameter(s) */
1450 
1451 typedef struct {
1452 	uint8_t		status;		/* 0x00 - success */
1453 	uint8_t		type;		/* inquiry scan type */
1454 } __packed hci_read_inquiry_scan_type_rp;
1455 
1456 #define HCI_OCF_WRITE_INQUIRY_SCAN_TYPE			0x0043
1457 #define HCI_CMD_WRITE_INQUIRY_SCAN_TYPE			0x0C43
1458 typedef struct {
1459 	uint8_t		type;		/* inquiry scan type */
1460 } __packed hci_write_inquiry_scan_type_cp;
1461 
1462 typedef hci_status_rp	hci_write_inquiry_scan_type_rp;
1463 
1464 #define HCI_OCF_READ_INQUIRY_MODE			0x0044
1465 #define HCI_CMD_READ_INQUIRY_MODE			0x0C44
1466 /* No command parameter(s) */
1467 
1468 typedef struct {
1469 	uint8_t		status;		/* 0x00 - success */
1470 	uint8_t		mode;		/* inquiry mode */
1471 } __packed hci_read_inquiry_mode_rp;
1472 
1473 #define HCI_OCF_WRITE_INQUIRY_MODE			0x0045
1474 #define HCI_CMD_WRITE_INQUIRY_MODE			0x0C45
1475 typedef struct {
1476 	uint8_t		mode;		/* inquiry mode */
1477 } __packed hci_write_inquiry_mode_cp;
1478 
1479 typedef hci_status_rp	hci_write_inquiry_mode_rp;
1480 
1481 #define HCI_OCF_READ_PAGE_SCAN_TYPE			0x0046
1482 #define HCI_CMD_READ_PAGE_SCAN_TYPE			0x0C46
1483 /* No command parameter(s) */
1484 
1485 typedef struct {
1486 	uint8_t		status;		/* 0x00 - success */
1487 	uint8_t		type;		/* page scan type */
1488 } __packed hci_read_page_scan_type_rp;
1489 
1490 #define HCI_OCF_WRITE_PAGE_SCAN_TYPE			0x0047
1491 #define HCI_CMD_WRITE_PAGE_SCAN_TYPE			0x0C47
1492 typedef struct {
1493 	uint8_t		type;		/* page scan type */
1494 } __packed hci_write_page_scan_type_cp;
1495 
1496 typedef hci_status_rp	hci_write_page_scan_type_rp;
1497 
1498 #define HCI_OCF_READ_AFH_ASSESSMENT			0x0048
1499 #define HCI_CMD_READ_AFH_ASSESSMENT			0x0C48
1500 /* No command parameter(s) */
1501 
1502 typedef struct {
1503 	uint8_t		status;		/* 0x00 - success */
1504 	uint8_t		mode;		/* assessment mode */
1505 } __packed hci_read_afh_assessment_rp;
1506 
1507 #define HCI_OCF_WRITE_AFH_ASSESSMENT			0x0049
1508 #define HCI_CMD_WRITE_AFH_ASSESSMENT			0x0C49
1509 typedef struct {
1510 	uint8_t		mode;		/* assessment mode */
1511 } __packed hci_write_afh_assessment_cp;
1512 
1513 typedef hci_status_rp	hci_write_afh_assessment_rp;
1514 
1515 #define HCI_OCF_READ_EXTENDED_INQUIRY_RSP		0x0051
1516 #define HCI_CMD_READ_EXTENDED_INQUIRY_RSP		0x0C51
1517 /* No command parameter(s) */
1518 
1519 typedef struct {
1520 	uint8_t		status;		/* 0x00 - success */
1521 	uint8_t		fec_required;
1522 	uint8_t		response[240];
1523 } __packed hci_read_extended_inquiry_rsp_rp;
1524 
1525 #define HCI_OCF_WRITE_EXTENDED_INQUIRY_RSP		0x0052
1526 #define HCI_CMD_WRITE_EXTENDED_INQUIRY_RSP		0x0C52
1527 typedef struct {
1528 	uint8_t		fec_required;
1529 	uint8_t		response[240];
1530 } __packed hci_write_extended_inquiry_rsp_cp;
1531 
1532 typedef hci_status_rp	hci_write_extended_inquiry_rsp_rp;
1533 
1534 #define HCI_OCF_REFRESH_ENCRYPTION_KEY			0x0053
1535 #define HCI_CMD_REFRESH_ENCRYPTION_KEY			0x0C53
1536 typedef struct {
1537 	uint16_t	con_handle;	/* connection handle */
1538 } __packed hci_refresh_encryption_key_cp;
1539 
1540 typedef hci_status_rp	hci_refresh_encryption_key_rp;
1541 
1542 #define HCI_OCF_READ_SIMPLE_PAIRING_MODE		0x0055
1543 #define HCI_CMD_READ_SIMPLE_PAIRING_MODE		0x0C55
1544 /* No command parameter(s) */
1545 
1546 typedef struct {
1547 	uint8_t		status;		/* 0x00 - success */
1548 	uint8_t		mode;		/* simple pairing mode */
1549 } __packed hci_read_simple_pairing_mode_rp;
1550 
1551 #define HCI_OCF_WRITE_SIMPLE_PAIRING_MODE		0x0056
1552 #define HCI_CMD_WRITE_SIMPLE_PAIRING_MODE		0x0C56
1553 typedef struct {
1554 	uint8_t		mode;		/* simple pairing mode */
1555 } __packed hci_write_simple_pairing_mode_cp;
1556 
1557 typedef hci_status_rp	hci_write_simple_pairing_mode_rp;
1558 
1559 #define HCI_OCF_READ_LOCAL_OOB_DATA			0x0057
1560 #define HCI_CMD_READ_LOCAL_OOB_DATA			0x0C57
1561 /* No command parameter(s) */
1562 
1563 typedef struct {
1564 	uint8_t		status;		/* 0x00 - success */
1565 	uint8_t		c[16];		/* pairing hash */
1566 	uint8_t		r[16];		/* pairing randomizer */
1567 } __packed hci_read_local_oob_data_rp;
1568 
1569 #define HCI_OCF_READ_INQUIRY_RSP_XMIT_POWER		0x0058
1570 #define HCI_CMD_READ_INQUIRY_RSP_XMIT_POWER		0x0C58
1571 /* No command parameter(s) */
1572 
1573 typedef struct {
1574 	uint8_t		status;		/* 0x00 - success */
1575 	int8_t		power;		/* TX power */
1576 } __packed hci_read_inquiry_rsp_xmit_power_rp;
1577 
1578 #define HCI_OCF_WRITE_INQUIRY_RSP_XMIT_POWER		0x0059
1579 #define HCI_CMD_WRITE_INQUIRY_RSP_XMIT_POWER		0x0C59
1580 typedef struct {
1581 	int8_t		power;		/* TX power */
1582 } __packed hci_write_inquiry_rsp_xmit_power_cp;
1583 
1584 typedef hci_status_rp	hci_write_inquiry_rsp_xmit_power_rp;
1585 
1586 #define HCI_OCF_READ_DEFAULT_ERRDATA_REPORTING		0x005A
1587 #define HCI_CMD_READ_DEFAULT_ERRDATA_REPORTING		0x0C5A
1588 /* No command parameter(s) */
1589 
1590 typedef struct {
1591 	uint8_t		status;		/* 0x00 - success */
1592 	uint8_t		reporting;	/* erroneous data reporting */
1593 } __packed hci_read_default_errdata_reporting_rp;
1594 
1595 #define HCI_OCF_WRITE_DEFAULT_ERRDATA_REPORTING		0x005B
1596 #define HCI_CMD_WRITE_DEFAULT_ERRDATA_REPORTING		0x0C5B
1597 typedef struct {
1598 	uint8_t		reporting;	/* erroneous data reporting */
1599 } __packed hci_write_default_errdata_reporting_cp;
1600 
1601 typedef hci_status_rp	hci_write_default_errdata_reporting_rp;
1602 
1603 #define HCI_OCF_ENHANCED_FLUSH				0x005F
1604 #define HCI_CMD_ENHANCED_FLUSH				0x0C5F
1605 typedef struct {
1606 	uint16_t	con_handle;	/* connection handle */
1607 	uint8_t		packet_type;
1608 } __packed hci_enhanced_flush_cp;
1609 
1610 /* No response parameter(s) */
1611 
1612 #define HCI_OCF_SEND_KEYPRESS_NOTIFICATION		0x0060
1613 #define HCI_CMD_SEND_KEYPRESS_NOTIFICATION		0x0C60
1614 typedef struct {
1615 	bdaddr_t	bdaddr;		/* remote address */
1616 	uint8_t		type;		/* notification type */
1617 } __packed hci_send_keypress_notification_cp;
1618 
1619 typedef struct {
1620 	uint8_t		status;		/* 0x00 - success */
1621 	bdaddr_t	bdaddr;		/* remote address */
1622 } __packed hci_send_keypress_notification_rp;
1623 
1624 /**************************************************************************
1625  **************************************************************************
1626  ** OGF 0x04	Informational commands and return parameters
1627  **************************************************************************
1628  **************************************************************************/
1629 
1630 #define HCI_OGF_INFO				0x04
1631 
1632 #define HCI_OCF_READ_LOCAL_VER				0x0001
1633 #define HCI_CMD_READ_LOCAL_VER				0x1001
1634 /* No command parameter(s) */
1635 typedef struct {
1636 	uint8_t		status;         /* 0x00 - success */
1637 	uint8_t		hci_version;    /* HCI version */
1638 	uint16_t	hci_revision;   /* HCI revision */
1639 	uint8_t		lmp_version;    /* LMP version */
1640 	uint16_t	manufacturer;   /* Hardware manufacturer name */
1641 	uint16_t	lmp_subversion; /* LMP sub-version */
1642 } __packed hci_read_local_ver_rp;
1643 
1644 #define HCI_OCF_READ_LOCAL_COMMANDS			0x0002
1645 #define HCI_CMD_READ_LOCAL_COMMANDS			0x1002
1646 /* No command parameter(s) */
1647 typedef struct {
1648 	uint8_t		status;		/* 0x00 - success */
1649 	uint8_t		commands[HCI_COMMANDS_SIZE];	/* opcode bitmask */
1650 } __packed hci_read_local_commands_rp;
1651 
1652 #define HCI_OCF_READ_LOCAL_FEATURES			0x0003
1653 #define HCI_CMD_READ_LOCAL_FEATURES			0x1003
1654 /* No command parameter(s) */
1655 typedef struct {
1656 	uint8_t		status;                      /* 0x00 - success */
1657 	uint8_t		features[HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
1658 } __packed hci_read_local_features_rp;
1659 
1660 #define HCI_OCF_READ_LOCAL_EXTENDED_FEATURES		0x0004
1661 #define HCI_CMD_READ_LOCAL_EXTENDED_FEATURES		0x1004
1662 typedef struct {
1663 	uint8_t		page;		/* page number */
1664 } __packed hci_read_local_extended_features_cp;
1665 
1666 typedef struct {
1667 	uint8_t		status;		/* 0x00 - success */
1668 	uint8_t		page;		/* page number */
1669 	uint8_t		max_page;	/* maximum page number */
1670 	uint8_t		features[HCI_FEATURES_SIZE];	/* LMP features */
1671 } __packed hci_read_local_extended_features_rp;
1672 
1673 #define HCI_OCF_READ_BUFFER_SIZE			0x0005
1674 #define HCI_CMD_READ_BUFFER_SIZE			0x1005
1675 /* No command parameter(s) */
1676 typedef struct {
1677 	uint8_t		status;       /* 0x00 - success */
1678 	uint16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
1679 	uint8_t		max_sco_size; /* Max. size of SCO packet (bytes) */
1680 	uint16_t	num_acl_pkts;  /* Max. number of ACL packets */
1681 	uint16_t	num_sco_pkts;  /* Max. number of SCO packets */
1682 } __packed hci_read_buffer_size_rp;
1683 
1684 /* Read Country Code is deprecated */
1685 #define HCI_OCF_READ_COUNTRY_CODE			0x0007
1686 #define HCI_CMD_READ_COUNTRY_CODE			0x1007
1687 /* No command parameter(s) */
1688 typedef struct {
1689 	uint8_t		status;       /* 0x00 - success */
1690 	uint8_t		country_code; /* 0x00 - NAM, EUR, JP; 0x01 - France */
1691 } __packed hci_read_country_code_rp;
1692 
1693 #define HCI_OCF_READ_BDADDR				0x0009
1694 #define HCI_CMD_READ_BDADDR				0x1009
1695 /* No command parameter(s) */
1696 typedef struct {
1697 	uint8_t		status; /* 0x00 - success */
1698 	bdaddr_t	bdaddr; /* unit address */
1699 } __packed hci_read_bdaddr_rp;
1700 
1701 /**************************************************************************
1702  **************************************************************************
1703  ** OGF 0x05	Status commands and return parameters
1704  **************************************************************************
1705  **************************************************************************/
1706 
1707 #define HCI_OGF_STATUS				0x05
1708 
1709 #define HCI_OCF_READ_FAILED_CONTACT_CNTR		0x0001
1710 #define HCI_CMD_READ_FAILED_CONTACT_CNTR		0x1401
1711 typedef struct {
1712 	uint16_t	con_handle; /* connection handle */
1713 } __packed hci_read_failed_contact_cntr_cp;
1714 
1715 typedef struct {
1716 	uint8_t		status;     /* 0x00 - success */
1717 	uint16_t	con_handle; /* connection handle */
1718 	uint16_t	counter;    /* number of consecutive failed contacts */
1719 } __packed hci_read_failed_contact_cntr_rp;
1720 
1721 #define HCI_OCF_RESET_FAILED_CONTACT_CNTR		0x0002
1722 #define HCI_CMD_RESET_FAILED_CONTACT_CNTR		0x1402
1723 typedef struct {
1724 	uint16_t	con_handle; /* connection handle */
1725 } __packed hci_reset_failed_contact_cntr_cp;
1726 
1727 typedef struct {
1728 	uint8_t		status;     /* 0x00 - success */
1729 	uint16_t	con_handle; /* connection handle */
1730 } __packed hci_reset_failed_contact_cntr_rp;
1731 
1732 #define HCI_OCF_READ_LINK_QUALITY			0x0003
1733 #define HCI_CMD_READ_LINK_QUALITY			0x1403
1734 typedef struct {
1735 	uint16_t	con_handle; /* connection handle */
1736 } __packed hci_read_link_quality_cp;
1737 
1738 typedef struct {
1739 	uint8_t		status;     /* 0x00 - success */
1740 	uint16_t	con_handle; /* connection handle */
1741 	uint8_t		quality;    /* higher value means better quality */
1742 } __packed hci_read_link_quality_rp;
1743 
1744 #define HCI_OCF_READ_RSSI				0x0005
1745 #define HCI_CMD_READ_RSSI				0x1405
1746 typedef struct {
1747 	uint16_t	con_handle; /* connection handle */
1748 } __packed hci_read_rssi_cp;
1749 
1750 typedef struct {
1751 	uint8_t		status;     /* 0x00 - success */
1752 	uint16_t	con_handle; /* connection handle */
1753 	char		rssi;       /* -127 <= rssi <= 127 dB */
1754 } __packed hci_read_rssi_rp;
1755 
1756 #define HCI_OCF_READ_AFH_CHANNEL_MAP			0x0006
1757 #define HCI_CMD_READ_AFH_CHANNEL_MAP			0x1406
1758 typedef struct {
1759 	uint16_t	con_handle; /* connection handle */
1760 } __packed hci_read_afh_channel_map_cp;
1761 
1762 typedef struct {
1763 	uint8_t		status;     /* 0x00 - success */
1764 	uint16_t	con_handle; /* connection handle */
1765 	uint8_t		mode;       /* AFH mode */
1766 	uint8_t		map[10];    /* AFH Channel Map */
1767 } __packed hci_read_afh_channel_map_rp;
1768 
1769 #define HCI_OCF_READ_CLOCK				0x0007
1770 #define HCI_CMD_READ_CLOCK				0x1407
1771 typedef struct {
1772 	uint16_t	con_handle;	/* connection handle */
1773 	uint8_t		clock;		/* which clock */
1774 } __packed hci_read_clock_cp;
1775 
1776 typedef struct {
1777 	uint8_t		status;		/* 0x00 - success */
1778 	uint16_t	con_handle;	/* connection handle */
1779 	uint32_t	clock;		/* clock value */
1780 	uint16_t	accuracy;	/* clock accuracy */
1781 } __packed hci_read_clock_rp;
1782 
1783 
1784 /**************************************************************************
1785  **************************************************************************
1786  ** OGF 0x06	Testing commands and return parameters
1787  **************************************************************************
1788  **************************************************************************/
1789 
1790 #define HCI_OGF_TESTING				0x06
1791 
1792 #define HCI_OCF_READ_LOOPBACK_MODE			0x0001
1793 #define HCI_CMD_READ_LOOPBACK_MODE			0x1801
1794 /* No command parameter(s) */
1795 typedef struct {
1796 	uint8_t		status; /* 0x00 - success */
1797 	uint8_t		lbmode; /* loopback mode */
1798 } __packed hci_read_loopback_mode_rp;
1799 
1800 #define HCI_OCF_WRITE_LOOPBACK_MODE			0x0002
1801 #define HCI_CMD_WRITE_LOOPBACK_MODE			0x1802
1802 typedef struct {
1803 	uint8_t		lbmode; /* loopback mode */
1804 } __packed hci_write_loopback_mode_cp;
1805 
1806 typedef hci_status_rp	hci_write_loopback_mode_rp;
1807 
1808 #define HCI_OCF_ENABLE_UNIT_UNDER_TEST			0x0003
1809 #define HCI_CMD_ENABLE_UNIT_UNDER_TEST			0x1803
1810 /* No command parameter(s) */
1811 typedef hci_status_rp	hci_enable_unit_under_test_rp;
1812 
1813 #define HCI_OCF_WRITE_SIMPLE_PAIRING_DEBUG_MODE		0x0004
1814 #define HCI_CMD_WRITE_SIMPLE_PAIRING_DEBUG_MODE		0x1804
1815 typedef struct {
1816 	uint8_t		mode;	/* simple pairing debug mode */
1817 } __packed hci_write_simple_pairing_debug_mode_cp;
1818 
1819 typedef hci_status_rp	hci_write_simple_pairing_debug_mode_rp;
1820 
1821 /**************************************************************************
1822  **************************************************************************
1823  ** OGF 0x3e	Bluetooth Logo Testing
1824  ** OGF 0x3f	Vendor Specific
1825  **************************************************************************
1826  **************************************************************************/
1827 
1828 #define HCI_OGF_BT_LOGO				0x3e
1829 #define HCI_OGF_VENDOR				0x3f
1830 
1831 /* Ericsson specific FC */
1832 #define HCI_CMD_ERICSSON_WRITE_PCM_SETTINGS		0xFC07
1833 #define HCI_CMD_ERICSSON_SET_UART_BAUD_RATE		0xFC09
1834 #define HCI_CMD_ERICSSON_SET_SCO_DATA_PATH		0xFC1D
1835 
1836 /* Cambridge Silicon Radio specific FC */
1837 #define HCI_CMD_CSR_EXTN				0xFC00
1838 
1839 
1840 /**************************************************************************
1841  **************************************************************************
1842  **                         Events and event parameters
1843  **************************************************************************
1844  **************************************************************************/
1845 
1846 #define HCI_EVENT_INQUIRY_COMPL			0x01
1847 typedef struct {
1848 	uint8_t		status; /* 0x00 - success */
1849 } __packed hci_inquiry_compl_ep;
1850 
1851 #define HCI_EVENT_INQUIRY_RESULT		0x02
1852 typedef struct {
1853 	uint8_t		num_responses;      /* number of responses */
1854 /*	hci_inquiry_response[num_responses]   -- see below */
1855 } __packed hci_inquiry_result_ep;
1856 
1857 typedef struct {
1858 	bdaddr_t	bdaddr;                   /* unit address */
1859 	uint8_t		page_scan_rep_mode;       /* page scan rep. mode */
1860 	uint8_t		page_scan_period_mode;    /* page scan period mode */
1861 	uint8_t		page_scan_mode;           /* page scan mode */
1862 	uint8_t		uclass[HCI_CLASS_SIZE];   /* unit class */
1863 	uint16_t	clock_offset;             /* clock offset */
1864 } __packed hci_inquiry_response;
1865 
1866 #define HCI_EVENT_CON_COMPL			0x03
1867 typedef struct {
1868 	uint8_t		status;          /* 0x00 - success */
1869 	uint16_t	con_handle;      /* Connection handle */
1870 	bdaddr_t	bdaddr;          /* remote unit address */
1871 	uint8_t		link_type;       /* Link type */
1872 	uint8_t		encryption_mode; /* Encryption mode */
1873 } __packed hci_con_compl_ep;
1874 
1875 #define HCI_EVENT_CON_REQ			0x04
1876 typedef struct {
1877 	bdaddr_t	bdaddr;                 /* remote unit address */
1878 	uint8_t		uclass[HCI_CLASS_SIZE]; /* remote unit class */
1879 	uint8_t		link_type;              /* link type */
1880 } __packed hci_con_req_ep;
1881 
1882 #define HCI_EVENT_DISCON_COMPL			0x05
1883 typedef struct {
1884 	uint8_t		status;     /* 0x00 - success */
1885 	uint16_t	con_handle; /* connection handle */
1886 	uint8_t		reason;     /* reason to disconnect */
1887 } __packed hci_discon_compl_ep;
1888 
1889 #define HCI_EVENT_AUTH_COMPL			0x06
1890 typedef struct {
1891 	uint8_t		status;     /* 0x00 - success */
1892 	uint16_t	con_handle; /* connection handle */
1893 } __packed hci_auth_compl_ep;
1894 
1895 #define HCI_EVENT_REMOTE_NAME_REQ_COMPL		0x07
1896 typedef struct {
1897 	uint8_t		status;                   /* 0x00 - success */
1898 	bdaddr_t	bdaddr;                   /* remote unit address */
1899 	char		name[HCI_UNIT_NAME_SIZE]; /* remote unit name */
1900 } __packed hci_remote_name_req_compl_ep;
1901 
1902 #define HCI_EVENT_ENCRYPTION_CHANGE		0x08
1903 typedef struct {
1904 	uint8_t		status;            /* 0x00 - success */
1905 	uint16_t	con_handle;        /* Connection handle */
1906 	uint8_t		encryption_enable; /* 0x00 - disable */
1907 } __packed hci_encryption_change_ep;
1908 
1909 #define HCI_EVENT_CHANGE_CON_LINK_KEY_COMPL	0x09
1910 typedef struct {
1911 	uint8_t		status;     /* 0x00 - success */
1912 	uint16_t	con_handle; /* Connection handle */
1913 } __packed hci_change_con_link_key_compl_ep;
1914 
1915 #define HCI_EVENT_MASTER_LINK_KEY_COMPL		0x0a
1916 typedef struct {
1917 	uint8_t		status;     /* 0x00 - success */
1918 	uint16_t	con_handle; /* Connection handle */
1919 	uint8_t		key_flag;   /* Key flag */
1920 } __packed hci_master_link_key_compl_ep;
1921 
1922 #define HCI_EVENT_READ_REMOTE_FEATURES_COMPL	0x0b
1923 typedef struct {
1924 	uint8_t		status;                      /* 0x00 - success */
1925 	uint16_t	con_handle;                  /* Connection handle */
1926 	uint8_t		features[HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
1927 } __packed hci_read_remote_features_compl_ep;
1928 
1929 #define HCI_EVENT_READ_REMOTE_VER_INFO_COMPL	0x0c
1930 typedef struct {
1931 	uint8_t		status;         /* 0x00 - success */
1932 	uint16_t	con_handle;     /* Connection handle */
1933 	uint8_t		lmp_version;    /* LMP version */
1934 	uint16_t	manufacturer;   /* Hardware manufacturer name */
1935 	uint16_t	lmp_subversion; /* LMP sub-version */
1936 } __packed hci_read_remote_ver_info_compl_ep;
1937 
1938 #define HCI_EVENT_QOS_SETUP_COMPL		0x0d
1939 typedef struct {
1940 	uint8_t		status;          /* 0x00 - success */
1941 	uint16_t	con_handle;      /* connection handle */
1942 	uint8_t		flags;           /* reserved for future use */
1943 	uint8_t		service_type;    /* service type */
1944 	uint32_t	token_rate;      /* bytes per second */
1945 	uint32_t	peak_bandwidth;  /* bytes per second */
1946 	uint32_t	latency;         /* microseconds */
1947 	uint32_t	delay_variation; /* microseconds */
1948 } __packed hci_qos_setup_compl_ep;
1949 
1950 #define HCI_EVENT_COMMAND_COMPL			0x0e
1951 typedef struct {
1952 	uint8_t		num_cmd_pkts; /* # of HCI command packets */
1953 	uint16_t	opcode;       /* command OpCode */
1954 	/* command return parameters (if any) */
1955 } __packed hci_command_compl_ep;
1956 
1957 #define HCI_EVENT_COMMAND_STATUS		0x0f
1958 typedef struct {
1959 	uint8_t		status;       /* 0x00 - pending */
1960 	uint8_t		num_cmd_pkts; /* # of HCI command packets */
1961 	uint16_t	opcode;       /* command OpCode */
1962 } __packed hci_command_status_ep;
1963 
1964 #define HCI_EVENT_HARDWARE_ERROR		0x10
1965 typedef struct {
1966 	uint8_t		hardware_code; /* hardware error code */
1967 } __packed hci_hardware_error_ep;
1968 
1969 #define HCI_EVENT_FLUSH_OCCUR			0x11
1970 typedef struct {
1971 	uint16_t	con_handle; /* connection handle */
1972 } __packed hci_flush_occur_ep;
1973 
1974 #define HCI_EVENT_ROLE_CHANGE			0x12
1975 typedef struct {
1976 	uint8_t		status; /* 0x00 - success */
1977 	bdaddr_t	bdaddr; /* address of remote unit */
1978 	uint8_t		role;   /* new connection role */
1979 } __packed hci_role_change_ep;
1980 
1981 #define HCI_EVENT_NUM_COMPL_PKTS		0x13
1982 typedef struct {
1983 	uint8_t		num_con_handles; /* # of connection handles */
1984 /* these are repeated "num_con_handles" times
1985 	uint16_t	con_handle; --- connection handle(s)
1986 	uint16_t	compl_pkts; --- # of completed packets */
1987 } __packed hci_num_compl_pkts_ep;
1988 
1989 #define HCI_EVENT_MODE_CHANGE			0x14
1990 typedef struct {
1991 	uint8_t		status;     /* 0x00 - success */
1992 	uint16_t	con_handle; /* connection handle */
1993 	uint8_t		unit_mode;  /* remote unit mode */
1994 	uint16_t	interval;   /* interval * 0.625 msec */
1995 } __packed hci_mode_change_ep;
1996 
1997 #define HCI_EVENT_RETURN_LINK_KEYS		0x15
1998 typedef struct {
1999 	uint8_t		num_keys; /* # of keys */
2000 /* these are repeated "num_keys" times
2001 	bdaddr_t	bdaddr;               --- remote address(es)
2002 	uint8_t		key[HCI_KEY_SIZE]; --- key(s) */
2003 } __packed hci_return_link_keys_ep;
2004 
2005 #define HCI_EVENT_PIN_CODE_REQ			0x16
2006 typedef struct {
2007 	bdaddr_t	bdaddr; /* remote unit address */
2008 } __packed hci_pin_code_req_ep;
2009 
2010 #define HCI_EVENT_LINK_KEY_REQ			0x17
2011 typedef struct {
2012 	bdaddr_t	bdaddr; /* remote unit address */
2013 } __packed hci_link_key_req_ep;
2014 
2015 #define HCI_EVENT_LINK_KEY_NOTIFICATION		0x18
2016 typedef struct {
2017 	bdaddr_t	bdaddr;            /* remote unit address */
2018 	uint8_t		key[HCI_KEY_SIZE]; /* link key */
2019 	uint8_t		key_type;          /* type of the key */
2020 } __packed hci_link_key_notification_ep;
2021 
2022 #define HCI_EVENT_LOOPBACK_COMMAND		0x19
2023 typedef hci_cmd_hdr_t	hci_loopback_command_ep;
2024 
2025 #define HCI_EVENT_DATA_BUFFER_OVERFLOW		0x1a
2026 typedef struct {
2027 	uint8_t		link_type; /* Link type */
2028 } __packed hci_data_buffer_overflow_ep;
2029 
2030 #define HCI_EVENT_MAX_SLOT_CHANGE		0x1b
2031 typedef struct {
2032 	uint16_t	con_handle;    /* connection handle */
2033 	uint8_t		lmp_max_slots; /* Max. # of slots allowed */
2034 } __packed hci_max_slot_change_ep;
2035 
2036 #define HCI_EVENT_READ_CLOCK_OFFSET_COMPL	0x1c
2037 typedef struct {
2038 	uint8_t		status;       /* 0x00 - success */
2039 	uint16_t	con_handle;   /* Connection handle */
2040 	uint16_t	clock_offset; /* Clock offset */
2041 } __packed hci_read_clock_offset_compl_ep;
2042 
2043 #define HCI_EVENT_CON_PKT_TYPE_CHANGED		0x1d
2044 typedef struct {
2045 	uint8_t		status;     /* 0x00 - success */
2046 	uint16_t	con_handle; /* connection handle */
2047 	uint16_t	pkt_type;   /* packet type */
2048 } __packed hci_con_pkt_type_changed_ep;
2049 
2050 #define HCI_EVENT_QOS_VIOLATION			0x1e
2051 typedef struct {
2052 	uint16_t	con_handle; /* connection handle */
2053 } __packed hci_qos_violation_ep;
2054 
2055 /* Page Scan Mode Change Event is deprecated */
2056 #define HCI_EVENT_PAGE_SCAN_MODE_CHANGE		0x1f
2057 typedef struct {
2058 	bdaddr_t	bdaddr;         /* destination address */
2059 	uint8_t		page_scan_mode; /* page scan mode */
2060 } __packed hci_page_scan_mode_change_ep;
2061 
2062 #define HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE	0x20
2063 typedef struct {
2064 	bdaddr_t	bdaddr;             /* destination address */
2065 	uint8_t		page_scan_rep_mode; /* page scan repetition mode */
2066 } __packed hci_page_scan_rep_mode_change_ep;
2067 
2068 #define HCI_EVENT_FLOW_SPECIFICATION_COMPL	0x21
2069 typedef struct {
2070 	uint8_t		status;		/* 0x00 - success */
2071 	uint16_t	con_handle;	/* connection handle */
2072 	uint8_t		flags;		/* reserved */
2073 	uint8_t		direction;	/* flow direction */
2074 	uint8_t		type;		/* service type */
2075 	uint32_t	token_rate;	/* token rate */
2076 	uint32_t	bucket_size;	/* token bucket size */
2077 	uint32_t	peak_bandwidth;	/* peak bandwidth */
2078 	uint32_t	latency;	/* access latency */
2079 } __packed hci_flow_specification_compl_ep;
2080 
2081 #define HCI_EVENT_RSSI_RESULT			0x22
2082 typedef struct {
2083 	uint8_t		num_responses;      /* number of responses */
2084 /*	hci_rssi_response[num_responses]   -- see below */
2085 } __packed hci_rssi_result_ep;
2086 
2087 typedef struct {
2088 	bdaddr_t	bdaddr;			/* unit address */
2089 	uint8_t		page_scan_rep_mode;	/* page scan rep. mode */
2090 	uint8_t		blank;			/* reserved */
2091 	uint8_t		uclass[HCI_CLASS_SIZE];	/* unit class */
2092 	uint16_t	clock_offset;		/* clock offset */
2093 	int8_t		rssi;			/* rssi */
2094 } __packed hci_rssi_response;
2095 
2096 #define HCI_EVENT_READ_REMOTE_EXTENDED_FEATURES	0x23
2097 typedef struct {
2098 	uint8_t		status;		/* 0x00 - success */
2099 	uint16_t	con_handle;	/* connection handle */
2100 	uint8_t		page;		/* page number */
2101 	uint8_t		max;		/* max page number */
2102 	uint8_t		features[HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
2103 } __packed hci_read_remote_extended_features_ep;
2104 
2105 #define HCI_EVENT_SCO_CON_COMPL			0x2c
2106 typedef struct {
2107 	uint8_t		status;		/* 0x00 - success */
2108 	uint16_t	con_handle;	/* connection handle */
2109 	bdaddr_t	bdaddr;		/* unit address */
2110 	uint8_t		link_type;	/* link type */
2111 	uint8_t		interval;	/* transmission interval */
2112 	uint8_t		window;		/* retransmission window */
2113 	uint16_t	rxlen;		/* rx packet length */
2114 	uint16_t	txlen;		/* tx packet length */
2115 	uint8_t		mode;		/* air mode */
2116 } __packed hci_sco_con_compl_ep;
2117 
2118 #define HCI_EVENT_SCO_CON_CHANGED		0x2d
2119 typedef struct {
2120 	uint8_t		status;		/* 0x00 - success */
2121 	uint16_t	con_handle;	/* connection handle */
2122 	uint8_t		interval;	/* transmission interval */
2123 	uint8_t		window;		/* retransmission window */
2124 	uint16_t	rxlen;		/* rx packet length */
2125 	uint16_t	txlen;		/* tx packet length */
2126 } __packed hci_sco_con_changed_ep;
2127 
2128 #define HCI_EVENT_SNIFF_SUBRATING		0x2e
2129 typedef struct {
2130 	uint8_t		status;		/* 0x00 - success */
2131 	uint16_t	con_handle;	/* connection handle */
2132 	uint16_t	tx_latency;	/* max transmit latency */
2133 	uint16_t	rx_latency;	/* max receive latency */
2134 	uint16_t	remote_timeout;	/* remote timeout */
2135 	uint16_t	local_timeout;	/* local timeout */
2136 } __packed hci_sniff_subrating_ep;
2137 
2138 #define HCI_EVENT_EXTENDED_RESULT		0x2f
2139 typedef struct {
2140 	uint8_t		num_responses;	/* must be 0x01 */
2141 	bdaddr_t	bdaddr;		/* remote device address */
2142 	uint8_t		page_scan_rep_mode;
2143 	uint8_t		reserved;
2144 	uint8_t		uclass[HCI_CLASS_SIZE];
2145 	uint16_t	clock_offset;
2146 	int8_t		rssi;
2147 	uint8_t		response[240];	/* extended inquiry response */
2148 } __packed hci_extended_result_ep;
2149 
2150 #define HCI_EVENT_ENCRYPTION_KEY_REFRESH	0x30
2151 typedef struct {
2152 	uint8_t		status;		/* 0x00 - success */
2153 	uint16_t	con_handle;	/* connection handle */
2154 } __packed hci_encryption_key_refresh_ep;
2155 
2156 #define HCI_EVENT_IO_CAPABILITY_REQ		0x31
2157 typedef struct {
2158 	bdaddr_t	bdaddr;		/* remote device address */
2159 } __packed hci_io_capability_req_ep;
2160 
2161 #define HCI_EVENT_IO_CAPABILITY_RSP		0x32
2162 typedef struct {
2163 	bdaddr_t	bdaddr;		/* remote device address */
2164 	uint8_t		io_capability;
2165 	uint8_t		oob_data_present;
2166 	uint8_t		auth_requirement;
2167 } __packed hci_io_capability_rsp_ep;
2168 
2169 #define HCI_EVENT_USER_CONFIRM_REQ		0x33
2170 typedef struct {
2171 	bdaddr_t	bdaddr;		/* remote device address */
2172 	uint32_t	value;		/* 000000 - 999999 */
2173 } __packed hci_user_confirm_req_ep;
2174 
2175 #define HCI_EVENT_USER_PASSKEY_REQ		0x34
2176 typedef struct {
2177 	bdaddr_t	bdaddr;		/* remote device address */
2178 } __packed hci_user_passkey_req_ep;
2179 
2180 #define HCI_EVENT_REMOTE_OOB_DATA_REQ		0x35
2181 typedef struct {
2182 	bdaddr_t	bdaddr;		/* remote device address */
2183 } __packed hci_remote_oob_data_req_ep;
2184 
2185 #define HCI_EVENT_SIMPLE_PAIRING_COMPL		0x36
2186 typedef struct {
2187 	uint8_t		status;		/* 0x00 - success */
2188 	bdaddr_t	bdaddr;		/* remote device address */
2189 } __packed hci_simple_pairing_compl_ep;
2190 
2191 #define HCI_EVENT_LINK_SUPERVISION_TO_CHANGED	0x38
2192 typedef struct {
2193 	uint16_t	con_handle;	/* connection handle */
2194 	uint16_t	timeout;	/* link supervision timeout */
2195 } __packed hci_link_supervision_to_changed_ep;
2196 
2197 #define HCI_EVENT_ENHANCED_FLUSH_COMPL		0x39
2198 typedef struct {
2199 	uint16_t	con_handle;	/* connection handle */
2200 } __packed hci_enhanced_flush_compl_ep;
2201 
2202 #define HCI_EVENT_USER_PASSKEY_NOTIFICATION	0x3b
2203 typedef struct {
2204 	bdaddr_t	bdaddr;		/* remote device address */
2205 	uint32_t	value;		/* 000000 - 999999 */
2206 } __packed hci_user_passkey_notification_ep;
2207 
2208 #define HCI_EVENT_KEYPRESS_NOTIFICATION		0x3c
2209 typedef struct {
2210 	bdaddr_t	bdaddr;		/* remote device address */
2211 	uint8_t		notification_type;
2212 } __packed hci_keypress_notification_ep;
2213 
2214 #define HCI_EVENT_REMOTE_FEATURES_NOTIFICATION	0x3d
2215 typedef struct {
2216 	bdaddr_t	bdaddr;		/* remote device address */
2217 	uint8_t		features[HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
2218 } __packed hci_remote_features_notification_ep;
2219 
2220 #define HCI_EVENT_BT_LOGO			0xfe
2221 
2222 #define HCI_EVENT_VENDOR			0xff
2223 
2224 /**************************************************************************
2225  **************************************************************************
2226  **                 HCI Socket Definitions
2227  **************************************************************************
2228  **************************************************************************/
2229 
2230 /* HCI socket options */
2231 #define SO_HCI_EVT_FILTER		1	/* get/set event filter */
2232 #define SO_HCI_PKT_FILTER		2	/* get/set packet filter */
2233 #define SO_HCI_DIRECTION		3	/* packet direction indicator */
2234 
2235 /* Control Messages */
2236 #define SCM_HCI_DIRECTION		SO_HCI_DIRECTION
2237 
2238 /*
2239  * HCI socket filter and get/set routines
2240  *
2241  * for ease of use, we filter 256 possible events/packets
2242  */
2243 struct hci_filter {
2244 	uint32_t	mask[8];	/* 256 bits */
2245 };
2246 
2247 static __inline void
2248 hci_filter_set(uint8_t bit, struct hci_filter *filter)
2249 {
2250 	uint8_t off = bit - 1;
2251 
2252 	off >>= 5;
2253 	filter->mask[off] |= (1 << ((bit - 1) & 0x1f));
2254 }
2255 
2256 static __inline void
2257 hci_filter_clr(uint8_t bit, struct hci_filter *filter)
2258 {
2259 	uint8_t off = bit - 1;
2260 
2261 	off >>= 5;
2262 	filter->mask[off] &= ~(1 << ((bit - 1) & 0x1f));
2263 }
2264 
2265 static __inline int
2266 hci_filter_test(uint8_t bit, struct hci_filter *filter)
2267 {
2268 	uint8_t off = bit - 1;
2269 
2270 	off >>= 5;
2271 	return (filter->mask[off] & (1 << ((bit - 1) & 0x1f)));
2272 }
2273 
2274 /*
2275  * HCI socket ioctl's
2276  *
2277  * Apart from GBTINFOA, these are all indexed on the unit name
2278  */
2279 
2280 #define SIOCGBTINFO	_IOWR('b',  5, struct btreq) /* get unit info */
2281 #define SIOCGBTINFOA	_IOWR('b',  6, struct btreq) /* get info by address */
2282 #define SIOCNBTINFO	_IOWR('b',  7, struct btreq) /* next unit info */
2283 
2284 #define SIOCSBTFLAGS	_IOWR('b',  8, struct btreq) /* set unit flags */
2285 #define SIOCSBTPOLICY	_IOWR('b',  9, struct btreq) /* set unit link policy */
2286 #define SIOCSBTPTYPE	_IOWR('b', 10, struct btreq) /* set unit packet type */
2287 
2288 #define SIOCGBTSTATS	_IOWR('b', 11, struct btreq) /* get unit statistics */
2289 #define SIOCZBTSTATS	_IOWR('b', 12, struct btreq) /* zero unit statistics */
2290 
2291 #define SIOCBTDUMP	 _IOW('b', 13, struct btreq) /* print debug info */
2292 #define SIOCSBTSCOMTU	_IOWR('b', 17, struct btreq) /* set sco_mtu value */
2293 
2294 struct bt_stats {
2295 	uint32_t	err_tx;
2296 	uint32_t	err_rx;
2297 	uint32_t	cmd_tx;
2298 	uint32_t	evt_rx;
2299 	uint32_t	acl_tx;
2300 	uint32_t	acl_rx;
2301 	uint32_t	sco_tx;
2302 	uint32_t	sco_rx;
2303 	uint32_t	byte_tx;
2304 	uint32_t	byte_rx;
2305 };
2306 
2307 struct btreq {
2308 	char	btr_name[HCI_DEVNAME_SIZE];	/* device name */
2309 
2310 	union {
2311 	    struct {
2312 		bdaddr_t btri_bdaddr;		/* device bdaddr */
2313 		uint16_t btri_flags;		/* flags */
2314 		uint16_t btri_num_cmd;		/* # of free cmd buffers */
2315 		uint16_t btri_num_acl;		/* # of free ACL buffers */
2316 		uint16_t btri_num_sco;		/* # of free SCO buffers */
2317 		uint16_t btri_acl_mtu;		/* ACL mtu */
2318 		uint16_t btri_sco_mtu;		/* SCO mtu */
2319 		uint16_t btri_link_policy;	/* Link Policy */
2320 		uint16_t btri_packet_type;	/* Packet Type */
2321 	    } btri;
2322 	    struct bt_stats btrs;   /* unit stats */
2323 	} btru;
2324 };
2325 
2326 #define btr_flags	btru.btri.btri_flags
2327 #define btr_bdaddr	btru.btri.btri_bdaddr
2328 #define btr_num_cmd	btru.btri.btri_num_cmd
2329 #define btr_num_acl	btru.btri.btri_num_acl
2330 #define btr_num_sco	btru.btri.btri_num_sco
2331 #define btr_acl_mtu	btru.btri.btri_acl_mtu
2332 #define btr_sco_mtu	btru.btri.btri_sco_mtu
2333 #define btr_link_policy btru.btri.btri_link_policy
2334 #define btr_packet_type btru.btri.btri_packet_type
2335 #define btr_stats	btru.btrs
2336 
2337 /* hci_unit & btr_flags */
2338 #define BTF_UP			(1<<0)	/* unit is up */
2339 #define BTF_RUNNING		(1<<1)	/* unit is running */
2340 #define BTF_XMIT_CMD		(1<<2)	/* unit is transmitting CMD packets */
2341 #define BTF_XMIT_ACL		(1<<3)	/* unit is transmitting ACL packets */
2342 #define BTF_XMIT_SCO		(1<<4)	/* unit is transmitting SCO packets */
2343 #define BTF_XMIT		(BTF_XMIT_CMD | BTF_XMIT_ACL | BTF_XMIT_SCO)
2344 #define BTF_INIT_BDADDR		(1<<5)	/* waiting for bdaddr */
2345 #define BTF_INIT_BUFFER_SIZE	(1<<6)	/* waiting for buffer size */
2346 #define BTF_INIT_FEATURES	(1<<7)	/* waiting for features */
2347 #define BTF_POWER_UP_NOOP	(1<<8)	/* should wait for No-op on power up */
2348 #define BTF_INIT_COMMANDS	(1<<9)	/* waiting for supported commands */
2349 
2350 #define BTF_INIT		(BTF_INIT_BDADDR	\
2351 				| BTF_INIT_BUFFER_SIZE	\
2352 				| BTF_INIT_FEATURES	\
2353 				| BTF_INIT_COMMANDS)
2354 
2355 /**************************************************************************
2356  **************************************************************************
2357  **                 HCI Kernel Definitions
2358  **************************************************************************
2359  **************************************************************************/
2360 
2361 #ifdef _KERNEL
2362 
2363 #include <sys/condvar.h>
2364 #include <sys/device.h>
2365 
2366 struct l2cap_channel;
2367 struct mbuf;
2368 struct sco_pcb;
2369 struct socket;
2370 struct sockopt;
2371 
2372 /* global HCI kernel variables */
2373 
2374 /* sysctl variables */
2375 extern int hci_memo_expiry;
2376 extern int hci_acl_expiry;
2377 extern int hci_sendspace, hci_recvspace;
2378 extern int hci_eventq_max, hci_aclrxq_max, hci_scorxq_max;
2379 
2380 /*
2381  * HCI Connection Information
2382  */
2383 struct hci_link {
2384 	struct hci_unit		*hl_unit;	/* our unit */
2385 	TAILQ_ENTRY(hci_link)	 hl_next;	/* next link on unit */
2386 
2387 	/* common info */
2388 	uint16_t		 hl_state;	/* connection state */
2389 	uint16_t		 hl_flags;	/* link flags */
2390 	bdaddr_t		 hl_bdaddr;	/* dest address */
2391 	uint16_t		 hl_handle;	/* connection handle */
2392 	uint8_t			 hl_type;	/* link type */
2393 
2394 	/* ACL link info */
2395 	uint8_t			 hl_lastid;	/* last id used */
2396 	uint16_t		 hl_refcnt;	/* reference count */
2397 	uint16_t		 hl_mtu;	/* signalling mtu for link */
2398 	uint16_t		 hl_flush;	/* flush timeout */
2399 	uint16_t		 hl_clock;	/* remote clock offset */
2400 
2401 	TAILQ_HEAD(,l2cap_pdu)	 hl_txq;	/* queue of outgoing PDUs */
2402 	int			 hl_txqlen;	/* number of fragments */
2403 	struct mbuf		*hl_rxp;	/* incoming PDU (accumulating)*/
2404 	callout_t		 hl_expire;	/* connection expiry timer */
2405 	TAILQ_HEAD(,l2cap_req)	 hl_reqs;	/* pending requests */
2406 
2407 	/* SCO link info */
2408 	struct hci_link		*hl_link;	/* SCO ACL link */
2409 	struct sco_pcb		*hl_sco;	/* SCO pcb */
2410 	MBUFQ_HEAD()		 hl_data;	/* SCO outgoing data */
2411 };
2412 
2413 /* hci_link state */
2414 #define HCI_LINK_CLOSED		0  /* closed */
2415 #define HCI_LINK_WAIT_CONNECT	1  /* waiting to connect */
2416 #define HCI_LINK_WAIT_AUTH	2  /* waiting for auth */
2417 #define HCI_LINK_WAIT_ENCRYPT	3  /* waiting for encrypt */
2418 #define HCI_LINK_WAIT_SECURE	4  /* waiting for secure */
2419 #define HCI_LINK_OPEN		5  /* ready and willing */
2420 #define HCI_LINK_BLOCK		6  /* open but blocking (see hci_acl_start) */
2421 
2422 /* hci_link flags */
2423 #define HCI_LINK_AUTH_REQ	(1<<0)  /* authentication requested */
2424 #define HCI_LINK_ENCRYPT_REQ	(1<<1)  /* encryption requested */
2425 #define HCI_LINK_SECURE_REQ	(1<<2)	/* secure link requested */
2426 #define HCI_LINK_AUTH		(1<<3)	/* link is authenticated */
2427 #define HCI_LINK_ENCRYPT	(1<<4)	/* link is encrypted */
2428 #define HCI_LINK_SECURE		(1<<5)	/* link is secured */
2429 #define HCI_LINK_CREATE_CON	(1<<6)	/* "Create Connection" pending */
2430 
2431 /*
2432  * Bluetooth Memo
2433  *	cached device information for remote devices that this unit has seen
2434  */
2435 struct hci_memo {
2436 	struct timeval		time;		/* time of last response */
2437 	bdaddr_t		bdaddr;
2438 	uint8_t			page_scan_rep_mode;
2439 	uint8_t			page_scan_mode;
2440 	uint16_t		clock_offset;
2441 	LIST_ENTRY(hci_memo)	next;
2442 };
2443 
2444 /*
2445  * The Bluetooth HCI interface attachment structure
2446  */
2447 struct hci_if {
2448 	int	(*enable)(device_t);
2449 	void	(*disable)(device_t);
2450 	void	(*output_cmd)(device_t, struct mbuf *);
2451 	void	(*output_acl)(device_t, struct mbuf *);
2452 	void	(*output_sco)(device_t, struct mbuf *);
2453 	void	(*get_stats)(device_t, struct bt_stats *, int);
2454 	int	ipl;		/* for locking */
2455 };
2456 
2457 /*
2458  * The Bluetooth HCI device unit structure
2459  */
2460 struct hci_unit {
2461 	device_t	 hci_dev;		/* bthci handle */
2462 	device_t	 hci_bthub;		/* bthub(4) handle */
2463 	const struct hci_if *hci_if;		/* bthci driver interface */
2464 
2465 	/* device info */
2466 	bdaddr_t	 hci_bdaddr;		/* device address */
2467 	uint16_t	 hci_flags;		/* see BTF_ above */
2468 	kcondvar_t	 hci_init;		/* sleep on this */
2469 
2470 	uint16_t	 hci_packet_type;	/* packet types */
2471 	uint16_t	 hci_acl_mask;		/* ACL packet capabilities */
2472 	uint16_t	 hci_sco_mask;		/* SCO packet capabilities */
2473 
2474 	uint16_t	 hci_link_policy;	/* link policy */
2475 	uint16_t	 hci_lmp_mask;		/* link policy capabilities */
2476 
2477 	uint8_t		 hci_cmds[HCI_COMMANDS_SIZE]; /* opcode bitmask */
2478 
2479 	/* flow control */
2480 	uint16_t	 hci_max_acl_size;	/* ACL payload mtu */
2481 	uint16_t	 hci_num_acl_pkts;	/* free ACL packet buffers */
2482 	uint8_t		 hci_num_cmd_pkts;	/* free CMD packet buffers */
2483 	uint8_t		 hci_max_sco_size;	/* SCO payload mtu */
2484 	uint16_t	 hci_num_sco_pkts;	/* free SCO packet buffers */
2485 
2486 	TAILQ_HEAD(,hci_link)	hci_links;	/* list of ACL/SCO links */
2487 	LIST_HEAD(,hci_memo)	hci_memos;	/* cached memo list */
2488 
2489 	/* input queues */
2490 	void			*hci_rxint;	/* receive interrupt cookie */
2491 	kmutex_t		 hci_devlock;	/* device queue lock */
2492 	MBUFQ_HEAD()		 hci_eventq;	/* Event queue */
2493 	MBUFQ_HEAD()		 hci_aclrxq;	/* ACL rx queue */
2494 	MBUFQ_HEAD()		 hci_scorxq;	/* SCO rx queue */
2495 	uint16_t		 hci_eventqlen;	/* Event queue length */
2496 	uint16_t		 hci_aclrxqlen;	/* ACL rx queue length */
2497 	uint16_t		 hci_scorxqlen;	/* SCO rx queue length */
2498 
2499 	/* output queues */
2500 	MBUFQ_HEAD()		 hci_cmdwait;	/* pending commands */
2501 	MBUFQ_HEAD()		 hci_scodone;	/* SCO done queue */
2502 
2503 	SIMPLEQ_ENTRY(hci_unit) hci_next;
2504 };
2505 
2506 extern SIMPLEQ_HEAD(hci_unit_list, hci_unit) hci_unit_list;
2507 
2508 /*
2509  * HCI layer function prototypes
2510  */
2511 
2512 /* hci_event.c */
2513 void hci_event(struct mbuf *, struct hci_unit *);
2514 
2515 /* hci_ioctl.c */
2516 int hci_ioctl(unsigned long, void *, struct lwp *);
2517 
2518 /* hci_link.c */
2519 struct hci_link *hci_acl_open(struct hci_unit *, bdaddr_t *);
2520 struct hci_link *hci_acl_newconn(struct hci_unit *, bdaddr_t *);
2521 void hci_acl_close(struct hci_link *, int);
2522 void hci_acl_timeout(void *);
2523 int hci_acl_setmode(struct hci_link *);
2524 void hci_acl_linkmode(struct hci_link *);
2525 void hci_acl_recv(struct mbuf *, struct hci_unit *);
2526 int hci_acl_send(struct mbuf *, struct hci_link *, struct l2cap_channel *);
2527 void hci_acl_start(struct hci_link *);
2528 void hci_acl_complete(struct hci_link *, int);
2529 struct hci_link *hci_sco_newconn(struct hci_unit *, bdaddr_t *);
2530 void hci_sco_recv(struct mbuf *, struct hci_unit *);
2531 void hci_sco_start(struct hci_link *);
2532 void hci_sco_complete(struct hci_link *, int);
2533 struct hci_link *hci_link_alloc(struct hci_unit *, bdaddr_t *, uint8_t);
2534 void hci_link_free(struct hci_link *, int);
2535 struct hci_link *hci_link_lookup_bdaddr(struct hci_unit *, bdaddr_t *, uint8_t);
2536 struct hci_link *hci_link_lookup_handle(struct hci_unit *, uint16_t);
2537 
2538 /* hci_misc.c */
2539 int hci_route_lookup(bdaddr_t *, bdaddr_t *);
2540 struct hci_memo *hci_memo_find(struct hci_unit *, bdaddr_t *);
2541 struct hci_memo *hci_memo_new(struct hci_unit *, bdaddr_t *);
2542 void hci_memo_free(struct hci_memo *);
2543 
2544 /* hci_socket.c */
2545 void hci_drop(void *);
2546 int hci_usrreq(struct socket *, int, struct mbuf *, struct mbuf *, struct mbuf *, struct lwp *);
2547 int hci_ctloutput(int, struct socket *, struct sockopt *);
2548 void hci_mtap(struct mbuf *, struct hci_unit *);
2549 
2550 /* hci_unit.c */
2551 struct hci_unit *hci_attach(const struct hci_if *, device_t, uint16_t);
2552 void hci_detach(struct hci_unit *);
2553 int hci_enable(struct hci_unit *);
2554 void hci_disable(struct hci_unit *);
2555 struct hci_unit *hci_unit_lookup(bdaddr_t *);
2556 int hci_send_cmd(struct hci_unit *, uint16_t, void *, uint8_t);
2557 void hci_num_cmds(struct hci_unit *, uint8_t);
2558 bool hci_input_event(struct hci_unit *, struct mbuf *);
2559 bool hci_input_acl(struct hci_unit *, struct mbuf *);
2560 bool hci_input_sco(struct hci_unit *, struct mbuf *);
2561 bool hci_complete_sco(struct hci_unit *, struct mbuf *);
2562 void hci_output_cmd(struct hci_unit *, struct mbuf *);
2563 void hci_output_acl(struct hci_unit *, struct mbuf *);
2564 void hci_output_sco(struct hci_unit *, struct mbuf *);
2565 
2566 #endif	/* _KERNEL */
2567 
2568 #endif /* _NETBT_HCI_H_ */
2569