Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1226320rwr; Wed, 26 Apr 2023 11:45:08 -0700 (PDT) X-Google-Smtp-Source: AKy350aYw53xwr95pnaSF+c+Q29lbKZYP+BqfZGfSH6UIbnuwzVm2QalqMqvT2/ajxES57akCX1a X-Received: by 2002:a05:6a00:21cf:b0:627:f0e1:4fbf with SMTP id t15-20020a056a0021cf00b00627f0e14fbfmr32998248pfj.33.1682534707762; Wed, 26 Apr 2023 11:45:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682534707; cv=none; d=google.com; s=arc-20160816; b=JiXNB/wlCaJ57pQ6+WAN/N5sY5SojauFcSkPo4v5aDC3Cvmf/Ez3CimQ2MFg3SXgDM 1LBIXD7xHsITwSoPvWFo20I41xrB5RRPg4k9Ru2Q89yjhP6HQus/48XrCWzN+n9jGcgv RKt4LvfPt268nxcVnWg7/8RoQkRpTwDZmvZzd7eUhSni9AxO2xWZXJGEHEIEkyKMGM3A CkGBMWqJE7JXwWgjf31K+KgooPRJq9681puebYdxbJ5RZiAtDeUApTbUXz1tHYG3X+gg Z94ZLD6Al87hJxTZjrmEvJXxoHylJY5CWjNM1dqRA40GVUgwRypf1L/kX0a9Hir4dTTV kbKw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=zL8eawPHCEGdqDFy/1gKXaFSyh+OEr3QsrolSnWTRmo=; b=h7lwM/e5D1sU3t8nQfSoUD19OrwDHmLH1GqghadDGZ8KTiqa54ji1lIxMFqx07Wz/j Aj4NFz+affpHK8m9rV2UcNqiWL1WmIbF6Qg0lOWattG04WhUjGNw7KSXWkAnDNlOPd4Q ajVpAKInDcT9J6vxbVWDm7OgVF7phYjeGOu9tFzYM4KK7IgFFhuuAihJsiByUFPWzBot sAb0/B058H5KDcjk8yU3ox7LssQDFDU7y8BnZATqaIdPXfPi7E2du019zYSnO76+znOJ R7uQ96cj8psLAJA7iu0iWPl4P5t58dtwiM48s+Ywy4FURxTM6o/1641CYMrfHa5Ri/hj duQg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b="TFN38/TQ"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z2-20020aa79902000000b0063d33dc49e8si16508096pff.363.2023.04.26.11.44.55; Wed, 26 Apr 2023 11:45:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth-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=@gmail.com header.s=20221208 header.b="TFN38/TQ"; spf=pass (google.com: domain of linux-bluetooth-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231377AbjDZSko (ORCPT + 99 others); Wed, 26 Apr 2023 14:40:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54932 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233980AbjDZSkn (ORCPT ); Wed, 26 Apr 2023 14:40:43 -0400 Received: from mail-ot1-x32a.google.com (mail-ot1-x32a.google.com [IPv6:2607:f8b0:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F3484173C for ; Wed, 26 Apr 2023 11:40:41 -0700 (PDT) Received: by mail-ot1-x32a.google.com with SMTP id 46e09a7af769-6a5f9c1200eso2947668a34.1 for ; Wed, 26 Apr 2023 11:40:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1682534441; x=1685126441; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=zL8eawPHCEGdqDFy/1gKXaFSyh+OEr3QsrolSnWTRmo=; b=TFN38/TQsztyMqmpfE8uGcXgrX8fbiY7aNc6RhDsywE44TSQNomnJbbYkSsPQzpvVd YJN/q5I/nsjseTzwtYAHDARnBa/KV5DZe1v+CJJ3wMU3A7u+yv0Z3FjV0KNlNqvy7EnX RDN3jtX6bejHtw0bpiJc419OjDjc13Ci0DDyZNlg/uwhAlpArfvK5BMKXNOqHgAKyNDh +z2rcomDCCXbE3ubyVP0mMYzYAbPcDCDnhyhPa4DxE9W6re497rQozAhNTYBHOPhdu2i gLYUVqn2K/Ee3NhT7PEo29lnQtpHcoQjuVXmBwMu8mCXNCLgJ9WHA/PpH/UuZUPGNGja u74A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1682534441; x=1685126441; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=zL8eawPHCEGdqDFy/1gKXaFSyh+OEr3QsrolSnWTRmo=; b=jO1pzQIByjvEjcOHzt9x7dVAGTgxEf94Iwh9dwe4mgV7Os7t0tmD4cJdjvaEcJ7D6w VRAd9VyO0iUgDAC2wBnD6BHMeJIyzkzpNCP5MmB8RvTEAs380oOvL1107iPm6U/qCg7k Vi3AnCJ/vGGW0hzJBs6TEXQFRb+IGef1AjmVfvfpbJpnTzlJOuyQrOVTAbgm7qj0zVvL 2ZidWqcDgYqwl3Zjv8IMSkgHJZ+DNhj3BJtTizzlEblx4TkBL4ZLeNNpMXqA/po43dPA xtZUZKoSDtR+ZR04YVKVfLU09BOdTRhWB8Bog7A0faCgIUpAuyjd940yfzd3xweFAZrp 9fSw== X-Gm-Message-State: AC+VfDwXSLRatmYmbqzFo2t3yTCIRey24LGSGrr2X7N3C31k5VXiSkT4 ucuO4CEumzIyipqr6dRcoH6Ecms+jqFvvqUz X-Received: by 2002:a05:6808:5c3:b0:390:77fa:1fce with SMTP id d3-20020a05680805c300b0039077fa1fcemr767903oij.40.1682534440255; Wed, 26 Apr 2023 11:40:40 -0700 (PDT) Received: from localhost.localdomain ([2804:14c:f429:2d04:9d9f:c9a0:8ef:bc50]) by smtp.gmail.com with ESMTPSA id p129-20020acabf87000000b00383cc29d6b2sm6906329oif.51.2023.04.26.11.40.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 26 Apr 2023 11:40:39 -0700 (PDT) From: Raul Cheleguini To: linux-bluetooth@vger.kernel.org Cc: marcel@holtmann.org, johan.hedberg@gmail.com, luiz.dentz@gmail.com, Raul Cheleguini Subject: [PATCH v2] Bluetooth: Fix unexpected SMP command errors for ATS2851 Date: Wed, 26 Apr 2023 15:40:17 -0300 Message-Id: <20230426184017.2051211-1-raul.cheleguini@gmail.com> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE, URIBL_BLOCKED autolearn=ham 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-bluetooth@vger.kernel.org Fix unexpected SMP 0x08 and 0x09 command errors when connecting and pairing devices using ATS2851 based controllers. The errors are a result of a race condition in which the host receives the commands (without prior authorization by SMP functions) in the moment host is sending WRITE_AUTH_PAYLOAD_TIMEOUT command. In such a situation, a disconnect event occurs, and the device cannot connect or pair. To address this issue, we add a condition that skips the WRITE_AUTH_PAYLOAD_TIMEOUT command for ATS2851, enabling the SMP functions to prepare for commands 0x08 and 0x09 in a timely manner. Signed-off-by: Raul Cheleguini --- V1 -> V2: Fix typo in commit message. - Note that this patch depends on the broken extended create connection quirk sent in [1]. [1]. https://marc.info/?l=linux-bluetooth&m=168244024503639&w=2 drivers/bluetooth/btusb.c | 1 + include/net/bluetooth/hci.h | 7 +++++++ net/bluetooth/hci_event.c | 7 +++++++ net/bluetooth/hci_sync.c | 5 ++++- 4 files changed, 19 insertions(+), 1 deletion(-) diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c index 1cf104feaf85..972ca94de6de 100644 --- a/drivers/bluetooth/btusb.c +++ b/drivers/bluetooth/btusb.c @@ -4374,6 +4374,7 @@ static int btusb_probe(struct usb_interface *intf, set_bit(HCI_QUIRK_BROKEN_SET_RPA_TIMEOUT, &hdev->quirks); set_bit(HCI_QUIRK_BROKEN_EXT_SCAN, &hdev->quirks); set_bit(HCI_QUIRK_BROKEN_EXT_CREATE_CONN, &hdev->quirks); + set_bit(HCI_QUIRK_BROKEN_WRITE_AUTH_PAYLOAD_TIMEOUT, &hdev->quirks); } if (!reset) diff --git a/include/net/bluetooth/hci.h b/include/net/bluetooth/hci.h index d5d0e44bf0b6..625c100a74ad 100644 --- a/include/net/bluetooth/hci.h +++ b/include/net/bluetooth/hci.h @@ -316,6 +316,13 @@ enum { * based controllers, which erroneously claims to support it. */ HCI_QUIRK_BROKEN_EXT_CREATE_CONN, + + /* + * When this quirk is set, the command WRITE_AUTH_PAYLOAD_TIMEOUT is + * skipped. This is required for the Actions Semiconductor ATS2851 + * based controllers, due to a race condition in pairing process. + */ + HCI_QUIRK_BROKEN_WRITE_AUTH_PAYLOAD_TIMEOUT, }; /* HCI device flags */ diff --git a/net/bluetooth/hci_event.c b/net/bluetooth/hci_event.c index d00ef6e3fc45..2077a7c921f1 100644 --- a/net/bluetooth/hci_event.c +++ b/net/bluetooth/hci_event.c @@ -3655,6 +3655,13 @@ static void hci_encrypt_change_evt(struct hci_dev *hdev, void *data, goto unlock; } + /* We skip the WRITE_AUTH_PAYLOAD_TIMEOUT for ATS2851 based controllers + * to avoid unexpected SMP command errors when pairing. + */ + if (test_bit(HCI_QUIRK_BROKEN_WRITE_AUTH_PAYLOAD_TIMEOUT, + &hdev->quirks)) + goto notify; + /* Set the default Authenticated Payload Timeout after * an LE Link is established. As per Core Spec v5.0, Vol 2, Part B * Section 3.3, the HCI command WRITE_AUTH_PAYLOAD_TIMEOUT should be diff --git a/net/bluetooth/hci_sync.c b/net/bluetooth/hci_sync.c index 26ab4deb6d52..ecd18c611122 100644 --- a/net/bluetooth/hci_sync.c +++ b/net/bluetooth/hci_sync.c @@ -4581,7 +4581,10 @@ static const struct { "advertised, but not supported."), HCI_QUIRK_BROKEN(EXT_CREATE_CONN, "HCI LE Extended Create Connection command is " - "advertised, but not supported.") + "advertised, but not supported."), + HCI_QUIRK_BROKEN(WRITE_AUTH_PAYLOAD_TIMEOUT, + "HCI WRITE AUTH PAYLOAD TIMEOUT command leads " + "to unexpected SMP errors when pairing.") }; /* This function handles hdev setup stage: -- 2.39.2