From patchwork Wed Feb 22 00:17:56 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengping Jiang X-Patchwork-Id: 60297 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp300011wrd; Tue, 21 Feb 2023 16:28:15 -0800 (PST) X-Google-Smtp-Source: AK7set+lfxQcz8lEWpua6ri5ZrA04jh/66FdQyVlhNkjKrTpbAyVf7KmHPhO1sUxR85IQ4kCD++i X-Received: by 2002:a17:902:d2cb:b0:19a:ad90:4223 with SMTP id n11-20020a170902d2cb00b0019aad904223mr10343619plc.48.1677025695363; Tue, 21 Feb 2023 16:28:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677025695; cv=none; d=google.com; s=arc-20160816; b=XVr2QmMbE9PUPq0EK5OmaZIl/04uSlSCPZX481hFKNbzEp+rG57bbkUTojjwGo0b93 9WqX/T4UpvfXcqz5KDm/qJ7PNxYNpvuXi4lB4FEJOoVp+ZR44rMiio6DTwVR72U5H2pa zRiWDdNbQCtQOf5yS55OGiwBkfa3upjZfU49Jjj48i1MMm/GFxhjFFZMROrWBDgAaerL vFHOQeizQTSANbWKX8gb1+UF8xKpxoGzyLcs1vDwKI/1kCiU24zZDSjZF+tBTa6F8cT+ 388kuD4UaGVjyXoLsaQPi9CdwnVAYiQq3CLOkycntvLPesWqaluux1cRllxeQM1Wx2OR osLQ== 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:message-id:mime-version:date :dkim-signature; bh=J9BtaV1ZeQpd3OOnFLxf3faqs1oNxew2rIeqnER9uJo=; b=fKmlpDSvl4Nra432rH6TRVVhR+xHCTluBVfwPjRW4pdS7BHEc+f/2L73rWvuscZCZ8 eulzch10jf4niygCixCwE8AVY2UPqK8mKmTD0DlBs+/tMF8GH2JibQn+akWia+8XH3pH XbuTOcXvyYf4Tmly+drP9VNDsMXzH0bHBBSAgjm6gOLQ+sAGNUDVJcHbR4JxDoqKpTY3 s1vhkGKDotD0OItehpYIXQ8expbpgAepSU8BYMTeFaP6rmggdF5Tjht2PB2C4at7bWQD 2Nm3c3c7Ew72vwkV3Y3bhUFjkUCs2dnLif+ffD96nzYPJg5AlBbbWHslhnrnKKdN8LAu 3Egw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=EJEFUQAl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d17-20020a170903231100b001890c6ff018si16191462plh.486.2023.02.21.16.28.02; Tue, 21 Feb 2023 16:28:15 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-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=EJEFUQAl; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-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 S230321AbjBVASF (ORCPT + 99 others); Tue, 21 Feb 2023 19:18:05 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58382 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230291AbjBVASD (ORCPT ); Tue, 21 Feb 2023 19:18:03 -0500 Received: from mail-pj1-x1049.google.com (mail-pj1-x1049.google.com [IPv6:2607:f8b0:4864:20::1049]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8F748125A4 for ; Tue, 21 Feb 2023 16:18:00 -0800 (PST) Received: by mail-pj1-x1049.google.com with SMTP id gf1-20020a17090ac7c100b002369bf87b7aso2705566pjb.8 for ; Tue, 21 Feb 2023 16:18:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:from:to:cc:subject :date:message-id:reply-to; bh=J9BtaV1ZeQpd3OOnFLxf3faqs1oNxew2rIeqnER9uJo=; b=EJEFUQAlfEKrvkYmyCpgmJInyPKTe3V/xDEINMW2a8e/zDFGP1uifrWMmX/1oEz9yn dIrLF0ezYBTmuB1ZhyLXzf8MzF6M47TLn8caRR9Hbjxg7dp7gLgKOvRVSnVWs4LN3ocS Jy4tR9tXYmbiSlw2ZJ5gLAaXvZVYzPSJvOuobOcThH9/PuLlX/l3vCoOBWSFrGUz2gXj WqsAgsGgfpwR0zeNK4JRtx07N2Gff8Mj8xbcXLIvQJ7cEP3bjmCQ7eC5OT6sv84YoYi5 1qMNxE2fdQX2f1qhnporQuIbvCYgyoXnj4402MLDT/8eFGDeZ+QkMEGCifOWSaszxN1G 9x3A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:mime-version:date:x-gm-message-state :from:to:cc:subject:date:message-id:reply-to; bh=J9BtaV1ZeQpd3OOnFLxf3faqs1oNxew2rIeqnER9uJo=; b=sxzwn8G6MxzQAQtDrGCqdmBCDfmfKcNejcmLy50WstQcLpYgGDNoZ7C/GnjSVEwqqS H5W6WHvYfKcONJIDLke2Lfk7LzlQRnx5bvPpPitsVRhqKR5spBrDTknJ6nu/1u8fdNBZ X5ePONgQDlym3keZJx/gMbYW/ilf9/T6TvhrLE7v62b7dGb9uYFG9czTLHwpWHV97N4O GkEWTsROwAzoo+xR89oGDk23s+aTn9VFvyY62pdFYadZnRX6lRUTeKWjeEkkUydLPmBm Y4NdNffGGk+AZkBgjZNYmZ5Lp+x5uQVlN0yvoe4Xp7lG9OlEuPWCtPyX6qO8DqR9yA30 vSEw== X-Gm-Message-State: AO0yUKXqQUDY7V1wuvh5G3MBcjecVFrC70xMNeOjiKgQKOx7EhnGvjNI iKkrqVLVsirbD0JzHZkmP+DrfbT/lopi X-Received: from jiangzp-glinux-dev.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4c52]) (user=jiangzp job=sendgmr) by 2002:a63:340d:0:b0:4fb:3591:c608 with SMTP id b13-20020a63340d000000b004fb3591c608mr795589pga.4.1677025080009; Tue, 21 Feb 2023 16:18:00 -0800 (PST) Date: Tue, 21 Feb 2023 16:17:56 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.2.637.g21b0678d19-goog Message-ID: <20230221161749.kernel.v3.1.Ibe4d3a42683381c1e78b8c3aa67b53fc74437ae9@changeid> Subject: [kernel PATCH v3] Bluetooth: hci_sync: Resume adv with no RPA when active scan From: Zhengping Jiang To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, Zhengping Jiang , "David S. Miller" , Eric Dumazet , Jakub Kicinski , Johan Hedberg , Paolo Abeni , linux-kernel@vger.kernel.org, netdev@vger.kernel.org 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-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1758488895901014201?= X-GMAIL-MSGID: =?utf-8?q?1758488895901014201?= The address resolution should be disabled during the active scan, so all the advertisements can reach the host. The advertising has to be paused before disabling the address resolution, because the advertising will prevent any changes to the resolving list and the address resolution status. Skipping this will cause the hci error and the discovery failure. According to the bluetooth specification: "7.8.44 LE Set Address Resolution Enable command This command shall not be used when: - Advertising (other than periodic advertising) is enabled, - Scanning is enabled, or - an HCI_LE_Create_Connection, HCI_LE_Extended_Create_Connection, or HCI_LE_Periodic_Advertising_Create_Sync command is outstanding." If the host is using RPA, the controller needs to generate RPA for the advertising, so the advertising must remain paused during the active scan. If the host is not using RPA, the advertising can be resumed after disabling the address resolution. Fixes: 9afc675edeeb ("Bluetooth: hci_sync: allow advertise when scan without RPA") Signed-off-by: Zhengping Jiang --- Changes in v3: - Add a function to check the requirements to pause addr resolution - Pause and resume advertising in hci_pause_addr_resolution - Resume advertising if pausing addr resolution fails or privacy mode is not used for advertising Changes in v2: - Commit message format Changes in v1: - With LL privacy, always pause advertising when active scan - Only resume the advertising if the host is not using RPA net/bluetooth/hci_sync.c | 64 +++++++++++++++++++++++++++------------- 1 file changed, 44 insertions(+), 20 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 117eedb6f709..37b002e1d576 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -2367,6 +2367,45 @@ static int hci_resume_advertising_sync(struct hci_dev *hdev) return err; } +static int hci_pause_addr_resolution(struct hci_dev *hdev) +{ + int err; + + if (!use_ll_privacy(hdev)) + return 0; + + if (!hci_dev_test_flag(hdev, HCI_LL_RPA_RESOLUTION)) + return 0; + + /* Cannot disable addr resolution if scanning is enabled or + * when initiating an LE connection. + */ + if (hci_dev_test_flag(hdev, HCI_LE_SCAN) || + hci_lookup_le_connect(hdev)) { + bt_dev_err(hdev, "Command not allowed when scan/LE connect"); + return -EPERM; + } + + // Cannot disable addr resolution if advertising is enabled. + err = hci_pause_advertising_sync(hdev); + if (err) { + bt_dev_err(hdev, "Pause advertising failed: %d", err); + return err; + } + + err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); + if (err) + bt_dev_err(hdev, "Unable to disable Address Resolution: %d", + err); + + // Return if address resolution is disabled and RPA is not used. + if (!err && scan_use_rpa(hdev)) + return err; + + hci_resume_advertising_sync(hdev); + return err; +} + struct sk_buff *hci_read_local_oob_data_sync(struct hci_dev *hdev, bool extended, struct sock *sk) { @@ -2402,7 +2441,7 @@ static u8 hci_update_accept_list_sync(struct hci_dev *hdev) u8 filter_policy; int err; - /* Pause advertising if resolving list can be used as controllers are + /* Pause advertising if resolving list can be used as controllers * cannot accept resolving list modifications while advertising. */ if (use_ll_privacy(hdev)) { @@ -5394,27 +5433,12 @@ static int hci_active_scan_sync(struct hci_dev *hdev, uint16_t interval) cancel_interleave_scan(hdev); - /* Pause advertising since active scanning disables address resolution - * which advertising depend on in order to generate its RPAs. - */ - if (use_ll_privacy(hdev) && hci_dev_test_flag(hdev, HCI_PRIVACY)) { - err = hci_pause_advertising_sync(hdev); - if (err) { - bt_dev_err(hdev, "pause advertising failed: %d", err); - goto failed; - } - } - - /* Disable address resolution while doing active scanning since the - * accept list shall not be used and all reports shall reach the host - * anyway. + /* Pause address resolution for active scan and stop advertising if + * privacy is enabled. */ - err = hci_le_set_addr_resolution_enable_sync(hdev, 0x00); - if (err) { - bt_dev_err(hdev, "Unable to disable Address Resolution: %d", - err); + err = hci_pause_addr_resolution(hdev); + if (err) goto failed; - } /* All active scans will be done with either a resolvable private * address (when privacy feature has been enabled) or non-resolvable