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 /* IBM/Lenovo ThinkPad with Broadcom chip */
108 { USB_DEVICE(0x0a5c, 0x201e), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
109 { USB_DEVICE(0x0a5c, 0x2110), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
112 { USB_DEVICE(0x0a5c, 0x2100), .driver_info
= BTUSB_RESET
},
114 /* ANYCOM Bluetooth USB-200 and USB-250 */
115 { USB_DEVICE(0x0a5c, 0x2111), .driver_info
= BTUSB_RESET
},
117 /* HP laptop with Broadcom chip */
118 { USB_DEVICE(0x03f0, 0x171d), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
120 /* Dell laptop with Broadcom chip */
121 { USB_DEVICE(0x413c, 0x8126), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
123 /* Dell Wireless 370 */
124 { USB_DEVICE(0x413c, 0x8156), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
126 /* Dell Wireless 410 */
127 { USB_DEVICE(0x413c, 0x8152), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
129 /* Microsoft Wireless Transceiver for Bluetooth 2.0 */
130 { USB_DEVICE(0x045e, 0x009c), .driver_info
= BTUSB_RESET
},
132 /* Kensington Bluetooth USB adapter */
133 { USB_DEVICE(0x047d, 0x105d), .driver_info
= BTUSB_RESET
},
134 { USB_DEVICE(0x047d, 0x105e), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
136 /* ISSC Bluetooth Adapter v3.1 */
137 { USB_DEVICE(0x1131, 0x1001), .driver_info
= BTUSB_RESET
},
139 /* RTX Telecom based adapters with buggy SCO support */
140 { USB_DEVICE(0x0400, 0x0807), .driver_info
= BTUSB_BROKEN_ISOC
},
141 { USB_DEVICE(0x0400, 0x080a), .driver_info
= BTUSB_BROKEN_ISOC
},
143 /* CONWISE Technology based adapters with buggy SCO support */
144 { USB_DEVICE(0x0e5e, 0x6622), .driver_info
= BTUSB_BROKEN_ISOC
},
146 /* Belkin F8T012 and F8T013 devices */
147 { USB_DEVICE(0x050d, 0x0012), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
148 { USB_DEVICE(0x050d, 0x0013), .driver_info
= BTUSB_RESET
| BTUSB_WRONG_SCO_MTU
},
150 /* Digianswer devices */
151 { USB_DEVICE(0x08fd, 0x0001), .driver_info
= BTUSB_DIGIANSWER
},
152 { USB_DEVICE(0x08fd, 0x0002), .driver_info
= BTUSB_IGNORE
},
154 /* CSR BlueCore Bluetooth Sniffer */
155 { USB_DEVICE(0x0a12, 0x0002), .driver_info
= BTUSB_SNIFFER
},
157 /* Frontline ComProbe Bluetooth Sniffer */
158 { USB_DEVICE(0x16d3, 0x0002), .driver_info
= BTUSB_SNIFFER
},
160 { } /* Terminating entry */
163 #define BTUSB_MAX_ISOC_FRAMES 10
165 #define BTUSB_INTR_RUNNING 0
166 #define BTUSB_BULK_RUNNING 1
167 #define BTUSB_ISOC_RUNNING 2
170 struct hci_dev
*hdev
;
171 struct usb_device
*udev
;
172 struct usb_interface
*isoc
;
178 struct work_struct work
;
180 struct usb_anchor tx_anchor
;
181 struct usb_anchor intr_anchor
;
182 struct usb_anchor bulk_anchor
;
183 struct usb_anchor isoc_anchor
;
185 struct usb_endpoint_descriptor
*intr_ep
;
186 struct usb_endpoint_descriptor
*bulk_tx_ep
;
187 struct usb_endpoint_descriptor
*bulk_rx_ep
;
188 struct usb_endpoint_descriptor
*isoc_tx_ep
;
189 struct usb_endpoint_descriptor
*isoc_rx_ep
;
194 static void btusb_intr_complete(struct urb
*urb
)
196 struct hci_dev
*hdev
= urb
->context
;
197 struct btusb_data
*data
= hdev
->driver_data
;
200 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
201 urb
, urb
->status
, urb
->actual_length
);
203 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
206 if (urb
->status
== 0) {
207 hdev
->stat
.byte_rx
+= urb
->actual_length
;
209 if (hci_recv_fragment(hdev
, HCI_EVENT_PKT
,
210 urb
->transfer_buffer
,
211 urb
->actual_length
) < 0) {
212 BT_ERR("%s corrupted event packet", hdev
->name
);
217 if (!test_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
220 usb_anchor_urb(urb
, &data
->intr_anchor
);
222 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
224 BT_ERR("%s urb %p failed to resubmit (%d)",
225 hdev
->name
, urb
, -err
);
226 usb_unanchor_urb(urb
);
230 static int btusb_submit_intr_urb(struct hci_dev
*hdev
)
232 struct btusb_data
*data
= hdev
->driver_data
;
238 BT_DBG("%s", hdev
->name
);
243 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
247 size
= le16_to_cpu(data
->intr_ep
->wMaxPacketSize
);
249 buf
= kmalloc(size
, GFP_ATOMIC
);
255 pipe
= usb_rcvintpipe(data
->udev
, data
->intr_ep
->bEndpointAddress
);
257 usb_fill_int_urb(urb
, data
->udev
, pipe
, buf
, size
,
258 btusb_intr_complete
, hdev
,
259 data
->intr_ep
->bInterval
);
261 urb
->transfer_flags
|= URB_FREE_BUFFER
;
263 usb_anchor_urb(urb
, &data
->intr_anchor
);
265 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
267 BT_ERR("%s urb %p submission failed (%d)",
268 hdev
->name
, urb
, -err
);
269 usb_unanchor_urb(urb
);
278 static void btusb_bulk_complete(struct urb
*urb
)
280 struct hci_dev
*hdev
= urb
->context
;
281 struct btusb_data
*data
= hdev
->driver_data
;
284 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
285 urb
, urb
->status
, urb
->actual_length
);
287 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
290 if (urb
->status
== 0) {
291 hdev
->stat
.byte_rx
+= urb
->actual_length
;
293 if (hci_recv_fragment(hdev
, HCI_ACLDATA_PKT
,
294 urb
->transfer_buffer
,
295 urb
->actual_length
) < 0) {
296 BT_ERR("%s corrupted ACL packet", hdev
->name
);
301 if (!test_bit(BTUSB_BULK_RUNNING
, &data
->flags
))
304 usb_anchor_urb(urb
, &data
->bulk_anchor
);
306 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
308 BT_ERR("%s urb %p failed to resubmit (%d)",
309 hdev
->name
, urb
, -err
);
310 usb_unanchor_urb(urb
);
314 static int btusb_submit_bulk_urb(struct hci_dev
*hdev
)
316 struct btusb_data
*data
= hdev
->driver_data
;
322 BT_DBG("%s", hdev
->name
);
324 if (!data
->bulk_rx_ep
)
327 urb
= usb_alloc_urb(0, GFP_KERNEL
);
331 size
= le16_to_cpu(data
->bulk_rx_ep
->wMaxPacketSize
);
333 buf
= kmalloc(size
, GFP_KERNEL
);
339 pipe
= usb_rcvbulkpipe(data
->udev
, data
->bulk_rx_ep
->bEndpointAddress
);
341 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
342 buf
, size
, btusb_bulk_complete
, hdev
);
344 urb
->transfer_flags
|= URB_FREE_BUFFER
;
346 usb_anchor_urb(urb
, &data
->bulk_anchor
);
348 err
= usb_submit_urb(urb
, GFP_KERNEL
);
350 BT_ERR("%s urb %p submission failed (%d)",
351 hdev
->name
, urb
, -err
);
352 usb_unanchor_urb(urb
);
361 static void btusb_isoc_complete(struct urb
*urb
)
363 struct hci_dev
*hdev
= urb
->context
;
364 struct btusb_data
*data
= hdev
->driver_data
;
367 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
368 urb
, urb
->status
, urb
->actual_length
);
370 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
373 if (urb
->status
== 0) {
374 for (i
= 0; i
< urb
->number_of_packets
; i
++) {
375 unsigned int offset
= urb
->iso_frame_desc
[i
].offset
;
376 unsigned int length
= urb
->iso_frame_desc
[i
].actual_length
;
378 if (urb
->iso_frame_desc
[i
].status
)
381 hdev
->stat
.byte_rx
+= length
;
383 if (hci_recv_fragment(hdev
, HCI_SCODATA_PKT
,
384 urb
->transfer_buffer
+ offset
,
386 BT_ERR("%s corrupted SCO packet", hdev
->name
);
392 if (!test_bit(BTUSB_ISOC_RUNNING
, &data
->flags
))
395 usb_anchor_urb(urb
, &data
->isoc_anchor
);
397 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
399 BT_ERR("%s urb %p failed to resubmit (%d)",
400 hdev
->name
, urb
, -err
);
401 usb_unanchor_urb(urb
);
405 static void inline __fill_isoc_descriptor(struct urb
*urb
, int len
, int mtu
)
409 BT_DBG("len %d mtu %d", len
, mtu
);
411 for (i
= 0; i
< BTUSB_MAX_ISOC_FRAMES
&& len
>= mtu
;
412 i
++, offset
+= mtu
, len
-= mtu
) {
413 urb
->iso_frame_desc
[i
].offset
= offset
;
414 urb
->iso_frame_desc
[i
].length
= mtu
;
417 if (len
&& i
< BTUSB_MAX_ISOC_FRAMES
) {
418 urb
->iso_frame_desc
[i
].offset
= offset
;
419 urb
->iso_frame_desc
[i
].length
= len
;
423 urb
->number_of_packets
= i
;
426 static int btusb_submit_isoc_urb(struct hci_dev
*hdev
)
428 struct btusb_data
*data
= hdev
->driver_data
;
434 BT_DBG("%s", hdev
->name
);
436 if (!data
->isoc_rx_ep
)
439 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_KERNEL
);
443 size
= le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
) *
444 BTUSB_MAX_ISOC_FRAMES
;
446 buf
= kmalloc(size
, GFP_KERNEL
);
452 pipe
= usb_rcvisocpipe(data
->udev
, data
->isoc_rx_ep
->bEndpointAddress
);
454 urb
->dev
= data
->udev
;
457 urb
->complete
= btusb_isoc_complete
;
458 urb
->interval
= data
->isoc_rx_ep
->bInterval
;
460 urb
->transfer_flags
= URB_FREE_BUFFER
| URB_ISO_ASAP
;
461 urb
->transfer_buffer
= buf
;
462 urb
->transfer_buffer_length
= size
;
464 __fill_isoc_descriptor(urb
, size
,
465 le16_to_cpu(data
->isoc_rx_ep
->wMaxPacketSize
));
467 usb_anchor_urb(urb
, &data
->isoc_anchor
);
469 err
= usb_submit_urb(urb
, GFP_KERNEL
);
471 BT_ERR("%s urb %p submission failed (%d)",
472 hdev
->name
, urb
, -err
);
473 usb_unanchor_urb(urb
);
482 static void btusb_tx_complete(struct urb
*urb
)
484 struct sk_buff
*skb
= urb
->context
;
485 struct hci_dev
*hdev
= (struct hci_dev
*) skb
->dev
;
487 BT_DBG("%s urb %p status %d count %d", hdev
->name
,
488 urb
, urb
->status
, urb
->actual_length
);
490 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
494 hdev
->stat
.byte_tx
+= urb
->transfer_buffer_length
;
499 kfree(urb
->setup_packet
);
504 static int btusb_open(struct hci_dev
*hdev
)
506 struct btusb_data
*data
= hdev
->driver_data
;
509 BT_DBG("%s", hdev
->name
);
511 if (test_and_set_bit(HCI_RUNNING
, &hdev
->flags
))
514 if (test_and_set_bit(BTUSB_INTR_RUNNING
, &data
->flags
))
517 err
= btusb_submit_intr_urb(hdev
);
519 clear_bit(BTUSB_INTR_RUNNING
, &hdev
->flags
);
520 clear_bit(HCI_RUNNING
, &hdev
->flags
);
526 static int btusb_close(struct hci_dev
*hdev
)
528 struct btusb_data
*data
= hdev
->driver_data
;
530 BT_DBG("%s", hdev
->name
);
532 if (!test_and_clear_bit(HCI_RUNNING
, &hdev
->flags
))
535 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
536 usb_kill_anchored_urbs(&data
->intr_anchor
);
538 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
539 usb_kill_anchored_urbs(&data
->bulk_anchor
);
541 clear_bit(BTUSB_INTR_RUNNING
, &data
->flags
);
542 usb_kill_anchored_urbs(&data
->intr_anchor
);
547 static int btusb_flush(struct hci_dev
*hdev
)
549 struct btusb_data
*data
= hdev
->driver_data
;
551 BT_DBG("%s", hdev
->name
);
553 usb_kill_anchored_urbs(&data
->tx_anchor
);
558 static int btusb_send_frame(struct sk_buff
*skb
)
560 struct hci_dev
*hdev
= (struct hci_dev
*) skb
->dev
;
561 struct btusb_data
*data
= hdev
->driver_data
;
562 struct usb_ctrlrequest
*dr
;
567 BT_DBG("%s", hdev
->name
);
569 if (!test_bit(HCI_RUNNING
, &hdev
->flags
))
572 switch (bt_cb(skb
)->pkt_type
) {
573 case HCI_COMMAND_PKT
:
574 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
578 dr
= kmalloc(sizeof(*dr
), GFP_ATOMIC
);
584 dr
->bRequestType
= USB_TYPE_CLASS
;
588 dr
->wLength
= __cpu_to_le16(skb
->len
);
590 pipe
= usb_sndctrlpipe(data
->udev
, 0x00);
592 usb_fill_control_urb(urb
, data
->udev
, pipe
, (void *) dr
,
593 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
598 case HCI_ACLDATA_PKT
:
599 if (!data
->bulk_tx_ep
|| hdev
->conn_hash
.acl_num
< 1)
602 urb
= usb_alloc_urb(0, GFP_ATOMIC
);
606 pipe
= usb_sndbulkpipe(data
->udev
,
607 data
->bulk_tx_ep
->bEndpointAddress
);
609 usb_fill_bulk_urb(urb
, data
->udev
, pipe
,
610 skb
->data
, skb
->len
, btusb_tx_complete
, skb
);
615 case HCI_SCODATA_PKT
:
616 if (!data
->isoc_tx_ep
|| hdev
->conn_hash
.sco_num
< 1)
619 urb
= usb_alloc_urb(BTUSB_MAX_ISOC_FRAMES
, GFP_ATOMIC
);
623 pipe
= usb_sndisocpipe(data
->udev
,
624 data
->isoc_tx_ep
->bEndpointAddress
);
626 urb
->dev
= data
->udev
;
629 urb
->complete
= btusb_tx_complete
;
630 urb
->interval
= data
->isoc_tx_ep
->bInterval
;
632 urb
->transfer_flags
= URB_ISO_ASAP
;
633 urb
->transfer_buffer
= skb
->data
;
634 urb
->transfer_buffer_length
= skb
->len
;
636 __fill_isoc_descriptor(urb
, skb
->len
,
637 le16_to_cpu(data
->isoc_tx_ep
->wMaxPacketSize
));
646 usb_anchor_urb(urb
, &data
->tx_anchor
);
648 err
= usb_submit_urb(urb
, GFP_ATOMIC
);
650 BT_ERR("%s urb %p submission failed", hdev
->name
, urb
);
651 kfree(urb
->setup_packet
);
652 usb_unanchor_urb(urb
);
660 static void btusb_destruct(struct hci_dev
*hdev
)
662 struct btusb_data
*data
= hdev
->driver_data
;
664 BT_DBG("%s", hdev
->name
);
669 static void btusb_notify(struct hci_dev
*hdev
, unsigned int evt
)
671 struct btusb_data
*data
= hdev
->driver_data
;
673 BT_DBG("%s evt %d", hdev
->name
, evt
);
675 if (evt
== HCI_NOTIFY_CONN_ADD
|| evt
== HCI_NOTIFY_CONN_DEL
)
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
.acl_num
> 0) {
728 if (!test_and_set_bit(BTUSB_BULK_RUNNING
, &data
->flags
)) {
729 if (btusb_submit_bulk_urb(hdev
) < 0)
730 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
732 btusb_submit_bulk_urb(hdev
);
735 clear_bit(BTUSB_BULK_RUNNING
, &data
->flags
);
736 usb_kill_anchored_urbs(&data
->bulk_anchor
);
739 if (hdev
->conn_hash
.sco_num
> 0) {
740 if (data
->isoc_altsetting
!= 2) {
741 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
742 usb_kill_anchored_urbs(&data
->isoc_anchor
);
744 if (__set_isoc_interface(hdev
, 2) < 0)
748 if (!test_and_set_bit(BTUSB_ISOC_RUNNING
, &data
->flags
)) {
749 if (btusb_submit_isoc_urb(hdev
) < 0)
750 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
752 btusb_submit_isoc_urb(hdev
);
755 clear_bit(BTUSB_ISOC_RUNNING
, &data
->flags
);
756 usb_kill_anchored_urbs(&data
->isoc_anchor
);
758 __set_isoc_interface(hdev
, 0);
762 static int btusb_probe(struct usb_interface
*intf
,
763 const struct usb_device_id
*id
)
765 struct usb_endpoint_descriptor
*ep_desc
;
766 struct btusb_data
*data
;
767 struct hci_dev
*hdev
;
770 BT_DBG("intf %p id %p", intf
, id
);
772 /* interface numbers are hardcoded in the spec */
773 if (intf
->cur_altsetting
->desc
.bInterfaceNumber
!= 0)
776 if (!id
->driver_info
) {
777 const struct usb_device_id
*match
;
778 match
= usb_match_id(intf
, blacklist_table
);
783 if (id
->driver_info
== BTUSB_IGNORE
)
786 if (ignore_dga
&& id
->driver_info
& BTUSB_DIGIANSWER
)
789 if (ignore_csr
&& id
->driver_info
& BTUSB_CSR
)
792 if (ignore_sniffer
&& id
->driver_info
& BTUSB_SNIFFER
)
795 data
= kzalloc(sizeof(*data
), GFP_KERNEL
);
799 for (i
= 0; i
< intf
->cur_altsetting
->desc
.bNumEndpoints
; i
++) {
800 ep_desc
= &intf
->cur_altsetting
->endpoint
[i
].desc
;
802 if (!data
->intr_ep
&& usb_endpoint_is_int_in(ep_desc
)) {
803 data
->intr_ep
= ep_desc
;
807 if (!data
->bulk_tx_ep
&& usb_endpoint_is_bulk_out(ep_desc
)) {
808 data
->bulk_tx_ep
= ep_desc
;
812 if (!data
->bulk_rx_ep
&& usb_endpoint_is_bulk_in(ep_desc
)) {
813 data
->bulk_rx_ep
= ep_desc
;
818 if (!data
->intr_ep
|| !data
->bulk_tx_ep
|| !data
->bulk_rx_ep
) {
823 data
->udev
= interface_to_usbdev(intf
);
825 spin_lock_init(&data
->lock
);
827 INIT_WORK(&data
->work
, btusb_work
);
829 init_usb_anchor(&data
->tx_anchor
);
830 init_usb_anchor(&data
->intr_anchor
);
831 init_usb_anchor(&data
->bulk_anchor
);
832 init_usb_anchor(&data
->isoc_anchor
);
834 hdev
= hci_alloc_dev();
840 hdev
->type
= HCI_USB
;
841 hdev
->driver_data
= data
;
845 SET_HCIDEV_DEV(hdev
, &intf
->dev
);
847 hdev
->open
= btusb_open
;
848 hdev
->close
= btusb_close
;
849 hdev
->flush
= btusb_flush
;
850 hdev
->send
= btusb_send_frame
;
851 hdev
->destruct
= btusb_destruct
;
852 hdev
->notify
= btusb_notify
;
854 hdev
->owner
= THIS_MODULE
;
856 /* interface numbers are hardcoded in the spec */
857 data
->isoc
= usb_ifnum_to_if(data
->udev
, 1);
859 if (reset
|| id
->driver_info
& BTUSB_RESET
)
860 set_bit(HCI_QUIRK_RESET_ON_INIT
, &hdev
->quirks
);
862 if (force_scofix
|| id
->driver_info
& BTUSB_WRONG_SCO_MTU
) {
864 set_bit(HCI_QUIRK_FIXUP_BUFFER_SIZE
, &hdev
->quirks
);
867 if (id
->driver_info
& BTUSB_BROKEN_ISOC
)
870 if (id
->driver_info
& BTUSB_SNIFFER
) {
871 struct usb_device
*udev
= data
->udev
;
873 if (le16_to_cpu(udev
->descriptor
.bcdDevice
) > 0x997)
874 set_bit(HCI_QUIRK_RAW_DEVICE
, &hdev
->quirks
);
879 if (id
->driver_info
& BTUSB_BCM92035
) {
880 unsigned char cmd
[] = { 0x3b, 0xfc, 0x01, 0x00 };
883 skb
= bt_skb_alloc(sizeof(cmd
), GFP_KERNEL
);
885 memcpy(skb_put(skb
, sizeof(cmd
)), cmd
, sizeof(cmd
));
886 skb_queue_tail(&hdev
->driver_init
, skb
);
891 err
= usb_driver_claim_interface(&btusb_driver
,
900 err
= hci_register_dev(hdev
);
907 usb_set_intfdata(intf
, data
);
912 static void btusb_disconnect(struct usb_interface
*intf
)
914 struct btusb_data
*data
= usb_get_intfdata(intf
);
915 struct hci_dev
*hdev
;
917 BT_DBG("intf %p", intf
);
925 usb_driver_release_interface(&btusb_driver
, data
->isoc
);
927 usb_set_intfdata(intf
, NULL
);
929 hci_unregister_dev(hdev
);
934 static struct usb_driver btusb_driver
= {
936 .probe
= btusb_probe
,
937 .disconnect
= btusb_disconnect
,
938 .id_table
= btusb_table
,
941 static int __init
btusb_init(void)
943 BT_INFO("Generic Bluetooth USB driver ver %s", VERSION
);
945 return usb_register(&btusb_driver
);
948 static void __exit
btusb_exit(void)
950 usb_deregister(&btusb_driver
);
953 module_init(btusb_init
);
954 module_exit(btusb_exit
);
956 module_param(ignore_dga
, bool, 0644);
957 MODULE_PARM_DESC(ignore_dga
, "Ignore devices with id 08fd:0001");
959 module_param(ignore_csr
, bool, 0644);
960 MODULE_PARM_DESC(ignore_csr
, "Ignore devices with id 0a12:0001");
962 module_param(ignore_sniffer
, bool, 0644);
963 MODULE_PARM_DESC(ignore_sniffer
, "Ignore devices with id 0a12:0002");
965 module_param(disable_scofix
, bool, 0644);
966 MODULE_PARM_DESC(disable_scofix
, "Disable fixup of wrong SCO buffer size");
968 module_param(force_scofix
, bool, 0644);
969 MODULE_PARM_DESC(force_scofix
, "Force fixup of wrong SCO buffers size");
971 module_param(reset
, bool, 0644);
972 MODULE_PARM_DESC(reset
, "Send HCI reset command on initialization");
974 MODULE_AUTHOR("Marcel Holtmann <marcel@holtmann.org>");
975 MODULE_DESCRIPTION("Generic Bluetooth USB driver ver " VERSION
);
976 MODULE_VERSION(VERSION
);
977 MODULE_LICENSE("GPL");