# USB, hotplug, and 2.6.1: bluetooth adventures

## ozonator

Not completely discouraged by my continuing problems getting gphoto2 to work in 2.6.1 (which others are having, too), I decided to try my USB bluetooth dongle, a D-link DBT-120.  The device works -- I've used it with MacOS X to communicate with my Palm -- but it's been a bit of an adventure to get it to work in Linux.

After following the preliminary steps described in this thread -- emerged the appropriate bluez ebuilds (latest versions of each), made sure I had the right kernel modules (SCO support in disabled, just in case) -- I found that something wasn't right.  hciconfig reported the bluetooth device address as 00:00:00:00:00:00, and that the device was 'down'.  Running 'hciconfig hci0 up' had no effect -- in fact, that process seemed to hang, and after trying that, not only could I not get the dongle to work, I had to cold reboot the machine to get the power and link lights to work again.

So, time to check the system logs.  Here's what I got when I plugged the dongle in:

```
Jan 15 22:15:40 [kernel] hub 4-0:1.0: new USB device on port 2, assigned address 3

Jan 15 22:15:41 [kernel] hci_usb: probe of 4-2:1.1 failed with error -5

Jan 15 22:15:41 [hcid] HCI dev 0 registered

Jan 15 22:15:41 [kernel] usb 4-2: control timeout on ep0in

Jan 15 22:15:41 [hcid] HCI dev 0 up

Jan 15 22:15:41 [hcid] Starting security manager 0

Jan 15 22:15:41 [kernel] usb 4-2: control timeout on ep0in

                - Last output repeated 290 times -

Jan 15 22:15:51 [hcid] Can't set auth on hci0. Connection timed out(110)_

Jan 15 22:15:51 [kernel] hci_cmd_task: hci0 command tx timeout

Jan 15 22:15:51 [kernel] usb 4-2: control timeout on ep0in

                - Last output repeated 141 times -

Jan 15 22:16:01 [hcid] Can't set encrypt on hci0. Connection timed out(110)_

Jan 15 22:16:01 [kernel] hci_cmd_task: hci0 command tx timeout

Jan 15 22:16:01 [kernel] usb 4-2: control timeout on ep0in

                - Last output repeated 4 times -

Jan 15 22:16:14 [hcid] HCI dev 0 down
```

After googling (unsuccessfully) for a solution, I unplugged the dongle and tried again:

```
Jan 15 22:33:34 [kernel] hub 4-0:1.0: new USB device on port 2, assigned address 4

Jan 15 22:33:35 [kernel] hci_usb: probe of 4-2:1.1 failed with error -5

Jan 15 22:33:35 [hcid] HCI dev 0 registered

Jan 15 22:33:35 [hcid] HCI dev 0 up

Jan 15 22:33:35 [hcid] Starting security manager 0

Jan 15 22:33:35 [kernel] usb 4-2: control timeout on ep0in

                - Last output repeated 5 times -

Jan 15 22:33:45 [hcid] Can't set scan mode on hci0. Connection timed out(110)_

Jan 15 22:33:45 [kernel] hci_cmd_task: hci0 command tx timeout

Jan 15 22:33:55 [hcid] Can't set auth on hci0. Connection timed out(110)_

Jan 15 22:33:55 [kernel] hci_cmd_task: hci0 command tx timeout

Jan 15 22:34:05 [hcid] Can't set encrypt on hci0. Connection timed out(110)_

Jan 15 22:34:05 [kernel] hci_cmd_task: hci0 command tx timeout

Jan 15 22:37:51 [hcid] HCI dev 0 down
```

This is essentially the same set of errors, except there were fewer 'control timeout' errors, and there's an additional 'can't set scan mode' error.

Finally, I tried once more:

```
Jan 15 22:49:17 [kernel] hub 4-0:1.0: new USB device on port 2, assigned address 5

Jan 15 22:49:22 [kernel] usb 4-2: control timeout on ep0out

                - Last output repeated twice -

Jan 15 22:50:00 [kernel] usb 4-2: device not accepting address 5, error -110
```

This time, the power and link lights on the dongle didn't even light up.  I needed to cold reboot the machine to get them to light up again.

Having seen the suggestion to disable kernel hotplugging (on the thread about gphoto2 and 2.6.1, linked above), I tried that, leaving all other kernel options the same -- and this time, it worked!  After loading the modules, and plugging in the dongle, hciconfig reported a proper hardware address; I started bluetooth (/etc/init.d/bluetooth), and could link to the dongle from my Palm.  A little more poking and prodding (some variations on the instructions in the the thread linked above), and I could surf the net from the Palm.

The long and short of all this is that even though USB seems to be working (USB mouse and flash reader are working fine for me, including on an ehci hub), there's something not quite right with the state of USB and/or hotplug in 2.6.1, as my experiences with bluetooth and gphoto2 show.  Maybe knowing that will save some of you some troubleshooting time.  And, thought I don't know if these logs help the developers much, I suppose I hope the more information that is known about this, the quicker a fix might be found.  Anyone have any insights?

----------

## motaboy

Finally one with my ~same problem.

I've got similar errors but in a big number. I've already posted this but on the "Other things gentoo".

My solution was to plug the device before the kernel boot, only in this mode I can make the device works perfectly. Have you tried this?

