Lines Matching defs:hdev

70 	BT_DBG("%s %x", req->hdev->name, scan);
81 BT_DBG("%s %x", req->hdev->name, auth);
92 BT_DBG("%s %x", req->hdev->name, encrypt);
103 BT_DBG("%s %x", req->hdev->name, policy);
114 struct hci_dev *hdev = NULL, *d;
124 hdev = hci_dev_hold(d);
129 return hdev;
134 bool hci_discovery_active(struct hci_dev *hdev)
136 struct discovery_state *discov = &hdev->discovery;
148 void hci_discovery_set_state(struct hci_dev *hdev, int state)
150 int old_state = hdev->discovery.state;
155 hdev->discovery.state = state;
159 hci_update_passive_scan(hdev);
162 mgmt_discovering(hdev, 0);
171 hdev->discovery.state = old_state;
174 mgmt_discovering(hdev, 1);
182 bt_dev_dbg(hdev, "state %u -> %u", old_state, state);
185 void hci_inquiry_cache_flush(struct hci_dev *hdev)
187 struct discovery_state *cache = &hdev->discovery;
199 struct inquiry_entry *hci_inquiry_cache_lookup(struct hci_dev *hdev,
202 struct discovery_state *cache = &hdev->discovery;
215 struct inquiry_entry *hci_inquiry_cache_lookup_unknown(struct hci_dev *hdev,
218 struct discovery_state *cache = &hdev->discovery;
231 struct inquiry_entry *hci_inquiry_cache_lookup_resolve(struct hci_dev *hdev,
235 struct discovery_state *cache = &hdev->discovery;
250 void hci_inquiry_cache_update_resolve(struct hci_dev *hdev,
253 struct discovery_state *cache = &hdev->discovery;
269 u32 hci_inquiry_cache_update(struct hci_dev *hdev, struct inquiry_data *data,
272 struct discovery_state *cache = &hdev->discovery;
278 hci_remove_remote_oob_data(hdev, &data->bdaddr, BDADDR_BREDR);
283 ie = hci_inquiry_cache_lookup(hdev, &data->bdaddr);
291 hci_inquiry_cache_update_resolve(hdev, ie);
331 static int inquiry_cache_dump(struct hci_dev *hdev, int num, __u8 *buf)
333 struct discovery_state *cache = &hdev->discovery;
362 struct hci_dev *hdev = req->hdev;
365 BT_DBG("%s", hdev->name);
367 if (test_bit(HCI_INQUIRY, &hdev->flags))
383 struct hci_dev *hdev;
391 hdev = hci_dev_get(ir.dev_id);
392 if (!hdev)
395 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
400 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
405 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
416 hci_dev_lock(hdev);
417 if (inquiry_cache_age(hdev) > INQUIRY_CACHE_AGE_MAX ||
418 inquiry_cache_empty(hdev) || ir.flags & IREQ_CACHE_FLUSH) {
419 hci_inquiry_cache_flush(hdev);
422 hci_dev_unlock(hdev);
427 err = hci_req_sync(hdev, hci_inq_req, (unsigned long) &ir,
435 if (wait_on_bit(&hdev->flags, HCI_INQUIRY,
456 hci_dev_lock(hdev);
457 ir.num_rsp = inquiry_cache_dump(hdev, max_rsp, buf);
458 hci_dev_unlock(hdev);
473 hci_dev_put(hdev);
477 static int hci_dev_do_open(struct hci_dev *hdev)
481 BT_DBG("%s %p", hdev->name, hdev);
483 hci_req_sync_lock(hdev);
485 ret = hci_dev_open_sync(hdev);
487 hci_req_sync_unlock(hdev);
495 struct hci_dev *hdev;
498 hdev = hci_dev_get(dev);
499 if (!hdev)
511 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED) &&
512 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
522 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF))
523 cancel_delayed_work(&hdev->power_off);
529 flush_workqueue(hdev->req_workqueue);
537 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
538 !hci_dev_test_flag(hdev, HCI_MGMT))
539 hci_dev_set_flag(hdev, HCI_BONDABLE);
541 err = hci_dev_do_open(hdev);
544 hci_dev_put(hdev);
548 int hci_dev_do_close(struct hci_dev *hdev)
552 BT_DBG("%s %p", hdev->name, hdev);
554 hci_req_sync_lock(hdev);
556 err = hci_dev_close_sync(hdev);
558 hci_req_sync_unlock(hdev);
565 struct hci_dev *hdev;
568 hdev = hci_dev_get(dev);
569 if (!hdev)
572 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
577 cancel_work_sync(&hdev->power_on);
578 if (hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF))
579 cancel_delayed_work(&hdev->power_off);
581 err = hci_dev_do_close(hdev);
584 hci_dev_put(hdev);
588 static int hci_dev_do_reset(struct hci_dev *hdev)
592 BT_DBG("%s %p", hdev->name, hdev);
594 hci_req_sync_lock(hdev);
597 skb_queue_purge(&hdev->rx_q);
598 skb_queue_purge(&hdev->cmd_q);
601 hci_dev_set_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
604 * if (!hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
605 * queue_delayed_work(&hdev->{cmd,ncmd}_timer)
611 cancel_delayed_work(&hdev->cmd_timer);
612 cancel_delayed_work(&hdev->ncmd_timer);
617 drain_workqueue(hdev->workqueue);
619 hci_dev_lock(hdev);
620 hci_inquiry_cache_flush(hdev);
621 hci_conn_hash_flush(hdev);
622 hci_dev_unlock(hdev);
624 if (hdev->flush)
625 hdev->flush(hdev);
627 hci_dev_clear_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE);
629 atomic_set(&hdev->cmd_cnt, 1);
630 hdev->acl_cnt = 0;
631 hdev->sco_cnt = 0;
632 hdev->le_cnt = 0;
633 hdev->iso_cnt = 0;
635 ret = hci_reset_sync(hdev);
637 hci_req_sync_unlock(hdev);
643 struct hci_dev *hdev;
646 hdev = hci_dev_get(dev);
647 if (!hdev)
650 if (!test_bit(HCI_UP, &hdev->flags)) {
655 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
660 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
665 err = hci_dev_do_reset(hdev);
668 hci_dev_put(hdev);
674 struct hci_dev *hdev;
677 hdev = hci_dev_get(dev);
678 if (!hdev)
681 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
686 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
691 memset(&hdev->stat, 0, sizeof(struct hci_dev_stats));
694 hci_dev_put(hdev);
698 static void hci_update_passive_scan_state(struct hci_dev *hdev, u8 scan)
702 BT_DBG("%s scan 0x%02x", hdev->name, scan);
705 conn_changed = !hci_dev_test_and_set_flag(hdev,
708 conn_changed = hci_dev_test_and_clear_flag(hdev,
712 discov_changed = !hci_dev_test_and_set_flag(hdev,
715 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE);
716 discov_changed = hci_dev_test_and_clear_flag(hdev,
720 if (!hci_dev_test_flag(hdev, HCI_MGMT))
725 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED);
727 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED))
728 hci_update_adv_data(hdev, hdev->cur_adv_instance);
730 mgmt_new_settings(hdev);
736 struct hci_dev *hdev;
743 hdev = hci_dev_get(dr.dev_id);
744 if (!hdev)
747 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
752 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) {
757 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) {
764 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt,
769 if (!lmp_encrypt_capable(hdev)) {
774 if (!test_bit(HCI_AUTH, &hdev->flags)) {
776 err = hci_req_sync(hdev, hci_auth_req, dr.dev_opt,
782 err = hci_req_sync(hdev, hci_encrypt_req, dr.dev_opt,
787 err = hci_req_sync(hdev, hci_scan_req, dr.dev_opt,
794 hci_update_passive_scan_state(hdev, dr.dev_opt);
798 err = hci_req_sync(hdev, hci_linkpol_req, dr.dev_opt,
803 hdev->link_mode = ((__u16) dr.dev_opt) &
808 if (hdev->pkt_type == (__u16) dr.dev_opt)
811 hdev->pkt_type = (__u16) dr.dev_opt;
812 mgmt_phy_configuration_changed(hdev, NULL);
816 hdev->acl_mtu = *((__u16 *) &dr.dev_opt + 1);
817 hdev->acl_pkts = *((__u16 *) &dr.dev_opt + 0);
821 hdev->sco_mtu = *((__u16 *) &dr.dev_opt + 1);
822 hdev->sco_pkts = *((__u16 *) &dr.dev_opt + 0);
831 hci_dev_put(hdev);
837 struct hci_dev *hdev;
858 list_for_each_entry(hdev, &hci_dev_list, list) {
859 unsigned long flags = hdev->flags;
865 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF))
868 (dr + n)->dev_id = hdev->id;
887 struct hci_dev *hdev;
895 hdev = hci_dev_get(di.dev_id);
896 if (!hdev)
903 if (hci_dev_test_flag(hdev, HCI_AUTO_OFF))
904 flags = hdev->flags & ~BIT(HCI_UP);
906 flags = hdev->flags;
908 strscpy(di.name, hdev->name, sizeof(di.name));
909 di.bdaddr = hdev->bdaddr;
910 di.type = (hdev->bus & 0x0f);
912 di.pkt_type = hdev->pkt_type;
913 if (lmp_bredr_capable(hdev)) {
914 di.acl_mtu = hdev->acl_mtu;
915 di.acl_pkts = hdev->acl_pkts;
916 di.sco_mtu = hdev->sco_mtu;
917 di.sco_pkts = hdev->sco_pkts;
919 di.acl_mtu = hdev->le_mtu;
920 di.acl_pkts = hdev->le_pkts;
924 di.link_policy = hdev->link_policy;
925 di.link_mode = hdev->link_mode;
927 memcpy(&di.stat, &hdev->stat, sizeof(di.stat));
928 memcpy(&di.features, &hdev->features, sizeof(di.features));
933 hci_dev_put(hdev);
940 static int hci_dev_do_poweroff(struct hci_dev *hdev)
944 BT_DBG("%s %p", hdev->name, hdev);
946 hci_req_sync_lock(hdev);
948 err = hci_set_powered_sync(hdev, false);
950 hci_req_sync_unlock(hdev);
957 struct hci_dev *hdev = data;
960 BT_DBG("%p name %s blocked %d", hdev, hdev->name, blocked);
962 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL))
965 if (blocked == hci_dev_test_flag(hdev, HCI_RFKILLED))
969 hci_dev_set_flag(hdev, HCI_RFKILLED);
971 if (!hci_dev_test_flag(hdev, HCI_SETUP) &&
972 !hci_dev_test_flag(hdev, HCI_CONFIG)) {
973 err = hci_dev_do_poweroff(hdev);
975 bt_dev_err(hdev, "Error when powering off device on rfkill (%d)",
982 hci_dev_do_close(hdev);
986 hci_dev_clear_flag(hdev, HCI_RFKILLED);
998 struct hci_dev *hdev = container_of(work, struct hci_dev, power_on);
1001 BT_DBG("%s", hdev->name);
1003 if (test_bit(HCI_UP, &hdev->flags) &&
1004 hci_dev_test_flag(hdev, HCI_MGMT) &&
1005 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) {
1006 cancel_delayed_work(&hdev->power_off);
1007 err = hci_powered_update_sync(hdev);
1008 mgmt_power_on(hdev, err);
1012 err = hci_dev_do_open(hdev);
1014 hci_dev_lock(hdev);
1015 mgmt_set_powered_failed(hdev, err);
1016 hci_dev_unlock(hdev);
1024 if (hci_dev_test_flag(hdev, HCI_RFKILLED) ||
1025 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) ||
1026 (!bacmp(&hdev->bdaddr, BDADDR_ANY) &&
1027 !bacmp(&hdev->static_addr, BDADDR_ANY))) {
1028 hci_dev_clear_flag(hdev, HCI_AUTO_OFF);
1029 hci_dev_do_close(hdev);
1030 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) {
1031 queue_delayed_work(hdev->req_workqueue, &hdev->power_off,
1035 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) {
1039 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
1040 set_bit(HCI_RAW, &hdev->flags);
1049 mgmt_index_added(hdev);
1050 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) {
1054 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
1055 clear_bit(HCI_RAW, &hdev->flags);
1061 mgmt_index_added(hdev);
1067 struct hci_dev *hdev = container_of(work, struct hci_dev,
1070 BT_DBG("%s", hdev->name);
1072 hci_dev_do_close(hdev);
1077 struct hci_dev *hdev = container_of(work, struct hci_dev, error_reset);
1079 hci_dev_hold(hdev);
1080 BT_DBG("%s", hdev->name);
1082 if (hdev->hw_error)
1083 hdev->hw_error(hdev, hdev->hw_error_code);
1085 bt_dev_err(hdev, "hardware error 0x%2.2x", hdev->hw_error_code);
1087 if (!hci_dev_do_close(hdev))
1088 hci_dev_do_open(hdev);
1090 hci_dev_put(hdev);
1093 void hci_uuids_clear(struct hci_dev *hdev)
1097 list_for_each_entry_safe(uuid, tmp, &hdev->uuids, list) {
1103 void hci_link_keys_clear(struct hci_dev *hdev)
1107 list_for_each_entry_safe(key, tmp, &hdev->link_keys, list) {
1113 void hci_smp_ltks_clear(struct hci_dev *hdev)
1117 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) {
1123 void hci_smp_irks_clear(struct hci_dev *hdev)
1127 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) {
1133 void hci_blocked_keys_clear(struct hci_dev *hdev)
1137 list_for_each_entry_safe(b, tmp, &hdev->blocked_keys, list) {
1143 bool hci_is_blocked_key(struct hci_dev *hdev, u8 type, u8 val[16])
1149 list_for_each_entry_rcu(b, &hdev->blocked_keys, list) {
1160 struct link_key *hci_find_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
1165 list_for_each_entry_rcu(k, &hdev->link_keys, list) {
1169 if (hci_is_blocked_key(hdev,
1172 bt_dev_warn_ratelimited(hdev,
1186 static bool hci_persistent_key(struct hci_dev *hdev, struct hci_conn *conn,
1234 struct smp_ltk *hci_find_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1240 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
1247 if (hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_LTK,
1249 bt_dev_warn_ratelimited(hdev,
1263 struct smp_irk *hci_find_irk_by_rpa(struct hci_dev *hdev, bdaddr_t *rpa)
1269 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
1276 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
1277 if (smp_irk_matches(hdev, irk->val, rpa)) {
1285 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK,
1287 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR",
1297 struct smp_irk *hci_find_irk_by_addr(struct hci_dev *hdev, bdaddr_t *bdaddr,
1308 list_for_each_entry_rcu(irk, &hdev->identity_resolving_keys, list) {
1318 if (irk_to_return && hci_is_blocked_key(hdev, HCI_BLOCKED_KEY_TYPE_IRK,
1320 bt_dev_warn_ratelimited(hdev, "Identity key blocked for %pMR",
1330 struct link_key *hci_add_link_key(struct hci_dev *hdev, struct hci_conn *conn,
1337 old_key = hci_find_link_key(hdev, bdaddr);
1346 list_add_rcu(&key->list, &hdev->link_keys);
1349 BT_DBG("%s key for %pMR type %u", hdev->name, bdaddr, type);
1371 *persistent = hci_persistent_key(hdev, conn, type,
1377 struct smp_ltk *hci_add_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1384 old_key = hci_find_ltk(hdev, bdaddr, addr_type, role);
1391 list_add_rcu(&key->list, &hdev->long_term_keys);
1406 struct smp_irk *hci_add_irk(struct hci_dev *hdev, bdaddr_t *bdaddr,
1411 irk = hci_find_irk_by_addr(hdev, bdaddr, addr_type);
1420 list_add_rcu(&irk->list, &hdev->identity_resolving_keys);
1429 int hci_remove_link_key(struct hci_dev *hdev, bdaddr_t *bdaddr)
1433 key = hci_find_link_key(hdev, bdaddr);
1437 BT_DBG("%s removing %pMR", hdev->name, bdaddr);
1445 int hci_remove_ltk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 bdaddr_type)
1450 list_for_each_entry_safe(k, tmp, &hdev->long_term_keys, list) {
1454 BT_DBG("%s removing %pMR", hdev->name, bdaddr);
1464 void hci_remove_irk(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 addr_type)
1468 list_for_each_entry_safe(k, tmp, &hdev->identity_resolving_keys, list) {
1472 BT_DBG("%s removing %pMR", hdev->name, bdaddr);
1479 bool hci_bdaddr_is_paired(struct hci_dev *hdev, bdaddr_t *bdaddr, u8 type)
1486 if (hci_find_link_key(hdev, bdaddr))
1497 irk = hci_get_irk(hdev, bdaddr, addr_type);
1504 list_for_each_entry_rcu(k, &hdev->long_term_keys, list) {
1518 struct hci_dev *hdev = container_of(work, struct hci_dev,
1521 if (hdev->req_skb) {
1522 u16 opcode = hci_skb_opcode(hdev->req_skb);
1524 bt_dev_err(hdev, "command 0x%4.4x tx timeout", opcode);
1526 hci_cmd_sync_cancel_sync(hdev, ETIMEDOUT);
1528 bt_dev_err(hdev, "command tx timeout");
1531 if (hdev->cmd_timeout)
1532 hdev->cmd_timeout(hdev);
1534 atomic_set(&hdev->cmd_cnt, 1);
1535 queue_work(hdev->workqueue, &hdev->cmd_work);
1541 struct hci_dev *hdev = container_of(work, struct hci_dev,
1544 bt_dev_err(hdev, "Controller not accepting commands anymore: ncmd = 0");
1549 if (test_bit(HCI_INIT, &hdev->flags))
1553 hci_reset_dev(hdev);
1556 struct oob_data *hci_find_remote_oob_data(struct hci_dev *hdev,
1561 list_for_each_entry(data, &hdev->remote_oob_data, list) {
1572 int hci_remove_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
1577 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type);
1581 BT_DBG("%s removing %pMR (%u)", hdev->name, bdaddr, bdaddr_type);
1589 void hci_remote_oob_data_clear(struct hci_dev *hdev)
1593 list_for_each_entry_safe(data, n, &hdev->remote_oob_data, list) {
1599 int hci_add_remote_oob_data(struct hci_dev *hdev, bdaddr_t *bdaddr,
1605 data = hci_find_remote_oob_data(hdev, bdaddr, bdaddr_type);
1613 list_add(&data->list, &hdev->remote_oob_data);
1640 BT_DBG("%s for %pMR", hdev->name, bdaddr);
1645 /* This function requires the caller holds hdev->lock */
1646 struct adv_info *hci_find_adv_instance(struct hci_dev *hdev, u8 instance)
1650 list_for_each_entry(adv_instance, &hdev->adv_instances, list) {
1658 /* This function requires the caller holds hdev->lock */
1659 struct adv_info *hci_get_next_instance(struct hci_dev *hdev, u8 instance)
1663 cur_instance = hci_find_adv_instance(hdev, instance);
1667 if (cur_instance == list_last_entry(&hdev->adv_instances,
1669 return list_first_entry(&hdev->adv_instances,
1675 /* This function requires the caller holds hdev->lock */
1676 int hci_remove_adv_instance(struct hci_dev *hdev, u8 instance)
1680 adv_instance = hci_find_adv_instance(hdev, instance);
1684 BT_DBG("%s removing %dMR", hdev->name, instance);
1686 if (hdev->cur_adv_instance == instance) {
1687 if (hdev->adv_instance_timeout) {
1688 cancel_delayed_work(&hdev->adv_instance_expire);
1689 hdev->adv_instance_timeout = 0;
1691 hdev->cur_adv_instance = 0x00;
1699 hdev->adv_instance_cnt--;
1704 void hci_adv_instances_set_rpa_expired(struct hci_dev *hdev, bool rpa_expired)
1708 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list)
1712 /* This function requires the caller holds hdev->lock */
1713 void hci_adv_instances_clear(struct hci_dev *hdev)
1717 if (hdev->adv_instance_timeout) {
1718 cancel_delayed_work(&hdev->adv_instance_expire);
1719 hdev->adv_instance_timeout = 0;
1722 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, list) {
1728 hdev->adv_instance_cnt = 0;
1729 hdev->cur_adv_instance = 0x00;
1742 /* This function requires the caller holds hdev->lock */
1743 struct adv_info *hci_add_adv_instance(struct hci_dev *hdev, u8 instance,
1752 adv = hci_find_adv_instance(hdev, instance);
1758 if (hdev->adv_instance_cnt >= hdev->le_num_of_adv_sets ||
1759 instance < 1 || instance > hdev->le_num_of_adv_sets + 1)
1772 if (hdev->le_num_of_adv_sets == 1 && instance == 1)
1777 list_add(&adv->list, &hdev->adv_instances);
1778 hdev->adv_instance_cnt++;
1791 hci_set_adv_instance_data(hdev, instance, adv_data_len, adv_data,
1798 adv->duration = hdev->def_multi_adv_rotation_duration;
1804 BT_DBG("%s for %dMR", hdev->name, instance);
1809 /* This function requires the caller holds hdev->lock */
1810 struct adv_info *hci_add_per_instance(struct hci_dev *hdev, u8 instance,
1816 adv = hci_add_adv_instance(hdev, instance, flags, 0, NULL, 0, NULL,
1831 /* This function requires the caller holds hdev->lock */
1832 int hci_set_adv_instance_data(struct hci_dev *hdev, u8 instance,
1838 adv = hci_find_adv_instance(hdev, instance);
1859 if (((adv->flags & MGMT_ADV_FLAG_APPEARANCE) && hdev->appearance) ||
1866 /* This function requires the caller holds hdev->lock */
1867 u32 hci_adv_instance_flags(struct hci_dev *hdev, u8 instance)
1881 if (hci_dev_test_flag(hdev, HCI_ADVERTISING_CONNECTABLE))
1884 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE))
1886 else if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE))
1892 adv = hci_find_adv_instance(hdev, instance);
1901 bool hci_adv_instance_is_scannable(struct hci_dev *hdev, u8 instance)
1909 adv = hci_find_adv_instance(hdev, instance);
1920 /* This function requires the caller holds hdev->lock */
1921 void hci_adv_monitors_clear(struct hci_dev *hdev)
1926 idr_for_each_entry(&hdev->adv_monitors_idr, monitor, handle)
1927 hci_free_adv_monitor(hdev, monitor);
1929 idr_destroy(&hdev->adv_monitors_idr);
1933 * This function requires the caller holds hdev->lock.
1935 void hci_free_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
1949 idr_remove(&hdev->adv_monitors_idr, monitor->handle);
1952 hdev->adv_monitors_cnt--;
1953 mgmt_adv_monitor_removed(hdev, monitor->handle);
1963 int hci_add_adv_monitor(struct hci_dev *hdev, struct adv_monitor *monitor)
1971 hci_dev_lock(hdev);
1975 handle = idr_alloc(&hdev->adv_monitors_idr, monitor, min, max,
1978 hci_dev_unlock(hdev);
1985 if (!hdev_is_powered(hdev))
1988 switch (hci_get_adv_monitor_offload_ext(hdev)) {
1990 bt_dev_dbg(hdev, "add monitor %d status %d",
1996 status = msft_add_monitor_pattern(hdev, monitor);
1997 bt_dev_dbg(hdev, "add monitor %d msft status %d",
2009 static int hci_remove_adv_monitor(struct hci_dev *hdev,
2015 switch (hci_get_adv_monitor_offload_ext(hdev)) {
2017 bt_dev_dbg(hdev, "remove monitor %d status %d",
2023 status = msft_remove_monitor(hdev, monitor);
2024 bt_dev_dbg(hdev, "remove monitor %d msft status %d",
2037 bt_dev_warn(hdev, "Removing monitor with no matching handle %d",
2039 hci_free_adv_monitor(hdev, monitor);
2045 int hci_remove_single_adv_monitor(struct hci_dev *hdev, u16 handle)
2047 struct adv_monitor *monitor = idr_find(&hdev->adv_monitors_idr, handle);
2052 return hci_remove_adv_monitor(hdev, monitor);
2056 int hci_remove_all_adv_monitor(struct hci_dev *hdev)
2063 monitor = idr_get_next(&hdev->adv_monitors_idr, &idr_next_id);
2067 status = hci_remove_adv_monitor(hdev, monitor);
2077 /* This function requires the caller holds hdev->lock */
2078 bool hci_is_adv_monitoring(struct hci_dev *hdev)
2080 return !idr_is_empty(&hdev->adv_monitors_idr);
2083 int hci_get_adv_monitor_offload_ext(struct hci_dev *hdev)
2085 if (msft_monitor_supported(hdev))
2276 /* This function requires the caller holds hdev->lock */
2277 struct hci_conn_params *hci_conn_params_lookup(struct hci_dev *hdev,
2282 list_for_each_entry(params, &hdev->le_conn_params, list) {
2292 /* This function requires the caller holds hdev->lock or rcu_read_lock */
2313 /* This function requires the caller holds hdev->lock */
2324 /* This function requires the caller holds hdev->lock */
2331 /* This function requires the caller holds hdev->lock */
2332 struct hci_conn_params *hci_conn_params_add(struct hci_dev *hdev,
2337 params = hci_conn_params_lookup(hdev, addr, addr_type);
2343 bt_dev_err(hdev, "out of memory");
2350 list_add(&params->list, &hdev->le_conn_params);
2353 params->conn_min_interval = hdev->le_conn_min_interval;
2354 params->conn_max_interval = hdev->le_conn_max_interval;
2355 params->conn_latency = hdev->le_conn_latency;
2356 params->supervision_timeout = hdev->le_supv_timeout;
2377 /* This function requires the caller holds hdev->lock */
2378 void hci_conn_params_del(struct hci_dev *hdev, bdaddr_t *addr, u8 addr_type)
2382 params = hci_conn_params_lookup(hdev, addr, addr_type);
2388 hci_update_passive_scan(hdev);
2393 /* This function requires the caller holds hdev->lock */
2394 void hci_conn_params_clear_disabled(struct hci_dev *hdev)
2398 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list) {
2416 /* This function requires the caller holds hdev->lock */
2417 static void hci_conn_params_clear_all(struct hci_dev *hdev)
2421 list_for_each_entry_safe(params, tmp, &hdev->le_conn_params, list)
2440 void hci_copy_identity_address(struct hci_dev *hdev, bdaddr_t *bdaddr,
2443 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ||
2444 !bacmp(&hdev->bdaddr, BDADDR_ANY) ||
2445 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) &&
2446 bacmp(&hdev->static_addr, BDADDR_ANY))) {
2447 bacpy(bdaddr, &hdev->static_addr);
2450 bacpy(bdaddr, &hdev->bdaddr);
2455 static void hci_clear_wake_reason(struct hci_dev *hdev)
2457 hci_dev_lock(hdev);
2459 hdev->wake_reason = 0;
2460 bacpy(&hdev->wake_addr, BDADDR_ANY);
2461 hdev->wake_addr_type = 0;
2463 hci_dev_unlock(hdev);
2469 struct hci_dev *hdev =
2474 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL))
2478 hci_dev_hold(hdev);
2481 ret = hci_suspend_dev(hdev);
2483 ret = hci_resume_dev(hdev);
2486 bt_dev_err(hdev, "Suspend notifier action (%lu) failed: %d",
2489 hci_dev_put(hdev);
2496 struct hci_dev *hdev;
2499 alloc_size = sizeof(*hdev);
2505 hdev = kzalloc(alloc_size, GFP_KERNEL);
2506 if (!hdev)
2509 hdev->pkt_type = (HCI_DM1 | HCI_DH1 | HCI_HV1);
2510 hdev->esco_type = (ESCO_HV1);
2511 hdev->link_mode = (HCI_LM_ACCEPT);
2512 hdev->num_iac = 0x01; /* One IAC support is mandatory */
2513 hdev->io_capability = 0x03; /* No Input No Output */
2514 hdev->manufacturer = 0xffff; /* Default to internal use */
2515 hdev->inq_tx_power = HCI_TX_POWER_INVALID;
2516 hdev->adv_tx_power = HCI_TX_POWER_INVALID;
2517 hdev->adv_instance_cnt = 0;
2518 hdev->cur_adv_instance = 0x00;
2519 hdev->adv_instance_timeout = 0;
2521 hdev->advmon_allowlist_duration = 300;
2522 hdev->advmon_no_filter_duration = 500;
2523 hdev->enable_advmon_interleave_scan = 0x00; /* Default to disable */
2525 hdev->sniff_max_interval = 800;
2526 hdev->sniff_min_interval = 80;
2528 hdev->le_adv_channel_map = 0x07;
2529 hdev->le_adv_min_interval = 0x0800;
2530 hdev->le_adv_max_interval = 0x0800;
2531 hdev->le_scan_interval = DISCOV_LE_SCAN_INT_FAST;
2532 hdev->le_scan_window = DISCOV_LE_SCAN_WIN_FAST;
2533 hdev->le_scan_int_suspend = DISCOV_LE_SCAN_INT_SLOW1;
2534 hdev->le_scan_window_suspend = DISCOV_LE_SCAN_WIN_SLOW1;
2535 hdev->le_scan_int_discovery = DISCOV_LE_SCAN_INT;
2536 hdev->le_scan_window_discovery = DISCOV_LE_SCAN_WIN;
2537 hdev->le_scan_int_adv_monitor = DISCOV_LE_SCAN_INT_FAST;
2538 hdev->le_scan_window_adv_monitor = DISCOV_LE_SCAN_WIN_FAST;
2539 hdev->le_scan_int_connect = DISCOV_LE_SCAN_INT_CONN;
2540 hdev->le_scan_window_connect = DISCOV_LE_SCAN_WIN_CONN;
2541 hdev->le_conn_min_interval = 0x0018;
2542 hdev->le_conn_max_interval = 0x0028;
2543 hdev->le_conn_latency = 0x0000;
2544 hdev->le_supv_timeout = 0x002a;
2545 hdev->le_def_tx_len = 0x001b;
2546 hdev->le_def_tx_time = 0x0148;
2547 hdev->le_max_tx_len = 0x001b;
2548 hdev->le_max_tx_time = 0x0148;
2549 hdev->le_max_rx_len = 0x001b;
2550 hdev->le_max_rx_time = 0x0148;
2551 hdev->le_max_key_size = SMP_MAX_ENC_KEY_SIZE;
2552 hdev->le_min_key_size = SMP_MIN_ENC_KEY_SIZE;
2553 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M;
2554 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M;
2555 hdev->le_num_of_adv_sets = HCI_MAX_ADV_INSTANCES;
2556 hdev->def_multi_adv_rotation_duration = HCI_DEFAULT_ADV_DURATION;
2557 hdev->def_le_autoconnect_timeout = HCI_LE_CONN_TIMEOUT;
2558 hdev->min_le_tx_power = HCI_TX_POWER_INVALID;
2559 hdev->max_le_tx_power = HCI_TX_POWER_INVALID;
2561 hdev->rpa_timeout = HCI_DEFAULT_RPA_TIMEOUT;
2562 hdev->discov_interleaved_timeout = DISCOV_INTERLEAVED_TIMEOUT;
2563 hdev->conn_info_min_age = DEFAULT_CONN_INFO_MIN_AGE;
2564 hdev->conn_info_max_age = DEFAULT_CONN_INFO_MAX_AGE;
2565 hdev->auth_payload_timeout = DEFAULT_AUTH_PAYLOAD_TIMEOUT;
2566 hdev->min_enc_key_size = HCI_MIN_ENC_KEY_SIZE;
2569 hdev->def_page_scan_type = PAGE_SCAN_TYPE_STANDARD;
2570 hdev->def_page_scan_int = 0x0800;
2571 hdev->def_page_scan_window = 0x0012;
2573 mutex_init(&hdev->lock);
2574 mutex_init(&hdev->req_lock);
2576 ida_init(&hdev->unset_handle_ida);
2578 INIT_LIST_HEAD(&hdev->mesh_pending);
2579 INIT_LIST_HEAD(&hdev->mgmt_pending);
2580 INIT_LIST_HEAD(&hdev->reject_list);
2581 INIT_LIST_HEAD(&hdev->accept_list);
2582 INIT_LIST_HEAD(&hdev->uuids);
2583 INIT_LIST_HEAD(&hdev->link_keys);
2584 INIT_LIST_HEAD(&hdev->long_term_keys);
2585 INIT_LIST_HEAD(&hdev->identity_resolving_keys);
2586 INIT_LIST_HEAD(&hdev->remote_oob_data);
2587 INIT_LIST_HEAD(&hdev->le_accept_list);
2588 INIT_LIST_HEAD(&hdev->le_resolv_list);
2589 INIT_LIST_HEAD(&hdev->le_conn_params);
2590 INIT_LIST_HEAD(&hdev->pend_le_conns);
2591 INIT_LIST_HEAD(&hdev->pend_le_reports);
2592 INIT_LIST_HEAD(&hdev->conn_hash.list);
2593 INIT_LIST_HEAD(&hdev->adv_instances);
2594 INIT_LIST_HEAD(&hdev->blocked_keys);
2595 INIT_LIST_HEAD(&hdev->monitored_devices);
2597 INIT_LIST_HEAD(&hdev->local_codecs);
2598 INIT_WORK(&hdev->rx_work, hci_rx_work);
2599 INIT_WORK(&hdev->cmd_work, hci_cmd_work);
2600 INIT_WORK(&hdev->tx_work, hci_tx_work);
2601 INIT_WORK(&hdev->power_on, hci_power_on);
2602 INIT_WORK(&hdev->error_reset, hci_error_reset);
2604 hci_cmd_sync_init(hdev);
2606 INIT_DELAYED_WORK(&hdev->power_off, hci_power_off);
2608 skb_queue_head_init(&hdev->rx_q);
2609 skb_queue_head_init(&hdev->cmd_q);
2610 skb_queue_head_init(&hdev->raw_q);
2612 init_waitqueue_head(&hdev->req_wait_q);
2614 INIT_DELAYED_WORK(&hdev->cmd_timer, hci_cmd_timeout);
2615 INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout);
2617 hci_devcd_setup(hdev);
2618 hci_request_setup(hdev);
2620 hci_init_sysfs(hdev);
2621 discovery_init(hdev);
2623 return hdev;
2628 void hci_free_dev(struct hci_dev *hdev)
2631 put_device(&hdev->dev);
2636 int hci_register_dev(struct hci_dev *hdev)
2640 if (!hdev->open || !hdev->close || !hdev->send)
2647 error = dev_set_name(&hdev->dev, "hci%u", id);
2651 hdev->name = dev_name(&hdev->dev);
2652 hdev->id = id;
2654 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
2656 hdev->workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI, hdev->name);
2657 if (!hdev->workqueue) {
2662 hdev->req_workqueue = alloc_ordered_workqueue("%s", WQ_HIGHPRI,
2663 hdev->name);
2664 if (!hdev->req_workqueue) {
2665 destroy_workqueue(hdev->workqueue);
2671 hdev->debugfs = debugfs_create_dir(hdev->name, bt_debugfs);
2673 error = device_add(&hdev->dev);
2677 hci_leds_init(hdev);
2679 hdev->rfkill = rfkill_alloc(hdev->name, &hdev->dev,
2681 hdev);
2682 if (hdev->rfkill) {
2683 if (rfkill_register(hdev->rfkill) < 0) {
2684 rfkill_destroy(hdev->rfkill);
2685 hdev->rfkill = NULL;
2689 if (hdev->rfkill && rfkill_blocked(hdev->rfkill))
2690 hci_dev_set_flag(hdev, HCI_RFKILLED);
2692 hci_dev_set_flag(hdev, HCI_SETUP);
2693 hci_dev_set_flag(hdev, HCI_AUTO_OFF);
2698 hci_dev_set_flag(hdev, HCI_BREDR_ENABLED);
2701 list_add(&hdev->list, &hci_dev_list);
2707 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks))
2708 hci_dev_set_flag(hdev, HCI_UNCONFIGURED);
2713 if (hdev->wakeup)
2714 hdev->conn_flags |= HCI_CONN_FLAG_REMOTE_WAKEUP;
2716 hci_sock_dev_event(hdev, HCI_DEV_REG);
2717 hci_dev_hold(hdev);
2719 error = hci_register_suspend_notifier(hdev);
2723 queue_work(hdev->req_workqueue, &hdev->power_on);
2725 idr_init(&hdev->adv_monitors_idr);
2726 msft_register(hdev);
2731 debugfs_remove_recursive(hdev->debugfs);
2732 destroy_workqueue(hdev->workqueue);
2733 destroy_workqueue(hdev->req_workqueue);
2735 ida_free(&hci_index_ida, hdev->id);
2742 void hci_unregister_dev(struct hci_dev *hdev)
2744 BT_DBG("%p name %s bus %d", hdev, hdev->name, hdev->bus);
2746 mutex_lock(&hdev->unregister_lock);
2747 hci_dev_set_flag(hdev, HCI_UNREGISTER);
2748 mutex_unlock(&hdev->unregister_lock);
2751 list_del(&hdev->list);
2754 cancel_work_sync(&hdev->power_on);
2756 hci_cmd_sync_clear(hdev);
2758 hci_unregister_suspend_notifier(hdev);
2760 hci_dev_do_close(hdev);
2762 if (!test_bit(HCI_INIT, &hdev->flags) &&
2763 !hci_dev_test_flag(hdev, HCI_SETUP) &&
2764 !hci_dev_test_flag(hdev, HCI_CONFIG)) {
2765 hci_dev_lock(hdev);
2766 mgmt_index_removed(hdev);
2767 hci_dev_unlock(hdev);
2772 BUG_ON(!list_empty(&hdev->mgmt_pending));
2774 hci_sock_dev_event(hdev, HCI_DEV_UNREG);
2776 if (hdev->rfkill) {
2777 rfkill_unregister(hdev->rfkill);
2778 rfkill_destroy(hdev->rfkill);
2781 device_del(&hdev->dev);
2783 hci_dev_put(hdev);
2788 void hci_release_dev(struct hci_dev *hdev)
2790 debugfs_remove_recursive(hdev->debugfs);
2791 kfree_const(hdev->hw_info);
2792 kfree_const(hdev->fw_info);
2794 destroy_workqueue(hdev->workqueue);
2795 destroy_workqueue(hdev->req_workqueue);
2797 hci_dev_lock(hdev);
2798 hci_bdaddr_list_clear(&hdev->reject_list);
2799 hci_bdaddr_list_clear(&hdev->accept_list);
2800 hci_uuids_clear(hdev);
2801 hci_link_keys_clear(hdev);
2802 hci_smp_ltks_clear(hdev);
2803 hci_smp_irks_clear(hdev);
2804 hci_remote_oob_data_clear(hdev);
2805 hci_adv_instances_clear(hdev);
2806 hci_adv_monitors_clear(hdev);
2807 hci_bdaddr_list_clear(&hdev->le_accept_list);
2808 hci_bdaddr_list_clear(&hdev->le_resolv_list);
2809 hci_conn_params_clear_all(hdev);
2810 hci_discovery_filter_clear(hdev);
2811 hci_blocked_keys_clear(hdev);
2812 hci_codec_list_clear(&hdev->local_codecs);
2813 msft_release(hdev);
2814 hci_dev_unlock(hdev);
2816 ida_destroy(&hdev->unset_handle_ida);
2817 ida_free(&hci_index_ida, hdev->id);
2818 kfree_skb(hdev->sent_cmd);
2819 kfree_skb(hdev->req_skb);
2820 kfree_skb(hdev->recv_event);
2821 kfree(hdev);
2825 int hci_register_suspend_notifier(struct hci_dev *hdev)
2829 if (!hdev->suspend_notifier.notifier_call &&
2830 !test_bit(HCI_QUIRK_NO_SUSPEND_NOTIFIER, &hdev->quirks)) {
2831 hdev->suspend_notifier.notifier_call = hci_suspend_notifier;
2832 ret = register_pm_notifier(&hdev->suspend_notifier);
2838 int hci_unregister_suspend_notifier(struct hci_dev *hdev)
2842 if (hdev->suspend_notifier.notifier_call) {
2843 ret = unregister_pm_notifier(&hdev->suspend_notifier);
2845 hdev->suspend_notifier.notifier_call = NULL;
2857 static void hci_cancel_cmd_sync(struct hci_dev *hdev, int err)
2859 bt_dev_dbg(hdev, "err 0x%2.2x", err);
2861 cancel_delayed_work_sync(&hdev->cmd_timer);
2862 cancel_delayed_work_sync(&hdev->ncmd_timer);
2863 atomic_set(&hdev->cmd_cnt, 1);
2865 hci_cmd_sync_cancel_sync(hdev, err);
2869 int hci_suspend_dev(struct hci_dev *hdev)
2873 bt_dev_dbg(hdev, "");
2876 if (!hdev_is_powered(hdev) ||
2877 hci_dev_test_flag(hdev, HCI_UNREGISTER))
2881 if (mgmt_powering_down(hdev))
2885 hci_cancel_cmd_sync(hdev, EHOSTDOWN);
2887 hci_req_sync_lock(hdev);
2888 ret = hci_suspend_sync(hdev);
2889 hci_req_sync_unlock(hdev);
2891 hci_clear_wake_reason(hdev);
2892 mgmt_suspending(hdev, hdev->suspend_state);
2894 hci_sock_dev_event(hdev, HCI_DEV_SUSPEND);
2900 int hci_resume_dev(struct hci_dev *hdev)
2904 bt_dev_dbg(hdev, "");
2907 if (!hdev_is_powered(hdev) ||
2908 hci_dev_test_flag(hdev, HCI_UNREGISTER))
2912 if (mgmt_powering_down(hdev))
2915 hci_req_sync_lock(hdev);
2916 ret = hci_resume_sync(hdev);
2917 hci_req_sync_unlock(hdev);
2919 mgmt_resuming(hdev, hdev->wake_reason, &hdev->wake_addr,
2920 hdev->wake_addr_type);
2922 hci_sock_dev_event(hdev, HCI_DEV_RESUME);
2928 int hci_reset_dev(struct hci_dev *hdev)
2940 bt_dev_err(hdev, "Injecting HCI hardware error event");
2943 return hci_recv_frame(hdev, skb);
2948 int hci_recv_frame(struct hci_dev *hdev, struct sk_buff *skb)
2950 if (!hdev || (!test_bit(HCI_UP, &hdev->flags)
2951 && !test_bit(HCI_INIT, &hdev->flags))) {
2961 if (hci_conn_num(hdev, ISO_LINK)) {
2965 type = hci_conn_lookup_type(hdev, hci_handle(handle));
2985 skb_queue_tail(&hdev->rx_q, skb);
2986 queue_work(hdev->workqueue, &hdev->rx_work);
2993 int hci_recv_diag(struct hci_dev *hdev, struct sk_buff *skb)
3001 skb_queue_tail(&hdev->rx_q, skb);
3002 queue_work(hdev->workqueue, &hdev->rx_work);
3008 void hci_set_hw_info(struct hci_dev *hdev, const char *fmt, ...)
3013 kfree_const(hdev->hw_info);
3014 hdev->hw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs);
3019 void hci_set_fw_info(struct hci_dev *hdev, const char *fmt, ...)
3024 kfree_const(hdev->fw_info);
3025 hdev->fw_info = kvasprintf_const(GFP_KERNEL, fmt, vargs);
3056 static int hci_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
3060 BT_DBG("%s type %d len %d", hdev->name, hci_skb_pkt_type(skb),
3067 hci_send_to_monitor(hdev, skb);
3069 if (atomic_read(&hdev->promisc)) {
3071 hci_send_to_sock(hdev, skb);
3077 if (!test_bit(HCI_RUNNING, &hdev->flags)) {
3082 err = hdev->send(hdev, skb);
3084 bt_dev_err(hdev, "sending frame failed (%d)", err);
3093 int hci_send_cmd(struct hci_dev *hdev, __u16 opcode, __u32 plen,
3098 BT_DBG("%s opcode 0x%4.4x plen %d", hdev->name, opcode, plen);
3100 skb = hci_prepare_cmd(hdev, opcode, plen, param);
3102 bt_dev_err(hdev, "no memory for command");
3111 skb_queue_tail(&hdev->cmd_q, skb);
3112 queue_work(hdev->workqueue, &hdev->cmd_work);
3117 int __hci_cmd_send(struct hci_dev *hdev, u16 opcode, u32 plen,
3131 bt_dev_err(hdev, "unresponded command not supported");
3135 skb = hci_prepare_cmd(hdev, opcode, plen, param);
3137 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)",
3142 hci_send_frame(hdev, skb);
3165 void *hci_sent_cmd_data(struct hci_dev *hdev, __u16 opcode)
3170 data = hci_cmd_data(hdev->sent_cmd, opcode);
3173 data = hci_cmd_data(hdev->req_skb, opcode);
3179 void *hci_recv_event_data(struct hci_dev *hdev, __u8 event)
3184 if (!hdev->recv_event)
3187 hdr = (void *)hdev->recv_event->data;
3195 ev = (void *)hdev->recv_event->data + offset;
3204 bt_dev_dbg(hdev, "event 0x%2.2x", event);
3206 return hdev->recv_event->data + offset;
3226 struct hci_dev *hdev = conn->hdev;
3239 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
3244 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
3265 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
3276 struct hci_dev *hdev = chan->conn->hdev;
3278 BT_DBG("%s chan %p flags 0x%4.4x", hdev->name, chan, flags);
3282 queue_work(hdev->workqueue, &hdev->tx_work);
3288 struct hci_dev *hdev = conn->hdev;
3291 BT_DBG("%s len %d", hdev->name, skb->len);
3303 queue_work(hdev->workqueue, &hdev->tx_work);
3322 struct hci_dev *hdev = conn->hdev;
3338 BT_DBG("%s nonfrag skb %p len %d", hdev->name, skb, skb->len);
3343 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
3357 BT_DBG("%s frag %p len %d", hdev->name, skb, skb->len);
3366 struct hci_dev *hdev = conn->hdev;
3368 BT_DBG("%s len %d", hdev->name, skb->len);
3372 queue_work(hdev->workqueue, &hdev->tx_work);
3380 struct hci_dev *hdev;
3388 hdev = conn->hdev;
3392 cnt = hdev->acl_cnt;
3396 cnt = hdev->sco_cnt;
3399 cnt = hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt;
3402 cnt = hdev->iso_mtu ? hdev->iso_cnt :
3403 hdev->le_mtu ? hdev->le_cnt : hdev->acl_cnt;
3407 bt_dev_err(hdev, "unknown link type %d", conn->type);
3414 static struct hci_conn *hci_low_sent(struct hci_dev *hdev, __u8 type,
3417 struct hci_conn_hash *h = &hdev->conn_hash;
3440 if (hci_conn_num(hdev, type) == num)
3452 static void hci_link_tx_to(struct hci_dev *hdev, __u8 type)
3454 struct hci_conn_hash *h = &hdev->conn_hash;
3457 bt_dev_err(hdev, "link tx timeout");
3464 bt_dev_err(hdev, "killing stalled connection %pMR",
3478 static struct hci_chan *hci_chan_sent(struct hci_dev *hdev, __u8 type,
3481 struct hci_conn_hash *h = &hdev->conn_hash;
3487 BT_DBG("%s", hdev->name);
3526 if (hci_conn_num(hdev, type) == conn_num)
3541 static void hci_prio_recalculate(struct hci_dev *hdev, __u8 type)
3543 struct hci_conn_hash *h = &hdev->conn_hash;
3547 BT_DBG("%s", hdev->name);
3583 if (hci_conn_num(hdev, type) == num)
3591 static void __check_timeout(struct hci_dev *hdev, unsigned int cnt, u8 type)
3595 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED))
3600 last_tx = hdev->le_last_tx;
3603 last_tx = hdev->acl_last_tx;
3611 hci_link_tx_to(hdev, type);
3615 static void hci_sched_sco(struct hci_dev *hdev)
3621 BT_DBG("%s", hdev->name);
3623 if (!hci_conn_num(hdev, SCO_LINK))
3626 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, SCO_LINK, &quote))) {
3629 hci_send_frame(hdev, skb);
3638 static void hci_sched_esco(struct hci_dev *hdev)
3644 BT_DBG("%s", hdev->name);
3646 if (!hci_conn_num(hdev, ESCO_LINK))
3649 while (hdev->sco_cnt && (conn = hci_low_sent(hdev, ESCO_LINK,
3653 hci_send_frame(hdev, skb);
3662 static void hci_sched_acl_pkt(struct hci_dev *hdev)
3664 unsigned int cnt = hdev->acl_cnt;
3669 __check_timeout(hdev, cnt, ACL_LINK);
3671 while (hdev->acl_cnt &&
3672 (chan = hci_chan_sent(hdev, ACL_LINK, &quote))) {
3687 hci_send_frame(hdev, skb);
3688 hdev->acl_last_tx = jiffies;
3690 hdev->acl_cnt--;
3695 hci_sched_sco(hdev);
3696 hci_sched_esco(hdev);
3700 if (cnt != hdev->acl_cnt)
3701 hci_prio_recalculate(hdev, ACL_LINK);
3704 static void hci_sched_acl(struct hci_dev *hdev)
3706 BT_DBG("%s", hdev->name);
3709 if (!hci_conn_num(hdev, ACL_LINK))
3712 hci_sched_acl_pkt(hdev);
3715 static void hci_sched_le(struct hci_dev *hdev)
3721 BT_DBG("%s", hdev->name);
3723 if (!hci_conn_num(hdev, LE_LINK))
3726 cnt = hdev->le_pkts ? hdev->le_cnt : hdev->acl_cnt;
3728 __check_timeout(hdev, cnt, LE_LINK);
3731 while (cnt && (chan = hci_chan_sent(hdev, LE_LINK, &quote))) {
3743 hci_send_frame(hdev, skb);
3744 hdev->le_last_tx = jiffies;
3751 hci_sched_sco(hdev);
3752 hci_sched_esco(hdev);
3756 if (hdev->le_pkts)
3757 hdev->le_cnt = cnt;
3759 hdev->acl_cnt = cnt;
3762 hci_prio_recalculate(hdev, LE_LINK);
3766 static void hci_sched_iso(struct hci_dev *hdev)
3772 BT_DBG("%s", hdev->name);
3774 if (!hci_conn_num(hdev, ISO_LINK))
3777 cnt = hdev->iso_pkts ? &hdev->iso_cnt :
3778 hdev->le_pkts ? &hdev->le_cnt : &hdev->acl_cnt;
3779 while (*cnt && (conn = hci_low_sent(hdev, ISO_LINK, &quote))) {
3782 hci_send_frame(hdev, skb);
3794 struct hci_dev *hdev = container_of(work, struct hci_dev, tx_work);
3797 BT_DBG("%s acl %d sco %d le %d iso %d", hdev->name, hdev->acl_cnt,
3798 hdev->sco_cnt, hdev->le_cnt, hdev->iso_cnt);
3800 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) {
3802 hci_sched_sco(hdev);
3803 hci_sched_esco(hdev);
3804 hci_sched_iso(hdev);
3805 hci_sched_acl(hdev);
3806 hci_sched_le(hdev);
3810 while ((skb = skb_dequeue(&hdev->raw_q)))
3811 hci_send_frame(hdev, skb);
3817 static void hci_acldata_packet(struct hci_dev *hdev, struct sk_buff *skb)
3829 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len,
3832 hdev->stat.acl_rx++;
3834 hci_dev_lock(hdev);
3835 conn = hci_conn_hash_lookup_handle(hdev, handle);
3836 hci_dev_unlock(hdev);
3845 bt_dev_err(hdev, "ACL packet for unknown connection handle %d",
3853 static void hci_scodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
3865 BT_DBG("%s len %d handle 0x%4.4x flags 0x%4.4x", hdev->name, skb->len,
3868 hdev->stat.sco_rx++;
3870 hci_dev_lock(hdev);
3871 conn = hci_conn_hash_lookup_handle(hdev, handle);
3872 hci_dev_unlock(hdev);
3880 bt_dev_err_ratelimited(hdev, "SCO packet for unknown connection handle %d",
3887 static void hci_isodata_packet(struct hci_dev *hdev, struct sk_buff *skb)
3895 bt_dev_err(hdev, "ISO packet too small");
3903 bt_dev_dbg(hdev, "len %d handle 0x%4.4x flags 0x%4.4x", skb->len,
3906 hci_dev_lock(hdev);
3907 conn = hci_conn_hash_lookup_handle(hdev, handle);
3908 hci_dev_unlock(hdev);
3911 bt_dev_err(hdev, "ISO packet for unknown connection handle %d",
3924 static bool hci_req_is_complete(struct hci_dev *hdev)
3928 skb = skb_peek(&hdev->cmd_q);
3935 static void hci_resend_last(struct hci_dev *hdev)
3941 if (!hdev->sent_cmd)
3944 sent = (void *) hdev->sent_cmd->data;
3949 skb = skb_clone(hdev->sent_cmd, GFP_KERNEL);
3953 skb_queue_head(&hdev->cmd_q, skb);
3954 queue_work(hdev->workqueue, &hdev->cmd_work);
3957 void hci_req_cmd_complete(struct hci_dev *hdev, u16 opcode, u8 status,
3969 if (!hci_sent_cmd_data(hdev, opcode)) {
3976 if (test_bit(HCI_INIT, &hdev->flags) && opcode == HCI_OP_RESET)
3977 hci_resend_last(hdev);
3983 hci_dev_clear_flag(hdev, HCI_CMD_PENDING);
3988 if (!status && !hci_req_is_complete(hdev))
3991 skb = hdev->req_skb;
3994 * callback would be found in hdev->req_skb instead of the
3995 * command queue (hdev->cmd_q).
4008 spin_lock_irqsave(&hdev->cmd_q.lock, flags);
4009 while ((skb = __skb_dequeue(&hdev->cmd_q))) {
4011 __skb_queue_head(&hdev->cmd_q, skb);
4021 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);
4026 struct hci_dev *hdev = container_of(work, struct hci_dev, rx_work);
4029 BT_DBG("%s", hdev->name);
4036 for (; (skb = skb_dequeue(&hdev->rx_q)); kcov_remote_stop()) {
4040 hci_send_to_monitor(hdev, skb);
4042 if (atomic_read(&hdev->promisc)) {
4044 hci_send_to_sock(hdev, skb);
4053 if (hci_dev_test_flag(hdev, HCI_USER_CHANNEL) &&
4054 !test_bit(HCI_INIT, &hdev->flags)) {
4059 if (test_bit(HCI_INIT, &hdev->flags)) {
4073 BT_DBG("%s Event packet", hdev->name);
4074 hci_event_packet(hdev, skb);
4078 BT_DBG("%s ACL data packet", hdev->name);
4079 hci_acldata_packet(hdev, skb);
4083 BT_DBG("%s SCO data packet", hdev->name);
4084 hci_scodata_packet(hdev, skb);
4088 BT_DBG("%s ISO data packet", hdev->name);
4089 hci_isodata_packet(hdev, skb);
4099 static void hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb)
4103 bt_dev_dbg(hdev, "skb %p", skb);
4105 kfree_skb(hdev->sent_cmd);
4107 hdev->sent_cmd = skb_clone(skb, GFP_KERNEL);
4108 if (!hdev->sent_cmd) {
4109 skb_queue_head(&hdev->cmd_q, skb);
4110 queue_work(hdev->workqueue, &hdev->cmd_work);
4114 err = hci_send_frame(hdev, skb);
4116 hci_cmd_sync_cancel_sync(hdev, -err);
4120 if (hci_req_status_pend(hdev) &&
4121 !hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) {
4122 kfree_skb(hdev->req_skb);
4123 hdev->req_skb = skb_clone(hdev->sent_cmd, GFP_KERNEL);
4126 atomic_dec(&hdev->cmd_cnt);
4131 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_work);
4134 BT_DBG("%s cmd_cnt %d cmd queued %d", hdev->name,
4135 atomic_read(&hdev->cmd_cnt), skb_queue_len(&hdev->cmd_q));
4138 if (atomic_read(&hdev->cmd_cnt)) {
4139 skb = skb_dequeue(&hdev->cmd_q);
4143 hci_send_cmd_sync(hdev, skb);
4146 if (test_bit(HCI_RESET, &hdev->flags) ||
4147 hci_dev_test_flag(hdev, HCI_CMD_DRAIN_WORKQUEUE))
4148 cancel_delayed_work(&hdev->cmd_timer);
4150 queue_delayed_work(hdev->workqueue, &hdev->cmd_timer,