Lines Matching defs: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 hdev->req_skb = skb_get(skb);
110 wake_up_interruptible(&hdev->req_wait_q);
115 int __hci_req_sync(struct hci_dev *hdev, int (*func)(struct hci_request *req,
122 bt_dev_dbg(hdev, "start");
124 hci_req_init(&req, hdev);
126 hdev->req_status = HCI_REQ_PEND;
137 hdev->req_status = 0;
156 err = wait_event_interruptible_timeout(hdev->req_wait_q,
157 hdev->req_status != HCI_REQ_PEND, timeout);
162 switch (hdev->req_status) {
164 err = -bt_to_errno(hdev->req_result);
166 *hci_status = hdev->req_result;
170 err = -hdev->req_result;
182 kfree_skb(hdev->req_skb);
183 hdev->req_skb = NULL;
184 hdev->req_status = hdev->req_result = 0;
186 bt_dev_dbg(hdev, "end: err %d", err);
191 int hci_req_sync(struct hci_dev *hdev, int (*req)(struct hci_request *req,
198 hci_req_sync_lock(hdev);
203 if (test_bit(HCI_UP, &hdev->flags))
204 ret = __hci_req_sync(hdev, req, opt, timeout, hci_status);
207 hci_req_sync_unlock(hdev);
212 struct sk_buff *hci_prepare_cmd(struct hci_dev *hdev, u16 opcode, u32 plen,
230 bt_dev_dbg(hdev, "skb len %d", skb->len);
242 struct hci_dev *hdev = req->hdev;
245 bt_dev_dbg(hdev, "opcode 0x%4.4x plen %d", opcode, plen);
253 skb = hci_prepare_cmd(hdev, opcode, plen, param);
255 bt_dev_err(hdev, "no memory for command (opcode 0x%4.4x)",
272 bt_dev_dbg(req->hdev, "HCI_REQ-0x%4.4x", opcode);
276 static void start_interleave_scan(struct hci_dev *hdev)
278 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER;
279 queue_delayed_work(hdev->req_workqueue,
280 &hdev->interleave_scan, 0);
283 static bool is_interleave_scanning(struct hci_dev *hdev)
285 return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE;
288 static void cancel_interleave_scan(struct hci_dev *hdev)
290 bt_dev_dbg(hdev, "cancelling interleave scan");
292 cancel_delayed_work_sync(&hdev->interleave_scan);
294 hdev->interleave_scan_state = INTERLEAVE_SCAN_NONE;
300 static bool __hci_update_interleaved_scan(struct hci_dev *hdev)
309 bool use_interleaving = hci_is_adv_monitoring(hdev) &&
310 !(list_empty(&hdev->pend_le_conns) &&
311 list_empty(&hdev->pend_le_reports)) &&
312 hci_get_adv_monitor_offload_ext(hdev) ==
314 bool is_interleaving = is_interleave_scanning(hdev);
317 start_interleave_scan(hdev);
318 bt_dev_dbg(hdev, "starting interleave scan");
323 cancel_interleave_scan(hdev);
330 struct hci_dev *hdev = req->hdev;
332 if (hdev->scanning_paused) {
333 bt_dev_dbg(hdev, "Scanning is paused for suspend");
337 if (use_ext_scan(hdev)) {
353 if (hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION) && !rpa_le_conn) {
368 bt_dev_dbg(req->hdev, "Remove %pMR (0x%x) from accept list", &cp.bdaddr,
372 if (use_ll_privacy(req->hdev)) {
375 irk = hci_find_irk_by_addr(req->hdev, bdaddr, bdaddr_type);
394 struct hci_dev *hdev = req->hdev;
397 if (hci_bdaddr_list_lookup(&hdev->le_accept_list, &params->addr,
402 if (*num_entries >= hdev->le_accept_list_size)
407 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
408 hci_find_irk_by_addr(hdev, &params->addr, params->addr_type)) {
413 if (hdev->suspended &&
421 bt_dev_dbg(hdev, "Add %pMR (0x%x) to accept list", &cp.bdaddr,
425 if (use_ll_privacy(hdev)) {
428 irk = hci_find_irk_by_addr(hdev, &params->addr,
437 if (hci_dev_test_flag(hdev, HCI_PRIVACY))
438 memcpy(cp.local_irk, hdev->irk, 16);
452 struct hci_dev *hdev = req->hdev;
462 bool allow_rpa = hdev->suspended;
464 if (use_ll_privacy(hdev))
473 list_for_each_entry(b, &hdev->le_accept_list, list) {
474 pend_conn = hci_pend_le_action_lookup(&hdev->pend_le_conns,
477 pend_report = hci_pend_le_action_lookup(&hdev->pend_le_reports,
491 !hci_dev_test_flag(hdev, HCI_ENABLE_LL_PRIVACY) &&
492 hci_find_irk_by_addr(hdev, &b->bdaddr, b->bdaddr_type)) {
509 list_for_each_entry(params, &hdev->pend_le_conns, action) {
518 list_for_each_entry(params, &hdev->pend_le_reports, action) {
528 if (!idr_is_empty(&hdev->adv_monitors_idr) && !hdev->suspended &&
529 hci_get_adv_monitor_offload_ext(hdev) == HCI_ADV_MONITOR_EXT_NONE &&
530 hdev->interleave_scan_state != INTERLEAVE_SCAN_ALLOWLIST)
537 static bool scan_use_rpa(struct hci_dev *hdev)
539 return hci_dev_test_flag(hdev, HCI_PRIVACY);
546 struct hci_dev *hdev = req->hdev;
548 if (hdev->scanning_paused) {
549 bt_dev_dbg(hdev, "Scanning is paused for suspend");
553 if (use_ll_privacy(hdev) && addr_resolv) {
562 if (use_ext_scan(hdev)) {
578 if (scan_1m(hdev) || scan_2m(hdev)) {
590 if (scan_coded(hdev)) {
637 struct hci_dev *hdev = req->hdev;
648 if (use_ll_privacy(hdev))
653 if (rpa_valid(hdev))
656 err = smp_generate_rpa(hdev, hdev->irk, &hdev->rpa);
658 bt_dev_err(hdev, "failed to generate new RPA");
662 set_random_addr(req, &hdev->rpa);
685 if (bacmp(&hdev->bdaddr, &nrpa))
703 if (hci_dev_test_flag(hdev, HCI_FORCE_STATIC_ADDR) ||
704 !bacmp(&hdev->bdaddr, BDADDR_ANY) ||
705 (!hci_dev_test_flag(hdev, HCI_BREDR_ENABLED) &&
706 bacmp(&hdev->static_addr, BDADDR_ANY))) {
708 if (bacmp(&hdev->static_addr, &hdev->random_addr))
710 &hdev->static_addr);
728 struct hci_dev *hdev = req->hdev;
737 if (hdev->scanning_paused) {
738 bt_dev_dbg(hdev, "Scanning is paused for suspend");
748 if (hci_update_random_address(req, false, scan_use_rpa(hdev),
752 if (hdev->enable_advmon_interleave_scan &&
753 __hci_update_interleaved_scan(hdev))
756 bt_dev_dbg(hdev, "interleave state %d", hdev->interleave_scan_state);
772 if (hci_dev_test_flag(hdev, HCI_PRIVACY) &&
773 (hdev->le_features[0] & HCI_LE_EXT_SCAN_POLICY))
776 if (hdev->suspended) {
777 window = hdev->le_scan_window_suspend;
778 interval = hdev->le_scan_int_suspend;
779 } else if (hci_is_le_conn_scanning(hdev)) {
780 window = hdev->le_scan_window_connect;
781 interval = hdev->le_scan_int_connect;
782 } else if (hci_is_adv_monitoring(hdev)) {
783 window = hdev->le_scan_window_adv_monitor;
784 interval = hdev->le_scan_int_adv_monitor;
800 window = hdev->le_scan_window;
801 interval = hdev->le_scan_interval;
804 bt_dev_dbg(hdev, "LE passive scan with accept list = %d",
814 struct hci_dev *hdev = req->hdev;
817 hci_dev_lock(hdev);
819 if (hci_dev_test_flag(hdev, HCI_LE_SCAN))
823 switch (hdev->interleave_scan_state) {
825 bt_dev_dbg(hdev, "next state: allowlist");
826 hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER;
829 bt_dev_dbg(hdev, "next state: no filter");
830 hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST;
837 hci_dev_unlock(hdev);
844 struct hci_dev *hdev = container_of(work, struct hci_dev,
849 if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) {
850 timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration);
851 } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) {
852 timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration);
854 bt_dev_err(hdev, "unexpected error");
858 hci_req_sync(hdev, hci_req_add_le_interleaved_scan, 0,
862 if (is_interleave_scanning(hdev))
863 queue_delayed_work(hdev->req_workqueue,
864 &hdev->interleave_scan, timeout);
869 struct hci_dev *hdev = req->hdev;
881 if (hci_dev_test_flag(hdev, HCI_LE_ADV) ||
882 hci_lookup_le_connect(hdev)) {
883 bt_dev_dbg(hdev, "Deferring random address update");
884 hci_dev_set_flag(hdev, HCI_RPA_EXPIRED);
891 void hci_request_setup(struct hci_dev *hdev)
893 INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work);
896 void hci_request_cancel_all(struct hci_dev *hdev)
898 hci_cmd_sync_cancel_sync(hdev, ENODEV);
900 cancel_interleave_scan(hdev);