Lines Matching refs:hdev
69 struct hci_dev *hdev = NULL, *d; in __hci_dev_get() local
79 hdev = hci_dev_hold(d); in __hci_dev_get()
86 return hdev; in __hci_dev_get()
99 static void hci_dev_put_srcu(struct hci_dev *hdev, int srcu_index) in hci_dev_put_srcu() argument
101 srcu_read_unlock(&hdev->srcu, srcu_index); in hci_dev_put_srcu()
102 hci_dev_put(hdev); in hci_dev_put_srcu()
107 bool hci_discovery_active(struct hci_dev *hdev) in hci_discovery_active() argument
109 struct discovery_state *discov = &hdev->discovery; in hci_discovery_active()
121 void hci_discovery_set_state(struct hci_dev *hdev, int state) in hci_discovery_set_state() argument
123 int old_state = hdev->discovery.state; in hci_discovery_set_state()
128 hdev->discovery.state = state; in hci_discovery_set_state()
132 hci_update_passive_scan(hdev); in hci_discovery_set_state()
135 mgmt_discovering(hdev, 0); in hci_discovery_set_state()
140 mgmt_discovering(hdev, 1); in hci_discovery_set_state()
148 bt_dev_dbg(hdev, "state %u -> %u", old_state, state); in hci_discovery_set_state()
151 void hci_inquiry_cache_flush(struct hci_dev *hdev) in hci_inquiry_cache_flush() argument
153 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_flush()
165 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, in hci_inquiry_cache_lookup() argument
168 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup()
181 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, in hci_inquiry_cache_lookup_unknown() argument
184 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_unknown()
197 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, in hci_inquiry_cache_lookup_resolve() argument
201 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_resolve()
216 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, in hci_inquiry_cache_update_resolve() argument
219 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update_resolve()
235 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, in hci_inquiry_cache_update() argument
238 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update()
244 hci_remove_remote_oob_data(hdev, &data->bdaddr, BDADDR_BREDR); in hci_inquiry_cache_update()
249 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); in hci_inquiry_cache_update()
257 hci_inquiry_cache_update_resolve(hdev, ie); in hci_inquiry_cache_update()
297 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf) in inquiry_cache_dump() argument
299 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_dump()
329 struct hci_dev *hdev; in hci_inquiry() local
336 hdev = hci_dev_get(ir.dev_id); in hci_inquiry()
337 if (!hdev) in hci_inquiry()
340 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_inquiry()
345 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_inquiry()
350 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_inquiry()
361 hci_dev_lock(hdev); in hci_inquiry()
362 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || in hci_inquiry()
363 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { in hci_inquiry()
364 hci_inquiry_cache_flush(hdev); in hci_inquiry()
367 hci_dev_unlock(hdev); in hci_inquiry()
370 hci_req_sync_lock(hdev); in hci_inquiry()
371 err = hci_inquiry_sync(hdev, ir.length, ir.num_rsp); in hci_inquiry()
372 hci_req_sync_unlock(hdev); in hci_inquiry()
380 if (wait_on_bit(&hdev->flags, HCI_INQUIRY, in hci_inquiry()
401 hci_dev_lock(hdev); in hci_inquiry()
402 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf); in hci_inquiry()
403 hci_dev_unlock(hdev); in hci_inquiry()
418 hci_dev_put(hdev); in hci_inquiry()
422 static int hci_dev_do_open(struct hci_dev *hdev) in hci_dev_do_open() argument
426 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_open()
428 hci_req_sync_lock(hdev); in hci_dev_do_open()
430 ret = hci_dev_open_sync(hdev); in hci_dev_do_open()
432 hci_req_sync_unlock(hdev); in hci_dev_do_open()
440 struct hci_dev *hdev; in hci_dev_open() local
443 hdev = hci_dev_get(dev); in hci_dev_open()
444 if (!hdev) in hci_dev_open()
456 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open()
457 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_open()
467 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_open()
468 cancel_delayed_work(&hdev->power_off); in hci_dev_open()
474 flush_workqueue(hdev->req_workqueue); in hci_dev_open()
482 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open()
483 !hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_open()
484 hci_dev_set_flag(hdev, HCI_BONDABLE); in hci_dev_open()
486 err = hci_dev_do_open(hdev); in hci_dev_open()
489 hci_dev_put(hdev); in hci_dev_open()
493 int hci_dev_do_close(struct hci_dev *hdev) in hci_dev_do_close() argument
497 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_close()
499 hci_req_sync_lock(hdev); in hci_dev_do_close()
501 err = hci_dev_close_sync(hdev); in hci_dev_do_close()
503 hci_req_sync_unlock(hdev); in hci_dev_do_close()
510 struct hci_dev *hdev; in hci_dev_close() local
513 hdev = hci_dev_get(dev); in hci_dev_close()
514 if (!hdev) in hci_dev_close()
517 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close()
522 cancel_work_sync(&hdev->power_on); in hci_dev_close()
523 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_close()
524 cancel_delayed_work(&hdev->power_off); in hci_dev_close()
526 err = hci_dev_do_close(hdev); in hci_dev_close()
529 hci_dev_put(hdev); in hci_dev_close()
533 static int hci_dev_do_reset(struct hci_dev *hdev) in hci_dev_do_reset() argument
537 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_reset()
539 hci_req_sync_lock(hdev); in hci_dev_do_reset()
542 skb_queue_purge(&hdev->rx_q); in hci_dev_do_reset()
543 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_reset()
546 hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); in hci_dev_do_reset()
556 cancel_delayed_work(&hdev->cmd_timer); in hci_dev_do_reset()
557 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_do_reset()
562 drain_workqueue(hdev->workqueue); in hci_dev_do_reset()
564 hci_dev_lock(hdev); in hci_dev_do_reset()
565 hci_inquiry_cache_flush(hdev); in hci_dev_do_reset()
566 hci_conn_hash_flush(hdev); in hci_dev_do_reset()
567 hci_dev_unlock(hdev); in hci_dev_do_reset()
569 if (hdev->flush) in hci_dev_do_reset()
570 hdev->flush(hdev); in hci_dev_do_reset()
572 hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); in hci_dev_do_reset()
574 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_reset()
575 hdev->acl_cnt = 0; in hci_dev_do_reset()
576 hdev->sco_cnt = 0; in hci_dev_do_reset()
577 hdev->le_cnt = 0; in hci_dev_do_reset()
578 hdev->iso_cnt = 0; in hci_dev_do_reset()
580 ret = hci_reset_sync(hdev); in hci_dev_do_reset()
582 hci_req_sync_unlock(hdev); in hci_dev_do_reset()
588 struct hci_dev *hdev; in hci_dev_reset() local
591 hdev = hci_dev_get_srcu(dev, &srcu_index); in hci_dev_reset()
592 if (!hdev) in hci_dev_reset()
595 if (!test_bit(HCI_UP, &hdev->flags)) { in hci_dev_reset()
600 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset()
605 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset()
610 err = hci_dev_do_reset(hdev); in hci_dev_reset()
613 hci_dev_put_srcu(hdev, srcu_index); in hci_dev_reset()
619 struct hci_dev *hdev; in hci_dev_reset_stat() local
622 hdev = hci_dev_get(dev); in hci_dev_reset_stat()
623 if (!hdev) in hci_dev_reset_stat()
626 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset_stat()
631 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset_stat()
636 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); in hci_dev_reset_stat()
639 hci_dev_put(hdev); in hci_dev_reset_stat()
643 static void hci_update_passive_scan_state(struct hci_dev *hdev, u8 scan) in hci_update_passive_scan_state() argument
647 BT_DBG("%s scan 0x%02x", hdev->name, scan); in hci_update_passive_scan_state()
650 conn_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_passive_scan_state()
653 conn_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_passive_scan_state()
657 discov_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_passive_scan_state()
660 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_update_passive_scan_state()
661 discov_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_passive_scan_state()
665 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in hci_update_passive_scan_state()
670 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_update_passive_scan_state()
672 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_state()
673 hci_update_adv_data(hdev, hdev->cur_adv_instance); in hci_update_passive_scan_state()
675 mgmt_new_settings(hdev); in hci_update_passive_scan_state()
681 struct hci_dev *hdev; in hci_dev_cmd() local
689 hdev = hci_dev_get(dr.dev_id); in hci_dev_cmd()
690 if (!hdev) in hci_dev_cmd()
693 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_cmd()
698 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_cmd()
703 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_dev_cmd()
710 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE, in hci_dev_cmd()
715 if (!lmp_encrypt_capable(hdev)) { in hci_dev_cmd()
720 if (!test_bit(HCI_AUTH, &hdev->flags)) { in hci_dev_cmd()
722 err = hci_cmd_sync_status(hdev, in hci_dev_cmd()
730 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_ENCRYPT_MODE, in hci_dev_cmd()
735 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE, in hci_dev_cmd()
742 hci_update_passive_scan_state(hdev, dr.dev_opt); in hci_dev_cmd()
748 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, in hci_dev_cmd()
753 hdev->link_mode = ((__u16) dr.dev_opt) & in hci_dev_cmd()
758 if (hdev->pkt_type == (__u16) dr.dev_opt) in hci_dev_cmd()
761 hdev->pkt_type = (__u16) dr.dev_opt; in hci_dev_cmd()
762 mgmt_phy_configuration_changed(hdev, NULL); in hci_dev_cmd()
766 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
767 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
771 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
772 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
781 hci_dev_put(hdev); in hci_dev_cmd()
787 struct hci_dev *hdev; in hci_get_dev_list() local
807 list_for_each_entry(hdev, &hci_dev_list, list) { in hci_get_dev_list()
808 unsigned long flags = hdev->flags; in hci_get_dev_list()
814 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_list()
817 dr[n].dev_id = hdev->id; in hci_get_dev_list()
834 struct hci_dev *hdev; in hci_get_dev_info() local
842 hdev = hci_dev_get(di.dev_id); in hci_get_dev_info()
843 if (!hdev) in hci_get_dev_info()
850 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_info()
851 flags = hdev->flags & ~BIT(HCI_UP); in hci_get_dev_info()
853 flags = hdev->flags; in hci_get_dev_info()
855 strscpy(di.name, hdev->name, sizeof(di.name)); in hci_get_dev_info()
856 di.bdaddr = hdev->bdaddr; in hci_get_dev_info()
857 di.type = (hdev->bus & 0x0f); in hci_get_dev_info()
859 di.pkt_type = hdev->pkt_type; in hci_get_dev_info()
860 if (lmp_bredr_capable(hdev)) { in hci_get_dev_info()
861 di.acl_mtu = hdev->acl_mtu; in hci_get_dev_info()
862 di.acl_pkts = hdev->acl_pkts; in hci_get_dev_info()
863 di.sco_mtu = hdev->sco_mtu; in hci_get_dev_info()
864 di.sco_pkts = hdev->sco_pkts; in hci_get_dev_info()
866 di.acl_mtu = hdev->le_mtu; in hci_get_dev_info()
867 di.acl_pkts = hdev->le_pkts; in hci_get_dev_info()
871 di.link_policy = hdev->link_policy; in hci_get_dev_info()
872 di.link_mode = hdev->link_mode; in hci_get_dev_info()
874 memcpy(&di.stat, &hdev->stat, sizeof(di.stat)); in hci_get_dev_info()
875 memcpy(&di.features, &hdev->features, sizeof(di.features)); in hci_get_dev_info()
880 hci_dev_put(hdev); in hci_get_dev_info()
887 static int hci_dev_do_poweroff(struct hci_dev *hdev) in hci_dev_do_poweroff() argument
891 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_poweroff()
893 hci_req_sync_lock(hdev); in hci_dev_do_poweroff()
895 err = hci_set_powered_sync(hdev, false); in hci_dev_do_poweroff()
897 hci_req_sync_unlock(hdev); in hci_dev_do_poweroff()
904 struct hci_dev *hdev = data; in hci_rfkill_set_block() local
907 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); in hci_rfkill_set_block()
909 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_rfkill_set_block()
912 if (blocked == hci_dev_test_flag(hdev, HCI_RFKILLED)) in hci_rfkill_set_block()
916 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
918 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_rfkill_set_block()
919 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_rfkill_set_block()
920 err = hci_dev_do_poweroff(hdev); in hci_rfkill_set_block()
922 bt_dev_err(hdev, "Error when powering off device on rfkill (%d)", in hci_rfkill_set_block()
929 hci_dev_do_close(hdev); in hci_rfkill_set_block()
933 hci_dev_clear_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
945 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); in hci_power_on() local
948 BT_DBG("%s", hdev->name); in hci_power_on()
950 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on()
951 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on()
952 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
953 cancel_delayed_work(&hdev->power_off); in hci_power_on()
954 err = hci_powered_update_sync(hdev); in hci_power_on()
955 mgmt_power_on(hdev, err); in hci_power_on()
959 err = hci_dev_do_open(hdev); in hci_power_on()
961 hci_dev_lock(hdev); in hci_power_on()
962 mgmt_set_powered_failed(hdev, err); in hci_power_on()
963 hci_dev_unlock(hdev); in hci_power_on()
971 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on()
972 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on()
973 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on()
974 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on()
975 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on()
976 hci_dev_do_close(hdev); in hci_power_on()
977 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
978 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on()
982 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on()
986 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
987 set_bit(HCI_RAW, &hdev->flags); in hci_power_on()
996 mgmt_index_added(hdev); in hci_power_on()
997 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on()
1001 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
1002 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on()
1008 mgmt_index_added(hdev); in hci_power_on()
1014 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_power_off() local
1017 BT_DBG("%s", hdev->name); in hci_power_off()
1019 hci_dev_do_close(hdev); in hci_power_off()
1024 struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset); in hci_error_reset() local
1026 hci_dev_hold(hdev); in hci_error_reset()
1027 BT_DBG("%s", hdev->name); in hci_error_reset()
1029 if (hdev->hw_error) in hci_error_reset()
1030 hdev->hw_error(hdev, hdev->hw_error_code); in hci_error_reset()
1032 bt_dev_err(hdev, "hardware error 0x%2.2x", hdev->hw_error_code); in hci_error_reset()
1034 if (!hci_dev_do_close(hdev)) in hci_error_reset()
1035 hci_dev_do_open(hdev); in hci_error_reset()
1037 hci_dev_put(hdev); in hci_error_reset()
1040 void hci_uuids_clear(struct hci_dev *hdev) in hci_uuids_clear() argument
1044 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) { in hci_uuids_clear()
1050 void hci_link_keys_clear(struct hci_dev *hdev) in hci_link_keys_clear() argument
1054 list_for_each_entry_safe(key, tmp, &hdev->link_keys, list) { in hci_link_keys_clear()
1060 void hci_smp_ltks_clear(struct hci_dev *hdev) in hci_smp_ltks_clear() argument
1064 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_smp_ltks_clear()
1070 void hci_smp_irks_clear(struct hci_dev *hdev) in hci_smp_irks_clear() argument
1074 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { in hci_smp_irks_clear()
1080 void hci_blocked_keys_clear(struct hci_dev *hdev) in hci_blocked_keys_clear() argument
1084 list_for_each_entry_safe(b, tmp, &hdev->blocked_keys, list) { in hci_blocked_keys_clear()
1090 bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]) in hci_is_blocked_key() argument
1096 list_for_each_entry_rcu(b, &hdev->blocked_keys, list) { in hci_is_blocked_key()
1107 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_find_link_key() argument
1112 list_for_each_entry_rcu(k, &hdev->link_keys, list) { in hci_find_link_key()
1116 if (hci_is_blocked_key(hdev, in hci_find_link_key()
1119 bt_dev_warn_ratelimited(hdev, in hci_find_link_key()
1133 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_persistent_key() argument
1181 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_ltk() argument
1187 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_find_ltk()
1194 if (hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_LTK, in hci_find_ltk()
1196 bt_dev_warn_ratelimited(hdev, in hci_find_ltk()
1210 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa) in hci_find_irk_by_rpa() argument
1216 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
1223 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
1224 if (smp_irk_matches(hdev, irk->val, rpa)) { in hci_find_irk_by_rpa()
1232 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_rpa()
1234 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_rpa()
1244 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_irk_by_addr() argument
1255 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_addr()
1263 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_addr()
1265 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_addr()
1275 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_add_link_key() argument
1282 old_key = hci_find_link_key(hdev, bdaddr); in hci_add_link_key()
1291 list_add_rcu(&key->list, &hdev->link_keys); in hci_add_link_key()
1294 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); in hci_add_link_key()
1316 *persistent = hci_persistent_key(hdev, conn, type, in hci_add_link_key()
1322 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_ltk() argument
1329 old_key = hci_find_ltk(hdev, bdaddr, addr_type, role); in hci_add_ltk()
1336 list_add_rcu(&key->list, &hdev->long_term_keys); in hci_add_ltk()
1351 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_irk() argument
1356 irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); in hci_add_irk()
1365 list_add_rcu(&irk->list, &hdev->identity_resolving_keys); in hci_add_irk()
1374 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_link_key() argument
1378 key = hci_find_link_key(hdev, bdaddr); in hci_remove_link_key()
1382 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_link_key()
1390 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) in hci_remove_ltk() argument
1395 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_remove_ltk()
1399 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_ltk()
1409 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) in hci_remove_irk() argument
1413 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { in hci_remove_irk()
1417 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_irk()
1424 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_bdaddr_is_paired() argument
1431 if (hci_find_link_key(hdev, bdaddr)) in hci_bdaddr_is_paired()
1442 irk = hci_get_irk(hdev, bdaddr, addr_type); in hci_bdaddr_is_paired()
1449 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_bdaddr_is_paired()
1463 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_cmd_timeout() local
1466 if (hdev->req_skb) { in hci_cmd_timeout()
1467 u16 opcode = hci_skb_opcode(hdev->req_skb); in hci_cmd_timeout()
1469 bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode); in hci_cmd_timeout()
1471 hci_cmd_sync_cancel_sync(hdev, ETIMEDOUT); in hci_cmd_timeout()
1473 bt_dev_err(hdev, "command tx timeout"); in hci_cmd_timeout()
1476 if (hdev->reset) in hci_cmd_timeout()
1477 hdev->reset(hdev); in hci_cmd_timeout()
1479 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_timeout()
1480 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_timeout()
1486 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_ncmd_timeout() local
1489 bt_dev_err(hdev, "Controller not accepting commands anymore: ncmd = 0"); in hci_ncmd_timeout()
1494 if (test_bit(HCI_INIT, &hdev->flags)) in hci_ncmd_timeout()
1498 hci_reset_dev(hdev); in hci_ncmd_timeout()
1501 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, in hci_find_remote_oob_data() argument
1506 list_for_each_entry(data, &hdev->remote_oob_data, list) { in hci_find_remote_oob_data()
1517 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_remove_remote_oob_data() argument
1522 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
1526 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
1534 void hci_remote_oob_data_clear(struct hci_dev *hdev) in hci_remote_oob_data_clear() argument
1538 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) { in hci_remote_oob_data_clear()
1544 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_remote_oob_data() argument
1550 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_add_remote_oob_data()
1558 list_add(&data->list, &hdev->remote_oob_data); in hci_add_remote_oob_data()
1585 BT_DBG("%s for %pMR", hdev->name, bdaddr); in hci_add_remote_oob_data()
1591 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance) in hci_find_adv_instance() argument
1595 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in hci_find_adv_instance()
1604 struct adv_info *hci_find_adv_sid(struct hci_dev *hdev, u8 sid) in hci_find_adv_sid() argument
1608 list_for_each_entry(adv, &hdev->adv_instances, list) { in hci_find_adv_sid()
1617 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) in hci_get_next_instance() argument
1621 cur_instance = hci_find_adv_instance(hdev, instance); in hci_get_next_instance()
1625 if (cur_instance == list_last_entry(&hdev->adv_instances, in hci_get_next_instance()
1627 return list_first_entry(&hdev->adv_instances, in hci_get_next_instance()
1634 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_adv_instance() argument
1638 adv_instance = hci_find_adv_instance(hdev, instance); in hci_remove_adv_instance()
1642 BT_DBG("%s removing %dMR", hdev->name, instance); in hci_remove_adv_instance()
1644 if (hdev->cur_adv_instance == instance) { in hci_remove_adv_instance()
1645 if (hdev->adv_instance_timeout) { in hci_remove_adv_instance()
1646 cancel_delayed_work(&hdev->adv_instance_expire); in hci_remove_adv_instance()
1647 hdev->adv_instance_timeout = 0; in hci_remove_adv_instance()
1649 hdev->cur_adv_instance = 0x00; in hci_remove_adv_instance()
1657 hdev->adv_instance_cnt--; in hci_remove_adv_instance()
1662 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired) in hci_adv_instances_set_rpa_expired() argument
1666 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) in hci_adv_instances_set_rpa_expired()
1671 void hci_adv_instances_clear(struct hci_dev *hdev) in hci_adv_instances_clear() argument
1675 if (hdev->adv_instance_timeout) { in hci_adv_instances_clear()
1676 disable_delayed_work(&hdev->adv_instance_expire); in hci_adv_instances_clear()
1677 hdev->adv_instance_timeout = 0; in hci_adv_instances_clear()
1680 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in hci_adv_instances_clear()
1686 hdev->adv_instance_cnt = 0; in hci_adv_instances_clear()
1687 hdev->cur_adv_instance = 0x00; in hci_adv_instances_clear()
1701 struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, in hci_add_adv_instance() argument
1710 adv = hci_find_adv_instance(hdev, instance); in hci_add_adv_instance()
1716 if (hdev->adv_instance_cnt >= hdev->le_num_of_adv_sets || in hci_add_adv_instance()
1717 instance < 1 || instance > hdev->le_num_of_adv_sets + 1) in hci_add_adv_instance()
1730 if (hdev->le_num_of_adv_sets == 1 && instance == 1) in hci_add_adv_instance()
1735 list_add(&adv->list, &hdev->adv_instances); in hci_add_adv_instance()
1736 hdev->adv_instance_cnt++; in hci_add_adv_instance()
1749 hci_set_adv_instance_data(hdev, instance, adv_data_len, adv_data, in hci_add_adv_instance()
1756 adv->duration = hdev->def_multi_adv_rotation_duration; in hci_add_adv_instance()
1762 BT_DBG("%s for %dMR", hdev->name, instance); in hci_add_adv_instance()
1768 struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance, u8 sid, in hci_add_per_instance() argument
1774 adv = hci_add_adv_instance(hdev, instance, flags, 0, NULL, 0, NULL, in hci_add_per_instance()
1791 int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, in hci_set_adv_instance_data() argument
1797 adv = hci_find_adv_instance(hdev, instance); in hci_set_adv_instance_data()
1818 if (((adv->flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) || in hci_set_adv_instance_data()
1826 u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance) in hci_adv_instance_flags() argument
1840 if (hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) in hci_adv_instance_flags()
1843 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_adv_instance_flags()
1845 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_adv_instance_flags()
1851 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_flags()
1860 bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance) in hci_adv_instance_is_scannable() argument
1868 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_is_scannable()
1880 void hci_adv_monitors_clear(struct hci_dev *hdev) in hci_adv_monitors_clear() argument
1885 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in hci_adv_monitors_clear()
1886 hci_free_adv_monitor(hdev, monitor); in hci_adv_monitors_clear()
1888 idr_destroy(&hdev->adv_monitors_idr); in hci_adv_monitors_clear()
1894 void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) in hci_free_adv_monitor() argument
1908 idr_remove(&hdev->adv_monitors_idr, monitor->handle); in hci_free_adv_monitor()
1911 hdev->adv_monitors_cnt--; in hci_free_adv_monitor()
1920 int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) in hci_add_adv_monitor() argument
1928 hci_dev_lock(hdev); in hci_add_adv_monitor()
1932 handle = idr_alloc(&hdev->adv_monitors_idr, monitor, min, max, in hci_add_adv_monitor()
1935 hci_dev_unlock(hdev); in hci_add_adv_monitor()
1942 if (!hdev_is_powered(hdev)) in hci_add_adv_monitor()
1945 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_add_adv_monitor()
1947 bt_dev_dbg(hdev, "add monitor %d status %d", in hci_add_adv_monitor()
1953 status = msft_add_monitor_pattern(hdev, monitor); in hci_add_adv_monitor()
1954 bt_dev_dbg(hdev, "add monitor %d msft status %d", in hci_add_adv_monitor()
1966 static int hci_remove_adv_monitor(struct hci_dev *hdev, in hci_remove_adv_monitor() argument
1972 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_remove_adv_monitor()
1974 bt_dev_dbg(hdev, "remove monitor %d status %d", in hci_remove_adv_monitor()
1980 status = msft_remove_monitor(hdev, monitor); in hci_remove_adv_monitor()
1981 bt_dev_dbg(hdev, "remove monitor %d msft status %d", in hci_remove_adv_monitor()
1994 bt_dev_warn(hdev, "Removing monitor with no matching handle %d", in hci_remove_adv_monitor()
1996 hci_free_adv_monitor(hdev, monitor); in hci_remove_adv_monitor()
2002 int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle) in hci_remove_single_adv_monitor() argument
2004 struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle); in hci_remove_single_adv_monitor()
2009 return hci_remove_adv_monitor(hdev, monitor); in hci_remove_single_adv_monitor()
2013 int hci_remove_all_adv_monitor(struct hci_dev *hdev) in hci_remove_all_adv_monitor() argument
2020 monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id); in hci_remove_all_adv_monitor()
2024 status = hci_remove_adv_monitor(hdev, monitor); in hci_remove_all_adv_monitor()
2035 bool hci_is_adv_monitoring(struct hci_dev *hdev) in hci_is_adv_monitoring() argument
2037 return !idr_is_empty(&hdev->adv_monitors_idr); in hci_is_adv_monitoring()
2040 int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev) in hci_get_adv_monitor_offload_ext() argument
2042 if (msft_monitor_supported(hdev)) in hci_get_adv_monitor_offload_ext()
2214 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, in hci_conn_params_lookup() argument
2219 list_for_each_entry(params, &hdev->le_conn_params, list) { in hci_conn_params_lookup()
2269 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, in hci_conn_params_add() argument
2274 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_add()
2280 bt_dev_err(hdev, "out of memory"); in hci_conn_params_add()
2287 list_add(¶ms->list, &hdev->le_conn_params); in hci_conn_params_add()
2290 params->conn_min_interval = hdev->le_conn_min_interval; in hci_conn_params_add()
2291 params->conn_max_interval = hdev->le_conn_max_interval; in hci_conn_params_add()
2292 params->conn_latency = hdev->le_conn_latency; in hci_conn_params_add()
2293 params->supervision_timeout = hdev->le_supv_timeout; in hci_conn_params_add()
2315 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) in hci_conn_params_del() argument
2319 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_del()
2325 hci_update_passive_scan(hdev); in hci_conn_params_del()
2331 void hci_conn_params_clear_disabled(struct hci_dev *hdev) in hci_conn_params_clear_disabled() argument
2335 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) { in hci_conn_params_clear_disabled()
2354 static void hci_conn_params_clear_all(struct hci_dev *hdev) in hci_conn_params_clear_all() argument
2358 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) in hci_conn_params_clear_all()
2377 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_copy_identity_address() argument
2380 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_copy_identity_address()
2381 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_copy_identity_address()
2382 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_copy_identity_address()
2383 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_copy_identity_address()
2384 bacpy(bdaddr, &hdev->static_addr); in hci_copy_identity_address()
2387 bacpy(bdaddr, &hdev->bdaddr); in hci_copy_identity_address()
2392 static void hci_clear_wake_reason(struct hci_dev *hdev) in hci_clear_wake_reason() argument
2394 hci_dev_lock(hdev); in hci_clear_wake_reason()
2396 hdev->wake_reason = 0; in hci_clear_wake_reason()
2397 bacpy(&hdev->wake_addr, BDADDR_ANY); in hci_clear_wake_reason()
2398 hdev->wake_addr_type = 0; in hci_clear_wake_reason()
2400 hci_dev_unlock(hdev); in hci_clear_wake_reason()
2406 struct hci_dev *hdev = in hci_suspend_notifier() local
2411 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_suspend_notifier()
2415 hci_dev_hold(hdev); in hci_suspend_notifier()
2420 ret = hci_suspend_dev(hdev); in hci_suspend_notifier()
2424 ret = hci_resume_dev(hdev); in hci_suspend_notifier()
2429 bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d", in hci_suspend_notifier()
2432 hci_dev_put(hdev); in hci_suspend_notifier()
2439 struct hci_dev *hdev; in hci_alloc_dev_priv() local
2442 alloc_size = sizeof(*hdev); in hci_alloc_dev_priv()
2448 hdev = kzalloc(alloc_size, GFP_KERNEL); in hci_alloc_dev_priv()
2449 if (!hdev) in hci_alloc_dev_priv()
2452 if (init_srcu_struct(&hdev->srcu)) { in hci_alloc_dev_priv()
2453 kfree(hdev); in hci_alloc_dev_priv()
2457 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev_priv()
2458 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev_priv()
2459 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev_priv()
2460 hdev->num_iac = 0x01; /* One IAC support is mandatory */ in hci_alloc_dev_priv()
2461 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev_priv()
2462 hdev->manufacturer = 0xffff; /* Default to internal use */ in hci_alloc_dev_priv()
2463 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2464 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2465 hdev->adv_instance_cnt = 0; in hci_alloc_dev_priv()
2466 hdev->cur_adv_instance = 0x00; in hci_alloc_dev_priv()
2467 hdev->adv_instance_timeout = 0; in hci_alloc_dev_priv()
2469 hdev->advmon_allowlist_duration = 300; in hci_alloc_dev_priv()
2470 hdev->advmon_no_filter_duration = 500; in hci_alloc_dev_priv()
2471 hdev->enable_advmon_interleave_scan = 0x00; /* Default to disable */ in hci_alloc_dev_priv()
2473 hdev->sniff_max_interval = 800; in hci_alloc_dev_priv()
2474 hdev->sniff_min_interval = 80; in hci_alloc_dev_priv()
2476 hdev->le_adv_channel_map = 0x07; in hci_alloc_dev_priv()
2477 hdev->le_adv_min_interval = 0x0800; in hci_alloc_dev_priv()
2478 hdev->le_adv_max_interval = 0x0800; in hci_alloc_dev_priv()
2479 hdev->le_scan_interval = DISCOV_LE_SCAN_INT_FAST; in hci_alloc_dev_priv()
2480 hdev->le_scan_window = DISCOV_LE_SCAN_WIN_FAST; in hci_alloc_dev_priv()
2481 hdev->le_scan_int_suspend = DISCOV_LE_SCAN_INT_SLOW1; in hci_alloc_dev_priv()
2482 hdev->le_scan_window_suspend = DISCOV_LE_SCAN_WIN_SLOW1; in hci_alloc_dev_priv()
2483 hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT; in hci_alloc_dev_priv()
2484 hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN; in hci_alloc_dev_priv()
2485 hdev->le_scan_int_adv_monitor = DISCOV_LE_SCAN_INT_FAST; in hci_alloc_dev_priv()
2486 hdev->le_scan_window_adv_monitor = DISCOV_LE_SCAN_WIN_FAST; in hci_alloc_dev_priv()
2487 hdev->le_scan_int_connect = DISCOV_LE_SCAN_INT_CONN; in hci_alloc_dev_priv()
2488 hdev->le_scan_window_connect = DISCOV_LE_SCAN_WIN_CONN; in hci_alloc_dev_priv()
2489 hdev->le_conn_min_interval = 0x0018; in hci_alloc_dev_priv()
2490 hdev->le_conn_max_interval = 0x0028; in hci_alloc_dev_priv()
2491 hdev->le_conn_latency = 0x0000; in hci_alloc_dev_priv()
2492 hdev->le_supv_timeout = 0x002a; in hci_alloc_dev_priv()
2493 hdev->le_def_tx_len = 0x001b; in hci_alloc_dev_priv()
2494 hdev->le_def_tx_time = 0x0148; in hci_alloc_dev_priv()
2495 hdev->le_max_tx_len = 0x001b; in hci_alloc_dev_priv()
2496 hdev->le_max_tx_time = 0x0148; in hci_alloc_dev_priv()
2497 hdev->le_max_rx_len = 0x001b; in hci_alloc_dev_priv()
2498 hdev->le_max_rx_time = 0x0148; in hci_alloc_dev_priv()
2499 hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2500 hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2501 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2502 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2503 hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; in hci_alloc_dev_priv()
2504 hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; in hci_alloc_dev_priv()
2505 hdev->def_le_autoconnect_timeout = HCI_LE_CONN_TIMEOUT; in hci_alloc_dev_priv()
2506 hdev->min_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2507 hdev->max_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2509 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; in hci_alloc_dev_priv()
2510 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; in hci_alloc_dev_priv()
2511 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE; in hci_alloc_dev_priv()
2512 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE; in hci_alloc_dev_priv()
2513 hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; in hci_alloc_dev_priv()
2514 hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2517 hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD; in hci_alloc_dev_priv()
2518 hdev->def_page_scan_int = 0x0800; in hci_alloc_dev_priv()
2519 hdev->def_page_scan_window = 0x0012; in hci_alloc_dev_priv()
2521 mutex_init(&hdev->lock); in hci_alloc_dev_priv()
2522 mutex_init(&hdev->req_lock); in hci_alloc_dev_priv()
2523 mutex_init(&hdev->mgmt_pending_lock); in hci_alloc_dev_priv()
2525 ida_init(&hdev->unset_handle_ida); in hci_alloc_dev_priv()
2527 INIT_LIST_HEAD(&hdev->mesh_pending); in hci_alloc_dev_priv()
2528 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev_priv()
2529 INIT_LIST_HEAD(&hdev->reject_list); in hci_alloc_dev_priv()
2530 INIT_LIST_HEAD(&hdev->accept_list); in hci_alloc_dev_priv()
2531 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev_priv()
2532 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev_priv()
2533 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev_priv()
2534 INIT_LIST_HEAD(&hdev->identity_resolving_keys); in hci_alloc_dev_priv()
2535 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev_priv()
2536 INIT_LIST_HEAD(&hdev->le_accept_list); in hci_alloc_dev_priv()
2537 INIT_LIST_HEAD(&hdev->le_resolv_list); in hci_alloc_dev_priv()
2538 INIT_LIST_HEAD(&hdev->le_conn_params); in hci_alloc_dev_priv()
2539 INIT_LIST_HEAD(&hdev->pend_le_conns); in hci_alloc_dev_priv()
2540 INIT_LIST_HEAD(&hdev->pend_le_reports); in hci_alloc_dev_priv()
2541 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev_priv()
2542 INIT_LIST_HEAD(&hdev->adv_instances); in hci_alloc_dev_priv()
2543 INIT_LIST_HEAD(&hdev->blocked_keys); in hci_alloc_dev_priv()
2544 INIT_LIST_HEAD(&hdev->monitored_devices); in hci_alloc_dev_priv()
2546 INIT_LIST_HEAD(&hdev->local_codecs); in hci_alloc_dev_priv()
2547 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev_priv()
2548 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev_priv()
2549 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev_priv()
2550 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev_priv()
2551 INIT_WORK(&hdev->error_reset, hci_error_reset); in hci_alloc_dev_priv()
2553 hci_cmd_sync_init(hdev); in hci_alloc_dev_priv()
2555 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev_priv()
2557 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev_priv()
2558 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev_priv()
2559 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev_priv()
2561 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev_priv()
2563 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); in hci_alloc_dev_priv()
2564 INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout); in hci_alloc_dev_priv()
2566 hci_devcd_setup(hdev); in hci_alloc_dev_priv()
2568 hci_init_sysfs(hdev); in hci_alloc_dev_priv()
2569 discovery_init(hdev); in hci_alloc_dev_priv()
2571 return hdev; in hci_alloc_dev_priv()
2576 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
2579 put_device(&hdev->dev); in hci_free_dev()
2584 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
2588 if (!hdev->open || !hdev->close || !hdev->send) in hci_register_dev()
2595 error = dev_set_name(&hdev->dev, "hci%u", id); in hci_register_dev()
2599 hdev->name = dev_name(&hdev->dev); in hci_register_dev()
2600 hdev->id = id; in hci_register_dev()
2602 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
2604 hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name); in hci_register_dev()
2605 if (!hdev->workqueue) { in hci_register_dev()
2610 hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, in hci_register_dev()
2611 hdev->name); in hci_register_dev()
2612 if (!hdev->req_workqueue) { in hci_register_dev()
2613 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2619 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); in hci_register_dev()
2621 error = device_add(&hdev->dev); in hci_register_dev()
2625 hci_leds_init(hdev); in hci_register_dev()
2627 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
2629 hdev); in hci_register_dev()
2630 if (hdev->rfkill) { in hci_register_dev()
2631 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
2632 rfkill_destroy(hdev->rfkill); in hci_register_dev()
2633 hdev->rfkill = NULL; in hci_register_dev()
2637 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) in hci_register_dev()
2638 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_register_dev()
2640 hci_dev_set_flag(hdev, HCI_SETUP); in hci_register_dev()
2641 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in hci_register_dev()
2646 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_register_dev()
2649 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
2655 if (hci_test_quirk(hdev, HCI_QUIRK_RAW_DEVICE)) in hci_register_dev()
2656 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_register_dev()
2661 if (hdev->wakeup) in hci_register_dev()
2662 hdev->conn_flags |= HCI_CONN_FLAG_REMOTE_WAKEUP; in hci_register_dev()
2664 hci_sock_dev_event(hdev, HCI_DEV_REG); in hci_register_dev()
2665 hci_dev_hold(hdev); in hci_register_dev()
2667 error = hci_register_suspend_notifier(hdev); in hci_register_dev()
2671 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
2673 idr_init(&hdev->adv_monitors_idr); in hci_register_dev()
2674 msft_register(hdev); in hci_register_dev()
2679 debugfs_remove_recursive(hdev->debugfs); in hci_register_dev()
2680 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2681 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
2683 ida_free(&hci_index_ida, hdev->id); in hci_register_dev()
2690 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
2692 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
2694 mutex_lock(&hdev->unregister_lock); in hci_unregister_dev()
2695 hci_dev_set_flag(hdev, HCI_UNREGISTER); in hci_unregister_dev()
2696 mutex_unlock(&hdev->unregister_lock); in hci_unregister_dev()
2699 list_del(&hdev->list); in hci_unregister_dev()
2702 synchronize_srcu(&hdev->srcu); in hci_unregister_dev()
2703 cleanup_srcu_struct(&hdev->srcu); in hci_unregister_dev()
2705 disable_work_sync(&hdev->rx_work); in hci_unregister_dev()
2706 disable_work_sync(&hdev->cmd_work); in hci_unregister_dev()
2707 disable_work_sync(&hdev->tx_work); in hci_unregister_dev()
2708 disable_work_sync(&hdev->power_on); in hci_unregister_dev()
2709 disable_work_sync(&hdev->error_reset); in hci_unregister_dev()
2711 hci_cmd_sync_clear(hdev); in hci_unregister_dev()
2713 hci_unregister_suspend_notifier(hdev); in hci_unregister_dev()
2715 hci_dev_do_close(hdev); in hci_unregister_dev()
2717 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
2718 !hci_dev_test_flag(hdev, HCI_SETUP) && in hci_unregister_dev()
2719 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_unregister_dev()
2720 hci_dev_lock(hdev); in hci_unregister_dev()
2721 mgmt_index_removed(hdev); in hci_unregister_dev()
2722 hci_dev_unlock(hdev); in hci_unregister_dev()
2727 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
2729 hci_sock_dev_event(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
2731 if (hdev->rfkill) { in hci_unregister_dev()
2732 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
2733 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
2736 device_del(&hdev->dev); in hci_unregister_dev()
2738 hci_dev_put(hdev); in hci_unregister_dev()
2743 void hci_release_dev(struct hci_dev *hdev) in hci_release_dev() argument
2745 debugfs_remove_recursive(hdev->debugfs); in hci_release_dev()
2746 kfree_const(hdev->hw_info); in hci_release_dev()
2747 kfree_const(hdev->fw_info); in hci_release_dev()
2749 destroy_workqueue(hdev->workqueue); in hci_release_dev()
2750 destroy_workqueue(hdev->req_workqueue); in hci_release_dev()
2752 hci_dev_lock(hdev); in hci_release_dev()
2753 hci_bdaddr_list_clear(&hdev->reject_list); in hci_release_dev()
2754 hci_bdaddr_list_clear(&hdev->accept_list); in hci_release_dev()
2755 hci_uuids_clear(hdev); in hci_release_dev()
2756 hci_link_keys_clear(hdev); in hci_release_dev()
2757 hci_smp_ltks_clear(hdev); in hci_release_dev()
2758 hci_smp_irks_clear(hdev); in hci_release_dev()
2759 hci_remote_oob_data_clear(hdev); in hci_release_dev()
2760 hci_adv_instances_clear(hdev); in hci_release_dev()
2761 hci_adv_monitors_clear(hdev); in hci_release_dev()
2762 hci_bdaddr_list_clear(&hdev->le_accept_list); in hci_release_dev()
2763 hci_bdaddr_list_clear(&hdev->le_resolv_list); in hci_release_dev()
2764 hci_conn_params_clear_all(hdev); in hci_release_dev()
2765 hci_discovery_filter_clear(hdev); in hci_release_dev()
2766 hci_blocked_keys_clear(hdev); in hci_release_dev()
2767 hci_codec_list_clear(&hdev->local_codecs); in hci_release_dev()
2768 msft_release(hdev); in hci_release_dev()
2769 hci_dev_unlock(hdev); in hci_release_dev()
2771 ida_destroy(&hdev->unset_handle_ida); in hci_release_dev()
2772 ida_free(&hci_index_ida, hdev->id); in hci_release_dev()
2773 kfree_skb(hdev->sent_cmd); in hci_release_dev()
2774 kfree_skb(hdev->req_skb); in hci_release_dev()
2775 kfree_skb(hdev->recv_event); in hci_release_dev()
2776 kfree(hdev); in hci_release_dev()
2780 int hci_register_suspend_notifier(struct hci_dev *hdev) in hci_register_suspend_notifier() argument
2784 if (!hdev->suspend_notifier.notifier_call && in hci_register_suspend_notifier()
2785 !hci_test_quirk(hdev, HCI_QUIRK_NO_SUSPEND_NOTIFIER)) { in hci_register_suspend_notifier()
2786 hdev->suspend_notifier.notifier_call = hci_suspend_notifier; in hci_register_suspend_notifier()
2787 ret = register_pm_notifier(&hdev->suspend_notifier); in hci_register_suspend_notifier()
2793 int hci_unregister_suspend_notifier(struct hci_dev *hdev) in hci_unregister_suspend_notifier() argument
2797 if (hdev->suspend_notifier.notifier_call) { in hci_unregister_suspend_notifier()
2798 ret = unregister_pm_notifier(&hdev->suspend_notifier); in hci_unregister_suspend_notifier()
2800 hdev->suspend_notifier.notifier_call = NULL; in hci_unregister_suspend_notifier()
2812 static void hci_cancel_cmd_sync(struct hci_dev *hdev, int err) in hci_cancel_cmd_sync() argument
2814 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_cancel_cmd_sync()
2816 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_cancel_cmd_sync()
2817 disable_delayed_work_sync(&hdev->cmd_timer); in hci_cancel_cmd_sync()
2818 disable_delayed_work_sync(&hdev->ncmd_timer); in hci_cancel_cmd_sync()
2820 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cancel_cmd_sync()
2821 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cancel_cmd_sync()
2824 atomic_set(&hdev->cmd_cnt, 1); in hci_cancel_cmd_sync()
2826 hci_cmd_sync_cancel_sync(hdev, err); in hci_cancel_cmd_sync()
2830 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
2834 bt_dev_dbg(hdev, ""); in hci_suspend_dev()
2837 if (!hdev_is_powered(hdev) || in hci_suspend_dev()
2838 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_suspend_dev()
2842 if (mgmt_powering_down(hdev)) in hci_suspend_dev()
2846 hci_cancel_cmd_sync(hdev, EHOSTDOWN); in hci_suspend_dev()
2848 hci_req_sync_lock(hdev); in hci_suspend_dev()
2849 ret = hci_suspend_sync(hdev); in hci_suspend_dev()
2850 hci_req_sync_unlock(hdev); in hci_suspend_dev()
2852 hci_clear_wake_reason(hdev); in hci_suspend_dev()
2853 mgmt_suspending(hdev, hdev->suspend_state); in hci_suspend_dev()
2855 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
2861 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
2865 bt_dev_dbg(hdev, ""); in hci_resume_dev()
2868 if (!hdev_is_powered(hdev) || in hci_resume_dev()
2869 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_resume_dev()
2873 if (mgmt_powering_down(hdev)) in hci_resume_dev()
2876 hci_req_sync_lock(hdev); in hci_resume_dev()
2877 ret = hci_resume_sync(hdev); in hci_resume_dev()
2878 hci_req_sync_unlock(hdev); in hci_resume_dev()
2880 mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, in hci_resume_dev()
2881 hdev->wake_addr_type); in hci_resume_dev()
2883 hci_sock_dev_event(hdev, HCI_DEV_RESUME); in hci_resume_dev()
2889 int hci_reset_dev(struct hci_dev *hdev) in hci_reset_dev() argument
2901 bt_dev_err(hdev, "Injecting HCI hardware error event"); in hci_reset_dev()
2904 return hci_recv_frame(hdev, skb); in hci_reset_dev()
2908 static u8 hci_dev_classify_pkt_type(struct hci_dev *hdev, struct sk_buff *skb) in hci_dev_classify_pkt_type() argument
2910 if (hdev->classify_pkt_type) in hci_dev_classify_pkt_type()
2911 return hdev->classify_pkt_type(hdev, skb); in hci_dev_classify_pkt_type()
2917 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_frame() argument
2921 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
2922 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
2928 dev_pkt_type = hci_dev_classify_pkt_type(hdev, skb); in hci_recv_frame()
2938 if (hci_conn_num(hdev, CIS_LINK) || in hci_recv_frame()
2939 hci_conn_num(hdev, BIS_LINK) || in hci_recv_frame()
2940 hci_conn_num(hdev, PA_LINK)) { in hci_recv_frame()
2944 type = hci_conn_lookup_type(hdev, hci_handle(handle)); in hci_recv_frame()
2967 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
2968 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
2975 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_diag() argument
2983 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_diag()
2984 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_diag()
2990 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_hw_info() argument
2995 kfree_const(hdev->hw_info); in hci_set_hw_info()
2996 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_hw_info()
3001 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_fw_info() argument
3006 kfree_const(hdev->fw_info); in hci_set_fw_info()
3007 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_fw_info()
3038 static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_frame() argument
3042 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb), in hci_send_frame()
3049 hci_send_to_monitor(hdev, skb); in hci_send_frame()
3051 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
3053 hci_send_to_sock(hdev, skb); in hci_send_frame()
3059 if (!test_bit(HCI_RUNNING, &hdev->flags)) { in hci_send_frame()
3068 err = hci_drv_process_cmd(hdev, skb); in hci_send_frame()
3073 err = hdev->send(hdev, skb); in hci_send_frame()
3075 bt_dev_err(hdev, "sending frame failed (%d)", err); in hci_send_frame()
3083 static int hci_send_conn_frame(struct hci_dev *hdev, struct hci_conn *conn, in hci_send_conn_frame() argument
3087 return hci_send_frame(hdev, skb); in hci_send_conn_frame()
3091 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
3096 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
3098 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, NULL); in hci_send_cmd()
3100 bt_dev_err(hdev, "no memory for command"); in hci_send_cmd()
3109 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
3110 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
3115 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_send() argument
3129 bt_dev_err(hdev, "unresponded command not supported"); in __hci_cmd_send()
3133 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, NULL); in __hci_cmd_send()
3135 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in __hci_cmd_send()
3140 hci_send_frame(hdev, skb); in __hci_cmd_send()
3163 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
3168 data = hci_cmd_data(hdev->sent_cmd, opcode); in hci_sent_cmd_data()
3171 data = hci_cmd_data(hdev->req_skb, opcode); in hci_sent_cmd_data()
3177 void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) in hci_recv_event_data() argument
3182 if (!hdev->recv_event) in hci_recv_event_data()
3185 hdr = (void *)hdev->recv_event->data; in hci_recv_event_data()
3193 ev = (void *)hdev->recv_event->data + offset; in hci_recv_event_data()
3202 bt_dev_dbg(hdev, "event 0x%2.2x", event); in hci_recv_event_data()
3204 return hdev->recv_event->data + offset; in hci_recv_event_data()
3224 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
3237 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3242 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3263 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3274 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
3276 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
3280 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
3286 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
3289 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
3301 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
3320 struct hci_dev *hdev = conn->hdev; in hci_queue_iso() local
3336 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3341 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3355 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3364 struct hci_dev *hdev = conn->hdev; in hci_send_iso() local
3366 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_iso()
3370 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_iso()
3378 struct hci_dev *hdev; in hci_quote_sent() local
3386 hdev = conn->hdev; in hci_quote_sent()
3390 cnt = hdev->acl_cnt; in hci_quote_sent()
3394 cnt = hdev->sco_cnt; in hci_quote_sent()
3397 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3402 cnt = hdev->iso_mtu ? hdev->iso_cnt : in hci_quote_sent()
3403 hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3407 bt_dev_err(hdev, "unknown link type %d", conn->type); in hci_quote_sent()
3414 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
3417 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
3441 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
3453 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
3455 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
3458 bt_dev_err(hdev, "link tx timeout"); in hci_link_tx_to()
3460 hci_dev_lock(hdev); in hci_link_tx_to()
3465 bt_dev_err(hdev, "killing stalled connection %pMR", in hci_link_tx_to()
3471 hci_dev_unlock(hdev); in hci_link_tx_to()
3474 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
3477 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
3483 BT_DBG("%s", hdev->name); in hci_chan_sent()
3522 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
3537 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
3539 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
3543 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
3579 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
3587 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt, u8 type) in __check_timeout() argument
3591 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in __check_timeout()
3596 last_tx = hdev->le_last_tx; in __check_timeout()
3599 last_tx = hdev->acl_last_tx; in __check_timeout()
3607 hci_link_tx_to(hdev, type); in __check_timeout()
3611 static void hci_sched_sco(struct hci_dev *hdev, __u8 type) in hci_sched_sco() argument
3616 unsigned int pkts = hdev->sco_pkts; in hci_sched_sco()
3618 bt_dev_dbg(hdev, "type %u", type); in hci_sched_sco()
3620 if (!hci_conn_num(hdev, type) || !pkts) in hci_sched_sco()
3626 if (!hci_dev_test_flag(hdev, HCI_SCO_FLOWCTL)) in hci_sched_sco()
3629 cnt = &hdev->sco_cnt; in hci_sched_sco()
3631 while (*cnt && (conn = hci_low_sent(hdev, type, "e))) { in hci_sched_sco()
3634 hci_send_conn_frame(hdev, conn, skb); in hci_sched_sco()
3648 if (!pkts && !hci_dev_test_flag(hdev, HCI_SCO_FLOWCTL)) in hci_sched_sco()
3649 queue_work(hdev->workqueue, &hdev->tx_work); in hci_sched_sco()
3652 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
3654 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
3659 __check_timeout(hdev, cnt, ACL_LINK); in hci_sched_acl_pkt()
3661 while (hdev->acl_cnt && in hci_sched_acl_pkt()
3662 (chan = hci_chan_sent(hdev, ACL_LINK, "e))) { in hci_sched_acl_pkt()
3677 hci_send_conn_frame(hdev, chan->conn, skb); in hci_sched_acl_pkt()
3678 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
3680 hdev->acl_cnt--; in hci_sched_acl_pkt()
3685 hci_sched_sco(hdev, SCO_LINK); in hci_sched_acl_pkt()
3686 hci_sched_sco(hdev, ESCO_LINK); in hci_sched_acl_pkt()
3690 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
3691 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
3694 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
3696 BT_DBG("%s", hdev->name); in hci_sched_acl()
3699 if (!hci_conn_num(hdev, ACL_LINK)) in hci_sched_acl()
3702 hci_sched_acl_pkt(hdev); in hci_sched_acl()
3705 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
3711 BT_DBG("%s", hdev->name); in hci_sched_le()
3713 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
3716 cnt = hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; in hci_sched_le()
3718 __check_timeout(hdev, *cnt, LE_LINK); in hci_sched_le()
3721 while (*cnt && (chan = hci_chan_sent(hdev, LE_LINK, "e))) { in hci_sched_le()
3733 hci_send_conn_frame(hdev, chan->conn, skb); in hci_sched_le()
3734 hdev->le_last_tx = jiffies; in hci_sched_le()
3741 hci_sched_sco(hdev, SCO_LINK); in hci_sched_le()
3742 hci_sched_sco(hdev, ESCO_LINK); in hci_sched_le()
3747 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
3751 static void hci_sched_iso(struct hci_dev *hdev, __u8 type) in hci_sched_iso() argument
3757 BT_DBG("%s", hdev->name); in hci_sched_iso()
3759 if (!hci_conn_num(hdev, type)) in hci_sched_iso()
3762 cnt = hdev->iso_pkts ? &hdev->iso_cnt : in hci_sched_iso()
3763 hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; in hci_sched_iso()
3764 while (*cnt && (conn = hci_low_sent(hdev, type, "e))) { in hci_sched_iso()
3767 hci_send_conn_frame(hdev, conn, skb); in hci_sched_iso()
3779 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
3782 BT_DBG("%s acl %d sco %d le %d iso %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
3783 hdev->sco_cnt, hdev->le_cnt, hdev->iso_cnt); in hci_tx_work()
3785 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_tx_work()
3787 hci_sched_sco(hdev, SCO_LINK); in hci_tx_work()
3788 hci_sched_sco(hdev, ESCO_LINK); in hci_tx_work()
3789 hci_sched_iso(hdev, CIS_LINK); in hci_tx_work()
3790 hci_sched_iso(hdev, BIS_LINK); in hci_tx_work()
3791 hci_sched_iso(hdev, PA_LINK); in hci_tx_work()
3792 hci_sched_acl(hdev); in hci_tx_work()
3793 hci_sched_le(hdev); in hci_tx_work()
3797 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
3798 hci_send_frame(hdev, skb); in hci_tx_work()
3804 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
3812 bt_dev_err(hdev, "ACL packet too small"); in hci_acldata_packet()
3820 bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, in hci_acldata_packet()
3823 hdev->stat.acl_rx++; in hci_acldata_packet()
3825 hci_dev_lock(hdev); in hci_acldata_packet()
3826 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
3827 hci_dev_unlock(hdev); in hci_acldata_packet()
3836 bt_dev_err(hdev, "ACL packet for unknown connection handle %d", in hci_acldata_packet()
3845 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
3853 bt_dev_err(hdev, "SCO packet too small"); in hci_scodata_packet()
3861 bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, in hci_scodata_packet()
3864 hdev->stat.sco_rx++; in hci_scodata_packet()
3866 hci_dev_lock(hdev); in hci_scodata_packet()
3867 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
3868 hci_dev_unlock(hdev); in hci_scodata_packet()
3876 bt_dev_err_ratelimited(hdev, "SCO packet for unknown connection handle %d", in hci_scodata_packet()
3884 static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_isodata_packet() argument
3892 bt_dev_err(hdev, "ISO packet too small"); in hci_isodata_packet()
3900 bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, in hci_isodata_packet()
3903 hci_dev_lock(hdev); in hci_isodata_packet()
3904 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_isodata_packet()
3905 hci_dev_unlock(hdev); in hci_isodata_packet()
3908 bt_dev_err(hdev, "ISO packet for unknown connection handle %d", in hci_isodata_packet()
3921 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
3925 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
3932 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
3938 if (!hdev->sent_cmd) in hci_resend_last()
3941 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
3946 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
3950 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
3951 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
3954 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, in hci_req_cmd_complete() argument
3966 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
3973 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
3974 hci_resend_last(hdev); in hci_req_cmd_complete()
3980 hci_dev_clear_flag(hdev, HCI_CMD_PENDING); in hci_req_cmd_complete()
3985 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
3988 skb = hdev->req_skb; in hci_req_cmd_complete()
4005 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4006 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
4008 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
4018 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4023 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
4026 BT_DBG("%s", hdev->name); in hci_rx_work()
4033 for (; (skb = skb_dequeue(&hdev->rx_q)); kcov_remote_stop()) { in hci_rx_work()
4037 hci_send_to_monitor(hdev, skb); in hci_rx_work()
4039 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
4041 hci_send_to_sock(hdev, skb); in hci_rx_work()
4050 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_rx_work()
4051 !test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4056 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4070 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
4071 hci_event_packet(hdev, skb); in hci_rx_work()
4075 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
4076 hci_acldata_packet(hdev, skb); in hci_rx_work()
4080 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
4081 hci_scodata_packet(hdev, skb); in hci_rx_work()
4085 BT_DBG("%s ISO data packet", hdev->name); in hci_rx_work()
4086 hci_isodata_packet(hdev, skb); in hci_rx_work()
4096 static void hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_cmd_sync() argument
4100 bt_dev_dbg(hdev, "skb %p", skb); in hci_send_cmd_sync()
4102 kfree_skb(hdev->sent_cmd); in hci_send_cmd_sync()
4104 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); in hci_send_cmd_sync()
4105 if (!hdev->sent_cmd) { in hci_send_cmd_sync()
4106 skb_queue_head(&hdev->cmd_q, skb); in hci_send_cmd_sync()
4107 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd_sync()
4112 err = hci_send_frame(hdev, skb); in hci_send_cmd_sync()
4114 hci_cmd_sync_cancel_sync(hdev, -err); in hci_send_cmd_sync()
4117 atomic_dec(&hdev->cmd_cnt); in hci_send_cmd_sync()
4120 if (hdev->req_status == HCI_REQ_PEND && in hci_send_cmd_sync()
4121 !hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) { in hci_send_cmd_sync()
4122 kfree_skb(hdev->req_skb); in hci_send_cmd_sync()
4123 hdev->req_skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_send_cmd_sync()
4129 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work); in hci_cmd_work() local
4132 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name, in hci_cmd_work()
4133 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q)); in hci_cmd_work()
4136 if (atomic_read(&hdev->cmd_cnt)) { in hci_cmd_work()
4137 skb = skb_dequeue(&hdev->cmd_q); in hci_cmd_work()
4141 hci_send_cmd_sync(hdev, skb); in hci_cmd_work()
4144 if (test_bit(HCI_RESET, &hdev->flags) || in hci_cmd_work()
4145 hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE)) in hci_cmd_work()
4146 cancel_delayed_work(&hdev->cmd_timer); in hci_cmd_work()
4148 queue_delayed_work(hdev->workqueue, &hdev->cmd_timer, in hci_cmd_work()