Marcel Holtmann | 48f0ed1 | 2015-04-06 00:52:11 -0700 | [diff] [blame] | 1 | /* |
| 2 | * |
| 3 | * Bluetooth support for Intel devices |
| 4 | * |
| 5 | * Copyright (C) 2015 Intel Corporation |
| 6 | * |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | * |
| 22 | */ |
| 23 | |
| 24 | #include <linux/module.h> |
Loic Poulain | 145f236 | 2015-09-04 17:54:34 +0200 | [diff] [blame] | 25 | #include <linux/firmware.h> |
Marcel Holtmann | 48f0ed1 | 2015-04-06 00:52:11 -0700 | [diff] [blame] | 26 | |
| 27 | #include <net/bluetooth/bluetooth.h> |
| 28 | #include <net/bluetooth/hci_core.h> |
| 29 | |
| 30 | #include "btintel.h" |
| 31 | |
| 32 | #define VERSION "0.1" |
| 33 | |
| 34 | #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}}) |
| 35 | |
| 36 | int btintel_check_bdaddr(struct hci_dev *hdev) |
| 37 | { |
| 38 | struct hci_rp_read_bd_addr *bda; |
| 39 | struct sk_buff *skb; |
| 40 | |
| 41 | skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL, |
| 42 | HCI_INIT_TIMEOUT); |
| 43 | if (IS_ERR(skb)) { |
| 44 | int err = PTR_ERR(skb); |
| 45 | BT_ERR("%s: Reading Intel device address failed (%d)", |
| 46 | hdev->name, err); |
| 47 | return err; |
| 48 | } |
| 49 | |
| 50 | if (skb->len != sizeof(*bda)) { |
| 51 | BT_ERR("%s: Intel device address length mismatch", hdev->name); |
| 52 | kfree_skb(skb); |
| 53 | return -EIO; |
| 54 | } |
| 55 | |
| 56 | bda = (struct hci_rp_read_bd_addr *)skb->data; |
Marcel Holtmann | 48f0ed1 | 2015-04-06 00:52:11 -0700 | [diff] [blame] | 57 | |
| 58 | /* For some Intel based controllers, the default Bluetooth device |
| 59 | * address 00:03:19:9E:8B:00 can be found. These controllers are |
| 60 | * fully operational, but have the danger of duplicate addresses |
| 61 | * and that in turn can cause problems with Bluetooth operation. |
| 62 | */ |
| 63 | if (!bacmp(&bda->bdaddr, BDADDR_INTEL)) { |
| 64 | BT_ERR("%s: Found Intel default device address (%pMR)", |
| 65 | hdev->name, &bda->bdaddr); |
| 66 | set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks); |
| 67 | } |
| 68 | |
| 69 | kfree_skb(skb); |
| 70 | |
| 71 | return 0; |
| 72 | } |
| 73 | EXPORT_SYMBOL_GPL(btintel_check_bdaddr); |
| 74 | |
| 75 | int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr) |
| 76 | { |
| 77 | struct sk_buff *skb; |
| 78 | int err; |
| 79 | |
| 80 | skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT); |
| 81 | if (IS_ERR(skb)) { |
| 82 | err = PTR_ERR(skb); |
| 83 | BT_ERR("%s: Changing Intel device address failed (%d)", |
| 84 | hdev->name, err); |
| 85 | return err; |
| 86 | } |
| 87 | kfree_skb(skb); |
| 88 | |
| 89 | return 0; |
| 90 | } |
| 91 | EXPORT_SYMBOL_GPL(btintel_set_bdaddr); |
| 92 | |
Marcel Holtmann | 973bb97 | 2015-07-05 14:37:38 +0200 | [diff] [blame] | 93 | void btintel_hw_error(struct hci_dev *hdev, u8 code) |
| 94 | { |
| 95 | struct sk_buff *skb; |
| 96 | u8 type = 0x00; |
| 97 | |
| 98 | BT_ERR("%s: Hardware error 0x%2.2x", hdev->name, code); |
| 99 | |
| 100 | skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT); |
| 101 | if (IS_ERR(skb)) { |
| 102 | BT_ERR("%s: Reset after hardware error failed (%ld)", |
| 103 | hdev->name, PTR_ERR(skb)); |
| 104 | return; |
| 105 | } |
| 106 | kfree_skb(skb); |
| 107 | |
| 108 | skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT); |
| 109 | if (IS_ERR(skb)) { |
| 110 | BT_ERR("%s: Retrieving Intel exception info failed (%ld)", |
| 111 | hdev->name, PTR_ERR(skb)); |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | if (skb->len != 13) { |
| 116 | BT_ERR("%s: Exception info size mismatch", hdev->name); |
| 117 | kfree_skb(skb); |
| 118 | return; |
| 119 | } |
| 120 | |
| 121 | BT_ERR("%s: Exception info %s", hdev->name, (char *)(skb->data + 1)); |
| 122 | |
| 123 | kfree_skb(skb); |
| 124 | } |
| 125 | EXPORT_SYMBOL_GPL(btintel_hw_error); |
| 126 | |
Marcel Holtmann | 7feb99e | 2015-07-05 15:02:07 +0200 | [diff] [blame] | 127 | void btintel_version_info(struct hci_dev *hdev, struct intel_version *ver) |
| 128 | { |
| 129 | const char *variant; |
| 130 | |
| 131 | switch (ver->fw_variant) { |
| 132 | case 0x06: |
| 133 | variant = "Bootloader"; |
| 134 | break; |
| 135 | case 0x23: |
| 136 | variant = "Firmware"; |
| 137 | break; |
| 138 | default: |
| 139 | return; |
| 140 | } |
| 141 | |
| 142 | BT_INFO("%s: %s revision %u.%u build %u week %u %u", hdev->name, |
| 143 | variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f, |
| 144 | ver->fw_build_num, ver->fw_build_ww, 2000 + ver->fw_build_yy); |
| 145 | } |
| 146 | EXPORT_SYMBOL_GPL(btintel_version_info); |
| 147 | |
Marcel Holtmann | 09df123 | 2015-07-05 14:55:36 +0200 | [diff] [blame] | 148 | int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen, |
| 149 | const void *param) |
| 150 | { |
| 151 | while (plen > 0) { |
| 152 | struct sk_buff *skb; |
| 153 | u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen; |
| 154 | |
| 155 | cmd_param[0] = fragment_type; |
| 156 | memcpy(cmd_param + 1, param, fragment_len); |
| 157 | |
| 158 | skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1, |
| 159 | cmd_param, HCI_INIT_TIMEOUT); |
| 160 | if (IS_ERR(skb)) |
| 161 | return PTR_ERR(skb); |
| 162 | |
| 163 | kfree_skb(skb); |
| 164 | |
| 165 | plen -= fragment_len; |
| 166 | param += fragment_len; |
| 167 | } |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | EXPORT_SYMBOL_GPL(btintel_secure_send); |
| 172 | |
Loic Poulain | 145f236 | 2015-09-04 17:54:34 +0200 | [diff] [blame] | 173 | int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name) |
| 174 | { |
| 175 | const struct firmware *fw; |
| 176 | struct sk_buff *skb; |
| 177 | const u8 *fw_ptr; |
| 178 | int err; |
| 179 | |
| 180 | err = request_firmware_direct(&fw, ddc_name, &hdev->dev); |
| 181 | if (err < 0) { |
| 182 | bt_dev_err(hdev, "Failed to load Intel DDC file %s (%d)", |
| 183 | ddc_name, err); |
| 184 | return err; |
| 185 | } |
| 186 | |
| 187 | bt_dev_info(hdev, "Found Intel DDC parameters: %s", ddc_name); |
| 188 | |
| 189 | fw_ptr = fw->data; |
| 190 | |
| 191 | /* DDC file contains one or more DDC structure which has |
| 192 | * Length (1 byte), DDC ID (2 bytes), and DDC value (Length - 2). |
| 193 | */ |
| 194 | while (fw->size > fw_ptr - fw->data) { |
| 195 | u8 cmd_plen = fw_ptr[0] + sizeof(u8); |
| 196 | |
| 197 | skb = __hci_cmd_sync(hdev, 0xfc8b, cmd_plen, fw_ptr, |
| 198 | HCI_INIT_TIMEOUT); |
| 199 | if (IS_ERR(skb)) { |
| 200 | bt_dev_err(hdev, "Failed to send Intel_Write_DDC (%ld)", |
| 201 | PTR_ERR(skb)); |
| 202 | release_firmware(fw); |
| 203 | return PTR_ERR(skb); |
| 204 | } |
| 205 | |
| 206 | fw_ptr += cmd_plen; |
| 207 | kfree_skb(skb); |
| 208 | } |
| 209 | |
| 210 | release_firmware(fw); |
| 211 | |
| 212 | bt_dev_info(hdev, "Applying Intel DDC parameters completed"); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | EXPORT_SYMBOL_GPL(btintel_load_ddc_config); |
| 217 | |
Marcel Holtmann | 48f0ed1 | 2015-04-06 00:52:11 -0700 | [diff] [blame] | 218 | MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>"); |
| 219 | MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION); |
| 220 | MODULE_VERSION(VERSION); |
| 221 | MODULE_LICENSE("GPL"); |
Marcel Holtmann | 0ed97e8 | 2015-08-27 08:57:39 +0200 | [diff] [blame] | 222 | MODULE_FIRMWARE("intel/ibt-11-5.sfi"); |
| 223 | MODULE_FIRMWARE("intel/ibt-11-5.ddc"); |