apple bluetooth keyboard and mouse: conflict between ubuntu and OS X

Bug #1001825 reported by Lunarts
74
This bug affects 15 people
Affects Status Importance Assigned to Milestone
bluez (Ubuntu)
Expired
Undecided
Unassigned

Bug Description

First of all, ubuntu 12.04(tested with mac specific iso and 64 bits) and grub 2(tested grub efi amd64 of course) do not acknowledge apple bluetooth keyboard(and mouse for ubuntu); installing blueman at ubuntu seems to be the only way to get both working on ubuntu, a very difficult process, which required an usb mouse because there are no working bluetooth apple devices; the issue is never fixed, only made less worse as shown below, please check these four threads for more information(the issue affect plenty of users, and has not been adressed properly since 2011?!):

http://ubuntuforums.org/showthread.php?t=1980171

http://ubuntuforums.org/showthread.php?t=1874245

http://ubuntuforums.org/showthread.php?p=11949032#post11949032

http://ubuntuforums.org/showthread.php?t=1980593

If ubuntu gets control of mac keyboard and mouse, Os X lose it(and pre boot keyboard pairing cease to exist, no more pre boot hotkeys possible); if OS X have control of keyboard and mouse, ubuntu lose it; switching from one to another requires quite painfull keyboard and mouse redetection with blueman from ubuntu, or, at osx side, osx take quite some time to detect them again after an ubuntu login.

The mac ubuntu community is quite insatisfied with this issue, and demands a fix; if any additional information is needed to help in this task, let us know.

description: updated
affects: ubuntu → bluez (Ubuntu)
Revision history for this message
Launchpad Janitor (janitor) wrote :

Status changed to 'Confirmed' because the bug affects multiple users.

Changed in bluez (Ubuntu):
status: New → Confirmed
Revision history for this message
Peter Hedlund (peter-peterandlinda) wrote :

sudo hcidump -XYt > $HOME/hci.log

gives this when attempting to reconnect first the Apple Wireless Keyboard and then the Magic Trackpad.

Revision history for this message
Yariv Barkan (yarivbarkan) wrote :

A related problem is that every time I try to pair a new trackpad (or re-pair an existing one, e.g. by removing it from the list of known devices) it takes quite a few iterations with the bluetooth wizard. Sometimes the device disappears mid-pairing, sometimes I am asked to enter some random string of numbers (maybe the trackpad identified as a keyboard?) and sometimes it just plain 'fails' the pairing process.

This happens to me on a standard PC (non-mac). I use a bluetooth dongle and dual-boot Ubuntu with Windows. Needless to say, there are no pairing problems, or any other trackpad-related problems, on the Windows side of things. Note that on Windows I use the official Apple driver.

Revision history for this message
Peter Hedlund (peter-peterandlinda) wrote :

In response to #3: I see all those issues on Mac hardware also.

Revision history for this message
Lunarts (lunartsbr-gmail) wrote :

Just something which may be usefull:

After ubuntu taking control of keyboard and mouse, and the keyboard not being setup correctly at mac startup anymore(no preboot hotkeys); detecting the keyboard at OS X login(just touching the keyboard power button or shuting down and restarting the keyboard) do not make the keyboard work at mac preboot; getting the keyboard to work at OS X itself after login does not work too; the only way to get the apple keyboard working at startup is to do the process shown at the mac manual(going to system preferences>keyboard>bluetooth configurations and detect the keyboard there)

Revision history for this message
joseph stermer (sterm) wrote :

I was able to make progress and solve half-the keyboard-part of the problem. To boot-with EfiT and Grub- and login to my account, I would use a USB keyboard*. The apple kB would connect after login. The mouse would be more difficult. Creating a /lib/bluetooth folder, adding a folder named <mac address of device> and placing a file named pincodes- Code: <unique ID> mac address- in the folder worked to keep the Kb connection on between reboots and allowing login with the Bluetooth keyboard**. The mouse worked but would not stay connected after rebooting. I solved the mouse problem using Blueman but it has to be reconnected each time I boot.

* Previously, the Bluetooth KB worked through EfiT and grub but the connetioned failed at the loging screen and then worked after login. Adding /lib/bluetooth caused the Bluetooth keyboard to stop working at EfiT or Grub then allowed connection through login.

** I may be missing a step-the addition of code pointing to "pincodes" in another bluetooth file. I found the advice after many wild searches and am unable to created the exact wording of the search.

