OK folks, I went through a lot of pain to get both my Apple Keyboard and Apple Magic Trackpad working on Ubuntu 10.10. I tried several solutions, including the ones mentioned here and others that required editing files that don't exist (e.g. /etc/default/bluetooth), and while some seemed to work at first, none were stable over time. After much trial and error, here is what I did to get both working, automatically reconnecting after restart and/or powering down the devices, with multi-touch capabilities on the trackpad. Getting each of those to work separately was painful enough, and this is how I finally got them all to work at the same time.
For the record, the bluetooth documentation and support for the "new" bluetooth kernel in 10.10 is junk, and the linux, bluetooth, and ubuntu team needs to do a far better job of providing documentation and support if they want people to take their operating system seriously as a consumer product. It should not be this hard, and it should not require trial and error based on informal community suggestions rather than documentation provided by the people who created the software, to do simple things like this.
Note that this is copied from my original post, with attachments, at https://prodigyone.com/in/doc/docs.php?nid=333&view=1
The problems appeared to be a) conflicting bluetooth software and b) a bug in bluez whereby it was not saving link keys in /var/lib/bluetooth.../linkkeys. Workarounds for both are below.
Step 1: Remove all bluetooth software and reboot
1a: Make a copy of your /etc/init.d/bluetooth script. You will need it if you choose option B in step 2 below. If you don't have it, you can use the one attached here
1b: Purge any installed package with the term "blue" in it
sudo apt-get purge bluez blueman gnome-bluetooth bluez-utils
1c: Remove or rename any config files that still remain
mv /var/lib/bluetooth /var/lib/bluetooth.old
1d: Remove any software repositories other than the normal 10.10 repositories (i.e. don't use brian-rogers or other builds)
Step 2- Option A: To connect without auto re-connect
This will allow you to connect without saving the link keys (I am guessing that it's a bluez bug that is failing to write the link keys to /var/lib/bluetooth/.../linkkeys, as the instruction to save the key there is contained in the bluez code). In other words, every time you end your connection, or reboot the computer, you will have to reconnect.
sudo apt-get install bluez blueman
Note that I did not install gnome-bluetooth, bluetooth-compat, bluez-utils, etc. I believe you'll be fine if you install gnome-bluetooth INSTEAD of blueman, but do not install both. It wouldn't work for me if both were installed.
After installation, reboot.
Step 2- Option B: Build bluez and blueman from scratch
This will allow you to connect and to automatically reconnect after reboot or after powering down the devices, which is everything I wanted to do (note that I was unable to get "hcitool putkey" to work-- not sure if that's a bug or a user error-- but it appears that I didn't needed it).
Step 2 Option B: First: Download, unpack, compile and install bluez and blueman from source.
I used the attached source code bluez 4.87 and blueman 1.21
wget xxx.tar.gz (where xxx.tar.gz is the location of the source tarball)
tar zxf xx.tar.gz
cd to the directory created from above step
./configure
make
sudo make install
During the configure step, pay attention to the output, because it may require installation of other packages. You can install these using the synaptic package manager, or using sudo apt-get install. Just make sure that in doing so, you do not install any package with "blue" anywhere in its name.
Originally, I had thought that I would fix the bluez code that was failing to write the /var/lib/.../linkkeys file. However, it appears to be working in the latest source (4.87 as of today), so I didn't need to fix anything.
Note: I'm not sure it is necessary to install blueman from source. If you can install it without overwriting / undoing your source-build of bluez, I would think that should work fine. But I didn't try that.
Step 2 Option B: Second, configure your system to start bluetoothd automatically
Chown and chmod the script from step 1a, then copy it to /etc/init.d
sudo chown root bluetooth
sudo chmod bluetooth 755
sudo cp bluetooth /etc/init.d
Now link it to each of the startup modes
sudo ln -s /etc/init.d/bluetooth /etc/rc5.d/S25bluetooth
sudo ln -s /etc/init.d/bluetooth /etc/rc0.d/K74bluetooth
sudo ln -s /etc/init.d/bluetooth /etc/rc2.d/S25bluetooth
sudo ln -s /etc/init.d/bluetooth /etc/rc4.d/S25bluetooth
sudo ln -s /etc/init.d/bluetooth /etc/rc6.d/K74bluetooth
sudo ln -s /etc/init.d/bluetooth /etc/rc1.d/K74bluetooth
sudo ln -s /etc/init.d/bluetooth /etc/rc3.d/S25bluetooth
Step 2 Option B: Finally, reboot
Step 3: Configure the keyboard
3a: Prepare to connect
The blueman applet should appear after your installation + reboot. Click on it and leave its window open
3b: Connect
Turn off all bluetooth devices except for your computer. Then hold the power button on the keyboard down for several seconds, until the green light turns off. Wait a moment, and if the green light doesn't start flashing, hit the power button once quickly.
If at any point it says that the keyboard is asking for authorization, choose to always give it permission.
Once you see the keyboard in the blueman window (hit Search if you do not-- this may take a few tries; you basically have to have blueman searching for the keyboard at the same time that the keyboard green light is flashing), click on it and choose pair.
During this time, it may help to hit the Return button a few times on the keyboard. I would advise against hitting other keys, however, as they may mess up the pairing process.
When prompted to pair, type in any 4 or 6 digit pin, hit return, and then do the same on your Apple keyboard. It should say "success". At this point, your keyboard may or may not work, for one of two reasons:
PROBLEM #1: keyboard was connected as a number pad only (e.g. it would type numbers instead of 'j', 'k', etc)
Solution, from How do I get the Apple Wireless Keyboard Working in 10.10?:
Press fn-F6 twice to disable numlock. To switch numlock off permanently after log-in go to System -> Preferences -> Keyboard -> Layout -> Layout Options -> Miscellaneous compatibility options -> turn on "Default numeric keypad keys"
PROBLEM #2: keyboard won't type anything at all, even after it is successfully connected
Solution: restart bluetooth, or, reboot. See below on restarting bluetooth.
3c: confirm that your link key is saved for next time
check that /var/lib/bluetooth/.../linkkeys contains your device with some string of hex values next to it. If it does not, the device will not be recognized after reboot.
Step 4: Configure the magic trackpad
Step 4a: Follow the same steps as step 3, except use a PIN of '0000' (and obviously you won't need to type the matching pin in on the mouse).
Step 4b: multi-touch driver
You should have basic mouse functionality now. To use multi-touch functionality, you need to override the default driver in xorg.conf. This is described in "https://wiki.ubuntu.com/Multitouch/AppleMagicTrackpad#Support on Ubuntu 10.04 (Lucid Lynx)", and I have copied some of the key steps below:
sudo lsinput
note the vendor and product. my Apple trackpad vendor/product is: 0x5ac/0x30e. Then, edit /etc/X11/xorg.conf and add the following to the bottom of it (change the matchUSBID value if your vendor/product is different):
Section "InputClass"
Identifier "Magic Trackpad"
MatchUSBID "05ac:030e"
Driver "synaptics"
EndSection
Step 4c: Reboot the computer so it reloads the xorg settings.
AND THAT'S ALL FOLKS! HOPEFULLY YOU ARE ALL SET NOW!
Below are some instructions for generic bluetooth-related functions:
Generic Bluetooth Functions: Restarting Bluetooth
Easiest option (if your startup scripts are set up)
/etc/init.d/bluetooth start|stop|restart
Harder option (without scripts):
sudo bluetoothd --udev
not sure what the udev does, but that's what the default install does
killall bluetoothd
If all else fails, reboot
Generic Bluetooth Functions: using hciconfig and hcitool
- hciconfig --help
- hcitool --help