坑点,linux的蓝牙配置的id和Windows下注册表的id有一条格式是不同的,需要转换,在此踩坑太久,具体哪条忘了,目前笔记本只用linux了
具体操作步骤忘了,只留下了使用过的资料
内容来源
http://aimingoff.way-nifty.com/blog/2018/09/windows-linux-b.html
https://medium.com/@richardvigars/where-to-find-bluetooth-link-keys-in-the-windows-registry-for-the-ekobuy-usb-dongle-csr-harmony-b7777c90b41
https://abcd40404.github.io/2018/09/11/bluetooth-keyboard-dual-boot-ubuntu/
https://www.insanelymac.com/forum/topic/268837-dual-boot-bluetooth-pairing-solved/
https://superuser.com/questions/229930/finding-bluetooth-link-key-in-windows-7-to-double-pair-a-device-on-dualboot-com
—————————————————————————-
Windows と Linux のデュアルブート環境で Bluetooth デバイスを共用する
最近立て続けに Dual boot 環境で Bluetooth デバイスを使う必要に迫られた。 滅多にやる作業ではないので、備忘録としてやり方を残しておく。
今回使うことになったのは以下。
- Bluetooth キーボード: サーバーの操作用 (主にメンテナンス)
- 通常は ssh 接続すれば事足りるが、たまに Windows やコンソールをいじりたい場合がある
- テレビに HDMI 接続しているので近寄って USB キーボードを繋ぐのもねぇ…
- Bluetooth Low Energy (BLE) マウス: ノートPC
- ノートだとやっぱりワイヤレスじゃないとね…
BLE ではないキーボードの方はネット上の情報も豊富で比較的簡単。
問題は BLE マウスの方。 こちらはネット上の情報も乏しく Linux でペアリングすること自体が面倒。 単なる Low Energy なマウスと思っていると痛い目に遭う。 いずれは GUI でできるようになるかもしれないが、今回は Debian Stretch の環境で BLE マウスを使えるようにする。
0) 事前作業
事前作業として sysinternals から pstools をダウンロードして PsExec を入手しておく。
A) Bluetooth デバイスを Windows / Linux Dual boot 環境で共用する
こちらは簡単。 ネット上に 日本語の情報 もあるので、その通りやれば OK。
A-1) まずは Linux 側でペアリングする
BLE ではない Bluetooth デバイスであれば、普通に GUI からでできるはず。
A-2) Windows 側でペアリングして情報を採取する
再起動して Windows を立ち上げ、同じ Bluetooth デバイスを Windows 側でペアリングする。
ペアリングが済んだら 0 項で入手した PsExec を使用して管理者権限でレジストリエディタを起動する。 (PsExec を使用するのは、通常のレジストリエディタ起動ではアクセスできないレジストリをアクセスするため)
PsExec64 -s -i regedit
レジストリエディタを起動したら HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys
を選択し、右クリックして内容をエクスポートする。 .reg
形式でも .txt
形式でもお好きな方を…
続いて、エクスポートしたファイルから Bluetooth デバイスの MAC アドレスを名前とする値を取り出す。 .reg
形式なら以下のような感じ。
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\xxxxxxxxxxxx]
"yyyyyyyyyyyy"=hex:00,11,22,33,44,55,66,77,88,99,aa,bb,cc,dd,ee,ff
xxxxxxxxxxxx
がホストの MAC アドレスyyyyyyyyyyyy
が Windows でペアリングした Bluetooth デバイスの MAC アドレス00,11,22,33,44,55,66,77,88,99,aa,bb,cc,dd,ee,ff
が必要な情報
A-3) Linux 側の情報を書き換える
再起動して Linux を立ち上げる。
root ユーザで /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/yy:yy:yy:yy:yy:yy/info
を編集して Key
を A-2 項で取り出した値に書き換える。
[LinkKey]
Key=00112233445566778899aabbccddeeff
ネットの情報では16進数を大文字に書き換えるような指示をしているものも見受けられるが、大文字に書き換えなくても大丈夫。
A-4) 再起動して Linux を立ち上げ直す
これで Windows と Linux の両方で同じ Bluetooth デバイスが使えるようになったはず。
B) Bluetooth Low Energy (BLE) デバイスを Windows / Linux Dual boot 環境で共用する
B-1) まずは Linux でペアリングさせる
この情報が意外に無い。 あっても古い情報が多く、実際に扱える状態まで至らず四苦八苦した。 最終的に参考にしたのは Ubuntu の Accessing GATT Services の内容。
bluetoothctl
コマンドを root ユーザで起動してペアリングさせる。 以下の中で zz:zz:zz:zz:zz:zz
が BLE デバイスの MAC アドレス。
scan on
の後で BLE デバイス側からペアリングを開始すると[New]
として検出される。- デバイスがリストされたら
scan off
でディスカバリーを止める。 - BLE の場合
pair
コマンドではなくconnect
コマンドで接続する。
しばらくして[CHG] Device zz:zz:zz:zz:zz:zz Paired: yes
が表示されたらペアリング完了。
root@XXXX # bluetoothctl
[NEW] Controller xx:xx:xx:xx:xx:xx XXXX [default]
[bluetooth]# agent on
Agent registered
[bluetooth]# default-agent
Default agent request successful
[bluetooth]# scan on
Discovery started
[CHG] Controller xx:xx:xx:xx:xx:xx Discovering: yes
...
[NEW] Device zz:zz:zz:zz:zz:zz ZZZZ Mouse
...
[bluetooth]# scan off
...
Discovery stopped
[CHG] Controller xx:xx:xx:xx:xx:xx Discovering: no
[bluetooth]# connect zz:zz:zz:zz:zz:zz
Attempting to connect to zz:zz:zz:zz:zz:zz
[CHG] Device zz:zz:zz:zz:zz:zz Connected: yes
Connection successful
[NEW] Primary Service
/org/bluez/hci0/dev_zz_zz_zz_zz_zz_zz/service0008
00001801-0000-1000-8000-00805f9b34fb
Generic Attribute Profile
[NEW] Characteristic
/org/bluez/hci0/dev_zz_zz_zz_zz_zz_zz/service0008/char0009
00002a05-0000-1000-8000-00805f9b34fb
Service Changed
[NEW] Descriptor
/org/bluez/hci0/dev_zz_zz_zz_zz_zz_zz/service0008/char0009/desc000b
00002902-0000-1000-8000-00805f9b34fb
Client Characteristic Configuration
...
[CHG] Device zz:zz:zz:zz:zz:zz UUIDs: 00001800-0000-1000-8000-00805f9b34fb
[CHG] Device zz:zz:zz:zz:zz:zz UUIDs: 00001801-0000-1000-8000-00805f9b34fb
[CHG] Device zz:zz:zz:zz:zz:zz UUIDs: 0000180a-0000-1000-8000-00805f9b34fb
[CHG] Device zz:zz:zz:zz:zz:zz UUIDs: 0000180f-0000-1000-8000-00805f9b34fb
[CHG] Device zz:zz:zz:zz:zz:zz UUIDs: 00001812-0000-1000-8000-00805f9b34fb
[CHG] Device zz:zz:zz:zz:zz:zz UUIDs: 00010000-0000-1000-8000-011f2000046d
[CHG] Device zz:zz:zz:zz:zz:zz ServicesResolved: yes
[CHG] Device zz:zz:zz:zz:zz:zz Modalias: usb:vZZZZpZZZZdZZZZ
[CHG] Device zz:zz:zz:zz:zz:zz Paired: yes
[ZZZZ Mouse]# exit
Agent unregistered
[DEL] Controller xx:xx:xx:xx:xx:xx XXXX [default]
...
これで xx:xx:xx:xx:xx:xx/zz:zz:zz:zz:zz:zz/
配下に attributes
と info
ファイルが作成され、 BLE デバイスが使えるようになったはず。
B-2) Windows 側でペアリングして情報を採取する
再起動して Windows を立ち上げ、同じ BLE デバイスをペアリングする。 Windows 10 であれば、普通にペアリングできるはず。
ペアリングが済んだら、 A-2 項と同様にレジストリの情報を採取する。
PsExec64 -s -i regedit
レジストリエディタを起動したら HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys
を選択し、右クリックして内容をエクスポートする。 BLE の場合は A-2 項に示した通常の Bluetooth デバイスと比べて内容が複雑で、 .reg
形式なら以下のような感じ。
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\xxxxxxxxxxxx]
"MasterIRK"=hex:00,10,20,30,40,50,60,70,80,90,a0,b0,c0,d0,e0,f0
[HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\xxxxxxxxxxxx\zzzzzzzzzzzz]
"LTK"=hex:01,11,21,31,41,51,61,71,81,91,a1,b1,c1,d1,e1,f1
"KeyLength"=dword:00000000
"ERand"=hex(b):02,12,22,32,42,52,62,72
"EDIV"=dword:0000a3b3
"IRK"=hex:04,14,24,34,44,54,64,74,84,94,a4,b4,c4,d4,e4,f4
"Address"=hex(b):zz,zz,zz,zz,zz,zz,00,00
"AddressType"=dword:00000000
"CSRKInbound"=hex:05,15,25,35,45,55,65,75,85,95,a5,b5,c5,d5,e5,f5
"InboundSignCounter"=hex(b):ff,ff,ff,ff,ff,ff,ff,ff
"CSRK"=hex:06,16,26,36,46,56,66,76,86,96,a6,b6,c6,d6,e6,f6
"OutboundSignCounter"=dword:00000000
"MasterIRKStatus"=dword:00000001
"AuthReq"=dword:00000005
B-3) Linux 側の情報を書き換える
再起動して Linux を立ち上げる。
root ユーザで /var/lib/bluetooth/xx:xx:xx:xx:xx:xx/zz:zz:zz:zz:zz:zz/info
を編集して B-2 項で採取した情報に基づき書き換える。 書き換えが必要なのは以下の部分。
[LocalSignatureKey]
Key=06162636465666768696a6b6c6d6e6f6
Counter=0
Authenticated=false
[LongTermKey]
Key=01112131415161718191a1b1c1d1e1f1
Authenticated=0
EncSize=16
EDiv=41907
Rand=8242240712303841794
[LocalSignatureKey]
のKey
を Windows 側のCSRK
の情報に書き換える。[LongTermKey]
のKey
を Windows 側のLTK
の情報に書き換える。[LongTermKey]
のEDiv
を Windows 側のEDIV
の情報を基に書き換える。
この項は 10 進数に変換して記載する必要がある。[LongTermKey]
のRand
を Windows 側のERand
の情報を基に書き換える。
この項は注意が必要。 Windows の.reg
ファイルの内容を逆順にした 16 進数 (B-2 の例では0x7262524232221202
) を 10 進数に変換して記載する必要があること。 (Little Endian の数値表現…と言えばわかる人はわかるでしょう)
こちらも16進数を大文字に書き換えなくても大丈夫。
このあたりは少し古いが console.systems の情報がわかりやすい。 他にも Arch Linux の BBS や Fedora の Q&A 等が参考になる。
B-4) 再起動して Linux を立ち上げ直す
これで Windows と Linux の両方で同じ BLE デバイスが使えるようになったはず。 PC の機種によっては reboot ではダメで、一旦 shutdown して電源を落として立ち上げ直さないと繋がらないことがある。
デュアルブート環境で、Bluetooth Low Energy (LE) マウスを快適に使う
こんにちは。ティッシュ社長です。
Bluetooth Low Energy (LE) のマウスをWindowsとLinux (Ubuntuなど)のデュアルブート環境で使うと、LinuxでペアリングしたマウスをWindowsではもう一度ペアリングしないといけない。。ということが起きます。
以下のようにすると、常にWindowsとLinuxでペアリングされたままでマウスが使えるので快適です。
ペアリング対象マウスは、Microsoft Designer Mouseです。
おそらくキーボードでも同じ。
大まかな手順
- Linuxでマウスをペアリングする。
- Windowsでマウスをペアリングする。
- Windowsからペアリングされた情報を引っ張ってくる。
- Linuxに対して、Windows側と同じペアリング情報を貼り付ける。
Linuxでマウスをペアリングする。
Windowsでマウスをペアリングする。
↑この2つは、通常どおりペアリングでOKです。
Windowsからペアリングされた情報を引っ張ってくる。
Windowsを起動して、PSToolsをダウンロード。
PSTools経由で、レジストリを起動。
psexec.exe -s -i regedit.exe
HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\
まで行きます。
BluetoothデバイスのMACアドレスのフォルダ下に、ペアリングされたマウスのMACアドレスが表示されているので、それ一式を保存。
一発で保存するならこんな感じ。
psexec.exe -s -i regedit /e C:\mouse.reg HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys
ついでに、 HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys 内部の ERandとEDIVの decimal 表記もメモっておきます。
C:\ に mouse.reg が出力されたはずです。
Windows Registry Editor Version 5.00
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys]
[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\f85971b362bb]
“MasterIRK”=hex:e6,8b,55,56,86,f3,a9,4c,eb,bd,d1,b7,81,e1,b2,86[HKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\f85971b362bb\c67d090c8295]
“LTK”=hex:e4,d9,bb,0f,f9,fc,e8,0c,92,a8,ab,45,fe,2c,ad,64
“KeyLength”=dword:00000000
“ERand”=hex(b):f3,50,ec,49,0c,ab,47,35 => 3839225276624818419
“EDIV”=dword:00003e1d => 15901
“IRK”=hex:6d,39,01,95,6d,37,bc,2c,e8,6f,54,e8,26,3d,74,98
“Address”=hex(b):95,82,0c,09,7d,c6,00,00
“AddressType”=dword:00000001
“CSRK”=hex:a1,c6,4d,a0,cb,8c,de,2d,95,da,5c,50,24,b8,27,24
“OutboundSignCounter”=dword:00000000
“MasterIRKStatus”=dword:00000001
“AuthReq”=dword:0000002d
mouse.reg と ERandのdecimal表記を持って、Linuxへ。
Linuxに対して、Windows側と同じペアリング情報を貼り付ける。
Linux内部では、一度マウスはペアリングされているので、 /var/lib/bluetooth 内にペアリング情報が入っています。
そのペアリング情報を、Windowsと同じものに置き換えることで、Windowsでペアリングしたマウスを、そのままLinuxで使える、というからくり。
1つづつ、ペアリング情報を変更していきます。
1. マウスのMACアドレスを変更する。
LinuxとWindowsでは、ペアリングされたマウスのMACアドレスが微妙に異なります。なぜだろう。例えば C5:AB:XX:XX:XX の場合は、 C5:AC:XX:XX:XX のように。
mouse.regでの表記はHKEY_LOCAL_MACHINE\SYSTEM\ControlSet001\Services\BTHPORT\Parameters\Keys\f85971b362bb\c67d090c8295 要するに、 C6:7D:09:0C:82:95 なので、/var/lib/bluetooth/XX:XX:XX:XX:XX:XX/C6:7C:09:0D:82:95 とかディレクトリを、C6:7D:09:0C:82:95 にリネームします。
(XX:XX:XX:XX:XX はbluetooth自体のMACアドレス)
2. ペアリング情報を変更する
作業場所は
/var/lib/bluetooth/XX:XX:XX:XX:XX/C6:7D:09:0C:82:95
infoというファイルがあるので、それを変更。
mouse.regを参照しながら。
LongTermKeyのKeyに、LTKの値を入れます。
e4,d9,bb,0f,f9,fc,e8,0c,92,a8,ab,45,fe,2c,ad,64 => E4D9BB0FF9FCE80C92A8AB45FE2CAD64
EDivにEDIVの値を入れます。windowsではhexですが、decimal表記にしておきます。
00003e1d => 15901
LocalSignatureKeyのKeyに、CSRKの値を入れます。
a1,c6,4d,a0,cb,8c,de,2d,95,da,5c,50,24,b8,27,24 => A1C64DA0CB8CDE2D95DA5C5024B82724
IdentitiyResolvingKeyに、IRKの値を入れます。
6d,39,01,95,6d,37,bc,2c,e8,6f,54,e8,26,3d,74,98 => 6D3901956D37BC2CE86F54E8263D7498
Randに、ERandのdecimal表記の値を入れます。
f3,50,ec,49,0c,ab,47,35 => 3839225276624818419
これで終わり!
WindowsとLinuxのデュアルブート環境でBluetooth Low Energy (BLE)のマウスが快適に使えるはず。
おしまい。
Where to find Bluetooth link keys in the Windows registry for the EkoBuy USB dongle / CSR Harmony stack
TLDR; the data you want is in
LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\CsrBtPort\ScDbData
and you’re looking for a 32 character string within that block, that changes when you re-pair the device.
Since 2005, I had been using the keyboard that came with the Dell desktop I bought when I went to university (with a brief interlude to find out that I don’t get on with Cherry MX black switches). By now, it’s pretty grotty. Also, my friend Jimmy spilled a glass of cheap red wine into it at some point in second year.
Having recently started working at a company where nearly everything is done on Macbooks, I have been very impressed with the Apple Magic keyboard that I was provided with. I thought I would give the Logitech K380 a go; especially appealing is a feature that allows you to switch between three devices without having to re-pair. This means that I can use it with my work laptop, and also with my home desktop, and have one channel left for my tablet.
My desktop machine is the frankensteiny result of cumulatively upgrading a 2011 AMD Phenom 2 x6 build (6 cores omg) — it just keeps on keeping on! But of course, it has nothing so exotic as onboard Bluetooth. The EkoBuy Bluetooth 4.0 dongle is well reviewed on Amazon, and cheap, so I decided to give it a try.
Once I had accepted that it wasn’t going to plug ’n’ play on Windows 7, and had installed the packaged drivers, it worked well enough. (I had trouble pairing a Logitech MX Master 2S mouse, but that works with a Logitech Universal Receiver, so whatevs.)
However, here’s the wrinkle: I dual-boot my computer with Linux (currently Linux Mint 18.3). Unfortunately, Bluetooth pairing relies on matching a key stored in both the device, and the computer’s OS. And a different key is generated each time it is paired. If you pair on Windows, reboot into Linux, and pair again, the Windows pairing will be broken. Pair again in Windows, and the Linux pairing will be broken. Therefore, you need to pair with one OS, then copy the link key to the other OS.
In Linux Mint, the Bluetooth link key is stored very sensibly, in a file called info
in the directory /var/lib/bluetooth/[bluetooth dongle MAC address]/[keyboard MAC address]/
Unfortunately, in Windows, the equivalent information is (like so many things) buried deep within the registry. Apparently, if the device is using the default Windows Bluetooth stack, the place to look is HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\BTHPORT\Parameters\Keys
, where you’ll find a set of keys corresponding to your paired Bluetooth devices’ MAC addresses.
But if, like me, you had to install the EkoBuy dongle’s drivers (which probably means you’re using Windows 7, 8 or Vista), then you will instead be using something that calls itself the ‘CSR Harmony stack’, which doesn’t use the default registry structure at all. Using the regedit
search function, I was able to find a whole bunch of likely-looking keys prefixed with csr
, but nothing resembling the MAC address of my keyboard.
Perhaps surprisingly for such an popular device, Googling both EkoBuy and CSR Harmony didn’t turn up anything obvious, so I had to search more widely in the registry.
There is a tool called whatchanged.exe
, downloadable from majorgeeks, which you can use to dump the registry to a text file, pair your device, and then scan the registry for changes, and dump the changed keys to another file. (It also takes bloody forever: it must be a very brute-force-y kind of a search. I imagine there is probably a fairly standard way to serialise the registry as text files that can then be diffed; I should work out how to do it that way next time.)
As expected, in the WhatChanged output file, there was no plaintext MAC address to be seen. But there was the following suspicious-looking key:
...\CurrentControlSet\services\CsrBtPort\ScDbData=šx€úÿÿ3Œ€øÿÿÁ•
CsrBtPort
certainly seems like a promising name! And, weird garbage characters in a text file usually mean binary data. Let’s have a closer look at it in regedit
:
Well, that’s definitely the name of my keyboard in the ASCII view on the right, and in the hex view on the left is its MAC address: backwards, and padded for some reason. The conventional representation
34:88:5d:95:0f:c1
has become
C1 0F 95 00 5D 00 88 34
But it’s definitely the MAC address I’m looking for! Hopefully the link key is buried somewhere else in this big block of binary data. Let’s export this registry data to a text file, delete and re-pair the keyboard, and see how it changes.
There are a few changes, here and there, between pairings. However, there is only one 16 byte string that changes between the two — could this be the link key?
b9f8e36c8975e07d800909b6d88f5aba
With the commas taken out, and saved to Dropbox, it’s ready to paste over the link key in Linux:
I don’t know much about Bluetooth development, but it seems a strange decision to encode Bluetooth pairing information like this. If I’d thought to search the registry for the MAC address in binary format, I probably wouldn’t have thought to search for it backwards. And if I had, I might have thought to take out the colons, but I probably wouldn’t have arbitrarily padded it with zeros. But now you know where to look!
References:
I learned most of what I needed on the practicalities of Bluetooth pairing, registry editing and dual-booting from this excellent post on Stack Exchange by Mario Olivio Flores:
How can I dig up the Bluetooth link key for a paired device in Windows 7? Is this something that is dependent on the Bluetooth stack I’m using (Toshiba), or is there a generic place to store these in Windows 7?
Note: I’m not talking about the six-digit code usually typed by the user during pairing – that is worthless since it’s discarded after pairing process. What I mean is the 128-bit link key that the devices exchange during pairing, and use thereafter to encrypt all their Bluetooth traffic.
Background:
I dualboot Windows 7 / Ubuntu on my laptop, and I would like to have my phone paired to both OS’s. Since the dualbooting computer has only one Bluetooth adapter and thus only one Bluetooth address, I cannot do two pairings to the phone, since on the second pairing (Windows) the phone just replaces the previous pairing (Linux) to the same Bluetooth address.
A thread on Ubuntu forums pointed me to what I have to do – pair first on Linux, then on Windows, and then replace the link key on Linux side with the one Windows negotiated.
I can find the Linux side pairing key from /var/lib/Bluetooth/[BD_ADDR]/linkkeys
– no problems there.
However, on Windows side I can’t find the key. According to the forum post, on Windows side the key should be in SYSTEM\ControlSet002\services\BTHPORT\Parameters\Keys\[BD_ADDR]
but while that registry key does exist, it has no subkeys. (And a similar registry path in ControlSet001 didn’t have any subkeys either.)
One thing I’ve been instructed to do is to capture all events during pairing with Sysinternals Process Monitor. I did this, but I haven’t been able to find any useful information from the captured events, not even by exporting the data to a huge XML and grepping that with the BD_ADDRs (with or without colons).
So how could I find the link key for a paired device in Windows 7?
Some reference information: Wikipedia: Bluetooth, Security Now: Bluetooth security
The registry key you should use is :
HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys
.
On my computer, it refused to let me access this key. I had to change the owner to Administrators before I could see the sub-key.
If you are using the Toshiba Bluetooth stack, its keys are stored somewhere else. One can either find where, or simply return to the Microsoft stack. In the later case, the Bluetooth keys will be stored in the registry as above.
This thread describes the process :
- Uninstall Toshiba Bluetooth (Add/Remove programs),
- Reboot,
- Windows should now detect the “new” Bluetooth device and install its own drivers for it.
Caution: Create a system restore point first, and ensure you have the installation media for the Toshiba driver for going back (just in case). Test well the functionality of the paired phone before crying victory.
- I changed the owner to Administrator, which then let me access that key, but unfortunately it contains no sub-keys. – Ilari Kajaste Jan 9 ’11 at 12:00
- Yes, I have and had the phone (plus two other devices) paired to windows. I wasn’t connected to any of them at the time, though – I figure that couldn’t matter since the key has to be stored in any case. – Ilari Kajaste Jan 9 ’11 at 18:33
- 1I am sure Toshiba wouldn’t use Microsoft registry entries. Can you go back to the Microsoft stack? – harrymc Jan 10 ’11 at 11:05
- 1This thread says: 1. Uninstall Toshiba Bluetooth (Add/Remove programs), 2. Reboot, 3. Windows should now detect the “new” Bluetooth device and install its own drivers for it. Create a system restore point first, and ensure you have the installation media for the Toshiba driver (in case). If this works, test well only the functionality of the paired phone that you really use. – harrymc Jan 10 ’11 at 20:14
The keys are not visible to the admin, you should open the registry as the system account:
This is for Windows 7 on a ThinkPad with thinkpad bluetooth 4.0 adapter but might work with other windows systems
Download PsExec: http://technet.microsoft.com/en-us/sysinternals/bb897553.aspx
Unpack it to c:\portable\pstools\ open cmd click start, type cmd, press enter, inside the black and white window type:
c:\portable\pstools\psexec -s -i regedit
regedit opens up, navigate to: HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\
there you’ll find MAC address of all of your bluetooth adapters, and under each adapter, are all the paired devices’s MAC addresses with their link keys.
to figure your adapter’s MAC address:
bluetooth settings> Hardware > ThinkPad Bluetooth 4.0 > Properties > Advanced > Address
to figure your device (keyboard/mouse) mac address:
Control Panel > Hardware and Sound > Devices and Printers > right click your device > Properties > Bluetooth > Unique Identifier
- From @Cristian: I used the methode described by thezeroth on my Xubuntu 15.10 / Windows 8 dualboot machine and it work like a charm. The only thing is that on Xubuntu the pairing key was not in the mentioned file but in a file called Info inside a subfolder named after the unique identifier a the mouse (a logitech M535). Other than that, perfect solution. – fixer1234 Nov 10 ’15 at 0:32
I had exactly the same problem, so I found this post and now want to share my experience. If you have android smartphone that task might be actually much more easy since pairing linkkey should be present on both of your devices.
The most useful tool is the ADB from Android SDK.
Let’s assume the phone have XX^6 address and PC — YY^6
$ adb shell
~ # find|grep linkkeys
~ # ./data/misc/bluetoothd/XX:XX:XX:XX:XX:XX/linkkeys
~ # cat ./data/misc/bluetoothd/XX:XX:XX:XX:XX:XX/linkkeys
YY:YY:YY:YY:YY:YY 393FCA48F0DB57AA4D59F423E4EA60D5 5 -1
~ #
Thus you can just pick the key from that file and put it into similar file on your PC:
pc $ sudo -s
pc # cat /var/lib/bluetooth/YY:YY:YY:YY:YY:YY/linkkeys
XX:XX:XX:XX:XX:XX 393FCA48F0DB57AA4D59F423E4EA60D5 5 0
This way seems to be most easy as linux and android usually use the same bluez bluetooth stack.
Still, if you personally despise such a technique, there is another way for getting the key from the windows registry provided standard windows drivers are used. I did receive that security message dialog, so I used “chntpw” native linux utility which allows one to reset the password or edit the windows registry file. The file requiered was “windows\system32\config\SYSTEM”.
Here it goes:
$ chntpw -e SYSTEM
blah-blah-blah
> cd ControlSet001\services\BTHPORT\Parameters\Keys\yyyyyyyyyyyy
(...)\BTHPORT\Parameters\Keys\5cac4c10c4f1> ls
Node has 0 subkeys and 1 values
size type value name [value if type DWORD]
16 REG_BINARY <xxxxxxxxxxxx>
(...)\BTHPORT\Parameters\Keys\5cac4c10c4f1> hex xxxxxxxxxxxx
Value <xxxxxxxxxxxx> of type REG_BINARY, data length 16 [0x10]
:00000 39 3F CA 48 F0 DB 57 AA 4D 59 F4 23 E4 EA 60 D5 9?.H..W.MY.#..`.
As you can see that is exactly the same numbers as in files above. Hope it will help future generations.
- Is your device rooted/has BusyBox installed? The “find” command failed. – user412652 Mar 16 ’15 at 5:45
For the reference, on Microsoft Bluetooth stack, the link keys are located in HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\aabbccddeeff
where aabbccddeeff is your Bluetooth adapter. Since the adapter is already installed, this key should exist.
Within that key, you can have multiple REG_BINARY values, where the value name is the paired device’s MAC address (in same form — hex, lowercase, no separators) and the value is the link key (16 bytes).
To pick up the link keys from OS X, perform (in OSX Terminal) defaults read /private/var/root/Library/Preferences/blued.plist
. Within LinkKeys, you should have a link key per MAC address of a paired device. The keys are base64-encoded so do: echo -n 'aabbcc...==' | base64 -d | hexdump -C
and type this key into your Windows registry.
PsExec.exe -s -i regedit /E %cd%\btkeys_export.txt “HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys”
- Welcome to Super User! Could you elaborate on this? Perhaps edit your answer to explain what you are describing and why you are making that suggestion. Thanks! – bertieb Jun 19 ’18 at 0:03
This thread was started to address the issue of losing bluetooth connectivity to peripherals when switching between OS X and Windows 7 because each OS has a different link key, therefore forcing you to renegotiate for a new link key to start a secure session. It also can be applied if you have to share one mouse across multiple machines. Further testing necessary, this is a work in progress.
I got tired of my wireless mouse not working after I paired with Windows, only to have to re-pair when I booted OS X. It’s an aggrevating little annoyance. Now I can pick up my mouse and walk from desktop to laptop and not have to stop and pair because I did this procedure on both. I still need to change the laptop’s OS X link key, that gets done with a hex editor.
One more thing, the registry keys referred to in this tut, point to where the standard Microsoft bluetooth driver records the link keys. If you see anything in device manager in Bluetooth radio, you should try changing to the generic bluetooth driver. If you have broadcom drivers installed or others, they write their keys to different parts of the registry and I don’t support them.
Converting OS X link key to Windows registry format tutorial
Here’s an example of what a portion of a link key might read in OS X : ABCDEF12
Of course it will be longer but I want to keep this as simple as possible at first.
Here’s how you convert it to Windows registry format.
You start at the right with 12, and work your way left, grouping up in pairs, so the next is EF, CD, AB.
This is what it should read after you’re done: 12 EF CD AB
All we’re doing is taking the furthest two right digits off and putting them in the beggining. Reordering
Now lets apply this to a hypothetical link key.
98542ff9 88e19449 475250e1 3943255b
Start with the furthest right group
5b 25 43 39
then the second from the right
e1 50 52 47
third from the right
49 94 e1 88
and the furthest from the right
f9 2f 54 98
Putting them back together in Windows registry format:
5b 25 43 39 e1 50 52 47 49 94 e1 88 f9 2f 54 98
Understanding how to decode the OS X link key is the difficult part. Converting from little endian to big endian, or vise versa.
Accquire your link key, convert, install to Windows registry
1.Pair the device in Windows first. So the entry and services are all created in the registry.
2. Find your device id aka unique identifier. (Open bluetooth devices icon in system tray, right click on device (mouse etc), go to properties, bluetooth.) Make a note of it
3. Boot OS X and pair the device.
4. Copy/Write down the link key from OS X into a text document or email to yourself so you have access to it when you go back in Windows.
sudo defaults read /private/var/root/Library/Preferences/blued.plist
Link key will be 16 bytes long, it looks like 4 groups of 8 characters in hex.
such as: 98542ff9 88e19449 475250e1 3943255b
To find the one you want, if there are more than one, you would need to find you device unique identifier. Refer to step 2 or you can do it in OS X. Bluetooth preferences, show more info.
5. Convert the 16 byte long string to Windows registry format. Refered to as little endian to big endian. (Refer to mini tutorial above)
5a. Boot to windows
6. Get a free utility from technet psexec (google) copy to desktop.
7. Start > type cmd > hit control+ shift+ enter to create a command prompt with Administrator privledges.
8.
cd Desktop
psexec -s -i regedit
9. Find the key in registry HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\services\BTHPORT\Parameters\Keys\(Unique ID of your network adapter not your device)
10. Your device unique id for your mouse should be visible on the right pane, right click and “Modify binary data”.
11. We want to erase Value data, and replace our own. Open that scratch pad where you’ve been taking notes and hopefully have converted the OS X link key to registry format without any typos, you need to enter it in here, one digit at a time, as it doesn’t support copy paste from notepad.
12. Hit OK, close registry, now you have the same link key in OS X and Windows 7. Changes take effect upon pressing OK. No need to reboot to see results.
If you try to pair that device to something else now, you’ll need to repeat this process because the link key will have changed on the device. I paired my mouse to the laptop then my desktop (Windows first for the sake of this guide, I still need to test my reverse theory to change OS X’s link key values, but first I need rest.) Bootcampers automatically have this done. This procedure is just an outline of what it takes, having a streamlined process like Apple would be the goal here.
-Camoguy