Revision history for this message
joseph stermer (sterm) wrote :

https://wiki.edubuntu.org/Multitouch/AppleMagicMouse

Contains information I refered to for making a connection. The info is for the mouse but it only worked for the keyboard.

Revision history for this message
3t0g0 (freetogo) wrote :

The put this script in /etc/init.d as an startup script. This partially solved my problem. This is not a complete solution unfortunately.

Revision history for this message
Peter Hedlund (peter-peterandlinda) wrote :

Thank you for the script. I modified it with the correct values for my devices and added it to /etc/init.d but I do not see any positive effects. What exactly is it supposed to help with?

If my keyboard and trackpad have been used in OSX I have a very hard time getting them to connect in Ubuntu. They often seem to connect for a few seconds but then immediately disconnect. A dialog about granting access keeps popping up and I repeatedly check always grant access but that of course does not happen.

Revision history for this message
3t0g0 (freetogo) wrote : Re: [Bug 1001825] Re: apple bluetooth keyboard and mouse: conflict between ubuntu and OS X

>update-rc.d keyboard.sh defaults

On Tue, Jun 19, 2012 at 11:42 PM, Peter Hedlund
<email address hidden>wrote:

> Thank you for the script. I modified it with the correct values for my
> devices and added it to /etc/init.d but I do not see any positive
> effects. What exactly is it supposed to help with?
>
> If my keyboard and trackpad have been used in OSX I have a very hard
> time getting them to connect in Ubuntu. They often seem to connect for a
> few seconds but then immediately disconnect. A dialog about granting
> access keeps popping up and I repeatedly check always grant access but
> that of course does not happen.
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1001825
>
> Title:
> apple bluetooth keyboard and mouse: conflict between ubuntu and OS X
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/1001825/+subscriptions
>

Revision history for this message
3t0g0 (freetogo) wrote :

Have u add the appropriate symbolic links to cause the script to be
executed when the system comes up?

sudo update-rc.d keyboard.sh defaults

On Wed, Jun 20, 2012 at 1:21 AM, Joe Chan <email address hidden> wrote:
>
> >update-rc.d keyboard.sh defaults
>
>
> On Tue, Jun 19, 2012 at 11:42 PM, Peter Hedlund <
<email address hidden>> wrote:
>>
>> Thank you for the script. I modified it with the correct values for my
>> devices and added it to /etc/init.d but I do not see any positive
>> effects. What exactly is it supposed to help with?
>>
>> If my keyboard and trackpad have been used in OSX I have a very hard
>> time getting them to connect in Ubuntu. They often seem to connect for a
>> few seconds but then immediately disconnect. A dialog about granting
>> access keeps popping up and I repeatedly check always grant access but
>> that of course does not happen.
>>
>> --
>> You received this bug notification because you are subscribed to the bug
>> report.
>> https://bugs.launchpad.net/bugs/1001825
>>
>> Title:
>> apple bluetooth keyboard and mouse: conflict between ubuntu and OS X
>>
>> To manage notifications about this bug go to:
>>
https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/1001825/+subscriptions
>
>

Revision history for this message
Peter Hedlund (peter-peterandlinda) wrote :

Wow, OK. That helped. Now the keyboard reconnects automatically, but the Magic Trackpad is still misbehaving. It tries to reconnect repeatedly but then immediately disconnects. Is that what you mean by partially?

Revision history for this message
3t0g0 (freetogo) wrote :

unless I got magic trackpad, otherwise I can't help.

by the way, partially means that I cant' "properly disconnect the connected bluetooth device upon shutting down ubuntu. To make it completely works, the bluetooth mouse and keyboard must forget ubuntu completely after shutting down.

Revision history for this message
Peter Hedlund (peter-peterandlinda) wrote :

My major problem when using the script and then shutting down the computer, is that the system locks up searching for the devices if they are not present (taking the MacBook to another location for example).

Revision history for this message
3t0g0 (freetogo) wrote :

Then the loop should be set to have a Max say 100 before it gives up

On 26 Jun, 2012, at 5:20 AM, Peter Hedlund <email address hidden> wrote:

> My major problem when using the script and then shutting down the
> computer, is that the system locks up searching for the devices if they
> are not present (taking the MacBook to another location for example).
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1001825
>
> Title:
> apple bluetooth keyboard and mouse: conflict between ubuntu and OS X
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/1001825/+subscriptions

Revision history for this message
3t0g0 (freetogo) wrote :

Attached please find the revised version.

