Lines Matching refs:hdev

35 void hci_req_init(struct hci_request *req, struct hci_dev *hdev)  in hci_req_init()  argument
38 req->hdev = hdev; in hci_req_init()
47 bool hci_req_status_pend(struct hci_dev *hdev) in hci_req_status_pend() argument
49 return hdev->req_status == HCI_REQ_PEND; in hci_req_status_pend()
55 struct hci_dev *hdev = req->hdev; in req_run() local
59 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q)); in req_run()
81 spin_lock_irqsave(&hdev->cmd_q.lock, flags); in req_run()
82 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q); in req_run()
83 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags); in req_run()
85 queue_work(hdev->workqueue, &hdev->cmd_work); in req_run()
100 void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode, in hci_req_sync_complete() argument
103 bt_dev_dbg(hdev, "result 0x%2.2x", result); in hci_req_sync_complete()
105 if (hdev->req_status == HCI_REQ_PEND) { in hci_req_sync_complete()
106 hdev->req_result = result; in hci_req_sync_complete()
107 hdev->req_status = HCI_REQ_DONE; in hci_req_sync_complete()
109 hdev->req_skb = skb_get(skb); in hci_req_sync_complete()
110 wake_up_interruptible(&hdev->req_wait_q); in hci_req_sync_complete()
115 int __hci_req_sync(struct hci_dev *hdev, int (*func)(struct hci_request *req, in __hci_req_sync() argument
122 bt_dev_dbg(hdev, "start"); in __hci_req_sync()
124 hci_req_init(&req, hdev); in __hci_req_sync()
126 hdev->req_status = HCI_REQ_PEND; in __hci_req_sync()
137 hdev->req_status = 0; in __hci_req_sync()
156 err = wait_event_interruptible_timeout(hdev->req_wait_q, in __hci_req_sync()
157 hdev->req_status != HCI_REQ_PEND, timeout); in __hci_req_sync()
162 switch (hdev->req_status) { in __hci_req_sync()
164 err = -bt_to_errno(hdev->req_result); in __hci_req_sync()
166 *hci_status = hdev->req_result; in __hci_req_sync()
170 err = -hdev->req_result; in __hci_req_sync()
182 kfree_skb(hdev->req_skb); in __hci_req_sync()
183 hdev->req_skb = NULL; in __hci_req_sync()
184 hdev->req_status = hdev->req_result = 0; in __hci_req_sync()
186 bt_dev_dbg(hdev, "end: err %d", err); in __hci_req_sync()
191 int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req, in hci_req_sync() argument
198 hci_req_sync_lock(hdev); in hci_req_sync()
203 if (test_bit(HCI_UP, &hdev->flags)) in hci_req_sync()
204 ret = __hci_req_sync(hdev, req, opt, timeout, hci_status); in hci_req_sync()
207 hci_req_sync_unlock(hdev); in hci_req_sync()
212 struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen, in hci_prepare_cmd() argument
230 bt_dev_dbg(hdev, "skb len %d", skb->len); in hci_prepare_cmd()
242 struct hci_dev *hdev = req->hdev; in hci_req_add_ev() local
245 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen); in hci_req_add_ev()
253 skb = hci_prepare_cmd(hdev, opcode, plen, param); in hci_req_add_ev()
255 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)", in hci_req_add_ev()
272 bt_dev_dbg(req->hdev, "HCI_REQ-0x%4.4x", opcode); in hci_req_add()
276 static void start_interleave_scan(struct hci_dev *hdev) in start_interleave_scan() argument
278 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in start_interleave_scan()
279 queue_delayed_work(hdev->req_workqueue, in start_interleave_scan()
280 &hdev->interleave_scan, 0); in start_interleave_scan()
283 static bool is_interleave_scanning(struct hci_dev *hdev) in is_interleave_scanning() argument
285 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE; in is_interleave_scanning()
288 static void cancel_interleave_scan(struct hci_dev *hdev) in cancel_interleave_scan() argument
290 bt_dev_dbg(hdev, "cancelling interleave scan"); in cancel_interleave_scan()
292 cancel_delayed_work_sync(&hdev->interleave_scan); in cancel_interleave_scan()
294 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE; in cancel_interleave_scan()
300 static bool __hci_update_interleaved_scan(struct hci_dev *hdev) in __hci_update_interleaved_scan() argument
309 bool use_interleaving = hci_is_adv_monitoring(hdev) && in __hci_update_interleaved_scan()
310 !(list_empty(&hdev->pend_le_conns) && in __hci_update_interleaved_scan()
311 list_empty(&hdev->pend_le_reports)) && in __hci_update_interleaved_scan()
312 hci_get_adv_monitor_offload_ext(hdev) == in __hci_update_interleaved_scan()
314 bool is_interleaving = is_interleave_scanning(hdev); in __hci_update_interleaved_scan()
317 start_interleave_scan(hdev); in __hci_update_interleaved_scan()
318 bt_dev_dbg(hdev, "starting interleave scan"); in __hci_update_interleaved_scan()
323 cancel_interleave_scan(hdev); in __hci_update_interleaved_scan()
330 struct hci_dev *hdev = req->hdev; in hci_req_add_le_scan_disable() local
332 if (hdev->scanning_paused) { in hci_req_add_le_scan_disable()
333 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_scan_disable()
337 if (use_ext_scan(hdev)) { in hci_req_add_le_scan_disable()
353 if (hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) { in hci_req_add_le_scan_disable()
368 bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from accept list", &cp.bdaddr, in del_from_accept_list()
372 if (use_ll_privacy(req->hdev)) { in del_from_accept_list()
375 irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type); in del_from_accept_list()
394 struct hci_dev *hdev = req->hdev; in add_to_accept_list() local
397 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr, in add_to_accept_list()
402 if (*num_entries >= hdev->le_accept_list_size) in add_to_accept_list()
407 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in add_to_accept_list()
408 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) { in add_to_accept_list()
413 if (hdev->suspended && in add_to_accept_list()
421 bt_dev_dbg(hdev, "Add %pMR (0x%x) to accept list", &cp.bdaddr, in add_to_accept_list()
425 if (use_ll_privacy(hdev)) { in add_to_accept_list()
428 irk = hci_find_irk_by_addr(hdev, &params->addr, in add_to_accept_list()
437 if (hci_dev_test_flag(hdev, HCI_PRIVACY)) in add_to_accept_list()
438 memcpy(cp.local_irk, hdev->irk, 16); in add_to_accept_list()
452 struct hci_dev *hdev = req->hdev; in update_accept_list() local
462 bool allow_rpa = hdev->suspended; in update_accept_list()
464 if (use_ll_privacy(hdev)) in update_accept_list()
473 list_for_each_entry(b, &hdev->le_accept_list, list) { in update_accept_list()
474 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns, in update_accept_list()
477 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports, in update_accept_list()
491 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) && in update_accept_list()
492 hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) { in update_accept_list()
509 list_for_each_entry(params, &hdev->pend_le_conns, action) { in update_accept_list()
518 list_for_each_entry(params, &hdev->pend_le_reports, action) { in update_accept_list()
528 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended && in update_accept_list()
529 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE && in update_accept_list()
530 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST) in update_accept_list()
537 static bool scan_use_rpa(struct hci_dev *hdev) in scan_use_rpa() argument
539 return hci_dev_test_flag(hdev, HCI_PRIVACY); in scan_use_rpa()
546 struct hci_dev *hdev = req->hdev; in hci_req_start_scan() local
548 if (hdev->scanning_paused) { in hci_req_start_scan()
549 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_start_scan()
553 if (use_ll_privacy(hdev) && addr_resolv) { in hci_req_start_scan()
562 if (use_ext_scan(hdev)) { in hci_req_start_scan()
578 if (scan_1m(hdev) || scan_2m(hdev)) { in hci_req_start_scan()
590 if (scan_coded(hdev)) { in hci_req_start_scan()
633 static inline bool hci_is_le_conn_scanning(struct hci_dev *hdev) in hci_is_le_conn_scanning() argument
635 struct hci_conn_hash *h = &hdev->conn_hash; in hci_is_le_conn_scanning()
658 struct hci_dev *hdev = req->hdev; in hci_update_random_address() local
669 if (use_ll_privacy(hdev)) in hci_update_random_address()
674 if (rpa_valid(hdev)) in hci_update_random_address()
677 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa); in hci_update_random_address()
679 bt_dev_err(hdev, "failed to generate new RPA"); in hci_update_random_address()
683 set_random_addr(req, &hdev->rpa); in hci_update_random_address()
706 if (bacmp(&hdev->bdaddr, &nrpa)) in hci_update_random_address()
724 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) || in hci_update_random_address()
725 !bacmp(&hdev->bdaddr, BDADDR_ANY) || in hci_update_random_address()
726 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) && in hci_update_random_address()
727 bacmp(&hdev->static_addr, BDADDR_ANY))) { in hci_update_random_address()
729 if (bacmp(&hdev->static_addr, &hdev->random_addr)) in hci_update_random_address()
731 &hdev->static_addr); in hci_update_random_address()
749 struct hci_dev *hdev = req->hdev; in hci_req_add_le_passive_scan() local
758 if (hdev->scanning_paused) { in hci_req_add_le_passive_scan()
759 bt_dev_dbg(hdev, "Scanning is paused for suspend"); in hci_req_add_le_passive_scan()
769 if (hci_update_random_address(req, false, scan_use_rpa(hdev), in hci_req_add_le_passive_scan()
773 if (hdev->enable_advmon_interleave_scan && in hci_req_add_le_passive_scan()
774 __hci_update_interleaved_scan(hdev)) in hci_req_add_le_passive_scan()
777 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state); in hci_req_add_le_passive_scan()
793 if (hci_dev_test_flag(hdev, HCI_PRIVACY) && in hci_req_add_le_passive_scan()
794 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY)) in hci_req_add_le_passive_scan()
797 if (hdev->suspended) { in hci_req_add_le_passive_scan()
798 window = hdev->le_scan_window_suspend; in hci_req_add_le_passive_scan()
799 interval = hdev->le_scan_int_suspend; in hci_req_add_le_passive_scan()
800 } else if (hci_is_le_conn_scanning(hdev)) { in hci_req_add_le_passive_scan()
801 window = hdev->le_scan_window_connect; in hci_req_add_le_passive_scan()
802 interval = hdev->le_scan_int_connect; in hci_req_add_le_passive_scan()
803 } else if (hci_is_adv_monitoring(hdev)) { in hci_req_add_le_passive_scan()
804 window = hdev->le_scan_window_adv_monitor; in hci_req_add_le_passive_scan()
805 interval = hdev->le_scan_int_adv_monitor; in hci_req_add_le_passive_scan()
821 window = hdev->le_scan_window; in hci_req_add_le_passive_scan()
822 interval = hdev->le_scan_interval; in hci_req_add_le_passive_scan()
825 bt_dev_dbg(hdev, "LE passive scan with accept list = %d", in hci_req_add_le_passive_scan()
835 struct hci_dev *hdev = req->hdev; in hci_req_add_le_interleaved_scan() local
838 hci_dev_lock(hdev); in hci_req_add_le_interleaved_scan()
840 if (hci_dev_test_flag(hdev, HCI_LE_SCAN)) in hci_req_add_le_interleaved_scan()
844 switch (hdev->interleave_scan_state) { in hci_req_add_le_interleaved_scan()
846 bt_dev_dbg(hdev, "next state: allowlist"); in hci_req_add_le_interleaved_scan()
847 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER; in hci_req_add_le_interleaved_scan()
850 bt_dev_dbg(hdev, "next state: no filter"); in hci_req_add_le_interleaved_scan()
851 hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST; in hci_req_add_le_interleaved_scan()
858 hci_dev_unlock(hdev); in hci_req_add_le_interleaved_scan()
865 struct hci_dev *hdev = container_of(work, struct hci_dev, in interleave_scan_work() local
870 if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) { in interleave_scan_work()
871 timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration); in interleave_scan_work()
872 } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) { in interleave_scan_work()
873 timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration); in interleave_scan_work()
875 bt_dev_err(hdev, "unexpected error"); in interleave_scan_work()
879 hci_req_sync(hdev, hci_req_add_le_interleaved_scan, 0, in interleave_scan_work()
883 if (is_interleave_scanning(hdev)) in interleave_scan_work()
884 queue_delayed_work(hdev->req_workqueue, in interleave_scan_work()
885 &hdev->interleave_scan, timeout); in interleave_scan_work()
890 struct hci_dev *hdev = req->hdev; in set_random_addr() local
902 if (hci_dev_test_flag(hdev, HCI_LE_ADV) || in set_random_addr()
903 hci_lookup_le_connect(hdev)) { in set_random_addr()
904 bt_dev_dbg(hdev, "Deferring random address update"); in set_random_addr()
905 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED); in set_random_addr()
912 void hci_request_setup(struct hci_dev *hdev) in hci_request_setup() argument
914 INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work); in hci_request_setup()
917 void hci_request_cancel_all(struct hci_dev *hdev) in hci_request_cancel_all() argument
919 __hci_cmd_sync_cancel(hdev, ENODEV); in hci_request_cancel_all()
921 cancel_interleave_scan(hdev); in hci_request_cancel_all()