Received: by 2002:ac0:e350:0:0:0:0:0 with SMTP id g16csp510235imn; Wed, 3 Aug 2022 13:28:04 -0700 (PDT) X-Google-Smtp-Source: AA6agR6q9YxAZAFXRxz7EByzTDO5l0dLddDJuRwItdXqjqxtFeCH+ZodKW0Ilh2oBWaC1fjyOqAI X-Received: by 2002:a17:907:738a:b0:730:6d62:4ec8 with SMTP id er10-20020a170907738a00b007306d624ec8mr14415443ejc.590.1659558484546; Wed, 03 Aug 2022 13:28:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1659558484; cv=none; d=google.com; s=arc-20160816; b=k8D0eALaOZCDfY3Ion6PTyKUf9jUKE7hMgwgP085CluvvWVx0EWL33jCzXSJeiOqmP HMem4pMrMqsqpxuppLA8XPkv3iwU+93dp3l8Wn4TvQuGSIFxN4695RbBQD22GFWPdKVT Lnp+JQmihJOmnVi1rtSgg3BqeOSCrj3mlZUi302ikQ48zTFwMjURai6V0GUUY28I7B2s YDCmbjb8KMmyYH3nhR3Dv8C1fsq7fMAxQ2CCSnl8dL9eCf7DQYeq8h5Q9cGaQ2Mp3yoP qkv57RpPqi2hBMGCcLOOy+mUOCYL3qGQQHtNjFQE4vQBs5OisUJBvmUhrgcHWo4gKRly 9/tw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:from:subject:mime-version:message-id:date :dkim-signature; bh=MG4NVz9yj2aFOgp1HtlyEgPmRnBQqcRnRDU4maqxDLs=; b=gh7t6Rw/NGLyiptqm2lUEBlpARGxJecpdit4DuTaRrFj9HWZOWo5smpZBZ6/KOZmqR sMYU6KZS9KBbiTP1fj0tg8fbNRWAzVgbnJ6DuK9dQAwRxJVUkR/zkuxK7cdEzqbZe0ST BXFVg1lWM4Sp6lDyIJdR8eQeYkXLi0LIaBFJb6JQkI3e8IGK+Qpds7bazRXhmb0p3fa4 UB+/uMvU3lKU7nKNH+r6fZbeQ6m3zJuhVdntchCTc+xwOgRi1BOXs0kdoVvkxHHxskuY 9VToWEQGGX/j0avaDE4epKeulWj9UyhWYT9P0q0ZWTj9vsMfor2LsjRfTp3Rg/Jv4916 PbNg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ac+Kon2B; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id wt9-20020a170906ee8900b006f44d992450si12831304ejb.11.2022.08.03.13.27.08; Wed, 03 Aug 2022 13:28:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=ac+Kon2B; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238537AbiHCUY6 (ORCPT + 99 others); Wed, 3 Aug 2022 16:24:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35408 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S238545AbiHCUY5 (ORCPT ); Wed, 3 Aug 2022 16:24:57 -0400 Received: from mail-yw1-x1149.google.com (mail-yw1-x1149.google.com [IPv6:2607:f8b0:4864:20::1149]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 133BD53D25 for ; Wed, 3 Aug 2022 13:24:56 -0700 (PDT) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-31f46b4759bso151188157b3.0 for ; Wed, 03 Aug 2022 13:24:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:from:to:cc; bh=MG4NVz9yj2aFOgp1HtlyEgPmRnBQqcRnRDU4maqxDLs=; b=ac+Kon2BynLX4PUenHyxIDUcn1exeZCxVb3lFiCKZxJGscBLaZVq1IS4i8FPji9GSs bPhe0/gEK3wWy3S/IUzPCtZc15S/x/0Qa+tsyQpNdPyJeuQKn4bsns/qb5XNKJ0SE4cc BqSQecGZRufHziIFY7/jtCvQjU4p8FDdabjc2X/Tkcli6ZEg7sntef9yedlmVpTseUiW VcH5HDzJNK3+ZLdx7K7rgeHIE110gCCu5t24Rh+XwnfnDJCwx8q2pq7wHdO+2y961y2O TvxmZg9cx00v9XHwi46QDtHpv6k8qfLYhpjvUB50CMpM0dWKv+mmxaYUMtWmiMbfixBv G5Rg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:mime-version:message-id:date:x-gm-message-state :from:to:cc; bh=MG4NVz9yj2aFOgp1HtlyEgPmRnBQqcRnRDU4maqxDLs=; b=VanSE72VV7oVgjimTJ6SWU2mf5kqLhQKJjNn4TrXeLmEOrMQd2S7e9+PI9VycOv4O+ +ak4kYRUlrmjN6iYzCeZIJRZ40e1aSbbcQjtqvI7UtRQZonPn8o5//1rEVa9kA4kqnwM 9maTIQV0yRyN+BrDXskjdw1bjYu68+xaxIUTSlnOILK/OCHuTKi49mlv9uyTG9nwH5ey 5ZBBJ498DmjhLsyFyK4RXjOIdBIsnOw4+9zUO74lZVrpiyiQDaL8YQnjyA8/xH8JYtgy JMfvI0qrGyCYxsPw8mYCJZB2mbT4qtlG9gtqXCsG3GhhMo4KfDOWXjdm9P2CiKUIGhpV S6kw== X-Gm-Message-State: ACgBeo06SZE5M2qxGdAwx5E3Ap7MbJ6GQe10HWlZs/8G6oe1ADrgoAOb ElQVqWONaN/s2aI7CGjssOzrujflBRaTxw== X-Received: from mmandlik.mtv.corp.google.com ([2620:15c:202:201:6eae:dfce:5d69:e05f]) (user=mmandlik job=sendgmr) by 2002:a0d:e8c1:0:b0:322:e31a:9c4a with SMTP id r184-20020a0de8c1000000b00322e31a9c4amr24937744ywe.334.1659558295388; Wed, 03 Aug 2022 13:24:55 -0700 (PDT) Date: Wed, 3 Aug 2022 13:24:50 -0700 Message-Id: <20220803132319.1.I5acde3b5af78dbd2ea078d5eb4158d23b496ac87@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.37.1.455.g008518b4e5-goog Subject: [PATCH 1/2] Bluetooth: Disable AdvMonitor SamplingPeriod while active scan From: Manish Mandlik To: marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, linux-bluetooth@vger.kernel.org, Manish Mandlik , Miao-chen Chou , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Johan Hedberg , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-9.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS,USER_IN_DEF_DKIM_WL autolearn=unavailable autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org Some controllers apply Sampling Period even while active scanning. So, to keep the behavior consistent across all controllers, don't use Sampling Period during active scanning to force the controller to report all advertisements even if it matches the monitor. Signed-off-by: Manish Mandlik Reviewed-by: Miao-chen Chou --- net/bluetooth/hci_sync.c | 6 ++++++ net/bluetooth/msft.c | 45 +++++++++++++++++++++++++++++++++++++--- net/bluetooth/msft.h | 2 ++ 3 files changed, 50 insertions(+), 3 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index e6d804b82b67..cb0c219ebe1c 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4649,6 +4649,9 @@ int hci_stop_discovery_sync(struct hci_dev *hdev) if (use_ll_privacy(hdev)) hci_resume_advertising_sync(hdev); + /* Sampling Period is disabled while active scanning, re-enable it */ + msft_set_active_scan(hdev, false); + /* No further actions needed for LE-only discovery */ if (d->type == DISCOV_TYPE_LE) return 0; @@ -5139,6 +5142,9 @@ int hci_start_discovery_sync(struct hci_dev *hdev) if (err) return err; + /* Disable Sampling Period while active scanning */ + msft_set_active_scan(hdev, true); + bt_dev_dbg(hdev, "timeout %u ms", jiffies_to_msecs(timeout)); /* When service discovery is used and the controller has a diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c index bee6a4c656be..f63c911b210c 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -101,6 +101,7 @@ struct msft_data { struct list_head handle_map; __u8 resuming; __u8 suspending; + __u8 active_scan; __u8 filter_enabled; }; @@ -333,14 +334,14 @@ static int msft_remove_monitor_sync(struct hci_dev *hdev, } /* This function requires the caller holds hci_req_sync_lock */ -int msft_suspend_sync(struct hci_dev *hdev) +static void remove_all_monitors(struct hci_dev *hdev) { struct msft_data *msft = hdev->msft_data; struct adv_monitor *monitor; int handle = 0; if (!msft || !msft_monitor_supported(hdev)) - return 0; + return; msft->suspending = true; @@ -356,6 +357,12 @@ int msft_suspend_sync(struct hci_dev *hdev) /* All monitors have been removed */ msft->suspending = false; +} + +/* This function requires the caller holds hci_req_sync_lock */ +int msft_suspend_sync(struct hci_dev *hdev) +{ + remove_all_monitors(hdev); return 0; } @@ -392,6 +399,7 @@ static bool msft_monitor_pattern_valid(struct adv_monitor *monitor) static int msft_add_monitor_sync(struct hci_dev *hdev, struct adv_monitor *monitor) { + struct msft_data *msft = hdev->msft_data; struct msft_cp_le_monitor_advertisement *cp; struct msft_le_monitor_advertisement_pattern_data *pattern_data; struct msft_le_monitor_advertisement_pattern *pattern; @@ -417,7 +425,16 @@ static int msft_add_monitor_sync(struct hci_dev *hdev, cp->rssi_high = monitor->rssi.high_threshold; cp->rssi_low = monitor->rssi.low_threshold; cp->rssi_low_interval = (u8)monitor->rssi.low_threshold_timeout; - cp->rssi_sampling_period = monitor->rssi.sampling_period; + + /* Some controllers apply Sampling Period even while active scanning. + * So, to keep the behavior consistent across all controllers, don't + * use Sampling Period during active scanning to force the controller + * to report all advertisements even if it matches the monitor. + */ + if (msft->active_scan) + cp->rssi_sampling_period = 0; + else + cp->rssi_sampling_period = monitor->rssi.sampling_period; cp->cond_type = MSFT_MONITOR_ADVERTISEMENT_TYPE_PATTERN; @@ -815,6 +832,28 @@ void msft_req_add_set_filter_enable(struct hci_request *req, bool enable) hci_req_add(req, hdev->msft_opcode, sizeof(cp), &cp); } +/* This function requires the caller holds hci_req_sync_lock */ +void msft_set_active_scan(struct hci_dev *hdev, bool enable) +{ + struct msft_data *msft = hdev->msft_data; + + if (!msft) + return; + + /* Remove all monitors */ + remove_all_monitors(hdev); + + /* Clear all tracked devices */ + hci_dev_lock(hdev); + hdev->advmon_pend_notify = false; + msft_monitor_device_del(hdev, 0, NULL, 0, true); + hci_dev_unlock(hdev); + + /* Update active scan and reregister all monitors */ + msft->active_scan = enable; + reregister_monitor(hdev); +} + int msft_set_filter_enable(struct hci_dev *hdev, bool enable) { struct hci_request req; diff --git a/net/bluetooth/msft.h b/net/bluetooth/msft.h index 2a63205b377b..7dfd866dacc4 100644 --- a/net/bluetooth/msft.h +++ b/net/bluetooth/msft.h @@ -22,6 +22,7 @@ __u64 msft_get_features(struct hci_dev *hdev); int msft_add_monitor_pattern(struct hci_dev *hdev, struct adv_monitor *monitor); int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor); void msft_req_add_set_filter_enable(struct hci_request *req, bool enable); +void msft_set_active_scan(struct hci_dev *hdev, bool enable); int msft_set_filter_enable(struct hci_dev *hdev, bool enable); int msft_suspend_sync(struct hci_dev *hdev); int msft_resume_sync(struct hci_dev *hdev); @@ -55,6 +56,7 @@ static inline int msft_remove_monitor(struct hci_dev *hdev, static inline void msft_req_add_set_filter_enable(struct hci_request *req, bool enable) {} +static inline void msft_set_active_scan(struct hci_dev *hdev, bool enable) {} static inline int msft_set_filter_enable(struct hci_dev *hdev, bool enable) { return -EOPNOTSUPP; -- 2.37.1.455.g008518b4e5-goog