btintel.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735
  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. #include <linux/module.h>
  24. #include <linux/firmware.h>
  25. #include <linux/regmap.h>
  26. #include <asm/unaligned.h>
  27. #include <net/bluetooth/bluetooth.h>
  28. #include <net/bluetooth/hci_core.h>
  29. #include "btintel.h"
  30. #define VERSION "0.1"
  31. #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
  32. int btintel_check_bdaddr(struct hci_dev *hdev)
  33. {
  34. struct hci_rp_read_bd_addr *bda;
  35. struct sk_buff *skb;
  36. skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
  37. HCI_INIT_TIMEOUT);
  38. if (IS_ERR(skb)) {
  39. int err = PTR_ERR(skb);
  40. bt_dev_err(hdev, "Reading Intel device address failed (%d)",
  41. err);
  42. return err;
  43. }
  44. if (skb->len != sizeof(*bda)) {
  45. bt_dev_err(hdev, "Intel device address length mismatch");
  46. kfree_skb(skb);
  47. return -EIO;
  48. }
  49. bda = (struct hci_rp_read_bd_addr *)skb->data;
  50. /* For some Intel based controllers, the default Bluetooth device
  51. * address 00:03:19:9E:8B:00 can be found. These controllers are
  52. * fully operational, but have the danger of duplicate addresses
  53. * and that in turn can cause problems with Bluetooth operation.
  54. */
  55. if (!bacmp(&bda->bdaddr, BDADDR_INTEL)) {
  56. bt_dev_err(hdev, "Found Intel default device address (%pMR)",
  57. &bda->bdaddr);
  58. set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
  59. }
  60. kfree_skb(skb);
  61. return 0;
  62. }
  63. EXPORT_SYMBOL_GPL(btintel_check_bdaddr);
  64. int btintel_enter_mfg(struct hci_dev *hdev)
  65. {
  66. static const u8 param[] = { 0x01, 0x00 };
  67. struct sk_buff *skb;
  68. skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
  69. if (IS_ERR(skb)) {
  70. bt_dev_err(hdev, "Entering manufacturer mode failed (%ld)",
  71. PTR_ERR(skb));
  72. return PTR_ERR(skb);
  73. }
  74. kfree_skb(skb);
  75. return 0;
  76. }
  77. EXPORT_SYMBOL_GPL(btintel_enter_mfg);
  78. int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched)
  79. {
  80. u8 param[] = { 0x00, 0x00 };
  81. struct sk_buff *skb;
  82. /* The 2nd command parameter specifies the manufacturing exit method:
  83. * 0x00: Just disable the manufacturing mode (0x00).
  84. * 0x01: Disable manufacturing mode and reset with patches deactivated.
  85. * 0x02: Disable manufacturing mode and reset with patches activated.
  86. */
  87. if (reset)
  88. param[1] |= patched ? 0x02 : 0x01;
  89. skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
  90. if (IS_ERR(skb)) {
  91. bt_dev_err(hdev, "Exiting manufacturer mode failed (%ld)",
  92. PTR_ERR(skb));
  93. return PTR_ERR(skb);
  94. }
  95. kfree_skb(skb);
  96. return 0;
  97. }
  98. EXPORT_SYMBOL_GPL(btintel_exit_mfg);
  99. int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
  100. {
  101. struct sk_buff *skb;
  102. int err;
  103. skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
  104. if (IS_ERR(skb)) {
  105. err = PTR_ERR(skb);
  106. bt_dev_err(hdev, "Changing Intel device address failed (%d)",
  107. err);
  108. return err;
  109. }
  110. kfree_skb(skb);
  111. return 0;
  112. }
  113. EXPORT_SYMBOL_GPL(btintel_set_bdaddr);
  114. int btintel_set_diag(struct hci_dev *hdev, bool enable)
  115. {
  116. struct sk_buff *skb;
  117. u8 param[3];
  118. int err;
  119. if (enable) {
  120. param[0] = 0x03;
  121. param[1] = 0x03;
  122. param[2] = 0x03;
  123. } else {
  124. param[0] = 0x00;
  125. param[1] = 0x00;
  126. param[2] = 0x00;
  127. }
  128. skb = __hci_cmd_sync(hdev, 0xfc43, 3, param, HCI_INIT_TIMEOUT);
  129. if (IS_ERR(skb)) {
  130. err = PTR_ERR(skb);
  131. if (err == -ENODATA)
  132. goto done;
  133. bt_dev_err(hdev, "Changing Intel diagnostic mode failed (%d)",
  134. err);
  135. return err;
  136. }
  137. kfree_skb(skb);
  138. done:
  139. btintel_set_event_mask(hdev, enable);
  140. return 0;
  141. }
  142. EXPORT_SYMBOL_GPL(btintel_set_diag);
  143. int btintel_set_diag_mfg(struct hci_dev *hdev, bool enable)
  144. {
  145. int err, ret;
  146. err = btintel_enter_mfg(hdev);
  147. if (err)
  148. return err;
  149. ret = btintel_set_diag(hdev, enable);
  150. err = btintel_exit_mfg(hdev, false, false);
  151. if (err)
  152. return err;
  153. return ret;
  154. }
  155. EXPORT_SYMBOL_GPL(btintel_set_diag_mfg);
  156. void btintel_hw_error(struct hci_dev *hdev, u8 code)
  157. {
  158. struct sk_buff *skb;
  159. u8 type = 0x00;
  160. bt_dev_err(hdev, "Hardware error 0x%2.2x", code);
  161. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
  162. if (IS_ERR(skb)) {
  163. bt_dev_err(hdev, "Reset after hardware error failed (%ld)",
  164. PTR_ERR(skb));
  165. return;
  166. }
  167. kfree_skb(skb);
  168. skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT);
  169. if (IS_ERR(skb)) {
  170. bt_dev_err(hdev, "Retrieving Intel exception info failed (%ld)",
  171. PTR_ERR(skb));
  172. return;
  173. }
  174. if (skb->len != 13) {
  175. bt_dev_err(hdev, "Exception info size mismatch");
  176. kfree_skb(skb);
  177. return;
  178. }
  179. bt_dev_err(hdev, "Exception info %s", (char *)(skb->data + 1));
  180. kfree_skb(skb);
  181. }
  182. EXPORT_SYMBOL_GPL(btintel_hw_error);
  183. void btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)
  184. {
  185. const char *variant;
  186. switch (ver->fw_variant) {
  187. case 0x06:
  188. variant = "Bootloader";
  189. break;
  190. case 0x23:
  191. variant = "Firmware";
  192. break;
  193. default:
  194. return;
  195. }
  196. bt_dev_info(hdev, "%s revision %u.%u build %u week %u %u",
  197. variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f,
  198. ver->fw_build_num, ver->fw_build_ww,
  199. 2000 + ver->fw_build_yy);
  200. }
  201. EXPORT_SYMBOL_GPL(btintel_version_info);
  202. int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,
  203. const void *param)
  204. {
  205. while (plen > 0) {
  206. struct sk_buff *skb;
  207. u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen;
  208. cmd_param[0] = fragment_type;
  209. memcpy(cmd_param + 1, param, fragment_len);
  210. skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1,
  211. cmd_param, HCI_INIT_TIMEOUT);
  212. if (IS_ERR(skb))
  213. return PTR_ERR(skb);
  214. kfree_skb(skb);
  215. plen -= fragment_len;
  216. param += fragment_len;
  217. }
  218. return 0;
  219. }
  220. EXPORT_SYMBOL_GPL(btintel_secure_send);
  221. int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name)
  222. {
  223. const struct firmware *fw;
  224. struct sk_buff *skb;
  225. const u8 *fw_ptr;
  226. int err;
  227. err = request_firmware_direct(&fw, ddc_name, &hdev->dev);
  228. if (err < 0) {
  229. bt_dev_err(hdev, "Failed to load Intel DDC file %s (%d)",
  230. ddc_name, err);
  231. return err;
  232. }
  233. bt_dev_info(hdev, "Found Intel DDC parameters: %s", ddc_name);
  234. fw_ptr = fw->data;
  235. /* DDC file contains one or more DDC structure which has
  236. * Length (1 byte), DDC ID (2 bytes), and DDC value (Length - 2).
  237. */
  238. while (fw->size > fw_ptr - fw->data) {
  239. u8 cmd_plen = fw_ptr[0] + sizeof(u8);
  240. skb = __hci_cmd_sync(hdev, 0xfc8b, cmd_plen, fw_ptr,
  241. HCI_INIT_TIMEOUT);
  242. if (IS_ERR(skb)) {
  243. bt_dev_err(hdev, "Failed to send Intel_Write_DDC (%ld)",
  244. PTR_ERR(skb));
  245. release_firmware(fw);
  246. return PTR_ERR(skb);
  247. }
  248. fw_ptr += cmd_plen;
  249. kfree_skb(skb);
  250. }
  251. release_firmware(fw);
  252. bt_dev_info(hdev, "Applying Intel DDC parameters completed");
  253. return 0;
  254. }
  255. EXPORT_SYMBOL_GPL(btintel_load_ddc_config);
  256. int btintel_set_event_mask(struct hci_dev *hdev, bool debug)
  257. {
  258. u8 mask[8] = { 0x87, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
  259. struct sk_buff *skb;
  260. int err;
  261. if (debug)
  262. mask[1] |= 0x62;
  263. skb = __hci_cmd_sync(hdev, 0xfc52, 8, mask, HCI_INIT_TIMEOUT);
  264. if (IS_ERR(skb)) {
  265. err = PTR_ERR(skb);
  266. bt_dev_err(hdev, "Setting Intel event mask failed (%d)", err);
  267. return err;
  268. }
  269. kfree_skb(skb);
  270. return 0;
  271. }
  272. EXPORT_SYMBOL_GPL(btintel_set_event_mask);
  273. int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
  274. {
  275. int err, ret;
  276. err = btintel_enter_mfg(hdev);
  277. if (err)
  278. return err;
  279. ret = btintel_set_event_mask(hdev, debug);
  280. err = btintel_exit_mfg(hdev, false, false);
  281. if (err)
  282. return err;
  283. return ret;
  284. }
  285. EXPORT_SYMBOL_GPL(btintel_set_event_mask_mfg);
  286. int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver)
  287. {
  288. struct sk_buff *skb;
  289. skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_CMD_TIMEOUT);
  290. if (IS_ERR(skb)) {
  291. bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
  292. PTR_ERR(skb));
  293. return PTR_ERR(skb);
  294. }
  295. if (skb->len != sizeof(*ver)) {
  296. bt_dev_err(hdev, "Intel version event size mismatch");
  297. kfree_skb(skb);
  298. return -EILSEQ;
  299. }
  300. memcpy(ver, skb->data, sizeof(*ver));
  301. kfree_skb(skb);
  302. return 0;
  303. }
  304. EXPORT_SYMBOL_GPL(btintel_read_version);
  305. /* ------- REGMAP IBT SUPPORT ------- */
  306. #define IBT_REG_MODE_8BIT 0x00
  307. #define IBT_REG_MODE_16BIT 0x01
  308. #define IBT_REG_MODE_32BIT 0x02
  309. struct regmap_ibt_context {
  310. struct hci_dev *hdev;
  311. __u16 op_write;
  312. __u16 op_read;
  313. };
  314. struct ibt_cp_reg_access {
  315. __le32 addr;
  316. __u8 mode;
  317. __u8 len;
  318. __u8 data[0];
  319. } __packed;
  320. struct ibt_rp_reg_access {
  321. __u8 status;
  322. __le32 addr;
  323. __u8 data[0];
  324. } __packed;
  325. static int regmap_ibt_read(void *context, const void *addr, size_t reg_size,
  326. void *val, size_t val_size)
  327. {
  328. struct regmap_ibt_context *ctx = context;
  329. struct ibt_cp_reg_access cp;
  330. struct ibt_rp_reg_access *rp;
  331. struct sk_buff *skb;
  332. int err = 0;
  333. if (reg_size != sizeof(__le32))
  334. return -EINVAL;
  335. switch (val_size) {
  336. case 1:
  337. cp.mode = IBT_REG_MODE_8BIT;
  338. break;
  339. case 2:
  340. cp.mode = IBT_REG_MODE_16BIT;
  341. break;
  342. case 4:
  343. cp.mode = IBT_REG_MODE_32BIT;
  344. break;
  345. default:
  346. return -EINVAL;
  347. }
  348. /* regmap provides a little-endian formatted addr */
  349. cp.addr = *(__le32 *)addr;
  350. cp.len = val_size;
  351. bt_dev_dbg(ctx->hdev, "Register (0x%x) read", le32_to_cpu(cp.addr));
  352. skb = hci_cmd_sync(ctx->hdev, ctx->op_read, sizeof(cp), &cp,
  353. HCI_CMD_TIMEOUT);
  354. if (IS_ERR(skb)) {
  355. err = PTR_ERR(skb);
  356. bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error (%d)",
  357. le32_to_cpu(cp.addr), err);
  358. return err;
  359. }
  360. if (skb->len != sizeof(*rp) + val_size) {
  361. bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad len",
  362. le32_to_cpu(cp.addr));
  363. err = -EINVAL;
  364. goto done;
  365. }
  366. rp = (struct ibt_rp_reg_access *)skb->data;
  367. if (rp->addr != cp.addr) {
  368. bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad addr",
  369. le32_to_cpu(rp->addr));
  370. err = -EINVAL;
  371. goto done;
  372. }
  373. memcpy(val, rp->data, val_size);
  374. done:
  375. kfree_skb(skb);
  376. return err;
  377. }
  378. static int regmap_ibt_gather_write(void *context,
  379. const void *addr, size_t reg_size,
  380. const void *val, size_t val_size)
  381. {
  382. struct regmap_ibt_context *ctx = context;
  383. struct ibt_cp_reg_access *cp;
  384. struct sk_buff *skb;
  385. int plen = sizeof(*cp) + val_size;
  386. u8 mode;
  387. int err = 0;
  388. if (reg_size != sizeof(__le32))
  389. return -EINVAL;
  390. switch (val_size) {
  391. case 1:
  392. mode = IBT_REG_MODE_8BIT;
  393. break;
  394. case 2:
  395. mode = IBT_REG_MODE_16BIT;
  396. break;
  397. case 4:
  398. mode = IBT_REG_MODE_32BIT;
  399. break;
  400. default:
  401. return -EINVAL;
  402. }
  403. cp = kmalloc(plen, GFP_KERNEL);
  404. if (!cp)
  405. return -ENOMEM;
  406. /* regmap provides a little-endian formatted addr/value */
  407. cp->addr = *(__le32 *)addr;
  408. cp->mode = mode;
  409. cp->len = val_size;
  410. memcpy(&cp->data, val, val_size);
  411. bt_dev_dbg(ctx->hdev, "Register (0x%x) write", le32_to_cpu(cp->addr));
  412. skb = hci_cmd_sync(ctx->hdev, ctx->op_write, plen, cp, HCI_CMD_TIMEOUT);
  413. if (IS_ERR(skb)) {
  414. err = PTR_ERR(skb);
  415. bt_dev_err(ctx->hdev, "regmap: Register (0x%x) write error (%d)",
  416. le32_to_cpu(cp->addr), err);
  417. goto done;
  418. }
  419. kfree_skb(skb);
  420. done:
  421. kfree(cp);
  422. return err;
  423. }
  424. static int regmap_ibt_write(void *context, const void *data, size_t count)
  425. {
  426. /* data contains register+value, since we only support 32bit addr,
  427. * minimum data size is 4 bytes.
  428. */
  429. if (WARN_ONCE(count < 4, "Invalid register access"))
  430. return -EINVAL;
  431. return regmap_ibt_gather_write(context, data, 4, data + 4, count - 4);
  432. }
  433. static void regmap_ibt_free_context(void *context)
  434. {
  435. kfree(context);
  436. }
  437. static struct regmap_bus regmap_ibt = {
  438. .read = regmap_ibt_read,
  439. .write = regmap_ibt_write,
  440. .gather_write = regmap_ibt_gather_write,
  441. .free_context = regmap_ibt_free_context,
  442. .reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
  443. .val_format_endian_default = REGMAP_ENDIAN_LITTLE,
  444. };
  445. /* Config is the same for all register regions */
  446. static const struct regmap_config regmap_ibt_cfg = {
  447. .name = "btintel_regmap",
  448. .reg_bits = 32,
  449. .val_bits = 32,
  450. };
  451. struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
  452. u16 opcode_write)
  453. {
  454. struct regmap_ibt_context *ctx;
  455. bt_dev_info(hdev, "regmap: Init R%x-W%x region", opcode_read,
  456. opcode_write);
  457. ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
  458. if (!ctx)
  459. return ERR_PTR(-ENOMEM);
  460. ctx->op_read = opcode_read;
  461. ctx->op_write = opcode_write;
  462. ctx->hdev = hdev;
  463. return regmap_init(&hdev->dev, &regmap_ibt, ctx, &regmap_ibt_cfg);
  464. }
  465. EXPORT_SYMBOL_GPL(btintel_regmap_init);
  466. int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param)
  467. {
  468. struct intel_reset params = { 0x00, 0x01, 0x00, 0x01, 0x00000000 };
  469. struct sk_buff *skb;
  470. params.boot_param = cpu_to_le32(boot_param);
  471. skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(params), &params,
  472. HCI_INIT_TIMEOUT);
  473. if (IS_ERR(skb)) {
  474. bt_dev_err(hdev, "Failed to send Intel Reset command");
  475. return PTR_ERR(skb);
  476. }
  477. kfree_skb(skb);
  478. return 0;
  479. }
  480. EXPORT_SYMBOL_GPL(btintel_send_intel_reset);
  481. int btintel_read_boot_params(struct hci_dev *hdev,
  482. struct intel_boot_params *params)
  483. {
  484. struct sk_buff *skb;
  485. skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
  486. if (IS_ERR(skb)) {
  487. bt_dev_err(hdev, "Reading Intel boot parameters failed (%ld)",
  488. PTR_ERR(skb));
  489. return PTR_ERR(skb);
  490. }
  491. if (skb->len != sizeof(*params)) {
  492. bt_dev_err(hdev, "Intel boot parameters size mismatch");
  493. kfree_skb(skb);
  494. return -EILSEQ;
  495. }
  496. memcpy(params, skb->data, sizeof(*params));
  497. kfree_skb(skb);
  498. if (params->status) {
  499. bt_dev_err(hdev, "Intel boot parameters command failed (%02x)",
  500. params->status);
  501. return -bt_to_errno(params->status);
  502. }
  503. bt_dev_info(hdev, "Device revision is %u",
  504. le16_to_cpu(params->dev_revid));
  505. bt_dev_info(hdev, "Secure boot is %s",
  506. params->secure_boot ? "enabled" : "disabled");
  507. bt_dev_info(hdev, "OTP lock is %s",
  508. params->otp_lock ? "enabled" : "disabled");
  509. bt_dev_info(hdev, "API lock is %s",
  510. params->api_lock ? "enabled" : "disabled");
  511. bt_dev_info(hdev, "Debug lock is %s",
  512. params->debug_lock ? "enabled" : "disabled");
  513. bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
  514. params->min_fw_build_nn, params->min_fw_build_cw,
  515. 2000 + params->min_fw_build_yy);
  516. return 0;
  517. }
  518. EXPORT_SYMBOL_GPL(btintel_read_boot_params);
  519. int btintel_download_firmware(struct hci_dev *hdev, const struct firmware *fw,
  520. u32 *boot_param)
  521. {
  522. int err;
  523. const u8 *fw_ptr;
  524. u32 frag_len;
  525. /* Start the firmware download transaction with the Init fragment
  526. * represented by the 128 bytes of CSS header.
  527. */
  528. err = btintel_secure_send(hdev, 0x00, 128, fw->data);
  529. if (err < 0) {
  530. bt_dev_err(hdev, "Failed to send firmware header (%d)", err);
  531. goto done;
  532. }
  533. /* Send the 256 bytes of public key information from the firmware
  534. * as the PKey fragment.
  535. */
  536. err = btintel_secure_send(hdev, 0x03, 256, fw->data + 128);
  537. if (err < 0) {
  538. bt_dev_err(hdev, "Failed to send firmware pkey (%d)", err);
  539. goto done;
  540. }
  541. /* Send the 256 bytes of signature information from the firmware
  542. * as the Sign fragment.
  543. */
  544. err = btintel_secure_send(hdev, 0x02, 256, fw->data + 388);
  545. if (err < 0) {
  546. bt_dev_err(hdev, "Failed to send firmware signature (%d)", err);
  547. goto done;
  548. }
  549. fw_ptr = fw->data + 644;
  550. frag_len = 0;
  551. while (fw_ptr - fw->data < fw->size) {
  552. struct hci_command_hdr *cmd = (void *)(fw_ptr + frag_len);
  553. /* Each SKU has a different reset parameter to use in the
  554. * HCI_Intel_Reset command and it is embedded in the firmware
  555. * data. So, instead of using static value per SKU, check
  556. * the firmware data and save it for later use.
  557. */
  558. if (le16_to_cpu(cmd->opcode) == 0xfc0e) {
  559. /* The boot parameter is the first 32-bit value
  560. * and rest of 3 octets are reserved.
  561. */
  562. *boot_param = get_unaligned_le32(fw_ptr + sizeof(*cmd));
  563. bt_dev_dbg(hdev, "boot_param=0x%x", *boot_param);
  564. }
  565. frag_len += sizeof(*cmd) + cmd->plen;
  566. /* The parameter length of the secure send command requires
  567. * a 4 byte alignment. It happens so that the firmware file
  568. * contains proper Intel_NOP commands to align the fragments
  569. * as needed.
  570. *
  571. * Send set of commands with 4 byte alignment from the
  572. * firmware data buffer as a single Data fragement.
  573. */
  574. if (!(frag_len % 4)) {
  575. err = btintel_secure_send(hdev, 0x01, frag_len, fw_ptr);
  576. if (err < 0) {
  577. bt_dev_err(hdev,
  578. "Failed to send firmware data (%d)",
  579. err);
  580. goto done;
  581. }
  582. fw_ptr += frag_len;
  583. frag_len = 0;
  584. }
  585. }
  586. done:
  587. return err;
  588. }
  589. EXPORT_SYMBOL_GPL(btintel_download_firmware);
  590. MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
  591. MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
  592. MODULE_VERSION(VERSION);
  593. MODULE_LICENSE("GPL");
  594. MODULE_FIRMWARE("intel/ibt-11-5.sfi");
  595. MODULE_FIRMWARE("intel/ibt-11-5.ddc");
  596. MODULE_FIRMWARE("intel/ibt-12-16.sfi");
  597. MODULE_FIRMWARE("intel/ibt-12-16.ddc");