From patchwork Tue Feb 28 00:13:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengping Jiang X-Patchwork-Id: 62218 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:5915:0:0:0:0:0 with SMTP id v21csp2723045wrd; Mon, 27 Feb 2023 16:27:07 -0800 (PST) X-Google-Smtp-Source: AK7set8e2McYmLoLkUJROWZDZhAc3LSyCFVTN+nlP5JnRsKxrxPjCHcAOZrazCxYaPxpY3Jxylkc X-Received: by 2002:a17:902:f605:b0:196:7664:39c with SMTP id n5-20020a170902f60500b001967664039cmr879886plg.31.1677544027018; Mon, 27 Feb 2023 16:27:07 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1677544027; cv=none; d=google.com; s=arc-20160816; b=pmJZ4bGtK+YCxoVfjQxr/cHyaqJ2zE0GA0Z56H2DwP0jzPZAroDfBSG/td1GZQXQqg 20GubX9LvdfuDq4QaGmh1il7d3vBIghlj3hEeEhc8RlPO0n5+K7g306qYEIWhbtgv0vb 4yOX8eTK6npKZhZkapEZLD0y1wWF1/nYBU+tm3ED4Gl+uiX9G0tPMQUehtM3t1jqvH6y MKP8vD4xjznLA9dWdXjr971qm4CSL9mVsi4hbZSwTYaWNUAEO65JQSOgQ2EX7f+aZhne OQCcwH3AjOl3zxYqmo6UzEZd7sQBmyMn8QnRKo+TQdD0ZVkCrYgijGDBCOQLx5fSeiGP kWOw== 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=zganrZlEZNt1pC9IiqoJtBTU38y2S6sutB3XmJEIjOQ=; b=o91w1DKFuzxIblPcyYAZFhEEfqxQQWOEGhHCrt+k9KCXXKywKJmyigs5DnhOZ+uDsF BupmZfPNMABVJhIc2uR2t2LwHEwydgJEIbs0jV1rrPR86vZsIA7LOcOgpNrsgr2Jh8hJ 3gyqky75K9Ac/aYszI4f0QmYUPjp94cF3Dbp7fmFb6rAxV2PODliVAhJOAgqj66YpCfy RJns2d5+kObqIdgcHyT7/gbu6ttrP/D64QiAqt1dlTJFeQKxfXRtCwWJkfIT+BUvk1wf JZaHXee9WHrVrQMLk4HXxzzpK6Nm/PesxWKyFu+VVdYuiyK/Zla8tcI5ofLXfkYA37yN 3Afg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=GvuKeHm6; 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 ji10-20020a170903324a00b001929550b3e4si7764103plb.466.2023.02.27.16.26.53; Mon, 27 Feb 2023 16:27:06 -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=GvuKeHm6; 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 S229895AbjB1ANn (ORCPT + 99 others); Mon, 27 Feb 2023 19:13:43 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229919AbjB1ANg (ORCPT ); Mon, 27 Feb 2023 19:13:36 -0500 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 728A41BDA for ; Mon, 27 Feb 2023 16:13:27 -0800 (PST) Received: by mail-yw1-x1149.google.com with SMTP id 00721157ae682-536c02ed619so174873457b3.8 for ; Mon, 27 Feb 2023 16:13:27 -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=zganrZlEZNt1pC9IiqoJtBTU38y2S6sutB3XmJEIjOQ=; b=GvuKeHm6KryowowADTIzEiupUt+Pr9uk0FdmdW3FBhCJBtHSpwcisZRn69OkTrIF1r ovptt5Pbb+y8e92zqed7MQ4ubg5BBAn+TAFnFgZJ9hiDYuzIjwmdQ47hiFoAp+lyOMzp bw4zH/F6+yjkw4sk75HV5NXkL0nGNLHJbaRe1IpRcgQog1k6fbATreaWbqCLU0ohaX+p NE6Xoc4ajh2vBehbHJRkTsAJBJC9nBY8GkMoKJvVGY9U+wduDLZff85sNoTcfUiLiB9p IdhjNFuPqObYV/uQBlsy7Ia26HHzvLc6EHvN1xpSydqDtaBQfV3sUoEu81V+gqKujirm AAcw== 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=zganrZlEZNt1pC9IiqoJtBTU38y2S6sutB3XmJEIjOQ=; b=ijwZYU9LccZ7lFjCslJneecA3vRae/1/Q8Ay+9tTinCtNMKU/oKzSDVd0MsZwsHLRn BEnnqcpH449U7EKr2QGl2Hfznf/AeLMBL7ITEVSlybLggzvA63ntA1aeezy5oOFD4xFv LENDOXguyYz4mNZvBXeSZP32R3iDillV/rY4YKm/NndFc0x/s0DaZIF3528ZBryShI3k 9Br2oy3oOsAY3Au0He9tO1uFQ5hS3mWrsNmQdQdhRQ6PBsL7ToERvYYpRCMOh5gUwjl8 wVHoqZQmgSC8r/5yvSso1PkBhxAekVoGtg7RS66DPkAMbn0voUAVaye3cuCUK5Ei4m9N ztsg== X-Gm-Message-State: AO0yUKX+FUw1YG7rVA7LO3n6KvFANq6laIBbWrAYgxq3jHetms1k4DYG ExLf97bRIiAtatIg8Bj737Mp8/w2Y/Sb X-Received: from jiangzp-glinux-dev.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4c52]) (user=jiangzp job=sendgmr) by 2002:a5b:346:0:b0:855:fa17:4f66 with SMTP id q6-20020a5b0346000000b00855fa174f66mr169038ybp.8.1677543206646; Mon, 27 Feb 2023 16:13:26 -0800 (PST) Date: Mon, 27 Feb 2023 16:13:23 -0800 Mime-Version: 1.0 X-Mailer: git-send-email 2.39.2.722.g9855ee24e9-goog Message-ID: <20230227161320.kernel.v4.1.Ibe4d3a42683381c1e78b8c3aa67b53fc74437ae9@changeid> Subject: [kernel PATCH v4] 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?1759032405351068856?= X-GMAIL-MSGID: =?utf-8?q?1759032405351068856?= 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 v4: - Change return value of hci_pause_addr_resolution from err to 0 for readability 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..eb4429d94f95 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 0; + + 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