blob: da47f6dccd386d0744fe889a2a00423ffc7554ec [file] [log] [blame]
Marcel Holtmann48f0ed12015-04-06 00:52:11 -07001/*
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 Poulain145f2362015-09-04 17:54:34 +020025#include <linux/firmware.h>
Loic Poulaind06f1072015-10-01 18:16:21 +020026#include <linux/regmap.h>
Marcel Holtmann48f0ed12015-04-06 00:52:11 -070027
28#include <net/bluetooth/bluetooth.h>
29#include <net/bluetooth/hci_core.h>
30
31#include "btintel.h"
32
33#define VERSION "0.1"
34
35#define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
36
37int btintel_check_bdaddr(struct hci_dev *hdev)
38{
39 struct hci_rp_read_bd_addr *bda;
40 struct sk_buff *skb;
41
42 skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
43 HCI_INIT_TIMEOUT);
44 if (IS_ERR(skb)) {
45 int err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +010046 bt_dev_err(hdev, "Reading Intel device address failed (%d)",
47 err);
Marcel Holtmann48f0ed12015-04-06 00:52:11 -070048 return err;
49 }
50
51 if (skb->len != sizeof(*bda)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +010052 bt_dev_err(hdev, "Intel device address length mismatch");
Marcel Holtmann48f0ed12015-04-06 00:52:11 -070053 kfree_skb(skb);
54 return -EIO;
55 }
56
57 bda = (struct hci_rp_read_bd_addr *)skb->data;
Marcel Holtmann48f0ed12015-04-06 00:52:11 -070058
59 /* For some Intel based controllers, the default Bluetooth device
60 * address 00:03:19:9E:8B:00 can be found. These controllers are
61 * fully operational, but have the danger of duplicate addresses
62 * and that in turn can cause problems with Bluetooth operation.
63 */
64 if (!bacmp(&bda->bdaddr, BDADDR_INTEL)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +010065 bt_dev_err(hdev, "Found Intel default device address (%pMR)",
66 &bda->bdaddr);
Marcel Holtmann48f0ed12015-04-06 00:52:11 -070067 set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
68 }
69
70 kfree_skb(skb);
71
72 return 0;
73}
74EXPORT_SYMBOL_GPL(btintel_check_bdaddr);
75
Loic Poulain28dc4b92015-12-03 16:10:22 +010076int btintel_enter_mfg(struct hci_dev *hdev)
77{
Colin Ian King948c7ca2018-01-06 16:23:28 +000078 static const u8 param[] = { 0x01, 0x00 };
Loic Poulain28dc4b92015-12-03 16:10:22 +010079 struct sk_buff *skb;
80
81 skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
82 if (IS_ERR(skb)) {
83 bt_dev_err(hdev, "Entering manufacturer mode failed (%ld)",
84 PTR_ERR(skb));
85 return PTR_ERR(skb);
86 }
87 kfree_skb(skb);
88
89 return 0;
90}
91EXPORT_SYMBOL_GPL(btintel_enter_mfg);
92
93int btintel_exit_mfg(struct hci_dev *hdev, bool reset, bool patched)
94{
95 u8 param[] = { 0x00, 0x00 };
96 struct sk_buff *skb;
97
98 /* The 2nd command parameter specifies the manufacturing exit method:
99 * 0x00: Just disable the manufacturing mode (0x00).
100 * 0x01: Disable manufacturing mode and reset with patches deactivated.
101 * 0x02: Disable manufacturing mode and reset with patches activated.
102 */
103 if (reset)
104 param[1] |= patched ? 0x02 : 0x01;
105
106 skb = __hci_cmd_sync(hdev, 0xfc11, 2, param, HCI_CMD_TIMEOUT);
107 if (IS_ERR(skb)) {
108 bt_dev_err(hdev, "Exiting manufacturer mode failed (%ld)",
109 PTR_ERR(skb));
110 return PTR_ERR(skb);
111 }
112 kfree_skb(skb);
113
114 return 0;
115}
116EXPORT_SYMBOL_GPL(btintel_exit_mfg);
117
Marcel Holtmann48f0ed12015-04-06 00:52:11 -0700118int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
119{
120 struct sk_buff *skb;
121 int err;
122
123 skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
124 if (IS_ERR(skb)) {
125 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100126 bt_dev_err(hdev, "Changing Intel device address failed (%d)",
127 err);
Marcel Holtmann48f0ed12015-04-06 00:52:11 -0700128 return err;
129 }
130 kfree_skb(skb);
131
132 return 0;
133}
134EXPORT_SYMBOL_GPL(btintel_set_bdaddr);
135
Marcel Holtmann6d2e50d2015-10-09 14:42:08 +0200136int btintel_set_diag(struct hci_dev *hdev, bool enable)
137{
138 struct sk_buff *skb;
139 u8 param[3];
140 int err;
141
Marcel Holtmann6d2e50d2015-10-09 14:42:08 +0200142 if (enable) {
143 param[0] = 0x03;
144 param[1] = 0x03;
145 param[2] = 0x03;
146 } else {
147 param[0] = 0x00;
148 param[1] = 0x00;
149 param[2] = 0x00;
150 }
151
152 skb = __hci_cmd_sync(hdev, 0xfc43, 3, param, HCI_INIT_TIMEOUT);
153 if (IS_ERR(skb)) {
154 err = PTR_ERR(skb);
Marcel Holtmannd8270fb2015-10-17 16:00:27 +0200155 if (err == -ENODATA)
Marcel Holtmann213445b2015-10-21 02:45:19 +0200156 goto done;
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100157 bt_dev_err(hdev, "Changing Intel diagnostic mode failed (%d)",
158 err);
Marcel Holtmann6d2e50d2015-10-09 14:42:08 +0200159 return err;
160 }
161 kfree_skb(skb);
162
Marcel Holtmann213445b2015-10-21 02:45:19 +0200163done:
164 btintel_set_event_mask(hdev, enable);
Marcel Holtmann6d2e50d2015-10-09 14:42:08 +0200165 return 0;
166}
167EXPORT_SYMBOL_GPL(btintel_set_diag);
168
Marcel Holtmann3e247672015-10-17 16:00:28 +0200169int btintel_set_diag_mfg(struct hci_dev *hdev, bool enable)
170{
Loic Poulain28dc4b92015-12-03 16:10:22 +0100171 int err, ret;
Marcel Holtmann3e247672015-10-17 16:00:28 +0200172
Loic Poulain28dc4b92015-12-03 16:10:22 +0100173 err = btintel_enter_mfg(hdev);
174 if (err)
175 return err;
Marcel Holtmann3e247672015-10-17 16:00:28 +0200176
Loic Poulain28dc4b92015-12-03 16:10:22 +0100177 ret = btintel_set_diag(hdev, enable);
Marcel Holtmann3e247672015-10-17 16:00:28 +0200178
Loic Poulain28dc4b92015-12-03 16:10:22 +0100179 err = btintel_exit_mfg(hdev, false, false);
180 if (err)
181 return err;
Marcel Holtmann3e247672015-10-17 16:00:28 +0200182
Loic Poulain28dc4b92015-12-03 16:10:22 +0100183 return ret;
Marcel Holtmann3e247672015-10-17 16:00:28 +0200184}
185EXPORT_SYMBOL_GPL(btintel_set_diag_mfg);
186
Marcel Holtmann973bb972015-07-05 14:37:38 +0200187void btintel_hw_error(struct hci_dev *hdev, u8 code)
188{
189 struct sk_buff *skb;
190 u8 type = 0x00;
191
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100192 bt_dev_err(hdev, "Hardware error 0x%2.2x", code);
Marcel Holtmann973bb972015-07-05 14:37:38 +0200193
194 skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
195 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100196 bt_dev_err(hdev, "Reset after hardware error failed (%ld)",
197 PTR_ERR(skb));
Marcel Holtmann973bb972015-07-05 14:37:38 +0200198 return;
199 }
200 kfree_skb(skb);
201
202 skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT);
203 if (IS_ERR(skb)) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100204 bt_dev_err(hdev, "Retrieving Intel exception info failed (%ld)",
205 PTR_ERR(skb));
Marcel Holtmann973bb972015-07-05 14:37:38 +0200206 return;
207 }
208
209 if (skb->len != 13) {
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100210 bt_dev_err(hdev, "Exception info size mismatch");
Marcel Holtmann973bb972015-07-05 14:37:38 +0200211 kfree_skb(skb);
212 return;
213 }
214
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100215 bt_dev_err(hdev, "Exception info %s", (char *)(skb->data + 1));
Marcel Holtmann973bb972015-07-05 14:37:38 +0200216
217 kfree_skb(skb);
218}
219EXPORT_SYMBOL_GPL(btintel_hw_error);
220
Marcel Holtmann7feb99e2015-07-05 15:02:07 +0200221void btintel_version_info(struct hci_dev *hdev, struct intel_version *ver)
222{
223 const char *variant;
224
225 switch (ver->fw_variant) {
226 case 0x06:
227 variant = "Bootloader";
228 break;
229 case 0x23:
230 variant = "Firmware";
231 break;
232 default:
233 return;
234 }
235
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100236 bt_dev_info(hdev, "%s revision %u.%u build %u week %u %u",
237 variant, ver->fw_revision >> 4, ver->fw_revision & 0x0f,
238 ver->fw_build_num, ver->fw_build_ww,
239 2000 + ver->fw_build_yy);
Marcel Holtmann7feb99e2015-07-05 15:02:07 +0200240}
241EXPORT_SYMBOL_GPL(btintel_version_info);
242
Marcel Holtmann09df1232015-07-05 14:55:36 +0200243int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,
244 const void *param)
245{
246 while (plen > 0) {
247 struct sk_buff *skb;
248 u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen;
249
250 cmd_param[0] = fragment_type;
251 memcpy(cmd_param + 1, param, fragment_len);
252
253 skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1,
254 cmd_param, HCI_INIT_TIMEOUT);
255 if (IS_ERR(skb))
256 return PTR_ERR(skb);
257
258 kfree_skb(skb);
259
260 plen -= fragment_len;
261 param += fragment_len;
262 }
263
264 return 0;
265}
266EXPORT_SYMBOL_GPL(btintel_secure_send);
267
Loic Poulain145f2362015-09-04 17:54:34 +0200268int btintel_load_ddc_config(struct hci_dev *hdev, const char *ddc_name)
269{
270 const struct firmware *fw;
271 struct sk_buff *skb;
272 const u8 *fw_ptr;
273 int err;
274
275 err = request_firmware_direct(&fw, ddc_name, &hdev->dev);
276 if (err < 0) {
277 bt_dev_err(hdev, "Failed to load Intel DDC file %s (%d)",
278 ddc_name, err);
279 return err;
280 }
281
282 bt_dev_info(hdev, "Found Intel DDC parameters: %s", ddc_name);
283
284 fw_ptr = fw->data;
285
286 /* DDC file contains one or more DDC structure which has
287 * Length (1 byte), DDC ID (2 bytes), and DDC value (Length - 2).
288 */
289 while (fw->size > fw_ptr - fw->data) {
290 u8 cmd_plen = fw_ptr[0] + sizeof(u8);
291
292 skb = __hci_cmd_sync(hdev, 0xfc8b, cmd_plen, fw_ptr,
293 HCI_INIT_TIMEOUT);
294 if (IS_ERR(skb)) {
295 bt_dev_err(hdev, "Failed to send Intel_Write_DDC (%ld)",
296 PTR_ERR(skb));
297 release_firmware(fw);
298 return PTR_ERR(skb);
299 }
300
301 fw_ptr += cmd_plen;
302 kfree_skb(skb);
303 }
304
305 release_firmware(fw);
306
307 bt_dev_info(hdev, "Applying Intel DDC parameters completed");
308
309 return 0;
310}
311EXPORT_SYMBOL_GPL(btintel_load_ddc_config);
312
Marcel Holtmann213445b2015-10-21 02:45:19 +0200313int btintel_set_event_mask(struct hci_dev *hdev, bool debug)
314{
315 u8 mask[8] = { 0x87, 0x0c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 };
316 struct sk_buff *skb;
317 int err;
318
319 if (debug)
320 mask[1] |= 0x62;
321
322 skb = __hci_cmd_sync(hdev, 0xfc52, 8, mask, HCI_INIT_TIMEOUT);
323 if (IS_ERR(skb)) {
324 err = PTR_ERR(skb);
Marcel Holtmann2064ee32017-10-30 10:42:59 +0100325 bt_dev_err(hdev, "Setting Intel event mask failed (%d)", err);
Marcel Holtmann213445b2015-10-21 02:45:19 +0200326 return err;
327 }
328 kfree_skb(skb);
329
330 return 0;
331}
332EXPORT_SYMBOL_GPL(btintel_set_event_mask);
333
334int btintel_set_event_mask_mfg(struct hci_dev *hdev, bool debug)
335{
Loic Poulain28dc4b92015-12-03 16:10:22 +0100336 int err, ret;
Marcel Holtmann213445b2015-10-21 02:45:19 +0200337
Loic Poulain28dc4b92015-12-03 16:10:22 +0100338 err = btintel_enter_mfg(hdev);
339 if (err)
340 return err;
Marcel Holtmann213445b2015-10-21 02:45:19 +0200341
Loic Poulain28dc4b92015-12-03 16:10:22 +0100342 ret = btintel_set_event_mask(hdev, debug);
Marcel Holtmann213445b2015-10-21 02:45:19 +0200343
Loic Poulain28dc4b92015-12-03 16:10:22 +0100344 err = btintel_exit_mfg(hdev, false, false);
345 if (err)
346 return err;
Marcel Holtmann213445b2015-10-21 02:45:19 +0200347
Loic Poulain28dc4b92015-12-03 16:10:22 +0100348 return ret;
Marcel Holtmann213445b2015-10-21 02:45:19 +0200349}
350EXPORT_SYMBOL_GPL(btintel_set_event_mask_mfg);
351
Loic Poulain6c483de2015-12-06 16:18:34 +0100352int btintel_read_version(struct hci_dev *hdev, struct intel_version *ver)
353{
354 struct sk_buff *skb;
355
356 skb = __hci_cmd_sync(hdev, 0xfc05, 0, NULL, HCI_CMD_TIMEOUT);
357 if (IS_ERR(skb)) {
358 bt_dev_err(hdev, "Reading Intel version information failed (%ld)",
359 PTR_ERR(skb));
360 return PTR_ERR(skb);
361 }
362
363 if (skb->len != sizeof(*ver)) {
364 bt_dev_err(hdev, "Intel version event size mismatch");
365 kfree_skb(skb);
366 return -EILSEQ;
367 }
368
369 memcpy(ver, skb->data, sizeof(*ver));
370
371 kfree_skb(skb);
372
373 return 0;
374}
375EXPORT_SYMBOL_GPL(btintel_read_version);
376
Loic Poulaind06f1072015-10-01 18:16:21 +0200377/* ------- REGMAP IBT SUPPORT ------- */
378
379#define IBT_REG_MODE_8BIT 0x00
380#define IBT_REG_MODE_16BIT 0x01
381#define IBT_REG_MODE_32BIT 0x02
382
383struct regmap_ibt_context {
384 struct hci_dev *hdev;
385 __u16 op_write;
386 __u16 op_read;
387};
388
389struct ibt_cp_reg_access {
390 __le32 addr;
391 __u8 mode;
392 __u8 len;
393 __u8 data[0];
394} __packed;
395
396struct ibt_rp_reg_access {
397 __u8 status;
398 __le32 addr;
399 __u8 data[0];
400} __packed;
401
402static int regmap_ibt_read(void *context, const void *addr, size_t reg_size,
403 void *val, size_t val_size)
404{
405 struct regmap_ibt_context *ctx = context;
406 struct ibt_cp_reg_access cp;
407 struct ibt_rp_reg_access *rp;
408 struct sk_buff *skb;
409 int err = 0;
410
411 if (reg_size != sizeof(__le32))
412 return -EINVAL;
413
414 switch (val_size) {
415 case 1:
416 cp.mode = IBT_REG_MODE_8BIT;
417 break;
418 case 2:
419 cp.mode = IBT_REG_MODE_16BIT;
420 break;
421 case 4:
422 cp.mode = IBT_REG_MODE_32BIT;
423 break;
424 default:
425 return -EINVAL;
426 }
427
428 /* regmap provides a little-endian formatted addr */
429 cp.addr = *(__le32 *)addr;
430 cp.len = val_size;
431
432 bt_dev_dbg(ctx->hdev, "Register (0x%x) read", le32_to_cpu(cp.addr));
433
434 skb = hci_cmd_sync(ctx->hdev, ctx->op_read, sizeof(cp), &cp,
435 HCI_CMD_TIMEOUT);
436 if (IS_ERR(skb)) {
437 err = PTR_ERR(skb);
438 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error (%d)",
439 le32_to_cpu(cp.addr), err);
440 return err;
441 }
442
443 if (skb->len != sizeof(*rp) + val_size) {
444 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad len",
445 le32_to_cpu(cp.addr));
446 err = -EINVAL;
447 goto done;
448 }
449
450 rp = (struct ibt_rp_reg_access *)skb->data;
451
452 if (rp->addr != cp.addr) {
453 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) read error, bad addr",
454 le32_to_cpu(rp->addr));
455 err = -EINVAL;
456 goto done;
457 }
458
459 memcpy(val, rp->data, val_size);
460
461done:
462 kfree_skb(skb);
463 return err;
464}
465
466static int regmap_ibt_gather_write(void *context,
467 const void *addr, size_t reg_size,
468 const void *val, size_t val_size)
469{
470 struct regmap_ibt_context *ctx = context;
471 struct ibt_cp_reg_access *cp;
472 struct sk_buff *skb;
473 int plen = sizeof(*cp) + val_size;
474 u8 mode;
475 int err = 0;
476
477 if (reg_size != sizeof(__le32))
478 return -EINVAL;
479
480 switch (val_size) {
481 case 1:
482 mode = IBT_REG_MODE_8BIT;
483 break;
484 case 2:
485 mode = IBT_REG_MODE_16BIT;
486 break;
487 case 4:
488 mode = IBT_REG_MODE_32BIT;
489 break;
490 default:
491 return -EINVAL;
492 }
493
494 cp = kmalloc(plen, GFP_KERNEL);
495 if (!cp)
496 return -ENOMEM;
497
498 /* regmap provides a little-endian formatted addr/value */
499 cp->addr = *(__le32 *)addr;
500 cp->mode = mode;
501 cp->len = val_size;
502 memcpy(&cp->data, val, val_size);
503
504 bt_dev_dbg(ctx->hdev, "Register (0x%x) write", le32_to_cpu(cp->addr));
505
506 skb = hci_cmd_sync(ctx->hdev, ctx->op_write, plen, cp, HCI_CMD_TIMEOUT);
507 if (IS_ERR(skb)) {
508 err = PTR_ERR(skb);
509 bt_dev_err(ctx->hdev, "regmap: Register (0x%x) write error (%d)",
510 le32_to_cpu(cp->addr), err);
511 goto done;
512 }
513 kfree_skb(skb);
514
515done:
516 kfree(cp);
517 return err;
518}
519
520static int regmap_ibt_write(void *context, const void *data, size_t count)
521{
522 /* data contains register+value, since we only support 32bit addr,
523 * minimum data size is 4 bytes.
524 */
525 if (WARN_ONCE(count < 4, "Invalid register access"))
526 return -EINVAL;
527
528 return regmap_ibt_gather_write(context, data, 4, data + 4, count - 4);
529}
530
531static void regmap_ibt_free_context(void *context)
532{
533 kfree(context);
534}
535
536static struct regmap_bus regmap_ibt = {
537 .read = regmap_ibt_read,
538 .write = regmap_ibt_write,
539 .gather_write = regmap_ibt_gather_write,
540 .free_context = regmap_ibt_free_context,
541 .reg_format_endian_default = REGMAP_ENDIAN_LITTLE,
542 .val_format_endian_default = REGMAP_ENDIAN_LITTLE,
543};
544
545/* Config is the same for all register regions */
546static const struct regmap_config regmap_ibt_cfg = {
547 .name = "btintel_regmap",
548 .reg_bits = 32,
549 .val_bits = 32,
550};
551
552struct regmap *btintel_regmap_init(struct hci_dev *hdev, u16 opcode_read,
553 u16 opcode_write)
554{
555 struct regmap_ibt_context *ctx;
556
557 bt_dev_info(hdev, "regmap: Init R%x-W%x region", opcode_read,
558 opcode_write);
559
560 ctx = kzalloc(sizeof(*ctx), GFP_KERNEL);
561 if (!ctx)
562 return ERR_PTR(-ENOMEM);
563
564 ctx->op_read = opcode_read;
565 ctx->op_write = opcode_write;
566 ctx->hdev = hdev;
567
568 return regmap_init(&hdev->dev, &regmap_ibt, ctx, &regmap_ibt_cfg);
569}
570EXPORT_SYMBOL_GPL(btintel_regmap_init);
571
Tedd Ho-Jeong Ane5889af2018-01-24 09:19:18 -0800572int btintel_send_intel_reset(struct hci_dev *hdev, u32 boot_param)
573{
574 struct intel_reset params = { 0x00, 0x01, 0x00, 0x01, 0x00000000 };
575 struct sk_buff *skb;
576
577 params.boot_param = cpu_to_le32(boot_param);
578
579 skb = __hci_cmd_sync(hdev, 0xfc01, sizeof(params), &params,
580 HCI_INIT_TIMEOUT);
581 if (IS_ERR(skb)) {
582 bt_dev_err(hdev, "Failed to send Intel Reset command");
583 return PTR_ERR(skb);
584 }
585
586 kfree_skb(skb);
587
588 return 0;
589}
590EXPORT_SYMBOL_GPL(btintel_send_intel_reset);
591
Tedd Ho-Jeong Anfaf174d2018-01-24 09:19:20 -0800592int btintel_read_boot_params(struct hci_dev *hdev,
593 struct intel_boot_params *params)
594{
595 struct sk_buff *skb;
596
597 skb = __hci_cmd_sync(hdev, 0xfc0d, 0, NULL, HCI_INIT_TIMEOUT);
598 if (IS_ERR(skb)) {
599 bt_dev_err(hdev, "Reading Intel boot parameters failed (%ld)",
600 PTR_ERR(skb));
601 return PTR_ERR(skb);
602 }
603
604 if (skb->len != sizeof(*params)) {
605 bt_dev_err(hdev, "Intel boot parameters size mismatch");
606 kfree_skb(skb);
607 return -EILSEQ;
608 }
609
610 memcpy(params, skb->data, sizeof(*params));
611
612 kfree_skb(skb);
613
614 if (params->status) {
615 bt_dev_err(hdev, "Intel boot parameters command failed (%02x)",
616 params->status);
617 return -bt_to_errno(params->status);
618 }
619
620 bt_dev_info(hdev, "Device revision is %u",
621 le16_to_cpu(params->dev_revid));
622
623 bt_dev_info(hdev, "Secure boot is %s",
624 params->secure_boot ? "enabled" : "disabled");
625
626 bt_dev_info(hdev, "OTP lock is %s",
627 params->otp_lock ? "enabled" : "disabled");
628
629 bt_dev_info(hdev, "API lock is %s",
630 params->api_lock ? "enabled" : "disabled");
631
632 bt_dev_info(hdev, "Debug lock is %s",
633 params->debug_lock ? "enabled" : "disabled");
634
635 bt_dev_info(hdev, "Minimum firmware build %u week %u %u",
636 params->min_fw_build_nn, params->min_fw_build_cw,
637 2000 + params->min_fw_build_yy);
638
639 return 0;
640}
641EXPORT_SYMBOL_GPL(btintel_read_boot_params);
642
Marcel Holtmann48f0ed12015-04-06 00:52:11 -0700643MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
644MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
645MODULE_VERSION(VERSION);
646MODULE_LICENSE("GPL");
Marcel Holtmann0ed97e82015-08-27 08:57:39 +0200647MODULE_FIRMWARE("intel/ibt-11-5.sfi");
648MODULE_FIRMWARE("intel/ibt-11-5.ddc");
Jürg Billeterd1b7aba2017-05-23 18:46:25 +0200649MODULE_FIRMWARE("intel/ibt-12-16.sfi");
650MODULE_FIRMWARE("intel/ibt-12-16.ddc");