Mac和Windows双系统共用蓝牙设备无需重新配对
2020/10/14 计算机 次 0 条
转自https://github.com/digitalbirdo/BT-LinkkeySync/issues/12
一、生成Mac系统下的蓝牙配置文件
首先在Mac系统下配对蓝牙鼠标,配对之前可以先删除系统的蓝牙配对文件:
sudo rm /private/var/root/Library/Preferences/com.apple.bluetoothd.plist sudo rm /Library/Preferences/com.apple.Bluetooth.plist
配对鼠标,然后导出配置文件供以后修改:
在桌面上新建/mouse/文件夹
sudo cp /private/var/root/Library/Preferences/com.apple.bluetoothd.plist ~/Desktop/mouse/ sudo cp /Library/Preferences/com.apple.Bluetooth.plist ~/Desktop/mouse/
在两个文件上右键->显示简介,为当前用户添加读写权限。
二、得到Windows系统下的配置参数
重启进入到Windows系统,配对蓝牙鼠标,从微软官网下载PsExec Tool,使用管理员身份在 Power Shell 或命令行中运行:
.\PsExec.exe -s -i regedit
启动regedit,导出以下注册表项:
HKEY\_LOCAL\_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\{bluetooth adapter MAC}\
得到如下文件:
Windows Registry Editor Version 5.00 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys] [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\24f6770fef0d] "MasterIRK"=hex:07,5c,e7,43,8e,12,e4,1c,ae,f8,3e,21,51,75,d7,95 [HKEY_LOCAL_MACHINE\SYSTEM\CurrentControlSet\Services\BTHPORT\Parameters\Keys\24f6770fef0d\ff14dba41d96] "LTK"=hex:b8,5c,73,af,53,a3,7c,46,54,b9,0b,dc,20,49,4f,98 "KeyLength"=dword:00000010 "ERand"=hex(b):26,2f,59,c5,16,66,73,df "EDIV"=dword:0000804f "IRK"=hex:90,a5,5c,5a,88,af,ea,b1,d3,e3,dd,e6,b2,17,44,13 "Address"=hex(b):96,1d,a4,db,14,ff,00,00 "AddressType"=dword:00000001 "MasterIRKStatus"=dword:00000001 "AuthReq"=dword:0000002d
三、回到Mac系统,将Mac的蓝牙配置文件中的参数改成与Windows中一致
这里有三个值需要改字节序(Big Endian 与 Little Endian),分别是EVID、Address和IRK
LTK和RAND的字节序不用改,直接照抄过来就可以。
先将"Address"=hex(b):96,1d,a4,db,14,ff,00,00转换成ff-14-db-a4-1d-96
使用Plist Edit Pro工具修改com.apple.bluetoothd.plist文件,将其中所有的原地址改成上面转换后的地址
然后修改com.apple.bluetoothd.plist文件,修改后的部分内容如下:
"ff-14-db-a4-1d-96" = { Address = {length = 6, bytes = 0xff14dba41d96}; AddressType = 1; EDIV = {length = 2, bytes = 0x4f80}; IRK = {length = 16, bytes = 0x134417b2e6dde3d3b1eaaf885a5ca590}; LTK = {length = 16, bytes = 0xb85c73af53a37c4654b90bdc20494f98}; LTKLength = {length = 1, bytes = 0x10}; MITMProtection = 0; OriginalAddressType = 1; RAND = {length = 8, bytes = 0x262f59c5166673df}; };
四,将修改完成的配置文件复制回去替换掉原位置的文件
此步操作之前一定要先关闭蓝牙
先恢复这两个文件的权限和所有者:
sudo chown root:wheel ~/Desktop/mouse/com.apple.bluetoothd.plist sudo chown root:wheel ~/Desktop/mouse/com.apple.Bluetooth.plist sudo chmod 600 ~/Desktop/mouse/com.apple.bluetoothd.plist sudo chmod 600 ~/Desktop/mouse/com.apple.Bluetooth.plist
确定文件权限是-rw-------,所有者是root:wheel
ls -al ~/Desktop/mouse/
然后复制回去覆盖原文件:
sudo cp ~/Desktop/mouse/com.apple.bluetoothd.plist /private/var/root/Library/Preferences/com.apple.bluetoothd.plist sudo cp ~/Desktop/mouse/com.apple.Bluetooth.plist /Library/Preferences/com.apple.Bluetooth.plist
查看一下是否修改成功,有无遗漏的地方
sudo defaults read /private/var/root/Library/Preferences/com.apple.bluetoothd.plist sudo defaults read /Library/Preferences/com.apple.Bluetooth.plist
重启Mac系统,打开蓝牙,原来在Windows系统下配对的蓝牙鼠标现在不用重新配对就能直接在Mac系统下使用了,再次重启回到Windows系统下,鼠标依然能用。
成功!