3 * Generic Bluetooth USB driver
5 * Copyright (C) 2005-2008 Marcel Holtmann <marcel@holtmann.org>
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.
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.
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
24 #include <linux/kernel.h>
25 #include <linux/module.h>
26 #include <linux/init.h>
27 #include <linux/slab.h>
28 #include <linux/types.h>
29 #include <linux/sched.h>
30 #include <linux/errno.h>
31 #include <linux/skbuff.h>
33 #include <linux/usb.h>
35 #include <net/bluetooth/bluetooth.h>
36 #include <net/bluetooth/hci_core.h>
38 //#define CONFIG_BT_HCIBTUSB_DEBUG
39 #ifndef CONFIG_BT_HCIBTUSB_DEBUG
46 static int ignore_dga;
47 static int ignore_csr;
48 static int ignore_sniffer;
49 static int disable_scofix;
50 static int force_scofix;
53 static struct usb_driver btusb_driver;
55 #define BTUSB_IGNORE 0x01
56 #define BTUSB_RESET 0x02
57 #define BTUSB_DIGIANSWER 0x04
58 #define BTUSB_CSR 0x08
59 #define BTUSB_SNIFFER 0x10
60 #define BTUSB_BCM92035 0x20
61 #define BTUSB_BROKEN_ISOC 0x40
62 #define BTUSB_WRONG_SCO_MTU 0x80
64 static struct usb_device_id btusb_table[] = {
65 /* Generic Bluetooth USB device */
66 { USB_DEVICE_INFO(0xe0, 0x01, 0x01) },
68 /* AVM BlueFRITZ! USB v2.0 */
69 { USB_DEVICE(0x057c, 0x3800) },
71 /* Bluetooth Ultraport Module from IBM */
72 { USB_DEVICE(0x04bf, 0x030a) },
74 /* ALPS Modules with non-standard id */
75 { USB_DEVICE(0x044e, 0x3001) },
76 { USB_DEVICE(0x044e, 0x3002) },
78 /* Ericsson with non-standard id */
79 { USB_DEVICE(0x0bdb, 0x1002) },
81 /* Canyon CN-BTU1 with HID interfaces */
82 { USB_DEVICE(0x0c10, 0x0000), .driver_info = BTUSB_RESET },
84 { } /* Terminating entry */
87 MODULE_DEVICE_TABLE(usb, btusb_table);
89 static struct usb_device_id blacklist_table[] = {
90 /* CSR BlueCore devices */
91 { USB_DEVICE(0x0a12, 0x0001), .driver_info = BTUSB_CSR },
93 /* Broadcom BCM2033 without firmware */
94 { USB_DEVICE(0x0a5c, 0x2033), .driver_info = BTUSB_IGNORE },
96 /* Broadcom BCM2035 */
97 { USB_DEVICE(0x0a5c, 0x2035), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
98 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
100 /* Broadcom BCM2045 */
101 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
102 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
104 /* Broadcom BCM2046 */
105 { USB_DEVICE(0x0a5c, 0x2151), .driver_info = BTUSB_RESET },
107 /* Apple MacBook Pro with Broadcom chip */
108 { USB_DEVICE(0x05ac, 0x820f), .driver_info = BTUSB_RESET },
110 /* IBM/Lenovo ThinkPad with Broadcom chip */
111 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
112 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
115 { USB_DEVICE(0x0a5c, 0x2100), .driver_info = BTUSB_RESET },
116 { USB_DEVICE(0x0a5c, 0x2154), .driver_info = BTUSB_RESET },
118 /* ANYCOM Bluetooth USB-200 and USB-250 */
119 { USB_DEVICE(0x0a5c, 0x2111), .driver_info = BTUSB_RESET },
121 /* HP laptop with Broadcom chip */
122 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
124 /* Dell laptop with Broadcom chip */
125 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
127 /* Dell Wireless 370 */
128 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
130 /* Dell Wireless 410 */
131 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
133 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
134 { USB_DEVICE(0x045e, 0x009c), .driver_info = BTUSB_RESET },
136 /* Kensington Bluetooth USB adapter */
137 { USB_DEVICE(0x047d, 0x105d), .driver_info = BTUSB_RESET },
138 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
140 /* ISSC Bluetooth Adapter v3.1 */
141 { USB_DEVICE(0x1131, 0x1001), .driver_info = BTUSB_RESET },
143 /* RTX Telecom based adapters with buggy SCO support */
144 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
145 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
147 /* CONWISE Technology based adapters with buggy SCO support */
148 { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
150 /* Belkin F8T012 and F8T013 devices */
151 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
152 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_RESET | BTUSB_WRONG_SCO_MTU },
154 /* Belkin F8T016 device */
155 { USB_DEVICE(0x050d, 0x016a), .driver_info = BTUSB_RESET },
157 /* Digianswer devices */
158 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
159 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
161 /* CSR BlueCore Bluetooth Sniffer */
162 { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
164 /* Frontline ComProbe Bluetooth Sniffer */
165 { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
167 { } /* Terminating entry */
170 #define BTUSB_MAX_ISOC_FRAMES 10
172 #define BTUSB_INTR_RUNNING 0
173 #define BTUSB_BULK_RUNNING 1
174 #define BTUSB_ISOC_RUNNING 2
177 struct hci_dev *hdev;
178 struct usb_device *udev;
179 struct usb_interface *intf;
180 struct usb_interface *isoc;
186 struct work_struct work;
188 struct usb_anchor tx_anchor;
189 struct usb_anchor intr_anchor;
190 struct usb_anchor bulk_anchor;
191 struct usb_anchor isoc_anchor;
193 struct usb_endpoint_descriptor *intr_ep;
194 struct usb_endpoint_descriptor *bulk_tx_ep;
195 struct usb_endpoint_descriptor *bulk_rx_ep;
196 struct usb_endpoint_descriptor *isoc_tx_ep;
197 struct usb_endpoint_descriptor *isoc_rx_ep;
202 static void btusb_intr_complete(struct urb *urb)
204 struct hci_dev *hdev = urb->context;
205 struct btusb_data *data = hdev->driver_data;
208 BT_DBG("%s urb %p status %d count %d", hdev->name,
209 urb, urb->status, urb->actual_length);
211 if (!test_bit(HCI_RUNNING, &hdev->flags))
214 if (urb->status == 0) {
215 hdev->stat.byte_rx += urb->actual_length;
217 if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
218 urb->transfer_buffer,
219 urb->actual_length) < 0) {
220 BT_ERR("%s corrupted event packet", hdev->name);
225 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
228 usb_anchor_urb(urb, &data->intr_anchor);
230 err = usb_submit_urb(urb, GFP_ATOMIC);
232 BT_ERR("%s urb %p failed to resubmit (%d)",
233 hdev->name, urb, -err);
234 usb_unanchor_urb(urb);
238 static int btusb_submit_intr_urb(struct hci_dev *hdev)
240 struct btusb_data *data = hdev->driver_data;
246 BT_DBG("%s", hdev->name);
251 urb = usb_alloc_urb(0, GFP_ATOMIC);
255 size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
257 buf = kmalloc(size, GFP_ATOMIC);
263 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
265 usb_fill_int_urb(urb, data->udev, pipe, buf, size,
266 btusb_intr_complete, hdev,
267 data->intr_ep->bInterval);
269 urb->transfer_flags |= URB_FREE_BUFFER;
271 usb_anchor_urb(urb, &data->intr_anchor);
273 err = usb_submit_urb(urb, GFP_ATOMIC);
275 BT_ERR("%s urb %p submission failed (%d)",
276 hdev->name, urb, -err);
277 usb_unanchor_urb(urb);
285 static void btusb_bulk_complete(struct urb *urb)
287 struct hci_dev *hdev = urb->context;
288 struct btusb_data *data = hdev->driver_data;
291 BT_DBG("%s urb %p status %d count %d", hdev->name,
292 urb, urb->status, urb->actual_length);
294 if (!test_bit(HCI_RUNNING, &hdev->flags))
297 if (urb->status == 0) {
298 hdev->stat.byte_rx += urb->actual_length;
300 if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
301 urb->transfer_buffer,
302 urb->actual_length) < 0) {
303 BT_ERR("%s corrupted ACL packet", hdev->name);
308 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
311 usb_anchor_urb(urb, &data->bulk_anchor);
313 err = usb_submit_urb(urb, GFP_ATOMIC);
315 BT_ERR("%s urb %p failed to resubmit (%d)",
316 hdev->name, urb, -err);
317 usb_unanchor_urb(urb);
321 static int btusb_submit_bulk_urb(struct hci_dev *hdev)
323 struct btusb_data *data = hdev->driver_data;
329 BT_DBG("%s", hdev->name);
331 if (!data->bulk_rx_ep)
334 urb = usb_alloc_urb(0, GFP_KERNEL);
338 size = le16_to_cpu(data->bulk_rx_ep->wMaxPacketSize);
340 buf = kmalloc(size, GFP_KERNEL);
346 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
348 usb_fill_bulk_urb(urb, data->udev, pipe,
349 buf, size, btusb_bulk_complete, hdev);
351 urb->transfer_flags |= URB_FREE_BUFFER;
353 usb_anchor_urb(urb, &data->bulk_anchor);
355 err = usb_submit_urb(urb, GFP_KERNEL);
357 BT_ERR("%s urb %p submission failed (%d)",
358 hdev->name, urb, -err);
359 usb_unanchor_urb(urb);
367 static void btusb_isoc_complete(struct urb *urb)
369 struct hci_dev *hdev = urb->context;
370 struct btusb_data *data = hdev->driver_data;
373 BT_DBG("%s urb %p status %d count %d", hdev->name,
374 urb, urb->status, urb->actual_length);
376 if (!test_bit(HCI_RUNNING, &hdev->flags))
379 if (urb->status == 0) {
380 for (i = 0; i < urb->number_of_packets; i++) {
381 unsigned int offset = urb->iso_frame_desc[i].offset;
382 unsigned int length = urb->iso_frame_desc[i].actual_length;
384 if (urb->iso_frame_desc[i].status)
387 hdev->stat.byte_rx += length;
389 if (hci_recv_fragment(hdev, HCI_SCODATA_PKT,
390 urb->transfer_buffer + offset,
392 BT_ERR("%s corrupted SCO packet", hdev->name);
398 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
401 usb_anchor_urb(urb, &data->isoc_anchor);
403 err = usb_submit_urb(urb, GFP_ATOMIC);
405 BT_ERR("%s urb %p failed to resubmit (%d)",
406 hdev->name, urb, -err);
407 usb_unanchor_urb(urb);
411 static void inline __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
415 BT_DBG("len %d mtu %d", len, mtu);
417 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
418 i++, offset += mtu, len -= mtu) {
419 urb->iso_frame_desc[i].offset = offset;
420 urb->iso_frame_desc[i].length = mtu;
423 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
424 urb->iso_frame_desc[i].offset = offset;
425 urb->iso_frame_desc[i].length = len;
429 urb->number_of_packets = i;
432 static int btusb_submit_isoc_urb(struct hci_dev *hdev)
434 struct btusb_data *data = hdev->driver_data;
440 BT_DBG("%s", hdev->name);
442 if (!data->isoc_rx_ep)
445 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_KERNEL);
449 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
450 BTUSB_MAX_ISOC_FRAMES;
452 buf = kmalloc(size, GFP_KERNEL);
458 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
460 urb->dev = data->udev;
463 urb->complete = btusb_isoc_complete;
464 urb->interval = data->isoc_rx_ep->bInterval;
466 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
467 urb->transfer_buffer = buf;
468 urb->transfer_buffer_length = size;
470 __fill_isoc_descriptor(urb, size,
471 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
473 usb_anchor_urb(urb, &data->isoc_anchor);
475 err = usb_submit_urb(urb, GFP_KERNEL);
477 BT_ERR("%s urb %p submission failed (%d)",
478 hdev->name, urb, -err);
479 usb_unanchor_urb(urb);
487 static void btusb_tx_complete(struct urb *urb)
489 struct sk_buff *skb = urb->context;
490 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
492 BT_DBG("%s urb %p status %d count %d", hdev->name,
493 urb, urb->status, urb->actual_length);
495 if (!test_bit(HCI_RUNNING, &hdev->flags))
499 hdev->stat.byte_tx += urb->transfer_buffer_length;
504 kfree(urb->setup_packet);
509 static int btusb_open(struct hci_dev *hdev)
511 struct btusb_data *data = hdev->driver_data;
514 BT_DBG("%s", hdev->name);
516 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
519 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
522 err = btusb_submit_intr_urb(hdev);
524 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
525 clear_bit(HCI_RUNNING, &hdev->flags);
531 static int btusb_close(struct hci_dev *hdev)
533 struct btusb_data *data = hdev->driver_data;
535 BT_DBG("%s", hdev->name);
537 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
540 cancel_work_sync(&data->work);
542 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
543 usb_kill_anchored_urbs(&data->isoc_anchor);
545 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
546 usb_kill_anchored_urbs(&data->bulk_anchor);
548 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
549 usb_kill_anchored_urbs(&data->intr_anchor);
554 static int btusb_flush(struct hci_dev *hdev)
556 struct btusb_data *data = hdev->driver_data;
558 BT_DBG("%s", hdev->name);
560 usb_kill_anchored_urbs(&data->tx_anchor);
565 static int btusb_send_frame(struct sk_buff *skb)
567 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
568 struct btusb_data *data = hdev->driver_data;
569 struct usb_ctrlrequest *dr;
574 BT_DBG("%s", hdev->name);
576 if (!test_bit(HCI_RUNNING, &hdev->flags))
579 switch (bt_cb(skb)->pkt_type) {
580 case HCI_COMMAND_PKT:
581 urb = usb_alloc_urb(0, GFP_ATOMIC);
585 dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
591 dr->bRequestType = USB_TYPE_CLASS;
595 dr->wLength = __cpu_to_le16(skb->len);
597 pipe = usb_sndctrlpipe(data->udev, 0x00);
599 usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
600 skb->data, skb->len, btusb_tx_complete, skb);
605 case HCI_ACLDATA_PKT:
606 if (!data->bulk_tx_ep || hdev->conn_hash.acl_num < 1)
609 urb = usb_alloc_urb(0, GFP_ATOMIC);
613 pipe = usb_sndbulkpipe(data->udev,
614 data->bulk_tx_ep->bEndpointAddress);
616 usb_fill_bulk_urb(urb, data->udev, pipe,
617 skb->data, skb->len, btusb_tx_complete, skb);
622 case HCI_SCODATA_PKT:
623 if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1)
626 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
630 pipe = usb_sndisocpipe(data->udev,
631 data->isoc_tx_ep->bEndpointAddress);
633 urb->dev = data->udev;
636 urb->complete = btusb_tx_complete;
637 urb->interval = data->isoc_tx_ep->bInterval;
639 urb->transfer_flags = URB_ISO_ASAP;
640 urb->transfer_buffer = skb->data;
641 urb->transfer_buffer_length = skb->len;
643 __fill_isoc_descriptor(urb, skb->len,
644 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
653 usb_anchor_urb(urb, &data->tx_anchor);
655 err = usb_submit_urb(urb, GFP_ATOMIC);
657 BT_ERR("%s urb %p submission failed", hdev->name, urb);
658 kfree(urb->setup_packet);
659 usb_unanchor_urb(urb);
667 static void btusb_destruct(struct hci_dev *hdev)
669 struct btusb_data *data = hdev->driver_data;
671 BT_DBG("%s", hdev->name);
676 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
678 struct btusb_data *data = hdev->driver_data;
680 BT_DBG("%s evt %d", hdev->name, evt);
682 if (evt == HCI_NOTIFY_CONN_ADD || evt == HCI_NOTIFY_CONN_DEL)
683 schedule_work(&data->work);
686 static int inline __set_isoc_interface(struct hci_dev *hdev, int altsetting)
688 struct btusb_data *data = hdev->driver_data;
689 struct usb_interface *intf = data->isoc;
690 struct usb_endpoint_descriptor *ep_desc;
696 err = usb_set_interface(data->udev, 1, altsetting);
698 BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
702 data->isoc_altsetting = altsetting;
704 data->isoc_tx_ep = NULL;
705 data->isoc_rx_ep = NULL;
707 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
708 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
710 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
711 data->isoc_tx_ep = ep_desc;
715 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
716 data->isoc_rx_ep = ep_desc;
721 if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
722 BT_ERR("%s invalid SCO descriptors", hdev->name);
729 static void btusb_work(struct work_struct *work)
731 struct btusb_data *data = container_of(work, struct btusb_data, work);
732 struct hci_dev *hdev = data->hdev;
734 if (hdev->conn_hash.acl_num > 0) {
735 if (!test_and_set_bit(BTUSB_BULK_RUNNING, &data->flags)) {
736 if (btusb_submit_bulk_urb(hdev) < 0)
737 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
739 btusb_submit_bulk_urb(hdev);
742 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
743 usb_kill_anchored_urbs(&data->bulk_anchor);
746 if (hdev->conn_hash.sco_num > 0) {
747 if (data->isoc_altsetting != 2) {
748 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
749 usb_kill_anchored_urbs(&data->isoc_anchor);
751 if (__set_isoc_interface(hdev, 2) < 0)
755 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
756 if (btusb_submit_isoc_urb(hdev) < 0)
757 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
759 btusb_submit_isoc_urb(hdev);
762 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
763 usb_kill_anchored_urbs(&data->isoc_anchor);
765 __set_isoc_interface(hdev, 0);
769 static int btusb_probe(struct usb_interface *intf,
770 const struct usb_device_id *id)
772 struct usb_endpoint_descriptor *ep_desc;
773 struct btusb_data *data;
774 struct hci_dev *hdev;
777 BT_DBG("intf %p id %p", intf, id);
779 /* interface numbers are hardcoded in the spec */
780 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
783 if (!id->driver_info) {
784 const struct usb_device_id *match;
785 match = usb_match_id(intf, blacklist_table);
790 if (id->driver_info == BTUSB_IGNORE)
793 if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
796 if (ignore_csr && id->driver_info & BTUSB_CSR)
799 if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
802 data = kzalloc(sizeof(*data), GFP_KERNEL);
806 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
807 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
809 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
810 data->intr_ep = ep_desc;
814 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
815 data->bulk_tx_ep = ep_desc;
819 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
820 data->bulk_rx_ep = ep_desc;
825 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
830 data->udev = interface_to_usbdev(intf);
833 spin_lock_init(&data->lock);
835 INIT_WORK(&data->work, btusb_work);
837 init_usb_anchor(&data->tx_anchor);
838 init_usb_anchor(&data->intr_anchor);
839 init_usb_anchor(&data->bulk_anchor);
840 init_usb_anchor(&data->isoc_anchor);
842 hdev = hci_alloc_dev();
848 hdev->type = HCI_USB;
849 hdev->driver_data = data;
853 SET_HCIDEV_DEV(hdev, &intf->dev);
855 hdev->open = btusb_open;
856 hdev->close = btusb_close;
857 hdev->flush = btusb_flush;
858 hdev->send = btusb_send_frame;
859 hdev->destruct = btusb_destruct;
860 hdev->notify = btusb_notify;
862 hdev->owner = THIS_MODULE;
864 /* interface numbers are hardcoded in the spec */
865 data->isoc = usb_ifnum_to_if(data->udev, 1);
867 if (reset || id->driver_info & BTUSB_RESET)
868 set_bit(HCI_QUIRK_RESET_ON_INIT, &hdev->quirks);
870 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
872 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
875 if (id->driver_info & BTUSB_BROKEN_ISOC)
878 if (id->driver_info & BTUSB_SNIFFER) {
879 struct usb_device *udev = data->udev;
881 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
882 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
887 if (id->driver_info & BTUSB_BCM92035) {
888 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
891 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
893 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
894 skb_queue_tail(&hdev->driver_init, skb);
899 err = usb_driver_claim_interface(&btusb_driver,
908 err = hci_register_dev(hdev);
915 usb_set_intfdata(intf, data);
920 static void btusb_disconnect(struct usb_interface *intf)
922 struct btusb_data *data = usb_get_intfdata(intf);
923 struct hci_dev *hdev;
925 BT_DBG("intf %p", intf);
932 __hci_dev_hold(hdev);
934 usb_set_intfdata(data->intf, NULL);
937 usb_set_intfdata(data->isoc, NULL);
939 hci_unregister_dev(hdev);
941 if (intf == data->isoc)
942 usb_driver_release_interface(&btusb_driver, data->intf);
944 usb_driver_release_interface(&btusb_driver, data->isoc);
951 static struct usb_driver btusb_driver = {
953 .probe = btusb_probe,
954 .disconnect = btusb_disconnect,
955 .id_table = btusb_table,
958 static int __init btusb_init(void)
960 BT_INFO("Generic Bluetooth USB driver ver %s", VERSION);
962 return usb_register(&btusb_driver);
965 static void __exit btusb_exit(void)
967 usb_deregister(&btusb_driver);
970 module_init(btusb_init);
971 module_exit(btusb_exit);
973 module_param(ignore_dga, bool, 0644);
974 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
976 module_param(ignore_csr, bool, 0644);
977 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
979 module_param(ignore_sniffer, bool, 0644);
980 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
982 module_param(disable_scofix, bool, 0644);
983 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
985 module_param(force_scofix, bool, 0644);
986 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
988 module_param(reset, bool, 0644);
989 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
991 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
992 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
993 MODULE_VERSION(VERSION);
994 MODULE_LICENSE("GPL");