Proper way to do Bluetooth pairing on Linux & Windows dualboot
What’s the problem?
When you pair a Bluetooth device to your computer, a unique set of pairing keys is generated in the process. One is stored on the computer, associated with your device’s MAC address. Another is stored on the device, associated with you computer’s MAC address. Since the MAC address of your computer is defined by its hardware, Linux and WIndows will share it. Thus, when you re-pair the device to a second OS, the device replaces its key with a new one, making the old pairing unusable.
How to fix that
We will first pair the device on Linux, then pair it on Windows, and finally copy computer’s key from Windows to Linux. Make sure to record your computer’s and device’s MAC addresses at some point, you’ll need them in the process.
This note assumes a relatively modern Linux distribution (= not ancient, at the time of writing)
with systemd
init system and bluez
for managing Bluetooth, and Windows 10+.
Create all the necessary device configuration on both systems.
- As usual, pair your device on Linux.
- Do the same on Windows.
Get the keys from Windows.
- Download PsExec from here . It is necessary to get the priveleges required to view Bluetooth pairing keys.
- Open registry editor from console like this:
psexec -s -i regedit.exe
. - Descend into
HKEY_LOCAL_MACHINE\SYSTEM
. - Descend into
CurrentControlSet
or, if it does not exist, intoControlSet001
. - Descend into
Services\BTHPORT\Parameters\Keys
. - Descend into the key corresponding to your computer’s MAC address.
- For convinience export this key.
- In the exported file you will find a hex value of the pairing key corresponding to your device’s MAC address.
Alternatively, you can perform the same operations from Linux using a CLI registry browser like chntpw on a registry file
.../Windows/System32/config/SYSTEM
.Put the keys into Linux.
- Assume
root
privileges. - Go to
/var/lib/bluetooth/
. - Descend into the directory corresponding to your computer’s MAC address.
- Descend into the directory corresponding to your device’s MAC address.
- Open the
info
file for editing. - Find
[LinkKey]
section and replace theKey
attribute value with the key you fetched from Windows (beware of the formatting difference). - Restart Bluetooth service:
systemctl restart bluetooth
.
- Assume
Check that device is now paired with both Linux and Windows.
For Bluetooth LE the steps are a bit different:
Instead of a single value for a pairing key, you will find a key with multiple values in Windows registry. Specifically, you want
LTK
,KeyLength
,ERand
,EDIV
,IRK
andCSRK
.On Linux, you need to put these parameters in a unique and special way:
LTK
goes intoKey
of the[LongTermKey]
section (beware of the formatting difference here too).KeyLength
goes intoEncSize
of the[LongTermKey]
section as a decimal.ERand
goes intoRand
of the[LongTermKey]
section, reversed as hex, and then converted into decimal.EDIV
goes intoEDiv
of the[LongTermKey]
section as a decimal.IRK
goes intoKey
of the[IdentityResolvingKey]
section (ifIRK
exists).CSRK
goes intoKey
of the[LocalSignatureKey]
section (ifCSRK
exists).- Sections
[PeripheralLongTermKey]
,[SlaveLongTermKey]
, and any other which look like[SomethingSomethingKey]
go away.
If it still does not work, I don’t know what to do (yet). You can have a drink :)
Sources
- https://unix.stackexchange.com/questions/255509/bluetooth-pairing-on-dual-boot-of-windows-linux-mint-ubuntu-stop-having-to-p .
- https://console.systems/2014/09/how-to-pair-low-energy-le-bluetooth.html .