# bluetooth keyboard can only reconnect once

## doro1211

So I got a Bluetooth Multimedia Keyboard with Trackpad (Azio KB337BP).  Great keyboard so far, but I'm having trouble getting it working with Gentoo.  I know the Bluez project is about the worst in the entire open source world for documentation, but I'm hoping someone can help from experience.

First, I'm using Bluez 4.87.  I have also used 4.82 - no diff.  Kernel is gentoo-sources 2.6.35-r15 (can't go newer as the lirc in the portage tree does not work with 2.6.36).  I have used both gnome-bluetooth and blueman - same issues.  I have tried 2 adapters, different chipsets, both which support Linux and are recognized automatically in the kernel (cirago and iogear).

The keyboard has multiple pairings (6 total).  One is set to a windows 7 pc.  This one works perfectly.  The others are all set to various Gentoo Linux pc's (one is the alter-ego dual boot of the windows 7 pc).  They all have the same issues (all same gentoo versioning).  The initial pairing and connection work perfectly.  Keyboard and pad work - even multimedia keys work.  If I disconnect (either by rebooting, turning off the keyboard, or switching inputs), then reconnect, it works once usually.  The second time and thereafter it fails.  On th Windows 7 PC it always reconnects perfectly.

I get this in /var/log/messages: (the more I type or move the pad, the more messages are generated of this type)

