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()
41 hdev->req_skb = skb_get(skb); in hci_cmd_sync_complete()
44 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_complete()
47 static struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, in hci_cmd_sync_alloc() argument
66 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_cmd_sync_alloc()
85 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_add() local
88 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync_add()
96 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, sk); in hci_cmd_sync_add()
98 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_cmd_sync_add()
114 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_run() local
118 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in hci_cmd_sync_run()
136 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
137 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in hci_cmd_sync_run()
138 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
140 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_sync_run()
146 struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_sk() argument
154 bt_dev_dbg(hdev, "Opcode 0x%4x", opcode); in __hci_cmd_sync_sk()
156 hci_req_init(&req, hdev); in __hci_cmd_sync_sk()
160 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_sk()
166 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_sk()
167 hdev->req_status != HCI_REQ_PEND, in __hci_cmd_sync_sk()
173 switch (hdev->req_status) { in __hci_cmd_sync_sk()
175 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_sk()
179 err = -hdev->req_result; in __hci_cmd_sync_sk()
187 hdev->req_status = 0; in __hci_cmd_sync_sk()
188 hdev->req_result = 0; in __hci_cmd_sync_sk()
189 skb = hdev->req_skb; in __hci_cmd_sync_sk()
190 hdev->req_skb = NULL; in __hci_cmd_sync_sk()
192 bt_dev_dbg(hdev, "end: err %d", err); in __hci_cmd_sync_sk()
204 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync() argument
207 return __hci_cmd_sync_sk(hdev, opcode, plen, param, 0, timeout, NULL); in __hci_cmd_sync()
212 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync() argument
217 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
220 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync()
222 hci_req_sync_lock(hdev); in hci_cmd_sync()
223 skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout); in hci_cmd_sync()
224 hci_req_sync_unlock(hdev); in hci_cmd_sync()
231 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_ev() argument
234 return __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, in __hci_cmd_sync_ev()
240 int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status_sk() argument
247 skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk); in __hci_cmd_sync_status_sk()
249 bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode, in __hci_cmd_sync_status_sk()
269 int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status() argument
272 return __hci_cmd_sync_status_sk(hdev, opcode, plen, param, 0, timeout, in __hci_cmd_sync_status()
279 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_work); in hci_cmd_sync_work() local
281 bt_dev_dbg(hdev, ""); in hci_cmd_sync_work()
287 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
288 entry = list_first_entry_or_null(&hdev->cmd_sync_work_list, in hci_cmd_sync_work()
293 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
298 bt_dev_dbg(hdev, "entry %p", entry); in hci_cmd_sync_work()
303 hci_req_sync_lock(hdev); in hci_cmd_sync_work()
304 err = entry->func(hdev, entry->data); in hci_cmd_sync_work()
306 entry->destroy(hdev, entry->data, err); in hci_cmd_sync_work()
307 hci_req_sync_unlock(hdev); in hci_cmd_sync_work()
316 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_cancel_work); in hci_cmd_sync_cancel_work() local
318 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cmd_sync_cancel_work()
319 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cmd_sync_cancel_work()
320 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_sync_cancel_work()
322 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_work()
325 static int hci_scan_disable_sync(struct hci_dev *hdev);
326 static int scan_disable_sync(struct hci_dev *hdev, void *data) in scan_disable_sync() argument
328 return hci_scan_disable_sync(hdev); in scan_disable_sync()
331 static int hci_inquiry_sync(struct hci_dev *hdev, u8 length);
332 static int interleaved_inquiry_sync(struct hci_dev *hdev, void *data) in interleaved_inquiry_sync() argument
334 return hci_inquiry_sync(hdev, DISCOV_INTERLEAVED_INQUIRY_LEN); in interleaved_inquiry_sync()
339 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable() local
343 bt_dev_dbg(hdev, ""); in le_scan_disable()
344 hci_dev_lock(hdev); in le_scan_disable()
346 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_disable()
349 cancel_delayed_work(&hdev->le_scan_restart); in le_scan_disable()
351 status = hci_cmd_sync_queue(hdev, scan_disable_sync, NULL, NULL); in le_scan_disable()
353 bt_dev_err(hdev, "failed to disable LE scan: %d", status); in le_scan_disable()
357 hdev->discovery.scan_start = 0; in le_scan_disable()
367 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable()
370 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable()
373 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable()
374 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable()
375 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable()
381 status = hci_cmd_sync_queue(hdev, interleaved_inquiry_sync, NULL, NULL); in le_scan_disable()
383 bt_dev_err(hdev, "inquiry failed: status %d", status); in le_scan_disable()
390 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in le_scan_disable()
393 hci_dev_unlock(hdev); in le_scan_disable()
396 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val,
398 static int hci_le_scan_restart_sync(struct hci_dev *hdev) in hci_le_scan_restart_sync() argument
401 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_le_scan_restart_sync()
404 if (hdev->scanning_paused) { in hci_le_scan_restart_sync()
405 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_le_scan_restart_sync()
409 hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_le_scan_restart_sync()
410 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, in hci_le_scan_restart_sync()
414 static int le_scan_restart_sync(struct hci_dev *hdev, void *data) in le_scan_restart_sync() argument
416 return hci_le_scan_restart_sync(hdev); in le_scan_restart_sync()
421 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_restart() local
426 bt_dev_dbg(hdev, ""); in le_scan_restart()
428 hci_dev_lock(hdev); in le_scan_restart()
430 status = hci_cmd_sync_queue(hdev, le_scan_restart_sync, NULL, NULL); in le_scan_restart()
432 bt_dev_err(hdev, "failed to restart LE scan: status %d", in le_scan_restart()
437 if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) || in le_scan_restart()
438 !hdev->discovery.scan_start) in le_scan_restart()
446 duration = hdev->discovery.scan_duration; in le_scan_restart()
447 scan_start = hdev->discovery.scan_start; in le_scan_restart()
462 queue_delayed_work(hdev->req_workqueue, in le_scan_restart()
463 &hdev->le_scan_disable, timeout); in le_scan_restart()
466 hci_dev_unlock(hdev); in le_scan_restart()
469 static int reenable_adv_sync(struct hci_dev *hdev, void *data) in reenable_adv_sync() argument
471 bt_dev_dbg(hdev, ""); in reenable_adv_sync()
473 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in reenable_adv_sync()
474 list_empty(&hdev->adv_instances)) in reenable_adv_sync()
477 if (hdev->cur_adv_instance) { in reenable_adv_sync()
478 return hci_schedule_adv_instance_sync(hdev, in reenable_adv_sync()
479 hdev->cur_adv_instance, in reenable_adv_sync()
482 if (ext_adv_capable(hdev)) { in reenable_adv_sync()
483 hci_start_ext_adv_sync(hdev, 0x00); in reenable_adv_sync()
485 hci_update_adv_data_sync(hdev, 0x00); in reenable_adv_sync()
486 hci_update_scan_rsp_data_sync(hdev, 0x00); in reenable_adv_sync()
487 hci_enable_advertising_sync(hdev); in reenable_adv_sync()
496 struct hci_dev *hdev = container_of(work, struct hci_dev, in reenable_adv() local
500 bt_dev_dbg(hdev, ""); in reenable_adv()
502 hci_dev_lock(hdev); in reenable_adv()
504 status = hci_cmd_sync_queue(hdev, reenable_adv_sync, NULL, NULL); in reenable_adv()
506 bt_dev_err(hdev, "failed to reenable ADV: %d", status); in reenable_adv()
508 hci_dev_unlock(hdev); in reenable_adv()
511 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
513 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
514 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
515 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
530 int hci_clear_adv_instance_sync(struct hci_dev *hdev, struct sock *sk, in hci_clear_adv_instance_sync() argument
538 if (!instance || hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
539 cancel_adv_timeout(hdev); in hci_clear_adv_instance_sync()
545 if (instance && hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
546 next_instance = hci_get_next_instance(hdev, instance); in hci_clear_adv_instance_sync()
549 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_clear_adv_instance_sync()
555 err = hci_remove_adv_instance(hdev, rem_inst); in hci_clear_adv_instance_sync()
557 mgmt_advertising_removed(sk, hdev, rem_inst); in hci_clear_adv_instance_sync()
560 adv_instance = hci_find_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
569 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
571 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_instance_sync()
575 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_clear_adv_instance_sync()
578 if (next_instance && !ext_adv_capable(hdev)) in hci_clear_adv_instance_sync()
579 return hci_schedule_adv_instance_sync(hdev, in hci_clear_adv_instance_sync()
586 static int adv_timeout_expire_sync(struct hci_dev *hdev, void *data) in adv_timeout_expire_sync() argument
592 hci_clear_adv_instance_sync(hdev, NULL, instance, false); in adv_timeout_expire_sync()
594 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire_sync()
595 return hci_disable_advertising_sync(hdev); in adv_timeout_expire_sync()
603 struct hci_dev *hdev = container_of(work, struct hci_dev, in adv_timeout_expire() local
606 bt_dev_dbg(hdev, ""); in adv_timeout_expire()
608 hci_dev_lock(hdev); in adv_timeout_expire()
610 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
612 if (hdev->cur_adv_instance == 0x00) in adv_timeout_expire()
619 *inst_ptr = hdev->cur_adv_instance; in adv_timeout_expire()
620 hci_cmd_sync_queue(hdev, adv_timeout_expire_sync, inst_ptr, NULL); in adv_timeout_expire()
623 hci_dev_unlock(hdev); in adv_timeout_expire()
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()
632 INIT_WORK(&hdev->cmd_sync_cancel_work, hci_cmd_sync_cancel_work); in hci_cmd_sync_init()
633 INIT_WORK(&hdev->reenable_adv_work, reenable_adv); in hci_cmd_sync_init()
634 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable); in hci_cmd_sync_init()
635 INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart); in hci_cmd_sync_init()
636 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_cmd_sync_init()
639 void hci_cmd_sync_clear(struct hci_dev *hdev) in hci_cmd_sync_clear() argument
643 cancel_work_sync(&hdev->cmd_sync_work); in hci_cmd_sync_clear()
644 cancel_work_sync(&hdev->reenable_adv_work); in hci_cmd_sync_clear()
646 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) { in hci_cmd_sync_clear()
648 entry->destroy(hdev, entry->data, -ECANCELED); in hci_cmd_sync_clear()
655 void __hci_cmd_sync_cancel(struct hci_dev *hdev, int err) in __hci_cmd_sync_cancel() argument
657 bt_dev_dbg(hdev, "err 0x%2.2x", err); in __hci_cmd_sync_cancel()
659 if (hdev->req_status == HCI_REQ_PEND) { in __hci_cmd_sync_cancel()
660 hdev->req_result = err; in __hci_cmd_sync_cancel()
661 hdev->req_status = HCI_REQ_CANCELED; in __hci_cmd_sync_cancel()
663 cancel_delayed_work_sync(&hdev->cmd_timer); in __hci_cmd_sync_cancel()
664 cancel_delayed_work_sync(&hdev->ncmd_timer); in __hci_cmd_sync_cancel()
665 atomic_set(&hdev->cmd_cnt, 1); in __hci_cmd_sync_cancel()
667 wake_up_interruptible(&hdev->req_wait_q); in __hci_cmd_sync_cancel()
671 void hci_cmd_sync_cancel(struct hci_dev *hdev, int err) in hci_cmd_sync_cancel() argument
673 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_cmd_sync_cancel()
675 if (hdev->req_status == HCI_REQ_PEND) { in hci_cmd_sync_cancel()
676 hdev->req_result = err; in hci_cmd_sync_cancel()
677 hdev->req_status = HCI_REQ_CANCELED; in hci_cmd_sync_cancel()
679 queue_work(hdev->workqueue, &hdev->cmd_sync_cancel_work); in hci_cmd_sync_cancel()
684 int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_queue() argument
689 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_cmd_sync_queue()
700 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_queue()
701 list_add_tail(&entry->list, &hdev->cmd_sync_work_list); in hci_cmd_sync_queue()
702 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_queue()
704 queue_work(hdev->req_workqueue, &hdev->cmd_sync_work); in hci_cmd_sync_queue()
710 int hci_update_eir_sync(struct hci_dev *hdev) in hci_update_eir_sync() argument
714 bt_dev_dbg(hdev, ""); in hci_update_eir_sync()
716 if (!hdev_is_powered(hdev)) in hci_update_eir_sync()
719 if (!lmp_ext_inq_capable(hdev)) in hci_update_eir_sync()
722 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_update_eir_sync()
725 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_eir_sync()
730 eir_create(hdev, cp.data); in hci_update_eir_sync()
732 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in hci_update_eir_sync()
735 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in hci_update_eir_sync()
737 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_update_eir_sync()
741 static u8 get_service_classes(struct hci_dev *hdev) in get_service_classes() argument
746 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
752 int hci_update_class_sync(struct hci_dev *hdev) in hci_update_class_sync() argument
756 bt_dev_dbg(hdev, ""); in hci_update_class_sync()
758 if (!hdev_is_powered(hdev)) in hci_update_class_sync()
761 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_class_sync()
764 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_class_sync()
767 cod[0] = hdev->minor_class; in hci_update_class_sync()
768 cod[1] = hdev->major_class; in hci_update_class_sync()
769 cod[2] = get_service_classes(hdev); in hci_update_class_sync()
771 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_update_class_sync()
774 if (memcmp(cod, hdev->dev_class, 3) == 0) in hci_update_class_sync()
777 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CLASS_OF_DEV, in hci_update_class_sync()
781 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) in is_advertising_allowed() argument
784 if (hci_conn_num(hdev, LE_LINK) == 0) in is_advertising_allowed()
788 if (hdev->conn_hash.le_num_peripheral > 0) { in is_advertising_allowed()
792 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
798 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
799 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
804 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_peripheral) { in is_advertising_allowed()
806 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
812 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
813 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
820 static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags) in adv_use_rpa() argument
823 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in adv_use_rpa()
827 if (!hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in adv_use_rpa()
834 hci_dev_test_flag(hdev, HCI_BONDABLE)) in adv_use_rpa()
843 static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa) in hci_set_random_addr_sync() argument
855 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in hci_set_random_addr_sync()
856 hci_lookup_le_connect(hdev)) { in hci_set_random_addr_sync()
857 bt_dev_dbg(hdev, "Deferring random address update"); in hci_set_random_addr_sync()
858 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_set_random_addr_sync()
862 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RANDOM_ADDR, in hci_set_random_addr_sync()
866 int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy, in hci_update_random_address_sync() argument
879 if (use_ll_privacy(hdev)) in hci_update_random_address_sync()
885 if (rpa_valid(hdev)) in hci_update_random_address_sync()
888 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address_sync()
890 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address_sync()
894 err = hci_set_random_addr_sync(hdev, &hdev->rpa); in hci_update_random_address_sync()
919 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address_sync()
925 return hci_set_random_addr_sync(hdev, &nrpa); in hci_update_random_address_sync()
937 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address_sync()
938 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address_sync()
939 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address_sync()
940 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address_sync()
942 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address_sync()
943 return hci_set_random_addr_sync(hdev, in hci_update_random_address_sync()
944 &hdev->static_addr); in hci_update_random_address_sync()
956 static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_disable_ext_adv_instance_sync() argument
967 adv = hci_find_adv_instance(hdev, instance); in hci_disable_ext_adv_instance_sync()
989 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_disable_ext_adv_instance_sync()
993 static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, in hci_set_adv_set_random_addr_sync() argument
1005 err = hci_set_random_addr_sync(hdev, random_addr); in hci_set_adv_set_random_addr_sync()
1015 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, in hci_set_adv_set_random_addr_sync()
1019 int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_setup_ext_adv_instance_sync() argument
1031 adv = hci_find_adv_instance(hdev, instance); in hci_setup_ext_adv_instance_sync()
1043 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_setup_ext_adv_instance_sync()
1048 flags = hci_adv_instance_flags(hdev, instance); in hci_setup_ext_adv_instance_sync()
1054 mgmt_get_connectable(hdev); in hci_setup_ext_adv_instance_sync()
1056 if (!is_advertising_allowed(hdev, connectable)) in hci_setup_ext_adv_instance_sync()
1063 err = hci_get_random_address(hdev, !connectable, in hci_setup_ext_adv_instance_sync()
1064 adv_use_rpa(hdev, flags), adv, in hci_setup_ext_adv_instance_sync()
1076 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1077 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1088 } else if (hci_adv_instance_is_scannable(hdev, instance) || in hci_setup_ext_adv_instance_sync()
1109 hci_copy_identity_address(hdev, &cp.peer_addr, in hci_setup_ext_adv_instance_sync()
1113 cp.channel_map = hdev->le_adv_channel_map; in hci_setup_ext_adv_instance_sync()
1128 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_setup_ext_adv_instance_sync()
1141 if (!bacmp(&random_addr, &hdev->random_addr)) in hci_setup_ext_adv_instance_sync()
1145 return hci_set_adv_set_random_addr_sync(hdev, instance, in hci_setup_ext_adv_instance_sync()
1152 static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_scan_rsp_data_sync() argument
1165 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_scan_rsp_data_sync()
1170 len = eir_create_scan_rsp(hdev, instance, pdu.data); in hci_set_ext_scan_rsp_data_sync()
1177 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA, in hci_set_ext_scan_rsp_data_sync()
1186 memcpy(hdev->scan_rsp_data, pdu.data, len); in hci_set_ext_scan_rsp_data_sync()
1187 hdev->scan_rsp_data_len = len; in hci_set_ext_scan_rsp_data_sync()
1193 static int __hci_set_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in __hci_set_scan_rsp_data_sync() argument
1200 len = eir_create_scan_rsp(hdev, instance, cp.data); in __hci_set_scan_rsp_data_sync()
1202 if (hdev->scan_rsp_data_len == len && in __hci_set_scan_rsp_data_sync()
1203 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_set_scan_rsp_data_sync()
1206 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_set_scan_rsp_data_sync()
1207 hdev->scan_rsp_data_len = len; in __hci_set_scan_rsp_data_sync()
1211 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_RSP_DATA, in __hci_set_scan_rsp_data_sync()
1215 int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_scan_rsp_data_sync() argument
1217 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_rsp_data_sync()
1220 if (ext_adv_capable(hdev)) in hci_update_scan_rsp_data_sync()
1221 return hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1223 return __hci_set_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1226 int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_ext_advertising_sync() argument
1234 adv = hci_find_adv_instance(hdev, instance); in hci_enable_ext_advertising_sync()
1266 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_enable_ext_advertising_sync()
1272 int hci_start_ext_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_ext_adv_sync() argument
1276 err = hci_setup_ext_adv_instance_sync(hdev, instance); in hci_start_ext_adv_sync()
1280 err = hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_start_ext_adv_sync()
1284 return hci_enable_ext_advertising_sync(hdev, instance); in hci_start_ext_adv_sync()
1287 static int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_disable_per_advertising_sync() argument
1292 if (!hci_dev_test_flag(hdev, HCI_LE_PER_ADV)) in hci_disable_per_advertising_sync()
1300 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_disable_per_advertising_sync()
1304 static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, in hci_set_per_adv_params_sync() argument
1322 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS, in hci_set_per_adv_params_sync()
1326 static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_per_adv_data_sync() argument
1337 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_set_per_adv_data_sync()
1343 len = eir_create_per_adv_data(hdev, instance, pdu.data); in hci_set_per_adv_data_sync()
1349 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_DATA, in hci_set_per_adv_data_sync()
1354 static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_per_advertising_sync() argument
1359 if (hci_dev_test_flag(hdev, HCI_LE_PER_ADV)) in hci_enable_per_advertising_sync()
1367 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_enable_per_advertising_sync()
1374 static int hci_adv_bcast_annoucement(struct hci_dev *hdev, struct adv_info *adv) in hci_adv_bcast_annoucement() argument
1404 hci_set_adv_instance_data(hdev, adv->instance, sizeof(ad), ad, 0, NULL); in hci_adv_bcast_annoucement()
1406 return hci_update_adv_data_sync(hdev, adv->instance); in hci_adv_bcast_annoucement()
1409 int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len, in hci_start_per_adv_sync() argument
1417 hci_disable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1420 adv = hci_find_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1423 adv = hci_add_per_instance(hdev, instance, flags, in hci_start_per_adv_sync()
1437 err = hci_start_ext_adv_sync(hdev, instance); in hci_start_per_adv_sync()
1441 err = hci_adv_bcast_annoucement(hdev, adv); in hci_start_per_adv_sync()
1446 err = hci_set_per_adv_params_sync(hdev, instance, min_interval, in hci_start_per_adv_sync()
1451 err = hci_set_per_adv_data_sync(hdev, instance); in hci_start_per_adv_sync()
1455 err = hci_enable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1463 hci_remove_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1468 static int hci_start_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_adv_sync() argument
1472 if (ext_adv_capable(hdev)) in hci_start_adv_sync()
1473 return hci_start_ext_adv_sync(hdev, instance); in hci_start_adv_sync()
1475 err = hci_update_adv_data_sync(hdev, instance); in hci_start_adv_sync()
1479 err = hci_update_scan_rsp_data_sync(hdev, instance); in hci_start_adv_sync()
1483 return hci_enable_advertising_sync(hdev); in hci_start_adv_sync()
1486 int hci_enable_advertising_sync(struct hci_dev *hdev) in hci_enable_advertising_sync() argument
1496 if (ext_adv_capable(hdev)) in hci_enable_advertising_sync()
1497 return hci_enable_ext_advertising_sync(hdev, in hci_enable_advertising_sync()
1498 hdev->cur_adv_instance); in hci_enable_advertising_sync()
1500 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1501 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1507 mgmt_get_connectable(hdev); in hci_enable_advertising_sync()
1509 if (!is_advertising_allowed(hdev, connectable)) in hci_enable_advertising_sync()
1512 status = hci_disable_advertising_sync(hdev); in hci_enable_advertising_sync()
1521 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_enable_advertising_sync()
1527 status = hci_update_random_address_sync(hdev, !connectable, in hci_enable_advertising_sync()
1528 adv_use_rpa(hdev, flags), in hci_enable_advertising_sync()
1539 adv_min_interval = hdev->le_adv_min_interval; in hci_enable_advertising_sync()
1540 adv_max_interval = hdev->le_adv_max_interval; in hci_enable_advertising_sync()
1546 if (hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance)) in hci_enable_advertising_sync()
1551 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in hci_enable_advertising_sync()
1552 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_enable_advertising_sync()
1561 cp.channel_map = hdev->le_adv_channel_map; in hci_enable_advertising_sync()
1563 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_enable_advertising_sync()
1568 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_enable_advertising_sync()
1572 static int enable_advertising_sync(struct hci_dev *hdev, void *data) in enable_advertising_sync() argument
1574 return hci_enable_advertising_sync(hdev); in enable_advertising_sync()
1577 int hci_enable_advertising(struct hci_dev *hdev) in hci_enable_advertising() argument
1579 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_enable_advertising()
1580 list_empty(&hdev->adv_instances)) in hci_enable_advertising()
1583 return hci_cmd_sync_queue(hdev, enable_advertising_sync, NULL, NULL); in hci_enable_advertising()
1586 int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_remove_ext_adv_instance_sync() argument
1591 if (!ext_adv_capable(hdev)) in hci_remove_ext_adv_instance_sync()
1594 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_remove_ext_adv_instance_sync()
1599 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in hci_remove_ext_adv_instance_sync()
1602 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, in hci_remove_ext_adv_instance_sync()
1607 static int remove_ext_adv_sync(struct hci_dev *hdev, void *data) in remove_ext_adv_sync() argument
1615 return hci_remove_ext_adv_instance_sync(hdev, instance, NULL); in remove_ext_adv_sync()
1618 int hci_remove_ext_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_ext_adv_instance() argument
1623 adv = hci_find_adv_instance(hdev, instance); in hci_remove_ext_adv_instance()
1628 return hci_cmd_sync_queue(hdev, remove_ext_adv_sync, adv, NULL); in hci_remove_ext_adv_instance()
1631 int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) in hci_le_terminate_big_sync() argument
1639 return __hci_cmd_sync_status(hdev, HCI_OP_LE_TERM_BIG, in hci_le_terminate_big_sync()
1643 static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_adv_data_sync() argument
1656 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_adv_data_sync()
1661 len = eir_create_adv_data(hdev, instance, pdu.data); in hci_set_ext_adv_data_sync()
1668 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_DATA, in hci_set_ext_adv_data_sync()
1678 memcpy(hdev->adv_data, pdu.data, len); in hci_set_ext_adv_data_sync()
1679 hdev->adv_data_len = len; in hci_set_ext_adv_data_sync()
1685 static int hci_set_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_adv_data_sync() argument
1692 len = eir_create_adv_data(hdev, instance, cp.data); in hci_set_adv_data_sync()
1695 if (hdev->adv_data_len == len && in hci_set_adv_data_sync()
1696 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_set_adv_data_sync()
1699 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_set_adv_data_sync()
1700 hdev->adv_data_len = len; in hci_set_adv_data_sync()
1704 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_DATA, in hci_set_adv_data_sync()
1708 int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_adv_data_sync() argument
1710 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_adv_data_sync()
1713 if (ext_adv_capable(hdev)) in hci_update_adv_data_sync()
1714 return hci_set_ext_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1716 return hci_set_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1719 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_schedule_adv_instance_sync() argument
1725 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) && !ext_adv_capable(hdev)) in hci_schedule_adv_instance_sync()
1728 if (hdev->adv_instance_timeout) in hci_schedule_adv_instance_sync()
1731 adv = hci_find_adv_instance(hdev, instance); in hci_schedule_adv_instance_sync()
1755 if (!ext_adv_capable(hdev)) { in hci_schedule_adv_instance_sync()
1756 hdev->adv_instance_timeout = timeout; in hci_schedule_adv_instance_sync()
1757 queue_delayed_work(hdev->req_workqueue, in hci_schedule_adv_instance_sync()
1758 &hdev->adv_instance_expire, in hci_schedule_adv_instance_sync()
1766 if (!force && hdev->cur_adv_instance == instance && in hci_schedule_adv_instance_sync()
1767 hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_schedule_adv_instance_sync()
1770 hdev->cur_adv_instance = instance; in hci_schedule_adv_instance_sync()
1772 return hci_start_adv_sync(hdev, instance); in hci_schedule_adv_instance_sync()
1775 static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk) in hci_clear_adv_sets_sync() argument
1779 if (!ext_adv_capable(hdev)) in hci_clear_adv_sets_sync()
1783 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_clear_adv_sets_sync()
1787 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CLEAR_ADV_SETS, in hci_clear_adv_sets_sync()
1791 static int hci_clear_adv_sync(struct hci_dev *hdev, struct sock *sk, bool force) in hci_clear_adv_sync() argument
1796 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1798 err = hci_clear_adv_sets_sync(hdev, sk); in hci_clear_adv_sync()
1799 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1805 hci_dev_lock(hdev); in hci_clear_adv_sync()
1808 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in hci_clear_adv_sync()
1815 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_sync()
1817 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_sync()
1820 hci_dev_unlock(hdev); in hci_clear_adv_sync()
1825 static int hci_remove_adv_sync(struct hci_dev *hdev, u8 instance, in hci_remove_adv_sync() argument
1831 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1832 err = hci_remove_ext_adv_instance_sync(hdev, instance, sk); in hci_remove_adv_sync()
1833 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1839 hci_dev_lock(hdev); in hci_remove_adv_sync()
1841 err = hci_remove_adv_instance(hdev, instance); in hci_remove_adv_sync()
1843 mgmt_advertising_removed(sk, hdev, instance); in hci_remove_adv_sync()
1845 hci_dev_unlock(hdev); in hci_remove_adv_sync()
1861 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, in hci_remove_advertising_sync() argument
1868 if (!instance || hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1869 cancel_adv_timeout(hdev); in hci_remove_advertising_sync()
1875 if (hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1876 next = hci_get_next_instance(hdev, instance); in hci_remove_advertising_sync()
1879 err = hci_clear_adv_sync(hdev, sk, force); in hci_remove_advertising_sync()
1883 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_remove_advertising_sync()
1890 err = hci_remove_adv_sync(hdev, instance, sk); in hci_remove_advertising_sync()
1896 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_remove_advertising_sync()
1899 if (next && !ext_adv_capable(hdev)) in hci_remove_advertising_sync()
1900 hci_schedule_adv_instance_sync(hdev, next->instance, false); in hci_remove_advertising_sync()
1905 int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle) in hci_read_rssi_sync() argument
1910 return __hci_cmd_sync_status(hdev, HCI_OP_READ_RSSI, in hci_read_rssi_sync()
1914 int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp) in hci_read_clock_sync() argument
1916 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLOCK, in hci_read_clock_sync()
1920 int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type) in hci_read_tx_power_sync() argument
1926 return __hci_cmd_sync_status(hdev, HCI_OP_READ_TX_POWER, in hci_read_tx_power_sync()
1930 int hci_disable_advertising_sync(struct hci_dev *hdev) in hci_disable_advertising_sync() argument
1936 if (!hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_disable_advertising_sync()
1939 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
1940 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_disable_advertising_sync()
1941 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
1944 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_disable_advertising_sync()
1948 static int hci_le_set_ext_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_ext_scan_enable_sync() argument
1956 if (hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_ext_scan_enable_sync()
1961 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE, in hci_le_set_ext_scan_enable_sync()
1965 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_scan_enable_sync() argument
1970 if (use_ext_scan(hdev)) in hci_le_set_scan_enable_sync()
1971 return hci_le_set_ext_scan_enable_sync(hdev, val, filter_dup); in hci_le_set_scan_enable_sync()
1976 if (val && hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_scan_enable_sync()
1981 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_ENABLE, in hci_le_set_scan_enable_sync()
1985 static int hci_le_set_addr_resolution_enable_sync(struct hci_dev *hdev, u8 val) in hci_le_set_addr_resolution_enable_sync() argument
1987 if (!use_ll_privacy(hdev)) in hci_le_set_addr_resolution_enable_sync()
1991 if (val == hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_le_set_addr_resolution_enable_sync()
1994 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, in hci_le_set_addr_resolution_enable_sync()
1998 static int hci_scan_disable_sync(struct hci_dev *hdev) in hci_scan_disable_sync() argument
2003 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_scan_disable_sync()
2006 if (hdev->scanning_paused) { in hci_scan_disable_sync()
2007 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_scan_disable_sync()
2011 err = hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_scan_disable_sync()
2013 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_scan_disable_sync()
2020 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
2022 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
2025 static void hci_start_interleave_scan(struct hci_dev *hdev) in hci_start_interleave_scan() argument
2027 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_start_interleave_scan()
2028 queue_delayed_work(hdev->req_workqueue, in hci_start_interleave_scan()
2029 &hdev->interleave_scan, 0); in hci_start_interleave_scan()
2032 static bool is_interleave_scanning(struct hci_dev *hdev) in is_interleave_scanning() argument
2034 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
2037 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
2039 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
2041 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
2043 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
2049 static bool hci_update_interleaved_scan_sync(struct hci_dev *hdev) in hci_update_interleaved_scan_sync() argument
2058 bool use_interleaving = hci_is_adv_monitoring(hdev) && in hci_update_interleaved_scan_sync()
2059 !(list_empty(&hdev->pend_le_conns) && in hci_update_interleaved_scan_sync()
2060 list_empty(&hdev->pend_le_reports)) && in hci_update_interleaved_scan_sync()
2061 hci_get_adv_monitor_offload_ext(hdev) == in hci_update_interleaved_scan_sync()
2063 bool is_interleaving = is_interleave_scanning(hdev); in hci_update_interleaved_scan_sync()
2066 hci_start_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2067 bt_dev_dbg(hdev, "starting interleave scan"); in hci_update_interleaved_scan_sync()
2072 cancel_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2078 static int hci_le_del_resolve_list_sync(struct hci_dev *hdev, in hci_le_del_resolve_list_sync() argument
2084 if (!use_ll_privacy(hdev)) in hci_le_del_resolve_list_sync()
2088 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, in hci_le_del_resolve_list_sync()
2096 return __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST, in hci_le_del_resolve_list_sync()
2100 static int hci_le_del_accept_list_sync(struct hci_dev *hdev, in hci_le_del_accept_list_sync() argument
2107 if (!hci_bdaddr_list_lookup(&hdev->le_accept_list, bdaddr, bdaddr_type)) in hci_le_del_accept_list_sync()
2116 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_del_accept_list_sync()
2118 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST, in hci_le_del_accept_list_sync()
2121 bt_dev_err(hdev, "Unable to remove from allow list: %d", err); in hci_le_del_accept_list_sync()
2125 bt_dev_dbg(hdev, "Remove %pMR (0x%x) from allow list", &cp.bdaddr, in hci_le_del_accept_list_sync()
2134 static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, in hci_le_add_resolve_list_sync() argument
2141 if (!use_ll_privacy(hdev)) in hci_le_add_resolve_list_sync()
2148 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2151 hci_copy_identity_address(hdev, &cp.bdaddr, &cp.bdaddr_type); in hci_le_add_resolve_list_sync()
2152 memcpy(cp.peer_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2156 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2161 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, in hci_le_add_resolve_list_sync()
2175 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2176 memcpy(cp.local_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2180 return __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST, in hci_le_add_resolve_list_sync()
2185 static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev, in hci_le_set_privacy_mode_sync() argument
2202 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_set_privacy_mode_sync()
2211 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PRIVACY_MODE, in hci_le_set_privacy_mode_sync()
2219 static int hci_le_add_accept_list_sync(struct hci_dev *hdev, in hci_le_add_accept_list_sync() argument
2227 if (hdev->suspended && in hci_le_add_accept_list_sync()
2232 if (*num_entries >= hdev->le_accept_list_size) in hci_le_add_accept_list_sync()
2236 if (!use_ll_privacy(hdev) && in hci_le_add_accept_list_sync()
2237 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) in hci_le_add_accept_list_sync()
2244 err = hci_le_add_resolve_list_sync(hdev, params); in hci_le_add_accept_list_sync()
2246 bt_dev_err(hdev, "Unable to add to resolve list: %d", err); in hci_le_add_accept_list_sync()
2251 err = hci_le_set_privacy_mode_sync(hdev, params); in hci_le_add_accept_list_sync()
2253 bt_dev_err(hdev, "Unable to set privacy mode: %d", err); in hci_le_add_accept_list_sync()
2258 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in hci_le_add_accept_list_sync()
2266 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST, in hci_le_add_accept_list_sync()
2269 bt_dev_err(hdev, "Unable to add to allow list: %d", err); in hci_le_add_accept_list_sync()
2271 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_add_accept_list_sync()
2275 bt_dev_dbg(hdev, "Add %pMR (0x%x) to allow list", &cp.bdaddr, in hci_le_add_accept_list_sync()
2282 static int hci_pause_advertising_sync(struct hci_dev *hdev) in hci_pause_advertising_sync() argument
2288 if (hdev->advertising_paused) in hci_pause_advertising_sync()
2291 bt_dev_dbg(hdev, "Pausing directed advertising"); in hci_pause_advertising_sync()
2294 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_pause_advertising_sync()
2301 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_pause_advertising_sync()
2302 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_pause_advertising_sync()
2303 hdev->discov_timeout = 0; in hci_pause_advertising_sync()
2306 bt_dev_dbg(hdev, "Pausing advertising instances"); in hci_pause_advertising_sync()
2311 err = hci_disable_advertising_sync(hdev); in hci_pause_advertising_sync()
2316 if (!ext_adv_capable(hdev)) in hci_pause_advertising_sync()
2317 cancel_adv_timeout(hdev); in hci_pause_advertising_sync()
2319 hdev->advertising_paused = true; in hci_pause_advertising_sync()
2320 hdev->advertising_old_state = old_state; in hci_pause_advertising_sync()
2326 static int hci_resume_advertising_sync(struct hci_dev *hdev) in hci_resume_advertising_sync() argument
2332 if (!hdev->advertising_paused) in hci_resume_advertising_sync()
2336 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2337 if (hdev->advertising_old_state) { in hci_resume_advertising_sync()
2338 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_resume_advertising_sync()
2339 hdev->advertising_old_state = 0; in hci_resume_advertising_sync()
2342 bt_dev_dbg(hdev, "Resuming advertising instances"); in hci_resume_advertising_sync()
2344 if (ext_adv_capable(hdev)) { in hci_resume_advertising_sync()
2346 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) { in hci_resume_advertising_sync()
2347 err = hci_enable_ext_advertising_sync(hdev, in hci_resume_advertising_sync()
2353 hci_remove_ext_adv_instance_sync(hdev, adv->instance, in hci_resume_advertising_sync()
2360 err = hci_schedule_adv_instance_sync(hdev, in hci_resume_advertising_sync()
2361 hdev->cur_adv_instance, in hci_resume_advertising_sync()
2365 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2370 struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, in hci_read_local_oob_data_sync() argument
2376 return __hci_cmd_sync_sk(hdev, opcode, 0, NULL, 0, HCI_CMD_TIMEOUT, sk); in hci_read_local_oob_data_sync()
2396 static u8 hci_update_accept_list_sync(struct hci_dev *hdev) in hci_update_accept_list_sync() argument
2408 if (use_ll_privacy(hdev)) { in hci_update_accept_list_sync()
2409 err = hci_pause_advertising_sync(hdev); in hci_update_accept_list_sync()
2411 bt_dev_err(hdev, "pause advertising failed: %d", err); in hci_update_accept_list_sync()
2420 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_update_accept_list_sync()
2422 bt_dev_err(hdev, "Unable to disable LL privacy: %d", err); in hci_update_accept_list_sync()
2432 list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { in hci_update_accept_list_sync()
2433 if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) in hci_update_accept_list_sync()
2436 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_update_accept_list_sync()
2439 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_update_accept_list_sync()
2447 hci_le_del_accept_list_sync(hdev, &b->bdaddr, in hci_update_accept_list_sync()
2465 list_for_each_entry(params, &hdev->pend_le_conns, action) { in hci_update_accept_list_sync()
2466 err = hci_le_add_accept_list_sync(hdev, params, &num_entries); in hci_update_accept_list_sync()
2475 list_for_each_entry(params, &hdev->pend_le_reports, action) { in hci_update_accept_list_sync()
2476 err = hci_le_add_accept_list_sync(hdev, params, &num_entries); in hci_update_accept_list_sync()
2486 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in hci_update_accept_list_sync()
2487 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE && in hci_update_accept_list_sync()
2488 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in hci_update_accept_list_sync()
2495 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_update_accept_list_sync()
2497 bt_dev_err(hdev, "Unable to enable LL privacy: %d", err); in hci_update_accept_list_sync()
2500 if (use_ll_privacy(hdev)) in hci_update_accept_list_sync()
2501 hci_resume_advertising_sync(hdev); in hci_update_accept_list_sync()
2508 static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev) in hci_is_le_conn_scanning() argument
2510 struct hci_conn_hash *h = &hdev->conn_hash; in hci_is_le_conn_scanning()
2528 static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_ext_scan_param_sync() argument
2545 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_le_set_ext_scan_param_sync()
2556 if (scan_coded(hdev)) { in hci_le_set_ext_scan_param_sync()
2567 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS, in hci_le_set_ext_scan_param_sync()
2572 static int hci_le_set_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_scan_param_sync() argument
2578 if (use_ext_scan(hdev)) in hci_le_set_scan_param_sync()
2579 return hci_le_set_ext_scan_param_sync(hdev, type, interval, in hci_le_set_scan_param_sync()
2590 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_PARAM, in hci_le_set_scan_param_sync()
2594 static int hci_start_scan_sync(struct hci_dev *hdev, u8 type, u16 interval, in hci_start_scan_sync() argument
2600 if (hdev->scanning_paused) { in hci_start_scan_sync()
2601 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_start_scan_sync()
2605 err = hci_le_set_scan_param_sync(hdev, type, interval, window, in hci_start_scan_sync()
2610 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, filter_dup); in hci_start_scan_sync()
2613 static int hci_passive_scan_sync(struct hci_dev *hdev) in hci_passive_scan_sync() argument
2621 if (hdev->scanning_paused) { in hci_passive_scan_sync()
2622 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_passive_scan_sync()
2626 err = hci_scan_disable_sync(hdev); in hci_passive_scan_sync()
2628 bt_dev_err(hdev, "disable scanning failed: %d", err); in hci_passive_scan_sync()
2638 if (hci_update_random_address_sync(hdev, false, scan_use_rpa(hdev), in hci_passive_scan_sync()
2642 if (hdev->enable_advmon_interleave_scan && in hci_passive_scan_sync()
2643 hci_update_interleaved_scan_sync(hdev)) in hci_passive_scan_sync()
2646 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_passive_scan_sync()
2652 filter_policy = hci_update_accept_list_sync(hdev); in hci_passive_scan_sync()
2663 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_passive_scan_sync()
2664 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_passive_scan_sync()
2667 if (hdev->suspended) { in hci_passive_scan_sync()
2668 window = hdev->le_scan_window_suspend; in hci_passive_scan_sync()
2669 interval = hdev->le_scan_int_suspend; in hci_passive_scan_sync()
2670 } else if (hci_is_le_conn_scanning(hdev)) { in hci_passive_scan_sync()
2671 window = hdev->le_scan_window_connect; in hci_passive_scan_sync()
2672 interval = hdev->le_scan_int_connect; in hci_passive_scan_sync()
2673 } else if (hci_is_adv_monitoring(hdev)) { in hci_passive_scan_sync()
2674 window = hdev->le_scan_window_adv_monitor; in hci_passive_scan_sync()
2675 interval = hdev->le_scan_int_adv_monitor; in hci_passive_scan_sync()
2677 window = hdev->le_scan_window; in hci_passive_scan_sync()
2678 interval = hdev->le_scan_interval; in hci_passive_scan_sync()
2682 if (hci_dev_test_flag(hdev, HCI_MESH)) { in hci_passive_scan_sync()
2687 bt_dev_dbg(hdev, "LE passive scan with acceptlist = %d", filter_policy); in hci_passive_scan_sync()
2689 return hci_start_scan_sync(hdev, LE_SCAN_PASSIVE, interval, window, in hci_passive_scan_sync()
2708 int hci_update_passive_scan_sync(struct hci_dev *hdev) in hci_update_passive_scan_sync() argument
2712 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan_sync()
2713 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan_sync()
2714 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan_sync()
2715 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan_sync()
2716 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan_sync()
2717 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan_sync()
2721 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_sync()
2725 if (hdev->discovery.state != DISCOVERY_STOPPED) in hci_update_passive_scan_sync()
2735 hci_discovery_filter_clear(hdev); in hci_update_passive_scan_sync()
2737 bt_dev_dbg(hdev, "ADV monitoring is %s", in hci_update_passive_scan_sync()
2738 hci_is_adv_monitoring(hdev) ? "on" : "off"); in hci_update_passive_scan_sync()
2740 if (!hci_dev_test_flag(hdev, HCI_MESH) && in hci_update_passive_scan_sync()
2741 list_empty(&hdev->pend_le_conns) && in hci_update_passive_scan_sync()
2742 list_empty(&hdev->pend_le_reports) && in hci_update_passive_scan_sync()
2743 !hci_is_adv_monitoring(hdev) && in hci_update_passive_scan_sync()
2744 !hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_update_passive_scan_sync()
2750 bt_dev_dbg(hdev, "stopping background scanning"); in hci_update_passive_scan_sync()
2752 err = hci_scan_disable_sync(hdev); in hci_update_passive_scan_sync()
2754 bt_dev_err(hdev, "stop background scanning failed: %d", in hci_update_passive_scan_sync()
2765 if (hci_lookup_le_connect(hdev)) in hci_update_passive_scan_sync()
2768 bt_dev_dbg(hdev, "start background scanning"); in hci_update_passive_scan_sync()
2770 err = hci_passive_scan_sync(hdev); in hci_update_passive_scan_sync()
2772 bt_dev_err(hdev, "start background scanning failed: %d", in hci_update_passive_scan_sync()
2779 static int update_scan_sync(struct hci_dev *hdev, void *data) in update_scan_sync() argument
2781 return hci_update_scan_sync(hdev); in update_scan_sync()
2784 int hci_update_scan(struct hci_dev *hdev) in hci_update_scan() argument
2786 return hci_cmd_sync_queue(hdev, update_scan_sync, NULL, NULL); in hci_update_scan()
2789 static int update_passive_scan_sync(struct hci_dev *hdev, void *data) in update_passive_scan_sync() argument
2791 return hci_update_passive_scan_sync(hdev); in update_passive_scan_sync()
2794 int hci_update_passive_scan(struct hci_dev *hdev) in hci_update_passive_scan() argument
2797 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan()
2798 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan()
2799 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan()
2800 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan()
2801 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan()
2802 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan()
2805 return hci_cmd_sync_queue(hdev, update_passive_scan_sync, NULL, NULL); in hci_update_passive_scan()
2808 int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val) in hci_write_sc_support_sync() argument
2812 if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev)) in hci_write_sc_support_sync()
2815 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_sync()
2820 hdev->features[1][0] |= LMP_HOST_SC; in hci_write_sc_support_sync()
2821 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
2823 hdev->features[1][0] &= ~LMP_HOST_SC; in hci_write_sc_support_sync()
2824 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
2831 int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) in hci_write_ssp_mode_sync() argument
2835 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_ssp_mode_sync()
2836 lmp_host_ssp_capable(hdev)) in hci_write_ssp_mode_sync()
2839 if (!mode && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) { in hci_write_ssp_mode_sync()
2840 __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in hci_write_ssp_mode_sync()
2844 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_sync()
2849 return hci_write_sc_support_sync(hdev, 0x01); in hci_write_ssp_mode_sync()
2852 int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul) in hci_write_le_host_supported_sync() argument
2856 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in hci_write_le_host_supported_sync()
2857 !lmp_bredr_capable(hdev)) in hci_write_le_host_supported_sync()
2863 if (le == lmp_host_le_capable(hdev) && in hci_write_le_host_supported_sync()
2864 simul == lmp_host_le_br_capable(hdev)) in hci_write_le_host_supported_sync()
2872 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_write_le_host_supported_sync()
2876 static int hci_powered_update_adv_sync(struct hci_dev *hdev) in hci_powered_update_adv_sync() argument
2881 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_powered_update_adv_sync()
2889 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) { in hci_powered_update_adv_sync()
2890 hci_le_add_resolve_list_sync(hdev, NULL); in hci_powered_update_adv_sync()
2891 hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_powered_update_adv_sync()
2898 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_powered_update_adv_sync()
2899 list_empty(&hdev->adv_instances)) { in hci_powered_update_adv_sync()
2900 if (ext_adv_capable(hdev)) { in hci_powered_update_adv_sync()
2901 err = hci_setup_ext_adv_instance_sync(hdev, 0x00); in hci_powered_update_adv_sync()
2903 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
2905 err = hci_update_adv_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
2907 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
2910 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_powered_update_adv_sync()
2911 hci_enable_advertising_sync(hdev); in hci_powered_update_adv_sync()
2915 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) in hci_powered_update_adv_sync()
2916 hci_schedule_adv_instance_sync(hdev, adv->instance, true); in hci_powered_update_adv_sync()
2921 static int hci_write_auth_enable_sync(struct hci_dev *hdev) in hci_write_auth_enable_sync() argument
2925 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in hci_write_auth_enable_sync()
2926 if (link_sec == test_bit(HCI_AUTH, &hdev->flags)) in hci_write_auth_enable_sync()
2929 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE, in hci_write_auth_enable_sync()
2934 int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable) in hci_write_fast_connectable_sync() argument
2940 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_write_fast_connectable_sync()
2943 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_write_fast_connectable_sync()
2954 type = hdev->def_page_scan_type; in hci_write_fast_connectable_sync()
2955 cp.interval = cpu_to_le16(hdev->def_page_scan_int); in hci_write_fast_connectable_sync()
2958 cp.window = cpu_to_le16(hdev->def_page_scan_window); in hci_write_fast_connectable_sync()
2960 if (__cpu_to_le16(hdev->page_scan_interval) != cp.interval || in hci_write_fast_connectable_sync()
2961 __cpu_to_le16(hdev->page_scan_window) != cp.window) { in hci_write_fast_connectable_sync()
2962 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
2969 if (hdev->page_scan_type != type) in hci_write_fast_connectable_sync()
2970 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
2978 static bool disconnected_accept_list_entries(struct hci_dev *hdev) in disconnected_accept_list_entries() argument
2982 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
2985 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
2996 static int hci_write_scan_enable_sync(struct hci_dev *hdev, u8 val) in hci_write_scan_enable_sync() argument
2998 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE, in hci_write_scan_enable_sync()
3003 int hci_update_scan_sync(struct hci_dev *hdev) in hci_update_scan_sync() argument
3007 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_scan_sync()
3010 if (!hdev_is_powered(hdev)) in hci_update_scan_sync()
3013 if (mgmt_powering_down(hdev)) in hci_update_scan_sync()
3016 if (hdev->scanning_paused) in hci_update_scan_sync()
3019 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in hci_update_scan_sync()
3020 disconnected_accept_list_entries(hdev)) in hci_update_scan_sync()
3025 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_update_scan_sync()
3028 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in hci_update_scan_sync()
3029 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in hci_update_scan_sync()
3032 return hci_write_scan_enable_sync(hdev, scan); in hci_update_scan_sync()
3035 int hci_update_name_sync(struct hci_dev *hdev) in hci_update_name_sync() argument
3041 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in hci_update_name_sync()
3043 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME, in hci_update_name_sync()
3059 int hci_powered_update_sync(struct hci_dev *hdev) in hci_powered_update_sync() argument
3068 smp_register(hdev); in hci_powered_update_sync()
3070 err = hci_write_ssp_mode_sync(hdev, 0x01); in hci_powered_update_sync()
3074 err = hci_write_le_host_supported_sync(hdev, 0x01, 0x00); in hci_powered_update_sync()
3078 err = hci_powered_update_adv_sync(hdev); in hci_powered_update_sync()
3082 err = hci_write_auth_enable_sync(hdev); in hci_powered_update_sync()
3086 if (lmp_bredr_capable(hdev)) { in hci_powered_update_sync()
3087 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in hci_powered_update_sync()
3088 hci_write_fast_connectable_sync(hdev, true); in hci_powered_update_sync()
3090 hci_write_fast_connectable_sync(hdev, false); in hci_powered_update_sync()
3091 hci_update_scan_sync(hdev); in hci_powered_update_sync()
3092 hci_update_class_sync(hdev); in hci_powered_update_sync()
3093 hci_update_name_sync(hdev); in hci_powered_update_sync()
3094 hci_update_eir_sync(hdev); in hci_powered_update_sync()
3112 static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) in hci_dev_get_bd_addr_from_property() argument
3114 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
3123 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3127 int (*func)(struct hci_dev *hdev);
3131 static int hci_init_stage_sync(struct hci_dev *hdev, in hci_init_stage_sync() argument
3139 err = stage[i].func(hdev); in hci_init_stage_sync()
3148 static int hci_read_local_version_sync(struct hci_dev *hdev) in hci_read_local_version_sync() argument
3150 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_VERSION, in hci_read_local_version_sync()
3155 static int hci_read_bd_addr_sync(struct hci_dev *hdev) in hci_read_bd_addr_sync() argument
3157 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BD_ADDR, in hci_read_bd_addr_sync()
3174 int hci_reset_sync(struct hci_dev *hdev) in hci_reset_sync() argument
3178 set_bit(HCI_RESET, &hdev->flags); in hci_reset_sync()
3180 err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL, in hci_reset_sync()
3188 static int hci_init0_sync(struct hci_dev *hdev) in hci_init0_sync() argument
3192 bt_dev_dbg(hdev, ""); in hci_init0_sync()
3195 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init0_sync()
3196 err = hci_reset_sync(hdev); in hci_init0_sync()
3201 return hci_init_stage_sync(hdev, hci_init0); in hci_init0_sync()
3204 static int hci_unconf_init_sync(struct hci_dev *hdev) in hci_unconf_init_sync() argument
3208 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_unconf_init_sync()
3211 err = hci_init0_sync(hdev); in hci_unconf_init_sync()
3215 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_unconf_init_sync()
3216 hci_debugfs_create_basic(hdev); in hci_unconf_init_sync()
3222 static int hci_read_local_features_sync(struct hci_dev *hdev) in hci_read_local_features_sync() argument
3225 if (hdev->dev_type == HCI_AMP && !(hdev->commands[14] & 0x20)) in hci_read_local_features_sync()
3228 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_FEATURES, in hci_read_local_features_sync()
3244 static int hci_read_local_cmds_sync(struct hci_dev *hdev) in hci_read_local_cmds_sync() argument
3254 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_read_local_cmds_sync()
3255 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_read_local_cmds_sync()
3256 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_COMMANDS, in hci_read_local_cmds_sync()
3263 static int hci_read_local_amp_info_sync(struct hci_dev *hdev) in hci_read_local_amp_info_sync() argument
3265 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_AMP_INFO, in hci_read_local_amp_info_sync()
3270 static int hci_read_data_block_size_sync(struct hci_dev *hdev) in hci_read_data_block_size_sync() argument
3272 return __hci_cmd_sync_status(hdev, HCI_OP_READ_DATA_BLOCK_SIZE, in hci_read_data_block_size_sync()
3277 static int hci_read_flow_control_mode_sync(struct hci_dev *hdev) in hci_read_flow_control_mode_sync() argument
3279 return __hci_cmd_sync_status(hdev, HCI_OP_READ_FLOW_CONTROL_MODE, in hci_read_flow_control_mode_sync()
3284 static int hci_read_location_data_sync(struct hci_dev *hdev) in hci_read_location_data_sync() argument
3286 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCATION_DATA, in hci_read_location_data_sync()
3306 static int hci_init1_sync(struct hci_dev *hdev) in hci_init1_sync() argument
3310 bt_dev_dbg(hdev, ""); in hci_init1_sync()
3313 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init1_sync()
3314 err = hci_reset_sync(hdev); in hci_init1_sync()
3319 switch (hdev->dev_type) { in hci_init1_sync()
3321 hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_PACKET_BASED; in hci_init1_sync()
3322 return hci_init_stage_sync(hdev, br_init1); in hci_init1_sync()
3324 hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED; in hci_init1_sync()
3325 return hci_init_stage_sync(hdev, amp_init1); in hci_init1_sync()
3327 bt_dev_err(hdev, "Unknown device type %d", hdev->dev_type); in hci_init1_sync()
3341 static int hci_read_buffer_size_sync(struct hci_dev *hdev) in hci_read_buffer_size_sync() argument
3343 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BUFFER_SIZE, in hci_read_buffer_size_sync()
3348 static int hci_read_dev_class_sync(struct hci_dev *hdev) in hci_read_dev_class_sync() argument
3350 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLASS_OF_DEV, in hci_read_dev_class_sync()
3355 static int hci_read_local_name_sync(struct hci_dev *hdev) in hci_read_local_name_sync() argument
3357 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_NAME, in hci_read_local_name_sync()
3362 static int hci_read_voice_setting_sync(struct hci_dev *hdev) in hci_read_voice_setting_sync() argument
3364 return __hci_cmd_sync_status(hdev, HCI_OP_READ_VOICE_SETTING, in hci_read_voice_setting_sync()
3369 static int hci_read_num_supported_iac_sync(struct hci_dev *hdev) in hci_read_num_supported_iac_sync() argument
3371 return __hci_cmd_sync_status(hdev, HCI_OP_READ_NUM_SUPPORTED_IAC, in hci_read_num_supported_iac_sync()
3376 static int hci_read_current_iac_lap_sync(struct hci_dev *hdev) in hci_read_current_iac_lap_sync() argument
3378 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CURRENT_IAC_LAP, in hci_read_current_iac_lap_sync()
3382 static int hci_set_event_filter_sync(struct hci_dev *hdev, u8 flt_type, in hci_set_event_filter_sync() argument
3388 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_set_event_filter_sync()
3391 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_set_event_filter_sync()
3403 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_FLT, in hci_set_event_filter_sync()
3409 static int hci_clear_event_filter_sync(struct hci_dev *hdev) in hci_clear_event_filter_sync() argument
3411 if (!hci_dev_test_flag(hdev, HCI_EVENT_FILTER_CONFIGURED)) in hci_clear_event_filter_sync()
3418 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_clear_event_filter_sync()
3421 return hci_set_event_filter_sync(hdev, HCI_FLT_CLEAR_ALL, 0x00, in hci_clear_event_filter_sync()
3426 static int hci_write_ca_timeout_sync(struct hci_dev *hdev) in hci_write_ca_timeout_sync() argument
3430 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CA_TIMEOUT, in hci_write_ca_timeout_sync()
3455 static int hci_write_ssp_mode_1_sync(struct hci_dev *hdev) in hci_write_ssp_mode_1_sync() argument
3459 if (!lmp_ssp_capable(hdev) || !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_ssp_mode_1_sync()
3468 hdev->max_page = 0x01; in hci_write_ssp_mode_1_sync()
3470 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_1_sync()
3474 static int hci_write_eir_sync(struct hci_dev *hdev) in hci_write_eir_sync() argument
3478 if (!lmp_ssp_capable(hdev) || hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_eir_sync()
3481 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_write_eir_sync()
3484 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_write_eir_sync()
3488 static int hci_write_inquiry_mode_sync(struct hci_dev *hdev) in hci_write_inquiry_mode_sync() argument
3492 if (!lmp_inq_rssi_capable(hdev) && in hci_write_inquiry_mode_sync()
3493 !test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_write_inquiry_mode_sync()
3500 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_write_inquiry_mode_sync()
3502 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_INQUIRY_MODE, in hci_write_inquiry_mode_sync()
3506 static int hci_read_inq_rsp_tx_power_sync(struct hci_dev *hdev) in hci_read_inq_rsp_tx_power_sync() argument
3508 if (!lmp_inq_tx_pwr_capable(hdev)) in hci_read_inq_rsp_tx_power_sync()
3511 return __hci_cmd_sync_status(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, in hci_read_inq_rsp_tx_power_sync()
3515 static int hci_read_local_ext_features_sync(struct hci_dev *hdev, u8 page) in hci_read_local_ext_features_sync() argument
3519 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_sync()
3525 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, in hci_read_local_ext_features_sync()
3529 static int hci_read_local_ext_features_1_sync(struct hci_dev *hdev) in hci_read_local_ext_features_1_sync() argument
3531 return hci_read_local_ext_features_sync(hdev, 0x01); in hci_read_local_ext_features_1_sync()
3554 static int hci_le_read_buffer_size_sync(struct hci_dev *hdev) in hci_le_read_buffer_size_sync() argument
3557 if (hdev->commands[41] & 0x20) in hci_le_read_buffer_size_sync()
3558 return __hci_cmd_sync_status(hdev, in hci_le_read_buffer_size_sync()
3562 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_BUFFER_SIZE, in hci_le_read_buffer_size_sync()
3567 static int hci_le_read_local_features_sync(struct hci_dev *hdev) in hci_le_read_local_features_sync() argument
3569 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_LOCAL_FEATURES, in hci_le_read_local_features_sync()
3574 static int hci_le_read_supported_states_sync(struct hci_dev *hdev) in hci_le_read_supported_states_sync() argument
3576 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_SUPPORTED_STATES, in hci_le_read_supported_states_sync()
3591 static int hci_init2_sync(struct hci_dev *hdev) in hci_init2_sync() argument
3595 bt_dev_dbg(hdev, ""); in hci_init2_sync()
3597 if (hdev->dev_type == HCI_AMP) in hci_init2_sync()
3598 return hci_init_stage_sync(hdev, amp_init2); in hci_init2_sync()
3600 err = hci_init_stage_sync(hdev, hci_init2); in hci_init2_sync()
3604 if (lmp_bredr_capable(hdev)) { in hci_init2_sync()
3605 err = hci_init_stage_sync(hdev, br_init2); in hci_init2_sync()
3609 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_sync()
3612 if (lmp_le_capable(hdev)) { in hci_init2_sync()
3613 err = hci_init_stage_sync(hdev, le_init2); in hci_init2_sync()
3617 if (!lmp_bredr_capable(hdev)) in hci_init2_sync()
3618 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in hci_init2_sync()
3624 static int hci_set_event_mask_sync(struct hci_dev *hdev) in hci_set_event_mask_sync() argument
3635 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_set_event_mask_sync()
3638 if (lmp_bredr_capable(hdev)) { in hci_set_event_mask_sync()
3645 if (hdev->suspended) in hci_set_event_mask_sync()
3658 if (hdev->commands[0] & 0x20) { in hci_set_event_mask_sync()
3663 if (!hdev->suspended) in hci_set_event_mask_sync()
3672 if (hdev->commands[2] & 0x80) in hci_set_event_mask_sync()
3677 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_set_event_mask_sync()
3683 if (lmp_inq_rssi_capable(hdev) || in hci_set_event_mask_sync()
3684 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_set_event_mask_sync()
3687 if (lmp_ext_feat_capable(hdev)) in hci_set_event_mask_sync()
3690 if (lmp_esco_capable(hdev)) { in hci_set_event_mask_sync()
3695 if (lmp_sniffsubr_capable(hdev)) in hci_set_event_mask_sync()
3698 if (lmp_pause_enc_capable(hdev)) in hci_set_event_mask_sync()
3701 if (lmp_ext_inq_capable(hdev)) in hci_set_event_mask_sync()
3704 if (lmp_no_flush_capable(hdev)) in hci_set_event_mask_sync()
3707 if (lmp_lsto_capable(hdev)) in hci_set_event_mask_sync()
3710 if (lmp_ssp_capable(hdev)) { in hci_set_event_mask_sync()
3724 if (lmp_le_capable(hdev)) in hci_set_event_mask_sync()
3727 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK, in hci_set_event_mask_sync()
3731 static int hci_read_stored_link_key_sync(struct hci_dev *hdev) in hci_read_stored_link_key_sync() argument
3735 if (!(hdev->commands[6] & 0x20) || in hci_read_stored_link_key_sync()
3736 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_read_stored_link_key_sync()
3743 return __hci_cmd_sync_status(hdev, HCI_OP_READ_STORED_LINK_KEY, in hci_read_stored_link_key_sync()
3747 static int hci_setup_link_policy_sync(struct hci_dev *hdev) in hci_setup_link_policy_sync() argument
3752 if (!(hdev->commands[5] & 0x10)) in hci_setup_link_policy_sync()
3757 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy_sync()
3759 if (lmp_hold_capable(hdev)) in hci_setup_link_policy_sync()
3761 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy_sync()
3763 if (lmp_park_capable(hdev)) in hci_setup_link_policy_sync()
3768 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, in hci_setup_link_policy_sync()
3772 static int hci_read_page_scan_activity_sync(struct hci_dev *hdev) in hci_read_page_scan_activity_sync() argument
3774 if (!(hdev->commands[8] & 0x01)) in hci_read_page_scan_activity_sync()
3777 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_ACTIVITY, in hci_read_page_scan_activity_sync()
3781 static int hci_read_def_err_data_reporting_sync(struct hci_dev *hdev) in hci_read_def_err_data_reporting_sync() argument
3783 if (!(hdev->commands[18] & 0x04) || in hci_read_def_err_data_reporting_sync()
3784 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_read_def_err_data_reporting_sync()
3785 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_read_def_err_data_reporting_sync()
3788 return __hci_cmd_sync_status(hdev, HCI_OP_READ_DEF_ERR_DATA_REPORTING, in hci_read_def_err_data_reporting_sync()
3792 static int hci_read_page_scan_type_sync(struct hci_dev *hdev) in hci_read_page_scan_type_sync() argument
3798 if (!(hdev->commands[13] & 0x01)) in hci_read_page_scan_type_sync()
3801 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_TYPE, in hci_read_page_scan_type_sync()
3806 static int hci_read_local_ext_features_all_sync(struct hci_dev *hdev) in hci_read_local_ext_features_all_sync() argument
3811 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_all_sync()
3814 for (page = 2; page < HCI_MAX_PAGES && page <= hdev->max_page; in hci_read_local_ext_features_all_sync()
3816 err = hci_read_local_ext_features_sync(hdev, page); in hci_read_local_ext_features_all_sync()
3843 static int hci_le_set_event_mask_sync(struct hci_dev *hdev) in hci_le_set_event_mask_sync() argument
3847 if (!lmp_le_capable(hdev)) in hci_le_set_event_mask_sync()
3852 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_le_set_event_mask_sync()
3858 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_le_set_event_mask_sync()
3865 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_le_set_event_mask_sync()
3871 if (use_enhanced_conn_complete(hdev)) in hci_le_set_event_mask_sync()
3877 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_le_set_event_mask_sync()
3883 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_le_set_event_mask_sync()
3889 if (hdev->commands[26] & 0x08) in hci_le_set_event_mask_sync()
3895 if (hdev->commands[26] & 0x10) in hci_le_set_event_mask_sync()
3901 if (hdev->commands[27] & 0x04) in hci_le_set_event_mask_sync()
3907 if (hdev->commands[27] & 0x20) in hci_le_set_event_mask_sync()
3914 if (hdev->commands[34] & 0x02) in hci_le_set_event_mask_sync()
3921 if (hdev->commands[34] & 0x04) in hci_le_set_event_mask_sync()
3927 if (hdev->commands[35] & (0x20 | 0x40)) in hci_le_set_event_mask_sync()
3934 if (use_ext_scan(hdev)) in hci_le_set_event_mask_sync()
3940 if (ext_adv_capable(hdev)) in hci_le_set_event_mask_sync()
3943 if (cis_capable(hdev)) { in hci_le_set_event_mask_sync()
3945 if (cis_peripheral_capable(hdev)) in hci_le_set_event_mask_sync()
3949 if (bis_capable(hdev)) { in hci_le_set_event_mask_sync()
3956 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EVENT_MASK, in hci_le_set_event_mask_sync()
3961 static int hci_le_read_adv_tx_power_sync(struct hci_dev *hdev) in hci_le_read_adv_tx_power_sync() argument
3963 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_le_read_adv_tx_power_sync()
3970 return __hci_cmd_sync_status(hdev, in hci_le_read_adv_tx_power_sync()
3979 static int hci_le_read_tx_power_sync(struct hci_dev *hdev) in hci_le_read_tx_power_sync() argument
3981 if (!(hdev->commands[38] & 0x80) || in hci_le_read_tx_power_sync()
3982 test_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks)) in hci_le_read_tx_power_sync()
3985 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_TRANSMIT_POWER, in hci_le_read_tx_power_sync()
3990 static int hci_le_read_accept_list_size_sync(struct hci_dev *hdev) in hci_le_read_accept_list_size_sync() argument
3992 if (!(hdev->commands[26] & 0x40)) in hci_le_read_accept_list_size_sync()
3995 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_ACCEPT_LIST_SIZE, in hci_le_read_accept_list_size_sync()
4000 static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) in hci_le_clear_accept_list_sync() argument
4002 if (!(hdev->commands[26] & 0x80)) in hci_le_clear_accept_list_sync()
4005 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_ACCEPT_LIST, 0, NULL, in hci_le_clear_accept_list_sync()
4010 static int hci_le_read_resolv_list_size_sync(struct hci_dev *hdev) in hci_le_read_resolv_list_size_sync() argument
4012 if (!(hdev->commands[34] & 0x40)) in hci_le_read_resolv_list_size_sync()
4015 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_RESOLV_LIST_SIZE, in hci_le_read_resolv_list_size_sync()
4020 static int hci_le_clear_resolv_list_sync(struct hci_dev *hdev) in hci_le_clear_resolv_list_sync() argument
4022 if (!(hdev->commands[34] & 0x20)) in hci_le_clear_resolv_list_sync()
4025 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL, in hci_le_clear_resolv_list_sync()
4030 static int hci_le_set_rpa_timeout_sync(struct hci_dev *hdev) in hci_le_set_rpa_timeout_sync() argument
4032 __le16 timeout = cpu_to_le16(hdev->rpa_timeout); in hci_le_set_rpa_timeout_sync()
4034 if (!(hdev->commands[35] & 0x04)) in hci_le_set_rpa_timeout_sync()
4037 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RPA_TIMEOUT, in hci_le_set_rpa_timeout_sync()
4043 static int hci_le_read_max_data_len_sync(struct hci_dev *hdev) in hci_le_read_max_data_len_sync() argument
4045 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_max_data_len_sync()
4048 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL, in hci_le_read_max_data_len_sync()
4053 static int hci_le_read_def_data_len_sync(struct hci_dev *hdev) in hci_le_read_def_data_len_sync() argument
4055 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_def_data_len_sync()
4058 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_DEF_DATA_LEN, 0, NULL, in hci_le_read_def_data_len_sync()
4063 static int hci_le_read_num_support_adv_sets_sync(struct hci_dev *hdev) in hci_le_read_num_support_adv_sets_sync() argument
4065 if (!ext_adv_capable(hdev)) in hci_le_read_num_support_adv_sets_sync()
4068 return __hci_cmd_sync_status(hdev, in hci_le_read_num_support_adv_sets_sync()
4074 static int hci_set_le_support_sync(struct hci_dev *hdev) in hci_set_le_support_sync() argument
4079 if (!lmp_bredr_capable(hdev)) in hci_set_le_support_sync()
4084 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support_sync()
4089 if (cp.le == lmp_host_le_capable(hdev)) in hci_set_le_support_sync()
4092 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_set_le_support_sync()
4097 static int hci_le_set_host_feature_sync(struct hci_dev *hdev) in hci_le_set_host_feature_sync() argument
4101 if (!iso_capable(hdev)) in hci_le_set_host_feature_sync()
4110 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_HOST_FEATURE, in hci_le_set_host_feature_sync()
4145 static int hci_init3_sync(struct hci_dev *hdev) in hci_init3_sync() argument
4149 bt_dev_dbg(hdev, ""); in hci_init3_sync()
4151 err = hci_init_stage_sync(hdev, hci_init3); in hci_init3_sync()
4155 if (lmp_le_capable(hdev)) in hci_init3_sync()
4156 return hci_init_stage_sync(hdev, le_init3); in hci_init3_sync()
4161 static int hci_delete_stored_link_key_sync(struct hci_dev *hdev) in hci_delete_stored_link_key_sync() argument
4178 if (!(hdev->commands[6] & 0x80) || in hci_delete_stored_link_key_sync()
4179 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_delete_stored_link_key_sync()
4186 return __hci_cmd_sync_status(hdev, HCI_OP_DELETE_STORED_LINK_KEY, in hci_delete_stored_link_key_sync()
4190 static int hci_set_event_mask_page_2_sync(struct hci_dev *hdev) in hci_set_event_mask_page_2_sync() argument
4196 if (!(hdev->commands[22] & 0x04)) in hci_set_event_mask_page_2_sync()
4202 if (lmp_cpb_central_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4213 if (lmp_cpb_peripheral_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4222 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2_sync()
4236 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK_PAGE_2, in hci_set_event_mask_page_2_sync()
4241 static int hci_read_local_codecs_sync(struct hci_dev *hdev) in hci_read_local_codecs_sync() argument
4243 if (hdev->commands[45] & 0x04) in hci_read_local_codecs_sync()
4244 hci_read_supported_codecs_v2(hdev); in hci_read_local_codecs_sync()
4245 else if (hdev->commands[29] & 0x20) in hci_read_local_codecs_sync()
4246 hci_read_supported_codecs(hdev); in hci_read_local_codecs_sync()
4252 static int hci_read_local_pairing_opts_sync(struct hci_dev *hdev) in hci_read_local_pairing_opts_sync() argument
4254 if (!(hdev->commands[41] & 0x08)) in hci_read_local_pairing_opts_sync()
4257 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_PAIRING_OPTS, in hci_read_local_pairing_opts_sync()
4262 static int hci_get_mws_transport_config_sync(struct hci_dev *hdev) in hci_get_mws_transport_config_sync() argument
4264 if (!(hdev->commands[30] & 0x08)) in hci_get_mws_transport_config_sync()
4267 return __hci_cmd_sync_status(hdev, HCI_OP_GET_MWS_TRANSPORT_CONFIG, in hci_get_mws_transport_config_sync()
4272 static int hci_read_sync_train_params_sync(struct hci_dev *hdev) in hci_read_sync_train_params_sync() argument
4274 if (!lmp_sync_train_capable(hdev)) in hci_read_sync_train_params_sync()
4277 return __hci_cmd_sync_status(hdev, HCI_OP_READ_SYNC_TRAIN_PARAMS, in hci_read_sync_train_params_sync()
4282 static int hci_write_sc_support_1_sync(struct hci_dev *hdev) in hci_write_sc_support_1_sync() argument
4286 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_sc_support_1_sync()
4287 !bredr_sc_enabled(hdev)) in hci_write_sc_support_1_sync()
4290 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_1_sync()
4298 static int hci_set_err_data_report_sync(struct hci_dev *hdev) in hci_set_err_data_report_sync() argument
4301 bool enabled = hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED); in hci_set_err_data_report_sync()
4303 if (!(hdev->commands[18] & 0x08) || in hci_set_err_data_report_sync()
4304 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_set_err_data_report_sync()
4305 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_set_err_data_report_sync()
4308 if (enabled == hdev->err_data_reporting) in hci_set_err_data_report_sync()
4315 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING, in hci_set_err_data_report_sync()
4340 static int hci_le_set_write_def_data_len_sync(struct hci_dev *hdev) in hci_le_set_write_def_data_len_sync() argument
4344 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_set_write_def_data_len_sync()
4348 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_le_set_write_def_data_len_sync()
4349 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_le_set_write_def_data_len_sync()
4351 return __hci_cmd_sync_status(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN, in hci_le_set_write_def_data_len_sync()
4356 static int hci_le_set_default_phy_sync(struct hci_dev *hdev) in hci_le_set_default_phy_sync() argument
4360 if (!(hdev->commands[35] & 0x20)) in hci_le_set_default_phy_sync()
4365 cp.tx_phys = hdev->le_tx_def_phys; in hci_le_set_default_phy_sync()
4366 cp.rx_phys = hdev->le_rx_def_phys; in hci_le_set_default_phy_sync()
4368 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in hci_le_set_default_phy_sync()
4380 static int hci_init4_sync(struct hci_dev *hdev) in hci_init4_sync() argument
4384 bt_dev_dbg(hdev, ""); in hci_init4_sync()
4386 err = hci_init_stage_sync(hdev, hci_init4); in hci_init4_sync()
4390 if (lmp_le_capable(hdev)) in hci_init4_sync()
4391 return hci_init_stage_sync(hdev, le_init4); in hci_init4_sync()
4396 static int hci_init_sync(struct hci_dev *hdev) in hci_init_sync() argument
4400 err = hci_init1_sync(hdev); in hci_init_sync()
4404 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_init_sync()
4405 hci_debugfs_create_basic(hdev); in hci_init_sync()
4407 err = hci_init2_sync(hdev); in hci_init_sync()
4415 if (hdev->dev_type != HCI_PRIMARY) in hci_init_sync()
4418 err = hci_init3_sync(hdev); in hci_init_sync()
4422 err = hci_init4_sync(hdev); in hci_init_sync()
4438 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_init_sync()
4439 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_init_sync()
4442 hci_debugfs_create_common(hdev); in hci_init_sync()
4444 if (lmp_bredr_capable(hdev)) in hci_init_sync()
4445 hci_debugfs_create_bredr(hdev); in hci_init_sync()
4447 if (lmp_le_capable(hdev)) in hci_init_sync()
4448 hci_debugfs_create_le(hdev); in hci_init_sync()
4482 static int hci_dev_setup_sync(struct hci_dev *hdev) in hci_dev_setup_sync() argument
4488 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_setup_sync()
4489 !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) in hci_dev_setup_sync()
4492 bt_dev_dbg(hdev, ""); in hci_dev_setup_sync()
4494 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_setup_sync()
4496 if (hdev->setup) in hci_dev_setup_sync()
4497 ret = hdev->setup(hdev); in hci_dev_setup_sync()
4500 if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) in hci_dev_setup_sync()
4501 bt_dev_warn(hdev, "%s", hci_broken_table[i].desc); in hci_dev_setup_sync()
4508 invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); in hci_dev_setup_sync()
4511 if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { in hci_dev_setup_sync()
4512 if (!bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_setup_sync()
4513 hci_dev_get_bd_addr_from_property(hdev); in hci_dev_setup_sync()
4515 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_setup_sync()
4516 hdev->set_bdaddr) { in hci_dev_setup_sync()
4517 ret = hdev->set_bdaddr(hdev, in hci_dev_setup_sync()
4518 &hdev->public_addr); in hci_dev_setup_sync()
4541 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_setup_sync()
4543 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_setup_sync()
4553 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_setup_sync()
4554 return hci_unconf_init_sync(hdev); in hci_dev_setup_sync()
4564 static int hci_dev_init_sync(struct hci_dev *hdev) in hci_dev_init_sync() argument
4568 bt_dev_dbg(hdev, ""); in hci_dev_init_sync()
4570 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_init_sync()
4571 set_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4573 ret = hci_dev_setup_sync(hdev); in hci_dev_init_sync()
4575 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_init_sync()
4581 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_init_sync()
4582 hdev->set_bdaddr) in hci_dev_init_sync()
4583 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_init_sync()
4589 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_init_sync()
4590 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4591 ret = hci_init_sync(hdev); in hci_dev_init_sync()
4592 if (!ret && hdev->post_init) in hci_dev_init_sync()
4593 ret = hdev->post_init(hdev); in hci_dev_init_sync()
4601 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_init_sync()
4602 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_init_sync()
4603 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_init_sync()
4604 ret = hdev->set_diag(hdev, true); in hci_dev_init_sync()
4606 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4607 msft_do_open(hdev); in hci_dev_init_sync()
4608 aosp_do_open(hdev); in hci_dev_init_sync()
4611 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4616 int hci_dev_open_sync(struct hci_dev *hdev) in hci_dev_open_sync() argument
4620 bt_dev_dbg(hdev, ""); in hci_dev_open_sync()
4622 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_open_sync()
4627 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
4628 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_open_sync()
4632 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_open_sync()
4649 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
4650 hdev->dev_type == HCI_PRIMARY && in hci_dev_open_sync()
4651 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_open_sync()
4652 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_open_sync()
4658 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open_sync()
4663 if (hdev->open(hdev)) { in hci_dev_open_sync()
4668 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4669 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_open_sync()
4671 ret = hci_dev_init_sync(hdev); in hci_dev_open_sync()
4673 hci_dev_hold(hdev); in hci_dev_open_sync()
4674 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_open_sync()
4675 hci_adv_instances_set_rpa_expired(hdev, true); in hci_dev_open_sync()
4676 set_bit(HCI_UP, &hdev->flags); in hci_dev_open_sync()
4677 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_open_sync()
4678 hci_leds_update_powered(hdev, true); in hci_dev_open_sync()
4679 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
4680 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_open_sync()
4681 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open_sync()
4682 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
4683 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_dev_open_sync()
4684 hdev->dev_type == HCI_PRIMARY) { in hci_dev_open_sync()
4685 ret = hci_powered_update_sync(hdev); in hci_dev_open_sync()
4686 mgmt_power_on(hdev, ret); in hci_dev_open_sync()
4690 flush_work(&hdev->tx_work); in hci_dev_open_sync()
4696 flush_work(&hdev->rx_work); in hci_dev_open_sync()
4697 flush_work(&hdev->cmd_work); in hci_dev_open_sync()
4699 skb_queue_purge(&hdev->cmd_q); in hci_dev_open_sync()
4700 skb_queue_purge(&hdev->rx_q); in hci_dev_open_sync()
4702 if (hdev->flush) in hci_dev_open_sync()
4703 hdev->flush(hdev); in hci_dev_open_sync()
4705 if (hdev->sent_cmd) { in hci_dev_open_sync()
4706 kfree_skb(hdev->sent_cmd); in hci_dev_open_sync()
4707 hdev->sent_cmd = NULL; in hci_dev_open_sync()
4710 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4711 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_open_sync()
4713 hdev->close(hdev); in hci_dev_open_sync()
4714 hdev->flags &= BIT(HCI_RAW); in hci_dev_open_sync()
4722 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
4726 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
4738 static int hci_dev_shutdown(struct hci_dev *hdev) in hci_dev_shutdown() argument
4748 hci_dev_test_and_clear_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
4750 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_shutdown()
4751 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_shutdown()
4753 if (hdev->shutdown) in hci_dev_shutdown()
4754 err = hdev->shutdown(hdev); in hci_dev_shutdown()
4758 hci_dev_set_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
4763 int hci_dev_close_sync(struct hci_dev *hdev) in hci_dev_close_sync() argument
4768 bt_dev_dbg(hdev, ""); in hci_dev_close_sync()
4770 cancel_delayed_work(&hdev->power_off); in hci_dev_close_sync()
4771 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
4772 cancel_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
4773 cancel_delayed_work(&hdev->le_scan_restart); in hci_dev_close_sync()
4775 hci_request_cancel_all(hdev); in hci_dev_close_sync()
4777 if (hdev->adv_instance_timeout) { in hci_dev_close_sync()
4778 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_dev_close_sync()
4779 hdev->adv_instance_timeout = 0; in hci_dev_close_sync()
4782 err = hci_dev_shutdown(hdev); in hci_dev_close_sync()
4784 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_close_sync()
4785 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
4789 hci_leds_update_powered(hdev, false); in hci_dev_close_sync()
4792 flush_work(&hdev->tx_work); in hci_dev_close_sync()
4793 flush_work(&hdev->rx_work); in hci_dev_close_sync()
4795 if (hdev->discov_timeout > 0) { in hci_dev_close_sync()
4796 hdev->discov_timeout = 0; in hci_dev_close_sync()
4797 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_close_sync()
4798 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_close_sync()
4801 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_close_sync()
4802 cancel_delayed_work(&hdev->service_cache); in hci_dev_close_sync()
4804 if (hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_close_sync()
4807 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_close_sync()
4809 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_close_sync()
4816 drain_workqueue(hdev->workqueue); in hci_dev_close_sync()
4818 hci_dev_lock(hdev); in hci_dev_close_sync()
4820 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_close_sync()
4822 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_close_sync()
4824 if (!auto_off && hdev->dev_type == HCI_PRIMARY && in hci_dev_close_sync()
4825 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_close_sync()
4826 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_close_sync()
4827 __mgmt_power_off(hdev); in hci_dev_close_sync()
4829 hci_inquiry_cache_flush(hdev); in hci_dev_close_sync()
4830 hci_pend_le_actions_clear(hdev); in hci_dev_close_sync()
4831 hci_conn_hash_flush(hdev); in hci_dev_close_sync()
4833 smp_unregister(hdev); in hci_dev_close_sync()
4834 hci_dev_unlock(hdev); in hci_dev_close_sync()
4836 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_close_sync()
4838 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close_sync()
4839 aosp_do_close(hdev); in hci_dev_close_sync()
4840 msft_do_close(hdev); in hci_dev_close_sync()
4843 if (hdev->flush) in hci_dev_close_sync()
4844 hdev->flush(hdev); in hci_dev_close_sync()
4847 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
4848 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_close_sync()
4849 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_close_sync()
4850 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_close_sync()
4851 set_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
4852 hci_reset_sync(hdev); in hci_dev_close_sync()
4853 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
4857 flush_work(&hdev->cmd_work); in hci_dev_close_sync()
4860 skb_queue_purge(&hdev->rx_q); in hci_dev_close_sync()
4861 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
4862 skb_queue_purge(&hdev->raw_q); in hci_dev_close_sync()
4865 if (hdev->sent_cmd) { in hci_dev_close_sync()
4866 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
4867 kfree_skb(hdev->sent_cmd); in hci_dev_close_sync()
4868 hdev->sent_cmd = NULL; in hci_dev_close_sync()
4871 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_close_sync()
4872 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_close_sync()
4875 hdev->close(hdev); in hci_dev_close_sync()
4878 hdev->flags &= BIT(HCI_RAW); in hci_dev_close_sync()
4879 hci_dev_clear_volatile_flags(hdev); in hci_dev_close_sync()
4882 hdev->amp_status = AMP_STATUS_POWERED_DOWN; in hci_dev_close_sync()
4884 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_close_sync()
4885 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_close_sync()
4886 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_close_sync()
4888 hci_dev_put(hdev); in hci_dev_close_sync()
4898 static int hci_power_on_sync(struct hci_dev *hdev) in hci_power_on_sync() argument
4902 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on_sync()
4903 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on_sync()
4904 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
4905 cancel_delayed_work(&hdev->power_off); in hci_power_on_sync()
4906 return hci_powered_update_sync(hdev); in hci_power_on_sync()
4909 err = hci_dev_open_sync(hdev); in hci_power_on_sync()
4917 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on_sync()
4918 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on_sync()
4919 (hdev->dev_type == HCI_PRIMARY && in hci_power_on_sync()
4920 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on_sync()
4921 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on_sync()
4922 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on_sync()
4923 hci_dev_close_sync(hdev); in hci_power_on_sync()
4924 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
4925 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on_sync()
4929 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on_sync()
4933 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
4934 set_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
4943 mgmt_index_added(hdev); in hci_power_on_sync()
4944 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on_sync()
4948 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
4949 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
4955 mgmt_index_added(hdev); in hci_power_on_sync()
4961 static int hci_remote_name_cancel_sync(struct hci_dev *hdev, bdaddr_t *addr) in hci_remote_name_cancel_sync() argument
4968 return __hci_cmd_sync_status(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, in hci_remote_name_cancel_sync()
4972 int hci_stop_discovery_sync(struct hci_dev *hdev) in hci_stop_discovery_sync() argument
4974 struct discovery_state *d = &hdev->discovery; in hci_stop_discovery_sync()
4978 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_stop_discovery_sync()
4981 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_stop_discovery_sync()
4982 err = __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY_CANCEL, in hci_stop_discovery_sync()
4988 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_stop_discovery_sync()
4989 cancel_delayed_work(&hdev->le_scan_disable); in hci_stop_discovery_sync()
4990 cancel_delayed_work(&hdev->le_scan_restart); in hci_stop_discovery_sync()
4992 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
4998 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5004 if (use_ll_privacy(hdev)) in hci_stop_discovery_sync()
5005 hci_resume_advertising_sync(hdev); in hci_stop_discovery_sync()
5012 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_stop_discovery_sync()
5017 return hci_remote_name_cancel_sync(hdev, &e->data.bdaddr); in hci_stop_discovery_sync()
5023 static int hci_disconnect_phy_link_sync(struct hci_dev *hdev, u16 handle, in hci_disconnect_phy_link_sync() argument
5032 return __hci_cmd_sync_status(hdev, HCI_OP_DISCONN_PHY_LINK, in hci_disconnect_phy_link_sync()
5036 static int hci_disconnect_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_disconnect_sync() argument
5042 return hci_disconnect_phy_link_sync(hdev, conn->handle, reason); in hci_disconnect_sync()
5051 if (!hdev->suspended) in hci_disconnect_sync()
5052 return __hci_cmd_sync_status_sk(hdev, HCI_OP_DISCONNECT, in hci_disconnect_sync()
5057 return __hci_cmd_sync_status(hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp, in hci_disconnect_sync()
5061 static int hci_le_connect_cancel_sync(struct hci_dev *hdev, in hci_le_connect_cancel_sync() argument
5067 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, in hci_le_connect_cancel_sync()
5071 static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_connect_cancel_sync() argument
5074 return hci_le_connect_cancel_sync(hdev, conn); in hci_connect_cancel_sync()
5076 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_connect_cancel_sync()
5079 return __hci_cmd_sync_status(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5083 static int hci_reject_sco_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_sco_sync() argument
5098 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_SYNC_CONN_REQ, in hci_reject_sco_sync()
5102 static int hci_reject_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_conn_sync() argument
5108 return hci_reject_sco_sync(hdev, conn, reason); in hci_reject_conn_sync()
5114 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_CONN_REQ, in hci_reject_conn_sync()
5118 int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) in hci_abort_conn_sync() argument
5125 return hci_disconnect_sync(hdev, conn, reason); in hci_abort_conn_sync()
5127 err = hci_connect_cancel_sync(hdev, conn); in hci_abort_conn_sync()
5132 hci_dev_lock(hdev); in hci_abort_conn_sync()
5134 hci_dev_unlock(hdev); in hci_abort_conn_sync()
5138 return hci_reject_conn_sync(hdev, conn, reason); in hci_abort_conn_sync()
5147 static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) in hci_disconnect_all_sync() argument
5152 list_for_each_entry_safe(conn, tmp, &hdev->conn_hash.list, list) { in hci_disconnect_all_sync()
5153 err = hci_abort_conn_sync(hdev, conn, reason); in hci_disconnect_all_sync()
5168 static int hci_power_off_sync(struct hci_dev *hdev) in hci_power_off_sync() argument
5173 if (!test_bit(HCI_UP, &hdev->flags)) in hci_power_off_sync()
5176 if (test_bit(HCI_ISCAN, &hdev->flags) || in hci_power_off_sync()
5177 test_bit(HCI_PSCAN, &hdev->flags)) { in hci_power_off_sync()
5178 err = hci_write_scan_enable_sync(hdev, 0x00); in hci_power_off_sync()
5183 err = hci_clear_adv_sync(hdev, NULL, false); in hci_power_off_sync()
5187 err = hci_stop_discovery_sync(hdev); in hci_power_off_sync()
5192 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_power_off_sync()
5196 return hci_dev_close_sync(hdev); in hci_power_off_sync()
5199 int hci_set_powered_sync(struct hci_dev *hdev, u8 val) in hci_set_powered_sync() argument
5202 return hci_power_on_sync(hdev); in hci_set_powered_sync()
5204 return hci_power_off_sync(hdev); in hci_set_powered_sync()
5207 static int hci_write_iac_sync(struct hci_dev *hdev) in hci_write_iac_sync() argument
5211 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_write_iac_sync()
5216 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_write_iac_sync()
5218 cp.num_iac = min_t(u8, hdev->num_iac, 2); in hci_write_iac_sync()
5233 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CURRENT_IAC_LAP, in hci_write_iac_sync()
5238 int hci_update_discoverable_sync(struct hci_dev *hdev) in hci_update_discoverable_sync() argument
5242 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_update_discoverable_sync()
5243 err = hci_write_iac_sync(hdev); in hci_update_discoverable_sync()
5247 err = hci_update_scan_sync(hdev); in hci_update_discoverable_sync()
5251 err = hci_update_class_sync(hdev); in hci_update_discoverable_sync()
5259 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in hci_update_discoverable_sync()
5260 err = hci_update_adv_data_sync(hdev, 0x00); in hci_update_discoverable_sync()
5267 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in hci_update_discoverable_sync()
5268 if (ext_adv_capable(hdev)) in hci_update_discoverable_sync()
5269 err = hci_start_ext_adv_sync(hdev, 0x00); in hci_update_discoverable_sync()
5271 err = hci_enable_advertising_sync(hdev); in hci_update_discoverable_sync()
5278 static int update_discoverable_sync(struct hci_dev *hdev, void *data) in update_discoverable_sync() argument
5280 return hci_update_discoverable_sync(hdev); in update_discoverable_sync()
5283 int hci_update_discoverable(struct hci_dev *hdev) in hci_update_discoverable() argument
5286 if (hdev_is_powered(hdev) && in hci_update_discoverable()
5287 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_update_discoverable()
5288 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in hci_update_discoverable()
5289 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in hci_update_discoverable()
5290 return hci_cmd_sync_queue(hdev, update_discoverable_sync, NULL, in hci_update_discoverable()
5296 int hci_update_connectable_sync(struct hci_dev *hdev) in hci_update_connectable_sync() argument
5300 err = hci_update_scan_sync(hdev); in hci_update_connectable_sync()
5308 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_connectable_sync()
5309 err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in hci_update_connectable_sync()
5312 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_update_connectable_sync()
5313 !list_empty(&hdev->adv_instances)) { in hci_update_connectable_sync()
5314 if (ext_adv_capable(hdev)) in hci_update_connectable_sync()
5315 err = hci_start_ext_adv_sync(hdev, in hci_update_connectable_sync()
5316 hdev->cur_adv_instance); in hci_update_connectable_sync()
5318 err = hci_enable_advertising_sync(hdev); in hci_update_connectable_sync()
5324 return hci_update_passive_scan_sync(hdev); in hci_update_connectable_sync()
5327 static int hci_inquiry_sync(struct hci_dev *hdev, u8 length) in hci_inquiry_sync() argument
5333 bt_dev_dbg(hdev, ""); in hci_inquiry_sync()
5335 if (hci_dev_test_flag(hdev, HCI_INQUIRY)) in hci_inquiry_sync()
5338 hci_dev_lock(hdev); in hci_inquiry_sync()
5339 hci_inquiry_cache_flush(hdev); in hci_inquiry_sync()
5340 hci_dev_unlock(hdev); in hci_inquiry_sync()
5344 if (hdev->discovery.limited) in hci_inquiry_sync()
5351 return __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY, in hci_inquiry_sync()
5355 static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) in hci_active_scan_sync() argument
5364 bt_dev_dbg(hdev, ""); in hci_active_scan_sync()
5370 err = hci_scan_disable_sync(hdev); in hci_active_scan_sync()
5372 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_active_scan_sync()
5376 cancel_interleave_scan(hdev); in hci_active_scan_sync()
5381 if (use_ll_privacy(hdev) && hci_dev_test_flag(hdev, HCI_PRIVACY)) { in hci_active_scan_sync()
5382 err = hci_pause_advertising_sync(hdev); in hci_active_scan_sync()
5384 bt_dev_err(hdev, "pause advertising failed: %d", err); in hci_active_scan_sync()
5393 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_active_scan_sync()
5395 bt_dev_err(hdev, "Unable to disable Address Resolution: %d", in hci_active_scan_sync()
5404 err = hci_update_random_address_sync(hdev, true, scan_use_rpa(hdev), in hci_active_scan_sync()
5409 if (hci_is_adv_monitoring(hdev)) { in hci_active_scan_sync()
5426 err = hci_start_scan_sync(hdev, LE_SCAN_ACTIVE, interval, in hci_active_scan_sync()
5427 hdev->le_scan_window_discovery, in hci_active_scan_sync()
5434 if (use_ll_privacy(hdev)) in hci_active_scan_sync()
5435 hci_resume_advertising_sync(hdev); in hci_active_scan_sync()
5438 hci_update_passive_scan_sync(hdev); in hci_active_scan_sync()
5442 static int hci_start_interleaved_discovery_sync(struct hci_dev *hdev) in hci_start_interleaved_discovery_sync() argument
5446 bt_dev_dbg(hdev, ""); in hci_start_interleaved_discovery_sync()
5448 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery * 2); in hci_start_interleaved_discovery_sync()
5452 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN); in hci_start_interleaved_discovery_sync()
5455 int hci_start_discovery_sync(struct hci_dev *hdev) in hci_start_discovery_sync() argument
5460 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in hci_start_discovery_sync()
5462 switch (hdev->discovery.type) { in hci_start_discovery_sync()
5464 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN); in hci_start_discovery_sync()
5475 &hdev->quirks)) { in hci_start_discovery_sync()
5481 err = hci_start_interleaved_discovery_sync(hdev); in hci_start_discovery_sync()
5485 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in hci_start_discovery_sync()
5486 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5490 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5499 bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout)); in hci_start_discovery_sync()
5506 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in hci_start_discovery_sync()
5507 hdev->discovery.result_filtering) { in hci_start_discovery_sync()
5508 hdev->discovery.scan_start = jiffies; in hci_start_discovery_sync()
5509 hdev->discovery.scan_duration = timeout; in hci_start_discovery_sync()
5512 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in hci_start_discovery_sync()
5517 static void hci_suspend_monitor_sync(struct hci_dev *hdev) in hci_suspend_monitor_sync() argument
5519 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_suspend_monitor_sync()
5521 msft_suspend_sync(hdev); in hci_suspend_monitor_sync()
5529 static int hci_pause_discovery_sync(struct hci_dev *hdev) in hci_pause_discovery_sync() argument
5531 int old_state = hdev->discovery.state; in hci_pause_discovery_sync()
5536 hdev->discovery_paused) in hci_pause_discovery_sync()
5539 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_pause_discovery_sync()
5540 err = hci_stop_discovery_sync(hdev); in hci_pause_discovery_sync()
5544 hdev->discovery_paused = true; in hci_pause_discovery_sync()
5545 hdev->discovery_old_state = old_state; in hci_pause_discovery_sync()
5546 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_pause_discovery_sync()
5551 static int hci_update_event_filter_sync(struct hci_dev *hdev) in hci_update_event_filter_sync() argument
5555 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_update_event_filter_sync()
5558 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_event_filter_sync()
5564 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_update_event_filter_sync()
5568 hci_clear_event_filter_sync(hdev); in hci_update_event_filter_sync()
5570 list_for_each_entry(b, &hdev->accept_list, list) { in hci_update_event_filter_sync()
5574 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_update_event_filter_sync()
5576 err = hci_set_event_filter_sync(hdev, HCI_FLT_CONN_SETUP, in hci_update_event_filter_sync()
5581 bt_dev_dbg(hdev, "Failed to set event filter for %pMR", in hci_update_event_filter_sync()
5588 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
5590 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
5596 static int hci_pause_scan_sync(struct hci_dev *hdev) in hci_pause_scan_sync() argument
5598 if (hdev->scanning_paused) in hci_pause_scan_sync()
5602 if (test_bit(HCI_PSCAN, &hdev->flags)) in hci_pause_scan_sync()
5603 hci_write_scan_enable_sync(hdev, SCAN_DISABLED); in hci_pause_scan_sync()
5605 hci_scan_disable_sync(hdev); in hci_pause_scan_sync()
5607 hdev->scanning_paused = true; in hci_pause_scan_sync()
5625 int hci_suspend_sync(struct hci_dev *hdev) in hci_suspend_sync() argument
5630 if (hdev->suspended) in hci_suspend_sync()
5634 hdev->suspended = true; in hci_suspend_sync()
5637 hci_pause_discovery_sync(hdev); in hci_suspend_sync()
5640 hci_pause_advertising_sync(hdev); in hci_suspend_sync()
5643 hci_suspend_monitor_sync(hdev); in hci_suspend_sync()
5646 hci_pause_scan_sync(hdev); in hci_suspend_sync()
5648 if (hci_conn_count(hdev)) { in hci_suspend_sync()
5650 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_suspend_sync()
5653 hdev->suspend_state = BT_RUNNING; in hci_suspend_sync()
5654 hci_resume_sync(hdev); in hci_suspend_sync()
5661 hci_set_event_mask_sync(hdev); in hci_suspend_sync()
5667 if (!hdev->wakeup || !hdev->wakeup(hdev)) { in hci_suspend_sync()
5668 hdev->suspend_state = BT_SUSPEND_DISCONNECT; in hci_suspend_sync()
5673 hdev->scanning_paused = false; in hci_suspend_sync()
5676 hci_update_event_filter_sync(hdev); in hci_suspend_sync()
5679 hci_update_passive_scan_sync(hdev); in hci_suspend_sync()
5682 hdev->scanning_paused = true; in hci_suspend_sync()
5684 hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; in hci_suspend_sync()
5690 static int hci_resume_discovery_sync(struct hci_dev *hdev) in hci_resume_discovery_sync() argument
5695 if (!hdev->discovery_paused) in hci_resume_discovery_sync()
5698 hdev->discovery_paused = false; in hci_resume_discovery_sync()
5700 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_resume_discovery_sync()
5702 err = hci_start_discovery_sync(hdev); in hci_resume_discovery_sync()
5704 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED : in hci_resume_discovery_sync()
5710 static void hci_resume_monitor_sync(struct hci_dev *hdev) in hci_resume_monitor_sync() argument
5712 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_resume_monitor_sync()
5714 msft_resume_sync(hdev); in hci_resume_monitor_sync()
5722 static int hci_resume_scan_sync(struct hci_dev *hdev) in hci_resume_scan_sync() argument
5724 if (!hdev->scanning_paused) in hci_resume_scan_sync()
5727 hdev->scanning_paused = false; in hci_resume_scan_sync()
5729 hci_update_scan_sync(hdev); in hci_resume_scan_sync()
5732 hci_update_passive_scan_sync(hdev); in hci_resume_scan_sync()
5745 int hci_resume_sync(struct hci_dev *hdev) in hci_resume_sync() argument
5748 if (!hdev->suspended) in hci_resume_sync()
5751 hdev->suspended = false; in hci_resume_sync()
5754 hci_set_event_mask_sync(hdev); in hci_resume_sync()
5757 hci_clear_event_filter_sync(hdev); in hci_resume_sync()
5760 hci_resume_scan_sync(hdev); in hci_resume_sync()
5763 hci_resume_monitor_sync(hdev); in hci_resume_sync()
5766 hci_resume_advertising_sync(hdev); in hci_resume_sync()
5769 hci_resume_discovery_sync(hdev); in hci_resume_sync()
5776 struct hci_dev *hdev = conn->hdev; in conn_use_rpa() local
5778 return hci_dev_test_flag(hdev, HCI_PRIVACY); in conn_use_rpa()
5781 static int hci_le_ext_directed_advertising_sync(struct hci_dev *hdev, in hci_le_ext_directed_advertising_sync() argument
5789 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_ext_directed_advertising_sync()
5797 err = hci_get_random_address(hdev, false, conn_use_rpa(conn), NULL, in hci_le_ext_directed_advertising_sync()
5806 cp.channel_map = hdev->le_adv_channel_map; in hci_le_ext_directed_advertising_sync()
5823 err = hci_remove_ext_adv_instance_sync(hdev, cp.handle, NULL); in hci_le_ext_directed_advertising_sync()
5827 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_le_ext_directed_advertising_sync()
5835 bacmp(&random_addr, &hdev->random_addr)) { in hci_le_ext_directed_advertising_sync()
5836 err = hci_set_adv_set_random_addr_sync(hdev, 0x00, in hci_le_ext_directed_advertising_sync()
5842 return hci_enable_ext_advertising_sync(hdev, 0x00); in hci_le_ext_directed_advertising_sync()
5845 static int hci_le_directed_advertising_sync(struct hci_dev *hdev, in hci_le_directed_advertising_sync() argument
5853 if (ext_adv_capable(hdev)) in hci_le_directed_advertising_sync()
5854 return hci_le_ext_directed_advertising_sync(hdev, conn); in hci_le_directed_advertising_sync()
5861 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_le_directed_advertising_sync()
5866 status = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_directed_advertising_sync()
5884 cp.channel_map = hdev->le_adv_channel_map; in hci_le_directed_advertising_sync()
5886 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_le_directed_advertising_sync()
5893 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_le_directed_advertising_sync()
5900 struct hci_dev *hdev = conn->hdev; in set_ext_conn_params() local
5904 p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in set_ext_conn_params()
5905 p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); in set_ext_conn_params()
5914 static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, in hci_le_ext_create_conn_sync() argument
5933 if (scan_1m(hdev)) { in hci_le_ext_create_conn_sync()
5941 if (scan_2m(hdev)) { in hci_le_ext_create_conn_sync()
5949 if (scan_coded(hdev)) { in hci_le_ext_create_conn_sync()
5956 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_EXT_CREATE_CONN, in hci_le_ext_create_conn_sync()
5962 int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_le_create_conn_sync() argument
5974 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in hci_le_create_conn_sync()
5975 hdev->le_scan_type == LE_SCAN_ACTIVE && in hci_le_create_conn_sync()
5976 !hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) { in hci_le_create_conn_sync()
5982 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
5984 err = hci_le_directed_advertising_sync(hdev, conn); in hci_le_create_conn_sync()
5989 if (!hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in hci_le_create_conn_sync()
5990 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
5992 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_create_conn_sync()
5999 conn->le_conn_min_interval = hdev->le_conn_min_interval; in hci_le_create_conn_sync()
6000 conn->le_conn_max_interval = hdev->le_conn_max_interval; in hci_le_create_conn_sync()
6001 conn->le_conn_latency = hdev->le_conn_latency; in hci_le_create_conn_sync()
6002 conn->le_supv_timeout = hdev->le_supv_timeout; in hci_le_create_conn_sync()
6011 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_le_create_conn_sync()
6012 hci_scan_disable_sync(hdev); in hci_le_create_conn_sync()
6013 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED); in hci_le_create_conn_sync()
6019 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_create_conn_sync()
6024 if (use_ext_conn(hdev)) { in hci_le_create_conn_sync()
6025 err = hci_le_ext_create_conn_sync(hdev, conn, own_addr_type); in hci_le_create_conn_sync()
6031 cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in hci_le_create_conn_sync()
6032 cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); in hci_le_create_conn_sync()
6050 err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CONN, in hci_le_create_conn_sync()
6052 use_enhanced_conn_complete(hdev) ? in hci_le_create_conn_sync()
6059 hci_resume_advertising_sync(hdev); in hci_le_create_conn_sync()
6063 int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle) in hci_le_remove_cig_sync() argument
6070 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REMOVE_CIG, sizeof(cp), in hci_le_remove_cig_sync()
6074 int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle) in hci_le_big_terminate_sync() argument
6081 return __hci_cmd_sync_status(hdev, HCI_OP_LE_BIG_TERM_SYNC, in hci_le_big_terminate_sync()
6085 int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle) in hci_le_pa_terminate_sync() argument
6092 return __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_TERM_SYNC, in hci_le_pa_terminate_sync()
6096 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
6111 if (use_ll_privacy(hdev)) in hci_get_random_address()
6120 if (rpa_valid(hdev)) in hci_get_random_address()
6124 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
6126 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
6130 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
6153 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
6169 static int _update_adv_data_sync(struct hci_dev *hdev, void *data) in _update_adv_data_sync() argument
6175 return hci_update_adv_data_sync(hdev, instance); in _update_adv_data_sync()
6178 int hci_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_update_adv_data() argument
6186 return hci_cmd_sync_queue(hdev, _update_adv_data_sync, inst_ptr, NULL); in hci_update_adv_data()