Running "putkey" for keyboards and mice
Heya,
Did a small test this week-end on my Macbook, and running "hciconfig" with putkey works, adding the just paired keyboards' linkkey into the Bluetooth adapter.
This meant that even though I paired the device in Linux, it was still available in MacOS X, without any more pairing.
My question is whether we should, for all the adapters listed in the hid2hci rules, copy the linkkeys for keyboards and (paired) mice[1] to the adapter itself.
How would you like to see this implemented? Would a device plugin be good enough to track newly paired devices?
Cheers
[1]: Just the mice that would require pairing, obviously, such as the Apple mice
Luiz Augusto von Dentz
maintainerHi,
Quoted 9 lines · Bastien Nocera
Heya,
Did a small test this week-end on my Macbook, and running "hciconfig" with putkey works, adding the just paired keyboards' linkkey into the Bluetooth adapter.
This meant that even though I paired the device in Linux, it was still available in MacOS X, without any more pairing.
Quoted 6 lines
My question is whether we should, for all the adapters listed in the hid2hci rules, copy the linkkeys for keyboards and (paired) mice[1] to the adapter itself.
How would you like to see this implemented? Would a device plugin be good enough to track newly paired devices?
Im not sure this is going to work the other way round, when you pair in some other SO and than save the key in the chip we would need to load this device as it is already paired. If that can be done than IMOH this should be integrated directly in core, perhaps adding .putkey/.delkey/.getkeys to hciops so we can properly use the keys stored on chip, but I guess we need to maintain our own storage too since chips normally have very limited space for storing keys.
Signature · 2 lines
Luiz Augusto von Dentz Computer Engineer
Quoted 16 lines · Luiz Augusto von Dentz
Hi,
Quoted 13 lines · Bastien Nocera
Heya,
Did a small test this week-end on my Macbook, and running "hciconfig" with putkey works, adding the just paired keyboards' linkkey into the Bluetooth adapter.
This meant that even though I paired the device in Linux, it was still available in MacOS X, without any more pairing.
My question is whether we should, for all the adapters listed in the hid2hci rules, copy the linkkeys for keyboards and (paired) mice[1] to the adapter itself.
Quoted 6 lines
Quoted 2 lines
How would you like to see this implemented? Would a device plugin be good enough to track newly paired devices?
Im not sure this is going to work the other way round, when you pair in some other SO and than save the key in the chip we would need to load this device as it is already paired.
Some Windows drivers support doing this, though not all of them. MacOS X clearly supports this, as the recommended way to make sure a keyboard will be available in Windows, when dual-booting with BootCamp, is to boot into MacOS X, which will write the linkkeys to the device. So the Windows Apple Bluetooth drivers know how to read the linkkeys, but not write them.
Quoted 5 lines
If that can be done than
IMOH this should be integrated directly in core, perhaps adding .putkey/.delkey/.getkeys to hciops so we can properly use the keys stored on chip, but I guess we need to maintain our own storage too since chips normally have very limited space for storing keys.
Johan mentioned that we could implement this using a boolean property for whether to store the linkkey on the device or not. When TRUE, should we store the linkkey on both the device and on the local filesystem, or just on the device?
hci_read_stored_link_key() is not currently used in the code at all, so it's possible that a device will be paired, but not marked as such in the interface.
Cheers
On Mon, 2010-09-06 at 13:19 +0100, Bastien Nocera wrote:
<snip>
Quoted 8 lines
Johan mentioned that we could implement this using a boolean property for whether to store the linkkey on the device or not. When TRUE, should we store the linkkey on both the device and on the local filesystem, or just on the device?
hci_read_stored_link_key()is not currently used in the code at all, so it's possible that a device will be paired, but not marked as such in the interface.
I was wrongly reading the code, and it already does that.
Patch attached to add the "KeyOnAdapter" property to devices.
Note that I did not test this thoroughly yet. I'm more looking for comments right now.
Cheers
Quoted 1 line
From
f387bbee64306db9096e28316160fe547388c6c3Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Mon, 6 Sep 2010 17:21:30 +0100
Subject: [PATCH] Add KeyOnAdapter property to devices
The KeyOnAdapter property will be true if the linkkey comes from the adapter storage, rather than the local filesystem storage.
This makes it possible for front-ends to add linkkeys to the adapter itself for keyboard and mice to automatically work when dual-booting under other OSes.
--- doc/device-api.txt | 16 ++++++++ plugins/hciops.c | 32 ++++++++++++++++ src/adapter.c | 22 +++++++++++ src/adapter.h | 6 +++ src/dbus-hci.c | 1 + src/device.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + 7 files changed, 184 insertions(+), 0 deletions(-)
doc/device-api.txt +16 -0
@@ -161,6 +161,22 @@ Properties string Address [readonly] drivers will also be removed and no new ones will be probed as long as the device is blocked. + boolean KeyOnAdapter [readwrite] + + Whether the linkkey for the device is available + on the adapter. This will be FALSE if the device + is not paired, or the key is not available on + the adapter (and just on the filesystem). + + Setting this to TRUE, will write the key to the + adapter, returning an error if the adapter + does not support this. + + Note that the key is not removed from the local + filesystem storage, as, once on the adapter, it + will lack linkkey type information, which is + required for Bluetooth 2.1 devices. + string Alias [readwrite] The name alias for the remote device. The alias can
plugins/hciops.c +32 -0
@@ -748,6 +748,36 @@ static int hciops_fast_connectable(int index, gboolean enable)return err; } +static int hciops_put_key (int index,bdaddr_t bdaddr,uint8_t *key) +{ +int dd, err; + + dd =hci_open_dev (index); +if (dd <0 ) +return -EIO ; + + err =hci_write_stored_link_key (dd, &bdaddr, key,HCI_REQ_TIMEOUT ); + +hci_close_dev (dd); + +return -err; +} + +static int hciops_del_key (int index,bdaddr_t bdaddr) +{ +int dd, err; + + dd =hci_open_dev (index); +if (dd <0 ) +return -EIO ; + + err =hci_delete_stored_link_key (dd, &bdaddr,0 ,HCI_REQ_TIMEOUT ); + +hci_close_dev (dd); + +return -err; +} +static struct btd_adapter_ops hci_ops = { .setup = hciops_setup, .cleanup = hciops_cleanup,
@@ -765,6 +795,8 @@ static struct btd_adapter_ops hci_ops = { .read_name = hciops_read_name, .set_class = hciops_set_class, .set_fast_connectable = hciops_fast_connectable, + .put_key = hciops_put_key, + .del_key = hciops_del_key, };static int hciops_init (void )
src/adapter.c +22 -0
@@ -3519,3 +3519,25 @@ int btd_adapter_set_fast_connectable(struct btd_adapter *adapter,return adapter_ops->set_fast_connectable (adapter->dev_id, enable); } + +int btd_adapter_put_key (struct btd_adapter *adapter,bdaddr_t bdaddr,uint8_t *key) +{ +if (!adapter_ops) +return -EINVAL ; + +if (!adapter->up) +return -EINVAL ; + +return adapter_ops->put_key (adapter->dev_id, bdaddr, key); +} + +int btd_adapter_del_key (struct btd_adapter *adapter,bdaddr_t bdaddr) +{ +if (!adapter_ops) +return -EINVAL ; + +if (!adapter->up) +return -EINVAL ; + +return adapter_ops->del_key (adapter->dev_id, bdaddr); +}
src/adapter.h +6 -0
@@ -187,6 +187,8 @@ struct btd_adapter_ops {int (*read_name) (int index);int (*set_class) (int index,uint32_t class);int (*set_fast_connectable) (int index,gboolean enable); +int (*put_key) (int index,bdaddr_t bdaddr,uint8_t *key); +int (*del_key) (int index,bdaddr_t bdaddr); };int btd_register_adapter_ops (struct btd_adapter_ops *btd_adapter_ops);
@@ -205,3 +207,7 @@ void btd_adapter_unregister_powered_callback(struct btd_adapter *adapter,* type to default values. Valid for both connectable and discoverable modes. */ int btd_adapter_set_fast_connectable (struct btd_adapter *adapter,gboolean enable); +int btd_adapter_put_key (struct btd_adapter *adapter, +bdaddr_t bdaddr, +uint8_t *key); +int btd_adapter_del_key (struct btd_adapter *adapter,bdaddr_t bdaddr);
src/dbus-hci.c +1 -0
@@ -903,6 +903,7 @@ void hcid_dbus_returned_link_key(bdaddr_t *local, bdaddr_t *peer)return ;device_set_paired (device, TRUE); +device_set_key_on_adapter (device, TRUE); } int hcid_dbus_get_io_cap(bdaddr_t *local, bdaddr_t *remote,
src/device.c +106 -0
142 lines not on this page · raw message
src/device.h +1 -0
@@ -55,6 +55,7 @@ gboolean device_is_temporary(struct btd_device *device);gboolean device_is_paired (struct btd_device *device);gboolean device_is_trusted (struct btd_device *device);void device_set_paired (struct btd_device *device,gboolean paired); +void device_set_key_on_adapter (struct btd_device *device,gboolean key_on_adapter);void device_set_temporary (struct btd_device *device,gboolean temporary);void device_set_cap (struct btd_device *device,uint8_t cap);uint8_t device_get_cap (struct btd_device *device);
Signature · 1 line
1.7.0.1
Quoted 11 lines · Bastien Nocera
On Mon, 2010-09-06 at 13:19 +0100, Bastien Nocera wrote:
<snip>Quoted 8 lines
Johan mentioned that we could implement this using a boolean property for whether to store the linkkey on the device or not. When TRUE, should we store the linkkey on both the device and on the local filesystem, or just on the device?
hci_read_stored_link_key()is not currently used in the code at all, so it's possible that a device will be paired, but not marked as such in the interface.
Quoted 6 lines
I was wrongly reading the code, and it already does that.
Patch attached to add the "KeyOnAdapter" property to devices.
Note that I did not test this thoroughly yet. I'm more looking for comments right now.
Updated for latest git master.
Cheers
Quoted 1 line
From
ae889732f66e1814622b546f167963cda2fa5de5Mon Sep 17 00:00:00 2001
From: Bastien Nocera <[email protected]>
Date: Mon, 6 Sep 2010 17:21:30 +0100
Subject: [PATCH] Add KeyOnAdapter property to devices
The KeyOnAdapter property will be true if the linkkey comes from the adapter storage, rather than the local filesystem storage.
This makes it possible for front-ends to add linkkeys to the adapter itself for keyboard and mice to automatically work when dual-booting under other OSes.
--- doc/device-api.txt | 16 ++++++++ plugins/hciops.c | 32 ++++++++++++++++ src/adapter.c | 22 +++++++++++ src/adapter.h | 7 +++ src/dbus-hci.c | 1 + src/device.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++ src/device.h | 1 + 7 files changed, 185 insertions(+), 0 deletions(-)
doc/device-api.txt +16 -0
@@ -161,6 +161,22 @@ Properties string Address [readonly] drivers will also be removed and no new ones will be probed as long as the device is blocked. + boolean KeyOnAdapter [readwrite] + + Whether the linkkey for the device is available + on the adapter. This will be FALSE if the device + is not paired, or the key is not available on + the adapter (and just on the filesystem). + + Setting this to TRUE, will write the key to the + adapter, returning an error if the adapter + does not support this. + + Note that the key is not removed from the local + filesystem storage, as, once on the adapter, it + will lack linkkey type information, which is + required for Bluetooth 2.1 devices. + string Alias [readwrite] The name alias for the remote device. The alias can
plugins/hciops.c +32 -0
@@ -786,6 +786,36 @@ fail:return err; } +static int hciops_put_key (int index,bdaddr_t bdaddr,uint8_t *key) +{ +int dd, err; + + dd =hci_open_dev (index); +if (dd <0 ) +return -EIO ; + + err =hci_write_stored_link_key (dd, &bdaddr, key,HCI_REQ_TIMEOUT ); + +hci_close_dev (dd); + +return -err; +} + +static int hciops_del_key (int index,bdaddr_t bdaddr) +{ +int dd, err; + + dd =hci_open_dev (index); +if (dd <0 ) +return -EIO ; + + err =hci_delete_stored_link_key (dd, &bdaddr,0 ,HCI_REQ_TIMEOUT ); + +hci_close_dev (dd); + +return -err; +} +static struct btd_adapter_ops hci_ops = { .setup = hciops_setup, .cleanup = hciops_cleanup,
@@ -805,6 +835,8 @@ static struct btd_adapter_ops hci_ops = { .set_fast_connectable = hciops_fast_connectable, .read_clock = hciops_read_clock, .get_conn_handle = hciops_conn_handle, + .put_key = hciops_put_key, + .del_key = hciops_del_key, };static int hciops_init (void )
src/adapter.c +22 -0
@@ -3544,3 +3544,25 @@ int btd_adapter_get_conn_handle(struct btd_adapter *adapter,return adapter_ops->get_conn_handle (adapter->dev_id, bdaddr, handle); } + +int btd_adapter_put_key (struct btd_adapter *adapter,bdaddr_t bdaddr,uint8_t *key) +{ +if (!adapter_ops) +return -EINVAL ; + +if (!adapter->up) +return -EINVAL ; + +return adapter_ops->put_key (adapter->dev_id, bdaddr, key); +} + +int btd_adapter_del_key (struct btd_adapter *adapter,bdaddr_t bdaddr) +{ +if (!adapter_ops) +return -EINVAL ; + +if (!adapter->up) +return -EINVAL ; + +return adapter_ops->del_key (adapter->dev_id, bdaddr); +}
src/adapter.h +7 -0
@@ -190,6 +190,8 @@ struct btd_adapter_ops {int (*read_clock) (int index,int handle,int which,int timeout,uint32_t *clock,uint16_t *accuracy);int (*get_conn_handle) (int index,const bdaddr_t *bdaddr,int *handle); +int (*put_key) (int index,bdaddr_t bdaddr,uint8_t *key); +int (*del_key) (int index,bdaddr_t bdaddr); };int btd_register_adapter_ops (struct btd_adapter_ops *btd_adapter_ops);
@@ -214,3 +216,8 @@ int btd_adapter_read_clock(struct btd_adapter *adapter, int handle, int which, uint16_t *accuracy);int btd_adapter_get_conn_handle (struct btd_adapter *adapter,const bdaddr_t *bdaddr,int *handle); + +int btd_adapter_put_key (struct btd_adapter *adapter, +bdaddr_t bdaddr, +uint8_t *key); +int btd_adapter_del_key (struct btd_adapter *adapter,bdaddr_t bdaddr);
src/dbus-hci.c +1 -0
@@ -903,6 +903,7 @@ void hcid_dbus_returned_link_key(bdaddr_t *local, bdaddr_t *peer)return ;device_set_paired (device, TRUE); +device_set_key_on_adapter (device, TRUE); } int hcid_dbus_get_io_cap(bdaddr_t *local, bdaddr_t *remote,
src/device.c +106 -0
142 lines not on this page · raw message
src/device.h +1 -0
@@ -55,6 +55,7 @@ gboolean device_is_temporary(struct btd_device *device);gboolean device_is_paired (struct btd_device *device);gboolean device_is_trusted (struct btd_device *device);void device_set_paired (struct btd_device *device,gboolean paired); +void device_set_key_on_adapter (struct btd_device *device,gboolean key_on_adapter);void device_set_temporary (struct btd_device *device,gboolean temporary);void device_set_cap (struct btd_device *device,uint8_t cap);uint8_t device_get_cap (struct btd_device *device);
Signature · 1 line
1.7.2.3