Feb 13 11:52:16 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Feb 13 11:52:23 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Feb 13 11:52:58 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Once this happens, I cannot re-pair the device (it does seem to be already paired, but connecting now fails in blueman).  Removing and re-pairing fails with the same error.  The only way to make it work again is to rm -rf /var/lib/bluetooth/*, remove it from blueman, reset the keyboard, and start over.

I have tried everything and am at a complete loss.  I do not know if this is a bluetooth error at the kernel level or userspace, a dbus error (note some weird dbus errors in /var/log/messages - googling has suggested these may be harmless), or something entirely different.  If anyone has encountered a similar situation and can offer advice, it would be much appreciated.  I am also including some output from dmesg on Bluetooth.  Irrelevant sections of dmesg have been cut to save space and make it more readable, but let me know if anything else I can provide would be useful.

partial dmesg output:

Bluetooth: Core ver 2.15

NET: Registered protocol family 31

Bluetooth: HCI device and connection manager initialized

Bluetooth: HCI socket layer initialized

...

Bluetooth: Virtual HCI driver ver 1.3

Bluetooth: HCI UART driver ver 2.2

Bluetooth: HCI H4 protocol initialized

Bluetooth: HCI BCSP protocol initialized

Bluetooth: HCILL protocol initialized

Bluetooth: Broadcom Blutonium firmware driver ver 1.2

usbcore: registered new interface driver bcm203x

Bluetooth: Digianswer Bluetooth USB driver ver 0.10

usbcore: registered new interface driver bpa10x

Bluetooth: BlueFRITZ! USB driver ver 1.2

usbcore: registered new interface driver bfusb

Bluetooth: Generic Bluetooth USB driver ver 0.6

usbcore: registered new interface driver btusb

Bluetooth: Generic Bluetooth SDIO driver ver 0.1

Bluetooth: Atheros AR30xx firmware driver ver 1.0

usbcore: registered new interface driver ath3k

...

Bluetooth: L2CAP ver 2.14

Bluetooth: L2CAP socket layer initialized

Bluetooth: SCO (Voice Link) ver 0.6

Bluetooth: SCO socket layer initialized

Bluetooth: RFCOMM TTY layer initialized

Bluetooth: RFCOMM socket layer initialized

Bluetooth: RFCOMM ver 1.11

Bluetooth: BNEP (Ethernet Emulation) ver 1.3

Bluetooth: BNEP filters: protocol multicast

Bluetooth: HIDP (Human Interface Emulation) ver 1.2

...

input: Bluetooth Keyboard With TouchPad as /devices/pci0000:00/0000:00:04.0/usb4/4-2/4-2.3/4-2.3:1.0/bluetooth/hci0/hci0:11/input8

generic-bluetooth 0005:099A:6371.0006: input,hidraw5: BLUETOOTH HID v1.1b Keyboard [Bluetooth Keyboard With TouchPad] on

input: Bluetooth Keyboard With TouchPad as /devices/pci0000:00/0000:00:04.0/usb4/4-2/4-2.3/4-2.3:1.0/bluetooth/hci0/hci0:11/input9

generic-bluetooth 0005:099A:6371.0007: input,hidraw5: BLUETOOTH HID v1.1b Keyboard [Bluetooth Keyboard With TouchPad] on

(the last part probably appears twice because it usually connects initially, then one more time, then fails thereafter - that message generally means the connection has been established and the kb is working)

output of tail -1000 /var/log/messages | grep -i blue 

Feb 13 11:46:37 varda rc-scripts: ERROR:  bluetooth is already starting.

Feb 13 11:46:37 varda bluetoothd[4555]: Bluetooth deamon 4.87

Feb 13 11:46:37 varda bluetoothd[4556]: Starting SDP server

Feb 13 11:46:37 varda bluetoothd[4556]: Failed to open RFKILL control device

Feb 13 11:46:37 varda bluetoothd[4556]: HCI dev 0 registered

Feb 13 11:46:37 varda bluetoothd[4556]: Listening for HCI events on hci0

Feb 13 11:46:37 varda bluetoothd[4556]: HCI dev 0 up

Feb 13 11:46:37 varda bluetoothd[4556]: Clearing blocked list failed: Invalid argument (22)

Feb 13 11:46:37 varda bluetoothd[4556]: Adapter /org/bluez/4555/hci0 has been enabled

Feb 13 11:47:35 varda blueman-mechanism: Starting blueman-mechanism 

Feb 13 11:47:35 varda blueman-mechanism: reload 0 0 

Feb 13 11:48:05 varda blueman-mechanism: Exiting 

Feb 13 11:49:01 varda bluetoothd[4556]: Discovery session 0x7fc30238e570 with :1.30 activated

Feb 13 11:49:12 varda bluetoothd[4556]: Stopping discovery

Feb 13 11:49:26 varda dbus-daemon: [system] Rejected send message, 1 matched rules; type="method_return", sender=":1.32" (uid=103 pid=5785 comm="/usr/bin/python2.6) interface="(unset)" member="(unset)" error name="(unset)" requested_reply=0 destination=":1.1" (uid=0 pid=4555 comm="/usr/sbin/bluetoothd))

Feb 13 11:49:36 varda kernel: input: Bluetooth Keyboard With TouchPad as /devices/pci0000:00/0000:00:04.0/usb4/4-2/4-2.3/4-2.3:1.0/bluetooth/hci0/hci0:11/input8

Feb 13 11:49:36 varda kernel: generic-bluetooth 0005:099A:6371.0006: input,hidraw5: BLUETOOTH HID v1.1b Keyboard [Bluetooth Keyboard With TouchPad]

Feb 13 11:51:41 varda kernel: input: Bluetooth Keyboard With TouchPad as /devices/pci0000:00/0000:00:04.0/usb4/4-2/4-2.3/4-2.3:1.0/bluetooth/hci0/hci0:11/input9

Feb 13 11:51:41 varda kernel: generic-bluetooth 0005:099A:6371.0007: input,hidraw5: BLUETOOTH HID v1.1b Keyboard [Bluetooth Keyboard With TouchPad]

Feb 13 11:52:16 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Feb 13 11:52:23 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Feb 13 11:52:58 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Feb 13 11:53:17 varda bluetoothd[4556]: Host is down (112)

Feb 13 11:53:35 varda bluetoothd[4556]: Host is down (112)

Feb 13 12:03:18 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Feb 13 12:03:25 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

Feb 13 12:13:33 varda bluetoothd[4556]: Encryption failed: Permission denied(0x5)

----------

