我正在尝试为 Ubuntu 14.10 中的设备设置特定的蓝牙链接密钥,但找不到它们的存储位置。
目的是让蓝牙鼠标在 Ubuntu 和 Windows 中都能正常工作,而无需在切换操作系统后重新配对。
我在 AskUbuntu 上找到的所有答案都表明密钥存储在,/var/lib/bluetooth/<mac_address>/linkkeys
并且至少在 13.10 之前都是这种情况,但在 14.10 中,干净的桌面安装中缺少此文件,手动创建它没有任何效果,它会被 bluetoothd 忽略。
编辑:看来鼠标没有发出配对请求,并且在这种情况下没有存储链接密钥。但是,在 Windows 中连接鼠标然后在 Ubuntu 中重新启动会导致蓝牙连接失败(并且需要移除鼠标并重新添加到蓝牙设备列表中),因此肯定存在一些密钥交换/身份验证,阻止鼠标在两个操作系统中共享。问题仍然存在,如何在连接此鼠标时强制 bluetoothd 保存并使用已保存的链接密钥?
硬件详细信息:
- 微软蓝牙笔记本鼠标 5000
- 413c:8161 戴尔计算机公司无线 365 蓝牙 (Broadcom BCM2046B1)
下面的两个日志显示,对于可配对设备(移动电话),密钥存储在 linkkeys 文件中;对于鼠标则不是这样。我知道旧版的 bluetoothd 也用于保存鼠标的链接密钥,因为 askubuntu 和 ubuntuforums 上有很多关于将链接密钥从 Windows 复制到 Ubuntu 的答案/教程,具体目的是在两个操作系统之间共享鼠标。
以下是鼠标发现和连接设置的蓝牙日志:
bluetoothd[15615]: plugins/mgmtops.c:mgmt_start_discovery() index 0
bluetoothd[15615]: Discovery session 0x7feb52b14130 with :1.137 activated
bluetoothd[15615]: src/adapter.c:session_ref() 0x7feb52b14130: ref=1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 10 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: plugins/mgmtops.c:start_discovery_complete() hci0 type 1 status 0
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 8 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_discovering() Controller 0 type 1 discovering 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 25 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_device_found() hci0 addr DE:AD:BE:EF:00:00, rssi -43 flags 0x0003 eir_len 5
bluetoothd[15615]: plugins/mgmtops.c:mgmt_confirm_name() hci0 bdaddr DE:AD:BE:EF:00:00 name_known 0
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 16 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: Unknown command complete for opcode 37
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 61 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_device_found() hci0 addr DE:AD:BE:EF:00:00, rssi -43 flags 0x0000 eir_len 41
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 8 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_discovering() Controller 0 type 1 discovering 0
bluetoothd[15615]: src/adapter.c:adapter_set_discovering() hci0 restarting discovery, disc_sessions 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_start_discovery() index 0
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 10 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: plugins/mgmtops.c:start_discovery_complete() hci0 type 1 status 0
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 8 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_discovering() Controller 0 type 1 discovering 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 25 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_device_found() hci0 addr DE:AD:BE:EF:00:00, rssi -43 flags 0x0003 eir_len 5
bluetoothd[15615]: src/adapter.c:session_unref() 0x7feb52b14130: ref=0
bluetoothd[15615]: src/adapter.c:session_remove() Discovery session 0x7feb52b14130 with :1.137 deactivated
bluetoothd[15615]: src/adapter.c:session_remove() Stopping discovery
bluetoothd[15615]: plugins/mgmtops.c:mgmt_stop_discovery() index 0
bluetoothd[15615]: Stopping discovery
bluetoothd[15615]: src/adapter.c:create_device() DE:AD:BE:EF:00:00
bluetoothd[15615]: src/adapter.c:adapter_create_device() DE:AD:BE:EF:00:00
bluetoothd[15615]: src/device.c:device_create() Creating device /org/bluez/15615/hci0/dev_DE:AD:BE:EF:00:00
bluetoothd[15615]: src/device.c:btd_device_ref() 0x7feb52b15680: ref=1
bluetoothd[15615]: src/device.c:device_set_temporary() temporary 1
bluetoothd[15615]: src/device.c:btd_device_ref() 0x7feb52b15680: ref=2
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 10 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete() stop_discovery complete
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 8 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_discovering() Controller 0 type 1 discovering 0
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 65 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_device_connected() hci0 device DE:AD:BE:EF:00:00 connected eir_len 46
bluetoothd[15615]: src/adapter.c:adapter_get_device() DE:AD:BE:EF:00:00
bluetoothd[15615]: src/device.c:device_probe_drivers() Probing drivers for DE:AD:BE:EF:00:00
bluetoothd[15615]: input/manager.c:hid_device_probe() path /org/bluez/15615/hci0/dev_DE:AD:BE:EF:00:00
bluetoothd[15615]: src/device.c:btd_device_ref() 0x7feb52b15680: ref=3
bluetoothd[15615]: input/device.c:input_device_new() Registered interface org.bluez.Input on path /org/bluez/15615/hci0/dev_DE:AD:BE:EF:00:00
bluetoothd[15615]: src/device.c:device_set_temporary() temporary 0
bluetoothd[15615]: src/device.c:btd_device_unref() 0x7feb52b15680: ref=2
以下是手机配对的蓝牙日志(要求用户验证两个设备上显示的代码):
bluetoothd[15615]: plugins/mgmtops.c:mgmt_start_discovery() index 0
bluetoothd[15615]: Discovery session 0x7feb52b14ca0 with :1.138 activated
bluetoothd[15615]: src/adapter.c:session_ref() 0x7feb52b14ca0: ref=1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 10 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: plugins/mgmtops.c:start_discovery_complete() hci0 type 1 status 0
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 8 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_discovering() Controller 0 type 1 discovering 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 64 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_device_found() hci0 addr DE:AD:BE:EF:01:01, rssi -52 flags 0x0000 eir_len 44
bluetoothd[15615]: src/adapter.c:session_unref() 0x7feb52b14ca0: ref=0
bluetoothd[15615]: src/adapter.c:session_remove() Discovery session 0x7feb52b14ca0 with :1.138 deactivated
bluetoothd[15615]: src/adapter.c:session_remove() Stopping discovery
bluetoothd[15615]: plugins/mgmtops.c:mgmt_stop_discovery() index 0
bluetoothd[15615]: Stopping discovery
bluetoothd[15615]: src/adapter.c:adapter_create_device() DE:AD:BE:EF:01:01
bluetoothd[15615]: src/device.c:device_create() Creating device /org/bluez/15615/hci0/dev_DE:AD:BE:EF:01:01
bluetoothd[15615]: src/device.c:btd_device_ref() 0x7feb52b17cd0: ref=1
bluetoothd[15615]: src/device.c:device_set_temporary() temporary 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_create_bonding() hci0 bdaddr DE:AD:BE:EF:01:01 io_cap 0x01
bluetoothd[15615]: src/device.c:bonding_request_new() Requesting bonding for DE:AD:BE:EF:01:01
bluetoothd[15615]: src/device.c:bonding_request_new() Temporary agent registered for DE:AD:BE:EF:01:01 at :1.138:/org/bluez/agent/wizard
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 10 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete() stop_discovery complete
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 8 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_discovering() Controller 0 type 1 discovering 0
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 37 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_device_connected() hci0 device DE:AD:BE:EF:01:01 connected eir_len 18
bluetoothd[15615]: src/adapter.c:adapter_get_device() DE:AD:BE:EF:01:01
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 18 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_user_confirm_request() hci0 DE:AD:BE:EF:01:01 confirm_hint 0
bluetoothd[15615]: src/adapter.c:adapter_get_device() DE:AD:BE:EF:01:01
bluetoothd[15615]: src/device.c:new_auth() Requesting agent authentication for DE:AD:BE:EF:01:01
bluetoothd[15615]: src/agent.c:agent_request_confirmation() Calling Agent.RequestConfirmation: name=:1.138, path=/org/bluez/agent/wizard, passkey=436733
bluetoothd[15615]: plugins/mgmtops.c:mgmt_confirm_reply() index 0 addr DE:AD:BE:EF:01:01 success 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 16 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete() user_confirm_reply complete
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 32 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_new_link_key() Controller 0 new key of type 5 pin_len 0
bluetoothd[15615]: src/adapter.c:adapter_get_device() DE:AD:BE:EF:01:01
bluetoothd[15615]: src/event.c:btd_event_link_key_notify() storing link key of type 0x05
bluetoothd[15615]: src/device.c:device_set_bonded() bonded 1
bluetoothd[15615]: src/device.c:device_set_temporary() temporary 0
bluetoothd[15615]: src/adapter.c:adapter_get_device() DE:AD:BE:EF:01:01
bluetoothd[15615]: src/device.c:device_bonding_complete() bonding 0x7feb52b2d270 status 0x00
bluetoothd[15615]: src/device.c:device_bonding_complete() Proceeding with service discovery
bluetoothd[15615]: src/device.c:btd_device_ref() 0x7feb52b17cd0: ref=2
bluetoothd[15615]: src/agent.c:agent_release() Releasing agent :1.138, /org/bluez/agent/wizard
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() cond 1
bluetoothd[15615]: plugins/mgmtops.c:mgmt_event() Received 16 bytes from management socket
bluetoothd[15615]: plugins/mgmtops.c:mgmt_cmd_complete()
bluetoothd[15615]: plugins/mgmtops.c:pair_device_complete() hci0 DE:AD:BE:EF:01:01 pairing complete status 0
bluetoothd[15615]: src/adapter.c:adapter_get_device() DE:AD:BE:EF:01:01
bluetoothd[15615]: src/device.c:device_bonding_complete() bonding (nil) status 0x00
答案1
过了一会儿,我终于解决了我面临的问题。我仍然没有找到最初问题的答案(我无法确定此特定 bluez/适配器/外围设备组合的链接密钥存储在哪里),但我发现 bluez 将读取链接密钥文件(如果存在),并使用文件中的密钥。
因此,即使配对后链接密钥可能不会写入文件中,也可以通过手动将其添加到链接密钥文件中来覆盖这些密钥。
正确设置密钥类型非常重要,否则密钥将被忽略。
作为参考,在我的情况下起作用的关键类型显示如下:https://askubuntu.com/a/246791/352576
答案2
Ubuntu 13.10 使用 bluez 4.98、14.04 和 14.10 使用 4.101
两个版本都使用相同的选项 (--localstatedir=/var) 进行编译
我正在使用 14.04,并且文件在那里,如果我删除或添加设备,/var/lib/bluetooth/(myadapteraddress)/linkkeys 文件也会相应更新。
我在 14.10 系统上进行了测试,添加了一个 BT 设备,并创建了 /var/lib/bluetooth/(adapteraddress)/linkkeys 文件
也许您正在使用较新版本的 bluez。
bluez 新版本的架构(我认为是 5 及以上版本):
/var/lib/bluetooth/<adapter address>/<remote device address>/info
在新版 bluez 的设置存储文档中,我发现了这一点:
http://git.kernel.org/cgit/bluetooth/bluez.git/tree/doc/settings-storage.txt
...
Storage directory structure
There is one directory per adapter, named by its Bluetooth address, which
contains:
- a settings file for the local adapter
- an attributes file containing attributes of supported LE services
- a cache directory containing:
- one file per device, named by remote device address, which contains device name
- one directory per remote device, named by remote device address, which contains:
- an info file
- an attributes file containing attributes of remote LE services
- a ccc file containing persistent Client Characteristic Configuration
(CCC) descriptor information for GATT characteristics
So the directory structure is:
/var/lib/bluetooth/<adapter address>/
./settings
./attributes
./cache/
./<remote device address>
./<remote device address>
...
./<remote device address>/
./info
./attributes
./ccc
./<remote device address>/
./info
./attributes
...
...
Info file format
...
[LinkKey] group contains:
Key String Key in hexadecimal format
Type Integer Type of link key
PINLength Integer Length of PIN
...
无论如何,bluez似乎应该将文件存储在/var/lib/blueoth中
如果你使用此命令
bluetoothd --version
你得了 4.101 吗?
答案3
/var/lib/蓝牙/{蓝牙地址}/链接键
在哪里{蓝牙地址}是你的蓝牙接口(你应该只有一个,它看起来像一个 mac 地址)
文件格式为 {remoteaddr} {128 位链接密钥} {type}。
20:12:03:22:EE:0E C21D3A69DEA0A8C629F1BB5D12AEEA79 4 0
00:18:94:68:3E:90 EC02519ED656DB87B7F152E899F8A810 0 4
00:21:3F:3E:2E:6C 948A0EF91FA8E9EB9032CE775BF8E0B0 0 4
答案4
在 Debian Jessie 中,我认为 Ubuntu 中您也可以手动设置要使用的 PIN。
- 按照这篇文章做https://askubuntu.com/a/246791/352576描述如何获取您的 Windows 密钥。
- 你的
/var/lib/bluetooth/XX:XX:XX:XX:XX:AA
(XX: ... :AA
你电脑的 BT 适配器的 mac 在哪里)应该包含一个目录,其中有你的 BT 鼠标/键盘的 mac(我将其表示为XX: ... :BF
,以及文件配置和设置)。 其中
XX: ... BF
有一个文件info
归 root 所有,并且 root 具有 rw 权限。没有其他权限。-- 内容应为:[LinkKey] Key=A7XXXXXXXXXXXXXXXXXXXXXXXXXXXX89 Type=4 PINLength=0 [General] Name=yourMouseName Class=0x002580 SupportedTechnologies=BR/EDR; Trusted=true Blocked=false Services=00001000-0000-1000-8000-00805f9b34fb;00001124-0000-1000-8000-00805f9b34fb;00001200-0000-1000-8000-00805f9b34fb; [DeviceID] Source=2 Vendor=1133 Product=45069 Version=1792
注意密钥长度为 16 个字节。
将 linkkeys 文件粘贴在这些目录中对我没有帮助——尽管我把它们留在那里。