Skip to content

Commit 89bc22d

Browse files
holtmannjhedberg
authored andcommitted
Bluetooth: Add quirk for invalid controller address setting
When a Bluetooth controller does not have a valid public Bluetooth address, then allow the driver to indicate this. If the quirk is set, the Bluetooth core will switch to unconfigured state first and will allow userspace to configure the address before starting the full initialization of the controller. Signed-off-by: Marcel Holtmann <marcel@holtmann.org> Signed-off-by: Johan Hedberg <johan.hedberg@intel.com>
1 parent 118305b commit 89bc22d

3 files changed

Lines changed: 32 additions & 5 deletions

File tree

‎include/net/bluetooth/hci.h‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,16 @@ enum {
110110
* This quirk must be set before hci_register_dev is called.
111111
*/
112112
HCI_QUIRK_BROKEN_STORED_LINK_KEY,
113+
114+
/* When this quirk is set, the public Bluetooth address
115+
* initially reported by HCI Read BD Address command
116+
* is considered invalid. Controller configuration is
117+
* required before this device can be used.
118+
*
119+
* This quirk can be set before hci_register_dev is called or
120+
* during the hdev->setup vendor callback.
121+
*/
122+
HCI_QUIRK_INVALID_BDADDR,
113123
};
114124

115125
/* HCI device flags */

‎net/bluetooth/hci_core.c‎

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2246,9 +2246,13 @@ static int hci_dev_do_open(struct hci_dev *hdev)
22462246
atomic_set(&hdev->cmd_cnt, 1);
22472247
set_bit(HCI_INIT, &hdev->flags);
22482248

2249-
if (hdev->setup && test_bit(HCI_SETUP, &hdev->dev_flags))
2249+
if (hdev->setup && test_bit(HCI_SETUP, &hdev->dev_flags)) {
22502250
ret = hdev->setup(hdev);
22512251

2252+
if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks))
2253+
set_bit(HCI_UNCONFIGURED, &hdev->dev_flags);
2254+
}
2255+
22522256
/* If public address change is configured, ensure that the
22532257
* address gets programmed. If the driver does not support
22542258
* changing the public address, fail the power on procedure.

‎net/bluetooth/mgmt.c‎

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -441,22 +441,35 @@ static int read_unconf_index_list(struct sock *sk, struct hci_dev *hdev,
441441
return err;
442442
}
443443

444+
static __le32 get_missing_options(struct hci_dev *hdev)
445+
{
446+
u32 options = 0;
447+
448+
if (test_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks) &&
449+
!bacmp(&hdev->public_addr, BDADDR_ANY))
450+
options |= MGMT_OPTION_PUBLIC_ADDRESS;
451+
452+
return cpu_to_le32(options);
453+
}
454+
444455
static int read_config_info(struct sock *sk, struct hci_dev *hdev,
445456
void *data, u16 data_len)
446457
{
447458
struct mgmt_rp_read_config_info rp;
459+
u32 options = 0;
448460

449461
BT_DBG("sock %p %s", sk, hdev->name);
450462

451463
hci_dev_lock(hdev);
452464

453465
memset(&rp, 0, sizeof(rp));
454466
rp.manufacturer = cpu_to_le16(hdev->manufacturer);
467+
455468
if (hdev->set_bdaddr)
456-
rp.supported_options = cpu_to_le32(MGMT_OPTION_PUBLIC_ADDRESS);
457-
else
458-
rp.supported_options = cpu_to_le32(0);
459-
rp.missing_options = cpu_to_le32(0);
469+
options |= MGMT_OPTION_PUBLIC_ADDRESS;
470+
471+
rp.supported_options = cpu_to_le32(options);
472+
rp.missing_options = get_missing_options(hdev);
460473

461474
hci_dev_unlock(hdev);
462475

0 commit comments

Comments
 (0)