Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp1936165lqp; Tue, 16 Apr 2024 02:17:22 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWk2jtXsGiu58mReWLF3MHNZEcX4cOc8tDHWsJkXlSphX9kRzpo0SC2C9L6gXrNjIBPmpJ+0T8N1am/1QekVpjJMfrwxnYTnTtwfn0gqQ== X-Google-Smtp-Source: AGHT+IH5Ggnye96faTn71KlrL8GIQrw78TCgpAD2y3Xu21xxz+rH9I/lcqlkDKURZ3KCiVCiYGHr X-Received: by 2002:a05:6830:6f8f:b0:6eb:8435:6d with SMTP id eg15-20020a0568306f8f00b006eb8435006dmr5403116otb.16.1713259042494; Tue, 16 Apr 2024 02:17:22 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1713259042; cv=pass; d=google.com; s=arc-20160816; b=d+ionTp3ueovwkRoxIb1oheSzdL4iy6eC/lmwME3FOKHn4ruzgrpUjH52sYJs0CIb+ Tj1bvruZp/k4Bw2lMcwgdudIAt9tc9htTtu6ciLxTdF429S8kguqUQwBzcCEr1ZuWqYX HcRZs033HLKtRLqaYmkRcu3SO89K5Ys6nONRHjv6BDeFQXr+Y3kKFjXcqkB/a/pH9KXk E++rGl60csM+tzK0HCpazt6qXlHxMDJILmNLC7WOnZ1povR8MDdbZWpvLrfLMPZmjcbU IoOI1xAx8aX4it1U35os9SXEXzSOAQ+FNnFy/jjOJ9Pv9gohNFay6f18Y5y5BV+URHo+ I9ow== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:message-id:date:subject:cc:to :from:dkim-signature; bh=f0HkVGO3LQ/bTm+bKGKvEJ3aIFGqYP8+4lXZaitKLfY=; fh=UVZM1H1TcGbvP7MD2+RCqXGE+/++byzpd6aiLlQ8bd8=; b=XmMWyl/RgIKm3nqBXuuvEA5ZOdD2K8epCTVQROL6GGuD4q2pm8VPpBZD0o043MVszG sAqdl98u8FOyxEIzeRkocgJtw8ldl6XZ6KKehEl7jA7fusUIhSFtqrytUGw896YNqUtl 4mM2QFWMQFR1pMno5ReGh3UuXZfXj/pGfRcRVEEsQjpHLpGwB81Hz4ipIdo3gt/g1Pmk 55AJ98p6xJFgF+lZYvwU7qy/1XFoBgYcDH0JPi3a19kM9VzFZHYgF+s6ujOX9ZB6RGvJ aCbIwIngMqiHUBq5OijD+y3KJhwMwbEG1Va0P3KjNrLRSIE1aWxgRP4q2ITt5x9at6eq /7bw==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kr55DqIc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-bluetooth+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id i7-20020a636d07000000b005e83b6752bdsi9447943pgc.269.2024.04.16.02.17.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 16 Apr 2024 02:17:22 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-bluetooth+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=kr55DqIc; arc=pass (i=1 dkim=pass dkdomain=kernel.org); spf=pass (google.com: domain of linux-bluetooth+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-bluetooth+bounces-3613-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by sv.mirrors.kernel.org (Postfix) with ESMTPS id D42FE286347 for ; Tue, 16 Apr 2024 09:17:09 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C5A38528D; Tue, 16 Apr 2024 09:16:59 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b="kr55DqIc" X-Original-To: linux-bluetooth@vger.kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 698C684E0A; Tue, 16 Apr 2024 09:16:58 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713259018; cv=none; b=YY0yCf1o7PAqKAn5Hxztj2zViDyVScL+AGYDuA0RCXkygg5UMw8fheFO33R0+e5+cC5dlb14lZmbXiDWWCSVCYZ/ZsR+lRUrhNJ8b92RuSQUdUGl8E0oW1WkrJpwtDY9P1jbg0/IcWejL3FCRZAAneM2kS0OLkW1/6pqfeukoNU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1713259018; c=relaxed/simple; bh=Et/xGVRO67Io7N9eFsHAPc1PlNaNznIJ/8e09IRteZI=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bMup2jcnQj9kfUqOmLeisnapjzVAkQzTWxCg0OGDvwoh8CgZd8gl94kgJWyRovK6mgXdFYRyIQ7wuk1UF8ez6Lhw02E/MOTNEdJ2xnaUWmsKVuXWeyKp1CXuwSKQwBSFn8UJyDvu9nwCC2d76ERfpWavbTui12V87rZHbzbdEZA= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.b=kr55DqIc; arc=none smtp.client-ip=10.30.226.201 Received: by smtp.kernel.org (Postfix) with ESMTPSA id ED8FAC113CE; Tue, 16 Apr 2024 09:16:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1713259018; bh=Et/xGVRO67Io7N9eFsHAPc1PlNaNznIJ/8e09IRteZI=; h=From:To:Cc:Subject:Date:From; b=kr55DqIcHpqG3Al2mrRmGyIOmA4znqmdkhqdJdezTxhEHudatB8Ikl7Y+j+jJMtzo zi7LAgPZuwxs7XbFlmWgr+8l1vcKHyrnC3yfCs8gsBkge8aHl64dg37Rdm6wXdeYVN Jp7rXByi6LJHd3qaR7H5e8DK5Wwv8y0PhsW5VQaHyurV4utsW/u6tJdWKXS6xa4mf8 JzzUXmg7dN9kiIBhrAfoNhClXOyOQ61ZW44vj94JwOxljoM+TNmesGkbBoX3pstXMO MC+zdMNU4KKca8c0X2cFDZU8Sxph5ax53S6jFbMMm+sJUFWJuMvMb0olo5EZkdmzbV +x3sf90R5CNQg== Received: from johan by xi.lan with local (Exim 4.97.1) (envelope-from ) id 1rwevu-000000005EL-3yOS; Tue, 16 Apr 2024 11:16:55 +0200 From: Johan Hovold To: Marcel Holtmann , Luiz Augusto von Dentz Cc: Matthias Kaehlcke , Doug Anderson , linux-bluetooth@vger.kernel.org, linux-kernel@vger.kernel.org, Johan Hovold , Janaki Ramaiah Thota , stable@vger.kernel.org Subject: [PATCH] Bluetooth: qca: fix invalid device address check Date: Tue, 16 Apr 2024 11:15:09 +0200 Message-ID: <20240416091509.19995-1-johan+linaro@kernel.org> X-Mailer: git-send-email 2.43.2 Precedence: bulk X-Mailing-List: linux-bluetooth@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Qualcomm Bluetooth controllers may not have been provisioned with a valid device address and instead end up using the default address 00:00:00:00:5a:ad. This was previously believed to be due to lack of persistent storage for the address but it may also be due to integrators opting to not use the on-chip OTP memory and instead store the address elsewhere (e.g. in storage managed by secure world firmware). According to Qualcomm, at least WCN6750, WCN6855 and WCN7850 have on-chip OTP storage for the address. As the device type alone cannot be used to determine when the address is valid, instead read back the address during setup() and only set the HCI_QUIRK_USE_BDADDR_PROPERTY flag when needed. This specifically makes sure that controllers that have been provisioned with an address do not start as unconfigured. Reported-by: Janaki Ramaiah Thota Link: https://lore.kernel.org/r/124a7d54-5a18-4be7-9a76-a12017f6cce5@quicinc.com/ Fixes: 5971752de44c ("Bluetooth: hci_qca: Set HCI_QUIRK_USE_BDADDR_PROPERTY for wcn3990") Fixes: e668eb1e1578 ("Bluetooth: hci_core: Don't stop BT if the BD address missing in dts") Fixes: 6945795bc81a ("Bluetooth: fix use-bdaddr-property quirk") Cc: stable@vger.kernel.org # 6.5 Cc: Matthias Kaehlcke Signed-off-by: Johan Hovold --- drivers/bluetooth/btqca.c | 38 +++++++++++++++++++++++++++++++++++++ drivers/bluetooth/hci_qca.c | 2 -- 2 files changed, 38 insertions(+), 2 deletions(-) Matthias and Doug, As Chromium is the only known user of the 'local-bd-address' property, could you please confirm that your controllers use the 00:00:00:00:5a:ad address by default so that the quirk continues to be set as intended? Johan diff --git a/drivers/bluetooth/btqca.c b/drivers/bluetooth/btqca.c index 19cfc342fc7b..216826c31ee3 100644 --- a/drivers/bluetooth/btqca.c +++ b/drivers/bluetooth/btqca.c @@ -15,6 +15,8 @@ #define VERSION "0.1" +#define QCA_BDADDR_DEFAULT (&(bdaddr_t) {{ 0xad, 0x5a, 0x00, 0x00, 0x00, 0x00 }}) + int qca_read_soc_version(struct hci_dev *hdev, struct qca_btsoc_version *ver, enum qca_btsoc_type soc_type) { @@ -612,6 +614,38 @@ int qca_set_bdaddr_rome(struct hci_dev *hdev, const bdaddr_t *bdaddr) } EXPORT_SYMBOL_GPL(qca_set_bdaddr_rome); +static int qca_check_bdaddr(struct hci_dev *hdev) +{ + struct hci_rp_read_bd_addr *bda; + struct sk_buff *skb; + int err; + + if (bacmp(&hdev->public_addr, BDADDR_ANY)) + return 0; + + skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL, + HCI_INIT_TIMEOUT); + if (IS_ERR(skb)) { + err = PTR_ERR(skb); + bt_dev_err(hdev, "Failed to read device address (%d)", err); + return err; + } + + if (skb->len != sizeof(*bda)) { + bt_dev_err(hdev, "Device address length mismatch"); + kfree_skb(skb); + return -EIO; + } + + bda = (struct hci_rp_read_bd_addr *)skb->data; + if (!bacmp(&bda->bdaddr, QCA_BDADDR_DEFAULT)) + set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); + + kfree_skb(skb); + + return 0; +} + static void qca_generate_hsp_nvm_name(char *fwname, size_t max_size, struct qca_btsoc_version ver, u8 rom_ver, u16 bid) { @@ -818,6 +852,10 @@ int qca_uart_setup(struct hci_dev *hdev, uint8_t baudrate, break; } + err = qca_check_bdaddr(hdev); + if (err) + return err; + bt_dev_info(hdev, "QCA setup on UART is completed"); return 0; diff --git a/drivers/bluetooth/hci_qca.c b/drivers/bluetooth/hci_qca.c index ecbc52eaf101..92fa20f5ac7d 100644 --- a/drivers/bluetooth/hci_qca.c +++ b/drivers/bluetooth/hci_qca.c @@ -1905,8 +1905,6 @@ static int qca_setup(struct hci_uart *hu) case QCA_WCN6750: case QCA_WCN6855: case QCA_WCN7850: - set_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks); - qcadev = serdev_device_get_drvdata(hu->serdev); if (qcadev->bdaddr_property_broken) set_bit(HCI_QUIRK_BDADDR_PROPERTY_BROKEN, &hdev->quirks); -- 2.43.2