xref: /openbmc/linux/include/net/bluetooth/hci.h (revision bcada3d4b8c96b8792c2306f363992ca5ab9da42)
1 /*
2    BlueZ - Bluetooth protocol stack for Linux
3    Copyright (C) 2000-2001 Qualcomm Incorporated
4 
5    Written 2000,2001 by Maxim Krasnyansky <maxk@qualcomm.com>
6 
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License version 2 as
9    published by the Free Software Foundation;
10 
11    THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12    OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13    FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT OF THIRD PARTY RIGHTS.
14    IN NO EVENT SHALL THE COPYRIGHT HOLDER(S) AND AUTHOR(S) BE LIABLE FOR ANY
15    CLAIM, OR ANY SPECIAL INDIRECT OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES
16    WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17    ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18    OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19 
20    ALL LIABILITY, INCLUDING LIABILITY FOR INFRINGEMENT OF ANY PATENTS,
21    COPYRIGHTS, TRADEMARKS OR OTHER RIGHTS, RELATING TO USE OF THIS
22    SOFTWARE IS DISCLAIMED.
23 */
24 
25 #ifndef __HCI_H
26 #define __HCI_H
27 
28 #define HCI_MAX_ACL_SIZE	1024
29 #define HCI_MAX_SCO_SIZE	255
30 #define HCI_MAX_EVENT_SIZE	260
31 #define HCI_MAX_FRAME_SIZE	(HCI_MAX_ACL_SIZE + 4)
32 
33 #define HCI_LINK_KEY_SIZE	16
34 #define HCI_AMP_LINK_KEY_SIZE	(2 * HCI_LINK_KEY_SIZE)
35 
36 /* HCI dev events */
37 #define HCI_DEV_REG			1
38 #define HCI_DEV_UNREG			2
39 #define HCI_DEV_UP			3
40 #define HCI_DEV_DOWN			4
41 #define HCI_DEV_SUSPEND			5
42 #define HCI_DEV_RESUME			6
43 
44 /* HCI notify events */
45 #define HCI_NOTIFY_CONN_ADD		1
46 #define HCI_NOTIFY_CONN_DEL		2
47 #define HCI_NOTIFY_VOICE_SETTING	3
48 
49 /* HCI bus types */
50 #define HCI_VIRTUAL	0
51 #define HCI_USB		1
52 #define HCI_PCCARD	2
53 #define HCI_UART	3
54 #define HCI_RS232	4
55 #define HCI_PCI		5
56 #define HCI_SDIO	6
57 
58 /* HCI controller types */
59 #define HCI_BREDR	0x00
60 #define HCI_AMP		0x01
61 
62 /* First BR/EDR Controller shall have ID = 0 */
63 #define HCI_BREDR_ID	0
64 
65 /* HCI device quirks */
66 enum {
67 	HCI_QUIRK_RESET_ON_CLOSE,
68 	HCI_QUIRK_RAW_DEVICE,
69 	HCI_QUIRK_FIXUP_BUFFER_SIZE
70 };
71 
72 /* HCI device flags */
73 enum {
74 	HCI_UP,
75 	HCI_INIT,
76 	HCI_RUNNING,
77 
78 	HCI_PSCAN,
79 	HCI_ISCAN,
80 	HCI_AUTH,
81 	HCI_ENCRYPT,
82 	HCI_INQUIRY,
83 
84 	HCI_RAW,
85 
86 	HCI_RESET,
87 };
88 
89 /*
90  * BR/EDR and/or LE controller flags: the flags defined here should represent
91  * states from the controller.
92  */
93 enum {
94 	HCI_SETUP,
95 	HCI_AUTO_OFF,
96 	HCI_MGMT,
97 	HCI_PAIRABLE,
98 	HCI_SERVICE_CACHE,
99 	HCI_LINK_KEYS,
100 	HCI_DEBUG_KEYS,
101 	HCI_UNREGISTER,
102 
103 	HCI_LE_SCAN,
104 	HCI_SSP_ENABLED,
105 	HCI_HS_ENABLED,
106 	HCI_LE_ENABLED,
107 	HCI_CONNECTABLE,
108 	HCI_DISCOVERABLE,
109 	HCI_LINK_SECURITY,
110 	HCI_PENDING_CLASS,
111 	HCI_PERIODIC_INQ,
112 };
113 
114 /* HCI ioctl defines */
115 #define HCIDEVUP	_IOW('H', 201, int)
116 #define HCIDEVDOWN	_IOW('H', 202, int)
117 #define HCIDEVRESET	_IOW('H', 203, int)
118 #define HCIDEVRESTAT	_IOW('H', 204, int)
119 
120 #define HCIGETDEVLIST	_IOR('H', 210, int)
121 #define HCIGETDEVINFO	_IOR('H', 211, int)
122 #define HCIGETCONNLIST	_IOR('H', 212, int)
123 #define HCIGETCONNINFO	_IOR('H', 213, int)
124 #define HCIGETAUTHINFO	_IOR('H', 215, int)
125 
126 #define HCISETRAW	_IOW('H', 220, int)
127 #define HCISETSCAN	_IOW('H', 221, int)
128 #define HCISETAUTH	_IOW('H', 222, int)
129 #define HCISETENCRYPT	_IOW('H', 223, int)
130 #define HCISETPTYPE	_IOW('H', 224, int)
131 #define HCISETLINKPOL	_IOW('H', 225, int)
132 #define HCISETLINKMODE	_IOW('H', 226, int)
133 #define HCISETACLMTU	_IOW('H', 227, int)
134 #define HCISETSCOMTU	_IOW('H', 228, int)
135 
136 #define HCIBLOCKADDR	_IOW('H', 230, int)
137 #define HCIUNBLOCKADDR	_IOW('H', 231, int)
138 
139 #define HCIINQUIRY	_IOR('H', 240, int)
140 
141 /* HCI timeouts */
142 #define HCI_DISCONN_TIMEOUT	msecs_to_jiffies(2000)	/* 2 seconds */
143 #define HCI_PAIRING_TIMEOUT	msecs_to_jiffies(60000)	/* 60 seconds */
144 #define HCI_INIT_TIMEOUT	msecs_to_jiffies(10000)	/* 10 seconds */
145 #define HCI_CMD_TIMEOUT		msecs_to_jiffies(1000)	/* 1 second */
146 #define HCI_ACL_TX_TIMEOUT	msecs_to_jiffies(45000)	/* 45 seconds */
147 #define HCI_AUTO_OFF_TIMEOUT	msecs_to_jiffies(2000)	/* 2 seconds */
148 
149 /* HCI data types */
150 #define HCI_COMMAND_PKT		0x01
151 #define HCI_ACLDATA_PKT		0x02
152 #define HCI_SCODATA_PKT		0x03
153 #define HCI_EVENT_PKT		0x04
154 #define HCI_VENDOR_PKT		0xff
155 
156 /* HCI packet types */
157 #define HCI_DM1		0x0008
158 #define HCI_DM3		0x0400
159 #define HCI_DM5		0x4000
160 #define HCI_DH1		0x0010
161 #define HCI_DH3		0x0800
162 #define HCI_DH5		0x8000
163 
164 #define HCI_HV1		0x0020
165 #define HCI_HV2		0x0040
166 #define HCI_HV3		0x0080
167 
168 #define SCO_PTYPE_MASK	(HCI_HV1 | HCI_HV2 | HCI_HV3)
169 #define ACL_PTYPE_MASK	(~SCO_PTYPE_MASK)
170 
171 /* eSCO packet types */
172 #define ESCO_HV1	0x0001
173 #define ESCO_HV2	0x0002
174 #define ESCO_HV3	0x0004
175 #define ESCO_EV3	0x0008
176 #define ESCO_EV4	0x0010
177 #define ESCO_EV5	0x0020
178 #define ESCO_2EV3	0x0040
179 #define ESCO_3EV3	0x0080
180 #define ESCO_2EV5	0x0100
181 #define ESCO_3EV5	0x0200
182 
183 #define SCO_ESCO_MASK  (ESCO_HV1 | ESCO_HV2 | ESCO_HV3)
184 #define EDR_ESCO_MASK  (ESCO_2EV3 | ESCO_3EV3 | ESCO_2EV5 | ESCO_3EV5)
185 
186 /* ACL flags */
187 #define ACL_START_NO_FLUSH	0x00
188 #define ACL_CONT		0x01
189 #define ACL_START		0x02
190 #define ACL_ACTIVE_BCAST	0x04
191 #define ACL_PICO_BCAST		0x08
192 
193 /* Baseband links */
194 #define SCO_LINK	0x00
195 #define ACL_LINK	0x01
196 #define ESCO_LINK	0x02
197 /* Low Energy links do not have defined link type. Use invented one */
198 #define LE_LINK		0x80
199 
200 /* LMP features */
201 #define LMP_3SLOT	0x01
202 #define LMP_5SLOT	0x02
203 #define LMP_ENCRYPT	0x04
204 #define LMP_SOFFSET	0x08
205 #define LMP_TACCURACY	0x10
206 #define LMP_RSWITCH	0x20
207 #define LMP_HOLD	0x40
208 #define LMP_SNIFF	0x80
209 
210 #define LMP_PARK	0x01
211 #define LMP_RSSI	0x02
212 #define LMP_QUALITY	0x04
213 #define LMP_SCO		0x08
214 #define LMP_HV2		0x10
215 #define LMP_HV3		0x20
216 #define LMP_ULAW	0x40
217 #define LMP_ALAW	0x80
218 
219 #define LMP_CVSD	0x01
220 #define LMP_PSCHEME	0x02
221 #define LMP_PCONTROL	0x04
222 
223 #define LMP_RSSI_INQ	0x40
224 #define LMP_ESCO	0x80
225 
226 #define LMP_EV4		0x01
227 #define LMP_EV5		0x02
228 #define LMP_NO_BREDR	0x20
229 #define LMP_LE		0x40
230 
231 #define LMP_SNIFF_SUBR	0x02
232 #define LMP_PAUSE_ENC	0x04
233 #define LMP_EDR_ESCO_2M	0x20
234 #define LMP_EDR_ESCO_3M	0x40
235 #define LMP_EDR_3S_ESCO	0x80
236 
237 #define LMP_EXT_INQ	0x01
238 #define LMP_SIMUL_LE_BR	0x02
239 #define LMP_SIMPLE_PAIR	0x08
240 #define LMP_NO_FLUSH	0x40
241 
242 #define LMP_LSTO	0x01
243 #define LMP_INQ_TX_PWR	0x02
244 #define LMP_EXTFEATURES	0x80
245 
246 /* Extended LMP features */
247 #define LMP_HOST_SSP		0x01
248 #define LMP_HOST_LE		0x02
249 #define LMP_HOST_LE_BREDR	0x04
250 
251 /* Connection modes */
252 #define HCI_CM_ACTIVE	0x0000
253 #define HCI_CM_HOLD	0x0001
254 #define HCI_CM_SNIFF	0x0002
255 #define HCI_CM_PARK	0x0003
256 
257 /* Link policies */
258 #define HCI_LP_RSWITCH	0x0001
259 #define HCI_LP_HOLD	0x0002
260 #define HCI_LP_SNIFF	0x0004
261 #define HCI_LP_PARK	0x0008
262 
263 /* Link modes */
264 #define HCI_LM_ACCEPT	0x8000
265 #define HCI_LM_MASTER	0x0001
266 #define HCI_LM_AUTH	0x0002
267 #define HCI_LM_ENCRYPT	0x0004
268 #define HCI_LM_TRUSTED	0x0008
269 #define HCI_LM_RELIABLE	0x0010
270 #define HCI_LM_SECURE	0x0020
271 
272 /* Authentication types */
273 #define HCI_AT_NO_BONDING		0x00
274 #define HCI_AT_NO_BONDING_MITM		0x01
275 #define HCI_AT_DEDICATED_BONDING	0x02
276 #define HCI_AT_DEDICATED_BONDING_MITM	0x03
277 #define HCI_AT_GENERAL_BONDING		0x04
278 #define HCI_AT_GENERAL_BONDING_MITM	0x05
279 
280 /* Link Key types */
281 #define HCI_LK_COMBINATION		0x00
282 #define HCI_LK_LOCAL_UNIT		0x01
283 #define HCI_LK_REMOTE_UNIT		0x02
284 #define HCI_LK_DEBUG_COMBINATION	0x03
285 #define HCI_LK_UNAUTH_COMBINATION	0x04
286 #define HCI_LK_AUTH_COMBINATION		0x05
287 #define HCI_LK_CHANGED_COMBINATION	0x06
288 /* The spec doesn't define types for SMP keys, the _MASTER suffix is implied */
289 #define HCI_SMP_STK			0x80
290 #define HCI_SMP_STK_SLAVE		0x81
291 #define HCI_SMP_LTK			0x82
292 #define HCI_SMP_LTK_SLAVE		0x83
293 
294 /* ---- HCI Error Codes ---- */
295 #define HCI_ERROR_AUTH_FAILURE		0x05
296 #define HCI_ERROR_REJ_BAD_ADDR		0x0f
297 #define HCI_ERROR_REMOTE_USER_TERM	0x13
298 #define HCI_ERROR_LOCAL_HOST_TERM	0x16
299 #define HCI_ERROR_PAIRING_NOT_ALLOWED	0x18
300 
301 /* Flow control modes */
302 #define HCI_FLOW_CTL_MODE_PACKET_BASED	0x00
303 #define HCI_FLOW_CTL_MODE_BLOCK_BASED	0x01
304 
305 /* Extended Inquiry Response field types */
306 #define EIR_FLAGS		0x01 /* flags */
307 #define EIR_UUID16_SOME		0x02 /* 16-bit UUID, more available */
308 #define EIR_UUID16_ALL		0x03 /* 16-bit UUID, all listed */
309 #define EIR_UUID32_SOME		0x04 /* 32-bit UUID, more available */
310 #define EIR_UUID32_ALL		0x05 /* 32-bit UUID, all listed */
311 #define EIR_UUID128_SOME	0x06 /* 128-bit UUID, more available */
312 #define EIR_UUID128_ALL		0x07 /* 128-bit UUID, all listed */
313 #define EIR_NAME_SHORT		0x08 /* shortened local name */
314 #define EIR_NAME_COMPLETE	0x09 /* complete local name */
315 #define EIR_TX_POWER		0x0A /* transmit power level */
316 #define EIR_CLASS_OF_DEV	0x0D /* Class of Device */
317 #define EIR_SSP_HASH_C		0x0E /* Simple Pairing Hash C */
318 #define EIR_SSP_RAND_R		0x0F /* Simple Pairing Randomizer R */
319 #define EIR_DEVICE_ID		0x10 /* device ID */
320 
321 /* -----  HCI Commands ---- */
322 #define HCI_OP_NOP			0x0000
323 
324 #define HCI_OP_INQUIRY			0x0401
325 struct hci_cp_inquiry {
326 	__u8     lap[3];
327 	__u8     length;
328 	__u8     num_rsp;
329 } __packed;
330 
331 #define HCI_OP_INQUIRY_CANCEL		0x0402
332 
333 #define HCI_OP_PERIODIC_INQ		0x0403
334 
335 #define HCI_OP_EXIT_PERIODIC_INQ	0x0404
336 
337 #define HCI_OP_CREATE_CONN		0x0405
338 struct hci_cp_create_conn {
339 	bdaddr_t bdaddr;
340 	__le16   pkt_type;
341 	__u8     pscan_rep_mode;
342 	__u8     pscan_mode;
343 	__le16   clock_offset;
344 	__u8     role_switch;
345 } __packed;
346 
347 #define HCI_OP_DISCONNECT		0x0406
348 struct hci_cp_disconnect {
349 	__le16   handle;
350 	__u8     reason;
351 } __packed;
352 
353 #define HCI_OP_ADD_SCO			0x0407
354 struct hci_cp_add_sco {
355 	__le16   handle;
356 	__le16   pkt_type;
357 } __packed;
358 
359 #define HCI_OP_CREATE_CONN_CANCEL	0x0408
360 struct hci_cp_create_conn_cancel {
361 	bdaddr_t bdaddr;
362 } __packed;
363 
364 #define HCI_OP_ACCEPT_CONN_REQ		0x0409
365 struct hci_cp_accept_conn_req {
366 	bdaddr_t bdaddr;
367 	__u8     role;
368 } __packed;
369 
370 #define HCI_OP_REJECT_CONN_REQ		0x040a
371 struct hci_cp_reject_conn_req {
372 	bdaddr_t bdaddr;
373 	__u8     reason;
374 } __packed;
375 
376 #define HCI_OP_LINK_KEY_REPLY		0x040b
377 struct hci_cp_link_key_reply {
378 	bdaddr_t bdaddr;
379 	__u8     link_key[HCI_LINK_KEY_SIZE];
380 } __packed;
381 
382 #define HCI_OP_LINK_KEY_NEG_REPLY	0x040c
383 struct hci_cp_link_key_neg_reply {
384 	bdaddr_t bdaddr;
385 } __packed;
386 
387 #define HCI_OP_PIN_CODE_REPLY		0x040d
388 struct hci_cp_pin_code_reply {
389 	bdaddr_t bdaddr;
390 	__u8     pin_len;
391 	__u8     pin_code[16];
392 } __packed;
393 struct hci_rp_pin_code_reply {
394 	__u8     status;
395 	bdaddr_t bdaddr;
396 } __packed;
397 
398 #define HCI_OP_PIN_CODE_NEG_REPLY	0x040e
399 struct hci_cp_pin_code_neg_reply {
400 	bdaddr_t bdaddr;
401 } __packed;
402 struct hci_rp_pin_code_neg_reply {
403 	__u8     status;
404 	bdaddr_t bdaddr;
405 } __packed;
406 
407 #define HCI_OP_CHANGE_CONN_PTYPE	0x040f
408 struct hci_cp_change_conn_ptype {
409 	__le16   handle;
410 	__le16   pkt_type;
411 } __packed;
412 
413 #define HCI_OP_AUTH_REQUESTED		0x0411
414 struct hci_cp_auth_requested {
415 	__le16   handle;
416 } __packed;
417 
418 #define HCI_OP_SET_CONN_ENCRYPT		0x0413
419 struct hci_cp_set_conn_encrypt {
420 	__le16   handle;
421 	__u8     encrypt;
422 } __packed;
423 
424 #define HCI_OP_CHANGE_CONN_LINK_KEY	0x0415
425 struct hci_cp_change_conn_link_key {
426 	__le16   handle;
427 } __packed;
428 
429 #define HCI_OP_REMOTE_NAME_REQ		0x0419
430 struct hci_cp_remote_name_req {
431 	bdaddr_t bdaddr;
432 	__u8     pscan_rep_mode;
433 	__u8     pscan_mode;
434 	__le16   clock_offset;
435 } __packed;
436 
437 #define HCI_OP_REMOTE_NAME_REQ_CANCEL	0x041a
438 struct hci_cp_remote_name_req_cancel {
439 	bdaddr_t bdaddr;
440 } __packed;
441 
442 #define HCI_OP_READ_REMOTE_FEATURES	0x041b
443 struct hci_cp_read_remote_features {
444 	__le16   handle;
445 } __packed;
446 
447 #define HCI_OP_READ_REMOTE_EXT_FEATURES	0x041c
448 struct hci_cp_read_remote_ext_features {
449 	__le16   handle;
450 	__u8     page;
451 } __packed;
452 
453 #define HCI_OP_READ_REMOTE_VERSION	0x041d
454 struct hci_cp_read_remote_version {
455 	__le16   handle;
456 } __packed;
457 
458 #define HCI_OP_SETUP_SYNC_CONN		0x0428
459 struct hci_cp_setup_sync_conn {
460 	__le16   handle;
461 	__le32   tx_bandwidth;
462 	__le32   rx_bandwidth;
463 	__le16   max_latency;
464 	__le16   voice_setting;
465 	__u8     retrans_effort;
466 	__le16   pkt_type;
467 } __packed;
468 
469 #define HCI_OP_ACCEPT_SYNC_CONN_REQ	0x0429
470 struct hci_cp_accept_sync_conn_req {
471 	bdaddr_t bdaddr;
472 	__le32   tx_bandwidth;
473 	__le32   rx_bandwidth;
474 	__le16   max_latency;
475 	__le16   content_format;
476 	__u8     retrans_effort;
477 	__le16   pkt_type;
478 } __packed;
479 
480 #define HCI_OP_REJECT_SYNC_CONN_REQ	0x042a
481 struct hci_cp_reject_sync_conn_req {
482 	bdaddr_t bdaddr;
483 	__u8     reason;
484 } __packed;
485 
486 #define HCI_OP_IO_CAPABILITY_REPLY	0x042b
487 struct hci_cp_io_capability_reply {
488 	bdaddr_t bdaddr;
489 	__u8     capability;
490 	__u8     oob_data;
491 	__u8     authentication;
492 } __packed;
493 
494 #define HCI_OP_USER_CONFIRM_REPLY		0x042c
495 struct hci_cp_user_confirm_reply {
496 	bdaddr_t bdaddr;
497 } __packed;
498 struct hci_rp_user_confirm_reply {
499 	__u8     status;
500 	bdaddr_t bdaddr;
501 } __packed;
502 
503 #define HCI_OP_USER_CONFIRM_NEG_REPLY	0x042d
504 
505 #define HCI_OP_USER_PASSKEY_REPLY		0x042e
506 struct hci_cp_user_passkey_reply {
507 	bdaddr_t bdaddr;
508 	__le32	passkey;
509 } __packed;
510 
511 #define HCI_OP_USER_PASSKEY_NEG_REPLY	0x042f
512 
513 #define HCI_OP_REMOTE_OOB_DATA_REPLY	0x0430
514 struct hci_cp_remote_oob_data_reply {
515 	bdaddr_t bdaddr;
516 	__u8     hash[16];
517 	__u8     randomizer[16];
518 } __packed;
519 
520 #define HCI_OP_REMOTE_OOB_DATA_NEG_REPLY	0x0433
521 struct hci_cp_remote_oob_data_neg_reply {
522 	bdaddr_t bdaddr;
523 } __packed;
524 
525 #define HCI_OP_IO_CAPABILITY_NEG_REPLY	0x0434
526 struct hci_cp_io_capability_neg_reply {
527 	bdaddr_t bdaddr;
528 	__u8     reason;
529 } __packed;
530 
531 #define HCI_OP_CREATE_PHY_LINK		0x0435
532 struct hci_cp_create_phy_link {
533 	__u8     phy_handle;
534 	__u8     key_len;
535 	__u8     key_type;
536 	__u8     key[HCI_AMP_LINK_KEY_SIZE];
537 } __packed;
538 
539 #define HCI_OP_ACCEPT_PHY_LINK		0x0436
540 struct hci_cp_accept_phy_link {
541 	__u8     phy_handle;
542 	__u8     key_len;
543 	__u8     key_type;
544 	__u8     key[HCI_AMP_LINK_KEY_SIZE];
545 } __packed;
546 
547 #define HCI_OP_DISCONN_PHY_LINK	0x0437
548 struct hci_cp_disconn_phy_link {
549 	__u8     phy_handle;
550 	__u8     reason;
551 } __packed;
552 
553 #define HCI_OP_SNIFF_MODE		0x0803
554 struct hci_cp_sniff_mode {
555 	__le16   handle;
556 	__le16   max_interval;
557 	__le16   min_interval;
558 	__le16   attempt;
559 	__le16   timeout;
560 } __packed;
561 
562 #define HCI_OP_EXIT_SNIFF_MODE		0x0804
563 struct hci_cp_exit_sniff_mode {
564 	__le16   handle;
565 } __packed;
566 
567 #define HCI_OP_ROLE_DISCOVERY		0x0809
568 struct hci_cp_role_discovery {
569 	__le16   handle;
570 } __packed;
571 struct hci_rp_role_discovery {
572 	__u8     status;
573 	__le16   handle;
574 	__u8     role;
575 } __packed;
576 
577 #define HCI_OP_SWITCH_ROLE		0x080b
578 struct hci_cp_switch_role {
579 	bdaddr_t bdaddr;
580 	__u8     role;
581 } __packed;
582 
583 #define HCI_OP_READ_LINK_POLICY		0x080c
584 struct hci_cp_read_link_policy {
585 	__le16   handle;
586 } __packed;
587 struct hci_rp_read_link_policy {
588 	__u8     status;
589 	__le16   handle;
590 	__le16   policy;
591 } __packed;
592 
593 #define HCI_OP_WRITE_LINK_POLICY	0x080d
594 struct hci_cp_write_link_policy {
595 	__le16   handle;
596 	__le16   policy;
597 } __packed;
598 struct hci_rp_write_link_policy {
599 	__u8     status;
600 	__le16   handle;
601 } __packed;
602 
603 #define HCI_OP_READ_DEF_LINK_POLICY	0x080e
604 struct hci_rp_read_def_link_policy {
605 	__u8     status;
606 	__le16   policy;
607 } __packed;
608 
609 #define HCI_OP_WRITE_DEF_LINK_POLICY	0x080f
610 struct hci_cp_write_def_link_policy {
611 	__le16   policy;
612 } __packed;
613 
614 #define HCI_OP_SNIFF_SUBRATE		0x0811
615 struct hci_cp_sniff_subrate {
616 	__le16   handle;
617 	__le16   max_latency;
618 	__le16   min_remote_timeout;
619 	__le16   min_local_timeout;
620 } __packed;
621 
622 #define HCI_OP_SET_EVENT_MASK		0x0c01
623 struct hci_cp_set_event_mask {
624 	__u8     mask[8];
625 } __packed;
626 
627 #define HCI_OP_RESET			0x0c03
628 
629 #define HCI_OP_SET_EVENT_FLT		0x0c05
630 struct hci_cp_set_event_flt {
631 	__u8     flt_type;
632 	__u8     cond_type;
633 	__u8     condition[0];
634 } __packed;
635 
636 /* Filter types */
637 #define HCI_FLT_CLEAR_ALL	0x00
638 #define HCI_FLT_INQ_RESULT	0x01
639 #define HCI_FLT_CONN_SETUP	0x02
640 
641 /* CONN_SETUP Condition types */
642 #define HCI_CONN_SETUP_ALLOW_ALL	0x00
643 #define HCI_CONN_SETUP_ALLOW_CLASS	0x01
644 #define HCI_CONN_SETUP_ALLOW_BDADDR	0x02
645 
646 /* CONN_SETUP Conditions */
647 #define HCI_CONN_SETUP_AUTO_OFF	0x01
648 #define HCI_CONN_SETUP_AUTO_ON	0x02
649 
650 #define HCI_OP_DELETE_STORED_LINK_KEY	0x0c12
651 struct hci_cp_delete_stored_link_key {
652 	bdaddr_t bdaddr;
653 	__u8     delete_all;
654 } __packed;
655 
656 #define HCI_MAX_NAME_LENGTH		248
657 
658 #define HCI_OP_WRITE_LOCAL_NAME		0x0c13
659 struct hci_cp_write_local_name {
660 	__u8     name[HCI_MAX_NAME_LENGTH];
661 } __packed;
662 
663 #define HCI_OP_READ_LOCAL_NAME		0x0c14
664 struct hci_rp_read_local_name {
665 	__u8     status;
666 	__u8     name[HCI_MAX_NAME_LENGTH];
667 } __packed;
668 
669 #define HCI_OP_WRITE_CA_TIMEOUT		0x0c16
670 
671 #define HCI_OP_WRITE_PG_TIMEOUT		0x0c18
672 
673 #define HCI_OP_WRITE_SCAN_ENABLE	0x0c1a
674 	#define SCAN_DISABLED		0x00
675 	#define SCAN_INQUIRY		0x01
676 	#define SCAN_PAGE		0x02
677 
678 #define HCI_OP_READ_AUTH_ENABLE		0x0c1f
679 
680 #define HCI_OP_WRITE_AUTH_ENABLE	0x0c20
681 	#define AUTH_DISABLED		0x00
682 	#define AUTH_ENABLED		0x01
683 
684 #define HCI_OP_READ_ENCRYPT_MODE	0x0c21
685 
686 #define HCI_OP_WRITE_ENCRYPT_MODE	0x0c22
687 	#define ENCRYPT_DISABLED	0x00
688 	#define ENCRYPT_P2P		0x01
689 	#define ENCRYPT_BOTH		0x02
690 
691 #define HCI_OP_READ_CLASS_OF_DEV	0x0c23
692 struct hci_rp_read_class_of_dev {
693 	__u8     status;
694 	__u8     dev_class[3];
695 } __packed;
696 
697 #define HCI_OP_WRITE_CLASS_OF_DEV	0x0c24
698 struct hci_cp_write_class_of_dev {
699 	__u8     dev_class[3];
700 } __packed;
701 
702 #define HCI_OP_READ_VOICE_SETTING	0x0c25
703 struct hci_rp_read_voice_setting {
704 	__u8     status;
705 	__le16   voice_setting;
706 } __packed;
707 
708 #define HCI_OP_WRITE_VOICE_SETTING	0x0c26
709 struct hci_cp_write_voice_setting {
710 	__le16   voice_setting;
711 } __packed;
712 
713 #define HCI_OP_HOST_BUFFER_SIZE		0x0c33
714 struct hci_cp_host_buffer_size {
715 	__le16   acl_mtu;
716 	__u8     sco_mtu;
717 	__le16   acl_max_pkt;
718 	__le16   sco_max_pkt;
719 } __packed;
720 
721 #define HCI_OP_WRITE_INQUIRY_MODE	0x0c45
722 
723 #define HCI_MAX_EIR_LENGTH		240
724 
725 #define HCI_OP_WRITE_EIR		0x0c52
726 struct hci_cp_write_eir {
727 	__u8	fec;
728 	__u8	data[HCI_MAX_EIR_LENGTH];
729 } __packed;
730 
731 #define HCI_OP_READ_SSP_MODE		0x0c55
732 struct hci_rp_read_ssp_mode {
733 	__u8     status;
734 	__u8     mode;
735 } __packed;
736 
737 #define HCI_OP_WRITE_SSP_MODE		0x0c56
738 struct hci_cp_write_ssp_mode {
739 	__u8     mode;
740 } __packed;
741 
742 #define HCI_OP_READ_LOCAL_OOB_DATA		0x0c57
743 struct hci_rp_read_local_oob_data {
744 	__u8     status;
745 	__u8     hash[16];
746 	__u8     randomizer[16];
747 } __packed;
748 
749 #define HCI_OP_READ_INQ_RSP_TX_POWER	0x0c58
750 struct hci_rp_read_inq_rsp_tx_power {
751 	__u8     status;
752 	__s8     tx_power;
753 } __packed;
754 
755 #define HCI_OP_READ_FLOW_CONTROL_MODE	0x0c66
756 struct hci_rp_read_flow_control_mode {
757 	__u8     status;
758 	__u8     mode;
759 } __packed;
760 
761 #define HCI_OP_WRITE_LE_HOST_SUPPORTED	0x0c6d
762 struct hci_cp_write_le_host_supported {
763 	__u8	le;
764 	__u8	simul;
765 } __packed;
766 
767 #define HCI_OP_READ_LOCAL_VERSION	0x1001
768 struct hci_rp_read_local_version {
769 	__u8     status;
770 	__u8     hci_ver;
771 	__le16   hci_rev;
772 	__u8     lmp_ver;
773 	__le16   manufacturer;
774 	__le16   lmp_subver;
775 } __packed;
776 
777 #define HCI_OP_READ_LOCAL_COMMANDS	0x1002
778 struct hci_rp_read_local_commands {
779 	__u8     status;
780 	__u8     commands[64];
781 } __packed;
782 
783 #define HCI_OP_READ_LOCAL_FEATURES	0x1003
784 struct hci_rp_read_local_features {
785 	__u8     status;
786 	__u8     features[8];
787 } __packed;
788 
789 #define HCI_OP_READ_LOCAL_EXT_FEATURES	0x1004
790 struct hci_cp_read_local_ext_features {
791 	__u8     page;
792 } __packed;
793 struct hci_rp_read_local_ext_features {
794 	__u8     status;
795 	__u8     page;
796 	__u8     max_page;
797 	__u8     features[8];
798 } __packed;
799 
800 #define HCI_OP_READ_BUFFER_SIZE		0x1005
801 struct hci_rp_read_buffer_size {
802 	__u8     status;
803 	__le16   acl_mtu;
804 	__u8     sco_mtu;
805 	__le16   acl_max_pkt;
806 	__le16   sco_max_pkt;
807 } __packed;
808 
809 #define HCI_OP_READ_BD_ADDR		0x1009
810 struct hci_rp_read_bd_addr {
811 	__u8     status;
812 	bdaddr_t bdaddr;
813 } __packed;
814 
815 #define HCI_OP_READ_DATA_BLOCK_SIZE	0x100a
816 struct hci_rp_read_data_block_size {
817 	__u8     status;
818 	__le16   max_acl_len;
819 	__le16   block_len;
820 	__le16   num_blocks;
821 } __packed;
822 
823 #define HCI_OP_WRITE_PAGE_SCAN_ACTIVITY	0x0c1c
824 struct hci_cp_write_page_scan_activity {
825 	__le16   interval;
826 	__le16   window;
827 } __packed;
828 
829 #define HCI_OP_WRITE_PAGE_SCAN_TYPE	0x0c47
830 	#define PAGE_SCAN_TYPE_STANDARD		0x00
831 	#define PAGE_SCAN_TYPE_INTERLACED	0x01
832 
833 #define HCI_OP_READ_LOCAL_AMP_INFO	0x1409
834 struct hci_rp_read_local_amp_info {
835 	__u8     status;
836 	__u8     amp_status;
837 	__le32   total_bw;
838 	__le32   max_bw;
839 	__le32   min_latency;
840 	__le32   max_pdu;
841 	__u8     amp_type;
842 	__le16   pal_cap;
843 	__le16   max_assoc_size;
844 	__le32   max_flush_to;
845 	__le32   be_flush_to;
846 } __packed;
847 
848 #define HCI_OP_READ_LOCAL_AMP_ASSOC	0x140a
849 struct hci_cp_read_local_amp_assoc {
850 	__u8     phy_handle;
851 	__le16   len_so_far;
852 	__le16   max_len;
853 } __packed;
854 struct hci_rp_read_local_amp_assoc {
855 	__u8     status;
856 	__u8     phy_handle;
857 	__le16   rem_len;
858 	__u8     frag[0];
859 } __packed;
860 
861 #define HCI_OP_WRITE_REMOTE_AMP_ASSOC	0x140b
862 struct hci_cp_write_remote_amp_assoc {
863 	__u8     phy_handle;
864 	__le16   len_so_far;
865 	__le16   rem_len;
866 	__u8     frag[0];
867 } __packed;
868 struct hci_rp_write_remote_amp_assoc {
869 	__u8     status;
870 	__u8     phy_handle;
871 } __packed;
872 
873 #define HCI_OP_LE_SET_EVENT_MASK	0x2001
874 struct hci_cp_le_set_event_mask {
875 	__u8     mask[8];
876 } __packed;
877 
878 #define HCI_OP_LE_READ_BUFFER_SIZE	0x2002
879 struct hci_rp_le_read_buffer_size {
880 	__u8     status;
881 	__le16   le_mtu;
882 	__u8     le_max_pkt;
883 } __packed;
884 
885 #define HCI_OP_LE_SET_SCAN_PARAM	0x200b
886 struct hci_cp_le_set_scan_param {
887 	__u8    type;
888 	__le16  interval;
889 	__le16  window;
890 	__u8    own_address_type;
891 	__u8    filter_policy;
892 } __packed;
893 
894 #define LE_SCANNING_DISABLED		0x00
895 #define LE_SCANNING_ENABLED		0x01
896 
897 #define HCI_OP_LE_SET_SCAN_ENABLE	0x200c
898 struct hci_cp_le_set_scan_enable {
899 	__u8     enable;
900 	__u8     filter_dup;
901 } __packed;
902 
903 #define HCI_OP_LE_CREATE_CONN		0x200d
904 struct hci_cp_le_create_conn {
905 	__le16   scan_interval;
906 	__le16   scan_window;
907 	__u8     filter_policy;
908 	__u8     peer_addr_type;
909 	bdaddr_t peer_addr;
910 	__u8     own_address_type;
911 	__le16   conn_interval_min;
912 	__le16   conn_interval_max;
913 	__le16   conn_latency;
914 	__le16   supervision_timeout;
915 	__le16   min_ce_len;
916 	__le16   max_ce_len;
917 } __packed;
918 
919 #define HCI_OP_LE_CREATE_CONN_CANCEL	0x200e
920 
921 #define HCI_OP_LE_CONN_UPDATE		0x2013
922 struct hci_cp_le_conn_update {
923 	__le16   handle;
924 	__le16   conn_interval_min;
925 	__le16   conn_interval_max;
926 	__le16   conn_latency;
927 	__le16   supervision_timeout;
928 	__le16   min_ce_len;
929 	__le16   max_ce_len;
930 } __packed;
931 
932 #define HCI_OP_LE_START_ENC		0x2019
933 struct hci_cp_le_start_enc {
934 	__le16	handle;
935 	__u8	rand[8];
936 	__le16	ediv;
937 	__u8	ltk[16];
938 } __packed;
939 
940 #define HCI_OP_LE_LTK_REPLY		0x201a
941 struct hci_cp_le_ltk_reply {
942 	__le16	handle;
943 	__u8	ltk[16];
944 } __packed;
945 struct hci_rp_le_ltk_reply {
946 	__u8	status;
947 	__le16	handle;
948 } __packed;
949 
950 #define HCI_OP_LE_LTK_NEG_REPLY		0x201b
951 struct hci_cp_le_ltk_neg_reply {
952 	__le16	handle;
953 } __packed;
954 struct hci_rp_le_ltk_neg_reply {
955 	__u8	status;
956 	__le16	handle;
957 } __packed;
958 
959 /* ---- HCI Events ---- */
960 #define HCI_EV_INQUIRY_COMPLETE		0x01
961 
962 #define HCI_EV_INQUIRY_RESULT		0x02
963 struct inquiry_info {
964 	bdaddr_t bdaddr;
965 	__u8     pscan_rep_mode;
966 	__u8     pscan_period_mode;
967 	__u8     pscan_mode;
968 	__u8     dev_class[3];
969 	__le16   clock_offset;
970 } __packed;
971 
972 #define HCI_EV_CONN_COMPLETE		0x03
973 struct hci_ev_conn_complete {
974 	__u8     status;
975 	__le16   handle;
976 	bdaddr_t bdaddr;
977 	__u8     link_type;
978 	__u8     encr_mode;
979 } __packed;
980 
981 #define HCI_EV_CONN_REQUEST		0x04
982 struct hci_ev_conn_request {
983 	bdaddr_t bdaddr;
984 	__u8     dev_class[3];
985 	__u8     link_type;
986 } __packed;
987 
988 #define HCI_EV_DISCONN_COMPLETE		0x05
989 struct hci_ev_disconn_complete {
990 	__u8     status;
991 	__le16   handle;
992 	__u8     reason;
993 } __packed;
994 
995 #define HCI_EV_AUTH_COMPLETE		0x06
996 struct hci_ev_auth_complete {
997 	__u8     status;
998 	__le16   handle;
999 } __packed;
1000 
1001 #define HCI_EV_REMOTE_NAME		0x07
1002 struct hci_ev_remote_name {
1003 	__u8     status;
1004 	bdaddr_t bdaddr;
1005 	__u8     name[HCI_MAX_NAME_LENGTH];
1006 } __packed;
1007 
1008 #define HCI_EV_ENCRYPT_CHANGE		0x08
1009 struct hci_ev_encrypt_change {
1010 	__u8     status;
1011 	__le16   handle;
1012 	__u8     encrypt;
1013 } __packed;
1014 
1015 #define HCI_EV_CHANGE_LINK_KEY_COMPLETE	0x09
1016 struct hci_ev_change_link_key_complete {
1017 	__u8     status;
1018 	__le16   handle;
1019 } __packed;
1020 
1021 #define HCI_EV_REMOTE_FEATURES		0x0b
1022 struct hci_ev_remote_features {
1023 	__u8     status;
1024 	__le16   handle;
1025 	__u8     features[8];
1026 } __packed;
1027 
1028 #define HCI_EV_REMOTE_VERSION		0x0c
1029 struct hci_ev_remote_version {
1030 	__u8     status;
1031 	__le16   handle;
1032 	__u8     lmp_ver;
1033 	__le16   manufacturer;
1034 	__le16   lmp_subver;
1035 } __packed;
1036 
1037 #define HCI_EV_QOS_SETUP_COMPLETE	0x0d
1038 struct hci_qos {
1039 	__u8     service_type;
1040 	__u32    token_rate;
1041 	__u32    peak_bandwidth;
1042 	__u32    latency;
1043 	__u32    delay_variation;
1044 } __packed;
1045 struct hci_ev_qos_setup_complete {
1046 	__u8     status;
1047 	__le16   handle;
1048 	struct   hci_qos qos;
1049 } __packed;
1050 
1051 #define HCI_EV_CMD_COMPLETE		0x0e
1052 struct hci_ev_cmd_complete {
1053 	__u8     ncmd;
1054 	__le16   opcode;
1055 } __packed;
1056 
1057 #define HCI_EV_CMD_STATUS		0x0f
1058 struct hci_ev_cmd_status {
1059 	__u8     status;
1060 	__u8     ncmd;
1061 	__le16   opcode;
1062 } __packed;
1063 
1064 #define HCI_EV_ROLE_CHANGE		0x12
1065 struct hci_ev_role_change {
1066 	__u8     status;
1067 	bdaddr_t bdaddr;
1068 	__u8     role;
1069 } __packed;
1070 
1071 #define HCI_EV_NUM_COMP_PKTS		0x13
1072 struct hci_comp_pkts_info {
1073 	__le16   handle;
1074 	__le16   count;
1075 } __packed;
1076 
1077 struct hci_ev_num_comp_pkts {
1078 	__u8     num_hndl;
1079 	struct hci_comp_pkts_info handles[0];
1080 } __packed;
1081 
1082 #define HCI_EV_MODE_CHANGE		0x14
1083 struct hci_ev_mode_change {
1084 	__u8     status;
1085 	__le16   handle;
1086 	__u8     mode;
1087 	__le16   interval;
1088 } __packed;
1089 
1090 #define HCI_EV_PIN_CODE_REQ		0x16
1091 struct hci_ev_pin_code_req {
1092 	bdaddr_t bdaddr;
1093 } __packed;
1094 
1095 #define HCI_EV_LINK_KEY_REQ		0x17
1096 struct hci_ev_link_key_req {
1097 	bdaddr_t bdaddr;
1098 } __packed;
1099 
1100 #define HCI_EV_LINK_KEY_NOTIFY		0x18
1101 struct hci_ev_link_key_notify {
1102 	bdaddr_t bdaddr;
1103 	__u8     link_key[HCI_LINK_KEY_SIZE];
1104 	__u8     key_type;
1105 } __packed;
1106 
1107 #define HCI_EV_CLOCK_OFFSET		0x1c
1108 struct hci_ev_clock_offset {
1109 	__u8     status;
1110 	__le16   handle;
1111 	__le16   clock_offset;
1112 } __packed;
1113 
1114 #define HCI_EV_PKT_TYPE_CHANGE		0x1d
1115 struct hci_ev_pkt_type_change {
1116 	__u8     status;
1117 	__le16   handle;
1118 	__le16   pkt_type;
1119 } __packed;
1120 
1121 #define HCI_EV_PSCAN_REP_MODE		0x20
1122 struct hci_ev_pscan_rep_mode {
1123 	bdaddr_t bdaddr;
1124 	__u8     pscan_rep_mode;
1125 } __packed;
1126 
1127 #define HCI_EV_INQUIRY_RESULT_WITH_RSSI	0x22
1128 struct inquiry_info_with_rssi {
1129 	bdaddr_t bdaddr;
1130 	__u8     pscan_rep_mode;
1131 	__u8     pscan_period_mode;
1132 	__u8     dev_class[3];
1133 	__le16   clock_offset;
1134 	__s8     rssi;
1135 } __packed;
1136 struct inquiry_info_with_rssi_and_pscan_mode {
1137 	bdaddr_t bdaddr;
1138 	__u8     pscan_rep_mode;
1139 	__u8     pscan_period_mode;
1140 	__u8     pscan_mode;
1141 	__u8     dev_class[3];
1142 	__le16   clock_offset;
1143 	__s8     rssi;
1144 } __packed;
1145 
1146 #define HCI_EV_REMOTE_EXT_FEATURES	0x23
1147 struct hci_ev_remote_ext_features {
1148 	__u8     status;
1149 	__le16   handle;
1150 	__u8     page;
1151 	__u8     max_page;
1152 	__u8     features[8];
1153 } __packed;
1154 
1155 #define HCI_EV_SYNC_CONN_COMPLETE	0x2c
1156 struct hci_ev_sync_conn_complete {
1157 	__u8     status;
1158 	__le16   handle;
1159 	bdaddr_t bdaddr;
1160 	__u8     link_type;
1161 	__u8     tx_interval;
1162 	__u8     retrans_window;
1163 	__le16   rx_pkt_len;
1164 	__le16   tx_pkt_len;
1165 	__u8     air_mode;
1166 } __packed;
1167 
1168 #define HCI_EV_SYNC_CONN_CHANGED	0x2d
1169 struct hci_ev_sync_conn_changed {
1170 	__u8     status;
1171 	__le16   handle;
1172 	__u8     tx_interval;
1173 	__u8     retrans_window;
1174 	__le16   rx_pkt_len;
1175 	__le16   tx_pkt_len;
1176 } __packed;
1177 
1178 #define HCI_EV_SNIFF_SUBRATE		0x2e
1179 struct hci_ev_sniff_subrate {
1180 	__u8     status;
1181 	__le16   handle;
1182 	__le16   max_tx_latency;
1183 	__le16   max_rx_latency;
1184 	__le16   max_remote_timeout;
1185 	__le16   max_local_timeout;
1186 } __packed;
1187 
1188 #define HCI_EV_EXTENDED_INQUIRY_RESULT	0x2f
1189 struct extended_inquiry_info {
1190 	bdaddr_t bdaddr;
1191 	__u8     pscan_rep_mode;
1192 	__u8     pscan_period_mode;
1193 	__u8     dev_class[3];
1194 	__le16   clock_offset;
1195 	__s8     rssi;
1196 	__u8     data[240];
1197 } __packed;
1198 
1199 #define HCI_EV_KEY_REFRESH_COMPLETE	0x30
1200 struct hci_ev_key_refresh_complete {
1201 	__u8	status;
1202 	__le16	handle;
1203 } __packed;
1204 
1205 #define HCI_EV_IO_CAPA_REQUEST		0x31
1206 struct hci_ev_io_capa_request {
1207 	bdaddr_t bdaddr;
1208 } __packed;
1209 
1210 #define HCI_EV_IO_CAPA_REPLY		0x32
1211 struct hci_ev_io_capa_reply {
1212 	bdaddr_t bdaddr;
1213 	__u8     capability;
1214 	__u8     oob_data;
1215 	__u8     authentication;
1216 } __packed;
1217 
1218 #define HCI_EV_USER_CONFIRM_REQUEST	0x33
1219 struct hci_ev_user_confirm_req {
1220 	bdaddr_t	bdaddr;
1221 	__le32		passkey;
1222 } __packed;
1223 
1224 #define HCI_EV_USER_PASSKEY_REQUEST	0x34
1225 struct hci_ev_user_passkey_req {
1226 	bdaddr_t	bdaddr;
1227 } __packed;
1228 
1229 #define HCI_EV_REMOTE_OOB_DATA_REQUEST	0x35
1230 struct hci_ev_remote_oob_data_request {
1231 	bdaddr_t bdaddr;
1232 } __packed;
1233 
1234 #define HCI_EV_SIMPLE_PAIR_COMPLETE	0x36
1235 struct hci_ev_simple_pair_complete {
1236 	__u8     status;
1237 	bdaddr_t bdaddr;
1238 } __packed;
1239 
1240 #define HCI_EV_REMOTE_HOST_FEATURES	0x3d
1241 struct hci_ev_remote_host_features {
1242 	bdaddr_t bdaddr;
1243 	__u8     features[8];
1244 } __packed;
1245 
1246 #define HCI_EV_LE_META			0x3e
1247 struct hci_ev_le_meta {
1248 	__u8     subevent;
1249 } __packed;
1250 
1251 #define HCI_EV_PHY_LINK_COMPLETE	0x40
1252 struct hci_ev_phy_link_complete {
1253 	__u8     status;
1254 	__u8     phy_handle;
1255 } __packed;
1256 
1257 #define HCI_EV_CHANNEL_SELECTED		0x41
1258 struct hci_ev_channel_selected {
1259 	__u8     phy_handle;
1260 } __packed;
1261 
1262 #define HCI_EV_DISCONN_PHY_LINK_COMPLETE	0x42
1263 struct hci_ev_disconn_phy_link_complete {
1264 	__u8     status;
1265 	__u8     phy_handle;
1266 	__u8     reason;
1267 } __packed;
1268 
1269 #define HCI_EV_LOGICAL_LINK_COMPLETE		0x45
1270 struct hci_ev_logical_link_complete {
1271 	__u8     status;
1272 	__le16   handle;
1273 	__u8     phy_handle;
1274 	__u8     flow_spec_id;
1275 } __packed;
1276 
1277 #define HCI_EV_DISCONN_LOGICAL_LINK_COMPLETE	0x46
1278 struct hci_ev_disconn_logical_link_complete {
1279 	__u8     status;
1280 	__le16   handle;
1281 	__u8     reason;
1282 } __packed;
1283 
1284 #define HCI_EV_NUM_COMP_BLOCKS		0x48
1285 struct hci_comp_blocks_info {
1286 	__le16   handle;
1287 	__le16   pkts;
1288 	__le16   blocks;
1289 } __packed;
1290 
1291 struct hci_ev_num_comp_blocks {
1292 	__le16   num_blocks;
1293 	__u8     num_hndl;
1294 	struct hci_comp_blocks_info handles[0];
1295 } __packed;
1296 
1297 /* Low energy meta events */
1298 #define HCI_EV_LE_CONN_COMPLETE		0x01
1299 struct hci_ev_le_conn_complete {
1300 	__u8     status;
1301 	__le16   handle;
1302 	__u8     role;
1303 	__u8     bdaddr_type;
1304 	bdaddr_t bdaddr;
1305 	__le16   interval;
1306 	__le16   latency;
1307 	__le16   supervision_timeout;
1308 	__u8     clk_accurancy;
1309 } __packed;
1310 
1311 #define HCI_EV_LE_LTK_REQ		0x05
1312 struct hci_ev_le_ltk_req {
1313 	__le16	handle;
1314 	__u8	random[8];
1315 	__le16	ediv;
1316 } __packed;
1317 
1318 /* Advertising report event types */
1319 #define ADV_IND		0x00
1320 #define ADV_DIRECT_IND	0x01
1321 #define ADV_SCAN_IND	0x02
1322 #define ADV_NONCONN_IND	0x03
1323 #define ADV_SCAN_RSP	0x04
1324 
1325 #define ADDR_LE_DEV_PUBLIC	0x00
1326 #define ADDR_LE_DEV_RANDOM	0x01
1327 
1328 #define HCI_EV_LE_ADVERTISING_REPORT	0x02
1329 struct hci_ev_le_advertising_info {
1330 	__u8	 evt_type;
1331 	__u8	 bdaddr_type;
1332 	bdaddr_t bdaddr;
1333 	__u8	 length;
1334 	__u8	 data[0];
1335 } __packed;
1336 
1337 /* Internal events generated by Bluetooth stack */
1338 #define HCI_EV_STACK_INTERNAL	0xfd
1339 struct hci_ev_stack_internal {
1340 	__u16    type;
1341 	__u8     data[0];
1342 } __packed;
1343 
1344 #define HCI_EV_SI_DEVICE	0x01
1345 struct hci_ev_si_device {
1346 	__u16    event;
1347 	__u16    dev_id;
1348 } __packed;
1349 
1350 #define HCI_EV_SI_SECURITY	0x02
1351 struct hci_ev_si_security {
1352 	__u16    event;
1353 	__u16    proto;
1354 	__u16    subproto;
1355 	__u8     incoming;
1356 } __packed;
1357 
1358 /* ---- HCI Packet structures ---- */
1359 #define HCI_COMMAND_HDR_SIZE 3
1360 #define HCI_EVENT_HDR_SIZE   2
1361 #define HCI_ACL_HDR_SIZE     4
1362 #define HCI_SCO_HDR_SIZE     3
1363 
1364 struct hci_command_hdr {
1365 	__le16	opcode;		/* OCF & OGF */
1366 	__u8	plen;
1367 } __packed;
1368 
1369 struct hci_event_hdr {
1370 	__u8	evt;
1371 	__u8	plen;
1372 } __packed;
1373 
1374 struct hci_acl_hdr {
1375 	__le16	handle;		/* Handle & Flags(PB, BC) */
1376 	__le16	dlen;
1377 } __packed;
1378 
1379 struct hci_sco_hdr {
1380 	__le16	handle;
1381 	__u8	dlen;
1382 } __packed;
1383 
1384 static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb)
1385 {
1386 	return (struct hci_event_hdr *) skb->data;
1387 }
1388 
1389 static inline struct hci_acl_hdr *hci_acl_hdr(const struct sk_buff *skb)
1390 {
1391 	return (struct hci_acl_hdr *) skb->data;
1392 }
1393 
1394 static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb)
1395 {
1396 	return (struct hci_sco_hdr *) skb->data;
1397 }
1398 
1399 /* Command opcode pack/unpack */
1400 #define hci_opcode_pack(ogf, ocf)	((__u16) ((ocf & 0x03ff)|(ogf << 10)))
1401 #define hci_opcode_ogf(op)		(op >> 10)
1402 #define hci_opcode_ocf(op)		(op & 0x03ff)
1403 
1404 /* ACL handle and flags pack/unpack */
1405 #define hci_handle_pack(h, f)	((__u16) ((h & 0x0fff)|(f << 12)))
1406 #define hci_handle(h)		(h & 0x0fff)
1407 #define hci_flags(h)		(h >> 12)
1408 
1409 /* ---- HCI Sockets ---- */
1410 
1411 /* Socket options */
1412 #define HCI_DATA_DIR	1
1413 #define HCI_FILTER	2
1414 #define HCI_TIME_STAMP	3
1415 
1416 /* CMSG flags */
1417 #define HCI_CMSG_DIR	0x0001
1418 #define HCI_CMSG_TSTAMP	0x0002
1419 
1420 struct sockaddr_hci {
1421 	sa_family_t    hci_family;
1422 	unsigned short hci_dev;
1423 	unsigned short hci_channel;
1424 };
1425 #define HCI_DEV_NONE	0xffff
1426 
1427 #define HCI_CHANNEL_RAW		0
1428 #define HCI_CHANNEL_MONITOR	2
1429 #define HCI_CHANNEL_CONTROL	3
1430 
1431 struct hci_filter {
1432 	unsigned long type_mask;
1433 	unsigned long event_mask[2];
1434 	__le16 opcode;
1435 };
1436 
1437 struct hci_ufilter {
1438 	__u32  type_mask;
1439 	__u32  event_mask[2];
1440 	__le16 opcode;
1441 };
1442 
1443 #define HCI_FLT_TYPE_BITS	31
1444 #define HCI_FLT_EVENT_BITS	63
1445 #define HCI_FLT_OGF_BITS	63
1446 #define HCI_FLT_OCF_BITS	127
1447 
1448 /* ---- HCI Ioctl requests structures ---- */
1449 struct hci_dev_stats {
1450 	__u32 err_rx;
1451 	__u32 err_tx;
1452 	__u32 cmd_tx;
1453 	__u32 evt_rx;
1454 	__u32 acl_tx;
1455 	__u32 acl_rx;
1456 	__u32 sco_tx;
1457 	__u32 sco_rx;
1458 	__u32 byte_rx;
1459 	__u32 byte_tx;
1460 };
1461 
1462 struct hci_dev_info {
1463 	__u16 dev_id;
1464 	char  name[8];
1465 
1466 	bdaddr_t bdaddr;
1467 
1468 	__u32 flags;
1469 	__u8  type;
1470 
1471 	__u8  features[8];
1472 
1473 	__u32 pkt_type;
1474 	__u32 link_policy;
1475 	__u32 link_mode;
1476 
1477 	__u16 acl_mtu;
1478 	__u16 acl_pkts;
1479 	__u16 sco_mtu;
1480 	__u16 sco_pkts;
1481 
1482 	struct hci_dev_stats stat;
1483 };
1484 
1485 struct hci_conn_info {
1486 	__u16    handle;
1487 	bdaddr_t bdaddr;
1488 	__u8     type;
1489 	__u8     out;
1490 	__u16    state;
1491 	__u32    link_mode;
1492 };
1493 
1494 struct hci_dev_req {
1495 	__u16  dev_id;
1496 	__u32  dev_opt;
1497 };
1498 
1499 struct hci_dev_list_req {
1500 	__u16  dev_num;
1501 	struct hci_dev_req dev_req[0];	/* hci_dev_req structures */
1502 };
1503 
1504 struct hci_conn_list_req {
1505 	__u16  dev_id;
1506 	__u16  conn_num;
1507 	struct hci_conn_info conn_info[0];
1508 };
1509 
1510 struct hci_conn_info_req {
1511 	bdaddr_t bdaddr;
1512 	__u8     type;
1513 	struct   hci_conn_info conn_info[0];
1514 };
1515 
1516 struct hci_auth_info_req {
1517 	bdaddr_t bdaddr;
1518 	__u8     type;
1519 };
1520 
1521 struct hci_inquiry_req {
1522 	__u16 dev_id;
1523 	__u16 flags;
1524 	__u8  lap[3];
1525 	__u8  length;
1526 	__u8  num_rsp;
1527 };
1528 #define IREQ_CACHE_FLUSH 0x0001
1529 
1530 extern bool enable_hs;
1531 
1532 #endif /* __HCI_H */
1533