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