The computer will try 10 ($maxLoop) times before it gives up.

In my case, $maxLoop > 2 will suffice.

On Tue, Jun 26, 2012 at 8:33 AM, Joe Chan <email address hidden> wrote:

> Then the loop should be set to have a Max say 100 before it gives up
>
>
>
> On 26 Jun, 2012, at 5:20 AM, Peter Hedlund <email address hidden>
> wrote:
>
> > My major problem when using the script and then shutting down the
> > computer, is that the system locks up searching for the devices if they
> > are not present (taking the MacBook to another location for example).
> >
> > --
> > You received this bug notification because you are subscribed to the bug
> > report.
> > https://bugs.launchpad.net/bugs/1001825
> >
> > Title:
> > apple bluetooth keyboard and mouse: conflict between ubuntu and OS X
> >
> > To manage notifications about this bug go to:
> >
> https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/1001825/+subscriptions
>

Revision history for this message
Peter Hedlund (peter-peterandlinda) wrote :

OK, so that works. An ignorant question (and I have not tested) but would it not be simpler to not include the script in runlevel 0?

Revision history for this message
3t0g0 (freetogo) wrote :

Please let me know if my script works other than running at runlevel 0.

By the way, I don't have touchpad and I am curious to know whether the
touchpad works with my script or not.

Joe

On Wed, Jun 27, 2012 at 11:53 PM, Peter Hedlund
<email address hidden>wrote:

> OK, so that works. An ignorant question (and I have not tested) but
> would it not be simpler to not include the script in runlevel 0?
>
> --
> You received this bug notification because you are subscribed to the bug
> report.
> https://bugs.launchpad.net/bugs/1001825
>
> Title:
> apple bluetooth keyboard and mouse: conflict between ubuntu and OS X
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/ubuntu/+source/bluez/+bug/1001825/+subscriptions
>

Revision history for this message
Peter Hedlund (peter-peterandlinda) wrote :

The script works with the Magic Trackpad. I just have to be a bit patient on startup until everything is loaded.

I wrote a wrapper init script and an install script. They are simple adaptations of other scripts so they should be harmless, but no guarantees. This way I avoid running your main script on shutdown (runlevel 0, which defaults to stop and now does nothing).

I renamed your script apple-keyboard, but otherwise it is unaltered. Actually, with this solution it should be possible to remove the loop again.

Revision history for this message
Leif Huhn (leif-dkstat) wrote :

Things will go much more smoothly if you use the same link keys in both OS X and Linux. Then the device won't need to be repaired everytime you switch between them.

You can do this by:

1. Pairing in Linux
2. Pairing in OS X
3. Copying the link keys from OS X to Linux

Attached is a script that will perform step 3. It assumes you are in Linux and have your OS X partition mounted at /media/osx (readonly is fine). It will overwrite all your Linux link keys (so anything not paired in OS X will stop working).

Also, Linux apparently needs to know how many digits the PIN was when pairing. I have hardcoded the script to assume 6 but to make an exception for a given hardware address. You might want to edit the script with the hardware address of your mouse.

It requires the package libplist-utils (sudo apt-get install libplist-utils).

Revision history for this message
Leif Huhn (leif-dkstat) wrote :

I can't get get launchpad to upload my attachment. The post button does nothing, so here's the script:

#!/bin/sh
cd /var/lib/bluetooth
for i in *; do
    cd "$i"
    plutil -i /media/osx/private/var/root/Library/Preferences/blued.plist -o /dev/stdout |
    perl -0777 -MMIME::Base64 -ne 's|\s||g; $s = $_; while ($s =~ m|<key>(..-..-..-..-..-..)</key><data>(.*?)</data>|g) { $mac = uc($1); $key = uc(unpack("H*",reverse decode_base64($2))); $mac =~ s/-/:/g; $pinlength = 6; $pinlength = 4 if $mac eq "C4:2C:03:A0:C7:20"; print "$mac $key 0 $pinlength\n"; }' |
    tee linkkeys
    cd ..
done
service bluetooth restart

Revision history for this message
dustbunny (dustbunny) wrote :

any updates on the status of this issue?

Revision history for this message
Tom Close (snapstaldo) wrote :

I can confirm that Leif's fix works perfectly for me. Thanks Leif, I was going a bit crazy with this for a while!

Revision history for this message
Maksim Shkrebtan (mshkrebtan) wrote :

Could you guys tell me how to use this script please for both of my Wireless Keyboard and Magic Mouse? I am a newbie in Linux...

