Monday, December 16, 2013

Linux Tip: How to Pair your Bluetooth Device when Using Bluez 5.x and Kernel 3.11-12

It seems like there are problems with Bluez 5.x and newer kernels, especially post 3.10 ones. Since 3.13 is not yet out, these tips apply to kernel 3.11 and 3.12.

I specifically tested and applied the solution below to pair my Microsoft keyboard and mouse. My specifications are as follows:

[bluetooth]# version
Version 5.10
csaba ~ # uname -a
Linux csaba 3.12.0-sabayon #1 SMP Tue Dec 3 15:10:14 UTC 2013 x86_64 Intel(R) Core(TM) i7-3770 CPU @ 3.40GHz GenuineIntel GNU/Linux

So if you were looking for things like:
I can't pair my bluetooth keyboard on Linux
My bluetooth mouse won't work on newer kernel
My bluetooth headset pairs but doesn't connect
My phone can be discovered but not connected or paired over bluetooth
... then here is how to do it with bluetoothctl.

csaba ~ # bluetoothctl 
[NEW] Controller 00:15:83:3D:0A:57 csaba-0 [default]
[NEW] Device 7C:1E:52:A8:47:74 Microsoft Bluetooth Mobile Keyboard 6000

Start bluetoothctl. Mine found the keyboard automatically with it set in discoverable mode. However, it is possible you will need to enable scanning. Just write:

[bluetooth]# scan on

If it is not showing up at this point, you may have problems with your bluetooth receiver or the device is not set in discoverable mode (with that "connect" button pressed).

After my device was found I wen on immediately and tried to pair it. However, it asked for no PIN or anything, it just timed out with an error that I failed to provide correct PIN code. This made me think, maybe I missed something. And I did.

[bluetooth]# default-agent
No agent is registered

There was no default-agent. Now, I do not exactly know what these agents are, so if you know, feel free to comment below with details. However we can easily start one.

[bluetooth]# agent on
Agent registered

And we try to pair now...

[bluetooth]# pair 7C:1E:52:A8:47:74
Attempting to pair with 7C:1E:52:A8:47:74
[CHG] Device 7C:1E:52:A8:47:74 Connected: yes
[agent] PIN code: 241178
[CHG] Device 7C:1E:52:A8:47:74 Modalias: usb:v045Ep0762d0013
[CHG] Device 7C:1E:52:A8:47:74 Modalias: usb:v045Ep0762d0013
[CHG] Device 7C:1E:52:A8:47:74 UUIDs has unsupported type
[CHG] Device 7C:1E:52:A8:47:74 Paired: yes
Pairing successful
[CHG] Device 7C:1E:52:A8:47:74 Connected: no

So we are halfway there. Paired, but not yet connected. I also noted at this point, that the "connecting" LEDs on my devices were still blinking. So the keyboard and mouse did not yet know about the computer. But I could see them...

[bluetooth]# info 7C:1E:52:A8:47:74
Device 7C:1E:52:A8:47:74
        Name: Microsoft Bluetooth Mobile Keyboard 6000
        Alias: Microsoft Bluetooth Mobile Keyboard 6000
        Class: 0x002540
        Icon: input-keyboard
        Paired: yes
        Trusted: no
        Blocked: no
        Connected: no
        LegacyPairing: yes
        UUID: Service Discovery Serve.. (00001000-0000-1000-8000-00805f9b34fb)
        UUID: Human Interface Device... (00001124-0000-1000-8000-00805f9b34fb)
        UUID: PnP Information           (00001200-0000-1000-8000-00805f9b34fb)
        Modalias: usb:v045Ep0762d0013

So I went on and trusted the device.

[bluetooth]# trust 7C:1E:52:A8:47:74
[CHG] Device 7C:1E:52:A8:47:74 Trusted: yes
Changing 7C:1E:52:A8:47:74 trust succeeded

Then connecting worked. The blinking LEDs turned off. Great. And the connection remained ON.

[bluetooth]# connect 7C:1E:52:A8:47:74
Attempting to connect to 7C:1E:52:A8:47:74
[CHG] Device 7C:1E:52:A8:47:74 Connected: yes
Connection successful
[CHG] Device 7C:1E:52:A8:47:74 Modalias: usb:v045Ep0762d0013
[CHG] Device 7C:1E:52:A8:47:74 Modalias: usb:v045Ep0762d0013

I did reboot my computer and the settings are persistent. I know these devices are working correctly on my computer, I had them paired and working for the past year or so. In fact, if you had them paired before you upgraded to 3.11-12 kernels, you will have them working. Only pairing fails.

I could not find out a way to make pairing work from KDE or other desktop environments.

I hope I could help some of you, and save you some precious time.

Have a nice day.

No comments:

Post a Comment