Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 304C6C54EED for ; Wed, 25 Jan 2023 21:12:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S236318AbjAYVMo (ORCPT ); Wed, 25 Jan 2023 16:12:44 -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-Google-Smtp-Source: AK7set/jBOwnX0/QoX7ixwv9e2pNPa64RC5YCboTV73zgRZKUW3KNBAU33alOxNSlCaoaeo/b2tuD9s294fU 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 Content-Type: text/plain; charset="UTF-8" Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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) -- 2.39.1.456.gfc5497dd1b-goog