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