I've made A LOT OF tries, I've disabled/enabled all the BIOS and kernel options like APIC, ACPI, assign irq to USB(in the BIOS) but nothing changed.

I've noticed that this isn't a bluez stuff because I've disabled all the bluetooth modules and the errors happened too.

Have you got a VIA USB chipset? I've got a KT400. unfortunately I don't have any other usb device to try with.

I've already posted the bugs at:

http://bugme.osdl.org/show_bug.cgi?id=1873 but no response for now.

Let me know if you have more infos!

Bye!

----------

## ozonator

I've tried having the bluetooth dongle plugged in before the machine boots, but that didn't seem to help.  When I do that, I have to unplug and re-plug it after the bluetooth modules are loaded.  I don't know if compiling bluetooth support into the kernel would make that any different; I haven't tried, and so far am only using modules.

My usb controllers all have VIA chipsets.  I have three USB 1.1 controllers on my motherboard, which uses the KT266A chipset, and a USB 2.0 pci card, also with a VIA chip.  Interestingly, lspci -v indicates 'wrong id' where one might expect to see a chip name, e.g.:

```
00:0e.1 USB Controller: VIA Technologies, Inc. USB (rev 50) (prog-if 00 [UHCI])

        Subsystem: VIA Technologies, Inc. (Wrong ID) USB Controller

        Flags: bus master, medium devsel, latency 32, IRQ 5

        I/O ports at b000 [size=32]

        Capabilities: [80] Power Management version 2

00:0e.2 USB Controller: VIA Technologies, Inc. USB 2.0 (rev 51) (prog-if 20 [EHCI])

        Subsystem: VIA Technologies, Inc. (Wrong ID): Unknown device 1234

        Flags: bus master, medium devsel, latency 32, IRQ 9

        Memory at f6800000 (32-bit, non-prefetchable) [size=256]

        Capabilities: [80] Power Management version 2

```

Other than that, and repeating that disabling hotplug was key to getting this to work, I have only one other thing to add:  after using the bluetooth connection for a while, connecting/disconnecting etc., I've had a couple of serious crashes.  In each case, I got a 'serial error', on the Palm, specifically:  "Error: Serial: timeout. Could be bad cable or faulty Modem (0x0305)".  And, in each case, this was followed very shortly by a crash of the linux desktop, i.e., complete freeze of the machine, requiring hitting the reset button on the computer.  This error is in the Palm 'support knowledge library', where it's suggested that it's the result of bluetooth not being turned on (not the case here), or if the Palm is no longer in the list of linked devices on the computer/phone (shouldn't be the case here, since I didn't remove it on the linux side).  In any case, this is a little distressing, and there's no information at all left behind in the system log.  I'll see how it goes, and if I can get some more useful debugging info; most of the time, however, it's working fine now.

----------

## ozonator

Having just gotten that serial error on the Palm again, and subsequently failed to get a bluetooth connection with Linux, I've found another clue.  I decided to unload and reload the bluetooth modules, but found I can't remove the l2cap module, which is reported to be 'in use'.  Looking with lsmod, here are the bluetooth modules still in the kernel:

```
Module                  Size  Used by

l2cap                  21760  4294967294 

hci_usb                 9472  1 

bluetooth              42724  2 l2cap,hci_usb
```

Seems like something is going seriously wrong with the l2cap module, given the number in the 'used by' column.  Nothing out of order in the system logs, but given that I've had hard crashes a couple times already today, I think it's time I rebooted...

----------

## motaboy

The last Marcel Holtmann patch for 2.6.1 fixes a bug related to the connection counter in the l2cap. You can find it here:

http://www.holtmann.org/linux/kernel/patch-2.6.1-mh3.gz

Bye!

----------

## motaboy

I've found the solutions to my problem.

I've got to umount the usbfs before plugging the device. For this reason it worked well when I plugged it before the init scripts start, because the usbfs wasn't already loaded. I don't know if this is a solution for your problem but you can always try.

Bye!

----------

## ozonator

 *motaboy wrote:*   

> The last Marcel Holtmann patch for 2.6.1 fixes a bug related to the connection counter in the l2cap. You can find it here:
> 
> http://www.holtmann.org/linux/kernel/patch-2.6.1-mh3.gz
> 
> Bye!

 

Many thanks for the link!  His web pages don't list that; where did you find it?

I've applied the patches, rebooted, loaded the modules and ran the scripts.  All seems well enough so far, and the 'used by' number for l2cap seems much more sane:

```
Module                  Size  Used by

bnep                   12800  2 

rfcomm                 34968  3 

l2cap                  21760  9 bnep,rfcomm

hci_usb                 9536  2 

bluetooth              42980  8 bnep,rfcomm,l2cap,hci_usb
```

One other thing I notice now:  the device class (reported and/or set with hciconfig is correctly set now by hcid).  Previously, it would be 0x000000, now it's 0x000100, which is what I want.

Thanks again.  With luck, this patched version will be stable!

----------

## motaboy

I'm happy that this work!

I'm subscribed to the bluez-devel mailing list and I've found it here because Marcel Holtmann don't have enought time to update the webpage. 

Now I've written to the usb-devel list for the usbfs problem and they gived me a patch to try, I'll try it in this days.

Bye!

----------

## kryoboy

Hi, hcitool scan, will pickup my mouse and keyboard, what to do now to make them work ? please help. woooooee =P lol

----------

