1 /* 2 BlueZ - Bluetooth protocol stack for Linux 3 Copyright (c) 2000-2001, 2010, Code Aurora Forum. All rights reserved. 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_CORE_H 26 #define __HCI_CORE_H 27 28 #include <linux/idr.h> 29 #include <linux/leds.h> 30 #include <linux/rculist.h> 31 32 #include <net/bluetooth/hci.h> 33 #include <net/bluetooth/hci_sync.h> 34 #include <net/bluetooth/hci_sock.h> 35 36 /* HCI priority */ 37 #define HCI_PRIO_MAX 7 38 39 /* HCI maximum id value */ 40 #define HCI_MAX_ID 10000 41 42 /* HCI Core structures */ 43 struct inquiry_data { 44 bdaddr_t bdaddr; 45 __u8 pscan_rep_mode; 46 __u8 pscan_period_mode; 47 __u8 pscan_mode; 48 __u8 dev_class[3]; 49 __le16 clock_offset; 50 __s8 rssi; 51 __u8 ssp_mode; 52 }; 53 54 struct inquiry_entry { 55 struct list_head all; /* inq_cache.all */ 56 struct list_head list; /* unknown or resolve */ 57 enum { 58 NAME_NOT_KNOWN, 59 NAME_NEEDED, 60 NAME_PENDING, 61 NAME_KNOWN, 62 } name_state; 63 __u32 timestamp; 64 struct inquiry_data data; 65 }; 66 67 struct discovery_state { 68 int type; 69 enum { 70 DISCOVERY_STOPPED, 71 DISCOVERY_STARTING, 72 DISCOVERY_FINDING, 73 DISCOVERY_RESOLVING, 74 DISCOVERY_STOPPING, 75 } state; 76 struct list_head all; /* All devices found during inquiry */ 77 struct list_head unknown; /* Name state not known */ 78 struct list_head resolve; /* Name needs to be resolved */ 79 __u32 timestamp; 80 bdaddr_t last_adv_addr; 81 u8 last_adv_addr_type; 82 s8 last_adv_rssi; 83 u32 last_adv_flags; 84 u8 last_adv_data[HCI_MAX_AD_LENGTH]; 85 u8 last_adv_data_len; 86 bool report_invalid_rssi; 87 bool result_filtering; 88 bool limited; 89 s8 rssi; 90 u16 uuid_count; 91 u8 (*uuids)[16]; 92 unsigned long scan_start; 93 unsigned long scan_duration; 94 unsigned long name_resolve_timeout; 95 }; 96 97 #define SUSPEND_NOTIFIER_TIMEOUT msecs_to_jiffies(2000) /* 2 seconds */ 98 99 enum suspend_tasks { 100 SUSPEND_PAUSE_DISCOVERY, 101 SUSPEND_UNPAUSE_DISCOVERY, 102 103 SUSPEND_PAUSE_ADVERTISING, 104 SUSPEND_UNPAUSE_ADVERTISING, 105 106 SUSPEND_SCAN_DISABLE, 107 SUSPEND_SCAN_ENABLE, 108 SUSPEND_DISCONNECTING, 109 110 SUSPEND_POWERING_DOWN, 111 112 SUSPEND_PREPARE_NOTIFIER, 113 114 SUSPEND_SET_ADV_FILTER, 115 __SUSPEND_NUM_TASKS 116 }; 117 118 enum suspended_state { 119 BT_RUNNING = 0, 120 BT_SUSPEND_DISCONNECT, 121 BT_SUSPEND_CONFIGURE_WAKE, 122 }; 123 124 struct hci_conn_hash { 125 struct list_head list; 126 unsigned int acl_num; 127 unsigned int amp_num; 128 unsigned int sco_num; 129 unsigned int le_num; 130 unsigned int le_num_peripheral; 131 }; 132 133 struct bdaddr_list { 134 struct list_head list; 135 bdaddr_t bdaddr; 136 u8 bdaddr_type; 137 }; 138 139 struct codec_list { 140 struct list_head list; 141 u8 id; 142 __u16 cid; 143 __u16 vid; 144 u8 transport; 145 u8 num_caps; 146 u32 len; 147 struct hci_codec_caps caps[]; 148 }; 149 150 struct bdaddr_list_with_irk { 151 struct list_head list; 152 bdaddr_t bdaddr; 153 u8 bdaddr_type; 154 u8 peer_irk[16]; 155 u8 local_irk[16]; 156 }; 157 158 enum hci_conn_flags { 159 HCI_CONN_FLAG_REMOTE_WAKEUP, 160 HCI_CONN_FLAG_DEVICE_PRIVACY, 161 162 __HCI_CONN_NUM_FLAGS, 163 }; 164 165 /* Make sure number of flags doesn't exceed sizeof(current_flags) */ 166 static_assert(__HCI_CONN_NUM_FLAGS < 32); 167 168 struct bdaddr_list_with_flags { 169 struct list_head list; 170 bdaddr_t bdaddr; 171 u8 bdaddr_type; 172 DECLARE_BITMAP(flags, __HCI_CONN_NUM_FLAGS); 173 }; 174 175 struct bt_uuid { 176 struct list_head list; 177 u8 uuid[16]; 178 u8 size; 179 u8 svc_hint; 180 }; 181 182 struct blocked_key { 183 struct list_head list; 184 struct rcu_head rcu; 185 u8 type; 186 u8 val[16]; 187 }; 188 189 struct smp_csrk { 190 bdaddr_t bdaddr; 191 u8 bdaddr_type; 192 u8 type; 193 u8 val[16]; 194 }; 195 196 struct smp_ltk { 197 struct list_head list; 198 struct rcu_head rcu; 199 bdaddr_t bdaddr; 200 u8 bdaddr_type; 201 u8 authenticated; 202 u8 type; 203 u8 enc_size; 204 __le16 ediv; 205 __le64 rand; 206 u8 val[16]; 207 }; 208 209 struct smp_irk { 210 struct list_head list; 211 struct rcu_head rcu; 212 bdaddr_t rpa; 213 bdaddr_t bdaddr; 214 u8 addr_type; 215 u8 val[16]; 216 }; 217 218 struct link_key { 219 struct list_head list; 220 struct rcu_head rcu; 221 bdaddr_t bdaddr; 222 u8 type; 223 u8 val[HCI_LINK_KEY_SIZE]; 224 u8 pin_len; 225 }; 226 227 struct oob_data { 228 struct list_head list; 229 bdaddr_t bdaddr; 230 u8 bdaddr_type; 231 u8 present; 232 u8 hash192[16]; 233 u8 rand192[16]; 234 u8 hash256[16]; 235 u8 rand256[16]; 236 }; 237 238 struct adv_info { 239 struct list_head list; 240 bool enabled; 241 bool pending; 242 __u8 instance; 243 __u32 flags; 244 __u16 timeout; 245 __u16 remaining_time; 246 __u16 duration; 247 __u16 adv_data_len; 248 __u8 adv_data[HCI_MAX_EXT_AD_LENGTH]; 249 __u16 scan_rsp_len; 250 __u8 scan_rsp_data[HCI_MAX_EXT_AD_LENGTH]; 251 __s8 tx_power; 252 __u32 min_interval; 253 __u32 max_interval; 254 bdaddr_t random_addr; 255 bool rpa_expired; 256 struct delayed_work rpa_expired_cb; 257 }; 258 259 #define HCI_MAX_ADV_INSTANCES 5 260 #define HCI_DEFAULT_ADV_DURATION 2 261 262 #define HCI_ADV_TX_POWER_NO_PREFERENCE 0x7F 263 264 struct monitored_device { 265 struct list_head list; 266 267 bdaddr_t bdaddr; 268 __u8 addr_type; 269 __u16 handle; 270 bool notified; 271 }; 272 273 struct adv_pattern { 274 struct list_head list; 275 __u8 ad_type; 276 __u8 offset; 277 __u8 length; 278 __u8 value[HCI_MAX_AD_LENGTH]; 279 }; 280 281 struct adv_rssi_thresholds { 282 __s8 low_threshold; 283 __s8 high_threshold; 284 __u16 low_threshold_timeout; 285 __u16 high_threshold_timeout; 286 __u8 sampling_period; 287 }; 288 289 struct adv_monitor { 290 struct list_head patterns; 291 struct adv_rssi_thresholds rssi; 292 __u16 handle; 293 294 enum { 295 ADV_MONITOR_STATE_NOT_REGISTERED, 296 ADV_MONITOR_STATE_REGISTERED, 297 ADV_MONITOR_STATE_OFFLOADED 298 } state; 299 }; 300 301 #define HCI_MIN_ADV_MONITOR_HANDLE 1 302 #define HCI_MAX_ADV_MONITOR_NUM_HANDLES 32 303 #define HCI_MAX_ADV_MONITOR_NUM_PATTERNS 16 304 #define HCI_ADV_MONITOR_EXT_NONE 1 305 #define HCI_ADV_MONITOR_EXT_MSFT 2 306 307 #define HCI_MAX_SHORT_NAME_LENGTH 10 308 309 #define HCI_CONN_HANDLE_UNSET 0xffff 310 #define HCI_CONN_HANDLE_MAX 0x0eff 311 312 /* Min encryption key size to match with SMP */ 313 #define HCI_MIN_ENC_KEY_SIZE 7 314 315 /* Default LE RPA expiry time, 15 minutes */ 316 #define HCI_DEFAULT_RPA_TIMEOUT (15 * 60) 317 318 /* Default min/max age of connection information (1s/3s) */ 319 #define DEFAULT_CONN_INFO_MIN_AGE 1000 320 #define DEFAULT_CONN_INFO_MAX_AGE 3000 321 /* Default authenticated payload timeout 30s */ 322 #define DEFAULT_AUTH_PAYLOAD_TIMEOUT 0x0bb8 323 324 struct amp_assoc { 325 __u16 len; 326 __u16 offset; 327 __u16 rem_len; 328 __u16 len_so_far; 329 __u8 data[HCI_MAX_AMP_ASSOC_SIZE]; 330 }; 331 332 #define HCI_MAX_PAGES 3 333 334 struct hci_dev { 335 struct list_head list; 336 struct mutex lock; 337 338 char name[8]; 339 unsigned long flags; 340 __u16 id; 341 __u8 bus; 342 __u8 dev_type; 343 bdaddr_t bdaddr; 344 bdaddr_t setup_addr; 345 bdaddr_t public_addr; 346 bdaddr_t random_addr; 347 bdaddr_t static_addr; 348 __u8 adv_addr_type; 349 __u8 dev_name[HCI_MAX_NAME_LENGTH]; 350 __u8 short_name[HCI_MAX_SHORT_NAME_LENGTH]; 351 __u8 eir[HCI_MAX_EIR_LENGTH]; 352 __u16 appearance; 353 __u8 dev_class[3]; 354 __u8 major_class; 355 __u8 minor_class; 356 __u8 max_page; 357 __u8 features[HCI_MAX_PAGES][8]; 358 __u8 le_features[8]; 359 __u8 le_accept_list_size; 360 __u8 le_resolv_list_size; 361 __u8 le_num_of_adv_sets; 362 __u8 le_states[8]; 363 __u8 commands[64]; 364 __u8 hci_ver; 365 __u16 hci_rev; 366 __u8 lmp_ver; 367 __u16 manufacturer; 368 __u16 lmp_subver; 369 __u16 voice_setting; 370 __u8 num_iac; 371 __u16 stored_max_keys; 372 __u16 stored_num_keys; 373 __u8 io_capability; 374 __s8 inq_tx_power; 375 __u8 err_data_reporting; 376 __u16 page_scan_interval; 377 __u16 page_scan_window; 378 __u8 page_scan_type; 379 __u8 le_adv_channel_map; 380 __u16 le_adv_min_interval; 381 __u16 le_adv_max_interval; 382 __u8 le_scan_type; 383 __u16 le_scan_interval; 384 __u16 le_scan_window; 385 __u16 le_scan_int_suspend; 386 __u16 le_scan_window_suspend; 387 __u16 le_scan_int_discovery; 388 __u16 le_scan_window_discovery; 389 __u16 le_scan_int_adv_monitor; 390 __u16 le_scan_window_adv_monitor; 391 __u16 le_scan_int_connect; 392 __u16 le_scan_window_connect; 393 __u16 le_conn_min_interval; 394 __u16 le_conn_max_interval; 395 __u16 le_conn_latency; 396 __u16 le_supv_timeout; 397 __u16 le_def_tx_len; 398 __u16 le_def_tx_time; 399 __u16 le_max_tx_len; 400 __u16 le_max_tx_time; 401 __u16 le_max_rx_len; 402 __u16 le_max_rx_time; 403 __u8 le_max_key_size; 404 __u8 le_min_key_size; 405 __u16 discov_interleaved_timeout; 406 __u16 conn_info_min_age; 407 __u16 conn_info_max_age; 408 __u16 auth_payload_timeout; 409 __u8 min_enc_key_size; 410 __u8 max_enc_key_size; 411 __u8 pairing_opts; 412 __u8 ssp_debug_mode; 413 __u8 hw_error_code; 414 __u32 clock; 415 __u16 advmon_allowlist_duration; 416 __u16 advmon_no_filter_duration; 417 __u8 enable_advmon_interleave_scan; 418 419 __u16 devid_source; 420 __u16 devid_vendor; 421 __u16 devid_product; 422 __u16 devid_version; 423 424 __u8 def_page_scan_type; 425 __u16 def_page_scan_int; 426 __u16 def_page_scan_window; 427 __u8 def_inq_scan_type; 428 __u16 def_inq_scan_int; 429 __u16 def_inq_scan_window; 430 __u16 def_br_lsto; 431 __u16 def_page_timeout; 432 __u16 def_multi_adv_rotation_duration; 433 __u16 def_le_autoconnect_timeout; 434 __s8 min_le_tx_power; 435 __s8 max_le_tx_power; 436 437 __u16 pkt_type; 438 __u16 esco_type; 439 __u16 link_policy; 440 __u16 link_mode; 441 442 __u32 idle_timeout; 443 __u16 sniff_min_interval; 444 __u16 sniff_max_interval; 445 446 __u8 amp_status; 447 __u32 amp_total_bw; 448 __u32 amp_max_bw; 449 __u32 amp_min_latency; 450 __u32 amp_max_pdu; 451 __u8 amp_type; 452 __u16 amp_pal_cap; 453 __u16 amp_assoc_size; 454 __u32 amp_max_flush_to; 455 __u32 amp_be_flush_to; 456 457 struct amp_assoc loc_assoc; 458 459 __u8 flow_ctl_mode; 460 461 unsigned int auto_accept_delay; 462 463 unsigned long quirks; 464 465 atomic_t cmd_cnt; 466 unsigned int acl_cnt; 467 unsigned int sco_cnt; 468 unsigned int le_cnt; 469 470 unsigned int acl_mtu; 471 unsigned int sco_mtu; 472 unsigned int le_mtu; 473 unsigned int acl_pkts; 474 unsigned int sco_pkts; 475 unsigned int le_pkts; 476 477 __u16 block_len; 478 __u16 block_mtu; 479 __u16 num_blocks; 480 __u16 block_cnt; 481 482 unsigned long acl_last_tx; 483 unsigned long sco_last_tx; 484 unsigned long le_last_tx; 485 486 __u8 le_tx_def_phys; 487 __u8 le_rx_def_phys; 488 489 struct workqueue_struct *workqueue; 490 struct workqueue_struct *req_workqueue; 491 492 struct work_struct power_on; 493 struct delayed_work power_off; 494 struct work_struct error_reset; 495 struct work_struct cmd_sync_work; 496 struct list_head cmd_sync_work_list; 497 struct mutex cmd_sync_work_lock; 498 struct work_struct cmd_sync_cancel_work; 499 500 __u16 discov_timeout; 501 struct delayed_work discov_off; 502 503 struct delayed_work service_cache; 504 505 struct delayed_work cmd_timer; 506 struct delayed_work ncmd_timer; 507 508 struct work_struct rx_work; 509 struct work_struct cmd_work; 510 struct work_struct tx_work; 511 512 struct work_struct discov_update; 513 struct work_struct scan_update; 514 struct delayed_work le_scan_disable; 515 struct delayed_work le_scan_restart; 516 517 struct sk_buff_head rx_q; 518 struct sk_buff_head raw_q; 519 struct sk_buff_head cmd_q; 520 521 struct sk_buff *sent_cmd; 522 523 struct mutex req_lock; 524 wait_queue_head_t req_wait_q; 525 __u32 req_status; 526 __u32 req_result; 527 struct sk_buff *req_skb; 528 529 void *smp_data; 530 void *smp_bredr_data; 531 532 struct discovery_state discovery; 533 534 int discovery_old_state; 535 bool discovery_paused; 536 int advertising_old_state; 537 bool advertising_paused; 538 539 struct notifier_block suspend_notifier; 540 enum suspended_state suspend_state_next; 541 enum suspended_state suspend_state; 542 bool scanning_paused; 543 bool suspended; 544 u8 wake_reason; 545 bdaddr_t wake_addr; 546 u8 wake_addr_type; 547 548 struct hci_conn_hash conn_hash; 549 550 struct list_head mgmt_pending; 551 struct list_head reject_list; 552 struct list_head accept_list; 553 struct list_head uuids; 554 struct list_head link_keys; 555 struct list_head long_term_keys; 556 struct list_head identity_resolving_keys; 557 struct list_head remote_oob_data; 558 struct list_head le_accept_list; 559 struct list_head le_resolv_list; 560 struct list_head le_conn_params; 561 struct list_head pend_le_conns; 562 struct list_head pend_le_reports; 563 struct list_head blocked_keys; 564 struct list_head local_codecs; 565 566 struct hci_dev_stats stat; 567 568 atomic_t promisc; 569 570 const char *hw_info; 571 const char *fw_info; 572 struct dentry *debugfs; 573 574 struct device dev; 575 576 struct rfkill *rfkill; 577 578 DECLARE_BITMAP(dev_flags, __HCI_NUM_FLAGS); 579 DECLARE_BITMAP(conn_flags, __HCI_CONN_NUM_FLAGS); 580 581 __s8 adv_tx_power; 582 __u8 adv_data[HCI_MAX_EXT_AD_LENGTH]; 583 __u8 adv_data_len; 584 __u8 scan_rsp_data[HCI_MAX_EXT_AD_LENGTH]; 585 __u8 scan_rsp_data_len; 586 587 struct list_head adv_instances; 588 unsigned int adv_instance_cnt; 589 __u8 cur_adv_instance; 590 __u16 adv_instance_timeout; 591 struct delayed_work adv_instance_expire; 592 593 struct idr adv_monitors_idr; 594 unsigned int adv_monitors_cnt; 595 596 __u8 irk[16]; 597 __u32 rpa_timeout; 598 struct delayed_work rpa_expired; 599 bdaddr_t rpa; 600 601 enum { 602 INTERLEAVE_SCAN_NONE, 603 INTERLEAVE_SCAN_NO_FILTER, 604 INTERLEAVE_SCAN_ALLOWLIST 605 } interleave_scan_state; 606 607 struct delayed_work interleave_scan; 608 609 struct list_head monitored_devices; 610 bool advmon_pend_notify; 611 612 #if IS_ENABLED(CONFIG_BT_LEDS) 613 struct led_trigger *power_led; 614 #endif 615 616 #if IS_ENABLED(CONFIG_BT_MSFTEXT) 617 __u16 msft_opcode; 618 void *msft_data; 619 bool msft_curve_validity; 620 #endif 621 622 #if IS_ENABLED(CONFIG_BT_AOSPEXT) 623 bool aosp_capable; 624 bool aosp_quality_report; 625 #endif 626 627 int (*open)(struct hci_dev *hdev); 628 int (*close)(struct hci_dev *hdev); 629 int (*flush)(struct hci_dev *hdev); 630 int (*setup)(struct hci_dev *hdev); 631 int (*shutdown)(struct hci_dev *hdev); 632 int (*send)(struct hci_dev *hdev, struct sk_buff *skb); 633 void (*notify)(struct hci_dev *hdev, unsigned int evt); 634 void (*hw_error)(struct hci_dev *hdev, u8 code); 635 int (*post_init)(struct hci_dev *hdev); 636 int (*set_diag)(struct hci_dev *hdev, bool enable); 637 int (*set_bdaddr)(struct hci_dev *hdev, const bdaddr_t *bdaddr); 638 void (*cmd_timeout)(struct hci_dev *hdev); 639 bool (*wakeup)(struct hci_dev *hdev); 640 int (*set_quality_report)(struct hci_dev *hdev, bool enable); 641 int (*get_data_path_id)(struct hci_dev *hdev, __u8 *data_path); 642 int (*get_codec_config_data)(struct hci_dev *hdev, __u8 type, 643 struct bt_codec *codec, __u8 *vnd_len, 644 __u8 **vnd_data); 645 }; 646 647 #define HCI_PHY_HANDLE(handle) (handle & 0xff) 648 649 enum conn_reasons { 650 CONN_REASON_PAIR_DEVICE, 651 CONN_REASON_L2CAP_CHAN, 652 CONN_REASON_SCO_CONNECT, 653 }; 654 655 struct hci_conn { 656 struct list_head list; 657 658 atomic_t refcnt; 659 660 bdaddr_t dst; 661 __u8 dst_type; 662 bdaddr_t src; 663 __u8 src_type; 664 bdaddr_t init_addr; 665 __u8 init_addr_type; 666 bdaddr_t resp_addr; 667 __u8 resp_addr_type; 668 __u8 adv_instance; 669 __u16 handle; 670 __u16 state; 671 __u8 mode; 672 __u8 type; 673 __u8 role; 674 bool out; 675 __u8 attempt; 676 __u8 dev_class[3]; 677 __u8 features[HCI_MAX_PAGES][8]; 678 __u16 pkt_type; 679 __u16 link_policy; 680 __u8 key_type; 681 __u8 auth_type; 682 __u8 sec_level; 683 __u8 pending_sec_level; 684 __u8 pin_length; 685 __u8 enc_key_size; 686 __u8 io_capability; 687 __u32 passkey_notify; 688 __u8 passkey_entered; 689 __u16 disc_timeout; 690 __u16 conn_timeout; 691 __u16 setting; 692 __u16 auth_payload_timeout; 693 __u16 le_conn_min_interval; 694 __u16 le_conn_max_interval; 695 __u16 le_conn_interval; 696 __u16 le_conn_latency; 697 __u16 le_supv_timeout; 698 __u8 le_adv_data[HCI_MAX_AD_LENGTH]; 699 __u8 le_adv_data_len; 700 __u8 le_tx_phy; 701 __u8 le_rx_phy; 702 __s8 rssi; 703 __s8 tx_power; 704 __s8 max_tx_power; 705 unsigned long flags; 706 707 enum conn_reasons conn_reason; 708 709 __u32 clock; 710 __u16 clock_accuracy; 711 712 unsigned long conn_info_timestamp; 713 714 __u8 remote_cap; 715 __u8 remote_auth; 716 __u8 remote_id; 717 718 unsigned int sent; 719 720 struct sk_buff_head data_q; 721 struct list_head chan_list; 722 723 struct delayed_work disc_work; 724 struct delayed_work auto_accept_work; 725 struct delayed_work idle_work; 726 struct delayed_work le_conn_timeout; 727 struct work_struct le_scan_cleanup; 728 729 struct device dev; 730 struct dentry *debugfs; 731 732 struct hci_dev *hdev; 733 void *l2cap_data; 734 void *sco_data; 735 struct amp_mgr *amp_mgr; 736 737 struct hci_conn *link; 738 struct bt_codec codec; 739 740 void (*connect_cfm_cb) (struct hci_conn *conn, u8 status); 741 void (*security_cfm_cb) (struct hci_conn *conn, u8 status); 742 void (*disconn_cfm_cb) (struct hci_conn *conn, u8 reason); 743 }; 744 745 struct hci_chan { 746 struct list_head list; 747 __u16 handle; 748 struct hci_conn *conn; 749 struct sk_buff_head data_q; 750 unsigned int sent; 751 __u8 state; 752 bool amp; 753 }; 754 755 struct hci_conn_params { 756 struct list_head list; 757 struct list_head action; 758 759 bdaddr_t addr; 760 u8 addr_type; 761 762 u16 conn_min_interval; 763 u16 conn_max_interval; 764 u16 conn_latency; 765 u16 supervision_timeout; 766 767 enum { 768 HCI_AUTO_CONN_DISABLED, 769 HCI_AUTO_CONN_REPORT, 770 HCI_AUTO_CONN_DIRECT, 771 HCI_AUTO_CONN_ALWAYS, 772 HCI_AUTO_CONN_LINK_LOSS, 773 HCI_AUTO_CONN_EXPLICIT, 774 } auto_connect; 775 776 struct hci_conn *conn; 777 bool explicit_connect; 778 DECLARE_BITMAP(flags, __HCI_CONN_NUM_FLAGS); 779 u8 privacy_mode; 780 }; 781 782 extern struct list_head hci_dev_list; 783 extern struct list_head hci_cb_list; 784 extern rwlock_t hci_dev_list_lock; 785 extern struct mutex hci_cb_list_lock; 786 787 #define hci_dev_set_flag(hdev, nr) set_bit((nr), (hdev)->dev_flags) 788 #define hci_dev_clear_flag(hdev, nr) clear_bit((nr), (hdev)->dev_flags) 789 #define hci_dev_change_flag(hdev, nr) change_bit((nr), (hdev)->dev_flags) 790 #define hci_dev_test_flag(hdev, nr) test_bit((nr), (hdev)->dev_flags) 791 #define hci_dev_test_and_set_flag(hdev, nr) test_and_set_bit((nr), (hdev)->dev_flags) 792 #define hci_dev_test_and_clear_flag(hdev, nr) test_and_clear_bit((nr), (hdev)->dev_flags) 793 #define hci_dev_test_and_change_flag(hdev, nr) test_and_change_bit((nr), (hdev)->dev_flags) 794 795 #define hci_dev_clear_volatile_flags(hdev) \ 796 do { \ 797 hci_dev_clear_flag(hdev, HCI_LE_SCAN); \ 798 hci_dev_clear_flag(hdev, HCI_LE_ADV); \ 799 hci_dev_clear_flag(hdev, HCI_LL_RPA_RESOLUTION);\ 800 hci_dev_clear_flag(hdev, HCI_PERIODIC_INQ); \ 801 hci_dev_clear_flag(hdev, HCI_QUALITY_REPORT); \ 802 } while (0) 803 804 #define hci_dev_le_state_simultaneous(hdev) \ 805 (test_bit(HCI_QUIRK_VALID_LE_STATES, &hdev->quirks) && \ 806 (hdev->le_states[4] & 0x08) && /* Central */ \ 807 (hdev->le_states[4] & 0x40) && /* Peripheral */ \ 808 (hdev->le_states[3] & 0x10)) /* Simultaneous */ 809 810 /* ----- HCI interface to upper protocols ----- */ 811 int l2cap_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr); 812 int l2cap_disconn_ind(struct hci_conn *hcon); 813 void l2cap_recv_acldata(struct hci_conn *hcon, struct sk_buff *skb, u16 flags); 814 815 #if IS_ENABLED(CONFIG_BT_BREDR) 816 int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, __u8 *flags); 817 void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb); 818 #else 819 static inline int sco_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, 820 __u8 *flags) 821 { 822 return 0; 823 } 824 825 static inline void sco_recv_scodata(struct hci_conn *hcon, struct sk_buff *skb) 826 { 827 } 828 #endif 829 830 /* ----- Inquiry cache ----- */ 831 #define INQUIRY_CACHE_AGE_MAX (HZ*30) /* 30 seconds */ 832 #define INQUIRY_ENTRY_AGE_MAX (HZ*60) /* 60 seconds */ 833 834 static inline void discovery_init(struct hci_dev *hdev) 835 { 836 hdev->discovery.state = DISCOVERY_STOPPED; 837 INIT_LIST_HEAD(&hdev->discovery.all); 838 INIT_LIST_HEAD(&hdev->discovery.unknown); 839 INIT_LIST_HEAD(&hdev->discovery.resolve); 840 hdev->discovery.report_invalid_rssi = true; 841 hdev->discovery.rssi = HCI_RSSI_INVALID; 842 } 843 844 static inline void hci_discovery_filter_clear(struct hci_dev *hdev) 845 { 846 hdev->discovery.result_filtering = false; 847 hdev->discovery.report_invalid_rssi = true; 848 hdev->discovery.rssi = HCI_RSSI_INVALID; 849 hdev->discovery.uuid_count = 0; 850 kfree(hdev->discovery.uuids); 851 hdev->discovery.uuids = NULL; 852 hdev->discovery.scan_start = 0; 853 hdev->discovery.scan_duration = 0; 854 } 855 856 bool hci_discovery_active(struct hci_dev *hdev); 857 858 void hci_discovery_set_state(struct hci_dev *hdev, int state); 859 860 static inline int inquiry_cache_empty(struct hci_dev *hdev) 861 { 862 return list_empty(&hdev->discovery.all); 863 } 864 865 static inline long inquiry_cache_age(struct hci_dev *hdev) 866 { 867 struct discovery_state *c = &hdev->discovery; 868 return jiffies - c->timestamp; 869 } 870 871 static inline long inquiry_entry_age(struct inquiry_entry *e) 872 { 873 return jiffies - e->timestamp; 874 } 875 876 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, 877 bdaddr_t *bdaddr); 878 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, 879 bdaddr_t *bdaddr); 880 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, 881 bdaddr_t *bdaddr, 882 int state); 883 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, 884 struct inquiry_entry *ie); 885 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, 886 bool name_known); 887 void hci_inquiry_cache_flush(struct hci_dev *hdev); 888 889 /* ----- HCI Connections ----- */ 890 enum { 891 HCI_CONN_AUTH_PEND, 892 HCI_CONN_REAUTH_PEND, 893 HCI_CONN_ENCRYPT_PEND, 894 HCI_CONN_RSWITCH_PEND, 895 HCI_CONN_MODE_CHANGE_PEND, 896 HCI_CONN_SCO_SETUP_PEND, 897 HCI_CONN_MGMT_CONNECTED, 898 HCI_CONN_SSP_ENABLED, 899 HCI_CONN_SC_ENABLED, 900 HCI_CONN_AES_CCM, 901 HCI_CONN_POWER_SAVE, 902 HCI_CONN_FLUSH_KEY, 903 HCI_CONN_ENCRYPT, 904 HCI_CONN_AUTH, 905 HCI_CONN_SECURE, 906 HCI_CONN_FIPS, 907 HCI_CONN_STK_ENCRYPT, 908 HCI_CONN_AUTH_INITIATOR, 909 HCI_CONN_DROP, 910 HCI_CONN_PARAM_REMOVAL_PEND, 911 HCI_CONN_NEW_LINK_KEY, 912 HCI_CONN_SCANNING, 913 HCI_CONN_AUTH_FAILURE, 914 }; 915 916 static inline bool hci_conn_ssp_enabled(struct hci_conn *conn) 917 { 918 struct hci_dev *hdev = conn->hdev; 919 return hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && 920 test_bit(HCI_CONN_SSP_ENABLED, &conn->flags); 921 } 922 923 static inline bool hci_conn_sc_enabled(struct hci_conn *conn) 924 { 925 struct hci_dev *hdev = conn->hdev; 926 return hci_dev_test_flag(hdev, HCI_SC_ENABLED) && 927 test_bit(HCI_CONN_SC_ENABLED, &conn->flags); 928 } 929 930 static inline void hci_conn_hash_add(struct hci_dev *hdev, struct hci_conn *c) 931 { 932 struct hci_conn_hash *h = &hdev->conn_hash; 933 list_add_rcu(&c->list, &h->list); 934 switch (c->type) { 935 case ACL_LINK: 936 h->acl_num++; 937 break; 938 case AMP_LINK: 939 h->amp_num++; 940 break; 941 case LE_LINK: 942 h->le_num++; 943 if (c->role == HCI_ROLE_SLAVE) 944 h->le_num_peripheral++; 945 break; 946 case SCO_LINK: 947 case ESCO_LINK: 948 h->sco_num++; 949 break; 950 } 951 } 952 953 static inline void hci_conn_hash_del(struct hci_dev *hdev, struct hci_conn *c) 954 { 955 struct hci_conn_hash *h = &hdev->conn_hash; 956 957 list_del_rcu(&c->list); 958 synchronize_rcu(); 959 960 switch (c->type) { 961 case ACL_LINK: 962 h->acl_num--; 963 break; 964 case AMP_LINK: 965 h->amp_num--; 966 break; 967 case LE_LINK: 968 h->le_num--; 969 if (c->role == HCI_ROLE_SLAVE) 970 h->le_num_peripheral--; 971 break; 972 case SCO_LINK: 973 case ESCO_LINK: 974 h->sco_num--; 975 break; 976 } 977 } 978 979 static inline unsigned int hci_conn_num(struct hci_dev *hdev, __u8 type) 980 { 981 struct hci_conn_hash *h = &hdev->conn_hash; 982 switch (type) { 983 case ACL_LINK: 984 return h->acl_num; 985 case AMP_LINK: 986 return h->amp_num; 987 case LE_LINK: 988 return h->le_num; 989 case SCO_LINK: 990 case ESCO_LINK: 991 return h->sco_num; 992 default: 993 return 0; 994 } 995 } 996 997 static inline unsigned int hci_conn_count(struct hci_dev *hdev) 998 { 999 struct hci_conn_hash *c = &hdev->conn_hash; 1000 1001 return c->acl_num + c->amp_num + c->sco_num + c->le_num; 1002 } 1003 1004 static inline __u8 hci_conn_lookup_type(struct hci_dev *hdev, __u16 handle) 1005 { 1006 struct hci_conn_hash *h = &hdev->conn_hash; 1007 struct hci_conn *c; 1008 __u8 type = INVALID_LINK; 1009 1010 rcu_read_lock(); 1011 1012 list_for_each_entry_rcu(c, &h->list, list) { 1013 if (c->handle == handle) { 1014 type = c->type; 1015 break; 1016 } 1017 } 1018 1019 rcu_read_unlock(); 1020 1021 return type; 1022 } 1023 1024 static inline struct hci_conn *hci_conn_hash_lookup_handle(struct hci_dev *hdev, 1025 __u16 handle) 1026 { 1027 struct hci_conn_hash *h = &hdev->conn_hash; 1028 struct hci_conn *c; 1029 1030 rcu_read_lock(); 1031 1032 list_for_each_entry_rcu(c, &h->list, list) { 1033 if (c->handle == handle) { 1034 rcu_read_unlock(); 1035 return c; 1036 } 1037 } 1038 rcu_read_unlock(); 1039 1040 return NULL; 1041 } 1042 1043 static inline struct hci_conn *hci_conn_hash_lookup_ba(struct hci_dev *hdev, 1044 __u8 type, bdaddr_t *ba) 1045 { 1046 struct hci_conn_hash *h = &hdev->conn_hash; 1047 struct hci_conn *c; 1048 1049 rcu_read_lock(); 1050 1051 list_for_each_entry_rcu(c, &h->list, list) { 1052 if (c->type == type && !bacmp(&c->dst, ba)) { 1053 rcu_read_unlock(); 1054 return c; 1055 } 1056 } 1057 1058 rcu_read_unlock(); 1059 1060 return NULL; 1061 } 1062 1063 static inline struct hci_conn *hci_conn_hash_lookup_le(struct hci_dev *hdev, 1064 bdaddr_t *ba, 1065 __u8 ba_type) 1066 { 1067 struct hci_conn_hash *h = &hdev->conn_hash; 1068 struct hci_conn *c; 1069 1070 rcu_read_lock(); 1071 1072 list_for_each_entry_rcu(c, &h->list, list) { 1073 if (c->type != LE_LINK) 1074 continue; 1075 1076 if (ba_type == c->dst_type && !bacmp(&c->dst, ba)) { 1077 rcu_read_unlock(); 1078 return c; 1079 } 1080 } 1081 1082 rcu_read_unlock(); 1083 1084 return NULL; 1085 } 1086 1087 static inline struct hci_conn *hci_conn_hash_lookup_state(struct hci_dev *hdev, 1088 __u8 type, __u16 state) 1089 { 1090 struct hci_conn_hash *h = &hdev->conn_hash; 1091 struct hci_conn *c; 1092 1093 rcu_read_lock(); 1094 1095 list_for_each_entry_rcu(c, &h->list, list) { 1096 if (c->type == type && c->state == state) { 1097 rcu_read_unlock(); 1098 return c; 1099 } 1100 } 1101 1102 rcu_read_unlock(); 1103 1104 return NULL; 1105 } 1106 1107 static inline struct hci_conn *hci_lookup_le_connect(struct hci_dev *hdev) 1108 { 1109 struct hci_conn_hash *h = &hdev->conn_hash; 1110 struct hci_conn *c; 1111 1112 rcu_read_lock(); 1113 1114 list_for_each_entry_rcu(c, &h->list, list) { 1115 if (c->type == LE_LINK && c->state == BT_CONNECT && 1116 !test_bit(HCI_CONN_SCANNING, &c->flags)) { 1117 rcu_read_unlock(); 1118 return c; 1119 } 1120 } 1121 1122 rcu_read_unlock(); 1123 1124 return NULL; 1125 } 1126 1127 int hci_disconnect(struct hci_conn *conn, __u8 reason); 1128 bool hci_setup_sync(struct hci_conn *conn, __u16 handle); 1129 void hci_sco_setup(struct hci_conn *conn, __u8 status); 1130 1131 struct hci_conn *hci_conn_add(struct hci_dev *hdev, int type, bdaddr_t *dst, 1132 u8 role); 1133 int hci_conn_del(struct hci_conn *conn); 1134 void hci_conn_hash_flush(struct hci_dev *hdev); 1135 void hci_conn_check_pending(struct hci_dev *hdev); 1136 1137 struct hci_chan *hci_chan_create(struct hci_conn *conn); 1138 void hci_chan_del(struct hci_chan *chan); 1139 void hci_chan_list_flush(struct hci_conn *conn); 1140 struct hci_chan *hci_chan_lookup_handle(struct hci_dev *hdev, __u16 handle); 1141 1142 struct hci_conn *hci_connect_le_scan(struct hci_dev *hdev, bdaddr_t *dst, 1143 u8 dst_type, u8 sec_level, 1144 u16 conn_timeout, 1145 enum conn_reasons conn_reason); 1146 struct hci_conn *hci_connect_le(struct hci_dev *hdev, bdaddr_t *dst, 1147 u8 dst_type, bool dst_resolved, u8 sec_level, 1148 u16 conn_timeout, u8 role); 1149 struct hci_conn *hci_connect_acl(struct hci_dev *hdev, bdaddr_t *dst, 1150 u8 sec_level, u8 auth_type, 1151 enum conn_reasons conn_reason); 1152 struct hci_conn *hci_connect_sco(struct hci_dev *hdev, int type, bdaddr_t *dst, 1153 __u16 setting, struct bt_codec *codec); 1154 int hci_conn_check_link_mode(struct hci_conn *conn); 1155 int hci_conn_check_secure(struct hci_conn *conn, __u8 sec_level); 1156 int hci_conn_security(struct hci_conn *conn, __u8 sec_level, __u8 auth_type, 1157 bool initiator); 1158 int hci_conn_switch_role(struct hci_conn *conn, __u8 role); 1159 1160 void hci_conn_enter_active_mode(struct hci_conn *conn, __u8 force_active); 1161 1162 void hci_conn_failed(struct hci_conn *conn, u8 status); 1163 1164 /* 1165 * hci_conn_get() and hci_conn_put() are used to control the life-time of an 1166 * "hci_conn" object. They do not guarantee that the hci_conn object is running, 1167 * working or anything else. They just guarantee that the object is available 1168 * and can be dereferenced. So you can use its locks, local variables and any 1169 * other constant data. 1170 * Before accessing runtime data, you _must_ lock the object and then check that 1171 * it is still running. As soon as you release the locks, the connection might 1172 * get dropped, though. 1173 * 1174 * On the other hand, hci_conn_hold() and hci_conn_drop() are used to control 1175 * how long the underlying connection is held. So every channel that runs on the 1176 * hci_conn object calls this to prevent the connection from disappearing. As 1177 * long as you hold a device, you must also guarantee that you have a valid 1178 * reference to the device via hci_conn_get() (or the initial reference from 1179 * hci_conn_add()). 1180 * The hold()/drop() ref-count is known to drop below 0 sometimes, which doesn't 1181 * break because nobody cares for that. But this means, we cannot use 1182 * _get()/_drop() in it, but require the caller to have a valid ref (FIXME). 1183 */ 1184 1185 static inline struct hci_conn *hci_conn_get(struct hci_conn *conn) 1186 { 1187 get_device(&conn->dev); 1188 return conn; 1189 } 1190 1191 static inline void hci_conn_put(struct hci_conn *conn) 1192 { 1193 put_device(&conn->dev); 1194 } 1195 1196 static inline void hci_conn_hold(struct hci_conn *conn) 1197 { 1198 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 1199 1200 atomic_inc(&conn->refcnt); 1201 cancel_delayed_work(&conn->disc_work); 1202 } 1203 1204 static inline void hci_conn_drop(struct hci_conn *conn) 1205 { 1206 BT_DBG("hcon %p orig refcnt %d", conn, atomic_read(&conn->refcnt)); 1207 1208 if (atomic_dec_and_test(&conn->refcnt)) { 1209 unsigned long timeo; 1210 1211 switch (conn->type) { 1212 case ACL_LINK: 1213 case LE_LINK: 1214 cancel_delayed_work(&conn->idle_work); 1215 if (conn->state == BT_CONNECTED) { 1216 timeo = conn->disc_timeout; 1217 if (!conn->out) 1218 timeo *= 2; 1219 } else { 1220 timeo = 0; 1221 } 1222 break; 1223 1224 case AMP_LINK: 1225 timeo = conn->disc_timeout; 1226 break; 1227 1228 default: 1229 timeo = 0; 1230 break; 1231 } 1232 1233 cancel_delayed_work(&conn->disc_work); 1234 queue_delayed_work(conn->hdev->workqueue, 1235 &conn->disc_work, timeo); 1236 } 1237 } 1238 1239 /* ----- HCI Devices ----- */ 1240 static inline void hci_dev_put(struct hci_dev *d) 1241 { 1242 BT_DBG("%s orig refcnt %d", d->name, 1243 kref_read(&d->dev.kobj.kref)); 1244 1245 put_device(&d->dev); 1246 } 1247 1248 static inline struct hci_dev *hci_dev_hold(struct hci_dev *d) 1249 { 1250 BT_DBG("%s orig refcnt %d", d->name, 1251 kref_read(&d->dev.kobj.kref)); 1252 1253 get_device(&d->dev); 1254 return d; 1255 } 1256 1257 #define hci_dev_lock(d) mutex_lock(&d->lock) 1258 #define hci_dev_unlock(d) mutex_unlock(&d->lock) 1259 1260 #define to_hci_dev(d) container_of(d, struct hci_dev, dev) 1261 #define to_hci_conn(c) container_of(c, struct hci_conn, dev) 1262 1263 static inline void *hci_get_drvdata(struct hci_dev *hdev) 1264 { 1265 return dev_get_drvdata(&hdev->dev); 1266 } 1267 1268 static inline void hci_set_drvdata(struct hci_dev *hdev, void *data) 1269 { 1270 dev_set_drvdata(&hdev->dev, data); 1271 } 1272 1273 static inline void *hci_get_priv(struct hci_dev *hdev) 1274 { 1275 return (char *)hdev + sizeof(*hdev); 1276 } 1277 1278 struct hci_dev *hci_dev_get(int index); 1279 struct hci_dev *hci_get_route(bdaddr_t *dst, bdaddr_t *src, u8 src_type); 1280 1281 struct hci_dev *hci_alloc_dev_priv(int sizeof_priv); 1282 1283 static inline struct hci_dev *hci_alloc_dev(void) 1284 { 1285 return hci_alloc_dev_priv(0); 1286 } 1287 1288 void hci_free_dev(struct hci_dev *hdev); 1289 int hci_register_dev(struct hci_dev *hdev); 1290 void hci_unregister_dev(struct hci_dev *hdev); 1291 void hci_release_dev(struct hci_dev *hdev); 1292 int hci_suspend_dev(struct hci_dev *hdev); 1293 int hci_resume_dev(struct hci_dev *hdev); 1294 int hci_reset_dev(struct hci_dev *hdev); 1295 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb); 1296 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb); 1297 __printf(2, 3) void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...); 1298 __printf(2, 3) void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...); 1299 1300 static inline void hci_set_msft_opcode(struct hci_dev *hdev, __u16 opcode) 1301 { 1302 #if IS_ENABLED(CONFIG_BT_MSFTEXT) 1303 hdev->msft_opcode = opcode; 1304 #endif 1305 } 1306 1307 static inline void hci_set_aosp_capable(struct hci_dev *hdev) 1308 { 1309 #if IS_ENABLED(CONFIG_BT_AOSPEXT) 1310 hdev->aosp_capable = true; 1311 #endif 1312 } 1313 1314 int hci_dev_open(__u16 dev); 1315 int hci_dev_close(__u16 dev); 1316 int hci_dev_do_close(struct hci_dev *hdev); 1317 int hci_dev_reset(__u16 dev); 1318 int hci_dev_reset_stat(__u16 dev); 1319 int hci_dev_cmd(unsigned int cmd, void __user *arg); 1320 int hci_get_dev_list(void __user *arg); 1321 int hci_get_dev_info(void __user *arg); 1322 int hci_get_conn_list(void __user *arg); 1323 int hci_get_conn_info(struct hci_dev *hdev, void __user *arg); 1324 int hci_get_auth_info(struct hci_dev *hdev, void __user *arg); 1325 int hci_inquiry(void __user *arg); 1326 1327 struct bdaddr_list *hci_bdaddr_list_lookup(struct list_head *list, 1328 bdaddr_t *bdaddr, u8 type); 1329 struct bdaddr_list_with_irk *hci_bdaddr_list_lookup_with_irk( 1330 struct list_head *list, bdaddr_t *bdaddr, 1331 u8 type); 1332 struct bdaddr_list_with_flags * 1333 hci_bdaddr_list_lookup_with_flags(struct list_head *list, bdaddr_t *bdaddr, 1334 u8 type); 1335 int hci_bdaddr_list_add(struct list_head *list, bdaddr_t *bdaddr, u8 type); 1336 int hci_bdaddr_list_add_with_irk(struct list_head *list, bdaddr_t *bdaddr, 1337 u8 type, u8 *peer_irk, u8 *local_irk); 1338 int hci_bdaddr_list_add_with_flags(struct list_head *list, bdaddr_t *bdaddr, 1339 u8 type, u32 flags); 1340 int hci_bdaddr_list_del(struct list_head *list, bdaddr_t *bdaddr, u8 type); 1341 int hci_bdaddr_list_del_with_irk(struct list_head *list, bdaddr_t *bdaddr, 1342 u8 type); 1343 int hci_bdaddr_list_del_with_flags(struct list_head *list, bdaddr_t *bdaddr, 1344 u8 type); 1345 void hci_bdaddr_list_clear(struct list_head *list); 1346 1347 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, 1348 bdaddr_t *addr, u8 addr_type); 1349 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, 1350 bdaddr_t *addr, u8 addr_type); 1351 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type); 1352 void hci_conn_params_clear_disabled(struct hci_dev *hdev); 1353 1354 struct hci_conn_params *hci_pend_le_action_lookup(struct list_head *list, 1355 bdaddr_t *addr, 1356 u8 addr_type); 1357 1358 void hci_uuids_clear(struct hci_dev *hdev); 1359 1360 void hci_link_keys_clear(struct hci_dev *hdev); 1361 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 1362 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, 1363 bdaddr_t *bdaddr, u8 *val, u8 type, 1364 u8 pin_len, bool *persistent); 1365 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, 1366 u8 addr_type, u8 type, u8 authenticated, 1367 u8 tk[16], u8 enc_size, __le16 ediv, __le64 rand); 1368 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, 1369 u8 addr_type, u8 role); 1370 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type); 1371 void hci_smp_ltks_clear(struct hci_dev *hdev); 1372 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr); 1373 1374 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa); 1375 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, 1376 u8 addr_type); 1377 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, 1378 u8 addr_type, u8 val[16], bdaddr_t *rpa); 1379 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type); 1380 bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]); 1381 void hci_blocked_keys_clear(struct hci_dev *hdev); 1382 void hci_smp_irks_clear(struct hci_dev *hdev); 1383 1384 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type); 1385 1386 void hci_remote_oob_data_clear(struct hci_dev *hdev); 1387 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, 1388 bdaddr_t *bdaddr, u8 bdaddr_type); 1389 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 1390 u8 bdaddr_type, u8 *hash192, u8 *rand192, 1391 u8 *hash256, u8 *rand256); 1392 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, 1393 u8 bdaddr_type); 1394 1395 void hci_adv_instances_clear(struct hci_dev *hdev); 1396 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance); 1397 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance); 1398 int hci_add_adv_instance(struct hci_dev *hdev, u8 instance, u32 flags, 1399 u16 adv_data_len, u8 *adv_data, 1400 u16 scan_rsp_len, u8 *scan_rsp_data, 1401 u16 timeout, u16 duration, s8 tx_power, 1402 u32 min_interval, u32 max_interval); 1403 int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, 1404 u16 adv_data_len, u8 *adv_data, 1405 u16 scan_rsp_len, u8 *scan_rsp_data); 1406 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance); 1407 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired); 1408 u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance); 1409 bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance); 1410 1411 void hci_adv_monitors_clear(struct hci_dev *hdev); 1412 void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor); 1413 int hci_add_adv_patterns_monitor_complete(struct hci_dev *hdev, u8 status); 1414 int hci_remove_adv_monitor_complete(struct hci_dev *hdev, u8 status); 1415 bool hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor, 1416 int *err); 1417 bool hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle, int *err); 1418 bool hci_remove_all_adv_monitor(struct hci_dev *hdev, int *err); 1419 bool hci_is_adv_monitoring(struct hci_dev *hdev); 1420 int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev); 1421 1422 void hci_event_packet(struct hci_dev *hdev, struct sk_buff *skb); 1423 1424 void hci_init_sysfs(struct hci_dev *hdev); 1425 void hci_conn_init_sysfs(struct hci_conn *conn); 1426 void hci_conn_add_sysfs(struct hci_conn *conn); 1427 void hci_conn_del_sysfs(struct hci_conn *conn); 1428 1429 #define SET_HCIDEV_DEV(hdev, pdev) ((hdev)->dev.parent = (pdev)) 1430 1431 /* ----- LMP capabilities ----- */ 1432 #define lmp_encrypt_capable(dev) ((dev)->features[0][0] & LMP_ENCRYPT) 1433 #define lmp_rswitch_capable(dev) ((dev)->features[0][0] & LMP_RSWITCH) 1434 #define lmp_hold_capable(dev) ((dev)->features[0][0] & LMP_HOLD) 1435 #define lmp_sniff_capable(dev) ((dev)->features[0][0] & LMP_SNIFF) 1436 #define lmp_park_capable(dev) ((dev)->features[0][1] & LMP_PARK) 1437 #define lmp_inq_rssi_capable(dev) ((dev)->features[0][3] & LMP_RSSI_INQ) 1438 #define lmp_esco_capable(dev) ((dev)->features[0][3] & LMP_ESCO) 1439 #define lmp_bredr_capable(dev) (!((dev)->features[0][4] & LMP_NO_BREDR)) 1440 #define lmp_le_capable(dev) ((dev)->features[0][4] & LMP_LE) 1441 #define lmp_sniffsubr_capable(dev) ((dev)->features[0][5] & LMP_SNIFF_SUBR) 1442 #define lmp_pause_enc_capable(dev) ((dev)->features[0][5] & LMP_PAUSE_ENC) 1443 #define lmp_esco_2m_capable(dev) ((dev)->features[0][5] & LMP_EDR_ESCO_2M) 1444 #define lmp_ext_inq_capable(dev) ((dev)->features[0][6] & LMP_EXT_INQ) 1445 #define lmp_le_br_capable(dev) (!!((dev)->features[0][6] & LMP_SIMUL_LE_BR)) 1446 #define lmp_ssp_capable(dev) ((dev)->features[0][6] & LMP_SIMPLE_PAIR) 1447 #define lmp_no_flush_capable(dev) ((dev)->features[0][6] & LMP_NO_FLUSH) 1448 #define lmp_lsto_capable(dev) ((dev)->features[0][7] & LMP_LSTO) 1449 #define lmp_inq_tx_pwr_capable(dev) ((dev)->features[0][7] & LMP_INQ_TX_PWR) 1450 #define lmp_ext_feat_capable(dev) ((dev)->features[0][7] & LMP_EXTFEATURES) 1451 #define lmp_transp_capable(dev) ((dev)->features[0][2] & LMP_TRANSPARENT) 1452 #define lmp_edr_2m_capable(dev) ((dev)->features[0][3] & LMP_EDR_2M) 1453 #define lmp_edr_3m_capable(dev) ((dev)->features[0][3] & LMP_EDR_3M) 1454 #define lmp_edr_3slot_capable(dev) ((dev)->features[0][4] & LMP_EDR_3SLOT) 1455 #define lmp_edr_5slot_capable(dev) ((dev)->features[0][5] & LMP_EDR_5SLOT) 1456 1457 /* ----- Extended LMP capabilities ----- */ 1458 #define lmp_cpb_central_capable(dev) ((dev)->features[2][0] & LMP_CPB_CENTRAL) 1459 #define lmp_cpb_peripheral_capable(dev) ((dev)->features[2][0] & LMP_CPB_PERIPHERAL) 1460 #define lmp_sync_train_capable(dev) ((dev)->features[2][0] & LMP_SYNC_TRAIN) 1461 #define lmp_sync_scan_capable(dev) ((dev)->features[2][0] & LMP_SYNC_SCAN) 1462 #define lmp_sc_capable(dev) ((dev)->features[2][1] & LMP_SC) 1463 #define lmp_ping_capable(dev) ((dev)->features[2][1] & LMP_PING) 1464 1465 /* ----- Host capabilities ----- */ 1466 #define lmp_host_ssp_capable(dev) ((dev)->features[1][0] & LMP_HOST_SSP) 1467 #define lmp_host_sc_capable(dev) ((dev)->features[1][0] & LMP_HOST_SC) 1468 #define lmp_host_le_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE)) 1469 #define lmp_host_le_br_capable(dev) (!!((dev)->features[1][0] & LMP_HOST_LE_BREDR)) 1470 1471 #define hdev_is_powered(dev) (test_bit(HCI_UP, &(dev)->flags) && \ 1472 !hci_dev_test_flag(dev, HCI_AUTO_OFF)) 1473 #define bredr_sc_enabled(dev) (lmp_sc_capable(dev) && \ 1474 hci_dev_test_flag(dev, HCI_SC_ENABLED)) 1475 #define rpa_valid(dev) (bacmp(&dev->rpa, BDADDR_ANY) && \ 1476 !hci_dev_test_flag(dev, HCI_RPA_EXPIRED)) 1477 #define adv_rpa_valid(adv) (bacmp(&adv->random_addr, BDADDR_ANY) && \ 1478 !adv->rpa_expired) 1479 1480 #define scan_1m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_1M) || \ 1481 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_1M)) 1482 1483 #define scan_2m(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_2M) || \ 1484 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_2M)) 1485 1486 #define scan_coded(dev) (((dev)->le_tx_def_phys & HCI_LE_SET_PHY_CODED) || \ 1487 ((dev)->le_rx_def_phys & HCI_LE_SET_PHY_CODED)) 1488 1489 #define ll_privacy_capable(dev) ((dev)->le_features[0] & HCI_LE_LL_PRIVACY) 1490 1491 /* Use LL Privacy based address resolution if supported */ 1492 #define use_ll_privacy(dev) (ll_privacy_capable(dev) && \ 1493 hci_dev_test_flag(dev, HCI_ENABLE_LL_PRIVACY)) 1494 1495 #define privacy_mode_capable(dev) (use_ll_privacy(dev) && \ 1496 (hdev->commands[39] & 0x04)) 1497 1498 /* Use enhanced synchronous connection if command is supported */ 1499 #define enhanced_sco_capable(dev) ((dev)->commands[29] & 0x08) 1500 1501 /* Use ext scanning if set ext scan param and ext scan enable is supported */ 1502 #define use_ext_scan(dev) (((dev)->commands[37] & 0x20) && \ 1503 ((dev)->commands[37] & 0x40)) 1504 /* Use ext create connection if command is supported */ 1505 #define use_ext_conn(dev) ((dev)->commands[37] & 0x80) 1506 1507 /* Extended advertising support */ 1508 #define ext_adv_capable(dev) (((dev)->le_features[1] & HCI_LE_EXT_ADV)) 1509 1510 /* BLUETOOTH CORE SPECIFICATION Version 5.3 | Vol 4, Part E page 1789: 1511 * 1512 * C24: Mandatory if the LE Controller supports Connection State and either 1513 * LE Feature (LL Privacy) or LE Feature (Extended Advertising) is supported 1514 */ 1515 #define use_enhanced_conn_complete(dev) (ll_privacy_capable(dev) || \ 1516 ext_adv_capable(dev)) 1517 1518 /* ----- HCI protocols ----- */ 1519 #define HCI_PROTO_DEFER 0x01 1520 1521 static inline int hci_proto_connect_ind(struct hci_dev *hdev, bdaddr_t *bdaddr, 1522 __u8 type, __u8 *flags) 1523 { 1524 switch (type) { 1525 case ACL_LINK: 1526 return l2cap_connect_ind(hdev, bdaddr); 1527 1528 case SCO_LINK: 1529 case ESCO_LINK: 1530 return sco_connect_ind(hdev, bdaddr, flags); 1531 1532 default: 1533 BT_ERR("unknown link type %d", type); 1534 return -EINVAL; 1535 } 1536 } 1537 1538 static inline int hci_proto_disconn_ind(struct hci_conn *conn) 1539 { 1540 if (conn->type != ACL_LINK && conn->type != LE_LINK) 1541 return HCI_ERROR_REMOTE_USER_TERM; 1542 1543 return l2cap_disconn_ind(conn); 1544 } 1545 1546 /* ----- HCI callbacks ----- */ 1547 struct hci_cb { 1548 struct list_head list; 1549 1550 char *name; 1551 1552 void (*connect_cfm) (struct hci_conn *conn, __u8 status); 1553 void (*disconn_cfm) (struct hci_conn *conn, __u8 status); 1554 void (*security_cfm) (struct hci_conn *conn, __u8 status, 1555 __u8 encrypt); 1556 void (*key_change_cfm) (struct hci_conn *conn, __u8 status); 1557 void (*role_switch_cfm) (struct hci_conn *conn, __u8 status, __u8 role); 1558 }; 1559 1560 static inline void hci_connect_cfm(struct hci_conn *conn, __u8 status) 1561 { 1562 struct hci_cb *cb; 1563 1564 mutex_lock(&hci_cb_list_lock); 1565 list_for_each_entry(cb, &hci_cb_list, list) { 1566 if (cb->connect_cfm) 1567 cb->connect_cfm(conn, status); 1568 } 1569 mutex_unlock(&hci_cb_list_lock); 1570 1571 if (conn->connect_cfm_cb) 1572 conn->connect_cfm_cb(conn, status); 1573 } 1574 1575 static inline void hci_disconn_cfm(struct hci_conn *conn, __u8 reason) 1576 { 1577 struct hci_cb *cb; 1578 1579 mutex_lock(&hci_cb_list_lock); 1580 list_for_each_entry(cb, &hci_cb_list, list) { 1581 if (cb->disconn_cfm) 1582 cb->disconn_cfm(conn, reason); 1583 } 1584 mutex_unlock(&hci_cb_list_lock); 1585 1586 if (conn->disconn_cfm_cb) 1587 conn->disconn_cfm_cb(conn, reason); 1588 } 1589 1590 static inline void hci_auth_cfm(struct hci_conn *conn, __u8 status) 1591 { 1592 struct hci_cb *cb; 1593 __u8 encrypt; 1594 1595 if (test_bit(HCI_CONN_ENCRYPT_PEND, &conn->flags)) 1596 return; 1597 1598 encrypt = test_bit(HCI_CONN_ENCRYPT, &conn->flags) ? 0x01 : 0x00; 1599 1600 mutex_lock(&hci_cb_list_lock); 1601 list_for_each_entry(cb, &hci_cb_list, list) { 1602 if (cb->security_cfm) 1603 cb->security_cfm(conn, status, encrypt); 1604 } 1605 mutex_unlock(&hci_cb_list_lock); 1606 1607 if (conn->security_cfm_cb) 1608 conn->security_cfm_cb(conn, status); 1609 } 1610 1611 static inline void hci_encrypt_cfm(struct hci_conn *conn, __u8 status) 1612 { 1613 struct hci_cb *cb; 1614 __u8 encrypt; 1615 1616 if (conn->state == BT_CONFIG) { 1617 if (!status) 1618 conn->state = BT_CONNECTED; 1619 1620 hci_connect_cfm(conn, status); 1621 hci_conn_drop(conn); 1622 return; 1623 } 1624 1625 if (!test_bit(HCI_CONN_ENCRYPT, &conn->flags)) 1626 encrypt = 0x00; 1627 else if (test_bit(HCI_CONN_AES_CCM, &conn->flags)) 1628 encrypt = 0x02; 1629 else 1630 encrypt = 0x01; 1631 1632 if (!status) { 1633 if (conn->sec_level == BT_SECURITY_SDP) 1634 conn->sec_level = BT_SECURITY_LOW; 1635 1636 if (conn->pending_sec_level > conn->sec_level) 1637 conn->sec_level = conn->pending_sec_level; 1638 } 1639 1640 mutex_lock(&hci_cb_list_lock); 1641 list_for_each_entry(cb, &hci_cb_list, list) { 1642 if (cb->security_cfm) 1643 cb->security_cfm(conn, status, encrypt); 1644 } 1645 mutex_unlock(&hci_cb_list_lock); 1646 1647 if (conn->security_cfm_cb) 1648 conn->security_cfm_cb(conn, status); 1649 } 1650 1651 static inline void hci_key_change_cfm(struct hci_conn *conn, __u8 status) 1652 { 1653 struct hci_cb *cb; 1654 1655 mutex_lock(&hci_cb_list_lock); 1656 list_for_each_entry(cb, &hci_cb_list, list) { 1657 if (cb->key_change_cfm) 1658 cb->key_change_cfm(conn, status); 1659 } 1660 mutex_unlock(&hci_cb_list_lock); 1661 } 1662 1663 static inline void hci_role_switch_cfm(struct hci_conn *conn, __u8 status, 1664 __u8 role) 1665 { 1666 struct hci_cb *cb; 1667 1668 mutex_lock(&hci_cb_list_lock); 1669 list_for_each_entry(cb, &hci_cb_list, list) { 1670 if (cb->role_switch_cfm) 1671 cb->role_switch_cfm(conn, status, role); 1672 } 1673 mutex_unlock(&hci_cb_list_lock); 1674 } 1675 1676 static inline bool hci_bdaddr_is_rpa(bdaddr_t *bdaddr, u8 addr_type) 1677 { 1678 if (addr_type != ADDR_LE_DEV_RANDOM) 1679 return false; 1680 1681 if ((bdaddr->b[5] & 0xc0) == 0x40) 1682 return true; 1683 1684 return false; 1685 } 1686 1687 static inline bool hci_is_identity_address(bdaddr_t *addr, u8 addr_type) 1688 { 1689 if (addr_type == ADDR_LE_DEV_PUBLIC) 1690 return true; 1691 1692 /* Check for Random Static address type */ 1693 if ((addr->b[5] & 0xc0) == 0xc0) 1694 return true; 1695 1696 return false; 1697 } 1698 1699 static inline struct smp_irk *hci_get_irk(struct hci_dev *hdev, 1700 bdaddr_t *bdaddr, u8 addr_type) 1701 { 1702 if (!hci_bdaddr_is_rpa(bdaddr, addr_type)) 1703 return NULL; 1704 1705 return hci_find_irk_by_rpa(hdev, bdaddr); 1706 } 1707 1708 static inline int hci_check_conn_params(u16 min, u16 max, u16 latency, 1709 u16 to_multiplier) 1710 { 1711 u16 max_latency; 1712 1713 if (min > max || min < 6 || max > 3200) 1714 return -EINVAL; 1715 1716 if (to_multiplier < 10 || to_multiplier > 3200) 1717 return -EINVAL; 1718 1719 if (max >= to_multiplier * 8) 1720 return -EINVAL; 1721 1722 max_latency = (to_multiplier * 4 / max) - 1; 1723 if (latency > 499 || latency > max_latency) 1724 return -EINVAL; 1725 1726 return 0; 1727 } 1728 1729 int hci_register_cb(struct hci_cb *hcb); 1730 int hci_unregister_cb(struct hci_cb *hcb); 1731 1732 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, 1733 const void *param); 1734 1735 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, 1736 const void *param); 1737 void hci_send_acl(struct hci_chan *chan, struct sk_buff *skb, __u16 flags); 1738 void hci_send_sco(struct hci_conn *conn, struct sk_buff *skb); 1739 1740 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode); 1741 1742 u32 hci_conn_get_phy(struct hci_conn *conn); 1743 1744 /* ----- HCI Sockets ----- */ 1745 void hci_send_to_sock(struct hci_dev *hdev, struct sk_buff *skb); 1746 void hci_send_to_channel(unsigned short channel, struct sk_buff *skb, 1747 int flag, struct sock *skip_sk); 1748 void hci_send_to_monitor(struct hci_dev *hdev, struct sk_buff *skb); 1749 void hci_send_monitor_ctrl_event(struct hci_dev *hdev, u16 event, 1750 void *data, u16 data_len, ktime_t tstamp, 1751 int flag, struct sock *skip_sk); 1752 1753 void hci_sock_dev_event(struct hci_dev *hdev, int event); 1754 1755 #define HCI_MGMT_VAR_LEN BIT(0) 1756 #define HCI_MGMT_NO_HDEV BIT(1) 1757 #define HCI_MGMT_UNTRUSTED BIT(2) 1758 #define HCI_MGMT_UNCONFIGURED BIT(3) 1759 #define HCI_MGMT_HDEV_OPTIONAL BIT(4) 1760 1761 struct hci_mgmt_handler { 1762 int (*func) (struct sock *sk, struct hci_dev *hdev, void *data, 1763 u16 data_len); 1764 size_t data_len; 1765 unsigned long flags; 1766 }; 1767 1768 struct hci_mgmt_chan { 1769 struct list_head list; 1770 unsigned short channel; 1771 size_t handler_count; 1772 const struct hci_mgmt_handler *handlers; 1773 void (*hdev_init) (struct sock *sk, struct hci_dev *hdev); 1774 }; 1775 1776 int hci_mgmt_chan_register(struct hci_mgmt_chan *c); 1777 void hci_mgmt_chan_unregister(struct hci_mgmt_chan *c); 1778 1779 /* Management interface */ 1780 #define DISCOV_TYPE_BREDR (BIT(BDADDR_BREDR)) 1781 #define DISCOV_TYPE_LE (BIT(BDADDR_LE_PUBLIC) | \ 1782 BIT(BDADDR_LE_RANDOM)) 1783 #define DISCOV_TYPE_INTERLEAVED (BIT(BDADDR_BREDR) | \ 1784 BIT(BDADDR_LE_PUBLIC) | \ 1785 BIT(BDADDR_LE_RANDOM)) 1786 1787 /* These LE scan and inquiry parameters were chosen according to LE General 1788 * Discovery Procedure specification. 1789 */ 1790 #define DISCOV_LE_SCAN_WIN 0x12 1791 #define DISCOV_LE_SCAN_INT 0x12 1792 #define DISCOV_LE_TIMEOUT 10240 /* msec */ 1793 #define DISCOV_INTERLEAVED_TIMEOUT 5120 /* msec */ 1794 #define DISCOV_INTERLEAVED_INQUIRY_LEN 0x04 1795 #define DISCOV_BREDR_INQUIRY_LEN 0x08 1796 #define DISCOV_LE_RESTART_DELAY msecs_to_jiffies(200) /* msec */ 1797 #define DISCOV_LE_FAST_ADV_INT_MIN 0x00A0 /* 100 msec */ 1798 #define DISCOV_LE_FAST_ADV_INT_MAX 0x00F0 /* 150 msec */ 1799 1800 #define NAME_RESOLVE_DURATION msecs_to_jiffies(10240) /* 10.24 sec */ 1801 1802 void mgmt_fill_version_info(void *ver); 1803 int mgmt_new_settings(struct hci_dev *hdev); 1804 void mgmt_index_added(struct hci_dev *hdev); 1805 void mgmt_index_removed(struct hci_dev *hdev); 1806 void mgmt_set_powered_failed(struct hci_dev *hdev, int err); 1807 void mgmt_power_on(struct hci_dev *hdev, int err); 1808 void __mgmt_power_off(struct hci_dev *hdev); 1809 void mgmt_new_link_key(struct hci_dev *hdev, struct link_key *key, 1810 bool persistent); 1811 void mgmt_device_connected(struct hci_dev *hdev, struct hci_conn *conn, 1812 u8 *name, u8 name_len); 1813 void mgmt_device_disconnected(struct hci_dev *hdev, bdaddr_t *bdaddr, 1814 u8 link_type, u8 addr_type, u8 reason, 1815 bool mgmt_connected); 1816 void mgmt_disconnect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, 1817 u8 link_type, u8 addr_type, u8 status); 1818 void mgmt_connect_failed(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1819 u8 addr_type, u8 status); 1820 void mgmt_pin_code_request(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 secure); 1821 void mgmt_pin_code_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1822 u8 status); 1823 void mgmt_pin_code_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1824 u8 status); 1825 int mgmt_user_confirm_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1826 u8 link_type, u8 addr_type, u32 value, 1827 u8 confirm_hint); 1828 int mgmt_user_confirm_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1829 u8 link_type, u8 addr_type, u8 status); 1830 int mgmt_user_confirm_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1831 u8 link_type, u8 addr_type, u8 status); 1832 int mgmt_user_passkey_request(struct hci_dev *hdev, bdaddr_t *bdaddr, 1833 u8 link_type, u8 addr_type); 1834 int mgmt_user_passkey_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1835 u8 link_type, u8 addr_type, u8 status); 1836 int mgmt_user_passkey_neg_reply_complete(struct hci_dev *hdev, bdaddr_t *bdaddr, 1837 u8 link_type, u8 addr_type, u8 status); 1838 int mgmt_user_passkey_notify(struct hci_dev *hdev, bdaddr_t *bdaddr, 1839 u8 link_type, u8 addr_type, u32 passkey, 1840 u8 entered); 1841 void mgmt_auth_failed(struct hci_conn *conn, u8 status); 1842 void mgmt_auth_enable_complete(struct hci_dev *hdev, u8 status); 1843 void mgmt_set_class_of_dev_complete(struct hci_dev *hdev, u8 *dev_class, 1844 u8 status); 1845 void mgmt_set_local_name_complete(struct hci_dev *hdev, u8 *name, u8 status); 1846 void mgmt_start_discovery_complete(struct hci_dev *hdev, u8 status); 1847 void mgmt_stop_discovery_complete(struct hci_dev *hdev, u8 status); 1848 void mgmt_device_found(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1849 u8 addr_type, u8 *dev_class, s8 rssi, u32 flags, 1850 u8 *eir, u16 eir_len, u8 *scan_rsp, u8 scan_rsp_len); 1851 void mgmt_remote_name(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 link_type, 1852 u8 addr_type, s8 rssi, u8 *name, u8 name_len); 1853 void mgmt_discovering(struct hci_dev *hdev, u8 discovering); 1854 void mgmt_suspending(struct hci_dev *hdev, u8 state); 1855 void mgmt_resuming(struct hci_dev *hdev, u8 reason, bdaddr_t *bdaddr, 1856 u8 addr_type); 1857 bool mgmt_powering_down(struct hci_dev *hdev); 1858 void mgmt_new_ltk(struct hci_dev *hdev, struct smp_ltk *key, bool persistent); 1859 void mgmt_new_irk(struct hci_dev *hdev, struct smp_irk *irk, bool persistent); 1860 void mgmt_new_csrk(struct hci_dev *hdev, struct smp_csrk *csrk, 1861 bool persistent); 1862 void mgmt_new_conn_param(struct hci_dev *hdev, bdaddr_t *bdaddr, 1863 u8 bdaddr_type, u8 store_hint, u16 min_interval, 1864 u16 max_interval, u16 latency, u16 timeout); 1865 void mgmt_smp_complete(struct hci_conn *conn, bool complete); 1866 bool mgmt_get_connectable(struct hci_dev *hdev); 1867 u8 mgmt_get_adv_discov_flags(struct hci_dev *hdev); 1868 void mgmt_advertising_added(struct sock *sk, struct hci_dev *hdev, 1869 u8 instance); 1870 void mgmt_advertising_removed(struct sock *sk, struct hci_dev *hdev, 1871 u8 instance); 1872 void mgmt_adv_monitor_removed(struct hci_dev *hdev, u16 handle); 1873 int mgmt_phy_configuration_changed(struct hci_dev *hdev, struct sock *skip); 1874 int mgmt_add_adv_patterns_monitor_complete(struct hci_dev *hdev, u8 status); 1875 int mgmt_remove_adv_monitor_complete(struct hci_dev *hdev, u8 status); 1876 void mgmt_adv_monitor_device_lost(struct hci_dev *hdev, u16 handle, 1877 bdaddr_t *bdaddr, u8 addr_type); 1878 1879 u8 hci_le_conn_update(struct hci_conn *conn, u16 min, u16 max, u16 latency, 1880 u16 to_multiplier); 1881 void hci_le_start_enc(struct hci_conn *conn, __le16 ediv, __le64 rand, 1882 __u8 ltk[16], __u8 key_size); 1883 1884 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, 1885 u8 *bdaddr_type); 1886 1887 #define SCO_AIRMODE_MASK 0x0003 1888 #define SCO_AIRMODE_CVSD 0x0000 1889 #define SCO_AIRMODE_TRANSP 0x0003 1890 1891 #define LOCAL_CODEC_ACL_MASK BIT(0) 1892 #define LOCAL_CODEC_SCO_MASK BIT(1) 1893 1894 #define TRANSPORT_TYPE_MAX 0x04 1895 1896 #endif /* __HCI_CORE_H */ 1897