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
},
117 /* ANYCOM Bluetooth USB-200 and USB-250 */
118 { USB_DEVICE(0x0a5c, 0x2111), .driver_info
= BTUSB_RESET
},
120 /* HP laptop with Broadcom chip */
121 { USB_DEVICE(0x03f0, 0x171d), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
123 /* Dell laptop with Broadcom chip */
124 { USB_DEVICE(0x413c, 0x8126), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
126 /* Dell Wireless 370 */
127 { USB_DEVICE(0x413c, 0x8156), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
129 /* Dell Wireless 410 */
130 { USB_DEVICE(0x413c, 0x8152), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
132 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
133 { USB_DEVICE(0x045e, 0x009c), .driver_info
= BTUSB_RESET
},
135 /* Kensington Bluetooth USB adapter */
136 { USB_DEVICE(0x047d, 0x105d), .driver_info
= BTUSB_RESET
},
137 { USB_DEVICE(0x047d, 0x105e), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
139 /* ISSC Bluetooth Adapter v3.1 */
140 { USB_DEVICE(0x1131, 0x1001), .driver_info
= BTUSB_RESET
},
142 /* RTX Telecom based adapters with buggy SCO support */
143 { USB_DEVICE(0x0400, 0x0807), .driver_info
= BTUSB_BROKEN_ISOC
},
144 { USB_DEVICE(0x0400, 0x080a), .driver_info
= BTUSB_BROKEN_ISOC
},
146 /* CONWISE Technology based adapters with buggy SCO support */
147 { USB_DEVICE(0x0e5e, 0x6622), .driver_info
= BTUSB_BROKEN_ISOC
},
149 /* Belkin F8T012 and F8T013 devices */
150 { USB_DEVICE(0x050d, 0x0012), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
151 { USB_DEVICE(0x050d, 0x0013), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
153 /* Digianswer devices */
154 { USB_DEVICE(0x08fd, 0x0001), .driver_info
= BTUSB_DIGIANSWER
},
155 { USB_DEVICE(0x08fd, 0x0002), .driver_info
= BTUSB_IGNORE
},
157 /* CSR BlueCore Bluetooth Sniffer */
158 { USB_DEVICE(0x0a12, 0x0002), .driver_info
= BTUSB_SNIFFER
},
160 /* Frontline ComProbe Bluetooth Sniffer */
161 { USB_DEVICE(0x16d3, 0x0002), .driver_info
= BTUSB_SNIFFER
},
163 { } /* Terminating entry */
166 #define BTUSB_MAX_ISOC_FRAMES 10
168 #define BTUSB_INTR_RUNNING 0
169 #define BTUSB_BULK_RUNNING 1
170 #define BTUSB_ISOC_RUNNING 2
173 struct hci_dev
*hdev
;
174 struct usb_device
*udev
;
175 struct usb_interface
*intf
;
176 struct usb_interface
*isoc
;
182 struct work_struct work
;
184 struct usb_anchor tx_anchor
;
185 struct usb_anchor intr_anchor
;
186 struct usb_anchor bulk_anchor
;
187 struct usb_anchor isoc_anchor
;
189 struct usb_endpoint_descriptor
*intr_ep
;
190 struct usb_endpoint_descriptor
*bulk_tx_ep
;
191 struct usb_endpoint_descriptor
*bulk_rx_ep
;
192 struct usb_endpoint_descriptor
*isoc_tx_ep
;
193 struct usb_endpoint_descriptor
*isoc_rx_ep
;
198 static void btusb_intr_complete(struct urb
*urb
)
200 struct hci_dev
*hdev
= urb
->context
;
201 struct btusb_data
*data
= hdev
->driver_data
;
204 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
205 urb
, urb
->status
, urb
->actual_length
);
207 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
210 if (urb
->status
== 0) {
211 hdev
->stat
.byte_rx
+= urb
->actual_length
;
213 if (hci_recv_fragment(hdev
, HCI_EVENT_PKT
,
214 urb
->transfer_buffer
,
215 urb
->actual_length
) < 0) {
216 BT_ERR("%s corrupted event packet", hdev
->name
);
221 if (!test_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
224 usb_anchor_urb(urb
, &data
->intr_anchor
);
226 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
228 BT_ERR("%s urb %p failed to resubmit (%d)",
229 hdev
->name
, urb
, -err
);
230 usb_unanchor_urb(urb
);
234 static int btusb_submit_intr_urb(struct hci_dev
*hdev
)
236 struct btusb_data
*data
= hdev
->driver_data
;
242 BT_DBG("%s", hdev
->name
);
247 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
251 size
= le16_to_cpu(data
->intr_ep
->wMaxPacketSize
);
253 buf
= kmalloc(size
, GFP_ATOMIC
);
259 pipe
= usb_rcvintpipe(data
->udev
, data
->intr_ep
->bEndpointAddress
);
261 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
,
262 btusb_intr_complete
, hdev
,
263 data
->intr_ep
->bInterval
);
265 urb
->transfer_flags
|= URB_FREE_BUFFER
;
267 usb_anchor_urb(urb
, &data
->intr_anchor
);
269 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
271 BT_ERR("%s urb %p submission failed (%d)",
272 hdev
->name
, urb
, -err
);
273 usb_unanchor_urb(urb
);
281 static void btusb_bulk_complete(struct urb
*urb
)
283 struct hci_dev
*hdev
= urb
->context
;
284 struct btusb_data
*data
= hdev
->driver_data
;
287 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
288 urb
, urb
->status
, urb
->actual_length
);
290 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
293 if (urb
->status
== 0) {
294 hdev
->stat
.byte_rx
+= urb
->actual_length
;
296 if (hci_recv_fragment(hdev
, HCI_ACLDATA_PKT
,
297 urb
->transfer_buffer
,
298 urb
->actual_length
) < 0) {
299 BT_ERR("%s corrupted ACL packet", hdev
->name
);
304 if (!test_bit(BTUSB_BULK_RUNNING
, &data
->flags
))
307 usb_anchor_urb(urb
, &data
->bulk_anchor
);
309 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
311 BT_ERR("%s urb %p failed to resubmit (%d)",
312 hdev
->name
, urb
, -err
);
313 usb_unanchor_urb(urb
);
317 static int btusb_submit_bulk_urb(struct hci_dev
*hdev
)
319 struct btusb_data
*data
= hdev
->driver_data
;
325 BT_DBG("%s", hdev
->name
);
327 if (!data
->bulk_rx_ep
)
330 urb
= usb_alloc_urb(0, GFP_KERNEL
);
334 size
= le16_to_cpu(data
->bulk_rx_ep
->wMaxPacketSize
);
336 buf
= kmalloc(size
, GFP_KERNEL
);
342 pipe
= usb_rcvbulkpipe(data
->udev
, data
->bulk_rx_ep
->bEndpointAddress
);
344 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
345 buf
, size
, btusb_bulk_complete
, hdev
);
347 urb
->transfer_flags
|= URB_FREE_BUFFER
;
349 usb_anchor_urb(urb
, &data
->bulk_anchor
);
351 err
= usb_submit_urb(urb
, GFP_KERNEL
);
353 BT_ERR("%s urb %p submission failed (%d)",
354 hdev
->name
, urb
, -err
);
355 usb_unanchor_urb(urb
);
363 static void btusb_isoc_complete(struct urb
*urb
)
365 struct hci_dev
*hdev
= urb
->context
;
366 struct btusb_data
*data
= hdev
->driver_data
;
369 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
370 urb
, urb
->status
, urb
->actual_length
);
372 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
375 if (urb
->status
== 0) {
376 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
377 unsigned int offset
= urb
->iso_frame_desc
[i
].offset
;
378 unsigned int length
= urb
->iso_frame_desc
[i
].actual_length
;
380 if (urb
->iso_frame_desc
[i
].status
)
383 hdev
->stat
.byte_rx
+= length
;
385 if (hci_recv_fragment(hdev
, HCI_SCODATA_PKT
,
386 urb
->transfer_buffer
+ offset
,
388 BT_ERR("%s corrupted SCO packet", hdev
->name
);
394 if (!test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
))
397 usb_anchor_urb(urb
, &data
->isoc_anchor
);
399 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
401 BT_ERR("%s urb %p failed to resubmit (%d)",
402 hdev
->name
, urb
, -err
);
403 usb_unanchor_urb(urb
);
407 static void inline __fill_isoc_descriptor(struct urb
*urb
, int len
, int mtu
)
411 BT_DBG("len %d mtu %d", len
, mtu
);
413 for (i
= 0; i
< BTUSB_MAX_ISOC_FRAMES
&& len
>= mtu
;
414 i
++, offset
+= mtu
, len
-= mtu
) {
415 urb
->iso_frame_desc
[i
].offset
= offset
;
416 urb
->iso_frame_desc
[i
].length
= mtu
;
419 if (len
&& i
< BTUSB_MAX_ISOC_FRAMES
) {
420 urb
->iso_frame_desc
[i
].offset
= offset
;
421 urb
->iso_frame_desc
[i
].length
= len
;
425 urb
->number_of_packets
= i
;
428 static int btusb_submit_isoc_urb(struct hci_dev
*hdev
)
430 struct btusb_data
*data
= hdev
->driver_data
;
436 BT_DBG("%s", hdev
->name
);
438 if (!data
->isoc_rx_ep
)
441 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_KERNEL
);
445 size
= le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
) *
446 BTUSB_MAX_ISOC_FRAMES
;
448 buf
= kmalloc(size
, GFP_KERNEL
);
454 pipe
= usb_rcvisocpipe(data
->udev
, data
->isoc_rx_ep
->bEndpointAddress
);
456 urb
->dev
= data
->udev
;
459 urb
->complete
= btusb_isoc_complete
;
460 urb
->interval
= data
->isoc_rx_ep
->bInterval
;
462 urb
->transfer_flags
= URB_FREE_BUFFER
| URB_ISO_ASAP
;
463 urb
->transfer_buffer
= buf
;
464 urb
->transfer_buffer_length
= size
;
466 __fill_isoc_descriptor(urb
, size
,
467 le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
));
469 usb_anchor_urb(urb
, &data
->isoc_anchor
);
471 err
= usb_submit_urb(urb
, GFP_KERNEL
);
473 BT_ERR("%s urb %p submission failed (%d)",
474 hdev
->name
, urb
, -err
);
475 usb_unanchor_urb(urb
);
483 static void btusb_tx_complete(struct urb
*urb
)
485 struct sk_buff
*skb
= urb
->context
;
486 struct hci_dev
*hdev
= (struct hci_dev
*) skb
->dev
;
488 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
489 urb
, urb
->status
, urb
->actual_length
);
491 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
495 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
500 kfree(urb
->setup_packet
);
505 static int btusb_open(struct hci_dev
*hdev
)
507 struct btusb_data
*data
= hdev
->driver_data
;
510 BT_DBG("%s", hdev
->name
);
512 if (test_and_set_bit(HCI_RUNNING
, &hdev
->flags
))
515 if (test_and_set_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
518 err
= btusb_submit_intr_urb(hdev
);
520 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
521 clear_bit(HCI_RUNNING
, &hdev
->flags
);
527 static int btusb_close(struct hci_dev
*hdev
)
529 struct btusb_data
*data
= hdev
->driver_data
;
531 BT_DBG("%s", hdev
->name
);
533 if (!test_and_clear_bit(HCI_RUNNING
, &hdev
->flags
))
536 cancel_work_sync(&data
->work
);
538 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
539 usb_kill_anchored_urbs(&data
->isoc_anchor
);
541 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
542 usb_kill_anchored_urbs(&data
->bulk_anchor
);
544 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
545 usb_kill_anchored_urbs(&data
->intr_anchor
);
550 static int btusb_flush(struct hci_dev
*hdev
)
552 struct btusb_data
*data
= hdev
->driver_data
;
554 BT_DBG("%s", hdev
->name
);
556 usb_kill_anchored_urbs(&data
->tx_anchor
);
561 static int btusb_send_frame(struct sk_buff
*skb
)
563 struct hci_dev
*hdev
= (struct hci_dev
*) skb
->dev
;
564 struct btusb_data
*data
= hdev
->driver_data
;
565 struct usb_ctrlrequest
*dr
;
570 BT_DBG("%s", hdev
->name
);
572 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
575 switch (bt_cb(skb
)->pkt_type
) {
576 case HCI_COMMAND_PKT
:
577 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
581 dr
= kmalloc(sizeof(*dr
), GFP_ATOMIC
);
587 dr
->bRequestType
= USB_TYPE_CLASS
;
591 dr
->wLength
= __cpu_to_le16(skb
->len
);
593 pipe
= usb_sndctrlpipe(data
->udev
, 0x00);
595 usb_fill_control_urb(urb
, data
->udev
, pipe
, (void *) dr
,
596 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
601 case HCI_ACLDATA_PKT
:
602 if (!data
->bulk_tx_ep
|| hdev
->conn_hash
.acl_num
< 1)
605 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
609 pipe
= usb_sndbulkpipe(data
->udev
,
610 data
->bulk_tx_ep
->bEndpointAddress
);
612 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
613 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
618 case HCI_SCODATA_PKT
:
619 if (!data
->isoc_tx_ep
|| hdev
->conn_hash
.sco_num
< 1)
622 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_ATOMIC
);
626 pipe
= usb_sndisocpipe(data
->udev
,
627 data
->isoc_tx_ep
->bEndpointAddress
);
629 urb
->dev
= data
->udev
;
632 urb
->complete
= btusb_tx_complete
;
633 urb
->interval
= data
->isoc_tx_ep
->bInterval
;
635 urb
->transfer_flags
= URB_ISO_ASAP
;
636 urb
->transfer_buffer
= skb
->data
;
637 urb
->transfer_buffer_length
= skb
->len
;
639 __fill_isoc_descriptor(urb
, skb
->len
,
640 le16_to_cpu(data
->isoc_tx_ep
->wMaxPacketSize
));
649 usb_anchor_urb(urb
, &data
->tx_anchor
);
651 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
653 BT_ERR("%s urb %p submission failed", hdev
->name
, urb
);
654 kfree(urb
->setup_packet
);
655 usb_unanchor_urb(urb
);
663 static void btusb_destruct(struct hci_dev
*hdev
)
665 struct btusb_data
*data
= hdev
->driver_data
;
667 BT_DBG("%s", hdev
->name
);
672 static void btusb_notify(struct hci_dev
*hdev
, unsigned int evt
)
674 struct btusb_data
*data
= hdev
->driver_data
;
676 BT_DBG("%s evt %d", hdev
->name
, evt
);
678 if (evt
== HCI_NOTIFY_CONN_ADD
|| evt
== HCI_NOTIFY_CONN_DEL
)
679 schedule_work(&data
->work
);
682 static int inline __set_isoc_interface(struct hci_dev
*hdev
, int altsetting
)
684 struct btusb_data
*data
= hdev
->driver_data
;
685 struct usb_interface
*intf
= data
->isoc
;
686 struct usb_endpoint_descriptor
*ep_desc
;
692 err
= usb_set_interface(data
->udev
, 1, altsetting
);
694 BT_ERR("%s setting interface failed (%d)", hdev
->name
, -err
);
698 data
->isoc_altsetting
= altsetting
;
700 data
->isoc_tx_ep
= NULL
;
701 data
->isoc_rx_ep
= NULL
;
703 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
704 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
706 if (!data
->isoc_tx_ep
&& usb_endpoint_is_isoc_out(ep_desc
)) {
707 data
->isoc_tx_ep
= ep_desc
;
711 if (!data
->isoc_rx_ep
&& usb_endpoint_is_isoc_in(ep_desc
)) {
712 data
->isoc_rx_ep
= ep_desc
;
717 if (!data
->isoc_tx_ep
|| !data
->isoc_rx_ep
) {
718 BT_ERR("%s invalid SCO descriptors", hdev
->name
);
725 static void btusb_work(struct work_struct
*work
)
727 struct btusb_data
*data
= container_of(work
, struct btusb_data
, work
);
728 struct hci_dev
*hdev
= data
->hdev
;
730 if (hdev
->conn_hash
.acl_num
> 0) {
731 if (!test_and_set_bit(BTUSB_BULK_RUNNING
, &data
->flags
)) {
732 if (btusb_submit_bulk_urb(hdev
) < 0)
733 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
735 btusb_submit_bulk_urb(hdev
);
738 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
739 usb_kill_anchored_urbs(&data
->bulk_anchor
);
742 if (hdev
->conn_hash
.sco_num
> 0) {
743 if (data
->isoc_altsetting
!= 2) {
744 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
745 usb_kill_anchored_urbs(&data
->isoc_anchor
);
747 if (__set_isoc_interface(hdev
, 2) < 0)
751 if (!test_and_set_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
752 if (btusb_submit_isoc_urb(hdev
) < 0)
753 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
755 btusb_submit_isoc_urb(hdev
);
758 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
759 usb_kill_anchored_urbs(&data
->isoc_anchor
);
761 __set_isoc_interface(hdev
, 0);
765 static int btusb_probe(struct usb_interface
*intf
,
766 const struct usb_device_id
*id
)
768 struct usb_endpoint_descriptor
*ep_desc
;
769 struct btusb_data
*data
;
770 struct hci_dev
*hdev
;
773 BT_DBG("intf %p id %p", intf
, id
);
775 /* interface numbers are hardcoded in the spec */
776 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0)
779 if (!id
->driver_info
) {
780 const struct usb_device_id
*match
;
781 match
= usb_match_id(intf
, blacklist_table
);
786 if (id
->driver_info
== BTUSB_IGNORE
)
789 if (ignore_dga
&& id
->driver_info
& BTUSB_DIGIANSWER
)
792 if (ignore_csr
&& id
->driver_info
& BTUSB_CSR
)
795 if (ignore_sniffer
&& id
->driver_info
& BTUSB_SNIFFER
)
798 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
802 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
803 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
805 if (!data
->intr_ep
&& usb_endpoint_is_int_in(ep_desc
)) {
806 data
->intr_ep
= ep_desc
;
810 if (!data
->bulk_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
811 data
->bulk_tx_ep
= ep_desc
;
815 if (!data
->bulk_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
816 data
->bulk_rx_ep
= ep_desc
;
821 if (!data
->intr_ep
|| !data
->bulk_tx_ep
|| !data
->bulk_rx_ep
) {
826 data
->udev
= interface_to_usbdev(intf
);
829 spin_lock_init(&data
->lock
);
831 INIT_WORK(&data
->work
, btusb_work
);
833 init_usb_anchor(&data
->tx_anchor
);
834 init_usb_anchor(&data
->intr_anchor
);
835 init_usb_anchor(&data
->bulk_anchor
);
836 init_usb_anchor(&data
->isoc_anchor
);
838 hdev
= hci_alloc_dev();
844 hdev
->type
= HCI_USB
;
845 hdev
->driver_data
= data
;
849 SET_HCIDEV_DEV(hdev
, &intf
->dev
);
851 hdev
->open
= btusb_open
;
852 hdev
->close
= btusb_close
;
853 hdev
->flush
= btusb_flush
;
854 hdev
->send
= btusb_send_frame
;
855 hdev
->destruct
= btusb_destruct
;
856 hdev
->notify
= btusb_notify
;
858 hdev
->owner
= THIS_MODULE
;
860 /* interface numbers are hardcoded in the spec */
861 data
->isoc
= usb_ifnum_to_if(data
->udev
, 1);
863 if (reset
|| id
->driver_info
& BTUSB_RESET
)
864 set_bit(HCI_QUIRK_RESET_ON_INIT
, &hdev
->quirks
);
866 if (force_scofix
|| id
->driver_info
& BTUSB_WRONG_SCO_MTU
) {
868 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE
, &hdev
->quirks
);
871 if (id
->driver_info
& BTUSB_BROKEN_ISOC
)
874 if (id
->driver_info
& BTUSB_SNIFFER
) {
875 struct usb_device
*udev
= data
->udev
;
877 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) > 0x997)
878 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
883 if (id
->driver_info
& BTUSB_BCM92035
) {
884 unsigned char cmd
[] = { 0x3b, 0xfc, 0x01, 0x00 };
887 skb
= bt_skb_alloc(sizeof(cmd
), GFP_KERNEL
);
889 memcpy(skb_put(skb
, sizeof(cmd
)), cmd
, sizeof(cmd
));
890 skb_queue_tail(&hdev
->driver_init
, skb
);
895 err
= usb_driver_claim_interface(&btusb_driver
,
904 err
= hci_register_dev(hdev
);
911 usb_set_intfdata(intf
, data
);
916 static void btusb_disconnect(struct usb_interface
*intf
)
918 struct btusb_data
*data
= usb_get_intfdata(intf
);
919 struct hci_dev
*hdev
;
921 BT_DBG("intf %p", intf
);
928 __hci_dev_hold(hdev
);
930 usb_set_intfdata(data
->intf
, NULL
);
933 usb_set_intfdata(data
->isoc
, NULL
);
935 hci_unregister_dev(hdev
);
937 if (intf
== data
->isoc
)
938 usb_driver_release_interface(&btusb_driver
, data
->intf
);
940 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
947 static struct usb_driver btusb_driver
= {
949 .probe
= btusb_probe
,
950 .disconnect
= btusb_disconnect
,
951 .id_table
= btusb_table
,
954 static int __init
btusb_init(void)
956 BT_INFO("Generic Bluetooth USB driver ver %s", VERSION
);
958 return usb_register(&btusb_driver
);
961 static void __exit
btusb_exit(void)
963 usb_deregister(&btusb_driver
);
966 module_init(btusb_init
);
967 module_exit(btusb_exit
);
969 module_param(ignore_dga
, bool, 0644);
970 MODULE_PARM_DESC(ignore_dga
, "Ignore devices with id 08fd:0001");
972 module_param(ignore_csr
, bool, 0644);
973 MODULE_PARM_DESC(ignore_csr
, "Ignore devices with id 0a12:0001");
975 module_param(ignore_sniffer
, bool, 0644);
976 MODULE_PARM_DESC(ignore_sniffer
, "Ignore devices with id 0a12:0002");
978 module_param(disable_scofix
, bool, 0644);
979 MODULE_PARM_DESC(disable_scofix
, "Disable fixup of wrong SCO buffer size");
981 module_param(force_scofix
, bool, 0644);
982 MODULE_PARM_DESC(force_scofix
, "Force fixup of wrong SCO buffers size");
984 module_param(reset
, bool, 0644);
985 MODULE_PARM_DESC(reset
, "Send HCI reset command on initialization");
987 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
988 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION
);
989 MODULE_VERSION(VERSION
);
990 MODULE_LICENSE("GPL");