Bluetooth mouse on Linux

My friends have finally persuaded me to try the new Linux distributions. They were telling me that Linux offers everything Windows does and then some. Well, I’ve got to see that and when the conditions matured for me (like having appropriate hardware) I have installed Fedora 10 (Cambridge).

I couldn’t believe how improved the Linux system is compared to my trials at university, approximately 6 years ago. Almost all of the devices on the laptop where I installed Fedora were automatically identified and running after the initial install. The most outstanding issues, from easiest solved to the hardest, were related to the audio codec, the fingerprint reader, and the bluetooth mouse. Obviously, this article is about my findings on how to connect the bluetooth mouse to a Fedora 10 powered laptop whose built-in bluetooth dongle is installed properly.

First of all, let me share with you my worst findings throughout this journey:

- Linux people aren’t half willing to help a newbie as Microsoft people. (Nobody on IRC channels offered any help but referring me to Google, even after I told them repeatedly that I had spent almost 12 hours on Google trying to fix the issue. Good thing they didn’t refer me to AltaVista. Obviously these people are a little too arrogant to deal with minor issues?!)

- BlueZ has such a neat page but they don’t offer a clear and up to date user manual. There is a developer wiki only. (Maybe because they are too confident that everything would work hassle-free or maybe they are too busy.)

The latter is much more understandable since everything is free. So I am now trying to fill this gap a little with this post.

My setup is  as follows:

- Windows Vista SP1 (dual boot)

- Fedora 10 with BlueZ 4.22 (I’d expect the other distros with BlueZ to behave the same. Users of older BlueZ versions don’t need to read this article.)

- Microsoft Bluetooth Notebook Mouse 5000 (Accepts both PIN-less connection and PIN 0000 like most OEM mice do).

Now the initial steps of installation:

  • Boot Vista first. Since Vista offers much less control over the connected devices it goes first and we will work on the issues later with Fedora.
  • Turn on the mouse and hit the bottom button so that the mouse is ready to be paired.
  • Pair the mouse as usual by going through the necessary steps: Go to Control Panel -> Bluetooth Devices, click Add and follow instructions. I chose “No passkey” option instead of using 0000. That doesn’t seem to matter. You can try other if one doesn’t work at the end.
  • The mouse driver would be installed. Make sure that the buttons work.
  • Reboot to Fedora 10.
  • Login to Gnome Desktop as your regular user and go to: System -> Preferences -> Hardware -> Bluetooth.
  • Hit its bottom button so that the mouse is ready to be paired.
  • Click “Setup new device” and follow the instructions . If you can use the mouse without further ado you are probably done. The following instructions are for the less lucky people like me.
  • Keep in mind that you should complete all of the following steps before the pairing timeout occurs.
  • Open a terminal and become root. (Or use sudo as per your taste)
  • Go to bluetooth dongle setting directory and find your mouse’s hardware ID.

$ su root
$ cat /var/lib/bluetooth/*/lastseen | cut -c 1-17
00:xx:xx:xx:xx:x2

The x’ed part is axed for security reasons.

Now solving the first problem is relatively easy. Just use the HID daemon to connect the mouse. I had to do this since this mouse doesn’t support RFCOMM. This may be obvious to some but not to me.

$ hidd --connect 00:xx:xx:xx:xx:x2

Now you must be able to use your mouse. But we are not done yet. Actually following is the hardest part: to be able to use the mouse after a system restart and during the login screen. This is the part that took me hours to discover. Since we invoke the HID service manually BlueZ doesn’t save the linkkey* of the device. We would do this manually:1

$ echo 00:xx:xx:xx:xx:x2 01234567890012345678900123456789012 >> /var/lib/bluetooth/*/linkkeys

What is nice is that this mouse doesn’t require a PIN code so any linkkey should do. A linkkey is basically a 128-bit number and represented in hex so I just used the number you see above as a dummy linkkey. You could probably use any key provided it is represented in the linkkeys file with a 32 digit hexadecimal number.

The restart problem isn’t yet fixed. Apparently some dongles can’t perform a reconnect to an already paired device at boot time. This seems like a handshake/state problem. What needs to be done is a dongle reset at boot time. To accomplish this you should modify the bluetooth service startup script:

$ vi /etc/init.d/bluetooth

My startup script looks like this after modification:


