10

I am trying to set specific bluetooth link keys for a device in Ubuntu 14.10 but I am unable to find where they are stored.
The purpose is to have a bluetooth mouse working in both Ubuntu and Windows without having to re-pair it after switching operating systems.
All the answers I found on AskUbuntu state that the keys are stored in /var/lib/bluetooth/<mac_address>/linkkeys and this used to be the case at least until 13.10, but in 14.10 this file is missing from a clean desktop install and creating it manually has no effect, it is ignored by bluetoothd.

EDIT: It seems that the mouse doesn't issue a pairing request and the link keys aren't stored in this case. However, connecting the mouse in Windows and then rebooting in Ubuntu causes the bluetooth connection to fail (and the mouse needs to be removed and re-added to the bluetooth device list), so there's definitely some key exchange/authentication going on that prevents the mouse from being shared in both OS. The question remains, how can I force bluetoothd to save and use the saved link keys when connecting this mouse?

Hardware details:

  • Microsoft Bluetooth Notebook Mouse 5000
  • 413c:8161 Dell Computer Corp. Wireless 365 Bluetooth (Broadcom BCM2046B1)

The two logs below show that for a pairable device (mobile phone) the keys are stored in the linkkeys file; this is not the case for the mouse. I know that older bluetoothd versions used to save the link keys for mice as well, because there are lots of answers/tutorials here on askubuntu and ubuntuforums about copying linkkeys from Windows to Ubuntu for the specific purpose of sharing a mouse between the two OS.

Here is the bluetoothd log for the mouse discovery and connection setup:

    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

Here is the bluetoothd log for the pairing of a mobile phone (user is asked to validate a code shown on both devices):

    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
  • I've got 14.04 and the directory exists for me, but the mac address is the one for my internal bluetooth and linkkeys is empty... – Fabby Nov 27 '14 at 20:55
  • I had 14.04 and upgraded to 14.10, now I can't find the directory. I have the same issue as you, wanting to set the link key for a BT mouse. – Alasjo Nov 28 '14 at 11:30
3

After a while, I finally solved the issue I was facing. I still haven't found an answer to the initial question (I couldn't determine where the link keys are stored for this particular bluez/adapter/peripheral combination) but I did find out that bluez will read the linkkeys file, if present, and will use the keys in the file.

So even though the link keys might not be written to the file after pairing, it is possible to override those keys by manually adding them to the linkkeys file.

It is important that the key type is set correctly, otherwise the key will be ignored.

For reference, the key type that worked in my case is shown here: https://askubuntu.com/a/246791/352576

1

Ubuntu 13.10 uses bluez 4.98, 14.04 and 14.10 uses 4.101

Both versions were compiled with the same option (--localstatedir=/var)

I'm using 14.04 and the files are there and if I remove or add a device the /var/lib/bluetooth/(myadapteraddress)/linkkeys file is updated accordingly.

I made a test on a 14.10 system, I added a BT device and the /var/lib/bluetooth/(adapteraddress)/linkkeys file was created

Maybe you are using a newer version of bluez.

Schema for new versions of bluez (5 onwards i think) :

/var/lib/bluetooth/<adapter address>/<remote device address>/info

In the documentation of settings storage for the new bluez version, I found this:

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

...

In any case seems that bluez should storage the files in /var/lib/bluetooth

If you use this command

bluetoothd --version

you get 4.101?

  • 1
    Yes, bluetoothd version is 4.101. The var/lib/bluetoooth/<adapter address> folder exists but there is no linkkeys file, nor any subdirectory. The bluetooth device is paired and working, so the keys are stored somewhere but definitely not there. Maybe the Ubuntu version stores the keys somewhere else and I'm trying to find out where. I'm using a standard 14.10 desktop install, pairing made through the bluetooth indicator, nothing fancy. – ATAKAMA Dec 27 '14 at 17:37
  • 1
    It just occurred to me that some bluetooth adapters have hardware key storage. Would it be possible for the Ubuntu bluetoothd to store the link keys only in the adapter memory and not in the filesystem? The adapter is: 413c:8160 Dell Computer Corp. Wireless 365 Bluetooth based on Broadcom BCM2046 – ATAKAMA Dec 27 '14 at 18:10
  • Have you tried paring another device, a cellphone?... Later I will try in another PC with 14.10 – J.Serra Dec 27 '14 at 18:21
  • I just paired a mobile phone that was never paired with this adapter (neither in Ubuntu, nor in Windows). The linkkeys file was created. Then I tried to pair the mouse again, it paired, but its link key was not added to the file. How do I get bluetoothd to read the link key in the file and not use the one in the adapter (which is what it presumably does)? – ATAKAMA Dec 27 '14 at 18:52
  • That's is very curious... Maybe if you eliminate the device in windows, ubuntu creates the file. – J.Serra Dec 27 '14 at 18:56
0

/var/lib/bluetooth/{bluetoothaddr}/linkkeys

Where {bluetoothaddr} is your bluetooth interface (you should have only one, it looks like a mac address)

The file format is {remoteaddr} {128 bit link key} {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
  • Please read the question text carefully. That file no longer exists on a 14.10 install. There is no linkkeys file anywhere in the filesystem. The keys are stored somewhere else. The question is where. – ATAKAMA Dec 27 '14 at 16:05
  • On my new laptop where I installed (no update) 14.10, there is still the file as I described it. bluetoothd 4.101. What's the messages on syslog when you try to pair a new device? – Xavier Dec 28 '14 at 11:30
  • I edited the question and added some logs to compare the discovery and connection setup of this mouse vs the connection setup of a mobile phone, whose link keys are saved. – ATAKAMA Dec 28 '14 at 16:13
0

In Debian Jessie & I assume Ubuntu as well you can manually set the PIN to use.

  1. Do what this post https://askubuntu.com/a/246791/352576 describes to get your windows key.
  2. your /var/lib/bluetooth/XX:XX:XX:XX:XX:AA (where XX: ... :AA is the mac of your PC's BT adapter) should contain a dir with the mac of your BT mouse/keyboard (I'll represent it as XX: ... :BF, and files config, & settings.
  3. within XX: ... BF there is a file info owned by root, with permissions rw for root. No other permissions.-- contents should be:

    [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
    

    Note the key length is 16 bytes long.

sticking linkkeys files in these directories did not help me -- though I left them in there good measure.

-1

Type "linkkeys" in the search bar of nautilus while you are in the filesystem location. If you have got the file, just right click the file name and click the Open Item Location. It will navigate you to the file location and you can now note the location of the file.

  • This is not an answer to my question. I'm not looking for a file that was moved. I'm looking for data that used to be stored in that file but it's now stored somewhere else. – ATAKAMA Dec 27 '14 at 6:44
  • The linkkeys is what you are searching exactly for? or the transferred data from device to PC? – Wolverine Dec 27 '14 at 12:04
  • I'm searching for the Bluetooth link keys, the shared secret that enables two paired bluetooth devices to talk to each other. They are no longer stored in the linkkeys file. I'm trying to find out where they are stored in Ubuntu 14.10. – ATAKAMA Dec 27 '14 at 12:14
  • Why don't you search all the files in the /var/lib/bluetooth/nn:nn:nn:nn:nn:nn/ directory? – Wolverine Dec 27 '14 at 12:23

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.