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(key, &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(k, &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(k, &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(b, &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_rcu(k, &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_rcu(k, &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, "%s add monitor %d status %d", hdev->name, in hci_add_adv_monitor()
1958 status = msft_add_monitor_pattern(hdev, monitor); in hci_add_adv_monitor()
1959 bt_dev_dbg(hdev, "%s add monitor %d msft status %d", hdev->name, in hci_add_adv_monitor()
1971 static int hci_remove_adv_monitor(struct hci_dev *hdev, in hci_remove_adv_monitor() argument
1976 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_remove_adv_monitor()
1978 bt_dev_dbg(hdev, "%s remove monitor %d status %d", hdev->name, in hci_remove_adv_monitor()
1983 status = msft_remove_monitor(hdev, monitor); in hci_remove_adv_monitor()
1984 bt_dev_dbg(hdev, "%s remove monitor %d msft status %d", in hci_remove_adv_monitor()
1985 hdev->name, monitor->handle, status); in hci_remove_adv_monitor()
1997 bt_dev_warn(hdev, "Removing monitor with no matching handle %d", in hci_remove_adv_monitor()
1999 hci_free_adv_monitor(hdev, monitor); in hci_remove_adv_monitor()
2005 int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle) in hci_remove_single_adv_monitor() argument
2007 struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle); in hci_remove_single_adv_monitor()
2012 return hci_remove_adv_monitor(hdev, monitor); in hci_remove_single_adv_monitor()
2016 int hci_remove_all_adv_monitor(struct hci_dev *hdev) in hci_remove_all_adv_monitor() argument
2023 monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id); in hci_remove_all_adv_monitor()
2027 status = hci_remove_adv_monitor(hdev, monitor); in hci_remove_all_adv_monitor()
2038 bool hci_is_adv_monitoring(struct hci_dev *hdev) in hci_is_adv_monitoring() argument
2040 return !idr_is_empty(&hdev->adv_monitors_idr); in hci_is_adv_monitoring()
2043 int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev) in hci_get_adv_monitor_offload_ext() argument
2045 if (msft_monitor_supported(hdev)) in hci_get_adv_monitor_offload_ext()
2237 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev, in hci_conn_params_lookup() argument
2242 list_for_each_entry(params, &hdev->le_conn_params, list) { in hci_conn_params_lookup()
2268 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev, in hci_conn_params_add() argument
2273 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_add()
2279 bt_dev_err(hdev, "out of memory"); in hci_conn_params_add()
2286 list_add(&params->list, &hdev->le_conn_params); in hci_conn_params_add()
2289 params->conn_min_interval = hdev->le_conn_min_interval; in hci_conn_params_add()
2290 params->conn_max_interval = hdev->le_conn_max_interval; in hci_conn_params_add()
2291 params->conn_latency = hdev->le_conn_latency; in hci_conn_params_add()
2292 params->supervision_timeout = hdev->le_supv_timeout; in hci_conn_params_add()
2313 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type) in hci_conn_params_del() argument
2317 params = hci_conn_params_lookup(hdev, addr, addr_type); in hci_conn_params_del()
2323 hci_update_passive_scan(hdev); in hci_conn_params_del()
2329 void hci_conn_params_clear_disabled(struct hci_dev *hdev) in hci_conn_params_clear_disabled() argument
2333 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) { in hci_conn_params_clear_disabled()
2353 static void hci_conn_params_clear_all(struct hci_dev *hdev) in hci_conn_params_clear_all() argument
2357 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) in hci_conn_params_clear_all()
2376 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr, in hci_copy_identity_address() argument
2379 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_copy_identity_address()
2380 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_copy_identity_address()
2381 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_copy_identity_address()
2382 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_copy_identity_address()
2383 bacpy(bdaddr, &hdev->static_addr); in hci_copy_identity_address()
2386 bacpy(bdaddr, &hdev->bdaddr); in hci_copy_identity_address()
2391 static void hci_clear_wake_reason(struct hci_dev *hdev) in hci_clear_wake_reason() argument
2393 hci_dev_lock(hdev); in hci_clear_wake_reason()
2395 hdev->wake_reason = 0; in hci_clear_wake_reason()
2396 bacpy(&hdev->wake_addr, BDADDR_ANY); in hci_clear_wake_reason()
2397 hdev->wake_addr_type = 0; in hci_clear_wake_reason()
2399 hci_dev_unlock(hdev); in hci_clear_wake_reason()
2405 struct hci_dev *hdev = in hci_suspend_notifier() local
2410 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) in hci_suspend_notifier()
2414 ret = hci_suspend_dev(hdev); in hci_suspend_notifier()
2416 ret = hci_resume_dev(hdev); in hci_suspend_notifier()
2419 bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d", in hci_suspend_notifier()
2428 struct hci_dev *hdev; in hci_alloc_dev_priv() local
2431 alloc_size = sizeof(*hdev); in hci_alloc_dev_priv()
2437 hdev = kzalloc(alloc_size, GFP_KERNEL); in hci_alloc_dev_priv()
2438 if (!hdev) in hci_alloc_dev_priv()
2441 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1); in hci_alloc_dev_priv()
2442 hdev->esco_type = (ESCO_HV1); in hci_alloc_dev_priv()
2443 hdev->link_mode = (HCI_LM_ACCEPT); in hci_alloc_dev_priv()
2444 hdev->num_iac = 0x01; /* One IAC support is mandatory */ in hci_alloc_dev_priv()
2445 hdev->io_capability = 0x03; /* No Input No Output */ in hci_alloc_dev_priv()
2446 hdev->manufacturer = 0xffff; /* Default to internal use */ in hci_alloc_dev_priv()
2447 hdev->inq_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2448 hdev->adv_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2449 hdev->adv_instance_cnt = 0; in hci_alloc_dev_priv()
2450 hdev->cur_adv_instance = 0x00; in hci_alloc_dev_priv()
2451 hdev->adv_instance_timeout = 0; in hci_alloc_dev_priv()
2453 hdev->advmon_allowlist_duration = 300; in hci_alloc_dev_priv()
2454 hdev->advmon_no_filter_duration = 500; in hci_alloc_dev_priv()
2455 hdev->enable_advmon_interleave_scan = 0x00; /* Default to disable */ in hci_alloc_dev_priv()
2457 hdev->sniff_max_interval = 800; in hci_alloc_dev_priv()
2458 hdev->sniff_min_interval = 80; in hci_alloc_dev_priv()
2460 hdev->le_adv_channel_map = 0x07; in hci_alloc_dev_priv()
2461 hdev->le_adv_min_interval = 0x0800; in hci_alloc_dev_priv()
2462 hdev->le_adv_max_interval = 0x0800; in hci_alloc_dev_priv()
2463 hdev->le_scan_interval = 0x0060; in hci_alloc_dev_priv()
2464 hdev->le_scan_window = 0x0030; in hci_alloc_dev_priv()
2465 hdev->le_scan_int_suspend = 0x0400; in hci_alloc_dev_priv()
2466 hdev->le_scan_window_suspend = 0x0012; in hci_alloc_dev_priv()
2467 hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT; in hci_alloc_dev_priv()
2468 hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN; in hci_alloc_dev_priv()
2469 hdev->le_scan_int_adv_monitor = 0x0060; in hci_alloc_dev_priv()
2470 hdev->le_scan_window_adv_monitor = 0x0030; in hci_alloc_dev_priv()
2471 hdev->le_scan_int_connect = 0x0060; in hci_alloc_dev_priv()
2472 hdev->le_scan_window_connect = 0x0060; in hci_alloc_dev_priv()
2473 hdev->le_conn_min_interval = 0x0018; in hci_alloc_dev_priv()
2474 hdev->le_conn_max_interval = 0x0028; in hci_alloc_dev_priv()
2475 hdev->le_conn_latency = 0x0000; in hci_alloc_dev_priv()
2476 hdev->le_supv_timeout = 0x002a; in hci_alloc_dev_priv()
2477 hdev->le_def_tx_len = 0x001b; in hci_alloc_dev_priv()
2478 hdev->le_def_tx_time = 0x0148; in hci_alloc_dev_priv()
2479 hdev->le_max_tx_len = 0x001b; in hci_alloc_dev_priv()
2480 hdev->le_max_tx_time = 0x0148; in hci_alloc_dev_priv()
2481 hdev->le_max_rx_len = 0x001b; in hci_alloc_dev_priv()
2482 hdev->le_max_rx_time = 0x0148; in hci_alloc_dev_priv()
2483 hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2484 hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2485 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2486 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_alloc_dev_priv()
2487 hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES; in hci_alloc_dev_priv()
2488 hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION; in hci_alloc_dev_priv()
2489 hdev->def_le_autoconnect_timeout = HCI_LE_AUTOCONN_TIMEOUT; in hci_alloc_dev_priv()
2490 hdev->min_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2491 hdev->max_le_tx_power = HCI_TX_POWER_INVALID; in hci_alloc_dev_priv()
2493 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT; in hci_alloc_dev_priv()
2494 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT; in hci_alloc_dev_priv()
2495 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE; in hci_alloc_dev_priv()
2496 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE; in hci_alloc_dev_priv()
2497 hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT; in hci_alloc_dev_priv()
2498 hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE; in hci_alloc_dev_priv()
2501 hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD; in hci_alloc_dev_priv()
2502 hdev->def_page_scan_int = 0x0800; in hci_alloc_dev_priv()
2503 hdev->def_page_scan_window = 0x0012; in hci_alloc_dev_priv()
2505 mutex_init(&hdev->lock); in hci_alloc_dev_priv()
2506 mutex_init(&hdev->req_lock); in hci_alloc_dev_priv()
2508 INIT_LIST_HEAD(&hdev->mesh_pending); in hci_alloc_dev_priv()
2509 INIT_LIST_HEAD(&hdev->mgmt_pending); in hci_alloc_dev_priv()
2510 INIT_LIST_HEAD(&hdev->reject_list); in hci_alloc_dev_priv()
2511 INIT_LIST_HEAD(&hdev->accept_list); in hci_alloc_dev_priv()
2512 INIT_LIST_HEAD(&hdev->uuids); in hci_alloc_dev_priv()
2513 INIT_LIST_HEAD(&hdev->link_keys); in hci_alloc_dev_priv()
2514 INIT_LIST_HEAD(&hdev->long_term_keys); in hci_alloc_dev_priv()
2515 INIT_LIST_HEAD(&hdev->identity_resolving_keys); in hci_alloc_dev_priv()
2516 INIT_LIST_HEAD(&hdev->remote_oob_data); in hci_alloc_dev_priv()
2517 INIT_LIST_HEAD(&hdev->le_accept_list); in hci_alloc_dev_priv()
2518 INIT_LIST_HEAD(&hdev->le_resolv_list); in hci_alloc_dev_priv()
2519 INIT_LIST_HEAD(&hdev->le_conn_params); in hci_alloc_dev_priv()
2520 INIT_LIST_HEAD(&hdev->pend_le_conns); in hci_alloc_dev_priv()
2521 INIT_LIST_HEAD(&hdev->pend_le_reports); in hci_alloc_dev_priv()
2522 INIT_LIST_HEAD(&hdev->conn_hash.list); in hci_alloc_dev_priv()
2523 INIT_LIST_HEAD(&hdev->adv_instances); in hci_alloc_dev_priv()
2524 INIT_LIST_HEAD(&hdev->blocked_keys); in hci_alloc_dev_priv()
2525 INIT_LIST_HEAD(&hdev->monitored_devices); in hci_alloc_dev_priv()
2527 INIT_LIST_HEAD(&hdev->local_codecs); in hci_alloc_dev_priv()
2528 INIT_WORK(&hdev->rx_work, hci_rx_work); in hci_alloc_dev_priv()
2529 INIT_WORK(&hdev->cmd_work, hci_cmd_work); in hci_alloc_dev_priv()
2530 INIT_WORK(&hdev->tx_work, hci_tx_work); in hci_alloc_dev_priv()
2531 INIT_WORK(&hdev->power_on, hci_power_on); in hci_alloc_dev_priv()
2532 INIT_WORK(&hdev->error_reset, hci_error_reset); in hci_alloc_dev_priv()
2534 hci_cmd_sync_init(hdev); in hci_alloc_dev_priv()
2536 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off); in hci_alloc_dev_priv()
2538 skb_queue_head_init(&hdev->rx_q); in hci_alloc_dev_priv()
2539 skb_queue_head_init(&hdev->cmd_q); in hci_alloc_dev_priv()
2540 skb_queue_head_init(&hdev->raw_q); in hci_alloc_dev_priv()
2542 init_waitqueue_head(&hdev->req_wait_q); in hci_alloc_dev_priv()
2544 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout); in hci_alloc_dev_priv()
2545 INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout); in hci_alloc_dev_priv()
2547 hci_request_setup(hdev); in hci_alloc_dev_priv()
2549 hci_init_sysfs(hdev); in hci_alloc_dev_priv()
2550 discovery_init(hdev); in hci_alloc_dev_priv()
2552 return hdev; in hci_alloc_dev_priv()
2557 void hci_free_dev(struct hci_dev *hdev) in hci_free_dev() argument
2560 put_device(&hdev->dev); in hci_free_dev()
2565 int hci_register_dev(struct hci_dev *hdev) in hci_register_dev() argument
2569 if (!hdev->open || !hdev->close || !hdev->send) in hci_register_dev()
2575 switch (hdev->dev_type) { in hci_register_dev()
2589 snprintf(hdev->name, sizeof(hdev->name), "hci%d", id); in hci_register_dev()
2590 hdev->id = id; in hci_register_dev()
2592 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_register_dev()
2594 hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name); in hci_register_dev()
2595 if (!hdev->workqueue) { in hci_register_dev()
2600 hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, in hci_register_dev()
2601 hdev->name); in hci_register_dev()
2602 if (!hdev->req_workqueue) { in hci_register_dev()
2603 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2609 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs); in hci_register_dev()
2611 dev_set_name(&hdev->dev, "%s", hdev->name); in hci_register_dev()
2613 error = device_add(&hdev->dev); in hci_register_dev()
2617 hci_leds_init(hdev); in hci_register_dev()
2619 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev, in hci_register_dev()
2621 hdev); in hci_register_dev()
2622 if (hdev->rfkill) { in hci_register_dev()
2623 if (rfkill_register(hdev->rfkill) < 0) { in hci_register_dev()
2624 rfkill_destroy(hdev->rfkill); in hci_register_dev()
2625 hdev->rfkill = NULL; in hci_register_dev()
2629 if (hdev->rfkill && rfkill_blocked(hdev->rfkill)) in hci_register_dev()
2630 hci_dev_set_flag(hdev, HCI_RFKILLED); in hci_register_dev()
2632 hci_dev_set_flag(hdev, HCI_SETUP); in hci_register_dev()
2633 hci_dev_set_flag(hdev, HCI_AUTO_OFF); in hci_register_dev()
2635 if (hdev->dev_type == HCI_PRIMARY) { in hci_register_dev()
2639 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED); in hci_register_dev()
2643 list_add(&hdev->list, &hci_dev_list); in hci_register_dev()
2649 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_register_dev()
2650 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_register_dev()
2655 if (hdev->wakeup) in hci_register_dev()
2656 hdev->conn_flags |= HCI_CONN_FLAG_REMOTE_WAKEUP; in hci_register_dev()
2658 hci_sock_dev_event(hdev, HCI_DEV_REG); in hci_register_dev()
2659 hci_dev_hold(hdev); in hci_register_dev()
2661 error = hci_register_suspend_notifier(hdev); in hci_register_dev()
2665 queue_work(hdev->req_workqueue, &hdev->power_on); in hci_register_dev()
2667 idr_init(&hdev->adv_monitors_idr); in hci_register_dev()
2668 msft_register(hdev); in hci_register_dev()
2673 debugfs_remove_recursive(hdev->debugfs); in hci_register_dev()
2674 destroy_workqueue(hdev->workqueue); in hci_register_dev()
2675 destroy_workqueue(hdev->req_workqueue); in hci_register_dev()
2677 ida_simple_remove(&hci_index_ida, hdev->id); in hci_register_dev()
2684 void hci_unregister_dev(struct hci_dev *hdev) in hci_unregister_dev() argument
2686 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus); in hci_unregister_dev()
2688 hci_dev_set_flag(hdev, HCI_UNREGISTER); in hci_unregister_dev()
2691 list_del(&hdev->list); in hci_unregister_dev()
2694 cancel_work_sync(&hdev->power_on); in hci_unregister_dev()
2696 hci_cmd_sync_clear(hdev); in hci_unregister_dev()
2698 hci_unregister_suspend_notifier(hdev); in hci_unregister_dev()
2700 msft_unregister(hdev); in hci_unregister_dev()
2702 hci_dev_do_close(hdev); in hci_unregister_dev()
2704 if (!test_bit(HCI_INIT, &hdev->flags) && in hci_unregister_dev()
2705 !hci_dev_test_flag(hdev, HCI_SETUP) && in hci_unregister_dev()
2706 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_unregister_dev()
2707 hci_dev_lock(hdev); in hci_unregister_dev()
2708 mgmt_index_removed(hdev); in hci_unregister_dev()
2709 hci_dev_unlock(hdev); in hci_unregister_dev()
2714 BUG_ON(!list_empty(&hdev->mgmt_pending)); in hci_unregister_dev()
2716 hci_sock_dev_event(hdev, HCI_DEV_UNREG); in hci_unregister_dev()
2718 if (hdev->rfkill) { in hci_unregister_dev()
2719 rfkill_unregister(hdev->rfkill); in hci_unregister_dev()
2720 rfkill_destroy(hdev->rfkill); in hci_unregister_dev()
2723 device_del(&hdev->dev); in hci_unregister_dev()
2725 hci_dev_put(hdev); in hci_unregister_dev()
2730 void hci_release_dev(struct hci_dev *hdev) in hci_release_dev() argument
2732 debugfs_remove_recursive(hdev->debugfs); in hci_release_dev()
2733 kfree_const(hdev->hw_info); in hci_release_dev()
2734 kfree_const(hdev->fw_info); in hci_release_dev()
2736 destroy_workqueue(hdev->workqueue); in hci_release_dev()
2737 destroy_workqueue(hdev->req_workqueue); in hci_release_dev()
2739 hci_dev_lock(hdev); in hci_release_dev()
2740 hci_bdaddr_list_clear(&hdev->reject_list); in hci_release_dev()
2741 hci_bdaddr_list_clear(&hdev->accept_list); in hci_release_dev()
2742 hci_uuids_clear(hdev); in hci_release_dev()
2743 hci_link_keys_clear(hdev); in hci_release_dev()
2744 hci_smp_ltks_clear(hdev); in hci_release_dev()
2745 hci_smp_irks_clear(hdev); in hci_release_dev()
2746 hci_remote_oob_data_clear(hdev); in hci_release_dev()
2747 hci_adv_instances_clear(hdev); in hci_release_dev()
2748 hci_adv_monitors_clear(hdev); in hci_release_dev()
2749 hci_bdaddr_list_clear(&hdev->le_accept_list); in hci_release_dev()
2750 hci_bdaddr_list_clear(&hdev->le_resolv_list); in hci_release_dev()
2751 hci_conn_params_clear_all(hdev); in hci_release_dev()
2752 hci_discovery_filter_clear(hdev); in hci_release_dev()
2753 hci_blocked_keys_clear(hdev); in hci_release_dev()
2754 hci_dev_unlock(hdev); in hci_release_dev()
2756 ida_simple_remove(&hci_index_ida, hdev->id); in hci_release_dev()
2757 kfree_skb(hdev->sent_cmd); 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()
2790 int hci_suspend_dev(struct hci_dev *hdev) in hci_suspend_dev() argument
2794 bt_dev_dbg(hdev, ""); in hci_suspend_dev()
2797 if (!hdev_is_powered(hdev) || in hci_suspend_dev()
2798 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_suspend_dev()
2802 if (mgmt_powering_down(hdev)) in hci_suspend_dev()
2805 hci_req_sync_lock(hdev); in hci_suspend_dev()
2806 ret = hci_suspend_sync(hdev); in hci_suspend_dev()
2807 hci_req_sync_unlock(hdev); in hci_suspend_dev()
2809 hci_clear_wake_reason(hdev); in hci_suspend_dev()
2810 mgmt_suspending(hdev, hdev->suspend_state); in hci_suspend_dev()
2812 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND); in hci_suspend_dev()
2818 int hci_resume_dev(struct hci_dev *hdev) in hci_resume_dev() argument
2822 bt_dev_dbg(hdev, ""); in hci_resume_dev()
2825 if (!hdev_is_powered(hdev) || in hci_resume_dev()
2826 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_resume_dev()
2830 if (mgmt_powering_down(hdev)) in hci_resume_dev()
2833 hci_req_sync_lock(hdev); in hci_resume_dev()
2834 ret = hci_resume_sync(hdev); in hci_resume_dev()
2835 hci_req_sync_unlock(hdev); in hci_resume_dev()
2837 mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr, in hci_resume_dev()
2838 hdev->wake_addr_type); in hci_resume_dev()
2840 hci_sock_dev_event(hdev, HCI_DEV_RESUME); in hci_resume_dev()
2846 int hci_reset_dev(struct hci_dev *hdev) in hci_reset_dev() argument
2858 bt_dev_err(hdev, "Injecting HCI hardware error event"); in hci_reset_dev()
2861 return hci_recv_frame(hdev, skb); in hci_reset_dev()
2866 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_frame() argument
2868 if (!hdev || (!test_bit(HCI_UP, &hdev->flags) in hci_recv_frame()
2869 && !test_bit(HCI_INIT, &hdev->flags))) { in hci_recv_frame()
2888 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_frame()
2889 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_frame()
2896 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb) in hci_recv_diag() argument
2904 skb_queue_tail(&hdev->rx_q, skb); in hci_recv_diag()
2905 queue_work(hdev->workqueue, &hdev->rx_work); in hci_recv_diag()
2911 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_hw_info() argument
2916 kfree_const(hdev->hw_info); in hci_set_hw_info()
2917 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_hw_info()
2922 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...) in hci_set_fw_info() argument
2927 kfree_const(hdev->fw_info); in hci_set_fw_info()
2928 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs); in hci_set_fw_info()
2959 static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb) in hci_send_frame() argument
2963 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb), in hci_send_frame()
2970 hci_send_to_monitor(hdev, skb); in hci_send_frame()
2972 if (atomic_read(&hdev->promisc)) { in hci_send_frame()
2974 hci_send_to_sock(hdev, skb); in hci_send_frame()
2980 if (!test_bit(HCI_RUNNING, &hdev->flags)) { in hci_send_frame()
2985 err = hdev->send(hdev, skb); in hci_send_frame()
2987 bt_dev_err(hdev, "sending frame failed (%d)", err); in hci_send_frame()
2996 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen, in hci_send_cmd() argument
3001 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen); in hci_send_cmd()
3003 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_send_cmd()
3005 bt_dev_err(hdev, "no memory for command"); in hci_send_cmd()
3014 skb_queue_tail(&hdev->cmd_q, skb); in hci_send_cmd()
3015 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_send_cmd()
3020 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_send() argument
3034 bt_dev_err(hdev, "unresponded command not supported"); in __hci_cmd_send()
3038 skb = hci_prepare_cmd(hdev, opcode, plen, param); in __hci_cmd_send()
3040 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in __hci_cmd_send()
3045 hci_send_frame(hdev, skb); in __hci_cmd_send()
3052 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode) in hci_sent_cmd_data() argument
3056 if (!hdev->sent_cmd) in hci_sent_cmd_data()
3059 hdr = (void *) hdev->sent_cmd->data; in hci_sent_cmd_data()
3064 BT_DBG("%s opcode 0x%4.4x", hdev->name, opcode); in hci_sent_cmd_data()
3066 return hdev->sent_cmd->data + HCI_COMMAND_HDR_SIZE; in hci_sent_cmd_data()
3070 void *hci_recv_event_data(struct hci_dev *hdev, __u8 event) in hci_recv_event_data() argument
3075 if (!hdev->recv_event) in hci_recv_event_data()
3078 hdr = (void *)hdev->recv_event->data; in hci_recv_event_data()
3086 ev = (void *)hdev->recv_event->data + offset; in hci_recv_event_data()
3095 bt_dev_dbg(hdev, "event 0x%2.2x", event); in hci_recv_event_data()
3097 return hdev->recv_event->data + offset; in hci_recv_event_data()
3117 struct hci_dev *hdev = conn->hdev; in hci_queue_acl() local
3125 switch (hdev->dev_type) { in hci_queue_acl()
3133 bt_dev_err(hdev, "unknown dev_type %d", hdev->dev_type); in hci_queue_acl()
3140 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3145 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3166 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_acl()
3177 struct hci_dev *hdev = chan->conn->hdev; in hci_send_acl() local
3179 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags); in hci_send_acl()
3183 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_acl()
3189 struct hci_dev *hdev = conn->hdev; in hci_send_sco() local
3192 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_sco()
3204 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_sco()
3223 struct hci_dev *hdev = conn->hdev; in hci_queue_iso() local
3239 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3244 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3258 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len); in hci_queue_iso()
3267 struct hci_dev *hdev = conn->hdev; in hci_send_iso() local
3269 BT_DBG("%s len %d", hdev->name, skb->len); in hci_send_iso()
3273 queue_work(hdev->workqueue, &hdev->tx_work); in hci_send_iso()
3281 struct hci_dev *hdev; in hci_quote_sent() local
3289 hdev = conn->hdev; in hci_quote_sent()
3293 cnt = hdev->acl_cnt; in hci_quote_sent()
3296 cnt = hdev->block_cnt; in hci_quote_sent()
3300 cnt = hdev->sco_cnt; in hci_quote_sent()
3303 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3306 cnt = hdev->iso_mtu ? hdev->iso_cnt : in hci_quote_sent()
3307 hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt; in hci_quote_sent()
3311 bt_dev_err(hdev, "unknown link type %d", conn->type); in hci_quote_sent()
3318 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type, in hci_low_sent() argument
3321 struct hci_conn_hash *h = &hdev->conn_hash; in hci_low_sent()
3344 if (hci_conn_num(hdev, type) == num) in hci_low_sent()
3356 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type) in hci_link_tx_to() argument
3358 struct hci_conn_hash *h = &hdev->conn_hash; in hci_link_tx_to()
3361 bt_dev_err(hdev, "link tx timeout"); in hci_link_tx_to()
3368 bt_dev_err(hdev, "killing stalled connection %pMR", in hci_link_tx_to()
3377 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type, in hci_chan_sent() argument
3380 struct hci_conn_hash *h = &hdev->conn_hash; in hci_chan_sent()
3386 BT_DBG("%s", hdev->name); in hci_chan_sent()
3425 if (hci_conn_num(hdev, type) == conn_num) in hci_chan_sent()
3440 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type) in hci_prio_recalculate() argument
3442 struct hci_conn_hash *h = &hdev->conn_hash; in hci_prio_recalculate()
3446 BT_DBG("%s", hdev->name); in hci_prio_recalculate()
3482 if (hci_conn_num(hdev, type) == num) in hci_prio_recalculate()
3490 static inline int __get_blocks(struct hci_dev *hdev, struct sk_buff *skb) in __get_blocks() argument
3493 return DIV_ROUND_UP(skb->len - HCI_ACL_HDR_SIZE, hdev->block_len); in __get_blocks()
3496 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt, u8 type) in __check_timeout() argument
3500 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in __check_timeout()
3505 last_tx = hdev->le_last_tx; in __check_timeout()
3508 last_tx = hdev->acl_last_tx; in __check_timeout()
3516 hci_link_tx_to(hdev, type); in __check_timeout()
3520 static void hci_sched_sco(struct hci_dev *hdev) in hci_sched_sco() argument
3526 BT_DBG("%s", hdev->name); in hci_sched_sco()
3528 if (!hci_conn_num(hdev, SCO_LINK)) in hci_sched_sco()
3531 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, &quote))) { in hci_sched_sco()
3534 hci_send_frame(hdev, skb); in hci_sched_sco()
3543 static void hci_sched_esco(struct hci_dev *hdev) in hci_sched_esco() argument
3549 BT_DBG("%s", hdev->name); in hci_sched_esco()
3551 if (!hci_conn_num(hdev, ESCO_LINK)) in hci_sched_esco()
3554 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK, in hci_sched_esco()
3558 hci_send_frame(hdev, skb); in hci_sched_esco()
3567 static void hci_sched_acl_pkt(struct hci_dev *hdev) in hci_sched_acl_pkt() argument
3569 unsigned int cnt = hdev->acl_cnt; in hci_sched_acl_pkt()
3574 __check_timeout(hdev, cnt, ACL_LINK); in hci_sched_acl_pkt()
3576 while (hdev->acl_cnt && in hci_sched_acl_pkt()
3577 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) { in hci_sched_acl_pkt()
3592 hci_send_frame(hdev, skb); in hci_sched_acl_pkt()
3593 hdev->acl_last_tx = jiffies; in hci_sched_acl_pkt()
3595 hdev->acl_cnt--; in hci_sched_acl_pkt()
3600 hci_sched_sco(hdev); in hci_sched_acl_pkt()
3601 hci_sched_esco(hdev); in hci_sched_acl_pkt()
3605 if (cnt != hdev->acl_cnt) in hci_sched_acl_pkt()
3606 hci_prio_recalculate(hdev, ACL_LINK); in hci_sched_acl_pkt()
3609 static void hci_sched_acl_blk(struct hci_dev *hdev) in hci_sched_acl_blk() argument
3611 unsigned int cnt = hdev->block_cnt; in hci_sched_acl_blk()
3617 BT_DBG("%s", hdev->name); in hci_sched_acl_blk()
3619 if (hdev->dev_type == HCI_AMP) in hci_sched_acl_blk()
3624 __check_timeout(hdev, cnt, type); in hci_sched_acl_blk()
3626 while (hdev->block_cnt > 0 && in hci_sched_acl_blk()
3627 (chan = hci_chan_sent(hdev, type, &quote))) { in hci_sched_acl_blk()
3641 blocks = __get_blocks(hdev, skb); in hci_sched_acl_blk()
3642 if (blocks > hdev->block_cnt) in hci_sched_acl_blk()
3648 hci_send_frame(hdev, skb); in hci_sched_acl_blk()
3649 hdev->acl_last_tx = jiffies; in hci_sched_acl_blk()
3651 hdev->block_cnt -= blocks; in hci_sched_acl_blk()
3659 if (cnt != hdev->block_cnt) in hci_sched_acl_blk()
3660 hci_prio_recalculate(hdev, type); in hci_sched_acl_blk()
3663 static void hci_sched_acl(struct hci_dev *hdev) in hci_sched_acl() argument
3665 BT_DBG("%s", hdev->name); in hci_sched_acl()
3668 if (!hci_conn_num(hdev, ACL_LINK) && hdev->dev_type == HCI_PRIMARY) in hci_sched_acl()
3672 if (!hci_conn_num(hdev, AMP_LINK) && hdev->dev_type == HCI_AMP) in hci_sched_acl()
3675 switch (hdev->flow_ctl_mode) { in hci_sched_acl()
3677 hci_sched_acl_pkt(hdev); in hci_sched_acl()
3681 hci_sched_acl_blk(hdev); in hci_sched_acl()
3686 static void hci_sched_le(struct hci_dev *hdev) in hci_sched_le() argument
3692 BT_DBG("%s", hdev->name); in hci_sched_le()
3694 if (!hci_conn_num(hdev, LE_LINK)) in hci_sched_le()
3697 cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt; in hci_sched_le()
3699 __check_timeout(hdev, cnt, LE_LINK); in hci_sched_le()
3702 while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, &quote))) { in hci_sched_le()
3714 hci_send_frame(hdev, skb); in hci_sched_le()
3715 hdev->le_last_tx = jiffies; in hci_sched_le()
3722 hci_sched_sco(hdev); in hci_sched_le()
3723 hci_sched_esco(hdev); in hci_sched_le()
3727 if (hdev->le_pkts) in hci_sched_le()
3728 hdev->le_cnt = cnt; in hci_sched_le()
3730 hdev->acl_cnt = cnt; in hci_sched_le()
3733 hci_prio_recalculate(hdev, LE_LINK); in hci_sched_le()
3737 static void hci_sched_iso(struct hci_dev *hdev) in hci_sched_iso() argument
3743 BT_DBG("%s", hdev->name); in hci_sched_iso()
3745 if (!hci_conn_num(hdev, ISO_LINK)) in hci_sched_iso()
3748 cnt = hdev->iso_pkts ? &hdev->iso_cnt : in hci_sched_iso()
3749 hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt; in hci_sched_iso()
3750 while (*cnt && (conn = hci_low_sent(hdev, ISO_LINK, &quote))) { in hci_sched_iso()
3753 hci_send_frame(hdev, skb); in hci_sched_iso()
3765 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work); in hci_tx_work() local
3768 BT_DBG("%s acl %d sco %d le %d iso %d", hdev->name, hdev->acl_cnt, in hci_tx_work()
3769 hdev->sco_cnt, hdev->le_cnt, hdev->iso_cnt); in hci_tx_work()
3771 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_tx_work()
3773 hci_sched_sco(hdev); in hci_tx_work()
3774 hci_sched_esco(hdev); in hci_tx_work()
3775 hci_sched_iso(hdev); in hci_tx_work()
3776 hci_sched_acl(hdev); in hci_tx_work()
3777 hci_sched_le(hdev); in hci_tx_work()
3781 while ((skb = skb_dequeue(&hdev->raw_q))) in hci_tx_work()
3782 hci_send_frame(hdev, skb); in hci_tx_work()
3788 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_acldata_packet() argument
3800 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_acldata_packet()
3803 hdev->stat.acl_rx++; in hci_acldata_packet()
3805 hci_dev_lock(hdev); in hci_acldata_packet()
3806 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_acldata_packet()
3807 hci_dev_unlock(hdev); in hci_acldata_packet()
3816 bt_dev_err(hdev, "ACL packet for unknown connection handle %d", in hci_acldata_packet()
3824 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_scodata_packet() argument
3836 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len, in hci_scodata_packet()
3839 hdev->stat.sco_rx++; in hci_scodata_packet()
3841 hci_dev_lock(hdev); in hci_scodata_packet()
3842 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_scodata_packet()
3843 hci_dev_unlock(hdev); in hci_scodata_packet()
3851 bt_dev_err_ratelimited(hdev, "SCO packet for unknown connection handle %d", in hci_scodata_packet()
3858 static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb) in hci_isodata_packet() argument
3866 bt_dev_err(hdev, "ISO packet too small"); in hci_isodata_packet()
3874 bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len, in hci_isodata_packet()
3877 hci_dev_lock(hdev); in hci_isodata_packet()
3878 conn = hci_conn_hash_lookup_handle(hdev, handle); in hci_isodata_packet()
3879 hci_dev_unlock(hdev); in hci_isodata_packet()
3882 bt_dev_err(hdev, "ISO packet for unknown connection handle %d", in hci_isodata_packet()
3895 static bool hci_req_is_complete(struct hci_dev *hdev) in hci_req_is_complete() argument
3899 skb = skb_peek(&hdev->cmd_q); in hci_req_is_complete()
3906 static void hci_resend_last(struct hci_dev *hdev) in hci_resend_last() argument
3912 if (!hdev->sent_cmd) in hci_resend_last()
3915 sent = (void *) hdev->sent_cmd->data; in hci_resend_last()
3920 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL); in hci_resend_last()
3924 skb_queue_head(&hdev->cmd_q, skb); in hci_resend_last()
3925 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_resend_last()
3928 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status, in hci_req_cmd_complete() argument
3940 if (!hci_sent_cmd_data(hdev, opcode)) { in hci_req_cmd_complete()
3947 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET) in hci_req_cmd_complete()
3948 hci_resend_last(hdev); in hci_req_cmd_complete()
3954 hci_dev_clear_flag(hdev, HCI_CMD_PENDING); in hci_req_cmd_complete()
3959 if (!status && !hci_req_is_complete(hdev)) in hci_req_cmd_complete()
3966 if (bt_cb(hdev->sent_cmd)->hci.req_flags & HCI_REQ_SKB) { in hci_req_cmd_complete()
3967 *req_complete_skb = bt_cb(hdev->sent_cmd)->hci.req_complete_skb; in hci_req_cmd_complete()
3971 if (bt_cb(hdev->sent_cmd)->hci.req_complete) { in hci_req_cmd_complete()
3972 *req_complete = bt_cb(hdev->sent_cmd)->hci.req_complete; in hci_req_cmd_complete()
3977 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
3978 while ((skb = __skb_dequeue(&hdev->cmd_q))) { in hci_req_cmd_complete()
3980 __skb_queue_head(&hdev->cmd_q, skb); in hci_req_cmd_complete()
3990 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_cmd_complete()
3995 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work); in hci_rx_work() local
3998 BT_DBG("%s", hdev->name); in hci_rx_work()
4005 for (; (skb = skb_dequeue(&hdev->rx_q)); kcov_remote_stop()) { in hci_rx_work()
4009 hci_send_to_monitor(hdev, skb); in hci_rx_work()
4011 if (atomic_read(&hdev->promisc)) { in hci_rx_work()
4013 hci_send_to_sock(hdev, skb); in hci_rx_work()
4022 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_rx_work()
4023 !test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4028 if (test_bit(HCI_INIT, &hdev->flags)) { in hci_rx_work()
4042 BT_DBG("%s Event packet", hdev->name); in hci_rx_work()
4043 hci_event_packet(hdev, skb); in hci_rx_work()
4047 BT_DBG("%s ACL data packet", hdev->name); in hci_rx_work()
4048 hci_acldata_packet(hdev, skb); in hci_rx_work()
4052 BT_DBG("%s SCO data packet", hdev->name); in hci_rx_work()
4053 hci_scodata_packet(hdev, skb); in hci_rx_work()
4057 BT_DBG("%s ISO data packet", hdev->name); in hci_rx_work()
4058 hci_isodata_packet(hdev, skb); in hci_rx_work()
4070 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work); in hci_cmd_work() local
4073 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name, in hci_cmd_work()
4074 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q)); in hci_cmd_work()
4077 if (atomic_read(&hdev->cmd_cnt)) { in hci_cmd_work()
4078 skb = skb_dequeue(&hdev->cmd_q); in hci_cmd_work()
4082 kfree_skb(hdev->sent_cmd); in hci_cmd_work()
4084 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL); in hci_cmd_work()
4085 if (hdev->sent_cmd) { in hci_cmd_work()
4087 if (hci_req_status_pend(hdev)) in hci_cmd_work()
4088 hci_dev_set_flag(hdev, HCI_CMD_PENDING); in hci_cmd_work()
4089 atomic_dec(&hdev->cmd_cnt); in hci_cmd_work()
4091 res = hci_send_frame(hdev, skb); in hci_cmd_work()
4093 __hci_cmd_sync_cancel(hdev, -res); in hci_cmd_work()
4096 if (test_bit(HCI_RESET, &hdev->flags) || in hci_cmd_work()
4097 hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE)) in hci_cmd_work()
4098 cancel_delayed_work(&hdev->cmd_timer); in hci_cmd_work()
4100 queue_delayed_work(hdev->workqueue, &hdev->cmd_timer, in hci_cmd_work()
4104 skb_queue_head(&hdev->cmd_q, skb); in hci_cmd_work()
4105 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_work()