Lines Matching +full:cpb +full:- +full:codec
1 // SPDX-License-Identifier: GPL-2.0
3 * BlueZ - Bluetooth protocol stack for Linux
28 if (hdev->req_status != HCI_REQ_PEND) in hci_cmd_sync_complete()
31 hdev->req_result = result; in hci_cmd_sync_complete()
32 hdev->req_status = HCI_REQ_DONE; in hci_cmd_sync_complete()
41 hdev->req_skb = skb_get(skb); in hci_cmd_sync_complete()
44 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_complete()
60 hdr->opcode = cpu_to_le16(opcode); in hci_cmd_sync_alloc()
61 hdr->plen = plen; in hci_cmd_sync_alloc()
66 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_cmd_sync_alloc()
85 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_add()
93 if (req->err) in hci_cmd_sync_add()
100 req->err = -ENOMEM; in hci_cmd_sync_add()
104 if (skb_queue_empty(&req->cmd_q)) in hci_cmd_sync_add()
105 bt_cb(skb)->hci.req_flags |= HCI_REQ_START; in hci_cmd_sync_add()
109 skb_queue_tail(&req->cmd_q, skb); in hci_cmd_sync_add()
114 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_run()
118 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in hci_cmd_sync_run()
123 if (req->err) { in hci_cmd_sync_run()
124 skb_queue_purge(&req->cmd_q); in hci_cmd_sync_run()
125 return req->err; in hci_cmd_sync_run()
129 if (skb_queue_empty(&req->cmd_q)) in hci_cmd_sync_run()
130 return -ENODATA; in hci_cmd_sync_run()
132 skb = skb_peek_tail(&req->cmd_q); in hci_cmd_sync_run()
133 bt_cb(skb)->hci.req_complete_skb = hci_cmd_sync_complete; in hci_cmd_sync_run()
134 bt_cb(skb)->hci.req_flags |= HCI_REQ_SKB; in hci_cmd_sync_run()
136 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
137 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in hci_cmd_sync_run()
138 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
140 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_sync_run()
145 /* This function requires the caller holds hdev->req_lock. */
160 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_sk()
166 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_sk()
167 hdev->req_status != HCI_REQ_PEND, in __hci_cmd_sync_sk()
170 if (err == -ERESTARTSYS) in __hci_cmd_sync_sk()
171 return ERR_PTR(-EINTR); in __hci_cmd_sync_sk()
173 switch (hdev->req_status) { in __hci_cmd_sync_sk()
175 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_sk()
179 err = -hdev->req_result; in __hci_cmd_sync_sk()
183 err = -ETIMEDOUT; in __hci_cmd_sync_sk()
187 hdev->req_status = 0; in __hci_cmd_sync_sk()
188 hdev->req_result = 0; in __hci_cmd_sync_sk()
189 skb = hdev->req_skb; in __hci_cmd_sync_sk()
190 hdev->req_skb = NULL; in __hci_cmd_sync_sk()
203 /* This function requires the caller holds hdev->req_lock. */
217 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
218 return ERR_PTR(-ENETDOWN); in hci_cmd_sync()
230 /* This function requires the caller holds hdev->req_lock. */
239 /* This function requires the caller holds hdev->req_lock. */
261 status = skb->data[0]; in __hci_cmd_sync_status_sk()
287 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
288 entry = list_first_entry_or_null(&hdev->cmd_sync_work_list, in hci_cmd_sync_work()
292 list_del(&entry->list); in hci_cmd_sync_work()
293 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
300 if (entry->func) { in hci_cmd_sync_work()
304 err = entry->func(hdev, entry->data); in hci_cmd_sync_work()
305 if (entry->destroy) in hci_cmd_sync_work()
306 entry->destroy(hdev, entry->data, err); in hci_cmd_sync_work()
318 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cmd_sync_cancel_work()
319 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cmd_sync_cancel_work()
320 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_sync_cancel_work()
322 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_work()
349 cancel_delayed_work(&hdev->le_scan_restart); in le_scan_disable()
357 hdev->discovery.scan_start = 0; in le_scan_disable()
367 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable()
370 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable()
373 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable()
374 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable()
375 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable()
404 if (hdev->scanning_paused) { in hci_le_scan_restart_sync()
437 if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) || in le_scan_restart()
438 !hdev->discovery.scan_start) in le_scan_restart()
441 /* When the scan was started, hdev->le_scan_disable has been queued in le_scan_restart()
446 duration = hdev->discovery.scan_duration; in le_scan_restart()
447 scan_start = hdev->discovery.scan_start; in le_scan_restart()
449 if (now - scan_start <= duration) { in le_scan_restart()
453 elapsed = now - scan_start; in le_scan_restart()
455 elapsed = ULONG_MAX - scan_start + now; in le_scan_restart()
457 timeout = duration - elapsed; in le_scan_restart()
462 queue_delayed_work(hdev->req_workqueue, in le_scan_restart()
463 &hdev->le_scan_disable, timeout); in le_scan_restart()
474 list_empty(&hdev->adv_instances)) in reenable_adv_sync()
477 if (hdev->cur_adv_instance) { in reenable_adv_sync()
479 hdev->cur_adv_instance, in reenable_adv_sync()
513 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
514 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
515 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
520 * - force == true: The instance will be removed even when its remaining
522 * - force == false: the instance will be deactivated but kept stored unless
526 * - force == true: All instances will be removed regardless of their timeout
528 * - force == false: Only instances that have a timeout will be removed.
538 if (!instance || hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
545 if (instance && hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
549 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_clear_adv_instance_sync()
551 if (!(force || adv_instance->timeout)) in hci_clear_adv_instance_sync()
554 rem_inst = adv_instance->instance; in hci_clear_adv_instance_sync()
562 if (force || (adv_instance && adv_instance->timeout && in hci_clear_adv_instance_sync()
563 !adv_instance->remaining_time)) { in hci_clear_adv_instance_sync()
566 next_instance->instance == instance) in hci_clear_adv_instance_sync()
580 next_instance->instance, in hci_clear_adv_instance_sync()
594 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire_sync()
610 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
612 if (hdev->cur_adv_instance == 0x00) in adv_timeout_expire()
619 *inst_ptr = hdev->cur_adv_instance; in adv_timeout_expire()
628 INIT_WORK(&hdev->cmd_sync_work, hci_cmd_sync_work); in hci_cmd_sync_init()
629 INIT_LIST_HEAD(&hdev->cmd_sync_work_list); in hci_cmd_sync_init()
630 mutex_init(&hdev->cmd_sync_work_lock); in hci_cmd_sync_init()
632 INIT_WORK(&hdev->cmd_sync_cancel_work, hci_cmd_sync_cancel_work); in hci_cmd_sync_init()
633 INIT_WORK(&hdev->reenable_adv_work, reenable_adv); in hci_cmd_sync_init()
634 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable); in hci_cmd_sync_init()
635 INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart); in hci_cmd_sync_init()
636 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_cmd_sync_init()
643 cancel_work_sync(&hdev->cmd_sync_work); in hci_cmd_sync_clear()
644 cancel_work_sync(&hdev->reenable_adv_work); in hci_cmd_sync_clear()
646 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) { in hci_cmd_sync_clear()
647 if (entry->destroy) in hci_cmd_sync_clear()
648 entry->destroy(hdev, entry->data, -ECANCELED); in hci_cmd_sync_clear()
650 list_del(&entry->list); in hci_cmd_sync_clear()
659 if (hdev->req_status == HCI_REQ_PEND) { in __hci_cmd_sync_cancel()
660 hdev->req_result = err; in __hci_cmd_sync_cancel()
661 hdev->req_status = HCI_REQ_CANCELED; in __hci_cmd_sync_cancel()
663 cancel_delayed_work_sync(&hdev->cmd_timer); in __hci_cmd_sync_cancel()
664 cancel_delayed_work_sync(&hdev->ncmd_timer); in __hci_cmd_sync_cancel()
665 atomic_set(&hdev->cmd_cnt, 1); in __hci_cmd_sync_cancel()
667 wake_up_interruptible(&hdev->req_wait_q); in __hci_cmd_sync_cancel()
675 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel()
676 hdev->req_result = err; in hci_cmd_sync_cancel()
677 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel()
679 queue_work(hdev->workqueue, &hdev->cmd_sync_cancel_work); in hci_cmd_sync_cancel()
690 return -ENODEV; in hci_cmd_sync_queue()
694 return -ENOMEM; in hci_cmd_sync_queue()
696 entry->func = func; in hci_cmd_sync_queue()
697 entry->data = data; in hci_cmd_sync_queue()
698 entry->destroy = destroy; in hci_cmd_sync_queue()
700 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_queue()
701 list_add_tail(&entry->list, &hdev->cmd_sync_work_list); in hci_cmd_sync_queue()
702 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_queue()
704 queue_work(hdev->req_workqueue, &hdev->cmd_sync_work); in hci_cmd_sync_queue()
732 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in hci_update_eir_sync()
735 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in hci_update_eir_sync()
746 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
747 val |= uuid->svc_hint; in get_service_classes()
767 cod[0] = hdev->minor_class; in hci_update_class_sync()
768 cod[1] = hdev->major_class; in hci_update_class_sync()
774 if (memcmp(cod, hdev->dev_class, 3) == 0) in hci_update_class_sync()
788 if (hdev->conn_hash.le_num_peripheral > 0) { in is_advertising_allowed()
792 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
798 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
799 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
804 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_peripheral) { in is_advertising_allowed()
806 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
812 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
813 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
888 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address_sync()
894 err = hci_set_random_addr_sync(hdev, &hdev->rpa); in hci_update_random_address_sync()
902 * use an non-resolvable private address. This is useful for active in hci_update_random_address_sync()
903 * scanning and non-connectable advertising. in hci_update_random_address_sync()
909 /* The non-resolvable private address is generated in hci_update_random_address_sync()
916 /* The non-resolvable private address shall not be in hci_update_random_address_sync()
919 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address_sync()
933 * In case BR/EDR has been disabled on a dual-mode controller in hci_update_random_address_sync()
938 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address_sync()
940 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address_sync()
942 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address_sync()
944 &hdev->static_addr); in hci_update_random_address_sync()
969 return -EINVAL; in hci_disable_ext_adv_instance_sync()
972 if (!adv->enabled) in hci_disable_ext_adv_instance_sync()
979 set = (void *)cp->data; in hci_disable_ext_adv_instance_sync()
982 cp->num_of_sets = !!instance; in hci_disable_ext_adv_instance_sync()
983 cp->enable = 0x00; in hci_disable_ext_adv_instance_sync()
985 set->handle = instance; in hci_disable_ext_adv_instance_sync()
987 size = sizeof(*cp) + sizeof(*set) * cp->num_of_sets; in hci_disable_ext_adv_instance_sync()
1001 * hdev->random_addr to track its address so whenever it needs in hci_set_adv_set_random_addr_sync()
1003 * hdev->random_addr is shared with scan state machine. in hci_set_adv_set_random_addr_sync()
1033 return -EINVAL; in hci_setup_ext_adv_instance_sync()
1042 if (adv && !adv->pending) { in hci_setup_ext_adv_instance_sync()
1057 return -EPERM; in hci_setup_ext_adv_instance_sync()
1059 /* Set require_privacy to true only when non-connectable in hci_setup_ext_adv_instance_sync()
1061 * non-resolvable private address. in hci_setup_ext_adv_instance_sync()
1072 hci_cpu_to_le24(adv->min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1073 hci_cpu_to_le24(adv->max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1074 cp.tx_power = adv->tx_power; in hci_setup_ext_adv_instance_sync()
1076 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1077 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1113 cp.channel_map = hdev->le_adv_channel_map; in hci_setup_ext_adv_instance_sync()
1138 if (!bacmp(&random_addr, &adv->random_addr)) in hci_setup_ext_adv_instance_sync()
1141 if (!bacmp(&random_addr, &hdev->random_addr)) in hci_setup_ext_adv_instance_sync()
1166 if (!adv || !adv->scan_rsp_changed) in hci_set_ext_scan_rsp_data_sync()
1184 adv->scan_rsp_changed = false; in hci_set_ext_scan_rsp_data_sync()
1186 memcpy(hdev->scan_rsp_data, pdu.data, len); in hci_set_ext_scan_rsp_data_sync()
1187 hdev->scan_rsp_data_len = len; in hci_set_ext_scan_rsp_data_sync()
1202 if (hdev->scan_rsp_data_len == len && in __hci_set_scan_rsp_data_sync()
1203 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_set_scan_rsp_data_sync()
1206 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_set_scan_rsp_data_sync()
1207 hdev->scan_rsp_data_len = len; in __hci_set_scan_rsp_data_sync()
1236 return -EINVAL; in hci_enable_ext_advertising_sync()
1238 if (adv->enabled) in hci_enable_ext_advertising_sync()
1245 set = (void *)cp->data; in hci_enable_ext_advertising_sync()
1249 cp->enable = 0x01; in hci_enable_ext_advertising_sync()
1250 cp->num_of_sets = 0x01; in hci_enable_ext_advertising_sync()
1254 set->handle = instance; in hci_enable_ext_advertising_sync()
1259 if (adv && adv->timeout) { in hci_enable_ext_advertising_sync()
1260 u16 duration = adv->timeout * MSEC_PER_SEC; in hci_enable_ext_advertising_sync()
1263 set->duration = cpu_to_le16(duration / 10); in hci_enable_ext_advertising_sync()
1268 sizeof(*set) * cp->num_of_sets, in hci_enable_ext_advertising_sync()
1339 if (!adv || !adv->periodic) in hci_set_per_adv_data_sync()
1389 if (!eir_get_service_data(adv->per_adv_data, adv->per_adv_data_len, in hci_adv_bcast_annoucement()
1397 if (eir_get_service_data(adv->adv_data, adv->adv_data_len, 0x1852, in hci_adv_bcast_annoucement()
1404 hci_set_adv_instance_data(hdev, adv->instance, sizeof(ad), ad, 0, NULL); in hci_adv_bcast_annoucement()
1406 return hci_update_adv_data_sync(hdev, adv->instance); in hci_adv_bcast_annoucement()
1498 hdev->cur_adv_instance); in hci_enable_advertising_sync()
1500 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1501 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1510 return -EINVAL; in hci_enable_advertising_sync()
1523 /* Set require_privacy to true only when non-connectable in hci_enable_advertising_sync()
1525 * non-resolvable private address. in hci_enable_advertising_sync()
1536 adv_min_interval = adv_instance->min_interval; in hci_enable_advertising_sync()
1537 adv_max_interval = adv_instance->max_interval; in hci_enable_advertising_sync()
1539 adv_min_interval = hdev->le_adv_min_interval; in hci_enable_advertising_sync()
1540 adv_max_interval = hdev->le_adv_max_interval; in hci_enable_advertising_sync()
1546 if (hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance)) in hci_enable_advertising_sync()
1561 cp.channel_map = hdev->le_adv_channel_map; in hci_enable_advertising_sync()
1580 list_empty(&hdev->adv_instances)) in hci_enable_advertising()
1600 return -EINVAL; in hci_remove_ext_adv_instance_sync()
1613 instance = adv->instance; in remove_ext_adv_sync()
1625 return -EINVAL; in hci_remove_ext_adv_instance()
1657 if (!adv || !adv->adv_data_changed) in hci_set_ext_adv_data_sync()
1676 adv->adv_data_changed = false; in hci_set_ext_adv_data_sync()
1678 memcpy(hdev->adv_data, pdu.data, len); in hci_set_ext_adv_data_sync()
1679 hdev->adv_data_len = len; in hci_set_ext_adv_data_sync()
1695 if (hdev->adv_data_len == len && in hci_set_adv_data_sync()
1696 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_set_adv_data_sync()
1699 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_set_adv_data_sync()
1700 hdev->adv_data_len = len; in hci_set_adv_data_sync()
1726 return -EPERM; in hci_schedule_adv_instance_sync()
1728 if (hdev->adv_instance_timeout) in hci_schedule_adv_instance_sync()
1729 return -EBUSY; in hci_schedule_adv_instance_sync()
1733 return -ENOENT; in hci_schedule_adv_instance_sync()
1743 if (adv->timeout == 0 || adv->duration <= adv->remaining_time) in hci_schedule_adv_instance_sync()
1744 timeout = adv->duration; in hci_schedule_adv_instance_sync()
1746 timeout = adv->remaining_time; in hci_schedule_adv_instance_sync()
1751 if (adv->timeout) in hci_schedule_adv_instance_sync()
1752 adv->remaining_time = adv->remaining_time - timeout; in hci_schedule_adv_instance_sync()
1756 hdev->adv_instance_timeout = timeout; in hci_schedule_adv_instance_sync()
1757 queue_delayed_work(hdev->req_workqueue, in hci_schedule_adv_instance_sync()
1758 &hdev->adv_instance_expire, in hci_schedule_adv_instance_sync()
1762 /* If we're just re-scheduling the same instance again then do not in hci_schedule_adv_instance_sync()
1766 if (!force && hdev->cur_adv_instance == instance && in hci_schedule_adv_instance_sync()
1770 hdev->cur_adv_instance = instance; in hci_schedule_adv_instance_sync()
1807 /* Cleanup non-ext instances */ in hci_clear_adv_sync()
1808 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in hci_clear_adv_sync()
1809 u8 instance = adv->instance; in hci_clear_adv_sync()
1812 if (!(force || adv->timeout)) in hci_clear_adv_sync()
1851 * - force == true: The instance will be removed even when its remaining
1853 * - force == false: the instance will be deactivated but kept stored unless
1857 * - force == true: All instances will be removed regardless of their timeout
1859 * - force == false: Only instances that have a timeout will be removed.
1868 if (!instance || hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1875 if (hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1885 if (force || (adv && adv->timeout && !adv->remaining_time)) { in hci_remove_advertising_sync()
1887 if (next && next->instance == instance) in hci_remove_advertising_sync()
1900 hci_schedule_adv_instance_sync(hdev, next->instance, false); in hci_remove_advertising_sync()
2006 if (hdev->scanning_paused) { in hci_scan_disable_sync()
2027 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_start_interleave_scan()
2028 queue_delayed_work(hdev->req_workqueue, in hci_start_interleave_scan()
2029 &hdev->interleave_scan, 0); in hci_start_interleave_scan()
2034 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
2041 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
2043 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
2052 * - There is at least one ADV monitor in hci_update_interleaved_scan_sync()
2053 * - At least one pending LE connection or one device to be scanned for in hci_update_interleaved_scan_sync()
2054 * - Monitor offloading is not supported in hci_update_interleaved_scan_sync()
2059 !(list_empty(&hdev->pend_le_conns) && in hci_update_interleaved_scan_sync()
2060 list_empty(&hdev->pend_le_reports)) && in hci_update_interleaved_scan_sync()
2088 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, in hci_le_del_resolve_list_sync()
2107 if (!hci_bdaddr_list_lookup(&hdev->le_accept_list, bdaddr, bdaddr_type)) in hci_le_del_accept_list_sync()
2132 * Setting params to NULL programs local hdev->irk
2152 memcpy(cp.peer_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2156 irk = hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2161 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, in hci_le_add_resolve_list_sync()
2162 ¶ms->addr, in hci_le_add_resolve_list_sync()
2163 params->addr_type); in hci_le_add_resolve_list_sync()
2167 cp.bdaddr_type = params->addr_type; in hci_le_add_resolve_list_sync()
2168 bacpy(&cp.bdaddr, ¶ms->addr); in hci_le_add_resolve_list_sync()
2169 memcpy(cp.peer_irk, irk->val, 16); in hci_le_add_resolve_list_sync()
2172 params->privacy_mode = HCI_NETWORK_PRIVACY; in hci_le_add_resolve_list_sync()
2176 memcpy(cp.local_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2192 if (params->privacy_mode == HCI_DEVICE_PRIVACY) in hci_le_set_privacy_mode_sync()
2199 if (!(params->flags & HCI_CONN_FLAG_DEVICE_PRIVACY)) in hci_le_set_privacy_mode_sync()
2202 irk = hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type); in hci_le_set_privacy_mode_sync()
2207 cp.bdaddr_type = irk->addr_type; in hci_le_set_privacy_mode_sync()
2208 bacpy(&cp.bdaddr, &irk->bdaddr); in hci_le_set_privacy_mode_sync()
2227 if (hdev->suspended && in hci_le_add_accept_list_sync()
2228 !(params->flags & HCI_CONN_FLAG_REMOTE_WAKEUP)) in hci_le_add_accept_list_sync()
2232 if (*num_entries >= hdev->le_accept_list_size) in hci_le_add_accept_list_sync()
2233 return -ENOSPC; in hci_le_add_accept_list_sync()
2237 hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) in hci_le_add_accept_list_sync()
2238 return -EINVAL; in hci_le_add_accept_list_sync()
2258 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, ¶ms->addr, in hci_le_add_accept_list_sync()
2259 params->addr_type)) in hci_le_add_accept_list_sync()
2263 cp.bdaddr_type = params->addr_type; in hci_le_add_accept_list_sync()
2264 bacpy(&cp.bdaddr, ¶ms->addr); in hci_le_add_accept_list_sync()
2288 if (hdev->advertising_paused) in hci_pause_advertising_sync()
2303 hdev->discov_timeout = 0; in hci_pause_advertising_sync()
2319 hdev->advertising_paused = true; in hci_pause_advertising_sync()
2320 hdev->advertising_old_state = old_state; in hci_pause_advertising_sync()
2332 if (!hdev->advertising_paused) in hci_resume_advertising_sync()
2336 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2337 if (hdev->advertising_old_state) { in hci_resume_advertising_sync()
2339 hdev->advertising_old_state = 0; in hci_resume_advertising_sync()
2345 /* Call for each tracked instance to be re-enabled */ in hci_resume_advertising_sync()
2346 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) { in hci_resume_advertising_sync()
2348 adv->instance); in hci_resume_advertising_sync()
2353 hci_remove_ext_adv_instance_sync(hdev, adv->instance, in hci_resume_advertising_sync()
2361 hdev->cur_adv_instance, in hci_resume_advertising_sync()
2365 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2383 * use_ll_privacy((Disable Advertising) -> Disable Resolving List) ->
2384 * Remove Devices From Accept List ->
2385 * (has IRK && use_ll_privacy(Remove Devices From Resolving List))->
2386 * Add Devices to Accept List ->
2387 * (has IRK && use_ll_privacy(Remove Devices From Resolving List)) ->
2388 * use_ll_privacy(Enable Resolving List -> (Enable Advertising)) ->
2432 list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { in hci_update_accept_list_sync()
2433 if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) in hci_update_accept_list_sync()
2436 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_update_accept_list_sync()
2437 &b->bdaddr, in hci_update_accept_list_sync()
2438 b->bdaddr_type); in hci_update_accept_list_sync()
2439 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_update_accept_list_sync()
2440 &b->bdaddr, in hci_update_accept_list_sync()
2441 b->bdaddr_type); in hci_update_accept_list_sync()
2447 hci_le_del_accept_list_sync(hdev, &b->bdaddr, in hci_update_accept_list_sync()
2448 b->bdaddr_type); in hci_update_accept_list_sync()
2465 list_for_each_entry(params, &hdev->pend_le_conns, action) { in hci_update_accept_list_sync()
2475 list_for_each_entry(params, &hdev->pend_le_reports, action) { in hci_update_accept_list_sync()
2482 * - We are not currently suspending in hci_update_accept_list_sync()
2483 * - There are 1 or more ADV monitors registered and it's not offloaded in hci_update_accept_list_sync()
2484 * - Interleaved scanning is not currently using the allowlist in hci_update_accept_list_sync()
2486 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in hci_update_accept_list_sync()
2488 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in hci_update_accept_list_sync()
2489 err = -EINVAL; in hci_update_accept_list_sync()
2510 struct hci_conn_hash *h = &hdev->conn_hash; in hci_is_le_conn_scanning()
2515 list_for_each_entry_rcu(c, &h->list, list) { in hci_is_le_conn_scanning()
2516 if (c->type == LE_LINK && c->state == BT_CONNECT && in hci_is_le_conn_scanning()
2517 test_bit(HCI_CONN_SCANNING, &c->flags)) { in hci_is_le_conn_scanning()
2538 phy = (void *)cp->data; in hci_le_set_ext_scan_param_sync()
2542 cp->own_addr_type = own_addr_type; in hci_le_set_ext_scan_param_sync()
2543 cp->filter_policy = filter_policy; in hci_le_set_ext_scan_param_sync()
2546 cp->scanning_phys |= LE_SCAN_PHY_1M; in hci_le_set_ext_scan_param_sync()
2548 phy->type = type; in hci_le_set_ext_scan_param_sync()
2549 phy->interval = cpu_to_le16(interval); in hci_le_set_ext_scan_param_sync()
2550 phy->window = cpu_to_le16(window); in hci_le_set_ext_scan_param_sync()
2557 cp->scanning_phys |= LE_SCAN_PHY_CODED; in hci_le_set_ext_scan_param_sync()
2559 phy->type = type; in hci_le_set_ext_scan_param_sync()
2560 phy->interval = cpu_to_le16(interval); in hci_le_set_ext_scan_param_sync()
2561 phy->window = cpu_to_le16(window); in hci_le_set_ext_scan_param_sync()
2600 if (hdev->scanning_paused) { in hci_start_scan_sync()
2621 if (hdev->scanning_paused) { in hci_passive_scan_sync()
2633 * during passive scanning. Not using an non-resolvable address in hci_passive_scan_sync()
2642 if (hdev->enable_advmon_interleave_scan && in hci_passive_scan_sync()
2646 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_passive_scan_sync()
2664 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_passive_scan_sync()
2667 if (hdev->suspended) { in hci_passive_scan_sync()
2668 window = hdev->le_scan_window_suspend; in hci_passive_scan_sync()
2669 interval = hdev->le_scan_int_suspend; in hci_passive_scan_sync()
2671 window = hdev->le_scan_window_connect; in hci_passive_scan_sync()
2672 interval = hdev->le_scan_int_connect; in hci_passive_scan_sync()
2674 window = hdev->le_scan_window_adv_monitor; in hci_passive_scan_sync()
2675 interval = hdev->le_scan_int_adv_monitor; in hci_passive_scan_sync()
2677 window = hdev->le_scan_window; in hci_passive_scan_sync()
2678 interval = hdev->le_scan_interval; in hci_passive_scan_sync()
2693 /* This function controls the passive scanning based on hdev->pend_le_conns
2699 * Disable Scanning -> Update Accept List ->
2700 * use_ll_privacy((Disable Advertising) -> Disable Resolving List ->
2701 * Update Resolving List -> Enable Resolving List -> (Enable Advertising)) ->
2712 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan_sync()
2713 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan_sync()
2725 if (hdev->discovery.state != DISCOVERY_STOPPED) in hci_update_passive_scan_sync()
2741 list_empty(&hdev->pend_le_conns) && in hci_update_passive_scan_sync()
2742 list_empty(&hdev->pend_le_reports) && in hci_update_passive_scan_sync()
2797 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan()
2798 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan()
2820 hdev->features[1][0] |= LMP_HOST_SC; in hci_write_sc_support_sync()
2823 hdev->features[1][0] &= ~LMP_HOST_SC; in hci_write_sc_support_sync()
2899 list_empty(&hdev->adv_instances)) { in hci_powered_update_adv_sync()
2915 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) in hci_powered_update_adv_sync()
2916 hci_schedule_adv_instance_sync(hdev, adv->instance, true); in hci_powered_update_adv_sync()
2926 if (link_sec == test_bit(HCI_AUTH, &hdev->flags)) in hci_write_auth_enable_sync()
2943 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_write_fast_connectable_sync()
2954 type = hdev->def_page_scan_type; in hci_write_fast_connectable_sync()
2955 cp.interval = cpu_to_le16(hdev->def_page_scan_int); in hci_write_fast_connectable_sync()
2958 cp.window = cpu_to_le16(hdev->def_page_scan_window); in hci_write_fast_connectable_sync()
2960 if (__cpu_to_le16(hdev->page_scan_interval) != cp.interval || in hci_write_fast_connectable_sync()
2961 __cpu_to_le16(hdev->page_scan_window) != cp.window) { in hci_write_fast_connectable_sync()
2969 if (hdev->page_scan_type != type) in hci_write_fast_connectable_sync()
2982 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
2985 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
2989 if (conn->state != BT_CONNECTED && conn->state != BT_CONFIG) in disconnected_accept_list_entries()
3016 if (hdev->scanning_paused) in hci_update_scan_sync()
3028 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in hci_update_scan_sync()
3029 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in hci_update_scan_sync()
3041 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in hci_update_name_sync()
3053 * HCI_LE_ENABLED(use_ll_privacy(Add local IRK to Resolving List) ->
3056 * lmp_bredr_capable(Set Fast Connectable -> Set Scan Type -> Set Class ->
3057 * Set Name -> Set EIR)
3101 * hci_dev_get_bd_addr_from_property - Get the Bluetooth Device Address
3106 * Search the firmware node for 'local-bd-address'.
3108 * All-zero BD addresses are rejected, because those could be properties
3110 * example, the DTS could define 'local-bd-address', with zero BD addresses.
3114 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
3118 ret = fwnode_property_read_u8_array(fwnode, "local-bd-address", in hci_dev_get_bd_addr_from_property()
3123 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3178 set_bit(HCI_RESET, &hdev->flags); in hci_reset_sync()
3195 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init0_sync()
3208 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_unconf_init_sync()
3225 if (hdev->dev_type == HCI_AMP && !(hdev->commands[14] & 0x20)) in hci_read_local_features_sync()
3254 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_read_local_cmds_sync()
3255 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_read_local_cmds_sync()
3313 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init1_sync()
3319 switch (hdev->dev_type) { in hci_init1_sync()
3321 hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_PACKET_BASED; in hci_init1_sync()
3324 hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED; in hci_init1_sync()
3327 bt_dev_err(hdev, "Unknown device type %d", hdev->dev_type); in hci_init1_sync()
3391 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_set_event_filter_sync()
3418 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_clear_event_filter_sync()
3468 hdev->max_page = 0x01; in hci_write_ssp_mode_1_sync()
3481 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_write_eir_sync()
3493 !test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_write_inquiry_mode_sync()
3557 if (hdev->commands[41] & 0x20) in hci_le_read_buffer_size_sync()
3597 if (hdev->dev_type == HCI_AMP) in hci_init2_sync()
3616 /* LE-only controllers have LE implicitly enabled */ in hci_init2_sync()
3635 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_set_event_mask_sync()
3645 if (hdev->suspended) in hci_set_event_mask_sync()
3648 /* Use a different default for LE-only devices */ in hci_set_event_mask_sync()
3658 if (hdev->commands[0] & 0x20) { in hci_set_event_mask_sync()
3663 if (!hdev->suspended) in hci_set_event_mask_sync()
3672 if (hdev->commands[2] & 0x80) in hci_set_event_mask_sync()
3677 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_set_event_mask_sync()
3684 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_set_event_mask_sync()
3725 events[7] |= 0x20; /* LE Meta-Event */ in hci_set_event_mask_sync()
3735 if (!(hdev->commands[6] & 0x20) || in hci_read_stored_link_key_sync()
3736 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_read_stored_link_key_sync()
3752 if (!(hdev->commands[5] & 0x10)) in hci_setup_link_policy_sync()
3774 if (!(hdev->commands[8] & 0x01)) in hci_read_page_scan_activity_sync()
3783 if (!(hdev->commands[18] & 0x04) || in hci_read_def_err_data_reporting_sync()
3784 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_read_def_err_data_reporting_sync()
3785 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_read_def_err_data_reporting_sync()
3798 if (!(hdev->commands[13] & 0x01)) in hci_read_page_scan_type_sync()
3814 for (page = 2; page < HCI_MAX_PAGES && page <= hdev->max_page; in hci_read_local_ext_features_all_sync()
3852 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_le_set_event_mask_sync()
3858 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_le_set_event_mask_sync()
3865 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_le_set_event_mask_sync()
3877 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_le_set_event_mask_sync()
3883 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_le_set_event_mask_sync()
3889 if (hdev->commands[26] & 0x08) in hci_le_set_event_mask_sync()
3895 if (hdev->commands[26] & 0x10) in hci_le_set_event_mask_sync()
3901 if (hdev->commands[27] & 0x04) in hci_le_set_event_mask_sync()
3907 if (hdev->commands[27] & 0x20) in hci_le_set_event_mask_sync()
3911 /* If the controller supports the LE Read Local P-256 in hci_le_set_event_mask_sync()
3914 if (hdev->commands[34] & 0x02) in hci_le_set_event_mask_sync()
3915 /* LE Read Local P-256 Public Key Complete */ in hci_le_set_event_mask_sync()
3921 if (hdev->commands[34] & 0x04) in hci_le_set_event_mask_sync()
3927 if (hdev->commands[35] & (0x20 | 0x40)) in hci_le_set_event_mask_sync()
3963 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_le_read_adv_tx_power_sync()
3981 if (!(hdev->commands[38] & 0x80) || in hci_le_read_tx_power_sync()
3982 test_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks)) in hci_le_read_tx_power_sync()
3992 if (!(hdev->commands[26] & 0x40)) in hci_le_read_accept_list_size_sync()
4002 if (!(hdev->commands[26] & 0x80)) in hci_le_clear_accept_list_sync()
4012 if (!(hdev->commands[34] & 0x40)) in hci_le_read_resolv_list_size_sync()
4022 if (!(hdev->commands[34] & 0x20)) in hci_le_clear_resolv_list_sync()
4032 __le16 timeout = cpu_to_le16(hdev->rpa_timeout); in hci_le_set_rpa_timeout_sync()
4034 if (!(hdev->commands[35] & 0x04)) in hci_le_set_rpa_timeout_sync()
4045 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_max_data_len_sync()
4055 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_def_data_len_sync()
4078 /* LE-only devices do not support explicit enablement */ in hci_set_le_support_sync()
4178 if (!(hdev->commands[6] & 0x80) || in hci_delete_stored_link_key_sync()
4179 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_delete_stored_link_key_sync()
4196 if (!(hdev->commands[22] & 0x04)) in hci_set_event_mask_page_2_sync()
4206 events[2] |= 0x20; /* CPB Channel Map Change */ in hci_set_event_mask_page_2_sync()
4215 events[2] |= 0x02; /* CPB Receive */ in hci_set_event_mask_page_2_sync()
4216 events[2] |= 0x04; /* CPB Timeout */ in hci_set_event_mask_page_2_sync()
4222 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2_sync()
4240 /* Read local codec list if the HCI command is supported */
4243 if (hdev->commands[45] & 0x04) in hci_read_local_codecs_sync()
4245 else if (hdev->commands[29] & 0x20) in hci_read_local_codecs_sync()
4254 if (!(hdev->commands[41] & 0x08)) in hci_read_local_pairing_opts_sync()
4264 if (!(hdev->commands[30] & 0x08)) in hci_get_mws_transport_config_sync()
4303 if (!(hdev->commands[18] & 0x08) || in hci_set_err_data_report_sync()
4304 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_set_err_data_report_sync()
4305 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_set_err_data_report_sync()
4308 if (enabled == hdev->err_data_reporting) in hci_set_err_data_report_sync()
4344 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_set_write_def_data_len_sync()
4348 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_le_set_write_def_data_len_sync()
4349 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_le_set_write_def_data_len_sync()
4360 if (!(hdev->commands[35] & 0x20)) in hci_le_set_default_phy_sync()
4365 cp.tx_phys = hdev->le_tx_def_phys; in hci_le_set_default_phy_sync()
4366 cp.rx_phys = hdev->le_rx_def_phys; in hci_le_set_default_phy_sync()
4411 /* HCI_PRIMARY covers both single-mode LE, BR/EDR and dual-mode in hci_init_sync()
4415 if (hdev->dev_type != HCI_PRIMARY) in hci_init_sync()
4479 * Calls hdev->setup
4489 !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) in hci_dev_setup_sync()
4496 if (hdev->setup) in hci_dev_setup_sync()
4497 ret = hdev->setup(hdev); in hci_dev_setup_sync()
4500 if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) in hci_dev_setup_sync()
4508 invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); in hci_dev_setup_sync()
4511 if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { in hci_dev_setup_sync()
4512 if (!bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_setup_sync()
4515 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_setup_sync()
4516 hdev->set_bdaddr) { in hci_dev_setup_sync()
4517 ret = hdev->set_bdaddr(hdev, in hci_dev_setup_sync()
4518 &hdev->public_addr); in hci_dev_setup_sync()
4541 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_setup_sync()
4570 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_init_sync()
4571 set_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4581 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_init_sync()
4582 hdev->set_bdaddr) in hci_dev_init_sync()
4583 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_init_sync()
4585 ret = -EADDRNOTAVAIL; in hci_dev_init_sync()
4592 if (!ret && hdev->post_init) in hci_dev_init_sync()
4593 ret = hdev->post_init(hdev); in hci_dev_init_sync()
4601 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_init_sync()
4603 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_init_sync()
4604 ret = hdev->set_diag(hdev, true); in hci_dev_init_sync()
4611 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4623 ret = -ENODEV; in hci_dev_open_sync()
4633 ret = -ERFKILL; in hci_dev_open_sync()
4650 hdev->dev_type == HCI_PRIMARY && in hci_dev_open_sync()
4651 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_open_sync()
4652 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_open_sync()
4653 ret = -EADDRNOTAVAIL; in hci_dev_open_sync()
4658 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open_sync()
4659 ret = -EALREADY; in hci_dev_open_sync()
4663 if (hdev->open(hdev)) { in hci_dev_open_sync()
4664 ret = -EIO; in hci_dev_open_sync()
4668 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4676 set_bit(HCI_UP, &hdev->flags); in hci_dev_open_sync()
4684 hdev->dev_type == HCI_PRIMARY) { in hci_dev_open_sync()
4690 flush_work(&hdev->tx_work); in hci_dev_open_sync()
4696 flush_work(&hdev->rx_work); in hci_dev_open_sync()
4697 flush_work(&hdev->cmd_work); in hci_dev_open_sync()
4699 skb_queue_purge(&hdev->cmd_q); in hci_dev_open_sync()
4700 skb_queue_purge(&hdev->rx_q); in hci_dev_open_sync()
4702 if (hdev->flush) in hci_dev_open_sync()
4703 hdev->flush(hdev); in hci_dev_open_sync()
4705 if (hdev->sent_cmd) { in hci_dev_open_sync()
4706 kfree_skb(hdev->sent_cmd); in hci_dev_open_sync()
4707 hdev->sent_cmd = NULL; in hci_dev_open_sync()
4710 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4713 hdev->close(hdev); in hci_dev_open_sync()
4714 hdev->flags &= BIT(HCI_RAW); in hci_dev_open_sync()
4721 /* This function requires the caller holds hdev->lock */
4726 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
4727 if (p->conn) { in hci_pend_le_actions_clear()
4728 hci_conn_drop(p->conn); in hci_pend_le_actions_clear()
4729 hci_conn_put(p->conn); in hci_pend_le_actions_clear()
4730 p->conn = NULL; in hci_pend_le_actions_clear()
4732 list_del_init(&p->action); in hci_pend_le_actions_clear()
4751 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_shutdown()
4753 if (hdev->shutdown) in hci_dev_shutdown()
4754 err = hdev->shutdown(hdev); in hci_dev_shutdown()
4770 cancel_delayed_work(&hdev->power_off); in hci_dev_close_sync()
4771 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
4772 cancel_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
4773 cancel_delayed_work(&hdev->le_scan_restart); in hci_dev_close_sync()
4777 if (hdev->adv_instance_timeout) { in hci_dev_close_sync()
4778 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_dev_close_sync()
4779 hdev->adv_instance_timeout = 0; in hci_dev_close_sync()
4784 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_close_sync()
4785 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
4792 flush_work(&hdev->tx_work); in hci_dev_close_sync()
4793 flush_work(&hdev->rx_work); in hci_dev_close_sync()
4795 if (hdev->discov_timeout > 0) { in hci_dev_close_sync()
4796 hdev->discov_timeout = 0; in hci_dev_close_sync()
4802 cancel_delayed_work(&hdev->service_cache); in hci_dev_close_sync()
4807 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_close_sync()
4809 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_close_sync()
4810 cancel_delayed_work_sync(&adv_instance->rpa_expired_cb); in hci_dev_close_sync()
4816 drain_workqueue(hdev->workqueue); in hci_dev_close_sync()
4824 if (!auto_off && hdev->dev_type == HCI_PRIMARY && in hci_dev_close_sync()
4832 /* Prevent data races on hdev->smp_data or hdev->smp_bredr_data */ in hci_dev_close_sync()
4843 if (hdev->flush) in hci_dev_close_sync()
4844 hdev->flush(hdev); in hci_dev_close_sync()
4847 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
4848 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_close_sync()
4849 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_close_sync()
4851 set_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
4853 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
4857 flush_work(&hdev->cmd_work); in hci_dev_close_sync()
4860 skb_queue_purge(&hdev->rx_q); in hci_dev_close_sync()
4861 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
4862 skb_queue_purge(&hdev->raw_q); in hci_dev_close_sync()
4865 if (hdev->sent_cmd) { in hci_dev_close_sync()
4866 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
4867 kfree_skb(hdev->sent_cmd); in hci_dev_close_sync()
4868 hdev->sent_cmd = NULL; in hci_dev_close_sync()
4871 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_close_sync()
4875 hdev->close(hdev); in hci_dev_close_sync()
4878 hdev->flags &= BIT(HCI_RAW); in hci_dev_close_sync()
4882 hdev->amp_status = AMP_STATUS_POWERED_DOWN; in hci_dev_close_sync()
4884 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_close_sync()
4885 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_close_sync()
4886 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_close_sync()
4902 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on_sync()
4905 cancel_delayed_work(&hdev->power_off); in hci_power_on_sync()
4919 (hdev->dev_type == HCI_PRIMARY && in hci_power_on_sync()
4920 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on_sync()
4921 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on_sync()
4925 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on_sync()
4934 set_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
4949 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
4974 struct discovery_state *d = &hdev->discovery; in hci_stop_discovery_sync()
4978 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_stop_discovery_sync()
4980 if (d->state == DISCOVERY_FINDING || d->state == DISCOVERY_STOPPING) { in hci_stop_discovery_sync()
4981 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_stop_discovery_sync()
4989 cancel_delayed_work(&hdev->le_scan_disable); in hci_stop_discovery_sync()
4990 cancel_delayed_work(&hdev->le_scan_restart); in hci_stop_discovery_sync()
5007 /* No further actions needed for LE-only discovery */ in hci_stop_discovery_sync()
5008 if (d->type == DISCOV_TYPE_LE) in hci_stop_discovery_sync()
5011 if (d->state == DISCOVERY_RESOLVING || d->state == DISCOVERY_STOPPING) { in hci_stop_discovery_sync()
5017 return hci_remote_name_cancel_sync(hdev, &e->data.bdaddr); in hci_stop_discovery_sync()
5041 if (conn->type == AMP_LINK) in hci_disconnect_sync()
5042 return hci_disconnect_phy_link_sync(hdev, conn->handle, reason); in hci_disconnect_sync()
5045 cp.handle = cpu_to_le16(conn->handle); in hci_disconnect_sync()
5051 if (!hdev->suspended) in hci_disconnect_sync()
5064 if (test_bit(HCI_CONN_SCANNING, &conn->flags)) in hci_le_connect_cancel_sync()
5068 6, &conn->dst, HCI_CMD_TIMEOUT); in hci_le_connect_cancel_sync()
5073 if (conn->type == LE_LINK) in hci_connect_cancel_sync()
5076 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_connect_cancel_sync()
5080 6, &conn->dst, HCI_CMD_TIMEOUT); in hci_connect_cancel_sync()
5089 bacpy(&cp.bdaddr, &conn->dst); in hci_reject_sco_sync()
5093 * allowed error values (0x0D-0x0F). in hci_reject_sco_sync()
5107 if (conn->type == SCO_LINK || conn->type == ESCO_LINK) in hci_reject_conn_sync()
5111 bacpy(&cp.bdaddr, &conn->dst); in hci_reject_conn_sync()
5122 switch (conn->state) { in hci_abort_conn_sync()
5140 conn->state = BT_CLOSED; in hci_abort_conn_sync()
5152 list_for_each_entry_safe(conn, tmp, &hdev->conn_hash.list, list) { in hci_disconnect_all_sync()
5173 if (!test_bit(HCI_UP, &hdev->flags)) in hci_power_off_sync()
5176 if (test_bit(HCI_ISCAN, &hdev->flags) || in hci_power_off_sync()
5177 test_bit(HCI_PSCAN, &hdev->flags)) { in hci_power_off_sync()
5218 cp.num_iac = min_t(u8, hdev->num_iac, 2); in hci_write_iac_sync()
5305 * by-product of disabling connectable, we need to update the in hci_update_connectable_sync()
5309 err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in hci_update_connectable_sync()
5313 !list_empty(&hdev->adv_instances)) { in hci_update_connectable_sync()
5316 hdev->cur_adv_instance); in hci_update_connectable_sync()
5344 if (hdev->discovery.limited) in hci_inquiry_sync()
5401 * address (when privacy feature has been enabled) or non-resolvable in hci_active_scan_sync()
5427 hdev->le_scan_window_discovery, in hci_active_scan_sync()
5448 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery * 2); in hci_start_interleaved_discovery_sync()
5460 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in hci_start_discovery_sync()
5462 switch (hdev->discovery.type) { in hci_start_discovery_sync()
5475 &hdev->quirks)) { in hci_start_discovery_sync()
5485 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in hci_start_discovery_sync()
5486 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5490 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5493 return -EINVAL; in hci_start_discovery_sync()
5506 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in hci_start_discovery_sync()
5507 hdev->discovery.result_filtering) { in hci_start_discovery_sync()
5508 hdev->discovery.scan_start = jiffies; in hci_start_discovery_sync()
5509 hdev->discovery.scan_duration = timeout; in hci_start_discovery_sync()
5512 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in hci_start_discovery_sync()
5531 int old_state = hdev->discovery.state; in hci_pause_discovery_sync()
5536 hdev->discovery_paused) in hci_pause_discovery_sync()
5544 hdev->discovery_paused = true; in hci_pause_discovery_sync()
5545 hdev->discovery_old_state = old_state; in hci_pause_discovery_sync()
5555 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_update_event_filter_sync()
5564 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_update_event_filter_sync()
5570 list_for_each_entry(b, &hdev->accept_list, list) { in hci_update_event_filter_sync()
5571 if (!(b->flags & HCI_CONN_FLAG_REMOTE_WAKEUP)) in hci_update_event_filter_sync()
5574 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_update_event_filter_sync()
5578 &b->bdaddr, in hci_update_event_filter_sync()
5582 &b->bdaddr); in hci_update_event_filter_sync()
5598 if (hdev->scanning_paused) in hci_pause_scan_sync()
5602 if (test_bit(HCI_PSCAN, &hdev->flags)) in hci_pause_scan_sync()
5607 hdev->scanning_paused = true; in hci_pause_scan_sync()
5630 if (hdev->suspended) in hci_suspend_sync()
5634 hdev->suspended = true; in hci_suspend_sync()
5645 /* Prevent disconnects from causing scanning to be re-enabled */ in hci_suspend_sync()
5653 hdev->suspend_state = BT_RUNNING; in hci_suspend_sync()
5667 if (!hdev->wakeup || !hdev->wakeup(hdev)) { in hci_suspend_sync()
5668 hdev->suspend_state = BT_SUSPEND_DISCONNECT; in hci_suspend_sync()
5673 hdev->scanning_paused = false; in hci_suspend_sync()
5682 hdev->scanning_paused = true; in hci_suspend_sync()
5684 hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; in hci_suspend_sync()
5695 if (!hdev->discovery_paused) in hci_resume_discovery_sync()
5698 hdev->discovery_paused = false; in hci_resume_discovery_sync()
5724 if (!hdev->scanning_paused) in hci_resume_scan_sync()
5727 hdev->scanning_paused = false; in hci_resume_scan_sync()
5748 if (!hdev->suspended) in hci_resume_sync()
5751 hdev->suspended = false; in hci_resume_sync()
5776 struct hci_dev *hdev = conn->hdev; in conn_use_rpa()
5806 cp.channel_map = hdev->le_adv_channel_map; in hci_le_ext_directed_advertising_sync()
5812 cp.peer_addr_type = conn->dst_type; in hci_le_ext_directed_advertising_sync()
5813 bacpy(&cp.peer_addr, &conn->dst); in hci_le_ext_directed_advertising_sync()
5835 bacmp(&random_addr, &hdev->random_addr)) { in hci_le_ext_directed_advertising_sync()
5882 cp.direct_addr_type = conn->dst_type; in hci_le_directed_advertising_sync()
5883 bacpy(&cp.direct_addr, &conn->dst); in hci_le_directed_advertising_sync()
5884 cp.channel_map = hdev->le_adv_channel_map; in hci_le_directed_advertising_sync()
5900 struct hci_dev *hdev = conn->hdev; in set_ext_conn_params()
5904 p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in set_ext_conn_params()
5905 p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); in set_ext_conn_params()
5906 p->conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); in set_ext_conn_params()
5907 p->conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); in set_ext_conn_params()
5908 p->conn_latency = cpu_to_le16(conn->le_conn_latency); in set_ext_conn_params()
5909 p->supervision_timeout = cpu_to_le16(conn->le_supv_timeout); in set_ext_conn_params()
5910 p->min_ce_len = cpu_to_le16(0x0000); in set_ext_conn_params()
5911 p->max_ce_len = cpu_to_le16(0x0000); in set_ext_conn_params()
5923 p = (void *)cp->data; in hci_le_ext_create_conn_sync()
5927 bacpy(&cp->peer_addr, &conn->dst); in hci_le_ext_create_conn_sync()
5928 cp->peer_addr_type = conn->dst_type; in hci_le_ext_create_conn_sync()
5929 cp->own_addr_type = own_addr_type; in hci_le_ext_create_conn_sync()
5934 cp->phys |= LE_SCAN_PHY_1M; in hci_le_ext_create_conn_sync()
5942 cp->phys |= LE_SCAN_PHY_2M; in hci_le_ext_create_conn_sync()
5950 cp->phys |= LE_SCAN_PHY_CODED; in hci_le_ext_create_conn_sync()
5959 conn->conn_timeout, NULL); in hci_le_ext_create_conn_sync()
5970 if (conn->role == HCI_ROLE_SLAVE) { in hci_le_create_conn_sync()
5975 hdev->le_scan_type == LE_SCAN_ACTIVE && in hci_le_create_conn_sync()
5978 return -EBUSY; in hci_le_create_conn_sync()
5992 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_create_conn_sync()
5994 conn->le_conn_min_interval = params->conn_min_interval; in hci_le_create_conn_sync()
5995 conn->le_conn_max_interval = params->conn_max_interval; in hci_le_create_conn_sync()
5996 conn->le_conn_latency = params->conn_latency; in hci_le_create_conn_sync()
5997 conn->le_supv_timeout = params->supervision_timeout; in hci_le_create_conn_sync()
5999 conn->le_conn_min_interval = hdev->le_conn_min_interval; in hci_le_create_conn_sync()
6000 conn->le_conn_max_interval = hdev->le_conn_max_interval; in hci_le_create_conn_sync()
6001 conn->le_conn_latency = hdev->le_conn_latency; in hci_le_create_conn_sync()
6002 conn->le_supv_timeout = hdev->le_supv_timeout; in hci_le_create_conn_sync()
6017 * that we never connect with an non-resolvable address. in hci_le_create_conn_sync()
6031 cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in hci_le_create_conn_sync()
6032 cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); in hci_le_create_conn_sync()
6034 bacpy(&cp.peer_addr, &conn->dst); in hci_le_create_conn_sync()
6035 cp.peer_addr_type = conn->dst_type; in hci_le_create_conn_sync()
6037 cp.conn_interval_min = cpu_to_le16(conn->le_conn_min_interval); in hci_le_create_conn_sync()
6038 cp.conn_interval_max = cpu_to_le16(conn->le_conn_max_interval); in hci_le_create_conn_sync()
6039 cp.conn_latency = cpu_to_le16(conn->le_conn_latency); in hci_le_create_conn_sync()
6040 cp.supervision_timeout = cpu_to_le16(conn->le_supv_timeout); in hci_le_create_conn_sync()
6055 conn->conn_timeout, NULL); in hci_le_create_conn_sync()
6058 /* Re-enable advertising after the connection attempt is finished. */ in hci_le_create_conn_sync()
6124 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
6130 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
6136 * use an non-resolvable private address. This is useful for in hci_get_random_address()
6137 * non-connectable advertising. in hci_get_random_address()
6143 /* The non-resolvable private address is generated in hci_get_random_address()
6150 /* The non-resolvable private address shall not be in hci_get_random_address()
6153 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
6183 return -ENOMEM; in hci_update_adv_data()