From patchwork Wed Nov 3 05:33:14 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12600129 X-Patchwork-Delegate: kuba@kernel.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CA3F9C433FE for ; Wed, 3 Nov 2021 05:33:27 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A62546109F for ; Wed, 3 Nov 2021 05:33:27 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230382AbhKCFgA (ORCPT ); Wed, 3 Nov 2021 01:36:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48988 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229650AbhKCFf7 (ORCPT ); Wed, 3 Nov 2021 01:35:59 -0400 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 BDDC8C061714 for ; Tue, 2 Nov 2021 22:33:23 -0700 (PDT) Received: by mail-yb1-xb49.google.com with SMTP id b15-20020a25ae8f000000b005c20f367790so2634968ybj.2 for ; Tue, 02 Nov 2021 22:33:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:message-id:mime-version:subject:from:to:cc; bh=xs0T0WVw07avkfyokmmkdCQmH6GIfXLpMlnt8tnR1gM=; b=YEa6S5jxUvaRXnXk6KYLcnE93FShL1ZE72b/FVSD34hL3j8YB4vC9QiWItu9YAS+yS mcQiPv56PH0TVoAgfZkApROCJVL1O2RrJah4Y2uVt1YD5Ye/dh8I16FxdTrhPxvDVJAN VNs6s47NqqPhQPUzNkvteUFgRZ1Tw4bYYkSIs8CP8X/AqGsOjypIuc+Sq4MgsY2owWGp csYCpv1qhV81L+6UZWFZE9uNElVtHXpk/Wnk/7DVf5yfVE+/FjY8o1+5eC56sRu+AaAi 1UBI9Ic8EBg7b5HstspzA4GHwZVEI3/fAmz2jVGRyp2zGB1cB8pUEeHdPstvegT33AGS uLuw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:message-id:mime-version:subject:from:to:cc; bh=xs0T0WVw07avkfyokmmkdCQmH6GIfXLpMlnt8tnR1gM=; b=LQi84R6dsBTuqJN8g+UV/qxKyqORt2vSxJYj9g2uOLjr8E9hUz2AYFHBb0ePrstqsW /yEed24mCYWrQ91rJQ+C5wDDz63Bq4E5+ebOCnTDK6F1YH4JjkHXy8moaHdmpno2Q2dh rdrN17DI09YPz9MZpX/t1sTZTM22aO+sdsHlhksCKN2w3EQXH7aNRMOK0tZH3oyyFRS1 SFm0zZdDoXIB24RA18c8qztEbqfBUqpVXDM+EpeXmKhn5e+d4rJZnsfmk4bGpkj/E+BN 3h6FEn9fpbIk4Hl477Y/bSPZM8zMelOEEYmvp/+eRugHClOzPs1bk/HF+u6OcED3QjTh dfVA== X-Gm-Message-State: AOAM532KPKhHk7OtiRBM4og2x6UFmRahSwaOcdLejybPDy/KOsap4fBV Mgf0owCSj8Oppo1Qn4Mw6i7sUJeCa7Vd X-Google-Smtp-Source: ABdhPJwSvjB5cPYxJxzN/oBjy/POAcp2ZMLNYY9yCfCgcipAK6CWpatsZlfm0N6cRGHW3xDfEvyYuIQ7KhpX X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:7af7:a937:5810:b542]) (user=apusaka job=sendgmr) by 2002:a25:d6c6:: with SMTP id n189mr22646041ybg.272.1635917602348; Tue, 02 Nov 2021 22:33:22 -0700 (PDT) Date: Wed, 3 Nov 2021 13:33:14 +0800 Message-Id: <20211103133225.v2.1.I3ba1a76d72da5a813cf6e6f219838c9ef28c5eaa@changeid> Mime-Version: 1.0 X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH v2 1/2] Bluetooth: Ignore HCI_ERROR_CANCELLED_BY_HOST on adv set terminated event From: Archie Pusaka To: linux-bluetooth , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , "David S. Miller" , Jakub Kicinski , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Archie Pusaka This event is received when the controller stops advertising, specifically for these three reasons: (a) Connection is successfully created (success). (b) Timeout is reached (error). (c) Number of advertising events is reached (error). (*) This event is NOT generated when the host stops the advertisement. Refer to the BT spec ver 5.3 vol 4 part E sec 7.7.65.18. Note that the section was revised from BT spec ver 5.0 vol 2 part E sec 7.7.65.18 which was ambiguous about (*). Some chips (e.g. RTL8822CE) send this event when the host stops the advertisement with status = HCI_ERROR_CANCELLED_BY_HOST (due to (*) above). This is treated as an error and the advertisement will be removed and userspace will be informed via MGMT event. On suspend, we are supposed to temporarily disable advertisements, and continue advertising on resume. However, due to the behavior above, the advertisements are removed instead. This patch returns early if HCI_ERROR_CANCELLED_BY_HOST is received. Btmon snippet of the unexpected behavior: @ MGMT Command: Remove Advertising (0x003f) plen 1 Instance: 1 < HCI Command: LE Set Extended Advertising Enable (0x08|0x0039) plen 6 Extended advertising: Disabled (0x00) Number of sets: 1 (0x01) Entry 0 Handle: 0x01 Duration: 0 ms (0x00) Max ext adv events: 0 > HCI Event: LE Meta Event (0x3e) plen 6 LE Advertising Set Terminated (0x12) Status: Operation Cancelled by Host (0x44) Handle: 1 Connection handle: 0 Number of completed extended advertising events: 5 > HCI Event: Command Complete (0x0e) plen 4 LE Set Extended Advertising Enable (0x08|0x0039) ncmd 2 Status: Success (0x00) Signed-off-by: Archie Pusaka --- Changes in v2: * Split clearing HCI_LE_ADV into its own patch * Reword comments include/net/bluetooth/hci.h | 1 + net/bluetooth/hci_event.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index 63065bc01b76..84db6b275231 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -566,6 +566,7 @@ enum { #define HCI_ERROR_INVALID_LL_PARAMS 0x1e #define HCI_ERROR_UNSPECIFIED 0x1f #define HCI_ERROR_ADVERTISING_TIMEOUT 0x3c +#define HCI_ERROR_CANCELLED_BY_HOST 0x44 /* Flow control modes */ #define HCI_FLOW_CTL_MODE_PACKET_BASED 0x00 diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index d4b75a6cfeee..7d875927c48b 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -5538,6 +5538,18 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb) adv = hci_find_adv_instance(hdev, ev->handle); + /* The Bluetooth Core 5.3 specification clearly states that this event + * shall not be sent when the Host disables the advertising set. So in + * case of HCI_ERROR_CANCELLED_BY_HOST, just ignore the event. + * + * When the Host disables an advertising set, all cleanup is done via + * its command callback and not needed to be duplicated here. + */ + if (ev->status == HCI_ERROR_CANCELLED_BY_HOST) { + bt_dev_warn_ratelimited(hdev, "Unexpected advertising set terminated event"); + return; + } + if (ev->status) { if (!adv) return; From patchwork Wed Nov 3 05:33:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Archie Pusaka X-Patchwork-Id: 12600131 X-Patchwork-Delegate: kuba@kernel.org 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 mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9F0E4C433EF for ; Wed, 3 Nov 2021 05:33:36 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 809336109F for ; Wed, 3 Nov 2021 05:33:36 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230516AbhKCFgJ (ORCPT ); Wed, 3 Nov 2021 01:36:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49020 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230471AbhKCFgF (ORCPT ); Wed, 3 Nov 2021 01:36:05 -0400 Received: from mail-yb1-xb4a.google.com (mail-yb1-xb4a.google.com [IPv6:2607:f8b0:4864:20::b4a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BB54BC061205 for ; Tue, 2 Nov 2021 22:33:29 -0700 (PDT) Received: by mail-yb1-xb4a.google.com with SMTP id v133-20020a25c58b000000b005c20153475dso2531573ybe.17 for ; Tue, 02 Nov 2021 22:33:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20210112; h=date:in-reply-to:message-id:mime-version:references:subject:from:to :cc; bh=4wxVF/UA81bHWpJF1BL34JMLRn0mSFTIFUNKVwG9QEw=; b=Ihx+IrzfR2aW4Ou0bbTr4U5Qrc6b3DU33j64hUzTZbKmXBZb7VIJtx0FIrIyhDWqlG IEw0ijFDvKCgKMHPtyc5DysiVhYAHqDkIE7Yf7QaC5fg2QCg4VkjYhYTFX7u7GvzM4Wd SM0KsvnTRNolYrWnmJ1EEGebyu9VcwzlZBWFcX4kF4590eGElny1s3tetr5boLe6BZvz 5DnjaTYkYrnocu5f70QxcVG9Dus42cfuwz1975+U8t/DgQw/fQqxhghILBscIHLZlCQU eVfCS36EEKQZ0x0BjLjZsh+mUaDnvDEINbkOO4grMpATgEkSTBw7KmFUHfKkaIwQDN+3 0sQQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:in-reply-to:message-id:mime-version :references:subject:from:to:cc; bh=4wxVF/UA81bHWpJF1BL34JMLRn0mSFTIFUNKVwG9QEw=; b=pw2OwdbikERVMVB/+GYC6B3N5LGuRqlWokp2w24JGqYuO4maYjgjuphxozJz/X1aMU zoPI6SCM/hSOtW9+5VRjKSGalTTIAG06PkyK5NbXK+TCj3R826FAlCtgB03f0B1ww4WF /gmfTgKu/8o7FbIGETK9IjjsAQ3zuoKDboSA2FWxaR8qr4UxsGfpT7N+LS7Iov2zRBLz DuhN4+aRtCkTBHi1N3GkrcY4Og+neQQNQ/aBOlzgzg6X5JbtUn3XQEFhyBaU73SerVSz XWZY50IXJ8p/207pdcdJ56YlWKbQmFKb1QWixjSomhN/pMOk+JFxsabfJIg88yk833ej vASw== X-Gm-Message-State: AOAM532VktctHHQQACTwoM2pdwCgA6MQO2b58lsgP8ZVZRSYAtu3haza sWzLIYXyTRPbrxWO47GLIYhMwI8dJSv0 X-Google-Smtp-Source: ABdhPJyxMd+VMAKgNb3yje1nfRoE5XJsNYWwKr2u4DrGOxfpm6OJpKMkQz3gmxEIkptTp0PoU/Yuud9UeefO X-Received: from apusaka-p920.tpe.corp.google.com ([2401:fa00:1:10:7af7:a937:5810:b542]) (user=apusaka job=sendgmr) by 2002:a25:7146:: with SMTP id m67mr45521192ybc.353.1635917608988; Tue, 02 Nov 2021 22:33:28 -0700 (PDT) Date: Wed, 3 Nov 2021 13:33:15 +0800 In-Reply-To: <20211103133225.v2.1.I3ba1a76d72da5a813cf6e6f219838c9ef28c5eaa@changeid> Message-Id: <20211103133225.v2.2.I4e34d9e5fdd7515aa15d0ee2ef94d57dcb48a927@changeid> Mime-Version: 1.0 References: <20211103133225.v2.1.I3ba1a76d72da5a813cf6e6f219838c9ef28c5eaa@changeid> X-Mailer: git-send-email 2.33.1.1089.g2158813163f-goog Subject: [PATCH v2 2/2] Bluetooth: Attempt to clear HCI_LE_ADV on adv set terminated error event From: Archie Pusaka To: linux-bluetooth , Marcel Holtmann Cc: CrosBT Upstreaming , Archie Pusaka , "David S. Miller" , Jakub Kicinski , Johan Hedberg , Luiz Augusto von Dentz , linux-kernel@vger.kernel.org, netdev@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org X-Patchwork-Delegate: kuba@kernel.org From: Archie Pusaka We should clear the flag if the adv instance removed due to receiving this error status is the last one we have. Signed-off-by: Archie Pusaka --- (no changes since v1) net/bluetooth/hci_event.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index 7d875927c48b..d3478cdfd009 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -5558,6 +5558,10 @@ static void hci_le_ext_adv_term_evt(struct hci_dev *hdev, struct sk_buff *skb) hci_remove_adv_instance(hdev, ev->handle); mgmt_advertising_removed(NULL, hdev, ev->handle); + /* If we are no longer advertising, clear HCI_LE_ADV */ + if (list_empty(&hdev->adv_instances)) + hci_dev_clear_flag(hdev, HCI_LE_ADV); + return; }