1 /*
2  * ng_hci.h
3  */
4 
5 /*-
6  * Copyright (c) 2001 Maksim Yevmenkin <m_evmenkin@yahoo.com>
7  * All rights reserved.
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions
11  * are met:
12  * 1. Redistributions of source code must retain the above copyright
13  *    notice, this list of conditions and the following disclaimer.
14  * 2. Redistributions in binary form must reproduce the above copyright
15  *    notice, this list of conditions and the following disclaimer in the
16  *    documentation and/or other materials provided with the distribution.
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
19  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
22  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28  * SUCH DAMAGE.
29  *
30  * $Id: ng_hci.h,v 1.2 2003/03/18 00:09:37 max Exp $
31  * $FreeBSD: src/sys/netgraph/bluetooth/include/ng_hci.h,v 1.7 2006/05/17 00:13:06 emax Exp $
32  * $DragonFly: src/sys/netgraph7/bluetooth/include/ng_hci.h,v 1.2 2008/06/26 23:05:40 dillon 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_CLASS_SIZE			3   /* unit class */
80 #define NG_HCI_FEATURES_SIZE			8   /* LMP features */
81 #define NG_HCI_UNIT_NAME_SIZE			248 /* unit name size */
82 
83 /* HCI specification */
84 #define NG_HCI_SPEC_V10				0x00 /* v1.0 */
85 #define NG_HCI_SPEC_V11				0x01 /* v1.1 */
86 /* 0x02 - 0xFF - reserved for future use */
87 
88 /* LMP features */
89 /* ------------------- byte 0 --------------------*/
90 #define NG_HCI_LMP_3SLOT			0x01
91 #define NG_HCI_LMP_5SLOT			0x02
92 #define NG_HCI_LMP_ENCRYPTION			0x04
93 #define NG_HCI_LMP_SLOT_OFFSET			0x08
94 #define NG_HCI_LMP_TIMING_ACCURACY		0x10
95 #define NG_HCI_LMP_SWITCH			0x20
96 #define NG_HCI_LMP_HOLD_MODE			0x40
97 #define NG_HCI_LMP_SNIFF_MODE			0x80
98 /* ------------------- byte 1 --------------------*/
99 #define NG_HCI_LMP_PARK_MODE			0x01
100 #define NG_HCI_LMP_RSSI				0x02
101 #define NG_HCI_LMP_CHANNEL_QUALITY		0x04
102 #define NG_HCI_LMP_SCO_LINK			0x08
103 #define NG_HCI_LMP_HV2_PKT			0x10
104 #define NG_HCI_LMP_HV3_PKT			0x20
105 #define NG_HCI_LMP_ULAW_LOG			0x40
106 #define NG_HCI_LMP_ALAW_LOG			0x80
107 /* ------------------- byte 2 --------------------*/
108 #define NG_HCI_LMP_CVSD				0x01
109 #define NG_HCI_LMP_PAGING_SCHEME		0x02
110 #define NG_HCI_LMP_POWER_CONTROL		0x04
111 #define NG_HCI_LMP_TRANSPARENT_SCO		0x08
112 #define NG_HCI_LMP_FLOW_CONTROL_LAG0		0x10
113 #define NG_HCI_LMP_FLOW_CONTROL_LAG1		0x20
114 #define NG_HCI_LMP_FLOW_CONTROL_LAG2		0x40
115 
116 /* Link types */
117 #define NG_HCI_LINK_SCO				0x00 /* Voice */
118 #define NG_HCI_LINK_ACL				0x01 /* Data */
119 /* 0x02 - 0xFF - reserved for future use */
120 
121 /* Packet types */
122 				/* 0x0001 - 0x0004 - reserved for future use */
123 #define NG_HCI_PKT_DM1				0x0008 /* ACL link */
124 #define NG_HCI_PKT_DH1				0x0010 /* ACL link */
125 #define NG_HCI_PKT_HV1				0x0020 /* SCO link */
126 #define NG_HCI_PKT_HV2				0x0040 /* SCO link */
127 #define NG_HCI_PKT_HV3				0x0080 /* SCO link */
128 				/* 0x0100 - 0x0200 - reserved for future use */
129 #define NG_HCI_PKT_DM3				0x0400 /* ACL link */
130 #define NG_HCI_PKT_DH3				0x0800 /* ACL link */
131 				/* 0x1000 - 0x2000 - reserved for future use */
132 #define NG_HCI_PKT_DM5				0x4000 /* ACL link */
133 #define NG_HCI_PKT_DH5				0x8000 /* ACL link */
134 
135 /*
136  * Connection modes/Unit modes
137  *
138  * This is confusing. It means that one of the units change its mode
139  * for the specific connection. For example one connection was put on
140  * hold (but i could be wrong :)
141  */
142 
143 #define NG_HCI_UNIT_MODE_ACTIVE			0x00
144 #define NG_HCI_UNIT_MODE_HOLD			0x01
145 #define NG_HCI_UNIT_MODE_SNIFF			0x02
146 #define NG_HCI_UNIT_MODE_PARK			0x03
147 /* 0x04 - 0xFF - reserved for future use */
148 
149 /* Page scan modes */
150 #define NG_HCI_MANDATORY_PAGE_SCAN_MODE		0x00
151 #define NG_HCI_OPTIONAL_PAGE_SCAN_MODE1		0x01
152 #define NG_HCI_OPTIONAL_PAGE_SCAN_MODE2		0x02
153 #define NG_HCI_OPTIONAL_PAGE_SCAN_MODE3		0x03
154 /* 0x04 - 0xFF - reserved for future use */
155 
156 /* Page scan repetition modes */
157 #define NG_HCI_SCAN_REP_MODE0			0x00
158 #define NG_HCI_SCAN_REP_MODE1			0x01
159 #define NG_HCI_SCAN_REP_MODE2			0x02
160 /* 0x03 - 0xFF - reserved for future use */
161 
162 /* Page scan period modes */
163 #define NG_HCI_PAGE_SCAN_PERIOD_MODE0		0x00
164 #define NG_HCI_PAGE_SCAN_PERIOD_MODE1		0x01
165 #define NG_HCI_PAGE_SCAN_PERIOD_MODE2		0x02
166 /* 0x03 - 0xFF - reserved for future use */
167 
168 /* Scan enable */
169 #define NG_HCI_NO_SCAN_ENABLE			0x00
170 #define NG_HCI_INQUIRY_ENABLE_PAGE_DISABLE	0x01
171 #define NG_HCI_INQUIRY_DISABLE_PAGE_ENABLE	0x02
172 #define NG_HCI_INQUIRY_ENABLE_PAGE_ENABLE	0x03
173 /* 0x04 - 0xFF - reserved for future use */
174 
175 /* Hold mode activities */
176 #define NG_HCI_HOLD_MODE_NO_CHANGE		0x00
177 #define NG_HCI_HOLD_MODE_SUSPEND_PAGE_SCAN	0x01
178 #define NG_HCI_HOLD_MODE_SUSPEND_INQUIRY_SCAN	0x02
179 #define NG_HCI_HOLD_MODE_SUSPEND_PERIOD_INQUIRY	0x04
180 /* 0x08 - 0x80 - reserved for future use */
181 
182 /* Connection roles */
183 #define NG_HCI_ROLE_MASTER			0x00
184 #define NG_HCI_ROLE_SLAVE			0x01
185 /* 0x02 - 0xFF - reserved for future use */
186 
187 /* Key flags */
188 #define NG_HCI_USE_SEMI_PERMANENT_LINK_KEYS	0x00
189 #define NG_HCI_USE_TEMPORARY_LINK_KEY		0x01
190 /* 0x02 - 0xFF - reserved for future use */
191 
192 /* Pin types */
193 #define NG_HCI_PIN_TYPE_VARIABLE		0x00
194 #define NG_HCI_PIN_TYPE_FIXED			0x01
195 
196 /* Link key types */
197 #define NG_HCI_LINK_KEY_TYPE_COMBINATION_KEY	0x00
198 #define NG_HCI_LINK_KEY_TYPE_LOCAL_UNIT_KEY	0x01
199 #define NG_HCI_LINK_KEY_TYPE_REMOTE_UNIT_KEY	0x02
200 /* 0x03 - 0xFF - reserved for future use */
201 
202 /* Encryption modes */
203 #define NG_HCI_ENCRYPTION_MODE_NONE		0x00
204 #define NG_HCI_ENCRYPTION_MODE_P2P		0x01
205 #define NG_HCI_ENCRYPTION_MODE_ALL		0x02
206 /* 0x03 - 0xFF - reserved for future use */
207 
208 /* Quality of service types */
209 #define NG_HCI_SERVICE_TYPE_NO_TRAFFIC		0x00
210 #define NG_HCI_SERVICE_TYPE_BEST_EFFORT		0x01
211 #define NG_HCI_SERVICE_TYPE_GUARANTEED		0x02
212 /* 0x03 - 0xFF - reserved for future use */
213 
214 /* Link policy settings */
215 #define NG_HCI_LINK_POLICY_DISABLE_ALL_LM_MODES	0x0000
216 #define NG_HCI_LINK_POLICY_ENABLE_ROLE_SWITCH	0x0001 /* Master/Slave switch */
217 #define NG_HCI_LINK_POLICY_ENABLE_HOLD_MODE	0x0002
218 #define NG_HCI_LINK_POLICY_ENABLE_SNIFF_MODE	0x0004
219 #define NG_HCI_LINK_POLICY_ENABLE_PARK_MODE	0x0008
220 /* 0x0010 - 0x8000 - reserved for future use */
221 
222 /* Event masks */
223 #define NG_HCI_EVMSK_ALL			0x00000000ffffffff
224 #define NG_HCI_EVMSK_NONE			0x0000000000000000
225 #define NG_HCI_EVMSK_INQUIRY_COMPL		0x0000000000000001
226 #define NG_HCI_EVMSK_INQUIRY_RESULT		0x0000000000000002
227 #define NG_HCI_EVMSK_CON_COMPL			0x0000000000000004
228 #define NG_HCI_EVMSK_CON_REQ			0x0000000000000008
229 #define NG_HCI_EVMSK_DISCON_COMPL		0x0000000000000010
230 #define NG_HCI_EVMSK_AUTH_COMPL			0x0000000000000020
231 #define NG_HCI_EVMSK_REMOTE_NAME_REQ_COMPL	0x0000000000000040
232 #define NG_HCI_EVMSK_ENCRYPTION_CHANGE		0x0000000000000080
233 #define NG_HCI_EVMSK_CHANGE_CON_LINK_KEY_COMPL	0x0000000000000100
234 #define NG_HCI_EVMSK_MASTER_LINK_KEY_COMPL	0x0000000000000200
235 #define NG_HCI_EVMSK_READ_REMOTE_FEATURES_COMPL	0x0000000000000400
236 #define NG_HCI_EVMSK_READ_REMOTE_VER_INFO_COMPL	0x0000000000000800
237 #define NG_HCI_EVMSK_QOS_SETUP_COMPL		0x0000000000001000
238 #define NG_HCI_EVMSK_COMMAND_COMPL		0x0000000000002000
239 #define NG_HCI_EVMSK_COMMAND_STATUS		0x0000000000004000
240 #define NG_HCI_EVMSK_HARDWARE_ERROR		0x0000000000008000
241 #define NG_HCI_EVMSK_FLUSH_OCCUR		0x0000000000010000
242 #define NG_HCI_EVMSK_ROLE_CHANGE		0x0000000000020000
243 #define NG_HCI_EVMSK_NUM_COMPL_PKTS		0x0000000000040000
244 #define NG_HCI_EVMSK_MODE_CHANGE		0x0000000000080000
245 #define NG_HCI_EVMSK_RETURN_LINK_KEYS		0x0000000000100000
246 #define NG_HCI_EVMSK_PIN_CODE_REQ		0x0000000000200000
247 #define NG_HCI_EVMSK_LINK_KEY_REQ		0x0000000000400000
248 #define NG_HCI_EVMSK_LINK_KEY_NOTIFICATION	0x0000000000800000
249 #define NG_HCI_EVMSK_LOOPBACK_COMMAND		0x0000000001000000
250 #define NG_HCI_EVMSK_DATA_BUFFER_OVERFLOW	0x0000000002000000
251 #define NG_HCI_EVMSK_MAX_SLOT_CHANGE		0x0000000004000000
252 #define NG_HCI_EVMSK_READ_CLOCK_OFFSET_COMLETE	0x0000000008000000
253 #define NG_HCI_EVMSK_CON_PKT_TYPE_CHANGED	0x0000000010000000
254 #define NG_HCI_EVMSK_QOS_VIOLATION		0x0000000020000000
255 #define NG_HCI_EVMSK_PAGE_SCAN_MODE_CHANGE	0x0000000040000000
256 #define NG_HCI_EVMSK_PAGE_SCAN_REP_MODE_CHANGE	0x0000000080000000
257 /* 0x0000000100000000 - 0x8000000000000000 - reserved for future use */
258 
259 /* Filter types */
260 #define NG_HCI_FILTER_TYPE_NONE			0x00
261 #define NG_HCI_FILTER_TYPE_INQUIRY_RESULT	0x01
262 #define NG_HCI_FILTER_TYPE_CON_SETUP		0x02
263 /* 0x03 - 0xFF - reserved for future use */
264 
265 /* Filter condition types for NG_HCI_FILTER_TYPE_INQUIRY_RESULT */
266 #define NG_HCI_FILTER_COND_INQUIRY_NEW_UNIT	0x00
267 #define NG_HCI_FILTER_COND_INQUIRY_UNIT_CLASS	0x01
268 #define NG_HCI_FILTER_COND_INQUIRY_BDADDR	0x02
269 /* 0x03 - 0xFF - reserved for future use */
270 
271 /* Filter condition types for NG_HCI_FILTER_TYPE_CON_SETUP */
272 #define NG_HCI_FILTER_COND_CON_ANY_UNIT		0x00
273 #define NG_HCI_FILTER_COND_CON_UNIT_CLASS	0x01
274 #define NG_HCI_FILTER_COND_CON_BDADDR		0x02
275 /* 0x03 - 0xFF - reserved for future use */
276 
277 /* Xmit level types */
278 #define NG_HCI_XMIT_LEVEL_CURRENT		0x00
279 #define NG_HCI_XMIT_LEVEL_MAXIMUM		0x01
280 /* 0x02 - 0xFF - reserved for future use */
281 
282 /* Host to Host Controller flow control */
283 #define NG_HCI_H2HC_FLOW_CONTROL_NONE		0x00
284 #define NG_HCI_H2HC_FLOW_CONTROL_ACL		0x01
285 #define NG_HCI_H2HC_FLOW_CONTROL_SCO		0x02
286 #define NG_HCI_H2HC_FLOW_CONTROL_BOTH		0x03	/* ACL and SCO */
287 /* 0x04 - 0xFF - reserved future use */
288 
289 /* Country codes */
290 #define NG_HCI_COUNTRY_CODE_NAM_EUR_JP		0x00
291 #define NG_HCI_COUNTRY_CODE_FRANCE		0x01
292 /* 0x02 - 0xFF - reserved future use */
293 
294 /* Loopback modes */
295 #define NG_HCI_LOOPBACK_NONE			0x00
296 #define NG_HCI_LOOPBACK_LOCAL			0x01
297 #define NG_HCI_LOOPBACK_REMOTE			0x02
298 /* 0x03 - 0xFF - reserved future use */
299 
300 /**************************************************************************
301  **************************************************************************
302  **                 Link level defines, headers and types
303  **************************************************************************
304  **************************************************************************/
305 
306 /*
307  * Macro(s) to combine OpCode and extract OGF (OpCode Group Field)
308  * and OCF (OpCode Command Field) from OpCode.
309  */
310 
311 #define NG_HCI_OPCODE(gf,cf)		((((gf) & 0x3f) << 10) | ((cf) & 0x3ff))
312 #define NG_HCI_OCF(op)			((op) & 0x3ff)
313 #define NG_HCI_OGF(op)			(((op) >> 10) & 0x3f)
314 
315 /*
316  * Marco(s) to extract/combine connection handle, BC (Broadcast) and
317  * PB (Packet boundary) flags.
318  */
319 
320 #define NG_HCI_CON_HANDLE(h)		((h) & 0x0fff)
321 #define NG_HCI_PB_FLAG(h)		(((h) & 0x3000) >> 12)
322 #define NG_HCI_BC_FLAG(h)		(((h) & 0xc000) >> 14)
323 #define NG_HCI_MK_CON_HANDLE(h, pb, bc) \
324 	(((h) & 0x0fff) | (((pb) & 3) << 12) | (((bc) & 3) << 14))
325 
326 /* PB flag values */
327 					/* 00 - reserved for future use */
328 #define	NG_HCI_PACKET_FRAGMENT		0x1
329 #define	NG_HCI_PACKET_START		0x2
330 					/* 11 - reserved for future use */
331 
332 /* BC flag values */
333 #define NG_HCI_POINT2POINT		0x0 /* only Host controller to Host */
334 #define NG_HCI_BROADCAST_ACTIVE		0x1 /* both directions */
335 #define NG_HCI_BROADCAST_PICONET	0x2 /* both directions */
336 					/* 11 - reserved for future use */
337 
338 /* HCI command packet header */
339 #define NG_HCI_CMD_PKT			0x01
340 #define NG_HCI_CMD_PKT_SIZE		0xff /* without header */
341 typedef struct {
342 	u_int8_t	type;   /* MUST be 0x1 */
343 	u_int16_t	opcode; /* OpCode */
344 	u_int8_t	length; /* parameter(s) length in bytes */
345 } __attribute__ ((packed)) ng_hci_cmd_pkt_t;
346 
347 /* ACL data packet header */
348 #define NG_HCI_ACL_DATA_PKT		0x02
349 #define NG_HCI_ACL_PKT_SIZE		0xffff /* without header */
350 typedef struct {
351 	u_int8_t	type;        /* MUST be 0x2 */
352 	u_int16_t	con_handle;  /* connection handle + PB + BC flags */
353 	u_int16_t	length;      /* payload length in bytes */
354 } __attribute__ ((packed)) ng_hci_acldata_pkt_t;
355 
356 /* SCO data packet header */
357 #define NG_HCI_SCO_DATA_PKT		0x03
358 #define NG_HCI_SCO_PKT_SIZE		0xff /* without header */
359 typedef struct {
360 	u_int8_t	type;       /* MUST be 0x3 */
361 	u_int16_t	con_handle; /* connection handle + reserved bits */
362 	u_int8_t	length;     /* payload length in bytes */
363 } __attribute__ ((packed)) ng_hci_scodata_pkt_t;
364 
365 /* HCI event packet header */
366 #define NG_HCI_EVENT_PKT		0x04
367 #define NG_HCI_EVENT_PKT_SIZE		0xff /* without header */
368 typedef struct {
369 	u_int8_t	type;   /* MUST be 0x4 */
370 	u_int8_t	event;  /* event */
371 	u_int8_t	length; /* parameter(s) length in bytes */
372 } __attribute__ ((packed)) ng_hci_event_pkt_t;
373 
374 /* Bluetooth unit address */
375 typedef struct {
376 	u_int8_t	b[NG_HCI_BDADDR_SIZE];
377 } __attribute__ ((packed)) bdaddr_t;
378 typedef bdaddr_t *	bdaddr_p;
379 
380 /* Any BD_ADDR. Note: This is actually 7 bytes (count '\0' terminator) */
381 #define NG_HCI_BDADDR_ANY	((bdaddr_p) "\000\000\000\000\000\000")
382 
383 /* HCI status return parameter */
384 typedef struct {
385 	u_int8_t	status; /* 0x00 - success */
386 } __attribute__ ((packed)) ng_hci_status_rp;
387 
388 /**************************************************************************
389  **************************************************************************
390  **        Upper layer protocol interface. LP_xxx event parameters
391  **************************************************************************
392  **************************************************************************/
393 
394 /* Connection Request Event */
395 #define NGM_HCI_LP_CON_REQ			1  /* Upper -> HCI */
396 typedef struct {
397 	u_int16_t	link_type; /* type of connection */
398 	bdaddr_t	bdaddr;    /* remote unit address */
399 } ng_hci_lp_con_req_ep;
400 
401 /*
402  * XXX XXX XXX
403  *
404  * NOTE: This request is not defined by Bluetooth specification,
405  * but i find it useful :)
406  */
407 #define NGM_HCI_LP_DISCON_REQ			2 /* Upper -> HCI */
408 typedef struct {
409 	u_int16_t	con_handle; /* connection handle */
410 	u_int16_t	reason;	    /* reason to disconnect (only low byte) */
411 } ng_hci_lp_discon_req_ep;
412 
413 /* Connection Confirmation Event */
414 #define NGM_HCI_LP_CON_CFM			3  /* HCI -> Upper */
415 typedef struct {
416 	u_int8_t	status;     /* 0x00 - success */
417 	u_int8_t	link_type;  /* link type */
418 	u_int16_t	con_handle; /* con_handle */
419 	bdaddr_t	bdaddr;     /* remote unit address */
420 } ng_hci_lp_con_cfm_ep;
421 
422 /* Connection Indication Event */
423 #define NGM_HCI_LP_CON_IND			4  /* HCI -> Upper */
424 typedef struct {
425 	u_int8_t	link_type;                 /* link type */
426 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* unit class */
427 	bdaddr_t	bdaddr;                    /* remote unit address */
428 } ng_hci_lp_con_ind_ep;
429 
430 /* Connection Response Event */
431 #define NGM_HCI_LP_CON_RSP			5  /* Upper -> HCI */
432 typedef struct {
433 	u_int8_t	status;    /* 0x00 - accept connection */
434 	u_int8_t	link_type; /* link type */
435 	bdaddr_t	bdaddr;    /* remote unit address */
436 } ng_hci_lp_con_rsp_ep;
437 
438 /* Disconnection Indication Event */
439 #define NGM_HCI_LP_DISCON_IND			6  /* HCI -> Upper */
440 typedef struct {
441 	u_int8_t	reason;     /* reason to disconnect (only low byte) */
442 	u_int8_t	link_type;  /* link type */
443 	u_int16_t	con_handle; /* connection handle */
444 } ng_hci_lp_discon_ind_ep;
445 
446 /* QoS Setup Request Event */
447 #define NGM_HCI_LP_QOS_REQ			7  /* Upper -> HCI */
448 typedef struct {
449 	u_int16_t	con_handle;      /* connection handle */
450 	u_int8_t	flags;           /* reserved */
451 	u_int8_t	service_type;    /* service type */
452 	u_int32_t	token_rate;      /* bytes/sec */
453 	u_int32_t	peak_bandwidth;  /* bytes/sec */
454 	u_int32_t	latency;         /* msec */
455 	u_int32_t	delay_variation; /* msec */
456 } ng_hci_lp_qos_req_ep;
457 
458 /* QoS Conformition Event */
459 #define NGM_HCI_LP_QOS_CFM			8  /* HCI -> Upper */
460 typedef struct {
461 	u_int16_t	status;          /* 0x00 - success  (only low byte) */
462 	u_int16_t	con_handle;      /* connection handle */
463 } ng_hci_lp_qos_cfm_ep;
464 
465 /* QoS Violation Indication Event */
466 #define NGM_HCI_LP_QOS_IND			9  /* HCI -> Upper */
467 typedef struct {
468 	u_int16_t	con_handle; /* connection handle */
469 } ng_hci_lp_qos_ind_ep;
470 
471 /**************************************************************************
472  **************************************************************************
473  **                    HCI node command/event parameters
474  **************************************************************************
475  **************************************************************************/
476 
477 /* Debug levels */
478 #define NG_HCI_ALERT_LEVEL		1
479 #define NG_HCI_ERR_LEVEL		2
480 #define NG_HCI_WARN_LEVEL		3
481 #define NG_HCI_INFO_LEVEL		4
482 
483 /* Unit states */
484 #define NG_HCI_UNIT_CONNECTED		(1 << 0)
485 #define NG_HCI_UNIT_INITED		(1 << 1)
486 #define NG_HCI_UNIT_READY	(NG_HCI_UNIT_CONNECTED|NG_HCI_UNIT_INITED)
487 #define NG_HCI_UNIT_COMMAND_PENDING	(1 << 2)
488 
489 /* Connection state */
490 #define NG_HCI_CON_CLOSED		0 /* connection closed */
491 #define NG_HCI_CON_W4_LP_CON_RSP	1 /* wait for LP_ConnectRsp */
492 #define NG_HCI_CON_W4_CONN_COMPLETE	2 /* wait for Connection_Complete evt */
493 #define NG_HCI_CON_OPEN			3 /* connection open */
494 
495 /* Get HCI node (unit) state (see states above) */
496 #define NGM_HCI_NODE_GET_STATE			100  /* HCI -> User */
497 typedef u_int16_t	ng_hci_node_state_ep;
498 
499 /* Turn on "inited" bit */
500 #define NGM_HCI_NODE_INIT			101 /* User -> HCI */
501 /* No parameters */
502 
503 /* Get/Set node debug level (see debug levels above) */
504 #define NGM_HCI_NODE_GET_DEBUG			102 /* HCI -> User */
505 #define NGM_HCI_NODE_SET_DEBUG			103 /* User -> HCI */
506 typedef u_int16_t	ng_hci_node_debug_ep;
507 
508 /* Get node buffer info */
509 #define NGM_HCI_NODE_GET_BUFFER			104 /* HCI -> User */
510 typedef struct {
511 	u_int8_t	cmd_free; /* number of free command packets */
512 	u_int8_t	sco_size; /* max. size of SCO packet */
513 	u_int16_t	sco_pkts; /* number of SCO packets */
514 	u_int16_t	sco_free; /* number of free SCO packets */
515 	u_int16_t	acl_size; /* max. size of ACL packet */
516 	u_int16_t	acl_pkts; /* number of ACL packets */
517 	u_int16_t	acl_free; /* number of free ACL packets */
518 } ng_hci_node_buffer_ep;
519 
520 /* Get BDADDR */
521 #define NGM_HCI_NODE_GET_BDADDR			105 /* HCI -> User */
522 /* bdaddr_t -- BDADDR */
523 
524 /* Get features */
525 #define NGM_HCI_NODE_GET_FEATURES		106 /* HCI -> User */
526 /* features[NG_HCI_FEATURES_SIZE] -- features */
527 
528 #define NGM_HCI_NODE_GET_STAT			107 /* HCI -> User */
529 typedef struct {
530 	u_int32_t	cmd_sent;   /* number of HCI commands sent */
531 	u_int32_t	evnt_recv;  /* number of HCI events received */
532 	u_int32_t	acl_recv;   /* number of ACL packets received */
533 	u_int32_t	acl_sent;   /* number of ACL packets sent */
534 	u_int32_t	sco_recv;   /* number of SCO packets received */
535 	u_int32_t	sco_sent;   /* number of SCO packets sent */
536 	u_int32_t	bytes_recv; /* total number of bytes received */
537 	u_int32_t	bytes_sent; /* total number of bytes sent */
538 } ng_hci_node_stat_ep;
539 
540 #define NGM_HCI_NODE_RESET_STAT			108 /* User -> HCI */
541 /* No parameters */
542 
543 #define NGM_HCI_NODE_FLUSH_NEIGHBOR_CACHE	109 /* User -> HCI */
544 
545 #define NGM_HCI_NODE_GET_NEIGHBOR_CACHE		110 /* HCI -> User */
546 typedef struct {
547 	u_int32_t	num_entries;	/* number of entries */
548 } ng_hci_node_get_neighbor_cache_ep;
549 
550 typedef struct {
551 	u_int16_t	page_scan_rep_mode;             /* page rep scan mode */
552 	u_int16_t	page_scan_mode;                 /* page scan mode */
553 	u_int16_t	clock_offset;                   /* clock offset */
554 	bdaddr_t	bdaddr;                         /* bdaddr */
555 	u_int8_t	features[NG_HCI_FEATURES_SIZE]; /* features */
556 } ng_hci_node_neighbor_cache_entry_ep;
557 
558 #define NG_HCI_MAX_NEIGHBOR_NUM \
559 	((0xffff - sizeof(ng_hci_node_get_neighbor_cache_ep))/sizeof(ng_hci_node_neighbor_cache_entry_ep))
560 
561 #define NGM_HCI_NODE_GET_CON_LIST		111 /* HCI -> User */
562 typedef struct {
563 	u_int32_t	num_connections; /* number of connections */
564 } ng_hci_node_con_list_ep;
565 
566 typedef struct {
567 	u_int8_t	link_type;       /* ACL or SCO */
568 	u_int8_t	encryption_mode; /* none, p2p, ... */
569 	u_int8_t	mode;            /* ACTIVE, HOLD ... */
570 	u_int8_t	role;            /* MASTER/SLAVE */
571 	u_int16_t	state;           /* connection state */
572 	u_int16_t	reserved;        /* place holder */
573 	u_int16_t	pending;         /* number of pending packets */
574 	u_int16_t	queue_len;       /* number of packets in queue */
575 	u_int16_t	con_handle;      /* connection handle */
576 	bdaddr_t	bdaddr;          /* remote bdaddr */
577 } ng_hci_node_con_ep;
578 
579 #define NG_HCI_MAX_CON_NUM \
580 	((0xffff - sizeof(ng_hci_node_con_list_ep))/sizeof(ng_hci_node_con_ep))
581 
582 #define NGM_HCI_NODE_UP				112 /* HCI -> Upper */
583 typedef struct {
584 	u_int16_t	pkt_size; /* max. ACL/SCO packet size (w/out header) */
585 	u_int16_t	num_pkts; /* ACL/SCO packet queue size */
586 	u_int16_t	reserved; /* place holder */
587 	bdaddr_t	bdaddr;	  /* bdaddr */
588 } ng_hci_node_up_ep;
589 
590 #define NGM_HCI_SYNC_CON_QUEUE			113 /* HCI -> Upper */
591 typedef struct {
592 	u_int16_t	con_handle; /* connection handle */
593 	u_int16_t	completed;  /* number of completed packets */
594 } ng_hci_sync_con_queue_ep;
595 
596 #define NGM_HCI_NODE_GET_LINK_POLICY_SETTINGS_MASK	114 /* HCI -> User */
597 #define NGM_HCI_NODE_SET_LINK_POLICY_SETTINGS_MASK	115 /* User -> HCI */
598 typedef u_int16_t	ng_hci_node_link_policy_mask_ep;
599 
600 #define NGM_HCI_NODE_GET_PACKET_MASK		116 /* HCI -> User */
601 #define NGM_HCI_NODE_SET_PACKET_MASK		117 /* User -> HCI */
602 typedef u_int16_t	ng_hci_node_packet_mask_ep;
603 
604 #define NGM_HCI_NODE_GET_ROLE_SWITCH		118 /* HCI -> User */
605 #define NGM_HCI_NODE_SET_ROLE_SWITCH		119 /* User -> HCI */
606 typedef u_int16_t	ng_hci_node_role_switch_ep;
607 
608 #define	NGM_HCI_NODE_LIST_NAMES			200 /* HCI -> User */
609 
610 /**************************************************************************
611  **************************************************************************
612  **             Link control commands and return parameters
613  **************************************************************************
614  **************************************************************************/
615 
616 #define NG_HCI_OGF_LINK_CONTROL			0x01 /* OpCode Group Field */
617 
618 #define NG_HCI_OCF_INQUIRY			0x0001
619 typedef struct {
620 	u_int8_t	lap[NG_HCI_LAP_SIZE]; /* LAP */
621 	u_int8_t	inquiry_length; /* (N x 1.28) sec */
622 	u_int8_t	num_responses;  /* Max. # of responses before halted */
623 } __attribute__ ((packed)) ng_hci_inquiry_cp;
624 /* No return parameter(s) */
625 
626 #define NG_HCI_OCF_INQUIRY_CANCEL		0x0002
627 /* No command parameter(s) */
628 typedef ng_hci_status_rp	ng_hci_inquiry_cancel_rp;
629 
630 #define NG_HCI_OCF_PERIODIC_INQUIRY		0x0003
631 typedef struct {
632 	u_int16_t	max_period_length; /* Max. and min. amount of time */
633 	u_int16_t	min_period_length; /* between consecutive inquiries */
634 	u_int8_t	lap[NG_HCI_LAP_SIZE]; /* LAP */
635 	u_int8_t	inquiry_length;    /* (inquiry_length * 1.28) sec */
636 	u_int8_t	num_responses;     /* Max. # of responses */
637 } __attribute__ ((packed)) ng_hci_periodic_inquiry_cp;
638 
639 typedef ng_hci_status_rp	ng_hci_periodic_inquiry_rp;
640 
641 #define NG_HCI_OCF_EXIT_PERIODIC_INQUIRY	0x0004
642 /* No command parameter(s) */
643 typedef ng_hci_status_rp	ng_hci_exit_periodic_inquiry_rp;
644 
645 #define NG_HCI_OCF_CREATE_CON			0x0005
646 typedef struct {
647 	bdaddr_t	bdaddr;             /* destination address */
648 	u_int16_t	pkt_type;           /* packet type */
649 	u_int8_t	page_scan_rep_mode; /* page scan repetition mode */
650 	u_int8_t	page_scan_mode;     /* page scan mode */
651 	u_int16_t	clock_offset;       /* clock offset */
652 	u_int8_t	accept_role_switch; /* accept role switch? 0x00 - no */
653 } __attribute__ ((packed)) ng_hci_create_con_cp;
654 /* No return parameter(s) */
655 
656 #define NG_HCI_OCF_DISCON			0x0006
657 typedef struct {
658 	u_int16_t	con_handle; /* connection handle */
659 	u_int8_t	reason;     /* reason to disconnect */
660 } __attribute__ ((packed)) ng_hci_discon_cp;
661 /* No return parameter(s) */
662 
663 #define NG_HCI_OCF_ADD_SCO_CON			0x0007
664 typedef struct {
665 	u_int16_t	con_handle; /* connection handle */
666 	u_int16_t	pkt_type;   /* packet type */
667 } __attribute__ ((packed)) ng_hci_add_sco_con_cp;
668 /* No return parameter(s) */
669 
670 #define NG_HCI_OCF_ACCEPT_CON			0x0009
671 typedef struct {
672 	bdaddr_t	bdaddr; /* address of unit to be connected */
673 	u_int8_t	role;   /* connection role */
674 } __attribute__ ((packed)) ng_hci_accept_con_cp;
675 /* No return parameter(s) */
676 
677 #define NG_HCI_OCF_REJECT_CON			0x000a
678 typedef struct {
679 	bdaddr_t	bdaddr; /* remote address */
680 	u_int8_t	reason; /* reason to reject */
681 } __attribute__ ((packed)) ng_hci_reject_con_cp;
682 /* No return parameter(s) */
683 
684 #define NG_HCI_OCF_LINK_KEY_REP			0x000b
685 typedef struct {
686 	bdaddr_t	bdaddr;               /* remote address */
687 	u_int8_t	key[NG_HCI_KEY_SIZE]; /* key */
688 } __attribute__ ((packed)) ng_hci_link_key_rep_cp;
689 
690 typedef struct {
691 	u_int8_t	status; /* 0x00 - success */
692 	bdaddr_t	bdaddr; /* unit address */
693 } __attribute__ ((packed)) ng_hci_link_key_rep_rp;
694 
695 #define NG_HCI_OCF_LINK_KEY_NEG_REP		0x000c
696 typedef struct {
697 	bdaddr_t	bdaddr; /* remote address */
698 } __attribute__ ((packed)) ng_hci_link_key_neg_rep_cp;
699 
700 typedef struct {
701 	u_int8_t	status; /* 0x00 - success */
702 	bdaddr_t	bdaddr; /* unit address */
703 } __attribute__ ((packed)) ng_hci_link_key_neg_rep_rp;
704 
705 #define NG_HCI_OCF_PIN_CODE_REP			0x000d
706 typedef struct {
707 	bdaddr_t	bdaddr;               /* remote address */
708 	u_int8_t	pin_size;             /* pin code length (in bytes) */
709 	u_int8_t	pin[NG_HCI_PIN_SIZE]; /* pin code */
710 } __attribute__ ((packed)) ng_hci_pin_code_rep_cp;
711 
712 typedef struct {
713 	u_int8_t	status; /* 0x00 - success */
714 	bdaddr_t	bdaddr; /* unit address */
715 } __attribute__ ((packed)) ng_hci_pin_code_rep_rp;
716 
717 #define NG_HCI_OCF_PIN_CODE_NEG_REP		0x000e
718 typedef struct {
719 	bdaddr_t	bdaddr;  /* remote address */
720 } __attribute__ ((packed)) ng_hci_pin_code_neg_rep_cp;
721 
722 typedef struct {
723 	u_int8_t	status; /* 0x00 - success */
724 	bdaddr_t	bdaddr; /* unit address */
725 } __attribute__ ((packed)) ng_hci_pin_code_neg_rep_rp;
726 
727 #define NG_HCI_OCF_CHANGE_CON_PKT_TYPE		0x000f
728 typedef struct {
729 	u_int16_t	con_handle; /* connection handle */
730 	u_int16_t	pkt_type;   /* packet type */
731 } __attribute__ ((packed)) ng_hci_change_con_pkt_type_cp;
732 /* No return parameter(s) */
733 
734 #define NG_HCI_OCF_AUTH_REQ			0x0011
735 typedef struct {
736 	u_int16_t	con_handle; /* connection handle */
737 } __attribute__ ((packed)) ng_hci_auth_req_cp;
738 /* No return parameter(s) */
739 
740 #define NG_HCI_OCF_SET_CON_ENCRYPTION		0x0013
741 typedef struct {
742 	u_int16_t	con_handle;        /* connection handle */
743 	u_int8_t	encryption_enable; /* 0x00 - disable, 0x01 - enable */
744 } __attribute__ ((packed)) ng_hci_set_con_encryption_cp;
745 /* No return parameter(s) */
746 
747 #define NG_HCI_OCF_CHANGE_CON_LINK_KEY		0x0015
748 typedef struct {
749 	u_int16_t	con_handle; /* connection handle */
750 } __attribute__ ((packed)) ng_hci_change_con_link_key_cp;
751 /* No return parameter(s) */
752 
753 #define NG_HCI_OCF_MASTER_LINK_KEY		0x0017
754 typedef struct {
755 	u_int8_t	key_flag; /* key flag */
756 } __attribute__ ((packed)) ng_hci_master_link_key_cp;
757 /* No return parameter(s) */
758 
759 #define NG_HCI_OCF_REMOTE_NAME_REQ		0x0019
760 typedef struct {
761 	bdaddr_t	bdaddr;             /* remote address */
762 	u_int8_t	page_scan_rep_mode; /* page scan repetition mode */
763 	u_int8_t	page_scan_mode;     /* page scan mode */
764 	u_int16_t	clock_offset;       /* clock offset */
765 } __attribute__ ((packed)) ng_hci_remote_name_req_cp;
766 /* No return parameter(s) */
767 
768 #define NG_HCI_OCF_READ_REMOTE_FEATURES		0x001b
769 typedef struct {
770 	u_int16_t	con_handle; /* connection handle */
771 } __attribute__ ((packed)) ng_hci_read_remote_features_cp;
772 /* No return parameter(s) */
773 
774 #define NG_HCI_OCF_READ_REMOTE_VER_INFO		0x001d
775 typedef struct {
776 	u_int16_t	con_handle; /* connection handle */
777 } __attribute__ ((packed)) ng_hci_read_remote_ver_info_cp;
778 /* No return parameter(s) */
779 
780 #define NG_HCI_OCF_READ_CLOCK_OFFSET		 0x001f
781 typedef struct {
782 	u_int16_t	con_handle; /* connection handle */
783 } __attribute__ ((packed)) ng_hci_read_clock_offset_cp;
784 /* No return parameter(s) */
785 
786 /**************************************************************************
787  **************************************************************************
788  **        Link policy commands and return parameters
789  **************************************************************************
790  **************************************************************************/
791 
792 #define NG_HCI_OGF_LINK_POLICY			0x02 /* OpCode Group Field */
793 
794 #define NG_HCI_OCF_HOLD_MODE			0x0001
795 typedef struct {
796 	u_int16_t	con_handle;   /* connection handle */
797 	u_int16_t	max_interval; /* (max_interval * 0.625) msec */
798 	u_int16_t	min_interval; /* (max_interval * 0.625) msec */
799 } __attribute__ ((packed)) ng_hci_hold_mode_cp;
800 /* No return parameter(s) */
801 
802 #define NG_HCI_OCF_SNIFF_MODE			0x0003
803 typedef struct {
804 	u_int16_t	con_handle;   /* connection handle */
805 	u_int16_t	max_interval; /* (max_interval * 0.625) msec */
806 	u_int16_t	min_interval; /* (max_interval * 0.625) msec */
807 	u_int16_t	attempt;      /* (2 * attempt - 1) * 0.625 msec */
808 	u_int16_t	timeout;      /* (2 * attempt - 1) * 0.625 msec */
809 } __attribute__ ((packed)) ng_hci_sniff_mode_cp;
810 /* No return parameter(s) */
811 
812 #define NG_HCI_OCF_EXIT_SNIFF_MODE		0x0004
813 typedef struct {
814 	u_int16_t	con_handle; /* connection handle */
815 } __attribute__ ((packed)) ng_hci_exit_sniff_mode_cp;
816 /* No return parameter(s) */
817 
818 #define NG_HCI_OCF_PARK_MODE			0x0005
819 typedef struct {
820 	u_int16_t	con_handle;   /* connection handle */
821 	u_int16_t	max_interval; /* (max_interval * 0.625) msec */
822 	u_int16_t	min_interval; /* (max_interval * 0.625) msec */
823 } __attribute__ ((packed)) ng_hci_park_mode_cp;
824 /* No return parameter(s) */
825 
826 #define NG_HCI_OCF_EXIT_PARK_MODE		0x0006
827 typedef struct {
828 	u_int16_t	con_handle; /* connection handle */
829 } __attribute__ ((packed)) ng_hci_exit_park_mode_cp;
830 /* No return parameter(s) */
831 
832 #define NG_HCI_OCF_QOS_SETUP			0x0007
833 typedef struct {
834 	u_int16_t	con_handle;      /* connection handle */
835 	u_int8_t	flags;           /* reserved for future use */
836 	u_int8_t	service_type;    /* service type */
837 	u_int32_t	token_rate;      /* bytes per second */
838 	u_int32_t	peak_bandwidth;  /* bytes per second */
839 	u_int32_t	latency;         /* microseconds */
840 	u_int32_t	delay_variation; /* microseconds */
841 } __attribute__ ((packed)) ng_hci_qos_setup_cp;
842 /* No return parameter(s) */
843 
844 #define NG_HCI_OCF_ROLE_DISCOVERY		0x0009
845 typedef struct {
846 	u_int16_t	con_handle; /* connection handle */
847 } __attribute__ ((packed)) ng_hci_role_discovery_cp;
848 
849 typedef struct {
850 	u_int8_t	status;     /* 0x00 - success */
851 	u_int16_t	con_handle; /* connection handle */
852 	u_int8_t	role;       /* role for the connection handle */
853 } __attribute__ ((packed)) ng_hci_role_discovery_rp;
854 
855 #define NG_HCI_OCF_SWITCH_ROLE			0x000b
856 typedef struct {
857 	bdaddr_t	bdaddr; /* remote address */
858 	u_int8_t	role;   /* new local role */
859 } __attribute__ ((packed)) ng_hci_switch_role_cp;
860 /* No return parameter(s) */
861 
862 #define NG_HCI_OCF_READ_LINK_POLICY_SETTINGS	0x000c
863 typedef struct {
864 	u_int16_t	con_handle; /* connection handle */
865 } __attribute__ ((packed)) ng_hci_read_link_policy_settings_cp;
866 
867 typedef struct {
868 	u_int8_t	status;     /* 0x00 - success */
869 	u_int16_t	con_handle; /* connection handle */
870 	u_int16_t	settings;   /* link policy settings */
871 } __attribute__ ((packed)) ng_hci_read_link_policy_settings_rp;
872 
873 #define NG_HCI_OCF_WRITE_LINK_POLICY_SETTINGS	0x000d
874 typedef struct {
875 	u_int16_t	con_handle; /* connection handle */
876 	u_int16_t	settings;   /* link policy settings */
877 } __attribute__ ((packed)) ng_hci_write_link_policy_settings_cp;
878 
879 typedef struct {
880 	u_int8_t	status;     /* 0x00 - success */
881 	u_int16_t	con_handle; /* connection handle */
882 } __attribute__ ((packed)) ng_hci_write_link_policy_settings_rp;
883 
884 /**************************************************************************
885  **************************************************************************
886  **   Host controller and baseband commands and return parameters
887  **************************************************************************
888  **************************************************************************/
889 
890 #define NG_HCI_OGF_HC_BASEBAND			0x03 /* OpCode Group Field */
891 
892 #define NG_HCI_OCF_SET_EVENT_MASK		0x0001
893 typedef struct {
894 	u_int8_t	event_mask[NG_HCI_EVENT_MASK_SIZE]; /* event_mask */
895 } __attribute__ ((packed)) ng_hci_set_event_mask_cp;
896 
897 typedef ng_hci_status_rp	ng_hci_set_event_mask_rp;
898 
899 #define NG_HCI_OCF_RESET			0x0003
900 /* No command parameter(s) */
901 typedef ng_hci_status_rp	ng_hci_reset_rp;
902 
903 #define NG_HCI_OCF_SET_EVENT_FILTER		0x0005
904 typedef struct {
905 	u_int8_t	filter_type;           /* filter type */
906 	u_int8_t	filter_condition_type; /* filter condition type */
907 	u_int8_t	condition[0];          /* conditions - variable size */
908 } __attribute__ ((packed)) ng_hci_set_event_filter_cp;
909 
910 typedef ng_hci_status_rp	ng_hci_set_event_filter_rp;
911 
912 #define NG_HCI_OCF_FLUSH			0x0008
913 typedef struct {
914 	u_int16_t	con_handle; /* connection handle */
915 } __attribute__ ((packed)) ng_hci_flush_cp;
916 
917 typedef struct {
918 	u_int8_t	status;     /* 0x00 - success */
919 	u_int16_t	con_handle; /* connection handle */
920 } __attribute__ ((packed)) ng_hci_flush_rp;
921 
922 #define NG_HCI_OCF_READ_PIN_TYPE		0x0009
923 /* No command parameter(s) */
924 typedef struct {
925 	u_int8_t	status;   /* 0x00 - success */
926 	u_int8_t	pin_type; /* PIN type */
927 } __attribute__ ((packed)) ng_hci_read_pin_type_rp;
928 
929 #define NG_HCI_OCF_WRITE_PIN_TYPE		0x000a
930 typedef struct {
931 	u_int8_t	pin_type; /* PIN type */
932 } __attribute__ ((packed)) ng_hci_write_pin_type_cp;
933 
934 typedef ng_hci_status_rp	ng_hci_write_pin_type_rp;
935 
936 #define NG_HCI_OCF_CREATE_NEW_UNIT_KEY		0x000b
937 /* No command parameter(s) */
938 typedef ng_hci_status_rp	ng_hci_create_new_unit_key_rp;
939 
940 #define NG_HCI_OCF_READ_STORED_LINK_KEY		0x000d
941 typedef struct {
942 	bdaddr_t	bdaddr;   /* address */
943 	u_int8_t	read_all; /* read all keys? 0x01 - yes */
944 } __attribute__ ((packed)) ng_hci_read_stored_link_key_cp;
945 
946 typedef struct {
947 	u_int8_t	status;        /* 0x00 - success */
948 	u_int16_t	max_num_keys;  /* Max. number of keys */
949 	u_int16_t	num_keys_read; /* Number of stored keys */
950 } __attribute__ ((packed)) ng_hci_read_stored_link_key_rp;
951 
952 #define NG_HCI_OCF_WRITE_STORED_LINK_KEY	0x0011
953 typedef struct {
954 	u_int8_t	num_keys_write; /* # of keys to write */
955 /* these are repeated "num_keys_write" times
956 	bdaddr_t	bdaddr;                --- remote address(es)
957 	u_int8_t	key[NG_HCI_KEY_SIZE];  --- key(s) */
958 } __attribute__ ((packed)) ng_hci_write_stored_link_key_cp;
959 
960 typedef struct {
961 	u_int8_t	status;           /* 0x00 - success */
962 	u_int8_t	num_keys_written; /* # of keys successfully written */
963 } __attribute__ ((packed)) ng_hci_write_stored_link_key_rp;
964 
965 #define NG_HCI_OCF_DELETE_STORED_LINK_KEY	0x0012
966 typedef struct {
967 	bdaddr_t	bdaddr;     /* address */
968 	u_int8_t	delete_all; /* delete all keys? 0x01 - yes */
969 } __attribute__ ((packed)) ng_hci_delete_stored_link_key_cp;
970 
971 typedef struct {
972 	u_int8_t	status;           /* 0x00 - success */
973 	u_int16_t	num_keys_deleted; /* Number of keys deleted */
974 } __attribute__ ((packed)) ng_hci_delete_stored_link_key_rp;
975 
976 #define NG_HCI_OCF_CHANGE_LOCAL_NAME		0x0013
977 typedef struct {
978 	char		name[NG_HCI_UNIT_NAME_SIZE]; /* new unit name */
979 } __attribute__ ((packed)) ng_hci_change_local_name_cp;
980 
981 typedef ng_hci_status_rp	ng_hci_change_local_name_rp;
982 
983 #define NG_HCI_OCF_READ_LOCAL_NAME		0x0014
984 /* No command parameter(s) */
985 typedef struct {
986 	u_int8_t	status;  /* 0x00 - success */
987 	char		name[NG_HCI_UNIT_NAME_SIZE]; /* unit name */
988 } __attribute__ ((packed)) ng_hci_read_local_name_rp;
989 
990 #define NG_HCI_OCF_READ_CON_ACCEPT_TIMO		0x0015
991 /* No command parameter(s) */
992 typedef struct {
993 	u_int8_t	status;  /* 0x00 - success */
994 	u_int16_t	timeout; /* (timeout * 0.625) msec */
995 } __attribute__ ((packed)) ng_hci_read_con_accept_timo_rp;
996 
997 #define NG_HCI_OCF_WRITE_CON_ACCEPT_TIMO	0x0016
998 typedef struct {
999 	u_int16_t	timeout; /* (timeout * 0.625) msec */
1000 } __attribute__ ((packed)) ng_hci_write_con_accept_timo_cp;
1001 
1002 typedef ng_hci_status_rp	ng_hci_write_con_accept_timo_rp;
1003 
1004 #define NG_HCI_OCF_READ_PAGE_TIMO		0x0017
1005 /* No command parameter(s) */
1006 typedef struct {
1007 	u_int8_t	status;  /* 0x00 - success */
1008 	u_int16_t	timeout; /* (timeout * 0.625) msec */
1009 } __attribute__ ((packed)) ng_hci_read_page_timo_rp;
1010 
1011 #define NG_HCI_OCF_WRITE_PAGE_TIMO		0x0018
1012 typedef struct {
1013 	u_int16_t	timeout; /* (timeout * 0.625) msec */
1014 } __attribute__ ((packed)) ng_hci_write_page_timo_cp;
1015 
1016 typedef ng_hci_status_rp	ng_hci_write_page_timo_rp;
1017 
1018 #define NG_HCI_OCF_READ_SCAN_ENABLE		0x0019
1019 /* No command parameter(s) */
1020 typedef struct {
1021 	u_int8_t	status;      /* 0x00 - success */
1022 	u_int8_t	scan_enable; /* Scan enable */
1023 } __attribute__ ((packed)) ng_hci_read_scan_enable_rp;
1024 
1025 #define NG_HCI_OCF_WRITE_SCAN_ENABLE		0x001a
1026 typedef struct {
1027 	u_int8_t	scan_enable; /* Scan enable */
1028 } __attribute__ ((packed)) ng_hci_write_scan_enable_cp;
1029 
1030 typedef ng_hci_status_rp	ng_hci_write_scan_enable_rp;
1031 
1032 #define NG_HCI_OCF_READ_PAGE_SCAN_ACTIVITY	0x001b
1033 /* No command parameter(s) */
1034 typedef struct {
1035 	u_int8_t	status;             /* 0x00 - success */
1036 	u_int16_t	page_scan_interval; /* interval * 0.625 msec */
1037 	u_int16_t	page_scan_window;   /* window * 0.625 msec */
1038 } __attribute__ ((packed)) ng_hci_read_page_scan_activity_rp;
1039 
1040 #define NG_HCI_OCF_WRITE_PAGE_SCAN_ACTIVITY	0x001c
1041 typedef struct {
1042 	u_int16_t	page_scan_interval; /* interval * 0.625 msec */
1043 	u_int16_t	page_scan_window;   /* window * 0.625 msec */
1044 } __attribute__ ((packed)) ng_hci_write_page_scan_activity_cp;
1045 
1046 typedef ng_hci_status_rp	ng_hci_write_page_scan_activity_rp;
1047 
1048 #define NG_HCI_OCF_READ_INQUIRY_SCAN_ACTIVITY	0x001d
1049 /* No command parameter(s) */
1050 typedef struct {
1051 	u_int8_t	status;                /* 0x00 - success */
1052 	u_int16_t	inquiry_scan_interval; /* interval * 0.625 msec */
1053 	u_int16_t	inquiry_scan_window;   /* window * 0.625 msec */
1054 } __attribute__ ((packed)) ng_hci_read_inquiry_scan_activity_rp;
1055 
1056 #define NG_HCI_OCF_WRITE_INQUIRY_SCAN_ACTIVITY	0x001e
1057 typedef struct {
1058 	u_int16_t	inquiry_scan_interval; /* interval * 0.625 msec */
1059 	u_int16_t	inquiry_scan_window;   /* window * 0.625 msec */
1060 } __attribute__ ((packed)) ng_hci_write_inquiry_scan_activity_cp;
1061 
1062 typedef ng_hci_status_rp	ng_hci_write_inquiry_scan_activity_rp;
1063 
1064 #define NG_HCI_OCF_READ_AUTH_ENABLE		0x001f
1065 /* No command parameter(s) */
1066 typedef struct {
1067 	u_int8_t	status;      /* 0x00 - success */
1068 	u_int8_t	auth_enable; /* 0x01 - enabled */
1069 } __attribute__ ((packed)) ng_hci_read_auth_enable_rp;
1070 
1071 #define NG_HCI_OCF_WRITE_AUTH_ENABLE		0x0020
1072 typedef struct {
1073 	u_int8_t	auth_enable; /* 0x01 - enabled */
1074 } __attribute__ ((packed)) ng_hci_write_auth_enable_cp;
1075 
1076 typedef ng_hci_status_rp	ng_hci_write_auth_enable_rp;
1077 
1078 #define NG_HCI_OCF_READ_ENCRYPTION_MODE		0x0021
1079 /* No command parameter(s) */
1080 typedef struct {
1081 	u_int8_t	status;          /* 0x00 - success */
1082 	u_int8_t	encryption_mode; /* encryption mode */
1083 } __attribute__ ((packed)) ng_hci_read_encryption_mode_rp;
1084 
1085 #define NG_HCI_OCF_WRITE_ENCRYPTION_MODE	0x0022
1086 typedef struct {
1087 	u_int8_t	encryption_mode; /* encryption mode */
1088 } __attribute__ ((packed)) ng_hci_write_encryption_mode_cp;
1089 
1090 typedef ng_hci_status_rp	ng_hci_write_encryption_mode_rp;
1091 
1092 #define NG_HCI_OCF_READ_UNIT_CLASS		0x0023
1093 /* No command parameter(s) */
1094 typedef struct {
1095 	u_int8_t	status;                    /* 0x00 - success */
1096 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* unit class */
1097 } __attribute__ ((packed)) ng_hci_read_unit_class_rp;
1098 
1099 #define NG_HCI_OCF_WRITE_UNIT_CLASS		0x0024
1100 typedef struct {
1101 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* unit class */
1102 } __attribute__ ((packed)) ng_hci_write_unit_class_cp;
1103 
1104 typedef ng_hci_status_rp	ng_hci_write_unit_class_rp;
1105 
1106 #define NG_HCI_OCF_READ_VOICE_SETTINGS		0x0025
1107 /* No command parameter(s) */
1108 typedef struct {
1109 	u_int8_t	status;   /* 0x00 - success */
1110 	u_int16_t	settings; /* voice settings */
1111 } __attribute__ ((packed)) ng_hci_read_voice_settings_rp;
1112 
1113 #define NG_HCI_OCF_WRITE_VOICE_SETTINGS		0x0026
1114 typedef struct {
1115 	u_int16_t	settings; /* voice settings */
1116 } __attribute__ ((packed)) ng_hci_write_voice_settings_cp;
1117 
1118 typedef ng_hci_status_rp	ng_hci_write_voice_settings_rp;
1119 
1120 #define NG_HCI_OCF_READ_AUTO_FLUSH_TIMO		0x0027
1121 typedef struct {
1122 	u_int16_t	con_handle; /* connection handle */
1123 } __attribute__ ((packed)) ng_hci_read_auto_flush_timo_cp;
1124 
1125 typedef struct {
1126 	u_int8_t	status;     /* 0x00 - success */
1127 	u_int16_t	con_handle; /* connection handle */
1128 	u_int16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
1129 } __attribute__ ((packed)) ng_hci_read_auto_flush_timo_rp;
1130 
1131 #define NG_HCI_OCF_WRITE_AUTO_FLUSH_TIMO	0x0028
1132 typedef struct {
1133 	u_int16_t	con_handle; /* connection handle */
1134 	u_int16_t	timeout;    /* 0x00 - no flush, timeout * 0.625 msec */
1135 } __attribute__ ((packed)) ng_hci_write_auto_flush_timo_cp;
1136 
1137 typedef struct {
1138 	u_int8_t	status;     /* 0x00 - success */
1139 	u_int16_t	con_handle; /* connection handle */
1140 } __attribute__ ((packed)) ng_hci_write_auto_flush_timo_rp;
1141 
1142 #define NG_HCI_OCF_READ_NUM_BROADCAST_RETRANS	0x0029
1143 /* No command parameter(s) */
1144 typedef struct {
1145 	u_int8_t	status;  /* 0x00 - success */
1146 	u_int8_t	counter; /* number of broadcast retransmissions */
1147 } __attribute__ ((packed)) ng_hci_read_num_broadcast_retrans_rp;
1148 
1149 #define NG_HCI_OCF_WRITE_NUM_BROADCAST_RETRANS	0x002a
1150 typedef struct {
1151 	u_int8_t	counter; /* number of broadcast retransmissions */
1152 } __attribute__ ((packed)) ng_hci_write_num_broadcast_retrans_cp;
1153 
1154 typedef ng_hci_status_rp	ng_hci_write_num_broadcast_retrans_rp;
1155 
1156 #define NG_HCI_OCF_READ_HOLD_MODE_ACTIVITY	0x002b
1157 /* No command parameter(s) */
1158 typedef struct {
1159 	u_int8_t	status;             /* 0x00 - success */
1160 	u_int8_t	hold_mode_activity; /* Hold mode activities */
1161 } __attribute__ ((packed)) ng_hci_read_hold_mode_activity_rp;
1162 
1163 #define NG_HCI_OCF_WRITE_HOLD_MODE_ACTIVITY	0x002c
1164 typedef struct {
1165 	u_int8_t	hold_mode_activity; /* Hold mode activities */
1166 } __attribute__ ((packed)) ng_hci_write_hold_mode_activity_cp;
1167 
1168 typedef ng_hci_status_rp	ng_hci_write_hold_mode_activity_rp;
1169 
1170 #define NG_HCI_OCF_READ_XMIT_LEVEL		0x002d
1171 typedef struct {
1172 	u_int16_t	con_handle; /* connection handle */
1173 	u_int8_t	type;       /* Xmit level type */
1174 } __attribute__ ((packed)) ng_hci_read_xmit_level_cp;
1175 
1176 typedef struct {
1177 	u_int8_t	status;     /* 0x00 - success */
1178 	u_int16_t	con_handle; /* connection handle */
1179 	char		level;      /* -30 <= level <= 30 dBm */
1180 } __attribute__ ((packed)) ng_hci_read_xmit_level_rp;
1181 
1182 #define NG_HCI_OCF_READ_SCO_FLOW_CONTROL	0x002e
1183 /* No command parameter(s) */
1184 typedef struct {
1185 	u_int8_t	status;       /* 0x00 - success */
1186 	u_int8_t	flow_control; /* 0x00 - disabled */
1187 } __attribute__ ((packed)) ng_hci_read_sco_flow_control_rp;
1188 
1189 #define NG_HCI_OCF_WRITE_SCO_FLOW_CONTROL	0x002f
1190 typedef struct {
1191 	u_int8_t	flow_control; /* 0x00 - disabled */
1192 } __attribute__ ((packed)) ng_hci_write_sco_flow_control_cp;
1193 
1194 typedef ng_hci_status_rp	ng_hci_write_sco_flow_control_rp;
1195 
1196 #define NG_HCI_OCF_H2HC_FLOW_CONTROL		0x0031
1197 typedef struct {
1198 	u_int8_t	h2hc_flow; /* Host to Host controller flow control */
1199 } __attribute__ ((packed)) ng_hci_h2hc_flow_control_cp;
1200 
1201 typedef ng_hci_status_rp	ng_hci_h2hc_flow_control_rp;
1202 
1203 #define NG_HCI_OCF_HOST_BUFFER_SIZE		0x0033
1204 typedef struct {
1205 	u_int16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
1206 	u_int8_t	max_sco_size; /* Max. size of SCO packet (bytes) */
1207 	u_int16_t	num_acl_pkt;  /* Max. number of ACL packets */
1208 	u_int16_t	num_sco_pkt;  /* Max. number of SCO packets */
1209 } __attribute__ ((packed)) ng_hci_host_buffer_size_cp;
1210 
1211 typedef ng_hci_status_rp	ng_hci_host_buffer_size_rp;
1212 
1213 #define NG_HCI_OCF_HOST_NUM_COMPL_PKTS		0x0035
1214 typedef struct {
1215 	u_int8_t	num_con_handles; /* # of connection handles */
1216 /* these are repeated "num_con_handles" times
1217 	u_int16_t	con_handle; --- connection handle(s)
1218 	u_int16_t	compl_pkt;  --- # of completed packets */
1219 } __attribute__ ((packed)) ng_hci_host_num_compl_pkts_cp;
1220 /* No return parameter(s) */
1221 
1222 #define NG_HCI_OCF_READ_LINK_SUPERVISION_TIMO	0x0036
1223 typedef struct {
1224 	u_int16_t	con_handle; /* connection handle */
1225 } __attribute__ ((packed)) ng_hci_read_link_supervision_timo_cp;
1226 
1227 typedef struct {
1228 	u_int8_t	status;     /* 0x00 - success */
1229 	u_int16_t	con_handle; /* connection handle */
1230 	u_int16_t	timeout;    /* Link supervision timeout * 0.625 msec */
1231 } __attribute__ ((packed)) ng_hci_read_link_supervision_timo_rp;
1232 
1233 #define NG_HCI_OCF_WRITE_LINK_SUPERVISION_TIMO	0x0037
1234 typedef struct {
1235 	u_int16_t	con_handle; /* connection handle */
1236 	u_int16_t	timeout;    /* Link supervision timeout * 0.625 msec */
1237 } __attribute__ ((packed)) ng_hci_write_link_supervision_timo_cp;
1238 
1239 typedef struct {
1240 	u_int8_t	status;     /* 0x00 - success */
1241 	u_int16_t	con_handle; /* connection handle */
1242 } __attribute__ ((packed)) ng_hci_write_link_supervision_timo_rp;
1243 
1244 #define NG_HCI_OCF_READ_SUPPORTED_IAC_NUM	0x0038
1245 /* No command parameter(s) */
1246 typedef struct {
1247 	u_int8_t	status;  /* 0x00 - success */
1248 	u_int8_t	num_iac; /* # of supported IAC during scan */
1249 } __attribute__ ((packed)) ng_hci_read_supported_iac_num_rp;
1250 
1251 #define NG_HCI_OCF_READ_IAC_LAP			0x0039
1252 /* No command parameter(s) */
1253 typedef struct {
1254 	u_int8_t	status;  /* 0x00 - success */
1255 	u_int8_t	num_iac; /* # of IAC */
1256 /* these are repeated "num_iac" times
1257 	u_int8_t	laps[NG_HCI_LAP_SIZE]; --- LAPs */
1258 } __attribute__ ((packed)) ng_hci_read_iac_lap_rp;
1259 
1260 #define NG_HCI_OCF_WRITE_IAC_LAP		0x003a
1261 typedef struct {
1262 	u_int8_t	num_iac; /* # of IAC */
1263 /* these are repeated "num_iac" times
1264 	u_int8_t	laps[NG_HCI_LAP_SIZE]; --- LAPs */
1265 } __attribute__ ((packed)) ng_hci_write_iac_lap_cp;
1266 
1267 typedef ng_hci_status_rp	ng_hci_write_iac_lap_rp;
1268 
1269 #define NG_HCI_OCF_READ_PAGE_SCAN_PERIOD	0x003b
1270 /* No command parameter(s) */
1271 typedef struct {
1272 	u_int8_t	status;                /* 0x00 - success */
1273 	u_int8_t	page_scan_period_mode; /* Page scan period mode */
1274 } __attribute__ ((packed)) ng_hci_read_page_scan_period_rp;
1275 
1276 #define NG_HCI_OCF_WRITE_PAGE_SCAN_PERIOD	0x003c
1277 typedef struct {
1278 	u_int8_t	page_scan_period_mode; /* Page scan period mode */
1279 } __attribute__ ((packed)) ng_hci_write_page_scan_period_cp;
1280 
1281 typedef ng_hci_status_rp	ng_hci_write_page_scan_period_rp;
1282 
1283 #define NG_HCI_OCF_READ_PAGE_SCAN		0x003d
1284 /* No command parameter(s) */
1285 typedef struct {
1286 	u_int8_t	status;         /* 0x00 - success */
1287 	u_int8_t	page_scan_mode; /* Page scan mode */
1288 } __attribute__ ((packed)) ng_hci_read_page_scan_rp;
1289 
1290 #define NG_HCI_OCF_WRITE_PAGE_SCAN		0x003e
1291 typedef struct {
1292 	u_int8_t	page_scan_mode; /* Page scan mode */
1293 } __attribute__ ((packed)) ng_hci_write_page_scan_cp;
1294 
1295 typedef ng_hci_status_rp	ng_hci_write_page_scan_rp;
1296 
1297 /**************************************************************************
1298  **************************************************************************
1299  **           Informational commands and return parameters
1300  **     All commands in this category do not accept any parameters
1301  **************************************************************************
1302  **************************************************************************/
1303 
1304 #define NG_HCI_OGF_INFO				0x04 /* OpCode Group Field */
1305 
1306 #define NG_HCI_OCF_READ_LOCAL_VER		0x0001
1307 typedef struct {
1308 	u_int8_t	status;         /* 0x00 - success */
1309 	u_int8_t	hci_version;    /* HCI version */
1310 	u_int16_t	hci_revision;   /* HCI revision */
1311 	u_int8_t	lmp_version;    /* LMP version */
1312 	u_int16_t	manufacturer;   /* Hardware manufacturer name */
1313 	u_int16_t	lmp_subversion; /* LMP sub-version */
1314 } __attribute__ ((packed)) ng_hci_read_local_ver_rp;
1315 
1316 #define NG_HCI_OCF_READ_LOCAL_FEATURES		0x0003
1317 typedef struct {
1318 	u_int8_t	status;                         /* 0x00 - success */
1319 	u_int8_t	features[NG_HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
1320 } __attribute__ ((packed)) ng_hci_read_local_features_rp;
1321 
1322 #define NG_HCI_OCF_READ_BUFFER_SIZE		0x0005
1323 typedef struct {
1324 	u_int8_t	status;       /* 0x00 - success */
1325 	u_int16_t	max_acl_size; /* Max. size of ACL packet (bytes) */
1326 	u_int8_t	max_sco_size; /* Max. size of SCO packet (bytes) */
1327 	u_int16_t	num_acl_pkt;  /* Max. number of ACL packets */
1328 	u_int16_t	num_sco_pkt;  /* Max. number of SCO packets */
1329 } __attribute__ ((packed)) ng_hci_read_buffer_size_rp;
1330 
1331 #define NG_HCI_OCF_READ_COUNTRY_CODE		0x0007
1332 typedef struct {
1333 	u_int8_t	status;       /* 0x00 - success */
1334 	u_int8_t	country_code; /* 0x00 - NAM, EUR, JP; 0x01 - France */
1335 } __attribute__ ((packed)) ng_hci_read_country_code_rp;
1336 
1337 #define NG_HCI_OCF_READ_BDADDR			0x0009
1338 typedef struct {
1339 	u_int8_t	status; /* 0x00 - success */
1340 	bdaddr_t	bdaddr; /* unit address */
1341 } __attribute__ ((packed)) ng_hci_read_bdaddr_rp;
1342 
1343 /**************************************************************************
1344  **************************************************************************
1345  **            Status commands and return parameters
1346  **************************************************************************
1347  **************************************************************************/
1348 
1349 #define NG_HCI_OGF_STATUS			0x05 /* OpCode Group Field */
1350 
1351 #define NG_HCI_OCF_READ_FAILED_CONTACT_CNTR	0x0001
1352 typedef struct {
1353 	u_int16_t	con_handle; /* connection handle */
1354 } __attribute__ ((packed)) ng_hci_read_failed_contact_cntr_cp;
1355 
1356 typedef struct {
1357 	u_int8_t	status;     /* 0x00 - success */
1358 	u_int16_t	con_handle; /* connection handle */
1359 	u_int16_t	counter;    /* number of consecutive failed contacts */
1360 } __attribute__ ((packed)) ng_hci_read_failed_contact_cntr_rp;
1361 
1362 #define NG_HCI_OCF_RESET_FAILED_CONTACT_CNTR	0x0002
1363 typedef struct {
1364 	u_int16_t	con_handle; /* connection handle */
1365 } __attribute__ ((packed)) ng_hci_reset_failed_contact_cntr_cp;
1366 
1367 typedef struct {
1368 	u_int8_t	status;     /* 0x00 - success */
1369 	u_int16_t	con_handle; /* connection handle */
1370 } __attribute__ ((packed)) ng_hci_reset_failed_contact_cntr_rp;
1371 
1372 #define NG_HCI_OCF_GET_LINK_QUALITY		0x0003
1373 typedef struct {
1374 	u_int16_t	con_handle; /* connection handle */
1375 } __attribute__ ((packed)) ng_hci_get_link_quality_cp;
1376 
1377 typedef struct {
1378 	u_int8_t	status;     /* 0x00 - success */
1379 	u_int16_t	con_handle; /* connection handle */
1380 	u_int8_t	quality;    /* higher value means better quality */
1381 } __attribute__ ((packed)) ng_hci_get_link_quality_rp;
1382 
1383 #define NG_HCI_OCF_READ_RSSI			0x0005
1384 typedef struct {
1385 	u_int16_t	con_handle; /* connection handle */
1386 } __attribute__ ((packed)) ng_hci_read_rssi_cp;
1387 
1388 typedef struct {
1389 	u_int8_t	status;     /* 0x00 - success */
1390 	u_int16_t	con_handle; /* connection handle */
1391 	char		rssi;       /* -127 <= rssi <= 127 dB */
1392 } __attribute__ ((packed)) ng_hci_read_rssi_rp;
1393 
1394 /**************************************************************************
1395  **************************************************************************
1396  **             Testing commands and return parameters
1397  **************************************************************************
1398  **************************************************************************/
1399 
1400 #define NG_HCI_OGF_TESTING			0x06 /* OpCode Group Field */
1401 
1402 #define NG_HCI_OCF_READ_LOOPBACK_MODE		0x0001
1403 /* No command parameter(s) */
1404 typedef struct {
1405 	u_int8_t	status; /* 0x00 - success */
1406 	u_int8_t	lbmode; /* loopback mode */
1407 } __attribute__ ((packed)) ng_hci_read_loopback_mode_rp;
1408 
1409 #define NG_HCI_OCF_WRITE_LOOPBACK_MODE		0x0002
1410 typedef struct {
1411 	u_int8_t	lbmode; /* loopback mode */
1412 } __attribute__ ((packed)) ng_hci_write_loopback_mode_cp;
1413 
1414 typedef ng_hci_status_rp	ng_hci_write_loopback_mode_rp;
1415 
1416 #define NG_HCI_OCF_ENABLE_UNIT_UNDER_TEST	0x0003
1417 /* No command parameter(s) */
1418 typedef ng_hci_status_rp	ng_hci_enable_unit_under_test_rp;
1419 
1420 /**************************************************************************
1421  **************************************************************************
1422  **                Special HCI OpCode group field values
1423  **************************************************************************
1424  **************************************************************************/
1425 
1426 #define NG_HCI_OGF_BT_LOGO			0x3e
1427 
1428 #define NG_HCI_OGF_VENDOR			0x3f
1429 
1430 /**************************************************************************
1431  **************************************************************************
1432  **                         Events and event parameters
1433  **************************************************************************
1434  **************************************************************************/
1435 
1436 #define NG_HCI_EVENT_INQUIRY_COMPL		0x01
1437 typedef struct {
1438 	u_int8_t	status; /* 0x00 - success */
1439 } __attribute__ ((packed)) ng_hci_inquiry_compl_ep;
1440 
1441 #define NG_HCI_EVENT_INQUIRY_RESULT		0x02
1442 typedef struct {
1443 	u_int8_t	num_responses;      /* number of responses */
1444 /*	ng_hci_inquiry_response[num_responses]   -- see below */
1445 } __attribute__ ((packed)) ng_hci_inquiry_result_ep;
1446 
1447 typedef struct {
1448 	bdaddr_t	bdaddr;                   /* unit address */
1449 	u_int8_t	page_scan_rep_mode;       /* page scan rep. mode */
1450 	u_int8_t	page_scan_period_mode;    /* page scan period mode */
1451 	u_int8_t	page_scan_mode;           /* page scan mode */
1452 	u_int8_t	uclass[NG_HCI_CLASS_SIZE];/* unit class */
1453 	u_int16_t	clock_offset;             /* clock offset */
1454 } __attribute__ ((packed)) ng_hci_inquiry_response;
1455 
1456 #define NG_HCI_EVENT_CON_COMPL			0x03
1457 typedef struct {
1458 	u_int8_t	status;          /* 0x00 - success */
1459 	u_int16_t	con_handle;      /* Connection handle */
1460 	bdaddr_t	bdaddr;          /* remote unit address */
1461 	u_int8_t	link_type;       /* Link type */
1462 	u_int8_t	encryption_mode; /* Encryption mode */
1463 } __attribute__ ((packed)) ng_hci_con_compl_ep;
1464 
1465 #define NG_HCI_EVENT_CON_REQ			0x04
1466 typedef struct {
1467 	bdaddr_t	bdaddr;                    /* remote unit address */
1468 	u_int8_t	uclass[NG_HCI_CLASS_SIZE]; /* remote unit class */
1469 	u_int8_t	link_type;                 /* link type */
1470 } __attribute__ ((packed)) ng_hci_con_req_ep;
1471 
1472 #define NG_HCI_EVENT_DISCON_COMPL		0x05
1473 typedef struct {
1474 	u_int8_t	status;     /* 0x00 - success */
1475 	u_int16_t	con_handle; /* connection handle */
1476 	u_int8_t	reason;     /* reason to disconnect */
1477 } __attribute__ ((packed)) ng_hci_discon_compl_ep;
1478 
1479 #define NG_HCI_EVENT_AUTH_COMPL			0x06
1480 typedef struct {
1481 	u_int8_t	status;     /* 0x00 - success */
1482 	u_int16_t	con_handle; /* connection handle */
1483 } __attribute__ ((packed)) ng_hci_auth_compl_ep;
1484 
1485 #define NG_HCI_EVENT_REMOTE_NAME_REQ_COMPL	0x7
1486 typedef struct {
1487 	u_int8_t	status; /* 0x00 - success */
1488 	bdaddr_t	bdaddr; /* remote unit address */
1489 	char		name[NG_HCI_UNIT_NAME_SIZE]; /* remote unit name */
1490 } __attribute__ ((packed)) ng_hci_remote_name_req_compl_ep;
1491 
1492 #define NG_HCI_EVENT_ENCRYPTION_CHANGE		0x08
1493 typedef struct {
1494 	u_int8_t	status;            /* 0x00 - success */
1495 	u_int16_t	con_handle;        /* Connection handle */
1496 	u_int8_t	encryption_enable; /* 0x00 - disable */
1497 } __attribute__ ((packed)) ng_hci_encryption_change_ep;
1498 
1499 #define NG_HCI_EVENT_CHANGE_CON_LINK_KEY_COMPL	0x09
1500 typedef struct {
1501 	u_int8_t	status;     /* 0x00 - success */
1502 	u_int16_t	con_handle; /* Connection handle */
1503 } __attribute__ ((packed)) ng_hci_change_con_link_key_compl_ep;
1504 
1505 #define NG_HCI_EVENT_MASTER_LINK_KEY_COMPL	0x0a
1506 typedef struct {
1507 	u_int8_t	status;     /* 0x00 - success */
1508 	u_int16_t	con_handle; /* Connection handle */
1509 	u_int8_t	key_flag;   /* Key flag */
1510 } __attribute__ ((packed)) ng_hci_master_link_key_compl_ep;
1511 
1512 #define NG_HCI_EVENT_READ_REMOTE_FEATURES_COMPL	0x0b
1513 typedef struct {
1514 	u_int8_t	status;                         /* 0x00 - success */
1515 	u_int16_t	con_handle;                     /* Connection handle */
1516 	u_int8_t	features[NG_HCI_FEATURES_SIZE]; /* LMP features bitmsk*/
1517 } __attribute__ ((packed)) ng_hci_read_remote_features_compl_ep;
1518 
1519 #define NG_HCI_EVENT_READ_REMOTE_VER_INFO_COMPL	0x0c
1520 typedef struct {
1521 	u_int8_t	status;         /* 0x00 - success */
1522 	u_int16_t	con_handle;     /* Connection handle */
1523 	u_int8_t	lmp_version;    /* LMP version */
1524 	u_int16_t	manufacturer;   /* Hardware manufacturer name */
1525 	u_int16_t	lmp_subversion; /* LMP sub-version */
1526 } __attribute__ ((packed)) ng_hci_read_remote_ver_info_compl_ep;
1527 
1528 #define NG_HCI_EVENT_QOS_SETUP_COMPL		0x0d
1529 typedef struct {
1530 	u_int8_t	status;          /* 0x00 - success */
1531 	u_int16_t	con_handle;      /* connection handle */
1532 	u_int8_t	flags;           /* reserved for future use */
1533 	u_int8_t	service_type;    /* service type */
1534 	u_int32_t	token_rate;      /* bytes per second */
1535 	u_int32_t	peak_bandwidth;  /* bytes per second */
1536 	u_int32_t	latency;         /* microseconds */
1537 	u_int32_t	delay_variation; /* microseconds */
1538 } __attribute__ ((packed)) ng_hci_qos_setup_compl_ep;
1539 
1540 #define NG_HCI_EVENT_COMMAND_COMPL		0x0e
1541 typedef struct {
1542 	u_int8_t	num_cmd_pkts; /* # of HCI command packets */
1543 	u_int16_t	opcode;       /* command OpCode */
1544 	/* command return parameters (if any) */
1545 } __attribute__ ((packed)) ng_hci_command_compl_ep;
1546 
1547 #define NG_HCI_EVENT_COMMAND_STATUS		0x0f
1548 typedef struct {
1549 	u_int8_t	status;       /* 0x00 - pending */
1550 	u_int8_t	num_cmd_pkts; /* # of HCI command packets */
1551 	u_int16_t	opcode;       /* command OpCode */
1552 } __attribute__ ((packed)) ng_hci_command_status_ep;
1553 
1554 #define NG_HCI_EVENT_HARDWARE_ERROR		0x10
1555 typedef struct {
1556 	u_int8_t	hardware_code; /* hardware error code */
1557 } __attribute__ ((packed)) ng_hci_hardware_error_ep;
1558 
1559 #define NG_HCI_EVENT_FLUSH_OCCUR		0x11
1560 typedef struct {
1561 	u_int16_t	con_handle; /* connection handle */
1562 } __attribute__ ((packed)) ng_hci_flush_occur_ep;
1563 
1564 #define NG_HCI_EVENT_ROLE_CHANGE		0x12
1565 typedef struct {
1566 	u_int8_t	status; /* 0x00 - success */
1567 	bdaddr_t	bdaddr; /* address of remote unit */
1568 	u_int8_t	role;   /* new connection role */
1569 } __attribute__ ((packed)) ng_hci_role_change_ep;
1570 
1571 #define NG_HCI_EVENT_NUM_COMPL_PKTS		0x13
1572 typedef struct {
1573 	u_int8_t	num_con_handles; /* # of connection handles */
1574 /* these are repeated "num_con_handles" times
1575 	u_int16_t	con_handle; --- connection handle(s)
1576 	u_int16_t	compl_pkt;  --- # of completed packets */
1577 } __attribute__ ((packed)) ng_hci_num_compl_pkts_ep;
1578 
1579 #define NG_HCI_EVENT_MODE_CHANGE		0x14
1580 typedef struct {
1581 	u_int8_t	status;     /* 0x00 - success */
1582 	u_int16_t	con_handle; /* connection handle */
1583 	u_int8_t	unit_mode;  /* remote unit mode */
1584 	u_int16_t	interval;   /* interval * 0.625 msec */
1585 } __attribute__ ((packed)) ng_hci_mode_change_ep;
1586 
1587 #define NG_HCI_EVENT_RETURN_LINK_KEYS		0x15
1588 typedef struct {
1589 	u_int8_t	num_keys; /* # of keys */
1590 /* these are repeated "num_keys" times
1591 	bdaddr_t	bdaddr;               --- remote address(es)
1592 	u_int8_t	key[NG_HCI_KEY_SIZE]; --- key(s) */
1593 } __attribute__ ((packed)) ng_hci_return_link_keys_ep;
1594 
1595 #define NG_HCI_EVENT_PIN_CODE_REQ		0x16
1596 typedef struct {
1597 	bdaddr_t	bdaddr; /* remote unit address */
1598 } __attribute__ ((packed)) ng_hci_pin_code_req_ep;
1599 
1600 #define NG_HCI_EVENT_LINK_KEY_REQ		0x17
1601 typedef struct {
1602 	bdaddr_t	bdaddr; /* remote unit address */
1603 } __attribute__ ((packed)) ng_hci_link_key_req_ep;
1604 
1605 #define NG_HCI_EVENT_LINK_KEY_NOTIFICATION	0x18
1606 typedef struct {
1607 	bdaddr_t	bdaddr;               /* remote unit address */
1608 	u_int8_t	key[NG_HCI_KEY_SIZE]; /* link key */
1609 	u_int8_t	key_type;             /* type of the key */
1610 } __attribute__ ((packed)) ng_hci_link_key_notification_ep;
1611 
1612 #define NG_HCI_EVENT_LOOPBACK_COMMAND		0x19
1613 typedef struct {
1614 	u_int8_t	command[0]; /* Command packet */
1615 } __attribute__ ((packed)) ng_hci_loopback_command_ep;
1616 
1617 #define NG_HCI_EVENT_DATA_BUFFER_OVERFLOW	0x1a
1618 typedef struct {
1619 	u_int8_t	link_type; /* Link type */
1620 } __attribute__ ((packed)) ng_hci_data_buffer_overflow_ep;
1621 
1622 #define NG_HCI_EVENT_MAX_SLOT_CHANGE		0x1b
1623 typedef struct {
1624 	u_int16_t	con_handle;    /* connection handle */
1625 	u_int8_t	lmp_max_slots; /* Max. # of slots allowed */
1626 } __attribute__ ((packed)) ng_hci_max_slot_change_ep;
1627 
1628 #define NG_HCI_EVENT_READ_CLOCK_OFFSET_COMPL	0x1c
1629 typedef struct {
1630 	u_int8_t	status;       /* 0x00 - success */
1631 	u_int16_t	con_handle;   /* Connection handle */
1632 	u_int16_t	clock_offset; /* Clock offset */
1633 } __attribute__ ((packed)) ng_hci_read_clock_offset_compl_ep;
1634 
1635 #define NG_HCI_EVENT_CON_PKT_TYPE_CHANGED	0x1d
1636 typedef struct {
1637 	u_int8_t	status;     /* 0x00 - success */
1638 	u_int16_t	con_handle; /* connection handle */
1639 	u_int16_t	pkt_type;   /* packet type */
1640 } __attribute__ ((packed)) ng_hci_con_pkt_type_changed_ep;
1641 
1642 #define NG_HCI_EVENT_QOS_VIOLATION		0x1e
1643 typedef struct {
1644 	u_int16_t	con_handle; /* connection handle */
1645 } __attribute__ ((packed)) ng_hci_qos_violation_ep;
1646 
1647 #define NG_HCI_EVENT_PAGE_SCAN_MODE_CHANGE	0x1f
1648 typedef struct {
1649 	bdaddr_t	bdaddr;         /* destination address */
1650 	u_int8_t	page_scan_mode; /* page scan mode */
1651 } __attribute__ ((packed)) ng_hci_page_scan_mode_change_ep;
1652 
1653 #define NG_HCI_EVENT_PAGE_SCAN_REP_MODE_CHANGE	0x20
1654 typedef struct {
1655 	bdaddr_t	bdaddr;             /* destination address */
1656 	u_int8_t	page_scan_rep_mode; /* page scan repetition mode */
1657 } __attribute__ ((packed)) ng_hci_page_scan_rep_mode_change_ep;
1658 
1659 #define NG_HCI_EVENT_BT_LOGO			0xfe
1660 
1661 #define NG_HCI_EVENT_VENDOR			0xff
1662 
1663 #endif /* ndef _NETGRAPH_HCI_H_ */
1664