Lines Matching refs:hdev

35 void hci_req_init(struct hci_request *req, struct hci_dev *hdev)
38 req->hdev = hdev;
47 bool hci_req_status_pend(struct hci_dev *hdev)
49 return hdev->req_status == HCI_REQ_PEND;
55 struct hci_dev *hdev = req->hdev;
59 bt_dev_dbg(hdev, "length %u", skb_queue_len(&req->cmd_q));
81 spin_lock_irqsave(&hdev->cmd_q.lock, flags);
82 skb_queue_splice_tail(&req->cmd_q, &hdev->cmd_q);
83 spin_unlock_irqrestore(&hdev->cmd_q.lock, flags);
85 queue_work(hdev->workqueue, &hdev->cmd_work);
100 void hci_req_sync_complete(struct hci_dev *hdev, u8 result, u16 opcode,
103 bt_dev_dbg(hdev, "result 0x%2.2x", result);
105 if (hdev->req_status == HCI_REQ_PEND) {
106 hdev->req_result = result;
107 hdev->req_status = HCI_REQ_DONE;
109 kfree_skb(hdev->req_skb);
110 hdev->req_skb = skb_get(skb);
112 wake_up_interruptible(&hdev->req_wait_q);
117 int __hci_req_sync(struct hci_dev *hdev, int (*func)(struct hci_request *req,
124 bt_dev_dbg(hdev, "start");
126 hci_req_init(&req, hdev);
128 hdev->req_status = HCI_REQ_PEND;
139 hdev->req_status = 0;
158 err = wait_event_interruptible_timeout(hdev->req_wait_q,
159 hdev->req_status != HCI_REQ_PEND, timeout);
164 switch (hdev->req_status) {
166 err = -bt_to_errno(hdev->req_result);
168 *hci_status = hdev->req_result;
172 err = -hdev->req_result;
184 kfree_skb(hdev->req_skb);
185 hdev->req_skb = NULL;
186 hdev->req_status = hdev->req_result = 0;
188 bt_dev_dbg(hdev, "end: err %d", err);
193 int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req,
200 hci_req_sync_lock(hdev);
205 if (test_bit(HCI_UP, &hdev->flags))
206 ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
209 hci_req_sync_unlock(hdev);
214 struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen,
232 bt_dev_dbg(hdev, "skb len %d", skb->len);
244 struct hci_dev *hdev = req->hdev;
247 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen);
255 skb = hci_prepare_cmd(hdev, opcode, plen, param);
257 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)",
274 bt_dev_dbg(req->hdev, "HCI_REQ-0x%4.4x", opcode);
278 static void start_interleave_scan(struct hci_dev *hdev)
280 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER;
281 queue_delayed_work(hdev->req_workqueue,
282 &hdev->interleave_scan, 0);
285 static bool is_interleave_scanning(struct hci_dev *hdev)
287 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE;
290 static void cancel_interleave_scan(struct hci_dev *hdev)
292 bt_dev_dbg(hdev, "cancelling interleave scan");
294 cancel_delayed_work_sync(&hdev->interleave_scan);
296 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE;
302 static bool __hci_update_interleaved_scan(struct hci_dev *hdev)
311 bool use_interleaving = hci_is_adv_monitoring(hdev) &&
312 !(list_empty(&hdev->pend_le_conns) &&
313 list_empty(&hdev->pend_le_reports)) &&
314 hci_get_adv_monitor_offload_ext(hdev) ==
316 bool is_interleaving = is_interleave_scanning(hdev);
319 start_interleave_scan(hdev);
320 bt_dev_dbg(hdev, "starting interleave scan");
325 cancel_interleave_scan(hdev);
332 struct hci_dev *hdev = req->hdev;
334 if (hdev->scanning_paused) {
335 bt_dev_dbg(hdev, "Scanning is paused for suspend");
339 if (use_ext_scan(hdev)) {
355 if (hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
370 bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from accept list", &cp.bdaddr,
374 if (use_ll_privacy(req->hdev)) {
377 irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type);
396 struct hci_dev *hdev = req->hdev;
399 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr,
404 if (*num_entries >= hdev->le_accept_list_size)
409 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
410 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
415 if (hdev->suspended &&
423 bt_dev_dbg(hdev, "Add %pMR (0x%x) to accept list", &cp.bdaddr,
427 if (use_ll_privacy(hdev)) {
430 irk = hci_find_irk_by_addr(hdev, &params->addr,
439 if (hci_dev_test_flag(hdev, HCI_PRIVACY))
440 memcpy(cp.local_irk, hdev->irk, 16);
454 struct hci_dev *hdev = req->hdev;
464 bool allow_rpa = hdev->suspended;
466 if (use_ll_privacy(hdev))
475 list_for_each_entry(b, &hdev->le_accept_list, list) {
476 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns,
479 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports,
493 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
494 hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) {
511 list_for_each_entry(params, &hdev->pend_le_conns, action) {
520 list_for_each_entry(params, &hdev->pend_le_reports, action) {
530 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended &&
531 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE &&
532 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST)
539 static bool scan_use_rpa(struct hci_dev *hdev)
541 return hci_dev_test_flag(hdev, HCI_PRIVACY);
548 struct hci_dev *hdev = req->hdev;
550 if (hdev->scanning_paused) {
551 bt_dev_dbg(hdev, "Scanning is paused for suspend");
555 if (use_ll_privacy(hdev) && addr_resolv) {
564 if (use_ext_scan(hdev)) {
580 if (scan_1m(hdev) || scan_2m(hdev)) {
592 if (scan_coded(hdev)) {
639 struct hci_dev *hdev = req->hdev;
650 if (use_ll_privacy(hdev))
655 if (rpa_valid(hdev))
658 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa);
660 bt_dev_err(hdev, "failed to generate new RPA");
664 set_random_addr(req, &hdev->rpa);
687 if (bacmp(&hdev->bdaddr, &nrpa))
705 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ||
706 !bacmp(&hdev->bdaddr, BDADDR_ANY) ||
707 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) &&
708 bacmp(&hdev->static_addr, BDADDR_ANY))) {
710 if (bacmp(&hdev->static_addr, &hdev->random_addr))
712 &hdev->static_addr);
730 struct hci_dev *hdev = req->hdev;
739 if (hdev->scanning_paused) {
740 bt_dev_dbg(hdev, "Scanning is paused for suspend");
750 if (hci_update_random_address(req, false, scan_use_rpa(hdev),
754 if (hdev->enable_advmon_interleave_scan &&
755 __hci_update_interleaved_scan(hdev))
758 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state);
774 if (hci_dev_test_flag(hdev, HCI_PRIVACY) &&
775 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY))
778 if (hdev->suspended) {
779 window = hdev->le_scan_window_suspend;
780 interval = hdev->le_scan_int_suspend;
781 } else if (hci_is_le_conn_scanning(hdev)) {
782 window = hdev->le_scan_window_connect;
783 interval = hdev->le_scan_int_connect;
784 } else if (hci_is_adv_monitoring(hdev)) {
785 window = hdev->le_scan_window_adv_monitor;
786 interval = hdev->le_scan_int_adv_monitor;
802 window = hdev->le_scan_window;
803 interval = hdev->le_scan_interval;
806 bt_dev_dbg(hdev, "LE passive scan with accept list = %d",
816 struct hci_dev *hdev = req->hdev;
819 hci_dev_lock(hdev);
821 if (hci_dev_test_flag(hdev, HCI_LE_SCAN))
825 switch (hdev->interleave_scan_state) {
827 bt_dev_dbg(hdev, "next state: allowlist");
828 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER;
831 bt_dev_dbg(hdev, "next state: no filter");
832 hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST;
839 hci_dev_unlock(hdev);
846 struct hci_dev *hdev = container_of(work, struct hci_dev,
851 if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) {
852 timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration);
853 } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) {
854 timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration);
856 bt_dev_err(hdev, "unexpected error");
860 hci_req_sync(hdev, hci_req_add_le_interleaved_scan, 0,
864 if (is_interleave_scanning(hdev))
865 queue_delayed_work(hdev->req_workqueue,
866 &hdev->interleave_scan, timeout);
871 struct hci_dev *hdev = req->hdev;
883 if (hci_dev_test_flag(hdev, HCI_LE_ADV) ||
884 hci_lookup_le_connect(hdev)) {
885 bt_dev_dbg(hdev, "Deferring random address update");
886 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
893 void hci_request_setup(struct hci_dev *hdev)
895 INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work);
898 void hci_request_cancel_all(struct hci_dev *hdev)
900 hci_cmd_sync_cancel_sync(hdev, ENODEV);
902 cancel_interleave_scan(hdev);