From patchwork Wed Jan 25 21:12:10 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Zhengping Jiang X-Patchwork-Id: 48357 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp488988wrn; Wed, 25 Jan 2023 13:15:31 -0800 (PST) X-Google-Smtp-Source: AMrXdXtt7KT1ORqzeQFA9fo217xgK+Rny6bXbnfHMcN2pHKaU5gdWRXiSmAfsWrwq20Ytqw+WPrS X-Received: by 2002:a17:906:8d86:b0:870:dceb:696d with SMTP id ry6-20020a1709068d8600b00870dceb696dmr41689311ejc.43.1674681331289; Wed, 25 Jan 2023 13:15:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674681331; cv=none; d=google.com; s=arc-20160816; b=VNChKIWjGtiCgifvt1Zxso8S3wZNzrsY5vfQMed87E52VIo7MUX3eta//DpcN0vD8B HeVGuCJ5W/P9ne1orU5rxyk44SDbwVPqJjGf1vs5NyR51YEzWWLt4vcoyGiRjI82ktyD 9qd9V+ZgryROrb40XbjVFUrTj0u7QBj5AXCcgud0BgC7msgTdghinXcKfJykNuEf3MzC zjjTjH53L+4/tZ8iTLKna+HiomC8bQv/AYm9Q7wlkE2sTzWXP/2UM7KUociuwHiTBmR2 Jz2gVKj/mnSInaXVuIEO4NmD6j6byrlax2BRCLsNZGzi67TLhf+pu5gjIH3aEiXFfSI7 y+4A== 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:references :mime-version:in-reply-to:date:dkim-signature; bh=mjUP68ZzzFyh8hG9RPeRlc5xrTMio/O97kr7jaJq5/0=; b=kqCEYhDa27Z2v1zEiXdy991M5tDcWzUvFR3mSPa6Pr5DE/v6EqccM68uhDnHa2IZRj 22RTYkkPK+Fz+f+ZeAPavd/KRBj+W0LLsfuCl+to382AYlLzYYM+ByCoR2dQasC6uiiB E7vnmJcuEG3fdklMipbl0aK5hIvqdzLs52Ea5WN/2b2pZnp9oMz9Z2RkINw1+hSo9mz1 rQsOT7YQ+EgooR+oaGc1+cQJS85qO/vg6B/zs9o3LmT0e7svUwON0DQpWKwZYxuKc49H FbYPsM+nnyRQimrMoFBp7cEOOGTB+B2QWwAyKJ+RVaQps3ZT2da1Ltt3KWqqWZx1A+11 +Hjg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20210112 header.b=bZKAmtw+; 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 fh5-20020a1709073a8500b00839f873bf66si7235139ejc.320.2023.01.25.13.15.07; Wed, 25 Jan 2023 13:15:31 -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=bZKAmtw+; 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 S235895AbjAYVMm (ORCPT + 99 others); Wed, 25 Jan 2023 16:12:42 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:34338 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236358AbjAYVMc (ORCPT ); Wed, 25 Jan 2023 16:12:32 -0500 Received: from mail-yw1-x114a.google.com (mail-yw1-x114a.google.com [IPv6:2607:f8b0:4864:20::114a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB93B5B591 for ; Wed, 25 Jan 2023 13:12:18 -0800 (PST) Received: by mail-yw1-x114a.google.com with SMTP id 00721157ae682-507aac99fdfso15110927b3.11 for ; Wed, 25 Jan 2023 13:12:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=mjUP68ZzzFyh8hG9RPeRlc5xrTMio/O97kr7jaJq5/0=; b=bZKAmtw+epp2hdpRq2aYZvzRqfJc+Q6/JLBQqH5S+RddlZ7/gEumJ8QBuUtH4JWCly j7q66n+q3gB/gV8f/YYIHMDdCMOwWhy+uzwQtvA/D61T0UT1V0/8briK5e8ZSyVk9mAq 59XvAqGaezM4lbTaFzWrDGZIMwNbymCD559QZxaOngdKp1+Ve6S35nnMjPrWPEuM8mkv ipDr0Yg39ysUTCH6HQ/gFQfaGx9E+Nsl3gUQYX1hdhyHPC14SwlYYLynR6SU91texQ0c skYI1gNfNvokuscJm7PhDqmEn8trMNm6HJi7YaGhBxfK3BDztlX1jjguaQxvsshZ/wsm CxmQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=mjUP68ZzzFyh8hG9RPeRlc5xrTMio/O97kr7jaJq5/0=; b=LXbp8ve8J2Joy/QnOdckcCoNsdK0DEf0vGbhyk0LVMhQ8f9UWpp/q3rrsZn9koZgO8 zAakaZaMtQGzXBZ5jfQdcDKBnc8XUxDdwqx2SiOmZGamL+dtq1WHmD7WFOEbYKORvtqt Xw8JzHat21dzyIMZdsTD5k4v97OX/jSiBQFAmigsVNNFGqd1IQo0vjVgZNF1ySTsyej1 TGyEr0+AdZFV0ubVMnY4P0T0fkcUOBPyg3d9nIw8HFWDwB/oYRsAv1Lw41tmY0q60arI RKJ8Wdn5MVwHtC1wVv4crQnqA6OrT1at8UNxUpnwC/v0PCrvoXyq4t7hC2Dw8PKMhktl phEg== X-Gm-Message-State: AO0yUKW215HhrTw+cqOUP9d1X0Ur9X4MzqcHs1RuEd7aA+lvqT7zVQBH lOkvl1Lsv2m+MOtade8xMPPUiZNbnPuU X-Received: from jiangzp-glinux-dev.c.googlers.com ([fda3:e722:ac3:cc00:7f:e700:c0a8:4c52]) (user=jiangzp job=sendgmr) by 2002:a0d:d6c7:0:b0:506:3481:ced0 with SMTP id y190-20020a0dd6c7000000b005063481ced0mr1197728ywd.396.1674681137911; Wed, 25 Jan 2023 13:12:17 -0800 (PST) Date: Wed, 25 Jan 2023 13:12:10 -0800 In-Reply-To: <20230125211210.552679-1-jiangzp@google.com> Mime-Version: 1.0 References: <20230125211210.552679-1-jiangzp@google.com> X-Mailer: git-send-email 2.39.1.456.gfc5497dd1b-goog Message-ID: <20230125131159.kernel.v1.1.Id80089feef7af8846cc6f8182eddc5d7a0ac4ea7@changeid> Subject: [kernel PATCH v1 1/1] Bluetooth: Don't send HCI commands to remove adv if adapter is off From: Zhengping Jiang To: linux-bluetooth@vger.kernel.org, marcel@holtmann.org, luiz.dentz@gmail.com Cc: chromeos-bluetooth-upstreaming@chromium.org, Archie Pusaka , 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?1756030651768595604?= X-GMAIL-MSGID: =?utf-8?q?1756030651768595604?= From: Archie Pusaka Mark the advertisement as disabled when powering off the adapter without removing the advertisement, so they can be correctly re-enabled when adapter is powered on again. When adapter is off and user requested to remove advertisement, a HCI command will be issued. This causes the command to timeout and trigger GPIO reset. Therefore, immediately remove the advertisement without sending any HCI commands. Note that the above scenario only happens with extended advertisement (i.e. not using software rotation), because on the SW rotation scenario, we just wait until the rotation timer runs out before sending the HCI command. Since the timer is inactive when adapter is off, no HCI commands are sent. Signed-off-by: Archie Pusaka Signed-off-by: Zhengping Jiang --- Changes in v1: - Mark the advertisement as disabled instead of clearing it. - Remove the advertisement without sending HCI command if the adapter is off. net/bluetooth/hci_sync.c | 57 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 53 insertions(+), 4 deletions(-) diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 117eedb6f709..08da68a30acc 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -1591,6 +1591,16 @@ int hci_remove_ext_adv_instance_sync(struct hci_dev *hdev, u8 instance, if (!ext_adv_capable(hdev)) return 0; + /* When adapter is off, remove adv without sending HCI commands */ + if (!hdev_is_powered(hdev)) { + hci_dev_lock(hdev); + err = hci_remove_adv_instance(hdev, instance); + if (!err) + mgmt_advertising_removed(sk, hdev, instance); + hci_dev_unlock(hdev); + return err; + } + err = hci_disable_ext_adv_instance_sync(hdev, instance); if (err) return err; @@ -1772,6 +1782,23 @@ int hci_schedule_adv_instance_sync(struct hci_dev *hdev, u8 instance, return hci_start_adv_sync(hdev, instance); } +static void hci_clear_ext_adv_ins_during_power_off(struct hci_dev *hdev, + struct sock *sk) +{ + struct adv_info *adv, *n; + int err; + + hci_dev_lock(hdev); + list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) { + u8 instance = adv->instance; + + err = hci_remove_adv_instance(hdev, instance); + if (!err) + mgmt_advertising_removed(sk, hdev, instance); + } + hci_dev_unlock(hdev); +} + static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk) { int err; @@ -1779,6 +1806,12 @@ static int hci_clear_adv_sets_sync(struct hci_dev *hdev, struct sock *sk) if (!ext_adv_capable(hdev)) return 0; + /* When adapter is off, remove adv without sending HCI commands */ + if (!hdev_is_powered(hdev)) { + hci_clear_ext_adv_ins_during_power_off(hdev, sk); + return 0; + } + /* Disable instance 0x00 to disable all instances */ err = hci_disable_ext_adv_instance_sync(hdev, 0x00); if (err) @@ -5177,9 +5210,27 @@ static int hci_disconnect_all_sync(struct hci_dev *hdev, u8 reason) return 0; } +static void hci_disable_ext_advertising_temporarily(struct hci_dev *hdev) +{ + struct adv_info *adv, *n; + + if (!ext_adv_capable(hdev)) + return; + + hci_dev_lock(hdev); + + list_for_each_entry_safe(adv, n, &hdev->adv_instances, list) + adv->enabled = false; + + hci_dev_clear_flag(hdev, HCI_LE_ADV); + + hci_dev_unlock(hdev); +} + /* This function perform power off HCI command sequence as follows: * - * Clear Advertising + * Disable Advertising Instances. Do not clear adv instances so advertising + * can be re-enabled on power on. * Stop Discovery * Disconnect all connections * hci_dev_close_sync @@ -5199,9 +5250,7 @@ static int hci_power_off_sync(struct hci_dev *hdev) return err; } - err = hci_clear_adv_sync(hdev, NULL, false); - if (err) - return err; + hci_disable_ext_advertising_temporarily(hdev); err = hci_stop_discovery_sync(hdev); if (err)