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