btusb.c 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723
  1. /*
  2. *
  3. * Generic Bluetooth USB driver
  4. *
  5. * Copyright (C) 2005-2007 Marcel Holtmann <marcel@holtmann.org>
  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/kernel.h>
  24. #include <linux/module.h>
  25. #include <linux/init.h>
  26. #include <linux/slab.h>
  27. #include <linux/types.h>
  28. #include <linux/sched.h>
  29. #include <linux/errno.h>
  30. #include <linux/skbuff.h>
  31. #include <linux/usb.h>
  32. #include <net/bluetooth/bluetooth.h>
  33. #include <net/bluetooth/hci_core.h>
  34. //#define CONFIG_BT_HCIBTUSB_DEBUG
  35. #ifndef CONFIG_BT_HCIBTUSB_DEBUG
  36. #undef BT_DBG
  37. #define BT_DBG(D...)
  38. #endif
  39. #define VERSION "0.2"
  40. static int ignore_dga;
  41. static int ignore_csr;
  42. static int ignore_sniffer;
  43. static int disable_scofix;
  44. static int force_scofix;
  45. static int reset;
  46. static struct usb_driver btusb_driver;
  47. #define BTUSB_IGNORE 0x01
  48. #define BTUSB_RESET 0x02
  49. #define BTUSB_DIGIANSWER 0x04
  50. #define BTUSB_CSR 0x08
  51. #define BTUSB_SNIFFER 0x10
  52. #define BTUSB_BCM92035 0x20
  53. #define BTUSB_BROKEN_ISOC 0x40
  54. #define BTUSB_WRONG_SCO_MTU 0x80
  55. static struct usb_device_id btusb_table[] = {
  56. /* Generic Bluetooth USB device */
  57. { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
  58. /* AVM BlueFRITZ! USB v2.0 */
  59. { USB_DEVICE(0x057c, 0x3800) },
  60. /* Bluetooth Ultraport Module from IBM */
  61. { USB_DEVICE(0x04bf, 0x030a) },
  62. /* ALPS Modules with non-standard id */
  63. { USB_DEVICE(0x044e, 0x3001) },
  64. { USB_DEVICE(0x044e, 0x3002) },
  65. /* Ericsson with non-standard id */
  66. { USB_DEVICE(0x0bdb, 0x1002) },
  67. /* Canyon CN-BTU1 with HID interfaces */
  68. { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_RESET },
  69. { } /* Terminating entry */
  70. };
  71. MODULE_DEVICE_TABLE(usb, btusb_table);
  72. static struct usb_device_id blacklist_table[] = {
  73. /* CSR BlueCore devices */
  74. { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
  75. /* Broadcom BCM2033 without firmware */
  76. { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
  77. /* Broadcom BCM2035 */
  78. { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  79. { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  80. /* Broadcom BCM2045 */
  81. { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  82. { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  83. /* Broadcom BCM2046 */
  84. { USB_DEVICE(0x0a5c, 0x2151), .driver_info = BTUSB_RESET },
  85. /* IBM/Lenovo ThinkPad with Broadcom chip */
  86. { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  87. { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  88. /* Targus ACB10US */
  89. { USB_DEVICE(0x0a5c, 0x2100), .driver_info = BTUSB_RESET },
  90. /* ANYCOM Bluetooth USB-200 and USB-250 */
  91. { USB_DEVICE(0x0a5c, 0x2111), .driver_info = BTUSB_RESET },
  92. /* HP laptop with Broadcom chip */
  93. { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  94. /* Dell laptop with Broadcom chip */
  95. { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  96. /* Dell Wireless 370 */
  97. { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  98. /* Dell Wireless 410 */
  99. { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  100. /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
  101. { USB_DEVICE(0x045e, 0x009c), .driver_info = BTUSB_RESET },
  102. /* Kensington Bluetooth USB adapter */
  103. { USB_DEVICE(0x047d, 0x105d), .driver_info = BTUSB_RESET },
  104. { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  105. /* ISSC Bluetooth Adapter v3.1 */
  106. { USB_DEVICE(0x1131, 0x1001), .driver_info = BTUSB_RESET },
  107. /* RTX Telecom based adapters with buggy SCO support */
  108. { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
  109. { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
  110. /* CONWISE Technology based adapters with buggy SCO support */
  111. { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
  112. /* Belkin F8T012 and F8T013 devices */
  113. { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  114. { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
  115. /* Digianswer devices */
  116. { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
  117. { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
  118. /* CSR BlueCore Bluetooth Sniffer */
  119. { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
  120. /* Frontline ComProbe Bluetooth Sniffer */
  121. { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
  122. { } /* Terminating entry */
  123. };
  124. #define BTUSB_INTR_RUNNING 0
  125. #define BTUSB_BULK_RUNNING 1
  126. struct btusb_data {
  127. struct hci_dev *hdev;
  128. struct usb_device *udev;
  129. spinlock_t lock;
  130. unsigned long flags;
  131. struct work_struct work;
  132. struct usb_anchor tx_anchor;
  133. struct usb_anchor intr_anchor;
  134. struct usb_anchor bulk_anchor;
  135. struct usb_endpoint_descriptor *intr_ep;
  136. struct usb_endpoint_descriptor *bulk_tx_ep;
  137. struct usb_endpoint_descriptor *bulk_rx_ep;
  138. };
  139. static void btusb_intr_complete(struct urb *urb)
  140. {
  141. struct hci_dev *hdev = urb->context;
  142. struct btusb_data *data = hdev->driver_data;
  143. int err;
  144. BT_DBG("%s urb %p status %d count %d", hdev->name,
  145. urb, urb->status, urb->actual_length);
  146. if (!test_bit(HCI_RUNNING, &hdev->flags))
  147. return;
  148. if (urb->status == 0) {
  149. if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
  150. urb->transfer_buffer,
  151. urb->actual_length) < 0) {
  152. BT_ERR("%s corrupted event packet", hdev->name);
  153. hdev->stat.err_rx++;
  154. }
  155. }
  156. if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
  157. return;
  158. usb_anchor_urb(urb, &data->intr_anchor);
  159. err = usb_submit_urb(urb, GFP_ATOMIC);
  160. if (err < 0) {
  161. BT_ERR("%s urb %p failed to resubmit (%d)",
  162. hdev->name, urb, -err);
  163. usb_unanchor_urb(urb);
  164. }
  165. }
  166. static inline int btusb_submit_intr_urb(struct hci_dev *hdev)
  167. {
  168. struct btusb_data *data = hdev->driver_data;
  169. struct urb *urb;
  170. unsigned char *buf;
  171. unsigned int pipe;
  172. int err, size;
  173. BT_DBG("%s", hdev->name);
  174. urb = usb_alloc_urb(0, GFP_ATOMIC);
  175. if (!urb)
  176. return -ENOMEM;
  177. size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
  178. buf = kmalloc(size, GFP_ATOMIC);
  179. if (!buf) {
  180. usb_free_urb(urb);
  181. return -ENOMEM;
  182. }
  183. pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
  184. usb_fill_int_urb(urb, data->udev, pipe, buf, size,
  185. btusb_intr_complete, hdev,
  186. data->intr_ep->bInterval);
  187. urb->transfer_flags |= URB_FREE_BUFFER;
  188. usb_anchor_urb(urb, &data->intr_anchor);
  189. err = usb_submit_urb(urb, GFP_ATOMIC);
  190. if (err < 0) {
  191. BT_ERR("%s urb %p submission failed (%d)",
  192. hdev->name, urb, -err);
  193. usb_unanchor_urb(urb);
  194. kfree(buf);
  195. }
  196. usb_free_urb(urb);
  197. return err;
  198. }
  199. static void btusb_bulk_complete(struct urb *urb)
  200. {
  201. struct hci_dev *hdev = urb->context;
  202. struct btusb_data *data = hdev->driver_data;
  203. int err;
  204. BT_DBG("%s urb %p status %d count %d", hdev->name,
  205. urb, urb->status, urb->actual_length);
  206. if (!test_bit(HCI_RUNNING, &hdev->flags))
  207. return;
  208. if (urb->status == 0) {
  209. if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
  210. urb->transfer_buffer,
  211. urb->actual_length) < 0) {
  212. BT_ERR("%s corrupted ACL packet", hdev->name);
  213. hdev->stat.err_rx++;
  214. }
  215. }
  216. if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
  217. return;
  218. usb_anchor_urb(urb, &data->bulk_anchor);
  219. err = usb_submit_urb(urb, GFP_ATOMIC);
  220. if (err < 0) {
  221. BT_ERR("%s urb %p failed to resubmit (%d)",
  222. hdev->name, urb, -err);
  223. usb_unanchor_urb(urb);
  224. }
  225. }
  226. static inline int btusb_submit_bulk_urb(struct hci_dev *hdev)
  227. {
  228. struct btusb_data *data = hdev->driver_data;
  229. struct urb *urb;
  230. unsigned char *buf;
  231. unsigned int pipe;
  232. int err, size;
  233. BT_DBG("%s", hdev->name);
  234. urb = usb_alloc_urb(0, GFP_KERNEL);
  235. if (!urb)
  236. return -ENOMEM;
  237. size = le16_to_cpu(data->bulk_rx_ep->wMaxPacketSize);
  238. buf = kmalloc(size, GFP_KERNEL);
  239. if (!buf) {
  240. usb_free_urb(urb);
  241. return -ENOMEM;
  242. }
  243. pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
  244. usb_fill_bulk_urb(urb, data->udev, pipe,
  245. buf, size, btusb_bulk_complete, hdev);
  246. urb->transfer_flags |= URB_FREE_BUFFER;
  247. usb_anchor_urb(urb, &data->bulk_anchor);
  248. err = usb_submit_urb(urb, GFP_KERNEL);
  249. if (err < 0) {
  250. BT_ERR("%s urb %p submission failed (%d)",
  251. hdev->name, urb, -err);
  252. usb_unanchor_urb(urb);
  253. kfree(buf);
  254. }
  255. usb_free_urb(urb);
  256. return err;
  257. }
  258. static void btusb_tx_complete(struct urb *urb)
  259. {
  260. struct sk_buff *skb = urb->context;
  261. struct hci_dev *hdev = (struct hci_dev *) skb->dev;
  262. BT_DBG("%s urb %p status %d count %d", hdev->name,
  263. urb, urb->status, urb->actual_length);
  264. if (!test_bit(HCI_RUNNING, &hdev->flags))
  265. goto done;
  266. if (!urb->status)
  267. hdev->stat.byte_tx += urb->transfer_buffer_length;
  268. else
  269. hdev->stat.err_tx++;
  270. done:
  271. kfree(urb->setup_packet);
  272. kfree_skb(skb);
  273. }
  274. static int btusb_open(struct hci_dev *hdev)
  275. {
  276. struct btusb_data *data = hdev->driver_data;
  277. int err;
  278. BT_DBG("%s", hdev->name);
  279. if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
  280. return 0;
  281. if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
  282. return 0;
  283. err = btusb_submit_intr_urb(hdev);
  284. if (err < 0) {
  285. clear_bit(BTUSB_INTR_RUNNING, &hdev->flags);
  286. clear_bit(HCI_RUNNING, &hdev->flags);
  287. }
  288. return err;
  289. }
  290. static int btusb_close(struct hci_dev *hdev)
  291. {
  292. struct btusb_data *data = hdev->driver_data;
  293. BT_DBG("%s", hdev->name);
  294. if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
  295. return 0;
  296. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  297. usb_kill_anchored_urbs(&data->bulk_anchor);
  298. clear_bit(BTUSB_INTR_RUNNING, &data->flags);
  299. usb_kill_anchored_urbs(&data->intr_anchor);
  300. return 0;
  301. }
  302. static int btusb_flush(struct hci_dev *hdev)
  303. {
  304. struct btusb_data *data = hdev->driver_data;
  305. BT_DBG("%s", hdev->name);
  306. usb_kill_anchored_urbs(&data->tx_anchor);
  307. return 0;
  308. }
  309. static int btusb_send_frame(struct sk_buff *skb)
  310. {
  311. struct hci_dev *hdev = (struct hci_dev *) skb->dev;
  312. struct btusb_data *data = hdev->driver_data;
  313. struct usb_ctrlrequest *dr;
  314. struct urb *urb;
  315. unsigned int pipe;
  316. int err;
  317. BT_DBG("%s", hdev->name);
  318. if (!test_bit(HCI_RUNNING, &hdev->flags))
  319. return -EBUSY;
  320. switch (bt_cb(skb)->pkt_type) {
  321. case HCI_COMMAND_PKT:
  322. urb = usb_alloc_urb(0, GFP_ATOMIC);
  323. if (!urb)
  324. return -ENOMEM;
  325. dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
  326. if (!dr) {
  327. usb_free_urb(urb);
  328. return -ENOMEM;
  329. }
  330. dr->bRequestType = USB_TYPE_CLASS;
  331. dr->bRequest = 0;
  332. dr->wIndex = 0;
  333. dr->wValue = 0;
  334. dr->wLength = __cpu_to_le16(skb->len);
  335. pipe = usb_sndctrlpipe(data->udev, 0x00);
  336. usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
  337. skb->data, skb->len, btusb_tx_complete, skb);
  338. hdev->stat.cmd_tx++;
  339. break;
  340. case HCI_ACLDATA_PKT:
  341. urb = usb_alloc_urb(0, GFP_ATOMIC);
  342. if (!urb)
  343. return -ENOMEM;
  344. pipe = usb_sndbulkpipe(data->udev,
  345. data->bulk_tx_ep->bEndpointAddress);
  346. usb_fill_bulk_urb(urb, data->udev, pipe,
  347. skb->data, skb->len, btusb_tx_complete, skb);
  348. hdev->stat.acl_tx++;
  349. break;
  350. case HCI_SCODATA_PKT:
  351. hdev->stat.sco_tx++;
  352. kfree_skb(skb);
  353. return 0;
  354. default:
  355. return -EILSEQ;
  356. }
  357. usb_anchor_urb(urb, &data->tx_anchor);
  358. err = usb_submit_urb(urb, GFP_ATOMIC);
  359. if (err < 0) {
  360. BT_ERR("%s urb %p submission failed", hdev->name, urb);
  361. kfree(urb->setup_packet);
  362. usb_unanchor_urb(urb);
  363. }
  364. usb_free_urb(urb);
  365. return err;
  366. }
  367. static void btusb_destruct(struct hci_dev *hdev)
  368. {
  369. struct btusb_data *data = hdev->driver_data;
  370. BT_DBG("%s", hdev->name);
  371. kfree(data);
  372. }
  373. static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
  374. {
  375. struct btusb_data *data = hdev->driver_data;
  376. BT_DBG("%s evt %d", hdev->name, evt);
  377. if (evt == HCI_NOTIFY_CONN_ADD || evt == HCI_NOTIFY_CONN_DEL)
  378. schedule_work(&data->work);
  379. }
  380. static void btusb_work(struct work_struct *work)
  381. {
  382. struct btusb_data *data = container_of(work, struct btusb_data, work);
  383. struct hci_dev *hdev = data->hdev;
  384. if (hdev->conn_hash.acl_num == 0) {
  385. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  386. usb_kill_anchored_urbs(&data->bulk_anchor);
  387. return;
  388. }
  389. if (!test_and_set_bit(BTUSB_BULK_RUNNING, &data->flags)) {
  390. if (btusb_submit_bulk_urb(hdev) < 0)
  391. clear_bit(BTUSB_BULK_RUNNING, &data->flags);
  392. else
  393. btusb_submit_bulk_urb(hdev);
  394. }
  395. }
  396. static int btusb_probe(struct usb_interface *intf,
  397. const struct usb_device_id *id)
  398. {
  399. struct usb_endpoint_descriptor *ep_desc;
  400. struct btusb_data *data;
  401. struct hci_dev *hdev;
  402. int i, err;
  403. BT_DBG("intf %p id %p", intf, id);
  404. /* interface numbers are hardcoded in the spec */
  405. if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
  406. return -ENODEV;
  407. if (!id->driver_info) {
  408. const struct usb_device_id *match;
  409. match = usb_match_id(intf, blacklist_table);
  410. if (match)
  411. id = match;
  412. }
  413. if (id->driver_info == BTUSB_IGNORE)
  414. return -ENODEV;
  415. if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
  416. return -ENODEV;
  417. if (ignore_csr && id->driver_info & BTUSB_CSR)
  418. return -ENODEV;
  419. if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
  420. return -ENODEV;
  421. data = kzalloc(sizeof(*data), GFP_KERNEL);
  422. if (!data)
  423. return -ENOMEM;
  424. for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
  425. ep_desc = &intf->cur_altsetting->endpoint[i].desc;
  426. if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
  427. data->intr_ep = ep_desc;
  428. continue;
  429. }
  430. if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
  431. data->bulk_tx_ep = ep_desc;
  432. continue;
  433. }
  434. if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
  435. data->bulk_rx_ep = ep_desc;
  436. continue;
  437. }
  438. }
  439. if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
  440. kfree(data);
  441. return -ENODEV;
  442. }
  443. data->udev = interface_to_usbdev(intf);
  444. spin_lock_init(&data->lock);
  445. INIT_WORK(&data->work, btusb_work);
  446. init_usb_anchor(&data->tx_anchor);
  447. init_usb_anchor(&data->intr_anchor);
  448. init_usb_anchor(&data->bulk_anchor);
  449. hdev = hci_alloc_dev();
  450. if (!hdev) {
  451. kfree(data);
  452. return -ENOMEM;
  453. }
  454. hdev->type = HCI_USB;
  455. hdev->driver_data = data;
  456. data->hdev = hdev;
  457. SET_HCIDEV_DEV(hdev, &intf->dev);
  458. hdev->open = btusb_open;
  459. hdev->close = btusb_close;
  460. hdev->flush = btusb_flush;
  461. hdev->send = btusb_send_frame;
  462. hdev->destruct = btusb_destruct;
  463. hdev->notify = btusb_notify;
  464. hdev->owner = THIS_MODULE;
  465. if (reset || id->driver_info & BTUSB_RESET)
  466. set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks);
  467. if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
  468. if (!disable_scofix)
  469. set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
  470. }
  471. if (id->driver_info & BTUSB_SNIFFER) {
  472. struct usb_device *udev = interface_to_usbdev(intf);
  473. if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
  474. set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
  475. }
  476. if (id->driver_info & BTUSB_BCM92035) {
  477. unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
  478. struct sk_buff *skb;
  479. skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
  480. if (skb) {
  481. memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
  482. skb_queue_tail(&hdev->driver_init, skb);
  483. }
  484. }
  485. err = hci_register_dev(hdev);
  486. if (err < 0) {
  487. hci_free_dev(hdev);
  488. kfree(data);
  489. return err;
  490. }
  491. usb_set_intfdata(intf, data);
  492. return 0;
  493. }
  494. static void btusb_disconnect(struct usb_interface *intf)
  495. {
  496. struct btusb_data *data = usb_get_intfdata(intf);
  497. struct hci_dev *hdev;
  498. BT_DBG("intf %p", intf);
  499. if (!data)
  500. return;
  501. hdev = data->hdev;
  502. usb_set_intfdata(intf, NULL);
  503. hci_unregister_dev(hdev);
  504. hci_free_dev(hdev);
  505. }
  506. static struct usb_driver btusb_driver = {
  507. .name = "btusb",
  508. .probe = btusb_probe,
  509. .disconnect = btusb_disconnect,
  510. .id_table = btusb_table,
  511. };
  512. static int __init btusb_init(void)
  513. {
  514. BT_INFO("Generic Bluetooth USB driver ver %s", VERSION);
  515. return usb_register(&btusb_driver);
  516. }
  517. static void __exit btusb_exit(void)
  518. {
  519. usb_deregister(&btusb_driver);
  520. }
  521. module_init(btusb_init);
  522. module_exit(btusb_exit);
  523. module_param(ignore_dga, bool, 0644);
  524. MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
  525. module_param(ignore_csr, bool, 0644);
  526. MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
  527. module_param(ignore_sniffer, bool, 0644);
  528. MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
  529. module_param(disable_scofix, bool, 0644);
  530. MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
  531. module_param(force_scofix, bool, 0644);
  532. MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
  533. module_param(reset, bool, 0644);
  534. MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
  535. MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
  536. MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
  537. MODULE_VERSION(VERSION);
  538. MODULE_LICENSE("GPL");