Revision history for this message
Wilbert Sequeira (wilbertcr) wrote :

What if I don't have a MAC?

Revision history for this message
esinahkatakki (esinahkatakka) wrote :
Download full text (3.3 KiB)

This bug nearly made me throw my mac through the window and move to forest. None of the above works. After spending several days struggling with this, searching the whole internets, I finally managed to get bluetooth work while dual booting. And here's how it goes:

I've got late 2012 Imac with 3TB fusion drive. I've split the fusion drive into separate SSD and HDD to gain full control of the disks and clean installed Yosemite on one SSD partition and Linux Mint Debian on the other SSD partition. HDD is solely for photos and stuff. I've got refind installed too. But this has nothing to do with bluetooth! Just little background.

I've got Apple bluetooth keyboard and bluetooh Apple Magic Mouse. And here's how you make them work with LINUX / OSX Yosemite dualboot system.

1. Pair the mouse and keyboard while on LINUX
2. Pair the mouse and keyboard while on OSX

then on OSX terminal run:
sudo defaults read /private/var/root/Library/Preferences/blued.plist

after typing your password, you'll get this:
-------------
{
    LinkKeys = {
        "4b-8g-cd-43-22-g4" = {
            "7c-21-aa-cd-33-4c" = <d2a3cd51 3af1247a 11020891 d2b3df83>;
            "e4-89-7a-dc-45-8b" = <35194ceb 8b0c9128 0fdfec7e e17f31e7>;
        };
    };
}

------------
The "4b-8g-cd-43-22-g4" is mac address of computer's bluetooth. 7c-21-aa-cd-33-4c and e4-89-7a-dc-45-8b are mac addresses of keyboard and magic mouse. Make sure the check which one is which!! You can check it from your mac's bluetooth settings for example. You can also check them after pairing them first time on LINUX at phase 1.

Those long hex numbers d2a3cd51 3af1247a 11020891 d2b3df83 AND 35194ceb 8b0c9128 0fdfec7e e17f31e7 after the mac addresses are the pairing codes ! WRITE / COPY THEM DOWN! And under that, write down the pairing code in REVERSED - PAIR - MANNER. WTF ?!

Like this:
original: d2a3cd513af1247a11020891d2b3df83
reversed in pairs: 83dfb3d2910802117a24f13a51cda3d2

3. Reboot to Linux, but DO NOT PAIR the keyboard nor the magic mouse, instead use usb keyboard and mouse !
4. Open your file system, go to /var/lib/bluetooth (you need to open it with root priviledges--> right click the folder and select "open as root")

There you'll find folder named after your computer's BLUETOOTH MAC ADDRESS, i.e. in my case "4b:8g:cd:43:22:g4" seen above. Open it (as root of course).

Inside this folder, you'll find a file called LINKKEYS. It contains your Linux bluetooth pairing codes for bluetooth keyboard and magic mouse. Open it, and you'll see something familiar: The MAC addresses of your keyboard and Magic Mouse followed by 16 HEX code, followed by "06" or "04". The 06 means that the original pairing code was 6 digit figure, and 04 means that it was four digit figure i.e. "0000" for magic mouse. After the HEX conversion the pairing code is naturally something nearly cryptical.

Now, replace the HEX figures with the reversed-in-pairs code you wrote down (see above). Leave the "06" and "04" untouched. And MAKE SURE you know which mac address is your mouse and which one is keyboard!

Save the file. Do not pair anything yet.

Reboot and see the bluetooth magic work finally!...

Read more...

Revision history for this message
Aman Thethy (hillsidecres) wrote :

Thanks for the guide, esinahkatakka! I'm taking a stab in the dark here, but could it maybe be that Ubuntu turns the keyboard/mouse off when you shutdown and OS X doesn't?

Revision history for this message
Daniel van Vugt (vanvugt) wrote :

Lunarts,

Thank you for reporting this bug to Ubuntu. Ubuntu 12.04 (precise) reached end-of-life on April 28, 2017.

See this document for currently supported Ubuntu releases:
https://wiki.ubuntu.com/Releases

Please upgrade to the latest version and re-test.

Changed in bluez (Ubuntu):
status: Confirmed → Incomplete
Revision history for this message
Launchpad Janitor (janitor) wrote :

[Expired for bluez (Ubuntu) because there has been no activity for 60 days.]

Changed in bluez (Ubuntu):
status: Incomplete → Expired
To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.