Lines Matching refs:hdev
70 BT_DBG("%s %x", req->hdev->name, scan); in hci_scan_req()
81 BT_DBG("%s %x", req->hdev->name, auth); in hci_auth_req()
92 BT_DBG("%s %x", req->hdev->name, encrypt); in hci_encrypt_req()
103 BT_DBG("%s %x", req->hdev->name, policy); in hci_linkpol_req()
114 struct hci_dev *hdev = NULL, *d; in hci_dev_get() local
124 hdev = hci_dev_hold(d); in hci_dev_get()
129 return hdev; in hci_dev_get()
134 bool hci_discovery_active(struct hci_dev *hdev) in hci_discovery_active() argument
136 struct discovery_state *discov = &hdev->discovery; in hci_discovery_active()
148 void hci_discovery_set_state(struct hci_dev *hdev, int state) in hci_discovery_set_state() argument
150 int old_state = hdev->discovery.state; in hci_discovery_set_state()
152 BT_DBG("%s state %u -> %u", hdev->name, hdev->discovery.state, state); in hci_discovery_set_state()
157 hdev->discovery.state = state; in hci_discovery_set_state()
161 hci_update_passive_scan(hdev); in hci_discovery_set_state()
164 mgmt_discovering(hdev, 0); in hci_discovery_set_state()
169 mgmt_discovering(hdev, 1); in hci_discovery_set_state()
178 void hci_inquiry_cache_flush(struct hci_dev *hdev) in hci_inquiry_cache_flush() argument
180 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_flush()
192 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev, in hci_inquiry_cache_lookup() argument
195 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup()
208 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev, in hci_inquiry_cache_lookup_unknown() argument
211 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_unknown()
224 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev, in hci_inquiry_cache_lookup_resolve() argument
228 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_lookup_resolve()
243 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev, in hci_inquiry_cache_update_resolve() argument
246 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update_resolve()
262 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data, in hci_inquiry_cache_update() argument
265 struct discovery_state *cache = &hdev->discovery; in hci_inquiry_cache_update()
271 hci_remove_remote_oob_data(hdev, &data->bdaddr, BDADDR_BREDR); in hci_inquiry_cache_update()
276 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr); in hci_inquiry_cache_update()
284 hci_inquiry_cache_update_resolve(hdev, ie); in hci_inquiry_cache_update()
324 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf) in inquiry_cache_dump() argument
326 struct discovery_state *cache = &hdev->discovery; in inquiry_cache_dump()
355 struct hci_dev *hdev = req->hdev; in hci_inq_req() local
358 BT_DBG("%s", hdev->name); in hci_inq_req()
360 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inq_req()
376 struct hci_dev *hdev; in hci_inquiry() local
384 hdev = hci_dev_get(ir.dev_id); in hci_inquiry()
385 if (!hdev) in hci_inquiry()
388 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_inquiry()
393 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_inquiry()
398 if (hdev->dev_type != HCI_PRIMARY) { in hci_inquiry()
403 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_inquiry()
414 hci_dev_lock(hdev); in hci_inquiry()
415 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX || in hci_inquiry()
416 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) { in hci_inquiry()
417 hci_inquiry_cache_flush(hdev); in hci_inquiry()
420 hci_dev_unlock(hdev); in hci_inquiry()
425 err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir, in hci_inquiry()
433 if (wait_on_bit(&hdev->flags, HCI_INQUIRY, in hci_inquiry()
454 hci_dev_lock(hdev); in hci_inquiry()
455 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf); in hci_inquiry()
456 hci_dev_unlock(hdev); in hci_inquiry()
471 hci_dev_put(hdev); in hci_inquiry()
475 static int hci_dev_do_open(struct hci_dev *hdev) in hci_dev_do_open() argument
479 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_open()
481 hci_req_sync_lock(hdev); in hci_dev_do_open()
483 ret = hci_dev_open_sync(hdev); in hci_dev_do_open()
485 hci_req_sync_unlock(hdev); in hci_dev_do_open()
493 struct hci_dev *hdev; in hci_dev_open() local
496 hdev = hci_dev_get(dev); in hci_dev_open()
497 if (!hdev) in hci_dev_open()
509 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open()
510 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_open()
520 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_open()
521 cancel_delayed_work(&hdev->power_off); in hci_dev_open()
527 flush_workqueue(hdev->req_workqueue); in hci_dev_open()
535 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open()
536 !hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_open()
537 hci_dev_set_flag(hdev, HCI_BONDABLE); in hci_dev_open()
539 err = hci_dev_do_open(hdev); in hci_dev_open()
542 hci_dev_put(hdev); in hci_dev_open()
546 int hci_dev_do_close(struct hci_dev *hdev) in hci_dev_do_close() argument
550 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_close()
552 hci_req_sync_lock(hdev); in hci_dev_do_close()
554 err = hci_dev_close_sync(hdev); in hci_dev_do_close()
556 hci_req_sync_unlock(hdev); in hci_dev_do_close()
563 struct hci_dev *hdev; in hci_dev_close() local
566 hdev = hci_dev_get(dev); in hci_dev_close()
567 if (!hdev) in hci_dev_close()
570 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close()
575 cancel_work_sync(&hdev->power_on); in hci_dev_close()
576 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) in hci_dev_close()
577 cancel_delayed_work(&hdev->power_off); in hci_dev_close()
579 err = hci_dev_do_close(hdev); in hci_dev_close()
582 hci_dev_put(hdev); in hci_dev_close()
586 static int hci_dev_do_reset(struct hci_dev *hdev) in hci_dev_do_reset() argument
590 BT_DBG("%s %p", hdev->name, hdev); in hci_dev_do_reset()
592 hci_req_sync_lock(hdev); in hci_dev_do_reset()
595 skb_queue_purge(&hdev->rx_q); in hci_dev_do_reset()
596 skb_queue_purge(&hdev->cmd_q); in hci_dev_do_reset()
599 hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); in hci_dev_do_reset()
609 cancel_delayed_work(&hdev->cmd_timer); in hci_dev_do_reset()
610 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_do_reset()
615 drain_workqueue(hdev->workqueue); in hci_dev_do_reset()
617 hci_dev_lock(hdev); in hci_dev_do_reset()
618 hci_inquiry_cache_flush(hdev); in hci_dev_do_reset()
619 hci_conn_hash_flush(hdev); in hci_dev_do_reset()
620 hci_dev_unlock(hdev); in hci_dev_do_reset()
622 if (hdev->flush) in hci_dev_do_reset()
623 hdev->flush(hdev); in hci_dev_do_reset()
625 hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE); in hci_dev_do_reset()
627 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_do_reset()
628 hdev->acl_cnt = 0; in hci_dev_do_reset()
629 hdev->sco_cnt = 0; in hci_dev_do_reset()
630 hdev->le_cnt = 0; in hci_dev_do_reset()
631 hdev->iso_cnt = 0; in hci_dev_do_reset()
633 ret = hci_reset_sync(hdev); in hci_dev_do_reset()
635 hci_req_sync_unlock(hdev); in hci_dev_do_reset()
641 struct hci_dev *hdev; in hci_dev_reset() local
644 hdev = hci_dev_get(dev); in hci_dev_reset()
645 if (!hdev) in hci_dev_reset()
648 if (!test_bit(HCI_UP, &hdev->flags)) { in hci_dev_reset()
653 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset()
658 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset()
663 err = hci_dev_do_reset(hdev); in hci_dev_reset()
666 hci_dev_put(hdev); in hci_dev_reset()
672 struct hci_dev *hdev; in hci_dev_reset_stat() local
675 hdev = hci_dev_get(dev); in hci_dev_reset_stat()
676 if (!hdev) in hci_dev_reset_stat()
679 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_reset_stat()
684 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_reset_stat()
689 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats)); in hci_dev_reset_stat()
692 hci_dev_put(hdev); in hci_dev_reset_stat()
696 static void hci_update_passive_scan_state(struct hci_dev *hdev, u8 scan) in hci_update_passive_scan_state() argument
700 BT_DBG("%s scan 0x%02x", hdev->name, scan); in hci_update_passive_scan_state()
703 conn_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_passive_scan_state()
706 conn_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_passive_scan_state()
710 discov_changed = !hci_dev_test_and_set_flag(hdev, in hci_update_passive_scan_state()
713 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_update_passive_scan_state()
714 discov_changed = hci_dev_test_and_clear_flag(hdev, in hci_update_passive_scan_state()
718 if (!hci_dev_test_flag(hdev, HCI_MGMT)) in hci_update_passive_scan_state()
723 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_update_passive_scan_state()
725 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_state()
726 hci_update_adv_data(hdev, hdev->cur_adv_instance); in hci_update_passive_scan_state()
728 mgmt_new_settings(hdev); in hci_update_passive_scan_state()
734 struct hci_dev *hdev; in hci_dev_cmd() local
741 hdev = hci_dev_get(dr.dev_id); in hci_dev_cmd()
742 if (!hdev) in hci_dev_cmd()
745 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_cmd()
750 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_cmd()
755 if (hdev->dev_type != HCI_PRIMARY) { in hci_dev_cmd()
760 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_dev_cmd()
767 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
772 if (!lmp_encrypt_capable(hdev)) { in hci_dev_cmd()
777 if (!test_bit(HCI_AUTH, &hdev->flags)) { in hci_dev_cmd()
779 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt, in hci_dev_cmd()
785 err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt, in hci_dev_cmd()
790 err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt, in hci_dev_cmd()
797 hci_update_passive_scan_state(hdev, dr.dev_opt); in hci_dev_cmd()
801 err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt, in hci_dev_cmd()
806 hdev->link_mode = ((__u16) dr.dev_opt) & in hci_dev_cmd()
811 if (hdev->pkt_type == (__u16) dr.dev_opt) in hci_dev_cmd()
814 hdev->pkt_type = (__u16) dr.dev_opt; in hci_dev_cmd()
815 mgmt_phy_configuration_changed(hdev, NULL); in hci_dev_cmd()
819 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
820 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
824 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1); in hci_dev_cmd()
825 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0); in hci_dev_cmd()
834 hci_dev_put(hdev); in hci_dev_cmd()
840 struct hci_dev *hdev; in hci_get_dev_list() local
861 list_for_each_entry(hdev, &hci_dev_list, list) { in hci_get_dev_list()
862 unsigned long flags = hdev->flags; in hci_get_dev_list()
868 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_list()
871 (dr + n)->dev_id = hdev->id; in hci_get_dev_list()
890 struct hci_dev *hdev; in hci_get_dev_info() local
898 hdev = hci_dev_get(di.dev_id); in hci_get_dev_info()
899 if (!hdev) in hci_get_dev_info()
906 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) in hci_get_dev_info()
907 flags = hdev->flags & ~BIT(HCI_UP); in hci_get_dev_info()
909 flags = hdev->flags; in hci_get_dev_info()
911 strcpy(di.name, hdev->name); in hci_get_dev_info()
912 di.bdaddr = hdev->bdaddr; in hci_get_dev_info()
913 di.type = (hdev->bus & 0x0f) | ((hdev->dev_type & 0x03) << 4); in hci_get_dev_info()
915 di.pkt_type = hdev->pkt_type; in hci_get_dev_info()
916 if (lmp_bredr_capable(hdev)) { in hci_get_dev_info()
917 di.acl_mtu = hdev->acl_mtu; in hci_get_dev_info()
918 di.acl_pkts = hdev->acl_pkts; in hci_get_dev_info()
919 di.sco_mtu = hdev->sco_mtu; in hci_get_dev_info()
920 di.sco_pkts = hdev->sco_pkts; in hci_get_dev_info()
922 di.acl_mtu = hdev->le_mtu; in hci_get_dev_info()
923 di.acl_pkts = hdev->le_pkts; in hci_get_dev_info()
927 di.link_policy = hdev->link_policy; in hci_get_dev_info()
928 di.link_mode = hdev->link_mode; in hci_get_dev_info()
930 memcpy(&di.stat, &hdev->stat, sizeof(di.stat)); in hci_get_dev_info()
931 memcpy(&di.features, &hdev->features, sizeof(di.features)); in hci_get_dev_info()
936 hci_dev_put(hdev); in hci_get_dev_info()
945 struct hci_dev *hdev = data; in hci_rfkill_set_block() local
947 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked); in hci_rfkill_set_block()
949 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_rfkill_set_block()
953 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
954 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_rfkill_set_block()
955 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_rfkill_set_block()
956 hci_dev_do_close(hdev); in hci_rfkill_set_block()
958 hci_dev_clear_flag(hdev, HCI_RFKILLED); in hci_rfkill_set_block()
970 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on); in hci_power_on() local
973 BT_DBG("%s", hdev->name); in hci_power_on()
975 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on()
976 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on()
977 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
978 cancel_delayed_work(&hdev->power_off); in hci_power_on()
979 err = hci_powered_update_sync(hdev); in hci_power_on()
980 mgmt_power_on(hdev, err); in hci_power_on()
984 err = hci_dev_do_open(hdev); in hci_power_on()
986 hci_dev_lock(hdev); in hci_power_on()
987 mgmt_set_powered_failed(hdev, err); in hci_power_on()
988 hci_dev_unlock(hdev); in hci_power_on()
996 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on()
997 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on()
998 (hdev->dev_type == HCI_PRIMARY && in hci_power_on()
999 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on()
1000 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on()
1001 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on()
1002 hci_dev_do_close(hdev); in hci_power_on()
1003 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on()
1004 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on()
1008 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on()
1012 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
1013 set_bit(HCI_RAW, &hdev->flags); in hci_power_on()
1022 mgmt_index_added(hdev); in hci_power_on()
1023 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on()
1027 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on()
1028 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on()
1034 mgmt_index_added(hdev); in hci_power_on()
1040 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_power_off() local
1043 BT_DBG("%s", hdev->name); in hci_power_off()
1045 hci_dev_do_close(hdev); in hci_power_off()
1050 struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset); in hci_error_reset() local
1052 BT_DBG("%s", hdev->name); in hci_error_reset()
1054 if (hdev->hw_error) in hci_error_reset()
1055 hdev->hw_error(hdev, hdev->hw_error_code); in hci_error_reset()
1057 bt_dev_err(hdev, "hardware error 0x%2.2x", hdev->hw_error_code); in hci_error_reset()
1059 if (hci_dev_do_close(hdev)) in hci_error_reset()
1062 hci_dev_do_open(hdev); in hci_error_reset()
1065 void hci_uuids_clear(struct hci_dev *hdev) in hci_uuids_clear() argument
1069 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) { in hci_uuids_clear()
1075 void hci_link_keys_clear(struct hci_dev *hdev) in hci_link_keys_clear() argument
1079 list_for_each_entry_safe(key, tmp, &hdev->link_keys, list) { in hci_link_keys_clear()
1085 void hci_smp_ltks_clear(struct hci_dev *hdev) in hci_smp_ltks_clear() argument
1089 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_smp_ltks_clear()
1095 void hci_smp_irks_clear(struct hci_dev *hdev) in hci_smp_irks_clear() argument
1099 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { in hci_smp_irks_clear()
1105 void hci_blocked_keys_clear(struct hci_dev *hdev) in hci_blocked_keys_clear() argument
1109 list_for_each_entry_safe(b, tmp, &hdev->blocked_keys, list) { in hci_blocked_keys_clear()
1115 bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16]) in hci_is_blocked_key() argument
1121 list_for_each_entry_rcu(b, &hdev->blocked_keys, list) { in hci_is_blocked_key()
1132 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_find_link_key() argument
1137 list_for_each_entry_rcu(k, &hdev->link_keys, list) { in hci_find_link_key()
1141 if (hci_is_blocked_key(hdev, in hci_find_link_key()
1144 bt_dev_warn_ratelimited(hdev, in hci_find_link_key()
1158 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_persistent_key() argument
1206 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_ltk() argument
1212 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_find_ltk()
1219 if (hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_LTK, in hci_find_ltk()
1221 bt_dev_warn_ratelimited(hdev, in hci_find_ltk()
1235 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa) in hci_find_irk_by_rpa() argument
1241 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
1248 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_rpa()
1249 if (smp_irk_matches(hdev, irk->val, rpa)) { in hci_find_irk_by_rpa()
1257 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_rpa()
1259 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_rpa()
1269 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_find_irk_by_addr() argument
1280 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) { in hci_find_irk_by_addr()
1290 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK, in hci_find_irk_by_addr()
1292 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR", in hci_find_irk_by_addr()
1302 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn, in hci_add_link_key() argument
1309 old_key = hci_find_link_key(hdev, bdaddr); in hci_add_link_key()
1318 list_add_rcu(&key->list, &hdev->link_keys); in hci_add_link_key()
1321 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type); in hci_add_link_key()
1343 *persistent = hci_persistent_key(hdev, conn, type, in hci_add_link_key()
1349 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_ltk() argument
1356 old_key = hci_find_ltk(hdev, bdaddr, addr_type, role); in hci_add_ltk()
1363 list_add_rcu(&key->list, &hdev->long_term_keys); in hci_add_ltk()
1378 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_irk() argument
1383 irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type); in hci_add_irk()
1392 list_add_rcu(&irk->list, &hdev->identity_resolving_keys); in hci_add_irk()
1401 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr) in hci_remove_link_key() argument
1405 key = hci_find_link_key(hdev, bdaddr); in hci_remove_link_key()
1409 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_link_key()
1417 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type) in hci_remove_ltk() argument
1422 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) { in hci_remove_ltk()
1426 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_ltk()
1436 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type) in hci_remove_irk() argument
1440 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) { in hci_remove_irk()
1444 BT_DBG("%s removing %pMR", hdev->name, bdaddr); in hci_remove_irk()
1451 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type) in hci_bdaddr_is_paired() argument
1458 if (hci_find_link_key(hdev, bdaddr)) in hci_bdaddr_is_paired()
1469 irk = hci_get_irk(hdev, bdaddr, addr_type); in hci_bdaddr_is_paired()
1476 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) { in hci_bdaddr_is_paired()
1490 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_cmd_timeout() local
1493 if (hdev->sent_cmd) { in hci_cmd_timeout()
1494 struct hci_command_hdr *sent = (void *) hdev->sent_cmd->data; in hci_cmd_timeout()
1497 bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode); in hci_cmd_timeout()
1499 bt_dev_err(hdev, "command tx timeout"); in hci_cmd_timeout()
1502 if (hdev->cmd_timeout) in hci_cmd_timeout()
1503 hdev->cmd_timeout(hdev); in hci_cmd_timeout()
1505 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_timeout()
1506 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_timeout()
1512 struct hci_dev *hdev = container_of(work, struct hci_dev, in hci_ncmd_timeout() local
1515 bt_dev_err(hdev, "Controller not accepting commands anymore: ncmd = 0"); in hci_ncmd_timeout()
1520 if (test_bit(HCI_INIT, &hdev->flags)) in hci_ncmd_timeout()
1524 hci_reset_dev(hdev); in hci_ncmd_timeout()
1527 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev, in hci_find_remote_oob_data() argument
1532 list_for_each_entry(data, &hdev->remote_oob_data, list) { in hci_find_remote_oob_data()
1543 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_remove_remote_oob_data() argument
1548 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
1552 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type); in hci_remove_remote_oob_data()
1560 void hci_remote_oob_data_clear(struct hci_dev *hdev) in hci_remote_oob_data_clear() argument
1564 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) { in hci_remote_oob_data_clear()
1570 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_add_remote_oob_data() argument
1576 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type); in hci_add_remote_oob_data()
1584 list_add(&data->list, &hdev->remote_oob_data); in hci_add_remote_oob_data()
1611 BT_DBG("%s for %pMR", hdev->name, bdaddr); in hci_add_remote_oob_data()
1617 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance) in hci_find_adv_instance() argument
1621 list_for_each_entry(adv_instance, &hdev->adv_instances, list) { in hci_find_adv_instance()
1630 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance) in hci_get_next_instance() argument
1634 cur_instance = hci_find_adv_instance(hdev, instance); in hci_get_next_instance()
1638 if (cur_instance == list_last_entry(&hdev->adv_instances, in hci_get_next_instance()
1640 return list_first_entry(&hdev->adv_instances, in hci_get_next_instance()
1647 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_adv_instance() argument
1651 adv_instance = hci_find_adv_instance(hdev, instance); in hci_remove_adv_instance()
1655 BT_DBG("%s removing %dMR", hdev->name, instance); in hci_remove_adv_instance()
1657 if (hdev->cur_adv_instance == instance) { in hci_remove_adv_instance()
1658 if (hdev->adv_instance_timeout) { in hci_remove_adv_instance()
1659 cancel_delayed_work(&hdev->adv_instance_expire); in hci_remove_adv_instance()
1660 hdev->adv_instance_timeout = 0; in hci_remove_adv_instance()
1662 hdev->cur_adv_instance = 0x00; in hci_remove_adv_instance()
1670 hdev->adv_instance_cnt--; in hci_remove_adv_instance()
1675 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired) in hci_adv_instances_set_rpa_expired() argument
1679 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) in hci_adv_instances_set_rpa_expired()
1684 void hci_adv_instances_clear(struct hci_dev *hdev) in hci_adv_instances_clear() argument
1688 if (hdev->adv_instance_timeout) { in hci_adv_instances_clear()
1689 cancel_delayed_work(&hdev->adv_instance_expire); in hci_adv_instances_clear()
1690 hdev->adv_instance_timeout = 0; in hci_adv_instances_clear()
1693 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) { in hci_adv_instances_clear()
1699 hdev->adv_instance_cnt = 0; in hci_adv_instances_clear()
1700 hdev->cur_adv_instance = 0x00; in hci_adv_instances_clear()
1714 struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance, in hci_add_adv_instance() argument
1723 adv = hci_find_adv_instance(hdev, instance); in hci_add_adv_instance()
1729 if (hdev->adv_instance_cnt >= hdev->le_num_of_adv_sets || in hci_add_adv_instance()
1730 instance < 1 || instance > hdev->le_num_of_adv_sets + 1) in hci_add_adv_instance()
1739 list_add(&adv->list, &hdev->adv_instances); in hci_add_adv_instance()
1740 hdev->adv_instance_cnt++; in hci_add_adv_instance()
1753 hci_set_adv_instance_data(hdev, instance, adv_data_len, adv_data, in hci_add_adv_instance()
1760 adv->duration = hdev->def_multi_adv_rotation_duration; in hci_add_adv_instance()
1766 BT_DBG("%s for %dMR", hdev->name, instance); in hci_add_adv_instance()
1772 struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance, in hci_add_per_instance() argument
1778 adv = hci_add_adv_instance(hdev, instance, flags, 0, NULL, 0, NULL, in hci_add_per_instance()
1794 int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance, in hci_set_adv_instance_data() argument
1800 adv = hci_find_adv_instance(hdev, instance); in hci_set_adv_instance_data()
1821 if (((adv->flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) || in hci_set_adv_instance_data()
1829 u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance) in hci_adv_instance_flags() argument
1843 if (hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE)) in hci_adv_instance_flags()
1846 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_adv_instance_flags()
1848 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_adv_instance_flags()
1854 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_flags()
1863 bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance) in hci_adv_instance_is_scannable() argument
1871 adv = hci_find_adv_instance(hdev, instance); in hci_adv_instance_is_scannable()
1883 void hci_adv_monitors_clear(struct hci_dev *hdev) in hci_adv_monitors_clear() argument
1888 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle) in hci_adv_monitors_clear()
1889 hci_free_adv_monitor(hdev, monitor); in hci_adv_monitors_clear()
1891 idr_destroy(&hdev->adv_monitors_idr); in hci_adv_monitors_clear()
1897 void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) in hci_free_adv_monitor() argument
1911 idr_remove(&hdev->adv_monitors_idr, monitor->handle); in hci_free_adv_monitor()
1914 hdev->adv_monitors_cnt--; in hci_free_adv_monitor()
1915 mgmt_adv_monitor_removed(hdev, monitor->handle); in hci_free_adv_monitor()
1925 int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor) in hci_add_adv_monitor() argument
1933 hci_dev_lock(hdev); in hci_add_adv_monitor()
1937 handle = idr_alloc(&hdev->adv_monitors_idr, monitor, min, max, in hci_add_adv_monitor()
1940 hci_dev_unlock(hdev); in hci_add_adv_monitor()
1947 if (!hdev_is_powered(hdev)) in hci_add_adv_monitor()
1950 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_add_adv_monitor()
1952 bt_dev_dbg(hdev, "add monitor %d status %d", in hci_add_adv_monitor()
1958 status = msft_add_monitor_pattern(hdev, monitor); in hci_add_adv_monitor()
1959 bt_dev_dbg(hdev, "add monitor %d msft status %d", in hci_add_adv_monitor()
1971 static int hci_remove_adv_monitor(struct hci_dev *hdev, in hci_remove_adv_monitor() argument
1977 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_remove_adv_monitor()
1979 bt_dev_dbg(hdev, "remove monitor %d status %d", in hci_remove_adv_monitor()
1985 status = msft_remove_monitor(hdev, monitor); in hci_remove_adv_monitor()
1986 bt_dev_dbg(hdev, "remove monitor %d msft status %d", in hci_remove_adv_monitor()
1999 bt_dev_warn(hdev, "Removing monitor with no matching handle %d", in hci_remove_adv_monitor()
2001 hci_free_adv_monitor(hdev, monitor); in hci_remove_adv_monitor()
2007 int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle) in hci_remove_single_adv_monitor() argument
2009 struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle); in hci_remove_single_adv_monitor()
2014 return hci_remove_adv_monitor(hdev, monitor); in hci_remove_single_adv_monitor()
2018 int hci_remove_all_adv_monitor(struct hci_dev *hdev) in hci_remove_all_adv_monitor() argument
2025 monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id); in hci_remove_all_adv_monitor()
2029 status = hci_remove_adv_monitor(hdev, monitor); in hci_remove_all_adv_monitor()
2040 bool hci_is_adv_monitoring(struct hci_dev *hdev) in hci_is_adv_monitoring() argument
2042 return !idr_is_empty(&hdev->adv_monitors_idr); in hci_is_adv_monitoring()
2045 int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev) in hci_get_adv_monitor_offload_ext() argument
2047 if (msft_monitor_supported(hdev)) in hci_get_adv_monitor_offload_ext()
2239 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, in hci_conn_params_lookup() argument
2244 list_for_each_entry(params, &hdev->le_conn_params, list) { in hci_conn_params_lookup()
2294 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, in hci_conn_params_add() argument
2299 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_add()
2305 bt_dev_err(hdev, "out of memory"); in hci_conn_params_add()
2312 list_add(¶ms->list, &hdev->le_conn_params); in hci_conn_params_add()
2315 params->conn_min_interval = hdev->le_conn_min_interval; in hci_conn_params_add()
2316 params->conn_max_interval = hdev->le_conn_max_interval; in hci_conn_params_add()
2317 params->conn_latency = hdev->le_conn_latency; in hci_conn_params_add()
2318 params->supervision_timeout = hdev->le_supv_timeout; in hci_conn_params_add()
2340 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) in hci_conn_params_del() argument
2344 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_del()
2350 hci_update_passive_scan(hdev); in hci_conn_params_del()
2356 void hci_conn_params_clear_disabled(struct hci_dev *hdev) in hci_conn_params_clear_disabled() argument
2360 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) { in hci_conn_params_clear_disabled()
2379 static void hci_conn_params_clear_all(struct hci_dev *hdev) in hci_conn_params_clear_all() argument
2383 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) in hci_conn_params_clear_all()
2402 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_copy_identity_address() argument
2405 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_copy_identity_address()
2406 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_copy_identity_address()
2407 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_copy_identity_address()
2408 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_copy_identity_address()
2409 bacpy(bdaddr, &hdev->static_addr); in hci_copy_identity_address()
2412 bacpy(bdaddr, &hdev->bdaddr); in hci_copy_identity_address()
2417 static void hci_clear_wake_reason(struct hci_dev *hdev) in hci_clear_wake_reason() argument
2419 hci_dev_lock(hdev); in hci_clear_wake_reason()
2421 hdev->wake_reason = 0; in hci_clear_wake_reason()
2422 bacpy(&hdev->wake_addr, BDADDR_ANY); in hci_clear_wake_reason()
2423 hdev->wake_addr_type = 0; in hci_clear_wake_reason()
2425 hci_dev_unlock(hdev); in hci_clear_wake_reason()
2431 struct hci_dev *hdev = in hci_suspend_notifier() local
2436 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_suspend_notifier()
2440 hci_dev_hold(hdev); in hci_suspend_notifier()
2443 ret = hci_suspend_dev(hdev); in hci_suspend_notifier()
2445 ret = hci_resume_dev(hdev); in hci_suspend_notifier()
2448 bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d", in hci_suspend_notifier()
2451 hci_dev_put(hdev); in hci_suspend_notifier()
2458 struct hci_dev *hdev; in hci_alloc_dev_priv() local
2461 alloc_size = sizeof(*hdev); in hci_alloc_dev_priv()
2467 hdev = kzalloc(alloc_size, GFP_KERNEL); in hci_alloc_dev_priv()
2468 if (!hdev) in hci_alloc_dev_priv()
2471 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev_priv()
2472 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev_priv()
2473 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev_priv()
2474 hdev->num_iac = 0x01; /* One IAC support is mandatory */ in hci_alloc_dev_priv()
2475 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev_priv()
2476 hdev->manufacturer = 0xffff; /* Default to internal use */ in hci_alloc_dev_priv()
2477 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2478 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2479 hdev->adv_instance_cnt = 0; in hci_alloc_dev_priv()
2480 hdev->cur_adv_instance = 0x00; in hci_alloc_dev_priv()
2481 hdev->adv_instance_timeout = 0; in hci_alloc_dev_priv()
2483 hdev->advmon_allowlist_duration = 300; in hci_alloc_dev_priv()
2484 hdev->advmon_no_filter_duration = 500; in hci_alloc_dev_priv()
2485 hdev->enable_advmon_interleave_scan = 0x00; /* Default to disable */ in hci_alloc_dev_priv()
2487 hdev->sniff_max_interval = 800; in hci_alloc_dev_priv()
2488 hdev->sniff_min_interval = 80; in hci_alloc_dev_priv()
2490 hdev->le_adv_channel_map = 0x07; in hci_alloc_dev_priv()
2491 hdev->le_adv_min_interval = 0x0800; in hci_alloc_dev_priv()
2492 hdev->le_adv_max_interval = 0x0800; in hci_alloc_dev_priv()
2493 hdev->le_scan_interval = 0x0060; in hci_alloc_dev_priv()
2494 hdev->le_scan_window = 0x0030; in hci_alloc_dev_priv()
2495 hdev->le_scan_int_suspend = 0x0400; in hci_alloc_dev_priv()
2496 hdev->le_scan_window_suspend = 0x0012; in hci_alloc_dev_priv()
2497 hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT; in hci_alloc_dev_priv()
2498 hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN; in hci_alloc_dev_priv()
2499 hdev->le_scan_int_adv_monitor = 0x0060; in hci_alloc_dev_priv()
2500 hdev->le_scan_window_adv_monitor = 0x0030; in hci_alloc_dev_priv()
2501 hdev->le_scan_int_connect = 0x0060; in hci_alloc_dev_priv()
2502 hdev->le_scan_window_connect = 0x0060; in hci_alloc_dev_priv()
2503 hdev->le_conn_min_interval = 0x0018; in hci_alloc_dev_priv()
2504 hdev->le_conn_max_interval = 0x0028; in hci_alloc_dev_priv()
2505 hdev->le_conn_latency = 0x0000; in hci_alloc_dev_priv()
2506 hdev->le_supv_timeout = 0x002a; in hci_alloc_dev_priv()
2507 hdev->le_def_tx_len = 0x001b; in hci_alloc_dev_priv()
2508 hdev->le_def_tx_time = 0x0148; in hci_alloc_dev_priv()
2509 hdev->le_max_tx_len = 0x001b; in hci_alloc_dev_priv()
2510 hdev->le_max_tx_time = 0x0148; in hci_alloc_dev_priv()
2511 hdev->le_max_rx_len = 0x001b; in hci_alloc_dev_priv()
2512 hdev->le_max_rx_time = 0x0148; in hci_alloc_dev_priv()
2513 hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2514 hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2515 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2516 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2517 hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; in hci_alloc_dev_priv()
2518 hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; in hci_alloc_dev_priv()
2519 hdev->def_le_autoconnect_timeout = HCI_LE_AUTOCONN_TIMEOUT; in hci_alloc_dev_priv()
2520 hdev->min_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2521 hdev->max_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2523 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; in hci_alloc_dev_priv()
2524 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; in hci_alloc_dev_priv()
2525 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE; in hci_alloc_dev_priv()
2526 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE; in hci_alloc_dev_priv()
2527 hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; in hci_alloc_dev_priv()
2528 hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2531 hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD; in hci_alloc_dev_priv()
2532 hdev->def_page_scan_int = 0x0800; in hci_alloc_dev_priv()
2533 hdev->def_page_scan_window = 0x0012; in hci_alloc_dev_priv()
2535 mutex_init(&hdev->lock); in hci_alloc_dev_priv()
2536 mutex_init(&hdev->req_lock); in hci_alloc_dev_priv()
2538 INIT_LIST_HEAD(&hdev->mesh_pending); in hci_alloc_dev_priv()
2539 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev_priv()
2540 INIT_LIST_HEAD(&hdev->reject_list); in hci_alloc_dev_priv()
2541 INIT_LIST_HEAD(&hdev->accept_list); in hci_alloc_dev_priv()
2542 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev_priv()
2543 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev_priv()
2544 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev_priv()
2545 INIT_LIST_HEAD(&hdev->identity_resolving_keys); in hci_alloc_dev_priv()
2546 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev_priv()
2547 INIT_LIST_HEAD(&hdev->le_accept_list); in hci_alloc_dev_priv()
2548 INIT_LIST_HEAD(&hdev->le_resolv_list); in hci_alloc_dev_priv()
2549 INIT_LIST_HEAD(&hdev->le_conn_params); in hci_alloc_dev_priv()
2550 INIT_LIST_HEAD(&hdev->pend_le_conns); in hci_alloc_dev_priv()
2551 INIT_LIST_HEAD(&hdev->pend_le_reports); in hci_alloc_dev_priv()
2552 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev_priv()
2553 INIT_LIST_HEAD(&hdev->adv_instances); in hci_alloc_dev_priv()
2554 INIT_LIST_HEAD(&hdev->blocked_keys); in hci_alloc_dev_priv()
2555 INIT_LIST_HEAD(&hdev->monitored_devices); in hci_alloc_dev_priv()
2557 INIT_LIST_HEAD(&hdev->local_codecs); in hci_alloc_dev_priv()
2558 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev_priv()
2559 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev_priv()
2560 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev_priv()
2561 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev_priv()
2562 INIT_WORK(&hdev->error_reset, hci_error_reset); in hci_alloc_dev_priv()
2564 hci_cmd_sync_init(hdev); in hci_alloc_dev_priv()
2566 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev_priv()
2568 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev_priv()
2569 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev_priv()
2570 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev_priv()
2572 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev_priv()
2574 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); in hci_alloc_dev_priv()
2575 INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout); in hci_alloc_dev_priv()
2577 hci_devcd_setup(hdev); in hci_alloc_dev_priv()
2578 hci_request_setup(hdev); in hci_alloc_dev_priv()
2580 hci_init_sysfs(hdev); in hci_alloc_dev_priv()
2581 discovery_init(hdev); in hci_alloc_dev_priv()
2583 return hdev; in hci_alloc_dev_priv()
2588 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
2591 put_device(&hdev->dev); in hci_free_dev()
2596 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
2600 if (!hdev->open || !hdev->close || !hdev->send) in hci_register_dev()
2606 switch (hdev->dev_type) { in hci_register_dev()
2620 error = dev_set_name(&hdev->dev, "hci%u", id); in hci_register_dev()
2624 hdev->name = dev_name(&hdev->dev); in hci_register_dev()
2625 hdev->id = id; in hci_register_dev()
2627 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
2629 hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name); in hci_register_dev()
2630 if (!hdev->workqueue) { in hci_register_dev()
2635 hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, in hci_register_dev()
2636 hdev->name); in hci_register_dev()
2637 if (!hdev->req_workqueue) { in hci_register_dev()
2638 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2644 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); in hci_register_dev()
2646 error = device_add(&hdev->dev); in hci_register_dev()
2650 hci_leds_init(hdev); in hci_register_dev()
2652 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
2654 hdev); in hci_register_dev()
2655 if (hdev->rfkill) { in hci_register_dev()
2656 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
2657 rfkill_destroy(hdev->rfkill); in hci_register_dev()
2658 hdev->rfkill = NULL; in hci_register_dev()
2662 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) in hci_register_dev()
2663 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_register_dev()
2665 hci_dev_set_flag(hdev, HCI_SETUP); in hci_register_dev()
2666 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in hci_register_dev()
2668 if (hdev->dev_type == HCI_PRIMARY) { in hci_register_dev()
2672 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_register_dev()
2676 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
2682 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_register_dev()
2683 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_register_dev()
2688 if (hdev->wakeup) in hci_register_dev()
2689 hdev->conn_flags |= HCI_CONN_FLAG_REMOTE_WAKEUP; in hci_register_dev()
2691 hci_sock_dev_event(hdev, HCI_DEV_REG); in hci_register_dev()
2692 hci_dev_hold(hdev); in hci_register_dev()
2694 error = hci_register_suspend_notifier(hdev); in hci_register_dev()
2698 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
2700 idr_init(&hdev->adv_monitors_idr); in hci_register_dev()
2701 msft_register(hdev); in hci_register_dev()
2706 debugfs_remove_recursive(hdev->debugfs); in hci_register_dev()
2707 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2708 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
2710 ida_simple_remove(&hci_index_ida, hdev->id); in hci_register_dev()
2717 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
2719 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
2721 mutex_lock(&hdev->unregister_lock); in hci_unregister_dev()
2722 hci_dev_set_flag(hdev, HCI_UNREGISTER); in hci_unregister_dev()
2723 mutex_unlock(&hdev->unregister_lock); in hci_unregister_dev()
2726 list_del(&hdev->list); in hci_unregister_dev()
2729 cancel_work_sync(&hdev->power_on); in hci_unregister_dev()
2731 hci_cmd_sync_clear(hdev); in hci_unregister_dev()
2733 hci_unregister_suspend_notifier(hdev); in hci_unregister_dev()
2735 msft_unregister(hdev); in hci_unregister_dev()
2737 hci_dev_do_close(hdev); in hci_unregister_dev()
2739 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
2740 !hci_dev_test_flag(hdev, HCI_SETUP) && in hci_unregister_dev()
2741 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_unregister_dev()
2742 hci_dev_lock(hdev); in hci_unregister_dev()
2743 mgmt_index_removed(hdev); in hci_unregister_dev()
2744 hci_dev_unlock(hdev); in hci_unregister_dev()
2749 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
2751 hci_sock_dev_event(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
2753 if (hdev->rfkill) { in hci_unregister_dev()
2754 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
2755 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
2758 device_del(&hdev->dev); in hci_unregister_dev()
2760 hci_dev_put(hdev); in hci_unregister_dev()
2765 void hci_release_dev(struct hci_dev *hdev) in hci_release_dev() argument
2767 debugfs_remove_recursive(hdev->debugfs); in hci_release_dev()
2768 kfree_const(hdev->hw_info); in hci_release_dev()
2769 kfree_const(hdev->fw_info); in hci_release_dev()
2771 destroy_workqueue(hdev->workqueue); in hci_release_dev()
2772 destroy_workqueue(hdev->req_workqueue); in hci_release_dev()
2774 hci_dev_lock(hdev); in hci_release_dev()
2775 hci_bdaddr_list_clear(&hdev->reject_list); in hci_release_dev()
2776 hci_bdaddr_list_clear(&hdev->accept_list); in hci_release_dev()
2777 hci_uuids_clear(hdev); in hci_release_dev()
2778 hci_link_keys_clear(hdev); in hci_release_dev()
2779 hci_smp_ltks_clear(hdev); in hci_release_dev()
2780 hci_smp_irks_clear(hdev); in hci_release_dev()
2781 hci_remote_oob_data_clear(hdev); in hci_release_dev()
2782 hci_adv_instances_clear(hdev); in hci_release_dev()
2783 hci_adv_monitors_clear(hdev); in hci_release_dev()
2784 hci_bdaddr_list_clear(&hdev->le_accept_list); in hci_release_dev()
2785 hci_bdaddr_list_clear(&hdev->le_resolv_list); in hci_release_dev()
2786 hci_conn_params_clear_all(hdev); in hci_release_dev()
2787 hci_discovery_filter_clear(hdev); in hci_release_dev()
2788 hci_blocked_keys_clear(hdev); in hci_release_dev()
2789 hci_codec_list_clear(&hdev->local_codecs); in hci_release_dev()
2790 hci_dev_unlock(hdev); in hci_release_dev()
2792 ida_simple_remove(&hci_index_ida, hdev->id); in hci_release_dev()
2793 kfree_skb(hdev->sent_cmd); in hci_release_dev()
2794 kfree_skb(hdev->recv_event); in hci_release_dev()
2795 kfree(hdev); in hci_release_dev()
2799 int hci_register_suspend_notifier(struct hci_dev *hdev) in hci_register_suspend_notifier() argument
2803 if (!hdev->suspend_notifier.notifier_call && in hci_register_suspend_notifier()
2804 !test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) { in hci_register_suspend_notifier()
2805 hdev->suspend_notifier.notifier_call = hci_suspend_notifier; in hci_register_suspend_notifier()
2806 ret = register_pm_notifier(&hdev->suspend_notifier); in hci_register_suspend_notifier()
2812 int hci_unregister_suspend_notifier(struct hci_dev *hdev) in hci_unregister_suspend_notifier() argument
2816 if (hdev->suspend_notifier.notifier_call) { in hci_unregister_suspend_notifier()
2817 ret = unregister_pm_notifier(&hdev->suspend_notifier); in hci_unregister_suspend_notifier()
2819 hdev->suspend_notifier.notifier_call = NULL; in hci_unregister_suspend_notifier()
2826 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
2830 bt_dev_dbg(hdev, ""); in hci_suspend_dev()
2833 if (!hdev_is_powered(hdev) || in hci_suspend_dev()
2834 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_suspend_dev()
2838 if (mgmt_powering_down(hdev)) in hci_suspend_dev()
2842 __hci_cmd_sync_cancel(hdev, -EHOSTDOWN); in hci_suspend_dev()
2844 hci_req_sync_lock(hdev); in hci_suspend_dev()
2845 ret = hci_suspend_sync(hdev); in hci_suspend_dev()
2846 hci_req_sync_unlock(hdev); in hci_suspend_dev()
2848 hci_clear_wake_reason(hdev); in hci_suspend_dev()
2849 mgmt_suspending(hdev, hdev->suspend_state); in hci_suspend_dev()
2851 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
2857 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
2861 bt_dev_dbg(hdev, ""); in hci_resume_dev()
2864 if (!hdev_is_powered(hdev) || in hci_resume_dev()
2865 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_resume_dev()
2869 if (mgmt_powering_down(hdev)) in hci_resume_dev()
2872 hci_req_sync_lock(hdev); in hci_resume_dev()
2873 ret = hci_resume_sync(hdev); in hci_resume_dev()
2874 hci_req_sync_unlock(hdev); in hci_resume_dev()
2876 mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, in hci_resume_dev()
2877 hdev->wake_addr_type); in hci_resume_dev()
2879 hci_sock_dev_event(hdev, HCI_DEV_RESUME); in hci_resume_dev()
2885 int hci_reset_dev(struct hci_dev *hdev) in hci_reset_dev() argument
2897 bt_dev_err(hdev, "Injecting HCI hardware error event"); in hci_reset_dev()
2900 return hci_recv_frame(hdev, skb); in hci_reset_dev()
2905 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_frame() argument
2907 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
2908 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
2918 if (hci_conn_num(hdev, ISO_LINK)) { in hci_recv_frame()
2922 type = hci_conn_lookup_type(hdev, hci_handle(handle)); in hci_recv_frame()
2942 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
2943 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
2950 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_diag() argument
2958 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_diag()
2959 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_diag()
2965 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_hw_info() argument
2970 kfree_const(hdev->hw_info); in hci_set_hw_info()
2971 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_hw_info()
2976 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_fw_info() argument
2981 kfree_const(hdev->fw_info); in hci_set_fw_info()
2982 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_fw_info()
3013 static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_frame() argument
3017 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb), in hci_send_frame()
3024 hci_send_to_monitor(hdev, skb); in hci_send_frame()
3026 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
3028 hci_send_to_sock(hdev, skb); in hci_send_frame()
3034 if (!test_bit(HCI_RUNNING, &hdev->flags)) { in hci_send_frame()
3039 err = hdev->send(hdev, skb); in hci_send_frame()
3041 bt_dev_err(hdev, "sending frame failed (%d)", err); in hci_send_frame()
3050 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
3055 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
3057 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_send_cmd()
3059 bt_dev_err(hdev, "no memory for command"); in hci_send_cmd()
3068 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
3069 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
3074 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_send() argument
3088 bt_dev_err(hdev, "unresponded command not supported"); in __hci_cmd_send()
3092 skb = hci_prepare_cmd(hdev, opcode, plen, param); in __hci_cmd_send()
3094 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in __hci_cmd_send()
3099 hci_send_frame(hdev, skb); in __hci_cmd_send()
3106 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
3110 if (!hdev->sent_cmd) in hci_sent_cmd_data()
3113 hdr = (void *) hdev->sent_cmd->data; in hci_sent_cmd_data()
3118 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); in hci_sent_cmd_data()
3120 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; in hci_sent_cmd_data()
3124 void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) in hci_recv_event_data() argument
3129 if (!hdev->recv_event) in hci_recv_event_data()
3132 hdr = (void *)hdev->recv_event->data; in hci_recv_event_data()
3140 ev = (void *)hdev->recv_event->data + offset; in hci_recv_event_data()
3149 bt_dev_dbg(hdev, "event 0x%2.2x", event); in hci_recv_event_data()
3151 return hdev->recv_event->data + offset; in hci_recv_event_data()
3171 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
3179 switch (hdev->dev_type) { in hci_queue_acl()
3187 bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type); in hci_queue_acl()
3194 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3199 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3220 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3231 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
3233 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
3237 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
3243 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
3246 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
3258 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
3277 struct hci_dev *hdev = conn->hdev; in hci_queue_iso() local
3293 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3298 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3312 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3321 struct hci_dev *hdev = conn->hdev; in hci_send_iso() local
3323 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_iso()
3327 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_iso()
3335 struct hci_dev *hdev; in hci_quote_sent() local
3343 hdev = conn->hdev; in hci_quote_sent()
3347 cnt = hdev->acl_cnt; in hci_quote_sent()
3350 cnt = hdev->block_cnt; in hci_quote_sent()
3354 cnt = hdev->sco_cnt; in hci_quote_sent()
3357 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3360 cnt = hdev->iso_mtu ? hdev->iso_cnt : in hci_quote_sent()
3361 hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3365 bt_dev_err(hdev, "unknown link type %d", conn->type); in hci_quote_sent()
3372 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
3375 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
3398 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
3410 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
3412 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
3415 bt_dev_err(hdev, "link tx timeout"); in hci_link_tx_to()
3422 bt_dev_err(hdev, "killing stalled connection %pMR", in hci_link_tx_to()
3436 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
3439 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
3445 BT_DBG("%s", hdev->name); in hci_chan_sent()
3484 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
3499 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
3501 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
3505 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
3541 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
3549 static inline int __get_blocks(struct hci_dev *hdev, struct sk_buff *skb) in __get_blocks() argument
3552 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len); in __get_blocks()
3555 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt, u8 type) in __check_timeout() argument
3559 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in __check_timeout()
3564 last_tx = hdev->le_last_tx; in __check_timeout()
3567 last_tx = hdev->acl_last_tx; in __check_timeout()
3575 hci_link_tx_to(hdev, type); in __check_timeout()
3579 static void hci_sched_sco(struct hci_dev *hdev) in hci_sched_sco() argument
3585 BT_DBG("%s", hdev->name); in hci_sched_sco()
3587 if (!hci_conn_num(hdev, SCO_LINK)) in hci_sched_sco()
3590 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, "e))) { in hci_sched_sco()
3593 hci_send_frame(hdev, skb); in hci_sched_sco()
3602 static void hci_sched_esco(struct hci_dev *hdev) in hci_sched_esco() argument
3608 BT_DBG("%s", hdev->name); in hci_sched_esco()
3610 if (!hci_conn_num(hdev, ESCO_LINK)) in hci_sched_esco()
3613 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, in hci_sched_esco()
3617 hci_send_frame(hdev, skb); in hci_sched_esco()
3626 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
3628 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
3633 __check_timeout(hdev, cnt, ACL_LINK); in hci_sched_acl_pkt()
3635 while (hdev->acl_cnt && in hci_sched_acl_pkt()
3636 (chan = hci_chan_sent(hdev, ACL_LINK, "e))) { in hci_sched_acl_pkt()
3651 hci_send_frame(hdev, skb); in hci_sched_acl_pkt()
3652 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
3654 hdev->acl_cnt--; in hci_sched_acl_pkt()
3659 hci_sched_sco(hdev); in hci_sched_acl_pkt()
3660 hci_sched_esco(hdev); in hci_sched_acl_pkt()
3664 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
3665 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
3668 static void hci_sched_acl_blk(struct hci_dev *hdev) in hci_sched_acl_blk() argument
3670 unsigned int cnt = hdev->block_cnt; in hci_sched_acl_blk()
3676 BT_DBG("%s", hdev->name); in hci_sched_acl_blk()
3678 if (hdev->dev_type == HCI_AMP) in hci_sched_acl_blk()
3683 __check_timeout(hdev, cnt, type); in hci_sched_acl_blk()
3685 while (hdev->block_cnt > 0 && in hci_sched_acl_blk()
3686 (chan = hci_chan_sent(hdev, type, "e))) { in hci_sched_acl_blk()
3700 blocks = __get_blocks(hdev, skb); in hci_sched_acl_blk()
3701 if (blocks > hdev->block_cnt) in hci_sched_acl_blk()
3707 hci_send_frame(hdev, skb); in hci_sched_acl_blk()
3708 hdev->acl_last_tx = jiffies; in hci_sched_acl_blk()
3710 hdev->block_cnt -= blocks; in hci_sched_acl_blk()
3718 if (cnt != hdev->block_cnt) in hci_sched_acl_blk()
3719 hci_prio_recalculate(hdev, type); in hci_sched_acl_blk()
3722 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
3724 BT_DBG("%s", hdev->name); in hci_sched_acl()
3727 if (!hci_conn_num(hdev, ACL_LINK) && hdev->dev_type == HCI_PRIMARY) in hci_sched_acl()
3731 if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP) in hci_sched_acl()
3734 switch (hdev->flow_ctl_mode) { in hci_sched_acl()
3736 hci_sched_acl_pkt(hdev); in hci_sched_acl()
3740 hci_sched_acl_blk(hdev); in hci_sched_acl()
3745 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
3751 BT_DBG("%s", hdev->name); in hci_sched_le()
3753 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
3756 cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; in hci_sched_le()
3758 __check_timeout(hdev, cnt, LE_LINK); in hci_sched_le()
3761 while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, "e))) { in hci_sched_le()
3773 hci_send_frame(hdev, skb); in hci_sched_le()
3774 hdev->le_last_tx = jiffies; in hci_sched_le()
3781 hci_sched_sco(hdev); in hci_sched_le()
3782 hci_sched_esco(hdev); in hci_sched_le()
3786 if (hdev->le_pkts) in hci_sched_le()
3787 hdev->le_cnt = cnt; in hci_sched_le()
3789 hdev->acl_cnt = cnt; in hci_sched_le()
3792 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
3796 static void hci_sched_iso(struct hci_dev *hdev) in hci_sched_iso() argument
3802 BT_DBG("%s", hdev->name); in hci_sched_iso()
3804 if (!hci_conn_num(hdev, ISO_LINK)) in hci_sched_iso()
3807 cnt = hdev->iso_pkts ? &hdev->iso_cnt : in hci_sched_iso()
3808 hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; in hci_sched_iso()
3809 while (*cnt && (conn = hci_low_sent(hdev, ISO_LINK, "e))) { in hci_sched_iso()
3812 hci_send_frame(hdev, skb); in hci_sched_iso()
3824 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
3827 BT_DBG("%s acl %d sco %d le %d iso %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
3828 hdev->sco_cnt, hdev->le_cnt, hdev->iso_cnt); in hci_tx_work()
3830 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_tx_work()
3832 hci_sched_sco(hdev); in hci_tx_work()
3833 hci_sched_esco(hdev); in hci_tx_work()
3834 hci_sched_iso(hdev); in hci_tx_work()
3835 hci_sched_acl(hdev); in hci_tx_work()
3836 hci_sched_le(hdev); in hci_tx_work()
3840 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
3841 hci_send_frame(hdev, skb); in hci_tx_work()
3847 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
3859 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_acldata_packet()
3862 hdev->stat.acl_rx++; in hci_acldata_packet()
3864 hci_dev_lock(hdev); in hci_acldata_packet()
3865 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
3866 hci_dev_unlock(hdev); in hci_acldata_packet()
3875 bt_dev_err(hdev, "ACL packet for unknown connection handle %d", in hci_acldata_packet()
3883 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
3895 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_scodata_packet()
3898 hdev->stat.sco_rx++; in hci_scodata_packet()
3900 hci_dev_lock(hdev); in hci_scodata_packet()
3901 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
3902 hci_dev_unlock(hdev); in hci_scodata_packet()
3910 bt_dev_err_ratelimited(hdev, "SCO packet for unknown connection handle %d", in hci_scodata_packet()
3917 static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_isodata_packet() argument
3925 bt_dev_err(hdev, "ISO packet too small"); in hci_isodata_packet()
3933 bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, in hci_isodata_packet()
3936 hci_dev_lock(hdev); in hci_isodata_packet()
3937 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_isodata_packet()
3938 hci_dev_unlock(hdev); in hci_isodata_packet()
3941 bt_dev_err(hdev, "ISO packet for unknown connection handle %d", in hci_isodata_packet()
3954 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
3958 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
3965 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
3971 if (!hdev->sent_cmd) in hci_resend_last()
3974 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
3979 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
3983 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
3984 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
3987 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, in hci_req_cmd_complete() argument
3999 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
4006 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
4007 hci_resend_last(hdev); in hci_req_cmd_complete()
4013 hci_dev_clear_flag(hdev, HCI_CMD_PENDING); in hci_req_cmd_complete()
4018 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
4025 if (bt_cb(hdev->sent_cmd)->hci.req_flags & HCI_REQ_SKB) { in hci_req_cmd_complete()
4026 *req_complete_skb = bt_cb(hdev->sent_cmd)->hci.req_complete_skb; in hci_req_cmd_complete()
4030 if (bt_cb(hdev->sent_cmd)->hci.req_complete) { in hci_req_cmd_complete()
4031 *req_complete = bt_cb(hdev->sent_cmd)->hci.req_complete; in hci_req_cmd_complete()
4036 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4037 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
4039 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
4049 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
4054 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
4057 BT_DBG("%s", hdev->name); in hci_rx_work()
4064 for (; (skb = skb_dequeue(&hdev->rx_q)); kcov_remote_stop()) { in hci_rx_work()
4068 hci_send_to_monitor(hdev, skb); in hci_rx_work()
4070 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
4072 hci_send_to_sock(hdev, skb); in hci_rx_work()
4081 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_rx_work()
4082 !test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4087 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4101 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
4102 hci_event_packet(hdev, skb); in hci_rx_work()
4106 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
4107 hci_acldata_packet(hdev, skb); in hci_rx_work()
4111 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
4112 hci_scodata_packet(hdev, skb); in hci_rx_work()
4116 BT_DBG("%s ISO data packet", hdev->name); in hci_rx_work()
4117 hci_isodata_packet(hdev, skb); in hci_rx_work()
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 kfree_skb(hdev->sent_cmd); in hci_cmd_work()
4143 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); in hci_cmd_work()
4144 if (hdev->sent_cmd) { in hci_cmd_work()
4146 if (hci_req_status_pend(hdev)) in hci_cmd_work()
4147 hci_dev_set_flag(hdev, HCI_CMD_PENDING); in hci_cmd_work()
4148 atomic_dec(&hdev->cmd_cnt); in hci_cmd_work()
4150 res = hci_send_frame(hdev, skb); in hci_cmd_work()
4152 __hci_cmd_sync_cancel(hdev, -res); in hci_cmd_work()
4155 if (test_bit(HCI_RESET, &hdev->flags) || in hci_cmd_work()
4156 hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE)) in hci_cmd_work()
4157 cancel_delayed_work(&hdev->cmd_timer); in hci_cmd_work()
4159 queue_delayed_work(hdev->workqueue, &hdev->cmd_timer, in hci_cmd_work()
4163 skb_queue_head(&hdev->cmd_q, skb); in hci_cmd_work()
4164 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_work()