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