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