Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp2942275ybc; Thu, 21 Nov 2019 00:28:30 -0800 (PST) X-Google-Smtp-Source: APXvYqx/ezoUJtYvmBOM/aJo2O0rKKtwc9JyXlGPsUDAnoF8efzqFuipN0ouLWKKHfXOAkaMxepO X-Received: by 2002:a17:906:fad1:: with SMTP id lu17mr12247752ejb.24.1574324910532; Thu, 21 Nov 2019 00:28:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1574324910; cv=none; d=google.com; s=arc-20160816; b=fQM7OcLwls1cBj3a0Lr7zioxz2RH7UIjb8FIvAIRtRcjJIHslrUzGr4jm+XJc7j4tv kWoTICxOqYd48cM0967+lEgXL8oTYeE7fXLuDNxvHhrdKU1tNWLxEiqvXsyFMcPIvTxP f1JRf46+rXSOTMj13C1DR4tV0kcSrsRcLZoE2X12MLRI6J1j7chEQQbLdiT87gIvJFlM O5DtK6ul1O1c+XlvSK9unZJmPFxNS7pMRiVma4fCGi7FMaNs+oOUdcsNsX7/rwbSFZzs nusqG4395yYw6ouEVTuah4TaL4Uw7y+0XgDlmYiGy2Z13q9oy6c13aJRF+oxFnE6HvsX xsFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :message-id:date:subject:to:from; bh=c8KRB16OUddepNPFNdmFcNwKHDn9W1Q3GSA8XHOxgSM=; b=FtjYNc93//2tgwtS+wHDVHMl8bTGUJt83hrrKpyLbU5Z3V77LfbIav+0dA1bDYuDfw Phma2Ug8E5iwNZ+gSeTAgUgccUWN/U6/60s9bQhpLiLtM0EkNGg6KVF7EW1GcOR+SBCn ydWp6OzennB074CRwpjKqEJ4YFiWsuuP00awVyplKw0BA/FEbRjkrEaKyehqEeN/xw4G Fz1kbdFPij/5AG58hYC7/wmp0qdXCjOTkIDds7U3DZgiXOyPv26NF0rb5c6ZaialOHNP P+q5exqokxi6Iipxj8Uuy1/jcRl3eodsT4o3W3eJx08xRElDDgTylLpsm2uQlnATkaDn 36aw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id t19si1149279ejr.411.2019.11.21.00.28.04; Thu, 21 Nov 2019 00:28:30 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-bluetooth-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-bluetooth-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726132AbfKUI1l (ORCPT + 99 others); Thu, 21 Nov 2019 03:27:41 -0500 Received: from coyote.holtmann.net ([212.227.132.17]:40448 "EHLO mail.holtmann.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726165AbfKUI1l (ORCPT ); Thu, 21 Nov 2019 03:27:41 -0500 Received: from localhost.localdomain (tmo-101-191.customers.d1-online.com [80.187.101.191]) by mail.holtmann.org (Postfix) with ESMTPSA id 6BC55CED0F for ; Thu, 21 Nov 2019 09:36:47 +0100 (CET) From: Marcel Holtmann To: linux-bluetooth@vger.kernel.org Subject: [PATCH 2/2] Bluetooth: Allow combination of BDADDR_PROPERTY and INVALID_BDADDR quirks Date: Thu, 21 Nov 2019 08:51:30 +0100 Message-Id: <20191121075130.92705-2-marcel@holtmann.org> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-bluetooth-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-bluetooth@vger.kernel.org When utilizing BDADDR_PROPERTY and INVALID_BDADDR quirks together it results in an unconfigured controller even if the bootloader provides a valid address. Fix this by allowing a bootloader provided address to mark the controller as configured. Signed-off-by: Marcel Holtmann --- net/bluetooth/hci_core.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/net/bluetooth/hci_core.c b/net/bluetooth/hci_core.c index c957f0611f74..6039105c96c0 100644 --- a/net/bluetooth/hci_core.c +++ b/net/bluetooth/hci_core.c @@ -1444,6 +1444,8 @@ static int hci_dev_do_open(struct hci_dev *hdev) if (hci_dev_test_flag(hdev, HCI_SETUP) || test_bit(HCI_QUIRK_NON_PERSISTENT_SETUP, &hdev->quirks)) { + bool invalid_bdaddr; + hci_sock_dev_event(hdev, HCI_DEV_SETUP); if (hdev->setup) { @@ -1452,25 +1454,45 @@ static int hci_dev_do_open(struct hci_dev *hdev) goto setup_failed; } + /* The transport driver can set the quirk to mark the + * BD_ADDR invalid before creating the HCI device or in + * its setup callback. + */ + invalid_bdaddr = test_bit(HCI_QUIRK_INVALID_BDADDR, + &hdev->quirks); + if (test_bit(HCI_QUIRK_USE_BDADDR_PROPERTY, &hdev->quirks)) { if (!bacmp(&hdev->public_addr, BDADDR_ANY)) hci_dev_get_bd_addr_from_property(hdev); if (bacmp(&hdev->public_addr, BDADDR_ANY) && - hdev->set_bdaddr) + hdev->set_bdaddr) { ret = hdev->set_bdaddr(hdev, &hdev->public_addr); + + /* If setting of the BD_ADDR from the device + * property succeeds, then treat the address + * as valid even if the invalid BD_ADDR + * quirk indicates otherwise. + */ + if (!ret) + invalid_bdaddr = false; + } } setup_failed: /* The transport driver can set these quirks before * creating the HCI device or in its setup callback. * + * For the invalid BD_ADDR quirk it is possible that + * it becomes a valid address if the bootloader does + * provide it (see above). + * * In case any of them is set, the controller has to * start up as unconfigured. */ if (test_bit(HCI_QUIRK_EXTERNAL_CONFIG, &hdev->quirks) || - test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks)) + invalid_bdaddr) hci_dev_set_flag(hdev, HCI_UNCONFIGURED); /* For an unconfigured controller it is required to -- 2.23.0