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;
54 static struct usb_driver btusb_driver;
56 #define BTUSB_IGNORE 0x01
57 #define BTUSB_DIGIANSWER 0x02
58 #define BTUSB_CSR 0x04
59 #define BTUSB_SNIFFER 0x08
60 #define BTUSB_BCM92035 0x10
61 #define BTUSB_BROKEN_ISOC 0x20
62 #define BTUSB_WRONG_SCO_MTU 0x40
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) },
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_WRONG_SCO_MTU },
98 { USB_DEVICE(0x0a5c, 0x200a), .driver_info = BTUSB_WRONG_SCO_MTU },
99 { USB_DEVICE(0x0a5c, 0x2009), .driver_info = BTUSB_BCM92035 },
101 /* Broadcom BCM2045 */
102 { USB_DEVICE(0x0a5c, 0x2039), .driver_info = BTUSB_WRONG_SCO_MTU },
103 { USB_DEVICE(0x0a5c, 0x2101), .driver_info = BTUSB_WRONG_SCO_MTU },
105 /* IBM/Lenovo ThinkPad with Broadcom chip */
106 { USB_DEVICE(0x0a5c, 0x201e), .driver_info = BTUSB_WRONG_SCO_MTU },
107 { USB_DEVICE(0x0a5c, 0x2110), .driver_info = BTUSB_WRONG_SCO_MTU },
109 /* HP laptop with Broadcom chip */
110 { USB_DEVICE(0x03f0, 0x171d), .driver_info = BTUSB_WRONG_SCO_MTU },
112 /* Dell laptop with Broadcom chip */
113 { USB_DEVICE(0x413c, 0x8126), .driver_info = BTUSB_WRONG_SCO_MTU },
115 /* Dell Wireless 370 and 410 devices */
116 { USB_DEVICE(0x413c, 0x8152), .driver_info = BTUSB_WRONG_SCO_MTU },
117 { USB_DEVICE(0x413c, 0x8156), .driver_info = BTUSB_WRONG_SCO_MTU },
119 /* Belkin F8T012 and F8T013 devices */
120 { USB_DEVICE(0x050d, 0x0012), .driver_info = BTUSB_WRONG_SCO_MTU },
121 { USB_DEVICE(0x050d, 0x0013), .driver_info = BTUSB_WRONG_SCO_MTU },
123 /* Asus WL-BTD202 device */
124 { USB_DEVICE(0x0b05, 0x1715), .driver_info = BTUSB_WRONG_SCO_MTU },
126 /* Kensington Bluetooth USB adapter */
127 { USB_DEVICE(0x047d, 0x105e), .driver_info = BTUSB_WRONG_SCO_MTU },
129 /* RTX Telecom based adapters with buggy SCO support */
130 { USB_DEVICE(0x0400, 0x0807), .driver_info = BTUSB_BROKEN_ISOC },
131 { USB_DEVICE(0x0400, 0x080a), .driver_info = BTUSB_BROKEN_ISOC },
133 /* CONWISE Technology based adapters with buggy SCO support */
134 { USB_DEVICE(0x0e5e, 0x6622), .driver_info = BTUSB_BROKEN_ISOC },
136 /* Digianswer devices */
137 { USB_DEVICE(0x08fd, 0x0001), .driver_info = BTUSB_DIGIANSWER },
138 { USB_DEVICE(0x08fd, 0x0002), .driver_info = BTUSB_IGNORE },
140 /* CSR BlueCore Bluetooth Sniffer */
141 { USB_DEVICE(0x0a12, 0x0002), .driver_info = BTUSB_SNIFFER },
143 /* Frontline ComProbe Bluetooth Sniffer */
144 { USB_DEVICE(0x16d3, 0x0002), .driver_info = BTUSB_SNIFFER },
146 { } /* Terminating entry */
149 #define BTUSB_MAX_ISOC_FRAMES 10
151 #define BTUSB_INTR_RUNNING 0
152 #define BTUSB_BULK_RUNNING 1
153 #define BTUSB_ISOC_RUNNING 2
156 struct hci_dev *hdev;
157 struct usb_device *udev;
158 struct usb_interface *intf;
159 struct usb_interface *isoc;
165 struct work_struct work;
167 struct usb_anchor tx_anchor;
168 struct usb_anchor intr_anchor;
169 struct usb_anchor bulk_anchor;
170 struct usb_anchor isoc_anchor;
172 struct usb_endpoint_descriptor *intr_ep;
173 struct usb_endpoint_descriptor *bulk_tx_ep;
174 struct usb_endpoint_descriptor *bulk_rx_ep;
175 struct usb_endpoint_descriptor *isoc_tx_ep;
176 struct usb_endpoint_descriptor *isoc_rx_ep;
184 static void btusb_intr_complete(struct urb *urb)
186 struct hci_dev *hdev = urb->context;
187 struct btusb_data *data = hdev->driver_data;
190 BT_DBG("%s urb %p status %d count %d", hdev->name,
191 urb, urb->status, urb->actual_length);
193 if (!test_bit(HCI_RUNNING, &hdev->flags))
196 if (urb->status == 0) {
197 hdev->stat.byte_rx += urb->actual_length;
199 if (hci_recv_fragment(hdev, HCI_EVENT_PKT,
200 urb->transfer_buffer,
201 urb->actual_length) < 0) {
202 BT_ERR("%s corrupted event packet", hdev->name);
207 if (!test_bit(BTUSB_INTR_RUNNING, &data->flags))
210 usb_anchor_urb(urb, &data->intr_anchor);
212 err = usb_submit_urb(urb, GFP_ATOMIC);
214 BT_ERR("%s urb %p failed to resubmit (%d)",
215 hdev->name, urb, -err);
216 usb_unanchor_urb(urb);
220 static int btusb_submit_intr_urb(struct hci_dev *hdev, gfp_t mem_flags)
222 struct btusb_data *data = hdev->driver_data;
228 BT_DBG("%s", hdev->name);
233 urb = usb_alloc_urb(0, mem_flags);
237 size = le16_to_cpu(data->intr_ep->wMaxPacketSize);
239 buf = kmalloc(size, mem_flags);
245 pipe = usb_rcvintpipe(data->udev, data->intr_ep->bEndpointAddress);
247 usb_fill_int_urb(urb, data->udev, pipe, buf, size,
248 btusb_intr_complete, hdev,
249 data->intr_ep->bInterval);
251 urb->transfer_flags |= URB_FREE_BUFFER;
253 usb_anchor_urb(urb, &data->intr_anchor);
255 err = usb_submit_urb(urb, mem_flags);
257 BT_ERR("%s urb %p submission failed (%d)",
258 hdev->name, urb, -err);
259 usb_unanchor_urb(urb);
267 static void btusb_bulk_complete(struct urb *urb)
269 struct hci_dev *hdev = urb->context;
270 struct btusb_data *data = hdev->driver_data;
273 BT_DBG("%s urb %p status %d count %d", hdev->name,
274 urb, urb->status, urb->actual_length);
276 if (!test_bit(HCI_RUNNING, &hdev->flags))
279 if (urb->status == 0) {
280 hdev->stat.byte_rx += urb->actual_length;
282 if (hci_recv_fragment(hdev, HCI_ACLDATA_PKT,
283 urb->transfer_buffer,
284 urb->actual_length) < 0) {
285 BT_ERR("%s corrupted ACL packet", hdev->name);
290 if (!test_bit(BTUSB_BULK_RUNNING, &data->flags))
293 usb_anchor_urb(urb, &data->bulk_anchor);
295 err = usb_submit_urb(urb, GFP_ATOMIC);
297 BT_ERR("%s urb %p failed to resubmit (%d)",
298 hdev->name, urb, -err);
299 usb_unanchor_urb(urb);
303 static int btusb_submit_bulk_urb(struct hci_dev *hdev, gfp_t mem_flags)
305 struct btusb_data *data = hdev->driver_data;
311 BT_DBG("%s", hdev->name);
313 if (!data->bulk_rx_ep)
316 urb = usb_alloc_urb(0, mem_flags);
320 size = le16_to_cpu(data->bulk_rx_ep->wMaxPacketSize);
322 buf = kmalloc(size, mem_flags);
328 pipe = usb_rcvbulkpipe(data->udev, data->bulk_rx_ep->bEndpointAddress);
330 usb_fill_bulk_urb(urb, data->udev, pipe,
331 buf, size, btusb_bulk_complete, hdev);
333 urb->transfer_flags |= URB_FREE_BUFFER;
335 usb_anchor_urb(urb, &data->bulk_anchor);
337 err = usb_submit_urb(urb, mem_flags);
339 BT_ERR("%s urb %p submission failed (%d)",
340 hdev->name, urb, -err);
341 usb_unanchor_urb(urb);
349 static void btusb_isoc_complete(struct urb *urb)
351 struct hci_dev *hdev = urb->context;
352 struct btusb_data *data = hdev->driver_data;
355 BT_DBG("%s urb %p status %d count %d", hdev->name,
356 urb, urb->status, urb->actual_length);
358 if (!test_bit(HCI_RUNNING, &hdev->flags))
361 if (urb->status == 0) {
362 for (i = 0; i < urb->number_of_packets; i++) {
363 unsigned int offset = urb->iso_frame_desc[i].offset;
364 unsigned int length = urb->iso_frame_desc[i].actual_length;
366 if (urb->iso_frame_desc[i].status)
369 hdev->stat.byte_rx += length;
371 if (hci_recv_fragment(hdev, HCI_SCODATA_PKT,
372 urb->transfer_buffer + offset,
374 BT_ERR("%s corrupted SCO packet", hdev->name);
380 if (!test_bit(BTUSB_ISOC_RUNNING, &data->flags))
383 usb_anchor_urb(urb, &data->isoc_anchor);
385 err = usb_submit_urb(urb, GFP_ATOMIC);
387 BT_ERR("%s urb %p failed to resubmit (%d)",
388 hdev->name, urb, -err);
389 usb_unanchor_urb(urb);
393 static void inline __fill_isoc_descriptor(struct urb *urb, int len, int mtu)
397 BT_DBG("len %d mtu %d", len, mtu);
399 for (i = 0; i < BTUSB_MAX_ISOC_FRAMES && len >= mtu;
400 i++, offset += mtu, len -= mtu) {
401 urb->iso_frame_desc[i].offset = offset;
402 urb->iso_frame_desc[i].length = mtu;
405 if (len && i < BTUSB_MAX_ISOC_FRAMES) {
406 urb->iso_frame_desc[i].offset = offset;
407 urb->iso_frame_desc[i].length = len;
411 urb->number_of_packets = i;
414 static int btusb_submit_isoc_urb(struct hci_dev *hdev, gfp_t mem_flags)
416 struct btusb_data *data = hdev->driver_data;
422 BT_DBG("%s", hdev->name);
424 if (!data->isoc_rx_ep)
427 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, mem_flags);
431 size = le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize) *
432 BTUSB_MAX_ISOC_FRAMES;
434 buf = kmalloc(size, mem_flags);
440 pipe = usb_rcvisocpipe(data->udev, data->isoc_rx_ep->bEndpointAddress);
442 urb->dev = data->udev;
445 urb->complete = btusb_isoc_complete;
446 urb->interval = data->isoc_rx_ep->bInterval;
448 urb->transfer_flags = URB_FREE_BUFFER | URB_ISO_ASAP;
449 urb->transfer_buffer = buf;
450 urb->transfer_buffer_length = size;
452 __fill_isoc_descriptor(urb, size,
453 le16_to_cpu(data->isoc_rx_ep->wMaxPacketSize));
455 usb_anchor_urb(urb, &data->isoc_anchor);
457 err = usb_submit_urb(urb, mem_flags);
459 BT_ERR("%s urb %p submission failed (%d)",
460 hdev->name, urb, -err);
461 usb_unanchor_urb(urb);
469 static void btusb_tx_complete(struct urb *urb)
471 struct sk_buff *skb = urb->context;
472 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
474 BT_DBG("%s urb %p status %d count %d", hdev->name,
475 urb, urb->status, urb->actual_length);
477 if (!test_bit(HCI_RUNNING, &hdev->flags))
481 hdev->stat.byte_tx += urb->transfer_buffer_length;
486 kfree(urb->setup_packet);
491 static int btusb_open(struct hci_dev *hdev)
493 struct btusb_data *data = hdev->driver_data;
496 BT_DBG("%s", hdev->name);
498 if (test_and_set_bit(HCI_RUNNING, &hdev->flags))
501 if (test_and_set_bit(BTUSB_INTR_RUNNING, &data->flags))
504 err = btusb_submit_intr_urb(hdev, GFP_KERNEL);
506 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
507 clear_bit(HCI_RUNNING, &hdev->flags);
513 static int btusb_close(struct hci_dev *hdev)
515 struct btusb_data *data = hdev->driver_data;
517 BT_DBG("%s", hdev->name);
519 if (!test_and_clear_bit(HCI_RUNNING, &hdev->flags))
522 cancel_work_sync(&data->work);
524 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
525 usb_kill_anchored_urbs(&data->isoc_anchor);
527 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
528 usb_kill_anchored_urbs(&data->bulk_anchor);
530 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
531 usb_kill_anchored_urbs(&data->intr_anchor);
536 static int btusb_flush(struct hci_dev *hdev)
538 struct btusb_data *data = hdev->driver_data;
540 BT_DBG("%s", hdev->name);
542 usb_kill_anchored_urbs(&data->tx_anchor);
547 static int btusb_send_frame(struct sk_buff *skb)
549 struct hci_dev *hdev = (struct hci_dev *) skb->dev;
550 struct btusb_data *data = hdev->driver_data;
551 struct usb_ctrlrequest *dr;
556 BT_DBG("%s", hdev->name);
558 if (!test_bit(HCI_RUNNING, &hdev->flags))
561 switch (bt_cb(skb)->pkt_type) {
562 case HCI_COMMAND_PKT:
563 urb = usb_alloc_urb(0, GFP_ATOMIC);
567 dr = kmalloc(sizeof(*dr), GFP_ATOMIC);
573 dr->bRequestType = data->cmdreq_type;
577 dr->wLength = __cpu_to_le16(skb->len);
579 pipe = usb_sndctrlpipe(data->udev, 0x00);
581 usb_fill_control_urb(urb, data->udev, pipe, (void *) dr,
582 skb->data, skb->len, btusb_tx_complete, skb);
587 case HCI_ACLDATA_PKT:
588 if (!data->bulk_tx_ep || hdev->conn_hash.acl_num < 1)
591 urb = usb_alloc_urb(0, GFP_ATOMIC);
595 pipe = usb_sndbulkpipe(data->udev,
596 data->bulk_tx_ep->bEndpointAddress);
598 usb_fill_bulk_urb(urb, data->udev, pipe,
599 skb->data, skb->len, btusb_tx_complete, skb);
604 case HCI_SCODATA_PKT:
605 if (!data->isoc_tx_ep || hdev->conn_hash.sco_num < 1)
608 urb = usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES, GFP_ATOMIC);
612 pipe = usb_sndisocpipe(data->udev,
613 data->isoc_tx_ep->bEndpointAddress);
615 urb->dev = data->udev;
618 urb->complete = btusb_tx_complete;
619 urb->interval = data->isoc_tx_ep->bInterval;
621 urb->transfer_flags = URB_ISO_ASAP;
622 urb->transfer_buffer = skb->data;
623 urb->transfer_buffer_length = skb->len;
625 __fill_isoc_descriptor(urb, skb->len,
626 le16_to_cpu(data->isoc_tx_ep->wMaxPacketSize));
635 usb_anchor_urb(urb, &data->tx_anchor);
637 err = usb_submit_urb(urb, GFP_ATOMIC);
639 BT_ERR("%s urb %p submission failed", hdev->name, urb);
640 kfree(urb->setup_packet);
641 usb_unanchor_urb(urb);
649 static void btusb_destruct(struct hci_dev *hdev)
651 struct btusb_data *data = hdev->driver_data;
653 BT_DBG("%s", hdev->name);
658 static void btusb_notify(struct hci_dev *hdev, unsigned int evt)
660 struct btusb_data *data = hdev->driver_data;
662 BT_DBG("%s evt %d", hdev->name, evt);
664 if (hdev->conn_hash.acl_num > 0) {
665 if (!test_and_set_bit(BTUSB_BULK_RUNNING, &data->flags)) {
666 if (btusb_submit_bulk_urb(hdev, GFP_ATOMIC) < 0)
667 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
669 btusb_submit_bulk_urb(hdev, GFP_ATOMIC);
672 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
673 usb_unlink_anchored_urbs(&data->bulk_anchor);
676 schedule_work(&data->work);
679 static int inline __set_isoc_interface(struct hci_dev *hdev, int altsetting)
681 struct btusb_data *data = hdev->driver_data;
682 struct usb_interface *intf = data->isoc;
683 struct usb_endpoint_descriptor *ep_desc;
689 err = usb_set_interface(data->udev, 1, altsetting);
691 BT_ERR("%s setting interface failed (%d)", hdev->name, -err);
695 data->isoc_altsetting = altsetting;
697 data->isoc_tx_ep = NULL;
698 data->isoc_rx_ep = NULL;
700 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
701 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
703 if (!data->isoc_tx_ep && usb_endpoint_is_isoc_out(ep_desc)) {
704 data->isoc_tx_ep = ep_desc;
708 if (!data->isoc_rx_ep && usb_endpoint_is_isoc_in(ep_desc)) {
709 data->isoc_rx_ep = ep_desc;
714 if (!data->isoc_tx_ep || !data->isoc_rx_ep) {
715 BT_ERR("%s invalid SCO descriptors", hdev->name);
722 static void btusb_work(struct work_struct *work)
724 struct btusb_data *data = container_of(work, struct btusb_data, work);
725 struct hci_dev *hdev = data->hdev;
727 if (hdev->conn_hash.sco_num > 0) {
728 if (data->isoc_altsetting != 2) {
729 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
730 usb_kill_anchored_urbs(&data->isoc_anchor);
732 if (__set_isoc_interface(hdev, 2) < 0)
736 if (!test_and_set_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
737 if (btusb_submit_isoc_urb(hdev, GFP_KERNEL) < 0)
738 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
740 btusb_submit_isoc_urb(hdev, GFP_KERNEL);
743 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
744 usb_kill_anchored_urbs(&data->isoc_anchor);
746 __set_isoc_interface(hdev, 0);
750 static int btusb_probe(struct usb_interface *intf,
751 const struct usb_device_id *id)
753 struct usb_endpoint_descriptor *ep_desc;
754 struct btusb_data *data;
755 struct hci_dev *hdev;
758 BT_DBG("intf %p id %p", intf, id);
760 /* interface numbers are hardcoded in the spec */
761 if (intf->cur_altsetting->desc.bInterfaceNumber != 0)
764 if (!id->driver_info) {
765 const struct usb_device_id *match;
766 match = usb_match_id(intf, blacklist_table);
771 if (id->driver_info == BTUSB_IGNORE)
774 if (ignore_dga && id->driver_info & BTUSB_DIGIANSWER)
777 if (ignore_csr && id->driver_info & BTUSB_CSR)
780 if (ignore_sniffer && id->driver_info & BTUSB_SNIFFER)
783 data = kzalloc(sizeof(*data), GFP_KERNEL);
787 for (i = 0; i < intf->cur_altsetting->desc.bNumEndpoints; i++) {
788 ep_desc = &intf->cur_altsetting->endpoint[i].desc;
790 if (!data->intr_ep && usb_endpoint_is_int_in(ep_desc)) {
791 data->intr_ep = ep_desc;
795 if (!data->bulk_tx_ep && usb_endpoint_is_bulk_out(ep_desc)) {
796 data->bulk_tx_ep = ep_desc;
800 if (!data->bulk_rx_ep && usb_endpoint_is_bulk_in(ep_desc)) {
801 data->bulk_rx_ep = ep_desc;
806 if (!data->intr_ep || !data->bulk_tx_ep || !data->bulk_rx_ep) {
811 data->cmdreq_type = USB_TYPE_CLASS;
813 data->udev = interface_to_usbdev(intf);
816 spin_lock_init(&data->lock);
818 INIT_WORK(&data->work, btusb_work);
820 init_usb_anchor(&data->tx_anchor);
821 init_usb_anchor(&data->intr_anchor);
822 init_usb_anchor(&data->bulk_anchor);
823 init_usb_anchor(&data->isoc_anchor);
825 hdev = hci_alloc_dev();
831 hdev->type = HCI_USB;
832 hdev->driver_data = data;
836 SET_HCIDEV_DEV(hdev, &intf->dev);
838 hdev->open = btusb_open;
839 hdev->close = btusb_close;
840 hdev->flush = btusb_flush;
841 hdev->send = btusb_send_frame;
842 hdev->destruct = btusb_destruct;
843 hdev->notify = btusb_notify;
845 hdev->owner = THIS_MODULE;
847 /* Interface numbers are hardcoded in the specification */
848 data->isoc = usb_ifnum_to_if(data->udev, 1);
851 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
853 if (force_scofix || id->driver_info & BTUSB_WRONG_SCO_MTU) {
855 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE, &hdev->quirks);
858 if (id->driver_info & BTUSB_BROKEN_ISOC)
861 if (id->driver_info & BTUSB_DIGIANSWER) {
862 data->cmdreq_type = USB_TYPE_VENDOR;
863 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
866 if (id->driver_info & BTUSB_CSR) {
867 struct usb_device *udev = data->udev;
869 /* Old firmware would otherwise execute USB reset */
870 if (le16_to_cpu(udev->descriptor.bcdDevice) < 0x117)
871 set_bit(HCI_QUIRK_NO_RESET, &hdev->quirks);
874 if (id->driver_info & BTUSB_SNIFFER) {
875 struct usb_device *udev = data->udev;
877 /* New sniffer firmware has crippled HCI interface */
878 if (le16_to_cpu(udev->descriptor.bcdDevice) > 0x997)
879 set_bit(HCI_QUIRK_RAW_DEVICE, &hdev->quirks);
884 if (id->driver_info & BTUSB_BCM92035) {
885 unsigned char cmd[] = { 0x3b, 0xfc, 0x01, 0x00 };
888 skb = bt_skb_alloc(sizeof(cmd), GFP_KERNEL);
890 memcpy(skb_put(skb, sizeof(cmd)), cmd, sizeof(cmd));
891 skb_queue_tail(&hdev->driver_init, skb);
896 err = usb_driver_claim_interface(&btusb_driver,
905 err = hci_register_dev(hdev);
912 usb_set_intfdata(intf, data);
917 static void btusb_disconnect(struct usb_interface *intf)
919 struct btusb_data *data = usb_get_intfdata(intf);
920 struct hci_dev *hdev;
922 BT_DBG("intf %p", intf);
929 __hci_dev_hold(hdev);
931 usb_set_intfdata(data->intf, NULL);
934 usb_set_intfdata(data->isoc, NULL);
936 hci_unregister_dev(hdev);
938 if (intf == data->isoc)
939 usb_driver_release_interface(&btusb_driver, data->intf);
941 usb_driver_release_interface(&btusb_driver, data->isoc);
948 static int btusb_suspend(struct usb_interface *intf, pm_message_t message)
950 struct btusb_data *data = usb_get_intfdata(intf);
952 BT_DBG("intf %p", intf);
954 if (data->suspend_count++)
957 cancel_work_sync(&data->work);
959 usb_kill_anchored_urbs(&data->tx_anchor);
961 usb_kill_anchored_urbs(&data->isoc_anchor);
962 usb_kill_anchored_urbs(&data->bulk_anchor);
963 usb_kill_anchored_urbs(&data->intr_anchor);
968 static int btusb_resume(struct usb_interface *intf)
970 struct btusb_data *data = usb_get_intfdata(intf);
971 struct hci_dev *hdev = data->hdev;
974 BT_DBG("intf %p", intf);
976 if (--data->suspend_count)
979 if (!test_bit(HCI_RUNNING, &hdev->flags))
982 if (test_bit(BTUSB_INTR_RUNNING, &data->flags)) {
983 err = btusb_submit_intr_urb(hdev, GFP_NOIO);
985 clear_bit(BTUSB_INTR_RUNNING, &data->flags);
990 if (test_bit(BTUSB_BULK_RUNNING, &data->flags)) {
991 if (btusb_submit_bulk_urb(hdev, GFP_NOIO) < 0)
992 clear_bit(BTUSB_BULK_RUNNING, &data->flags);
994 btusb_submit_bulk_urb(hdev, GFP_NOIO);
997 if (test_bit(BTUSB_ISOC_RUNNING, &data->flags)) {
998 if (btusb_submit_isoc_urb(hdev, GFP_NOIO) < 0)
999 clear_bit(BTUSB_ISOC_RUNNING, &data->flags);
1001 btusb_submit_isoc_urb(hdev, GFP_NOIO);
1007 static struct usb_driver btusb_driver = {
1009 .probe = btusb_probe,
1010 .disconnect = btusb_disconnect,
1011 .suspend = btusb_suspend,
1012 .resume = btusb_resume,
1013 .id_table = btusb_table,
1016 static int __init btusb_init(void)
1018 BT_INFO("Generic Bluetooth USB driver ver %s", VERSION);
1020 return usb_register(&btusb_driver);
1023 static void __exit btusb_exit(void)
1025 usb_deregister(&btusb_driver);
1028 module_init(btusb_init);
1029 module_exit(btusb_exit);
1031 module_param(ignore_dga, bool, 0644);
1032 MODULE_PARM_DESC(ignore_dga, "Ignore devices with id 08fd:0001");
1034 module_param(ignore_csr, bool, 0644);
1035 MODULE_PARM_DESC(ignore_csr, "Ignore devices with id 0a12:0001");
1037 module_param(ignore_sniffer, bool, 0644);
1038 MODULE_PARM_DESC(ignore_sniffer, "Ignore devices with id 0a12:0002");
1040 module_param(disable_scofix, bool, 0644);
1041 MODULE_PARM_DESC(disable_scofix, "Disable fixup of wrong SCO buffer size");
1043 module_param(force_scofix, bool, 0644);
1044 MODULE_PARM_DESC(force_scofix, "Force fixup of wrong SCO buffers size");
1046 module_param(reset, bool, 0644);
1047 MODULE_PARM_DESC(reset, "Send HCI reset command on initialization");
1049 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
1050 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION);
1051 MODULE_VERSION(VERSION);
1052 MODULE_LICENSE("GPL");