btintel.c 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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 <net/bluetooth/bluetooth.h>
  25. #include <net/bluetooth/hci_core.h>
  26. #include "btintel.h"
  27. #define VERSION "0.1"
  28. #define BDADDR_INTEL (&(bdaddr_t) {{0x00, 0x8b, 0x9e, 0x19, 0x03, 0x00}})
  29. int btintel_check_bdaddr(struct hci_dev *hdev)
  30. {
  31. struct hci_rp_read_bd_addr *bda;
  32. struct sk_buff *skb;
  33. skb = __hci_cmd_sync(hdev, HCI_OP_READ_BD_ADDR, 0, NULL,
  34. HCI_INIT_TIMEOUT);
  35. if (IS_ERR(skb)) {
  36. int err = PTR_ERR(skb);
  37. BT_ERR("%s: Reading Intel device address failed (%d)",
  38. hdev->name, err);
  39. return err;
  40. }
  41. if (skb->len != sizeof(*bda)) {
  42. BT_ERR("%s: Intel device address length mismatch", hdev->name);
  43. kfree_skb(skb);
  44. return -EIO;
  45. }
  46. bda = (struct hci_rp_read_bd_addr *)skb->data;
  47. /* For some Intel based controllers, the default Bluetooth device
  48. * address 00:03:19:9E:8B:00 can be found. These controllers are
  49. * fully operational, but have the danger of duplicate addresses
  50. * and that in turn can cause problems with Bluetooth operation.
  51. */
  52. if (!bacmp(&bda->bdaddr, BDADDR_INTEL)) {
  53. BT_ERR("%s: Found Intel default device address (%pMR)",
  54. hdev->name, &bda->bdaddr);
  55. set_bit(HCI_QUIRK_INVALID_BDADDR, &hdev->quirks);
  56. }
  57. kfree_skb(skb);
  58. return 0;
  59. }
  60. EXPORT_SYMBOL_GPL(btintel_check_bdaddr);
  61. int btintel_set_bdaddr(struct hci_dev *hdev, const bdaddr_t *bdaddr)
  62. {
  63. struct sk_buff *skb;
  64. int err;
  65. skb = __hci_cmd_sync(hdev, 0xfc31, 6, bdaddr, HCI_INIT_TIMEOUT);
  66. if (IS_ERR(skb)) {
  67. err = PTR_ERR(skb);
  68. BT_ERR("%s: Changing Intel device address failed (%d)",
  69. hdev->name, err);
  70. return err;
  71. }
  72. kfree_skb(skb);
  73. return 0;
  74. }
  75. EXPORT_SYMBOL_GPL(btintel_set_bdaddr);
  76. void btintel_hw_error(struct hci_dev *hdev, u8 code)
  77. {
  78. struct sk_buff *skb;
  79. u8 type = 0x00;
  80. BT_ERR("%s: Hardware error 0x%2.2x", hdev->name, code);
  81. skb = __hci_cmd_sync(hdev, HCI_OP_RESET, 0, NULL, HCI_INIT_TIMEOUT);
  82. if (IS_ERR(skb)) {
  83. BT_ERR("%s: Reset after hardware error failed (%ld)",
  84. hdev->name, PTR_ERR(skb));
  85. return;
  86. }
  87. kfree_skb(skb);
  88. skb = __hci_cmd_sync(hdev, 0xfc22, 1, &type, HCI_INIT_TIMEOUT);
  89. if (IS_ERR(skb)) {
  90. BT_ERR("%s: Retrieving Intel exception info failed (%ld)",
  91. hdev->name, PTR_ERR(skb));
  92. return;
  93. }
  94. if (skb->len != 13) {
  95. BT_ERR("%s: Exception info size mismatch", hdev->name);
  96. kfree_skb(skb);
  97. return;
  98. }
  99. BT_ERR("%s: Exception info %s", hdev->name, (char *)(skb->data + 1));
  100. kfree_skb(skb);
  101. }
  102. EXPORT_SYMBOL_GPL(btintel_hw_error);
  103. int btintel_secure_send(struct hci_dev *hdev, u8 fragment_type, u32 plen,
  104. const void *param)
  105. {
  106. while (plen > 0) {
  107. struct sk_buff *skb;
  108. u8 cmd_param[253], fragment_len = (plen > 252) ? 252 : plen;
  109. cmd_param[0] = fragment_type;
  110. memcpy(cmd_param + 1, param, fragment_len);
  111. skb = __hci_cmd_sync(hdev, 0xfc09, fragment_len + 1,
  112. cmd_param, HCI_INIT_TIMEOUT);
  113. if (IS_ERR(skb))
  114. return PTR_ERR(skb);
  115. kfree_skb(skb);
  116. plen -= fragment_len;
  117. param += fragment_len;
  118. }
  119. return 0;
  120. }
  121. EXPORT_SYMBOL_GPL(btintel_secure_send);
  122. MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
  123. MODULE_DESCRIPTION("Bluetooth support for Intel devices ver " VERSION);
  124. MODULE_VERSION(VERSION);
  125. MODULE_LICENSE("GPL");