• Home
  • Raw
  • Download

Lines Matching refs:hdev

24 static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,  in hci_cmd_sync_complete()  argument
27 bt_dev_dbg(hdev, "result 0x%2.2x", result); in hci_cmd_sync_complete()
29 if (hdev->req_status != HCI_REQ_PEND) in hci_cmd_sync_complete()
32 hdev->req_result = result; in hci_cmd_sync_complete()
33 hdev->req_status = HCI_REQ_DONE; in hci_cmd_sync_complete()
36 kfree_skb(hdev->req_skb); in hci_cmd_sync_complete()
37 hdev->req_skb = NULL; in hci_cmd_sync_complete()
46 hdev->req_rsp = skb_get(skb); in hci_cmd_sync_complete()
49 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_complete()
52 static struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, in hci_cmd_sync_alloc() argument
71 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_cmd_sync_alloc()
90 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_add() local
93 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync_add()
101 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, sk); in hci_cmd_sync_add()
103 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_cmd_sync_add()
119 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_run() local
123 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in hci_cmd_sync_run()
141 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
142 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in hci_cmd_sync_run()
143 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
145 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_sync_run()
151 struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_sk() argument
159 bt_dev_dbg(hdev, "Opcode 0x%4.4x", opcode); in __hci_cmd_sync_sk()
161 hci_req_init(&req, hdev); in __hci_cmd_sync_sk()
165 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_sk()
171 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_sk()
172 hdev->req_status != HCI_REQ_PEND, in __hci_cmd_sync_sk()
178 switch (hdev->req_status) { in __hci_cmd_sync_sk()
180 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_sk()
184 err = -hdev->req_result; in __hci_cmd_sync_sk()
192 hdev->req_status = 0; in __hci_cmd_sync_sk()
193 hdev->req_result = 0; in __hci_cmd_sync_sk()
194 skb = hdev->req_rsp; in __hci_cmd_sync_sk()
195 hdev->req_rsp = NULL; in __hci_cmd_sync_sk()
197 bt_dev_dbg(hdev, "end: err %d", err); in __hci_cmd_sync_sk()
209 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync() argument
212 return __hci_cmd_sync_sk(hdev, opcode, plen, param, 0, timeout, NULL); in __hci_cmd_sync()
217 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync() argument
222 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
225 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync()
227 hci_req_sync_lock(hdev); in hci_cmd_sync()
228 skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout); in hci_cmd_sync()
229 hci_req_sync_unlock(hdev); in hci_cmd_sync()
236 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_ev() argument
239 return __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, in __hci_cmd_sync_ev()
245 int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status_sk() argument
252 skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk); in __hci_cmd_sync_status_sk()
255 bt_dev_err(hdev, "Opcode 0x%4.4x failed: %ld", opcode, in __hci_cmd_sync_status_sk()
275 int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status() argument
278 return __hci_cmd_sync_status_sk(hdev, opcode, plen, param, 0, timeout, in __hci_cmd_sync_status()
283 int hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync_status() argument
288 hci_req_sync_lock(hdev); in hci_cmd_sync_status()
289 err = __hci_cmd_sync_status(hdev, opcode, plen, param, timeout); in hci_cmd_sync_status()
290 hci_req_sync_unlock(hdev); in hci_cmd_sync_status()
298 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_work); in hci_cmd_sync_work() local
300 bt_dev_dbg(hdev, ""); in hci_cmd_sync_work()
306 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
307 entry = list_first_entry_or_null(&hdev->cmd_sync_work_list, in hci_cmd_sync_work()
312 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
317 bt_dev_dbg(hdev, "entry %p", entry); in hci_cmd_sync_work()
322 hci_req_sync_lock(hdev); in hci_cmd_sync_work()
323 err = entry->func(hdev, entry->data); in hci_cmd_sync_work()
325 entry->destroy(hdev, entry->data, err); in hci_cmd_sync_work()
326 hci_req_sync_unlock(hdev); in hci_cmd_sync_work()
335 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_cancel_work); in hci_cmd_sync_cancel_work() local
337 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cmd_sync_cancel_work()
338 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cmd_sync_cancel_work()
339 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_sync_cancel_work()
341 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_work()
344 static int hci_scan_disable_sync(struct hci_dev *hdev);
345 static int scan_disable_sync(struct hci_dev *hdev, void *data) in scan_disable_sync() argument
347 return hci_scan_disable_sync(hdev); in scan_disable_sync()
350 static int hci_inquiry_sync(struct hci_dev *hdev, u8 length);
351 static int interleaved_inquiry_sync(struct hci_dev *hdev, void *data) in interleaved_inquiry_sync() argument
353 return hci_inquiry_sync(hdev, DISCOV_INTERLEAVED_INQUIRY_LEN); in interleaved_inquiry_sync()
358 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable() local
362 bt_dev_dbg(hdev, ""); in le_scan_disable()
363 hci_dev_lock(hdev); in le_scan_disable()
365 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_disable()
368 cancel_delayed_work(&hdev->le_scan_restart); in le_scan_disable()
370 status = hci_cmd_sync_queue(hdev, scan_disable_sync, NULL, NULL); in le_scan_disable()
372 bt_dev_err(hdev, "failed to disable LE scan: %d", status); in le_scan_disable()
376 hdev->discovery.scan_start = 0; in le_scan_disable()
386 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable()
389 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable()
392 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable()
393 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable()
394 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable()
400 status = hci_cmd_sync_queue(hdev, interleaved_inquiry_sync, NULL, NULL); in le_scan_disable()
402 bt_dev_err(hdev, "inquiry failed: status %d", status); in le_scan_disable()
409 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in le_scan_disable()
412 hci_dev_unlock(hdev); in le_scan_disable()
415 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val,
417 static int hci_le_scan_restart_sync(struct hci_dev *hdev) in hci_le_scan_restart_sync() argument
420 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_le_scan_restart_sync()
423 if (hdev->scanning_paused) { in hci_le_scan_restart_sync()
424 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_le_scan_restart_sync()
428 hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_le_scan_restart_sync()
429 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, in hci_le_scan_restart_sync()
435 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_restart() local
440 bt_dev_dbg(hdev, ""); in le_scan_restart()
442 status = hci_le_scan_restart_sync(hdev); in le_scan_restart()
444 bt_dev_err(hdev, "failed to restart LE scan: status %d", in le_scan_restart()
449 hci_dev_lock(hdev); in le_scan_restart()
451 if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) || in le_scan_restart()
452 !hdev->discovery.scan_start) in le_scan_restart()
460 duration = hdev->discovery.scan_duration; in le_scan_restart()
461 scan_start = hdev->discovery.scan_start; in le_scan_restart()
476 queue_delayed_work(hdev->req_workqueue, in le_scan_restart()
477 &hdev->le_scan_disable, timeout); in le_scan_restart()
480 hci_dev_unlock(hdev); in le_scan_restart()
483 static int reenable_adv_sync(struct hci_dev *hdev, void *data) in reenable_adv_sync() argument
485 bt_dev_dbg(hdev, ""); in reenable_adv_sync()
487 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in reenable_adv_sync()
488 list_empty(&hdev->adv_instances)) in reenable_adv_sync()
491 if (hdev->cur_adv_instance) { in reenable_adv_sync()
492 return hci_schedule_adv_instance_sync(hdev, in reenable_adv_sync()
493 hdev->cur_adv_instance, in reenable_adv_sync()
496 if (ext_adv_capable(hdev)) { in reenable_adv_sync()
497 hci_start_ext_adv_sync(hdev, 0x00); in reenable_adv_sync()
499 hci_update_adv_data_sync(hdev, 0x00); in reenable_adv_sync()
500 hci_update_scan_rsp_data_sync(hdev, 0x00); in reenable_adv_sync()
501 hci_enable_advertising_sync(hdev); in reenable_adv_sync()
510 struct hci_dev *hdev = container_of(work, struct hci_dev, in reenable_adv() local
514 bt_dev_dbg(hdev, ""); in reenable_adv()
516 hci_dev_lock(hdev); in reenable_adv()
518 status = hci_cmd_sync_queue(hdev, reenable_adv_sync, NULL, NULL); in reenable_adv()
520 bt_dev_err(hdev, "failed to reenable ADV: %d", status); in reenable_adv()
522 hci_dev_unlock(hdev); in reenable_adv()
525 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
527 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
528 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
529 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
544 int hci_clear_adv_instance_sync(struct hci_dev *hdev, struct sock *sk, in hci_clear_adv_instance_sync() argument
552 if (!instance || hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
553 cancel_adv_timeout(hdev); in hci_clear_adv_instance_sync()
559 if (instance && hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
560 next_instance = hci_get_next_instance(hdev, instance); in hci_clear_adv_instance_sync()
563 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_clear_adv_instance_sync()
569 err = hci_remove_adv_instance(hdev, rem_inst); in hci_clear_adv_instance_sync()
571 mgmt_advertising_removed(sk, hdev, rem_inst); in hci_clear_adv_instance_sync()
574 adv_instance = hci_find_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
583 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
585 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_instance_sync()
589 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_clear_adv_instance_sync()
592 if (next_instance && !ext_adv_capable(hdev)) in hci_clear_adv_instance_sync()
593 return hci_schedule_adv_instance_sync(hdev, in hci_clear_adv_instance_sync()
600 static int adv_timeout_expire_sync(struct hci_dev *hdev, void *data) in adv_timeout_expire_sync() argument
606 hci_clear_adv_instance_sync(hdev, NULL, instance, false); in adv_timeout_expire_sync()
608 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire_sync()
609 return hci_disable_advertising_sync(hdev); in adv_timeout_expire_sync()
617 struct hci_dev *hdev = container_of(work, struct hci_dev, in adv_timeout_expire() local
620 bt_dev_dbg(hdev, ""); in adv_timeout_expire()
622 hci_dev_lock(hdev); in adv_timeout_expire()
624 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
626 if (hdev->cur_adv_instance == 0x00) in adv_timeout_expire()
633 *inst_ptr = hdev->cur_adv_instance; in adv_timeout_expire()
634 hci_cmd_sync_queue(hdev, adv_timeout_expire_sync, inst_ptr, NULL); in adv_timeout_expire()
637 hci_dev_unlock(hdev); in adv_timeout_expire()
640 void hci_cmd_sync_init(struct hci_dev *hdev) in hci_cmd_sync_init() argument
642 INIT_WORK(&hdev->cmd_sync_work, hci_cmd_sync_work); in hci_cmd_sync_init()
643 INIT_LIST_HEAD(&hdev->cmd_sync_work_list); in hci_cmd_sync_init()
644 mutex_init(&hdev->cmd_sync_work_lock); in hci_cmd_sync_init()
645 mutex_init(&hdev->unregister_lock); in hci_cmd_sync_init()
647 INIT_WORK(&hdev->cmd_sync_cancel_work, hci_cmd_sync_cancel_work); in hci_cmd_sync_init()
648 INIT_WORK(&hdev->reenable_adv_work, reenable_adv); in hci_cmd_sync_init()
649 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable); in hci_cmd_sync_init()
650 INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart); in hci_cmd_sync_init()
651 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_cmd_sync_init()
654 void hci_cmd_sync_clear(struct hci_dev *hdev) in hci_cmd_sync_clear() argument
658 cancel_work_sync(&hdev->cmd_sync_work); in hci_cmd_sync_clear()
659 cancel_work_sync(&hdev->reenable_adv_work); in hci_cmd_sync_clear()
661 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_clear()
662 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) { in hci_cmd_sync_clear()
664 entry->destroy(hdev, entry->data, -ECANCELED); in hci_cmd_sync_clear()
669 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_clear()
672 void hci_cmd_sync_cancel(struct hci_dev *hdev, int err) in hci_cmd_sync_cancel() argument
674 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_cmd_sync_cancel()
676 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel()
677 hdev->req_result = err; in hci_cmd_sync_cancel()
678 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel()
680 queue_work(hdev->workqueue, &hdev->cmd_sync_cancel_work); in hci_cmd_sync_cancel()
690 void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err) in hci_cmd_sync_cancel_sync() argument
692 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_cmd_sync_cancel_sync()
694 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel_sync()
698 hdev->req_result = err < 0 ? -err : err; in hci_cmd_sync_cancel_sync()
699 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel_sync()
701 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_sync()
710 int hci_cmd_sync_submit(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_submit() argument
716 mutex_lock(&hdev->unregister_lock); in hci_cmd_sync_submit()
717 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_cmd_sync_submit()
731 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
732 list_add_tail(&entry->list, &hdev->cmd_sync_work_list); in hci_cmd_sync_submit()
733 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
735 queue_work(hdev->req_workqueue, &hdev->cmd_sync_work); in hci_cmd_sync_submit()
738 mutex_unlock(&hdev->unregister_lock); in hci_cmd_sync_submit()
747 int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_queue() argument
753 if (!test_bit(HCI_RUNNING, &hdev->flags)) in hci_cmd_sync_queue()
756 return hci_cmd_sync_submit(hdev, func, data, destroy); in hci_cmd_sync_queue()
760 int hci_update_eir_sync(struct hci_dev *hdev) in hci_update_eir_sync() argument
764 bt_dev_dbg(hdev, ""); in hci_update_eir_sync()
766 if (!hdev_is_powered(hdev)) in hci_update_eir_sync()
769 if (!lmp_ext_inq_capable(hdev)) in hci_update_eir_sync()
772 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_update_eir_sync()
775 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_eir_sync()
780 eir_create(hdev, cp.data); in hci_update_eir_sync()
782 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in hci_update_eir_sync()
785 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in hci_update_eir_sync()
787 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_update_eir_sync()
791 static u8 get_service_classes(struct hci_dev *hdev) in get_service_classes() argument
796 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
802 int hci_update_class_sync(struct hci_dev *hdev) in hci_update_class_sync() argument
806 bt_dev_dbg(hdev, ""); in hci_update_class_sync()
808 if (!hdev_is_powered(hdev)) in hci_update_class_sync()
811 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_class_sync()
814 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_class_sync()
817 cod[0] = hdev->minor_class; in hci_update_class_sync()
818 cod[1] = hdev->major_class; in hci_update_class_sync()
819 cod[2] = get_service_classes(hdev); in hci_update_class_sync()
821 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_update_class_sync()
824 if (memcmp(cod, hdev->dev_class, 3) == 0) in hci_update_class_sync()
827 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CLASS_OF_DEV, in hci_update_class_sync()
831 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) in is_advertising_allowed() argument
834 if (hci_conn_num(hdev, LE_LINK) == 0) in is_advertising_allowed()
838 if (hdev->conn_hash.le_num_peripheral > 0) { in is_advertising_allowed()
842 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
848 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
849 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
854 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_peripheral) { in is_advertising_allowed()
856 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
862 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
863 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
870 static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags) in adv_use_rpa() argument
873 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in adv_use_rpa()
877 if (!hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in adv_use_rpa()
884 hci_dev_test_flag(hdev, HCI_BONDABLE)) in adv_use_rpa()
893 static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa) in hci_set_random_addr_sync() argument
905 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in hci_set_random_addr_sync()
906 hci_lookup_le_connect(hdev)) { in hci_set_random_addr_sync()
907 bt_dev_dbg(hdev, "Deferring random address update"); in hci_set_random_addr_sync()
908 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_set_random_addr_sync()
912 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RANDOM_ADDR, in hci_set_random_addr_sync()
916 int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy, in hci_update_random_address_sync() argument
929 if (use_ll_privacy(hdev)) in hci_update_random_address_sync()
935 if (rpa_valid(hdev)) in hci_update_random_address_sync()
938 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address_sync()
940 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address_sync()
944 err = hci_set_random_addr_sync(hdev, &hdev->rpa); in hci_update_random_address_sync()
969 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address_sync()
975 return hci_set_random_addr_sync(hdev, &nrpa); in hci_update_random_address_sync()
987 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address_sync()
988 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address_sync()
989 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address_sync()
990 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address_sync()
992 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address_sync()
993 return hci_set_random_addr_sync(hdev, in hci_update_random_address_sync()
994 &hdev->static_addr); in hci_update_random_address_sync()
1006 static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_disable_ext_adv_instance_sync() argument
1017 adv = hci_find_adv_instance(hdev, instance); in hci_disable_ext_adv_instance_sync()
1039 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_disable_ext_adv_instance_sync()
1043 static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, in hci_set_adv_set_random_addr_sync() argument
1055 err = hci_set_random_addr_sync(hdev, random_addr); in hci_set_adv_set_random_addr_sync()
1065 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, in hci_set_adv_set_random_addr_sync()
1069 int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_setup_ext_adv_instance_sync() argument
1081 adv = hci_find_adv_instance(hdev, instance); in hci_setup_ext_adv_instance_sync()
1093 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_setup_ext_adv_instance_sync()
1098 flags = hci_adv_instance_flags(hdev, instance); in hci_setup_ext_adv_instance_sync()
1104 mgmt_get_connectable(hdev); in hci_setup_ext_adv_instance_sync()
1106 if (!is_advertising_allowed(hdev, connectable)) in hci_setup_ext_adv_instance_sync()
1113 err = hci_get_random_address(hdev, !connectable, in hci_setup_ext_adv_instance_sync()
1114 adv_use_rpa(hdev, flags), adv, in hci_setup_ext_adv_instance_sync()
1126 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1127 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1138 } else if (hci_adv_instance_is_scannable(hdev, instance) || in hci_setup_ext_adv_instance_sync()
1159 hci_copy_identity_address(hdev, &cp.peer_addr, in hci_setup_ext_adv_instance_sync()
1163 cp.channel_map = hdev->le_adv_channel_map; in hci_setup_ext_adv_instance_sync()
1178 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_setup_ext_adv_instance_sync()
1191 if (!bacmp(&random_addr, &hdev->random_addr)) in hci_setup_ext_adv_instance_sync()
1195 return hci_set_adv_set_random_addr_sync(hdev, instance, in hci_setup_ext_adv_instance_sync()
1202 static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_scan_rsp_data_sync() argument
1215 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_scan_rsp_data_sync()
1220 len = eir_create_scan_rsp(hdev, instance, pdu.data); in hci_set_ext_scan_rsp_data_sync()
1227 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA, in hci_set_ext_scan_rsp_data_sync()
1236 memcpy(hdev->scan_rsp_data, pdu.data, len); in hci_set_ext_scan_rsp_data_sync()
1237 hdev->scan_rsp_data_len = len; in hci_set_ext_scan_rsp_data_sync()
1243 static int __hci_set_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in __hci_set_scan_rsp_data_sync() argument
1250 len = eir_create_scan_rsp(hdev, instance, cp.data); in __hci_set_scan_rsp_data_sync()
1252 if (hdev->scan_rsp_data_len == len && in __hci_set_scan_rsp_data_sync()
1253 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_set_scan_rsp_data_sync()
1256 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_set_scan_rsp_data_sync()
1257 hdev->scan_rsp_data_len = len; in __hci_set_scan_rsp_data_sync()
1261 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_RSP_DATA, in __hci_set_scan_rsp_data_sync()
1265 int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_scan_rsp_data_sync() argument
1267 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_rsp_data_sync()
1270 if (ext_adv_capable(hdev)) in hci_update_scan_rsp_data_sync()
1271 return hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1273 return __hci_set_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1276 int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_ext_advertising_sync() argument
1284 adv = hci_find_adv_instance(hdev, instance); in hci_enable_ext_advertising_sync()
1316 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_enable_ext_advertising_sync()
1322 int hci_start_ext_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_ext_adv_sync() argument
1326 err = hci_setup_ext_adv_instance_sync(hdev, instance); in hci_start_ext_adv_sync()
1330 err = hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_start_ext_adv_sync()
1334 return hci_enable_ext_advertising_sync(hdev, instance); in hci_start_ext_adv_sync()
1337 int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_disable_per_advertising_sync() argument
1343 adv = hci_find_adv_instance(hdev, instance); in hci_disable_per_advertising_sync()
1352 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_disable_per_advertising_sync()
1356 static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, in hci_set_per_adv_params_sync() argument
1374 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS, in hci_set_per_adv_params_sync()
1378 static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_per_adv_data_sync() argument
1389 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_set_per_adv_data_sync()
1395 len = eir_create_per_adv_data(hdev, instance, pdu.data); in hci_set_per_adv_data_sync()
1401 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_DATA, in hci_set_per_adv_data_sync()
1406 static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_per_advertising_sync() argument
1412 adv = hci_find_adv_instance(hdev, instance); in hci_enable_per_advertising_sync()
1421 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_enable_per_advertising_sync()
1428 static int hci_adv_bcast_annoucement(struct hci_dev *hdev, struct adv_info *adv) in hci_adv_bcast_annoucement() argument
1458 hci_set_adv_instance_data(hdev, adv->instance, sizeof(ad), ad, 0, NULL); in hci_adv_bcast_annoucement()
1460 return hci_update_adv_data_sync(hdev, adv->instance); in hci_adv_bcast_annoucement()
1463 int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len, in hci_start_per_adv_sync() argument
1471 hci_disable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1474 adv = hci_find_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1477 adv = hci_add_per_instance(hdev, instance, flags, in hci_start_per_adv_sync()
1489 err = hci_start_ext_adv_sync(hdev, instance); in hci_start_per_adv_sync()
1493 err = hci_adv_bcast_annoucement(hdev, adv); in hci_start_per_adv_sync()
1497 err = hci_set_per_adv_params_sync(hdev, instance, min_interval, in hci_start_per_adv_sync()
1502 err = hci_set_per_adv_data_sync(hdev, instance); in hci_start_per_adv_sync()
1506 err = hci_enable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1514 hci_remove_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1519 static int hci_start_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_adv_sync() argument
1523 if (ext_adv_capable(hdev)) in hci_start_adv_sync()
1524 return hci_start_ext_adv_sync(hdev, instance); in hci_start_adv_sync()
1526 err = hci_update_adv_data_sync(hdev, instance); in hci_start_adv_sync()
1530 err = hci_update_scan_rsp_data_sync(hdev, instance); in hci_start_adv_sync()
1534 return hci_enable_advertising_sync(hdev); in hci_start_adv_sync()
1537 int hci_enable_advertising_sync(struct hci_dev *hdev) in hci_enable_advertising_sync() argument
1547 if (ext_adv_capable(hdev)) in hci_enable_advertising_sync()
1548 return hci_enable_ext_advertising_sync(hdev, in hci_enable_advertising_sync()
1549 hdev->cur_adv_instance); in hci_enable_advertising_sync()
1551 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1552 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1558 mgmt_get_connectable(hdev); in hci_enable_advertising_sync()
1560 if (!is_advertising_allowed(hdev, connectable)) in hci_enable_advertising_sync()
1563 status = hci_disable_advertising_sync(hdev); in hci_enable_advertising_sync()
1572 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_enable_advertising_sync()
1578 status = hci_update_random_address_sync(hdev, !connectable, in hci_enable_advertising_sync()
1579 adv_use_rpa(hdev, flags), in hci_enable_advertising_sync()
1590 adv_min_interval = hdev->le_adv_min_interval; in hci_enable_advertising_sync()
1591 adv_max_interval = hdev->le_adv_max_interval; in hci_enable_advertising_sync()
1597 if (hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance)) in hci_enable_advertising_sync()
1602 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in hci_enable_advertising_sync()
1603 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_enable_advertising_sync()
1612 cp.channel_map = hdev->le_adv_channel_map; in hci_enable_advertising_sync()
1614 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_enable_advertising_sync()
1619 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_enable_advertising_sync()
1623 static int enable_advertising_sync(struct hci_dev *hdev, void *data) in enable_advertising_sync() argument
1625 return hci_enable_advertising_sync(hdev); in enable_advertising_sync()
1628 int hci_enable_advertising(struct hci_dev *hdev) in hci_enable_advertising() argument
1630 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_enable_advertising()
1631 list_empty(&hdev->adv_instances)) in hci_enable_advertising()
1634 return hci_cmd_sync_queue(hdev, enable_advertising_sync, NULL, NULL); in hci_enable_advertising()
1637 int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_remove_ext_adv_instance_sync() argument
1642 if (!ext_adv_capable(hdev)) in hci_remove_ext_adv_instance_sync()
1645 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_remove_ext_adv_instance_sync()
1650 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in hci_remove_ext_adv_instance_sync()
1653 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, in hci_remove_ext_adv_instance_sync()
1658 static int remove_ext_adv_sync(struct hci_dev *hdev, void *data) in remove_ext_adv_sync() argument
1666 return hci_remove_ext_adv_instance_sync(hdev, instance, NULL); in remove_ext_adv_sync()
1669 int hci_remove_ext_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_ext_adv_instance() argument
1674 adv = hci_find_adv_instance(hdev, instance); in hci_remove_ext_adv_instance()
1679 return hci_cmd_sync_queue(hdev, remove_ext_adv_sync, adv, NULL); in hci_remove_ext_adv_instance()
1682 int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) in hci_le_terminate_big_sync() argument
1690 return __hci_cmd_sync_status(hdev, HCI_OP_LE_TERM_BIG, in hci_le_terminate_big_sync()
1694 static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_adv_data_sync() argument
1707 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_adv_data_sync()
1712 len = eir_create_adv_data(hdev, instance, pdu.data); in hci_set_ext_adv_data_sync()
1719 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_DATA, in hci_set_ext_adv_data_sync()
1729 memcpy(hdev->adv_data, pdu.data, len); in hci_set_ext_adv_data_sync()
1730 hdev->adv_data_len = len; in hci_set_ext_adv_data_sync()
1736 static int hci_set_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_adv_data_sync() argument
1743 len = eir_create_adv_data(hdev, instance, cp.data); in hci_set_adv_data_sync()
1746 if (hdev->adv_data_len == len && in hci_set_adv_data_sync()
1747 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_set_adv_data_sync()
1750 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_set_adv_data_sync()
1751 hdev->adv_data_len = len; in hci_set_adv_data_sync()
1755 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_DATA, in hci_set_adv_data_sync()
1759 int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_adv_data_sync() argument
1761 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_adv_data_sync()
1764 if (ext_adv_capable(hdev)) in hci_update_adv_data_sync()
1765 return hci_set_ext_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1767 return hci_set_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1770 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_schedule_adv_instance_sync() argument
1776 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) && !ext_adv_capable(hdev)) in hci_schedule_adv_instance_sync()
1779 if (hdev->adv_instance_timeout) in hci_schedule_adv_instance_sync()
1782 adv = hci_find_adv_instance(hdev, instance); in hci_schedule_adv_instance_sync()
1806 if (!ext_adv_capable(hdev)) { in hci_schedule_adv_instance_sync()
1807 hdev->adv_instance_timeout = timeout; in hci_schedule_adv_instance_sync()
1808 queue_delayed_work(hdev->req_workqueue, in hci_schedule_adv_instance_sync()
1809 &hdev->adv_instance_expire, in hci_schedule_adv_instance_sync()
1817 if (!force && hdev->cur_adv_instance == instance && in hci_schedule_adv_instance_sync()
1818 hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_schedule_adv_instance_sync()
1821 hdev->cur_adv_instance = instance; in hci_schedule_adv_instance_sync()
1823 return hci_start_adv_sync(hdev, instance); in hci_schedule_adv_instance_sync()
1826 static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk) in hci_clear_adv_sets_sync() argument
1830 if (!ext_adv_capable(hdev)) in hci_clear_adv_sets_sync()
1834 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_clear_adv_sets_sync()
1838 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CLEAR_ADV_SETS, in hci_clear_adv_sets_sync()
1842 static int hci_clear_adv_sync(struct hci_dev *hdev, struct sock *sk, bool force) in hci_clear_adv_sync() argument
1847 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1849 err = hci_clear_adv_sets_sync(hdev, sk); in hci_clear_adv_sync()
1850 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1856 hci_dev_lock(hdev); in hci_clear_adv_sync()
1859 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in hci_clear_adv_sync()
1866 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_sync()
1868 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_sync()
1871 hci_dev_unlock(hdev); in hci_clear_adv_sync()
1876 static int hci_remove_adv_sync(struct hci_dev *hdev, u8 instance, in hci_remove_adv_sync() argument
1882 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1883 err = hci_remove_ext_adv_instance_sync(hdev, instance, sk); in hci_remove_adv_sync()
1884 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1890 hci_dev_lock(hdev); in hci_remove_adv_sync()
1892 err = hci_remove_adv_instance(hdev, instance); in hci_remove_adv_sync()
1894 mgmt_advertising_removed(sk, hdev, instance); in hci_remove_adv_sync()
1896 hci_dev_unlock(hdev); in hci_remove_adv_sync()
1912 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, in hci_remove_advertising_sync() argument
1919 if (!instance || hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1920 cancel_adv_timeout(hdev); in hci_remove_advertising_sync()
1926 if (hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1927 next = hci_get_next_instance(hdev, instance); in hci_remove_advertising_sync()
1930 err = hci_clear_adv_sync(hdev, sk, force); in hci_remove_advertising_sync()
1934 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_remove_advertising_sync()
1941 err = hci_remove_adv_sync(hdev, instance, sk); in hci_remove_advertising_sync()
1947 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_remove_advertising_sync()
1950 if (next && !ext_adv_capable(hdev)) in hci_remove_advertising_sync()
1951 hci_schedule_adv_instance_sync(hdev, next->instance, false); in hci_remove_advertising_sync()
1956 int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle) in hci_read_rssi_sync() argument
1961 return __hci_cmd_sync_status(hdev, HCI_OP_READ_RSSI, in hci_read_rssi_sync()
1965 int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp) in hci_read_clock_sync() argument
1967 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLOCK, in hci_read_clock_sync()
1971 int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type) in hci_read_tx_power_sync() argument
1977 return __hci_cmd_sync_status(hdev, HCI_OP_READ_TX_POWER, in hci_read_tx_power_sync()
1981 int hci_disable_advertising_sync(struct hci_dev *hdev) in hci_disable_advertising_sync() argument
1987 if (!hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_disable_advertising_sync()
1990 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
1991 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_disable_advertising_sync()
1992 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
1995 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_disable_advertising_sync()
1999 static int hci_le_set_ext_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_ext_scan_enable_sync() argument
2007 if (hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_ext_scan_enable_sync()
2012 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE, in hci_le_set_ext_scan_enable_sync()
2016 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_scan_enable_sync() argument
2021 if (use_ext_scan(hdev)) in hci_le_set_scan_enable_sync()
2022 return hci_le_set_ext_scan_enable_sync(hdev, val, filter_dup); in hci_le_set_scan_enable_sync()
2027 if (val && hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_scan_enable_sync()
2032 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_ENABLE, in hci_le_set_scan_enable_sync()
2036 static int hci_le_set_addr_resolution_enable_sync(struct hci_dev *hdev, u8 val) in hci_le_set_addr_resolution_enable_sync() argument
2038 if (!use_ll_privacy(hdev)) in hci_le_set_addr_resolution_enable_sync()
2042 if (val == hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_le_set_addr_resolution_enable_sync()
2045 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, in hci_le_set_addr_resolution_enable_sync()
2049 static int hci_scan_disable_sync(struct hci_dev *hdev) in hci_scan_disable_sync() argument
2054 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_scan_disable_sync()
2057 if (hdev->scanning_paused) { in hci_scan_disable_sync()
2058 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_scan_disable_sync()
2062 err = hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_scan_disable_sync()
2064 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_scan_disable_sync()
2071 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
2073 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
2076 static void hci_start_interleave_scan(struct hci_dev *hdev) in hci_start_interleave_scan() argument
2078 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_start_interleave_scan()
2079 queue_delayed_work(hdev->req_workqueue, in hci_start_interleave_scan()
2080 &hdev->interleave_scan, 0); in hci_start_interleave_scan()
2083 static bool is_interleave_scanning(struct hci_dev *hdev) in is_interleave_scanning() argument
2085 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
2088 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
2090 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
2092 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
2094 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
2100 static bool hci_update_interleaved_scan_sync(struct hci_dev *hdev) in hci_update_interleaved_scan_sync() argument
2109 bool use_interleaving = hci_is_adv_monitoring(hdev) && in hci_update_interleaved_scan_sync()
2110 !(list_empty(&hdev->pend_le_conns) && in hci_update_interleaved_scan_sync()
2111 list_empty(&hdev->pend_le_reports)) && in hci_update_interleaved_scan_sync()
2112 hci_get_adv_monitor_offload_ext(hdev) == in hci_update_interleaved_scan_sync()
2114 bool is_interleaving = is_interleave_scanning(hdev); in hci_update_interleaved_scan_sync()
2117 hci_start_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2118 bt_dev_dbg(hdev, "starting interleave scan"); in hci_update_interleaved_scan_sync()
2123 cancel_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2129 static int hci_le_del_resolve_list_sync(struct hci_dev *hdev, in hci_le_del_resolve_list_sync() argument
2135 if (!use_ll_privacy(hdev)) in hci_le_del_resolve_list_sync()
2139 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, in hci_le_del_resolve_list_sync()
2147 return __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST, in hci_le_del_resolve_list_sync()
2151 static int hci_le_del_accept_list_sync(struct hci_dev *hdev, in hci_le_del_accept_list_sync() argument
2158 if (!hci_bdaddr_list_lookup(&hdev->le_accept_list, bdaddr, bdaddr_type)) in hci_le_del_accept_list_sync()
2167 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_del_accept_list_sync()
2169 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST, in hci_le_del_accept_list_sync()
2172 bt_dev_err(hdev, "Unable to remove from allow list: %d", err); in hci_le_del_accept_list_sync()
2176 bt_dev_dbg(hdev, "Remove %pMR (0x%x) from allow list", &cp.bdaddr, in hci_le_del_accept_list_sync()
2192 static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, in hci_le_add_resolve_list_sync() argument
2200 if (!use_ll_privacy(hdev)) in hci_le_add_resolve_list_sync()
2207 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2210 hci_copy_identity_address(hdev, &cp.bdaddr, &cp.bdaddr_type); in hci_le_add_resolve_list_sync()
2211 memcpy(cp.peer_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2215 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2220 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, in hci_le_add_resolve_list_sync()
2234 p = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_le_add_resolve_list_sync()
2237 p = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_le_add_resolve_list_sync()
2244 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2245 memcpy(cp.local_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2249 return __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST, in hci_le_add_resolve_list_sync()
2254 static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev, in hci_le_set_privacy_mode_sync() argument
2271 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_set_privacy_mode_sync()
2282 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PRIVACY_MODE, in hci_le_set_privacy_mode_sync()
2290 static int hci_le_add_accept_list_sync(struct hci_dev *hdev, in hci_le_add_accept_list_sync() argument
2298 if (hdev->suspended && in hci_le_add_accept_list_sync()
2300 hci_le_del_accept_list_sync(hdev, &params->addr, in hci_le_add_accept_list_sync()
2306 if (*num_entries >= hdev->le_accept_list_size) in hci_le_add_accept_list_sync()
2310 if (!use_ll_privacy(hdev) && in hci_le_add_accept_list_sync()
2311 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) in hci_le_add_accept_list_sync()
2318 err = hci_le_add_resolve_list_sync(hdev, params); in hci_le_add_accept_list_sync()
2320 bt_dev_err(hdev, "Unable to add to resolve list: %d", err); in hci_le_add_accept_list_sync()
2325 err = hci_le_set_privacy_mode_sync(hdev, params); in hci_le_add_accept_list_sync()
2327 bt_dev_err(hdev, "Unable to set privacy mode: %d", err); in hci_le_add_accept_list_sync()
2332 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in hci_le_add_accept_list_sync()
2340 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST, in hci_le_add_accept_list_sync()
2343 bt_dev_err(hdev, "Unable to add to allow list: %d", err); in hci_le_add_accept_list_sync()
2345 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_add_accept_list_sync()
2349 bt_dev_dbg(hdev, "Add %pMR (0x%x) to allow list", &cp.bdaddr, in hci_le_add_accept_list_sync()
2356 static int hci_pause_advertising_sync(struct hci_dev *hdev) in hci_pause_advertising_sync() argument
2362 if (hdev->advertising_paused) in hci_pause_advertising_sync()
2365 bt_dev_dbg(hdev, "Pausing directed advertising"); in hci_pause_advertising_sync()
2368 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_pause_advertising_sync()
2375 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_pause_advertising_sync()
2376 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_pause_advertising_sync()
2377 hdev->discov_timeout = 0; in hci_pause_advertising_sync()
2380 bt_dev_dbg(hdev, "Pausing advertising instances"); in hci_pause_advertising_sync()
2385 err = hci_disable_advertising_sync(hdev); in hci_pause_advertising_sync()
2390 if (!ext_adv_capable(hdev)) in hci_pause_advertising_sync()
2391 cancel_adv_timeout(hdev); in hci_pause_advertising_sync()
2393 hdev->advertising_paused = true; in hci_pause_advertising_sync()
2394 hdev->advertising_old_state = old_state; in hci_pause_advertising_sync()
2400 static int hci_resume_advertising_sync(struct hci_dev *hdev) in hci_resume_advertising_sync() argument
2406 if (!hdev->advertising_paused) in hci_resume_advertising_sync()
2410 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2411 if (hdev->advertising_old_state) { in hci_resume_advertising_sync()
2412 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_resume_advertising_sync()
2413 hdev->advertising_old_state = 0; in hci_resume_advertising_sync()
2416 bt_dev_dbg(hdev, "Resuming advertising instances"); in hci_resume_advertising_sync()
2418 if (ext_adv_capable(hdev)) { in hci_resume_advertising_sync()
2420 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) { in hci_resume_advertising_sync()
2421 err = hci_enable_ext_advertising_sync(hdev, in hci_resume_advertising_sync()
2427 hci_remove_ext_adv_instance_sync(hdev, adv->instance, in hci_resume_advertising_sync()
2434 err = hci_schedule_adv_instance_sync(hdev, in hci_resume_advertising_sync()
2435 hdev->cur_adv_instance, in hci_resume_advertising_sync()
2439 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2444 static int hci_pause_addr_resolution(struct hci_dev *hdev) in hci_pause_addr_resolution() argument
2448 if (!use_ll_privacy(hdev)) in hci_pause_addr_resolution()
2451 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_pause_addr_resolution()
2457 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) || in hci_pause_addr_resolution()
2458 hci_lookup_le_connect(hdev)) { in hci_pause_addr_resolution()
2459 bt_dev_err(hdev, "Command not allowed when scan/LE connect"); in hci_pause_addr_resolution()
2464 err = hci_pause_advertising_sync(hdev); in hci_pause_addr_resolution()
2466 bt_dev_err(hdev, "Pause advertising failed: %d", err); in hci_pause_addr_resolution()
2470 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_pause_addr_resolution()
2472 bt_dev_err(hdev, "Unable to disable Address Resolution: %d", in hci_pause_addr_resolution()
2476 if (!err && scan_use_rpa(hdev)) in hci_pause_addr_resolution()
2479 hci_resume_advertising_sync(hdev); in hci_pause_addr_resolution()
2483 struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, in hci_read_local_oob_data_sync() argument
2489 return __hci_cmd_sync_sk(hdev, opcode, 0, NULL, 0, HCI_CMD_TIMEOUT, sk); in hci_read_local_oob_data_sync()
2555 static u8 hci_update_accept_list_sync(struct hci_dev *hdev) in hci_update_accept_list_sync() argument
2568 if (use_ll_privacy(hdev)) { in hci_update_accept_list_sync()
2569 err = hci_pause_advertising_sync(hdev); in hci_update_accept_list_sync()
2571 bt_dev_err(hdev, "pause advertising failed: %d", err); in hci_update_accept_list_sync()
2580 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_update_accept_list_sync()
2582 bt_dev_err(hdev, "Unable to disable LL privacy: %d", err); in hci_update_accept_list_sync()
2592 list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { in hci_update_accept_list_sync()
2593 if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) in hci_update_accept_list_sync()
2597 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_update_accept_list_sync()
2600 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_update_accept_list_sync()
2608 hci_le_del_accept_list_sync(hdev, &b->bdaddr, in hci_update_accept_list_sync()
2630 params = conn_params_copy(&hdev->pend_le_conns, &n); in hci_update_accept_list_sync()
2637 err = hci_le_add_accept_list_sync(hdev, &params[i], in hci_update_accept_list_sync()
2652 params = conn_params_copy(&hdev->pend_le_reports, &n); in hci_update_accept_list_sync()
2659 err = hci_le_add_accept_list_sync(hdev, &params[i], in hci_update_accept_list_sync()
2674 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in hci_update_accept_list_sync()
2675 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE && in hci_update_accept_list_sync()
2676 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in hci_update_accept_list_sync()
2683 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_update_accept_list_sync()
2685 bt_dev_err(hdev, "Unable to enable LL privacy: %d", err); in hci_update_accept_list_sync()
2688 if (use_ll_privacy(hdev)) in hci_update_accept_list_sync()
2689 hci_resume_advertising_sync(hdev); in hci_update_accept_list_sync()
2703 static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_ext_scan_param_sync() argument
2723 if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_le_set_ext_scan_param_sync()
2726 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST); in hci_le_set_ext_scan_param_sync()
2730 conn = hci_conn_hash_lookup_ba(hdev, ISO_LINK, in hci_le_set_ext_scan_param_sync()
2760 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_le_set_ext_scan_param_sync()
2767 if (scan_coded(hdev)) { in hci_le_set_ext_scan_param_sync()
2778 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS, in hci_le_set_ext_scan_param_sync()
2783 static int hci_le_set_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_scan_param_sync() argument
2789 if (use_ext_scan(hdev)) in hci_le_set_scan_param_sync()
2790 return hci_le_set_ext_scan_param_sync(hdev, type, interval, in hci_le_set_scan_param_sync()
2801 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_PARAM, in hci_le_set_scan_param_sync()
2805 static int hci_start_scan_sync(struct hci_dev *hdev, u8 type, u16 interval, in hci_start_scan_sync() argument
2811 if (hdev->scanning_paused) { in hci_start_scan_sync()
2812 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_start_scan_sync()
2816 err = hci_le_set_scan_param_sync(hdev, type, interval, window, in hci_start_scan_sync()
2821 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, filter_dup); in hci_start_scan_sync()
2824 static int hci_passive_scan_sync(struct hci_dev *hdev) in hci_passive_scan_sync() argument
2832 if (hdev->scanning_paused) { in hci_passive_scan_sync()
2833 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_passive_scan_sync()
2837 err = hci_scan_disable_sync(hdev); in hci_passive_scan_sync()
2839 bt_dev_err(hdev, "disable scanning failed: %d", err); in hci_passive_scan_sync()
2849 if (hci_update_random_address_sync(hdev, false, scan_use_rpa(hdev), in hci_passive_scan_sync()
2853 if (hdev->enable_advmon_interleave_scan && in hci_passive_scan_sync()
2854 hci_update_interleaved_scan_sync(hdev)) in hci_passive_scan_sync()
2857 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_passive_scan_sync()
2863 filter_policy = hci_update_accept_list_sync(hdev); in hci_passive_scan_sync()
2869 if (hdev->suspended && !filter_policy) { in hci_passive_scan_sync()
2873 if (list_empty(&hdev->le_accept_list)) in hci_passive_scan_sync()
2895 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_passive_scan_sync()
2896 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_passive_scan_sync()
2899 if (hdev->suspended) { in hci_passive_scan_sync()
2900 window = hdev->le_scan_window_suspend; in hci_passive_scan_sync()
2901 interval = hdev->le_scan_int_suspend; in hci_passive_scan_sync()
2902 } else if (hci_is_le_conn_scanning(hdev)) { in hci_passive_scan_sync()
2903 window = hdev->le_scan_window_connect; in hci_passive_scan_sync()
2904 interval = hdev->le_scan_int_connect; in hci_passive_scan_sync()
2905 } else if (hci_is_adv_monitoring(hdev)) { in hci_passive_scan_sync()
2906 window = hdev->le_scan_window_adv_monitor; in hci_passive_scan_sync()
2907 interval = hdev->le_scan_int_adv_monitor; in hci_passive_scan_sync()
2923 window = hdev->le_scan_window; in hci_passive_scan_sync()
2924 interval = hdev->le_scan_interval; in hci_passive_scan_sync()
2928 if (hci_dev_test_flag(hdev, HCI_MESH)) { in hci_passive_scan_sync()
2933 bt_dev_dbg(hdev, "LE passive scan with acceptlist = %d", filter_policy); in hci_passive_scan_sync()
2935 return hci_start_scan_sync(hdev, LE_SCAN_PASSIVE, interval, window, in hci_passive_scan_sync()
2954 int hci_update_passive_scan_sync(struct hci_dev *hdev) in hci_update_passive_scan_sync() argument
2958 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan_sync()
2959 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan_sync()
2960 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan_sync()
2961 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan_sync()
2962 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan_sync()
2963 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan_sync()
2967 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_sync()
2971 if (hdev->discovery.state != DISCOVERY_STOPPED) in hci_update_passive_scan_sync()
2981 hci_discovery_filter_clear(hdev); in hci_update_passive_scan_sync()
2983 bt_dev_dbg(hdev, "ADV monitoring is %s", in hci_update_passive_scan_sync()
2984 hci_is_adv_monitoring(hdev) ? "on" : "off"); in hci_update_passive_scan_sync()
2986 if (!hci_dev_test_flag(hdev, HCI_MESH) && in hci_update_passive_scan_sync()
2987 list_empty(&hdev->pend_le_conns) && in hci_update_passive_scan_sync()
2988 list_empty(&hdev->pend_le_reports) && in hci_update_passive_scan_sync()
2989 !hci_is_adv_monitoring(hdev) && in hci_update_passive_scan_sync()
2990 !hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_update_passive_scan_sync()
2996 bt_dev_dbg(hdev, "stopping background scanning"); in hci_update_passive_scan_sync()
2998 err = hci_scan_disable_sync(hdev); in hci_update_passive_scan_sync()
3000 bt_dev_err(hdev, "stop background scanning failed: %d", in hci_update_passive_scan_sync()
3011 if (hci_lookup_le_connect(hdev)) in hci_update_passive_scan_sync()
3014 bt_dev_dbg(hdev, "start background scanning"); in hci_update_passive_scan_sync()
3016 err = hci_passive_scan_sync(hdev); in hci_update_passive_scan_sync()
3018 bt_dev_err(hdev, "start background scanning failed: %d", in hci_update_passive_scan_sync()
3025 static int update_scan_sync(struct hci_dev *hdev, void *data) in update_scan_sync() argument
3027 return hci_update_scan_sync(hdev); in update_scan_sync()
3030 int hci_update_scan(struct hci_dev *hdev) in hci_update_scan() argument
3032 return hci_cmd_sync_queue(hdev, update_scan_sync, NULL, NULL); in hci_update_scan()
3035 static int update_passive_scan_sync(struct hci_dev *hdev, void *data) in update_passive_scan_sync() argument
3037 return hci_update_passive_scan_sync(hdev); in update_passive_scan_sync()
3040 int hci_update_passive_scan(struct hci_dev *hdev) in hci_update_passive_scan() argument
3043 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan()
3044 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan()
3045 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan()
3046 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan()
3047 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan()
3048 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan()
3051 return hci_cmd_sync_queue(hdev, update_passive_scan_sync, NULL, NULL); in hci_update_passive_scan()
3054 int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val) in hci_write_sc_support_sync() argument
3058 if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev)) in hci_write_sc_support_sync()
3061 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_sync()
3066 hdev->features[1][0] |= LMP_HOST_SC; in hci_write_sc_support_sync()
3067 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
3069 hdev->features[1][0] &= ~LMP_HOST_SC; in hci_write_sc_support_sync()
3070 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
3077 int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) in hci_write_ssp_mode_sync() argument
3081 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_ssp_mode_sync()
3082 lmp_host_ssp_capable(hdev)) in hci_write_ssp_mode_sync()
3085 if (!mode && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) { in hci_write_ssp_mode_sync()
3086 __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in hci_write_ssp_mode_sync()
3090 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_sync()
3095 return hci_write_sc_support_sync(hdev, 0x01); in hci_write_ssp_mode_sync()
3098 int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul) in hci_write_le_host_supported_sync() argument
3102 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in hci_write_le_host_supported_sync()
3103 !lmp_bredr_capable(hdev)) in hci_write_le_host_supported_sync()
3109 if (le == lmp_host_le_capable(hdev) && in hci_write_le_host_supported_sync()
3110 simul == lmp_host_le_br_capable(hdev)) in hci_write_le_host_supported_sync()
3118 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_write_le_host_supported_sync()
3122 static int hci_powered_update_adv_sync(struct hci_dev *hdev) in hci_powered_update_adv_sync() argument
3127 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_powered_update_adv_sync()
3135 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) { in hci_powered_update_adv_sync()
3136 hci_le_add_resolve_list_sync(hdev, NULL); in hci_powered_update_adv_sync()
3137 hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_powered_update_adv_sync()
3144 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_powered_update_adv_sync()
3145 list_empty(&hdev->adv_instances)) { in hci_powered_update_adv_sync()
3146 if (ext_adv_capable(hdev)) { in hci_powered_update_adv_sync()
3147 err = hci_setup_ext_adv_instance_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3149 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3151 err = hci_update_adv_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3153 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3156 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_powered_update_adv_sync()
3157 hci_enable_advertising_sync(hdev); in hci_powered_update_adv_sync()
3161 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) in hci_powered_update_adv_sync()
3162 hci_schedule_adv_instance_sync(hdev, adv->instance, true); in hci_powered_update_adv_sync()
3167 static int hci_write_auth_enable_sync(struct hci_dev *hdev) in hci_write_auth_enable_sync() argument
3171 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in hci_write_auth_enable_sync()
3172 if (link_sec == test_bit(HCI_AUTH, &hdev->flags)) in hci_write_auth_enable_sync()
3175 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE, in hci_write_auth_enable_sync()
3180 int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable) in hci_write_fast_connectable_sync() argument
3186 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_write_fast_connectable_sync()
3189 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_write_fast_connectable_sync()
3200 type = hdev->def_page_scan_type; in hci_write_fast_connectable_sync()
3201 cp.interval = cpu_to_le16(hdev->def_page_scan_int); in hci_write_fast_connectable_sync()
3204 cp.window = cpu_to_le16(hdev->def_page_scan_window); in hci_write_fast_connectable_sync()
3206 if (__cpu_to_le16(hdev->page_scan_interval) != cp.interval || in hci_write_fast_connectable_sync()
3207 __cpu_to_le16(hdev->page_scan_window) != cp.window) { in hci_write_fast_connectable_sync()
3208 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3215 if (hdev->page_scan_type != type) in hci_write_fast_connectable_sync()
3216 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3224 static bool disconnected_accept_list_entries(struct hci_dev *hdev) in disconnected_accept_list_entries() argument
3228 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
3231 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
3242 static int hci_write_scan_enable_sync(struct hci_dev *hdev, u8 val) in hci_write_scan_enable_sync() argument
3244 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE, in hci_write_scan_enable_sync()
3249 int hci_update_scan_sync(struct hci_dev *hdev) in hci_update_scan_sync() argument
3253 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_scan_sync()
3256 if (!hdev_is_powered(hdev)) in hci_update_scan_sync()
3259 if (mgmt_powering_down(hdev)) in hci_update_scan_sync()
3262 if (hdev->scanning_paused) in hci_update_scan_sync()
3265 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in hci_update_scan_sync()
3266 disconnected_accept_list_entries(hdev)) in hci_update_scan_sync()
3271 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_update_scan_sync()
3274 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in hci_update_scan_sync()
3275 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in hci_update_scan_sync()
3278 return hci_write_scan_enable_sync(hdev, scan); in hci_update_scan_sync()
3281 int hci_update_name_sync(struct hci_dev *hdev) in hci_update_name_sync() argument
3287 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in hci_update_name_sync()
3289 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME, in hci_update_name_sync()
3306 int hci_powered_update_sync(struct hci_dev *hdev) in hci_powered_update_sync() argument
3315 smp_register(hdev); in hci_powered_update_sync()
3317 err = hci_write_ssp_mode_sync(hdev, 0x01); in hci_powered_update_sync()
3321 err = hci_write_le_host_supported_sync(hdev, 0x01, 0x00); in hci_powered_update_sync()
3325 err = hci_powered_update_adv_sync(hdev); in hci_powered_update_sync()
3329 err = hci_write_auth_enable_sync(hdev); in hci_powered_update_sync()
3333 if (lmp_bredr_capable(hdev)) { in hci_powered_update_sync()
3334 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in hci_powered_update_sync()
3335 hci_write_fast_connectable_sync(hdev, true); in hci_powered_update_sync()
3337 hci_write_fast_connectable_sync(hdev, false); in hci_powered_update_sync()
3338 hci_update_scan_sync(hdev); in hci_powered_update_sync()
3339 hci_update_class_sync(hdev); in hci_powered_update_sync()
3340 hci_update_name_sync(hdev); in hci_powered_update_sync()
3341 hci_update_eir_sync(hdev); in hci_powered_update_sync()
3353 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_powered_update_sync()
3354 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_powered_update_sync()
3355 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))) { in hci_powered_update_sync()
3356 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in hci_powered_update_sync()
3357 return hci_set_random_addr_sync(hdev, in hci_powered_update_sync()
3358 &hdev->static_addr); in hci_powered_update_sync()
3376 static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) in hci_dev_get_bd_addr_from_property() argument
3378 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
3387 if (test_bit(HCI_QUIRK_BDADDR_PROPERTY_BROKEN, &hdev->quirks)) in hci_dev_get_bd_addr_from_property()
3388 baswap(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3390 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3394 int (*func)(struct hci_dev *hdev);
3398 static int hci_init_stage_sync(struct hci_dev *hdev, in hci_init_stage_sync() argument
3406 err = stage[i].func(hdev); in hci_init_stage_sync()
3415 static int hci_read_local_version_sync(struct hci_dev *hdev) in hci_read_local_version_sync() argument
3417 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_VERSION, in hci_read_local_version_sync()
3422 static int hci_read_bd_addr_sync(struct hci_dev *hdev) in hci_read_bd_addr_sync() argument
3424 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BD_ADDR, in hci_read_bd_addr_sync()
3441 int hci_reset_sync(struct hci_dev *hdev) in hci_reset_sync() argument
3445 set_bit(HCI_RESET, &hdev->flags); in hci_reset_sync()
3447 err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL, in hci_reset_sync()
3455 static int hci_init0_sync(struct hci_dev *hdev) in hci_init0_sync() argument
3459 bt_dev_dbg(hdev, ""); in hci_init0_sync()
3462 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init0_sync()
3463 err = hci_reset_sync(hdev); in hci_init0_sync()
3468 return hci_init_stage_sync(hdev, hci_init0); in hci_init0_sync()
3471 static int hci_unconf_init_sync(struct hci_dev *hdev) in hci_unconf_init_sync() argument
3475 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_unconf_init_sync()
3478 err = hci_init0_sync(hdev); in hci_unconf_init_sync()
3482 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_unconf_init_sync()
3483 hci_debugfs_create_basic(hdev); in hci_unconf_init_sync()
3489 static int hci_read_local_features_sync(struct hci_dev *hdev) in hci_read_local_features_sync() argument
3491 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_FEATURES, in hci_read_local_features_sync()
3507 static int hci_read_local_cmds_sync(struct hci_dev *hdev) in hci_read_local_cmds_sync() argument
3517 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_read_local_cmds_sync()
3518 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_read_local_cmds_sync()
3519 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_COMMANDS, in hci_read_local_cmds_sync()
3525 static int hci_init1_sync(struct hci_dev *hdev) in hci_init1_sync() argument
3529 bt_dev_dbg(hdev, ""); in hci_init1_sync()
3532 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init1_sync()
3533 err = hci_reset_sync(hdev); in hci_init1_sync()
3538 return hci_init_stage_sync(hdev, br_init1); in hci_init1_sync()
3542 static int hci_read_buffer_size_sync(struct hci_dev *hdev) in hci_read_buffer_size_sync() argument
3544 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BUFFER_SIZE, in hci_read_buffer_size_sync()
3549 static int hci_read_dev_class_sync(struct hci_dev *hdev) in hci_read_dev_class_sync() argument
3551 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLASS_OF_DEV, in hci_read_dev_class_sync()
3556 static int hci_read_local_name_sync(struct hci_dev *hdev) in hci_read_local_name_sync() argument
3558 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_NAME, in hci_read_local_name_sync()
3563 static int hci_read_voice_setting_sync(struct hci_dev *hdev) in hci_read_voice_setting_sync() argument
3565 return __hci_cmd_sync_status(hdev, HCI_OP_READ_VOICE_SETTING, in hci_read_voice_setting_sync()
3570 static int hci_read_num_supported_iac_sync(struct hci_dev *hdev) in hci_read_num_supported_iac_sync() argument
3572 return __hci_cmd_sync_status(hdev, HCI_OP_READ_NUM_SUPPORTED_IAC, in hci_read_num_supported_iac_sync()
3577 static int hci_read_current_iac_lap_sync(struct hci_dev *hdev) in hci_read_current_iac_lap_sync() argument
3579 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CURRENT_IAC_LAP, in hci_read_current_iac_lap_sync()
3583 static int hci_set_event_filter_sync(struct hci_dev *hdev, u8 flt_type, in hci_set_event_filter_sync() argument
3589 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_set_event_filter_sync()
3592 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_set_event_filter_sync()
3604 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_FLT, in hci_set_event_filter_sync()
3610 static int hci_clear_event_filter_sync(struct hci_dev *hdev) in hci_clear_event_filter_sync() argument
3612 if (!hci_dev_test_flag(hdev, HCI_EVENT_FILTER_CONFIGURED)) in hci_clear_event_filter_sync()
3619 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_clear_event_filter_sync()
3622 return hci_set_event_filter_sync(hdev, HCI_FLT_CLEAR_ALL, 0x00, in hci_clear_event_filter_sync()
3627 static int hci_write_ca_timeout_sync(struct hci_dev *hdev) in hci_write_ca_timeout_sync() argument
3631 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CA_TIMEOUT, in hci_write_ca_timeout_sync()
3656 static int hci_write_ssp_mode_1_sync(struct hci_dev *hdev) in hci_write_ssp_mode_1_sync() argument
3660 if (!lmp_ssp_capable(hdev) || !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_ssp_mode_1_sync()
3669 hdev->max_page = 0x01; in hci_write_ssp_mode_1_sync()
3671 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_1_sync()
3675 static int hci_write_eir_sync(struct hci_dev *hdev) in hci_write_eir_sync() argument
3679 if (!lmp_ssp_capable(hdev) || hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_eir_sync()
3682 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_write_eir_sync()
3685 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_write_eir_sync()
3689 static int hci_write_inquiry_mode_sync(struct hci_dev *hdev) in hci_write_inquiry_mode_sync() argument
3693 if (!lmp_inq_rssi_capable(hdev) && in hci_write_inquiry_mode_sync()
3694 !test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_write_inquiry_mode_sync()
3701 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_write_inquiry_mode_sync()
3703 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_INQUIRY_MODE, in hci_write_inquiry_mode_sync()
3707 static int hci_read_inq_rsp_tx_power_sync(struct hci_dev *hdev) in hci_read_inq_rsp_tx_power_sync() argument
3709 if (!lmp_inq_tx_pwr_capable(hdev)) in hci_read_inq_rsp_tx_power_sync()
3712 return __hci_cmd_sync_status(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, in hci_read_inq_rsp_tx_power_sync()
3716 static int hci_read_local_ext_features_sync(struct hci_dev *hdev, u8 page) in hci_read_local_ext_features_sync() argument
3720 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_sync()
3726 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, in hci_read_local_ext_features_sync()
3730 static int hci_read_local_ext_features_1_sync(struct hci_dev *hdev) in hci_read_local_ext_features_1_sync() argument
3732 return hci_read_local_ext_features_sync(hdev, 0x01); in hci_read_local_ext_features_1_sync()
3755 static int hci_le_read_buffer_size_sync(struct hci_dev *hdev) in hci_le_read_buffer_size_sync() argument
3758 if (iso_capable(hdev) && hdev->commands[41] & 0x20) in hci_le_read_buffer_size_sync()
3759 return __hci_cmd_sync_status(hdev, in hci_le_read_buffer_size_sync()
3763 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_BUFFER_SIZE, in hci_le_read_buffer_size_sync()
3768 static int hci_le_read_local_features_sync(struct hci_dev *hdev) in hci_le_read_local_features_sync() argument
3770 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_LOCAL_FEATURES, in hci_le_read_local_features_sync()
3775 static int hci_le_read_supported_states_sync(struct hci_dev *hdev) in hci_le_read_supported_states_sync() argument
3777 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_SUPPORTED_STATES, in hci_le_read_supported_states_sync()
3792 static int hci_init2_sync(struct hci_dev *hdev) in hci_init2_sync() argument
3796 bt_dev_dbg(hdev, ""); in hci_init2_sync()
3798 err = hci_init_stage_sync(hdev, hci_init2); in hci_init2_sync()
3802 if (lmp_bredr_capable(hdev)) { in hci_init2_sync()
3803 err = hci_init_stage_sync(hdev, br_init2); in hci_init2_sync()
3807 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_sync()
3810 if (lmp_le_capable(hdev)) { in hci_init2_sync()
3811 err = hci_init_stage_sync(hdev, le_init2); in hci_init2_sync()
3815 if (!lmp_bredr_capable(hdev)) in hci_init2_sync()
3816 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in hci_init2_sync()
3822 static int hci_set_event_mask_sync(struct hci_dev *hdev) in hci_set_event_mask_sync() argument
3833 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_set_event_mask_sync()
3836 if (lmp_bredr_capable(hdev)) { in hci_set_event_mask_sync()
3843 if (hdev->suspended) { in hci_set_event_mask_sync()
3858 if (hdev->commands[0] & 0x20) { in hci_set_event_mask_sync()
3863 if (!hdev->suspended) in hci_set_event_mask_sync()
3872 if (hdev->commands[2] & 0x80) in hci_set_event_mask_sync()
3877 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_set_event_mask_sync()
3883 if (lmp_inq_rssi_capable(hdev) || in hci_set_event_mask_sync()
3884 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_set_event_mask_sync()
3887 if (lmp_ext_feat_capable(hdev)) in hci_set_event_mask_sync()
3890 if (lmp_esco_capable(hdev)) { in hci_set_event_mask_sync()
3895 if (lmp_sniffsubr_capable(hdev)) in hci_set_event_mask_sync()
3898 if (lmp_pause_enc_capable(hdev)) in hci_set_event_mask_sync()
3901 if (lmp_ext_inq_capable(hdev)) in hci_set_event_mask_sync()
3904 if (lmp_no_flush_capable(hdev)) in hci_set_event_mask_sync()
3907 if (lmp_lsto_capable(hdev)) in hci_set_event_mask_sync()
3910 if (lmp_ssp_capable(hdev)) { in hci_set_event_mask_sync()
3924 if (lmp_le_capable(hdev)) in hci_set_event_mask_sync()
3927 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK, in hci_set_event_mask_sync()
3931 static int hci_read_stored_link_key_sync(struct hci_dev *hdev) in hci_read_stored_link_key_sync() argument
3935 if (!(hdev->commands[6] & 0x20) || in hci_read_stored_link_key_sync()
3936 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_read_stored_link_key_sync()
3943 return __hci_cmd_sync_status(hdev, HCI_OP_READ_STORED_LINK_KEY, in hci_read_stored_link_key_sync()
3947 static int hci_setup_link_policy_sync(struct hci_dev *hdev) in hci_setup_link_policy_sync() argument
3952 if (!(hdev->commands[5] & 0x10)) in hci_setup_link_policy_sync()
3957 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy_sync()
3959 if (lmp_hold_capable(hdev)) in hci_setup_link_policy_sync()
3961 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy_sync()
3963 if (lmp_park_capable(hdev)) in hci_setup_link_policy_sync()
3968 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, in hci_setup_link_policy_sync()
3972 static int hci_read_page_scan_activity_sync(struct hci_dev *hdev) in hci_read_page_scan_activity_sync() argument
3974 if (!(hdev->commands[8] & 0x01)) in hci_read_page_scan_activity_sync()
3977 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_ACTIVITY, in hci_read_page_scan_activity_sync()
3981 static int hci_read_def_err_data_reporting_sync(struct hci_dev *hdev) in hci_read_def_err_data_reporting_sync() argument
3983 if (!(hdev->commands[18] & 0x04) || in hci_read_def_err_data_reporting_sync()
3984 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_read_def_err_data_reporting_sync()
3985 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_read_def_err_data_reporting_sync()
3988 return __hci_cmd_sync_status(hdev, HCI_OP_READ_DEF_ERR_DATA_REPORTING, in hci_read_def_err_data_reporting_sync()
3992 static int hci_read_page_scan_type_sync(struct hci_dev *hdev) in hci_read_page_scan_type_sync() argument
3998 if (!(hdev->commands[13] & 0x01)) in hci_read_page_scan_type_sync()
4001 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_TYPE, in hci_read_page_scan_type_sync()
4006 static int hci_read_local_ext_features_all_sync(struct hci_dev *hdev) in hci_read_local_ext_features_all_sync() argument
4011 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_all_sync()
4014 for (page = 2; page < HCI_MAX_PAGES && page <= hdev->max_page; in hci_read_local_ext_features_all_sync()
4016 err = hci_read_local_ext_features_sync(hdev, page); in hci_read_local_ext_features_all_sync()
4043 static int hci_le_set_event_mask_sync(struct hci_dev *hdev) in hci_le_set_event_mask_sync() argument
4047 if (!lmp_le_capable(hdev)) in hci_le_set_event_mask_sync()
4052 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_le_set_event_mask_sync()
4058 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_le_set_event_mask_sync()
4065 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_le_set_event_mask_sync()
4071 if (use_enhanced_conn_complete(hdev)) in hci_le_set_event_mask_sync()
4077 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_le_set_event_mask_sync()
4083 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_le_set_event_mask_sync()
4089 if (hdev->commands[26] & 0x08) in hci_le_set_event_mask_sync()
4095 if (hdev->commands[26] & 0x10) in hci_le_set_event_mask_sync()
4101 if (hdev->commands[27] & 0x04) in hci_le_set_event_mask_sync()
4107 if (hdev->commands[27] & 0x20) in hci_le_set_event_mask_sync()
4114 if (hdev->commands[34] & 0x02) in hci_le_set_event_mask_sync()
4121 if (hdev->commands[34] & 0x04) in hci_le_set_event_mask_sync()
4127 if (hdev->commands[35] & (0x20 | 0x40)) in hci_le_set_event_mask_sync()
4134 if (use_ext_scan(hdev)) in hci_le_set_event_mask_sync()
4140 if (ext_adv_capable(hdev)) in hci_le_set_event_mask_sync()
4143 if (cis_capable(hdev)) { in hci_le_set_event_mask_sync()
4145 if (cis_peripheral_capable(hdev)) in hci_le_set_event_mask_sync()
4149 if (bis_capable(hdev)) { in hci_le_set_event_mask_sync()
4159 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EVENT_MASK, in hci_le_set_event_mask_sync()
4164 static int hci_le_read_adv_tx_power_sync(struct hci_dev *hdev) in hci_le_read_adv_tx_power_sync() argument
4166 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_le_read_adv_tx_power_sync()
4173 return __hci_cmd_sync_status(hdev, in hci_le_read_adv_tx_power_sync()
4182 static int hci_le_read_tx_power_sync(struct hci_dev *hdev) in hci_le_read_tx_power_sync() argument
4184 if (!(hdev->commands[38] & 0x80) || in hci_le_read_tx_power_sync()
4185 test_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks)) in hci_le_read_tx_power_sync()
4188 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_TRANSMIT_POWER, in hci_le_read_tx_power_sync()
4193 static int hci_le_read_accept_list_size_sync(struct hci_dev *hdev) in hci_le_read_accept_list_size_sync() argument
4195 if (!(hdev->commands[26] & 0x40)) in hci_le_read_accept_list_size_sync()
4198 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_ACCEPT_LIST_SIZE, in hci_le_read_accept_list_size_sync()
4203 static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) in hci_le_clear_accept_list_sync() argument
4205 if (!(hdev->commands[26] & 0x80)) in hci_le_clear_accept_list_sync()
4208 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_ACCEPT_LIST, 0, NULL, in hci_le_clear_accept_list_sync()
4213 static int hci_le_read_resolv_list_size_sync(struct hci_dev *hdev) in hci_le_read_resolv_list_size_sync() argument
4215 if (!(hdev->commands[34] & 0x40)) in hci_le_read_resolv_list_size_sync()
4218 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_RESOLV_LIST_SIZE, in hci_le_read_resolv_list_size_sync()
4223 static int hci_le_clear_resolv_list_sync(struct hci_dev *hdev) in hci_le_clear_resolv_list_sync() argument
4225 if (!(hdev->commands[34] & 0x20)) in hci_le_clear_resolv_list_sync()
4228 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL, in hci_le_clear_resolv_list_sync()
4233 static int hci_le_set_rpa_timeout_sync(struct hci_dev *hdev) in hci_le_set_rpa_timeout_sync() argument
4235 __le16 timeout = cpu_to_le16(hdev->rpa_timeout); in hci_le_set_rpa_timeout_sync()
4237 if (!(hdev->commands[35] & 0x04) || in hci_le_set_rpa_timeout_sync()
4238 test_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT, &hdev->quirks)) in hci_le_set_rpa_timeout_sync()
4241 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RPA_TIMEOUT, in hci_le_set_rpa_timeout_sync()
4247 static int hci_le_read_max_data_len_sync(struct hci_dev *hdev) in hci_le_read_max_data_len_sync() argument
4249 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_max_data_len_sync()
4252 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL, in hci_le_read_max_data_len_sync()
4257 static int hci_le_read_def_data_len_sync(struct hci_dev *hdev) in hci_le_read_def_data_len_sync() argument
4259 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_def_data_len_sync()
4262 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_DEF_DATA_LEN, 0, NULL, in hci_le_read_def_data_len_sync()
4267 static int hci_le_read_num_support_adv_sets_sync(struct hci_dev *hdev) in hci_le_read_num_support_adv_sets_sync() argument
4269 if (!ext_adv_capable(hdev)) in hci_le_read_num_support_adv_sets_sync()
4272 return __hci_cmd_sync_status(hdev, in hci_le_read_num_support_adv_sets_sync()
4278 static int hci_set_le_support_sync(struct hci_dev *hdev) in hci_set_le_support_sync() argument
4283 if (!lmp_bredr_capable(hdev)) in hci_set_le_support_sync()
4288 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support_sync()
4293 if (cp.le == lmp_host_le_capable(hdev)) in hci_set_le_support_sync()
4296 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_set_le_support_sync()
4301 static int hci_le_set_host_feature_sync(struct hci_dev *hdev) in hci_le_set_host_feature_sync() argument
4305 if (!iso_capable(hdev)) in hci_le_set_host_feature_sync()
4314 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_HOST_FEATURE, in hci_le_set_host_feature_sync()
4349 static int hci_init3_sync(struct hci_dev *hdev) in hci_init3_sync() argument
4353 bt_dev_dbg(hdev, ""); in hci_init3_sync()
4355 err = hci_init_stage_sync(hdev, hci_init3); in hci_init3_sync()
4359 if (lmp_le_capable(hdev)) in hci_init3_sync()
4360 return hci_init_stage_sync(hdev, le_init3); in hci_init3_sync()
4365 static int hci_delete_stored_link_key_sync(struct hci_dev *hdev) in hci_delete_stored_link_key_sync() argument
4382 if (!(hdev->commands[6] & 0x80) || in hci_delete_stored_link_key_sync()
4383 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_delete_stored_link_key_sync()
4390 return __hci_cmd_sync_status(hdev, HCI_OP_DELETE_STORED_LINK_KEY, in hci_delete_stored_link_key_sync()
4394 static int hci_set_event_mask_page_2_sync(struct hci_dev *hdev) in hci_set_event_mask_page_2_sync() argument
4400 if (!(hdev->commands[22] & 0x04)) in hci_set_event_mask_page_2_sync()
4406 if (lmp_cpb_central_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4417 if (lmp_cpb_peripheral_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4426 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2_sync()
4440 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK_PAGE_2, in hci_set_event_mask_page_2_sync()
4445 static int hci_read_local_codecs_sync(struct hci_dev *hdev) in hci_read_local_codecs_sync() argument
4447 if (hdev->commands[45] & 0x04) in hci_read_local_codecs_sync()
4448 hci_read_supported_codecs_v2(hdev); in hci_read_local_codecs_sync()
4449 else if (hdev->commands[29] & 0x20) in hci_read_local_codecs_sync()
4450 hci_read_supported_codecs(hdev); in hci_read_local_codecs_sync()
4456 static int hci_read_local_pairing_opts_sync(struct hci_dev *hdev) in hci_read_local_pairing_opts_sync() argument
4458 if (!(hdev->commands[41] & 0x08)) in hci_read_local_pairing_opts_sync()
4461 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_PAIRING_OPTS, in hci_read_local_pairing_opts_sync()
4466 static int hci_get_mws_transport_config_sync(struct hci_dev *hdev) in hci_get_mws_transport_config_sync() argument
4468 if (!mws_transport_config_capable(hdev)) in hci_get_mws_transport_config_sync()
4471 return __hci_cmd_sync_status(hdev, HCI_OP_GET_MWS_TRANSPORT_CONFIG, in hci_get_mws_transport_config_sync()
4476 static int hci_read_sync_train_params_sync(struct hci_dev *hdev) in hci_read_sync_train_params_sync() argument
4478 if (!lmp_sync_train_capable(hdev)) in hci_read_sync_train_params_sync()
4481 return __hci_cmd_sync_status(hdev, HCI_OP_READ_SYNC_TRAIN_PARAMS, in hci_read_sync_train_params_sync()
4486 static int hci_write_sc_support_1_sync(struct hci_dev *hdev) in hci_write_sc_support_1_sync() argument
4490 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_sc_support_1_sync()
4491 !bredr_sc_enabled(hdev)) in hci_write_sc_support_1_sync()
4494 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_1_sync()
4502 static int hci_set_err_data_report_sync(struct hci_dev *hdev) in hci_set_err_data_report_sync() argument
4505 bool enabled = hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED); in hci_set_err_data_report_sync()
4507 if (!(hdev->commands[18] & 0x08) || in hci_set_err_data_report_sync()
4508 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_set_err_data_report_sync()
4509 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_set_err_data_report_sync()
4512 if (enabled == hdev->err_data_reporting) in hci_set_err_data_report_sync()
4519 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING, in hci_set_err_data_report_sync()
4544 static int hci_le_set_write_def_data_len_sync(struct hci_dev *hdev) in hci_le_set_write_def_data_len_sync() argument
4548 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_set_write_def_data_len_sync()
4552 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_le_set_write_def_data_len_sync()
4553 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_le_set_write_def_data_len_sync()
4555 return __hci_cmd_sync_status(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN, in hci_le_set_write_def_data_len_sync()
4562 static int hci_le_set_default_phy_sync(struct hci_dev *hdev) in hci_le_set_default_phy_sync() argument
4566 if (!(hdev->commands[35] & 0x20)) { in hci_le_set_default_phy_sync()
4570 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4571 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4581 if (le_2m_capable(hdev)) { in hci_le_set_default_phy_sync()
4587 if (le_coded_capable(hdev)) { in hci_le_set_default_phy_sync()
4592 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in hci_le_set_default_phy_sync()
4604 static int hci_init4_sync(struct hci_dev *hdev) in hci_init4_sync() argument
4608 bt_dev_dbg(hdev, ""); in hci_init4_sync()
4610 err = hci_init_stage_sync(hdev, hci_init4); in hci_init4_sync()
4614 if (lmp_le_capable(hdev)) in hci_init4_sync()
4615 return hci_init_stage_sync(hdev, le_init4); in hci_init4_sync()
4620 static int hci_init_sync(struct hci_dev *hdev) in hci_init_sync() argument
4624 err = hci_init1_sync(hdev); in hci_init_sync()
4628 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_init_sync()
4629 hci_debugfs_create_basic(hdev); in hci_init_sync()
4631 err = hci_init2_sync(hdev); in hci_init_sync()
4635 err = hci_init3_sync(hdev); in hci_init_sync()
4639 err = hci_init4_sync(hdev); in hci_init_sync()
4655 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_init_sync()
4656 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_init_sync()
4659 if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) in hci_init_sync()
4662 hci_debugfs_create_common(hdev); in hci_init_sync()
4664 if (lmp_bredr_capable(hdev)) in hci_init_sync()
4665 hci_debugfs_create_bredr(hdev); in hci_init_sync()
4667 if (lmp_le_capable(hdev)) in hci_init_sync()
4668 hci_debugfs_create_le(hdev); in hci_init_sync()
4708 static int hci_dev_setup_sync(struct hci_dev *hdev) in hci_dev_setup_sync() argument
4714 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_setup_sync()
4715 !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) in hci_dev_setup_sync()
4718 bt_dev_dbg(hdev, ""); in hci_dev_setup_sync()
4720 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_setup_sync()
4722 if (hdev->setup) in hci_dev_setup_sync()
4723 ret = hdev->setup(hdev); in hci_dev_setup_sync()
4726 if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) in hci_dev_setup_sync()
4727 bt_dev_warn(hdev, "%s", hci_broken_table[i].desc); in hci_dev_setup_sync()
4734 invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in hci_dev_setup_sync()
4735 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); in hci_dev_setup_sync()
4737 if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks) && in hci_dev_setup_sync()
4738 !bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_setup_sync()
4739 hci_dev_get_bd_addr_from_property(hdev); in hci_dev_setup_sync()
4741 if (invalid_bdaddr && bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_setup_sync()
4742 hdev->set_bdaddr) { in hci_dev_setup_sync()
4743 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_setup_sync()
4759 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_setup_sync()
4761 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_setup_sync()
4771 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_setup_sync()
4772 return hci_unconf_init_sync(hdev); in hci_dev_setup_sync()
4782 static int hci_dev_init_sync(struct hci_dev *hdev) in hci_dev_init_sync() argument
4786 bt_dev_dbg(hdev, ""); in hci_dev_init_sync()
4788 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_init_sync()
4789 set_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4791 ret = hci_dev_setup_sync(hdev); in hci_dev_init_sync()
4793 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_init_sync()
4799 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_init_sync()
4800 hdev->set_bdaddr) in hci_dev_init_sync()
4801 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_init_sync()
4807 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_init_sync()
4808 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4809 ret = hci_init_sync(hdev); in hci_dev_init_sync()
4810 if (!ret && hdev->post_init) in hci_dev_init_sync()
4811 ret = hdev->post_init(hdev); in hci_dev_init_sync()
4819 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_init_sync()
4820 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_init_sync()
4821 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_init_sync()
4822 ret = hdev->set_diag(hdev, true); in hci_dev_init_sync()
4824 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4825 msft_do_open(hdev); in hci_dev_init_sync()
4826 aosp_do_open(hdev); in hci_dev_init_sync()
4829 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4834 int hci_dev_open_sync(struct hci_dev *hdev) in hci_dev_open_sync() argument
4838 bt_dev_dbg(hdev, ""); in hci_dev_open_sync()
4840 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_open_sync()
4845 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
4846 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_open_sync()
4850 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_open_sync()
4864 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
4865 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_open_sync()
4866 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_open_sync()
4872 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open_sync()
4877 if (hdev->open(hdev)) { in hci_dev_open_sync()
4882 hci_devcd_reset(hdev); in hci_dev_open_sync()
4884 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4885 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_open_sync()
4887 ret = hci_dev_init_sync(hdev); in hci_dev_open_sync()
4889 hci_dev_hold(hdev); in hci_dev_open_sync()
4890 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_open_sync()
4891 hci_adv_instances_set_rpa_expired(hdev, true); in hci_dev_open_sync()
4892 set_bit(HCI_UP, &hdev->flags); in hci_dev_open_sync()
4893 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_open_sync()
4894 hci_leds_update_powered(hdev, true); in hci_dev_open_sync()
4895 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
4896 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_open_sync()
4897 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open_sync()
4898 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
4899 hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_open_sync()
4900 ret = hci_powered_update_sync(hdev); in hci_dev_open_sync()
4901 mgmt_power_on(hdev, ret); in hci_dev_open_sync()
4905 flush_work(&hdev->tx_work); in hci_dev_open_sync()
4911 flush_work(&hdev->rx_work); in hci_dev_open_sync()
4912 flush_work(&hdev->cmd_work); in hci_dev_open_sync()
4914 skb_queue_purge(&hdev->cmd_q); in hci_dev_open_sync()
4915 skb_queue_purge(&hdev->rx_q); in hci_dev_open_sync()
4917 if (hdev->flush) in hci_dev_open_sync()
4918 hdev->flush(hdev); in hci_dev_open_sync()
4920 if (hdev->sent_cmd) { in hci_dev_open_sync()
4921 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_open_sync()
4922 kfree_skb(hdev->sent_cmd); in hci_dev_open_sync()
4923 hdev->sent_cmd = NULL; in hci_dev_open_sync()
4926 if (hdev->req_skb) { in hci_dev_open_sync()
4927 kfree_skb(hdev->req_skb); in hci_dev_open_sync()
4928 hdev->req_skb = NULL; in hci_dev_open_sync()
4931 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4932 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_open_sync()
4934 hdev->close(hdev); in hci_dev_open_sync()
4935 hdev->flags &= BIT(HCI_RAW); in hci_dev_open_sync()
4943 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
4947 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
4959 static int hci_dev_shutdown(struct hci_dev *hdev) in hci_dev_shutdown() argument
4969 hci_dev_test_and_clear_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
4971 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_shutdown()
4972 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_shutdown()
4974 if (hdev->shutdown) in hci_dev_shutdown()
4975 err = hdev->shutdown(hdev); in hci_dev_shutdown()
4979 hci_dev_set_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
4984 int hci_dev_close_sync(struct hci_dev *hdev) in hci_dev_close_sync() argument
4989 bt_dev_dbg(hdev, ""); in hci_dev_close_sync()
4991 cancel_delayed_work(&hdev->power_off); in hci_dev_close_sync()
4992 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
4993 cancel_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
4994 cancel_delayed_work(&hdev->le_scan_restart); in hci_dev_close_sync()
4996 hci_request_cancel_all(hdev); in hci_dev_close_sync()
4998 if (hdev->adv_instance_timeout) { in hci_dev_close_sync()
4999 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_dev_close_sync()
5000 hdev->adv_instance_timeout = 0; in hci_dev_close_sync()
5003 err = hci_dev_shutdown(hdev); in hci_dev_close_sync()
5005 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_close_sync()
5006 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5010 hci_leds_update_powered(hdev, false); in hci_dev_close_sync()
5013 flush_work(&hdev->tx_work); in hci_dev_close_sync()
5014 flush_work(&hdev->rx_work); in hci_dev_close_sync()
5016 if (hdev->discov_timeout > 0) { in hci_dev_close_sync()
5017 hdev->discov_timeout = 0; in hci_dev_close_sync()
5018 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_close_sync()
5019 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_close_sync()
5022 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_close_sync()
5023 cancel_delayed_work(&hdev->service_cache); in hci_dev_close_sync()
5025 if (hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_close_sync()
5028 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_close_sync()
5030 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_close_sync()
5037 drain_workqueue(hdev->workqueue); in hci_dev_close_sync()
5039 hci_dev_lock(hdev); in hci_dev_close_sync()
5041 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_close_sync()
5043 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_close_sync()
5045 if (!auto_off && !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_close_sync()
5046 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_close_sync()
5047 __mgmt_power_off(hdev); in hci_dev_close_sync()
5049 hci_inquiry_cache_flush(hdev); in hci_dev_close_sync()
5050 hci_pend_le_actions_clear(hdev); in hci_dev_close_sync()
5051 hci_conn_hash_flush(hdev); in hci_dev_close_sync()
5053 smp_unregister(hdev); in hci_dev_close_sync()
5054 hci_dev_unlock(hdev); in hci_dev_close_sync()
5056 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_close_sync()
5058 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close_sync()
5059 aosp_do_close(hdev); in hci_dev_close_sync()
5060 msft_do_close(hdev); in hci_dev_close_sync()
5063 if (hdev->flush) in hci_dev_close_sync()
5064 hdev->flush(hdev); in hci_dev_close_sync()
5067 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5068 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_close_sync()
5069 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_close_sync()
5070 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_close_sync()
5071 set_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5072 hci_reset_sync(hdev); in hci_dev_close_sync()
5073 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5077 flush_work(&hdev->cmd_work); in hci_dev_close_sync()
5080 skb_queue_purge(&hdev->rx_q); in hci_dev_close_sync()
5081 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5082 skb_queue_purge(&hdev->raw_q); in hci_dev_close_sync()
5085 if (hdev->sent_cmd) { in hci_dev_close_sync()
5086 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5087 kfree_skb(hdev->sent_cmd); in hci_dev_close_sync()
5088 hdev->sent_cmd = NULL; in hci_dev_close_sync()
5092 if (hdev->req_skb) { in hci_dev_close_sync()
5093 kfree_skb(hdev->req_skb); in hci_dev_close_sync()
5094 hdev->req_skb = NULL; in hci_dev_close_sync()
5097 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_close_sync()
5098 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_close_sync()
5101 hdev->close(hdev); in hci_dev_close_sync()
5104 hdev->flags &= BIT(HCI_RAW); in hci_dev_close_sync()
5105 hci_dev_clear_volatile_flags(hdev); in hci_dev_close_sync()
5107 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_close_sync()
5108 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_close_sync()
5109 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_close_sync()
5110 hci_codec_list_clear(&hdev->local_codecs); in hci_dev_close_sync()
5112 hci_dev_put(hdev); in hci_dev_close_sync()
5122 static int hci_power_on_sync(struct hci_dev *hdev) in hci_power_on_sync() argument
5126 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on_sync()
5127 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on_sync()
5128 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5129 cancel_delayed_work(&hdev->power_off); in hci_power_on_sync()
5130 return hci_powered_update_sync(hdev); in hci_power_on_sync()
5133 err = hci_dev_open_sync(hdev); in hci_power_on_sync()
5141 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on_sync()
5142 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on_sync()
5143 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on_sync()
5144 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on_sync()
5145 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on_sync()
5146 hci_dev_close_sync(hdev); in hci_power_on_sync()
5147 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5148 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on_sync()
5152 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on_sync()
5156 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5157 set_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5166 mgmt_index_added(hdev); in hci_power_on_sync()
5167 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on_sync()
5171 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5172 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5178 mgmt_index_added(hdev); in hci_power_on_sync()
5184 static int hci_remote_name_cancel_sync(struct hci_dev *hdev, bdaddr_t *addr) in hci_remote_name_cancel_sync() argument
5191 return __hci_cmd_sync_status(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, in hci_remote_name_cancel_sync()
5195 int hci_stop_discovery_sync(struct hci_dev *hdev) in hci_stop_discovery_sync() argument
5197 struct discovery_state *d = &hdev->discovery; in hci_stop_discovery_sync()
5201 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_stop_discovery_sync()
5204 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_stop_discovery_sync()
5205 err = __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY_CANCEL, in hci_stop_discovery_sync()
5211 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_stop_discovery_sync()
5212 cancel_delayed_work(&hdev->le_scan_disable); in hci_stop_discovery_sync()
5213 cancel_delayed_work(&hdev->le_scan_restart); in hci_stop_discovery_sync()
5215 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5221 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5227 if (use_ll_privacy(hdev)) in hci_stop_discovery_sync()
5228 hci_resume_advertising_sync(hdev); in hci_stop_discovery_sync()
5235 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_stop_discovery_sync()
5240 return hci_remote_name_cancel_sync(hdev, &e->data.bdaddr); in hci_stop_discovery_sync()
5246 static int hci_disconnect_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_disconnect_sync() argument
5255 hci_dev_lock(hdev); in hci_disconnect_sync()
5257 hci_dev_unlock(hdev); in hci_disconnect_sync()
5272 return __hci_cmd_sync_status_sk(hdev, HCI_OP_DISCONNECT, in hci_disconnect_sync()
5277 return __hci_cmd_sync_status(hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp, in hci_disconnect_sync()
5281 static int hci_le_connect_cancel_sync(struct hci_dev *hdev, in hci_le_connect_cancel_sync() argument
5294 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, in hci_le_connect_cancel_sync()
5298 static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_connect_cancel_sync() argument
5302 return hci_le_connect_cancel_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5314 return hci_disconnect_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5326 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_connect_cancel_sync()
5335 return __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5340 return __hci_cmd_sync_status(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5344 static int hci_reject_sco_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_sco_sync() argument
5359 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_SYNC_CONN_REQ, in hci_reject_sco_sync()
5363 static int hci_le_reject_cis_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_le_reject_cis_sync() argument
5372 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REJECT_CIS, in hci_le_reject_cis_sync()
5376 static int hci_reject_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_conn_sync() argument
5382 return hci_le_reject_cis_sync(hdev, conn, reason); in hci_reject_conn_sync()
5385 return hci_reject_sco_sync(hdev, conn, reason); in hci_reject_conn_sync()
5391 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_CONN_REQ, in hci_reject_conn_sync()
5395 int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) in hci_abort_conn_sync() argument
5405 err = hci_disconnect_sync(hdev, conn, reason); in hci_abort_conn_sync()
5408 err = hci_connect_cancel_sync(hdev, conn, reason); in hci_abort_conn_sync()
5411 err = hci_reject_conn_sync(hdev, conn, reason); in hci_abort_conn_sync()
5421 hci_dev_lock(hdev); in hci_abort_conn_sync()
5424 c = hci_conn_hash_lookup_handle(hdev, handle); in hci_abort_conn_sync()
5444 hci_dev_unlock(hdev); in hci_abort_conn_sync()
5448 static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) in hci_disconnect_all_sync() argument
5450 struct list_head *head = &hdev->conn_hash.list; in hci_disconnect_all_sync()
5463 hci_abort_conn_sync(hdev, conn, reason); in hci_disconnect_all_sync()
5479 static int hci_power_off_sync(struct hci_dev *hdev) in hci_power_off_sync() argument
5484 if (!test_bit(HCI_UP, &hdev->flags)) in hci_power_off_sync()
5487 if (test_bit(HCI_ISCAN, &hdev->flags) || in hci_power_off_sync()
5488 test_bit(HCI_PSCAN, &hdev->flags)) { in hci_power_off_sync()
5489 err = hci_write_scan_enable_sync(hdev, 0x00); in hci_power_off_sync()
5494 err = hci_clear_adv_sync(hdev, NULL, false); in hci_power_off_sync()
5498 err = hci_stop_discovery_sync(hdev); in hci_power_off_sync()
5503 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_power_off_sync()
5507 return hci_dev_close_sync(hdev); in hci_power_off_sync()
5510 int hci_set_powered_sync(struct hci_dev *hdev, u8 val) in hci_set_powered_sync() argument
5513 return hci_power_on_sync(hdev); in hci_set_powered_sync()
5515 return hci_power_off_sync(hdev); in hci_set_powered_sync()
5518 static int hci_write_iac_sync(struct hci_dev *hdev) in hci_write_iac_sync() argument
5522 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_write_iac_sync()
5527 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_write_iac_sync()
5529 cp.num_iac = min_t(u8, hdev->num_iac, 2); in hci_write_iac_sync()
5544 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CURRENT_IAC_LAP, in hci_write_iac_sync()
5549 int hci_update_discoverable_sync(struct hci_dev *hdev) in hci_update_discoverable_sync() argument
5553 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_update_discoverable_sync()
5554 err = hci_write_iac_sync(hdev); in hci_update_discoverable_sync()
5558 err = hci_update_scan_sync(hdev); in hci_update_discoverable_sync()
5562 err = hci_update_class_sync(hdev); in hci_update_discoverable_sync()
5570 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in hci_update_discoverable_sync()
5571 err = hci_update_adv_data_sync(hdev, 0x00); in hci_update_discoverable_sync()
5578 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in hci_update_discoverable_sync()
5579 if (ext_adv_capable(hdev)) in hci_update_discoverable_sync()
5580 err = hci_start_ext_adv_sync(hdev, 0x00); in hci_update_discoverable_sync()
5582 err = hci_enable_advertising_sync(hdev); in hci_update_discoverable_sync()
5589 static int update_discoverable_sync(struct hci_dev *hdev, void *data) in update_discoverable_sync() argument
5591 return hci_update_discoverable_sync(hdev); in update_discoverable_sync()
5594 int hci_update_discoverable(struct hci_dev *hdev) in hci_update_discoverable() argument
5597 if (hdev_is_powered(hdev) && in hci_update_discoverable()
5598 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_update_discoverable()
5599 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in hci_update_discoverable()
5600 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in hci_update_discoverable()
5601 return hci_cmd_sync_queue(hdev, update_discoverable_sync, NULL, in hci_update_discoverable()
5607 int hci_update_connectable_sync(struct hci_dev *hdev) in hci_update_connectable_sync() argument
5611 err = hci_update_scan_sync(hdev); in hci_update_connectable_sync()
5619 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_connectable_sync()
5620 err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in hci_update_connectable_sync()
5623 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_update_connectable_sync()
5624 !list_empty(&hdev->adv_instances)) { in hci_update_connectable_sync()
5625 if (ext_adv_capable(hdev)) in hci_update_connectable_sync()
5626 err = hci_start_ext_adv_sync(hdev, in hci_update_connectable_sync()
5627 hdev->cur_adv_instance); in hci_update_connectable_sync()
5629 err = hci_enable_advertising_sync(hdev); in hci_update_connectable_sync()
5635 return hci_update_passive_scan_sync(hdev); in hci_update_connectable_sync()
5638 static int hci_inquiry_sync(struct hci_dev *hdev, u8 length) in hci_inquiry_sync() argument
5644 bt_dev_dbg(hdev, ""); in hci_inquiry_sync()
5646 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inquiry_sync()
5649 hci_dev_lock(hdev); in hci_inquiry_sync()
5650 hci_inquiry_cache_flush(hdev); in hci_inquiry_sync()
5651 hci_dev_unlock(hdev); in hci_inquiry_sync()
5655 if (hdev->discovery.limited) in hci_inquiry_sync()
5662 return __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY, in hci_inquiry_sync()
5666 static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) in hci_active_scan_sync() argument
5675 bt_dev_dbg(hdev, ""); in hci_active_scan_sync()
5681 err = hci_scan_disable_sync(hdev); in hci_active_scan_sync()
5683 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_active_scan_sync()
5687 cancel_interleave_scan(hdev); in hci_active_scan_sync()
5692 err = hci_pause_addr_resolution(hdev); in hci_active_scan_sync()
5700 err = hci_update_random_address_sync(hdev, true, scan_use_rpa(hdev), in hci_active_scan_sync()
5705 if (hci_is_adv_monitoring(hdev)) { in hci_active_scan_sync()
5722 err = hci_start_scan_sync(hdev, LE_SCAN_ACTIVE, interval, in hci_active_scan_sync()
5723 hdev->le_scan_window_discovery, in hci_active_scan_sync()
5730 if (use_ll_privacy(hdev)) in hci_active_scan_sync()
5731 hci_resume_advertising_sync(hdev); in hci_active_scan_sync()
5734 hci_update_passive_scan_sync(hdev); in hci_active_scan_sync()
5738 static int hci_start_interleaved_discovery_sync(struct hci_dev *hdev) in hci_start_interleaved_discovery_sync() argument
5742 bt_dev_dbg(hdev, ""); in hci_start_interleaved_discovery_sync()
5744 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery * 2); in hci_start_interleaved_discovery_sync()
5748 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN); in hci_start_interleaved_discovery_sync()
5751 int hci_start_discovery_sync(struct hci_dev *hdev) in hci_start_discovery_sync() argument
5756 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in hci_start_discovery_sync()
5758 switch (hdev->discovery.type) { in hci_start_discovery_sync()
5760 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN); in hci_start_discovery_sync()
5771 &hdev->quirks)) { in hci_start_discovery_sync()
5777 err = hci_start_interleaved_discovery_sync(hdev); in hci_start_discovery_sync()
5781 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in hci_start_discovery_sync()
5782 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5786 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5795 bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout)); in hci_start_discovery_sync()
5802 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in hci_start_discovery_sync()
5803 hdev->discovery.result_filtering) { in hci_start_discovery_sync()
5804 hdev->discovery.scan_start = jiffies; in hci_start_discovery_sync()
5805 hdev->discovery.scan_duration = timeout; in hci_start_discovery_sync()
5808 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in hci_start_discovery_sync()
5813 static void hci_suspend_monitor_sync(struct hci_dev *hdev) in hci_suspend_monitor_sync() argument
5815 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_suspend_monitor_sync()
5817 msft_suspend_sync(hdev); in hci_suspend_monitor_sync()
5825 static int hci_pause_discovery_sync(struct hci_dev *hdev) in hci_pause_discovery_sync() argument
5827 int old_state = hdev->discovery.state; in hci_pause_discovery_sync()
5832 hdev->discovery_paused) in hci_pause_discovery_sync()
5835 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_pause_discovery_sync()
5836 err = hci_stop_discovery_sync(hdev); in hci_pause_discovery_sync()
5840 hdev->discovery_paused = true; in hci_pause_discovery_sync()
5841 hdev->discovery_old_state = old_state; in hci_pause_discovery_sync()
5842 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_pause_discovery_sync()
5847 static int hci_update_event_filter_sync(struct hci_dev *hdev) in hci_update_event_filter_sync() argument
5851 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_update_event_filter_sync()
5854 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_event_filter_sync()
5860 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_update_event_filter_sync()
5864 hci_clear_event_filter_sync(hdev); in hci_update_event_filter_sync()
5866 list_for_each_entry(b, &hdev->accept_list, list) { in hci_update_event_filter_sync()
5870 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_update_event_filter_sync()
5872 err = hci_set_event_filter_sync(hdev, HCI_FLT_CONN_SETUP, in hci_update_event_filter_sync()
5877 bt_dev_dbg(hdev, "Failed to set event filter for %pMR", in hci_update_event_filter_sync()
5884 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
5886 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
5892 static int hci_pause_scan_sync(struct hci_dev *hdev) in hci_pause_scan_sync() argument
5894 if (hdev->scanning_paused) in hci_pause_scan_sync()
5898 if (test_bit(HCI_PSCAN, &hdev->flags)) in hci_pause_scan_sync()
5899 hci_write_scan_enable_sync(hdev, SCAN_DISABLED); in hci_pause_scan_sync()
5901 hci_scan_disable_sync(hdev); in hci_pause_scan_sync()
5903 hdev->scanning_paused = true; in hci_pause_scan_sync()
5921 int hci_suspend_sync(struct hci_dev *hdev) in hci_suspend_sync() argument
5926 if (hdev->suspended) in hci_suspend_sync()
5930 hdev->suspended = true; in hci_suspend_sync()
5933 hci_pause_discovery_sync(hdev); in hci_suspend_sync()
5936 hci_pause_advertising_sync(hdev); in hci_suspend_sync()
5939 hci_suspend_monitor_sync(hdev); in hci_suspend_sync()
5942 hci_pause_scan_sync(hdev); in hci_suspend_sync()
5944 if (hci_conn_count(hdev)) { in hci_suspend_sync()
5946 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_suspend_sync()
5949 hdev->suspend_state = BT_RUNNING; in hci_suspend_sync()
5950 hci_resume_sync(hdev); in hci_suspend_sync()
5957 hci_set_event_mask_sync(hdev); in hci_suspend_sync()
5963 if (!hdev->wakeup || !hdev->wakeup(hdev)) { in hci_suspend_sync()
5964 hdev->suspend_state = BT_SUSPEND_DISCONNECT; in hci_suspend_sync()
5969 hdev->scanning_paused = false; in hci_suspend_sync()
5972 hci_update_event_filter_sync(hdev); in hci_suspend_sync()
5975 hci_update_passive_scan_sync(hdev); in hci_suspend_sync()
5978 hdev->scanning_paused = true; in hci_suspend_sync()
5980 hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; in hci_suspend_sync()
5986 static int hci_resume_discovery_sync(struct hci_dev *hdev) in hci_resume_discovery_sync() argument
5991 if (!hdev->discovery_paused) in hci_resume_discovery_sync()
5994 hdev->discovery_paused = false; in hci_resume_discovery_sync()
5996 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_resume_discovery_sync()
5998 err = hci_start_discovery_sync(hdev); in hci_resume_discovery_sync()
6000 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED : in hci_resume_discovery_sync()
6006 static void hci_resume_monitor_sync(struct hci_dev *hdev) in hci_resume_monitor_sync() argument
6008 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_resume_monitor_sync()
6010 msft_resume_sync(hdev); in hci_resume_monitor_sync()
6018 static int hci_resume_scan_sync(struct hci_dev *hdev) in hci_resume_scan_sync() argument
6020 if (!hdev->scanning_paused) in hci_resume_scan_sync()
6023 hdev->scanning_paused = false; in hci_resume_scan_sync()
6025 hci_update_scan_sync(hdev); in hci_resume_scan_sync()
6028 hci_update_passive_scan_sync(hdev); in hci_resume_scan_sync()
6041 int hci_resume_sync(struct hci_dev *hdev) in hci_resume_sync() argument
6044 if (!hdev->suspended) in hci_resume_sync()
6047 hdev->suspended = false; in hci_resume_sync()
6050 hci_set_event_mask_sync(hdev); in hci_resume_sync()
6053 hci_clear_event_filter_sync(hdev); in hci_resume_sync()
6056 hci_resume_scan_sync(hdev); in hci_resume_sync()
6059 hci_resume_monitor_sync(hdev); in hci_resume_sync()
6062 hci_resume_advertising_sync(hdev); in hci_resume_sync()
6065 hci_resume_discovery_sync(hdev); in hci_resume_sync()
6072 struct hci_dev *hdev = conn->hdev; in conn_use_rpa() local
6074 return hci_dev_test_flag(hdev, HCI_PRIVACY); in conn_use_rpa()
6077 static int hci_le_ext_directed_advertising_sync(struct hci_dev *hdev, in hci_le_ext_directed_advertising_sync() argument
6085 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_ext_directed_advertising_sync()
6093 err = hci_get_random_address(hdev, false, conn_use_rpa(conn), NULL, in hci_le_ext_directed_advertising_sync()
6101 cp.channel_map = hdev->le_adv_channel_map; in hci_le_ext_directed_advertising_sync()
6118 err = hci_remove_ext_adv_instance_sync(hdev, cp.handle, NULL); in hci_le_ext_directed_advertising_sync()
6122 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_le_ext_directed_advertising_sync()
6130 bacmp(&random_addr, &hdev->random_addr)) { in hci_le_ext_directed_advertising_sync()
6131 err = hci_set_adv_set_random_addr_sync(hdev, 0x00, in hci_le_ext_directed_advertising_sync()
6137 return hci_enable_ext_advertising_sync(hdev, 0x00); in hci_le_ext_directed_advertising_sync()
6140 static int hci_le_directed_advertising_sync(struct hci_dev *hdev, in hci_le_directed_advertising_sync() argument
6148 if (ext_adv_capable(hdev)) in hci_le_directed_advertising_sync()
6149 return hci_le_ext_directed_advertising_sync(hdev, conn); in hci_le_directed_advertising_sync()
6156 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_le_directed_advertising_sync()
6161 status = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_directed_advertising_sync()
6179 cp.channel_map = hdev->le_adv_channel_map; in hci_le_directed_advertising_sync()
6181 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_le_directed_advertising_sync()
6188 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_le_directed_advertising_sync()
6195 struct hci_dev *hdev = conn->hdev; in set_ext_conn_params() local
6199 p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in set_ext_conn_params()
6200 p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); in set_ext_conn_params()
6209 static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, in hci_le_ext_create_conn_sync() argument
6228 if (scan_1m(hdev)) { in hci_le_ext_create_conn_sync()
6236 if (scan_2m(hdev)) { in hci_le_ext_create_conn_sync()
6244 if (scan_coded(hdev)) { in hci_le_ext_create_conn_sync()
6251 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_EXT_CREATE_CONN, in hci_le_ext_create_conn_sync()
6257 int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_le_create_conn_sync() argument
6269 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in hci_le_create_conn_sync()
6270 hdev->le_scan_type == LE_SCAN_ACTIVE && in hci_le_create_conn_sync()
6271 !hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) { in hci_le_create_conn_sync()
6277 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6279 err = hci_le_directed_advertising_sync(hdev, conn); in hci_le_create_conn_sync()
6284 if (!hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in hci_le_create_conn_sync()
6285 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6287 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_create_conn_sync()
6294 conn->le_conn_min_interval = hdev->le_conn_min_interval; in hci_le_create_conn_sync()
6295 conn->le_conn_max_interval = hdev->le_conn_max_interval; in hci_le_create_conn_sync()
6296 conn->le_conn_latency = hdev->le_conn_latency; in hci_le_create_conn_sync()
6297 conn->le_supv_timeout = hdev->le_supv_timeout; in hci_le_create_conn_sync()
6306 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_le_create_conn_sync()
6307 hci_scan_disable_sync(hdev); in hci_le_create_conn_sync()
6308 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED); in hci_le_create_conn_sync()
6314 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_create_conn_sync()
6319 if (use_ext_conn(hdev)) { in hci_le_create_conn_sync()
6320 err = hci_le_ext_create_conn_sync(hdev, conn, own_addr_type); in hci_le_create_conn_sync()
6326 cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in hci_le_create_conn_sync()
6327 cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); in hci_le_create_conn_sync()
6345 err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CONN, in hci_le_create_conn_sync()
6347 use_enhanced_conn_complete(hdev) ? in hci_le_create_conn_sync()
6354 hci_le_connect_cancel_sync(hdev, conn, 0x00); in hci_le_create_conn_sync()
6357 hci_resume_advertising_sync(hdev); in hci_le_create_conn_sync()
6361 int hci_le_create_cis_sync(struct hci_dev *hdev) in hci_le_create_cis_sync() argument
6395 hci_dev_lock(hdev); in hci_le_create_cis_sync()
6400 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6406 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6414 list_for_each_entry_rcu(link, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6430 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6449 hci_dev_unlock(hdev); in hci_le_create_cis_sync()
6455 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CIS, in hci_le_create_cis_sync()
6462 int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle) in hci_le_remove_cig_sync() argument
6469 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REMOVE_CIG, sizeof(cp), in hci_le_remove_cig_sync()
6473 int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle) in hci_le_big_terminate_sync() argument
6480 return __hci_cmd_sync_status(hdev, HCI_OP_LE_BIG_TERM_SYNC, in hci_le_big_terminate_sync()
6484 int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle) in hci_le_pa_terminate_sync() argument
6491 return __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_TERM_SYNC, in hci_le_pa_terminate_sync()
6495 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
6510 if (use_ll_privacy(hdev)) in hci_get_random_address()
6519 if (rpa_valid(hdev)) in hci_get_random_address()
6523 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
6525 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
6529 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
6552 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
6568 static int _update_adv_data_sync(struct hci_dev *hdev, void *data) in _update_adv_data_sync() argument
6572 return hci_update_adv_data_sync(hdev, instance); in _update_adv_data_sync()
6575 int hci_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_update_adv_data() argument
6577 return hci_cmd_sync_queue(hdev, _update_adv_data_sync, in hci_update_adv_data()