Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Bluetooth: hci_bcm: Fall back to getting bdaddr from EFI if not set

On some devices the BCM Bluetooth adapter does not have a valid bdaddr set.

btbcm.c currently sets HCI_QUIRK_INVALID_BDADDR to indicate when this is
the case. But this requires users to manual setup a btaddr, by doing e.g.:

btmgmt -i hci0 public-addr 'B0:F1:EC:82:1D:B3'

Which means that Bluetooth will not work out of the box on such devices.
To avoid this (where possible) hci_bcm sets: HCI_QUIRK_USE_BDADDR_PROPERTY
which tries to get the bdaddr from devicetree.

But this only works on devicetree platforms. On UEFI based platforms
there is a special Broadcom UEFI variable which when present contains
the devices bdaddr, just like how there is another UEFI variable which
contains wifi nvram contents including the wifi MAC address.

Add support for getting the bdaddr from this Broadcom UEFI variable,
so that Bluetooth will work OOTB for users on devices where this
UEFI variable is present.

This fixes Bluetooth not working on for example Asus T100HA 2-in-1s.

Signed-off-by: Hans de Goede <hdegoede@redhat.com>
Signed-off-by: Luiz Augusto von Dentz <luiz.von.dentz@intel.com>

authored by

Hans de Goede and committed by
Luiz Augusto von Dentz
0d218c36 3c0d41f1

+44 -3
+44 -3
drivers/bluetooth/btbcm.c
··· 6 6 * Copyright (C) 2015 Intel Corporation 7 7 */ 8 8 9 + #include <linux/efi.h> 9 10 #include <linux/module.h> 10 11 #include <linux/firmware.h> 11 12 #include <linux/dmi.h> ··· 34 33 #define BCM_FW_NAME_COUNT_MAX 4 35 34 /* For kmalloc-ing the fw-name array instead of putting it on the stack */ 36 35 typedef char bcm_fw_name[BCM_FW_NAME_LEN]; 36 + 37 + #ifdef CONFIG_EFI 38 + static int btbcm_set_bdaddr_from_efi(struct hci_dev *hdev) 39 + { 40 + efi_guid_t guid = EFI_GUID(0x74b00bd9, 0x805a, 0x4d61, 0xb5, 0x1f, 41 + 0x43, 0x26, 0x81, 0x23, 0xd1, 0x13); 42 + bdaddr_t efi_bdaddr, bdaddr; 43 + efi_status_t status; 44 + unsigned long len; 45 + int ret; 46 + 47 + if (!efi_rt_services_supported(EFI_RT_SUPPORTED_GET_VARIABLE)) 48 + return -EOPNOTSUPP; 49 + 50 + len = sizeof(efi_bdaddr); 51 + status = efi.get_variable(L"BDADDR", &guid, NULL, &len, &efi_bdaddr); 52 + if (status != EFI_SUCCESS) 53 + return -ENXIO; 54 + 55 + if (len != sizeof(efi_bdaddr)) 56 + return -EIO; 57 + 58 + baswap(&bdaddr, &efi_bdaddr); 59 + 60 + ret = btbcm_set_bdaddr(hdev, &bdaddr); 61 + if (ret) 62 + return ret; 63 + 64 + bt_dev_info(hdev, "BCM: Using EFI device address (%pMR)", &bdaddr); 65 + return 0; 66 + } 67 + #else 68 + static int btbcm_set_bdaddr_from_efi(struct hci_dev *hdev) 69 + { 70 + return -EOPNOTSUPP; 71 + } 72 + #endif 37 73 38 74 int btbcm_check_bdaddr(struct hci_dev *hdev) 39 75 { ··· 125 87 !bacmp(&bda->bdaddr, BDADDR_BCM4345C5) || 126 88 !bacmp(&bda->bdaddr, BDADDR_BCM43430A0) || 127 89 !bacmp(&bda->bdaddr, BDADDR_BCM43341B)) { 128 - bt_dev_info(hdev, "BCM: Using default device address (%pMR)", 129 - &bda->bdaddr); 130 - set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); 90 + /* Try falling back to BDADDR EFI variable */ 91 + if (btbcm_set_bdaddr_from_efi(hdev) != 0) { 92 + bt_dev_info(hdev, "BCM: Using default device address (%pMR)", 93 + &bda->bdaddr); 94 + set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); 95 + } 131 96 } 132 97 133 98 kfree_skb(skb);