Lines Matching refs:hdev

24 static void hci_cmd_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,  in hci_cmd_sync_complete()  argument
27 bt_dev_dbg(hdev, "result 0x%2.2x", result); in hci_cmd_sync_complete()
29 if (hdev->req_status != HCI_REQ_PEND) in hci_cmd_sync_complete()
32 hdev->req_result = result; in hci_cmd_sync_complete()
33 hdev->req_status = HCI_REQ_DONE; in hci_cmd_sync_complete()
42 hdev->req_skb = skb_get(skb); in hci_cmd_sync_complete()
45 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_complete()
48 static struct sk_buff *hci_cmd_sync_alloc(struct hci_dev *hdev, u16 opcode, in hci_cmd_sync_alloc() argument
67 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_cmd_sync_alloc()
86 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_add() local
89 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync_add()
97 skb = hci_cmd_sync_alloc(hdev, opcode, plen, param, sk); in hci_cmd_sync_add()
99 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_cmd_sync_add()
115 struct hci_dev *hdev = req->hdev; in hci_cmd_sync_run() local
119 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in hci_cmd_sync_run()
137 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
138 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in hci_cmd_sync_run()
139 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in hci_cmd_sync_run()
141 queue_work(hdev->workqueue, &hdev->cmd_work); in hci_cmd_sync_run()
147 struct sk_buff *__hci_cmd_sync_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_sk() argument
155 bt_dev_dbg(hdev, "Opcode 0x%4x", opcode); in __hci_cmd_sync_sk()
157 hci_req_init(&req, hdev); in __hci_cmd_sync_sk()
161 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_sk()
167 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_sk()
168 hdev->req_status != HCI_REQ_PEND, in __hci_cmd_sync_sk()
174 switch (hdev->req_status) { in __hci_cmd_sync_sk()
176 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_sk()
180 err = -hdev->req_result; in __hci_cmd_sync_sk()
188 hdev->req_status = 0; in __hci_cmd_sync_sk()
189 hdev->req_result = 0; in __hci_cmd_sync_sk()
190 skb = hdev->req_skb; in __hci_cmd_sync_sk()
191 hdev->req_skb = NULL; in __hci_cmd_sync_sk()
193 bt_dev_dbg(hdev, "end: err %d", err); in __hci_cmd_sync_sk()
205 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync() argument
208 return __hci_cmd_sync_sk(hdev, opcode, plen, param, 0, timeout, NULL); in __hci_cmd_sync()
213 struct sk_buff *hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_cmd_sync() argument
218 if (!test_bit(HCI_UP, &hdev->flags)) in hci_cmd_sync()
221 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_cmd_sync()
223 hci_req_sync_lock(hdev); in hci_cmd_sync()
224 skb = __hci_cmd_sync(hdev, opcode, plen, param, timeout); in hci_cmd_sync()
225 hci_req_sync_unlock(hdev); in hci_cmd_sync()
232 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_ev() argument
235 return __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, in __hci_cmd_sync_ev()
241 int __hci_cmd_sync_status_sk(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status_sk() argument
248 skb = __hci_cmd_sync_sk(hdev, opcode, plen, param, event, timeout, sk); in __hci_cmd_sync_status_sk()
251 bt_dev_err(hdev, "Opcode 0x%4x failed: %ld", opcode, in __hci_cmd_sync_status_sk()
271 int __hci_cmd_sync_status(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_status() argument
274 return __hci_cmd_sync_status_sk(hdev, opcode, plen, param, 0, timeout, in __hci_cmd_sync_status()
281 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_work); in hci_cmd_sync_work() local
283 bt_dev_dbg(hdev, ""); in hci_cmd_sync_work()
289 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
290 entry = list_first_entry_or_null(&hdev->cmd_sync_work_list, in hci_cmd_sync_work()
295 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_work()
300 bt_dev_dbg(hdev, "entry %p", entry); in hci_cmd_sync_work()
305 hci_req_sync_lock(hdev); in hci_cmd_sync_work()
306 err = entry->func(hdev, entry->data); in hci_cmd_sync_work()
308 entry->destroy(hdev, entry->data, err); in hci_cmd_sync_work()
309 hci_req_sync_unlock(hdev); in hci_cmd_sync_work()
318 struct hci_dev *hdev = container_of(work, struct hci_dev, cmd_sync_cancel_work); in hci_cmd_sync_cancel_work() local
320 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_cmd_sync_cancel_work()
321 cancel_delayed_work_sync(&hdev->ncmd_timer); in hci_cmd_sync_cancel_work()
322 atomic_set(&hdev->cmd_cnt, 1); in hci_cmd_sync_cancel_work()
324 wake_up_interruptible(&hdev->req_wait_q); in hci_cmd_sync_cancel_work()
327 static int hci_scan_disable_sync(struct hci_dev *hdev);
328 static int scan_disable_sync(struct hci_dev *hdev, void *data) in scan_disable_sync() argument
330 return hci_scan_disable_sync(hdev); in scan_disable_sync()
333 static int hci_inquiry_sync(struct hci_dev *hdev, u8 length);
334 static int interleaved_inquiry_sync(struct hci_dev *hdev, void *data) in interleaved_inquiry_sync() argument
336 return hci_inquiry_sync(hdev, DISCOV_INTERLEAVED_INQUIRY_LEN); in interleaved_inquiry_sync()
341 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable() local
345 bt_dev_dbg(hdev, ""); in le_scan_disable()
346 hci_dev_lock(hdev); in le_scan_disable()
348 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_disable()
351 cancel_delayed_work(&hdev->le_scan_restart); in le_scan_disable()
353 status = hci_cmd_sync_queue(hdev, scan_disable_sync, NULL, NULL); in le_scan_disable()
355 bt_dev_err(hdev, "failed to disable LE scan: %d", status); in le_scan_disable()
359 hdev->discovery.scan_start = 0; in le_scan_disable()
369 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable()
372 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable()
375 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable()
376 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable()
377 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable()
383 status = hci_cmd_sync_queue(hdev, interleaved_inquiry_sync, NULL, NULL); in le_scan_disable()
385 bt_dev_err(hdev, "inquiry failed: status %d", status); in le_scan_disable()
392 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in le_scan_disable()
395 hci_dev_unlock(hdev); in le_scan_disable()
398 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val,
400 static int hci_le_scan_restart_sync(struct hci_dev *hdev) in hci_le_scan_restart_sync() argument
403 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_le_scan_restart_sync()
406 if (hdev->scanning_paused) { in hci_le_scan_restart_sync()
407 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_le_scan_restart_sync()
411 hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_le_scan_restart_sync()
412 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, in hci_le_scan_restart_sync()
418 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_restart() local
423 bt_dev_dbg(hdev, ""); in le_scan_restart()
425 status = hci_le_scan_restart_sync(hdev); in le_scan_restart()
427 bt_dev_err(hdev, "failed to restart LE scan: status %d", in le_scan_restart()
432 hci_dev_lock(hdev); in le_scan_restart()
434 if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) || in le_scan_restart()
435 !hdev->discovery.scan_start) in le_scan_restart()
443 duration = hdev->discovery.scan_duration; in le_scan_restart()
444 scan_start = hdev->discovery.scan_start; in le_scan_restart()
459 queue_delayed_work(hdev->req_workqueue, in le_scan_restart()
460 &hdev->le_scan_disable, timeout); in le_scan_restart()
463 hci_dev_unlock(hdev); in le_scan_restart()
466 static int reenable_adv_sync(struct hci_dev *hdev, void *data) in reenable_adv_sync() argument
468 bt_dev_dbg(hdev, ""); in reenable_adv_sync()
470 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in reenable_adv_sync()
471 list_empty(&hdev->adv_instances)) in reenable_adv_sync()
474 if (hdev->cur_adv_instance) { in reenable_adv_sync()
475 return hci_schedule_adv_instance_sync(hdev, in reenable_adv_sync()
476 hdev->cur_adv_instance, in reenable_adv_sync()
479 if (ext_adv_capable(hdev)) { in reenable_adv_sync()
480 hci_start_ext_adv_sync(hdev, 0x00); in reenable_adv_sync()
482 hci_update_adv_data_sync(hdev, 0x00); in reenable_adv_sync()
483 hci_update_scan_rsp_data_sync(hdev, 0x00); in reenable_adv_sync()
484 hci_enable_advertising_sync(hdev); in reenable_adv_sync()
493 struct hci_dev *hdev = container_of(work, struct hci_dev, in reenable_adv() local
497 bt_dev_dbg(hdev, ""); in reenable_adv()
499 hci_dev_lock(hdev); in reenable_adv()
501 status = hci_cmd_sync_queue(hdev, reenable_adv_sync, NULL, NULL); in reenable_adv()
503 bt_dev_err(hdev, "failed to reenable ADV: %d", status); in reenable_adv()
505 hci_dev_unlock(hdev); in reenable_adv()
508 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
510 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
511 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
512 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
527 int hci_clear_adv_instance_sync(struct hci_dev *hdev, struct sock *sk, in hci_clear_adv_instance_sync() argument
535 if (!instance || hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
536 cancel_adv_timeout(hdev); in hci_clear_adv_instance_sync()
542 if (instance && hdev->cur_adv_instance == instance) in hci_clear_adv_instance_sync()
543 next_instance = hci_get_next_instance(hdev, instance); in hci_clear_adv_instance_sync()
546 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_clear_adv_instance_sync()
552 err = hci_remove_adv_instance(hdev, rem_inst); in hci_clear_adv_instance_sync()
554 mgmt_advertising_removed(sk, hdev, rem_inst); in hci_clear_adv_instance_sync()
557 adv_instance = hci_find_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
566 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_instance_sync()
568 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_instance_sync()
572 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_clear_adv_instance_sync()
575 if (next_instance && !ext_adv_capable(hdev)) in hci_clear_adv_instance_sync()
576 return hci_schedule_adv_instance_sync(hdev, in hci_clear_adv_instance_sync()
583 static int adv_timeout_expire_sync(struct hci_dev *hdev, void *data) in adv_timeout_expire_sync() argument
589 hci_clear_adv_instance_sync(hdev, NULL, instance, false); in adv_timeout_expire_sync()
591 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire_sync()
592 return hci_disable_advertising_sync(hdev); in adv_timeout_expire_sync()
600 struct hci_dev *hdev = container_of(work, struct hci_dev, in adv_timeout_expire() local
603 bt_dev_dbg(hdev, ""); in adv_timeout_expire()
605 hci_dev_lock(hdev); in adv_timeout_expire()
607 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
609 if (hdev->cur_adv_instance == 0x00) in adv_timeout_expire()
616 *inst_ptr = hdev->cur_adv_instance; in adv_timeout_expire()
617 hci_cmd_sync_queue(hdev, adv_timeout_expire_sync, inst_ptr, NULL); in adv_timeout_expire()
620 hci_dev_unlock(hdev); in adv_timeout_expire()
623 void hci_cmd_sync_init(struct hci_dev *hdev) in hci_cmd_sync_init() argument
625 INIT_WORK(&hdev->cmd_sync_work, hci_cmd_sync_work); in hci_cmd_sync_init()
626 INIT_LIST_HEAD(&hdev->cmd_sync_work_list); in hci_cmd_sync_init()
627 mutex_init(&hdev->cmd_sync_work_lock); in hci_cmd_sync_init()
628 mutex_init(&hdev->unregister_lock); in hci_cmd_sync_init()
630 INIT_WORK(&hdev->cmd_sync_cancel_work, hci_cmd_sync_cancel_work); in hci_cmd_sync_init()
631 INIT_WORK(&hdev->reenable_adv_work, reenable_adv); in hci_cmd_sync_init()
632 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable); in hci_cmd_sync_init()
633 INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart); in hci_cmd_sync_init()
634 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_cmd_sync_init()
637 void hci_cmd_sync_clear(struct hci_dev *hdev) in hci_cmd_sync_clear() argument
641 cancel_work_sync(&hdev->cmd_sync_work); in hci_cmd_sync_clear()
642 cancel_work_sync(&hdev->reenable_adv_work); in hci_cmd_sync_clear()
644 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_clear()
645 list_for_each_entry_safe(entry, tmp, &hdev->cmd_sync_work_list, list) { in hci_cmd_sync_clear()
647 entry->destroy(hdev, entry->data, -ECANCELED); in hci_cmd_sync_clear()
652 mutex_unlock(&hdev->cmd_sync_work_lock); 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()
688 int hci_cmd_sync_submit(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_submit() argument
694 mutex_lock(&hdev->unregister_lock); in hci_cmd_sync_submit()
695 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_cmd_sync_submit()
709 mutex_lock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
710 list_add_tail(&entry->list, &hdev->cmd_sync_work_list); in hci_cmd_sync_submit()
711 mutex_unlock(&hdev->cmd_sync_work_lock); in hci_cmd_sync_submit()
713 queue_work(hdev->req_workqueue, &hdev->cmd_sync_work); in hci_cmd_sync_submit()
716 mutex_unlock(&hdev->unregister_lock); in hci_cmd_sync_submit()
725 int hci_cmd_sync_queue(struct hci_dev *hdev, hci_cmd_sync_work_func_t func, in hci_cmd_sync_queue() argument
731 if (!test_bit(HCI_RUNNING, &hdev->flags)) in hci_cmd_sync_queue()
734 return hci_cmd_sync_submit(hdev, func, data, destroy); in hci_cmd_sync_queue()
738 int hci_update_eir_sync(struct hci_dev *hdev) in hci_update_eir_sync() argument
742 bt_dev_dbg(hdev, ""); in hci_update_eir_sync()
744 if (!hdev_is_powered(hdev)) in hci_update_eir_sync()
747 if (!lmp_ext_inq_capable(hdev)) in hci_update_eir_sync()
750 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_update_eir_sync()
753 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_eir_sync()
758 eir_create(hdev, cp.data); in hci_update_eir_sync()
760 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in hci_update_eir_sync()
763 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in hci_update_eir_sync()
765 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_update_eir_sync()
769 static u8 get_service_classes(struct hci_dev *hdev) in get_service_classes() argument
774 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
780 int hci_update_class_sync(struct hci_dev *hdev) in hci_update_class_sync() argument
784 bt_dev_dbg(hdev, ""); in hci_update_class_sync()
786 if (!hdev_is_powered(hdev)) in hci_update_class_sync()
789 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_class_sync()
792 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in hci_update_class_sync()
795 cod[0] = hdev->minor_class; in hci_update_class_sync()
796 cod[1] = hdev->major_class; in hci_update_class_sync()
797 cod[2] = get_service_classes(hdev); in hci_update_class_sync()
799 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in hci_update_class_sync()
802 if (memcmp(cod, hdev->dev_class, 3) == 0) in hci_update_class_sync()
805 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CLASS_OF_DEV, in hci_update_class_sync()
809 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) in is_advertising_allowed() argument
812 if (hci_conn_num(hdev, LE_LINK) == 0) in is_advertising_allowed()
816 if (hdev->conn_hash.le_num_peripheral > 0) { in is_advertising_allowed()
820 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
826 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
827 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
832 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_peripheral) { in is_advertising_allowed()
834 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
840 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
841 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
848 static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags) in adv_use_rpa() argument
851 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in adv_use_rpa()
855 if (!hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in adv_use_rpa()
862 hci_dev_test_flag(hdev, HCI_BONDABLE)) in adv_use_rpa()
871 static int hci_set_random_addr_sync(struct hci_dev *hdev, bdaddr_t *rpa) in hci_set_random_addr_sync() argument
883 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in hci_set_random_addr_sync()
884 hci_lookup_le_connect(hdev)) { in hci_set_random_addr_sync()
885 bt_dev_dbg(hdev, "Deferring random address update"); in hci_set_random_addr_sync()
886 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_set_random_addr_sync()
890 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RANDOM_ADDR, in hci_set_random_addr_sync()
894 int hci_update_random_address_sync(struct hci_dev *hdev, bool require_privacy, in hci_update_random_address_sync() argument
907 if (use_ll_privacy(hdev)) in hci_update_random_address_sync()
913 if (rpa_valid(hdev)) in hci_update_random_address_sync()
916 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address_sync()
918 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address_sync()
922 err = hci_set_random_addr_sync(hdev, &hdev->rpa); in hci_update_random_address_sync()
947 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address_sync()
953 return hci_set_random_addr_sync(hdev, &nrpa); in hci_update_random_address_sync()
965 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address_sync()
966 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address_sync()
967 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address_sync()
968 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address_sync()
970 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address_sync()
971 return hci_set_random_addr_sync(hdev, in hci_update_random_address_sync()
972 &hdev->static_addr); in hci_update_random_address_sync()
984 static int hci_disable_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_disable_ext_adv_instance_sync() argument
995 adv = hci_find_adv_instance(hdev, instance); in hci_disable_ext_adv_instance_sync()
1017 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_disable_ext_adv_instance_sync()
1021 static int hci_set_adv_set_random_addr_sync(struct hci_dev *hdev, u8 instance, in hci_set_adv_set_random_addr_sync() argument
1033 err = hci_set_random_addr_sync(hdev, random_addr); in hci_set_adv_set_random_addr_sync()
1043 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_SET_RAND_ADDR, in hci_set_adv_set_random_addr_sync()
1047 int hci_setup_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance) in hci_setup_ext_adv_instance_sync() argument
1059 adv = hci_find_adv_instance(hdev, instance); in hci_setup_ext_adv_instance_sync()
1071 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_setup_ext_adv_instance_sync()
1076 flags = hci_adv_instance_flags(hdev, instance); in hci_setup_ext_adv_instance_sync()
1082 mgmt_get_connectable(hdev); in hci_setup_ext_adv_instance_sync()
1084 if (!is_advertising_allowed(hdev, connectable)) in hci_setup_ext_adv_instance_sync()
1091 err = hci_get_random_address(hdev, !connectable, in hci_setup_ext_adv_instance_sync()
1092 adv_use_rpa(hdev, flags), adv, in hci_setup_ext_adv_instance_sync()
1104 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in hci_setup_ext_adv_instance_sync()
1105 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in hci_setup_ext_adv_instance_sync()
1116 } else if (hci_adv_instance_is_scannable(hdev, instance) || in hci_setup_ext_adv_instance_sync()
1137 hci_copy_identity_address(hdev, &cp.peer_addr, in hci_setup_ext_adv_instance_sync()
1141 cp.channel_map = hdev->le_adv_channel_map; in hci_setup_ext_adv_instance_sync()
1156 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_setup_ext_adv_instance_sync()
1169 if (!bacmp(&random_addr, &hdev->random_addr)) in hci_setup_ext_adv_instance_sync()
1173 return hci_set_adv_set_random_addr_sync(hdev, instance, in hci_setup_ext_adv_instance_sync()
1180 static int hci_set_ext_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_scan_rsp_data_sync() argument
1193 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_scan_rsp_data_sync()
1198 len = eir_create_scan_rsp(hdev, instance, pdu.data); in hci_set_ext_scan_rsp_data_sync()
1205 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_RSP_DATA, in hci_set_ext_scan_rsp_data_sync()
1214 memcpy(hdev->scan_rsp_data, pdu.data, len); in hci_set_ext_scan_rsp_data_sync()
1215 hdev->scan_rsp_data_len = len; in hci_set_ext_scan_rsp_data_sync()
1221 static int __hci_set_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in __hci_set_scan_rsp_data_sync() argument
1228 len = eir_create_scan_rsp(hdev, instance, cp.data); in __hci_set_scan_rsp_data_sync()
1230 if (hdev->scan_rsp_data_len == len && in __hci_set_scan_rsp_data_sync()
1231 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_set_scan_rsp_data_sync()
1234 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_set_scan_rsp_data_sync()
1235 hdev->scan_rsp_data_len = len; in __hci_set_scan_rsp_data_sync()
1239 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_RSP_DATA, in __hci_set_scan_rsp_data_sync()
1243 int hci_update_scan_rsp_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_scan_rsp_data_sync() argument
1245 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_scan_rsp_data_sync()
1248 if (ext_adv_capable(hdev)) in hci_update_scan_rsp_data_sync()
1249 return hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1251 return __hci_set_scan_rsp_data_sync(hdev, instance); in hci_update_scan_rsp_data_sync()
1254 int hci_enable_ext_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_ext_advertising_sync() argument
1262 adv = hci_find_adv_instance(hdev, instance); in hci_enable_ext_advertising_sync()
1294 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_ENABLE, in hci_enable_ext_advertising_sync()
1300 int hci_start_ext_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_ext_adv_sync() argument
1304 err = hci_setup_ext_adv_instance_sync(hdev, instance); in hci_start_ext_adv_sync()
1308 err = hci_set_ext_scan_rsp_data_sync(hdev, instance); in hci_start_ext_adv_sync()
1312 return hci_enable_ext_advertising_sync(hdev, instance); in hci_start_ext_adv_sync()
1315 static int hci_disable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_disable_per_advertising_sync() argument
1321 adv = hci_find_adv_instance(hdev, instance); in hci_disable_per_advertising_sync()
1330 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_disable_per_advertising_sync()
1334 static int hci_set_per_adv_params_sync(struct hci_dev *hdev, u8 instance, in hci_set_per_adv_params_sync() argument
1352 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_PARAMS, in hci_set_per_adv_params_sync()
1356 static int hci_set_per_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_per_adv_data_sync() argument
1367 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_set_per_adv_data_sync()
1373 len = eir_create_per_adv_data(hdev, instance, pdu.data); in hci_set_per_adv_data_sync()
1379 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_DATA, in hci_set_per_adv_data_sync()
1384 static int hci_enable_per_advertising_sync(struct hci_dev *hdev, u8 instance) in hci_enable_per_advertising_sync() argument
1390 adv = hci_find_adv_instance(hdev, instance); in hci_enable_per_advertising_sync()
1399 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PER_ADV_ENABLE, in hci_enable_per_advertising_sync()
1406 static int hci_adv_bcast_annoucement(struct hci_dev *hdev, struct adv_info *adv) in hci_adv_bcast_annoucement() argument
1436 hci_set_adv_instance_data(hdev, adv->instance, sizeof(ad), ad, 0, NULL); in hci_adv_bcast_annoucement()
1438 return hci_update_adv_data_sync(hdev, adv->instance); in hci_adv_bcast_annoucement()
1441 int hci_start_per_adv_sync(struct hci_dev *hdev, u8 instance, u8 data_len, in hci_start_per_adv_sync() argument
1449 hci_disable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1452 adv = hci_find_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1455 adv = hci_add_per_instance(hdev, instance, flags, in hci_start_per_adv_sync()
1467 err = hci_start_ext_adv_sync(hdev, instance); in hci_start_per_adv_sync()
1471 err = hci_adv_bcast_annoucement(hdev, adv); in hci_start_per_adv_sync()
1475 err = hci_set_per_adv_params_sync(hdev, instance, min_interval, in hci_start_per_adv_sync()
1480 err = hci_set_per_adv_data_sync(hdev, instance); in hci_start_per_adv_sync()
1484 err = hci_enable_per_advertising_sync(hdev, instance); in hci_start_per_adv_sync()
1492 hci_remove_adv_instance(hdev, instance); in hci_start_per_adv_sync()
1497 static int hci_start_adv_sync(struct hci_dev *hdev, u8 instance) in hci_start_adv_sync() argument
1501 if (ext_adv_capable(hdev)) in hci_start_adv_sync()
1502 return hci_start_ext_adv_sync(hdev, instance); in hci_start_adv_sync()
1504 err = hci_update_adv_data_sync(hdev, instance); in hci_start_adv_sync()
1508 err = hci_update_scan_rsp_data_sync(hdev, instance); in hci_start_adv_sync()
1512 return hci_enable_advertising_sync(hdev); in hci_start_adv_sync()
1515 int hci_enable_advertising_sync(struct hci_dev *hdev) in hci_enable_advertising_sync() argument
1525 if (ext_adv_capable(hdev)) in hci_enable_advertising_sync()
1526 return hci_enable_ext_advertising_sync(hdev, in hci_enable_advertising_sync()
1527 hdev->cur_adv_instance); in hci_enable_advertising_sync()
1529 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1530 adv_instance = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in hci_enable_advertising_sync()
1536 mgmt_get_connectable(hdev); in hci_enable_advertising_sync()
1538 if (!is_advertising_allowed(hdev, connectable)) in hci_enable_advertising_sync()
1541 status = hci_disable_advertising_sync(hdev); in hci_enable_advertising_sync()
1550 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_enable_advertising_sync()
1556 status = hci_update_random_address_sync(hdev, !connectable, in hci_enable_advertising_sync()
1557 adv_use_rpa(hdev, flags), in hci_enable_advertising_sync()
1568 adv_min_interval = hdev->le_adv_min_interval; in hci_enable_advertising_sync()
1569 adv_max_interval = hdev->le_adv_max_interval; in hci_enable_advertising_sync()
1575 if (hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance)) in hci_enable_advertising_sync()
1580 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in hci_enable_advertising_sync()
1581 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_enable_advertising_sync()
1590 cp.channel_map = hdev->le_adv_channel_map; in hci_enable_advertising_sync()
1592 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_enable_advertising_sync()
1597 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_enable_advertising_sync()
1601 static int enable_advertising_sync(struct hci_dev *hdev, void *data) in enable_advertising_sync() argument
1603 return hci_enable_advertising_sync(hdev); in enable_advertising_sync()
1606 int hci_enable_advertising(struct hci_dev *hdev) in hci_enable_advertising() argument
1608 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_enable_advertising()
1609 list_empty(&hdev->adv_instances)) in hci_enable_advertising()
1612 return hci_cmd_sync_queue(hdev, enable_advertising_sync, NULL, NULL); in hci_enable_advertising()
1615 int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_remove_ext_adv_instance_sync() argument
1620 if (!ext_adv_capable(hdev)) in hci_remove_ext_adv_instance_sync()
1623 err = hci_disable_ext_adv_instance_sync(hdev, instance); in hci_remove_ext_adv_instance_sync()
1628 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in hci_remove_ext_adv_instance_sync()
1631 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_REMOVE_ADV_SET, in hci_remove_ext_adv_instance_sync()
1636 static int remove_ext_adv_sync(struct hci_dev *hdev, void *data) in remove_ext_adv_sync() argument
1644 return hci_remove_ext_adv_instance_sync(hdev, instance, NULL); in remove_ext_adv_sync()
1647 int hci_remove_ext_adv_instance(struct hci_dev *hdev, u8 instance) in hci_remove_ext_adv_instance() argument
1652 adv = hci_find_adv_instance(hdev, instance); in hci_remove_ext_adv_instance()
1657 return hci_cmd_sync_queue(hdev, remove_ext_adv_sync, adv, NULL); in hci_remove_ext_adv_instance()
1660 int hci_le_terminate_big_sync(struct hci_dev *hdev, u8 handle, u8 reason) in hci_le_terminate_big_sync() argument
1668 return __hci_cmd_sync_status(hdev, HCI_OP_LE_TERM_BIG, in hci_le_terminate_big_sync()
1672 static int hci_set_ext_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_ext_adv_data_sync() argument
1685 adv = hci_find_adv_instance(hdev, instance); in hci_set_ext_adv_data_sync()
1690 len = eir_create_adv_data(hdev, instance, pdu.data); in hci_set_ext_adv_data_sync()
1697 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_DATA, in hci_set_ext_adv_data_sync()
1707 memcpy(hdev->adv_data, pdu.data, len); in hci_set_ext_adv_data_sync()
1708 hdev->adv_data_len = len; in hci_set_ext_adv_data_sync()
1714 static int hci_set_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_set_adv_data_sync() argument
1721 len = eir_create_adv_data(hdev, instance, cp.data); in hci_set_adv_data_sync()
1724 if (hdev->adv_data_len == len && in hci_set_adv_data_sync()
1725 memcmp(cp.data, hdev->adv_data, len) == 0) in hci_set_adv_data_sync()
1728 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in hci_set_adv_data_sync()
1729 hdev->adv_data_len = len; in hci_set_adv_data_sync()
1733 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_DATA, in hci_set_adv_data_sync()
1737 int hci_update_adv_data_sync(struct hci_dev *hdev, u8 instance) in hci_update_adv_data_sync() argument
1739 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_adv_data_sync()
1742 if (ext_adv_capable(hdev)) in hci_update_adv_data_sync()
1743 return hci_set_ext_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1745 return hci_set_adv_data_sync(hdev, instance); in hci_update_adv_data_sync()
1748 int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, in hci_schedule_adv_instance_sync() argument
1754 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) && !ext_adv_capable(hdev)) in hci_schedule_adv_instance_sync()
1757 if (hdev->adv_instance_timeout) in hci_schedule_adv_instance_sync()
1760 adv = hci_find_adv_instance(hdev, instance); in hci_schedule_adv_instance_sync()
1784 if (!ext_adv_capable(hdev)) { in hci_schedule_adv_instance_sync()
1785 hdev->adv_instance_timeout = timeout; in hci_schedule_adv_instance_sync()
1786 queue_delayed_work(hdev->req_workqueue, in hci_schedule_adv_instance_sync()
1787 &hdev->adv_instance_expire, in hci_schedule_adv_instance_sync()
1795 if (!force && hdev->cur_adv_instance == instance && in hci_schedule_adv_instance_sync()
1796 hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_schedule_adv_instance_sync()
1799 hdev->cur_adv_instance = instance; in hci_schedule_adv_instance_sync()
1801 return hci_start_adv_sync(hdev, instance); in hci_schedule_adv_instance_sync()
1804 static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk) in hci_clear_adv_sets_sync() argument
1808 if (!ext_adv_capable(hdev)) in hci_clear_adv_sets_sync()
1812 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_clear_adv_sets_sync()
1816 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CLEAR_ADV_SETS, in hci_clear_adv_sets_sync()
1820 static int hci_clear_adv_sync(struct hci_dev *hdev, struct sock *sk, bool force) in hci_clear_adv_sync() argument
1825 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1827 err = hci_clear_adv_sets_sync(hdev, sk); in hci_clear_adv_sync()
1828 if (ext_adv_capable(hdev)) in hci_clear_adv_sync()
1834 hci_dev_lock(hdev); in hci_clear_adv_sync()
1837 list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { in hci_clear_adv_sync()
1844 err = hci_remove_adv_instance(hdev, instance); in hci_clear_adv_sync()
1846 mgmt_advertising_removed(sk, hdev, instance); in hci_clear_adv_sync()
1849 hci_dev_unlock(hdev); in hci_clear_adv_sync()
1854 static int hci_remove_adv_sync(struct hci_dev *hdev, u8 instance, in hci_remove_adv_sync() argument
1860 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1861 err = hci_remove_ext_adv_instance_sync(hdev, instance, sk); in hci_remove_adv_sync()
1862 if (ext_adv_capable(hdev)) in hci_remove_adv_sync()
1868 hci_dev_lock(hdev); in hci_remove_adv_sync()
1870 err = hci_remove_adv_instance(hdev, instance); in hci_remove_adv_sync()
1872 mgmt_advertising_removed(sk, hdev, instance); in hci_remove_adv_sync()
1874 hci_dev_unlock(hdev); in hci_remove_adv_sync()
1890 int hci_remove_advertising_sync(struct hci_dev *hdev, struct sock *sk, in hci_remove_advertising_sync() argument
1897 if (!instance || hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1898 cancel_adv_timeout(hdev); in hci_remove_advertising_sync()
1904 if (hdev->cur_adv_instance == instance) in hci_remove_advertising_sync()
1905 next = hci_get_next_instance(hdev, instance); in hci_remove_advertising_sync()
1908 err = hci_clear_adv_sync(hdev, sk, force); in hci_remove_advertising_sync()
1912 struct adv_info *adv = hci_find_adv_instance(hdev, instance); in hci_remove_advertising_sync()
1919 err = hci_remove_adv_sync(hdev, instance, sk); in hci_remove_advertising_sync()
1925 if (!hdev_is_powered(hdev) || hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_remove_advertising_sync()
1928 if (next && !ext_adv_capable(hdev)) in hci_remove_advertising_sync()
1929 hci_schedule_adv_instance_sync(hdev, next->instance, false); in hci_remove_advertising_sync()
1934 int hci_read_rssi_sync(struct hci_dev *hdev, __le16 handle) in hci_read_rssi_sync() argument
1939 return __hci_cmd_sync_status(hdev, HCI_OP_READ_RSSI, in hci_read_rssi_sync()
1943 int hci_read_clock_sync(struct hci_dev *hdev, struct hci_cp_read_clock *cp) in hci_read_clock_sync() argument
1945 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLOCK, in hci_read_clock_sync()
1949 int hci_read_tx_power_sync(struct hci_dev *hdev, __le16 handle, u8 type) in hci_read_tx_power_sync() argument
1955 return __hci_cmd_sync_status(hdev, HCI_OP_READ_TX_POWER, in hci_read_tx_power_sync()
1959 int hci_disable_advertising_sync(struct hci_dev *hdev) in hci_disable_advertising_sync() argument
1965 if (!hci_dev_test_flag(hdev, HCI_LE_ADV)) in hci_disable_advertising_sync()
1968 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
1969 err = hci_disable_ext_adv_instance_sync(hdev, 0x00); in hci_disable_advertising_sync()
1970 if (ext_adv_capable(hdev)) in hci_disable_advertising_sync()
1973 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_disable_advertising_sync()
1977 static int hci_le_set_ext_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_ext_scan_enable_sync() argument
1985 if (hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_ext_scan_enable_sync()
1990 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_ENABLE, in hci_le_set_ext_scan_enable_sync()
1994 static int hci_le_set_scan_enable_sync(struct hci_dev *hdev, u8 val, in hci_le_set_scan_enable_sync() argument
1999 if (use_ext_scan(hdev)) in hci_le_set_scan_enable_sync()
2000 return hci_le_set_ext_scan_enable_sync(hdev, val, filter_dup); in hci_le_set_scan_enable_sync()
2005 if (val && hci_dev_test_flag(hdev, HCI_MESH)) in hci_le_set_scan_enable_sync()
2010 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_ENABLE, in hci_le_set_scan_enable_sync()
2014 static int hci_le_set_addr_resolution_enable_sync(struct hci_dev *hdev, u8 val) in hci_le_set_addr_resolution_enable_sync() argument
2016 if (!use_ll_privacy(hdev)) in hci_le_set_addr_resolution_enable_sync()
2020 if (val == hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_le_set_addr_resolution_enable_sync()
2023 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADDR_RESOLV_ENABLE, in hci_le_set_addr_resolution_enable_sync()
2027 static int hci_scan_disable_sync(struct hci_dev *hdev) in hci_scan_disable_sync() argument
2032 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_scan_disable_sync()
2035 if (hdev->scanning_paused) { in hci_scan_disable_sync()
2036 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_scan_disable_sync()
2040 err = hci_le_set_scan_enable_sync(hdev, LE_SCAN_DISABLE, 0x00); in hci_scan_disable_sync()
2042 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_scan_disable_sync()
2049 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
2051 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
2054 static void hci_start_interleave_scan(struct hci_dev *hdev) in hci_start_interleave_scan() argument
2056 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_start_interleave_scan()
2057 queue_delayed_work(hdev->req_workqueue, in hci_start_interleave_scan()
2058 &hdev->interleave_scan, 0); in hci_start_interleave_scan()
2061 static bool is_interleave_scanning(struct hci_dev *hdev) in is_interleave_scanning() argument
2063 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
2066 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
2068 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
2070 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
2072 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
2078 static bool hci_update_interleaved_scan_sync(struct hci_dev *hdev) in hci_update_interleaved_scan_sync() argument
2087 bool use_interleaving = hci_is_adv_monitoring(hdev) && in hci_update_interleaved_scan_sync()
2088 !(list_empty(&hdev->pend_le_conns) && in hci_update_interleaved_scan_sync()
2089 list_empty(&hdev->pend_le_reports)) && in hci_update_interleaved_scan_sync()
2090 hci_get_adv_monitor_offload_ext(hdev) == in hci_update_interleaved_scan_sync()
2092 bool is_interleaving = is_interleave_scanning(hdev); in hci_update_interleaved_scan_sync()
2095 hci_start_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2096 bt_dev_dbg(hdev, "starting interleave scan"); in hci_update_interleaved_scan_sync()
2101 cancel_interleave_scan(hdev); in hci_update_interleaved_scan_sync()
2107 static int hci_le_del_resolve_list_sync(struct hci_dev *hdev, in hci_le_del_resolve_list_sync() argument
2113 if (!use_ll_privacy(hdev)) in hci_le_del_resolve_list_sync()
2117 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, bdaddr, in hci_le_del_resolve_list_sync()
2125 return __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_RESOLV_LIST, in hci_le_del_resolve_list_sync()
2129 static int hci_le_del_accept_list_sync(struct hci_dev *hdev, in hci_le_del_accept_list_sync() argument
2136 if (!hci_bdaddr_list_lookup(&hdev->le_accept_list, bdaddr, bdaddr_type)) in hci_le_del_accept_list_sync()
2145 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_del_accept_list_sync()
2147 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_DEL_FROM_ACCEPT_LIST, in hci_le_del_accept_list_sync()
2150 bt_dev_err(hdev, "Unable to remove from allow list: %d", err); in hci_le_del_accept_list_sync()
2154 bt_dev_dbg(hdev, "Remove %pMR (0x%x) from allow list", &cp.bdaddr, in hci_le_del_accept_list_sync()
2170 static int hci_le_add_resolve_list_sync(struct hci_dev *hdev, in hci_le_add_resolve_list_sync() argument
2178 if (!use_ll_privacy(hdev)) in hci_le_add_resolve_list_sync()
2185 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2188 hci_copy_identity_address(hdev, &cp.bdaddr, &cp.bdaddr_type); in hci_le_add_resolve_list_sync()
2189 memcpy(cp.peer_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2193 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_add_resolve_list_sync()
2198 entry = hci_bdaddr_list_lookup_with_irk(&hdev->le_resolv_list, in hci_le_add_resolve_list_sync()
2212 p = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_le_add_resolve_list_sync()
2215 p = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_le_add_resolve_list_sync()
2222 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in hci_le_add_resolve_list_sync()
2223 memcpy(cp.local_irk, hdev->irk, 16); in hci_le_add_resolve_list_sync()
2227 return __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_RESOLV_LIST, in hci_le_add_resolve_list_sync()
2232 static int hci_le_set_privacy_mode_sync(struct hci_dev *hdev, in hci_le_set_privacy_mode_sync() argument
2249 irk = hci_find_irk_by_addr(hdev, &params->addr, params->addr_type); in hci_le_set_privacy_mode_sync()
2260 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_PRIVACY_MODE, in hci_le_set_privacy_mode_sync()
2268 static int hci_le_add_accept_list_sync(struct hci_dev *hdev, in hci_le_add_accept_list_sync() argument
2276 if (hdev->suspended && in hci_le_add_accept_list_sync()
2281 if (*num_entries >= hdev->le_accept_list_size) in hci_le_add_accept_list_sync()
2285 if (!use_ll_privacy(hdev) && in hci_le_add_accept_list_sync()
2286 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) in hci_le_add_accept_list_sync()
2293 err = hci_le_add_resolve_list_sync(hdev, params); in hci_le_add_accept_list_sync()
2295 bt_dev_err(hdev, "Unable to add to resolve list: %d", err); in hci_le_add_accept_list_sync()
2300 err = hci_le_set_privacy_mode_sync(hdev, params); in hci_le_add_accept_list_sync()
2302 bt_dev_err(hdev, "Unable to set privacy mode: %d", err); in hci_le_add_accept_list_sync()
2307 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in hci_le_add_accept_list_sync()
2315 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_ADD_TO_ACCEPT_LIST, in hci_le_add_accept_list_sync()
2318 bt_dev_err(hdev, "Unable to add to allow list: %d", err); in hci_le_add_accept_list_sync()
2320 hci_le_del_resolve_list_sync(hdev, &cp.bdaddr, cp.bdaddr_type); in hci_le_add_accept_list_sync()
2324 bt_dev_dbg(hdev, "Add %pMR (0x%x) to allow list", &cp.bdaddr, in hci_le_add_accept_list_sync()
2331 static int hci_pause_advertising_sync(struct hci_dev *hdev) in hci_pause_advertising_sync() argument
2337 if (hdev->advertising_paused) in hci_pause_advertising_sync()
2340 bt_dev_dbg(hdev, "Pausing directed advertising"); in hci_pause_advertising_sync()
2343 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_pause_advertising_sync()
2350 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_pause_advertising_sync()
2351 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_pause_advertising_sync()
2352 hdev->discov_timeout = 0; in hci_pause_advertising_sync()
2355 bt_dev_dbg(hdev, "Pausing advertising instances"); in hci_pause_advertising_sync()
2360 err = hci_disable_advertising_sync(hdev); in hci_pause_advertising_sync()
2365 if (!ext_adv_capable(hdev)) in hci_pause_advertising_sync()
2366 cancel_adv_timeout(hdev); in hci_pause_advertising_sync()
2368 hdev->advertising_paused = true; in hci_pause_advertising_sync()
2369 hdev->advertising_old_state = old_state; in hci_pause_advertising_sync()
2375 static int hci_resume_advertising_sync(struct hci_dev *hdev) in hci_resume_advertising_sync() argument
2381 if (!hdev->advertising_paused) in hci_resume_advertising_sync()
2385 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2386 if (hdev->advertising_old_state) { in hci_resume_advertising_sync()
2387 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_resume_advertising_sync()
2388 hdev->advertising_old_state = 0; in hci_resume_advertising_sync()
2391 bt_dev_dbg(hdev, "Resuming advertising instances"); in hci_resume_advertising_sync()
2393 if (ext_adv_capable(hdev)) { in hci_resume_advertising_sync()
2395 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) { in hci_resume_advertising_sync()
2396 err = hci_enable_ext_advertising_sync(hdev, in hci_resume_advertising_sync()
2402 hci_remove_ext_adv_instance_sync(hdev, adv->instance, in hci_resume_advertising_sync()
2409 err = hci_schedule_adv_instance_sync(hdev, in hci_resume_advertising_sync()
2410 hdev->cur_adv_instance, in hci_resume_advertising_sync()
2414 hdev->advertising_paused = false; in hci_resume_advertising_sync()
2419 static int hci_pause_addr_resolution(struct hci_dev *hdev) in hci_pause_addr_resolution() argument
2423 if (!use_ll_privacy(hdev)) in hci_pause_addr_resolution()
2426 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_pause_addr_resolution()
2432 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) || in hci_pause_addr_resolution()
2433 hci_lookup_le_connect(hdev)) { in hci_pause_addr_resolution()
2434 bt_dev_err(hdev, "Command not allowed when scan/LE connect"); in hci_pause_addr_resolution()
2439 err = hci_pause_advertising_sync(hdev); in hci_pause_addr_resolution()
2441 bt_dev_err(hdev, "Pause advertising failed: %d", err); in hci_pause_addr_resolution()
2445 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_pause_addr_resolution()
2447 bt_dev_err(hdev, "Unable to disable Address Resolution: %d", in hci_pause_addr_resolution()
2451 if (!err && scan_use_rpa(hdev)) in hci_pause_addr_resolution()
2454 hci_resume_advertising_sync(hdev); in hci_pause_addr_resolution()
2458 struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, in hci_read_local_oob_data_sync() argument
2464 return __hci_cmd_sync_sk(hdev, opcode, 0, NULL, 0, HCI_CMD_TIMEOUT, sk); in hci_read_local_oob_data_sync()
2530 static u8 hci_update_accept_list_sync(struct hci_dev *hdev) in hci_update_accept_list_sync() argument
2543 if (use_ll_privacy(hdev)) { in hci_update_accept_list_sync()
2544 err = hci_pause_advertising_sync(hdev); in hci_update_accept_list_sync()
2546 bt_dev_err(hdev, "pause advertising failed: %d", err); in hci_update_accept_list_sync()
2555 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); in hci_update_accept_list_sync()
2557 bt_dev_err(hdev, "Unable to disable LL privacy: %d", err); in hci_update_accept_list_sync()
2567 list_for_each_entry_safe(b, t, &hdev->le_accept_list, list) { in hci_update_accept_list_sync()
2568 if (hci_conn_hash_lookup_le(hdev, &b->bdaddr, b->bdaddr_type)) in hci_update_accept_list_sync()
2572 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in hci_update_accept_list_sync()
2575 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in hci_update_accept_list_sync()
2583 hci_le_del_accept_list_sync(hdev, &b->bdaddr, in hci_update_accept_list_sync()
2605 params = conn_params_copy(&hdev->pend_le_conns, &n); in hci_update_accept_list_sync()
2612 err = hci_le_add_accept_list_sync(hdev, &params[i], in hci_update_accept_list_sync()
2627 params = conn_params_copy(&hdev->pend_le_reports, &n); in hci_update_accept_list_sync()
2634 err = hci_le_add_accept_list_sync(hdev, &params[i], in hci_update_accept_list_sync()
2649 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in hci_update_accept_list_sync()
2650 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE && in hci_update_accept_list_sync()
2651 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in hci_update_accept_list_sync()
2658 err = hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_update_accept_list_sync()
2660 bt_dev_err(hdev, "Unable to enable LL privacy: %d", err); in hci_update_accept_list_sync()
2663 if (use_ll_privacy(hdev)) in hci_update_accept_list_sync()
2664 hci_resume_advertising_sync(hdev); in hci_update_accept_list_sync()
2670 static int hci_le_set_ext_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_ext_scan_param_sync() argument
2687 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_le_set_ext_scan_param_sync()
2698 if (scan_coded(hdev)) { in hci_le_set_ext_scan_param_sync()
2709 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_SCAN_PARAMS, in hci_le_set_ext_scan_param_sync()
2714 static int hci_le_set_scan_param_sync(struct hci_dev *hdev, u8 type, in hci_le_set_scan_param_sync() argument
2720 if (use_ext_scan(hdev)) in hci_le_set_scan_param_sync()
2721 return hci_le_set_ext_scan_param_sync(hdev, type, interval, in hci_le_set_scan_param_sync()
2732 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_SCAN_PARAM, in hci_le_set_scan_param_sync()
2736 static int hci_start_scan_sync(struct hci_dev *hdev, u8 type, u16 interval, in hci_start_scan_sync() argument
2742 if (hdev->scanning_paused) { in hci_start_scan_sync()
2743 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_start_scan_sync()
2747 err = hci_le_set_scan_param_sync(hdev, type, interval, window, in hci_start_scan_sync()
2752 return hci_le_set_scan_enable_sync(hdev, LE_SCAN_ENABLE, filter_dup); in hci_start_scan_sync()
2755 static int hci_passive_scan_sync(struct hci_dev *hdev) in hci_passive_scan_sync() argument
2763 if (hdev->scanning_paused) { in hci_passive_scan_sync()
2764 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_passive_scan_sync()
2768 err = hci_scan_disable_sync(hdev); in hci_passive_scan_sync()
2770 bt_dev_err(hdev, "disable scanning failed: %d", err); in hci_passive_scan_sync()
2780 if (hci_update_random_address_sync(hdev, false, scan_use_rpa(hdev), in hci_passive_scan_sync()
2784 if (hdev->enable_advmon_interleave_scan && in hci_passive_scan_sync()
2785 hci_update_interleaved_scan_sync(hdev)) in hci_passive_scan_sync()
2788 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_passive_scan_sync()
2794 filter_policy = hci_update_accept_list_sync(hdev); in hci_passive_scan_sync()
2805 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_passive_scan_sync()
2806 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_passive_scan_sync()
2809 if (hdev->suspended) { in hci_passive_scan_sync()
2810 window = hdev->le_scan_window_suspend; in hci_passive_scan_sync()
2811 interval = hdev->le_scan_int_suspend; in hci_passive_scan_sync()
2812 } else if (hci_is_le_conn_scanning(hdev)) { in hci_passive_scan_sync()
2813 window = hdev->le_scan_window_connect; in hci_passive_scan_sync()
2814 interval = hdev->le_scan_int_connect; in hci_passive_scan_sync()
2815 } else if (hci_is_adv_monitoring(hdev)) { in hci_passive_scan_sync()
2816 window = hdev->le_scan_window_adv_monitor; in hci_passive_scan_sync()
2817 interval = hdev->le_scan_int_adv_monitor; in hci_passive_scan_sync()
2819 window = hdev->le_scan_window; in hci_passive_scan_sync()
2820 interval = hdev->le_scan_interval; in hci_passive_scan_sync()
2824 if (hci_dev_test_flag(hdev, HCI_MESH)) { in hci_passive_scan_sync()
2829 bt_dev_dbg(hdev, "LE passive scan with acceptlist = %d", filter_policy); in hci_passive_scan_sync()
2831 return hci_start_scan_sync(hdev, LE_SCAN_PASSIVE, interval, window, in hci_passive_scan_sync()
2850 int hci_update_passive_scan_sync(struct hci_dev *hdev) in hci_update_passive_scan_sync() argument
2854 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan_sync()
2855 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan_sync()
2856 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan_sync()
2857 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan_sync()
2858 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan_sync()
2859 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan_sync()
2863 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_update_passive_scan_sync()
2867 if (hdev->discovery.state != DISCOVERY_STOPPED) in hci_update_passive_scan_sync()
2877 hci_discovery_filter_clear(hdev); in hci_update_passive_scan_sync()
2879 bt_dev_dbg(hdev, "ADV monitoring is %s", in hci_update_passive_scan_sync()
2880 hci_is_adv_monitoring(hdev) ? "on" : "off"); in hci_update_passive_scan_sync()
2882 if (!hci_dev_test_flag(hdev, HCI_MESH) && in hci_update_passive_scan_sync()
2883 list_empty(&hdev->pend_le_conns) && in hci_update_passive_scan_sync()
2884 list_empty(&hdev->pend_le_reports) && in hci_update_passive_scan_sync()
2885 !hci_is_adv_monitoring(hdev) && in hci_update_passive_scan_sync()
2886 !hci_dev_test_flag(hdev, HCI_PA_SYNC)) { in hci_update_passive_scan_sync()
2892 bt_dev_dbg(hdev, "stopping background scanning"); in hci_update_passive_scan_sync()
2894 err = hci_scan_disable_sync(hdev); in hci_update_passive_scan_sync()
2896 bt_dev_err(hdev, "stop background scanning failed: %d", in hci_update_passive_scan_sync()
2907 if (hci_lookup_le_connect(hdev)) in hci_update_passive_scan_sync()
2910 bt_dev_dbg(hdev, "start background scanning"); in hci_update_passive_scan_sync()
2912 err = hci_passive_scan_sync(hdev); in hci_update_passive_scan_sync()
2914 bt_dev_err(hdev, "start background scanning failed: %d", in hci_update_passive_scan_sync()
2921 static int update_scan_sync(struct hci_dev *hdev, void *data) in update_scan_sync() argument
2923 return hci_update_scan_sync(hdev); in update_scan_sync()
2926 int hci_update_scan(struct hci_dev *hdev) in hci_update_scan() argument
2928 return hci_cmd_sync_queue(hdev, update_scan_sync, NULL, NULL); in hci_update_scan()
2931 static int update_passive_scan_sync(struct hci_dev *hdev, void *data) in update_passive_scan_sync() argument
2933 return hci_update_passive_scan_sync(hdev); in update_passive_scan_sync()
2936 int hci_update_passive_scan(struct hci_dev *hdev) in hci_update_passive_scan() argument
2939 if (!test_bit(HCI_UP, &hdev->flags) || in hci_update_passive_scan()
2940 test_bit(HCI_INIT, &hdev->flags) || in hci_update_passive_scan()
2941 hci_dev_test_flag(hdev, HCI_SETUP) || in hci_update_passive_scan()
2942 hci_dev_test_flag(hdev, HCI_CONFIG) || in hci_update_passive_scan()
2943 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in hci_update_passive_scan()
2944 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in hci_update_passive_scan()
2947 return hci_cmd_sync_queue(hdev, update_passive_scan_sync, NULL, NULL); in hci_update_passive_scan()
2950 int hci_write_sc_support_sync(struct hci_dev *hdev, u8 val) in hci_write_sc_support_sync() argument
2954 if (!bredr_sc_enabled(hdev) || lmp_host_sc_capable(hdev)) in hci_write_sc_support_sync()
2957 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_sync()
2962 hdev->features[1][0] |= LMP_HOST_SC; in hci_write_sc_support_sync()
2963 hci_dev_set_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
2965 hdev->features[1][0] &= ~LMP_HOST_SC; in hci_write_sc_support_sync()
2966 hci_dev_clear_flag(hdev, HCI_SC_ENABLED); in hci_write_sc_support_sync()
2973 int hci_write_ssp_mode_sync(struct hci_dev *hdev, u8 mode) in hci_write_ssp_mode_sync() argument
2977 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_ssp_mode_sync()
2978 lmp_host_ssp_capable(hdev)) in hci_write_ssp_mode_sync()
2981 if (!mode && hci_dev_test_flag(hdev, HCI_USE_DEBUG_KEYS)) { in hci_write_ssp_mode_sync()
2982 __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_DEBUG_MODE, in hci_write_ssp_mode_sync()
2986 err = __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_sync()
2991 return hci_write_sc_support_sync(hdev, 0x01); in hci_write_ssp_mode_sync()
2994 int hci_write_le_host_supported_sync(struct hci_dev *hdev, u8 le, u8 simul) in hci_write_le_host_supported_sync() argument
2998 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED) || in hci_write_le_host_supported_sync()
2999 !lmp_bredr_capable(hdev)) in hci_write_le_host_supported_sync()
3005 if (le == lmp_host_le_capable(hdev) && in hci_write_le_host_supported_sync()
3006 simul == lmp_host_le_br_capable(hdev)) in hci_write_le_host_supported_sync()
3014 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_write_le_host_supported_sync()
3018 static int hci_powered_update_adv_sync(struct hci_dev *hdev) in hci_powered_update_adv_sync() argument
3023 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in hci_powered_update_adv_sync()
3031 if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) { in hci_powered_update_adv_sync()
3032 hci_le_add_resolve_list_sync(hdev, NULL); in hci_powered_update_adv_sync()
3033 hci_le_set_addr_resolution_enable_sync(hdev, 0x01); in hci_powered_update_adv_sync()
3040 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_powered_update_adv_sync()
3041 list_empty(&hdev->adv_instances)) { in hci_powered_update_adv_sync()
3042 if (ext_adv_capable(hdev)) { in hci_powered_update_adv_sync()
3043 err = hci_setup_ext_adv_instance_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3045 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3047 err = hci_update_adv_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3049 hci_update_scan_rsp_data_sync(hdev, 0x00); in hci_powered_update_adv_sync()
3052 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_powered_update_adv_sync()
3053 hci_enable_advertising_sync(hdev); in hci_powered_update_adv_sync()
3057 list_for_each_entry_safe(adv, tmp, &hdev->adv_instances, list) in hci_powered_update_adv_sync()
3058 hci_schedule_adv_instance_sync(hdev, adv->instance, true); in hci_powered_update_adv_sync()
3063 static int hci_write_auth_enable_sync(struct hci_dev *hdev) in hci_write_auth_enable_sync() argument
3067 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in hci_write_auth_enable_sync()
3068 if (link_sec == test_bit(HCI_AUTH, &hdev->flags)) in hci_write_auth_enable_sync()
3071 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_AUTH_ENABLE, in hci_write_auth_enable_sync()
3076 int hci_write_fast_connectable_sync(struct hci_dev *hdev, bool enable) in hci_write_fast_connectable_sync() argument
3082 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_write_fast_connectable_sync()
3085 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_write_fast_connectable_sync()
3096 type = hdev->def_page_scan_type; in hci_write_fast_connectable_sync()
3097 cp.interval = cpu_to_le16(hdev->def_page_scan_int); in hci_write_fast_connectable_sync()
3100 cp.window = cpu_to_le16(hdev->def_page_scan_window); in hci_write_fast_connectable_sync()
3102 if (__cpu_to_le16(hdev->page_scan_interval) != cp.interval || in hci_write_fast_connectable_sync()
3103 __cpu_to_le16(hdev->page_scan_window) != cp.window) { in hci_write_fast_connectable_sync()
3104 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3111 if (hdev->page_scan_type != type) in hci_write_fast_connectable_sync()
3112 err = __hci_cmd_sync_status(hdev, in hci_write_fast_connectable_sync()
3120 static bool disconnected_accept_list_entries(struct hci_dev *hdev) in disconnected_accept_list_entries() argument
3124 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
3127 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
3138 static int hci_write_scan_enable_sync(struct hci_dev *hdev, u8 val) in hci_write_scan_enable_sync() argument
3140 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SCAN_ENABLE, in hci_write_scan_enable_sync()
3145 int hci_update_scan_sync(struct hci_dev *hdev) in hci_update_scan_sync() argument
3149 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_scan_sync()
3152 if (!hdev_is_powered(hdev)) in hci_update_scan_sync()
3155 if (mgmt_powering_down(hdev)) in hci_update_scan_sync()
3158 if (hdev->scanning_paused) in hci_update_scan_sync()
3161 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in hci_update_scan_sync()
3162 disconnected_accept_list_entries(hdev)) in hci_update_scan_sync()
3167 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_update_scan_sync()
3170 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in hci_update_scan_sync()
3171 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in hci_update_scan_sync()
3174 return hci_write_scan_enable_sync(hdev, scan); in hci_update_scan_sync()
3177 int hci_update_name_sync(struct hci_dev *hdev) in hci_update_name_sync() argument
3183 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in hci_update_name_sync()
3185 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LOCAL_NAME, in hci_update_name_sync()
3202 int hci_powered_update_sync(struct hci_dev *hdev) in hci_powered_update_sync() argument
3211 smp_register(hdev); in hci_powered_update_sync()
3213 err = hci_write_ssp_mode_sync(hdev, 0x01); in hci_powered_update_sync()
3217 err = hci_write_le_host_supported_sync(hdev, 0x01, 0x00); in hci_powered_update_sync()
3221 err = hci_powered_update_adv_sync(hdev); in hci_powered_update_sync()
3225 err = hci_write_auth_enable_sync(hdev); in hci_powered_update_sync()
3229 if (lmp_bredr_capable(hdev)) { in hci_powered_update_sync()
3230 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in hci_powered_update_sync()
3231 hci_write_fast_connectable_sync(hdev, true); in hci_powered_update_sync()
3233 hci_write_fast_connectable_sync(hdev, false); in hci_powered_update_sync()
3234 hci_update_scan_sync(hdev); in hci_powered_update_sync()
3235 hci_update_class_sync(hdev); in hci_powered_update_sync()
3236 hci_update_name_sync(hdev); in hci_powered_update_sync()
3237 hci_update_eir_sync(hdev); in hci_powered_update_sync()
3249 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_powered_update_sync()
3250 (!bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_powered_update_sync()
3251 !hci_dev_test_flag(hdev, HCI_BREDR_ENABLED))) { in hci_powered_update_sync()
3252 if (bacmp(&hdev->static_addr, BDADDR_ANY)) in hci_powered_update_sync()
3253 return hci_set_random_addr_sync(hdev, in hci_powered_update_sync()
3254 &hdev->static_addr); in hci_powered_update_sync()
3272 static void hci_dev_get_bd_addr_from_property(struct hci_dev *hdev) in hci_dev_get_bd_addr_from_property() argument
3274 struct fwnode_handle *fwnode = dev_fwnode(hdev->dev.parent); in hci_dev_get_bd_addr_from_property()
3283 bacpy(&hdev->public_addr, &ba); in hci_dev_get_bd_addr_from_property()
3287 int (*func)(struct hci_dev *hdev);
3291 static int hci_init_stage_sync(struct hci_dev *hdev, in hci_init_stage_sync() argument
3299 err = stage[i].func(hdev); in hci_init_stage_sync()
3308 static int hci_read_local_version_sync(struct hci_dev *hdev) in hci_read_local_version_sync() argument
3310 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_VERSION, in hci_read_local_version_sync()
3315 static int hci_read_bd_addr_sync(struct hci_dev *hdev) in hci_read_bd_addr_sync() argument
3317 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BD_ADDR, in hci_read_bd_addr_sync()
3334 int hci_reset_sync(struct hci_dev *hdev) in hci_reset_sync() argument
3338 set_bit(HCI_RESET, &hdev->flags); in hci_reset_sync()
3340 err = __hci_cmd_sync_status(hdev, HCI_OP_RESET, 0, NULL, in hci_reset_sync()
3348 static int hci_init0_sync(struct hci_dev *hdev) in hci_init0_sync() argument
3352 bt_dev_dbg(hdev, ""); in hci_init0_sync()
3355 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init0_sync()
3356 err = hci_reset_sync(hdev); in hci_init0_sync()
3361 return hci_init_stage_sync(hdev, hci_init0); in hci_init0_sync()
3364 static int hci_unconf_init_sync(struct hci_dev *hdev) in hci_unconf_init_sync() argument
3368 if (test_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks)) in hci_unconf_init_sync()
3371 err = hci_init0_sync(hdev); in hci_unconf_init_sync()
3375 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_unconf_init_sync()
3376 hci_debugfs_create_basic(hdev); in hci_unconf_init_sync()
3382 static int hci_read_local_features_sync(struct hci_dev *hdev) in hci_read_local_features_sync() argument
3385 if (hdev->dev_type == HCI_AMP && !(hdev->commands[14] & 0x20)) in hci_read_local_features_sync()
3388 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_FEATURES, in hci_read_local_features_sync()
3404 static int hci_read_local_cmds_sync(struct hci_dev *hdev) in hci_read_local_cmds_sync() argument
3414 if (hdev->hci_ver > BLUETOOTH_VER_1_1 && in hci_read_local_cmds_sync()
3415 !test_bit(HCI_QUIRK_BROKEN_LOCAL_COMMANDS, &hdev->quirks)) in hci_read_local_cmds_sync()
3416 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_COMMANDS, in hci_read_local_cmds_sync()
3423 static int hci_read_local_amp_info_sync(struct hci_dev *hdev) in hci_read_local_amp_info_sync() argument
3425 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_AMP_INFO, in hci_read_local_amp_info_sync()
3430 static int hci_read_data_block_size_sync(struct hci_dev *hdev) in hci_read_data_block_size_sync() argument
3432 return __hci_cmd_sync_status(hdev, HCI_OP_READ_DATA_BLOCK_SIZE, in hci_read_data_block_size_sync()
3437 static int hci_read_flow_control_mode_sync(struct hci_dev *hdev) in hci_read_flow_control_mode_sync() argument
3439 return __hci_cmd_sync_status(hdev, HCI_OP_READ_FLOW_CONTROL_MODE, in hci_read_flow_control_mode_sync()
3444 static int hci_read_location_data_sync(struct hci_dev *hdev) in hci_read_location_data_sync() argument
3446 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCATION_DATA, in hci_read_location_data_sync()
3467 static int hci_init1_sync(struct hci_dev *hdev) in hci_init1_sync() argument
3471 bt_dev_dbg(hdev, ""); in hci_init1_sync()
3474 if (!test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks)) { in hci_init1_sync()
3475 err = hci_reset_sync(hdev); in hci_init1_sync()
3480 switch (hdev->dev_type) { in hci_init1_sync()
3482 hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_PACKET_BASED; in hci_init1_sync()
3483 return hci_init_stage_sync(hdev, br_init1); in hci_init1_sync()
3485 hdev->flow_ctl_mode = HCI_FLOW_CTL_MODE_BLOCK_BASED; in hci_init1_sync()
3486 return hci_init_stage_sync(hdev, amp_init1); in hci_init1_sync()
3488 bt_dev_err(hdev, "Unknown device type %d", hdev->dev_type); in hci_init1_sync()
3503 static int hci_read_buffer_size_sync(struct hci_dev *hdev) in hci_read_buffer_size_sync() argument
3505 return __hci_cmd_sync_status(hdev, HCI_OP_READ_BUFFER_SIZE, in hci_read_buffer_size_sync()
3510 static int hci_read_dev_class_sync(struct hci_dev *hdev) in hci_read_dev_class_sync() argument
3512 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CLASS_OF_DEV, in hci_read_dev_class_sync()
3517 static int hci_read_local_name_sync(struct hci_dev *hdev) in hci_read_local_name_sync() argument
3519 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_NAME, in hci_read_local_name_sync()
3524 static int hci_read_voice_setting_sync(struct hci_dev *hdev) in hci_read_voice_setting_sync() argument
3526 return __hci_cmd_sync_status(hdev, HCI_OP_READ_VOICE_SETTING, in hci_read_voice_setting_sync()
3531 static int hci_read_num_supported_iac_sync(struct hci_dev *hdev) in hci_read_num_supported_iac_sync() argument
3533 return __hci_cmd_sync_status(hdev, HCI_OP_READ_NUM_SUPPORTED_IAC, in hci_read_num_supported_iac_sync()
3538 static int hci_read_current_iac_lap_sync(struct hci_dev *hdev) in hci_read_current_iac_lap_sync() argument
3540 return __hci_cmd_sync_status(hdev, HCI_OP_READ_CURRENT_IAC_LAP, in hci_read_current_iac_lap_sync()
3544 static int hci_set_event_filter_sync(struct hci_dev *hdev, u8 flt_type, in hci_set_event_filter_sync() argument
3550 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_set_event_filter_sync()
3553 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_set_event_filter_sync()
3565 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_FLT, in hci_set_event_filter_sync()
3571 static int hci_clear_event_filter_sync(struct hci_dev *hdev) in hci_clear_event_filter_sync() argument
3573 if (!hci_dev_test_flag(hdev, HCI_EVENT_FILTER_CONFIGURED)) in hci_clear_event_filter_sync()
3580 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_clear_event_filter_sync()
3583 return hci_set_event_filter_sync(hdev, HCI_FLT_CLEAR_ALL, 0x00, in hci_clear_event_filter_sync()
3588 static int hci_write_ca_timeout_sync(struct hci_dev *hdev) in hci_write_ca_timeout_sync() argument
3592 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CA_TIMEOUT, in hci_write_ca_timeout_sync()
3617 static int hci_write_ssp_mode_1_sync(struct hci_dev *hdev) in hci_write_ssp_mode_1_sync() argument
3621 if (!lmp_ssp_capable(hdev) || !hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_ssp_mode_1_sync()
3630 hdev->max_page = 0x01; in hci_write_ssp_mode_1_sync()
3632 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SSP_MODE, in hci_write_ssp_mode_1_sync()
3636 static int hci_write_eir_sync(struct hci_dev *hdev) in hci_write_eir_sync() argument
3640 if (!lmp_ssp_capable(hdev) || hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in hci_write_eir_sync()
3643 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_write_eir_sync()
3646 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_EIR, sizeof(cp), &cp, in hci_write_eir_sync()
3650 static int hci_write_inquiry_mode_sync(struct hci_dev *hdev) in hci_write_inquiry_mode_sync() argument
3654 if (!lmp_inq_rssi_capable(hdev) && in hci_write_inquiry_mode_sync()
3655 !test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_write_inquiry_mode_sync()
3662 mode = lmp_ext_inq_capable(hdev) ? 0x02 : 0x01; in hci_write_inquiry_mode_sync()
3664 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_INQUIRY_MODE, in hci_write_inquiry_mode_sync()
3668 static int hci_read_inq_rsp_tx_power_sync(struct hci_dev *hdev) in hci_read_inq_rsp_tx_power_sync() argument
3670 if (!lmp_inq_tx_pwr_capable(hdev)) in hci_read_inq_rsp_tx_power_sync()
3673 return __hci_cmd_sync_status(hdev, HCI_OP_READ_INQ_RSP_TX_POWER, in hci_read_inq_rsp_tx_power_sync()
3677 static int hci_read_local_ext_features_sync(struct hci_dev *hdev, u8 page) in hci_read_local_ext_features_sync() argument
3681 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_sync()
3687 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_EXT_FEATURES, in hci_read_local_ext_features_sync()
3691 static int hci_read_local_ext_features_1_sync(struct hci_dev *hdev) in hci_read_local_ext_features_1_sync() argument
3693 return hci_read_local_ext_features_sync(hdev, 0x01); in hci_read_local_ext_features_1_sync()
3716 static int hci_le_read_buffer_size_sync(struct hci_dev *hdev) in hci_le_read_buffer_size_sync() argument
3719 if (iso_capable(hdev) && hdev->commands[41] & 0x20) in hci_le_read_buffer_size_sync()
3720 return __hci_cmd_sync_status(hdev, in hci_le_read_buffer_size_sync()
3724 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_BUFFER_SIZE, in hci_le_read_buffer_size_sync()
3729 static int hci_le_read_local_features_sync(struct hci_dev *hdev) in hci_le_read_local_features_sync() argument
3731 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_LOCAL_FEATURES, in hci_le_read_local_features_sync()
3736 static int hci_le_read_supported_states_sync(struct hci_dev *hdev) in hci_le_read_supported_states_sync() argument
3738 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_SUPPORTED_STATES, in hci_le_read_supported_states_sync()
3753 static int hci_init2_sync(struct hci_dev *hdev) in hci_init2_sync() argument
3757 bt_dev_dbg(hdev, ""); in hci_init2_sync()
3759 if (hdev->dev_type == HCI_AMP) in hci_init2_sync()
3760 return hci_init_stage_sync(hdev, amp_init2); in hci_init2_sync()
3762 err = hci_init_stage_sync(hdev, hci_init2); in hci_init2_sync()
3766 if (lmp_bredr_capable(hdev)) { in hci_init2_sync()
3767 err = hci_init_stage_sync(hdev, br_init2); in hci_init2_sync()
3771 hci_dev_clear_flag(hdev, HCI_BREDR_ENABLED); in hci_init2_sync()
3774 if (lmp_le_capable(hdev)) { in hci_init2_sync()
3775 err = hci_init_stage_sync(hdev, le_init2); in hci_init2_sync()
3779 if (!lmp_bredr_capable(hdev)) in hci_init2_sync()
3780 hci_dev_set_flag(hdev, HCI_LE_ENABLED); in hci_init2_sync()
3786 static int hci_set_event_mask_sync(struct hci_dev *hdev) in hci_set_event_mask_sync() argument
3797 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_set_event_mask_sync()
3800 if (lmp_bredr_capable(hdev)) { in hci_set_event_mask_sync()
3807 if (hdev->suspended) in hci_set_event_mask_sync()
3820 if (hdev->commands[0] & 0x20) { in hci_set_event_mask_sync()
3825 if (!hdev->suspended) in hci_set_event_mask_sync()
3834 if (hdev->commands[2] & 0x80) in hci_set_event_mask_sync()
3839 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) { in hci_set_event_mask_sync()
3845 if (lmp_inq_rssi_capable(hdev) || in hci_set_event_mask_sync()
3846 test_bit(HCI_QUIRK_FIXUP_INQUIRY_MODE, &hdev->quirks)) in hci_set_event_mask_sync()
3849 if (lmp_ext_feat_capable(hdev)) in hci_set_event_mask_sync()
3852 if (lmp_esco_capable(hdev)) { in hci_set_event_mask_sync()
3857 if (lmp_sniffsubr_capable(hdev)) in hci_set_event_mask_sync()
3860 if (lmp_pause_enc_capable(hdev)) in hci_set_event_mask_sync()
3863 if (lmp_ext_inq_capable(hdev)) in hci_set_event_mask_sync()
3866 if (lmp_no_flush_capable(hdev)) in hci_set_event_mask_sync()
3869 if (lmp_lsto_capable(hdev)) in hci_set_event_mask_sync()
3872 if (lmp_ssp_capable(hdev)) { in hci_set_event_mask_sync()
3886 if (lmp_le_capable(hdev)) in hci_set_event_mask_sync()
3889 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK, in hci_set_event_mask_sync()
3893 static int hci_read_stored_link_key_sync(struct hci_dev *hdev) in hci_read_stored_link_key_sync() argument
3897 if (!(hdev->commands[6] & 0x20) || in hci_read_stored_link_key_sync()
3898 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_read_stored_link_key_sync()
3905 return __hci_cmd_sync_status(hdev, HCI_OP_READ_STORED_LINK_KEY, in hci_read_stored_link_key_sync()
3909 static int hci_setup_link_policy_sync(struct hci_dev *hdev) in hci_setup_link_policy_sync() argument
3914 if (!(hdev->commands[5] & 0x10)) in hci_setup_link_policy_sync()
3919 if (lmp_rswitch_capable(hdev)) in hci_setup_link_policy_sync()
3921 if (lmp_hold_capable(hdev)) in hci_setup_link_policy_sync()
3923 if (lmp_sniff_capable(hdev)) in hci_setup_link_policy_sync()
3925 if (lmp_park_capable(hdev)) in hci_setup_link_policy_sync()
3930 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_LINK_POLICY, in hci_setup_link_policy_sync()
3934 static int hci_read_page_scan_activity_sync(struct hci_dev *hdev) in hci_read_page_scan_activity_sync() argument
3936 if (!(hdev->commands[8] & 0x01)) in hci_read_page_scan_activity_sync()
3939 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_ACTIVITY, in hci_read_page_scan_activity_sync()
3943 static int hci_read_def_err_data_reporting_sync(struct hci_dev *hdev) in hci_read_def_err_data_reporting_sync() argument
3945 if (!(hdev->commands[18] & 0x04) || in hci_read_def_err_data_reporting_sync()
3946 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_read_def_err_data_reporting_sync()
3947 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_read_def_err_data_reporting_sync()
3950 return __hci_cmd_sync_status(hdev, HCI_OP_READ_DEF_ERR_DATA_REPORTING, in hci_read_def_err_data_reporting_sync()
3954 static int hci_read_page_scan_type_sync(struct hci_dev *hdev) in hci_read_page_scan_type_sync() argument
3960 if (!(hdev->commands[13] & 0x01)) in hci_read_page_scan_type_sync()
3963 return __hci_cmd_sync_status(hdev, HCI_OP_READ_PAGE_SCAN_TYPE, in hci_read_page_scan_type_sync()
3968 static int hci_read_local_ext_features_all_sync(struct hci_dev *hdev) in hci_read_local_ext_features_all_sync() argument
3973 if (!lmp_ext_feat_capable(hdev)) in hci_read_local_ext_features_all_sync()
3976 for (page = 2; page < HCI_MAX_PAGES && page <= hdev->max_page; in hci_read_local_ext_features_all_sync()
3978 err = hci_read_local_ext_features_sync(hdev, page); in hci_read_local_ext_features_all_sync()
4005 static int hci_le_set_event_mask_sync(struct hci_dev *hdev) in hci_le_set_event_mask_sync() argument
4009 if (!lmp_le_capable(hdev)) in hci_le_set_event_mask_sync()
4014 if (hdev->le_features[0] & HCI_LE_ENCRYPTION) in hci_le_set_event_mask_sync()
4020 if (hdev->le_features[0] & HCI_LE_CONN_PARAM_REQ_PROC) in hci_le_set_event_mask_sync()
4027 if (hdev->le_features[0] & HCI_LE_DATA_LEN_EXT) in hci_le_set_event_mask_sync()
4033 if (use_enhanced_conn_complete(hdev)) in hci_le_set_event_mask_sync()
4039 if (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY) in hci_le_set_event_mask_sync()
4045 if (hdev->le_features[1] & HCI_LE_CHAN_SEL_ALG2) in hci_le_set_event_mask_sync()
4051 if (hdev->commands[26] & 0x08) in hci_le_set_event_mask_sync()
4057 if (hdev->commands[26] & 0x10) in hci_le_set_event_mask_sync()
4063 if (hdev->commands[27] & 0x04) in hci_le_set_event_mask_sync()
4069 if (hdev->commands[27] & 0x20) in hci_le_set_event_mask_sync()
4076 if (hdev->commands[34] & 0x02) in hci_le_set_event_mask_sync()
4083 if (hdev->commands[34] & 0x04) in hci_le_set_event_mask_sync()
4089 if (hdev->commands[35] & (0x20 | 0x40)) in hci_le_set_event_mask_sync()
4096 if (use_ext_scan(hdev)) in hci_le_set_event_mask_sync()
4102 if (ext_adv_capable(hdev)) in hci_le_set_event_mask_sync()
4105 if (cis_capable(hdev)) { in hci_le_set_event_mask_sync()
4107 if (cis_peripheral_capable(hdev)) in hci_le_set_event_mask_sync()
4111 if (bis_capable(hdev)) { in hci_le_set_event_mask_sync()
4121 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EVENT_MASK, in hci_le_set_event_mask_sync()
4126 static int hci_le_read_adv_tx_power_sync(struct hci_dev *hdev) in hci_le_read_adv_tx_power_sync() argument
4128 if ((hdev->commands[25] & 0x40) && !ext_adv_capable(hdev)) { in hci_le_read_adv_tx_power_sync()
4135 return __hci_cmd_sync_status(hdev, in hci_le_read_adv_tx_power_sync()
4144 static int hci_le_read_tx_power_sync(struct hci_dev *hdev) in hci_le_read_tx_power_sync() argument
4146 if (!(hdev->commands[38] & 0x80) || in hci_le_read_tx_power_sync()
4147 test_bit(HCI_QUIRK_BROKEN_READ_TRANSMIT_POWER, &hdev->quirks)) in hci_le_read_tx_power_sync()
4150 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_TRANSMIT_POWER, in hci_le_read_tx_power_sync()
4155 static int hci_le_read_accept_list_size_sync(struct hci_dev *hdev) in hci_le_read_accept_list_size_sync() argument
4157 if (!(hdev->commands[26] & 0x40)) in hci_le_read_accept_list_size_sync()
4160 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_ACCEPT_LIST_SIZE, in hci_le_read_accept_list_size_sync()
4165 static int hci_le_clear_accept_list_sync(struct hci_dev *hdev) in hci_le_clear_accept_list_sync() argument
4167 if (!(hdev->commands[26] & 0x80)) in hci_le_clear_accept_list_sync()
4170 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_ACCEPT_LIST, 0, NULL, in hci_le_clear_accept_list_sync()
4175 static int hci_le_read_resolv_list_size_sync(struct hci_dev *hdev) in hci_le_read_resolv_list_size_sync() argument
4177 if (!(hdev->commands[34] & 0x40)) in hci_le_read_resolv_list_size_sync()
4180 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_RESOLV_LIST_SIZE, in hci_le_read_resolv_list_size_sync()
4185 static int hci_le_clear_resolv_list_sync(struct hci_dev *hdev) in hci_le_clear_resolv_list_sync() argument
4187 if (!(hdev->commands[34] & 0x20)) in hci_le_clear_resolv_list_sync()
4190 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CLEAR_RESOLV_LIST, 0, NULL, in hci_le_clear_resolv_list_sync()
4195 static int hci_le_set_rpa_timeout_sync(struct hci_dev *hdev) in hci_le_set_rpa_timeout_sync() argument
4197 __le16 timeout = cpu_to_le16(hdev->rpa_timeout); in hci_le_set_rpa_timeout_sync()
4199 if (!(hdev->commands[35] & 0x04) || in hci_le_set_rpa_timeout_sync()
4200 test_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT, &hdev->quirks)) in hci_le_set_rpa_timeout_sync()
4203 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_RPA_TIMEOUT, in hci_le_set_rpa_timeout_sync()
4209 static int hci_le_read_max_data_len_sync(struct hci_dev *hdev) in hci_le_read_max_data_len_sync() argument
4211 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_max_data_len_sync()
4214 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_MAX_DATA_LEN, 0, NULL, in hci_le_read_max_data_len_sync()
4219 static int hci_le_read_def_data_len_sync(struct hci_dev *hdev) in hci_le_read_def_data_len_sync() argument
4221 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_read_def_data_len_sync()
4224 return __hci_cmd_sync_status(hdev, HCI_OP_LE_READ_DEF_DATA_LEN, 0, NULL, in hci_le_read_def_data_len_sync()
4229 static int hci_le_read_num_support_adv_sets_sync(struct hci_dev *hdev) in hci_le_read_num_support_adv_sets_sync() argument
4231 if (!ext_adv_capable(hdev)) in hci_le_read_num_support_adv_sets_sync()
4234 return __hci_cmd_sync_status(hdev, in hci_le_read_num_support_adv_sets_sync()
4240 static int hci_set_le_support_sync(struct hci_dev *hdev) in hci_set_le_support_sync() argument
4245 if (!lmp_bredr_capable(hdev)) in hci_set_le_support_sync()
4250 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in hci_set_le_support_sync()
4255 if (cp.le == lmp_host_le_capable(hdev)) in hci_set_le_support_sync()
4258 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_LE_HOST_SUPPORTED, in hci_set_le_support_sync()
4263 static int hci_le_set_host_feature_sync(struct hci_dev *hdev) in hci_le_set_host_feature_sync() argument
4267 if (!iso_capable(hdev)) in hci_le_set_host_feature_sync()
4276 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_HOST_FEATURE, in hci_le_set_host_feature_sync()
4311 static int hci_init3_sync(struct hci_dev *hdev) in hci_init3_sync() argument
4315 bt_dev_dbg(hdev, ""); in hci_init3_sync()
4317 err = hci_init_stage_sync(hdev, hci_init3); in hci_init3_sync()
4321 if (lmp_le_capable(hdev)) in hci_init3_sync()
4322 return hci_init_stage_sync(hdev, le_init3); in hci_init3_sync()
4327 static int hci_delete_stored_link_key_sync(struct hci_dev *hdev) in hci_delete_stored_link_key_sync() argument
4344 if (!(hdev->commands[6] & 0x80) || in hci_delete_stored_link_key_sync()
4345 test_bit(HCI_QUIRK_BROKEN_STORED_LINK_KEY, &hdev->quirks)) in hci_delete_stored_link_key_sync()
4352 return __hci_cmd_sync_status(hdev, HCI_OP_DELETE_STORED_LINK_KEY, in hci_delete_stored_link_key_sync()
4356 static int hci_set_event_mask_page_2_sync(struct hci_dev *hdev) in hci_set_event_mask_page_2_sync() argument
4362 if (!(hdev->commands[22] & 0x04)) in hci_set_event_mask_page_2_sync()
4368 if (lmp_cpb_central_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4379 if (lmp_cpb_peripheral_capable(hdev)) { in hci_set_event_mask_page_2_sync()
4388 if (lmp_ping_capable(hdev) || hdev->le_features[0] & HCI_LE_PING) { in hci_set_event_mask_page_2_sync()
4402 return __hci_cmd_sync_status(hdev, HCI_OP_SET_EVENT_MASK_PAGE_2, in hci_set_event_mask_page_2_sync()
4407 static int hci_read_local_codecs_sync(struct hci_dev *hdev) in hci_read_local_codecs_sync() argument
4409 if (hdev->commands[45] & 0x04) in hci_read_local_codecs_sync()
4410 hci_read_supported_codecs_v2(hdev); in hci_read_local_codecs_sync()
4411 else if (hdev->commands[29] & 0x20) in hci_read_local_codecs_sync()
4412 hci_read_supported_codecs(hdev); in hci_read_local_codecs_sync()
4418 static int hci_read_local_pairing_opts_sync(struct hci_dev *hdev) in hci_read_local_pairing_opts_sync() argument
4420 if (!(hdev->commands[41] & 0x08)) in hci_read_local_pairing_opts_sync()
4423 return __hci_cmd_sync_status(hdev, HCI_OP_READ_LOCAL_PAIRING_OPTS, in hci_read_local_pairing_opts_sync()
4428 static int hci_get_mws_transport_config_sync(struct hci_dev *hdev) in hci_get_mws_transport_config_sync() argument
4430 if (!mws_transport_config_capable(hdev)) in hci_get_mws_transport_config_sync()
4433 return __hci_cmd_sync_status(hdev, HCI_OP_GET_MWS_TRANSPORT_CONFIG, in hci_get_mws_transport_config_sync()
4438 static int hci_read_sync_train_params_sync(struct hci_dev *hdev) in hci_read_sync_train_params_sync() argument
4440 if (!lmp_sync_train_capable(hdev)) in hci_read_sync_train_params_sync()
4443 return __hci_cmd_sync_status(hdev, HCI_OP_READ_SYNC_TRAIN_PARAMS, in hci_read_sync_train_params_sync()
4448 static int hci_write_sc_support_1_sync(struct hci_dev *hdev) in hci_write_sc_support_1_sync() argument
4452 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED) || in hci_write_sc_support_1_sync()
4453 !bredr_sc_enabled(hdev)) in hci_write_sc_support_1_sync()
4456 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_SC_SUPPORT, in hci_write_sc_support_1_sync()
4464 static int hci_set_err_data_report_sync(struct hci_dev *hdev) in hci_set_err_data_report_sync() argument
4467 bool enabled = hci_dev_test_flag(hdev, HCI_WIDEBAND_SPEECH_ENABLED); in hci_set_err_data_report_sync()
4469 if (!(hdev->commands[18] & 0x08) || in hci_set_err_data_report_sync()
4470 !(hdev->features[0][6] & LMP_ERR_DATA_REPORTING) || in hci_set_err_data_report_sync()
4471 test_bit(HCI_QUIRK_BROKEN_ERR_DATA_REPORTING, &hdev->quirks)) in hci_set_err_data_report_sync()
4474 if (enabled == hdev->err_data_reporting) in hci_set_err_data_report_sync()
4481 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_DEF_ERR_DATA_REPORTING, in hci_set_err_data_report_sync()
4506 static int hci_le_set_write_def_data_len_sync(struct hci_dev *hdev) in hci_le_set_write_def_data_len_sync() argument
4510 if (!(hdev->le_features[0] & HCI_LE_DATA_LEN_EXT)) in hci_le_set_write_def_data_len_sync()
4514 cp.tx_len = cpu_to_le16(hdev->le_max_tx_len); in hci_le_set_write_def_data_len_sync()
4515 cp.tx_time = cpu_to_le16(hdev->le_max_tx_time); in hci_le_set_write_def_data_len_sync()
4517 return __hci_cmd_sync_status(hdev, HCI_OP_LE_WRITE_DEF_DATA_LEN, in hci_le_set_write_def_data_len_sync()
4524 static int hci_le_set_default_phy_sync(struct hci_dev *hdev) in hci_le_set_default_phy_sync() argument
4528 if (!(hdev->commands[35] & 0x20)) { in hci_le_set_default_phy_sync()
4532 hdev->le_tx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4533 hdev->le_rx_def_phys = HCI_LE_SET_PHY_1M; in hci_le_set_default_phy_sync()
4543 if (le_2m_capable(hdev)) { in hci_le_set_default_phy_sync()
4549 if (le_coded_capable(hdev)) { in hci_le_set_default_phy_sync()
4554 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_DEFAULT_PHY, in hci_le_set_default_phy_sync()
4566 static int hci_init4_sync(struct hci_dev *hdev) in hci_init4_sync() argument
4570 bt_dev_dbg(hdev, ""); in hci_init4_sync()
4572 err = hci_init_stage_sync(hdev, hci_init4); in hci_init4_sync()
4576 if (lmp_le_capable(hdev)) in hci_init4_sync()
4577 return hci_init_stage_sync(hdev, le_init4); in hci_init4_sync()
4582 static int hci_init_sync(struct hci_dev *hdev) in hci_init_sync() argument
4586 err = hci_init1_sync(hdev); in hci_init_sync()
4590 if (hci_dev_test_flag(hdev, HCI_SETUP)) in hci_init_sync()
4591 hci_debugfs_create_basic(hdev); in hci_init_sync()
4593 err = hci_init2_sync(hdev); in hci_init_sync()
4601 if (hdev->dev_type != HCI_PRIMARY) in hci_init_sync()
4604 err = hci_init3_sync(hdev); in hci_init_sync()
4608 err = hci_init4_sync(hdev); in hci_init_sync()
4624 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_init_sync()
4625 !hci_dev_test_flag(hdev, HCI_CONFIG)) in hci_init_sync()
4628 if (hci_dev_test_and_set_flag(hdev, HCI_DEBUGFS_CREATED)) in hci_init_sync()
4631 hci_debugfs_create_common(hdev); in hci_init_sync()
4633 if (lmp_bredr_capable(hdev)) in hci_init_sync()
4634 hci_debugfs_create_bredr(hdev); in hci_init_sync()
4636 if (lmp_le_capable(hdev)) in hci_init_sync()
4637 hci_debugfs_create_le(hdev); in hci_init_sync()
4677 static int hci_dev_setup_sync(struct hci_dev *hdev) in hci_dev_setup_sync() argument
4683 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_setup_sync()
4684 !test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) in hci_dev_setup_sync()
4687 bt_dev_dbg(hdev, ""); in hci_dev_setup_sync()
4689 hci_sock_dev_event(hdev, HCI_DEV_SETUP); in hci_dev_setup_sync()
4691 if (hdev->setup) in hci_dev_setup_sync()
4692 ret = hdev->setup(hdev); in hci_dev_setup_sync()
4695 if (test_bit(hci_broken_table[i].quirk, &hdev->quirks)) in hci_dev_setup_sync()
4696 bt_dev_warn(hdev, "%s", hci_broken_table[i].desc); in hci_dev_setup_sync()
4703 invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) || in hci_dev_setup_sync()
4704 test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); in hci_dev_setup_sync()
4706 if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks) && in hci_dev_setup_sync()
4707 !bacmp(&hdev->public_addr, BDADDR_ANY)) in hci_dev_setup_sync()
4708 hci_dev_get_bd_addr_from_property(hdev); in hci_dev_setup_sync()
4710 if (invalid_bdaddr && bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_setup_sync()
4711 hdev->set_bdaddr) { in hci_dev_setup_sync()
4712 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_setup_sync()
4728 if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || in hci_dev_setup_sync()
4730 hci_dev_set_flag(hdev, HCI_UNCONFIGURED); in hci_dev_setup_sync()
4740 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_dev_setup_sync()
4741 return hci_unconf_init_sync(hdev); in hci_dev_setup_sync()
4751 static int hci_dev_init_sync(struct hci_dev *hdev) in hci_dev_init_sync() argument
4755 bt_dev_dbg(hdev, ""); in hci_dev_init_sync()
4757 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_init_sync()
4758 set_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4760 ret = hci_dev_setup_sync(hdev); in hci_dev_init_sync()
4762 if (hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_init_sync()
4768 if (bacmp(&hdev->public_addr, BDADDR_ANY) && in hci_dev_init_sync()
4769 hdev->set_bdaddr) in hci_dev_init_sync()
4770 ret = hdev->set_bdaddr(hdev, &hdev->public_addr); in hci_dev_init_sync()
4776 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_init_sync()
4777 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4778 ret = hci_init_sync(hdev); in hci_dev_init_sync()
4779 if (!ret && hdev->post_init) in hci_dev_init_sync()
4780 ret = hdev->post_init(hdev); in hci_dev_init_sync()
4788 if (test_bit(HCI_QUIRK_NON_PERSISTENT_DIAG, &hdev->quirks) && in hci_dev_init_sync()
4789 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_init_sync()
4790 hci_dev_test_flag(hdev, HCI_VENDOR_DIAG) && hdev->set_diag) in hci_dev_init_sync()
4791 ret = hdev->set_diag(hdev, true); in hci_dev_init_sync()
4793 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_init_sync()
4794 msft_do_open(hdev); in hci_dev_init_sync()
4795 aosp_do_open(hdev); in hci_dev_init_sync()
4798 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_init_sync()
4803 int hci_dev_open_sync(struct hci_dev *hdev) in hci_dev_open_sync() argument
4807 bt_dev_dbg(hdev, ""); in hci_dev_open_sync()
4809 if (hci_dev_test_flag(hdev, HCI_UNREGISTER)) { in hci_dev_open_sync()
4814 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
4815 !hci_dev_test_flag(hdev, HCI_CONFIG)) { in hci_dev_open_sync()
4819 if (hci_dev_test_flag(hdev, HCI_RFKILLED)) { in hci_dev_open_sync()
4836 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
4837 hdev->dev_type == HCI_PRIMARY && in hci_dev_open_sync()
4838 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_dev_open_sync()
4839 !bacmp(&hdev->static_addr, BDADDR_ANY)) { in hci_dev_open_sync()
4845 if (test_bit(HCI_UP, &hdev->flags)) { in hci_dev_open_sync()
4850 if (hdev->open(hdev)) { in hci_dev_open_sync()
4855 hci_devcd_reset(hdev); in hci_dev_open_sync()
4857 set_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4858 hci_sock_dev_event(hdev, HCI_DEV_OPEN); in hci_dev_open_sync()
4860 ret = hci_dev_init_sync(hdev); in hci_dev_open_sync()
4862 hci_dev_hold(hdev); in hci_dev_open_sync()
4863 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in hci_dev_open_sync()
4864 hci_adv_instances_set_rpa_expired(hdev, true); in hci_dev_open_sync()
4865 set_bit(HCI_UP, &hdev->flags); in hci_dev_open_sync()
4866 hci_sock_dev_event(hdev, HCI_DEV_UP); in hci_dev_open_sync()
4867 hci_leds_update_powered(hdev, true); in hci_dev_open_sync()
4868 if (!hci_dev_test_flag(hdev, HCI_SETUP) && in hci_dev_open_sync()
4869 !hci_dev_test_flag(hdev, HCI_CONFIG) && in hci_dev_open_sync()
4870 !hci_dev_test_flag(hdev, HCI_UNCONFIGURED) && in hci_dev_open_sync()
4871 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_open_sync()
4872 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_dev_open_sync()
4873 hdev->dev_type == HCI_PRIMARY) { in hci_dev_open_sync()
4874 ret = hci_powered_update_sync(hdev); in hci_dev_open_sync()
4875 mgmt_power_on(hdev, ret); in hci_dev_open_sync()
4879 flush_work(&hdev->tx_work); in hci_dev_open_sync()
4885 flush_work(&hdev->rx_work); in hci_dev_open_sync()
4886 flush_work(&hdev->cmd_work); in hci_dev_open_sync()
4888 skb_queue_purge(&hdev->cmd_q); in hci_dev_open_sync()
4889 skb_queue_purge(&hdev->rx_q); in hci_dev_open_sync()
4891 if (hdev->flush) in hci_dev_open_sync()
4892 hdev->flush(hdev); in hci_dev_open_sync()
4894 if (hdev->sent_cmd) { in hci_dev_open_sync()
4895 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_open_sync()
4896 kfree_skb(hdev->sent_cmd); in hci_dev_open_sync()
4897 hdev->sent_cmd = NULL; in hci_dev_open_sync()
4900 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_open_sync()
4901 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_open_sync()
4903 hdev->close(hdev); in hci_dev_open_sync()
4904 hdev->flags &= BIT(HCI_RAW); in hci_dev_open_sync()
4912 static void hci_pend_le_actions_clear(struct hci_dev *hdev) in hci_pend_le_actions_clear() argument
4916 list_for_each_entry(p, &hdev->le_conn_params, list) { in hci_pend_le_actions_clear()
4928 static int hci_dev_shutdown(struct hci_dev *hdev) in hci_dev_shutdown() argument
4938 hci_dev_test_and_clear_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
4940 if (!hci_dev_test_flag(hdev, HCI_UNREGISTER) && in hci_dev_shutdown()
4941 test_bit(HCI_UP, &hdev->flags)) { in hci_dev_shutdown()
4943 if (hdev->shutdown) in hci_dev_shutdown()
4944 err = hdev->shutdown(hdev); in hci_dev_shutdown()
4948 hci_dev_set_flag(hdev, HCI_USER_CHANNEL); in hci_dev_shutdown()
4953 int hci_dev_close_sync(struct hci_dev *hdev) in hci_dev_close_sync() argument
4958 bt_dev_dbg(hdev, ""); in hci_dev_close_sync()
4960 cancel_delayed_work(&hdev->power_off); in hci_dev_close_sync()
4961 cancel_delayed_work(&hdev->ncmd_timer); in hci_dev_close_sync()
4962 cancel_delayed_work(&hdev->le_scan_disable); in hci_dev_close_sync()
4963 cancel_delayed_work(&hdev->le_scan_restart); in hci_dev_close_sync()
4965 hci_request_cancel_all(hdev); in hci_dev_close_sync()
4967 if (hdev->adv_instance_timeout) { in hci_dev_close_sync()
4968 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_dev_close_sync()
4969 hdev->adv_instance_timeout = 0; in hci_dev_close_sync()
4972 err = hci_dev_shutdown(hdev); in hci_dev_close_sync()
4974 if (!test_and_clear_bit(HCI_UP, &hdev->flags)) { in hci_dev_close_sync()
4975 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
4979 hci_leds_update_powered(hdev, false); in hci_dev_close_sync()
4982 flush_work(&hdev->tx_work); in hci_dev_close_sync()
4983 flush_work(&hdev->rx_work); in hci_dev_close_sync()
4985 if (hdev->discov_timeout > 0) { in hci_dev_close_sync()
4986 hdev->discov_timeout = 0; in hci_dev_close_sync()
4987 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in hci_dev_close_sync()
4988 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in hci_dev_close_sync()
4991 if (hci_dev_test_and_clear_flag(hdev, HCI_SERVICE_CACHE)) in hci_dev_close_sync()
4992 cancel_delayed_work(&hdev->service_cache); in hci_dev_close_sync()
4994 if (hci_dev_test_flag(hdev, HCI_MGMT)) { in hci_dev_close_sync()
4997 cancel_delayed_work_sync(&hdev->rpa_expired); in hci_dev_close_sync()
4999 list_for_each_entry(adv_instance, &hdev->adv_instances, list) in hci_dev_close_sync()
5006 drain_workqueue(hdev->workqueue); in hci_dev_close_sync()
5008 hci_dev_lock(hdev); in hci_dev_close_sync()
5010 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_dev_close_sync()
5012 auto_off = hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF); in hci_dev_close_sync()
5014 if (!auto_off && hdev->dev_type == HCI_PRIMARY && in hci_dev_close_sync()
5015 !hci_dev_test_flag(hdev, HCI_USER_CHANNEL) && in hci_dev_close_sync()
5016 hci_dev_test_flag(hdev, HCI_MGMT)) in hci_dev_close_sync()
5017 __mgmt_power_off(hdev); in hci_dev_close_sync()
5019 hci_inquiry_cache_flush(hdev); in hci_dev_close_sync()
5020 hci_pend_le_actions_clear(hdev); in hci_dev_close_sync()
5021 hci_conn_hash_flush(hdev); in hci_dev_close_sync()
5023 smp_unregister(hdev); in hci_dev_close_sync()
5024 hci_dev_unlock(hdev); in hci_dev_close_sync()
5026 hci_sock_dev_event(hdev, HCI_DEV_DOWN); in hci_dev_close_sync()
5028 if (!hci_dev_test_flag(hdev, HCI_USER_CHANNEL)) { in hci_dev_close_sync()
5029 aosp_do_close(hdev); in hci_dev_close_sync()
5030 msft_do_close(hdev); in hci_dev_close_sync()
5033 if (hdev->flush) in hci_dev_close_sync()
5034 hdev->flush(hdev); in hci_dev_close_sync()
5037 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5038 atomic_set(&hdev->cmd_cnt, 1); in hci_dev_close_sync()
5039 if (test_bit(HCI_QUIRK_RESET_ON_CLOSE, &hdev->quirks) && in hci_dev_close_sync()
5040 !auto_off && !hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) { in hci_dev_close_sync()
5041 set_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5042 hci_reset_sync(hdev); in hci_dev_close_sync()
5043 clear_bit(HCI_INIT, &hdev->flags); in hci_dev_close_sync()
5047 flush_work(&hdev->cmd_work); in hci_dev_close_sync()
5050 skb_queue_purge(&hdev->rx_q); in hci_dev_close_sync()
5051 skb_queue_purge(&hdev->cmd_q); in hci_dev_close_sync()
5052 skb_queue_purge(&hdev->raw_q); in hci_dev_close_sync()
5055 if (hdev->sent_cmd) { in hci_dev_close_sync()
5056 cancel_delayed_work_sync(&hdev->cmd_timer); in hci_dev_close_sync()
5057 kfree_skb(hdev->sent_cmd); in hci_dev_close_sync()
5058 hdev->sent_cmd = NULL; in hci_dev_close_sync()
5061 clear_bit(HCI_RUNNING, &hdev->flags); in hci_dev_close_sync()
5062 hci_sock_dev_event(hdev, HCI_DEV_CLOSE); in hci_dev_close_sync()
5065 hdev->close(hdev); in hci_dev_close_sync()
5068 hdev->flags &= BIT(HCI_RAW); in hci_dev_close_sync()
5069 hci_dev_clear_volatile_flags(hdev); in hci_dev_close_sync()
5072 hdev->amp_status = AMP_STATUS_POWERED_DOWN; in hci_dev_close_sync()
5074 memset(hdev->eir, 0, sizeof(hdev->eir)); in hci_dev_close_sync()
5075 memset(hdev->dev_class, 0, sizeof(hdev->dev_class)); in hci_dev_close_sync()
5076 bacpy(&hdev->random_addr, BDADDR_ANY); in hci_dev_close_sync()
5077 hci_codec_list_clear(&hdev->local_codecs); in hci_dev_close_sync()
5079 hci_dev_put(hdev); in hci_dev_close_sync()
5089 static int hci_power_on_sync(struct hci_dev *hdev) in hci_power_on_sync() argument
5093 if (test_bit(HCI_UP, &hdev->flags) && in hci_power_on_sync()
5094 hci_dev_test_flag(hdev, HCI_MGMT) && in hci_power_on_sync()
5095 hci_dev_test_and_clear_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5096 cancel_delayed_work(&hdev->power_off); in hci_power_on_sync()
5097 return hci_powered_update_sync(hdev); in hci_power_on_sync()
5100 err = hci_dev_open_sync(hdev); in hci_power_on_sync()
5108 if (hci_dev_test_flag(hdev, HCI_RFKILLED) || in hci_power_on_sync()
5109 hci_dev_test_flag(hdev, HCI_UNCONFIGURED) || in hci_power_on_sync()
5110 (hdev->dev_type == HCI_PRIMARY && in hci_power_on_sync()
5111 !bacmp(&hdev->bdaddr, BDADDR_ANY) && in hci_power_on_sync()
5112 !bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_power_on_sync()
5113 hci_dev_clear_flag(hdev, HCI_AUTO_OFF); in hci_power_on_sync()
5114 hci_dev_close_sync(hdev); in hci_power_on_sync()
5115 } else if (hci_dev_test_flag(hdev, HCI_AUTO_OFF)) { in hci_power_on_sync()
5116 queue_delayed_work(hdev->req_workqueue, &hdev->power_off, in hci_power_on_sync()
5120 if (hci_dev_test_and_clear_flag(hdev, HCI_SETUP)) { in hci_power_on_sync()
5124 if (hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5125 set_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5134 mgmt_index_added(hdev); in hci_power_on_sync()
5135 } else if (hci_dev_test_and_clear_flag(hdev, HCI_CONFIG)) { in hci_power_on_sync()
5139 if (!hci_dev_test_flag(hdev, HCI_UNCONFIGURED)) in hci_power_on_sync()
5140 clear_bit(HCI_RAW, &hdev->flags); in hci_power_on_sync()
5146 mgmt_index_added(hdev); in hci_power_on_sync()
5152 static int hci_remote_name_cancel_sync(struct hci_dev *hdev, bdaddr_t *addr) in hci_remote_name_cancel_sync() argument
5159 return __hci_cmd_sync_status(hdev, HCI_OP_REMOTE_NAME_REQ_CANCEL, in hci_remote_name_cancel_sync()
5163 int hci_stop_discovery_sync(struct hci_dev *hdev) in hci_stop_discovery_sync() argument
5165 struct discovery_state *d = &hdev->discovery; in hci_stop_discovery_sync()
5169 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_stop_discovery_sync()
5172 if (test_bit(HCI_INQUIRY, &hdev->flags)) { in hci_stop_discovery_sync()
5173 err = __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY_CANCEL, in hci_stop_discovery_sync()
5179 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_stop_discovery_sync()
5180 cancel_delayed_work(&hdev->le_scan_disable); in hci_stop_discovery_sync()
5181 cancel_delayed_work(&hdev->le_scan_restart); in hci_stop_discovery_sync()
5183 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5189 err = hci_scan_disable_sync(hdev); in hci_stop_discovery_sync()
5195 if (use_ll_privacy(hdev)) in hci_stop_discovery_sync()
5196 hci_resume_advertising_sync(hdev); in hci_stop_discovery_sync()
5203 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_stop_discovery_sync()
5208 return hci_remote_name_cancel_sync(hdev, &e->data.bdaddr); in hci_stop_discovery_sync()
5214 static int hci_disconnect_phy_link_sync(struct hci_dev *hdev, u16 handle, in hci_disconnect_phy_link_sync() argument
5223 return __hci_cmd_sync_status(hdev, HCI_OP_DISCONN_PHY_LINK, in hci_disconnect_phy_link_sync()
5227 static int hci_disconnect_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_disconnect_sync() argument
5233 return hci_disconnect_phy_link_sync(hdev, conn->handle, reason); in hci_disconnect_sync()
5245 return __hci_cmd_sync_status_sk(hdev, HCI_OP_DISCONNECT, in hci_disconnect_sync()
5250 return __hci_cmd_sync_status(hdev, HCI_OP_DISCONNECT, sizeof(cp), &cp, in hci_disconnect_sync()
5254 static int hci_le_connect_cancel_sync(struct hci_dev *hdev, in hci_le_connect_cancel_sync() argument
5267 return __hci_cmd_sync_status(hdev, HCI_OP_LE_CREATE_CONN_CANCEL, in hci_le_connect_cancel_sync()
5271 static int hci_connect_cancel_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_connect_cancel_sync() argument
5275 return hci_le_connect_cancel_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5287 return hci_disconnect_sync(hdev, conn, reason); in hci_connect_cancel_sync()
5299 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in hci_connect_cancel_sync()
5308 return __hci_cmd_sync_status_sk(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5313 return __hci_cmd_sync_status(hdev, HCI_OP_CREATE_CONN_CANCEL, in hci_connect_cancel_sync()
5317 static int hci_reject_sco_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_sco_sync() argument
5332 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_SYNC_CONN_REQ, in hci_reject_sco_sync()
5336 static int hci_le_reject_cis_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_le_reject_cis_sync() argument
5345 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REJECT_CIS, in hci_le_reject_cis_sync()
5349 static int hci_reject_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, in hci_reject_conn_sync() argument
5355 return hci_le_reject_cis_sync(hdev, conn, reason); in hci_reject_conn_sync()
5358 return hci_reject_sco_sync(hdev, conn, reason); in hci_reject_conn_sync()
5364 return __hci_cmd_sync_status(hdev, HCI_OP_REJECT_CONN_REQ, in hci_reject_conn_sync()
5368 int hci_abort_conn_sync(struct hci_dev *hdev, struct hci_conn *conn, u8 reason) in hci_abort_conn_sync() argument
5378 err = hci_disconnect_sync(hdev, conn, reason); in hci_abort_conn_sync()
5381 err = hci_connect_cancel_sync(hdev, conn, reason); in hci_abort_conn_sync()
5384 err = hci_reject_conn_sync(hdev, conn, reason); in hci_abort_conn_sync()
5387 hci_dev_lock(hdev); in hci_abort_conn_sync()
5400 hci_dev_unlock(hdev); in hci_abort_conn_sync()
5409 hci_dev_lock(hdev); in hci_abort_conn_sync()
5412 c = hci_conn_hash_lookup_handle(hdev, handle); in hci_abort_conn_sync()
5432 hci_dev_unlock(hdev); in hci_abort_conn_sync()
5436 static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) in hci_disconnect_all_sync() argument
5438 struct list_head *head = &hdev->conn_hash.list; in hci_disconnect_all_sync()
5451 hci_abort_conn_sync(hdev, conn, reason); in hci_disconnect_all_sync()
5467 static int hci_power_off_sync(struct hci_dev *hdev) in hci_power_off_sync() argument
5472 if (!test_bit(HCI_UP, &hdev->flags)) in hci_power_off_sync()
5475 if (test_bit(HCI_ISCAN, &hdev->flags) || in hci_power_off_sync()
5476 test_bit(HCI_PSCAN, &hdev->flags)) { in hci_power_off_sync()
5477 err = hci_write_scan_enable_sync(hdev, 0x00); in hci_power_off_sync()
5482 err = hci_clear_adv_sync(hdev, NULL, false); in hci_power_off_sync()
5486 err = hci_stop_discovery_sync(hdev); in hci_power_off_sync()
5491 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_power_off_sync()
5495 return hci_dev_close_sync(hdev); in hci_power_off_sync()
5498 int hci_set_powered_sync(struct hci_dev *hdev, u8 val) in hci_set_powered_sync() argument
5501 return hci_power_on_sync(hdev); in hci_set_powered_sync()
5503 return hci_power_off_sync(hdev); in hci_set_powered_sync()
5506 static int hci_write_iac_sync(struct hci_dev *hdev) in hci_write_iac_sync() argument
5510 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in hci_write_iac_sync()
5515 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in hci_write_iac_sync()
5517 cp.num_iac = min_t(u8, hdev->num_iac, 2); in hci_write_iac_sync()
5532 return __hci_cmd_sync_status(hdev, HCI_OP_WRITE_CURRENT_IAC_LAP, in hci_write_iac_sync()
5537 int hci_update_discoverable_sync(struct hci_dev *hdev) in hci_update_discoverable_sync() argument
5541 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in hci_update_discoverable_sync()
5542 err = hci_write_iac_sync(hdev); in hci_update_discoverable_sync()
5546 err = hci_update_scan_sync(hdev); in hci_update_discoverable_sync()
5550 err = hci_update_class_sync(hdev); in hci_update_discoverable_sync()
5558 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in hci_update_discoverable_sync()
5559 err = hci_update_adv_data_sync(hdev, 0x00); in hci_update_discoverable_sync()
5566 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in hci_update_discoverable_sync()
5567 if (ext_adv_capable(hdev)) in hci_update_discoverable_sync()
5568 err = hci_start_ext_adv_sync(hdev, 0x00); in hci_update_discoverable_sync()
5570 err = hci_enable_advertising_sync(hdev); in hci_update_discoverable_sync()
5577 static int update_discoverable_sync(struct hci_dev *hdev, void *data) in update_discoverable_sync() argument
5579 return hci_update_discoverable_sync(hdev); in update_discoverable_sync()
5582 int hci_update_discoverable(struct hci_dev *hdev) in hci_update_discoverable() argument
5585 if (hdev_is_powered(hdev) && in hci_update_discoverable()
5586 hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_update_discoverable()
5587 hci_dev_test_flag(hdev, HCI_DISCOVERABLE) && in hci_update_discoverable()
5588 hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in hci_update_discoverable()
5589 return hci_cmd_sync_queue(hdev, update_discoverable_sync, NULL, in hci_update_discoverable()
5595 int hci_update_connectable_sync(struct hci_dev *hdev) in hci_update_connectable_sync() argument
5599 err = hci_update_scan_sync(hdev); in hci_update_connectable_sync()
5607 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_connectable_sync()
5608 err = hci_update_adv_data_sync(hdev, hdev->cur_adv_instance); in hci_update_connectable_sync()
5611 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in hci_update_connectable_sync()
5612 !list_empty(&hdev->adv_instances)) { in hci_update_connectable_sync()
5613 if (ext_adv_capable(hdev)) in hci_update_connectable_sync()
5614 err = hci_start_ext_adv_sync(hdev, in hci_update_connectable_sync()
5615 hdev->cur_adv_instance); in hci_update_connectable_sync()
5617 err = hci_enable_advertising_sync(hdev); in hci_update_connectable_sync()
5623 return hci_update_passive_scan_sync(hdev); in hci_update_connectable_sync()
5626 static int hci_inquiry_sync(struct hci_dev *hdev, u8 length) in hci_inquiry_sync() argument
5632 bt_dev_dbg(hdev, ""); in hci_inquiry_sync()
5634 if (hci_dev_test_flag(hdev, HCI_INQUIRY)) in hci_inquiry_sync()
5637 hci_dev_lock(hdev); in hci_inquiry_sync()
5638 hci_inquiry_cache_flush(hdev); in hci_inquiry_sync()
5639 hci_dev_unlock(hdev); in hci_inquiry_sync()
5643 if (hdev->discovery.limited) in hci_inquiry_sync()
5650 return __hci_cmd_sync_status(hdev, HCI_OP_INQUIRY, in hci_inquiry_sync()
5654 static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) in hci_active_scan_sync() argument
5663 bt_dev_dbg(hdev, ""); in hci_active_scan_sync()
5669 err = hci_scan_disable_sync(hdev); in hci_active_scan_sync()
5671 bt_dev_err(hdev, "Unable to disable scanning: %d", err); in hci_active_scan_sync()
5675 cancel_interleave_scan(hdev); in hci_active_scan_sync()
5680 err = hci_pause_addr_resolution(hdev); in hci_active_scan_sync()
5688 err = hci_update_random_address_sync(hdev, true, scan_use_rpa(hdev), in hci_active_scan_sync()
5693 if (hci_is_adv_monitoring(hdev)) { in hci_active_scan_sync()
5710 err = hci_start_scan_sync(hdev, LE_SCAN_ACTIVE, interval, in hci_active_scan_sync()
5711 hdev->le_scan_window_discovery, in hci_active_scan_sync()
5718 if (use_ll_privacy(hdev)) in hci_active_scan_sync()
5719 hci_resume_advertising_sync(hdev); in hci_active_scan_sync()
5722 hci_update_passive_scan_sync(hdev); in hci_active_scan_sync()
5726 static int hci_start_interleaved_discovery_sync(struct hci_dev *hdev) in hci_start_interleaved_discovery_sync() argument
5730 bt_dev_dbg(hdev, ""); in hci_start_interleaved_discovery_sync()
5732 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery * 2); in hci_start_interleaved_discovery_sync()
5736 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN); in hci_start_interleaved_discovery_sync()
5739 int hci_start_discovery_sync(struct hci_dev *hdev) in hci_start_discovery_sync() argument
5744 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in hci_start_discovery_sync()
5746 switch (hdev->discovery.type) { in hci_start_discovery_sync()
5748 return hci_inquiry_sync(hdev, DISCOV_BREDR_INQUIRY_LEN); in hci_start_discovery_sync()
5759 &hdev->quirks)) { in hci_start_discovery_sync()
5765 err = hci_start_interleaved_discovery_sync(hdev); in hci_start_discovery_sync()
5769 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in hci_start_discovery_sync()
5770 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5774 err = hci_active_scan_sync(hdev, hdev->le_scan_int_discovery); in hci_start_discovery_sync()
5783 bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout)); in hci_start_discovery_sync()
5790 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in hci_start_discovery_sync()
5791 hdev->discovery.result_filtering) { in hci_start_discovery_sync()
5792 hdev->discovery.scan_start = jiffies; in hci_start_discovery_sync()
5793 hdev->discovery.scan_duration = timeout; in hci_start_discovery_sync()
5796 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in hci_start_discovery_sync()
5801 static void hci_suspend_monitor_sync(struct hci_dev *hdev) in hci_suspend_monitor_sync() argument
5803 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_suspend_monitor_sync()
5805 msft_suspend_sync(hdev); in hci_suspend_monitor_sync()
5813 static int hci_pause_discovery_sync(struct hci_dev *hdev) in hci_pause_discovery_sync() argument
5815 int old_state = hdev->discovery.state; in hci_pause_discovery_sync()
5820 hdev->discovery_paused) in hci_pause_discovery_sync()
5823 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_pause_discovery_sync()
5824 err = hci_stop_discovery_sync(hdev); in hci_pause_discovery_sync()
5828 hdev->discovery_paused = true; in hci_pause_discovery_sync()
5829 hdev->discovery_old_state = old_state; in hci_pause_discovery_sync()
5830 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in hci_pause_discovery_sync()
5835 static int hci_update_event_filter_sync(struct hci_dev *hdev) in hci_update_event_filter_sync() argument
5839 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_update_event_filter_sync()
5842 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_update_event_filter_sync()
5848 if (test_bit(HCI_QUIRK_BROKEN_FILTER_CLEAR_ALL, &hdev->quirks)) in hci_update_event_filter_sync()
5852 hci_clear_event_filter_sync(hdev); in hci_update_event_filter_sync()
5854 list_for_each_entry(b, &hdev->accept_list, list) { in hci_update_event_filter_sync()
5858 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_update_event_filter_sync()
5860 err = hci_set_event_filter_sync(hdev, HCI_FLT_CONN_SETUP, in hci_update_event_filter_sync()
5865 bt_dev_dbg(hdev, "Failed to set event filter for %pMR", in hci_update_event_filter_sync()
5872 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
5874 hci_write_scan_enable_sync(hdev, scan); in hci_update_event_filter_sync()
5880 static int hci_pause_scan_sync(struct hci_dev *hdev) in hci_pause_scan_sync() argument
5882 if (hdev->scanning_paused) in hci_pause_scan_sync()
5886 if (test_bit(HCI_PSCAN, &hdev->flags)) in hci_pause_scan_sync()
5887 hci_write_scan_enable_sync(hdev, SCAN_DISABLED); in hci_pause_scan_sync()
5889 hci_scan_disable_sync(hdev); in hci_pause_scan_sync()
5891 hdev->scanning_paused = true; in hci_pause_scan_sync()
5909 int hci_suspend_sync(struct hci_dev *hdev) in hci_suspend_sync() argument
5914 if (hdev->suspended) in hci_suspend_sync()
5918 hdev->suspended = true; in hci_suspend_sync()
5921 hci_pause_discovery_sync(hdev); in hci_suspend_sync()
5924 hci_pause_advertising_sync(hdev); in hci_suspend_sync()
5927 hci_suspend_monitor_sync(hdev); in hci_suspend_sync()
5930 hci_pause_scan_sync(hdev); in hci_suspend_sync()
5932 if (hci_conn_count(hdev)) { in hci_suspend_sync()
5934 err = hci_disconnect_all_sync(hdev, HCI_ERROR_REMOTE_POWER_OFF); in hci_suspend_sync()
5937 hdev->suspend_state = BT_RUNNING; in hci_suspend_sync()
5938 hci_resume_sync(hdev); in hci_suspend_sync()
5945 hci_set_event_mask_sync(hdev); in hci_suspend_sync()
5951 if (!hdev->wakeup || !hdev->wakeup(hdev)) { in hci_suspend_sync()
5952 hdev->suspend_state = BT_SUSPEND_DISCONNECT; in hci_suspend_sync()
5957 hdev->scanning_paused = false; in hci_suspend_sync()
5960 hci_update_event_filter_sync(hdev); in hci_suspend_sync()
5963 hci_update_passive_scan_sync(hdev); in hci_suspend_sync()
5966 hdev->scanning_paused = true; in hci_suspend_sync()
5968 hdev->suspend_state = BT_SUSPEND_CONFIGURE_WAKE; in hci_suspend_sync()
5974 static int hci_resume_discovery_sync(struct hci_dev *hdev) in hci_resume_discovery_sync() argument
5979 if (!hdev->discovery_paused) in hci_resume_discovery_sync()
5982 hdev->discovery_paused = false; in hci_resume_discovery_sync()
5984 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_resume_discovery_sync()
5986 err = hci_start_discovery_sync(hdev); in hci_resume_discovery_sync()
5988 hci_discovery_set_state(hdev, err ? DISCOVERY_STOPPED : in hci_resume_discovery_sync()
5994 static void hci_resume_monitor_sync(struct hci_dev *hdev) in hci_resume_monitor_sync() argument
5996 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_resume_monitor_sync()
5998 msft_resume_sync(hdev); in hci_resume_monitor_sync()
6006 static int hci_resume_scan_sync(struct hci_dev *hdev) in hci_resume_scan_sync() argument
6008 if (!hdev->scanning_paused) in hci_resume_scan_sync()
6011 hdev->scanning_paused = false; in hci_resume_scan_sync()
6013 hci_update_scan_sync(hdev); in hci_resume_scan_sync()
6016 hci_update_passive_scan_sync(hdev); in hci_resume_scan_sync()
6029 int hci_resume_sync(struct hci_dev *hdev) in hci_resume_sync() argument
6032 if (!hdev->suspended) in hci_resume_sync()
6035 hdev->suspended = false; in hci_resume_sync()
6038 hci_set_event_mask_sync(hdev); in hci_resume_sync()
6041 hci_clear_event_filter_sync(hdev); in hci_resume_sync()
6044 hci_resume_scan_sync(hdev); in hci_resume_sync()
6047 hci_resume_monitor_sync(hdev); in hci_resume_sync()
6050 hci_resume_advertising_sync(hdev); in hci_resume_sync()
6053 hci_resume_discovery_sync(hdev); in hci_resume_sync()
6060 struct hci_dev *hdev = conn->hdev; in conn_use_rpa() local
6062 return hci_dev_test_flag(hdev, HCI_PRIVACY); in conn_use_rpa()
6065 static int hci_le_ext_directed_advertising_sync(struct hci_dev *hdev, in hci_le_ext_directed_advertising_sync() argument
6073 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_ext_directed_advertising_sync()
6081 err = hci_get_random_address(hdev, false, conn_use_rpa(conn), NULL, in hci_le_ext_directed_advertising_sync()
6089 cp.channel_map = hdev->le_adv_channel_map; in hci_le_ext_directed_advertising_sync()
6106 err = hci_remove_ext_adv_instance_sync(hdev, cp.handle, NULL); in hci_le_ext_directed_advertising_sync()
6110 err = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_EXT_ADV_PARAMS, in hci_le_ext_directed_advertising_sync()
6118 bacmp(&random_addr, &hdev->random_addr)) { in hci_le_ext_directed_advertising_sync()
6119 err = hci_set_adv_set_random_addr_sync(hdev, 0x00, in hci_le_ext_directed_advertising_sync()
6125 return hci_enable_ext_advertising_sync(hdev, 0x00); in hci_le_ext_directed_advertising_sync()
6128 static int hci_le_directed_advertising_sync(struct hci_dev *hdev, in hci_le_directed_advertising_sync() argument
6136 if (ext_adv_capable(hdev)) in hci_le_directed_advertising_sync()
6137 return hci_le_ext_directed_advertising_sync(hdev, conn); in hci_le_directed_advertising_sync()
6144 hci_dev_clear_flag(hdev, HCI_LE_ADV); in hci_le_directed_advertising_sync()
6149 status = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_directed_advertising_sync()
6167 cp.channel_map = hdev->le_adv_channel_map; in hci_le_directed_advertising_sync()
6169 status = __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_PARAM, in hci_le_directed_advertising_sync()
6176 return __hci_cmd_sync_status(hdev, HCI_OP_LE_SET_ADV_ENABLE, in hci_le_directed_advertising_sync()
6183 struct hci_dev *hdev = conn->hdev; in set_ext_conn_params() local
6187 p->scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in set_ext_conn_params()
6188 p->scan_window = cpu_to_le16(hdev->le_scan_window_connect); in set_ext_conn_params()
6197 static int hci_le_ext_create_conn_sync(struct hci_dev *hdev, in hci_le_ext_create_conn_sync() argument
6216 if (scan_1m(hdev)) { in hci_le_ext_create_conn_sync()
6224 if (scan_2m(hdev)) { in hci_le_ext_create_conn_sync()
6232 if (scan_coded(hdev)) { in hci_le_ext_create_conn_sync()
6239 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_EXT_CREATE_CONN, in hci_le_ext_create_conn_sync()
6245 int hci_le_create_conn_sync(struct hci_dev *hdev, struct hci_conn *conn) in hci_le_create_conn_sync() argument
6257 if (hci_dev_test_flag(hdev, HCI_LE_SCAN) && in hci_le_create_conn_sync()
6258 hdev->le_scan_type == LE_SCAN_ACTIVE && in hci_le_create_conn_sync()
6259 !hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) { in hci_le_create_conn_sync()
6265 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6267 err = hci_le_directed_advertising_sync(hdev, conn); in hci_le_create_conn_sync()
6272 if (!hci_dev_test_flag(hdev, HCI_LE_SIMULTANEOUS_ROLES)) in hci_le_create_conn_sync()
6273 hci_pause_advertising_sync(hdev); in hci_le_create_conn_sync()
6275 params = hci_conn_params_lookup(hdev, &conn->dst, conn->dst_type); in hci_le_create_conn_sync()
6282 conn->le_conn_min_interval = hdev->le_conn_min_interval; in hci_le_create_conn_sync()
6283 conn->le_conn_max_interval = hdev->le_conn_max_interval; in hci_le_create_conn_sync()
6284 conn->le_conn_latency = hdev->le_conn_latency; in hci_le_create_conn_sync()
6285 conn->le_supv_timeout = hdev->le_supv_timeout; in hci_le_create_conn_sync()
6294 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_le_create_conn_sync()
6295 hci_scan_disable_sync(hdev); in hci_le_create_conn_sync()
6296 hci_dev_set_flag(hdev, HCI_LE_SCAN_INTERRUPTED); in hci_le_create_conn_sync()
6302 err = hci_update_random_address_sync(hdev, false, conn_use_rpa(conn), in hci_le_create_conn_sync()
6307 if (use_ext_conn(hdev)) { in hci_le_create_conn_sync()
6308 err = hci_le_ext_create_conn_sync(hdev, conn, own_addr_type); in hci_le_create_conn_sync()
6314 cp.scan_interval = cpu_to_le16(hdev->le_scan_int_connect); in hci_le_create_conn_sync()
6315 cp.scan_window = cpu_to_le16(hdev->le_scan_window_connect); in hci_le_create_conn_sync()
6333 err = __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CONN, in hci_le_create_conn_sync()
6335 use_enhanced_conn_complete(hdev) ? in hci_le_create_conn_sync()
6342 hci_le_connect_cancel_sync(hdev, conn, 0x00); in hci_le_create_conn_sync()
6345 hci_resume_advertising_sync(hdev); in hci_le_create_conn_sync()
6349 int hci_le_create_cis_sync(struct hci_dev *hdev) in hci_le_create_cis_sync() argument
6383 hci_dev_lock(hdev); in hci_le_create_cis_sync()
6388 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6394 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6402 list_for_each_entry_rcu(link, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6418 list_for_each_entry_rcu(conn, &hdev->conn_hash.list, list) { in hci_le_create_cis_sync()
6437 hci_dev_unlock(hdev); in hci_le_create_cis_sync()
6443 return __hci_cmd_sync_status_sk(hdev, HCI_OP_LE_CREATE_CIS, in hci_le_create_cis_sync()
6450 int hci_le_remove_cig_sync(struct hci_dev *hdev, u8 handle) in hci_le_remove_cig_sync() argument
6457 return __hci_cmd_sync_status(hdev, HCI_OP_LE_REMOVE_CIG, sizeof(cp), in hci_le_remove_cig_sync()
6461 int hci_le_big_terminate_sync(struct hci_dev *hdev, u8 handle) in hci_le_big_terminate_sync() argument
6468 return __hci_cmd_sync_status(hdev, HCI_OP_LE_BIG_TERM_SYNC, in hci_le_big_terminate_sync()
6472 int hci_le_pa_terminate_sync(struct hci_dev *hdev, u16 handle) in hci_le_pa_terminate_sync() argument
6479 return __hci_cmd_sync_status(hdev, HCI_OP_LE_PA_TERM_SYNC, in hci_le_pa_terminate_sync()
6483 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
6498 if (use_ll_privacy(hdev)) in hci_get_random_address()
6507 if (rpa_valid(hdev)) in hci_get_random_address()
6511 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
6513 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
6517 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
6540 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
6556 static int _update_adv_data_sync(struct hci_dev *hdev, void *data) in _update_adv_data_sync() argument
6560 return hci_update_adv_data_sync(hdev, instance); in _update_adv_data_sync()
6563 int hci_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_update_adv_data() argument
6565 return hci_cmd_sync_queue(hdev, _update_adv_data_sync, in hci_update_adv_data()