Lines Matching refs:hdev

39 void hci_req_init(struct hci_request *req, struct hci_dev *hdev)  in hci_req_init()  argument
42 req->hdev = hdev; in hci_req_init()
51 bool hci_req_status_pend(struct hci_dev *hdev) in hci_req_status_pend() argument
53 return hdev->req_status == HCI_REQ_PEND; in hci_req_status_pend()
59 struct hci_dev *hdev = req->hdev; in req_run() local
63 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in req_run()
85 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in req_run()
86 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in req_run()
87 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in req_run()
89 queue_work(hdev->workqueue, &hdev->cmd_work); in req_run()
104 static void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, in hci_req_sync_complete() argument
107 bt_dev_dbg(hdev, "result 0x%2.2x", result); in hci_req_sync_complete()
109 if (hdev->req_status == HCI_REQ_PEND) { in hci_req_sync_complete()
110 hdev->req_result = result; in hci_req_sync_complete()
111 hdev->req_status = HCI_REQ_DONE; in hci_req_sync_complete()
113 hdev->req_skb = skb_get(skb); in hci_req_sync_complete()
114 wake_up_interruptible(&hdev->req_wait_q); in hci_req_sync_complete()
118 void hci_req_sync_cancel(struct hci_dev *hdev, int err) in hci_req_sync_cancel() argument
120 bt_dev_dbg(hdev, "err 0x%2.2x", err); in hci_req_sync_cancel()
122 if (hdev->req_status == HCI_REQ_PEND) { in hci_req_sync_cancel()
123 hdev->req_result = err; in hci_req_sync_cancel()
124 hdev->req_status = HCI_REQ_CANCELED; in hci_req_sync_cancel()
125 wake_up_interruptible(&hdev->req_wait_q); in hci_req_sync_cancel()
129 struct sk_buff *__hci_cmd_sync_ev(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync_ev() argument
136 bt_dev_dbg(hdev, ""); in __hci_cmd_sync_ev()
138 hci_req_init(&req, hdev); in __hci_cmd_sync_ev()
142 hdev->req_status = HCI_REQ_PEND; in __hci_cmd_sync_ev()
148 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_cmd_sync_ev()
149 hdev->req_status != HCI_REQ_PEND, timeout); in __hci_cmd_sync_ev()
154 switch (hdev->req_status) { in __hci_cmd_sync_ev()
156 err = -bt_to_errno(hdev->req_result); in __hci_cmd_sync_ev()
160 err = -hdev->req_result; in __hci_cmd_sync_ev()
168 hdev->req_status = hdev->req_result = 0; in __hci_cmd_sync_ev()
169 skb = hdev->req_skb; in __hci_cmd_sync_ev()
170 hdev->req_skb = NULL; in __hci_cmd_sync_ev()
172 bt_dev_dbg(hdev, "end: err %d", err); in __hci_cmd_sync_ev()
186 struct sk_buff *__hci_cmd_sync(struct hci_dev *hdev, u16 opcode, u32 plen, in __hci_cmd_sync() argument
189 return __hci_cmd_sync_ev(hdev, opcode, plen, param, 0, timeout); in __hci_cmd_sync()
194 int __hci_req_sync(struct hci_dev *hdev, int (*func)(struct hci_request *req, in __hci_req_sync() argument
201 bt_dev_dbg(hdev, "start"); in __hci_req_sync()
203 hci_req_init(&req, hdev); in __hci_req_sync()
205 hdev->req_status = HCI_REQ_PEND; in __hci_req_sync()
216 hdev->req_status = 0; in __hci_req_sync()
235 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_req_sync()
236 hdev->req_status != HCI_REQ_PEND, timeout); in __hci_req_sync()
241 switch (hdev->req_status) { in __hci_req_sync()
243 err = -bt_to_errno(hdev->req_result); in __hci_req_sync()
245 *hci_status = hdev->req_result; in __hci_req_sync()
249 err = -hdev->req_result; in __hci_req_sync()
261 kfree_skb(hdev->req_skb); in __hci_req_sync()
262 hdev->req_skb = NULL; in __hci_req_sync()
263 hdev->req_status = hdev->req_result = 0; in __hci_req_sync()
265 bt_dev_dbg(hdev, "end: err %d", err); in __hci_req_sync()
270 int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req, in hci_req_sync() argument
277 hci_req_sync_lock(hdev); in hci_req_sync()
282 if (test_bit(HCI_UP, &hdev->flags)) in hci_req_sync()
283 ret = __hci_req_sync(hdev, req, opt, timeout, hci_status); in hci_req_sync()
286 hci_req_sync_unlock(hdev); in hci_req_sync()
291 struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_prepare_cmd() argument
309 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_prepare_cmd()
321 struct hci_dev *hdev = req->hdev; in hci_req_add_ev() local
324 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_req_add_ev()
332 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_req_add_ev()
334 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_req_add_ev()
356 struct hci_dev *hdev = req->hdev; in __hci_req_write_fast_connectable() local
360 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_write_fast_connectable()
363 if (hdev->hci_ver < BLUETOOTH_VER_1_2) in __hci_req_write_fast_connectable()
372 type = hdev->def_page_scan_type; in __hci_req_write_fast_connectable()
373 acp.interval = cpu_to_le16(hdev->def_page_scan_int); in __hci_req_write_fast_connectable()
376 acp.window = cpu_to_le16(hdev->def_page_scan_window); in __hci_req_write_fast_connectable()
378 if (__cpu_to_le16(hdev->page_scan_interval) != acp.interval || in __hci_req_write_fast_connectable()
379 __cpu_to_le16(hdev->page_scan_window) != acp.window) in __hci_req_write_fast_connectable()
383 if (hdev->page_scan_type != type) in __hci_req_write_fast_connectable()
387 static void start_interleave_scan(struct hci_dev *hdev) in start_interleave_scan() argument
389 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in start_interleave_scan()
390 queue_delayed_work(hdev->req_workqueue, in start_interleave_scan()
391 &hdev->interleave_scan, 0); in start_interleave_scan()
394 static bool is_interleave_scanning(struct hci_dev *hdev) in is_interleave_scanning() argument
396 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
399 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
401 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
403 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
405 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
411 static bool __hci_update_interleaved_scan(struct hci_dev *hdev) in __hci_update_interleaved_scan() argument
420 bool use_interleaving = hci_is_adv_monitoring(hdev) && in __hci_update_interleaved_scan()
421 !(list_empty(&hdev->pend_le_conns) && in __hci_update_interleaved_scan()
422 list_empty(&hdev->pend_le_reports)) && in __hci_update_interleaved_scan()
423 hci_get_adv_monitor_offload_ext(hdev) == in __hci_update_interleaved_scan()
425 bool is_interleaving = is_interleave_scanning(hdev); in __hci_update_interleaved_scan()
428 start_interleave_scan(hdev); in __hci_update_interleaved_scan()
429 bt_dev_dbg(hdev, "starting interleave scan"); in __hci_update_interleaved_scan()
434 cancel_interleave_scan(hdev); in __hci_update_interleaved_scan()
447 struct hci_dev *hdev = req->hdev; in __hci_update_background_scan() local
449 if (!test_bit(HCI_UP, &hdev->flags) || in __hci_update_background_scan()
450 test_bit(HCI_INIT, &hdev->flags) || in __hci_update_background_scan()
451 hci_dev_test_flag(hdev, HCI_SETUP) || in __hci_update_background_scan()
452 hci_dev_test_flag(hdev, HCI_CONFIG) || in __hci_update_background_scan()
453 hci_dev_test_flag(hdev, HCI_AUTO_OFF) || in __hci_update_background_scan()
454 hci_dev_test_flag(hdev, HCI_UNREGISTER)) in __hci_update_background_scan()
458 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_update_background_scan()
462 if (hdev->discovery.state != DISCOVERY_STOPPED) in __hci_update_background_scan()
472 hci_discovery_filter_clear(hdev); in __hci_update_background_scan()
474 bt_dev_dbg(hdev, "ADV monitoring is %s", in __hci_update_background_scan()
475 hci_is_adv_monitoring(hdev) ? "on" : "off"); in __hci_update_background_scan()
477 if (list_empty(&hdev->pend_le_conns) && in __hci_update_background_scan()
478 list_empty(&hdev->pend_le_reports) && in __hci_update_background_scan()
479 !hci_is_adv_monitoring(hdev)) { in __hci_update_background_scan()
486 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in __hci_update_background_scan()
491 bt_dev_dbg(hdev, "stopping background scanning"); in __hci_update_background_scan()
501 if (hci_lookup_le_connect(hdev)) in __hci_update_background_scan()
507 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in __hci_update_background_scan()
511 bt_dev_dbg(hdev, "starting background scanning"); in __hci_update_background_scan()
517 struct hci_dev *hdev = req->hdev; in __hci_req_update_name() local
520 memcpy(cp.name, hdev->dev_name, sizeof(cp.name)); in __hci_req_update_name()
527 struct hci_dev *hdev = req->hdev; in __hci_req_update_eir() local
530 if (!hdev_is_powered(hdev)) in __hci_req_update_eir()
533 if (!lmp_ext_inq_capable(hdev)) in __hci_req_update_eir()
536 if (!hci_dev_test_flag(hdev, HCI_SSP_ENABLED)) in __hci_req_update_eir()
539 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in __hci_req_update_eir()
544 eir_create(hdev, cp.data); in __hci_req_update_eir()
546 if (memcmp(cp.data, hdev->eir, sizeof(cp.data)) == 0) in __hci_req_update_eir()
549 memcpy(hdev->eir, cp.data, sizeof(cp.data)); in __hci_req_update_eir()
556 struct hci_dev *hdev = req->hdev; in hci_req_add_le_scan_disable() local
558 if (hdev->scanning_paused) { in hci_req_add_le_scan_disable()
559 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_scan_disable()
563 if (hdev->suspended) in hci_req_add_le_scan_disable()
564 set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); in hci_req_add_le_scan_disable()
566 if (use_ext_scan(hdev)) { in hci_req_add_le_scan_disable()
582 if (use_ll_privacy(hdev) && in hci_req_add_le_scan_disable()
583 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in hci_req_add_le_scan_disable()
584 hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) { in hci_req_add_le_scan_disable()
599 bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from accept list", &cp.bdaddr, in del_from_accept_list()
603 if (use_ll_privacy(req->hdev) && in del_from_accept_list()
604 hci_dev_test_flag(req->hdev, HCI_ENABLE_LL_PRIVACY)) { in del_from_accept_list()
607 irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type); in del_from_accept_list()
626 struct hci_dev *hdev = req->hdev; in add_to_accept_list() local
629 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in add_to_accept_list()
634 if (*num_entries >= hdev->le_accept_list_size) in add_to_accept_list()
639 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in add_to_accept_list()
640 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) { in add_to_accept_list()
645 if (hdev->suspended && !hci_conn_test_flag(HCI_CONN_FLAG_REMOTE_WAKEUP, in add_to_accept_list()
653 bt_dev_dbg(hdev, "Add %pMR (0x%x) to accept list", &cp.bdaddr, in add_to_accept_list()
657 if (use_ll_privacy(hdev) && in add_to_accept_list()
658 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) { in add_to_accept_list()
661 irk = hci_find_irk_by_addr(hdev, &params->addr, in add_to_accept_list()
670 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in add_to_accept_list()
671 memcpy(cp.local_irk, hdev->irk, 16); in add_to_accept_list()
685 struct hci_dev *hdev = req->hdev; in update_accept_list() local
695 bool allow_rpa = hdev->suspended; in update_accept_list()
697 if (use_ll_privacy(hdev) && in update_accept_list()
698 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in update_accept_list()
707 list_for_each_entry(b, &hdev->le_accept_list, list) { in update_accept_list()
708 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in update_accept_list()
711 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in update_accept_list()
725 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in update_accept_list()
726 hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) { in update_accept_list()
743 list_for_each_entry(params, &hdev->pend_le_conns, action) { in update_accept_list()
752 list_for_each_entry(params, &hdev->pend_le_reports, action) { in update_accept_list()
762 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in update_accept_list()
763 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE && in update_accept_list()
764 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in update_accept_list()
771 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
773 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
780 struct hci_dev *hdev = req->hdev; in hci_req_start_scan() local
782 if (hdev->scanning_paused) { in hci_req_start_scan()
783 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_start_scan()
787 if (use_ll_privacy(hdev) && in hci_req_start_scan()
788 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in hci_req_start_scan()
798 if (use_ext_scan(hdev)) { in hci_req_start_scan()
814 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_req_start_scan()
826 if (scan_coded(hdev)) { in hci_req_start_scan()
869 static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev) in hci_is_le_conn_scanning() argument
871 struct hci_conn_hash *h = &hdev->conn_hash; in hci_is_le_conn_scanning()
895 struct hci_dev *hdev = req->hdev; in hci_req_add_le_passive_scan() local
904 if (hdev->scanning_paused) { in hci_req_add_le_passive_scan()
905 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_passive_scan()
915 if (hci_update_random_address(req, false, scan_use_rpa(hdev), in hci_req_add_le_passive_scan()
919 if (hdev->enable_advmon_interleave_scan && in hci_req_add_le_passive_scan()
920 __hci_update_interleaved_scan(hdev)) in hci_req_add_le_passive_scan()
923 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_req_add_le_passive_scan()
939 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_req_add_le_passive_scan()
940 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_req_add_le_passive_scan()
943 if (hdev->suspended) { in hci_req_add_le_passive_scan()
944 window = hdev->le_scan_window_suspend; in hci_req_add_le_passive_scan()
945 interval = hdev->le_scan_int_suspend; in hci_req_add_le_passive_scan()
947 set_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); in hci_req_add_le_passive_scan()
948 } else if (hci_is_le_conn_scanning(hdev)) { in hci_req_add_le_passive_scan()
949 window = hdev->le_scan_window_connect; in hci_req_add_le_passive_scan()
950 interval = hdev->le_scan_int_connect; in hci_req_add_le_passive_scan()
951 } else if (hci_is_adv_monitoring(hdev)) { in hci_req_add_le_passive_scan()
952 window = hdev->le_scan_window_adv_monitor; in hci_req_add_le_passive_scan()
953 interval = hdev->le_scan_int_adv_monitor; in hci_req_add_le_passive_scan()
969 window = hdev->le_scan_window; in hci_req_add_le_passive_scan()
970 interval = hdev->le_scan_interval; in hci_req_add_le_passive_scan()
973 bt_dev_dbg(hdev, "LE passive scan with accept list = %d", in hci_req_add_le_passive_scan()
984 if (!hci_dev_test_flag(req->hdev, HCI_BREDR_ENABLED)) in hci_req_clear_event_filter()
987 if (hci_dev_test_flag(req->hdev, HCI_EVENT_FILTER_CONFIGURED)) { in hci_req_clear_event_filter()
998 struct hci_dev *hdev = req->hdev; in hci_req_set_event_filter() local
1000 bool scanning = test_bit(HCI_PSCAN, &hdev->flags); in hci_req_set_event_filter()
1002 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in hci_req_set_event_filter()
1008 list_for_each_entry(b, &hdev->accept_list, list) { in hci_req_set_event_filter()
1019 bt_dev_dbg(hdev, "Adding event filters for %pMR", &b->bdaddr); in hci_req_set_event_filter()
1025 set_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); in hci_req_set_event_filter()
1028 set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); in hci_req_set_event_filter()
1033 static void cancel_adv_timeout(struct hci_dev *hdev) in cancel_adv_timeout() argument
1035 if (hdev->adv_instance_timeout) { in cancel_adv_timeout()
1036 hdev->adv_instance_timeout = 0; in cancel_adv_timeout()
1037 cancel_delayed_work(&hdev->adv_instance_expire); in cancel_adv_timeout()
1044 bt_dev_dbg(req->hdev, "Pausing advertising instances"); in __hci_req_pause_adv_instances()
1052 if (!ext_adv_capable(req->hdev)) in __hci_req_pause_adv_instances()
1053 cancel_adv_timeout(req->hdev); in __hci_req_pause_adv_instances()
1061 bt_dev_dbg(req->hdev, "Resuming advertising instances"); in __hci_req_resume_adv_instances()
1063 if (ext_adv_capable(req->hdev)) { in __hci_req_resume_adv_instances()
1065 list_for_each_entry(adv, &req->hdev->adv_instances, list) { in __hci_req_resume_adv_instances()
1075 req->hdev->cur_adv_instance, in __hci_req_resume_adv_instances()
1081 int hci_req_resume_adv_instances(struct hci_dev *hdev) in hci_req_resume_adv_instances() argument
1085 hci_req_init(&req, hdev); in hci_req_resume_adv_instances()
1091 static void suspend_req_complete(struct hci_dev *hdev, u8 status, u16 opcode) in suspend_req_complete() argument
1093 bt_dev_dbg(hdev, "Request complete opcode=0x%x, status=0x%x", opcode, in suspend_req_complete()
1095 if (test_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks) || in suspend_req_complete()
1096 test_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks)) { in suspend_req_complete()
1097 clear_bit(SUSPEND_SCAN_ENABLE, hdev->suspend_tasks); in suspend_req_complete()
1098 clear_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); in suspend_req_complete()
1099 wake_up(&hdev->suspend_wait_q); in suspend_req_complete()
1102 if (test_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks)) { in suspend_req_complete()
1103 clear_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks); in suspend_req_complete()
1104 wake_up(&hdev->suspend_wait_q); in suspend_req_complete()
1111 struct hci_dev *hdev = req->hdev; in hci_req_prepare_adv_monitor_suspend() local
1113 switch (hci_get_adv_monitor_offload_ext(hdev)) { in hci_req_prepare_adv_monitor_suspend()
1116 msft_suspend(hdev); in hci_req_prepare_adv_monitor_suspend()
1118 msft_resume(hdev); in hci_req_prepare_adv_monitor_suspend()
1125 if (hdev->suspended && suspending) in hci_req_prepare_adv_monitor_suspend()
1126 set_bit(SUSPEND_SET_ADV_FILTER, hdev->suspend_tasks); in hci_req_prepare_adv_monitor_suspend()
1130 void hci_req_prepare_suspend(struct hci_dev *hdev, enum suspended_state next) in hci_req_prepare_suspend() argument
1138 if (next == hdev->suspend_state) { in hci_req_prepare_suspend()
1139 bt_dev_dbg(hdev, "Same state before and after: %d", next); in hci_req_prepare_suspend()
1143 hdev->suspend_state = next; in hci_req_prepare_suspend()
1144 hci_req_init(&req, hdev); in hci_req_prepare_suspend()
1148 hdev->suspended = true; in hci_req_prepare_suspend()
1151 old_state = hdev->discovery.state; in hci_req_prepare_suspend()
1153 set_bit(SUSPEND_PAUSE_DISCOVERY, hdev->suspend_tasks); in hci_req_prepare_suspend()
1154 hci_discovery_set_state(hdev, DISCOVERY_STOPPING); in hci_req_prepare_suspend()
1155 queue_work(hdev->req_workqueue, &hdev->discov_update); in hci_req_prepare_suspend()
1158 hdev->discovery_paused = true; in hci_req_prepare_suspend()
1159 hdev->discovery_old_state = old_state; in hci_req_prepare_suspend()
1162 old_state = hci_dev_test_flag(hdev, HCI_ADVERTISING); in hci_req_prepare_suspend()
1164 set_bit(SUSPEND_PAUSE_ADVERTISING, hdev->suspend_tasks); in hci_req_prepare_suspend()
1165 cancel_delayed_work(&hdev->discov_off); in hci_req_prepare_suspend()
1166 queue_delayed_work(hdev->req_workqueue, in hci_req_prepare_suspend()
1167 &hdev->discov_off, 0); in hci_req_prepare_suspend()
1171 if (hdev->adv_instance_cnt) in hci_req_prepare_suspend()
1174 hdev->advertising_paused = true; in hci_req_prepare_suspend()
1175 hdev->advertising_old_state = old_state; in hci_req_prepare_suspend()
1178 if (test_bit(HCI_PSCAN, &hdev->flags)) { in hci_req_prepare_suspend()
1182 set_bit(SUSPEND_SCAN_DISABLE, hdev->suspend_tasks); in hci_req_prepare_suspend()
1186 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_req_prepare_suspend()
1187 cancel_interleave_scan(hdev); in hci_req_prepare_suspend()
1195 hdev->scanning_paused = true; in hci_req_prepare_suspend()
1202 list_for_each_entry(conn, &hdev->conn_hash.list, list) { in hci_req_prepare_suspend()
1208 bt_dev_dbg(hdev, in hci_req_prepare_suspend()
1211 set_bit(SUSPEND_DISCONNECTING, hdev->suspend_tasks); in hci_req_prepare_suspend()
1215 hdev->scanning_paused = false; in hci_req_prepare_suspend()
1221 hdev->scanning_paused = true; in hci_req_prepare_suspend()
1224 hdev->suspended = false; in hci_req_prepare_suspend()
1225 hdev->scanning_paused = false; in hci_req_prepare_suspend()
1237 hdev->advertising_paused = false; in hci_req_prepare_suspend()
1238 if (hdev->advertising_old_state) { in hci_req_prepare_suspend()
1240 hdev->suspend_tasks); in hci_req_prepare_suspend()
1241 hci_dev_set_flag(hdev, HCI_ADVERTISING); in hci_req_prepare_suspend()
1242 queue_work(hdev->req_workqueue, in hci_req_prepare_suspend()
1243 &hdev->discoverable_update); in hci_req_prepare_suspend()
1244 hdev->advertising_old_state = 0; in hci_req_prepare_suspend()
1248 if (hdev->adv_instance_cnt) in hci_req_prepare_suspend()
1252 hdev->discovery_paused = false; in hci_req_prepare_suspend()
1253 if (hdev->discovery_old_state != DISCOVERY_STOPPED && in hci_req_prepare_suspend()
1254 hdev->discovery_old_state != DISCOVERY_STOPPING) { in hci_req_prepare_suspend()
1255 set_bit(SUSPEND_UNPAUSE_DISCOVERY, hdev->suspend_tasks); in hci_req_prepare_suspend()
1256 hci_discovery_set_state(hdev, DISCOVERY_STARTING); in hci_req_prepare_suspend()
1257 queue_work(hdev->req_workqueue, &hdev->discov_update); in hci_req_prepare_suspend()
1263 hdev->suspend_state = next; in hci_req_prepare_suspend()
1266 clear_bit(SUSPEND_PREPARE_NOTIFIER, hdev->suspend_tasks); in hci_req_prepare_suspend()
1267 wake_up(&hdev->suspend_wait_q); in hci_req_prepare_suspend()
1270 static bool adv_cur_instance_is_scannable(struct hci_dev *hdev) in adv_cur_instance_is_scannable() argument
1272 return hci_adv_instance_is_scannable(hdev, hdev->cur_adv_instance); in adv_cur_instance_is_scannable()
1277 if (ext_adv_capable(req->hdev)) { in __hci_req_disable_advertising()
1287 static bool adv_use_rpa(struct hci_dev *hdev, uint32_t flags) in adv_use_rpa() argument
1290 if (!hci_dev_test_flag(hdev, HCI_PRIVACY)) in adv_use_rpa()
1294 if (!hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) in adv_use_rpa()
1301 hci_dev_test_flag(hdev, HCI_BONDABLE)) in adv_use_rpa()
1310 static bool is_advertising_allowed(struct hci_dev *hdev, bool connectable) in is_advertising_allowed() argument
1313 if (hci_conn_num(hdev, LE_LINK) == 0) in is_advertising_allowed()
1317 if (hdev->conn_hash.le_num_peripheral > 0) { in is_advertising_allowed()
1320 if (!connectable && !(hdev->le_states[2] & 0x10)) in is_advertising_allowed()
1326 if (connectable && (!(hdev->le_states[4] & 0x40) || in is_advertising_allowed()
1327 !(hdev->le_states[2] & 0x20))) in is_advertising_allowed()
1332 if (hci_conn_num(hdev, LE_LINK) != hdev->conn_hash.le_num_peripheral) { in is_advertising_allowed()
1334 if (!connectable && !(hdev->le_states[2] & 0x02)) in is_advertising_allowed()
1340 if (connectable && (!(hdev->le_states[4] & 0x08) || in is_advertising_allowed()
1341 !(hdev->le_states[2] & 0x08))) in is_advertising_allowed()
1350 struct hci_dev *hdev = req->hdev; in __hci_req_enable_advertising() local
1358 flags = hci_adv_instance_flags(hdev, hdev->cur_adv_instance); in __hci_req_enable_advertising()
1359 adv = hci_find_adv_instance(hdev, hdev->cur_adv_instance); in __hci_req_enable_advertising()
1365 mgmt_get_connectable(hdev); in __hci_req_enable_advertising()
1367 if (!is_advertising_allowed(hdev, connectable)) in __hci_req_enable_advertising()
1370 if (hci_dev_test_flag(hdev, HCI_LE_ADV)) in __hci_req_enable_advertising()
1378 hci_dev_clear_flag(hdev, HCI_LE_ADV); in __hci_req_enable_advertising()
1385 adv_use_rpa(hdev, flags), in __hci_req_enable_advertising()
1395 adv_min_interval = hdev->le_adv_min_interval; in __hci_req_enable_advertising()
1396 adv_max_interval = hdev->le_adv_max_interval; in __hci_req_enable_advertising()
1402 if (adv_cur_instance_is_scannable(hdev)) in __hci_req_enable_advertising()
1407 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE) || in __hci_req_enable_advertising()
1408 hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in __hci_req_enable_advertising()
1417 cp.channel_map = hdev->le_adv_channel_map; in __hci_req_enable_advertising()
1426 struct hci_dev *hdev = req->hdev; in __hci_req_update_scan_rsp_data() local
1429 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_req_update_scan_rsp_data()
1432 if (ext_adv_capable(hdev)) { in __hci_req_update_scan_rsp_data()
1440 len = eir_create_scan_rsp(hdev, instance, pdu.data); in __hci_req_update_scan_rsp_data()
1442 if (hdev->scan_rsp_data_len == len && in __hci_req_update_scan_rsp_data()
1443 !memcmp(pdu.data, hdev->scan_rsp_data, len)) in __hci_req_update_scan_rsp_data()
1446 memcpy(hdev->scan_rsp_data, pdu.data, len); in __hci_req_update_scan_rsp_data()
1447 hdev->scan_rsp_data_len = len; in __hci_req_update_scan_rsp_data()
1461 len = eir_create_scan_rsp(hdev, instance, cp.data); in __hci_req_update_scan_rsp_data()
1463 if (hdev->scan_rsp_data_len == len && in __hci_req_update_scan_rsp_data()
1464 !memcmp(cp.data, hdev->scan_rsp_data, len)) in __hci_req_update_scan_rsp_data()
1467 memcpy(hdev->scan_rsp_data, cp.data, sizeof(cp.data)); in __hci_req_update_scan_rsp_data()
1468 hdev->scan_rsp_data_len = len; in __hci_req_update_scan_rsp_data()
1478 struct hci_dev *hdev = req->hdev; in __hci_req_update_adv_data() local
1481 if (!hci_dev_test_flag(hdev, HCI_LE_ENABLED)) in __hci_req_update_adv_data()
1484 if (ext_adv_capable(hdev)) { in __hci_req_update_adv_data()
1492 len = eir_create_adv_data(hdev, instance, pdu.data); in __hci_req_update_adv_data()
1495 if (hdev->adv_data_len == len && in __hci_req_update_adv_data()
1496 memcmp(pdu.data, hdev->adv_data, len) == 0) in __hci_req_update_adv_data()
1499 memcpy(hdev->adv_data, pdu.data, len); in __hci_req_update_adv_data()
1500 hdev->adv_data_len = len; in __hci_req_update_adv_data()
1514 len = eir_create_adv_data(hdev, instance, cp.data); in __hci_req_update_adv_data()
1517 if (hdev->adv_data_len == len && in __hci_req_update_adv_data()
1518 memcmp(cp.data, hdev->adv_data, len) == 0) in __hci_req_update_adv_data()
1521 memcpy(hdev->adv_data, cp.data, sizeof(cp.data)); in __hci_req_update_adv_data()
1522 hdev->adv_data_len = len; in __hci_req_update_adv_data()
1530 int hci_req_update_adv_data(struct hci_dev *hdev, u8 instance) in hci_req_update_adv_data() argument
1534 hci_req_init(&req, hdev); in hci_req_update_adv_data()
1540 static void enable_addr_resolution_complete(struct hci_dev *hdev, u8 status, in enable_addr_resolution_complete() argument
1543 BT_DBG("%s status %u", hdev->name, status); in enable_addr_resolution_complete()
1546 void hci_req_disable_address_resolution(struct hci_dev *hdev) in hci_req_disable_address_resolution() argument
1551 if (!use_ll_privacy(hdev) && in hci_req_disable_address_resolution()
1552 !hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) in hci_req_disable_address_resolution()
1555 hci_req_init(&req, hdev); in hci_req_disable_address_resolution()
1562 static void adv_enable_complete(struct hci_dev *hdev, u8 status, u16 opcode) in adv_enable_complete() argument
1564 bt_dev_dbg(hdev, "status %u", status); in adv_enable_complete()
1567 void hci_req_reenable_advertising(struct hci_dev *hdev) in hci_req_reenable_advertising() argument
1571 if (!hci_dev_test_flag(hdev, HCI_ADVERTISING) && in hci_req_reenable_advertising()
1572 list_empty(&hdev->adv_instances)) in hci_req_reenable_advertising()
1575 hci_req_init(&req, hdev); in hci_req_reenable_advertising()
1577 if (hdev->cur_adv_instance) { in hci_req_reenable_advertising()
1578 __hci_req_schedule_adv_instance(&req, hdev->cur_adv_instance, in hci_req_reenable_advertising()
1581 if (ext_adv_capable(hdev)) { in hci_req_reenable_advertising()
1595 struct hci_dev *hdev = container_of(work, struct hci_dev, in adv_timeout_expire() local
1601 bt_dev_dbg(hdev, ""); in adv_timeout_expire()
1603 hci_dev_lock(hdev); in adv_timeout_expire()
1605 hdev->adv_instance_timeout = 0; in adv_timeout_expire()
1607 instance = hdev->cur_adv_instance; in adv_timeout_expire()
1611 hci_req_init(&req, hdev); in adv_timeout_expire()
1613 hci_req_clear_adv_instance(hdev, NULL, &req, instance, false); in adv_timeout_expire()
1615 if (list_empty(&hdev->adv_instances)) in adv_timeout_expire()
1621 hci_dev_unlock(hdev); in adv_timeout_expire()
1627 struct hci_dev *hdev = req->hdev; in hci_req_add_le_interleaved_scan() local
1630 hci_dev_lock(hdev); in hci_req_add_le_interleaved_scan()
1632 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_req_add_le_interleaved_scan()
1636 switch (hdev->interleave_scan_state) { in hci_req_add_le_interleaved_scan()
1638 bt_dev_dbg(hdev, "next state: allowlist"); in hci_req_add_le_interleaved_scan()
1639 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_req_add_le_interleaved_scan()
1642 bt_dev_dbg(hdev, "next state: no filter"); in hci_req_add_le_interleaved_scan()
1643 hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST; in hci_req_add_le_interleaved_scan()
1650 hci_dev_unlock(hdev); in hci_req_add_le_interleaved_scan()
1657 struct hci_dev *hdev = container_of(work, struct hci_dev, in interleave_scan_work() local
1662 if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) { in interleave_scan_work()
1663 timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration); in interleave_scan_work()
1664 } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) { in interleave_scan_work()
1665 timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration); in interleave_scan_work()
1667 bt_dev_err(hdev, "unexpected error"); in interleave_scan_work()
1671 hci_req_sync(hdev, hci_req_add_le_interleaved_scan, 0, in interleave_scan_work()
1675 if (is_interleave_scanning(hdev)) in interleave_scan_work()
1676 queue_delayed_work(hdev->req_workqueue, in interleave_scan_work()
1677 &hdev->interleave_scan, timeout); in interleave_scan_work()
1680 int hci_get_random_address(struct hci_dev *hdev, bool require_privacy, in hci_get_random_address() argument
1695 if (use_ll_privacy(hdev) && in hci_get_random_address()
1696 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in hci_get_random_address()
1705 if (rpa_valid(hdev)) in hci_get_random_address()
1709 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_get_random_address()
1711 bt_dev_err(hdev, "failed to generate new RPA"); in hci_get_random_address()
1715 bacpy(rand_addr, &hdev->rpa); in hci_get_random_address()
1738 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_get_random_address()
1761 struct hci_dev *hdev = req->hdev; in set_random_addr() local
1773 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in set_random_addr()
1774 hci_lookup_le_connect(hdev)) { in set_random_addr()
1775 bt_dev_dbg(hdev, "Deferring random address update"); in set_random_addr()
1776 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_random_addr()
1786 struct hci_dev *hdev = req->hdev; in __hci_req_setup_ext_adv_instance() local
1796 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_setup_ext_adv_instance()
1803 flags = hci_adv_instance_flags(hdev, instance); in __hci_req_setup_ext_adv_instance()
1809 mgmt_get_connectable(hdev); in __hci_req_setup_ext_adv_instance()
1811 if (!is_advertising_allowed(hdev, connectable)) in __hci_req_setup_ext_adv_instance()
1818 err = hci_get_random_address(hdev, !connectable, in __hci_req_setup_ext_adv_instance()
1819 adv_use_rpa(hdev, flags), adv_instance, in __hci_req_setup_ext_adv_instance()
1831 hci_cpu_to_le24(hdev->le_adv_min_interval, cp.min_interval); in __hci_req_setup_ext_adv_instance()
1832 hci_cpu_to_le24(hdev->le_adv_max_interval, cp.max_interval); in __hci_req_setup_ext_adv_instance()
1843 } else if (hci_adv_instance_is_scannable(hdev, instance) || in __hci_req_setup_ext_adv_instance()
1857 cp.channel_map = hdev->le_adv_channel_map; in __hci_req_setup_ext_adv_instance()
1883 if (!bacmp(&random_addr, &hdev->random_addr)) in __hci_req_setup_ext_adv_instance()
1909 struct hci_dev *hdev = req->hdev; in __hci_req_enable_ext_advertising() local
1916 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_enable_ext_advertising()
1954 struct hci_dev *hdev = req->hdev; in __hci_req_disable_ext_adv_instance() local
1961 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in __hci_req_disable_ext_adv_instance()
1983 struct hci_dev *hdev = req->hdev; in __hci_req_remove_ext_adv_instance() local
1986 if (instance > 0 && !hci_find_adv_instance(hdev, instance)) in __hci_req_remove_ext_adv_instance()
1996 struct hci_dev *hdev = req->hdev; in __hci_req_start_ext_adv() local
1997 struct adv_info *adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_start_ext_adv()
2019 struct hci_dev *hdev = req->hdev; in __hci_req_schedule_adv_instance() local
2023 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in __hci_req_schedule_adv_instance()
2024 list_empty(&hdev->adv_instances)) in __hci_req_schedule_adv_instance()
2027 if (hdev->adv_instance_timeout) in __hci_req_schedule_adv_instance()
2030 adv_instance = hci_find_adv_instance(hdev, instance); in __hci_req_schedule_adv_instance()
2056 if (!ext_adv_capable(hdev)) { in __hci_req_schedule_adv_instance()
2057 hdev->adv_instance_timeout = timeout; in __hci_req_schedule_adv_instance()
2058 queue_delayed_work(hdev->req_workqueue, in __hci_req_schedule_adv_instance()
2059 &hdev->adv_instance_expire, in __hci_req_schedule_adv_instance()
2067 if (!force && hdev->cur_adv_instance == instance && in __hci_req_schedule_adv_instance()
2068 hci_dev_test_flag(hdev, HCI_LE_ADV)) in __hci_req_schedule_adv_instance()
2071 hdev->cur_adv_instance = instance; in __hci_req_schedule_adv_instance()
2072 if (ext_adv_capable(hdev)) { in __hci_req_schedule_adv_instance()
2094 void hci_req_clear_adv_instance(struct hci_dev *hdev, struct sock *sk, in hci_req_clear_adv_instance() argument
2103 if (!instance || hdev->cur_adv_instance == instance) in hci_req_clear_adv_instance()
2104 cancel_adv_timeout(hdev); in hci_req_clear_adv_instance()
2110 if (instance && hdev->cur_adv_instance == instance) in hci_req_clear_adv_instance()
2111 next_instance = hci_get_next_instance(hdev, instance); in hci_req_clear_adv_instance()
2114 list_for_each_entry_safe(adv_instance, n, &hdev->adv_instances, in hci_req_clear_adv_instance()
2120 err = hci_remove_adv_instance(hdev, rem_inst); in hci_req_clear_adv_instance()
2122 mgmt_advertising_removed(sk, hdev, rem_inst); in hci_req_clear_adv_instance()
2125 adv_instance = hci_find_adv_instance(hdev, instance); in hci_req_clear_adv_instance()
2134 err = hci_remove_adv_instance(hdev, instance); in hci_req_clear_adv_instance()
2136 mgmt_advertising_removed(sk, hdev, instance); in hci_req_clear_adv_instance()
2140 if (!req || !hdev_is_powered(hdev) || in hci_req_clear_adv_instance()
2141 hci_dev_test_flag(hdev, HCI_ADVERTISING)) in hci_req_clear_adv_instance()
2144 if (next_instance && !ext_adv_capable(hdev)) in hci_req_clear_adv_instance()
2152 struct hci_dev *hdev = req->hdev; in hci_update_random_address() local
2163 if (use_ll_privacy(hdev) && in hci_update_random_address()
2164 hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY)) in hci_update_random_address()
2169 if (rpa_valid(hdev)) in hci_update_random_address()
2172 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address()
2174 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address()
2178 set_random_addr(req, &hdev->rpa); in hci_update_random_address()
2201 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address()
2219 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address()
2220 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address()
2221 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address()
2222 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address()
2224 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address()
2226 &hdev->static_addr); in hci_update_random_address()
2238 static bool disconnected_accept_list_entries(struct hci_dev *hdev) in disconnected_accept_list_entries() argument
2242 list_for_each_entry(b, &hdev->accept_list, list) { in disconnected_accept_list_entries()
2245 conn = hci_conn_hash_lookup_ba(hdev, ACL_LINK, &b->bdaddr); in disconnected_accept_list_entries()
2258 struct hci_dev *hdev = req->hdev; in __hci_req_update_scan() local
2261 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_update_scan()
2264 if (!hdev_is_powered(hdev)) in __hci_req_update_scan()
2267 if (mgmt_powering_down(hdev)) in __hci_req_update_scan()
2270 if (hdev->scanning_paused) in __hci_req_update_scan()
2273 if (hci_dev_test_flag(hdev, HCI_CONNECTABLE) || in __hci_req_update_scan()
2274 disconnected_accept_list_entries(hdev)) in __hci_req_update_scan()
2279 if (hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in __hci_req_update_scan()
2282 if (test_bit(HCI_PSCAN, &hdev->flags) == !!(scan & SCAN_PAGE) && in __hci_req_update_scan()
2283 test_bit(HCI_ISCAN, &hdev->flags) == !!(scan & SCAN_INQUIRY)) in __hci_req_update_scan()
2291 hci_dev_lock(req->hdev); in update_scan()
2293 hci_dev_unlock(req->hdev); in update_scan()
2299 struct hci_dev *hdev = container_of(work, struct hci_dev, scan_update); in scan_update_work() local
2301 hci_req_sync(hdev, update_scan, 0, HCI_CMD_TIMEOUT, NULL); in scan_update_work()
2306 struct hci_dev *hdev = req->hdev; in connectable_update() local
2308 hci_dev_lock(hdev); in connectable_update()
2316 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in connectable_update()
2317 __hci_req_update_adv_data(req, hdev->cur_adv_instance); in connectable_update()
2320 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in connectable_update()
2321 !list_empty(&hdev->adv_instances)) { in connectable_update()
2322 if (ext_adv_capable(hdev)) in connectable_update()
2323 __hci_req_start_ext_adv(req, hdev->cur_adv_instance); in connectable_update()
2330 hci_dev_unlock(hdev); in connectable_update()
2337 struct hci_dev *hdev = container_of(work, struct hci_dev, in connectable_update_work() local
2341 hci_req_sync(hdev, connectable_update, 0, HCI_CMD_TIMEOUT, &status); in connectable_update_work()
2342 mgmt_set_connectable_complete(hdev, status); in connectable_update_work()
2345 static u8 get_service_classes(struct hci_dev *hdev) in get_service_classes() argument
2350 list_for_each_entry(uuid, &hdev->uuids, list) in get_service_classes()
2358 struct hci_dev *hdev = req->hdev; in __hci_req_update_class() local
2361 bt_dev_dbg(hdev, ""); in __hci_req_update_class()
2363 if (!hdev_is_powered(hdev)) in __hci_req_update_class()
2366 if (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) in __hci_req_update_class()
2369 if (hci_dev_test_flag(hdev, HCI_SERVICE_CACHE)) in __hci_req_update_class()
2372 cod[0] = hdev->minor_class; in __hci_req_update_class()
2373 cod[1] = hdev->major_class; in __hci_req_update_class()
2374 cod[2] = get_service_classes(hdev); in __hci_req_update_class()
2376 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) in __hci_req_update_class()
2379 if (memcmp(cod, hdev->dev_class, 3) == 0) in __hci_req_update_class()
2387 struct hci_dev *hdev = req->hdev; in write_iac() local
2390 if (!hci_dev_test_flag(hdev, HCI_DISCOVERABLE)) in write_iac()
2393 if (hci_dev_test_flag(hdev, HCI_LIMITED_DISCOVERABLE)) { in write_iac()
2395 cp.num_iac = min_t(u8, hdev->num_iac, 2); in write_iac()
2416 struct hci_dev *hdev = req->hdev; in discoverable_update() local
2418 hci_dev_lock(hdev); in discoverable_update()
2420 if (hci_dev_test_flag(hdev, HCI_BREDR_ENABLED)) { in discoverable_update()
2429 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in discoverable_update()
2435 if (hci_dev_test_flag(hdev, HCI_LIMITED_PRIVACY)) { in discoverable_update()
2436 if (ext_adv_capable(hdev)) in discoverable_update()
2443 hci_dev_unlock(hdev); in discoverable_update()
2450 struct hci_dev *hdev = container_of(work, struct hci_dev, in discoverable_update_work() local
2454 hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, &status); in discoverable_update_work()
2455 mgmt_set_discoverable_complete(hdev, status); in discoverable_update_work()
2489 if (req->hdev->hci_ver < BLUETOOTH_VER_1_2) in __hci_abort_conn()
2527 static void abort_conn_complete(struct hci_dev *hdev, u8 status, u16 opcode) in abort_conn_complete() argument
2530 bt_dev_dbg(hdev, "Failed to abort connection: status 0x%2.2x", status); in abort_conn_complete()
2538 hci_req_init(&req, conn->hdev); in hci_abort_conn()
2544 bt_dev_err(conn->hdev, "failed to run HCI request: err %d", err); in hci_abort_conn()
2553 hci_dev_lock(req->hdev); in update_bg_scan()
2555 hci_dev_unlock(req->hdev); in update_bg_scan()
2561 struct hci_dev *hdev = container_of(work, struct hci_dev, in bg_scan_update() local
2567 err = hci_req_sync(hdev, update_bg_scan, 0, HCI_CMD_TIMEOUT, &status); in bg_scan_update()
2571 hci_dev_lock(hdev); in bg_scan_update()
2573 conn = hci_conn_hash_lookup_state(hdev, LE_LINK, BT_CONNECT); in bg_scan_update()
2577 hci_dev_unlock(hdev); in bg_scan_update()
2593 if (test_bit(HCI_INQUIRY, &req->hdev->flags)) in bredr_inquiry()
2596 bt_dev_dbg(req->hdev, ""); in bredr_inquiry()
2598 hci_dev_lock(req->hdev); in bredr_inquiry()
2599 hci_inquiry_cache_flush(req->hdev); in bredr_inquiry()
2600 hci_dev_unlock(req->hdev); in bredr_inquiry()
2604 if (req->hdev->discovery.limited) in bredr_inquiry()
2618 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_disable_work() local
2622 bt_dev_dbg(hdev, ""); in le_scan_disable_work()
2624 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_disable_work()
2627 cancel_delayed_work(&hdev->le_scan_restart); in le_scan_disable_work()
2629 hci_req_sync(hdev, le_scan_disable, 0, HCI_CMD_TIMEOUT, &status); in le_scan_disable_work()
2631 bt_dev_err(hdev, "failed to disable LE scan: status 0x%02x", in le_scan_disable_work()
2636 hdev->discovery.scan_start = 0; in le_scan_disable_work()
2646 if (hdev->discovery.type == DISCOV_TYPE_LE) in le_scan_disable_work()
2649 if (hdev->discovery.type != DISCOV_TYPE_INTERLEAVED) in le_scan_disable_work()
2652 if (test_bit(HCI_QUIRK_SIMULTANEOUS_DISCOVERY, &hdev->quirks)) { in le_scan_disable_work()
2653 if (!test_bit(HCI_INQUIRY, &hdev->flags) && in le_scan_disable_work()
2654 hdev->discovery.state != DISCOVERY_RESOLVING) in le_scan_disable_work()
2660 hci_req_sync(hdev, bredr_inquiry, DISCOV_INTERLEAVED_INQUIRY_LEN, in le_scan_disable_work()
2663 bt_dev_err(hdev, "inquiry failed: status 0x%02x", status); in le_scan_disable_work()
2670 hci_dev_lock(hdev); in le_scan_disable_work()
2671 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in le_scan_disable_work()
2672 hci_dev_unlock(hdev); in le_scan_disable_work()
2677 struct hci_dev *hdev = req->hdev; in le_scan_restart() local
2680 if (!hci_dev_test_flag(hdev, HCI_LE_SCAN)) in le_scan_restart()
2683 if (hdev->scanning_paused) { in le_scan_restart()
2684 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in le_scan_restart()
2690 if (use_ext_scan(hdev)) { in le_scan_restart()
2713 struct hci_dev *hdev = container_of(work, struct hci_dev, in le_scan_restart_work() local
2718 bt_dev_dbg(hdev, ""); in le_scan_restart_work()
2720 hci_req_sync(hdev, le_scan_restart, 0, HCI_CMD_TIMEOUT, &status); in le_scan_restart_work()
2722 bt_dev_err(hdev, "failed to restart LE scan: status %d", in le_scan_restart_work()
2727 hci_dev_lock(hdev); in le_scan_restart_work()
2729 if (!test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) || in le_scan_restart_work()
2730 !hdev->discovery.scan_start) in le_scan_restart_work()
2738 duration = hdev->discovery.scan_duration; in le_scan_restart_work()
2739 scan_start = hdev->discovery.scan_start; in le_scan_restart_work()
2754 queue_delayed_work(hdev->req_workqueue, in le_scan_restart_work()
2755 &hdev->le_scan_disable, timeout); in le_scan_restart_work()
2758 hci_dev_unlock(hdev); in le_scan_restart_work()
2764 struct hci_dev *hdev = req->hdev; in active_scan() local
2774 bt_dev_dbg(hdev, ""); in active_scan()
2780 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in active_scan()
2782 cancel_interleave_scan(hdev); in active_scan()
2789 err = hci_update_random_address(req, true, scan_use_rpa(hdev), in active_scan()
2794 if (hci_is_adv_monitoring(hdev)) { in active_scan()
2812 hdev->le_scan_window_discovery, own_addr_type, in active_scan()
2821 bt_dev_dbg(req->hdev, ""); in interleaved_discov()
2830 static void start_discovery(struct hci_dev *hdev, u8 *status) in start_discovery() argument
2834 bt_dev_dbg(hdev, "type %u", hdev->discovery.type); in start_discovery()
2836 switch (hdev->discovery.type) { in start_discovery()
2838 if (!hci_dev_test_flag(hdev, HCI_INQUIRY)) in start_discovery()
2839 hci_req_sync(hdev, bredr_inquiry, in start_discovery()
2853 &hdev->quirks)) { in start_discovery()
2859 hci_req_sync(hdev, interleaved_discov, in start_discovery()
2860 hdev->le_scan_int_discovery * 2, HCI_CMD_TIMEOUT, in start_discovery()
2865 timeout = msecs_to_jiffies(hdev->discov_interleaved_timeout); in start_discovery()
2866 hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, in start_discovery()
2871 hci_req_sync(hdev, active_scan, hdev->le_scan_int_discovery, in start_discovery()
2882 bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout)); in start_discovery()
2889 if (test_bit(HCI_QUIRK_STRICT_DUPLICATE_FILTER, &hdev->quirks) && in start_discovery()
2890 hdev->discovery.result_filtering) { in start_discovery()
2891 hdev->discovery.scan_start = jiffies; in start_discovery()
2892 hdev->discovery.scan_duration = timeout; in start_discovery()
2895 queue_delayed_work(hdev->req_workqueue, &hdev->le_scan_disable, in start_discovery()
2901 struct hci_dev *hdev = req->hdev; in hci_req_stop_discovery() local
2902 struct discovery_state *d = &hdev->discovery; in hci_req_stop_discovery()
2907 bt_dev_dbg(hdev, "state %u", hdev->discovery.state); in hci_req_stop_discovery()
2910 if (test_bit(HCI_INQUIRY, &hdev->flags)) in hci_req_stop_discovery()
2913 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_req_stop_discovery()
2914 cancel_delayed_work(&hdev->le_scan_disable); in hci_req_stop_discovery()
2915 cancel_delayed_work(&hdev->le_scan_restart); in hci_req_stop_discovery()
2922 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) { in hci_req_stop_discovery()
2933 e = hci_inquiry_cache_lookup_resolve(hdev, BDADDR_ANY, in hci_req_stop_discovery()
2947 static void config_data_path_complete(struct hci_dev *hdev, u8 status, in config_data_path_complete() argument
2950 bt_dev_dbg(hdev, "status %u", status); in config_data_path_complete()
2953 int hci_req_configure_datapath(struct hci_dev *hdev, struct bt_codec *codec) in hci_req_configure_datapath() argument
2960 hci_req_init(&req, hdev); in hci_req_configure_datapath()
2962 err = hdev->get_codec_config_data(hdev, ESCO_LINK, codec, &vnd_len, in hci_req_configure_datapath()
2973 err = hdev->get_data_path_id(hdev, &cmd->data_path_id); in hci_req_configure_datapath()
2996 hci_dev_lock(req->hdev); in stop_discovery()
2998 hci_dev_unlock(req->hdev); in stop_discovery()
3005 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_update() local
3009 switch (hdev->discovery.state) { in discov_update()
3011 start_discovery(hdev, &status); in discov_update()
3012 mgmt_start_discovery_complete(hdev, status); in discov_update()
3014 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in discov_update()
3016 hci_discovery_set_state(hdev, DISCOVERY_FINDING); in discov_update()
3019 hci_req_sync(hdev, stop_discovery, 0, HCI_CMD_TIMEOUT, &status); in discov_update()
3020 mgmt_stop_discovery_complete(hdev, status); in discov_update()
3022 hci_discovery_set_state(hdev, DISCOVERY_STOPPED); in discov_update()
3032 struct hci_dev *hdev = container_of(work, struct hci_dev, in discov_off() local
3035 bt_dev_dbg(hdev, ""); in discov_off()
3037 hci_dev_lock(hdev); in discov_off()
3044 hci_dev_clear_flag(hdev, HCI_LIMITED_DISCOVERABLE); in discov_off()
3045 hci_dev_clear_flag(hdev, HCI_DISCOVERABLE); in discov_off()
3046 hdev->discov_timeout = 0; in discov_off()
3048 hci_dev_unlock(hdev); in discov_off()
3050 hci_req_sync(hdev, discoverable_update, 0, HCI_CMD_TIMEOUT, NULL); in discov_off()
3051 mgmt_new_settings(hdev); in discov_off()
3056 struct hci_dev *hdev = req->hdev; in powered_update_hci() local
3059 hci_dev_lock(hdev); in powered_update_hci()
3061 if (hci_dev_test_flag(hdev, HCI_SSP_ENABLED) && in powered_update_hci()
3062 !lmp_host_ssp_capable(hdev)) { in powered_update_hci()
3067 if (bredr_sc_enabled(hdev) && !lmp_host_sc_capable(hdev)) { in powered_update_hci()
3075 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED) && in powered_update_hci()
3076 lmp_bredr_capable(hdev)) { in powered_update_hci()
3085 if (cp.le != lmp_host_le_capable(hdev) || in powered_update_hci()
3086 cp.simul != lmp_host_le_br_capable(hdev)) in powered_update_hci()
3091 if (hci_dev_test_flag(hdev, HCI_LE_ENABLED)) { in powered_update_hci()
3096 if (hci_dev_test_flag(hdev, HCI_ADVERTISING) || in powered_update_hci()
3097 list_empty(&hdev->adv_instances)) { in powered_update_hci()
3100 if (ext_adv_capable(hdev)) { in powered_update_hci()
3112 if (hci_dev_test_flag(hdev, HCI_ADVERTISING)) { in powered_update_hci()
3113 if (!ext_adv_capable(hdev)) in powered_update_hci()
3119 } else if (!list_empty(&hdev->adv_instances)) { in powered_update_hci()
3122 adv_instance = list_first_entry(&hdev->adv_instances, in powered_update_hci()
3130 link_sec = hci_dev_test_flag(hdev, HCI_LINK_SECURITY); in powered_update_hci()
3131 if (link_sec != test_bit(HCI_AUTH, &hdev->flags)) in powered_update_hci()
3135 if (lmp_bredr_capable(hdev)) { in powered_update_hci()
3136 if (hci_dev_test_flag(hdev, HCI_FAST_CONNECTABLE)) in powered_update_hci()
3146 hci_dev_unlock(hdev); in powered_update_hci()
3150 int __hci_req_hci_power_on(struct hci_dev *hdev) in __hci_req_hci_power_on() argument
3157 smp_register(hdev); in __hci_req_hci_power_on()
3159 return __hci_req_sync(hdev, powered_update_hci, 0, HCI_CMD_TIMEOUT, in __hci_req_hci_power_on()
3163 void hci_request_setup(struct hci_dev *hdev) in hci_request_setup() argument
3165 INIT_WORK(&hdev->discov_update, discov_update); in hci_request_setup()
3166 INIT_WORK(&hdev->bg_scan_update, bg_scan_update); in hci_request_setup()
3167 INIT_WORK(&hdev->scan_update, scan_update_work); in hci_request_setup()
3168 INIT_WORK(&hdev->connectable_update, connectable_update_work); in hci_request_setup()
3169 INIT_WORK(&hdev->discoverable_update, discoverable_update_work); in hci_request_setup()
3170 INIT_DELAYED_WORK(&hdev->discov_off, discov_off); in hci_request_setup()
3171 INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable_work); in hci_request_setup()
3172 INIT_DELAYED_WORK(&hdev->le_scan_restart, le_scan_restart_work); in hci_request_setup()
3173 INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire); in hci_request_setup()
3174 INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work); in hci_request_setup()
3177 void hci_request_cancel_all(struct hci_dev *hdev) in hci_request_cancel_all() argument
3179 hci_req_sync_cancel(hdev, ENODEV); in hci_request_cancel_all()
3181 cancel_work_sync(&hdev->discov_update); in hci_request_cancel_all()
3182 cancel_work_sync(&hdev->bg_scan_update); in hci_request_cancel_all()
3183 cancel_work_sync(&hdev->scan_update); in hci_request_cancel_all()
3184 cancel_work_sync(&hdev->connectable_update); in hci_request_cancel_all()
3185 cancel_work_sync(&hdev->discoverable_update); in hci_request_cancel_all()
3186 cancel_delayed_work_sync(&hdev->discov_off); in hci_request_cancel_all()
3187 cancel_delayed_work_sync(&hdev->le_scan_disable); in hci_request_cancel_all()
3188 cancel_delayed_work_sync(&hdev->le_scan_restart); in hci_request_cancel_all()
3190 if (hdev->adv_instance_timeout) { in hci_request_cancel_all()
3191 cancel_delayed_work_sync(&hdev->adv_instance_expire); in hci_request_cancel_all()
3192 hdev->adv_instance_timeout = 0; in hci_request_cancel_all()
3195 cancel_interleave_scan(hdev); in hci_request_cancel_all()