Bluetooth: hci_sync: Move handling of interleave_scan
authorLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 1 Jul 2024 20:50:30 +0000 (16:50 -0400)
committerLuiz Augusto von Dentz <luiz.von.dentz@intel.com>
Mon, 15 Jul 2024 14:11:31 +0000 (10:11 -0400)
This moves handling of interleave_scan work to hci_sync.c since
hci_request.c is deprecated.

Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>
net/bluetooth/hci_core.c
net/bluetooth/hci_sync.c

index 9bdd3e1f8cfc64fb24b4f2f17be3a46d2c0e3730..fc0424ae551e0189c7d0fa0fd1ad374dad543918 100644 (file)
@@ -2552,7 +2552,6 @@ struct hci_dev *hci_alloc_dev_priv(int sizeof_priv)
        INIT_DELAYED_WORK(&hdev->ncmd_timer, hci_ncmd_timeout);
 
        hci_devcd_setup(hdev);
-       hci_request_setup(hdev);
 
        hci_init_sysfs(hdev);
        discovery_init(hdev);
@@ -4074,7 +4073,7 @@ static void hci_send_cmd_sync(struct hci_dev *hdev, struct sk_buff *skb)
                return;
        }
 
-       if (hci_req_status_pend(hdev) &&
+       if (hdev->req_status == HCI_REQ_PEND &&
            !hci_dev_test_and_set_flag(hdev, HCI_CMD_PENDING)) {
                kfree_skb(hdev->req_skb);
                hdev->req_skb = skb_clone(hdev->sent_cmd, GFP_KERNEL);
index 0c8888448d3c6f442c32dfde0e0d9545153eeaf3..63548c4cc1ac3b06ea5d5eef2cc56f2e090c73e1 100644 (file)
@@ -566,6 +566,53 @@ unlock:
        hci_dev_unlock(hdev);
 }
 
+static bool is_interleave_scanning(struct hci_dev *hdev)
+{
+       return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE;
+}
+
+static int hci_passive_scan_sync(struct hci_dev *hdev);
+
+static void interleave_scan_work(struct work_struct *work)
+{
+       struct hci_dev *hdev = container_of(work, struct hci_dev,
+                                           interleave_scan.work);
+       unsigned long timeout;
+
+       if (hdev->interleave_scan_state == INTERLEAVE_SCAN_ALLOWLIST) {
+               timeout = msecs_to_jiffies(hdev->advmon_allowlist_duration);
+       } else if (hdev->interleave_scan_state == INTERLEAVE_SCAN_NO_FILTER) {
+               timeout = msecs_to_jiffies(hdev->advmon_no_filter_duration);
+       } else {
+               bt_dev_err(hdev, "unexpected error");
+               return;
+       }
+
+       hci_passive_scan_sync(hdev);
+
+       hci_dev_lock(hdev);
+
+       switch (hdev->interleave_scan_state) {
+       case INTERLEAVE_SCAN_ALLOWLIST:
+               bt_dev_dbg(hdev, "next state: allowlist");
+               hdev->interleave_scan_state = INTERLEAVE_SCAN_NO_FILTER;
+               break;
+       case INTERLEAVE_SCAN_NO_FILTER:
+               bt_dev_dbg(hdev, "next state: no filter");
+               hdev->interleave_scan_state = INTERLEAVE_SCAN_ALLOWLIST;
+               break;
+       case INTERLEAVE_SCAN_NONE:
+               bt_dev_err(hdev, "unexpected error");
+       }
+
+       hci_dev_unlock(hdev);
+
+       /* Don't continue interleaving if it was canceled */
+       if (is_interleave_scanning(hdev))
+               queue_delayed_work(hdev->req_workqueue,
+                                  &hdev->interleave_scan, timeout);
+}
+
 void hci_cmd_sync_init(struct hci_dev *hdev)
 {
        INIT_WORK(&hdev->cmd_sync_work, hci_cmd_sync_work);
@@ -577,6 +624,7 @@ void hci_cmd_sync_init(struct hci_dev *hdev)
        INIT_WORK(&hdev->reenable_adv_work, reenable_adv);
        INIT_DELAYED_WORK(&hdev->le_scan_disable, le_scan_disable);
        INIT_DELAYED_WORK(&hdev->adv_instance_expire, adv_timeout_expire);
+       INIT_DELAYED_WORK(&hdev->interleave_scan, interleave_scan_work);
 }
 
 static void _hci_cmd_sync_cancel_entry(struct hci_dev *hdev,
@@ -2110,11 +2158,6 @@ static void hci_start_interleave_scan(struct hci_dev *hdev)
                           &hdev->interleave_scan, 0);
 }
 
-static bool is_interleave_scanning(struct hci_dev *hdev)
-{
-       return hdev->interleave_scan_state != INTERLEAVE_SCAN_NONE;
-}
-
 static void cancel_interleave_scan(struct hci_dev *hdev)
 {
        bt_dev_dbg(hdev, "cancelling interleave scan");