start()
{
echo -n $"Starting Bluetooth services:"
daemon /usr/sbin/bluetoothd
RETVAL=$?
[ $RETVAL = 0 ] && touch /var/lock/subsys/bluetoothd
[ "$HID2HCI_ENABLE" = "true" ] && hid2hci --tohci > /dev/null 2>&1 || :
touch /var/lock/subsys/bluetooth
echo ""
sleep 1 && hciconfig hci0 reset
return $RETVAL
}

As you can see I just added the reset part. (Do not copy and directly paste this since my blog theme replaces some characters for better viewing) If this doesn’t work for you can try increasing the sleeping time. I have seen as far as 5 seconds in some posts. The built-in bluetooth dongle is named hci0 most of the time. You can see all devices using the following command:

$ hciconfig -a

At this time the reboot problem should be fixed. There is however, one last problem left. We have paired the mouse again and windows doesn’t know the latest linkkey. Even though we used a fake linkkey Microsoft will require a re-pairing. Linux people has foreseen this and provided a solution. It is very simple. We will just write the linkkey to the bluetooth dongle so that windows won’t require a re-pairing.

$ hciconfig hci0 putkey 00:xx:xx:xx:xx:x2

hci0 is the laptop dongle and the address is the device address of the paired mouse.

Voila. You can try to boot to either Fedora or Vista to see that your mouse works without re-pairing now. The down side is that you would probably have to go over some of these steps again if you pair the mouse with another device or accidentally click the pairing button under the mouse. That is because the linkkeys would need to be updated.

Now I can use my mouse as expected and probably so can you..

Happy happy joy joy!!

* When bluetooth devices pair, they mutually generate a symmetric key for encryption, which is called a linkkey.

References:
1 FAQs, Problems and Solutions, Internet Tablet Talk

Bu yazı English, Information Technology, Linux kategorisine gönderilmiş ve , , , , ile etiketlenmiş. Kalıcı bağlantıyı yer imlerinize ekleyin.
  • http://www.cubicorange.com/ cubicorange

    i thought you were writing in turkish? is this just to get higher up in google? :) i know how much time you spent to do all this, respect bro!
    btw: i dugg the story, hoping that it will help other people in need…

  • http://www.kirpininyeri.com kirpi

    Thanks a lot :) I’ll translate this into Turkish too. I am a little too lazy to start a sub blog for English speaking community :)

  • http://littlecornflakegirl.blogspot.com/ Cornflake Girl

    I really couldn’t figure out why linux people are reluctant to help you on these issues. It totally runs counter to the aim of linux concept? Or am I wrong?

    By the way, I appreciate you in terms of your detailed explanation. You’ve saved people’s time!! (lets say apprx. half a day! :) )

  • http://www.kirpininyeri.com kirpi

    I think they are too busy developing new stuff or something like that. Or to give Caesar’s right to Caesar, maybe they are tired of help requests from people who didn’t research enough.

    But my personal belief is that some of them are way too arrogant since they know a lot, and they expect everyone else to know as much.. Well why would I bother asking them if I knew that much, right?

    As you mentioned, what surprises me is that Windows people helped me somehow whenever I asked. I wasn’t as much frustrated with them.. Well maybe I expected too much aye? :)

  • Samus Aran

    I don't agree at all with your assumption that there's no help on IRC for newbies. You simply aren't in the right channels or on the right networks. You failed to mention any specific IRC channels as being elitist, so that's just a rash generalisation.

    I highly recommend you check out the channel:

    irc://irc.freenode.net/##Linux

    It's even in the rules not to be elitist, not to just send people to Google, etc.

    I've spent thousands of hours there over the years helping people, whether complete newbies or seasoned users. It sucks having you claim that there's no community. Friendly community is one of the main reasons I even use GNU+Linux systems.

  • http://www.kirpininyeri.com kirpi

    @samus

    It may be true that, freenode irc channel is more helpful than the channels I was trying my luck. I might have been asking for help in the wrong place. However, let me remind again that even after I stated that I have been researching for 12 hours, people were stil directing me to google.. Hence the bitter comment (and feeling)

    It's nice that you have a rule not to send people to Google, means that that's a genuine problem.

    Anyways, thank you for your comments. I'll definitely check that channel, asap..

  • Pingback: Getting the MSI Wind and Fedora Core 10 to work | Carl Hage

  • Pingback: Inspiration nature