Lines Matching refs:hdev
23 static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, in hci_cmd_sync_complete() argument
26 bt_dev_dbg(hdev, "result 0x%2.2x", result); in hci_cmd_sync_complete()
28 if (hdev->req_status != HCI_REQ_PEND) in hci_cmd_sync_complete()
31 hdev->req_result = result; in hci_cmd_sync_complete()
32 hdev->req_status = HCI_REQ_DONE; in hci_cmd_sync_complete()
35 kfree_skb(hdev->req_skb); in hci_cmd_sync_complete()
36 hdev->req_skb = NULL; in hci_cmd_sync_complete()
45 hdev->req_rsp = skb_get(skb); in hci_cmd_sync_complete()
48 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_complete()
51 struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync_alloc() argument
69 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_cmd_sync_alloc()
88 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_add() local
91 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync_add()
99 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, sk); in hci_cmd_sync_add()
101 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_cmd_sync_add()
117 struct hci_dev *hdev = req->hdev; in hci_req_sync_run() local
121 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in hci_req_sync_run()
139 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_req_sync_run()
140 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in hci_req_sync_run()
141 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_req_sync_run()
143 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_req_sync_run()
148 static void hci_request_init(struct hci_request *req, struct hci_dev *hdev) in hci_request_init() argument
151 req->hdev = hdev; in hci_request_init()
156 struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_sk() argument
164 bt_dev_dbg(hdev, "Opcode 0x%4.4x", opcode); in __hci_cmd_sync_sk()
166 hci_request_init(&req, hdev); in __hci_cmd_sync_sk()
170 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_sk()
176 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_sk()
177 hdev->req_status != HCI_REQ_PEND, in __hci_cmd_sync_sk()
183 switch (hdev->req_status) { in __hci_cmd_sync_sk()
185 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_sk()
189 err = -hdev->req_result; in __hci_cmd_sync_sk()
197 hdev->req_status = 0; in __hci_cmd_sync_sk()
198 hdev->req_result = 0; in __hci_cmd_sync_sk()
199 skb = hdev->req_rsp; in __hci_cmd_sync_sk()
200 hdev->req_rsp = NULL; in __hci_cmd_sync_sk()
202 bt_dev_dbg(hdev, "end: err %d", err); in __hci_cmd_sync_sk()
220 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync() argument
223 return __hci_cmd_sync_sk(hdev, opcode, plen, param, 0, timeout, NULL); in __hci_cmd_sync()
228 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync() argument
233 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
236 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync()
238 hci_req_sync_lock(hdev); in hci_cmd_sync()
239 skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout); in hci_cmd_sync()
240 hci_req_sync_unlock(hdev); in hci_cmd_sync()
247 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_ev() argument
250 return __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, in __hci_cmd_sync_ev()
256 int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status_sk() argument
263 skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk); in __hci_cmd_sync_status_sk()
271 bt_dev_err(hdev, "Opcode 0x%4.4x failed: %ld", opcode, in __hci_cmd_sync_status_sk()
284 int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status() argument
287 return __hci_cmd_sync_status_sk(hdev, opcode, plen, param, 0, timeout, in __hci_cmd_sync_status()
292 int hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync_status() argument
297 hci_req_sync_lock(hdev); in hci_cmd_sync_status()
298 err = __hci_cmd_sync_status(hdev, opcode, plen, param, timeout); in hci_cmd_sync_status()
299 hci_req_sync_unlock(hdev); in hci_cmd_sync_status()
307 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_work); in hci_cmd_sync_work() local
309 bt_dev_dbg(hdev, ""); in hci_cmd_sync_work()
315 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
316 entry = list_first_entry_or_null(&hdev->cmd_sync_work_list, in hci_cmd_sync_work()
321 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
326 bt_dev_dbg(hdev, "entry %p", entry); in hci_cmd_sync_work()
331 hci_req_sync_lock(hdev); in hci_cmd_sync_work()
332 err = entry->func(hdev, entry->data); in hci_cmd_sync_work()
334 entry->destroy(hdev, entry->data, err); in hci_cmd_sync_work()
335 hci_req_sync_unlock(hdev); in hci_cmd_sync_work()
344 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_cancel_work); in hci_cmd_sync_cancel_work() local
346 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cmd_sync_cancel_work()
347 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cmd_sync_cancel_work()
348 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_sync_cancel_work()
350 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_work()
353 static int hci_scan_disable_sync(struct hci_dev *hdev);
354 static int scan_disable_sync(struct hci_dev *hdev, void *data) in scan_disable_sync() argument
356 return hci_scan_disable_sync(hdev); in scan_disable_sync()
359 static int interleaved_inquiry_sync(struct hci_dev *hdev, void *data) in interleaved_inquiry_sync() argument
361 return hci_inquiry_sync(hdev, DISCOV_INTERLEAVED_INQUIRY_LEN, 0); in interleaved_inquiry_sync()
366 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable() local
370 bt_dev_dbg(hdev, ""); in le_scan_disable()
371 hci_dev_lock(hdev); in le_scan_disable()
373 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_disable()
376 status = hci_cmd_sync_queue(hdev, scan_disable_sync, NULL, NULL); in le_scan_disable()
378 bt_dev_err(hdev, "failed to disable LE scan: %d", status); in le_scan_disable()
390 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable()
393 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable()
396 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable()
397 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable()
398 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable()
404 status = hci_cmd_sync_queue(hdev, interleaved_inquiry_sync, NULL, NULL); in le_scan_disable()
406 bt_dev_err(hdev, "inquiry failed: status %d", status); in le_scan_disable()
413 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in le_scan_disable()
416 hci_dev_unlock(hdev); in le_scan_disable()
419 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val,
422 static int reenable_adv_sync(struct hci_dev *hdev, void *data) in reenable_adv_sync() argument
424 bt_dev_dbg(hdev, ""); in reenable_adv_sync()
426 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in reenable_adv_sync()
427 list_empty(&hdev->adv_instances)) in reenable_adv_sync()
430 if (hdev->cur_adv_instance) { in reenable_adv_sync()
431 return hci_schedule_adv_instance_sync(hdev, in reenable_adv_sync()
432 hdev->cur_adv_instance, in reenable_adv_sync()
435 if (ext_adv_capable(hdev)) { in reenable_adv_sync()
436 hci_start_ext_adv_sync(hdev, 0x00); in reenable_adv_sync()
438 hci_update_adv_data_sync(hdev, 0x00); in reenable_adv_sync()
439 hci_update_scan_rsp_data_sync(hdev, 0x00); in reenable_adv_sync()
440 hci_enable_advertising_sync(hdev); in reenable_adv_sync()
449 struct hci_dev *hdev = container_of(work, struct hci_dev, in reenable_adv() local
453 bt_dev_dbg(hdev, ""); in reenable_adv()
455 hci_dev_lock(hdev); in reenable_adv()
457 status = hci_cmd_sync_queue(hdev, reenable_adv_sync, NULL, NULL); in reenable_adv()
459 bt_dev_err(hdev, "failed to reenable ADV: %d", status); in reenable_adv()
461 hci_dev_unlock(hdev); in reenable_adv()
464 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
466 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
467 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
468 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
483 int hci_clear_adv_instance_sync(struct hci_dev *hdev, struct sock *sk, in hci_clear_adv_instance_sync() argument
491 if (!instance || hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
492 cancel_adv_timeout(hdev); in hci_clear_adv_instance_sync()
498 if (instance && hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
499 next_instance = hci_get_next_instance(hdev, instance); in hci_clear_adv_instance_sync()
502 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_clear_adv_instance_sync()
508 err = hci_remove_adv_instance(hdev, rem_inst); in hci_clear_adv_instance_sync()
510 mgmt_advertising_removed(sk, hdev, rem_inst); in hci_clear_adv_instance_sync()
513 adv_instance = hci_find_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
522 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
524 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_instance_sync()
528 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_clear_adv_instance_sync()
531 if (next_instance && !ext_adv_capable(hdev)) in hci_clear_adv_instance_sync()
532 return hci_schedule_adv_instance_sync(hdev, in hci_clear_adv_instance_sync()
539 static int adv_timeout_expire_sync(struct hci_dev *hdev, void *data) in adv_timeout_expire_sync() argument
545 hci_clear_adv_instance_sync(hdev, NULL, instance, false); in adv_timeout_expire_sync()
547 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire_sync()
548 return hci_disable_advertising_sync(hdev); in adv_timeout_expire_sync()
556 struct hci_dev *hdev = container_of(work, struct hci_dev, in adv_timeout_expire() local
559 bt_dev_dbg(hdev, ""); in adv_timeout_expire()
561 hci_dev_lock(hdev); in adv_timeout_expire()
563 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
565 if (hdev->cur_adv_instance == 0x00) in adv_timeout_expire()
572 *inst_ptr = hdev->cur_adv_instance; in adv_timeout_expire()
573 hci_cmd_sync_queue(hdev, adv_timeout_expire_sync, inst_ptr, NULL); in adv_timeout_expire()
576 hci_dev_unlock(hdev); in adv_timeout_expire()
579 static bool is_interleave_scanning(struct hci_dev *hdev) in is_interleave_scanning() argument
581 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
584 static int hci_passive_scan_sync(struct hci_dev *hdev);
588 struct hci_dev *hdev = container_of(work, struct hci_dev, in interleave_scan_work() local
592 if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) { in interleave_scan_work()
593 timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration); in interleave_scan_work()
594 } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) { in interleave_scan_work()
595 timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration); in interleave_scan_work()
597 bt_dev_err(hdev, "unexpected error"); in interleave_scan_work()
601 hci_passive_scan_sync(hdev); in interleave_scan_work()
603 hci_dev_lock(hdev); in interleave_scan_work()
605 switch (hdev->interleave_scan_state) { in interleave_scan_work()
607 bt_dev_dbg(hdev, "next state: allowlist"); in interleave_scan_work()
608 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in interleave_scan_work()
611 bt_dev_dbg(hdev, "next state: no filter"); in interleave_scan_work()
612 hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST; in interleave_scan_work()
615 bt_dev_err(hdev, "unexpected error"); in interleave_scan_work()
618 hci_dev_unlock(hdev); in interleave_scan_work()
621 if (is_interleave_scanning(hdev)) in interleave_scan_work()
622 queue_delayed_work(hdev->req_workqueue, in interleave_scan_work()
623 &hdev->interleave_scan, timeout); in interleave_scan_work()
626 void hci_cmd_sync_init(struct hci_dev *hdev) in hci_cmd_sync_init() argument
628 INIT_WORK(&hdev->cmd_sync_work, hci_cmd_sync_work); in hci_cmd_sync_init()
629 INIT_LIST_HEAD(&hdev->cmd_sync_work_list); in hci_cmd_sync_init()
630 mutex_init(&hdev->cmd_sync_work_lock); in hci_cmd_sync_init()
631 mutex_init(&hdev->unregister_lock); in hci_cmd_sync_init()
633 INIT_WORK(&hdev->cmd_sync_cancel_work, hci_cmd_sync_cancel_work); in hci_cmd_sync_init()
634 INIT_WORK(&hdev->reenable_adv_work, reenable_adv); in hci_cmd_sync_init()
635 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable); in hci_cmd_sync_init()
636 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_cmd_sync_init()
637 INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work); in hci_cmd_sync_init()
640 static void _hci_cmd_sync_cancel_entry(struct hci_dev *hdev, in _hci_cmd_sync_cancel_entry() argument
645 entry->destroy(hdev, entry->data, err); in _hci_cmd_sync_cancel_entry()
651 void hci_cmd_sync_clear(struct hci_dev *hdev) in hci_cmd_sync_clear() argument
655 cancel_work_sync(&hdev->cmd_sync_work); in hci_cmd_sync_clear()
656 cancel_work_sync(&hdev->reenable_adv_work); in hci_cmd_sync_clear()
658 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_clear()
659 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) in hci_cmd_sync_clear()
660 _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED); in hci_cmd_sync_clear()
661 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_clear()
664 void hci_cmd_sync_cancel(struct hci_dev *hdev, int err) in hci_cmd_sync_cancel() argument
666 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_cmd_sync_cancel()
668 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel()
669 hdev->req_result = err; in hci_cmd_sync_cancel()
670 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel()
672 queue_work(hdev->workqueue, &hdev->cmd_sync_cancel_work); in hci_cmd_sync_cancel()
682 void hci_cmd_sync_cancel_sync(struct hci_dev *hdev, int err) in hci_cmd_sync_cancel_sync() argument
684 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_cmd_sync_cancel_sync()
686 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel_sync()
690 hdev->req_result = err < 0 ? -err : err; in hci_cmd_sync_cancel_sync()
691 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel_sync()
693 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_sync()
702 int hci_cmd_sync_submit(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_submit() argument
708 mutex_lock(&hdev->unregister_lock); in hci_cmd_sync_submit()
709 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_cmd_sync_submit()
723 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
724 list_add_tail(&entry->list, &hdev->cmd_sync_work_list); in hci_cmd_sync_submit()
725 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
727 queue_work(hdev->req_workqueue, &hdev->cmd_sync_work); in hci_cmd_sync_submit()
730 mutex_unlock(&hdev->unregister_lock); in hci_cmd_sync_submit()
739 int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_queue() argument
745 if (!test_bit(HCI_RUNNING, &hdev->flags)) in hci_cmd_sync_queue()
748 return hci_cmd_sync_submit(hdev, func, data, destroy); in hci_cmd_sync_queue()
753 _hci_cmd_sync_lookup_entry(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in _hci_cmd_sync_lookup_entry() argument
758 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) { in _hci_cmd_sync_lookup_entry()
779 int hci_cmd_sync_queue_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_queue_once() argument
782 if (hci_cmd_sync_lookup_entry(hdev, func, data, destroy)) in hci_cmd_sync_queue_once()
785 return hci_cmd_sync_queue(hdev, func, data, destroy); in hci_cmd_sync_queue_once()
794 int hci_cmd_sync_run(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_run() argument
800 if (!test_bit(HCI_RUNNING, &hdev->flags)) in hci_cmd_sync_run()
804 if (current_work() == &hdev->cmd_sync_work) in hci_cmd_sync_run()
805 return func(hdev, data); in hci_cmd_sync_run()
807 return hci_cmd_sync_submit(hdev, func, data, destroy); in hci_cmd_sync_run()
817 int hci_cmd_sync_run_once(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_run_once() argument
820 if (hci_cmd_sync_lookup_entry(hdev, func, data, destroy)) in hci_cmd_sync_run_once()
823 return hci_cmd_sync_run(hdev, func, data, destroy); in hci_cmd_sync_run_once()
833 hci_cmd_sync_lookup_entry(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_lookup_entry() argument
838 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_lookup_entry()
839 entry = _hci_cmd_sync_lookup_entry(hdev, func, data, destroy); in hci_cmd_sync_lookup_entry()
840 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_lookup_entry()
847 void hci_cmd_sync_cancel_entry(struct hci_dev *hdev, in hci_cmd_sync_cancel_entry() argument
850 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_cancel_entry()
851 _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED); in hci_cmd_sync_cancel_entry()
852 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_cancel_entry()
860 bool hci_cmd_sync_dequeue_once(struct hci_dev *hdev, in hci_cmd_sync_dequeue_once() argument
866 entry = hci_cmd_sync_lookup_entry(hdev, func, data, destroy); in hci_cmd_sync_dequeue_once()
870 hci_cmd_sync_cancel_entry(hdev, entry); in hci_cmd_sync_dequeue_once()
881 bool hci_cmd_sync_dequeue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_dequeue() argument
887 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_dequeue()
888 while ((entry = _hci_cmd_sync_lookup_entry(hdev, func, data, in hci_cmd_sync_dequeue()
890 _hci_cmd_sync_cancel_entry(hdev, entry, -ECANCELED); in hci_cmd_sync_dequeue()
893 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_dequeue()
899 int hci_update_eir_sync(struct hci_dev *hdev) in hci_update_eir_sync() argument
903 bt_dev_dbg(hdev, ""); in hci_update_eir_sync()
905 if (!hdev_is_powered(hdev)) in hci_update_eir_sync()
908 if (!lmp_ext_inq_capable(hdev)) in hci_update_eir_sync()
911 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_update_eir_sync()
914 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_eir_sync()
919 eir_create(hdev, cp.data); in hci_update_eir_sync()
921 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in hci_update_eir_sync()
924 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in hci_update_eir_sync()
926 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_update_eir_sync()
930 static u8 get_service_classes(struct hci_dev *hdev) in get_service_classes() argument
935 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
941 int hci_update_class_sync(struct hci_dev *hdev) in hci_update_class_sync() argument
945 bt_dev_dbg(hdev, ""); in hci_update_class_sync()
947 if (!hdev_is_powered(hdev)) in hci_update_class_sync()
950 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_class_sync()
953 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_class_sync()
956 cod[0] = hdev->minor_class; in hci_update_class_sync()
957 cod[1] = hdev->major_class; in hci_update_class_sync()
958 cod[2] = get_service_classes(hdev); in hci_update_class_sync()
960 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_update_class_sync()
963 if (memcmp(cod, hdev->dev_class, 3) == 0) in hci_update_class_sync()
966 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CLASS_OF_DEV, in hci_update_class_sync()
970 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) in is_advertising_allowed() argument
973 if (hci_conn_num(hdev, LE_LINK) == 0) in is_advertising_allowed()
977 if (hdev->conn_hash.le_num_peripheral > 0) { in is_advertising_allowed()
981 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
987 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
988 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
993 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_peripheral) { in is_advertising_allowed()
995 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
1001 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
1002 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
1009 static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags) in adv_use_rpa() argument
1012 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in adv_use_rpa()
1016 if (!hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in adv_use_rpa()
1023 hci_dev_test_flag(hdev, HCI_BONDABLE)) in adv_use_rpa()
1032 static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa) in hci_set_random_addr_sync() argument
1044 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in hci_set_random_addr_sync()
1045 hci_lookup_le_connect(hdev)) { in hci_set_random_addr_sync()
1046 bt_dev_dbg(hdev, "Deferring random address update"); in hci_set_random_addr_sync()
1047 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_set_random_addr_sync()
1051 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RANDOM_ADDR, in hci_set_random_addr_sync()
1055 int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy, in hci_update_random_address_sync() argument
1068 if (use_ll_privacy(hdev)) in hci_update_random_address_sync()
1074 if (rpa_valid(hdev)) in hci_update_random_address_sync()
1077 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address_sync()
1079 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address_sync()
1083 err = hci_set_random_addr_sync(hdev, &hdev->rpa); in hci_update_random_address_sync()
1108 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address_sync()
1114 return hci_set_random_addr_sync(hdev, &nrpa); in hci_update_random_address_sync()
1126 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address_sync()
1127 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address_sync()
1128 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address_sync()
1129 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address_sync()
1131 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address_sync()
1132 return hci_set_random_addr_sync(hdev, in hci_update_random_address_sync()
1133 &hdev->static_addr); in hci_update_random_address_sync()
1145 static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_disable_ext_adv_instance_sync() argument
1155 adv = hci_find_adv_instance(hdev, instance); in hci_disable_ext_adv_instance_sync()
1177 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_disable_ext_adv_instance_sync()
1181 static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, in hci_set_adv_set_random_addr_sync() argument
1193 err = hci_set_random_addr_sync(hdev, random_addr); in hci_set_adv_set_random_addr_sync()
1203 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, in hci_set_adv_set_random_addr_sync()
1207 int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_setup_ext_adv_instance_sync() argument
1219 adv = hci_find_adv_instance(hdev, instance); in hci_setup_ext_adv_instance_sync()
1231 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_setup_ext_adv_instance_sync()
1236 flags = hci_adv_instance_flags(hdev, instance); in hci_setup_ext_adv_instance_sync()
1242 mgmt_get_connectable(hdev); in hci_setup_ext_adv_instance_sync()
1244 if (!is_advertising_allowed(hdev, connectable)) in hci_setup_ext_adv_instance_sync()
1251 err = hci_get_random_address(hdev, !connectable, in hci_setup_ext_adv_instance_sync()
1252 adv_use_rpa(hdev, flags), adv, in hci_setup_ext_adv_instance_sync()
1264 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1265 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1276 } else if (hci_adv_instance_is_scannable(hdev, instance) || in hci_setup_ext_adv_instance_sync()
1297 hci_copy_identity_address(hdev, &cp.peer_addr, in hci_setup_ext_adv_instance_sync()
1301 cp.channel_map = hdev->le_adv_channel_map; in hci_setup_ext_adv_instance_sync()
1316 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_setup_ext_adv_instance_sync()
1329 if (!bacmp(&random_addr, &hdev->random_addr)) in hci_setup_ext_adv_instance_sync()
1333 return hci_set_adv_set_random_addr_sync(hdev, instance, in hci_setup_ext_adv_instance_sync()
1340 static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_scan_rsp_data_sync() argument
1349 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_scan_rsp_data_sync()
1354 len = eir_create_scan_rsp(hdev, instance, pdu->data); in hci_set_ext_scan_rsp_data_sync()
1361 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA, in hci_set_ext_scan_rsp_data_sync()
1370 memcpy(hdev->scan_rsp_data, pdu->data, len); in hci_set_ext_scan_rsp_data_sync()
1371 hdev->scan_rsp_data_len = len; in hci_set_ext_scan_rsp_data_sync()
1377 static int __hci_set_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in __hci_set_scan_rsp_data_sync() argument
1384 len = eir_create_scan_rsp(hdev, instance, cp.data); in __hci_set_scan_rsp_data_sync()
1386 if (hdev->scan_rsp_data_len == len && in __hci_set_scan_rsp_data_sync()
1387 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_set_scan_rsp_data_sync()
1390 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_set_scan_rsp_data_sync()
1391 hdev->scan_rsp_data_len = len; in __hci_set_scan_rsp_data_sync()
1395 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_RSP_DATA, in __hci_set_scan_rsp_data_sync()
1399 int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_scan_rsp_data_sync() argument
1401 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_rsp_data_sync()
1404 if (ext_adv_capable(hdev)) in hci_update_scan_rsp_data_sync()
1405 return hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1407 return __hci_set_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1410 int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_ext_advertising_sync() argument
1418 adv = hci_find_adv_instance(hdev, instance); in hci_enable_ext_advertising_sync()
1450 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_enable_ext_advertising_sync()
1456 int hci_start_ext_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_ext_adv_sync() argument
1460 err = hci_setup_ext_adv_instance_sync(hdev, instance); in hci_start_ext_adv_sync()
1464 err = hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_start_ext_adv_sync()
1468 return hci_enable_ext_advertising_sync(hdev, instance); in hci_start_ext_adv_sync()
1471 int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_disable_per_advertising_sync() argument
1477 adv = hci_find_adv_instance(hdev, instance); in hci_disable_per_advertising_sync()
1486 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_disable_per_advertising_sync()
1490 static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, in hci_set_per_adv_params_sync() argument
1508 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS, in hci_set_per_adv_params_sync()
1512 static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_per_adv_data_sync() argument
1520 adv = hci_find_adv_instance(hdev, instance); in hci_set_per_adv_data_sync()
1525 len = eir_create_per_adv_data(hdev, instance, pdu->data); in hci_set_per_adv_data_sync()
1531 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_DATA, in hci_set_per_adv_data_sync()
1536 static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_per_advertising_sync() argument
1542 adv = hci_find_adv_instance(hdev, instance); in hci_enable_per_advertising_sync()
1551 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_enable_per_advertising_sync()
1558 static int hci_adv_bcast_annoucement(struct hci_dev *hdev, struct adv_info *adv) in hci_adv_bcast_annoucement() argument
1588 hci_set_adv_instance_data(hdev, adv->instance, sizeof(ad), ad, 0, NULL); in hci_adv_bcast_annoucement()
1590 return hci_update_adv_data_sync(hdev, adv->instance); in hci_adv_bcast_annoucement()
1593 int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len, in hci_start_per_adv_sync() argument
1601 hci_disable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1604 adv = hci_find_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1607 adv = hci_add_per_instance(hdev, instance, flags, in hci_start_per_adv_sync()
1619 err = hci_start_ext_adv_sync(hdev, instance); in hci_start_per_adv_sync()
1623 err = hci_adv_bcast_annoucement(hdev, adv); in hci_start_per_adv_sync()
1627 err = hci_set_per_adv_params_sync(hdev, instance, min_interval, in hci_start_per_adv_sync()
1632 err = hci_set_per_adv_data_sync(hdev, instance); in hci_start_per_adv_sync()
1636 err = hci_enable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1644 hci_remove_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1649 static int hci_start_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_adv_sync() argument
1653 if (ext_adv_capable(hdev)) in hci_start_adv_sync()
1654 return hci_start_ext_adv_sync(hdev, instance); in hci_start_adv_sync()
1656 err = hci_update_adv_data_sync(hdev, instance); in hci_start_adv_sync()
1660 err = hci_update_scan_rsp_data_sync(hdev, instance); in hci_start_adv_sync()
1664 return hci_enable_advertising_sync(hdev); in hci_start_adv_sync()
1667 int hci_enable_advertising_sync(struct hci_dev *hdev) in hci_enable_advertising_sync() argument
1677 if (ext_adv_capable(hdev)) in hci_enable_advertising_sync()
1678 return hci_enable_ext_advertising_sync(hdev, in hci_enable_advertising_sync()
1679 hdev->cur_adv_instance); in hci_enable_advertising_sync()
1681 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1682 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1688 mgmt_get_connectable(hdev); in hci_enable_advertising_sync()
1690 if (!is_advertising_allowed(hdev, connectable)) in hci_enable_advertising_sync()
1693 status = hci_disable_advertising_sync(hdev); in hci_enable_advertising_sync()
1702 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_enable_advertising_sync()
1708 status = hci_update_random_address_sync(hdev, !connectable, in hci_enable_advertising_sync()
1709 adv_use_rpa(hdev, flags), in hci_enable_advertising_sync()
1720 adv_min_interval = hdev->le_adv_min_interval; in hci_enable_advertising_sync()
1721 adv_max_interval = hdev->le_adv_max_interval; in hci_enable_advertising_sync()
1727 if (hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance)) in hci_enable_advertising_sync()
1732 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in hci_enable_advertising_sync()
1733 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_enable_advertising_sync()
1742 cp.channel_map = hdev->le_adv_channel_map; in hci_enable_advertising_sync()
1744 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_enable_advertising_sync()
1749 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_enable_advertising_sync()
1753 static int enable_advertising_sync(struct hci_dev *hdev, void *data) in enable_advertising_sync() argument
1755 return hci_enable_advertising_sync(hdev); in enable_advertising_sync()
1758 int hci_enable_advertising(struct hci_dev *hdev) in hci_enable_advertising() argument
1760 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_enable_advertising()
1761 list_empty(&hdev->adv_instances)) in hci_enable_advertising()
1764 return hci_cmd_sync_queue(hdev, enable_advertising_sync, NULL, NULL); in hci_enable_advertising()
1767 int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_remove_ext_adv_instance_sync() argument
1772 if (!ext_adv_capable(hdev)) in hci_remove_ext_adv_instance_sync()
1775 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_remove_ext_adv_instance_sync()
1780 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in hci_remove_ext_adv_instance_sync()
1783 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, in hci_remove_ext_adv_instance_sync()
1788 static int remove_ext_adv_sync(struct hci_dev *hdev, void *data) in remove_ext_adv_sync() argument
1796 return hci_remove_ext_adv_instance_sync(hdev, instance, NULL); in remove_ext_adv_sync()
1799 int hci_remove_ext_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_ext_adv_instance() argument
1804 adv = hci_find_adv_instance(hdev, instance); in hci_remove_ext_adv_instance()
1809 return hci_cmd_sync_queue(hdev, remove_ext_adv_sync, adv, NULL); in hci_remove_ext_adv_instance()
1812 int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) in hci_le_terminate_big_sync() argument
1820 return __hci_cmd_sync_status(hdev, HCI_OP_LE_TERM_BIG, in hci_le_terminate_big_sync()
1824 static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_adv_data_sync() argument
1833 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_adv_data_sync()
1838 len = eir_create_adv_data(hdev, instance, pdu->data); in hci_set_ext_adv_data_sync()
1845 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_DATA, in hci_set_ext_adv_data_sync()
1855 memcpy(hdev->adv_data, pdu->data, len); in hci_set_ext_adv_data_sync()
1856 hdev->adv_data_len = len; in hci_set_ext_adv_data_sync()
1862 static int hci_set_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_adv_data_sync() argument
1869 len = eir_create_adv_data(hdev, instance, cp.data); in hci_set_adv_data_sync()
1872 if (hdev->adv_data_len == len && in hci_set_adv_data_sync()
1873 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_set_adv_data_sync()
1876 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_set_adv_data_sync()
1877 hdev->adv_data_len = len; in hci_set_adv_data_sync()
1881 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_DATA, in hci_set_adv_data_sync()
1885 int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_adv_data_sync() argument
1887 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_adv_data_sync()
1890 if (ext_adv_capable(hdev)) in hci_update_adv_data_sync()
1891 return hci_set_ext_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1893 return hci_set_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1896 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_schedule_adv_instance_sync() argument
1902 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) && !ext_adv_capable(hdev)) in hci_schedule_adv_instance_sync()
1905 if (hdev->adv_instance_timeout) in hci_schedule_adv_instance_sync()
1908 adv = hci_find_adv_instance(hdev, instance); in hci_schedule_adv_instance_sync()
1932 if (!ext_adv_capable(hdev)) { in hci_schedule_adv_instance_sync()
1933 hdev->adv_instance_timeout = timeout; in hci_schedule_adv_instance_sync()
1934 queue_delayed_work(hdev->req_workqueue, in hci_schedule_adv_instance_sync()
1935 &hdev->adv_instance_expire, in hci_schedule_adv_instance_sync()
1943 if (!force && hdev->cur_adv_instance == instance && in hci_schedule_adv_instance_sync()
1944 hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_schedule_adv_instance_sync()
1947 hdev->cur_adv_instance = instance; in hci_schedule_adv_instance_sync()
1949 return hci_start_adv_sync(hdev, instance); in hci_schedule_adv_instance_sync()
1952 static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk) in hci_clear_adv_sets_sync() argument
1956 if (!ext_adv_capable(hdev)) in hci_clear_adv_sets_sync()
1960 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_clear_adv_sets_sync()
1964 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CLEAR_ADV_SETS, in hci_clear_adv_sets_sync()
1968 static int hci_clear_adv_sync(struct hci_dev *hdev, struct sock *sk, bool force) in hci_clear_adv_sync() argument
1973 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1975 err = hci_clear_adv_sets_sync(hdev, sk); in hci_clear_adv_sync()
1976 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1982 hci_dev_lock(hdev); in hci_clear_adv_sync()
1985 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in hci_clear_adv_sync()
1992 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_sync()
1994 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_sync()
1997 hci_dev_unlock(hdev); in hci_clear_adv_sync()
2002 static int hci_remove_adv_sync(struct hci_dev *hdev, u8 instance, in hci_remove_adv_sync() argument
2008 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
2009 err = hci_remove_ext_adv_instance_sync(hdev, instance, sk); in hci_remove_adv_sync()
2010 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
2016 hci_dev_lock(hdev); in hci_remove_adv_sync()
2018 err = hci_remove_adv_instance(hdev, instance); in hci_remove_adv_sync()
2020 mgmt_advertising_removed(sk, hdev, instance); in hci_remove_adv_sync()
2022 hci_dev_unlock(hdev); in hci_remove_adv_sync()
2038 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, in hci_remove_advertising_sync() argument
2045 if (!instance || hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
2046 cancel_adv_timeout(hdev); in hci_remove_advertising_sync()
2052 if (hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
2053 next = hci_get_next_instance(hdev, instance); in hci_remove_advertising_sync()
2056 err = hci_clear_adv_sync(hdev, sk, force); in hci_remove_advertising_sync()
2060 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_remove_advertising_sync()
2067 err = hci_remove_adv_sync(hdev, instance, sk); in hci_remove_advertising_sync()
2073 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_remove_advertising_sync()
2076 if (next && !ext_adv_capable(hdev)) in hci_remove_advertising_sync()
2077 hci_schedule_adv_instance_sync(hdev, next->instance, false); in hci_remove_advertising_sync()
2082 int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle) in hci_read_rssi_sync() argument
2087 return __hci_cmd_sync_status(hdev, HCI_OP_READ_RSSI, in hci_read_rssi_sync()
2091 int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp) in hci_read_clock_sync() argument
2093 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLOCK, in hci_read_clock_sync()
2097 int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type) in hci_read_tx_power_sync() argument
2103 return __hci_cmd_sync_status(hdev, HCI_OP_READ_TX_POWER, in hci_read_tx_power_sync()
2107 int hci_disable_advertising_sync(struct hci_dev *hdev) in hci_disable_advertising_sync() argument
2113 if (!hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_disable_advertising_sync()
2116 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
2117 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_disable_advertising_sync()
2118 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
2121 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_disable_advertising_sync()
2125 static int hci_le_set_ext_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_ext_scan_enable_sync() argument
2133 if (hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_ext_scan_enable_sync()
2138 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE, in hci_le_set_ext_scan_enable_sync()
2142 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_scan_enable_sync() argument
2147 if (use_ext_scan(hdev)) in hci_le_set_scan_enable_sync()
2148 return hci_le_set_ext_scan_enable_sync(hdev, val, filter_dup); in hci_le_set_scan_enable_sync()
2153 if (val && hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_scan_enable_sync()
2158 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_ENABLE, in hci_le_set_scan_enable_sync()
2162 static int hci_le_set_addr_resolution_enable_sync(struct hci_dev *hdev, u8 val) in hci_le_set_addr_resolution_enable_sync() argument
2164 if (!use_ll_privacy(hdev)) in hci_le_set_addr_resolution_enable_sync()
2168 if (val == hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_le_set_addr_resolution_enable_sync()
2171 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, in hci_le_set_addr_resolution_enable_sync()
2175 static int hci_scan_disable_sync(struct hci_dev *hdev) in hci_scan_disable_sync() argument
2180 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_scan_disable_sync()
2183 if (hdev->scanning_paused) { in hci_scan_disable_sync()
2184 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_scan_disable_sync()
2188 err = hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_scan_disable_sync()
2190 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_scan_disable_sync()
2197 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
2199 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
2202 static void hci_start_interleave_scan(struct hci_dev *hdev) in hci_start_interleave_scan() argument
2204 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_start_interleave_scan()
2205 queue_delayed_work(hdev->req_workqueue, in hci_start_interleave_scan()
2206 &hdev->interleave_scan, 0); in hci_start_interleave_scan()
2209 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
2211 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
2213 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
2215 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
2221 static bool hci_update_interleaved_scan_sync(struct hci_dev *hdev) in hci_update_interleaved_scan_sync() argument
2230 bool use_interleaving = hci_is_adv_monitoring(hdev) && in hci_update_interleaved_scan_sync()
2231 !(list_empty(&hdev->pend_le_conns) && in hci_update_interleaved_scan_sync()
2232 list_empty(&hdev->pend_le_reports)) && in hci_update_interleaved_scan_sync()
2233 hci_get_adv_monitor_offload_ext(hdev) == in hci_update_interleaved_scan_sync()
2235 bool is_interleaving = is_interleave_scanning(hdev); in hci_update_interleaved_scan_sync()
2238 hci_start_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2239 bt_dev_dbg(hdev, "starting interleave scan"); in hci_update_interleaved_scan_sync()
2244 cancel_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2250 static int hci_le_del_resolve_list_sync(struct hci_dev *hdev, in hci_le_del_resolve_list_sync() argument
2256 if (!use_ll_privacy(hdev)) in hci_le_del_resolve_list_sync()
2260 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, in hci_le_del_resolve_list_sync()
2268 return __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST, in hci_le_del_resolve_list_sync()
2272 static int hci_le_del_accept_list_sync(struct hci_dev *hdev, in hci_le_del_accept_list_sync() argument
2279 if (!hci_bdaddr_list_lookup(&hdev->le_accept_list, bdaddr, bdaddr_type)) in hci_le_del_accept_list_sync()
2288 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_del_accept_list_sync()
2290 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST, in hci_le_del_accept_list_sync()
2293 bt_dev_err(hdev, "Unable to remove from allow list: %d", err); in hci_le_del_accept_list_sync()
2297 bt_dev_dbg(hdev, "Remove %pMR (0x%x) from allow list", &cp.bdaddr, in hci_le_del_accept_list_sync()
2313 static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, in hci_le_add_resolve_list_sync() argument
2321 if (!use_ll_privacy(hdev)) in hci_le_add_resolve_list_sync()
2328 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2331 hci_copy_identity_address(hdev, &cp.bdaddr, &cp.bdaddr_type); in hci_le_add_resolve_list_sync()
2332 memcpy(cp.peer_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2336 irk = hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2341 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, in hci_le_add_resolve_list_sync()
2355 p = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_le_add_resolve_list_sync()
2358 p = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_le_add_resolve_list_sync()
2365 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2366 memcpy(cp.local_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2370 return __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST, in hci_le_add_resolve_list_sync()
2375 static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev, in hci_le_set_privacy_mode_sync() argument
2392 irk = hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type); in hci_le_set_privacy_mode_sync()
2403 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PRIVACY_MODE, in hci_le_set_privacy_mode_sync()
2411 static int hci_le_add_accept_list_sync(struct hci_dev *hdev, in hci_le_add_accept_list_sync() argument
2419 if (hdev->suspended && in hci_le_add_accept_list_sync()
2421 hci_le_del_accept_list_sync(hdev, ¶ms->addr, in hci_le_add_accept_list_sync()
2427 if (*num_entries >= hdev->le_accept_list_size) in hci_le_add_accept_list_sync()
2431 if (!use_ll_privacy(hdev) && in hci_le_add_accept_list_sync()
2432 hci_find_irk_by_addr(hdev, ¶ms->addr, params->addr_type)) in hci_le_add_accept_list_sync()
2439 err = hci_le_add_resolve_list_sync(hdev, params); in hci_le_add_accept_list_sync()
2441 bt_dev_err(hdev, "Unable to add to resolve list: %d", err); in hci_le_add_accept_list_sync()
2446 err = hci_le_set_privacy_mode_sync(hdev, params); in hci_le_add_accept_list_sync()
2448 bt_dev_err(hdev, "Unable to set privacy mode: %d", err); in hci_le_add_accept_list_sync()
2453 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, ¶ms->addr, in hci_le_add_accept_list_sync()
2461 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST, in hci_le_add_accept_list_sync()
2464 bt_dev_err(hdev, "Unable to add to allow list: %d", err); in hci_le_add_accept_list_sync()
2466 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_add_accept_list_sync()
2470 bt_dev_dbg(hdev, "Add %pMR (0x%x) to allow list", &cp.bdaddr, in hci_le_add_accept_list_sync()
2477 static int hci_pause_advertising_sync(struct hci_dev *hdev) in hci_pause_advertising_sync() argument
2483 if (hdev->advertising_paused) in hci_pause_advertising_sync()
2486 bt_dev_dbg(hdev, "Pausing directed advertising"); in hci_pause_advertising_sync()
2489 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_pause_advertising_sync()
2496 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_pause_advertising_sync()
2497 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_pause_advertising_sync()
2498 hdev->discov_timeout = 0; in hci_pause_advertising_sync()
2501 bt_dev_dbg(hdev, "Pausing advertising instances"); in hci_pause_advertising_sync()
2506 err = hci_disable_advertising_sync(hdev); in hci_pause_advertising_sync()
2511 if (!ext_adv_capable(hdev)) in hci_pause_advertising_sync()
2512 cancel_adv_timeout(hdev); in hci_pause_advertising_sync()
2514 hdev->advertising_paused = true; in hci_pause_advertising_sync()
2515 hdev->advertising_old_state = old_state; in hci_pause_advertising_sync()
2521 static int hci_resume_advertising_sync(struct hci_dev *hdev) in hci_resume_advertising_sync() argument
2527 if (!hdev->advertising_paused) in hci_resume_advertising_sync()
2531 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2532 if (hdev->advertising_old_state) { in hci_resume_advertising_sync()
2533 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_resume_advertising_sync()
2534 hdev->advertising_old_state = 0; in hci_resume_advertising_sync()
2537 bt_dev_dbg(hdev, "Resuming advertising instances"); in hci_resume_advertising_sync()
2539 if (ext_adv_capable(hdev)) { in hci_resume_advertising_sync()
2541 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) { in hci_resume_advertising_sync()
2542 err = hci_enable_ext_advertising_sync(hdev, in hci_resume_advertising_sync()
2548 hci_remove_ext_adv_instance_sync(hdev, adv->instance, in hci_resume_advertising_sync()
2555 err = hci_schedule_adv_instance_sync(hdev, in hci_resume_advertising_sync()
2556 hdev->cur_adv_instance, in hci_resume_advertising_sync()
2560 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2565 static int hci_pause_addr_resolution(struct hci_dev *hdev) in hci_pause_addr_resolution() argument
2569 if (!use_ll_privacy(hdev)) in hci_pause_addr_resolution()
2572 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_pause_addr_resolution()
2578 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) || in hci_pause_addr_resolution()
2579 hci_lookup_le_connect(hdev)) { in hci_pause_addr_resolution()
2580 bt_dev_err(hdev, "Command not allowed when scan/LE connect"); in hci_pause_addr_resolution()
2585 err = hci_pause_advertising_sync(hdev); in hci_pause_addr_resolution()
2587 bt_dev_err(hdev, "Pause advertising failed: %d", err); in hci_pause_addr_resolution()
2591 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_pause_addr_resolution()
2593 bt_dev_err(hdev, "Unable to disable Address Resolution: %d", in hci_pause_addr_resolution()
2597 if (!err && scan_use_rpa(hdev)) in hci_pause_addr_resolution()
2600 hci_resume_advertising_sync(hdev); in hci_pause_addr_resolution()
2604 struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, in hci_read_local_oob_data_sync() argument
2610 return __hci_cmd_sync_sk(hdev, opcode, 0, NULL, 0, HCI_CMD_TIMEOUT, sk); in hci_read_local_oob_data_sync()
2660 static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) in hci_le_clear_accept_list_sync() argument
2662 if (!(hdev->commands[26] & 0x80)) in hci_le_clear_accept_list_sync()
2665 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_ACCEPT_LIST, 0, NULL, in hci_le_clear_accept_list_sync()
2686 static u8 hci_update_accept_list_sync(struct hci_dev *hdev) in hci_update_accept_list_sync() argument
2699 if (use_ll_privacy(hdev)) { in hci_update_accept_list_sync()
2700 err = hci_pause_advertising_sync(hdev); in hci_update_accept_list_sync()
2702 bt_dev_err(hdev, "pause advertising failed: %d", err); in hci_update_accept_list_sync()
2711 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_update_accept_list_sync()
2713 bt_dev_err(hdev, "Unable to disable LL privacy: %d", err); in hci_update_accept_list_sync()
2718 if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_update_accept_list_sync()
2721 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_PA_CREATE_SYNC); in hci_update_accept_list_sync()
2733 hci_le_clear_accept_list_sync(hdev); in hci_update_accept_list_sync()
2736 err = hci_le_add_accept_list_sync(hdev, &pa, in hci_update_accept_list_sync()
2748 list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { in hci_update_accept_list_sync()
2749 if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) in hci_update_accept_list_sync()
2753 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_update_accept_list_sync()
2756 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_update_accept_list_sync()
2764 hci_le_del_accept_list_sync(hdev, &b->bdaddr, in hci_update_accept_list_sync()
2786 params = conn_params_copy(&hdev->pend_le_conns, &n); in hci_update_accept_list_sync()
2793 err = hci_le_add_accept_list_sync(hdev, ¶ms[i], in hci_update_accept_list_sync()
2808 params = conn_params_copy(&hdev->pend_le_reports, &n); in hci_update_accept_list_sync()
2815 err = hci_le_add_accept_list_sync(hdev, ¶ms[i], in hci_update_accept_list_sync()
2830 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in hci_update_accept_list_sync()
2831 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE && in hci_update_accept_list_sync()
2832 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in hci_update_accept_list_sync()
2839 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_update_accept_list_sync()
2841 bt_dev_err(hdev, "Unable to enable LL privacy: %d", err); in hci_update_accept_list_sync()
2844 if (use_ll_privacy(hdev)) in hci_update_accept_list_sync()
2845 hci_resume_advertising_sync(hdev); in hci_update_accept_list_sync()
2859 static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_ext_scan_param_sync() argument
2879 if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_le_set_ext_scan_param_sync()
2882 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST); in hci_le_set_ext_scan_param_sync()
2886 conn = hci_conn_hash_lookup_ba(hdev, ISO_LINK, in hci_le_set_ext_scan_param_sync()
2916 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_le_set_ext_scan_param_sync()
2923 if (scan_coded(hdev)) { in hci_le_set_ext_scan_param_sync()
2934 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS, in hci_le_set_ext_scan_param_sync()
2939 static int hci_le_set_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_scan_param_sync() argument
2945 if (use_ext_scan(hdev)) in hci_le_set_scan_param_sync()
2946 return hci_le_set_ext_scan_param_sync(hdev, type, interval, in hci_le_set_scan_param_sync()
2957 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_PARAM, in hci_le_set_scan_param_sync()
2961 static int hci_start_scan_sync(struct hci_dev *hdev, u8 type, u16 interval, in hci_start_scan_sync() argument
2967 if (hdev->scanning_paused) { in hci_start_scan_sync()
2968 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_start_scan_sync()
2972 err = hci_le_set_scan_param_sync(hdev, type, interval, window, in hci_start_scan_sync()
2977 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, filter_dup); in hci_start_scan_sync()
2980 static int hci_passive_scan_sync(struct hci_dev *hdev) in hci_passive_scan_sync() argument
2988 if (hdev->scanning_paused) { in hci_passive_scan_sync()
2989 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_passive_scan_sync()
2993 err = hci_scan_disable_sync(hdev); in hci_passive_scan_sync()
2995 bt_dev_err(hdev, "disable scanning failed: %d", err); in hci_passive_scan_sync()
3005 if (hci_update_random_address_sync(hdev, false, scan_use_rpa(hdev), in hci_passive_scan_sync()
3009 if (hdev->enable_advmon_interleave_scan && in hci_passive_scan_sync()
3010 hci_update_interleaved_scan_sync(hdev)) in hci_passive_scan_sync()
3013 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_passive_scan_sync()
3019 filter_policy = hci_update_accept_list_sync(hdev); in hci_passive_scan_sync()
3025 if (hdev->suspended && !filter_policy) { in hci_passive_scan_sync()
3029 if (list_empty(&hdev->le_accept_list)) in hci_passive_scan_sync()
3051 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_passive_scan_sync()
3052 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_passive_scan_sync()
3055 if (hdev->suspended) { in hci_passive_scan_sync()
3056 window = hdev->le_scan_window_suspend; in hci_passive_scan_sync()
3057 interval = hdev->le_scan_int_suspend; in hci_passive_scan_sync()
3058 } else if (hci_is_le_conn_scanning(hdev)) { in hci_passive_scan_sync()
3059 window = hdev->le_scan_window_connect; in hci_passive_scan_sync()
3060 interval = hdev->le_scan_int_connect; in hci_passive_scan_sync()
3061 } else if (hci_is_adv_monitoring(hdev)) { in hci_passive_scan_sync()
3062 window = hdev->le_scan_window_adv_monitor; in hci_passive_scan_sync()
3063 interval = hdev->le_scan_int_adv_monitor; in hci_passive_scan_sync()
3079 window = hdev->le_scan_window; in hci_passive_scan_sync()
3080 interval = hdev->le_scan_interval; in hci_passive_scan_sync()
3084 if (hci_dev_test_flag(hdev, HCI_MESH)) { in hci_passive_scan_sync()
3089 bt_dev_dbg(hdev, "LE passive scan with acceptlist = %d", filter_policy); in hci_passive_scan_sync()
3091 return hci_start_scan_sync(hdev, LE_SCAN_PASSIVE, interval, window, in hci_passive_scan_sync()
3110 int hci_update_passive_scan_sync(struct hci_dev *hdev) in hci_update_passive_scan_sync() argument
3114 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan_sync()
3115 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan_sync()
3116 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan_sync()
3117 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan_sync()
3118 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan_sync()
3119 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan_sync()
3123 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_sync()
3127 if (hdev->discovery.state != DISCOVERY_STOPPED) in hci_update_passive_scan_sync()
3137 hci_discovery_filter_clear(hdev); in hci_update_passive_scan_sync()
3139 bt_dev_dbg(hdev, "ADV monitoring is %s", in hci_update_passive_scan_sync()
3140 hci_is_adv_monitoring(hdev) ? "on" : "off"); in hci_update_passive_scan_sync()
3142 if (!hci_dev_test_flag(hdev, HCI_MESH) && in hci_update_passive_scan_sync()
3143 list_empty(&hdev->pend_le_conns) && in hci_update_passive_scan_sync()
3144 list_empty(&hdev->pend_le_reports) && in hci_update_passive_scan_sync()
3145 !hci_is_adv_monitoring(hdev) && in hci_update_passive_scan_sync()
3146 !hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_update_passive_scan_sync()
3152 bt_dev_dbg(hdev, "stopping background scanning"); in hci_update_passive_scan_sync()
3154 err = hci_scan_disable_sync(hdev); in hci_update_passive_scan_sync()
3156 bt_dev_err(hdev, "stop background scanning failed: %d", in hci_update_passive_scan_sync()
3167 if (hci_lookup_le_connect(hdev)) in hci_update_passive_scan_sync()
3170 bt_dev_dbg(hdev, "start background scanning"); in hci_update_passive_scan_sync()
3172 err = hci_passive_scan_sync(hdev); in hci_update_passive_scan_sync()
3174 bt_dev_err(hdev, "start background scanning failed: %d", in hci_update_passive_scan_sync()
3181 static int update_scan_sync(struct hci_dev *hdev, void *data) in update_scan_sync() argument
3183 return hci_update_scan_sync(hdev); in update_scan_sync()
3186 int hci_update_scan(struct hci_dev *hdev) in hci_update_scan() argument
3188 return hci_cmd_sync_queue(hdev, update_scan_sync, NULL, NULL); in hci_update_scan()
3191 static int update_passive_scan_sync(struct hci_dev *hdev, void *data) in update_passive_scan_sync() argument
3193 return hci_update_passive_scan_sync(hdev); in update_passive_scan_sync()
3196 int hci_update_passive_scan(struct hci_dev *hdev) in hci_update_passive_scan() argument
3199 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan()
3200 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan()
3201 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan()
3202 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan()
3203 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan()
3204 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan()
3207 return hci_cmd_sync_queue_once(hdev, update_passive_scan_sync, NULL, in hci_update_passive_scan()
3211 int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val) in hci_write_sc_support_sync() argument
3215 if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev)) in hci_write_sc_support_sync()
3218 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_sync()
3223 hdev->features[1][0] |= LMP_HOST_SC; in hci_write_sc_support_sync()
3224 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
3226 hdev->features[1][0] &= ~LMP_HOST_SC; in hci_write_sc_support_sync()
3227 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
3234 int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) in hci_write_ssp_mode_sync() argument
3238 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_ssp_mode_sync()
3239 lmp_host_ssp_capable(hdev)) in hci_write_ssp_mode_sync()
3242 if (!mode && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) { in hci_write_ssp_mode_sync()
3243 __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in hci_write_ssp_mode_sync()
3247 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_sync()
3252 return hci_write_sc_support_sync(hdev, 0x01); in hci_write_ssp_mode_sync()
3255 int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul) in hci_write_le_host_supported_sync() argument
3259 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in hci_write_le_host_supported_sync()
3260 !lmp_bredr_capable(hdev)) in hci_write_le_host_supported_sync()
3266 if (le == lmp_host_le_capable(hdev) && in hci_write_le_host_supported_sync()
3267 simul == lmp_host_le_br_capable(hdev)) in hci_write_le_host_supported_sync()
3275 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_write_le_host_supported_sync()
3279 static int hci_powered_update_adv_sync(struct hci_dev *hdev) in hci_powered_update_adv_sync() argument
3284 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_powered_update_adv_sync()
3292 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) { in hci_powered_update_adv_sync()
3293 hci_le_add_resolve_list_sync(hdev, NULL); in hci_powered_update_adv_sync()
3294 hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_powered_update_adv_sync()
3301 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_powered_update_adv_sync()
3302 list_empty(&hdev->adv_instances)) { in hci_powered_update_adv_sync()
3303 if (ext_adv_capable(hdev)) { in hci_powered_update_adv_sync()
3304 err = hci_setup_ext_adv_instance_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3306 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3308 err = hci_update_adv_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3310 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3313 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_powered_update_adv_sync()
3314 hci_enable_advertising_sync(hdev); in hci_powered_update_adv_sync()
3318 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) in hci_powered_update_adv_sync()
3319 hci_schedule_adv_instance_sync(hdev, adv->instance, true); in hci_powered_update_adv_sync()
3324 static int hci_write_auth_enable_sync(struct hci_dev *hdev) in hci_write_auth_enable_sync() argument
3328 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in hci_write_auth_enable_sync()
3329 if (link_sec == test_bit(HCI_AUTH, &hdev->flags)) in hci_write_auth_enable_sync()
3332 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE, in hci_write_auth_enable_sync()
3337 int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable) in hci_write_fast_connectable_sync() argument
3343 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_write_fast_connectable_sync()
3346 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_write_fast_connectable_sync()
3357 type = hdev->def_page_scan_type; in hci_write_fast_connectable_sync()
3358 cp.interval = cpu_to_le16(hdev->def_page_scan_int); in hci_write_fast_connectable_sync()
3361 cp.window = cpu_to_le16(hdev->def_page_scan_window); in hci_write_fast_connectable_sync()
3363 if (__cpu_to_le16(hdev->page_scan_interval) != cp.interval || in hci_write_fast_connectable_sync()
3364 __cpu_to_le16(hdev->page_scan_window) != cp.window) { in hci_write_fast_connectable_sync()
3365 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3372 if (hdev->page_scan_type != type) in hci_write_fast_connectable_sync()
3373 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3381 static bool disconnected_accept_list_entries(struct hci_dev *hdev) in disconnected_accept_list_entries() argument
3385 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
3388 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
3399 static int hci_write_scan_enable_sync(struct hci_dev *hdev, u8 val) in hci_write_scan_enable_sync() argument
3401 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE, in hci_write_scan_enable_sync()
3406 int hci_update_scan_sync(struct hci_dev *hdev) in hci_update_scan_sync() argument
3410 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_scan_sync()
3413 if (!hdev_is_powered(hdev)) in hci_update_scan_sync()
3416 if (mgmt_powering_down(hdev)) in hci_update_scan_sync()
3419 if (hdev->scanning_paused) in hci_update_scan_sync()
3422 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in hci_update_scan_sync()
3423 disconnected_accept_list_entries(hdev)) in hci_update_scan_sync()
3428 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_update_scan_sync()
3431 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in hci_update_scan_sync()
3432 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in hci_update_scan_sync()
3435 return hci_write_scan_enable_sync(hdev, scan); in hci_update_scan_sync()
3438 int hci_update_name_sync(struct hci_dev *hdev) in hci_update_name_sync() argument
3444 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in hci_update_name_sync()
3446 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME, in hci_update_name_sync()
3463 int hci_powered_update_sync(struct hci_dev *hdev) in hci_powered_update_sync() argument
3472 smp_register(hdev); in hci_powered_update_sync()
3474 err = hci_write_ssp_mode_sync(hdev, 0x01); in hci_powered_update_sync()
3478 err = hci_write_le_host_supported_sync(hdev, 0x01, 0x00); in hci_powered_update_sync()
3482 err = hci_powered_update_adv_sync(hdev); in hci_powered_update_sync()
3486 err = hci_write_auth_enable_sync(hdev); in hci_powered_update_sync()
3490 if (lmp_bredr_capable(hdev)) { in hci_powered_update_sync()
3491 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in hci_powered_update_sync()
3492 hci_write_fast_connectable_sync(hdev, true); in hci_powered_update_sync()
3494 hci_write_fast_connectable_sync(hdev, false); in hci_powered_update_sync()
3495 hci_update_scan_sync(hdev); in hci_powered_update_sync()
3496 hci_update_class_sync(hdev); in hci_powered_update_sync()
3497 hci_update_name_sync(hdev); in hci_powered_update_sync()
3498 hci_update_eir_sync(hdev); in hci_powered_update_sync()
3510 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_powered_update_sync()
3511 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_powered_update_sync()
3512 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))) { in hci_powered_update_sync()
3513 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in hci_powered_update_sync()
3514 return hci_set_random_addr_sync(hdev, in hci_powered_update_sync()
3515 &hdev->static_addr); in hci_powered_update_sync()
3533 static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) in hci_dev_get_bd_addr_from_property() argument
3535 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
3544 if (test_bit(HCI_QUIRK_BDADDR_PROPERTY_BROKEN, &hdev->quirks)) in hci_dev_get_bd_addr_from_property()
3545 baswap(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3547 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3551 int (*func)(struct hci_dev *hdev);
3555 static int hci_init_stage_sync(struct hci_dev *hdev, in hci_init_stage_sync() argument
3563 err = stage[i].func(hdev); in hci_init_stage_sync()
3572 static int hci_read_local_version_sync(struct hci_dev *hdev) in hci_read_local_version_sync() argument
3574 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_VERSION, in hci_read_local_version_sync()
3579 static int hci_read_bd_addr_sync(struct hci_dev *hdev) in hci_read_bd_addr_sync() argument
3581 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BD_ADDR, in hci_read_bd_addr_sync()
3598 int hci_reset_sync(struct hci_dev *hdev) in hci_reset_sync() argument
3602 set_bit(HCI_RESET, &hdev->flags); in hci_reset_sync()
3604 err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL, in hci_reset_sync()
3612 static int hci_init0_sync(struct hci_dev *hdev) in hci_init0_sync() argument
3616 bt_dev_dbg(hdev, ""); in hci_init0_sync()
3619 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init0_sync()
3620 err = hci_reset_sync(hdev); in hci_init0_sync()
3625 return hci_init_stage_sync(hdev, hci_init0); in hci_init0_sync()
3628 static int hci_unconf_init_sync(struct hci_dev *hdev) in hci_unconf_init_sync() argument
3632 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_unconf_init_sync()
3635 err = hci_init0_sync(hdev); in hci_unconf_init_sync()
3639 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_unconf_init_sync()
3640 hci_debugfs_create_basic(hdev); in hci_unconf_init_sync()
3646 static int hci_read_local_features_sync(struct hci_dev *hdev) in hci_read_local_features_sync() argument
3648 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_FEATURES, in hci_read_local_features_sync()
3664 static int hci_read_local_cmds_sync(struct hci_dev *hdev) in hci_read_local_cmds_sync() argument
3674 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_read_local_cmds_sync()
3675 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_read_local_cmds_sync()
3676 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_COMMANDS, in hci_read_local_cmds_sync()
3682 static int hci_init1_sync(struct hci_dev *hdev) in hci_init1_sync() argument
3686 bt_dev_dbg(hdev, ""); in hci_init1_sync()
3689 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init1_sync()
3690 err = hci_reset_sync(hdev); in hci_init1_sync()
3695 return hci_init_stage_sync(hdev, br_init1); in hci_init1_sync()
3699 static int hci_read_buffer_size_sync(struct hci_dev *hdev) in hci_read_buffer_size_sync() argument
3701 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BUFFER_SIZE, in hci_read_buffer_size_sync()
3706 static int hci_read_dev_class_sync(struct hci_dev *hdev) in hci_read_dev_class_sync() argument
3708 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLASS_OF_DEV, in hci_read_dev_class_sync()
3713 static int hci_read_local_name_sync(struct hci_dev *hdev) in hci_read_local_name_sync() argument
3715 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_NAME, in hci_read_local_name_sync()
3720 static int hci_read_voice_setting_sync(struct hci_dev *hdev) in hci_read_voice_setting_sync() argument
3722 return __hci_cmd_sync_status(hdev, HCI_OP_READ_VOICE_SETTING, in hci_read_voice_setting_sync()
3727 static int hci_read_num_supported_iac_sync(struct hci_dev *hdev) in hci_read_num_supported_iac_sync() argument
3729 return __hci_cmd_sync_status(hdev, HCI_OP_READ_NUM_SUPPORTED_IAC, in hci_read_num_supported_iac_sync()
3734 static int hci_read_current_iac_lap_sync(struct hci_dev *hdev) in hci_read_current_iac_lap_sync() argument
3736 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CURRENT_IAC_LAP, in hci_read_current_iac_lap_sync()
3740 static int hci_set_event_filter_sync(struct hci_dev *hdev, u8 flt_type, in hci_set_event_filter_sync() argument
3746 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_set_event_filter_sync()
3749 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_set_event_filter_sync()
3761 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_FLT, in hci_set_event_filter_sync()
3767 static int hci_clear_event_filter_sync(struct hci_dev *hdev) in hci_clear_event_filter_sync() argument
3769 if (!hci_dev_test_flag(hdev, HCI_EVENT_FILTER_CONFIGURED)) in hci_clear_event_filter_sync()
3776 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_clear_event_filter_sync()
3779 return hci_set_event_filter_sync(hdev, HCI_FLT_CLEAR_ALL, 0x00, in hci_clear_event_filter_sync()
3784 static int hci_write_ca_timeout_sync(struct hci_dev *hdev) in hci_write_ca_timeout_sync() argument
3788 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CA_TIMEOUT, in hci_write_ca_timeout_sync()
3813 static int hci_write_ssp_mode_1_sync(struct hci_dev *hdev) in hci_write_ssp_mode_1_sync() argument
3817 if (!lmp_ssp_capable(hdev) || !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_ssp_mode_1_sync()
3826 hdev->max_page = 0x01; in hci_write_ssp_mode_1_sync()
3828 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_1_sync()
3832 static int hci_write_eir_sync(struct hci_dev *hdev) in hci_write_eir_sync() argument
3836 if (!lmp_ssp_capable(hdev) || hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_eir_sync()
3839 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_write_eir_sync()
3842 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_write_eir_sync()
3846 static int hci_write_inquiry_mode_sync(struct hci_dev *hdev) in hci_write_inquiry_mode_sync() argument
3850 if (!lmp_inq_rssi_capable(hdev) && in hci_write_inquiry_mode_sync()
3851 !test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_write_inquiry_mode_sync()
3858 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_write_inquiry_mode_sync()
3860 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_INQUIRY_MODE, in hci_write_inquiry_mode_sync()
3864 static int hci_read_inq_rsp_tx_power_sync(struct hci_dev *hdev) in hci_read_inq_rsp_tx_power_sync() argument
3866 if (!lmp_inq_tx_pwr_capable(hdev)) in hci_read_inq_rsp_tx_power_sync()
3869 return __hci_cmd_sync_status(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, in hci_read_inq_rsp_tx_power_sync()
3873 static int hci_read_local_ext_features_sync(struct hci_dev *hdev, u8 page) in hci_read_local_ext_features_sync() argument
3877 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_sync()
3883 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, in hci_read_local_ext_features_sync()
3887 static int hci_read_local_ext_features_1_sync(struct hci_dev *hdev) in hci_read_local_ext_features_1_sync() argument
3889 return hci_read_local_ext_features_sync(hdev, 0x01); in hci_read_local_ext_features_1_sync()
3912 static int hci_le_read_buffer_size_sync(struct hci_dev *hdev) in hci_le_read_buffer_size_sync() argument
3915 if (iso_capable(hdev) && hdev->commands[41] & 0x20) in hci_le_read_buffer_size_sync()
3916 return __hci_cmd_sync_status(hdev, in hci_le_read_buffer_size_sync()
3920 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_BUFFER_SIZE, in hci_le_read_buffer_size_sync()
3925 static int hci_le_read_local_features_sync(struct hci_dev *hdev) in hci_le_read_local_features_sync() argument
3927 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_LOCAL_FEATURES, in hci_le_read_local_features_sync()
3932 static int hci_le_read_supported_states_sync(struct hci_dev *hdev) in hci_le_read_supported_states_sync() argument
3934 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_SUPPORTED_STATES, in hci_le_read_supported_states_sync()
3949 static int hci_init2_sync(struct hci_dev *hdev) in hci_init2_sync() argument
3953 bt_dev_dbg(hdev, ""); in hci_init2_sync()
3955 err = hci_init_stage_sync(hdev, hci_init2); in hci_init2_sync()
3959 if (lmp_bredr_capable(hdev)) { in hci_init2_sync()
3960 err = hci_init_stage_sync(hdev, br_init2); in hci_init2_sync()
3964 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_sync()
3967 if (lmp_le_capable(hdev)) { in hci_init2_sync()
3968 err = hci_init_stage_sync(hdev, le_init2); in hci_init2_sync()
3972 if (!lmp_bredr_capable(hdev)) in hci_init2_sync()
3973 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in hci_init2_sync()
3979 static int hci_set_event_mask_sync(struct hci_dev *hdev) in hci_set_event_mask_sync() argument
3990 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_set_event_mask_sync()
3993 if (lmp_bredr_capable(hdev)) { in hci_set_event_mask_sync()
4000 if (hdev->suspended) { in hci_set_event_mask_sync()
4015 if (hdev->commands[0] & 0x20) { in hci_set_event_mask_sync()
4020 if (!hdev->suspended) in hci_set_event_mask_sync()
4029 if (hdev->commands[2] & 0x80) in hci_set_event_mask_sync()
4034 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_set_event_mask_sync()
4040 if (lmp_inq_rssi_capable(hdev) || in hci_set_event_mask_sync()
4041 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_set_event_mask_sync()
4044 if (lmp_ext_feat_capable(hdev)) in hci_set_event_mask_sync()
4047 if (lmp_esco_capable(hdev)) { in hci_set_event_mask_sync()
4052 if (lmp_sniffsubr_capable(hdev)) in hci_set_event_mask_sync()
4055 if (lmp_pause_enc_capable(hdev)) in hci_set_event_mask_sync()
4058 if (lmp_ext_inq_capable(hdev)) in hci_set_event_mask_sync()
4061 if (lmp_no_flush_capable(hdev)) in hci_set_event_mask_sync()
4064 if (lmp_lsto_capable(hdev)) in hci_set_event_mask_sync()
4067 if (lmp_ssp_capable(hdev)) { in hci_set_event_mask_sync()
4081 if (lmp_le_capable(hdev)) in hci_set_event_mask_sync()
4084 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK, in hci_set_event_mask_sync()
4088 static int hci_read_stored_link_key_sync(struct hci_dev *hdev) in hci_read_stored_link_key_sync() argument
4092 if (!(hdev->commands[6] & 0x20) || in hci_read_stored_link_key_sync()
4093 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_read_stored_link_key_sync()
4100 return __hci_cmd_sync_status(hdev, HCI_OP_READ_STORED_LINK_KEY, in hci_read_stored_link_key_sync()
4104 static int hci_setup_link_policy_sync(struct hci_dev *hdev) in hci_setup_link_policy_sync() argument
4109 if (!(hdev->commands[5] & 0x10)) in hci_setup_link_policy_sync()
4114 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy_sync()
4116 if (lmp_hold_capable(hdev)) in hci_setup_link_policy_sync()
4118 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy_sync()
4120 if (lmp_park_capable(hdev)) in hci_setup_link_policy_sync()
4125 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, in hci_setup_link_policy_sync()
4129 static int hci_read_page_scan_activity_sync(struct hci_dev *hdev) in hci_read_page_scan_activity_sync() argument
4131 if (!(hdev->commands[8] & 0x01)) in hci_read_page_scan_activity_sync()
4134 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_ACTIVITY, in hci_read_page_scan_activity_sync()
4138 static int hci_read_def_err_data_reporting_sync(struct hci_dev *hdev) in hci_read_def_err_data_reporting_sync() argument
4140 if (!(hdev->commands[18] & 0x04) || in hci_read_def_err_data_reporting_sync()
4141 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_read_def_err_data_reporting_sync()
4142 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_read_def_err_data_reporting_sync()
4145 return __hci_cmd_sync_status(hdev, HCI_OP_READ_DEF_ERR_DATA_REPORTING, in hci_read_def_err_data_reporting_sync()
4149 static int hci_read_page_scan_type_sync(struct hci_dev *hdev) in hci_read_page_scan_type_sync() argument
4155 if (!(hdev->commands[13] & 0x01)) in hci_read_page_scan_type_sync()
4158 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_TYPE, in hci_read_page_scan_type_sync()
4163 static int hci_read_local_ext_features_all_sync(struct hci_dev *hdev) in hci_read_local_ext_features_all_sync() argument
4168 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_all_sync()
4171 for (page = 2; page < HCI_MAX_PAGES && page <= hdev->max_page; in hci_read_local_ext_features_all_sync()
4173 err = hci_read_local_ext_features_sync(hdev, page); in hci_read_local_ext_features_all_sync()
4200 static int hci_le_set_event_mask_sync(struct hci_dev *hdev) in hci_le_set_event_mask_sync() argument
4204 if (!lmp_le_capable(hdev)) in hci_le_set_event_mask_sync()
4209 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_le_set_event_mask_sync()
4215 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_le_set_event_mask_sync()
4222 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_le_set_event_mask_sync()
4228 if (use_enhanced_conn_complete(hdev)) in hci_le_set_event_mask_sync()
4234 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_le_set_event_mask_sync()
4240 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_le_set_event_mask_sync()
4246 if (hdev->commands[26] & 0x08) in hci_le_set_event_mask_sync()
4252 if (hdev->commands[26] & 0x10) in hci_le_set_event_mask_sync()
4258 if (hdev->commands[27] & 0x04) in hci_le_set_event_mask_sync()
4264 if (hdev->commands[27] & 0x20) in hci_le_set_event_mask_sync()
4271 if (hdev->commands[34] & 0x02) in hci_le_set_event_mask_sync()
4278 if (hdev->commands[34] & 0x04) in hci_le_set_event_mask_sync()
4284 if (hdev->commands[35] & (0x20 | 0x40)) in hci_le_set_event_mask_sync()
4291 if (use_ext_scan(hdev)) in hci_le_set_event_mask_sync()
4297 if (ext_adv_capable(hdev)) in hci_le_set_event_mask_sync()
4300 if (cis_capable(hdev)) { in hci_le_set_event_mask_sync()
4302 if (cis_peripheral_capable(hdev)) in hci_le_set_event_mask_sync()
4306 if (bis_capable(hdev)) { in hci_le_set_event_mask_sync()
4316 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EVENT_MASK, in hci_le_set_event_mask_sync()
4321 static int hci_le_read_adv_tx_power_sync(struct hci_dev *hdev) in hci_le_read_adv_tx_power_sync() argument
4323 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_le_read_adv_tx_power_sync()
4330 return __hci_cmd_sync_status(hdev, in hci_le_read_adv_tx_power_sync()
4339 static int hci_le_read_tx_power_sync(struct hci_dev *hdev) in hci_le_read_tx_power_sync() argument
4341 if (!(hdev->commands[38] & 0x80) || in hci_le_read_tx_power_sync()
4342 test_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks)) in hci_le_read_tx_power_sync()
4345 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_TRANSMIT_POWER, in hci_le_read_tx_power_sync()
4350 static int hci_le_read_accept_list_size_sync(struct hci_dev *hdev) in hci_le_read_accept_list_size_sync() argument
4352 if (!(hdev->commands[26] & 0x40)) in hci_le_read_accept_list_size_sync()
4355 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_ACCEPT_LIST_SIZE, in hci_le_read_accept_list_size_sync()
4360 static int hci_le_read_resolv_list_size_sync(struct hci_dev *hdev) in hci_le_read_resolv_list_size_sync() argument
4362 if (!(hdev->commands[34] & 0x40)) in hci_le_read_resolv_list_size_sync()
4365 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_RESOLV_LIST_SIZE, in hci_le_read_resolv_list_size_sync()
4370 static int hci_le_clear_resolv_list_sync(struct hci_dev *hdev) in hci_le_clear_resolv_list_sync() argument
4372 if (!(hdev->commands[34] & 0x20)) in hci_le_clear_resolv_list_sync()
4375 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL, in hci_le_clear_resolv_list_sync()
4380 static int hci_le_set_rpa_timeout_sync(struct hci_dev *hdev) in hci_le_set_rpa_timeout_sync() argument
4382 __le16 timeout = cpu_to_le16(hdev->rpa_timeout); in hci_le_set_rpa_timeout_sync()
4384 if (!(hdev->commands[35] & 0x04) || in hci_le_set_rpa_timeout_sync()
4385 test_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT, &hdev->quirks)) in hci_le_set_rpa_timeout_sync()
4388 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RPA_TIMEOUT, in hci_le_set_rpa_timeout_sync()
4394 static int hci_le_read_max_data_len_sync(struct hci_dev *hdev) in hci_le_read_max_data_len_sync() argument
4396 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_max_data_len_sync()
4399 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL, in hci_le_read_max_data_len_sync()
4404 static int hci_le_read_def_data_len_sync(struct hci_dev *hdev) in hci_le_read_def_data_len_sync() argument
4406 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_def_data_len_sync()
4409 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_DEF_DATA_LEN, 0, NULL, in hci_le_read_def_data_len_sync()
4414 static int hci_le_read_num_support_adv_sets_sync(struct hci_dev *hdev) in hci_le_read_num_support_adv_sets_sync() argument
4416 if (!ext_adv_capable(hdev)) in hci_le_read_num_support_adv_sets_sync()
4419 return __hci_cmd_sync_status(hdev, in hci_le_read_num_support_adv_sets_sync()
4425 static int hci_set_le_support_sync(struct hci_dev *hdev) in hci_set_le_support_sync() argument
4430 if (!lmp_bredr_capable(hdev)) in hci_set_le_support_sync()
4435 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support_sync()
4440 if (cp.le == lmp_host_le_capable(hdev)) in hci_set_le_support_sync()
4443 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_set_le_support_sync()
4448 static int hci_le_set_host_feature_sync(struct hci_dev *hdev) in hci_le_set_host_feature_sync() argument
4452 if (!cis_capable(hdev)) in hci_le_set_host_feature_sync()
4461 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_HOST_FEATURE, in hci_le_set_host_feature_sync()
4496 static int hci_init3_sync(struct hci_dev *hdev) in hci_init3_sync() argument
4500 bt_dev_dbg(hdev, ""); in hci_init3_sync()
4502 err = hci_init_stage_sync(hdev, hci_init3); in hci_init3_sync()
4506 if (lmp_le_capable(hdev)) in hci_init3_sync()
4507 return hci_init_stage_sync(hdev, le_init3); in hci_init3_sync()
4512 static int hci_delete_stored_link_key_sync(struct hci_dev *hdev) in hci_delete_stored_link_key_sync() argument
4529 if (!(hdev->commands[6] & 0x80) || in hci_delete_stored_link_key_sync()
4530 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_delete_stored_link_key_sync()
4537 return __hci_cmd_sync_status(hdev, HCI_OP_DELETE_STORED_LINK_KEY, in hci_delete_stored_link_key_sync()
4541 static int hci_set_event_mask_page_2_sync(struct hci_dev *hdev) in hci_set_event_mask_page_2_sync() argument
4547 if (!(hdev->commands[22] & 0x04)) in hci_set_event_mask_page_2_sync()
4553 if (lmp_cpb_central_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4564 if (lmp_cpb_peripheral_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4573 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2_sync()
4587 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK_PAGE_2, in hci_set_event_mask_page_2_sync()
4592 static int hci_read_local_codecs_sync(struct hci_dev *hdev) in hci_read_local_codecs_sync() argument
4594 if (hdev->commands[45] & 0x04) in hci_read_local_codecs_sync()
4595 hci_read_supported_codecs_v2(hdev); in hci_read_local_codecs_sync()
4596 else if (hdev->commands[29] & 0x20) in hci_read_local_codecs_sync()
4597 hci_read_supported_codecs(hdev); in hci_read_local_codecs_sync()
4603 static int hci_read_local_pairing_opts_sync(struct hci_dev *hdev) in hci_read_local_pairing_opts_sync() argument
4605 if (!(hdev->commands[41] & 0x08)) in hci_read_local_pairing_opts_sync()
4608 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_PAIRING_OPTS, in hci_read_local_pairing_opts_sync()
4613 static int hci_get_mws_transport_config_sync(struct hci_dev *hdev) in hci_get_mws_transport_config_sync() argument
4615 if (!mws_transport_config_capable(hdev)) in hci_get_mws_transport_config_sync()
4618 return __hci_cmd_sync_status(hdev, HCI_OP_GET_MWS_TRANSPORT_CONFIG, in hci_get_mws_transport_config_sync()
4623 static int hci_read_sync_train_params_sync(struct hci_dev *hdev) in hci_read_sync_train_params_sync() argument
4625 if (!lmp_sync_train_capable(hdev)) in hci_read_sync_train_params_sync()
4628 return __hci_cmd_sync_status(hdev, HCI_OP_READ_SYNC_TRAIN_PARAMS, in hci_read_sync_train_params_sync()
4633 static int hci_write_sc_support_1_sync(struct hci_dev *hdev) in hci_write_sc_support_1_sync() argument
4637 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_sc_support_1_sync()
4638 !bredr_sc_enabled(hdev)) in hci_write_sc_support_1_sync()
4641 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_1_sync()
4649 static int hci_set_err_data_report_sync(struct hci_dev *hdev) in hci_set_err_data_report_sync() argument
4652 bool enabled = hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED); in hci_set_err_data_report_sync()
4654 if (!(hdev->commands[18] & 0x08) || in hci_set_err_data_report_sync()
4655 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_set_err_data_report_sync()
4656 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_set_err_data_report_sync()
4659 if (enabled == hdev->err_data_reporting) in hci_set_err_data_report_sync()
4666 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING, in hci_set_err_data_report_sync()
4691 static int hci_le_set_write_def_data_len_sync(struct hci_dev *hdev) in hci_le_set_write_def_data_len_sync() argument
4695 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_set_write_def_data_len_sync()
4699 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_le_set_write_def_data_len_sync()
4700 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_le_set_write_def_data_len_sync()
4702 return __hci_cmd_sync_status(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN, in hci_le_set_write_def_data_len_sync()
4709 static int hci_le_set_default_phy_sync(struct hci_dev *hdev) in hci_le_set_default_phy_sync() argument
4713 if (!(hdev->commands[35] & 0x20)) { in hci_le_set_default_phy_sync()
4717 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4718 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4728 if (le_2m_capable(hdev)) { in hci_le_set_default_phy_sync()
4734 if (le_coded_capable(hdev)) { in hci_le_set_default_phy_sync()
4739 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in hci_le_set_default_phy_sync()
4751 static int hci_init4_sync(struct hci_dev *hdev) in hci_init4_sync() argument
4755 bt_dev_dbg(hdev, ""); in hci_init4_sync()
4757 err = hci_init_stage_sync(hdev, hci_init4); in hci_init4_sync()
4761 if (lmp_le_capable(hdev)) in hci_init4_sync()
4762 return hci_init_stage_sync(hdev, le_init4); in hci_init4_sync()
4767 static int hci_init_sync(struct hci_dev *hdev) in hci_init_sync() argument
4771 err = hci_init1_sync(hdev); in hci_init_sync()
4775 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_init_sync()
4776 hci_debugfs_create_basic(hdev); in hci_init_sync()
4778 err = hci_init2_sync(hdev); in hci_init_sync()
4782 err = hci_init3_sync(hdev); in hci_init_sync()
4786 err = hci_init4_sync(hdev); in hci_init_sync()
4802 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_init_sync()
4803 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_init_sync()
4806 if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) in hci_init_sync()
4809 hci_debugfs_create_common(hdev); in hci_init_sync()
4811 if (lmp_bredr_capable(hdev)) in hci_init_sync()
4812 hci_debugfs_create_bredr(hdev); in hci_init_sync()
4814 if (lmp_le_capable(hdev)) in hci_init_sync()
4815 hci_debugfs_create_le(hdev); in hci_init_sync()
4855 static int hci_dev_setup_sync(struct hci_dev *hdev) in hci_dev_setup_sync() argument
4861 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_setup_sync()
4862 !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) in hci_dev_setup_sync()
4865 bt_dev_dbg(hdev, ""); in hci_dev_setup_sync()
4867 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_setup_sync()
4869 if (hdev->setup) in hci_dev_setup_sync()
4870 ret = hdev->setup(hdev); in hci_dev_setup_sync()
4873 if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) in hci_dev_setup_sync()
4874 bt_dev_warn(hdev, "%s", hci_broken_table[i].desc); in hci_dev_setup_sync()
4881 invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in hci_dev_setup_sync()
4882 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); in hci_dev_setup_sync()
4884 if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks) && in hci_dev_setup_sync()
4885 !bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_setup_sync()
4886 hci_dev_get_bd_addr_from_property(hdev); in hci_dev_setup_sync()
4888 if (invalid_bdaddr && bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_setup_sync()
4889 hdev->set_bdaddr) { in hci_dev_setup_sync()
4890 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_setup_sync()
4906 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_setup_sync()
4908 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_setup_sync()
4918 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_setup_sync()
4919 return hci_unconf_init_sync(hdev); in hci_dev_setup_sync()
4929 static int hci_dev_init_sync(struct hci_dev *hdev) in hci_dev_init_sync() argument
4933 bt_dev_dbg(hdev, ""); in hci_dev_init_sync()
4935 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_init_sync()
4936 set_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4938 ret = hci_dev_setup_sync(hdev); in hci_dev_init_sync()
4940 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_init_sync()
4946 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_init_sync()
4947 hdev->set_bdaddr) in hci_dev_init_sync()
4948 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_init_sync()
4954 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_init_sync()
4955 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4956 ret = hci_init_sync(hdev); in hci_dev_init_sync()
4957 if (!ret && hdev->post_init) in hci_dev_init_sync()
4958 ret = hdev->post_init(hdev); in hci_dev_init_sync()
4966 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_init_sync()
4967 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_init_sync()
4968 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_init_sync()
4969 ret = hdev->set_diag(hdev, true); in hci_dev_init_sync()
4971 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4972 msft_do_open(hdev); in hci_dev_init_sync()
4973 aosp_do_open(hdev); in hci_dev_init_sync()
4976 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4981 int hci_dev_open_sync(struct hci_dev *hdev) in hci_dev_open_sync() argument
4985 bt_dev_dbg(hdev, ""); in hci_dev_open_sync()
4987 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_open_sync()
4992 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
4993 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_open_sync()
4997 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_open_sync()
5011 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
5012 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_open_sync()
5013 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_open_sync()
5019 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open_sync()
5024 if (hdev->open(hdev)) { in hci_dev_open_sync()
5029 hci_devcd_reset(hdev); in hci_dev_open_sync()
5031 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
5032 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_open_sync()
5034 ret = hci_dev_init_sync(hdev); in hci_dev_open_sync()
5036 hci_dev_hold(hdev); in hci_dev_open_sync()
5037 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_open_sync()
5038 hci_adv_instances_set_rpa_expired(hdev, true); in hci_dev_open_sync()
5039 set_bit(HCI_UP, &hdev->flags); in hci_dev_open_sync()
5040 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_open_sync()
5041 hci_leds_update_powered(hdev, true); in hci_dev_open_sync()
5042 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
5043 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_open_sync()
5044 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open_sync()
5045 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
5046 hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_open_sync()
5047 ret = hci_powered_update_sync(hdev); in hci_dev_open_sync()
5048 mgmt_power_on(hdev, ret); in hci_dev_open_sync()
5052 flush_work(&hdev->tx_work); in hci_dev_open_sync()
5058 flush_work(&hdev->rx_work); in hci_dev_open_sync()
5059 flush_work(&hdev->cmd_work); in hci_dev_open_sync()
5061 skb_queue_purge(&hdev->cmd_q); in hci_dev_open_sync()
5062 skb_queue_purge(&hdev->rx_q); in hci_dev_open_sync()
5064 if (hdev->flush) in hci_dev_open_sync()
5065 hdev->flush(hdev); in hci_dev_open_sync()
5067 if (hdev->sent_cmd) { in hci_dev_open_sync()
5068 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_open_sync()
5069 kfree_skb(hdev->sent_cmd); in hci_dev_open_sync()
5070 hdev->sent_cmd = NULL; in hci_dev_open_sync()
5073 if (hdev->req_skb) { in hci_dev_open_sync()
5074 kfree_skb(hdev->req_skb); in hci_dev_open_sync()
5075 hdev->req_skb = NULL; in hci_dev_open_sync()
5078 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
5079 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_open_sync()
5081 hdev->close(hdev); in hci_dev_open_sync()
5082 hdev->flags &= BIT(HCI_RAW); in hci_dev_open_sync()
5090 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
5094 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
5106 static int hci_dev_shutdown(struct hci_dev *hdev) in hci_dev_shutdown() argument
5116 hci_dev_test_and_clear_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
5118 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_shutdown()
5119 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_shutdown()
5121 if (hdev->shutdown) in hci_dev_shutdown()
5122 err = hdev->shutdown(hdev); in hci_dev_shutdown()
5126 hci_dev_set_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
5131 int hci_dev_close_sync(struct hci_dev *hdev) in hci_dev_close_sync() argument
5136 bt_dev_dbg(hdev, ""); in hci_dev_close_sync()
5138 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_close_sync()
5139 disable_delayed_work(&hdev->power_off); in hci_dev_close_sync()
5140 disable_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
5141 disable_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
5143 cancel_delayed_work(&hdev->power_off); in hci_dev_close_sync()
5144 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
5145 cancel_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
5148 hci_cmd_sync_cancel_sync(hdev, ENODEV); in hci_dev_close_sync()
5150 cancel_interleave_scan(hdev); in hci_dev_close_sync()
5152 if (hdev->adv_instance_timeout) { in hci_dev_close_sync()
5153 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_dev_close_sync()
5154 hdev->adv_instance_timeout = 0; in hci_dev_close_sync()
5157 err = hci_dev_shutdown(hdev); in hci_dev_close_sync()
5159 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_close_sync()
5160 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5164 hci_leds_update_powered(hdev, false); in hci_dev_close_sync()
5167 flush_work(&hdev->tx_work); in hci_dev_close_sync()
5168 flush_work(&hdev->rx_work); in hci_dev_close_sync()
5170 if (hdev->discov_timeout > 0) { in hci_dev_close_sync()
5171 hdev->discov_timeout = 0; in hci_dev_close_sync()
5172 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_close_sync()
5173 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_close_sync()
5176 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_close_sync()
5177 cancel_delayed_work(&hdev->service_cache); in hci_dev_close_sync()
5179 if (hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_close_sync()
5182 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_close_sync()
5184 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_close_sync()
5191 drain_workqueue(hdev->workqueue); in hci_dev_close_sync()
5193 hci_dev_lock(hdev); in hci_dev_close_sync()
5195 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_close_sync()
5197 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_close_sync()
5199 if (!auto_off && !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_close_sync()
5200 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_close_sync()
5201 __mgmt_power_off(hdev); in hci_dev_close_sync()
5203 hci_inquiry_cache_flush(hdev); in hci_dev_close_sync()
5204 hci_pend_le_actions_clear(hdev); in hci_dev_close_sync()
5205 hci_conn_hash_flush(hdev); in hci_dev_close_sync()
5207 smp_unregister(hdev); in hci_dev_close_sync()
5208 hci_dev_unlock(hdev); in hci_dev_close_sync()
5210 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_close_sync()
5212 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close_sync()
5213 aosp_do_close(hdev); in hci_dev_close_sync()
5214 msft_do_close(hdev); in hci_dev_close_sync()
5217 if (hdev->flush) in hci_dev_close_sync()
5218 hdev->flush(hdev); in hci_dev_close_sync()
5221 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5222 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_close_sync()
5223 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_close_sync()
5224 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_close_sync()
5225 set_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5226 hci_reset_sync(hdev); in hci_dev_close_sync()
5227 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5231 flush_work(&hdev->cmd_work); in hci_dev_close_sync()
5234 skb_queue_purge(&hdev->rx_q); in hci_dev_close_sync()
5235 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5236 skb_queue_purge(&hdev->raw_q); in hci_dev_close_sync()
5239 if (hdev->sent_cmd) { in hci_dev_close_sync()
5240 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5241 kfree_skb(hdev->sent_cmd); in hci_dev_close_sync()
5242 hdev->sent_cmd = NULL; in hci_dev_close_sync()
5246 if (hdev->req_skb) { in hci_dev_close_sync()
5247 kfree_skb(hdev->req_skb); in hci_dev_close_sync()
5248 hdev->req_skb = NULL; in hci_dev_close_sync()
5251 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_close_sync()
5252 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_close_sync()
5255 hdev->close(hdev); in hci_dev_close_sync()
5258 hdev->flags &= BIT(HCI_RAW); in hci_dev_close_sync()
5259 hci_dev_clear_volatile_flags(hdev); in hci_dev_close_sync()
5261 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_close_sync()
5262 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_close_sync()
5263 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_close_sync()
5264 hci_codec_list_clear(&hdev->local_codecs); in hci_dev_close_sync()
5266 hci_dev_put(hdev); in hci_dev_close_sync()
5276 static int hci_power_on_sync(struct hci_dev *hdev) in hci_power_on_sync() argument
5280 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on_sync()
5281 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on_sync()
5282 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5283 cancel_delayed_work(&hdev->power_off); in hci_power_on_sync()
5284 return hci_powered_update_sync(hdev); in hci_power_on_sync()
5287 err = hci_dev_open_sync(hdev); in hci_power_on_sync()
5295 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on_sync()
5296 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on_sync()
5297 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on_sync()
5298 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on_sync()
5299 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on_sync()
5300 hci_dev_close_sync(hdev); in hci_power_on_sync()
5301 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5302 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on_sync()
5306 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on_sync()
5310 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5311 set_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5320 mgmt_index_added(hdev); in hci_power_on_sync()
5321 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on_sync()
5325 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5326 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5332 mgmt_index_added(hdev); in hci_power_on_sync()
5338 static int hci_remote_name_cancel_sync(struct hci_dev *hdev, bdaddr_t *addr) in hci_remote_name_cancel_sync() argument
5345 return __hci_cmd_sync_status(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, in hci_remote_name_cancel_sync()
5349 int hci_stop_discovery_sync(struct hci_dev *hdev) in hci_stop_discovery_sync() argument
5351 struct discovery_state *d = &hdev->discovery; in hci_stop_discovery_sync()
5355 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_stop_discovery_sync()
5358 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_stop_discovery_sync()
5359 err = __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY_CANCEL, in hci_stop_discovery_sync()
5365 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_stop_discovery_sync()
5366 cancel_delayed_work(&hdev->le_scan_disable); in hci_stop_discovery_sync()
5368 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5374 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5380 if (use_ll_privacy(hdev)) in hci_stop_discovery_sync()
5381 hci_resume_advertising_sync(hdev); in hci_stop_discovery_sync()
5388 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_stop_discovery_sync()
5396 hci_remote_name_cancel_sync(hdev, &e->data.bdaddr); in hci_stop_discovery_sync()
5402 static int hci_disconnect_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_disconnect_sync() argument
5411 hci_dev_lock(hdev); in hci_disconnect_sync()
5413 hci_dev_unlock(hdev); in hci_disconnect_sync()
5428 return __hci_cmd_sync_status_sk(hdev, HCI_OP_DISCONNECT, in hci_disconnect_sync()
5433 return __hci_cmd_sync_status(hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp, in hci_disconnect_sync()
5437 static int hci_le_connect_cancel_sync(struct hci_dev *hdev, in hci_le_connect_cancel_sync() argument
5450 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, in hci_le_connect_cancel_sync()
5454 static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_connect_cancel_sync() argument
5458 return hci_le_connect_cancel_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5470 return hci_disconnect_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5482 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_connect_cancel_sync()
5491 return __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5496 return __hci_cmd_sync_status(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5500 static int hci_reject_sco_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_sco_sync() argument
5515 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_SYNC_CONN_REQ, in hci_reject_sco_sync()
5519 static int hci_le_reject_cis_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_le_reject_cis_sync() argument
5528 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REJECT_CIS, in hci_le_reject_cis_sync()
5532 static int hci_reject_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_conn_sync() argument
5538 return hci_le_reject_cis_sync(hdev, conn, reason); in hci_reject_conn_sync()
5541 return hci_reject_sco_sync(hdev, conn, reason); in hci_reject_conn_sync()
5547 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_CONN_REQ, in hci_reject_conn_sync()
5551 int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) in hci_abort_conn_sync() argument
5561 err = hci_disconnect_sync(hdev, conn, reason); in hci_abort_conn_sync()
5564 err = hci_connect_cancel_sync(hdev, conn, reason); in hci_abort_conn_sync()
5567 err = hci_reject_conn_sync(hdev, conn, reason); in hci_abort_conn_sync()
5577 hci_dev_lock(hdev); in hci_abort_conn_sync()
5580 c = hci_conn_hash_lookup_handle(hdev, handle); in hci_abort_conn_sync()
5600 hci_dev_unlock(hdev); in hci_abort_conn_sync()
5604 static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) in hci_disconnect_all_sync() argument
5606 struct list_head *head = &hdev->conn_hash.list; in hci_disconnect_all_sync()
5619 hci_abort_conn_sync(hdev, conn, reason); in hci_disconnect_all_sync()
5635 static int hci_power_off_sync(struct hci_dev *hdev) in hci_power_off_sync() argument
5640 if (!test_bit(HCI_UP, &hdev->flags)) in hci_power_off_sync()
5643 hci_dev_set_flag(hdev, HCI_POWERING_DOWN); in hci_power_off_sync()
5645 if (test_bit(HCI_ISCAN, &hdev->flags) || in hci_power_off_sync()
5646 test_bit(HCI_PSCAN, &hdev->flags)) { in hci_power_off_sync()
5647 err = hci_write_scan_enable_sync(hdev, 0x00); in hci_power_off_sync()
5652 err = hci_clear_adv_sync(hdev, NULL, false); in hci_power_off_sync()
5656 err = hci_stop_discovery_sync(hdev); in hci_power_off_sync()
5661 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_power_off_sync()
5665 err = hci_dev_close_sync(hdev); in hci_power_off_sync()
5668 hci_dev_clear_flag(hdev, HCI_POWERING_DOWN); in hci_power_off_sync()
5672 int hci_set_powered_sync(struct hci_dev *hdev, u8 val) in hci_set_powered_sync() argument
5675 return hci_power_on_sync(hdev); in hci_set_powered_sync()
5677 return hci_power_off_sync(hdev); in hci_set_powered_sync()
5680 static int hci_write_iac_sync(struct hci_dev *hdev) in hci_write_iac_sync() argument
5684 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_write_iac_sync()
5689 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_write_iac_sync()
5691 cp.num_iac = min_t(u8, hdev->num_iac, 2); in hci_write_iac_sync()
5706 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CURRENT_IAC_LAP, in hci_write_iac_sync()
5711 int hci_update_discoverable_sync(struct hci_dev *hdev) in hci_update_discoverable_sync() argument
5715 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_update_discoverable_sync()
5716 err = hci_write_iac_sync(hdev); in hci_update_discoverable_sync()
5720 err = hci_update_scan_sync(hdev); in hci_update_discoverable_sync()
5724 err = hci_update_class_sync(hdev); in hci_update_discoverable_sync()
5732 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in hci_update_discoverable_sync()
5733 err = hci_update_adv_data_sync(hdev, 0x00); in hci_update_discoverable_sync()
5740 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in hci_update_discoverable_sync()
5741 if (ext_adv_capable(hdev)) in hci_update_discoverable_sync()
5742 err = hci_start_ext_adv_sync(hdev, 0x00); in hci_update_discoverable_sync()
5744 err = hci_enable_advertising_sync(hdev); in hci_update_discoverable_sync()
5751 static int update_discoverable_sync(struct hci_dev *hdev, void *data) in update_discoverable_sync() argument
5753 return hci_update_discoverable_sync(hdev); in update_discoverable_sync()
5756 int hci_update_discoverable(struct hci_dev *hdev) in hci_update_discoverable() argument
5759 if (hdev_is_powered(hdev) && in hci_update_discoverable()
5760 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_update_discoverable()
5761 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in hci_update_discoverable()
5762 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in hci_update_discoverable()
5763 return hci_cmd_sync_queue(hdev, update_discoverable_sync, NULL, in hci_update_discoverable()
5769 int hci_update_connectable_sync(struct hci_dev *hdev) in hci_update_connectable_sync() argument
5773 err = hci_update_scan_sync(hdev); in hci_update_connectable_sync()
5781 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_connectable_sync()
5782 err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in hci_update_connectable_sync()
5785 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_update_connectable_sync()
5786 !list_empty(&hdev->adv_instances)) { in hci_update_connectable_sync()
5787 if (ext_adv_capable(hdev)) in hci_update_connectable_sync()
5788 err = hci_start_ext_adv_sync(hdev, in hci_update_connectable_sync()
5789 hdev->cur_adv_instance); in hci_update_connectable_sync()
5791 err = hci_enable_advertising_sync(hdev); in hci_update_connectable_sync()
5797 return hci_update_passive_scan_sync(hdev); in hci_update_connectable_sync()
5800 int hci_inquiry_sync(struct hci_dev *hdev, u8 length, u8 num_rsp) in hci_inquiry_sync() argument
5806 bt_dev_dbg(hdev, ""); in hci_inquiry_sync()
5808 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inquiry_sync()
5811 hci_dev_lock(hdev); in hci_inquiry_sync()
5812 hci_inquiry_cache_flush(hdev); in hci_inquiry_sync()
5813 hci_dev_unlock(hdev); in hci_inquiry_sync()
5817 if (hdev->discovery.limited) in hci_inquiry_sync()
5825 return __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY, in hci_inquiry_sync()
5829 static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) in hci_active_scan_sync() argument
5838 bt_dev_dbg(hdev, ""); in hci_active_scan_sync()
5844 err = hci_scan_disable_sync(hdev); in hci_active_scan_sync()
5846 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_active_scan_sync()
5850 cancel_interleave_scan(hdev); in hci_active_scan_sync()
5855 err = hci_pause_addr_resolution(hdev); in hci_active_scan_sync()
5863 err = hci_update_random_address_sync(hdev, true, scan_use_rpa(hdev), in hci_active_scan_sync()
5868 if (hci_is_adv_monitoring(hdev) || in hci_active_scan_sync()
5869 (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in hci_active_scan_sync()
5870 hdev->discovery.result_filtering)) { in hci_active_scan_sync()
5884 err = hci_start_scan_sync(hdev, LE_SCAN_ACTIVE, interval, in hci_active_scan_sync()
5885 hdev->le_scan_window_discovery, in hci_active_scan_sync()
5892 if (use_ll_privacy(hdev)) in hci_active_scan_sync()
5893 hci_resume_advertising_sync(hdev); in hci_active_scan_sync()
5896 hci_update_passive_scan_sync(hdev); in hci_active_scan_sync()
5900 static int hci_start_interleaved_discovery_sync(struct hci_dev *hdev) in hci_start_interleaved_discovery_sync() argument
5904 bt_dev_dbg(hdev, ""); in hci_start_interleaved_discovery_sync()
5906 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery * 2); in hci_start_interleaved_discovery_sync()
5910 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN, 0); in hci_start_interleaved_discovery_sync()
5913 int hci_start_discovery_sync(struct hci_dev *hdev) in hci_start_discovery_sync() argument
5918 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in hci_start_discovery_sync()
5920 switch (hdev->discovery.type) { in hci_start_discovery_sync()
5922 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN, 0); in hci_start_discovery_sync()
5933 &hdev->quirks)) { in hci_start_discovery_sync()
5939 err = hci_start_interleaved_discovery_sync(hdev); in hci_start_discovery_sync()
5943 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in hci_start_discovery_sync()
5944 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5948 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5957 bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout)); in hci_start_discovery_sync()
5959 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in hci_start_discovery_sync()
5964 static void hci_suspend_monitor_sync(struct hci_dev *hdev) in hci_suspend_monitor_sync() argument
5966 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_suspend_monitor_sync()
5968 msft_suspend_sync(hdev); in hci_suspend_monitor_sync()
5976 static int hci_pause_discovery_sync(struct hci_dev *hdev) in hci_pause_discovery_sync() argument
5978 int old_state = hdev->discovery.state; in hci_pause_discovery_sync()
5983 hdev->discovery_paused) in hci_pause_discovery_sync()
5986 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_pause_discovery_sync()
5987 err = hci_stop_discovery_sync(hdev); in hci_pause_discovery_sync()
5991 hdev->discovery_paused = true; in hci_pause_discovery_sync()
5992 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_pause_discovery_sync()
5997 static int hci_update_event_filter_sync(struct hci_dev *hdev) in hci_update_event_filter_sync() argument
6001 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_update_event_filter_sync()
6004 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_event_filter_sync()
6010 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_update_event_filter_sync()
6014 hci_clear_event_filter_sync(hdev); in hci_update_event_filter_sync()
6016 list_for_each_entry(b, &hdev->accept_list, list) { in hci_update_event_filter_sync()
6020 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_update_event_filter_sync()
6022 err = hci_set_event_filter_sync(hdev, HCI_FLT_CONN_SETUP, in hci_update_event_filter_sync()
6027 bt_dev_dbg(hdev, "Failed to set event filter for %pMR", in hci_update_event_filter_sync()
6034 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
6036 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
6042 static int hci_pause_scan_sync(struct hci_dev *hdev) in hci_pause_scan_sync() argument
6044 if (hdev->scanning_paused) in hci_pause_scan_sync()
6048 if (test_bit(HCI_PSCAN, &hdev->flags)) in hci_pause_scan_sync()
6049 hci_write_scan_enable_sync(hdev, SCAN_DISABLED); in hci_pause_scan_sync()
6051 hci_scan_disable_sync(hdev); in hci_pause_scan_sync()
6053 hdev->scanning_paused = true; in hci_pause_scan_sync()
6071 int hci_suspend_sync(struct hci_dev *hdev) in hci_suspend_sync() argument
6076 if (hdev->suspended) in hci_suspend_sync()
6080 hdev->suspended = true; in hci_suspend_sync()
6083 hci_pause_discovery_sync(hdev); in hci_suspend_sync()
6086 hci_pause_advertising_sync(hdev); in hci_suspend_sync()
6089 hci_suspend_monitor_sync(hdev); in hci_suspend_sync()
6092 hci_pause_scan_sync(hdev); in hci_suspend_sync()
6094 if (hci_conn_count(hdev)) { in hci_suspend_sync()
6096 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_suspend_sync()
6099 hdev->suspend_state = BT_RUNNING; in hci_suspend_sync()
6100 hci_resume_sync(hdev); in hci_suspend_sync()
6107 hci_set_event_mask_sync(hdev); in hci_suspend_sync()
6113 if (!hdev->wakeup || !hdev->wakeup(hdev)) { in hci_suspend_sync()
6114 hdev->suspend_state = BT_SUSPEND_DISCONNECT; in hci_suspend_sync()
6119 hdev->scanning_paused = false; in hci_suspend_sync()
6122 hci_update_event_filter_sync(hdev); in hci_suspend_sync()
6125 hci_update_passive_scan_sync(hdev); in hci_suspend_sync()
6128 hdev->scanning_paused = true; in hci_suspend_sync()
6130 hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; in hci_suspend_sync()
6136 static int hci_resume_discovery_sync(struct hci_dev *hdev) in hci_resume_discovery_sync() argument
6141 if (!hdev->discovery_paused) in hci_resume_discovery_sync()
6144 hdev->discovery_paused = false; in hci_resume_discovery_sync()
6146 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_resume_discovery_sync()
6148 err = hci_start_discovery_sync(hdev); in hci_resume_discovery_sync()
6150 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED : in hci_resume_discovery_sync()
6156 static void hci_resume_monitor_sync(struct hci_dev *hdev) in hci_resume_monitor_sync() argument
6158 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_resume_monitor_sync()
6160 msft_resume_sync(hdev); in hci_resume_monitor_sync()
6168 static int hci_resume_scan_sync(struct hci_dev *hdev) in hci_resume_scan_sync() argument
6170 if (!hdev->scanning_paused) in hci_resume_scan_sync()
6173 hdev->scanning_paused = false; in hci_resume_scan_sync()
6175 hci_update_scan_sync(hdev); in hci_resume_scan_sync()
6178 hci_update_passive_scan_sync(hdev); in hci_resume_scan_sync()
6191 int hci_resume_sync(struct hci_dev *hdev) in hci_resume_sync() argument
6194 if (!hdev->suspended) in hci_resume_sync()
6197 hdev->suspended = false; in hci_resume_sync()
6200 hci_set_event_mask_sync(hdev); in hci_resume_sync()
6203 hci_clear_event_filter_sync(hdev); in hci_resume_sync()
6206 hci_resume_scan_sync(hdev); in hci_resume_sync()
6209 hci_resume_monitor_sync(hdev); in hci_resume_sync()
6212 hci_resume_advertising_sync(hdev); in hci_resume_sync()
6215 hci_resume_discovery_sync(hdev); in hci_resume_sync()
6222 struct hci_dev *hdev = conn->hdev; in conn_use_rpa() local
6224 return hci_dev_test_flag(hdev, HCI_PRIVACY); in conn_use_rpa()
6227 static int hci_le_ext_directed_advertising_sync(struct hci_dev *hdev, in hci_le_ext_directed_advertising_sync() argument
6235 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_ext_directed_advertising_sync()
6243 err = hci_get_random_address(hdev, false, conn_use_rpa(conn), NULL, in hci_le_ext_directed_advertising_sync()
6251 cp.channel_map = hdev->le_adv_channel_map; in hci_le_ext_directed_advertising_sync()
6268 err = hci_remove_ext_adv_instance_sync(hdev, cp.handle, NULL); in hci_le_ext_directed_advertising_sync()
6272 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_le_ext_directed_advertising_sync()
6280 bacmp(&random_addr, &hdev->random_addr)) { in hci_le_ext_directed_advertising_sync()
6281 err = hci_set_adv_set_random_addr_sync(hdev, 0x00, in hci_le_ext_directed_advertising_sync()
6287 return hci_enable_ext_advertising_sync(hdev, 0x00); in hci_le_ext_directed_advertising_sync()
6290 static int hci_le_directed_advertising_sync(struct hci_dev *hdev, in hci_le_directed_advertising_sync() argument
6298 if (ext_adv_capable(hdev)) in hci_le_directed_advertising_sync()
6299 return hci_le_ext_directed_advertising_sync(hdev, conn); in hci_le_directed_advertising_sync()
6306 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_le_directed_advertising_sync()
6311 status = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_directed_advertising_sync()
6329 cp.channel_map = hdev->le_adv_channel_map; in hci_le_directed_advertising_sync()
6331 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_le_directed_advertising_sync()
6338 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_le_directed_advertising_sync()
6345 struct hci_dev *hdev = conn->hdev; in set_ext_conn_params() local
6349 p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in set_ext_conn_params()
6350 p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); in set_ext_conn_params()
6359 static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, in hci_le_ext_create_conn_sync() argument
6378 if (scan_1m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_1M || in hci_le_ext_create_conn_sync()
6387 if (scan_2m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_2M || in hci_le_ext_create_conn_sync()
6396 if (scan_coded(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_CODED || in hci_le_ext_create_conn_sync()
6404 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_EXT_CREATE_CONN, in hci_le_ext_create_conn_sync()
6410 static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) in hci_le_create_conn_sync() argument
6418 if (!hci_conn_valid(hdev, conn)) in hci_le_create_conn_sync()
6421 bt_dev_dbg(hdev, "conn %p", conn); in hci_le_create_conn_sync()
6431 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in hci_le_create_conn_sync()
6432 hdev->le_scan_type == LE_SCAN_ACTIVE && in hci_le_create_conn_sync()
6433 !hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) { in hci_le_create_conn_sync()
6439 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6441 err = hci_le_directed_advertising_sync(hdev, conn); in hci_le_create_conn_sync()
6446 if (!hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in hci_le_create_conn_sync()
6447 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6449 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_create_conn_sync()
6456 conn->le_conn_min_interval = hdev->le_conn_min_interval; in hci_le_create_conn_sync()
6457 conn->le_conn_max_interval = hdev->le_conn_max_interval; in hci_le_create_conn_sync()
6458 conn->le_conn_latency = hdev->le_conn_latency; in hci_le_create_conn_sync()
6459 conn->le_supv_timeout = hdev->le_supv_timeout; in hci_le_create_conn_sync()
6468 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_le_create_conn_sync()
6469 hci_scan_disable_sync(hdev); in hci_le_create_conn_sync()
6470 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED); in hci_le_create_conn_sync()
6476 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_create_conn_sync()
6481 if (use_ext_conn(hdev)) { in hci_le_create_conn_sync()
6482 err = hci_le_ext_create_conn_sync(hdev, conn, own_addr_type); in hci_le_create_conn_sync()
6488 cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in hci_le_create_conn_sync()
6489 cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); in hci_le_create_conn_sync()
6507 err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CONN, in hci_le_create_conn_sync()
6509 use_enhanced_conn_complete(hdev) ? in hci_le_create_conn_sync()
6516 hci_le_connect_cancel_sync(hdev, conn, 0x00); in hci_le_create_conn_sync()
6519 hci_resume_advertising_sync(hdev); in hci_le_create_conn_sync()
6523 int hci_le_create_cis_sync(struct hci_dev *hdev) in hci_le_create_cis_sync() argument
6553 hci_dev_lock(hdev); in hci_le_create_cis_sync()
6558 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6564 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6572 list_for_each_entry_rcu(link, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6588 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6608 hci_dev_unlock(hdev); in hci_le_create_cis_sync()
6614 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CIS, in hci_le_create_cis_sync()
6620 int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle) in hci_le_remove_cig_sync() argument
6627 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REMOVE_CIG, sizeof(cp), in hci_le_remove_cig_sync()
6631 int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle) in hci_le_big_terminate_sync() argument
6638 return __hci_cmd_sync_status(hdev, HCI_OP_LE_BIG_TERM_SYNC, in hci_le_big_terminate_sync()
6642 int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle) in hci_le_pa_terminate_sync() argument
6649 return __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_TERM_SYNC, in hci_le_pa_terminate_sync()
6653 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
6668 if (use_ll_privacy(hdev)) in hci_get_random_address()
6677 if (rpa_valid(hdev)) in hci_get_random_address()
6681 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
6683 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
6687 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
6710 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
6726 static int _update_adv_data_sync(struct hci_dev *hdev, void *data) in _update_adv_data_sync() argument
6730 return hci_update_adv_data_sync(hdev, instance); in _update_adv_data_sync()
6733 int hci_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_update_adv_data() argument
6735 return hci_cmd_sync_queue(hdev, _update_adv_data_sync, in hci_update_adv_data()
6739 static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data) in hci_acl_create_conn_sync() argument
6746 if (!hci_conn_valid(hdev, conn)) in hci_acl_create_conn_sync()
6757 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_acl_create_conn_sync()
6758 err = __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY_CANCEL, 0, in hci_acl_create_conn_sync()
6761 bt_dev_warn(hdev, "Failed to cancel inquiry %d", err); in hci_acl_create_conn_sync()
6770 conn->link_policy = hdev->link_policy; in hci_acl_create_conn_sync()
6776 ie = hci_inquiry_cache_lookup(hdev, &conn->dst); in hci_acl_create_conn_sync()
6789 if (lmp_rswitch_capable(hdev) && !(hdev->link_mode & HCI_LM_MASTER)) in hci_acl_create_conn_sync()
6794 return __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN, in hci_acl_create_conn_sync()
6800 int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_connect_acl_sync() argument
6802 return hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn, in hci_connect_acl_sync()
6806 static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) in create_le_conn_complete() argument
6810 bt_dev_dbg(hdev, "err %d", err); in create_le_conn_complete()
6815 hci_dev_lock(hdev); in create_le_conn_complete()
6817 if (!hci_conn_valid(hdev, conn)) in create_le_conn_complete()
6826 if (conn != hci_lookup_le_connect(hdev)) in create_le_conn_complete()
6834 hci_dev_unlock(hdev); in create_le_conn_complete()
6837 int hci_connect_le_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_connect_le_sync() argument
6839 return hci_cmd_sync_queue_once(hdev, hci_le_create_conn_sync, conn, in hci_connect_le_sync()
6843 int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_cancel_connect_sync() argument
6850 return !hci_cmd_sync_dequeue_once(hdev, in hci_cancel_connect_sync()
6854 return !hci_cmd_sync_dequeue_once(hdev, hci_le_create_conn_sync, in hci_cancel_connect_sync()
6861 int hci_le_conn_update_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_le_conn_update_sync() argument
6875 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CONN_UPDATE, in hci_le_conn_update_sync()