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 (bacmp(&hdev->random_addr, BDADDR_ANY) && in hci_set_random_addr_sync()
1045 (hci_dev_test_flag(hdev, HCI_LE_ADV) || in hci_set_random_addr_sync()
1046 hci_lookup_le_connect(hdev))) { in hci_set_random_addr_sync()
1047 bt_dev_dbg(hdev, "Deferring random address update"); in hci_set_random_addr_sync()
1048 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_set_random_addr_sync()
1052 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RANDOM_ADDR, in hci_set_random_addr_sync()
1056 int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy, in hci_update_random_address_sync() argument
1069 if (ll_privacy_capable(hdev)) in hci_update_random_address_sync()
1075 if (rpa_valid(hdev)) in hci_update_random_address_sync()
1078 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address_sync()
1080 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address_sync()
1084 err = hci_set_random_addr_sync(hdev, &hdev->rpa); in hci_update_random_address_sync()
1109 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address_sync()
1115 return hci_set_random_addr_sync(hdev, &nrpa); in hci_update_random_address_sync()
1127 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address_sync()
1128 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address_sync()
1129 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address_sync()
1130 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address_sync()
1132 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address_sync()
1133 return hci_set_random_addr_sync(hdev, in hci_update_random_address_sync()
1134 &hdev->static_addr); in hci_update_random_address_sync()
1146 static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_disable_ext_adv_instance_sync() argument
1156 adv = hci_find_adv_instance(hdev, instance); in hci_disable_ext_adv_instance_sync()
1178 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_disable_ext_adv_instance_sync()
1182 static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, in hci_set_adv_set_random_addr_sync() argument
1194 err = hci_set_random_addr_sync(hdev, random_addr); in hci_set_adv_set_random_addr_sync()
1204 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, in hci_set_adv_set_random_addr_sync()
1208 int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_setup_ext_adv_instance_sync() argument
1220 adv = hci_find_adv_instance(hdev, instance); in hci_setup_ext_adv_instance_sync()
1232 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_setup_ext_adv_instance_sync()
1237 flags = hci_adv_instance_flags(hdev, instance); in hci_setup_ext_adv_instance_sync()
1243 mgmt_get_connectable(hdev); in hci_setup_ext_adv_instance_sync()
1245 if (!is_advertising_allowed(hdev, connectable)) in hci_setup_ext_adv_instance_sync()
1252 err = hci_get_random_address(hdev, !connectable, in hci_setup_ext_adv_instance_sync()
1253 adv_use_rpa(hdev, flags), adv, in hci_setup_ext_adv_instance_sync()
1265 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1266 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1277 } else if (hci_adv_instance_is_scannable(hdev, instance) || in hci_setup_ext_adv_instance_sync()
1298 hci_copy_identity_address(hdev, &cp.peer_addr, in hci_setup_ext_adv_instance_sync()
1302 cp.channel_map = hdev->le_adv_channel_map; in hci_setup_ext_adv_instance_sync()
1317 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_setup_ext_adv_instance_sync()
1330 if (!bacmp(&random_addr, &hdev->random_addr)) in hci_setup_ext_adv_instance_sync()
1334 return hci_set_adv_set_random_addr_sync(hdev, instance, in hci_setup_ext_adv_instance_sync()
1341 static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_scan_rsp_data_sync() argument
1350 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_scan_rsp_data_sync()
1355 len = eir_create_scan_rsp(hdev, instance, pdu->data); in hci_set_ext_scan_rsp_data_sync()
1362 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA, in hci_set_ext_scan_rsp_data_sync()
1371 memcpy(hdev->scan_rsp_data, pdu->data, len); in hci_set_ext_scan_rsp_data_sync()
1372 hdev->scan_rsp_data_len = len; in hci_set_ext_scan_rsp_data_sync()
1378 static int __hci_set_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in __hci_set_scan_rsp_data_sync() argument
1385 len = eir_create_scan_rsp(hdev, instance, cp.data); in __hci_set_scan_rsp_data_sync()
1387 if (hdev->scan_rsp_data_len == len && in __hci_set_scan_rsp_data_sync()
1388 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_set_scan_rsp_data_sync()
1391 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_set_scan_rsp_data_sync()
1392 hdev->scan_rsp_data_len = len; in __hci_set_scan_rsp_data_sync()
1396 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_RSP_DATA, in __hci_set_scan_rsp_data_sync()
1400 int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_scan_rsp_data_sync() argument
1402 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_rsp_data_sync()
1405 if (ext_adv_capable(hdev)) in hci_update_scan_rsp_data_sync()
1406 return hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1408 return __hci_set_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1411 int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_ext_advertising_sync() argument
1419 adv = hci_find_adv_instance(hdev, instance); in hci_enable_ext_advertising_sync()
1451 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_enable_ext_advertising_sync()
1457 int hci_start_ext_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_ext_adv_sync() argument
1461 err = hci_setup_ext_adv_instance_sync(hdev, instance); in hci_start_ext_adv_sync()
1465 err = hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_start_ext_adv_sync()
1469 return hci_enable_ext_advertising_sync(hdev, instance); in hci_start_ext_adv_sync()
1472 int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_disable_per_advertising_sync() argument
1478 adv = hci_find_adv_instance(hdev, instance); in hci_disable_per_advertising_sync()
1487 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_disable_per_advertising_sync()
1491 static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, in hci_set_per_adv_params_sync() argument
1509 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS, in hci_set_per_adv_params_sync()
1513 static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_per_adv_data_sync() argument
1521 adv = hci_find_adv_instance(hdev, instance); in hci_set_per_adv_data_sync()
1526 len = eir_create_per_adv_data(hdev, instance, pdu->data); in hci_set_per_adv_data_sync()
1532 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_DATA, in hci_set_per_adv_data_sync()
1537 static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_per_advertising_sync() argument
1543 adv = hci_find_adv_instance(hdev, instance); in hci_enable_per_advertising_sync()
1552 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_enable_per_advertising_sync()
1559 static int hci_adv_bcast_annoucement(struct hci_dev *hdev, struct adv_info *adv) in hci_adv_bcast_annoucement() argument
1589 hci_set_adv_instance_data(hdev, adv->instance, sizeof(ad), ad, 0, NULL); in hci_adv_bcast_annoucement()
1591 return hci_update_adv_data_sync(hdev, adv->instance); in hci_adv_bcast_annoucement()
1594 int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len, in hci_start_per_adv_sync() argument
1602 hci_disable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1605 adv = hci_find_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1608 adv = hci_add_per_instance(hdev, instance, flags, in hci_start_per_adv_sync()
1620 err = hci_start_ext_adv_sync(hdev, instance); in hci_start_per_adv_sync()
1624 err = hci_adv_bcast_annoucement(hdev, adv); in hci_start_per_adv_sync()
1628 err = hci_set_per_adv_params_sync(hdev, instance, min_interval, in hci_start_per_adv_sync()
1633 err = hci_set_per_adv_data_sync(hdev, instance); in hci_start_per_adv_sync()
1637 err = hci_enable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1645 hci_remove_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1650 static int hci_start_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_adv_sync() argument
1654 if (ext_adv_capable(hdev)) in hci_start_adv_sync()
1655 return hci_start_ext_adv_sync(hdev, instance); in hci_start_adv_sync()
1657 err = hci_update_adv_data_sync(hdev, instance); in hci_start_adv_sync()
1661 err = hci_update_scan_rsp_data_sync(hdev, instance); in hci_start_adv_sync()
1665 return hci_enable_advertising_sync(hdev); in hci_start_adv_sync()
1668 int hci_enable_advertising_sync(struct hci_dev *hdev) in hci_enable_advertising_sync() argument
1678 if (ext_adv_capable(hdev)) in hci_enable_advertising_sync()
1679 return hci_enable_ext_advertising_sync(hdev, in hci_enable_advertising_sync()
1680 hdev->cur_adv_instance); in hci_enable_advertising_sync()
1682 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1683 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1689 mgmt_get_connectable(hdev); in hci_enable_advertising_sync()
1691 if (!is_advertising_allowed(hdev, connectable)) in hci_enable_advertising_sync()
1694 status = hci_disable_advertising_sync(hdev); in hci_enable_advertising_sync()
1703 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_enable_advertising_sync()
1709 status = hci_update_random_address_sync(hdev, !connectable, in hci_enable_advertising_sync()
1710 adv_use_rpa(hdev, flags), in hci_enable_advertising_sync()
1721 adv_min_interval = hdev->le_adv_min_interval; in hci_enable_advertising_sync()
1722 adv_max_interval = hdev->le_adv_max_interval; in hci_enable_advertising_sync()
1728 if (hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance)) in hci_enable_advertising_sync()
1733 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in hci_enable_advertising_sync()
1734 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_enable_advertising_sync()
1743 cp.channel_map = hdev->le_adv_channel_map; in hci_enable_advertising_sync()
1745 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_enable_advertising_sync()
1750 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_enable_advertising_sync()
1754 static int enable_advertising_sync(struct hci_dev *hdev, void *data) in enable_advertising_sync() argument
1756 return hci_enable_advertising_sync(hdev); in enable_advertising_sync()
1759 int hci_enable_advertising(struct hci_dev *hdev) in hci_enable_advertising() argument
1761 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_enable_advertising()
1762 list_empty(&hdev->adv_instances)) in hci_enable_advertising()
1765 return hci_cmd_sync_queue(hdev, enable_advertising_sync, NULL, NULL); in hci_enable_advertising()
1768 int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_remove_ext_adv_instance_sync() argument
1773 if (!ext_adv_capable(hdev)) in hci_remove_ext_adv_instance_sync()
1776 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_remove_ext_adv_instance_sync()
1781 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in hci_remove_ext_adv_instance_sync()
1784 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, in hci_remove_ext_adv_instance_sync()
1789 int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) in hci_le_terminate_big_sync() argument
1797 return __hci_cmd_sync_status(hdev, HCI_OP_LE_TERM_BIG, in hci_le_terminate_big_sync()
1801 static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_adv_data_sync() argument
1810 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_adv_data_sync()
1815 len = eir_create_adv_data(hdev, instance, pdu->data); in hci_set_ext_adv_data_sync()
1822 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_DATA, in hci_set_ext_adv_data_sync()
1832 memcpy(hdev->adv_data, pdu->data, len); in hci_set_ext_adv_data_sync()
1833 hdev->adv_data_len = len; in hci_set_ext_adv_data_sync()
1839 static int hci_set_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_adv_data_sync() argument
1846 len = eir_create_adv_data(hdev, instance, cp.data); in hci_set_adv_data_sync()
1849 if (hdev->adv_data_len == len && in hci_set_adv_data_sync()
1850 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_set_adv_data_sync()
1853 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_set_adv_data_sync()
1854 hdev->adv_data_len = len; in hci_set_adv_data_sync()
1858 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_DATA, in hci_set_adv_data_sync()
1862 int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_adv_data_sync() argument
1864 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_adv_data_sync()
1867 if (ext_adv_capable(hdev)) in hci_update_adv_data_sync()
1868 return hci_set_ext_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1870 return hci_set_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1873 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_schedule_adv_instance_sync() argument
1879 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) && !ext_adv_capable(hdev)) in hci_schedule_adv_instance_sync()
1882 if (hdev->adv_instance_timeout) in hci_schedule_adv_instance_sync()
1885 adv = hci_find_adv_instance(hdev, instance); in hci_schedule_adv_instance_sync()
1909 if (!ext_adv_capable(hdev)) { in hci_schedule_adv_instance_sync()
1910 hdev->adv_instance_timeout = timeout; in hci_schedule_adv_instance_sync()
1911 queue_delayed_work(hdev->req_workqueue, in hci_schedule_adv_instance_sync()
1912 &hdev->adv_instance_expire, in hci_schedule_adv_instance_sync()
1920 if (!force && hdev->cur_adv_instance == instance && in hci_schedule_adv_instance_sync()
1921 hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_schedule_adv_instance_sync()
1924 hdev->cur_adv_instance = instance; in hci_schedule_adv_instance_sync()
1926 return hci_start_adv_sync(hdev, instance); in hci_schedule_adv_instance_sync()
1929 static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk) in hci_clear_adv_sets_sync() argument
1933 if (!ext_adv_capable(hdev)) in hci_clear_adv_sets_sync()
1937 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_clear_adv_sets_sync()
1941 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CLEAR_ADV_SETS, in hci_clear_adv_sets_sync()
1945 static int hci_clear_adv_sync(struct hci_dev *hdev, struct sock *sk, bool force) in hci_clear_adv_sync() argument
1950 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1952 err = hci_clear_adv_sets_sync(hdev, sk); in hci_clear_adv_sync()
1953 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1959 hci_dev_lock(hdev); in hci_clear_adv_sync()
1962 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in hci_clear_adv_sync()
1969 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_sync()
1971 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_sync()
1974 hci_dev_unlock(hdev); in hci_clear_adv_sync()
1979 static int hci_remove_adv_sync(struct hci_dev *hdev, u8 instance, in hci_remove_adv_sync() argument
1985 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1986 err = hci_remove_ext_adv_instance_sync(hdev, instance, sk); in hci_remove_adv_sync()
1987 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1993 hci_dev_lock(hdev); in hci_remove_adv_sync()
1995 err = hci_remove_adv_instance(hdev, instance); in hci_remove_adv_sync()
1997 mgmt_advertising_removed(sk, hdev, instance); in hci_remove_adv_sync()
1999 hci_dev_unlock(hdev); in hci_remove_adv_sync()
2015 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, in hci_remove_advertising_sync() argument
2022 if (!instance || hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
2023 cancel_adv_timeout(hdev); in hci_remove_advertising_sync()
2029 if (hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
2030 next = hci_get_next_instance(hdev, instance); in hci_remove_advertising_sync()
2033 err = hci_clear_adv_sync(hdev, sk, force); in hci_remove_advertising_sync()
2037 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_remove_advertising_sync()
2044 err = hci_remove_adv_sync(hdev, instance, sk); in hci_remove_advertising_sync()
2050 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_remove_advertising_sync()
2053 if (next && !ext_adv_capable(hdev)) in hci_remove_advertising_sync()
2054 hci_schedule_adv_instance_sync(hdev, next->instance, false); in hci_remove_advertising_sync()
2059 int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle) in hci_read_rssi_sync() argument
2064 return __hci_cmd_sync_status(hdev, HCI_OP_READ_RSSI, in hci_read_rssi_sync()
2068 int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp) in hci_read_clock_sync() argument
2070 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLOCK, in hci_read_clock_sync()
2074 int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type) in hci_read_tx_power_sync() argument
2080 return __hci_cmd_sync_status(hdev, HCI_OP_READ_TX_POWER, in hci_read_tx_power_sync()
2084 int hci_disable_advertising_sync(struct hci_dev *hdev) in hci_disable_advertising_sync() argument
2090 if (!hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_disable_advertising_sync()
2093 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
2094 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_disable_advertising_sync()
2095 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
2098 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_disable_advertising_sync()
2102 static int hci_le_set_ext_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_ext_scan_enable_sync() argument
2110 if (hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_ext_scan_enable_sync()
2115 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE, in hci_le_set_ext_scan_enable_sync()
2119 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_scan_enable_sync() argument
2124 if (use_ext_scan(hdev)) in hci_le_set_scan_enable_sync()
2125 return hci_le_set_ext_scan_enable_sync(hdev, val, filter_dup); in hci_le_set_scan_enable_sync()
2130 if (val && hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_scan_enable_sync()
2135 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_ENABLE, in hci_le_set_scan_enable_sync()
2139 static int hci_le_set_addr_resolution_enable_sync(struct hci_dev *hdev, u8 val) in hci_le_set_addr_resolution_enable_sync() argument
2141 if (!ll_privacy_capable(hdev)) in hci_le_set_addr_resolution_enable_sync()
2145 if (val == hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_le_set_addr_resolution_enable_sync()
2148 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, in hci_le_set_addr_resolution_enable_sync()
2152 static int hci_scan_disable_sync(struct hci_dev *hdev) in hci_scan_disable_sync() argument
2157 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_scan_disable_sync()
2160 if (hdev->scanning_paused) { in hci_scan_disable_sync()
2161 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_scan_disable_sync()
2165 err = hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_scan_disable_sync()
2167 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_scan_disable_sync()
2174 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
2176 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
2179 static void hci_start_interleave_scan(struct hci_dev *hdev) in hci_start_interleave_scan() argument
2181 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_start_interleave_scan()
2182 queue_delayed_work(hdev->req_workqueue, in hci_start_interleave_scan()
2183 &hdev->interleave_scan, 0); in hci_start_interleave_scan()
2186 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
2188 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
2190 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
2192 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
2198 static bool hci_update_interleaved_scan_sync(struct hci_dev *hdev) in hci_update_interleaved_scan_sync() argument
2207 bool use_interleaving = hci_is_adv_monitoring(hdev) && in hci_update_interleaved_scan_sync()
2208 !(list_empty(&hdev->pend_le_conns) && in hci_update_interleaved_scan_sync()
2209 list_empty(&hdev->pend_le_reports)) && in hci_update_interleaved_scan_sync()
2210 hci_get_adv_monitor_offload_ext(hdev) == in hci_update_interleaved_scan_sync()
2212 bool is_interleaving = is_interleave_scanning(hdev); in hci_update_interleaved_scan_sync()
2215 hci_start_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2216 bt_dev_dbg(hdev, "starting interleave scan"); in hci_update_interleaved_scan_sync()
2221 cancel_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2227 static int hci_le_del_resolve_list_sync(struct hci_dev *hdev, in hci_le_del_resolve_list_sync() argument
2233 if (!ll_privacy_capable(hdev)) in hci_le_del_resolve_list_sync()
2237 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, in hci_le_del_resolve_list_sync()
2245 return __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST, in hci_le_del_resolve_list_sync()
2249 static int hci_le_del_accept_list_sync(struct hci_dev *hdev, in hci_le_del_accept_list_sync() argument
2256 if (!hci_bdaddr_list_lookup(&hdev->le_accept_list, bdaddr, bdaddr_type)) in hci_le_del_accept_list_sync()
2265 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_del_accept_list_sync()
2267 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST, in hci_le_del_accept_list_sync()
2270 bt_dev_err(hdev, "Unable to remove from allow list: %d", err); in hci_le_del_accept_list_sync()
2274 bt_dev_dbg(hdev, "Remove %pMR (0x%x) from allow list", &cp.bdaddr, in hci_le_del_accept_list_sync()
2290 static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, in hci_le_add_resolve_list_sync() argument
2298 if (!ll_privacy_capable(hdev)) in hci_le_add_resolve_list_sync()
2305 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2308 hci_copy_identity_address(hdev, &cp.bdaddr, &cp.bdaddr_type); in hci_le_add_resolve_list_sync()
2309 memcpy(cp.peer_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2314 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2319 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, in hci_le_add_resolve_list_sync()
2333 p = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_le_add_resolve_list_sync()
2336 p = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_le_add_resolve_list_sync()
2343 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2344 memcpy(cp.local_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2348 return __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST, in hci_le_add_resolve_list_sync()
2353 static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev, in hci_le_set_privacy_mode_sync() argument
2359 if (!ll_privacy_capable(hdev) || in hci_le_set_privacy_mode_sync()
2374 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_set_privacy_mode_sync()
2385 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PRIVACY_MODE, in hci_le_set_privacy_mode_sync()
2393 static int hci_le_add_accept_list_sync(struct hci_dev *hdev, in hci_le_add_accept_list_sync() argument
2401 if (hdev->suspended && in hci_le_add_accept_list_sync()
2403 hci_le_del_accept_list_sync(hdev, &params->addr, in hci_le_add_accept_list_sync()
2409 if (*num_entries >= hdev->le_accept_list_size) in hci_le_add_accept_list_sync()
2416 err = hci_le_add_resolve_list_sync(hdev, params); in hci_le_add_accept_list_sync()
2418 bt_dev_err(hdev, "Unable to add to resolve list: %d", err); in hci_le_add_accept_list_sync()
2423 err = hci_le_set_privacy_mode_sync(hdev, params); in hci_le_add_accept_list_sync()
2425 bt_dev_err(hdev, "Unable to set privacy mode: %d", err); in hci_le_add_accept_list_sync()
2430 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in hci_le_add_accept_list_sync()
2438 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST, in hci_le_add_accept_list_sync()
2441 bt_dev_err(hdev, "Unable to add to allow list: %d", err); in hci_le_add_accept_list_sync()
2443 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_add_accept_list_sync()
2447 bt_dev_dbg(hdev, "Add %pMR (0x%x) to allow list", &cp.bdaddr, in hci_le_add_accept_list_sync()
2454 static int hci_pause_advertising_sync(struct hci_dev *hdev) in hci_pause_advertising_sync() argument
2460 if (hdev->advertising_paused) in hci_pause_advertising_sync()
2463 bt_dev_dbg(hdev, "Pausing directed advertising"); in hci_pause_advertising_sync()
2466 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_pause_advertising_sync()
2473 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_pause_advertising_sync()
2474 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_pause_advertising_sync()
2475 hdev->discov_timeout = 0; in hci_pause_advertising_sync()
2478 bt_dev_dbg(hdev, "Pausing advertising instances"); in hci_pause_advertising_sync()
2483 err = hci_disable_advertising_sync(hdev); in hci_pause_advertising_sync()
2488 if (!ext_adv_capable(hdev)) in hci_pause_advertising_sync()
2489 cancel_adv_timeout(hdev); in hci_pause_advertising_sync()
2491 hdev->advertising_paused = true; in hci_pause_advertising_sync()
2492 hdev->advertising_old_state = old_state; in hci_pause_advertising_sync()
2498 static int hci_resume_advertising_sync(struct hci_dev *hdev) in hci_resume_advertising_sync() argument
2504 if (!hdev->advertising_paused) in hci_resume_advertising_sync()
2508 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2509 if (hdev->advertising_old_state) { in hci_resume_advertising_sync()
2510 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_resume_advertising_sync()
2511 hdev->advertising_old_state = 0; in hci_resume_advertising_sync()
2514 bt_dev_dbg(hdev, "Resuming advertising instances"); in hci_resume_advertising_sync()
2516 if (ext_adv_capable(hdev)) { in hci_resume_advertising_sync()
2518 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) { in hci_resume_advertising_sync()
2519 err = hci_enable_ext_advertising_sync(hdev, in hci_resume_advertising_sync()
2525 hci_remove_ext_adv_instance_sync(hdev, adv->instance, in hci_resume_advertising_sync()
2532 err = hci_schedule_adv_instance_sync(hdev, in hci_resume_advertising_sync()
2533 hdev->cur_adv_instance, in hci_resume_advertising_sync()
2537 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2542 static int hci_pause_addr_resolution(struct hci_dev *hdev) in hci_pause_addr_resolution() argument
2546 if (!ll_privacy_capable(hdev)) in hci_pause_addr_resolution()
2549 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_pause_addr_resolution()
2555 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) || in hci_pause_addr_resolution()
2556 hci_lookup_le_connect(hdev)) { in hci_pause_addr_resolution()
2557 bt_dev_err(hdev, "Command not allowed when scan/LE connect"); in hci_pause_addr_resolution()
2562 err = hci_pause_advertising_sync(hdev); in hci_pause_addr_resolution()
2564 bt_dev_err(hdev, "Pause advertising failed: %d", err); in hci_pause_addr_resolution()
2568 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_pause_addr_resolution()
2570 bt_dev_err(hdev, "Unable to disable Address Resolution: %d", in hci_pause_addr_resolution()
2574 if (!err && scan_use_rpa(hdev)) in hci_pause_addr_resolution()
2577 hci_resume_advertising_sync(hdev); in hci_pause_addr_resolution()
2581 struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, in hci_read_local_oob_data_sync() argument
2587 return __hci_cmd_sync_sk(hdev, opcode, 0, NULL, 0, HCI_CMD_TIMEOUT, sk); in hci_read_local_oob_data_sync()
2637 static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) in hci_le_clear_accept_list_sync() argument
2639 if (!(hdev->commands[26] & 0x80)) in hci_le_clear_accept_list_sync()
2642 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_ACCEPT_LIST, 0, NULL, in hci_le_clear_accept_list_sync()
2663 static u8 hci_update_accept_list_sync(struct hci_dev *hdev) in hci_update_accept_list_sync() argument
2676 if (ll_privacy_capable(hdev)) { in hci_update_accept_list_sync()
2677 err = hci_pause_advertising_sync(hdev); in hci_update_accept_list_sync()
2679 bt_dev_err(hdev, "pause advertising failed: %d", err); in hci_update_accept_list_sync()
2688 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_update_accept_list_sync()
2690 bt_dev_err(hdev, "Unable to disable LL privacy: %d", err); in hci_update_accept_list_sync()
2695 if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_update_accept_list_sync()
2698 conn = hci_conn_hash_lookup_create_pa_sync(hdev); in hci_update_accept_list_sync()
2710 hci_le_clear_accept_list_sync(hdev); in hci_update_accept_list_sync()
2713 err = hci_le_add_accept_list_sync(hdev, &pa, in hci_update_accept_list_sync()
2725 list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { in hci_update_accept_list_sync()
2726 if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) in hci_update_accept_list_sync()
2730 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_update_accept_list_sync()
2733 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_update_accept_list_sync()
2741 hci_le_del_accept_list_sync(hdev, &b->bdaddr, in hci_update_accept_list_sync()
2763 params = conn_params_copy(&hdev->pend_le_conns, &n); in hci_update_accept_list_sync()
2770 err = hci_le_add_accept_list_sync(hdev, &params[i], in hci_update_accept_list_sync()
2785 params = conn_params_copy(&hdev->pend_le_reports, &n); in hci_update_accept_list_sync()
2792 err = hci_le_add_accept_list_sync(hdev, &params[i], in hci_update_accept_list_sync()
2807 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in hci_update_accept_list_sync()
2808 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE && in hci_update_accept_list_sync()
2809 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in hci_update_accept_list_sync()
2816 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_update_accept_list_sync()
2818 bt_dev_err(hdev, "Unable to enable LL privacy: %d", err); in hci_update_accept_list_sync()
2821 if (ll_privacy_capable(hdev)) in hci_update_accept_list_sync()
2822 hci_resume_advertising_sync(hdev); in hci_update_accept_list_sync()
2836 static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_ext_scan_param_sync() argument
2856 if (hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_le_set_ext_scan_param_sync()
2859 sent = hci_sent_cmd_data(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST); in hci_le_set_ext_scan_param_sync()
2863 conn = hci_conn_hash_lookup_ba(hdev, ISO_LINK, in hci_le_set_ext_scan_param_sync()
2893 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_le_set_ext_scan_param_sync()
2900 if (scan_coded(hdev)) { in hci_le_set_ext_scan_param_sync()
2911 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS, in hci_le_set_ext_scan_param_sync()
2916 static int hci_le_set_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_scan_param_sync() argument
2922 if (use_ext_scan(hdev)) in hci_le_set_scan_param_sync()
2923 return hci_le_set_ext_scan_param_sync(hdev, type, interval, in hci_le_set_scan_param_sync()
2934 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_PARAM, in hci_le_set_scan_param_sync()
2938 static int hci_start_scan_sync(struct hci_dev *hdev, u8 type, u16 interval, in hci_start_scan_sync() argument
2944 if (hdev->scanning_paused) { in hci_start_scan_sync()
2945 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_start_scan_sync()
2949 err = hci_le_set_scan_param_sync(hdev, type, interval, window, in hci_start_scan_sync()
2954 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, filter_dup); in hci_start_scan_sync()
2957 static int hci_passive_scan_sync(struct hci_dev *hdev) in hci_passive_scan_sync() argument
2965 if (hdev->scanning_paused) { in hci_passive_scan_sync()
2966 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_passive_scan_sync()
2970 err = hci_scan_disable_sync(hdev); in hci_passive_scan_sync()
2972 bt_dev_err(hdev, "disable scanning failed: %d", err); in hci_passive_scan_sync()
2982 if (hci_update_random_address_sync(hdev, false, scan_use_rpa(hdev), in hci_passive_scan_sync()
2986 if (hdev->enable_advmon_interleave_scan && in hci_passive_scan_sync()
2987 hci_update_interleaved_scan_sync(hdev)) in hci_passive_scan_sync()
2990 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_passive_scan_sync()
2996 filter_policy = hci_update_accept_list_sync(hdev); in hci_passive_scan_sync()
3002 if (hdev->suspended && !filter_policy) { in hci_passive_scan_sync()
3006 if (list_empty(&hdev->le_accept_list)) in hci_passive_scan_sync()
3028 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_passive_scan_sync()
3029 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_passive_scan_sync()
3032 if (hdev->suspended) { in hci_passive_scan_sync()
3033 window = hdev->le_scan_window_suspend; in hci_passive_scan_sync()
3034 interval = hdev->le_scan_int_suspend; in hci_passive_scan_sync()
3035 } else if (hci_is_le_conn_scanning(hdev)) { in hci_passive_scan_sync()
3036 window = hdev->le_scan_window_connect; in hci_passive_scan_sync()
3037 interval = hdev->le_scan_int_connect; in hci_passive_scan_sync()
3038 } else if (hci_is_adv_monitoring(hdev)) { in hci_passive_scan_sync()
3039 window = hdev->le_scan_window_adv_monitor; in hci_passive_scan_sync()
3040 interval = hdev->le_scan_int_adv_monitor; in hci_passive_scan_sync()
3056 window = hdev->le_scan_window; in hci_passive_scan_sync()
3057 interval = hdev->le_scan_interval; in hci_passive_scan_sync()
3061 if (hci_dev_test_flag(hdev, HCI_MESH)) { in hci_passive_scan_sync()
3066 bt_dev_dbg(hdev, "LE passive scan with acceptlist = %d", filter_policy); in hci_passive_scan_sync()
3068 return hci_start_scan_sync(hdev, LE_SCAN_PASSIVE, interval, window, in hci_passive_scan_sync()
3087 int hci_update_passive_scan_sync(struct hci_dev *hdev) in hci_update_passive_scan_sync() argument
3091 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan_sync()
3092 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan_sync()
3093 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan_sync()
3094 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan_sync()
3095 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan_sync()
3096 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan_sync()
3100 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_sync()
3104 if (hdev->discovery.state != DISCOVERY_STOPPED) in hci_update_passive_scan_sync()
3114 hci_discovery_filter_clear(hdev); in hci_update_passive_scan_sync()
3116 bt_dev_dbg(hdev, "ADV monitoring is %s", in hci_update_passive_scan_sync()
3117 hci_is_adv_monitoring(hdev) ? "on" : "off"); in hci_update_passive_scan_sync()
3119 if (!hci_dev_test_flag(hdev, HCI_MESH) && in hci_update_passive_scan_sync()
3120 list_empty(&hdev->pend_le_conns) && in hci_update_passive_scan_sync()
3121 list_empty(&hdev->pend_le_reports) && in hci_update_passive_scan_sync()
3122 !hci_is_adv_monitoring(hdev) && in hci_update_passive_scan_sync()
3123 !hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_update_passive_scan_sync()
3129 bt_dev_dbg(hdev, "stopping background scanning"); in hci_update_passive_scan_sync()
3131 err = hci_scan_disable_sync(hdev); in hci_update_passive_scan_sync()
3133 bt_dev_err(hdev, "stop background scanning failed: %d", in hci_update_passive_scan_sync()
3144 if (hci_lookup_le_connect(hdev)) in hci_update_passive_scan_sync()
3147 bt_dev_dbg(hdev, "start background scanning"); in hci_update_passive_scan_sync()
3149 err = hci_passive_scan_sync(hdev); in hci_update_passive_scan_sync()
3151 bt_dev_err(hdev, "start background scanning failed: %d", in hci_update_passive_scan_sync()
3158 static int update_scan_sync(struct hci_dev *hdev, void *data) in update_scan_sync() argument
3160 return hci_update_scan_sync(hdev); in update_scan_sync()
3163 int hci_update_scan(struct hci_dev *hdev) in hci_update_scan() argument
3165 return hci_cmd_sync_queue(hdev, update_scan_sync, NULL, NULL); in hci_update_scan()
3168 static int update_passive_scan_sync(struct hci_dev *hdev, void *data) in update_passive_scan_sync() argument
3170 return hci_update_passive_scan_sync(hdev); in update_passive_scan_sync()
3173 int hci_update_passive_scan(struct hci_dev *hdev) in hci_update_passive_scan() argument
3176 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan()
3177 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan()
3178 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan()
3179 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan()
3180 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan()
3181 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan()
3184 return hci_cmd_sync_queue_once(hdev, update_passive_scan_sync, NULL, in hci_update_passive_scan()
3188 int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val) in hci_write_sc_support_sync() argument
3192 if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev)) in hci_write_sc_support_sync()
3195 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_sync()
3200 hdev->features[1][0] |= LMP_HOST_SC; in hci_write_sc_support_sync()
3201 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
3203 hdev->features[1][0] &= ~LMP_HOST_SC; in hci_write_sc_support_sync()
3204 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
3211 int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) in hci_write_ssp_mode_sync() argument
3215 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_ssp_mode_sync()
3216 lmp_host_ssp_capable(hdev)) in hci_write_ssp_mode_sync()
3219 if (!mode && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) { in hci_write_ssp_mode_sync()
3220 __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in hci_write_ssp_mode_sync()
3224 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_sync()
3229 return hci_write_sc_support_sync(hdev, 0x01); in hci_write_ssp_mode_sync()
3232 int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul) in hci_write_le_host_supported_sync() argument
3236 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in hci_write_le_host_supported_sync()
3237 !lmp_bredr_capable(hdev)) in hci_write_le_host_supported_sync()
3243 if (le == lmp_host_le_capable(hdev) && in hci_write_le_host_supported_sync()
3244 simul == lmp_host_le_br_capable(hdev)) in hci_write_le_host_supported_sync()
3252 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_write_le_host_supported_sync()
3256 static int hci_powered_update_adv_sync(struct hci_dev *hdev) in hci_powered_update_adv_sync() argument
3261 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_powered_update_adv_sync()
3269 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) { in hci_powered_update_adv_sync()
3270 hci_le_add_resolve_list_sync(hdev, NULL); in hci_powered_update_adv_sync()
3271 hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_powered_update_adv_sync()
3278 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_powered_update_adv_sync()
3279 list_empty(&hdev->adv_instances)) { in hci_powered_update_adv_sync()
3280 if (ext_adv_capable(hdev)) { in hci_powered_update_adv_sync()
3281 err = hci_setup_ext_adv_instance_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3283 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3285 err = hci_update_adv_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3287 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3290 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_powered_update_adv_sync()
3291 hci_enable_advertising_sync(hdev); in hci_powered_update_adv_sync()
3295 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) in hci_powered_update_adv_sync()
3296 hci_schedule_adv_instance_sync(hdev, adv->instance, true); in hci_powered_update_adv_sync()
3301 static int hci_write_auth_enable_sync(struct hci_dev *hdev) in hci_write_auth_enable_sync() argument
3305 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in hci_write_auth_enable_sync()
3306 if (link_sec == test_bit(HCI_AUTH, &hdev->flags)) in hci_write_auth_enable_sync()
3309 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE, in hci_write_auth_enable_sync()
3314 int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable) in hci_write_fast_connectable_sync() argument
3320 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_write_fast_connectable_sync()
3323 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_write_fast_connectable_sync()
3334 type = hdev->def_page_scan_type; in hci_write_fast_connectable_sync()
3335 cp.interval = cpu_to_le16(hdev->def_page_scan_int); in hci_write_fast_connectable_sync()
3338 cp.window = cpu_to_le16(hdev->def_page_scan_window); in hci_write_fast_connectable_sync()
3340 if (__cpu_to_le16(hdev->page_scan_interval) != cp.interval || in hci_write_fast_connectable_sync()
3341 __cpu_to_le16(hdev->page_scan_window) != cp.window) { in hci_write_fast_connectable_sync()
3342 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3349 if (hdev->page_scan_type != type) in hci_write_fast_connectable_sync()
3350 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3358 static bool disconnected_accept_list_entries(struct hci_dev *hdev) in disconnected_accept_list_entries() argument
3362 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
3365 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
3376 static int hci_write_scan_enable_sync(struct hci_dev *hdev, u8 val) in hci_write_scan_enable_sync() argument
3378 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE, in hci_write_scan_enable_sync()
3383 int hci_update_scan_sync(struct hci_dev *hdev) in hci_update_scan_sync() argument
3387 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_scan_sync()
3390 if (!hdev_is_powered(hdev)) in hci_update_scan_sync()
3393 if (mgmt_powering_down(hdev)) in hci_update_scan_sync()
3396 if (hdev->scanning_paused) in hci_update_scan_sync()
3399 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in hci_update_scan_sync()
3400 disconnected_accept_list_entries(hdev)) in hci_update_scan_sync()
3405 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_update_scan_sync()
3408 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in hci_update_scan_sync()
3409 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in hci_update_scan_sync()
3412 return hci_write_scan_enable_sync(hdev, scan); in hci_update_scan_sync()
3415 int hci_update_name_sync(struct hci_dev *hdev) in hci_update_name_sync() argument
3421 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in hci_update_name_sync()
3423 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME, in hci_update_name_sync()
3440 int hci_powered_update_sync(struct hci_dev *hdev) in hci_powered_update_sync() argument
3449 smp_register(hdev); in hci_powered_update_sync()
3451 err = hci_write_ssp_mode_sync(hdev, 0x01); in hci_powered_update_sync()
3455 err = hci_write_le_host_supported_sync(hdev, 0x01, 0x00); in hci_powered_update_sync()
3459 err = hci_powered_update_adv_sync(hdev); in hci_powered_update_sync()
3463 err = hci_write_auth_enable_sync(hdev); in hci_powered_update_sync()
3467 if (lmp_bredr_capable(hdev)) { in hci_powered_update_sync()
3468 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in hci_powered_update_sync()
3469 hci_write_fast_connectable_sync(hdev, true); in hci_powered_update_sync()
3471 hci_write_fast_connectable_sync(hdev, false); in hci_powered_update_sync()
3472 hci_update_scan_sync(hdev); in hci_powered_update_sync()
3473 hci_update_class_sync(hdev); in hci_powered_update_sync()
3474 hci_update_name_sync(hdev); in hci_powered_update_sync()
3475 hci_update_eir_sync(hdev); in hci_powered_update_sync()
3487 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_powered_update_sync()
3488 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_powered_update_sync()
3489 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))) { in hci_powered_update_sync()
3490 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in hci_powered_update_sync()
3491 return hci_set_random_addr_sync(hdev, in hci_powered_update_sync()
3492 &hdev->static_addr); in hci_powered_update_sync()
3510 static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) in hci_dev_get_bd_addr_from_property() argument
3512 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
3521 if (test_bit(HCI_QUIRK_BDADDR_PROPERTY_BROKEN, &hdev->quirks)) in hci_dev_get_bd_addr_from_property()
3522 baswap(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3524 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3528 int (*func)(struct hci_dev *hdev);
3532 static int hci_init_stage_sync(struct hci_dev *hdev, in hci_init_stage_sync() argument
3540 err = stage[i].func(hdev); in hci_init_stage_sync()
3549 static int hci_read_local_version_sync(struct hci_dev *hdev) in hci_read_local_version_sync() argument
3551 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_VERSION, in hci_read_local_version_sync()
3556 static int hci_read_bd_addr_sync(struct hci_dev *hdev) in hci_read_bd_addr_sync() argument
3558 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BD_ADDR, in hci_read_bd_addr_sync()
3575 int hci_reset_sync(struct hci_dev *hdev) in hci_reset_sync() argument
3579 set_bit(HCI_RESET, &hdev->flags); in hci_reset_sync()
3581 err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL, in hci_reset_sync()
3589 static int hci_init0_sync(struct hci_dev *hdev) in hci_init0_sync() argument
3593 bt_dev_dbg(hdev, ""); in hci_init0_sync()
3596 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init0_sync()
3597 err = hci_reset_sync(hdev); in hci_init0_sync()
3602 return hci_init_stage_sync(hdev, hci_init0); in hci_init0_sync()
3605 static int hci_unconf_init_sync(struct hci_dev *hdev) in hci_unconf_init_sync() argument
3609 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_unconf_init_sync()
3612 err = hci_init0_sync(hdev); in hci_unconf_init_sync()
3616 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_unconf_init_sync()
3617 hci_debugfs_create_basic(hdev); in hci_unconf_init_sync()
3623 static int hci_read_local_features_sync(struct hci_dev *hdev) in hci_read_local_features_sync() argument
3625 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_FEATURES, in hci_read_local_features_sync()
3641 static int hci_read_local_cmds_sync(struct hci_dev *hdev) in hci_read_local_cmds_sync() argument
3651 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_read_local_cmds_sync()
3652 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_read_local_cmds_sync()
3653 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_COMMANDS, in hci_read_local_cmds_sync()
3659 static int hci_init1_sync(struct hci_dev *hdev) in hci_init1_sync() argument
3663 bt_dev_dbg(hdev, ""); in hci_init1_sync()
3666 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init1_sync()
3667 err = hci_reset_sync(hdev); in hci_init1_sync()
3672 return hci_init_stage_sync(hdev, br_init1); in hci_init1_sync()
3676 static int hci_read_buffer_size_sync(struct hci_dev *hdev) in hci_read_buffer_size_sync() argument
3678 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BUFFER_SIZE, in hci_read_buffer_size_sync()
3683 static int hci_read_dev_class_sync(struct hci_dev *hdev) in hci_read_dev_class_sync() argument
3685 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLASS_OF_DEV, in hci_read_dev_class_sync()
3690 static int hci_read_local_name_sync(struct hci_dev *hdev) in hci_read_local_name_sync() argument
3692 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_NAME, in hci_read_local_name_sync()
3697 static int hci_read_voice_setting_sync(struct hci_dev *hdev) in hci_read_voice_setting_sync() argument
3699 if (!read_voice_setting_capable(hdev)) in hci_read_voice_setting_sync()
3702 return __hci_cmd_sync_status(hdev, HCI_OP_READ_VOICE_SETTING, in hci_read_voice_setting_sync()
3707 static int hci_read_num_supported_iac_sync(struct hci_dev *hdev) in hci_read_num_supported_iac_sync() argument
3709 return __hci_cmd_sync_status(hdev, HCI_OP_READ_NUM_SUPPORTED_IAC, in hci_read_num_supported_iac_sync()
3714 static int hci_read_current_iac_lap_sync(struct hci_dev *hdev) in hci_read_current_iac_lap_sync() argument
3716 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CURRENT_IAC_LAP, in hci_read_current_iac_lap_sync()
3720 static int hci_set_event_filter_sync(struct hci_dev *hdev, u8 flt_type, in hci_set_event_filter_sync() argument
3726 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_set_event_filter_sync()
3729 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_set_event_filter_sync()
3741 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_FLT, in hci_set_event_filter_sync()
3747 static int hci_clear_event_filter_sync(struct hci_dev *hdev) in hci_clear_event_filter_sync() argument
3749 if (!hci_dev_test_flag(hdev, HCI_EVENT_FILTER_CONFIGURED)) in hci_clear_event_filter_sync()
3756 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_clear_event_filter_sync()
3759 return hci_set_event_filter_sync(hdev, HCI_FLT_CLEAR_ALL, 0x00, in hci_clear_event_filter_sync()
3764 static int hci_write_ca_timeout_sync(struct hci_dev *hdev) in hci_write_ca_timeout_sync() argument
3768 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CA_TIMEOUT, in hci_write_ca_timeout_sync()
3773 static int hci_write_sync_flowctl_sync(struct hci_dev *hdev) in hci_write_sync_flowctl_sync() argument
3779 if (!lmp_sco_capable(hdev) || !(hdev->commands[10] & BIT(4)) || in hci_write_sync_flowctl_sync()
3780 !test_bit(HCI_QUIRK_SYNC_FLOWCTL_SUPPORTED, &hdev->quirks)) in hci_write_sync_flowctl_sync()
3786 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SYNC_FLOWCTL, in hci_write_sync_flowctl_sync()
3789 hci_dev_set_flag(hdev, HCI_SCO_FLOWCTL); in hci_write_sync_flowctl_sync()
3817 static int hci_write_ssp_mode_1_sync(struct hci_dev *hdev) in hci_write_ssp_mode_1_sync() argument
3821 if (!lmp_ssp_capable(hdev) || !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_ssp_mode_1_sync()
3830 hdev->max_page = 0x01; in hci_write_ssp_mode_1_sync()
3832 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_1_sync()
3836 static int hci_write_eir_sync(struct hci_dev *hdev) in hci_write_eir_sync() argument
3840 if (!lmp_ssp_capable(hdev) || hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_eir_sync()
3843 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_write_eir_sync()
3846 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_write_eir_sync()
3850 static int hci_write_inquiry_mode_sync(struct hci_dev *hdev) in hci_write_inquiry_mode_sync() argument
3854 if (!lmp_inq_rssi_capable(hdev) && in hci_write_inquiry_mode_sync()
3855 !test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_write_inquiry_mode_sync()
3862 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_write_inquiry_mode_sync()
3864 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_INQUIRY_MODE, in hci_write_inquiry_mode_sync()
3868 static int hci_read_inq_rsp_tx_power_sync(struct hci_dev *hdev) in hci_read_inq_rsp_tx_power_sync() argument
3870 if (!lmp_inq_tx_pwr_capable(hdev)) in hci_read_inq_rsp_tx_power_sync()
3873 return __hci_cmd_sync_status(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, in hci_read_inq_rsp_tx_power_sync()
3877 static int hci_read_local_ext_features_sync(struct hci_dev *hdev, u8 page) in hci_read_local_ext_features_sync() argument
3881 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_sync()
3887 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, in hci_read_local_ext_features_sync()
3891 static int hci_read_local_ext_features_1_sync(struct hci_dev *hdev) in hci_read_local_ext_features_1_sync() argument
3893 return hci_read_local_ext_features_sync(hdev, 0x01); in hci_read_local_ext_features_1_sync()
3916 static int hci_le_read_buffer_size_sync(struct hci_dev *hdev) in hci_le_read_buffer_size_sync() argument
3919 if (iso_capable(hdev) && hdev->commands[41] & 0x20) in hci_le_read_buffer_size_sync()
3920 return __hci_cmd_sync_status(hdev, in hci_le_read_buffer_size_sync()
3924 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_BUFFER_SIZE, in hci_le_read_buffer_size_sync()
3929 static int hci_le_read_local_features_sync(struct hci_dev *hdev) in hci_le_read_local_features_sync() argument
3931 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_LOCAL_FEATURES, in hci_le_read_local_features_sync()
3936 static int hci_le_read_supported_states_sync(struct hci_dev *hdev) in hci_le_read_supported_states_sync() argument
3938 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_SUPPORTED_STATES, in hci_le_read_supported_states_sync()
3953 static int hci_init2_sync(struct hci_dev *hdev) in hci_init2_sync() argument
3957 bt_dev_dbg(hdev, ""); in hci_init2_sync()
3959 err = hci_init_stage_sync(hdev, hci_init2); in hci_init2_sync()
3963 if (lmp_bredr_capable(hdev)) { in hci_init2_sync()
3964 err = hci_init_stage_sync(hdev, br_init2); in hci_init2_sync()
3968 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_sync()
3971 if (lmp_le_capable(hdev)) { in hci_init2_sync()
3972 err = hci_init_stage_sync(hdev, le_init2); in hci_init2_sync()
3976 if (!lmp_bredr_capable(hdev)) in hci_init2_sync()
3977 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in hci_init2_sync()
3983 static int hci_set_event_mask_sync(struct hci_dev *hdev) in hci_set_event_mask_sync() argument
3994 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_set_event_mask_sync()
3997 if (lmp_bredr_capable(hdev)) { in hci_set_event_mask_sync()
4004 if (hdev->suspended) { in hci_set_event_mask_sync()
4019 if (hdev->commands[0] & 0x20) { in hci_set_event_mask_sync()
4024 if (!hdev->suspended) in hci_set_event_mask_sync()
4033 if (hdev->commands[2] & 0x80) in hci_set_event_mask_sync()
4038 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_set_event_mask_sync()
4044 if (lmp_inq_rssi_capable(hdev) || in hci_set_event_mask_sync()
4045 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_set_event_mask_sync()
4048 if (lmp_ext_feat_capable(hdev)) in hci_set_event_mask_sync()
4051 if (lmp_esco_capable(hdev)) { in hci_set_event_mask_sync()
4056 if (lmp_sniffsubr_capable(hdev)) in hci_set_event_mask_sync()
4059 if (lmp_pause_enc_capable(hdev)) in hci_set_event_mask_sync()
4062 if (lmp_ext_inq_capable(hdev)) in hci_set_event_mask_sync()
4065 if (lmp_no_flush_capable(hdev)) in hci_set_event_mask_sync()
4068 if (lmp_lsto_capable(hdev)) in hci_set_event_mask_sync()
4071 if (lmp_ssp_capable(hdev)) { in hci_set_event_mask_sync()
4085 if (lmp_le_capable(hdev)) in hci_set_event_mask_sync()
4088 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK, in hci_set_event_mask_sync()
4092 static int hci_read_stored_link_key_sync(struct hci_dev *hdev) in hci_read_stored_link_key_sync() argument
4096 if (!(hdev->commands[6] & 0x20) || in hci_read_stored_link_key_sync()
4097 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_read_stored_link_key_sync()
4104 return __hci_cmd_sync_status(hdev, HCI_OP_READ_STORED_LINK_KEY, in hci_read_stored_link_key_sync()
4108 static int hci_setup_link_policy_sync(struct hci_dev *hdev) in hci_setup_link_policy_sync() argument
4113 if (!(hdev->commands[5] & 0x10)) in hci_setup_link_policy_sync()
4118 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy_sync()
4120 if (lmp_hold_capable(hdev)) in hci_setup_link_policy_sync()
4122 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy_sync()
4124 if (lmp_park_capable(hdev)) in hci_setup_link_policy_sync()
4129 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, in hci_setup_link_policy_sync()
4133 static int hci_read_page_scan_activity_sync(struct hci_dev *hdev) in hci_read_page_scan_activity_sync() argument
4135 if (!(hdev->commands[8] & 0x01)) in hci_read_page_scan_activity_sync()
4138 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_ACTIVITY, in hci_read_page_scan_activity_sync()
4142 static int hci_read_def_err_data_reporting_sync(struct hci_dev *hdev) in hci_read_def_err_data_reporting_sync() argument
4144 if (!(hdev->commands[18] & 0x04) || in hci_read_def_err_data_reporting_sync()
4145 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_read_def_err_data_reporting_sync()
4146 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_read_def_err_data_reporting_sync()
4149 return __hci_cmd_sync_status(hdev, HCI_OP_READ_DEF_ERR_DATA_REPORTING, in hci_read_def_err_data_reporting_sync()
4153 static int hci_read_page_scan_type_sync(struct hci_dev *hdev) in hci_read_page_scan_type_sync() argument
4159 if (!(hdev->commands[13] & 0x01) || in hci_read_page_scan_type_sync()
4160 test_bit(HCI_QUIRK_BROKEN_READ_PAGE_SCAN_TYPE, &hdev->quirks)) in hci_read_page_scan_type_sync()
4163 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_TYPE, in hci_read_page_scan_type_sync()
4168 static int hci_read_local_ext_features_all_sync(struct hci_dev *hdev) in hci_read_local_ext_features_all_sync() argument
4173 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_all_sync()
4176 for (page = 2; page < HCI_MAX_PAGES && page <= hdev->max_page; in hci_read_local_ext_features_all_sync()
4178 err = hci_read_local_ext_features_sync(hdev, page); in hci_read_local_ext_features_all_sync()
4205 static int hci_le_set_event_mask_sync(struct hci_dev *hdev) in hci_le_set_event_mask_sync() argument
4209 if (!lmp_le_capable(hdev)) in hci_le_set_event_mask_sync()
4214 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_le_set_event_mask_sync()
4220 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_le_set_event_mask_sync()
4227 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_le_set_event_mask_sync()
4233 if (use_enhanced_conn_complete(hdev)) in hci_le_set_event_mask_sync()
4237 if (privacy_mode_capable(hdev)) in hci_le_set_event_mask_sync()
4238 hdev->conn_flags |= HCI_CONN_FLAG_DEVICE_PRIVACY; in hci_le_set_event_mask_sync()
4241 if (ll_privacy_capable(hdev)) in hci_le_set_event_mask_sync()
4242 hdev->conn_flags |= HCI_CONN_FLAG_ADDRESS_RESOLUTION; in hci_le_set_event_mask_sync()
4247 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_le_set_event_mask_sync()
4253 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_le_set_event_mask_sync()
4259 if (hdev->commands[26] & 0x08) in hci_le_set_event_mask_sync()
4265 if (hdev->commands[26] & 0x10) in hci_le_set_event_mask_sync()
4271 if (hdev->commands[27] & 0x04) in hci_le_set_event_mask_sync()
4277 if (hdev->commands[27] & 0x20) in hci_le_set_event_mask_sync()
4284 if (hdev->commands[34] & 0x02) in hci_le_set_event_mask_sync()
4291 if (hdev->commands[34] & 0x04) in hci_le_set_event_mask_sync()
4297 if (hdev->commands[35] & (0x20 | 0x40)) in hci_le_set_event_mask_sync()
4304 if (use_ext_scan(hdev)) in hci_le_set_event_mask_sync()
4310 if (ext_adv_capable(hdev)) in hci_le_set_event_mask_sync()
4313 if (cis_capable(hdev)) { in hci_le_set_event_mask_sync()
4315 if (cis_peripheral_capable(hdev)) in hci_le_set_event_mask_sync()
4319 if (bis_capable(hdev)) { in hci_le_set_event_mask_sync()
4329 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EVENT_MASK, in hci_le_set_event_mask_sync()
4334 static int hci_le_read_adv_tx_power_sync(struct hci_dev *hdev) in hci_le_read_adv_tx_power_sync() argument
4336 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_le_read_adv_tx_power_sync()
4343 return __hci_cmd_sync_status(hdev, in hci_le_read_adv_tx_power_sync()
4352 static int hci_le_read_tx_power_sync(struct hci_dev *hdev) in hci_le_read_tx_power_sync() argument
4354 if (!(hdev->commands[38] & 0x80) || in hci_le_read_tx_power_sync()
4355 test_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks)) in hci_le_read_tx_power_sync()
4358 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_TRANSMIT_POWER, in hci_le_read_tx_power_sync()
4363 static int hci_le_read_accept_list_size_sync(struct hci_dev *hdev) in hci_le_read_accept_list_size_sync() argument
4365 if (!(hdev->commands[26] & 0x40)) in hci_le_read_accept_list_size_sync()
4368 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_ACCEPT_LIST_SIZE, in hci_le_read_accept_list_size_sync()
4373 static int hci_le_read_resolv_list_size_sync(struct hci_dev *hdev) in hci_le_read_resolv_list_size_sync() argument
4375 if (!(hdev->commands[34] & 0x40)) in hci_le_read_resolv_list_size_sync()
4378 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_RESOLV_LIST_SIZE, in hci_le_read_resolv_list_size_sync()
4383 static int hci_le_clear_resolv_list_sync(struct hci_dev *hdev) in hci_le_clear_resolv_list_sync() argument
4385 if (!(hdev->commands[34] & 0x20)) in hci_le_clear_resolv_list_sync()
4388 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL, in hci_le_clear_resolv_list_sync()
4393 static int hci_le_set_rpa_timeout_sync(struct hci_dev *hdev) in hci_le_set_rpa_timeout_sync() argument
4395 __le16 timeout = cpu_to_le16(hdev->rpa_timeout); in hci_le_set_rpa_timeout_sync()
4397 if (!(hdev->commands[35] & 0x04) || in hci_le_set_rpa_timeout_sync()
4398 test_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT, &hdev->quirks)) in hci_le_set_rpa_timeout_sync()
4401 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RPA_TIMEOUT, in hci_le_set_rpa_timeout_sync()
4407 static int hci_le_read_max_data_len_sync(struct hci_dev *hdev) in hci_le_read_max_data_len_sync() argument
4409 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_max_data_len_sync()
4412 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL, in hci_le_read_max_data_len_sync()
4417 static int hci_le_read_def_data_len_sync(struct hci_dev *hdev) in hci_le_read_def_data_len_sync() argument
4419 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_def_data_len_sync()
4422 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_DEF_DATA_LEN, 0, NULL, in hci_le_read_def_data_len_sync()
4427 static int hci_le_read_num_support_adv_sets_sync(struct hci_dev *hdev) in hci_le_read_num_support_adv_sets_sync() argument
4429 if (!ext_adv_capable(hdev)) in hci_le_read_num_support_adv_sets_sync()
4432 return __hci_cmd_sync_status(hdev, in hci_le_read_num_support_adv_sets_sync()
4438 static int hci_set_le_support_sync(struct hci_dev *hdev) in hci_set_le_support_sync() argument
4443 if (!lmp_bredr_capable(hdev)) in hci_set_le_support_sync()
4448 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support_sync()
4453 if (cp.le == lmp_host_le_capable(hdev)) in hci_set_le_support_sync()
4456 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_set_le_support_sync()
4461 static int hci_le_set_host_feature_sync(struct hci_dev *hdev) in hci_le_set_host_feature_sync() argument
4465 if (!cis_capable(hdev)) in hci_le_set_host_feature_sync()
4474 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_HOST_FEATURE, in hci_le_set_host_feature_sync()
4509 static int hci_init3_sync(struct hci_dev *hdev) in hci_init3_sync() argument
4513 bt_dev_dbg(hdev, ""); in hci_init3_sync()
4515 err = hci_init_stage_sync(hdev, hci_init3); in hci_init3_sync()
4519 if (lmp_le_capable(hdev)) in hci_init3_sync()
4520 return hci_init_stage_sync(hdev, le_init3); in hci_init3_sync()
4525 static int hci_delete_stored_link_key_sync(struct hci_dev *hdev) in hci_delete_stored_link_key_sync() argument
4542 if (!(hdev->commands[6] & 0x80) || in hci_delete_stored_link_key_sync()
4543 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_delete_stored_link_key_sync()
4550 return __hci_cmd_sync_status(hdev, HCI_OP_DELETE_STORED_LINK_KEY, in hci_delete_stored_link_key_sync()
4554 static int hci_set_event_mask_page_2_sync(struct hci_dev *hdev) in hci_set_event_mask_page_2_sync() argument
4560 if (!(hdev->commands[22] & 0x04)) in hci_set_event_mask_page_2_sync()
4566 if (lmp_cpb_central_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4577 if (lmp_cpb_peripheral_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4586 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2_sync()
4600 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK_PAGE_2, in hci_set_event_mask_page_2_sync()
4605 static int hci_read_local_codecs_sync(struct hci_dev *hdev) in hci_read_local_codecs_sync() argument
4607 if (hdev->commands[45] & 0x04) in hci_read_local_codecs_sync()
4608 hci_read_supported_codecs_v2(hdev); in hci_read_local_codecs_sync()
4609 else if (hdev->commands[29] & 0x20) in hci_read_local_codecs_sync()
4610 hci_read_supported_codecs(hdev); in hci_read_local_codecs_sync()
4616 static int hci_read_local_pairing_opts_sync(struct hci_dev *hdev) in hci_read_local_pairing_opts_sync() argument
4618 if (!(hdev->commands[41] & 0x08)) in hci_read_local_pairing_opts_sync()
4621 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_PAIRING_OPTS, in hci_read_local_pairing_opts_sync()
4626 static int hci_get_mws_transport_config_sync(struct hci_dev *hdev) in hci_get_mws_transport_config_sync() argument
4628 if (!mws_transport_config_capable(hdev)) in hci_get_mws_transport_config_sync()
4631 return __hci_cmd_sync_status(hdev, HCI_OP_GET_MWS_TRANSPORT_CONFIG, in hci_get_mws_transport_config_sync()
4636 static int hci_read_sync_train_params_sync(struct hci_dev *hdev) in hci_read_sync_train_params_sync() argument
4638 if (!lmp_sync_train_capable(hdev)) in hci_read_sync_train_params_sync()
4641 return __hci_cmd_sync_status(hdev, HCI_OP_READ_SYNC_TRAIN_PARAMS, in hci_read_sync_train_params_sync()
4646 static int hci_write_sc_support_1_sync(struct hci_dev *hdev) in hci_write_sc_support_1_sync() argument
4650 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_sc_support_1_sync()
4651 !bredr_sc_enabled(hdev)) in hci_write_sc_support_1_sync()
4654 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_1_sync()
4662 static int hci_set_err_data_report_sync(struct hci_dev *hdev) in hci_set_err_data_report_sync() argument
4665 bool enabled = hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED); in hci_set_err_data_report_sync()
4667 if (!(hdev->commands[18] & 0x08) || in hci_set_err_data_report_sync()
4668 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_set_err_data_report_sync()
4669 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_set_err_data_report_sync()
4672 if (enabled == hdev->err_data_reporting) in hci_set_err_data_report_sync()
4679 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING, in hci_set_err_data_report_sync()
4704 static int hci_le_set_write_def_data_len_sync(struct hci_dev *hdev) in hci_le_set_write_def_data_len_sync() argument
4708 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_set_write_def_data_len_sync()
4712 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_le_set_write_def_data_len_sync()
4713 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_le_set_write_def_data_len_sync()
4715 return __hci_cmd_sync_status(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN, in hci_le_set_write_def_data_len_sync()
4722 static int hci_le_set_default_phy_sync(struct hci_dev *hdev) in hci_le_set_default_phy_sync() argument
4726 if (!(hdev->commands[35] & 0x20)) { in hci_le_set_default_phy_sync()
4730 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4731 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4741 if (le_2m_capable(hdev)) { in hci_le_set_default_phy_sync()
4747 if (le_coded_capable(hdev)) { in hci_le_set_default_phy_sync()
4752 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in hci_le_set_default_phy_sync()
4764 static int hci_init4_sync(struct hci_dev *hdev) in hci_init4_sync() argument
4768 bt_dev_dbg(hdev, ""); in hci_init4_sync()
4770 err = hci_init_stage_sync(hdev, hci_init4); in hci_init4_sync()
4774 if (lmp_le_capable(hdev)) in hci_init4_sync()
4775 return hci_init_stage_sync(hdev, le_init4); in hci_init4_sync()
4780 static int hci_init_sync(struct hci_dev *hdev) in hci_init_sync() argument
4784 err = hci_init1_sync(hdev); in hci_init_sync()
4788 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_init_sync()
4789 hci_debugfs_create_basic(hdev); in hci_init_sync()
4791 err = hci_init2_sync(hdev); in hci_init_sync()
4795 err = hci_init3_sync(hdev); in hci_init_sync()
4799 err = hci_init4_sync(hdev); in hci_init_sync()
4815 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_init_sync()
4816 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_init_sync()
4819 if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) in hci_init_sync()
4822 hci_debugfs_create_common(hdev); in hci_init_sync()
4824 if (lmp_bredr_capable(hdev)) in hci_init_sync()
4825 hci_debugfs_create_bredr(hdev); in hci_init_sync()
4827 if (lmp_le_capable(hdev)) in hci_init_sync()
4828 hci_debugfs_create_le(hdev); in hci_init_sync()
4875 static int hci_dev_setup_sync(struct hci_dev *hdev) in hci_dev_setup_sync() argument
4881 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_setup_sync()
4882 !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) in hci_dev_setup_sync()
4885 bt_dev_dbg(hdev, ""); in hci_dev_setup_sync()
4887 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_setup_sync()
4889 if (hdev->setup) in hci_dev_setup_sync()
4890 ret = hdev->setup(hdev); in hci_dev_setup_sync()
4893 if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) in hci_dev_setup_sync()
4894 bt_dev_warn(hdev, "%s", hci_broken_table[i].desc); in hci_dev_setup_sync()
4901 invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in hci_dev_setup_sync()
4902 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); in hci_dev_setup_sync()
4904 if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks) && in hci_dev_setup_sync()
4905 !bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_setup_sync()
4906 hci_dev_get_bd_addr_from_property(hdev); in hci_dev_setup_sync()
4908 if (invalid_bdaddr && bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_setup_sync()
4909 hdev->set_bdaddr) { in hci_dev_setup_sync()
4910 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_setup_sync()
4926 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_setup_sync()
4928 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_setup_sync()
4938 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_setup_sync()
4939 return hci_unconf_init_sync(hdev); in hci_dev_setup_sync()
4949 static int hci_dev_init_sync(struct hci_dev *hdev) in hci_dev_init_sync() argument
4953 bt_dev_dbg(hdev, ""); in hci_dev_init_sync()
4955 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_init_sync()
4956 set_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4958 ret = hci_dev_setup_sync(hdev); in hci_dev_init_sync()
4960 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_init_sync()
4966 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_init_sync()
4967 hdev->set_bdaddr) in hci_dev_init_sync()
4968 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_init_sync()
4974 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_init_sync()
4975 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4976 ret = hci_init_sync(hdev); in hci_dev_init_sync()
4977 if (!ret && hdev->post_init) in hci_dev_init_sync()
4978 ret = hdev->post_init(hdev); in hci_dev_init_sync()
4986 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_init_sync()
4987 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_init_sync()
4988 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_init_sync()
4989 ret = hdev->set_diag(hdev, true); in hci_dev_init_sync()
4991 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4992 msft_do_open(hdev); in hci_dev_init_sync()
4993 aosp_do_open(hdev); in hci_dev_init_sync()
4996 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
5001 int hci_dev_open_sync(struct hci_dev *hdev) in hci_dev_open_sync() argument
5005 bt_dev_dbg(hdev, ""); in hci_dev_open_sync()
5007 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_open_sync()
5012 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
5013 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_open_sync()
5017 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_open_sync()
5031 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
5032 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_open_sync()
5033 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_open_sync()
5039 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open_sync()
5044 if (hdev->open(hdev)) { in hci_dev_open_sync()
5049 hci_devcd_reset(hdev); in hci_dev_open_sync()
5051 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
5052 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_open_sync()
5054 ret = hci_dev_init_sync(hdev); in hci_dev_open_sync()
5056 hci_dev_hold(hdev); in hci_dev_open_sync()
5057 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_open_sync()
5058 hci_adv_instances_set_rpa_expired(hdev, true); in hci_dev_open_sync()
5059 set_bit(HCI_UP, &hdev->flags); in hci_dev_open_sync()
5060 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_open_sync()
5061 hci_leds_update_powered(hdev, true); in hci_dev_open_sync()
5062 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
5063 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_open_sync()
5064 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open_sync()
5065 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
5066 hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_open_sync()
5067 ret = hci_powered_update_sync(hdev); in hci_dev_open_sync()
5068 mgmt_power_on(hdev, ret); in hci_dev_open_sync()
5072 flush_work(&hdev->tx_work); in hci_dev_open_sync()
5078 flush_work(&hdev->rx_work); in hci_dev_open_sync()
5079 flush_work(&hdev->cmd_work); in hci_dev_open_sync()
5081 skb_queue_purge(&hdev->cmd_q); in hci_dev_open_sync()
5082 skb_queue_purge(&hdev->rx_q); in hci_dev_open_sync()
5084 if (hdev->flush) in hci_dev_open_sync()
5085 hdev->flush(hdev); in hci_dev_open_sync()
5087 if (hdev->sent_cmd) { in hci_dev_open_sync()
5088 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_open_sync()
5089 kfree_skb(hdev->sent_cmd); in hci_dev_open_sync()
5090 hdev->sent_cmd = NULL; in hci_dev_open_sync()
5093 if (hdev->req_skb) { in hci_dev_open_sync()
5094 kfree_skb(hdev->req_skb); in hci_dev_open_sync()
5095 hdev->req_skb = NULL; in hci_dev_open_sync()
5098 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
5099 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_open_sync()
5101 hdev->close(hdev); in hci_dev_open_sync()
5102 hdev->flags &= BIT(HCI_RAW); in hci_dev_open_sync()
5110 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
5114 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
5126 static int hci_dev_shutdown(struct hci_dev *hdev) in hci_dev_shutdown() argument
5136 hci_dev_test_and_clear_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
5138 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_shutdown()
5139 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_shutdown()
5141 if (hdev->shutdown) in hci_dev_shutdown()
5142 err = hdev->shutdown(hdev); in hci_dev_shutdown()
5146 hci_dev_set_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
5151 int hci_dev_close_sync(struct hci_dev *hdev) in hci_dev_close_sync() argument
5156 bt_dev_dbg(hdev, ""); in hci_dev_close_sync()
5158 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_close_sync()
5159 disable_delayed_work(&hdev->power_off); in hci_dev_close_sync()
5160 disable_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
5161 disable_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
5163 cancel_delayed_work(&hdev->power_off); in hci_dev_close_sync()
5164 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
5165 cancel_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
5168 hci_cmd_sync_cancel_sync(hdev, ENODEV); in hci_dev_close_sync()
5170 cancel_interleave_scan(hdev); in hci_dev_close_sync()
5172 if (hdev->adv_instance_timeout) { in hci_dev_close_sync()
5173 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_dev_close_sync()
5174 hdev->adv_instance_timeout = 0; in hci_dev_close_sync()
5177 err = hci_dev_shutdown(hdev); in hci_dev_close_sync()
5179 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_close_sync()
5180 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5184 hci_leds_update_powered(hdev, false); in hci_dev_close_sync()
5187 flush_work(&hdev->tx_work); in hci_dev_close_sync()
5188 flush_work(&hdev->rx_work); in hci_dev_close_sync()
5190 if (hdev->discov_timeout > 0) { in hci_dev_close_sync()
5191 hdev->discov_timeout = 0; in hci_dev_close_sync()
5192 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_close_sync()
5193 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_close_sync()
5196 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_close_sync()
5197 cancel_delayed_work(&hdev->service_cache); in hci_dev_close_sync()
5199 if (hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_close_sync()
5202 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_close_sync()
5204 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_close_sync()
5211 drain_workqueue(hdev->workqueue); in hci_dev_close_sync()
5213 hci_dev_lock(hdev); in hci_dev_close_sync()
5215 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_close_sync()
5217 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_close_sync()
5219 if (!auto_off && !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_close_sync()
5220 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_close_sync()
5221 __mgmt_power_off(hdev); in hci_dev_close_sync()
5223 hci_inquiry_cache_flush(hdev); in hci_dev_close_sync()
5224 hci_pend_le_actions_clear(hdev); in hci_dev_close_sync()
5225 hci_conn_hash_flush(hdev); in hci_dev_close_sync()
5227 smp_unregister(hdev); in hci_dev_close_sync()
5228 hci_dev_unlock(hdev); in hci_dev_close_sync()
5230 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_close_sync()
5232 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close_sync()
5233 aosp_do_close(hdev); in hci_dev_close_sync()
5234 msft_do_close(hdev); in hci_dev_close_sync()
5237 if (hdev->flush) in hci_dev_close_sync()
5238 hdev->flush(hdev); in hci_dev_close_sync()
5241 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5242 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_close_sync()
5243 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_close_sync()
5244 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_close_sync()
5245 set_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5246 hci_reset_sync(hdev); in hci_dev_close_sync()
5247 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5251 flush_work(&hdev->cmd_work); in hci_dev_close_sync()
5254 skb_queue_purge(&hdev->rx_q); in hci_dev_close_sync()
5255 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5256 skb_queue_purge(&hdev->raw_q); in hci_dev_close_sync()
5259 if (hdev->sent_cmd) { in hci_dev_close_sync()
5260 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5261 kfree_skb(hdev->sent_cmd); in hci_dev_close_sync()
5262 hdev->sent_cmd = NULL; in hci_dev_close_sync()
5266 if (hdev->req_skb) { in hci_dev_close_sync()
5267 kfree_skb(hdev->req_skb); in hci_dev_close_sync()
5268 hdev->req_skb = NULL; in hci_dev_close_sync()
5271 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_close_sync()
5272 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_close_sync()
5275 hdev->close(hdev); in hci_dev_close_sync()
5278 hdev->flags &= BIT(HCI_RAW); in hci_dev_close_sync()
5279 hci_dev_clear_volatile_flags(hdev); in hci_dev_close_sync()
5281 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_close_sync()
5282 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_close_sync()
5283 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_close_sync()
5284 hci_codec_list_clear(&hdev->local_codecs); in hci_dev_close_sync()
5286 hci_dev_put(hdev); in hci_dev_close_sync()
5296 static int hci_power_on_sync(struct hci_dev *hdev) in hci_power_on_sync() argument
5300 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on_sync()
5301 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on_sync()
5302 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5303 cancel_delayed_work(&hdev->power_off); in hci_power_on_sync()
5304 return hci_powered_update_sync(hdev); in hci_power_on_sync()
5307 err = hci_dev_open_sync(hdev); in hci_power_on_sync()
5315 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on_sync()
5316 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on_sync()
5317 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on_sync()
5318 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on_sync()
5319 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on_sync()
5320 hci_dev_close_sync(hdev); in hci_power_on_sync()
5321 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5322 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on_sync()
5326 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on_sync()
5330 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5331 set_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5340 mgmt_index_added(hdev); in hci_power_on_sync()
5341 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on_sync()
5345 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5346 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5352 mgmt_index_added(hdev); in hci_power_on_sync()
5358 static int hci_remote_name_cancel_sync(struct hci_dev *hdev, bdaddr_t *addr) in hci_remote_name_cancel_sync() argument
5365 return __hci_cmd_sync_status(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, in hci_remote_name_cancel_sync()
5369 int hci_stop_discovery_sync(struct hci_dev *hdev) in hci_stop_discovery_sync() argument
5371 struct discovery_state *d = &hdev->discovery; in hci_stop_discovery_sync()
5375 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_stop_discovery_sync()
5378 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_stop_discovery_sync()
5379 err = __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY_CANCEL, in hci_stop_discovery_sync()
5385 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_stop_discovery_sync()
5386 cancel_delayed_work(&hdev->le_scan_disable); in hci_stop_discovery_sync()
5388 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5394 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5400 if (ll_privacy_capable(hdev)) in hci_stop_discovery_sync()
5401 hci_resume_advertising_sync(hdev); in hci_stop_discovery_sync()
5408 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_stop_discovery_sync()
5416 hci_remote_name_cancel_sync(hdev, &e->data.bdaddr); in hci_stop_discovery_sync()
5422 static int hci_disconnect_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_disconnect_sync() argument
5431 hci_dev_lock(hdev); in hci_disconnect_sync()
5433 hci_dev_unlock(hdev); in hci_disconnect_sync()
5448 return __hci_cmd_sync_status_sk(hdev, HCI_OP_DISCONNECT, in hci_disconnect_sync()
5453 return __hci_cmd_sync_status(hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp, in hci_disconnect_sync()
5457 static int hci_le_connect_cancel_sync(struct hci_dev *hdev, in hci_le_connect_cancel_sync() argument
5470 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, in hci_le_connect_cancel_sync()
5474 static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_connect_cancel_sync() argument
5478 return hci_le_connect_cancel_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5490 return hci_disconnect_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5502 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_connect_cancel_sync()
5511 return __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5516 return __hci_cmd_sync_status(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5520 static int hci_reject_sco_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_sco_sync() argument
5535 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_SYNC_CONN_REQ, in hci_reject_sco_sync()
5539 static int hci_le_reject_cis_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_le_reject_cis_sync() argument
5548 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REJECT_CIS, in hci_le_reject_cis_sync()
5552 static int hci_reject_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_conn_sync() argument
5558 return hci_le_reject_cis_sync(hdev, conn, reason); in hci_reject_conn_sync()
5561 return hci_reject_sco_sync(hdev, conn, reason); in hci_reject_conn_sync()
5567 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_CONN_REQ, in hci_reject_conn_sync()
5571 int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) in hci_abort_conn_sync() argument
5581 err = hci_disconnect_sync(hdev, conn, reason); in hci_abort_conn_sync()
5584 err = hci_connect_cancel_sync(hdev, conn, reason); in hci_abort_conn_sync()
5587 err = hci_reject_conn_sync(hdev, conn, reason); in hci_abort_conn_sync()
5597 hci_dev_lock(hdev); in hci_abort_conn_sync()
5600 c = hci_conn_hash_lookup_handle(hdev, handle); in hci_abort_conn_sync()
5620 hci_dev_unlock(hdev); in hci_abort_conn_sync()
5624 static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) in hci_disconnect_all_sync() argument
5626 struct list_head *head = &hdev->conn_hash.list; in hci_disconnect_all_sync()
5639 hci_abort_conn_sync(hdev, conn, reason); in hci_disconnect_all_sync()
5655 static int hci_power_off_sync(struct hci_dev *hdev) in hci_power_off_sync() argument
5660 if (!test_bit(HCI_UP, &hdev->flags)) in hci_power_off_sync()
5663 hci_dev_set_flag(hdev, HCI_POWERING_DOWN); in hci_power_off_sync()
5665 if (test_bit(HCI_ISCAN, &hdev->flags) || in hci_power_off_sync()
5666 test_bit(HCI_PSCAN, &hdev->flags)) { in hci_power_off_sync()
5667 err = hci_write_scan_enable_sync(hdev, 0x00); in hci_power_off_sync()
5672 err = hci_clear_adv_sync(hdev, NULL, false); in hci_power_off_sync()
5676 err = hci_stop_discovery_sync(hdev); in hci_power_off_sync()
5681 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_power_off_sync()
5685 err = hci_dev_close_sync(hdev); in hci_power_off_sync()
5688 hci_dev_clear_flag(hdev, HCI_POWERING_DOWN); in hci_power_off_sync()
5692 int hci_set_powered_sync(struct hci_dev *hdev, u8 val) in hci_set_powered_sync() argument
5695 return hci_power_on_sync(hdev); in hci_set_powered_sync()
5697 return hci_power_off_sync(hdev); in hci_set_powered_sync()
5700 static int hci_write_iac_sync(struct hci_dev *hdev) in hci_write_iac_sync() argument
5704 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_write_iac_sync()
5709 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_write_iac_sync()
5711 cp.num_iac = min_t(u8, hdev->num_iac, 2); in hci_write_iac_sync()
5726 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CURRENT_IAC_LAP, in hci_write_iac_sync()
5731 int hci_update_discoverable_sync(struct hci_dev *hdev) in hci_update_discoverable_sync() argument
5735 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_update_discoverable_sync()
5736 err = hci_write_iac_sync(hdev); in hci_update_discoverable_sync()
5740 err = hci_update_scan_sync(hdev); in hci_update_discoverable_sync()
5744 err = hci_update_class_sync(hdev); in hci_update_discoverable_sync()
5752 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in hci_update_discoverable_sync()
5753 err = hci_update_adv_data_sync(hdev, 0x00); in hci_update_discoverable_sync()
5760 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in hci_update_discoverable_sync()
5761 if (ext_adv_capable(hdev)) in hci_update_discoverable_sync()
5762 err = hci_start_ext_adv_sync(hdev, 0x00); in hci_update_discoverable_sync()
5764 err = hci_enable_advertising_sync(hdev); in hci_update_discoverable_sync()
5771 static int update_discoverable_sync(struct hci_dev *hdev, void *data) in update_discoverable_sync() argument
5773 return hci_update_discoverable_sync(hdev); in update_discoverable_sync()
5776 int hci_update_discoverable(struct hci_dev *hdev) in hci_update_discoverable() argument
5779 if (hdev_is_powered(hdev) && in hci_update_discoverable()
5780 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_update_discoverable()
5781 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in hci_update_discoverable()
5782 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in hci_update_discoverable()
5783 return hci_cmd_sync_queue(hdev, update_discoverable_sync, NULL, in hci_update_discoverable()
5789 int hci_update_connectable_sync(struct hci_dev *hdev) in hci_update_connectable_sync() argument
5793 err = hci_update_scan_sync(hdev); in hci_update_connectable_sync()
5801 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_connectable_sync()
5802 err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in hci_update_connectable_sync()
5805 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_update_connectable_sync()
5806 !list_empty(&hdev->adv_instances)) { in hci_update_connectable_sync()
5807 if (ext_adv_capable(hdev)) in hci_update_connectable_sync()
5808 err = hci_start_ext_adv_sync(hdev, in hci_update_connectable_sync()
5809 hdev->cur_adv_instance); in hci_update_connectable_sync()
5811 err = hci_enable_advertising_sync(hdev); in hci_update_connectable_sync()
5817 return hci_update_passive_scan_sync(hdev); in hci_update_connectable_sync()
5820 int hci_inquiry_sync(struct hci_dev *hdev, u8 length, u8 num_rsp) in hci_inquiry_sync() argument
5826 bt_dev_dbg(hdev, ""); in hci_inquiry_sync()
5828 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_inquiry_sync()
5831 hci_dev_lock(hdev); in hci_inquiry_sync()
5832 hci_inquiry_cache_flush(hdev); in hci_inquiry_sync()
5833 hci_dev_unlock(hdev); in hci_inquiry_sync()
5837 if (hdev->discovery.limited) in hci_inquiry_sync()
5845 return __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY, in hci_inquiry_sync()
5849 static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) in hci_active_scan_sync() argument
5858 bt_dev_dbg(hdev, ""); in hci_active_scan_sync()
5864 err = hci_scan_disable_sync(hdev); in hci_active_scan_sync()
5866 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_active_scan_sync()
5870 cancel_interleave_scan(hdev); in hci_active_scan_sync()
5875 err = hci_pause_addr_resolution(hdev); in hci_active_scan_sync()
5883 err = hci_update_random_address_sync(hdev, true, scan_use_rpa(hdev), in hci_active_scan_sync()
5888 if (hci_is_adv_monitoring(hdev) || in hci_active_scan_sync()
5889 (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in hci_active_scan_sync()
5890 hdev->discovery.result_filtering)) { in hci_active_scan_sync()
5904 err = hci_start_scan_sync(hdev, LE_SCAN_ACTIVE, interval, in hci_active_scan_sync()
5905 hdev->le_scan_window_discovery, in hci_active_scan_sync()
5912 if (ll_privacy_capable(hdev)) in hci_active_scan_sync()
5913 hci_resume_advertising_sync(hdev); in hci_active_scan_sync()
5916 hci_update_passive_scan_sync(hdev); in hci_active_scan_sync()
5920 static int hci_start_interleaved_discovery_sync(struct hci_dev *hdev) in hci_start_interleaved_discovery_sync() argument
5924 bt_dev_dbg(hdev, ""); in hci_start_interleaved_discovery_sync()
5926 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery * 2); in hci_start_interleaved_discovery_sync()
5930 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN, 0); in hci_start_interleaved_discovery_sync()
5933 int hci_start_discovery_sync(struct hci_dev *hdev) in hci_start_discovery_sync() argument
5938 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in hci_start_discovery_sync()
5940 switch (hdev->discovery.type) { in hci_start_discovery_sync()
5942 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN, 0); in hci_start_discovery_sync()
5953 &hdev->quirks)) { in hci_start_discovery_sync()
5959 err = hci_start_interleaved_discovery_sync(hdev); in hci_start_discovery_sync()
5963 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in hci_start_discovery_sync()
5964 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5968 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5977 bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout)); in hci_start_discovery_sync()
5979 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in hci_start_discovery_sync()
5984 static void hci_suspend_monitor_sync(struct hci_dev *hdev) in hci_suspend_monitor_sync() argument
5986 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_suspend_monitor_sync()
5988 msft_suspend_sync(hdev); in hci_suspend_monitor_sync()
5996 static int hci_pause_discovery_sync(struct hci_dev *hdev) in hci_pause_discovery_sync() argument
5998 int old_state = hdev->discovery.state; in hci_pause_discovery_sync()
6003 hdev->discovery_paused) in hci_pause_discovery_sync()
6006 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_pause_discovery_sync()
6007 err = hci_stop_discovery_sync(hdev); in hci_pause_discovery_sync()
6011 hdev->discovery_paused = true; in hci_pause_discovery_sync()
6012 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_pause_discovery_sync()
6017 static int hci_update_event_filter_sync(struct hci_dev *hdev) in hci_update_event_filter_sync() argument
6021 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_update_event_filter_sync()
6024 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_event_filter_sync()
6030 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_update_event_filter_sync()
6034 hci_clear_event_filter_sync(hdev); in hci_update_event_filter_sync()
6036 list_for_each_entry(b, &hdev->accept_list, list) { in hci_update_event_filter_sync()
6040 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_update_event_filter_sync()
6042 err = hci_set_event_filter_sync(hdev, HCI_FLT_CONN_SETUP, in hci_update_event_filter_sync()
6047 bt_dev_dbg(hdev, "Failed to set event filter for %pMR", in hci_update_event_filter_sync()
6054 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
6056 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
6062 static int hci_pause_scan_sync(struct hci_dev *hdev) in hci_pause_scan_sync() argument
6064 if (hdev->scanning_paused) in hci_pause_scan_sync()
6068 if (test_bit(HCI_PSCAN, &hdev->flags)) in hci_pause_scan_sync()
6069 hci_write_scan_enable_sync(hdev, SCAN_DISABLED); in hci_pause_scan_sync()
6071 hci_scan_disable_sync(hdev); in hci_pause_scan_sync()
6073 hdev->scanning_paused = true; in hci_pause_scan_sync()
6091 int hci_suspend_sync(struct hci_dev *hdev) in hci_suspend_sync() argument
6096 if (hdev->suspended) in hci_suspend_sync()
6100 hdev->suspended = true; in hci_suspend_sync()
6103 hci_pause_discovery_sync(hdev); in hci_suspend_sync()
6106 hci_pause_advertising_sync(hdev); in hci_suspend_sync()
6109 hci_suspend_monitor_sync(hdev); in hci_suspend_sync()
6112 hci_pause_scan_sync(hdev); in hci_suspend_sync()
6114 if (hci_conn_count(hdev)) { in hci_suspend_sync()
6116 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_suspend_sync()
6119 hdev->suspend_state = BT_RUNNING; in hci_suspend_sync()
6120 hci_resume_sync(hdev); in hci_suspend_sync()
6127 hci_set_event_mask_sync(hdev); in hci_suspend_sync()
6133 if (!hdev->wakeup || !hdev->wakeup(hdev)) { in hci_suspend_sync()
6134 hdev->suspend_state = BT_SUSPEND_DISCONNECT; in hci_suspend_sync()
6139 hdev->scanning_paused = false; in hci_suspend_sync()
6142 hci_update_event_filter_sync(hdev); in hci_suspend_sync()
6145 hci_update_passive_scan_sync(hdev); in hci_suspend_sync()
6148 hdev->scanning_paused = true; in hci_suspend_sync()
6150 hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; in hci_suspend_sync()
6156 static int hci_resume_discovery_sync(struct hci_dev *hdev) in hci_resume_discovery_sync() argument
6161 if (!hdev->discovery_paused) in hci_resume_discovery_sync()
6164 hdev->discovery_paused = false; in hci_resume_discovery_sync()
6166 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_resume_discovery_sync()
6168 err = hci_start_discovery_sync(hdev); in hci_resume_discovery_sync()
6170 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED : in hci_resume_discovery_sync()
6176 static void hci_resume_monitor_sync(struct hci_dev *hdev) in hci_resume_monitor_sync() argument
6178 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_resume_monitor_sync()
6180 msft_resume_sync(hdev); in hci_resume_monitor_sync()
6188 static int hci_resume_scan_sync(struct hci_dev *hdev) in hci_resume_scan_sync() argument
6190 if (!hdev->scanning_paused) in hci_resume_scan_sync()
6193 hdev->scanning_paused = false; in hci_resume_scan_sync()
6195 hci_update_scan_sync(hdev); in hci_resume_scan_sync()
6198 hci_update_passive_scan_sync(hdev); in hci_resume_scan_sync()
6211 int hci_resume_sync(struct hci_dev *hdev) in hci_resume_sync() argument
6214 if (!hdev->suspended) in hci_resume_sync()
6217 hdev->suspended = false; in hci_resume_sync()
6220 hci_set_event_mask_sync(hdev); in hci_resume_sync()
6223 hci_clear_event_filter_sync(hdev); in hci_resume_sync()
6226 hci_resume_scan_sync(hdev); in hci_resume_sync()
6229 hci_resume_monitor_sync(hdev); in hci_resume_sync()
6232 hci_resume_advertising_sync(hdev); in hci_resume_sync()
6235 hci_resume_discovery_sync(hdev); in hci_resume_sync()
6242 struct hci_dev *hdev = conn->hdev; in conn_use_rpa() local
6244 return hci_dev_test_flag(hdev, HCI_PRIVACY); in conn_use_rpa()
6247 static int hci_le_ext_directed_advertising_sync(struct hci_dev *hdev, in hci_le_ext_directed_advertising_sync() argument
6255 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_ext_directed_advertising_sync()
6263 err = hci_get_random_address(hdev, false, conn_use_rpa(conn), NULL, in hci_le_ext_directed_advertising_sync()
6271 cp.channel_map = hdev->le_adv_channel_map; in hci_le_ext_directed_advertising_sync()
6288 err = hci_remove_ext_adv_instance_sync(hdev, cp.handle, NULL); in hci_le_ext_directed_advertising_sync()
6292 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_le_ext_directed_advertising_sync()
6300 bacmp(&random_addr, &hdev->random_addr)) { in hci_le_ext_directed_advertising_sync()
6301 err = hci_set_adv_set_random_addr_sync(hdev, 0x00, in hci_le_ext_directed_advertising_sync()
6307 return hci_enable_ext_advertising_sync(hdev, 0x00); in hci_le_ext_directed_advertising_sync()
6310 static int hci_le_directed_advertising_sync(struct hci_dev *hdev, in hci_le_directed_advertising_sync() argument
6318 if (ext_adv_capable(hdev)) in hci_le_directed_advertising_sync()
6319 return hci_le_ext_directed_advertising_sync(hdev, conn); in hci_le_directed_advertising_sync()
6326 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_le_directed_advertising_sync()
6331 status = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_directed_advertising_sync()
6349 cp.channel_map = hdev->le_adv_channel_map; in hci_le_directed_advertising_sync()
6351 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_le_directed_advertising_sync()
6358 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_le_directed_advertising_sync()
6365 struct hci_dev *hdev = conn->hdev; in set_ext_conn_params() local
6369 p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in set_ext_conn_params()
6370 p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); in set_ext_conn_params()
6379 static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, in hci_le_ext_create_conn_sync() argument
6398 if (scan_1m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_1M || in hci_le_ext_create_conn_sync()
6407 if (scan_2m(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_2M || in hci_le_ext_create_conn_sync()
6416 if (scan_coded(hdev) && (conn->le_adv_phy == HCI_ADV_PHY_CODED || in hci_le_ext_create_conn_sync()
6424 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_EXT_CREATE_CONN, in hci_le_ext_create_conn_sync()
6430 static int hci_le_create_conn_sync(struct hci_dev *hdev, void *data) in hci_le_create_conn_sync() argument
6438 if (!hci_conn_valid(hdev, conn)) in hci_le_create_conn_sync()
6441 bt_dev_dbg(hdev, "conn %p", conn); in hci_le_create_conn_sync()
6451 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in hci_le_create_conn_sync()
6452 hdev->le_scan_type == LE_SCAN_ACTIVE && in hci_le_create_conn_sync()
6453 !hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) { in hci_le_create_conn_sync()
6459 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6461 err = hci_le_directed_advertising_sync(hdev, conn); in hci_le_create_conn_sync()
6466 if (!hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in hci_le_create_conn_sync()
6467 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6469 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_create_conn_sync()
6476 conn->le_conn_min_interval = hdev->le_conn_min_interval; in hci_le_create_conn_sync()
6477 conn->le_conn_max_interval = hdev->le_conn_max_interval; in hci_le_create_conn_sync()
6478 conn->le_conn_latency = hdev->le_conn_latency; in hci_le_create_conn_sync()
6479 conn->le_supv_timeout = hdev->le_supv_timeout; in hci_le_create_conn_sync()
6488 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_le_create_conn_sync()
6489 hci_scan_disable_sync(hdev); in hci_le_create_conn_sync()
6490 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED); in hci_le_create_conn_sync()
6496 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_create_conn_sync()
6501 if (use_ext_conn(hdev)) { in hci_le_create_conn_sync()
6502 err = hci_le_ext_create_conn_sync(hdev, conn, own_addr_type); in hci_le_create_conn_sync()
6508 cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in hci_le_create_conn_sync()
6509 cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); in hci_le_create_conn_sync()
6527 err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CONN, in hci_le_create_conn_sync()
6529 use_enhanced_conn_complete(hdev) ? in hci_le_create_conn_sync()
6536 hci_le_connect_cancel_sync(hdev, conn, 0x00); in hci_le_create_conn_sync()
6539 hci_resume_advertising_sync(hdev); in hci_le_create_conn_sync()
6543 int hci_le_create_cis_sync(struct hci_dev *hdev) in hci_le_create_cis_sync() argument
6573 hci_dev_lock(hdev); in hci_le_create_cis_sync()
6578 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6584 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6592 list_for_each_entry_rcu(link, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6608 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6628 hci_dev_unlock(hdev); in hci_le_create_cis_sync()
6634 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CIS, in hci_le_create_cis_sync()
6640 int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle) in hci_le_remove_cig_sync() argument
6647 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REMOVE_CIG, sizeof(cp), in hci_le_remove_cig_sync()
6651 int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle) in hci_le_big_terminate_sync() argument
6658 return __hci_cmd_sync_status(hdev, HCI_OP_LE_BIG_TERM_SYNC, in hci_le_big_terminate_sync()
6662 int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle) in hci_le_pa_terminate_sync() argument
6669 return __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_TERM_SYNC, in hci_le_pa_terminate_sync()
6673 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
6688 if (ll_privacy_capable(hdev)) in hci_get_random_address()
6697 if (rpa_valid(hdev)) in hci_get_random_address()
6701 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
6703 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
6707 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
6730 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
6746 static int _update_adv_data_sync(struct hci_dev *hdev, void *data) in _update_adv_data_sync() argument
6750 return hci_update_adv_data_sync(hdev, instance); in _update_adv_data_sync()
6753 int hci_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_update_adv_data() argument
6755 return hci_cmd_sync_queue(hdev, _update_adv_data_sync, in hci_update_adv_data()
6759 static int hci_acl_create_conn_sync(struct hci_dev *hdev, void *data) in hci_acl_create_conn_sync() argument
6766 if (!hci_conn_valid(hdev, conn)) in hci_acl_create_conn_sync()
6777 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_acl_create_conn_sync()
6778 err = __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY_CANCEL, 0, in hci_acl_create_conn_sync()
6781 bt_dev_warn(hdev, "Failed to cancel inquiry %d", err); in hci_acl_create_conn_sync()
6790 conn->link_policy = hdev->link_policy; in hci_acl_create_conn_sync()
6796 ie = hci_inquiry_cache_lookup(hdev, &conn->dst); in hci_acl_create_conn_sync()
6809 if (lmp_rswitch_capable(hdev) && !(hdev->link_mode & HCI_LM_MASTER)) in hci_acl_create_conn_sync()
6814 return __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN, in hci_acl_create_conn_sync()
6820 int hci_connect_acl_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_connect_acl_sync() argument
6822 return hci_cmd_sync_queue_once(hdev, hci_acl_create_conn_sync, conn, in hci_connect_acl_sync()
6826 static void create_le_conn_complete(struct hci_dev *hdev, void *data, int err) in create_le_conn_complete() argument
6830 bt_dev_dbg(hdev, "err %d", err); in create_le_conn_complete()
6835 hci_dev_lock(hdev); in create_le_conn_complete()
6837 if (!hci_conn_valid(hdev, conn)) in create_le_conn_complete()
6846 if (conn != hci_lookup_le_connect(hdev)) in create_le_conn_complete()
6854 hci_dev_unlock(hdev); in create_le_conn_complete()
6857 int hci_connect_le_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_connect_le_sync() argument
6859 return hci_cmd_sync_queue_once(hdev, hci_le_create_conn_sync, conn, in hci_connect_le_sync()
6863 int hci_cancel_connect_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_cancel_connect_sync() argument
6870 return !hci_cmd_sync_dequeue_once(hdev, in hci_cancel_connect_sync()
6874 return !hci_cmd_sync_dequeue_once(hdev, hci_le_create_conn_sync, in hci_cancel_connect_sync()
6881 int hci_le_conn_update_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_le_conn_update_sync() argument
6895 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CONN_UPDATE, in hci_le_conn_update_sync()
6899 static void create_pa_complete(struct hci_dev *hdev, void *data, int err) in create_pa_complete() argument
6901 bt_dev_dbg(hdev, "err %d", err); in create_pa_complete()
6906 hci_dev_clear_flag(hdev, HCI_PA_SYNC); in create_pa_complete()
6911 hci_dev_lock(hdev); in create_pa_complete()
6913 hci_update_passive_scan_sync(hdev); in create_pa_complete()
6915 hci_dev_unlock(hdev); in create_pa_complete()
6918 static int hci_le_pa_create_sync(struct hci_dev *hdev, void *data) in hci_le_pa_create_sync() argument
6925 if (!hci_conn_valid(hdev, conn)) in hci_le_pa_create_sync()
6928 if (hci_dev_test_and_set_flag(hdev, HCI_PA_SYNC)) in hci_le_pa_create_sync()
6937 hci_update_passive_scan_sync(hdev); in hci_le_pa_create_sync()
6959 err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_PA_CREATE_SYNC, in hci_le_pa_create_sync()
6964 __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_CREATE_SYNC_CANCEL, in hci_le_pa_create_sync()
6970 int hci_connect_pa_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_connect_pa_sync() argument
6972 return hci_cmd_sync_queue_once(hdev, hci_le_pa_create_sync, conn, in hci_connect_pa_sync()
6976 static void create_big_complete(struct hci_dev *hdev, void *data, int err) in create_big_complete() argument
6980 bt_dev_dbg(hdev, "err %d", err); in create_big_complete()
6985 if (hci_conn_valid(hdev, conn)) in create_big_complete()
6989 static int hci_le_big_create_sync(struct hci_dev *hdev, void *data) in hci_le_big_create_sync() argument
6996 if (!hci_conn_valid(hdev, conn)) in hci_le_big_create_sync()
7023 err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_BIG_CREATE_SYNC, in hci_le_big_create_sync()
7028 hci_le_big_terminate_sync(hdev, cp->handle); in hci_le_big_create_sync()
7033 int hci_connect_big_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_connect_big_sync() argument
7035 return hci_cmd_sync_queue_once(hdev, hci_le_big_create_sync, conn, in hci_connect_big_sync()