From patchwork Thu Dec 3 10:29:35 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 1410297 Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=vger.kernel.org (client-ip=23.128.96.18; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=google.com header.i=@google.com header.a=rsa-sha256 header.s=20161025 header.b=F6gxjT1z; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by ozlabs.org (Postfix) with ESMTP id 4CmsZV6bzfz9sVY for ; Thu, 3 Dec 2020 21:31:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2388867AbgLCKb3 (ORCPT ); Thu, 3 Dec 2020 05:31:29 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2387897AbgLCKb2 (ORCPT ); Thu, 3 Dec 2020 05:31:28 -0500 Received: from mail-yb1-xb49.google.com (mail-yb1-xb49.google.com [IPv6:2607:f8b0:4864:20::b49]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 83415C061A4D for ; Thu, 3 Dec 2020 02:30:11 -0800 (PST) Received: by mail-yb1-xb49.google.com with SMTP id x129so2059738ybg.12 for ; Thu, 03 Dec 2020 02:30:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=sender:date:in-reply-to:message-id:mime-version:references:subject :from:to:cc; bh=Uusy26fxweBxaYqTbY3aM4ThUJItFnRbtIun3wbJYAA=; b=F6gxjT1zu2MhqGPp0OAKuwreTuhBbhBTKr7/SSXi8b/2w2/yQ2GQy2oWzpCU01GRWk ot/9HuxJEaqIPZ1bdq1KvAKfwEDXymq9uoDBSMI7gAdL8JDS5D2rEZdqjBE0qSk+aed5 PnBb0H/XpMAe6Wo16zSM/BQHjwiPogGE+lakki6pUJCROIY0hjz6zi5wSBV65OV6erDP lAedw0ob/Myt3sE0mTM/KU3MT09LmJm8Qzvx+bVEwKvOUaCCNWnU+DG8P3rOdhS1+VRi 7JNJ0VoF8EWci9eSexTEMFOEcX47dtl4XaBvsQwosSqAOIbia5McIh+6Z8vc/y1rTaSP 0uxg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=Uusy26fxweBxaYqTbY3aM4ThUJItFnRbtIun3wbJYAA=; b=oQhxGiR5A2QRH8MRJiTTbsPI7v3FXhaROhCUkXxTBhGlpKvdpCTWhduH6cDrIQmL3R Q2CKGLhWuWhkUO46UzxReE1/rCKX+o3FQGg261DiG7yPwGEqP/Rf2HvMBOuIjN172TrJ Sv7jRp+1PwCF5BG5/dA5Um+iz3QWhHCoT//q9qxcTtQ68tp/3CIJZNB+/pcjubRBiT6w c++6siWQqfma6qqd/zQAPMgCKsAm3pILAkj3jtG+XAtPdhBIPiGjff0SbirVggyjEXrv ErjniiYuhEMOTJPhxChBl+Yncxuhwllmp0xnweokgw2uZhSTj5/sTsgMUpoewdpDHlDg 0rtw== X-Gm-Message-State: AOAM530QZrlfUL/mEC47guSdu9zlzIH86TmihCmWt8mGg+ppydycVfy2 WEFEhZ8/95z2oH8fhqbGdrtbwr2DaOnX X-Google-Smtp-Source: ABdhPJxzCBzy9YNWRm7NhHb4c8ir/aZGj5PiFMWk6k3YtggbFw5zNyOFfYTyVvMerIzfVJVxuNXG7nez6yGH Sender: "apusaka via sendgmr" X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:b:f693:9fff:fef4:2347]) (user=apusaka job=sendgmr) by 2002:a25:c6d5:: with SMTP id k204mr3446133ybf.363.1606991410787; Thu, 03 Dec 2020 02:30:10 -0800 (PST) Date: Thu, 3 Dec 2020 18:29:35 +0800 In-Reply-To: <20201203102936.4049556-1-apusaka@google.com> Message-Id: <20201203182903.v1.5.I96e97067afe1635dbda036b881ba2a01f37cd343@changeid> Mime-Version: 1.0 References: <20201203102936.4049556-1-apusaka@google.com> X-Mailer: git-send-email 2.29.2.454.gaff20da3a2-goog Subject: [PATCH v1 5/5] Bluetooth: advmon offload MSFT handle filter enablement From: Archie Pusaka To: linux-bluetooth , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , Miao-chen Chou , Yun-Hao Chung , "David S. Miller" , Jakub Kicinski , Johan Hedberg , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Archie Pusaka Implements the feature to disable/enable the filter used for advertising monitor on MSFT controller, effectively have the same effect as "remove all monitors" and "add all previously removed monitors". This feature would be needed when suspending, where we would not want to get packets from anything outside the allowlist. Note that the integration with the suspending part is not included in this patch. Signed-off-by: Archie Pusaka Reviewed-by: Miao-chen Chou Reviewed-by: Yun-Hao Chung --- net/bluetooth/msft.c | 67 ++++++++++++++++++++++++++++++++++++++++++++ net/bluetooth/msft.h | 6 ++++ 2 files changed, 73 insertions(+) diff --git a/net/bluetooth/msft.c b/net/bluetooth/msft.c index 7e33a85c3f1c..055cc5a260df 100644 --- a/net/bluetooth/msft.c +++ b/net/bluetooth/msft.c @@ -69,6 +69,17 @@ struct msft_rp_le_cancel_monitor_advertisement { __u8 sub_opcode; } __packed; +#define MSFT_OP_LE_SET_ADVERTISEMENT_FILTER_ENABLE 0x05 +struct msft_cp_le_set_advertisement_filter_enable { + __u8 sub_opcode; + __u8 enable; +} __packed; + +struct msft_rp_le_set_advertisement_filter_enable { + __u8 status; + __u8 sub_opcode; +} __packed; + struct msft_monitor_advertisement_handle_data { __u8 msft_handle; __u16 mgmt_handle; @@ -85,6 +96,7 @@ struct msft_data { struct { u8 reregistering:1; + u8 filter_enabled:1; } flags; }; @@ -193,6 +205,7 @@ void msft_do_open(struct hci_dev *hdev) if (msft_monitor_supported(hdev)) { msft->flags.reregistering = true; + msft_set_filter_enable(hdev, true); reregister_monitor_on_restart(hdev, 0); } } @@ -398,6 +411,40 @@ static void msft_le_cancel_monitor_advertisement_cb(struct hci_dev *hdev, hci_remove_adv_monitor_complete(hdev, status); } +static void msft_le_set_advertisement_filter_enable_cb(struct hci_dev *hdev, + u8 status, u16 opcode, + struct sk_buff *skb) +{ + struct msft_cp_le_set_advertisement_filter_enable *cp; + struct msft_rp_le_set_advertisement_filter_enable *rp; + struct msft_data *msft = hdev->msft_data; + + rp = (struct msft_rp_le_set_advertisement_filter_enable *)skb->data; + if (skb->len < sizeof(*rp)) + return; + + /* Error 0x0C would be returned if the filter enabled status is + * already set to whatever we were trying to set. + * Although the default state should be disabled, some controller set + * the initial value to enabled. Because there is no way to know the + * actual initial value before sending this command, here we also treat + * error 0x0C as success. + */ + if (status != 0x00 && status != 0x0C) + return; + + hci_dev_lock(hdev); + + cp = hci_sent_cmd_data(hdev, hdev->msft_opcode); + msft->flags.filter_enabled = cp->enable; + + if (status == 0x0C) + bt_dev_warn(hdev, "MSFT filter_enable is already %s", + cp->enable ? "on" : "off"); + + hci_dev_unlock(hdev); +} + static bool msft_monitor_rssi_valid(struct adv_monitor *monitor) { struct adv_rssi_thresholds *r = &monitor->rssi; @@ -534,3 +581,23 @@ int msft_remove_monitor(struct hci_dev *hdev, struct adv_monitor *monitor, return err; } + +int msft_set_filter_enable(struct hci_dev *hdev, bool enable) +{ + struct msft_cp_le_set_advertisement_filter_enable cp; + struct hci_request req; + struct msft_data *msft = hdev->msft_data; + int err; + + if (!msft) + return -EOPNOTSUPP; + + cp.sub_opcode = MSFT_OP_LE_SET_ADVERTISEMENT_FILTER_ENABLE; + cp.enable = enable; + + hci_req_init(&req, hdev); + hci_req_add(&req, hdev->msft_opcode, sizeof(cp), &cp); + err = hci_req_run_skb(&req, msft_le_set_advertisement_filter_enable_cb); + + return err; +} diff --git a/net/bluetooth/msft.h b/net/bluetooth/msft.h index 9f9a11f90b0c..44bee705c16d 100644 --- a/net/bluetooth/msft.h +++ b/net/bluetooth/msft.h @@ -20,6 +20,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, u16 handle); +int msft_set_filter_enable(struct hci_dev *hdev, bool enable); #else @@ -45,4 +46,9 @@ static inline bool msft_remove_monitor(struct hci_dev *hdev, return -EOPNOTSUPP; } +static inline int msft_set_filter_enable(struct hci_dev *hdev, bool enable) +{ + return -EOPNOTSUPP; +} + #endif