Those who dualboot know the pain of re-pairing your keyboard or mouse everytime you boot to a different OS. In this tutorial I will show how to pair a LE Bluetooth mouse in both Windows 8 and Debian simultaneously.
First pair the device in Debian, then reboot in Windows and pair the device there too. Yes, this will reset the paring in Debian, just carry on. Now we need to access the pairing keys in Windows. Download psexec.exeand open a command prompt with Administrator rights.
> cd Downloads
> psexec.exe -s -i regedit /e C:\BTKeys.reg HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\
Services\BTHPORT\Parameters\Keys
The keys should be now exported to C:\BTKeys.reg
. You should get something like:
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\
7512a3185b2c\84abd4a25ee1]
"LTK"=hex:6c,54,ee,80,40,47,6c,cb,fc,8e,f3,f1,c6,b2,04,9e
"KeyLength"=dword:00000000
"ERand"=hex(b):1e,12,aa,37,39,cc,af,34
"EDIV"=dword:00003549
"CSRK"=hex:38,d7,aa,c1,42,06,31,25,12,b8,5a,6d,c3,90,98,f2
7512a3185b2c
is the MAC address of the Bluetooth adapter, which can also be written in standard format as 75:12:A3:18:5B:2C
. 84abd4a25ee1
is the mouse address that was assigned during the pairing. We will need those numbers in the next steps.
Now boot again to Debian. The mouse wont paired automatically, because it is now assigned to a different address and with different keys. Let's fix it.
$ cd /var/lib/bluetooth/75:12:A3:18:5B:2C/
$ ls
cache 84:AB:D4:A2:5F:E1 settings
If you look closely, the mouse address is not the same as in Windows. In my case only the fifth group is different. We need the device addresses to match, so rename the file.
$ mv 84:AB:D4:A2:{5F,5E}:E1
$ cd 84:AB:D4:A2:5E:E1/
$ ls
attributes gatt info
Now open the info
file for editing and update the keys values. The relation between Windows and Bluez keys format is as follows:
LTK
goes into Key
of the LongTermKey
group. Change to uppercase and remove the commas.
KeyLength
goes into EncSize
. In my case I had to replace the original value 12
with 0
.
ERand
goes into Rand
. This is the tricky part. First you need to write down the ERand
value in reverse, so it becomes 34afcc3937aa121e
. Then convert it to decimal to get 3796477557015712286
.
EDIV
goes to EDiv
. Convert from HEX to decimal normally, no reverse this time.
CSRK
goes to Key
of the LocalSignatureKey
group. Uppercased and no commas.
At the end you should get this.
[LocalSignatureKey]
Key=38D7AAC14206312512B85A6DC39098F2
[LongTermKey]
Key=6C54EE8040476CCBFC8EF3F1C6B2049E
Authenticated=0
EncSize=0
EDiv=13641
Rand=3796477557015712286
Save the changes and reboot. From now on Debian and Windows will connect the mouse automatically. Awesome!
PS:
1) I did not reverse the Rand value, instead I used the decimal number regedit shows beside the hex key
2) I set EncSize to 16.
link link