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 /* HCI dev events */ 34 #define HCI_DEV_REG 1 35 #define HCI_DEV_UNREG 2 36 #define HCI_DEV_UP 3 37 #define HCI_DEV_DOWN 4 38 #define HCI_DEV_SUSPEND 5 39 #define HCI_DEV_RESUME 6 40 41 /* HCI notify events */ 42 #define HCI_NOTIFY_CONN_ADD 1 43 #define HCI_NOTIFY_CONN_DEL 2 44 #define HCI_NOTIFY_VOICE_SETTING 3 45 46 /* HCI bus types */ 47 #define HCI_VIRTUAL 0 48 #define HCI_USB 1 49 #define HCI_PCCARD 2 50 #define HCI_UART 3 51 #define HCI_RS232 4 52 #define HCI_PCI 5 53 #define HCI_SDIO 6 54 55 /* HCI controller types */ 56 #define HCI_BREDR 0x00 57 #define HCI_AMP 0x01 58 59 /* HCI device quirks */ 60 enum { 61 HCI_QUIRK_NO_RESET, 62 HCI_QUIRK_RAW_DEVICE, 63 HCI_QUIRK_FIXUP_BUFFER_SIZE 64 }; 65 66 /* HCI device flags */ 67 enum { 68 HCI_UP, 69 HCI_INIT, 70 HCI_RUNNING, 71 72 HCI_PSCAN, 73 HCI_ISCAN, 74 HCI_AUTH, 75 HCI_ENCRYPT, 76 HCI_INQUIRY, 77 78 HCI_RAW, 79 80 HCI_SETUP, 81 HCI_AUTO_OFF, 82 HCI_MGMT, 83 HCI_PAIRABLE, 84 HCI_SERVICE_CACHE, 85 HCI_LINK_KEYS, 86 HCI_DEBUG_KEYS, 87 }; 88 89 /* HCI ioctl defines */ 90 #define HCIDEVUP _IOW('H', 201, int) 91 #define HCIDEVDOWN _IOW('H', 202, int) 92 #define HCIDEVRESET _IOW('H', 203, int) 93 #define HCIDEVRESTAT _IOW('H', 204, int) 94 95 #define HCIGETDEVLIST _IOR('H', 210, int) 96 #define HCIGETDEVINFO _IOR('H', 211, int) 97 #define HCIGETCONNLIST _IOR('H', 212, int) 98 #define HCIGETCONNINFO _IOR('H', 213, int) 99 #define HCIGETAUTHINFO _IOR('H', 215, int) 100 101 #define HCISETRAW _IOW('H', 220, int) 102 #define HCISETSCAN _IOW('H', 221, int) 103 #define HCISETAUTH _IOW('H', 222, int) 104 #define HCISETENCRYPT _IOW('H', 223, int) 105 #define HCISETPTYPE _IOW('H', 224, int) 106 #define HCISETLINKPOL _IOW('H', 225, int) 107 #define HCISETLINKMODE _IOW('H', 226, int) 108 #define HCISETACLMTU _IOW('H', 227, int) 109 #define HCISETSCOMTU _IOW('H', 228, int) 110 111 #define HCIBLOCKADDR _IOW('H', 230, int) 112 #define HCIUNBLOCKADDR _IOW('H', 231, int) 113 114 #define HCIINQUIRY _IOR('H', 240, int) 115 116 /* HCI timeouts */ 117 #define HCI_CONNECT_TIMEOUT (40000) /* 40 seconds */ 118 #define HCI_DISCONN_TIMEOUT (2000) /* 2 seconds */ 119 #define HCI_PAIRING_TIMEOUT (60000) /* 60 seconds */ 120 #define HCI_IDLE_TIMEOUT (6000) /* 6 seconds */ 121 #define HCI_INIT_TIMEOUT (10000) /* 10 seconds */ 122 123 /* HCI data types */ 124 #define HCI_COMMAND_PKT 0x01 125 #define HCI_ACLDATA_PKT 0x02 126 #define HCI_SCODATA_PKT 0x03 127 #define HCI_EVENT_PKT 0x04 128 #define HCI_VENDOR_PKT 0xff 129 130 /* HCI packet types */ 131 #define HCI_DM1 0x0008 132 #define HCI_DM3 0x0400 133 #define HCI_DM5 0x4000 134 #define HCI_DH1 0x0010 135 #define HCI_DH3 0x0800 136 #define HCI_DH5 0x8000 137 138 #define HCI_HV1 0x0020 139 #define HCI_HV2 0x0040 140 #define HCI_HV3 0x0080 141 142 #define SCO_PTYPE_MASK (HCI_HV1 | HCI_HV2 | HCI_HV3) 143 #define ACL_PTYPE_MASK (~SCO_PTYPE_MASK) 144 145 /* eSCO packet types */ 146 #define ESCO_HV1 0x0001 147 #define ESCO_HV2 0x0002 148 #define ESCO_HV3 0x0004 149 #define ESCO_EV3 0x0008 150 #define ESCO_EV4 0x0010 151 #define ESCO_EV5 0x0020 152 #define ESCO_2EV3 0x0040 153 #define ESCO_3EV3 0x0080 154 #define ESCO_2EV5 0x0100 155 #define ESCO_3EV5 0x0200 156 157 #define SCO_ESCO_MASK (ESCO_HV1 | ESCO_HV2 | ESCO_HV3) 158 #define EDR_ESCO_MASK (ESCO_2EV3 | ESCO_3EV3 | ESCO_2EV5 | ESCO_3EV5) 159 160 /* ACL flags */ 161 #define ACL_START_NO_FLUSH 0x00 162 #define ACL_CONT 0x01 163 #define ACL_START 0x02 164 #define ACL_ACTIVE_BCAST 0x04 165 #define ACL_PICO_BCAST 0x08 166 167 /* Baseband links */ 168 #define SCO_LINK 0x00 169 #define ACL_LINK 0x01 170 #define ESCO_LINK 0x02 171 /* Low Energy links do not have defined link type. Use invented one */ 172 #define LE_LINK 0x80 173 174 /* LMP features */ 175 #define LMP_3SLOT 0x01 176 #define LMP_5SLOT 0x02 177 #define LMP_ENCRYPT 0x04 178 #define LMP_SOFFSET 0x08 179 #define LMP_TACCURACY 0x10 180 #define LMP_RSWITCH 0x20 181 #define LMP_HOLD 0x40 182 #define LMP_SNIFF 0x80 183 184 #define LMP_PARK 0x01 185 #define LMP_RSSI 0x02 186 #define LMP_QUALITY 0x04 187 #define LMP_SCO 0x08 188 #define LMP_HV2 0x10 189 #define LMP_HV3 0x20 190 #define LMP_ULAW 0x40 191 #define LMP_ALAW 0x80 192 193 #define LMP_CVSD 0x01 194 #define LMP_PSCHEME 0x02 195 #define LMP_PCONTROL 0x04 196 197 #define LMP_RSSI_INQ 0x40 198 #define LMP_ESCO 0x80 199 200 #define LMP_EV4 0x01 201 #define LMP_EV5 0x02 202 #define LMP_LE 0x40 203 204 #define LMP_SNIFF_SUBR 0x02 205 #define LMP_PAUSE_ENC 0x04 206 #define LMP_EDR_ESCO_2M 0x20 207 #define LMP_EDR_ESCO_3M 0x40 208 #define LMP_EDR_3S_ESCO 0x80 209 210 #define LMP_EXT_INQ 0x01 211 #define LMP_SIMPLE_PAIR 0x08 212 #define LMP_NO_FLUSH 0x40 213 214 #define LMP_LSTO 0x01 215 #define LMP_INQ_TX_PWR 0x02 216 217 /* Connection modes */ 218 #define HCI_CM_ACTIVE 0x0000 219 #define HCI_CM_HOLD 0x0001 220 #define HCI_CM_SNIFF 0x0002 221 #define HCI_CM_PARK 0x0003 222 223 /* Link policies */ 224 #define HCI_LP_RSWITCH 0x0001 225 #define HCI_LP_HOLD 0x0002 226 #define HCI_LP_SNIFF 0x0004 227 #define HCI_LP_PARK 0x0008 228 229 /* Link modes */ 230 #define HCI_LM_ACCEPT 0x8000 231 #define HCI_LM_MASTER 0x0001 232 #define HCI_LM_AUTH 0x0002 233 #define HCI_LM_ENCRYPT 0x0004 234 #define HCI_LM_TRUSTED 0x0008 235 #define HCI_LM_RELIABLE 0x0010 236 #define HCI_LM_SECURE 0x0020 237 238 /* Authentication types */ 239 #define HCI_AT_NO_BONDING 0x00 240 #define HCI_AT_NO_BONDING_MITM 0x01 241 #define HCI_AT_DEDICATED_BONDING 0x02 242 #define HCI_AT_DEDICATED_BONDING_MITM 0x03 243 #define HCI_AT_GENERAL_BONDING 0x04 244 #define HCI_AT_GENERAL_BONDING_MITM 0x05 245 246 /* ----- HCI Commands ---- */ 247 #define HCI_OP_INQUIRY 0x0401 248 struct hci_cp_inquiry { 249 __u8 lap[3]; 250 __u8 length; 251 __u8 num_rsp; 252 } __packed; 253 254 #define HCI_OP_INQUIRY_CANCEL 0x0402 255 256 #define HCI_OP_EXIT_PERIODIC_INQ 0x0404 257 258 #define HCI_OP_CREATE_CONN 0x0405 259 struct hci_cp_create_conn { 260 bdaddr_t bdaddr; 261 __le16 pkt_type; 262 __u8 pscan_rep_mode; 263 __u8 pscan_mode; 264 __le16 clock_offset; 265 __u8 role_switch; 266 } __packed; 267 268 #define HCI_OP_DISCONNECT 0x0406 269 struct hci_cp_disconnect { 270 __le16 handle; 271 __u8 reason; 272 } __packed; 273 274 #define HCI_OP_ADD_SCO 0x0407 275 struct hci_cp_add_sco { 276 __le16 handle; 277 __le16 pkt_type; 278 } __packed; 279 280 #define HCI_OP_CREATE_CONN_CANCEL 0x0408 281 struct hci_cp_create_conn_cancel { 282 bdaddr_t bdaddr; 283 } __packed; 284 285 #define HCI_OP_ACCEPT_CONN_REQ 0x0409 286 struct hci_cp_accept_conn_req { 287 bdaddr_t bdaddr; 288 __u8 role; 289 } __packed; 290 291 #define HCI_OP_REJECT_CONN_REQ 0x040a 292 struct hci_cp_reject_conn_req { 293 bdaddr_t bdaddr; 294 __u8 reason; 295 } __packed; 296 297 #define HCI_OP_LINK_KEY_REPLY 0x040b 298 struct hci_cp_link_key_reply { 299 bdaddr_t bdaddr; 300 __u8 link_key[16]; 301 } __packed; 302 303 #define HCI_OP_LINK_KEY_NEG_REPLY 0x040c 304 struct hci_cp_link_key_neg_reply { 305 bdaddr_t bdaddr; 306 } __packed; 307 308 #define HCI_OP_PIN_CODE_REPLY 0x040d 309 struct hci_cp_pin_code_reply { 310 bdaddr_t bdaddr; 311 __u8 pin_len; 312 __u8 pin_code[16]; 313 } __packed; 314 struct hci_rp_pin_code_reply { 315 __u8 status; 316 bdaddr_t bdaddr; 317 } __packed; 318 319 #define HCI_OP_PIN_CODE_NEG_REPLY 0x040e 320 struct hci_cp_pin_code_neg_reply { 321 bdaddr_t bdaddr; 322 } __packed; 323 struct hci_rp_pin_code_neg_reply { 324 __u8 status; 325 bdaddr_t bdaddr; 326 } __packed; 327 328 #define HCI_OP_CHANGE_CONN_PTYPE 0x040f 329 struct hci_cp_change_conn_ptype { 330 __le16 handle; 331 __le16 pkt_type; 332 } __packed; 333 334 #define HCI_OP_AUTH_REQUESTED 0x0411 335 struct hci_cp_auth_requested { 336 __le16 handle; 337 } __packed; 338 339 #define HCI_OP_SET_CONN_ENCRYPT 0x0413 340 struct hci_cp_set_conn_encrypt { 341 __le16 handle; 342 __u8 encrypt; 343 } __packed; 344 345 #define HCI_OP_CHANGE_CONN_LINK_KEY 0x0415 346 struct hci_cp_change_conn_link_key { 347 __le16 handle; 348 } __packed; 349 350 #define HCI_OP_REMOTE_NAME_REQ 0x0419 351 struct hci_cp_remote_name_req { 352 bdaddr_t bdaddr; 353 __u8 pscan_rep_mode; 354 __u8 pscan_mode; 355 __le16 clock_offset; 356 } __packed; 357 358 #define HCI_OP_REMOTE_NAME_REQ_CANCEL 0x041a 359 struct hci_cp_remote_name_req_cancel { 360 bdaddr_t bdaddr; 361 } __packed; 362 363 #define HCI_OP_READ_REMOTE_FEATURES 0x041b 364 struct hci_cp_read_remote_features { 365 __le16 handle; 366 } __packed; 367 368 #define HCI_OP_READ_REMOTE_EXT_FEATURES 0x041c 369 struct hci_cp_read_remote_ext_features { 370 __le16 handle; 371 __u8 page; 372 } __packed; 373 374 #define HCI_OP_READ_REMOTE_VERSION 0x041d 375 struct hci_cp_read_remote_version { 376 __le16 handle; 377 } __packed; 378 379 #define HCI_OP_SETUP_SYNC_CONN 0x0428 380 struct hci_cp_setup_sync_conn { 381 __le16 handle; 382 __le32 tx_bandwidth; 383 __le32 rx_bandwidth; 384 __le16 max_latency; 385 __le16 voice_setting; 386 __u8 retrans_effort; 387 __le16 pkt_type; 388 } __packed; 389 390 #define HCI_OP_ACCEPT_SYNC_CONN_REQ 0x0429 391 struct hci_cp_accept_sync_conn_req { 392 bdaddr_t bdaddr; 393 __le32 tx_bandwidth; 394 __le32 rx_bandwidth; 395 __le16 max_latency; 396 __le16 content_format; 397 __u8 retrans_effort; 398 __le16 pkt_type; 399 } __packed; 400 401 #define HCI_OP_REJECT_SYNC_CONN_REQ 0x042a 402 struct hci_cp_reject_sync_conn_req { 403 bdaddr_t bdaddr; 404 __u8 reason; 405 } __packed; 406 407 #define HCI_OP_IO_CAPABILITY_REPLY 0x042b 408 struct hci_cp_io_capability_reply { 409 bdaddr_t bdaddr; 410 __u8 capability; 411 __u8 oob_data; 412 __u8 authentication; 413 } __packed; 414 415 #define HCI_OP_IO_CAPABILITY_NEG_REPLY 0x0434 416 struct hci_cp_io_capability_neg_reply { 417 bdaddr_t bdaddr; 418 __u8 reason; 419 } __packed; 420 421 #define HCI_OP_SNIFF_MODE 0x0803 422 struct hci_cp_sniff_mode { 423 __le16 handle; 424 __le16 max_interval; 425 __le16 min_interval; 426 __le16 attempt; 427 __le16 timeout; 428 } __packed; 429 430 #define HCI_OP_EXIT_SNIFF_MODE 0x0804 431 struct hci_cp_exit_sniff_mode { 432 __le16 handle; 433 } __packed; 434 435 #define HCI_OP_ROLE_DISCOVERY 0x0809 436 struct hci_cp_role_discovery { 437 __le16 handle; 438 } __packed; 439 struct hci_rp_role_discovery { 440 __u8 status; 441 __le16 handle; 442 __u8 role; 443 } __packed; 444 445 #define HCI_OP_SWITCH_ROLE 0x080b 446 struct hci_cp_switch_role { 447 bdaddr_t bdaddr; 448 __u8 role; 449 } __packed; 450 451 #define HCI_OP_READ_LINK_POLICY 0x080c 452 struct hci_cp_read_link_policy { 453 __le16 handle; 454 } __packed; 455 struct hci_rp_read_link_policy { 456 __u8 status; 457 __le16 handle; 458 __le16 policy; 459 } __packed; 460 461 #define HCI_OP_WRITE_LINK_POLICY 0x080d 462 struct hci_cp_write_link_policy { 463 __le16 handle; 464 __le16 policy; 465 } __packed; 466 struct hci_rp_write_link_policy { 467 __u8 status; 468 __le16 handle; 469 } __packed; 470 471 #define HCI_OP_READ_DEF_LINK_POLICY 0x080e 472 struct hci_rp_read_def_link_policy { 473 __u8 status; 474 __le16 policy; 475 } __packed; 476 477 #define HCI_OP_WRITE_DEF_LINK_POLICY 0x080f 478 struct hci_cp_write_def_link_policy { 479 __le16 policy; 480 } __packed; 481 482 #define HCI_OP_SNIFF_SUBRATE 0x0811 483 struct hci_cp_sniff_subrate { 484 __le16 handle; 485 __le16 max_latency; 486 __le16 min_remote_timeout; 487 __le16 min_local_timeout; 488 } __packed; 489 490 #define HCI_OP_SET_EVENT_MASK 0x0c01 491 struct hci_cp_set_event_mask { 492 __u8 mask[8]; 493 } __packed; 494 495 #define HCI_OP_RESET 0x0c03 496 497 #define HCI_OP_SET_EVENT_FLT 0x0c05 498 struct hci_cp_set_event_flt { 499 __u8 flt_type; 500 __u8 cond_type; 501 __u8 condition[0]; 502 } __packed; 503 504 /* Filter types */ 505 #define HCI_FLT_CLEAR_ALL 0x00 506 #define HCI_FLT_INQ_RESULT 0x01 507 #define HCI_FLT_CONN_SETUP 0x02 508 509 /* CONN_SETUP Condition types */ 510 #define HCI_CONN_SETUP_ALLOW_ALL 0x00 511 #define HCI_CONN_SETUP_ALLOW_CLASS 0x01 512 #define HCI_CONN_SETUP_ALLOW_BDADDR 0x02 513 514 /* CONN_SETUP Conditions */ 515 #define HCI_CONN_SETUP_AUTO_OFF 0x01 516 #define HCI_CONN_SETUP_AUTO_ON 0x02 517 518 #define HCI_OP_DELETE_STORED_LINK_KEY 0x0c12 519 struct hci_cp_delete_stored_link_key { 520 bdaddr_t bdaddr; 521 __u8 delete_all; 522 } __packed; 523 524 #define HCI_OP_WRITE_LOCAL_NAME 0x0c13 525 struct hci_cp_write_local_name { 526 __u8 name[248]; 527 } __packed; 528 529 #define HCI_OP_READ_LOCAL_NAME 0x0c14 530 struct hci_rp_read_local_name { 531 __u8 status; 532 __u8 name[248]; 533 } __packed; 534 535 #define HCI_OP_WRITE_CA_TIMEOUT 0x0c16 536 537 #define HCI_OP_WRITE_PG_TIMEOUT 0x0c18 538 539 #define HCI_OP_WRITE_SCAN_ENABLE 0x0c1a 540 #define SCAN_DISABLED 0x00 541 #define SCAN_INQUIRY 0x01 542 #define SCAN_PAGE 0x02 543 544 #define HCI_OP_READ_AUTH_ENABLE 0x0c1f 545 546 #define HCI_OP_WRITE_AUTH_ENABLE 0x0c20 547 #define AUTH_DISABLED 0x00 548 #define AUTH_ENABLED 0x01 549 550 #define HCI_OP_READ_ENCRYPT_MODE 0x0c21 551 552 #define HCI_OP_WRITE_ENCRYPT_MODE 0x0c22 553 #define ENCRYPT_DISABLED 0x00 554 #define ENCRYPT_P2P 0x01 555 #define ENCRYPT_BOTH 0x02 556 557 #define HCI_OP_READ_CLASS_OF_DEV 0x0c23 558 struct hci_rp_read_class_of_dev { 559 __u8 status; 560 __u8 dev_class[3]; 561 } __packed; 562 563 #define HCI_OP_WRITE_CLASS_OF_DEV 0x0c24 564 struct hci_cp_write_class_of_dev { 565 __u8 dev_class[3]; 566 } __packed; 567 568 #define HCI_OP_READ_VOICE_SETTING 0x0c25 569 struct hci_rp_read_voice_setting { 570 __u8 status; 571 __le16 voice_setting; 572 } __packed; 573 574 #define HCI_OP_WRITE_VOICE_SETTING 0x0c26 575 struct hci_cp_write_voice_setting { 576 __le16 voice_setting; 577 } __packed; 578 579 #define HCI_OP_HOST_BUFFER_SIZE 0x0c33 580 struct hci_cp_host_buffer_size { 581 __le16 acl_mtu; 582 __u8 sco_mtu; 583 __le16 acl_max_pkt; 584 __le16 sco_max_pkt; 585 } __packed; 586 587 #define HCI_OP_WRITE_INQUIRY_MODE 0x0c45 588 589 #define HCI_OP_READ_SSP_MODE 0x0c55 590 struct hci_rp_read_ssp_mode { 591 __u8 status; 592 __u8 mode; 593 } __packed; 594 595 #define HCI_OP_WRITE_SSP_MODE 0x0c56 596 struct hci_cp_write_ssp_mode { 597 __u8 mode; 598 } __packed; 599 600 #define HCI_OP_READ_INQ_RSP_TX_POWER 0x0c58 601 602 #define HCI_OP_READ_LOCAL_VERSION 0x1001 603 struct hci_rp_read_local_version { 604 __u8 status; 605 __u8 hci_ver; 606 __le16 hci_rev; 607 __u8 lmp_ver; 608 __le16 manufacturer; 609 __le16 lmp_subver; 610 } __packed; 611 612 #define HCI_OP_READ_LOCAL_COMMANDS 0x1002 613 struct hci_rp_read_local_commands { 614 __u8 status; 615 __u8 commands[64]; 616 } __packed; 617 618 #define HCI_OP_READ_LOCAL_FEATURES 0x1003 619 struct hci_rp_read_local_features { 620 __u8 status; 621 __u8 features[8]; 622 } __packed; 623 624 #define HCI_OP_READ_LOCAL_EXT_FEATURES 0x1004 625 struct hci_rp_read_local_ext_features { 626 __u8 status; 627 __u8 page; 628 __u8 max_page; 629 __u8 features[8]; 630 } __packed; 631 632 #define HCI_OP_READ_BUFFER_SIZE 0x1005 633 struct hci_rp_read_buffer_size { 634 __u8 status; 635 __le16 acl_mtu; 636 __u8 sco_mtu; 637 __le16 acl_max_pkt; 638 __le16 sco_max_pkt; 639 } __packed; 640 641 #define HCI_OP_READ_BD_ADDR 0x1009 642 struct hci_rp_read_bd_addr { 643 __u8 status; 644 bdaddr_t bdaddr; 645 } __packed; 646 647 #define HCI_OP_LE_SET_EVENT_MASK 0x2001 648 struct hci_cp_le_set_event_mask { 649 __u8 mask[8]; 650 } __packed; 651 652 #define HCI_OP_LE_READ_BUFFER_SIZE 0x2002 653 struct hci_rp_le_read_buffer_size { 654 __u8 status; 655 __le16 le_mtu; 656 __u8 le_max_pkt; 657 } __packed; 658 659 #define HCI_OP_LE_CREATE_CONN 0x200d 660 struct hci_cp_le_create_conn { 661 __le16 scan_interval; 662 __le16 scan_window; 663 __u8 filter_policy; 664 __u8 peer_addr_type; 665 bdaddr_t peer_addr; 666 __u8 own_address_type; 667 __le16 conn_interval_min; 668 __le16 conn_interval_max; 669 __le16 conn_latency; 670 __le16 supervision_timeout; 671 __le16 min_ce_len; 672 __le16 max_ce_len; 673 } __packed; 674 675 #define HCI_OP_LE_CREATE_CONN_CANCEL 0x200e 676 677 /* ---- HCI Events ---- */ 678 #define HCI_EV_INQUIRY_COMPLETE 0x01 679 680 #define HCI_EV_INQUIRY_RESULT 0x02 681 struct inquiry_info { 682 bdaddr_t bdaddr; 683 __u8 pscan_rep_mode; 684 __u8 pscan_period_mode; 685 __u8 pscan_mode; 686 __u8 dev_class[3]; 687 __le16 clock_offset; 688 } __packed; 689 690 #define HCI_EV_CONN_COMPLETE 0x03 691 struct hci_ev_conn_complete { 692 __u8 status; 693 __le16 handle; 694 bdaddr_t bdaddr; 695 __u8 link_type; 696 __u8 encr_mode; 697 } __packed; 698 699 #define HCI_EV_CONN_REQUEST 0x04 700 struct hci_ev_conn_request { 701 bdaddr_t bdaddr; 702 __u8 dev_class[3]; 703 __u8 link_type; 704 } __packed; 705 706 #define HCI_EV_DISCONN_COMPLETE 0x05 707 struct hci_ev_disconn_complete { 708 __u8 status; 709 __le16 handle; 710 __u8 reason; 711 } __packed; 712 713 #define HCI_EV_AUTH_COMPLETE 0x06 714 struct hci_ev_auth_complete { 715 __u8 status; 716 __le16 handle; 717 } __packed; 718 719 #define HCI_EV_REMOTE_NAME 0x07 720 struct hci_ev_remote_name { 721 __u8 status; 722 bdaddr_t bdaddr; 723 __u8 name[248]; 724 } __packed; 725 726 #define HCI_EV_ENCRYPT_CHANGE 0x08 727 struct hci_ev_encrypt_change { 728 __u8 status; 729 __le16 handle; 730 __u8 encrypt; 731 } __packed; 732 733 #define HCI_EV_CHANGE_LINK_KEY_COMPLETE 0x09 734 struct hci_ev_change_link_key_complete { 735 __u8 status; 736 __le16 handle; 737 } __packed; 738 739 #define HCI_EV_REMOTE_FEATURES 0x0b 740 struct hci_ev_remote_features { 741 __u8 status; 742 __le16 handle; 743 __u8 features[8]; 744 } __packed; 745 746 #define HCI_EV_REMOTE_VERSION 0x0c 747 struct hci_ev_remote_version { 748 __u8 status; 749 __le16 handle; 750 __u8 lmp_ver; 751 __le16 manufacturer; 752 __le16 lmp_subver; 753 } __packed; 754 755 #define HCI_EV_QOS_SETUP_COMPLETE 0x0d 756 struct hci_qos { 757 __u8 service_type; 758 __u32 token_rate; 759 __u32 peak_bandwidth; 760 __u32 latency; 761 __u32 delay_variation; 762 } __packed; 763 struct hci_ev_qos_setup_complete { 764 __u8 status; 765 __le16 handle; 766 struct hci_qos qos; 767 } __packed; 768 769 #define HCI_EV_CMD_COMPLETE 0x0e 770 struct hci_ev_cmd_complete { 771 __u8 ncmd; 772 __le16 opcode; 773 } __packed; 774 775 #define HCI_EV_CMD_STATUS 0x0f 776 struct hci_ev_cmd_status { 777 __u8 status; 778 __u8 ncmd; 779 __le16 opcode; 780 } __packed; 781 782 #define HCI_EV_ROLE_CHANGE 0x12 783 struct hci_ev_role_change { 784 __u8 status; 785 bdaddr_t bdaddr; 786 __u8 role; 787 } __packed; 788 789 #define HCI_EV_NUM_COMP_PKTS 0x13 790 struct hci_ev_num_comp_pkts { 791 __u8 num_hndl; 792 /* variable length part */ 793 } __packed; 794 795 #define HCI_EV_MODE_CHANGE 0x14 796 struct hci_ev_mode_change { 797 __u8 status; 798 __le16 handle; 799 __u8 mode; 800 __le16 interval; 801 } __packed; 802 803 #define HCI_EV_PIN_CODE_REQ 0x16 804 struct hci_ev_pin_code_req { 805 bdaddr_t bdaddr; 806 } __packed; 807 808 #define HCI_EV_LINK_KEY_REQ 0x17 809 struct hci_ev_link_key_req { 810 bdaddr_t bdaddr; 811 } __packed; 812 813 #define HCI_EV_LINK_KEY_NOTIFY 0x18 814 struct hci_ev_link_key_notify { 815 bdaddr_t bdaddr; 816 __u8 link_key[16]; 817 __u8 key_type; 818 } __packed; 819 820 #define HCI_EV_CLOCK_OFFSET 0x1c 821 struct hci_ev_clock_offset { 822 __u8 status; 823 __le16 handle; 824 __le16 clock_offset; 825 } __packed; 826 827 #define HCI_EV_PKT_TYPE_CHANGE 0x1d 828 struct hci_ev_pkt_type_change { 829 __u8 status; 830 __le16 handle; 831 __le16 pkt_type; 832 } __packed; 833 834 #define HCI_EV_PSCAN_REP_MODE 0x20 835 struct hci_ev_pscan_rep_mode { 836 bdaddr_t bdaddr; 837 __u8 pscan_rep_mode; 838 } __packed; 839 840 #define HCI_EV_INQUIRY_RESULT_WITH_RSSI 0x22 841 struct inquiry_info_with_rssi { 842 bdaddr_t bdaddr; 843 __u8 pscan_rep_mode; 844 __u8 pscan_period_mode; 845 __u8 dev_class[3]; 846 __le16 clock_offset; 847 __s8 rssi; 848 } __packed; 849 struct inquiry_info_with_rssi_and_pscan_mode { 850 bdaddr_t bdaddr; 851 __u8 pscan_rep_mode; 852 __u8 pscan_period_mode; 853 __u8 pscan_mode; 854 __u8 dev_class[3]; 855 __le16 clock_offset; 856 __s8 rssi; 857 } __packed; 858 859 #define HCI_EV_REMOTE_EXT_FEATURES 0x23 860 struct hci_ev_remote_ext_features { 861 __u8 status; 862 __le16 handle; 863 __u8 page; 864 __u8 max_page; 865 __u8 features[8]; 866 } __packed; 867 868 #define HCI_EV_SYNC_CONN_COMPLETE 0x2c 869 struct hci_ev_sync_conn_complete { 870 __u8 status; 871 __le16 handle; 872 bdaddr_t bdaddr; 873 __u8 link_type; 874 __u8 tx_interval; 875 __u8 retrans_window; 876 __le16 rx_pkt_len; 877 __le16 tx_pkt_len; 878 __u8 air_mode; 879 } __packed; 880 881 #define HCI_EV_SYNC_CONN_CHANGED 0x2d 882 struct hci_ev_sync_conn_changed { 883 __u8 status; 884 __le16 handle; 885 __u8 tx_interval; 886 __u8 retrans_window; 887 __le16 rx_pkt_len; 888 __le16 tx_pkt_len; 889 } __packed; 890 891 #define HCI_EV_SNIFF_SUBRATE 0x2e 892 struct hci_ev_sniff_subrate { 893 __u8 status; 894 __le16 handle; 895 __le16 max_tx_latency; 896 __le16 max_rx_latency; 897 __le16 max_remote_timeout; 898 __le16 max_local_timeout; 899 } __packed; 900 901 #define HCI_EV_EXTENDED_INQUIRY_RESULT 0x2f 902 struct extended_inquiry_info { 903 bdaddr_t bdaddr; 904 __u8 pscan_rep_mode; 905 __u8 pscan_period_mode; 906 __u8 dev_class[3]; 907 __le16 clock_offset; 908 __s8 rssi; 909 __u8 data[240]; 910 } __packed; 911 912 #define HCI_EV_IO_CAPA_REQUEST 0x31 913 struct hci_ev_io_capa_request { 914 bdaddr_t bdaddr; 915 } __packed; 916 917 #define HCI_EV_IO_CAPA_REPLY 0x32 918 struct hci_ev_io_capa_reply { 919 bdaddr_t bdaddr; 920 __u8 capability; 921 __u8 oob_data; 922 __u8 authentication; 923 } __packed; 924 925 #define HCI_EV_SIMPLE_PAIR_COMPLETE 0x36 926 struct hci_ev_simple_pair_complete { 927 __u8 status; 928 bdaddr_t bdaddr; 929 } __packed; 930 931 #define HCI_EV_REMOTE_HOST_FEATURES 0x3d 932 struct hci_ev_remote_host_features { 933 bdaddr_t bdaddr; 934 __u8 features[8]; 935 } __packed; 936 937 #define HCI_EV_LE_META 0x3e 938 struct hci_ev_le_meta { 939 __u8 subevent; 940 } __packed; 941 942 /* Low energy meta events */ 943 #define HCI_EV_LE_CONN_COMPLETE 0x01 944 struct hci_ev_le_conn_complete { 945 __u8 status; 946 __le16 handle; 947 __u8 role; 948 __u8 bdaddr_type; 949 bdaddr_t bdaddr; 950 __le16 interval; 951 __le16 latency; 952 __le16 supervision_timeout; 953 __u8 clk_accurancy; 954 } __packed; 955 956 /* Internal events generated by Bluetooth stack */ 957 #define HCI_EV_STACK_INTERNAL 0xfd 958 struct hci_ev_stack_internal { 959 __u16 type; 960 __u8 data[0]; 961 } __packed; 962 963 #define HCI_EV_SI_DEVICE 0x01 964 struct hci_ev_si_device { 965 __u16 event; 966 __u16 dev_id; 967 } __packed; 968 969 #define HCI_EV_SI_SECURITY 0x02 970 struct hci_ev_si_security { 971 __u16 event; 972 __u16 proto; 973 __u16 subproto; 974 __u8 incoming; 975 } __packed; 976 977 /* ---- HCI Packet structures ---- */ 978 #define HCI_COMMAND_HDR_SIZE 3 979 #define HCI_EVENT_HDR_SIZE 2 980 #define HCI_ACL_HDR_SIZE 4 981 #define HCI_SCO_HDR_SIZE 3 982 983 struct hci_command_hdr { 984 __le16 opcode; /* OCF & OGF */ 985 __u8 plen; 986 } __packed; 987 988 struct hci_event_hdr { 989 __u8 evt; 990 __u8 plen; 991 } __packed; 992 993 struct hci_acl_hdr { 994 __le16 handle; /* Handle & Flags(PB, BC) */ 995 __le16 dlen; 996 } __packed; 997 998 struct hci_sco_hdr { 999 __le16 handle; 1000 __u8 dlen; 1001 } __packed; 1002 1003 #ifdef __KERNEL__ 1004 #include <linux/skbuff.h> 1005 static inline struct hci_event_hdr *hci_event_hdr(const struct sk_buff *skb) 1006 { 1007 return (struct hci_event_hdr *) skb->data; 1008 } 1009 1010 static inline struct hci_acl_hdr *hci_acl_hdr(const struct sk_buff *skb) 1011 { 1012 return (struct hci_acl_hdr *) skb->data; 1013 } 1014 1015 static inline struct hci_sco_hdr *hci_sco_hdr(const struct sk_buff *skb) 1016 { 1017 return (struct hci_sco_hdr *) skb->data; 1018 } 1019 #endif 1020 1021 /* Command opcode pack/unpack */ 1022 #define hci_opcode_pack(ogf, ocf) (__u16) ((ocf & 0x03ff)|(ogf << 10)) 1023 #define hci_opcode_ogf(op) (op >> 10) 1024 #define hci_opcode_ocf(op) (op & 0x03ff) 1025 1026 /* ACL handle and flags pack/unpack */ 1027 #define hci_handle_pack(h, f) (__u16) ((h & 0x0fff)|(f << 12)) 1028 #define hci_handle(h) (h & 0x0fff) 1029 #define hci_flags(h) (h >> 12) 1030 1031 /* ---- HCI Sockets ---- */ 1032 1033 /* Socket options */ 1034 #define HCI_DATA_DIR 1 1035 #define HCI_FILTER 2 1036 #define HCI_TIME_STAMP 3 1037 1038 /* CMSG flags */ 1039 #define HCI_CMSG_DIR 0x0001 1040 #define HCI_CMSG_TSTAMP 0x0002 1041 1042 struct sockaddr_hci { 1043 sa_family_t hci_family; 1044 unsigned short hci_dev; 1045 unsigned short hci_channel; 1046 }; 1047 #define HCI_DEV_NONE 0xffff 1048 1049 #define HCI_CHANNEL_RAW 0 1050 #define HCI_CHANNEL_CONTROL 1 1051 1052 struct hci_filter { 1053 unsigned long type_mask; 1054 unsigned long event_mask[2]; 1055 __le16 opcode; 1056 }; 1057 1058 struct hci_ufilter { 1059 __u32 type_mask; 1060 __u32 event_mask[2]; 1061 __le16 opcode; 1062 }; 1063 1064 #define HCI_FLT_TYPE_BITS 31 1065 #define HCI_FLT_EVENT_BITS 63 1066 #define HCI_FLT_OGF_BITS 63 1067 #define HCI_FLT_OCF_BITS 127 1068 1069 /* ---- HCI Ioctl requests structures ---- */ 1070 struct hci_dev_stats { 1071 __u32 err_rx; 1072 __u32 err_tx; 1073 __u32 cmd_tx; 1074 __u32 evt_rx; 1075 __u32 acl_tx; 1076 __u32 acl_rx; 1077 __u32 sco_tx; 1078 __u32 sco_rx; 1079 __u32 byte_rx; 1080 __u32 byte_tx; 1081 }; 1082 1083 struct hci_dev_info { 1084 __u16 dev_id; 1085 char name[8]; 1086 1087 bdaddr_t bdaddr; 1088 1089 __u32 flags; 1090 __u8 type; 1091 1092 __u8 features[8]; 1093 1094 __u32 pkt_type; 1095 __u32 link_policy; 1096 __u32 link_mode; 1097 1098 __u16 acl_mtu; 1099 __u16 acl_pkts; 1100 __u16 sco_mtu; 1101 __u16 sco_pkts; 1102 1103 struct hci_dev_stats stat; 1104 }; 1105 1106 struct hci_conn_info { 1107 __u16 handle; 1108 bdaddr_t bdaddr; 1109 __u8 type; 1110 __u8 out; 1111 __u16 state; 1112 __u32 link_mode; 1113 }; 1114 1115 struct hci_dev_req { 1116 __u16 dev_id; 1117 __u32 dev_opt; 1118 }; 1119 1120 struct hci_dev_list_req { 1121 __u16 dev_num; 1122 struct hci_dev_req dev_req[0]; /* hci_dev_req structures */ 1123 }; 1124 1125 struct hci_conn_list_req { 1126 __u16 dev_id; 1127 __u16 conn_num; 1128 struct hci_conn_info conn_info[0]; 1129 }; 1130 1131 struct hci_conn_info_req { 1132 bdaddr_t bdaddr; 1133 __u8 type; 1134 struct hci_conn_info conn_info[0]; 1135 }; 1136 1137 struct hci_auth_info_req { 1138 bdaddr_t bdaddr; 1139 __u8 type; 1140 }; 1141 1142 struct hci_inquiry_req { 1143 __u16 dev_id; 1144 __u16 flags; 1145 __u8 lap[3]; 1146 __u8 length; 1147 __u8 num_rsp; 1148 }; 1149 #define IREQ_CACHE_FLUSH 0x0001 1150 1151 #endif /* __HCI_H */ 1152