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()
84 return hdev; in hci_dev_get()
89 bool hci_discovery_active(struct hci_dev *hdev) in hci_discovery_active() argument
91 struct discovery_state *discov = &hdev->discovery; in hci_discovery_active()
103 void hci_discovery_set_state(struct hci_dev *hdev, int state) in hci_discovery_set_state() argument
105 int old_state = hdev->discovery.state; in hci_discovery_set_state()
110 hdev->discovery.state = state; in hci_discovery_set_state()
114 hci_update_passive_scan(hdev); in hci_discovery_set_state()
117 mgmt_discovering(hdev, 0); in hci_discovery_set_state()
122 mgmt_discovering(hdev, 1); in hci_discovery_set_state()
130 bt_dev_dbg(hdev, "state %u -> %u", old_state, state); in hci_discovery_set_state()
133 void hci_inquiry_cache_flush(struct hci_dev *hdev) in hci_inquiry_cache_flush() argument
135 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_flush()
147 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, in hci_inquiry_cache_lookup() argument
150 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup()
163 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, in hci_inquiry_cache_lookup_unknown() argument
166 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_unknown()
179 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, in hci_inquiry_cache_lookup_resolve() argument
183 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_resolve()
198 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, in hci_inquiry_cache_update_resolve() argument
201 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update_resolve()
217 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, in hci_inquiry_cache_update() argument
220 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update()
226 hci_remove_remote_oob_data(hdev, &data->bdaddr, BDADDR_BREDR); in hci_inquiry_cache_update()
231 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); in hci_inquiry_cache_update()
239 hci_inquiry_cache_update_resolve(hdev, ie); in hci_inquiry_cache_update()
279 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf) in inquiry_cache_dump() argument
281 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_dump()
311 struct hci_dev *hdev; in hci_inquiry() local
318 hdev = hci_dev_get(ir.dev_id); in hci_inquiry()
319 if (!hdev) in hci_inquiry()
322 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_inquiry()
327 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_inquiry()
332 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_inquiry()
343 hci_dev_lock(hdev); in hci_inquiry()
344 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || in hci_inquiry()
345 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { in hci_inquiry()
346 hci_inquiry_cache_flush(hdev); in hci_inquiry()
349 hci_dev_unlock(hdev); in hci_inquiry()
352 hci_req_sync_lock(hdev); in hci_inquiry()
353 err = hci_inquiry_sync(hdev, ir.length, ir.num_rsp); in hci_inquiry()
354 hci_req_sync_unlock(hdev); in hci_inquiry()
362 if (wait_on_bit(&hdev->flags, HCI_INQUIRY, in hci_inquiry()
383 hci_dev_lock(hdev); in hci_inquiry()
384 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf); in hci_inquiry()
385 hci_dev_unlock(hdev); in hci_inquiry()
400 hci_dev_put(hdev); in hci_inquiry()
404 static int hci_dev_do_open(struct hci_dev *hdev) in hci_dev_do_open() argument
408 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_open()
410 hci_req_sync_lock(hdev); in hci_dev_do_open()
412 ret = hci_dev_open_sync(hdev); in hci_dev_do_open()
414 hci_req_sync_unlock(hdev); in hci_dev_do_open()
422 struct hci_dev *hdev; in hci_dev_open() local
425 hdev = hci_dev_get(dev); in hci_dev_open()
426 if (!hdev) in hci_dev_open()
438 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open()
439 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_open()
449 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_open()
450 cancel_delayed_work(&hdev->power_off); in hci_dev_open()
456 flush_workqueue(hdev->req_workqueue); in hci_dev_open()
464 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open()
465 !hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_open()
466 hci_dev_set_flag(hdev, HCI_BONDABLE); in hci_dev_open()
468 err = hci_dev_do_open(hdev); in hci_dev_open()
471 hci_dev_put(hdev); in hci_dev_open()
475 int hci_dev_do_close(struct hci_dev *hdev) in hci_dev_do_close() argument
479 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_close()
481 hci_req_sync_lock(hdev); in hci_dev_do_close()
483 err = hci_dev_close_sync(hdev); in hci_dev_do_close()
485 hci_req_sync_unlock(hdev); in hci_dev_do_close()
492 struct hci_dev *hdev; in hci_dev_close() local
495 hdev = hci_dev_get(dev); in hci_dev_close()
496 if (!hdev) in hci_dev_close()
499 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close()
504 cancel_work_sync(&hdev->power_on); in hci_dev_close()
505 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_close()
506 cancel_delayed_work(&hdev->power_off); in hci_dev_close()
508 err = hci_dev_do_close(hdev); in hci_dev_close()
511 hci_dev_put(hdev); in hci_dev_close()
515 static int hci_dev_do_reset(struct hci_dev *hdev) in hci_dev_do_reset() argument
519 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_reset()
521 hci_req_sync_lock(hdev); in hci_dev_do_reset()
524 skb_queue_purge(&hdev->rx_q); in hci_dev_do_reset()
525 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_reset()
528 hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); in hci_dev_do_reset()
538 cancel_delayed_work(&hdev->cmd_timer); in hci_dev_do_reset()
539 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_do_reset()
544 drain_workqueue(hdev->workqueue); in hci_dev_do_reset()
546 hci_dev_lock(hdev); in hci_dev_do_reset()
547 hci_inquiry_cache_flush(hdev); in hci_dev_do_reset()
548 hci_conn_hash_flush(hdev); in hci_dev_do_reset()
549 hci_dev_unlock(hdev); in hci_dev_do_reset()
551 if (hdev->flush) in hci_dev_do_reset()
552 hdev->flush(hdev); in hci_dev_do_reset()
554 hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); in hci_dev_do_reset()
556 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_reset()
557 hdev->acl_cnt = 0; in hci_dev_do_reset()
558 hdev->sco_cnt = 0; in hci_dev_do_reset()
559 hdev->le_cnt = 0; in hci_dev_do_reset()
560 hdev->iso_cnt = 0; in hci_dev_do_reset()
562 ret = hci_reset_sync(hdev); in hci_dev_do_reset()
564 hci_req_sync_unlock(hdev); in hci_dev_do_reset()
570 struct hci_dev *hdev; in hci_dev_reset() local
573 hdev = hci_dev_get(dev); in hci_dev_reset()
574 if (!hdev) in hci_dev_reset()
577 if (!test_bit(HCI_UP, &hdev->flags)) { in hci_dev_reset()
582 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset()
587 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset()
592 err = hci_dev_do_reset(hdev); in hci_dev_reset()
595 hci_dev_put(hdev); in hci_dev_reset()
601 struct hci_dev *hdev; in hci_dev_reset_stat() local
604 hdev = hci_dev_get(dev); in hci_dev_reset_stat()
605 if (!hdev) in hci_dev_reset_stat()
608 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset_stat()
613 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset_stat()
618 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); in hci_dev_reset_stat()
621 hci_dev_put(hdev); in hci_dev_reset_stat()
625 static void hci_update_passive_scan_state(struct hci_dev *hdev, u8 scan) in hci_update_passive_scan_state() argument
629 BT_DBG("%s scan 0x%02x", hdev->name, scan); in hci_update_passive_scan_state()
632 conn_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_passive_scan_state()
635 conn_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_passive_scan_state()
639 discov_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_passive_scan_state()
642 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_update_passive_scan_state()
643 discov_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_passive_scan_state()
647 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in hci_update_passive_scan_state()
652 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_update_passive_scan_state()
654 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_state()
655 hci_update_adv_data(hdev, hdev->cur_adv_instance); in hci_update_passive_scan_state()
657 mgmt_new_settings(hdev); in hci_update_passive_scan_state()
663 struct hci_dev *hdev; in hci_dev_cmd() local
671 hdev = hci_dev_get(dr.dev_id); in hci_dev_cmd()
672 if (!hdev) in hci_dev_cmd()
675 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_cmd()
680 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_cmd()
685 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_dev_cmd()
692 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE, in hci_dev_cmd()
697 if (!lmp_encrypt_capable(hdev)) { in hci_dev_cmd()
702 if (!test_bit(HCI_AUTH, &hdev->flags)) { in hci_dev_cmd()
704 err = hci_cmd_sync_status(hdev, in hci_dev_cmd()
712 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_ENCRYPT_MODE, in hci_dev_cmd()
717 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE, in hci_dev_cmd()
724 hci_update_passive_scan_state(hdev, dr.dev_opt); in hci_dev_cmd()
730 err = hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, in hci_dev_cmd()
735 hdev->link_mode = ((__u16) dr.dev_opt) & in hci_dev_cmd()
740 if (hdev->pkt_type == (__u16) dr.dev_opt) in hci_dev_cmd()
743 hdev->pkt_type = (__u16) dr.dev_opt; in hci_dev_cmd()
744 mgmt_phy_configuration_changed(hdev, NULL); in hci_dev_cmd()
748 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
749 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
753 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
754 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
763 hci_dev_put(hdev); in hci_dev_cmd()
769 struct hci_dev *hdev; in hci_get_dev_list() local
789 list_for_each_entry(hdev, &hci_dev_list, list) { in hci_get_dev_list()
790 unsigned long flags = hdev->flags; in hci_get_dev_list()
796 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_list()
799 dr[n].dev_id = hdev->id; in hci_get_dev_list()
816 struct hci_dev *hdev; in hci_get_dev_info() local
824 hdev = hci_dev_get(di.dev_id); in hci_get_dev_info()
825 if (!hdev) in hci_get_dev_info()
832 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_info()
833 flags = hdev->flags & ~BIT(HCI_UP); in hci_get_dev_info()
835 flags = hdev->flags; in hci_get_dev_info()
837 strscpy(di.name, hdev->name, sizeof(di.name)); in hci_get_dev_info()
838 di.bdaddr = hdev->bdaddr; in hci_get_dev_info()
839 di.type = (hdev->bus & 0x0f); in hci_get_dev_info()
841 di.pkt_type = hdev->pkt_type; in hci_get_dev_info()
842 if (lmp_bredr_capable(hdev)) { in hci_get_dev_info()
843 di.acl_mtu = hdev->acl_mtu; in hci_get_dev_info()
844 di.acl_pkts = hdev->acl_pkts; in hci_get_dev_info()
845 di.sco_mtu = hdev->sco_mtu; in hci_get_dev_info()
846 di.sco_pkts = hdev->sco_pkts; in hci_get_dev_info()
848 di.acl_mtu = hdev->le_mtu; in hci_get_dev_info()
849 di.acl_pkts = hdev->le_pkts; in hci_get_dev_info()
853 di.link_policy = hdev->link_policy; in hci_get_dev_info()
854 di.link_mode = hdev->link_mode; in hci_get_dev_info()
856 memcpy(&di.stat, &hdev->stat, sizeof(di.stat)); in hci_get_dev_info()
857 memcpy(&di.features, &hdev->features, sizeof(di.features)); in hci_get_dev_info()
862 hci_dev_put(hdev); in hci_get_dev_info()
869 static int hci_dev_do_poweroff(struct hci_dev *hdev) in hci_dev_do_poweroff() argument
873 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_poweroff()
875 hci_req_sync_lock(hdev); in hci_dev_do_poweroff()
877 err = hci_set_powered_sync(hdev, false); in hci_dev_do_poweroff()
879 hci_req_sync_unlock(hdev); in hci_dev_do_poweroff()
886 struct hci_dev *hdev = data; in hci_rfkill_set_block() local
889 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); in hci_rfkill_set_block()
891 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_rfkill_set_block()
894 if (blocked == hci_dev_test_flag(hdev, HCI_RFKILLED)) in hci_rfkill_set_block()
898 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
900 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_rfkill_set_block()
901 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_rfkill_set_block()
902 err = hci_dev_do_poweroff(hdev); in hci_rfkill_set_block()
904 bt_dev_err(hdev, "Error when powering off device on rfkill (%d)", in hci_rfkill_set_block()
911 hci_dev_do_close(hdev); in hci_rfkill_set_block()
915 hci_dev_clear_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
927 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); in hci_power_on() local
930 BT_DBG("%s", hdev->name); in hci_power_on()
932 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on()
933 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on()
934 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
935 cancel_delayed_work(&hdev->power_off); in hci_power_on()
936 err = hci_powered_update_sync(hdev); in hci_power_on()
937 mgmt_power_on(hdev, err); in hci_power_on()
941 err = hci_dev_do_open(hdev); in hci_power_on()
943 hci_dev_lock(hdev); in hci_power_on()
944 mgmt_set_powered_failed(hdev, err); in hci_power_on()
945 hci_dev_unlock(hdev); in hci_power_on()
953 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on()
954 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on()
955 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on()
956 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on()
957 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on()
958 hci_dev_do_close(hdev); in hci_power_on()
959 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
960 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on()
964 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on()
968 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
969 set_bit(HCI_RAW, &hdev->flags); in hci_power_on()
978 mgmt_index_added(hdev); in hci_power_on()
979 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on()
983 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
984 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on()
990 mgmt_index_added(hdev); in hci_power_on()
996 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_power_off() local
999 BT_DBG("%s", hdev->name); in hci_power_off()
1001 hci_dev_do_close(hdev); in hci_power_off()
1006 struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset); in hci_error_reset() local
1008 hci_dev_hold(hdev); in hci_error_reset()
1009 BT_DBG("%s", hdev->name); in hci_error_reset()
1011 if (hdev->hw_error) in hci_error_reset()
1012 hdev->hw_error(hdev, hdev->hw_error_code); in hci_error_reset()
1014 bt_dev_err(hdev, "hardware error 0x%2.2x", hdev->hw_error_code); in hci_error_reset()
1016 if (!hci_dev_do_close(hdev)) in hci_error_reset()
1017 hci_dev_do_open(hdev); in hci_error_reset()
1019 hci_dev_put(hdev); in hci_error_reset()
1022 void hci_uuids_clear(struct hci_dev *hdev) in hci_uuids_clear() argument
1026 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) { in hci_uuids_clear()
1032 void hci_link_keys_clear(struct hci_dev *hdev) in hci_link_keys_clear() argument
1036 list_for_each_entry_safe(key, tmp, &hdev->link_keys, list) { in hci_link_keys_clear()
1042 void hci_smp_ltks_clear(struct hci_dev *hdev) in hci_smp_ltks_clear() argument
1046 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_smp_ltks_clear()
1052 void hci_smp_irks_clear(struct hci_dev *hdev) in hci_smp_irks_clear() argument
1056 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { in hci_smp_irks_clear()
1062 void hci_blocked_keys_clear(struct hci_dev *hdev) in hci_blocked_keys_clear() argument
1066 list_for_each_entry_safe(b, tmp, &hdev->blocked_keys, list) { in hci_blocked_keys_clear()
1072 bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]) in hci_is_blocked_key() argument
1078 list_for_each_entry_rcu(b, &hdev->blocked_keys, list) { in hci_is_blocked_key()
1089 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_find_link_key() argument
1094 list_for_each_entry_rcu(k, &hdev->link_keys, list) { in hci_find_link_key()
1098 if (hci_is_blocked_key(hdev, in hci_find_link_key()
1101 bt_dev_warn_ratelimited(hdev, in hci_find_link_key()
1115 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_persistent_key() argument
1163 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_ltk() argument
1169 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_find_ltk()
1176 if (hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_LTK, in hci_find_ltk()
1178 bt_dev_warn_ratelimited(hdev, in hci_find_ltk()
1192 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa) in hci_find_irk_by_rpa() argument
1198 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
1205 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
1206 if (smp_irk_matches(hdev, irk->val, rpa)) { in hci_find_irk_by_rpa()
1214 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_rpa()
1216 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_rpa()
1226 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_irk_by_addr() argument
1237 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_addr()
1247 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_addr()
1249 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_addr()
1259 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_add_link_key() argument
1266 old_key = hci_find_link_key(hdev, bdaddr); in hci_add_link_key()
1275 list_add_rcu(&key->list, &hdev->link_keys); in hci_add_link_key()
1278 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); in hci_add_link_key()
1300 *persistent = hci_persistent_key(hdev, conn, type, in hci_add_link_key()
1306 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_ltk() argument
1313 old_key = hci_find_ltk(hdev, bdaddr, addr_type, role); in hci_add_ltk()
1320 list_add_rcu(&key->list, &hdev->long_term_keys); in hci_add_ltk()
1335 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_irk() argument
1340 irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); in hci_add_irk()
1349 list_add_rcu(&irk->list, &hdev->identity_resolving_keys); in hci_add_irk()
1358 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_link_key() argument
1362 key = hci_find_link_key(hdev, bdaddr); in hci_remove_link_key()
1366 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_link_key()
1374 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) in hci_remove_ltk() argument
1379 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_remove_ltk()
1383 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_ltk()
1393 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) in hci_remove_irk() argument
1397 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { in hci_remove_irk()
1401 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_irk()
1408 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_bdaddr_is_paired() argument
1415 if (hci_find_link_key(hdev, bdaddr)) in hci_bdaddr_is_paired()
1426 irk = hci_get_irk(hdev, bdaddr, addr_type); in hci_bdaddr_is_paired()
1433 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_bdaddr_is_paired()
1447 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_cmd_timeout() local
1450 if (hdev->req_skb) { in hci_cmd_timeout()
1451 u16 opcode = hci_skb_opcode(hdev->req_skb); in hci_cmd_timeout()
1453 bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode); in hci_cmd_timeout()
1455 hci_cmd_sync_cancel_sync(hdev, ETIMEDOUT); in hci_cmd_timeout()
1457 bt_dev_err(hdev, "command tx timeout"); in hci_cmd_timeout()
1460 if (hdev->cmd_timeout) in hci_cmd_timeout()
1461 hdev->cmd_timeout(hdev); in hci_cmd_timeout()
1463 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_timeout()
1464 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_timeout()
1470 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_ncmd_timeout() local
1473 bt_dev_err(hdev, "Controller not accepting commands anymore: ncmd = 0"); in hci_ncmd_timeout()
1478 if (test_bit(HCI_INIT, &hdev->flags)) in hci_ncmd_timeout()
1482 hci_reset_dev(hdev); in hci_ncmd_timeout()
1485 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, in hci_find_remote_oob_data() argument
1490 list_for_each_entry(data, &hdev->remote_oob_data, list) { in hci_find_remote_oob_data()
1501 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_remove_remote_oob_data() argument
1506 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
1510 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
1518 void hci_remote_oob_data_clear(struct hci_dev *hdev) in hci_remote_oob_data_clear() argument
1522 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) { in hci_remote_oob_data_clear()
1528 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_remote_oob_data() argument
1534 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_add_remote_oob_data()
1542 list_add(&data->list, &hdev->remote_oob_data); in hci_add_remote_oob_data()
1569 BT_DBG("%s for %pMR", hdev->name, bdaddr); in hci_add_remote_oob_data()
1575 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance) in hci_find_adv_instance() argument
1579 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in hci_find_adv_instance()
1588 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) in hci_get_next_instance() argument
1592 cur_instance = hci_find_adv_instance(hdev, instance); in hci_get_next_instance()
1596 if (cur_instance == list_last_entry(&hdev->adv_instances, in hci_get_next_instance()
1598 return list_first_entry(&hdev->adv_instances, in hci_get_next_instance()
1605 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_adv_instance() argument
1609 adv_instance = hci_find_adv_instance(hdev, instance); in hci_remove_adv_instance()
1613 BT_DBG("%s removing %dMR", hdev->name, instance); in hci_remove_adv_instance()
1615 if (hdev->cur_adv_instance == instance) { in hci_remove_adv_instance()
1616 if (hdev->adv_instance_timeout) { in hci_remove_adv_instance()
1617 cancel_delayed_work(&hdev->adv_instance_expire); in hci_remove_adv_instance()
1618 hdev->adv_instance_timeout = 0; in hci_remove_adv_instance()
1620 hdev->cur_adv_instance = 0x00; in hci_remove_adv_instance()
1628 hdev->adv_instance_cnt--; in hci_remove_adv_instance()
1633 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired) in hci_adv_instances_set_rpa_expired() argument
1637 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) in hci_adv_instances_set_rpa_expired()
1642 void hci_adv_instances_clear(struct hci_dev *hdev) in hci_adv_instances_clear() argument
1646 if (hdev->adv_instance_timeout) { in hci_adv_instances_clear()
1647 disable_delayed_work(&hdev->adv_instance_expire); in hci_adv_instances_clear()
1648 hdev->adv_instance_timeout = 0; in hci_adv_instances_clear()
1651 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in hci_adv_instances_clear()
1657 hdev->adv_instance_cnt = 0; in hci_adv_instances_clear()
1658 hdev->cur_adv_instance = 0x00; in hci_adv_instances_clear()
1672 struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, in hci_add_adv_instance() argument
1681 adv = hci_find_adv_instance(hdev, instance); in hci_add_adv_instance()
1687 if (hdev->adv_instance_cnt >= hdev->le_num_of_adv_sets || in hci_add_adv_instance()
1688 instance < 1 || instance > hdev->le_num_of_adv_sets + 1) in hci_add_adv_instance()
1701 if (hdev->le_num_of_adv_sets == 1 && instance == 1) in hci_add_adv_instance()
1706 list_add(&adv->list, &hdev->adv_instances); in hci_add_adv_instance()
1707 hdev->adv_instance_cnt++; in hci_add_adv_instance()
1720 hci_set_adv_instance_data(hdev, instance, adv_data_len, adv_data, in hci_add_adv_instance()
1727 adv->duration = hdev->def_multi_adv_rotation_duration; in hci_add_adv_instance()
1733 BT_DBG("%s for %dMR", hdev->name, instance); in hci_add_adv_instance()
1739 struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance, in hci_add_per_instance() argument
1745 adv = hci_add_adv_instance(hdev, instance, flags, 0, NULL, 0, NULL, in hci_add_per_instance()
1761 int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, in hci_set_adv_instance_data() argument
1767 adv = hci_find_adv_instance(hdev, instance); in hci_set_adv_instance_data()
1788 if (((adv->flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) || in hci_set_adv_instance_data()
1796 u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance) in hci_adv_instance_flags() argument
1810 if (hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) in hci_adv_instance_flags()
1813 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_adv_instance_flags()
1815 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_adv_instance_flags()
1821 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_flags()
1830 bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance) in hci_adv_instance_is_scannable() argument
1838 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_is_scannable()
1850 void hci_adv_monitors_clear(struct hci_dev *hdev) in hci_adv_monitors_clear() argument
1855 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in hci_adv_monitors_clear()
1856 hci_free_adv_monitor(hdev, monitor); in hci_adv_monitors_clear()
1858 idr_destroy(&hdev->adv_monitors_idr); in hci_adv_monitors_clear()
1864 void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) in hci_free_adv_monitor() argument
1878 idr_remove(&hdev->adv_monitors_idr, monitor->handle); in hci_free_adv_monitor()
1881 hdev->adv_monitors_cnt--; in hci_free_adv_monitor()
1882 mgmt_adv_monitor_removed(hdev, monitor->handle); in hci_free_adv_monitor()
1892 int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) in hci_add_adv_monitor() argument
1900 hci_dev_lock(hdev); in hci_add_adv_monitor()
1904 handle = idr_alloc(&hdev->adv_monitors_idr, monitor, min, max, in hci_add_adv_monitor()
1907 hci_dev_unlock(hdev); in hci_add_adv_monitor()
1914 if (!hdev_is_powered(hdev)) in hci_add_adv_monitor()
1917 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_add_adv_monitor()
1919 bt_dev_dbg(hdev, "add monitor %d status %d", in hci_add_adv_monitor()
1925 status = msft_add_monitor_pattern(hdev, monitor); in hci_add_adv_monitor()
1926 bt_dev_dbg(hdev, "add monitor %d msft status %d", in hci_add_adv_monitor()
1938 static int hci_remove_adv_monitor(struct hci_dev *hdev, in hci_remove_adv_monitor() argument
1944 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_remove_adv_monitor()
1946 bt_dev_dbg(hdev, "remove monitor %d status %d", in hci_remove_adv_monitor()
1952 status = msft_remove_monitor(hdev, monitor); in hci_remove_adv_monitor()
1953 bt_dev_dbg(hdev, "remove monitor %d msft status %d", in hci_remove_adv_monitor()
1966 bt_dev_warn(hdev, "Removing monitor with no matching handle %d", in hci_remove_adv_monitor()
1968 hci_free_adv_monitor(hdev, monitor); in hci_remove_adv_monitor()
1974 int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle) in hci_remove_single_adv_monitor() argument
1976 struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle); in hci_remove_single_adv_monitor()
1981 return hci_remove_adv_monitor(hdev, monitor); in hci_remove_single_adv_monitor()
1985 int hci_remove_all_adv_monitor(struct hci_dev *hdev) in hci_remove_all_adv_monitor() argument
1992 monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id); in hci_remove_all_adv_monitor()
1996 status = hci_remove_adv_monitor(hdev, monitor); in hci_remove_all_adv_monitor()
2007 bool hci_is_adv_monitoring(struct hci_dev *hdev) in hci_is_adv_monitoring() argument
2009 return !idr_is_empty(&hdev->adv_monitors_idr); in hci_is_adv_monitoring()
2012 int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev) in hci_get_adv_monitor_offload_ext() argument
2014 if (msft_monitor_supported(hdev)) in hci_get_adv_monitor_offload_ext()
2206 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, in hci_conn_params_lookup() argument
2211 list_for_each_entry(params, &hdev->le_conn_params, list) { in hci_conn_params_lookup()
2261 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, in hci_conn_params_add() argument
2266 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_add()
2272 bt_dev_err(hdev, "out of memory"); in hci_conn_params_add()
2279 list_add(&params->list, &hdev->le_conn_params); in hci_conn_params_add()
2282 params->conn_min_interval = hdev->le_conn_min_interval; in hci_conn_params_add()
2283 params->conn_max_interval = hdev->le_conn_max_interval; in hci_conn_params_add()
2284 params->conn_latency = hdev->le_conn_latency; in hci_conn_params_add()
2285 params->supervision_timeout = hdev->le_supv_timeout; in hci_conn_params_add()
2307 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) in hci_conn_params_del() argument
2311 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_del()
2317 hci_update_passive_scan(hdev); in hci_conn_params_del()
2323 void hci_conn_params_clear_disabled(struct hci_dev *hdev) in hci_conn_params_clear_disabled() argument
2327 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) { in hci_conn_params_clear_disabled()
2346 static void hci_conn_params_clear_all(struct hci_dev *hdev) in hci_conn_params_clear_all() argument
2350 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) in hci_conn_params_clear_all()
2369 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_copy_identity_address() argument
2372 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_copy_identity_address()
2373 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_copy_identity_address()
2374 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_copy_identity_address()
2375 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_copy_identity_address()
2376 bacpy(bdaddr, &hdev->static_addr); in hci_copy_identity_address()
2379 bacpy(bdaddr, &hdev->bdaddr); in hci_copy_identity_address()
2384 static void hci_clear_wake_reason(struct hci_dev *hdev) in hci_clear_wake_reason() argument
2386 hci_dev_lock(hdev); in hci_clear_wake_reason()
2388 hdev->wake_reason = 0; in hci_clear_wake_reason()
2389 bacpy(&hdev->wake_addr, BDADDR_ANY); in hci_clear_wake_reason()
2390 hdev->wake_addr_type = 0; in hci_clear_wake_reason()
2392 hci_dev_unlock(hdev); in hci_clear_wake_reason()
2398 struct hci_dev *hdev = in hci_suspend_notifier() local
2403 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_suspend_notifier()
2407 hci_dev_hold(hdev); in hci_suspend_notifier()
2412 ret = hci_suspend_dev(hdev); in hci_suspend_notifier()
2416 ret = hci_resume_dev(hdev); in hci_suspend_notifier()
2421 bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d", in hci_suspend_notifier()
2424 hci_dev_put(hdev); in hci_suspend_notifier()
2431 struct hci_dev *hdev; in hci_alloc_dev_priv() local
2434 alloc_size = sizeof(*hdev); in hci_alloc_dev_priv()
2440 hdev = kzalloc(alloc_size, GFP_KERNEL); in hci_alloc_dev_priv()
2441 if (!hdev) in hci_alloc_dev_priv()
2444 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev_priv()
2445 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev_priv()
2446 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev_priv()
2447 hdev->num_iac = 0x01; /* One IAC support is mandatory */ in hci_alloc_dev_priv()
2448 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev_priv()
2449 hdev->manufacturer = 0xffff; /* Default to internal use */ in hci_alloc_dev_priv()
2450 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2451 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2452 hdev->adv_instance_cnt = 0; in hci_alloc_dev_priv()
2453 hdev->cur_adv_instance = 0x00; in hci_alloc_dev_priv()
2454 hdev->adv_instance_timeout = 0; in hci_alloc_dev_priv()
2456 hdev->advmon_allowlist_duration = 300; in hci_alloc_dev_priv()
2457 hdev->advmon_no_filter_duration = 500; in hci_alloc_dev_priv()
2458 hdev->enable_advmon_interleave_scan = 0x00; /* Default to disable */ in hci_alloc_dev_priv()
2460 hdev->sniff_max_interval = 800; in hci_alloc_dev_priv()
2461 hdev->sniff_min_interval = 80; in hci_alloc_dev_priv()
2463 hdev->le_adv_channel_map = 0x07; in hci_alloc_dev_priv()
2464 hdev->le_adv_min_interval = 0x0800; in hci_alloc_dev_priv()
2465 hdev->le_adv_max_interval = 0x0800; in hci_alloc_dev_priv()
2466 hdev->le_scan_interval = DISCOV_LE_SCAN_INT_FAST; in hci_alloc_dev_priv()
2467 hdev->le_scan_window = DISCOV_LE_SCAN_WIN_FAST; in hci_alloc_dev_priv()
2468 hdev->le_scan_int_suspend = DISCOV_LE_SCAN_INT_SLOW1; in hci_alloc_dev_priv()
2469 hdev->le_scan_window_suspend = DISCOV_LE_SCAN_WIN_SLOW1; in hci_alloc_dev_priv()
2470 hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT; in hci_alloc_dev_priv()
2471 hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN; in hci_alloc_dev_priv()
2472 hdev->le_scan_int_adv_monitor = DISCOV_LE_SCAN_INT_FAST; in hci_alloc_dev_priv()
2473 hdev->le_scan_window_adv_monitor = DISCOV_LE_SCAN_WIN_FAST; in hci_alloc_dev_priv()
2474 hdev->le_scan_int_connect = DISCOV_LE_SCAN_INT_CONN; in hci_alloc_dev_priv()
2475 hdev->le_scan_window_connect = DISCOV_LE_SCAN_WIN_CONN; in hci_alloc_dev_priv()
2476 hdev->le_conn_min_interval = 0x0018; in hci_alloc_dev_priv()
2477 hdev->le_conn_max_interval = 0x0028; in hci_alloc_dev_priv()
2478 hdev->le_conn_latency = 0x0000; in hci_alloc_dev_priv()
2479 hdev->le_supv_timeout = 0x002a; in hci_alloc_dev_priv()
2480 hdev->le_def_tx_len = 0x001b; in hci_alloc_dev_priv()
2481 hdev->le_def_tx_time = 0x0148; in hci_alloc_dev_priv()
2482 hdev->le_max_tx_len = 0x001b; in hci_alloc_dev_priv()
2483 hdev->le_max_tx_time = 0x0148; in hci_alloc_dev_priv()
2484 hdev->le_max_rx_len = 0x001b; in hci_alloc_dev_priv()
2485 hdev->le_max_rx_time = 0x0148; in hci_alloc_dev_priv()
2486 hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2487 hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2488 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2489 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2490 hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; in hci_alloc_dev_priv()
2491 hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; in hci_alloc_dev_priv()
2492 hdev->def_le_autoconnect_timeout = HCI_LE_CONN_TIMEOUT; in hci_alloc_dev_priv()
2493 hdev->min_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2494 hdev->max_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2496 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; in hci_alloc_dev_priv()
2497 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; in hci_alloc_dev_priv()
2498 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE; in hci_alloc_dev_priv()
2499 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE; in hci_alloc_dev_priv()
2500 hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; in hci_alloc_dev_priv()
2501 hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2504 hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD; in hci_alloc_dev_priv()
2505 hdev->def_page_scan_int = 0x0800; in hci_alloc_dev_priv()
2506 hdev->def_page_scan_window = 0x0012; in hci_alloc_dev_priv()
2508 mutex_init(&hdev->lock); in hci_alloc_dev_priv()
2509 mutex_init(&hdev->req_lock); in hci_alloc_dev_priv()
2511 ida_init(&hdev->unset_handle_ida); in hci_alloc_dev_priv()
2513 INIT_LIST_HEAD(&hdev->mesh_pending); in hci_alloc_dev_priv()
2514 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev_priv()
2515 INIT_LIST_HEAD(&hdev->reject_list); in hci_alloc_dev_priv()
2516 INIT_LIST_HEAD(&hdev->accept_list); in hci_alloc_dev_priv()
2517 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev_priv()
2518 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev_priv()
2519 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev_priv()
2520 INIT_LIST_HEAD(&hdev->identity_resolving_keys); in hci_alloc_dev_priv()
2521 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev_priv()
2522 INIT_LIST_HEAD(&hdev->le_accept_list); in hci_alloc_dev_priv()
2523 INIT_LIST_HEAD(&hdev->le_resolv_list); in hci_alloc_dev_priv()
2524 INIT_LIST_HEAD(&hdev->le_conn_params); in hci_alloc_dev_priv()
2525 INIT_LIST_HEAD(&hdev->pend_le_conns); in hci_alloc_dev_priv()
2526 INIT_LIST_HEAD(&hdev->pend_le_reports); in hci_alloc_dev_priv()
2527 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev_priv()
2528 INIT_LIST_HEAD(&hdev->adv_instances); in hci_alloc_dev_priv()
2529 INIT_LIST_HEAD(&hdev->blocked_keys); in hci_alloc_dev_priv()
2530 INIT_LIST_HEAD(&hdev->monitored_devices); in hci_alloc_dev_priv()
2532 INIT_LIST_HEAD(&hdev->local_codecs); in hci_alloc_dev_priv()
2533 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev_priv()
2534 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev_priv()
2535 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev_priv()
2536 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev_priv()
2537 INIT_WORK(&hdev->error_reset, hci_error_reset); in hci_alloc_dev_priv()
2539 hci_cmd_sync_init(hdev); in hci_alloc_dev_priv()
2541 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev_priv()
2543 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev_priv()
2544 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev_priv()
2545 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev_priv()
2547 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev_priv()
2549 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); in hci_alloc_dev_priv()
2550 INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout); in hci_alloc_dev_priv()
2552 hci_devcd_setup(hdev); in hci_alloc_dev_priv()
2554 hci_init_sysfs(hdev); in hci_alloc_dev_priv()
2555 discovery_init(hdev); in hci_alloc_dev_priv()
2557 return hdev; in hci_alloc_dev_priv()
2562 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
2565 put_device(&hdev->dev); in hci_free_dev()
2570 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
2574 if (!hdev->open || !hdev->close || !hdev->send) in hci_register_dev()
2581 error = dev_set_name(&hdev->dev, "hci%u", id); in hci_register_dev()
2585 hdev->name = dev_name(&hdev->dev); in hci_register_dev()
2586 hdev->id = id; in hci_register_dev()
2588 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
2590 hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name); in hci_register_dev()
2591 if (!hdev->workqueue) { in hci_register_dev()
2596 hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, in hci_register_dev()
2597 hdev->name); in hci_register_dev()
2598 if (!hdev->req_workqueue) { in hci_register_dev()
2599 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2605 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); in hci_register_dev()
2607 error = device_add(&hdev->dev); in hci_register_dev()
2611 hci_leds_init(hdev); in hci_register_dev()
2613 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
2615 hdev); in hci_register_dev()
2616 if (hdev->rfkill) { in hci_register_dev()
2617 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
2618 rfkill_destroy(hdev->rfkill); in hci_register_dev()
2619 hdev->rfkill = NULL; in hci_register_dev()
2623 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) in hci_register_dev()
2624 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_register_dev()
2626 hci_dev_set_flag(hdev, HCI_SETUP); in hci_register_dev()
2627 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in hci_register_dev()
2632 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_register_dev()
2635 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
2641 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_register_dev()
2642 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_register_dev()
2647 if (hdev->wakeup) in hci_register_dev()
2648 hdev->conn_flags |= HCI_CONN_FLAG_REMOTE_WAKEUP; in hci_register_dev()
2650 hci_sock_dev_event(hdev, HCI_DEV_REG); in hci_register_dev()
2651 hci_dev_hold(hdev); in hci_register_dev()
2653 error = hci_register_suspend_notifier(hdev); in hci_register_dev()
2657 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
2659 idr_init(&hdev->adv_monitors_idr); in hci_register_dev()
2660 msft_register(hdev); in hci_register_dev()
2665 debugfs_remove_recursive(hdev->debugfs); in hci_register_dev()
2666 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2667 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
2669 ida_free(&hci_index_ida, hdev->id); in hci_register_dev()
2676 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
2678 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
2680 mutex_lock(&hdev->unregister_lock); in hci_unregister_dev()
2681 hci_dev_set_flag(hdev, HCI_UNREGISTER); in hci_unregister_dev()
2682 mutex_unlock(&hdev->unregister_lock); in hci_unregister_dev()
2685 list_del(&hdev->list); in hci_unregister_dev()
2688 disable_work_sync(&hdev->rx_work); in hci_unregister_dev()
2689 disable_work_sync(&hdev->cmd_work); in hci_unregister_dev()
2690 disable_work_sync(&hdev->tx_work); in hci_unregister_dev()
2691 disable_work_sync(&hdev->power_on); in hci_unregister_dev()
2692 disable_work_sync(&hdev->error_reset); in hci_unregister_dev()
2694 hci_cmd_sync_clear(hdev); in hci_unregister_dev()
2696 hci_unregister_suspend_notifier(hdev); in hci_unregister_dev()
2698 hci_dev_do_close(hdev); in hci_unregister_dev()
2700 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
2701 !hci_dev_test_flag(hdev, HCI_SETUP) && in hci_unregister_dev()
2702 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_unregister_dev()
2703 hci_dev_lock(hdev); in hci_unregister_dev()
2704 mgmt_index_removed(hdev); in hci_unregister_dev()
2705 hci_dev_unlock(hdev); in hci_unregister_dev()
2710 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
2712 hci_sock_dev_event(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
2714 if (hdev->rfkill) { in hci_unregister_dev()
2715 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
2716 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
2719 device_del(&hdev->dev); in hci_unregister_dev()
2721 hci_dev_put(hdev); in hci_unregister_dev()
2726 void hci_release_dev(struct hci_dev *hdev) in hci_release_dev() argument
2728 debugfs_remove_recursive(hdev->debugfs); in hci_release_dev()
2729 kfree_const(hdev->hw_info); in hci_release_dev()
2730 kfree_const(hdev->fw_info); in hci_release_dev()
2732 destroy_workqueue(hdev->workqueue); in hci_release_dev()
2733 destroy_workqueue(hdev->req_workqueue); in hci_release_dev()
2735 hci_dev_lock(hdev); in hci_release_dev()
2736 hci_bdaddr_list_clear(&hdev->reject_list); in hci_release_dev()
2737 hci_bdaddr_list_clear(&hdev->accept_list); in hci_release_dev()
2738 hci_uuids_clear(hdev); in hci_release_dev()
2739 hci_link_keys_clear(hdev); in hci_release_dev()
2740 hci_smp_ltks_clear(hdev); in hci_release_dev()
2741 hci_smp_irks_clear(hdev); in hci_release_dev()
2742 hci_remote_oob_data_clear(hdev); in hci_release_dev()
2743 hci_adv_instances_clear(hdev); in hci_release_dev()
2744 hci_adv_monitors_clear(hdev); in hci_release_dev()
2745 hci_bdaddr_list_clear(&hdev->le_accept_list); in hci_release_dev()
2746 hci_bdaddr_list_clear(&hdev->le_resolv_list); in hci_release_dev()
2747 hci_conn_params_clear_all(hdev); in hci_release_dev()
2748 hci_discovery_filter_clear(hdev); in hci_release_dev()
2749 hci_blocked_keys_clear(hdev); in hci_release_dev()
2750 hci_codec_list_clear(&hdev->local_codecs); in hci_release_dev()
2751 msft_release(hdev); in hci_release_dev()
2752 hci_dev_unlock(hdev); in hci_release_dev()
2754 ida_destroy(&hdev->unset_handle_ida); in hci_release_dev()
2755 ida_free(&hci_index_ida, hdev->id); in hci_release_dev()
2756 kfree_skb(hdev->sent_cmd); in hci_release_dev()
2757 kfree_skb(hdev->req_skb); in hci_release_dev()
2758 kfree_skb(hdev->recv_event); in hci_release_dev()
2759 kfree(hdev); in hci_release_dev()
2763 int hci_register_suspend_notifier(struct hci_dev *hdev) in hci_register_suspend_notifier() argument
2767 if (!hdev->suspend_notifier.notifier_call && in hci_register_suspend_notifier()
2768 !test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { in hci_register_suspend_notifier()
2769 hdev->suspend_notifier.notifier_call = hci_suspend_notifier; in hci_register_suspend_notifier()
2770 ret = register_pm_notifier(&hdev->suspend_notifier); in hci_register_suspend_notifier()
2776 int hci_unregister_suspend_notifier(struct hci_dev *hdev) in hci_unregister_suspend_notifier() argument
2780 if (hdev->suspend_notifier.notifier_call) { in hci_unregister_suspend_notifier()
2781 ret = unregister_pm_notifier(&hdev->suspend_notifier); in hci_unregister_suspend_notifier()
2783 hdev->suspend_notifier.notifier_call = NULL; in hci_unregister_suspend_notifier()
2795 static void hci_cancel_cmd_sync(struct hci_dev *hdev, int err) in hci_cancel_cmd_sync() argument
2797 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_cancel_cmd_sync()
2799 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_cancel_cmd_sync()
2800 disable_delayed_work_sync(&hdev->cmd_timer); in hci_cancel_cmd_sync()
2801 disable_delayed_work_sync(&hdev->ncmd_timer); in hci_cancel_cmd_sync()
2803 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cancel_cmd_sync()
2804 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cancel_cmd_sync()
2807 atomic_set(&hdev->cmd_cnt, 1); in hci_cancel_cmd_sync()
2809 hci_cmd_sync_cancel_sync(hdev, err); in hci_cancel_cmd_sync()
2813 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
2817 bt_dev_dbg(hdev, ""); in hci_suspend_dev()
2820 if (!hdev_is_powered(hdev) || in hci_suspend_dev()
2821 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_suspend_dev()
2825 if (mgmt_powering_down(hdev)) in hci_suspend_dev()
2829 hci_cancel_cmd_sync(hdev, EHOSTDOWN); in hci_suspend_dev()
2831 hci_req_sync_lock(hdev); in hci_suspend_dev()
2832 ret = hci_suspend_sync(hdev); in hci_suspend_dev()
2833 hci_req_sync_unlock(hdev); in hci_suspend_dev()
2835 hci_clear_wake_reason(hdev); in hci_suspend_dev()
2836 mgmt_suspending(hdev, hdev->suspend_state); in hci_suspend_dev()
2838 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
2844 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
2848 bt_dev_dbg(hdev, ""); in hci_resume_dev()
2851 if (!hdev_is_powered(hdev) || in hci_resume_dev()
2852 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_resume_dev()
2856 if (mgmt_powering_down(hdev)) in hci_resume_dev()
2859 hci_req_sync_lock(hdev); in hci_resume_dev()
2860 ret = hci_resume_sync(hdev); in hci_resume_dev()
2861 hci_req_sync_unlock(hdev); in hci_resume_dev()
2863 mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, in hci_resume_dev()
2864 hdev->wake_addr_type); in hci_resume_dev()
2866 hci_sock_dev_event(hdev, HCI_DEV_RESUME); in hci_resume_dev()
2872 int hci_reset_dev(struct hci_dev *hdev) in hci_reset_dev() argument
2884 bt_dev_err(hdev, "Injecting HCI hardware error event"); in hci_reset_dev()
2887 return hci_recv_frame(hdev, skb); in hci_reset_dev()
2891 static u8 hci_dev_classify_pkt_type(struct hci_dev *hdev, struct sk_buff *skb) in hci_dev_classify_pkt_type() argument
2893 if (hdev->classify_pkt_type) in hci_dev_classify_pkt_type()
2894 return hdev->classify_pkt_type(hdev, skb); in hci_dev_classify_pkt_type()
2900 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_frame() argument
2904 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
2905 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
2911 dev_pkt_type = hci_dev_classify_pkt_type(hdev, skb); in hci_recv_frame()
2921 if (hci_conn_num(hdev, ISO_LINK)) { in hci_recv_frame()
2925 type = hci_conn_lookup_type(hdev, hci_handle(handle)); in hci_recv_frame()
2945 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
2946 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
2953 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_diag() argument
2961 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_diag()
2962 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_diag()
2968 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_hw_info() argument
2973 kfree_const(hdev->hw_info); in hci_set_hw_info()
2974 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_hw_info()
2979 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_fw_info() argument
2984 kfree_const(hdev->fw_info); in hci_set_fw_info()
2985 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_fw_info()
3016 static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_frame() argument
3020 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb), in hci_send_frame()
3027 hci_send_to_monitor(hdev, skb); in hci_send_frame()
3029 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
3031 hci_send_to_sock(hdev, skb); in hci_send_frame()
3037 if (!test_bit(HCI_RUNNING, &hdev->flags)) { in hci_send_frame()
3042 err = hdev->send(hdev, skb); in hci_send_frame()
3044 bt_dev_err(hdev, "sending frame failed (%d)", err); in hci_send_frame()
3053 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
3058 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
3060 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, NULL); in hci_send_cmd()
3062 bt_dev_err(hdev, "no memory for command"); in hci_send_cmd()
3071 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
3072 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
3077 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_send() argument
3091 bt_dev_err(hdev, "unresponded command not supported"); in __hci_cmd_send()
3095 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, NULL); in __hci_cmd_send()
3097 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in __hci_cmd_send()
3102 hci_send_frame(hdev, skb); in __hci_cmd_send()
3125 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
3130 data = hci_cmd_data(hdev->sent_cmd, opcode); in hci_sent_cmd_data()
3133 data = hci_cmd_data(hdev->req_skb, opcode); in hci_sent_cmd_data()
3139 void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) in hci_recv_event_data() argument
3144 if (!hdev->recv_event) in hci_recv_event_data()
3147 hdr = (void *)hdev->recv_event->data; in hci_recv_event_data()
3155 ev = (void *)hdev->recv_event->data + offset; in hci_recv_event_data()
3164 bt_dev_dbg(hdev, "event 0x%2.2x", event); in hci_recv_event_data()
3166 return hdev->recv_event->data + offset; in hci_recv_event_data()
3186 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
3199 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3204 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3225 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3236 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
3238 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
3242 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
3248 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
3251 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
3263 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
3282 struct hci_dev *hdev = conn->hdev; in hci_queue_iso() local
3298 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3303 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3317 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3326 struct hci_dev *hdev = conn->hdev; in hci_send_iso() local
3328 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_iso()
3332 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_iso()
3340 struct hci_dev *hdev; in hci_quote_sent() local
3348 hdev = conn->hdev; in hci_quote_sent()
3352 cnt = hdev->acl_cnt; in hci_quote_sent()
3356 cnt = hdev->sco_cnt; in hci_quote_sent()
3359 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3362 cnt = hdev->iso_mtu ? hdev->iso_cnt : in hci_quote_sent()
3363 hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3367 bt_dev_err(hdev, "unknown link type %d", conn->type); in hci_quote_sent()
3374 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
3377 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
3400 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
3412 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
3414 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
3417 bt_dev_err(hdev, "link tx timeout"); in hci_link_tx_to()
3424 bt_dev_err(hdev, "killing stalled connection %pMR", in hci_link_tx_to()
3438 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
3441 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
3447 BT_DBG("%s", hdev->name); in hci_chan_sent()
3486 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
3501 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
3503 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
3507 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
3543 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
3551 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt, u8 type) in __check_timeout() argument
3555 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in __check_timeout()
3560 last_tx = hdev->le_last_tx; in __check_timeout()
3563 last_tx = hdev->acl_last_tx; in __check_timeout()
3571 hci_link_tx_to(hdev, type); in __check_timeout()
3575 static void hci_sched_sco(struct hci_dev *hdev) in hci_sched_sco() argument
3581 BT_DBG("%s", hdev->name); in hci_sched_sco()
3583 if (!hci_conn_num(hdev, SCO_LINK)) in hci_sched_sco()
3586 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, &quote))) { in hci_sched_sco()
3589 hci_send_frame(hdev, skb); in hci_sched_sco()
3598 static void hci_sched_esco(struct hci_dev *hdev) in hci_sched_esco() argument
3604 BT_DBG("%s", hdev->name); in hci_sched_esco()
3606 if (!hci_conn_num(hdev, ESCO_LINK)) in hci_sched_esco()
3609 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, in hci_sched_esco()
3613 hci_send_frame(hdev, skb); in hci_sched_esco()
3622 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
3624 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
3629 __check_timeout(hdev, cnt, ACL_LINK); in hci_sched_acl_pkt()
3631 while (hdev->acl_cnt && in hci_sched_acl_pkt()
3632 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) { in hci_sched_acl_pkt()
3647 hci_send_frame(hdev, skb); in hci_sched_acl_pkt()
3648 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
3650 hdev->acl_cnt--; in hci_sched_acl_pkt()
3655 hci_sched_sco(hdev); in hci_sched_acl_pkt()
3656 hci_sched_esco(hdev); in hci_sched_acl_pkt()
3660 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
3661 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
3664 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
3666 BT_DBG("%s", hdev->name); in hci_sched_acl()
3669 if (!hci_conn_num(hdev, ACL_LINK)) in hci_sched_acl()
3672 hci_sched_acl_pkt(hdev); in hci_sched_acl()
3675 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
3681 BT_DBG("%s", hdev->name); in hci_sched_le()
3683 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
3686 cnt = hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; in hci_sched_le()
3688 __check_timeout(hdev, *cnt, LE_LINK); in hci_sched_le()
3691 while (*cnt && (chan = hci_chan_sent(hdev, LE_LINK, &quote))) { in hci_sched_le()
3703 hci_send_frame(hdev, skb); in hci_sched_le()
3704 hdev->le_last_tx = jiffies; in hci_sched_le()
3711 hci_sched_sco(hdev); in hci_sched_le()
3712 hci_sched_esco(hdev); in hci_sched_le()
3717 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
3721 static void hci_sched_iso(struct hci_dev *hdev) in hci_sched_iso() argument
3727 BT_DBG("%s", hdev->name); in hci_sched_iso()
3729 if (!hci_conn_num(hdev, ISO_LINK)) in hci_sched_iso()
3732 cnt = hdev->iso_pkts ? &hdev->iso_cnt : in hci_sched_iso()
3733 hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; in hci_sched_iso()
3734 while (*cnt && (conn = hci_low_sent(hdev, ISO_LINK, &quote))) { in hci_sched_iso()
3737 hci_send_frame(hdev, skb); in hci_sched_iso()
3749 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
3752 BT_DBG("%s acl %d sco %d le %d iso %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
3753 hdev->sco_cnt, hdev->le_cnt, hdev->iso_cnt); in hci_tx_work()
3755 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_tx_work()
3757 hci_sched_sco(hdev); in hci_tx_work()
3758 hci_sched_esco(hdev); in hci_tx_work()
3759 hci_sched_iso(hdev); in hci_tx_work()
3760 hci_sched_acl(hdev); in hci_tx_work()
3761 hci_sched_le(hdev); in hci_tx_work()
3765 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
3766 hci_send_frame(hdev, skb); in hci_tx_work()
3772 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
3784 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_acldata_packet()
3787 hdev->stat.acl_rx++; in hci_acldata_packet()
3789 hci_dev_lock(hdev); in hci_acldata_packet()
3790 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
3791 hci_dev_unlock(hdev); in hci_acldata_packet()
3800 bt_dev_err(hdev, "ACL packet for unknown connection handle %d", in hci_acldata_packet()
3808 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
3820 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_scodata_packet()
3823 hdev->stat.sco_rx++; in hci_scodata_packet()
3825 hci_dev_lock(hdev); in hci_scodata_packet()
3826 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
3827 hci_dev_unlock(hdev); in hci_scodata_packet()
3835 bt_dev_err_ratelimited(hdev, "SCO packet for unknown connection handle %d", in hci_scodata_packet()
3842 static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_isodata_packet() argument
3850 bt_dev_err(hdev, "ISO packet too small"); in hci_isodata_packet()
3858 bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, in hci_isodata_packet()
3861 hci_dev_lock(hdev); in hci_isodata_packet()
3862 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_isodata_packet()
3863 hci_dev_unlock(hdev); in hci_isodata_packet()
3866 bt_dev_err(hdev, "ISO packet for unknown connection handle %d", in hci_isodata_packet()
3879 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
3883 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
3890 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
3896 if (!hdev->sent_cmd) in hci_resend_last()
3899 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
3904 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
3908 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
3909 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
3912 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, in hci_req_cmd_complete() argument
3924 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
3931 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
3932 hci_resend_last(hdev); in hci_req_cmd_complete()
3938 hci_dev_clear_flag(hdev, HCI_CMD_PENDING); in hci_req_cmd_complete()
3943 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
3946 skb = hdev->req_skb; in hci_req_cmd_complete()
3963 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
3964 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
3966 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
3976 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
3981 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
3984 BT_DBG("%s", hdev->name); in hci_rx_work()
3991 for (; (skb = skb_dequeue(&hdev->rx_q)); kcov_remote_stop()) { in hci_rx_work()
3995 hci_send_to_monitor(hdev, skb); in hci_rx_work()
3997 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
3999 hci_send_to_sock(hdev, skb); in hci_rx_work()
4008 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_rx_work()
4009 !test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4014 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4028 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
4029 hci_event_packet(hdev, skb); in hci_rx_work()
4033 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
4034 hci_acldata_packet(hdev, skb); in hci_rx_work()
4038 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
4039 hci_scodata_packet(hdev, skb); in hci_rx_work()
4043 BT_DBG("%s ISO data packet", hdev->name); in hci_rx_work()
4044 hci_isodata_packet(hdev, skb); in hci_rx_work()
4054 static void hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_cmd_sync() argument
4058 bt_dev_dbg(hdev, "skb %p", skb); in hci_send_cmd_sync()
4060 kfree_skb(hdev->sent_cmd); in hci_send_cmd_sync()
4062 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); in hci_send_cmd_sync()
4063 if (!hdev->sent_cmd) { in hci_send_cmd_sync()
4064 skb_queue_head(&hdev->cmd_q, skb); in hci_send_cmd_sync()
4065 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd_sync()
4069 err = hci_send_frame(hdev, skb); in hci_send_cmd_sync()
4071 hci_cmd_sync_cancel_sync(hdev, -err); in hci_send_cmd_sync()
4075 if (hdev->req_status == HCI_REQ_PEND && in hci_send_cmd_sync()
4076 !hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) { in hci_send_cmd_sync()
4077 kfree_skb(hdev->req_skb); in hci_send_cmd_sync()
4078 hdev->req_skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_send_cmd_sync()
4081 atomic_dec(&hdev->cmd_cnt); in hci_send_cmd_sync()
4086 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work); in hci_cmd_work() local
4089 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name, in hci_cmd_work()
4090 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q)); in hci_cmd_work()
4093 if (atomic_read(&hdev->cmd_cnt)) { in hci_cmd_work()
4094 skb = skb_dequeue(&hdev->cmd_q); in hci_cmd_work()
4098 hci_send_cmd_sync(hdev, skb); in hci_cmd_work()
4101 if (test_bit(HCI_RESET, &hdev->flags) || in hci_cmd_work()
4102 hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE)) in hci_cmd_work()
4103 cancel_delayed_work(&hdev->cmd_timer); in hci_cmd_work()
4105 queue_delayed_work(hdev->workqueue, &hdev->cmd_timer, in hci_cmd_work()