1 /*
2  * ng_hci.h
3  */
4 
5 /*-
6  * SPDX-License-Identifier: BSD-2-Clause
7  *
8  * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com>
9  * All rights reserved.
10  *
11  * Redistribution and use in source and binary forms, with or without
12  * modification, are permitted provided that the following conditions
13  * are met:
14  * 1. Redistributions of source code must retain the above copyright
15  *    notice, this list of conditions and the following disclaimer.
16  * 2. Redistributions in binary form must reproduce the above copyright
17  *    notice, this list of conditions and the following disclaimer in the
18  *    documentation and/or other materials provided with the distribution.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
21  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
24  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30  * SUCH DAMAGE.
31  *
32  * $Id: ng_hci.h,v 1.2 2003/03/18 00:09:37 max Exp $
33  * $FreeBSD$
34  */
35 
36 /*
37  * This file contains everything that application needs to know about
38  * Host Controller Interface (HCI). All information was obtained from
39  * Bluetooth Specification Book v1.1.
40  *
41  * This file can be included by both kernel and userland applications.
42  *
43  * NOTE: Here and after Bluetooth device is called a "unit". Bluetooth
44  *       specification refers to both devices and units. They are the
45  *       same thing (i think), so to be consistent word "unit" will be
46  *       used.
47  */
48 
49 #ifndef _NETGRAPH_HCI_H_
50 #define _NETGRAPH_HCI_H_
51 
52 /**************************************************************************
53  **************************************************************************
54  **     Netgraph node hook name, type name and type cookie and commands
55  **************************************************************************
56  **************************************************************************/
57 
58 /* Node type name and type cookie */
59 #define NG_HCI_NODE_TYPE			"hci"
60 #define NGM_HCI_COOKIE				1000774184
61 
62 /* Netgraph node hook names */
63 #define NG_HCI_HOOK_DRV				"drv" /* Driver <-> HCI */
64 #define NG_HCI_HOOK_ACL				"acl" /* HCI <-> Upper */
65 #define NG_HCI_HOOK_SCO				"sco" /* HCI <-> Upper */
66 #define NG_HCI_HOOK_RAW				"raw" /* HCI <-> Upper */
67 
68 /**************************************************************************
69  **************************************************************************
70  **                   Common defines and types (HCI)
71  **************************************************************************
72  **************************************************************************/
73 
74 /* All sizes are in bytes */
75 #define NG_HCI_BDADDR_SIZE			6   /* unit address */
76 #define NG_HCI_LAP_SIZE				3   /* unit LAP */
77 #define NG_HCI_KEY_SIZE				16  /* link key */
78 #define NG_HCI_PIN_SIZE				16  /* link PIN */
79 #define NG_HCI_EVENT_MASK_SIZE			8   /* event mask */
80 #define NG_HCI_LE_EVENT_MASK_SIZE		8   /* event mask */
81 #define NG_HCI_CLASS_SIZE			3   /* unit class */
82 #define NG_HCI_FEATURES_SIZE			8   /* LMP features */
83 #define NG_HCI_UNIT_NAME_SIZE			248 /* unit name size */
84 #define NG_HCI_COMMANDS_SIZE			64  /*Command list BMP size*/
85 #define NG_HCI_EXTINQ_MAX			240 /**/
86 /* HCI specification */
87 #define NG_HCI_SPEC_V10				0x00 /* v1.0 */
88 #define NG_HCI_SPEC_V11				0x01 /* v1.1 */
89 /* 0x02 - 0xFF - reserved for future use */
90 
91 /* LMP features */
92 /* ------------------- byte 0 --------------------*/
93 #define NG_HCI_LMP_3SLOT			0x01
94 #define NG_HCI_LMP_5SLOT			0x02
95 #define NG_HCI_LMP_ENCRYPTION			0x04
96 #define NG_HCI_LMP_SLOT_OFFSET			0x08
97 #define NG_HCI_LMP_TIMING_ACCURACY		0x10
98 #define NG_HCI_LMP_SWITCH			0x20
99 #define NG_HCI_LMP_HOLD_MODE			0x40
100 #define NG_HCI_LMP_SNIFF_MODE			0x80
101 /* ------------------- byte 1 --------------------*/
102 #define NG_HCI_LMP_PARK_MODE			0x01
103 #define NG_HCI_LMP_RSSI				0x02
104 #define NG_HCI_LMP_CHANNEL_QUALITY		0x04
105 #define NG_HCI_LMP_SCO_LINK			0x08
106 #define NG_HCI_LMP_HV2_PKT			0x10
107 #define NG_HCI_LMP_HV3_PKT			0x20
108 #define NG_HCI_LMP_ULAW_LOG			0x40
109 #define NG_HCI_LMP_ALAW_LOG			0x80
110 /* ------------------- byte 2 --------------------*/
111 #define NG_HCI_LMP_CVSD				0x01
112 #define NG_HCI_LMP_PAGING_SCHEME		0x02
113 #define NG_HCI_LMP_POWER_CONTROL		0x04
114 #define NG_HCI_LMP_TRANSPARENT_SCO		0x08
115 #define NG_HCI_LMP_FLOW_CONTROL_LAG0		0x10
116 #define NG_HCI_LMP_FLOW_CONTROL_LAG1		0x20
117 #define NG_HCI_LMP_FLOW_CONTROL_LAG2		0x40
118 
119 /* Link types */
120 #define NG_HCI_LINK_SCO				0x00 /* Voice */
121 #define NG_HCI_LINK_ACL				0x01 /* Data */
122 #define NG_HCI_LINK_LE_PUBLIC			0x02 /* LE Public*/
123 #define NG_HCI_LINK_LE_RANDOM			0x03 /* LE Random*/
124 /* 0x02 - 0xFF - reserved for future use */
125 
126 /* Packet types */
127 				/* 0x0001 - 0x0004 - reserved for future use */
128 #define NG_HCI_PKT_DM1				0x0008 /* ACL link */
129 #define NG_HCI_PKT_DH1				0x0010 /* ACL link */
130 #define NG_HCI_PKT_HV1				0x0020 /* SCO link */
131 #define NG_HCI_PKT_HV2				0x0040 /* SCO link */
132 #define NG_HCI_PKT_HV3				0x0080 /* SCO link */
133 				/* 0x0100 - 0x0200 - reserved for future use */
134 #define NG_HCI_PKT_DM3				0x0400 /* ACL link */
135 #define NG_HCI_PKT_DH3				0x0800 /* ACL link */
136 				/* 0x1000 - 0x2000 - reserved for future use */
137 #define NG_HCI_PKT_DM5				0x4000 /* ACL link */
138 #define NG_HCI_PKT_DH5				0x8000 /* ACL link */
139 
140 /*
141  * Connection modes/Unit modes
142  *
143  * This is confusing. It means that one of the units change its mode
144  * for the specific connection. For example one connection was put on
145  * hold (but i could be wrong :)
146  */
147 
148 #define NG_HCI_UNIT_MODE_ACTIVE			0x00
149 #define NG_HCI_UNIT_MODE_HOLD			0x01
150 #define NG_HCI_UNIT_MODE_SNIFF			0x02
151 #define NG_HCI_UNIT_MODE_PARK			0x03
152 /* 0x04 - 0xFF - reserved for future use */
153 
154 /* Page scan modes */
155 #define NG_HCI_MANDATORY_PAGE_SCAN_MODE		0x00
156 #define NG_HCI_OPTIONAL_PAGE_SCAN_MODE1		0x01
157 #define NG_HCI_OPTIONAL_PAGE_SCAN_MODE2		0x02
158 #define NG_HCI_OPTIONAL_PAGE_SCAN_MODE3		0x03
159 /* 0x04 - 0xFF - reserved for future use */
160 
161 /* Page scan repetition modes */
162 #define NG_HCI_SCAN_REP_MODE0			0x00
163 #define NG_HCI_SCAN_REP_MODE1			0x01
164 #define NG_HCI_SCAN_REP_MODE2			0x02
165 /* 0x03 - 0xFF - reserved for future use */
166 
167 /* Page scan period modes */
168 #define NG_HCI_PAGE_SCAN_PERIOD_MODE0		0x00
169 #define NG_HCI_PAGE_SCAN_PERIOD_MODE1		0x01
170 #define NG_HCI_PAGE_SCAN_PERIOD_MODE2		0x02
171 /* 0x03 - 0xFF - reserved for future use */
172 
173 /* Scan enable */
174 #define NG_HCI_NO_SCAN_ENABLE			0x00
175 #define NG_HCI_INQUIRY_ENABLE_PAGE_DISABLE	0x01
176 #define NG_HCI_INQUIRY_DISABLE_PAGE_ENABLE	0x02
177 #define NG_HCI_INQUIRY_ENABLE_PAGE_ENABLE	0x03
178 /* 0x04 - 0xFF - reserved for future use */
179 
180 /* Hold mode activities */
181 #define NG_HCI_HOLD_MODE_NO_CHANGE		0x00
182 #define NG_HCI_HOLD_MODE_SUSPEND_PAGE_SCAN	0x01
183 #define NG_HCI_HOLD_MODE_SUSPEND_INQUIRY_SCAN	0x02
184 #define NG_HCI_HOLD_MODE_SUSPEND_PERIOD_INQUIRY	0x04
185 /* 0x08 - 0x80 - reserved for future use */
186 
187 /* Connection roles */
188 #define NG_HCI_ROLE_MASTER			0x00
189 #define NG_HCI_ROLE_SLAVE			0x01
190 /* 0x02 - 0xFF - reserved for future use */
191 
192 /* Key flags */
193 #define NG_HCI_USE_SEMI_PERMANENT_LINK_KEYS	0x00
194 #define NG_HCI_USE_TEMPORARY_LINK_KEY		0x01
195 /* 0x02 - 0xFF - reserved for future use */
196 
197 /* Pin types */
198 #define NG_HCI_PIN_TYPE_VARIABLE		0x00
199 #define NG_HCI_PIN_TYPE_FIXED			0x01
200 
201 /* Link key types */
202 #define NG_HCI_LINK_KEY_TYPE_COMBINATION_KEY	0x00
203 #define NG_HCI_LINK_KEY_TYPE_LOCAL_UNIT_KEY	0x01
204 #define NG_HCI_LINK_KEY_TYPE_REMOTE_UNIT_KEY	0x02
205 /* 0x03 - 0xFF - reserved for future use */
206 
207 /* Encryption modes */
208 #define NG_HCI_ENCRYPTION_MODE_NONE		0x00
209 #define NG_HCI_ENCRYPTION_MODE_P2P		0x01
210 #define NG_HCI_ENCRYPTION_MODE_ALL		0x02
211 /* 0x03 - 0xFF - reserved for future use */
212 
213 /* Quality of service types */
214 #define NG_HCI_SERVICE_TYPE_NO_TRAFFIC		0x00
215 #define NG_HCI_SERVICE_TYPE_BEST_EFFORT		0x01
216 #define NG_HCI_SERVICE_TYPE_GUARANTEED		0x02
217 /* 0x03 - 0xFF - reserved for future use */
218 
219 /* Link policy settings */
220 #define NG_HCI_LINK_POLICY_DISABLE_ALL_LM_MODES	0x0000
221 #define NG_HCI_LINK_POLICY_ENABLE_ROLE_SWITCH	0x0001 /* Master/Slave switch */
222 #define NG_HCI_LINK_POLICY_ENABLE_HOLD_MODE	0x0002
223 #define NG_HCI_LINK_POLICY_ENABLE_SNIFF_MODE	0x0004
224 #define NG_HCI_LINK_POLICY_ENABLE_PARK_MODE	0x0008
225 /* 0x0010 - 0x8000 - reserved for future use */
226 
227 /* Event masks */
228 #define NG_HCI_EVMSK_DEFAULT			0x00001fffffffffff
229 #define NG_HCI_EVMSK_ALL		 	0x1fffffffffffffff
230 #define NG_HCI_EVMSK_NONE			0x0000000000000000
231 #define NG_HCI_EVMSK_INQUIRY_COMPL		0x0000000000000001
232 #define NG_HCI_EVMSK_INQUIRY_RESULT		0x0000000000000002
233 #define NG_HCI_EVMSK_CON_COMPL			0x0000000000000004
234 #define NG_HCI_EVMSK_CON_REQ			0x0000000000000008
235 #define NG_HCI_EVMSK_DISCON_COMPL		0x0000000000000010
236 #define NG_HCI_EVMSK_AUTH_COMPL			0x0000000000000020
237 #define NG_HCI_EVMSK_REMOTE_NAME_REQ_COMPL	0x0000000000000040
238 #define NG_HCI_EVMSK_ENCRYPTION_CHANGE		0x0000000000000080
239 #define NG_HCI_EVMSK_CHANGE_CON_LINK_KEY_COMPL	0x0000000000000100
240 #define NG_HCI_EVMSK_MASTER_LINK_KEY_COMPL	0x0000000000000200
241 #define NG_HCI_EVMSK_READ_REMOTE_FEATURES_COMPL	0x0000000000000400
242 #define NG_HCI_EVMSK_READ_REMOTE_VER_INFO_COMPL	0x0000000000000800
243 #define NG_HCI_EVMSK_QOS_SETUP_COMPL		0x0000000000001000
244 #define NG_HCI_EVMSK_COMMAND_COMPL		0x0000000000002000
245 #define NG_HCI_EVMSK_COMMAND_STATUS		0x0000000000004000
246 #define NG_HCI_EVMSK_HARDWARE_ERROR		0x0000000000008000
247 #define NG_HCI_EVMSK_FLUSH_OCCUR		0x0000000000010000
248 #define NG_HCI_EVMSK_ROLE_CHANGE		0x0000000000020000
249 #define NG_HCI_EVMSK_NUM_COMPL_PKTS		0x0000000000040000
250 #define NG_HCI_EVMSK_MODE_CHANGE		0x0000000000080000
251 #define NG_HCI_EVMSK_RETURN_LINK_KEYS		0x0000000000100000
252 #define NG_HCI_EVMSK_PIN_CODE_REQ		0x0000000000200000
253 #define NG_HCI_EVMSK_LINK_KEY_REQ		0x0000000000400000
254 #define NG_HCI_EVMSK_LINK_KEY_NOTIFICATION	0x0000000000800000
255 #define NG_HCI_EVMSK_LOOPBACK_COMMAND		0x0000000001000000
256 #define NG_HCI_EVMSK_DATA_BUFFER_OVERFLOW	0x0000000002000000
257 #define NG_HCI_EVMSK_MAX_SLOT_CHANGE		0x0000000004000000
258 #define NG_HCI_EVMSK_READ_CLOCK_OFFSET_COMLETE	0x0000000008000000
259 #define NG_HCI_EVMSK_CON_PKT_TYPE_CHANGED	0x0000000010000000
260 #define NG_HCI_EVMSK_QOS_VIOLATION		0x0000000020000000
261 #define NG_HCI_EVMSK_PAGE_SCAN_MODE_CHANGE	0x0000000040000000
262 #define NG_HCI_EVMSK_PAGE_SCAN_REP_MODE_CHANGE	0x0000000080000000
263 #define NG_HCI_EVMSK_FLOW_SPEC_COMPL		0x0000000100000000
264 #define NG_HCI_EVMSK_INQUIRY_RESULT_W_RSSI	0x0000000200000000
265 #define NG_HCI_EVMSK_READ_REM_EXT_FEAT_COMPL	0x0000000400000000
266 
267 /* 0x0000000800000000 -	0x0000080000000000 - not in use */
268 
269 #define NG_HCI_EVMSK_SYNC_CONN_COMPL		0x0000100000000000
270 #define NG_HCI_EVMSK_SYNC_CONN_CHANGED		0x0000200000000000
271 #define NG_HCI_EVMSK_SNIFF_SUBRATING		0x0000400000000000
272 #define NG_HCI_EVMSK_EXT_INQUIRY_RESULT		0x0000800000000000
273 #define NG_HCI_EVMSK_ENC_KEY_REFRESH_COMPL	0x0001000000000000
274 #define NG_HCI_EVMSK_IO_CAPABILITY_REQ		0x0002000000000000
275 #define NG_HCI_EVMSK_IO_CAPABILITY_RESP		0x0004000000000000
276 #define NG_HCI_EVMSK_USER_CONFIRMATION_REQ	0x0008000000000000
277 #define NG_HCI_EVMSK_USER_PASSKEY_REQ		0x0010000000000000
278 #define NG_HCI_EVMSK_REM_OOB_DATA_REQ		0x0020000000000000
279 #define NG_HCI_EVMSK_SIMPLE_PAIRING_COMPL	0x0040000000000000
280 #define NG_HCI_EVMSK_LINK_SUPERV_TO_CHANGED	0x0080000000000000
281 #define NG_HCI_EVMSK_ENH_FLUSH_COMPL		0x0100000000000000
282 #define NG_HCI_EVMSK_USER_PASSKEY_NOTIFICATION	0x0200000000000000
283 #define NG_HCI_EVMSK_KEYPRESS_NOTIFICATION	0x0400000000000000
284 #define NG_HCI_EVMSK_REM_HOST_SUPP_FEAT_NOTIFI	0x0800000000000000
285 #define NG_HCI_EVMSK_LE_META			0x1000000000000000
286 /* 0x1000000100000000 - 0x8000000000000000 - reserved for future use */
287 
288 /* LE events masks*/
289 #define NG_HCI_LEEVMSK_ALL			0x000000003fffffff
290 #define NG_HCI_LEEVMSK_NONE			0x0000000000000000
291 #define NG_HCI_LEEVMSK_DEFAULT			0x000000000000001f
292 #define NG_HCI_LEEVMSK_CONN_COMPLETE		0x0000000000000001
293 #define NG_HCI_LEEVMSK_ADV_REP			0x0000000000000002
294 #define NG_HCI_LEEVMSK_CONN_UPDATE		0x0000000000000004
295 #define NG_HCI_LEEVMSK_READ_REM_FEAT_REQ	0x0000000000000008
296 #define NG_HCI_LEEVMSK_LONG_TERM_KEY_REQ	0x0000000000000010
297 #define NG_HCI_LEEVMSK_REM_CONN_PARAM_REQ	0x0000000000000020
298 #define NG_HCI_LEEVMSK_DATA_LENGTH_CHG		0x0000000000000040
299 #define NG_HCI_LEEVMSK_RD_LOC_P256_PK_COMPL	0x0000000000000080
300 #define NG_HCI_LEEVMSK_GEN_DHKEY_COMPL		0x0000000000000100
301 #define NG_HCI_LEEVMSK_ENH_CONN_COMPL		0x0000000000000200
302 #define NG_HCI_LEEVMSK_DIR_ADV_REP		0x0000000000000400
303 #define NG_HCI_LEEVMSK_PHY_UPD_COMPL		0x0000000000000800
304 #define NG_HCI_LEEVMSK_EXT_ADV_REP		0x0000000000001000
305 #define NG_HCI_LEEVMSK_PER_ADV_SYNC_EST		0x0000000000002000
306 #define NG_HCI_LEEVMSK_PER_ADV_REP		0x0000000000004000
307 #define NG_HCI_LEEVMSK_PER_ADV_SYNC_LOST	0x0000000000008000
308 #define NG_HCI_LEEVMSK_SCAN_TIMEOUT		0x0000000000010000
309 #define NG_HCI_LEEVMSK_ADV_SET_TERM		0x0000000000020000
310 #define NG_HCI_LEEVMSK_SCAN_REQ_RCVD		0x0000000000040000
311 #define NG_HCI_LEEVMSK_CHAN_SEL_ALGO		0x0000000000080000
312 #define NG_HCI_LEEVMSK_CONNLESS_IQ_REP		0x0000000000010000
313 #define NG_HCI_LEEVMSK_CONN_IQ_REP		0x0000000000020000
314 #define NG_HCI_LEEVMSK_CTE_REQ_FAILED		0x0000000000040000
315 #define NG_HCI_LEEVMSK_PER_ADV_SYN_TRF_RCVD	0x0000000000080000
316 #define NG_HCI_LEEVMSK_CIS_EST			0x0000000000100000
317 #define NG_HCI_LEEVMSK_CIS_REQ			0x0000000000200000
318 #define NG_HCI_LEEVMSK_CREATE_BIG_COMPL		0x0000000000400000
319 #define NG_HCI_LEEVMSK_TERM_BIG_COMPL		0x0000000000800000
320 #define NG_HCI_LEEVMSK_BIG_SYNC_EST		0x0000000001000000
321 #define NG_HCI_LEEVMSK_BIG_SYNC_LOST		0x0000000002000000
322 #define NG_HCI_LEEVMSK_REQ_PEER_SCA_COMPL	0x0000000004000000
323 #define NG_HCI_LEEVMSK_PATH_LOSS_THRESHOLD	0x0000000008000000
324 #define NG_HCI_LEEVMSK_TX_PWR_REP		0x0000000010000000
325 #define NG_HCI_LEEVMSK_BIGINFO_ADV_REP		0x0000000020000000
326 /* 0x0000000040000000 - 0x8000000000000000 - reserved for future use */
327 
328 /* Filter types */
329 #define NG_HCI_FILTER_TYPE_NONE			0x00
330 #define NG_HCI_FILTER_TYPE_INQUIRY_RESULT	0x01
331 #define NG_HCI_FILTER_TYPE_CON_SETUP		0x02
332 /* 0x03 - 0xFF - reserved for future use */
333 
334 /* Filter condition types for NG_HCI_FILTER_TYPE_INQUIRY_RESULT */
335 #define NG_HCI_FILTER_COND_INQUIRY_NEW_UNIT	0x00
336 #define NG_HCI_FILTER_COND_INQUIRY_UNIT_CLASS	0x01
337 #define NG_HCI_FILTER_COND_INQUIRY_BDADDR	0x02
338 /* 0x03 - 0xFF - reserved for future use */
339 
340 /* Filter condition types for NG_HCI_FILTER_TYPE_CON_SETUP */
341 #define NG_HCI_FILTER_COND_CON_ANY_UNIT		0x00
342 #define NG_HCI_FILTER_COND_CON_UNIT_CLASS	0x01
343 #define NG_HCI_FILTER_COND_CON_BDADDR		0x02
344 /* 0x03 - 0xFF - reserved for future use */
345 
346 /* Xmit level types */
347 #define NG_HCI_XMIT_LEVEL_CURRENT		0x00
348 #define NG_HCI_XMIT_LEVEL_MAXIMUM		0x01
349 /* 0x02 - 0xFF - reserved for future use */
350 
351 /* Host to Host Controller flow control */
352 #define NG_HCI_H2HC_FLOW_CONTROL_NONE		0x00
353 #define NG_HCI_H2HC_FLOW_CONTROL_ACL		0x01
354 #define NG_HCI_H2HC_FLOW_CONTROL_SCO		0x02
355 #define NG_HCI_H2HC_FLOW_CONTROL_BOTH		0x03	/* ACL and SCO */
356 /* 0x04 - 0xFF - reserved future use */
357 
358 /* Country codes */
359 #define NG_HCI_COUNTRY_CODE_NAM_EUR_JP		0x00
360 #define NG_HCI_COUNTRY_CODE_FRANCE		0x01
361 /* 0x02 - 0xFF - reserved future use */
362 
363 /* Loopback modes */
364 #define NG_HCI_LOOPBACK_NONE			0x00
365 #define NG_HCI_LOOPBACK_LOCAL			0x01
366 #define NG_HCI_LOOPBACK_REMOTE			0x02
367 /* 0x03 - 0xFF - reserved future use */
368 
369 /**************************************************************************
370  **************************************************************************
371  **                 Link level defines, headers and types
372  **************************************************************************
373  **************************************************************************/
374 
375 /*
376  * Macro(s) to combine OpCode and extract OGF (OpCode Group Field)
377  * and OCF (OpCode Command Field) from OpCode.
378  */
379 
380 #define NG_HCI_OPCODE(gf,cf)		((((gf) & 0x3f) << 10) | ((cf) & 0x3ff))
381 #define NG_HCI_OCF(op)			((op) & 0x3ff)
382 #define NG_HCI_OGF(op)			(((op) >> 10) & 0x3f)
383 
384 /*
385  * Marco(s) to extract/combine connection handle, BC (Broadcast) and
386  * PB (Packet boundary) flags.
387  */
388 
389 #define NG_HCI_CON_HANDLE(h)		((h) & 0x0fff)
390 #define NG_HCI_PB_FLAG(h)		(((h) & 0x3000) >> 12)
391 #define NG_HCI_BC_FLAG(h)		(((h) & 0xc000) >> 14)
392 #define NG_HCI_MK_CON_HANDLE(h, pb, bc) \
393 	(((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14))
394 
395 /* PB flag values */
396 #define	NG_HCI_LE_PACKET_START		0x0
397 #define	NG_HCI_PACKET_FRAGMENT		0x1
398 #define	NG_HCI_PACKET_START		0x2
399 					/* 11 for AMP packet, not supported */
400 
401 /* BC flag values */
402 #define NG_HCI_POINT2POINT		0x0 /* only Host controller to Host */
403 #define NG_HCI_BROADCAST_ACTIVE		0x1 /* both directions */
404 #define NG_HCI_BROADCAST_PICONET	0x2 /* both directions */
405 					/* 11 - reserved for future use */
406 
407 /* HCI command packet header */
408 #define NG_HCI_CMD_PKT			0x01
409 #define NG_HCI_CMD_PKT_SIZE		0xff /* without header */
410 typedef struct {
411 	u_int8_t	type;   /* MUST be 0x1 */
412 	u_int16_t	opcode; /* OpCode */
413 	u_int8_t	length; /* parameter(s) length in bytes */
414 } __attribute__ ((packed)) ng_hci_cmd_pkt_t;
415 
416 /* ACL data packet header */
417 #define NG_HCI_ACL_DATA_PKT		0x02
418 #define NG_HCI_ACL_PKT_SIZE		0xffff /* without header */
419 typedef struct {
420 	u_int8_t	type;        /* MUST be 0x2 */
421 	u_int16_t	con_handle;  /* connection handle + PB + BC flags */
422 	u_int16_t	length;      /* payload length in bytes */
423 } __attribute__ ((packed)) ng_hci_acldata_pkt_t;
424 
425 /* SCO data packet header */
426 #define NG_HCI_SCO_DATA_PKT		0x03
427 #define NG_HCI_SCO_PKT_SIZE		0xff /* without header */
428 typedef struct {
429 	u_int8_t	type;       /* MUST be 0x3 */
430 	u_int16_t	con_handle; /* connection handle + reserved bits */
431 	u_int8_t	length;     /* payload length in bytes */
432 } __attribute__ ((packed)) ng_hci_scodata_pkt_t;
433 
434 /* HCI event packet header */
435 #define NG_HCI_EVENT_PKT		0x04
436 #define NG_HCI_EVENT_PKT_SIZE		0xff /* without header */
437 typedef struct {
438 	u_int8_t	type;   /* MUST be 0x4 */
439 	u_int8_t	event;  /* event */
440 	u_int8_t	length; /* parameter(s) length in bytes */
441 } __attribute__ ((packed)) ng_hci_event_pkt_t;
442 
443 /* Bluetooth unit address */
444 typedef struct {
445 	u_int8_t	b[NG_HCI_BDADDR_SIZE];
446 } __attribute__ ((packed)) bdaddr_t;
447 typedef bdaddr_t *	bdaddr_p;
448 
449 /* Any BD_ADDR. Note: This is actually 7 bytes (count '\0' terminator) */
450 #define NG_HCI_BDADDR_ANY	((bdaddr_p) "\000\000\000\000\000\000")
451 
452 /* HCI status return parameter */
453 typedef struct {
454 	u_int8_t	status; /* 0x00 - success */
455 } __attribute__ ((packed)) ng_hci_status_rp;
456 
457 /**************************************************************************
458  **************************************************************************
459  **        Upper layer protocol interface. LP_xxx event parameters
460  **************************************************************************
461  **************************************************************************/
462 
463 /* Connection Request Event */
464 #define NGM_HCI_LP_CON_REQ			1  /* Upper -> HCI */
465 typedef struct {
466 	u_int16_t	link_type; /* type of connection */
467 	bdaddr_t	bdaddr;    /* remote unit address */
468 } ng_hci_lp_con_req_ep;
469 
470 /*
471  * XXX XXX XXX
472  *
473  * NOTE: This request is not defined by Bluetooth specification,
474  * but i find it useful :)
475  */
476 #define NGM_HCI_LP_DISCON_REQ			2 /* Upper -> HCI */
477 typedef struct {
478 	u_int16_t	con_handle; /* connection handle */
479 	u_int16_t	reason;	    /* reason to disconnect (only low byte) */
480 } ng_hci_lp_discon_req_ep;
481 
482 /* Connection Confirmation Event */
483 #define NGM_HCI_LP_CON_CFM			3  /* HCI -> Upper */
484 typedef struct {
485 	u_int8_t	status;     /* 0x00 - success */
486 	u_int8_t	link_type;  /* link type */
487 	u_int16_t	con_handle; /* con_handle */
488 	bdaddr_t	bdaddr;     /* remote unit address */
489 } ng_hci_lp_con_cfm_ep;
490 
491 /* Connection Indication Event */
492 #define NGM_HCI_LP_CON_IND			4  /* HCI -> Upper */
493 typedef struct {
494 	u_int8_t	link_type;                 /* link type */
495 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* unit class */
496 	bdaddr_t	bdaddr;                    /* remote unit address */
497 } ng_hci_lp_con_ind_ep;
498 
499 /* Connection Response Event */
500 #define NGM_HCI_LP_CON_RSP			5  /* Upper -> HCI */
501 typedef struct {
502 	u_int8_t	status;    /* 0x00 - accept connection */
503 	u_int8_t	link_type; /* link type */
504 	bdaddr_t	bdaddr;    /* remote unit address */
505 } ng_hci_lp_con_rsp_ep;
506 
507 /* Disconnection Indication Event */
508 #define NGM_HCI_LP_DISCON_IND			6  /* HCI -> Upper */
509 typedef struct {
510 	u_int8_t	reason;     /* reason to disconnect (only low byte) */
511 	u_int8_t	link_type;  /* link type */
512 	u_int16_t	con_handle; /* connection handle */
513 } ng_hci_lp_discon_ind_ep;
514 
515 /* QoS Setup Request Event */
516 #define NGM_HCI_LP_QOS_REQ			7  /* Upper -> HCI */
517 typedef struct {
518 	u_int16_t	con_handle;      /* connection handle */
519 	u_int8_t	flags;           /* reserved */
520 	u_int8_t	service_type;    /* service type */
521 	u_int32_t	token_rate;      /* bytes/sec */
522 	u_int32_t	peak_bandwidth;  /* bytes/sec */
523 	u_int32_t	latency;         /* msec */
524 	u_int32_t	delay_variation; /* msec */
525 } ng_hci_lp_qos_req_ep;
526 
527 /* QoS Conformition Event */
528 #define NGM_HCI_LP_QOS_CFM			8  /* HCI -> Upper */
529 typedef struct {
530 	u_int16_t	status;          /* 0x00 - success  (only low byte) */
531 	u_int16_t	con_handle;      /* connection handle */
532 } ng_hci_lp_qos_cfm_ep;
533 
534 /* QoS Violation Indication Event */
535 #define NGM_HCI_LP_QOS_IND			9  /* HCI -> Upper */
536 typedef struct {
537 	u_int16_t	con_handle; /* connection handle */
538 } ng_hci_lp_qos_ind_ep;
539 /*Encryption Change event*/
540 #define NGM_HCI_LP_ENC_CHG 			10 /* HCI->Upper*/
541 typedef struct {
542 	uint16_t con_handle;
543 	uint8_t status;
544 	uint8_t link_type;
545 }ng_hci_lp_enc_change_ep;
546 /**************************************************************************
547  **************************************************************************
548  **                    HCI node command/event parameters
549  **************************************************************************
550  **************************************************************************/
551 
552 /* Debug levels */
553 #define NG_HCI_ALERT_LEVEL		1
554 #define NG_HCI_ERR_LEVEL		2
555 #define NG_HCI_WARN_LEVEL		3
556 #define NG_HCI_INFO_LEVEL		4
557 
558 /* Unit states */
559 #define NG_HCI_UNIT_CONNECTED		(1 << 0)
560 #define NG_HCI_UNIT_INITED		(1 << 1)
561 #define NG_HCI_UNIT_READY	(NG_HCI_UNIT_CONNECTED|NG_HCI_UNIT_INITED)
562 #define NG_HCI_UNIT_COMMAND_PENDING	(1 << 2)
563 
564 /* Connection state */
565 #define NG_HCI_CON_CLOSED		0 /* connection closed */
566 #define NG_HCI_CON_W4_LP_CON_RSP	1 /* wait for LP_ConnectRsp */
567 #define NG_HCI_CON_W4_CONN_COMPLETE	2 /* wait for Connection_Complete evt */
568 #define NG_HCI_CON_OPEN			3 /* connection open */
569 
570 /* Get HCI node (unit) state (see states above) */
571 #define NGM_HCI_NODE_GET_STATE			100  /* HCI -> User */
572 typedef u_int16_t	ng_hci_node_state_ep;
573 
574 /* Turn on "inited" bit */
575 #define NGM_HCI_NODE_INIT			101 /* User -> HCI */
576 /* No parameters */
577 
578 /* Get/Set node debug level (see debug levels above) */
579 #define NGM_HCI_NODE_GET_DEBUG			102 /* HCI -> User */
580 #define NGM_HCI_NODE_SET_DEBUG			103 /* User -> HCI */
581 typedef u_int16_t	ng_hci_node_debug_ep;
582 
583 /* Get node buffer info */
584 #define NGM_HCI_NODE_GET_BUFFER			104 /* HCI -> User */
585 typedef struct {
586 	u_int8_t	cmd_free; /* number of free command packets */
587 	u_int8_t	sco_size; /* max. size of SCO packet */
588 	u_int16_t	sco_pkts; /* number of SCO packets */
589 	u_int16_t	sco_free; /* number of free SCO packets */
590 	u_int16_t	acl_size; /* max. size of ACL packet */
591 	u_int16_t	acl_pkts; /* number of ACL packets */
592 	u_int16_t	acl_free; /* number of free ACL packets */
593 } ng_hci_node_buffer_ep;
594 
595 /* Get BDADDR */
596 #define NGM_HCI_NODE_GET_BDADDR			105 /* HCI -> User */
597 /* bdaddr_t -- BDADDR */
598 
599 /* Get features */
600 #define NGM_HCI_NODE_GET_FEATURES		106 /* HCI -> User */
601 /* features[NG_HCI_FEATURES_SIZE] -- features */
602 
603 #define NGM_HCI_NODE_GET_STAT			107 /* HCI -> User */
604 typedef struct {
605 	u_int32_t	cmd_sent;   /* number of HCI commands sent */
606 	u_int32_t	evnt_recv;  /* number of HCI events received */
607 	u_int32_t	acl_recv;   /* number of ACL packets received */
608 	u_int32_t	acl_sent;   /* number of ACL packets sent */
609 	u_int32_t	sco_recv;   /* number of SCO packets received */
610 	u_int32_t	sco_sent;   /* number of SCO packets sent */
611 	u_int32_t	bytes_recv; /* total number of bytes received */
612 	u_int32_t	bytes_sent; /* total number of bytes sent */
613 } ng_hci_node_stat_ep;
614 
615 #define NGM_HCI_NODE_RESET_STAT			108 /* User -> HCI */
616 /* No parameters */
617 
618 #define NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE	109 /* User -> HCI */
619 
620 #define NGM_HCI_NODE_GET_NEIGHBOR_CACHE		110 /* HCI -> User */
621 typedef struct {
622 	u_int32_t	num_entries;	/* number of entries */
623 } ng_hci_node_get_neighbor_cache_ep;
624 
625 typedef struct {
626 	u_int16_t	page_scan_rep_mode;             /* page rep scan mode */
627 	u_int16_t	page_scan_mode;                 /* page scan mode */
628 	u_int16_t	clock_offset;                   /* clock offset */
629 	bdaddr_t	bdaddr;                         /* bdaddr */
630 	u_int8_t	features[NG_HCI_FEATURES_SIZE]; /* features */
631 	uint8_t 	addrtype;
632 	uint8_t		extinq_size; /* MAX 240*/
633 	uint8_t		extinq_data[NG_HCI_EXTINQ_MAX];
634 } ng_hci_node_neighbor_cache_entry_ep;
635 
636 #define NG_HCI_MAX_NEIGHBOR_NUM \
637 	((0xffff - sizeof(ng_hci_node_get_neighbor_cache_ep))/sizeof(ng_hci_node_neighbor_cache_entry_ep))
638 
639 #define NGM_HCI_NODE_GET_CON_LIST		111 /* HCI -> User */
640 typedef struct {
641 	u_int32_t	num_connections; /* number of connections */
642 } ng_hci_node_con_list_ep;
643 
644 typedef struct {
645 	u_int8_t	link_type;       /* ACL or SCO */
646 	u_int8_t	encryption_mode; /* none, p2p, ... */
647 	u_int8_t	mode;            /* ACTIVE, HOLD ... */
648 	u_int8_t	role;            /* MASTER/SLAVE */
649 	u_int16_t	state;           /* connection state */
650 	u_int16_t	reserved;        /* place holder */
651 	u_int16_t	pending;         /* number of pending packets */
652 	u_int16_t	queue_len;       /* number of packets in queue */
653 	u_int16_t	con_handle;      /* connection handle */
654 	bdaddr_t	bdaddr;          /* remote bdaddr */
655 } ng_hci_node_con_ep;
656 
657 #define NG_HCI_MAX_CON_NUM \
658 	((0xffff - sizeof(ng_hci_node_con_list_ep))/sizeof(ng_hci_node_con_ep))
659 
660 #define NGM_HCI_NODE_UP				112 /* HCI -> Upper */
661 typedef struct {
662 	u_int16_t	pkt_size; /* max. ACL/SCO packet size (w/out header) */
663 	u_int16_t	num_pkts; /* ACL/SCO packet queue size */
664 	u_int16_t	reserved; /* place holder */
665 	bdaddr_t	bdaddr;	  /* bdaddr */
666 } ng_hci_node_up_ep;
667 
668 #define NGM_HCI_SYNC_CON_QUEUE			113 /* HCI -> Upper */
669 typedef struct {
670 	u_int16_t	con_handle; /* connection handle */
671 	u_int16_t	completed;  /* number of completed packets */
672 } ng_hci_sync_con_queue_ep;
673 
674 #define NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK	114 /* HCI -> User */
675 #define NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK	115 /* User -> HCI */
676 typedef u_int16_t	ng_hci_node_link_policy_mask_ep;
677 
678 #define NGM_HCI_NODE_GET_PACKET_MASK		116 /* HCI -> User */
679 #define NGM_HCI_NODE_SET_PACKET_MASK		117 /* User -> HCI */
680 typedef u_int16_t	ng_hci_node_packet_mask_ep;
681 
682 #define NGM_HCI_NODE_GET_ROLE_SWITCH		118 /* HCI -> User */
683 #define NGM_HCI_NODE_SET_ROLE_SWITCH		119 /* User -> HCI */
684 typedef u_int16_t	ng_hci_node_role_switch_ep;
685 
686 #define	NGM_HCI_NODE_LIST_NAMES			200 /* HCI -> User */
687 
688 /**************************************************************************
689  **************************************************************************
690  **             Link control commands and return parameters
691  **************************************************************************
692  **************************************************************************/
693 
694 #define NG_HCI_OGF_LINK_CONTROL			0x01 /* OpCode Group Field */
695 
696 #define NG_HCI_OCF_INQUIRY			0x0001
697 typedef struct {
698 	u_int8_t	lap[NG_HCI_LAP_SIZE]; /* LAP */
699 	u_int8_t	inquiry_length; /* (N x 1.28) sec */
700 	u_int8_t	num_responses;  /* Max. # of responses before halted */
701 } __attribute__ ((packed)) ng_hci_inquiry_cp;
702 /* No return parameter(s) */
703 
704 #define NG_HCI_OCF_INQUIRY_CANCEL		0x0002
705 /* No command parameter(s) */
706 typedef ng_hci_status_rp	ng_hci_inquiry_cancel_rp;
707 
708 #define NG_HCI_OCF_PERIODIC_INQUIRY		0x0003
709 typedef struct {
710 	u_int16_t	max_period_length; /* Max. and min. amount of time */
711 	u_int16_t	min_period_length; /* between consecutive inquiries */
712 	u_int8_t	lap[NG_HCI_LAP_SIZE]; /* LAP */
713 	u_int8_t	inquiry_length;    /* (inquiry_length * 1.28) sec */
714 	u_int8_t	num_responses;     /* Max. # of responses */
715 } __attribute__ ((packed)) ng_hci_periodic_inquiry_cp;
716 
717 typedef ng_hci_status_rp	ng_hci_periodic_inquiry_rp;
718 
719 #define NG_HCI_OCF_EXIT_PERIODIC_INQUIRY	0x0004
720 /* No command parameter(s) */
721 typedef ng_hci_status_rp	ng_hci_exit_periodic_inquiry_rp;
722 
723 #define NG_HCI_OCF_CREATE_CON			0x0005
724 typedef struct {
725 	bdaddr_t	bdaddr;             /* destination address */
726 	u_int16_t	pkt_type;           /* packet type */
727 	u_int8_t	page_scan_rep_mode; /* page scan repetition mode */
728 	u_int8_t	page_scan_mode;     /* page scan mode */
729 	u_int16_t	clock_offset;       /* clock offset */
730 	u_int8_t	accept_role_switch; /* accept role switch? 0x00 - no */
731 } __attribute__ ((packed)) ng_hci_create_con_cp;
732 /* No return parameter(s) */
733 
734 #define NG_HCI_OCF_DISCON			0x0006
735 typedef struct {
736 	u_int16_t	con_handle; /* connection handle */
737 	u_int8_t	reason;     /* reason to disconnect */
738 } __attribute__ ((packed)) ng_hci_discon_cp;
739 /* No return parameter(s) */
740 
741 #define NG_HCI_OCF_ADD_SCO_CON			0x0007
742 typedef struct {
743 	u_int16_t	con_handle; /* connection handle */
744 	u_int16_t	pkt_type;   /* packet type */
745 } __attribute__ ((packed)) ng_hci_add_sco_con_cp;
746 /* No return parameter(s) */
747 
748 #define NG_HCI_OCF_ACCEPT_CON			0x0009
749 typedef struct {
750 	bdaddr_t	bdaddr; /* address of unit to be connected */
751 	u_int8_t	role;   /* connection role */
752 } __attribute__ ((packed)) ng_hci_accept_con_cp;
753 /* No return parameter(s) */
754 
755 #define NG_HCI_OCF_REJECT_CON			0x000a
756 typedef struct {
757 	bdaddr_t	bdaddr; /* remote address */
758 	u_int8_t	reason; /* reason to reject */
759 } __attribute__ ((packed)) ng_hci_reject_con_cp;
760 /* No return parameter(s) */
761 
762 #define NG_HCI_OCF_LINK_KEY_REP			0x000b
763 typedef struct {
764 	bdaddr_t	bdaddr;               /* remote address */
765 	u_int8_t	key[NG_HCI_KEY_SIZE]; /* key */
766 } __attribute__ ((packed)) ng_hci_link_key_rep_cp;
767 
768 typedef struct {
769 	u_int8_t	status; /* 0x00 - success */
770 	bdaddr_t	bdaddr; /* unit address */
771 } __attribute__ ((packed)) ng_hci_link_key_rep_rp;
772 
773 #define NG_HCI_OCF_LINK_KEY_NEG_REP		0x000c
774 typedef struct {
775 	bdaddr_t	bdaddr; /* remote address */
776 } __attribute__ ((packed)) ng_hci_link_key_neg_rep_cp;
777 
778 typedef struct {
779 	u_int8_t	status; /* 0x00 - success */
780 	bdaddr_t	bdaddr; /* unit address */
781 } __attribute__ ((packed)) ng_hci_link_key_neg_rep_rp;
782 
783 #define NG_HCI_OCF_PIN_CODE_REP			0x000d
784 typedef struct {
785 	bdaddr_t	bdaddr;               /* remote address */
786 	u_int8_t	pin_size;             /* pin code length (in bytes) */
787 	u_int8_t	pin[NG_HCI_PIN_SIZE]; /* pin code */
788 } __attribute__ ((packed)) ng_hci_pin_code_rep_cp;
789 
790 typedef struct {
791 	u_int8_t	status; /* 0x00 - success */
792 	bdaddr_t	bdaddr; /* unit address */
793 } __attribute__ ((packed)) ng_hci_pin_code_rep_rp;
794 
795 #define NG_HCI_OCF_PIN_CODE_NEG_REP		0x000e
796 typedef struct {
797 	bdaddr_t	bdaddr;  /* remote address */
798 } __attribute__ ((packed)) ng_hci_pin_code_neg_rep_cp;
799 
800 typedef struct {
801 	u_int8_t	status; /* 0x00 - success */
802 	bdaddr_t	bdaddr; /* unit address */
803 } __attribute__ ((packed)) ng_hci_pin_code_neg_rep_rp;
804 
805 #define NG_HCI_OCF_CHANGE_CON_PKT_TYPE		0x000f
806 typedef struct {
807 	u_int16_t	con_handle; /* connection handle */
808 	u_int16_t	pkt_type;   /* packet type */
809 } __attribute__ ((packed)) ng_hci_change_con_pkt_type_cp;
810 /* No return parameter(s) */
811 
812 #define NG_HCI_OCF_AUTH_REQ			0x0011
813 typedef struct {
814 	u_int16_t	con_handle; /* connection handle */
815 } __attribute__ ((packed)) ng_hci_auth_req_cp;
816 /* No return parameter(s) */
817 
818 #define NG_HCI_OCF_SET_CON_ENCRYPTION		0x0013
819 typedef struct {
820 	u_int16_t	con_handle;        /* connection handle */
821 	u_int8_t	encryption_enable; /* 0x00 - disable, 0x01 - enable */
822 } __attribute__ ((packed)) ng_hci_set_con_encryption_cp;
823 /* No return parameter(s) */
824 
825 #define NG_HCI_OCF_CHANGE_CON_LINK_KEY		0x0015
826 typedef struct {
827 	u_int16_t	con_handle; /* connection handle */
828 } __attribute__ ((packed)) ng_hci_change_con_link_key_cp;
829 /* No return parameter(s) */
830 
831 #define NG_HCI_OCF_MASTER_LINK_KEY		0x0017
832 typedef struct {
833 	u_int8_t	key_flag; /* key flag */
834 } __attribute__ ((packed)) ng_hci_master_link_key_cp;
835 /* No return parameter(s) */
836 
837 #define NG_HCI_OCF_REMOTE_NAME_REQ		0x0019
838 typedef struct {
839 	bdaddr_t	bdaddr;             /* remote address */
840 	u_int8_t	page_scan_rep_mode; /* page scan repetition mode */
841 	u_int8_t	page_scan_mode;     /* page scan mode */
842 	u_int16_t	clock_offset;       /* clock offset */
843 } __attribute__ ((packed)) ng_hci_remote_name_req_cp;
844 /* No return parameter(s) */
845 
846 #define NG_HCI_OCF_READ_REMOTE_FEATURES		0x001b
847 typedef struct {
848 	u_int16_t	con_handle; /* connection handle */
849 } __attribute__ ((packed)) ng_hci_read_remote_features_cp;
850 /* No return parameter(s) */
851 
852 #define NG_HCI_OCF_READ_REMOTE_VER_INFO		0x001d
853 typedef struct {
854 	u_int16_t	con_handle; /* connection handle */
855 } __attribute__ ((packed)) ng_hci_read_remote_ver_info_cp;
856 /* No return parameter(s) */
857 
858 #define NG_HCI_OCF_READ_CLOCK_OFFSET		 0x001f
859 typedef struct {
860 	u_int16_t	con_handle; /* connection handle */
861 } __attribute__ ((packed)) ng_hci_read_clock_offset_cp;
862 /* No return parameter(s) */
863 
864 /**************************************************************************
865  **************************************************************************
866  **        Link policy commands and return parameters
867  **************************************************************************
868  **************************************************************************/
869 
870 #define NG_HCI_OGF_LINK_POLICY			0x02 /* OpCode Group Field */
871 
872 #define NG_HCI_OCF_HOLD_MODE			0x0001
873 typedef struct {
874 	u_int16_t	con_handle;   /* connection handle */
875 	u_int16_t	max_interval; /* (max_interval * 0.625) msec */
876 	u_int16_t	min_interval; /* (max_interval * 0.625) msec */
877 } __attribute__ ((packed)) ng_hci_hold_mode_cp;
878 /* No return parameter(s) */
879 
880 #define NG_HCI_OCF_SNIFF_MODE			0x0003
881 typedef struct {
882 	u_int16_t	con_handle;   /* connection handle */
883 	u_int16_t	max_interval; /* (max_interval * 0.625) msec */
884 	u_int16_t	min_interval; /* (max_interval * 0.625) msec */
885 	u_int16_t	attempt;      /* (2 * attempt - 1) * 0.625 msec */
886 	u_int16_t	timeout;      /* (2 * attempt - 1) * 0.625 msec */
887 } __attribute__ ((packed)) ng_hci_sniff_mode_cp;
888 /* No return parameter(s) */
889 
890 #define NG_HCI_OCF_EXIT_SNIFF_MODE		0x0004
891 typedef struct {
892 	u_int16_t	con_handle; /* connection handle */
893 } __attribute__ ((packed)) ng_hci_exit_sniff_mode_cp;
894 /* No return parameter(s) */
895 
896 #define NG_HCI_OCF_PARK_MODE			0x0005
897 typedef struct {
898 	u_int16_t	con_handle;   /* connection handle */
899 	u_int16_t	max_interval; /* (max_interval * 0.625) msec */
900 	u_int16_t	min_interval; /* (max_interval * 0.625) msec */
901 } __attribute__ ((packed)) ng_hci_park_mode_cp;
902 /* No return parameter(s) */
903 
904 #define NG_HCI_OCF_EXIT_PARK_MODE		0x0006
905 typedef struct {
906 	u_int16_t	con_handle; /* connection handle */
907 } __attribute__ ((packed)) ng_hci_exit_park_mode_cp;
908 /* No return parameter(s) */
909 
910 #define NG_HCI_OCF_QOS_SETUP			0x0007
911 typedef struct {
912 	u_int16_t	con_handle;      /* connection handle */
913 	u_int8_t	flags;           /* reserved for future use */
914 	u_int8_t	service_type;    /* service type */
915 	u_int32_t	token_rate;      /* bytes per second */
916 	u_int32_t	peak_bandwidth;  /* bytes per second */
917 	u_int32_t	latency;         /* microseconds */
918 	u_int32_t	delay_variation; /* microseconds */
919 } __attribute__ ((packed)) ng_hci_qos_setup_cp;
920 /* No return parameter(s) */
921 
922 #define NG_HCI_OCF_ROLE_DISCOVERY		0x0009
923 typedef struct {
924 	u_int16_t	con_handle; /* connection handle */
925 } __attribute__ ((packed)) ng_hci_role_discovery_cp;
926 
927 typedef struct {
928 	u_int8_t	status;     /* 0x00 - success */
929 	u_int16_t	con_handle; /* connection handle */
930 	u_int8_t	role;       /* role for the connection handle */
931 } __attribute__ ((packed)) ng_hci_role_discovery_rp;
932 
933 #define NG_HCI_OCF_SWITCH_ROLE			0x000b
934 typedef struct {
935 	bdaddr_t	bdaddr; /* remote address */
936 	u_int8_t	role;   /* new local role */
937 } __attribute__ ((packed)) ng_hci_switch_role_cp;
938 /* No return parameter(s) */
939 
940 #define NG_HCI_OCF_READ_LINK_POLICY_SETTINGS	0x000c
941 typedef struct {
942 	u_int16_t	con_handle; /* connection handle */
943 } __attribute__ ((packed)) ng_hci_read_link_policy_settings_cp;
944 
945 typedef struct {
946 	u_int8_t	status;     /* 0x00 - success */
947 	u_int16_t	con_handle; /* connection handle */
948 	u_int16_t	settings;   /* link policy settings */
949 } __attribute__ ((packed)) ng_hci_read_link_policy_settings_rp;
950 
951 #define NG_HCI_OCF_WRITE_LINK_POLICY_SETTINGS	0x000d
952 typedef struct {
953 	u_int16_t	con_handle; /* connection handle */
954 	u_int16_t	settings;   /* link policy settings */
955 } __attribute__ ((packed)) ng_hci_write_link_policy_settings_cp;
956 
957 typedef struct {
958 	u_int8_t	status;     /* 0x00 - success */
959 	u_int16_t	con_handle; /* connection handle */
960 } __attribute__ ((packed)) ng_hci_write_link_policy_settings_rp;
961 
962 /**************************************************************************
963  **************************************************************************
964  **   Host controller and baseband commands and return parameters
965  **************************************************************************
966  **************************************************************************/
967 
968 #define NG_HCI_OGF_HC_BASEBAND			0x03 /* OpCode Group Field */
969 
970 #define NG_HCI_OCF_SET_EVENT_MASK		0x0001
971 typedef struct {
972 	u_int8_t	event_mask[NG_HCI_EVENT_MASK_SIZE]; /* event_mask */
973 } __attribute__ ((packed)) ng_hci_set_event_mask_cp;
974 
975 typedef ng_hci_status_rp	ng_hci_set_event_mask_rp;
976 #define NG_HCI_EVENT_MASK_DEFAULT 0x1fffffffffff
977 #define NG_HCI_EVENT_MASK_LE  0x2000000000000000
978 
979 #define NG_HCI_OCF_RESET			0x0003
980 /* No command parameter(s) */
981 typedef ng_hci_status_rp	ng_hci_reset_rp;
982 
983 #define NG_HCI_OCF_SET_EVENT_FILTER		0x0005
984 typedef struct {
985 	u_int8_t	filter_type;           /* filter type */
986 	u_int8_t	filter_condition_type; /* filter condition type */
987 	u_int8_t	condition[0];          /* conditions - variable size */
988 } __attribute__ ((packed)) ng_hci_set_event_filter_cp;
989 
990 typedef ng_hci_status_rp	ng_hci_set_event_filter_rp;
991 
992 #define NG_HCI_OCF_FLUSH			0x0008
993 typedef struct {
994 	u_int16_t	con_handle; /* connection handle */
995 } __attribute__ ((packed)) ng_hci_flush_cp;
996 
997 typedef struct {
998 	u_int8_t	status;     /* 0x00 - success */
999 	u_int16_t	con_handle; /* connection handle */
1000 } __attribute__ ((packed)) ng_hci_flush_rp;
1001 
1002 #define NG_HCI_OCF_READ_PIN_TYPE		0x0009
1003 /* No command parameter(s) */
1004 typedef struct {
1005 	u_int8_t	status;   /* 0x00 - success */
1006 	u_int8_t	pin_type; /* PIN type */
1007 } __attribute__ ((packed)) ng_hci_read_pin_type_rp;
1008 
1009 #define NG_HCI_OCF_WRITE_PIN_TYPE		0x000a
1010 typedef struct {
1011 	u_int8_t	pin_type; /* PIN type */
1012 } __attribute__ ((packed)) ng_hci_write_pin_type_cp;
1013 
1014 typedef ng_hci_status_rp	ng_hci_write_pin_type_rp;
1015 
1016 #define NG_HCI_OCF_CREATE_NEW_UNIT_KEY		0x000b
1017 /* No command parameter(s) */
1018 typedef ng_hci_status_rp	ng_hci_create_new_unit_key_rp;
1019 
1020 #define NG_HCI_OCF_READ_STORED_LINK_KEY		0x000d
1021 typedef struct {
1022 	bdaddr_t	bdaddr;   /* address */
1023 	u_int8_t	read_all; /* read all keys? 0x01 - yes */
1024 } __attribute__ ((packed)) ng_hci_read_stored_link_key_cp;
1025 
1026 typedef struct {
1027 	u_int8_t	status;        /* 0x00 - success */
1028 	u_int16_t	max_num_keys;  /* Max. number of keys */
1029 	u_int16_t	num_keys_read; /* Number of stored keys */
1030 } __attribute__ ((packed)) ng_hci_read_stored_link_key_rp;
1031 
1032 #define NG_HCI_OCF_WRITE_STORED_LINK_KEY	0x0011
1033 typedef struct {
1034 	u_int8_t	num_keys_write; /* # of keys to write */
1035 /* these are repeated "num_keys_write" times
1036 	bdaddr_t	bdaddr;                --- remote address(es)
1037 	u_int8_t	key[NG_HCI_KEY_SIZE];  --- key(s) */
1038 } __attribute__ ((packed)) ng_hci_write_stored_link_key_cp;
1039 
1040 typedef struct {
1041 	u_int8_t	status;           /* 0x00 - success */
1042 	u_int8_t	num_keys_written; /* # of keys successfully written */
1043 } __attribute__ ((packed)) ng_hci_write_stored_link_key_rp;
1044 
1045 #define NG_HCI_OCF_DELETE_STORED_LINK_KEY	0x0012
1046 typedef struct {
1047 	bdaddr_t	bdaddr;     /* address */
1048 	u_int8_t	delete_all; /* delete all keys? 0x01 - yes */
1049 } __attribute__ ((packed)) ng_hci_delete_stored_link_key_cp;
1050 
1051 typedef struct {
1052 	u_int8_t	status;           /* 0x00 - success */
1053 	u_int16_t	num_keys_deleted; /* Number of keys deleted */
1054 } __attribute__ ((packed)) ng_hci_delete_stored_link_key_rp;
1055 
1056 #define NG_HCI_OCF_CHANGE_LOCAL_NAME		0x0013
1057 typedef struct {
1058 	char		name[NG_HCI_UNIT_NAME_SIZE]; /* new unit name */
1059 } __attribute__ ((packed)) ng_hci_change_local_name_cp;
1060 
1061 typedef ng_hci_status_rp	ng_hci_change_local_name_rp;
1062 
1063 #define NG_HCI_OCF_READ_LOCAL_NAME		0x0014
1064 /* No command parameter(s) */
1065 typedef struct {
1066 	u_int8_t	status;  /* 0x00 - success */
1067 	char		name[NG_HCI_UNIT_NAME_SIZE]; /* unit name */
1068 } __attribute__ ((packed)) ng_hci_read_local_name_rp;
1069 
1070 #define NG_HCI_OCF_READ_CON_ACCEPT_TIMO		0x0015
1071 /* No command parameter(s) */
1072 typedef struct {
1073 	u_int8_t	status;  /* 0x00 - success */
1074 	u_int16_t	timeout; /* (timeout * 0.625) msec */
1075 } __attribute__ ((packed)) ng_hci_read_con_accept_timo_rp;
1076 
1077 #define NG_HCI_OCF_WRITE_CON_ACCEPT_TIMO	0x0016
1078 typedef struct {
1079 	u_int16_t	timeout; /* (timeout * 0.625) msec */
1080 } __attribute__ ((packed)) ng_hci_write_con_accept_timo_cp;
1081 
1082 typedef ng_hci_status_rp	ng_hci_write_con_accept_timo_rp;
1083 
1084 #define NG_HCI_OCF_READ_PAGE_TIMO		0x0017
1085 /* No command parameter(s) */
1086 typedef struct {
1087 	u_int8_t	status;  /* 0x00 - success */
1088 	u_int16_t	timeout; /* (timeout * 0.625) msec */
1089 } __attribute__ ((packed)) ng_hci_read_page_timo_rp;
1090 
1091 #define NG_HCI_OCF_WRITE_PAGE_TIMO		0x0018
1092 typedef struct {
1093 	u_int16_t	timeout; /* (timeout * 0.625) msec */
1094 } __attribute__ ((packed)) ng_hci_write_page_timo_cp;
1095 
1096 typedef ng_hci_status_rp	ng_hci_write_page_timo_rp;
1097 
1098 #define NG_HCI_OCF_READ_SCAN_ENABLE		0x0019
1099 /* No command parameter(s) */
1100 typedef struct {
1101 	u_int8_t	status;      /* 0x00 - success */
1102 	u_int8_t	scan_enable; /* Scan enable */
1103 } __attribute__ ((packed)) ng_hci_read_scan_enable_rp;
1104 
1105 #define NG_HCI_OCF_WRITE_SCAN_ENABLE		0x001a
1106 typedef struct {
1107 	u_int8_t	scan_enable; /* Scan enable */
1108 } __attribute__ ((packed)) ng_hci_write_scan_enable_cp;
1109 
1110 typedef ng_hci_status_rp	ng_hci_write_scan_enable_rp;
1111 
1112 #define NG_HCI_OCF_READ_PAGE_SCAN_ACTIVITY	0x001b
1113 /* No command parameter(s) */
1114 typedef struct {
1115 	u_int8_t	status;             /* 0x00 - success */
1116 	u_int16_t	page_scan_interval; /* interval * 0.625 msec */
1117 	u_int16_t	page_scan_window;   /* window * 0.625 msec */
1118 } __attribute__ ((packed)) ng_hci_read_page_scan_activity_rp;
1119 
1120 #define NG_HCI_OCF_WRITE_PAGE_SCAN_ACTIVITY	0x001c
1121 typedef struct {
1122 	u_int16_t	page_scan_interval; /* interval * 0.625 msec */
1123 	u_int16_t	page_scan_window;   /* window * 0.625 msec */
1124 } __attribute__ ((packed)) ng_hci_write_page_scan_activity_cp;
1125 
1126 typedef ng_hci_status_rp	ng_hci_write_page_scan_activity_rp;
1127 
1128 #define NG_HCI_OCF_READ_INQUIRY_SCAN_ACTIVITY	0x001d
1129 /* No command parameter(s) */
1130 typedef struct {
1131 	u_int8_t	status;                /* 0x00 - success */
1132 	u_int16_t	inquiry_scan_interval; /* interval * 0.625 msec */
1133 	u_int16_t	inquiry_scan_window;   /* window * 0.625 msec */
1134 } __attribute__ ((packed)) ng_hci_read_inquiry_scan_activity_rp;
1135 
1136 #define NG_HCI_OCF_WRITE_INQUIRY_SCAN_ACTIVITY	0x001e
1137 typedef struct {
1138 	u_int16_t	inquiry_scan_interval; /* interval * 0.625 msec */
1139 	u_int16_t	inquiry_scan_window;   /* window * 0.625 msec */
1140 } __attribute__ ((packed)) ng_hci_write_inquiry_scan_activity_cp;
1141 
1142 typedef ng_hci_status_rp	ng_hci_write_inquiry_scan_activity_rp;
1143 
1144 #define NG_HCI_OCF_READ_AUTH_ENABLE		0x001f
1145 /* No command parameter(s) */
1146 typedef struct {
1147 	u_int8_t	status;      /* 0x00 - success */
1148 	u_int8_t	auth_enable; /* 0x01 - enabled */
1149 } __attribute__ ((packed)) ng_hci_read_auth_enable_rp;
1150 
1151 #define NG_HCI_OCF_WRITE_AUTH_ENABLE		0x0020
1152 typedef struct {
1153 	u_int8_t	auth_enable; /* 0x01 - enabled */
1154 } __attribute__ ((packed)) ng_hci_write_auth_enable_cp;
1155 
1156 typedef ng_hci_status_rp	ng_hci_write_auth_enable_rp;
1157 
1158 #define NG_HCI_OCF_READ_ENCRYPTION_MODE		0x0021
1159 /* No command parameter(s) */
1160 typedef struct {
1161 	u_int8_t	status;          /* 0x00 - success */
1162 	u_int8_t	encryption_mode; /* encryption mode */
1163 } __attribute__ ((packed)) ng_hci_read_encryption_mode_rp;
1164 
1165 #define NG_HCI_OCF_WRITE_ENCRYPTION_MODE	0x0022
1166 typedef struct {
1167 	u_int8_t	encryption_mode; /* encryption mode */
1168 } __attribute__ ((packed)) ng_hci_write_encryption_mode_cp;
1169 
1170 typedef ng_hci_status_rp	ng_hci_write_encryption_mode_rp;
1171 
1172 #define NG_HCI_OCF_READ_UNIT_CLASS		0x0023
1173 /* No command parameter(s) */
1174 typedef struct {
1175 	u_int8_t	status;                    /* 0x00 - success */
1176 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* unit class */
1177 } __attribute__ ((packed)) ng_hci_read_unit_class_rp;
1178 
1179 #define NG_HCI_OCF_WRITE_UNIT_CLASS		0x0024
1180 typedef struct {
1181 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* unit class */
1182 } __attribute__ ((packed)) ng_hci_write_unit_class_cp;
1183 
1184 typedef ng_hci_status_rp	ng_hci_write_unit_class_rp;
1185 
1186 #define NG_HCI_OCF_READ_VOICE_SETTINGS		0x0025
1187 /* No command parameter(s) */
1188 typedef struct {
1189 	u_int8_t	status;   /* 0x00 - success */
1190 	u_int16_t	settings; /* voice settings */
1191 } __attribute__ ((packed)) ng_hci_read_voice_settings_rp;
1192 
1193 #define NG_HCI_OCF_WRITE_VOICE_SETTINGS		0x0026
1194 typedef struct {
1195 	u_int16_t	settings; /* voice settings */
1196 } __attribute__ ((packed)) ng_hci_write_voice_settings_cp;
1197 
1198 typedef ng_hci_status_rp	ng_hci_write_voice_settings_rp;
1199 
1200 #define NG_HCI_OCF_READ_AUTO_FLUSH_TIMO		0x0027
1201 typedef struct {
1202 	u_int16_t	con_handle; /* connection handle */
1203 } __attribute__ ((packed)) ng_hci_read_auto_flush_timo_cp;
1204 
1205 typedef struct {
1206 	u_int8_t	status;     /* 0x00 - success */
1207 	u_int16_t	con_handle; /* connection handle */
1208 	u_int16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
1209 } __attribute__ ((packed)) ng_hci_read_auto_flush_timo_rp;
1210 
1211 #define NG_HCI_OCF_WRITE_AUTO_FLUSH_TIMO	0x0028
1212 typedef struct {
1213 	u_int16_t	con_handle; /* connection handle */
1214 	u_int16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
1215 } __attribute__ ((packed)) ng_hci_write_auto_flush_timo_cp;
1216 
1217 typedef struct {
1218 	u_int8_t	status;     /* 0x00 - success */
1219 	u_int16_t	con_handle; /* connection handle */
1220 } __attribute__ ((packed)) ng_hci_write_auto_flush_timo_rp;
1221 
1222 #define NG_HCI_OCF_READ_NUM_BROADCAST_RETRANS	0x0029
1223 /* No command parameter(s) */
1224 typedef struct {
1225 	u_int8_t	status;  /* 0x00 - success */
1226 	u_int8_t	counter; /* number of broadcast retransmissions */
1227 } __attribute__ ((packed)) ng_hci_read_num_broadcast_retrans_rp;
1228 
1229 #define NG_HCI_OCF_WRITE_NUM_BROADCAST_RETRANS	0x002a
1230 typedef struct {
1231 	u_int8_t	counter; /* number of broadcast retransmissions */
1232 } __attribute__ ((packed)) ng_hci_write_num_broadcast_retrans_cp;
1233 
1234 typedef ng_hci_status_rp	ng_hci_write_num_broadcast_retrans_rp;
1235 
1236 #define NG_HCI_OCF_READ_HOLD_MODE_ACTIVITY	0x002b
1237 /* No command parameter(s) */
1238 typedef struct {
1239 	u_int8_t	status;             /* 0x00 - success */
1240 	u_int8_t	hold_mode_activity; /* Hold mode activities */
1241 } __attribute__ ((packed)) ng_hci_read_hold_mode_activity_rp;
1242 
1243 #define NG_HCI_OCF_WRITE_HOLD_MODE_ACTIVITY	0x002c
1244 typedef struct {
1245 	u_int8_t	hold_mode_activity; /* Hold mode activities */
1246 } __attribute__ ((packed)) ng_hci_write_hold_mode_activity_cp;
1247 
1248 typedef ng_hci_status_rp	ng_hci_write_hold_mode_activity_rp;
1249 
1250 #define NG_HCI_OCF_READ_XMIT_LEVEL		0x002d
1251 typedef struct {
1252 	u_int16_t	con_handle; /* connection handle */
1253 	u_int8_t	type;       /* Xmit level type */
1254 } __attribute__ ((packed)) ng_hci_read_xmit_level_cp;
1255 
1256 typedef struct {
1257 	u_int8_t	status;     /* 0x00 - success */
1258 	u_int16_t	con_handle; /* connection handle */
1259 	char		level;      /* -30 <= level <= 30 dBm */
1260 } __attribute__ ((packed)) ng_hci_read_xmit_level_rp;
1261 
1262 #define NG_HCI_OCF_READ_SCO_FLOW_CONTROL	0x002e
1263 /* No command parameter(s) */
1264 typedef struct {
1265 	u_int8_t	status;       /* 0x00 - success */
1266 	u_int8_t	flow_control; /* 0x00 - disabled */
1267 } __attribute__ ((packed)) ng_hci_read_sco_flow_control_rp;
1268 
1269 #define NG_HCI_OCF_WRITE_SCO_FLOW_CONTROL	0x002f
1270 typedef struct {
1271 	u_int8_t	flow_control; /* 0x00 - disabled */
1272 } __attribute__ ((packed)) ng_hci_write_sco_flow_control_cp;
1273 
1274 typedef ng_hci_status_rp	ng_hci_write_sco_flow_control_rp;
1275 
1276 #define NG_HCI_OCF_H2HC_FLOW_CONTROL		0x0031
1277 typedef struct {
1278 	u_int8_t	h2hc_flow; /* Host to Host controller flow control */
1279 } __attribute__ ((packed)) ng_hci_h2hc_flow_control_cp;
1280 
1281 typedef ng_hci_status_rp	ng_hci_h2hc_flow_control_rp;
1282 
1283 #define NG_HCI_OCF_HOST_BUFFER_SIZE		0x0033
1284 typedef struct {
1285 	u_int16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
1286 	u_int8_t	max_sco_size; /* Max. size of SCO packet (bytes) */
1287 	u_int16_t	num_acl_pkt;  /* Max. number of ACL packets */
1288 	u_int16_t	num_sco_pkt;  /* Max. number of SCO packets */
1289 } __attribute__ ((packed)) ng_hci_host_buffer_size_cp;
1290 
1291 typedef ng_hci_status_rp	ng_hci_host_buffer_size_rp;
1292 
1293 #define NG_HCI_OCF_HOST_NUM_COMPL_PKTS		0x0035
1294 typedef struct {
1295 	u_int8_t	num_con_handles; /* # of connection handles */
1296 /* these are repeated "num_con_handles" times
1297 	u_int16_t	con_handle; --- connection handle(s)
1298 	u_int16_t	compl_pkt;  --- # of completed packets */
1299 } __attribute__ ((packed)) ng_hci_host_num_compl_pkts_cp;
1300 /* No return parameter(s) */
1301 
1302 #define NG_HCI_OCF_READ_LINK_SUPERVISION_TIMO	0x0036
1303 typedef struct {
1304 	u_int16_t	con_handle; /* connection handle */
1305 } __attribute__ ((packed)) ng_hci_read_link_supervision_timo_cp;
1306 
1307 typedef struct {
1308 	u_int8_t	status;     /* 0x00 - success */
1309 	u_int16_t	con_handle; /* connection handle */
1310 	u_int16_t	timeout;    /* Link supervision timeout * 0.625 msec */
1311 } __attribute__ ((packed)) ng_hci_read_link_supervision_timo_rp;
1312 
1313 #define NG_HCI_OCF_WRITE_LINK_SUPERVISION_TIMO	0x0037
1314 typedef struct {
1315 	u_int16_t	con_handle; /* connection handle */
1316 	u_int16_t	timeout;    /* Link supervision timeout * 0.625 msec */
1317 } __attribute__ ((packed)) ng_hci_write_link_supervision_timo_cp;
1318 
1319 typedef struct {
1320 	u_int8_t	status;     /* 0x00 - success */
1321 	u_int16_t	con_handle; /* connection handle */
1322 } __attribute__ ((packed)) ng_hci_write_link_supervision_timo_rp;
1323 
1324 #define NG_HCI_OCF_READ_SUPPORTED_IAC_NUM	0x0038
1325 /* No command parameter(s) */
1326 typedef struct {
1327 	u_int8_t	status;  /* 0x00 - success */
1328 	u_int8_t	num_iac; /* # of supported IAC during scan */
1329 } __attribute__ ((packed)) ng_hci_read_supported_iac_num_rp;
1330 
1331 #define NG_HCI_OCF_READ_IAC_LAP			0x0039
1332 /* No command parameter(s) */
1333 typedef struct {
1334 	u_int8_t	status;  /* 0x00 - success */
1335 	u_int8_t	num_iac; /* # of IAC */
1336 /* these are repeated "num_iac" times
1337 	u_int8_t	laps[NG_HCI_LAP_SIZE]; --- LAPs */
1338 } __attribute__ ((packed)) ng_hci_read_iac_lap_rp;
1339 
1340 #define NG_HCI_OCF_WRITE_IAC_LAP		0x003a
1341 typedef struct {
1342 	u_int8_t	num_iac; /* # of IAC */
1343 /* these are repeated "num_iac" times
1344 	u_int8_t	laps[NG_HCI_LAP_SIZE]; --- LAPs */
1345 } __attribute__ ((packed)) ng_hci_write_iac_lap_cp;
1346 
1347 typedef ng_hci_status_rp	ng_hci_write_iac_lap_rp;
1348 
1349 /*0x003b-0x003e commands are depricated v2.0 or later*/
1350 #define NG_HCI_OCF_READ_PAGE_SCAN_PERIOD	0x003b
1351 /* No command parameter(s) */
1352 typedef struct {
1353 	u_int8_t	status;                /* 0x00 - success */
1354 	u_int8_t	page_scan_period_mode; /* Page scan period mode */
1355 } __attribute__ ((packed)) ng_hci_read_page_scan_period_rp;
1356 
1357 #define NG_HCI_OCF_WRITE_PAGE_SCAN_PERIOD	0x003c
1358 typedef struct {
1359 	u_int8_t	page_scan_period_mode; /* Page scan period mode */
1360 } __attribute__ ((packed)) ng_hci_write_page_scan_period_cp;
1361 
1362 typedef ng_hci_status_rp	ng_hci_write_page_scan_period_rp;
1363 
1364 #define NG_HCI_OCF_READ_PAGE_SCAN		0x003d
1365 /* No command parameter(s) */
1366 typedef struct {
1367 	u_int8_t	status;         /* 0x00 - success */
1368 	u_int8_t	page_scan_mode; /* Page scan mode */
1369 } __attribute__ ((packed)) ng_hci_read_page_scan_rp;
1370 
1371 #define NG_HCI_OCF_WRITE_PAGE_SCAN		0x003e
1372 typedef struct {
1373 	u_int8_t	page_scan_mode; /* Page scan mode */
1374 } __attribute__ ((packed)) ng_hci_write_page_scan_cp;
1375 
1376 typedef ng_hci_status_rp	ng_hci_write_page_scan_rp;
1377 
1378 #define NG_HCI_OCF_READ_LE_HOST_SUPPORTED  0x6c
1379 typedef struct {
1380 	u_int8_t	status;         /* 0x00 - success */
1381 	u_int8_t	le_supported_host ;/* LE host supported?*/
1382 	u_int8_t	simultaneous_le_host; /* BR/LE simulateneous? */
1383 } __attribute__ ((packed)) ng_hci_read_le_host_supported_rp;
1384 
1385 #define NG_HCI_OCF_WRITE_LE_HOST_SUPPORTED  0x6d
1386 typedef struct {
1387 	u_int8_t	le_supported_host; /* LE host supported?*/
1388 	u_int8_t	simultaneous_le_host; /* LE host supported?*/
1389 } __attribute__ ((packed)) ng_hci_write_le_host_supported_cp;
1390 
1391 typedef ng_hci_status_rp	ng_hci_write_le_host_supported_rp;
1392 
1393 /**************************************************************************
1394  **************************************************************************
1395  **           Informational commands and return parameters
1396  **     All commands in this category do not accept any parameters
1397  **************************************************************************
1398  **************************************************************************/
1399 
1400 #define NG_HCI_OGF_INFO				0x04 /* OpCode Group Field */
1401 
1402 #define NG_HCI_OCF_READ_LOCAL_VER		0x0001
1403 typedef struct {
1404 	u_int8_t	status;         /* 0x00 - success */
1405 	u_int8_t	hci_version;    /* HCI version */
1406 	u_int16_t	hci_revision;   /* HCI revision */
1407 	u_int8_t	lmp_version;    /* LMP version */
1408 	u_int16_t	manufacturer;   /* Hardware manufacturer name */
1409 	u_int16_t	lmp_subversion; /* LMP sub-version */
1410 } __attribute__ ((packed)) ng_hci_read_local_ver_rp;
1411 
1412 #define NG_HCI_OCF_READ_LOCAL_COMMANDS		0x0002
1413 typedef struct {
1414 	u_int8_t	status;                         /* 0x00 - success */
1415 	u_int8_t	features[NG_HCI_COMMANDS_SIZE]; /* command bitmsk*/
1416 } __attribute__ ((packed)) ng_hci_read_local_commands_rp;
1417 
1418 #define NG_HCI_OCF_READ_LOCAL_FEATURES		0x0003
1419 typedef struct {
1420 	u_int8_t	status;                         /* 0x00 - success */
1421 	u_int8_t	features[NG_HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
1422 } __attribute__ ((packed)) ng_hci_read_local_features_rp;
1423 
1424 #define NG_HCI_OCF_READ_BUFFER_SIZE		0x0005
1425 typedef struct {
1426 	u_int8_t	status;       /* 0x00 - success */
1427 	u_int16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
1428 	u_int8_t	max_sco_size; /* Max. size of SCO packet (bytes) */
1429 	u_int16_t	num_acl_pkt;  /* Max. number of ACL packets */
1430 	u_int16_t	num_sco_pkt;  /* Max. number of SCO packets */
1431 } __attribute__ ((packed)) ng_hci_read_buffer_size_rp;
1432 
1433 #define NG_HCI_OCF_READ_COUNTRY_CODE		0x0007
1434 typedef struct {
1435 	u_int8_t	status;       /* 0x00 - success */
1436 	u_int8_t	country_code; /* 0x00 - NAM, EUR, JP; 0x01 - France */
1437 } __attribute__ ((packed)) ng_hci_read_country_code_rp;
1438 
1439 #define NG_HCI_OCF_READ_BDADDR			0x0009
1440 typedef struct {
1441 	u_int8_t	status; /* 0x00 - success */
1442 	bdaddr_t	bdaddr; /* unit address */
1443 } __attribute__ ((packed)) ng_hci_read_bdaddr_rp;
1444 
1445 /**************************************************************************
1446  **************************************************************************
1447  **            Status commands and return parameters
1448  **************************************************************************
1449  **************************************************************************/
1450 
1451 #define NG_HCI_OGF_STATUS			0x05 /* OpCode Group Field */
1452 
1453 #define NG_HCI_OCF_READ_FAILED_CONTACT_CNTR	0x0001
1454 typedef struct {
1455 	u_int16_t	con_handle; /* connection handle */
1456 } __attribute__ ((packed)) ng_hci_read_failed_contact_cntr_cp;
1457 
1458 typedef struct {
1459 	u_int8_t	status;     /* 0x00 - success */
1460 	u_int16_t	con_handle; /* connection handle */
1461 	u_int16_t	counter;    /* number of consecutive failed contacts */
1462 } __attribute__ ((packed)) ng_hci_read_failed_contact_cntr_rp;
1463 
1464 #define NG_HCI_OCF_RESET_FAILED_CONTACT_CNTR	0x0002
1465 typedef struct {
1466 	u_int16_t	con_handle; /* connection handle */
1467 } __attribute__ ((packed)) ng_hci_reset_failed_contact_cntr_cp;
1468 
1469 typedef struct {
1470 	u_int8_t	status;     /* 0x00 - success */
1471 	u_int16_t	con_handle; /* connection handle */
1472 } __attribute__ ((packed)) ng_hci_reset_failed_contact_cntr_rp;
1473 
1474 #define NG_HCI_OCF_GET_LINK_QUALITY		0x0003
1475 typedef struct {
1476 	u_int16_t	con_handle; /* connection handle */
1477 } __attribute__ ((packed)) ng_hci_get_link_quality_cp;
1478 
1479 typedef struct {
1480 	u_int8_t	status;     /* 0x00 - success */
1481 	u_int16_t	con_handle; /* connection handle */
1482 	u_int8_t	quality;    /* higher value means better quality */
1483 } __attribute__ ((packed)) ng_hci_get_link_quality_rp;
1484 
1485 #define NG_HCI_OCF_READ_RSSI			0x0005
1486 typedef struct {
1487 	u_int16_t	con_handle; /* connection handle */
1488 } __attribute__ ((packed)) ng_hci_read_rssi_cp;
1489 
1490 typedef struct {
1491 	u_int8_t	status;     /* 0x00 - success */
1492 	u_int16_t	con_handle; /* connection handle */
1493 	char		rssi;       /* -127 <= rssi <= 127 dB */
1494 } __attribute__ ((packed)) ng_hci_read_rssi_rp;
1495 
1496 /**************************************************************************
1497  **************************************************************************
1498  **             Testing commands and return parameters
1499  **************************************************************************
1500  **************************************************************************/
1501 
1502 #define NG_HCI_OGF_TESTING			0x06 /* OpCode Group Field */
1503 
1504 #define NG_HCI_OCF_READ_LOOPBACK_MODE		0x0001
1505 /* No command parameter(s) */
1506 typedef struct {
1507 	u_int8_t	status; /* 0x00 - success */
1508 	u_int8_t	lbmode; /* loopback mode */
1509 } __attribute__ ((packed)) ng_hci_read_loopback_mode_rp;
1510 
1511 #define NG_HCI_OCF_WRITE_LOOPBACK_MODE		0x0002
1512 typedef struct {
1513 	u_int8_t	lbmode; /* loopback mode */
1514 } __attribute__ ((packed)) ng_hci_write_loopback_mode_cp;
1515 
1516 typedef ng_hci_status_rp	ng_hci_write_loopback_mode_rp;
1517 
1518 #define NG_HCI_OCF_ENABLE_UNIT_UNDER_TEST	0x0003
1519 /* No command parameter(s) */
1520 typedef ng_hci_status_rp	ng_hci_enable_unit_under_test_rp;
1521 
1522 /**************************************************************************
1523  **************************************************************************
1524  **                LE OpCode group field
1525  **************************************************************************
1526  **************************************************************************/
1527 
1528 #define NG_HCI_OGF_LE			0x08 /* OpCode Group Field */
1529 #define NG_HCI_OCF_LE_SET_EVENT_MASK			0x0001
1530 typedef struct {
1531 	u_int8_t	event_mask[NG_HCI_LE_EVENT_MASK_SIZE]; /* event_mask*/
1532 
1533 } __attribute__ ((packed)) ng_hci_le_set_event_mask_cp;
1534 typedef ng_hci_status_rp	ng_hci_le_set_event_mask_rp;
1535 #define NG_HCI_LE_EVENT_MASK_ALL 0x1f
1536 
1537 #define NG_HCI_OCF_LE_READ_BUFFER_SIZE			0x0002
1538 /*No command parameter */
1539 typedef struct {
1540 	u_int8_t	status; /*status*/
1541 	u_int16_t 	hc_le_data_packet_length;
1542 	u_int8_t	hc_total_num_le_data_packets;
1543 } __attribute__ ((packed)) ng_hci_le_read_buffer_size_rp;
1544 
1545 #define NG_HCI_OCF_LE_READ_LOCAL_SUPPORTED_FEATURES	0x0003
1546 /*No command parameter */
1547 typedef struct {
1548 	u_int8_t       	status; /*status*/
1549 	u_int64_t 	le_features;
1550 } __attribute__ ((packed)) ng_hci_le_read_local_supported_features_rp;
1551 
1552 #define NG_HCI_OCF_LE_SET_RANDOM_ADDRESS		0x0005
1553 typedef struct {
1554 	bdaddr_t 	random_address;
1555 } __attribute__ ((packed)) ng_hci_le_set_random_address_cp_;
1556 typedef ng_hci_status_rp	ng_hci_le_set_random_address_rp;
1557 
1558 #define NG_HCI_OCF_LE_SET_ADVERTISING_PARAMETERS	0x0006
1559 typedef struct {
1560 	u_int16_t	advertising_interval_min;
1561 	u_int16_t 	advertising_interval_max;
1562 	u_int8_t	advertising_type;
1563 	u_int8_t 	own_address_type;
1564 	u_int8_t 	direct_address_type;
1565 	bdaddr_t	direct_address;
1566 	u_int8_t	advertising_channel_map;
1567 	u_int8_t	advertising_filter_policy;
1568 } __attribute__ ((packed)) ng_hci_le_set_advertising_parameters_cp;
1569 typedef ng_hci_status_rp	ng_hci_le_set_advertising_parameters_rp;
1570 
1571 #define NG_HCI_OCF_LE_READ_ADVERTISING_CHANNEL_TX_POWER	0x0007
1572 /*No command parameter*/
1573 typedef struct {
1574 	u_int8_t status;
1575 	u_int8_t transmit_power_level;
1576 } __attribute__ ((packed)) ng_hci_le_read_advertising_channel_tx_power_rp;
1577 
1578 #define NG_HCI_OCF_LE_SET_ADVERTISING_DATA		0x0008
1579 #define NG_HCI_ADVERTISING_DATA_SIZE 31
1580 typedef struct {
1581 	u_int8_t advertising_data_length;
1582 	char advertising_data[NG_HCI_ADVERTISING_DATA_SIZE];
1583 } __attribute__ ((packed)) ng_hci_le_set_advertising_data_cp;
1584 typedef ng_hci_status_rp	ng_hci_le_set_advertising_data_rp;
1585 
1586 #define NG_HCI_OCF_LE_SET_SCAN_RESPONSE_DATA		0x0009
1587 
1588 typedef struct {
1589 	u_int8_t scan_response_data_length;
1590 	char scan_response_data[NG_HCI_ADVERTISING_DATA_SIZE];
1591 } __attribute__ ((packed)) ng_hci_le_set_scan_response_data_cp;
1592 typedef ng_hci_status_rp	ng_hci_le_set_scan_response_data_rp;
1593 
1594 #define NG_HCI_OCF_LE_SET_ADVERTISE_ENABLE		0x000a
1595 typedef struct {
1596 	u_int8_t advertising_enable;
1597 }__attribute__ ((packed)) ng_hci_le_set_advertise_enable_cp;
1598 typedef ng_hci_status_rp	ng_hci_le_set_advertise_enable_rp;
1599 
1600 #define NG_HCI_OCF_LE_SET_SCAN_PARAMETERS		0x000b
1601 typedef struct {
1602 	u_int8_t le_scan_type;
1603 	u_int16_t le_scan_interval;
1604 	u_int16_t le_scan_window;
1605 	u_int8_t own_address_type;
1606 	u_int8_t scanning_filter_policy;
1607 }__attribute__ ((packed)) ng_hci_le_set_scan_parameters_cp;
1608 typedef ng_hci_status_rp	ng_hci_le_set_scan_parameters_rp;
1609 
1610 #define NG_HCI_OCF_LE_SET_SCAN_ENABLE			0x000c
1611 typedef struct {
1612 	u_int8_t le_scan_enable;
1613 	u_int8_t filter_duplicates;
1614 }__attribute__ ((packed)) ng_hci_le_set_scan_enable_cp;
1615 typedef ng_hci_status_rp	ng_hci_le_set_scan_enable_rp;
1616 
1617 #define NG_HCI_OCF_LE_CREATE_CONNECTION			0x000d
1618 typedef struct {
1619 	u_int16_t scan_interval;
1620 	u_int16_t scan_window;
1621 	u_int8_t filter_policy;
1622 	u_int8_t peer_addr_type;
1623 	bdaddr_t peer_addr;
1624 	u_int8_t own_address_type;
1625 	u_int16_t conn_interval_min;
1626 	u_int16_t conn_interval_max;
1627 	u_int16_t conn_latency;
1628 	u_int16_t supervision_timeout;
1629 	u_int16_t min_ce_length;
1630 	u_int16_t max_ce_length;
1631 }__attribute__((packed)) ng_hci_le_create_connection_cp;
1632 /* No return parameters. */
1633 #define NG_HCI_OCF_LE_CREATE_CONNECTION_CANCEL		0x000e
1634 /*No command parameter*/
1635 typedef ng_hci_status_rp	ng_hci_le_create_connection_cancel_rp;
1636 #define NG_HCI_OCF_LE_READ_WHITE_LIST_SIZE		0x000f
1637 /*No command parameter*/
1638 typedef struct {
1639 	u_int8_t status;
1640 	u_int8_t white_list_size;
1641 } __attribute__ ((packed)) ng_hci_le_read_white_list_size_rp;
1642 
1643 #define NG_HCI_OCF_LE_CLEAR_WHITE_LIST			0x0010
1644 /* No command parameters. */
1645 typedef ng_hci_status_rp	ng_hci_le_clear_white_list_rp;
1646 #define NG_HCI_OCF_LE_ADD_DEVICE_TO_WHITE_LIST		0x0011
1647 typedef struct {
1648 	u_int8_t address_type;
1649 	bdaddr_t address;
1650 } __attribute__ ((packed)) ng_hci_le_add_device_to_white_list_cp;
1651 typedef ng_hci_status_rp	ng_hci_le_add_device_to_white_list_rp;
1652 
1653 #define NG_HCI_OCF_LE_REMOVE_DEVICE_FROM_WHITE_LIST	0x0012
1654 typedef struct {
1655 	u_int8_t address_type;
1656 	bdaddr_t address;
1657 } __attribute__ ((packed)) ng_hci_le_remove_device_from_white_list_cp;
1658 typedef ng_hci_status_rp	ng_hci_le_remove_device_from_white_list_rp;
1659 
1660 #define NG_HCI_OCF_LE_CONNECTION_UPDATE			0x0013
1661 typedef struct {
1662 	u_int16_t connection_handle;
1663 	u_int16_t conn_interval_min;
1664 	u_int16_t conn_interval_max;
1665 	u_int16_t conn_latency;
1666 	u_int16_t supervision_timeout;
1667 	u_int16_t minimum_ce_length;
1668 	u_int16_t maximum_ce_length;
1669 }__attribute__ ((packed)) ng_hci_le_connection_update_cp;
1670 /*no return parameter*/
1671 
1672 #define NG_HCI_OCF_LE_SET_HOST_CHANNEL_CLASSIFICATION	0x0014
1673 typedef struct{
1674 	u_int8_t le_channel_map[5];
1675 }__attribute__ ((packed)) ng_hci_le_set_host_channel_classification_cp;
1676 typedef ng_hci_status_rp	ng_hci_le_set_host_channel_classification_rp;
1677 
1678 #define NG_HCI_OCF_LE_READ_CHANNEL_MAP			0x0015
1679 typedef struct {
1680 	u_int16_t connection_handle;
1681 }__attribute__ ((packed)) ng_hci_le_read_channel_map_cp;
1682 typedef struct {
1683 	u_int8_t status;
1684 	u_int16_t connection_handle;
1685 	u_int8_t le_channel_map[5];
1686 } __attribute__ ((packed)) ng_hci_le_read_channel_map_rp;
1687 
1688 #define NG_HCI_OCF_LE_READ_REMOTE_USED_FEATURES		0x0016
1689 typedef struct {
1690 	u_int16_t connection_handle;
1691 }__attribute__ ((packed)) ng_hci_le_read_remote_used_features_cp;
1692 /*No return parameter*/
1693 #define NG_HCI_128BIT 16
1694 #define NG_HCI_OCF_LE_ENCRYPT				0x0017
1695 typedef struct {
1696 	u_int8_t key[NG_HCI_128BIT];
1697 	u_int8_t plaintext_data[NG_HCI_128BIT];
1698 }__attribute__ ((packed)) ng_hci_le_encrypt_cp;
1699 typedef struct {
1700 	u_int8_t status;
1701 	u_int8_t plaintext_data[NG_HCI_128BIT];
1702 }__attribute__ ((packed)) ng_hci_le_encrypt_rp;
1703 
1704 #define NG_HCI_OCF_LE_RAND				0x0018
1705 /*No command parameter*/
1706 typedef struct {
1707 	u_int8_t status;
1708 	u_int64_t random_number;
1709 }__attribute__ ((packed)) ng_hci_le_rand_rp;
1710 
1711 #define NG_HCI_OCF_LE_START_ENCRYPTION			0x0019
1712 typedef struct {
1713 	u_int16_t connection_handle;
1714 	u_int64_t random_number;
1715 	u_int16_t encrypted_diversifier;
1716 	u_int8_t long_term_key[NG_HCI_128BIT];
1717 }__attribute__ ((packed)) ng_hci_le_start_encryption_cp;
1718 /*No return parameter*/
1719 #define NG_HCI_OCF_LE_LONG_TERM_KEY_REQUEST_REPLY	0x001a
1720 typedef struct {
1721 	u_int16_t connection_handle;
1722 	u_int8_t long_term_key[NG_HCI_128BIT];
1723 }__attribute__ ((packed)) ng_hci_le_long_term_key_request_reply_cp;
1724 typedef struct {
1725 	u_int8_t status;
1726 	u_int16_t connection_handle;
1727 }__attribute__ ((packed)) ng_hci_le_long_term_key_request_reply_rp;
1728 
1729 #define NG_HCI_OCF_LE_LONG_TERM_KEY_REQUEST_NEGATIVE_REPLY 0x001b
1730 typedef struct{
1731 	u_int16_t connection_handle;
1732 }__attribute__((packed)) ng_hci_le_long_term_key_request_negative_reply_cp;
1733 typedef struct {
1734 	u_int8_t status;
1735 	u_int16_t connection_handle;
1736 }__attribute__ ((packed)) ng_hci_le_long_term_key_request_negative_reply_rp;
1737 
1738 #define NG_HCI_OCF_LE_READ_SUGGESTED_DATA_LENGTH 	0x0023
1739 /*No command parameter*/
1740 typedef struct {
1741 	u_int8_t status;
1742 	u_int16_t suggested_max_tx_octets;
1743 	u_int16_t suggested_max_tx_time;
1744 }__attribute__ ((packed)) ng_hci_le_read_suggested_data_length_rp;
1745 
1746 #define NG_HCI_OCF_LE_WRITE_SUGGESTED_DATA_LENGTH 	0x0024
1747 typedef struct {
1748 	u_int16_t suggested_max_tx_octets;
1749 	u_int16_t suggested_max_tx_time;
1750 }__attribute__ ((packed)) ng_hci_le_write_suggested_data_length_cp;
1751 typedef ng_hci_status_rp	ng_hci_le_write_suggested_data_length_rp;
1752 
1753 #define NG_HCI_OCF_LE_READ_BUFFER_SIZE_V2		0x0060
1754 /*No command parameter */
1755 typedef struct {
1756 	u_int8_t	status;
1757 	u_int16_t 	hc_le_data_packet_length;
1758 	u_int8_t	hc_total_num_le_data_packets;
1759 	u_int16_t 	hc_iso_data_packet_length;
1760 	u_int8_t	hc_total_num_iso_data_packets;
1761 } __attribute__ ((packed)) ng_hci_le_read_buffer_size_rp_v2;
1762 
1763 #define NG_HCI_OCF_LE_READ_SUPPORTED_STATES		0x001c
1764 /*No command parameter*/
1765 typedef struct {
1766 	u_int8_t status;
1767 	u_int64_t le_states;
1768 }__attribute__ ((packed)) ng_hci_le_read_supported_states_rp;
1769 
1770 #define NG_HCI_OCF_LE_RECEIVER_TEST			0x001d
1771 typedef struct{
1772 	u_int8_t rx_frequency;
1773 } __attribute__((packed)) ng_le_receiver_test_cp;
1774 typedef ng_hci_status_rp	ng_hci_le_receiver_test_rp;
1775 
1776 #define NG_HCI_OCF_LE_TRANSMITTER_TEST			0x001e
1777 typedef struct{
1778 	u_int8_t tx_frequency;
1779 	u_int8_t length_of_test_data;
1780 	u_int8_t packet_payload;
1781 } __attribute__((packed)) ng_le_transmitter_test_cp;
1782 typedef ng_hci_status_rp	ng_hci_le_transmitter_test_rp;
1783 
1784 #define NG_HCI_OCF_LE_TEST_END				0x001f
1785 /* No command parameter. */
1786 typedef struct {
1787 	u_int8_t status;
1788 	u_int16_t number_of_packets;
1789 }__attribute__ ((packed)) ng_hci_le_test_end_rp;
1790 
1791 /**************************************************************************
1792  **************************************************************************
1793  **                Special HCI OpCode group field values
1794  **************************************************************************
1795  **************************************************************************/
1796 
1797 #define NG_HCI_OGF_BT_LOGO			0x3e
1798 
1799 #define NG_HCI_OGF_VENDOR			0x3f
1800 
1801 /**************************************************************************
1802  **************************************************************************
1803  **                         Events and event parameters
1804  **************************************************************************
1805  **************************************************************************/
1806 
1807 #define NG_HCI_EVENT_INQUIRY_COMPL		0x01
1808 typedef struct {
1809 	u_int8_t	status; /* 0x00 - success */
1810 } __attribute__ ((packed)) ng_hci_inquiry_compl_ep;
1811 
1812 #define NG_HCI_EVENT_INQUIRY_RESULT		0x02
1813 typedef struct {
1814 	u_int8_t	num_responses;      /* number of responses */
1815 /*	ng_hci_inquiry_response[num_responses]   -- see below */
1816 } __attribute__ ((packed)) ng_hci_inquiry_result_ep;
1817 
1818 typedef struct {
1819 	bdaddr_t	bdaddr;                   /* unit address */
1820 	u_int8_t	page_scan_rep_mode;       /* page scan rep. mode */
1821 	u_int8_t	page_scan_period_mode;    /* page scan period mode */
1822 	u_int8_t	page_scan_mode;           /* page scan mode */
1823 	u_int8_t	uclass[NG_HCI_CLASS_SIZE];/* unit class */
1824 	u_int16_t	clock_offset;             /* clock offset */
1825 } __attribute__ ((packed)) ng_hci_inquiry_response;
1826 
1827 #define NG_HCI_EVENT_CON_COMPL			0x03
1828 typedef struct {
1829 	u_int8_t	status;          /* 0x00 - success */
1830 	u_int16_t	con_handle;      /* Connection handle */
1831 	bdaddr_t	bdaddr;          /* remote unit address */
1832 	u_int8_t	link_type;       /* Link type */
1833 	u_int8_t	encryption_mode; /* Encryption mode */
1834 } __attribute__ ((packed)) ng_hci_con_compl_ep;
1835 
1836 #define NG_HCI_EVENT_CON_REQ			0x04
1837 typedef struct {
1838 	bdaddr_t	bdaddr;                    /* remote unit address */
1839 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* remote unit class */
1840 	u_int8_t	link_type;                 /* link type */
1841 } __attribute__ ((packed)) ng_hci_con_req_ep;
1842 
1843 #define NG_HCI_EVENT_DISCON_COMPL		0x05
1844 typedef struct {
1845 	u_int8_t	status;     /* 0x00 - success */
1846 	u_int16_t	con_handle; /* connection handle */
1847 	u_int8_t	reason;     /* reason to disconnect */
1848 } __attribute__ ((packed)) ng_hci_discon_compl_ep;
1849 
1850 #define NG_HCI_EVENT_AUTH_COMPL			0x06
1851 typedef struct {
1852 	u_int8_t	status;     /* 0x00 - success */
1853 	u_int16_t	con_handle; /* connection handle */
1854 } __attribute__ ((packed)) ng_hci_auth_compl_ep;
1855 
1856 #define NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL	0x7
1857 typedef struct {
1858 	u_int8_t	status; /* 0x00 - success */
1859 	bdaddr_t	bdaddr; /* remote unit address */
1860 	char		name[NG_HCI_UNIT_NAME_SIZE]; /* remote unit name */
1861 } __attribute__ ((packed)) ng_hci_remote_name_req_compl_ep;
1862 
1863 #define NG_HCI_EVENT_ENCRYPTION_CHANGE		0x08
1864 typedef struct {
1865 	u_int8_t	status;            /* 0x00 - success */
1866 	u_int16_t	con_handle;        /* Connection handle */
1867 	u_int8_t	encryption_enable; /* 0x00 - disable */
1868 } __attribute__ ((packed)) ng_hci_encryption_change_ep;
1869 
1870 #define NG_HCI_EVENT_CHANGE_CON_LINK_KEY_COMPL	0x09
1871 typedef struct {
1872 	u_int8_t	status;     /* 0x00 - success */
1873 	u_int16_t	con_handle; /* Connection handle */
1874 } __attribute__ ((packed)) ng_hci_change_con_link_key_compl_ep;
1875 
1876 #define NG_HCI_EVENT_MASTER_LINK_KEY_COMPL	0x0a
1877 typedef struct {
1878 	u_int8_t	status;     /* 0x00 - success */
1879 	u_int16_t	con_handle; /* Connection handle */
1880 	u_int8_t	key_flag;   /* Key flag */
1881 } __attribute__ ((packed)) ng_hci_master_link_key_compl_ep;
1882 
1883 #define NG_HCI_EVENT_READ_REMOTE_FEATURES_COMPL	0x0b
1884 typedef struct {
1885 	u_int8_t	status;                         /* 0x00 - success */
1886 	u_int16_t	con_handle;                     /* Connection handle */
1887 	u_int8_t	features[NG_HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
1888 } __attribute__ ((packed)) ng_hci_read_remote_features_compl_ep;
1889 
1890 #define NG_HCI_EVENT_READ_REMOTE_VER_INFO_COMPL	0x0c
1891 typedef struct {
1892 	u_int8_t	status;         /* 0x00 - success */
1893 	u_int16_t	con_handle;     /* Connection handle */
1894 	u_int8_t	lmp_version;    /* LMP version */
1895 	u_int16_t	manufacturer;   /* Hardware manufacturer name */
1896 	u_int16_t	lmp_subversion; /* LMP sub-version */
1897 } __attribute__ ((packed)) ng_hci_read_remote_ver_info_compl_ep;
1898 
1899 #define NG_HCI_EVENT_QOS_SETUP_COMPL		0x0d
1900 typedef struct {
1901 	u_int8_t	status;          /* 0x00 - success */
1902 	u_int16_t	con_handle;      /* connection handle */
1903 	u_int8_t	flags;           /* reserved for future use */
1904 	u_int8_t	service_type;    /* service type */
1905 	u_int32_t	token_rate;      /* bytes per second */
1906 	u_int32_t	peak_bandwidth;  /* bytes per second */
1907 	u_int32_t	latency;         /* microseconds */
1908 	u_int32_t	delay_variation; /* microseconds */
1909 } __attribute__ ((packed)) ng_hci_qos_setup_compl_ep;
1910 
1911 #define NG_HCI_EVENT_COMMAND_COMPL		0x0e
1912 typedef struct {
1913 	u_int8_t	num_cmd_pkts; /* # of HCI command packets */
1914 	u_int16_t	opcode;       /* command OpCode */
1915 	/* command return parameters (if any) */
1916 } __attribute__ ((packed)) ng_hci_command_compl_ep;
1917 
1918 #define NG_HCI_EVENT_COMMAND_STATUS		0x0f
1919 typedef struct {
1920 	u_int8_t	status;       /* 0x00 - pending */
1921 	u_int8_t	num_cmd_pkts; /* # of HCI command packets */
1922 	u_int16_t	opcode;       /* command OpCode */
1923 } __attribute__ ((packed)) ng_hci_command_status_ep;
1924 
1925 #define NG_HCI_EVENT_HARDWARE_ERROR		0x10
1926 typedef struct {
1927 	u_int8_t	hardware_code; /* hardware error code */
1928 } __attribute__ ((packed)) ng_hci_hardware_error_ep;
1929 
1930 #define NG_HCI_EVENT_FLUSH_OCCUR		0x11
1931 typedef struct {
1932 	u_int16_t	con_handle; /* connection handle */
1933 } __attribute__ ((packed)) ng_hci_flush_occur_ep;
1934 
1935 #define NG_HCI_EVENT_ROLE_CHANGE		0x12
1936 typedef struct {
1937 	u_int8_t	status; /* 0x00 - success */
1938 	bdaddr_t	bdaddr; /* address of remote unit */
1939 	u_int8_t	role;   /* new connection role */
1940 } __attribute__ ((packed)) ng_hci_role_change_ep;
1941 
1942 #define NG_HCI_EVENT_NUM_COMPL_PKTS		0x13
1943 typedef struct {
1944 	u_int8_t	num_con_handles; /* # of connection handles */
1945 /* these are repeated "num_con_handles" times
1946 	u_int16_t	con_handle; --- connection handle(s)
1947 	u_int16_t	compl_pkt;  --- # of completed packets */
1948 } __attribute__ ((packed)) ng_hci_num_compl_pkts_ep;
1949 
1950 #define NG_HCI_EVENT_MODE_CHANGE		0x14
1951 typedef struct {
1952 	u_int8_t	status;     /* 0x00 - success */
1953 	u_int16_t	con_handle; /* connection handle */
1954 	u_int8_t	unit_mode;  /* remote unit mode */
1955 	u_int16_t	interval;   /* interval * 0.625 msec */
1956 } __attribute__ ((packed)) ng_hci_mode_change_ep;
1957 
1958 #define NG_HCI_EVENT_RETURN_LINK_KEYS		0x15
1959 typedef struct {
1960 	u_int8_t	num_keys; /* # of keys */
1961 /* these are repeated "num_keys" times
1962 	bdaddr_t	bdaddr;               --- remote address(es)
1963 	u_int8_t	key[NG_HCI_KEY_SIZE]; --- key(s) */
1964 } __attribute__ ((packed)) ng_hci_return_link_keys_ep;
1965 
1966 #define NG_HCI_EVENT_PIN_CODE_REQ		0x16
1967 typedef struct {
1968 	bdaddr_t	bdaddr; /* remote unit address */
1969 } __attribute__ ((packed)) ng_hci_pin_code_req_ep;
1970 
1971 #define NG_HCI_EVENT_LINK_KEY_REQ		0x17
1972 typedef struct {
1973 	bdaddr_t	bdaddr; /* remote unit address */
1974 } __attribute__ ((packed)) ng_hci_link_key_req_ep;
1975 
1976 #define NG_HCI_EVENT_LINK_KEY_NOTIFICATION	0x18
1977 typedef struct {
1978 	bdaddr_t	bdaddr;               /* remote unit address */
1979 	u_int8_t	key[NG_HCI_KEY_SIZE]; /* link key */
1980 	u_int8_t	key_type;             /* type of the key */
1981 } __attribute__ ((packed)) ng_hci_link_key_notification_ep;
1982 
1983 #define NG_HCI_EVENT_LOOPBACK_COMMAND		0x19
1984 typedef struct {
1985 	u_int8_t	command[0]; /* Command packet */
1986 } __attribute__ ((packed)) ng_hci_loopback_command_ep;
1987 
1988 #define NG_HCI_EVENT_DATA_BUFFER_OVERFLOW	0x1a
1989 typedef struct {
1990 	u_int8_t	link_type; /* Link type */
1991 } __attribute__ ((packed)) ng_hci_data_buffer_overflow_ep;
1992 
1993 #define NG_HCI_EVENT_MAX_SLOT_CHANGE		0x1b
1994 typedef struct {
1995 	u_int16_t	con_handle;    /* connection handle */
1996 	u_int8_t	lmp_max_slots; /* Max. # of slots allowed */
1997 } __attribute__ ((packed)) ng_hci_max_slot_change_ep;
1998 
1999 #define NG_HCI_EVENT_READ_CLOCK_OFFSET_COMPL	0x1c
2000 typedef struct {
2001 	u_int8_t	status;       /* 0x00 - success */
2002 	u_int16_t	con_handle;   /* Connection handle */
2003 	u_int16_t	clock_offset; /* Clock offset */
2004 } __attribute__ ((packed)) ng_hci_read_clock_offset_compl_ep;
2005 
2006 #define NG_HCI_EVENT_CON_PKT_TYPE_CHANGED	0x1d
2007 typedef struct {
2008 	u_int8_t	status;     /* 0x00 - success */
2009 	u_int16_t	con_handle; /* connection handle */
2010 	u_int16_t	pkt_type;   /* packet type */
2011 } __attribute__ ((packed)) ng_hci_con_pkt_type_changed_ep;
2012 
2013 #define NG_HCI_EVENT_QOS_VIOLATION		0x1e
2014 typedef struct {
2015 	u_int16_t	con_handle; /* connection handle */
2016 } __attribute__ ((packed)) ng_hci_qos_violation_ep;
2017 
2018 #define NG_HCI_EVENT_PAGE_SCAN_MODE_CHANGE	0x1f
2019 typedef struct {
2020 	bdaddr_t	bdaddr;         /* destination address */
2021 	u_int8_t	page_scan_mode; /* page scan mode */
2022 } __attribute__ ((packed)) ng_hci_page_scan_mode_change_ep;
2023 
2024 #define NG_HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE	0x20
2025 typedef struct {
2026 	bdaddr_t	bdaddr;             /* destination address */
2027 	u_int8_t	page_scan_rep_mode; /* page scan repetition mode */
2028 } __attribute__ ((packed)) ng_hci_page_scan_rep_mode_change_ep;
2029 #define NG_HCI_EVENT_LE				0x3e
2030 typedef struct {
2031 	u_int8_t	subevent_code;
2032 }__attribute__ ((packed)) ng_hci_le_ep;
2033 
2034 #define NG_HCI_LEEV_CON_COMPL		0x01
2035 
2036 typedef struct {
2037 	u_int8_t	status;
2038 	u_int16_t	handle;
2039 	u_int8_t 	role;
2040 	u_int8_t 	address_type;
2041 	bdaddr_t	address;
2042 	u_int16_t 	interval;
2043 	u_int8_t	latency;
2044 	u_int16_t	supervision_timeout;
2045 	u_int8_t	master_clock_accuracy;
2046 
2047 } __attribute__ ((packed)) ng_hci_le_connection_complete_ep;
2048 
2049 #define NG_HCI_LEEV_ADVREP 0x02
2050 typedef struct {
2051 	u_int8_t num_reports;
2052 
2053 }__attribute__ ((packed)) ng_hci_le_advertising_report_ep;
2054 #define NG_HCI_SCAN_RESPONSE_DATA_MAX 0x1f
2055 
2056 typedef struct {
2057 	u_int8_t event_type;
2058 	u_int8_t addr_type;
2059 	bdaddr_t bdaddr;
2060 	u_int8_t length_data;
2061 	/* The last octet is for RSSI */
2062 	u_int8_t data[NG_HCI_SCAN_RESPONSE_DATA_MAX+1];
2063 }__attribute__((packed)) ng_hci_le_advreport;
2064 
2065 #define NG_HCI_LEEV_CON_UPDATE_COMPL 0x03
2066 typedef struct {
2067 	u_int8_t status;
2068 	u_int16_t connection_handle;
2069 	u_int16_t conn_interval;
2070 	u_int16_t conn_latency;
2071 	u_int16_t supervision_timeout;
2072 }__attribute__((packed)) ng_hci_connection_update_complete_ep;
2073 
2074 #define NG_HCI_LEEV_READ_REMOTE_FEATURES_COMPL 0x04
2075 typedef struct {
2076 	u_int8_t 	status;
2077 	u_int16_t 	connection_handle;
2078 	u_int8_t	features[NG_HCI_FEATURES_SIZE];
2079 }__attribute__((packed)) ng_hci_le_read_remote_features_ep;
2080 
2081 #define NG_HCI_LEEV_LONG_TERM_KEY_REQUEST 0x05
2082 typedef struct {
2083 	u_int16_t 	connection_handle;
2084 	u_int64_t 	random_number;
2085 	u_int16_t 	encrypted_diversifier;
2086 }__attribute__((packed)) ng_hci_le_long_term_key_request_ep;
2087 
2088 #define NG_HCI_LEEV_REMOTE_CONN_PARAM_REQUEST 0x06
2089 typedef struct {
2090 	u_int16_t 	connection_handle;
2091 	u_int16_t 	interval_min;
2092 	u_int16_t 	interval_max;
2093 	u_int16_t 	latency;
2094 	u_int16_t 	timeout;
2095 }__attribute__((packed)) ng_hci_le_remote_conn_param_ep;
2096 
2097 #define NG_HCI_LEEV_DATA_LENGTH_CHANGE 0x07
2098 typedef struct {
2099 	u_int16_t 	connection_handle;
2100 	u_int16_t 	min_tx_octets;
2101 	u_int16_t 	max_tx_time;
2102 	u_int16_t 	max_rx_octets;
2103 	u_int16_t 	max_rx_time;
2104 }__attribute__((packed)) ng_hci_le_data_length_change_ep;
2105 
2106 #define NG_HCI_LEEV_READ_LOCAL_P256_PK_COMPL 0x08
2107 typedef struct {
2108 	u_int8_t 	status;
2109 	u_int8_t 	local_p256_pk[64];
2110 }__attribute__((packed)) ng_hci_le_read_local_p256_pk_compl_ep;
2111 
2112 #define NG_HCI_LEEV_GEN_DHKEY_COMPL 0x09
2113 typedef struct {
2114 	u_int8_t 	status;
2115 	u_int8_t 	dh_key[32];
2116 }__attribute__((packed)) ng_hci_le_gen_dhkey_compl_ep;
2117 
2118 #define NG_HCI_LEEV_ENH_CONN_COMPL 0x0a
2119 typedef struct {
2120 	u_int8_t 	status;
2121 	u_int16_t 	connection_handle;
2122 	u_int8_t	role;
2123 	u_int8_t 	peer_addr_type;
2124 	bdaddr_t 	peer_addr;
2125 	bdaddr_t 	local_res_private_addr;
2126 	bdaddr_t 	peer_res_private_addr;
2127 	u_int16_t 	conn_interval;
2128 	u_int16_t 	conn_latency;
2129 	u_int16_t 	supervision_timeout;
2130 	u_int8_t	master_clock_accuracy;
2131 }__attribute__((packed)) ng_hci_le_enh_conn_compl_ep;
2132 
2133 #define NG_HCI_EVENT_BT_LOGO			0xfe
2134 
2135 #define NG_HCI_EVENT_VENDOR			0xff
2136 
2137 #endif /* ndef _NETGRAPH_HCI_H_ */
2138