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