On startup the keys are loaded, even if the keyset is empty. As mentionned in a comment says this is to erase any keys in the kernel. However BLE only devices do not support loading keys (the operation always returns unsupported error code). So, if we get an unsupported operation error, and if the keyset is empty, ignore and continue. Signed-off-by: Martin Fuzzey <mfuzzey@xxxxxxxxxxx> --- android/bluetooth.c | 23 ++++++++++++++++++----- 1 file changed, 18 insertions(+), 5 deletions(-) diff --git a/android/bluetooth.c b/android/bluetooth.c index 51a31fe..8ea521e 100644 --- a/android/bluetooth.c +++ b/android/bluetooth.c @@ -2531,13 +2531,18 @@ static void register_mgmt_handlers(void) NULL, NULL); } +struct load_link_keys_userdata { + bt_bluetooth_ready cb; + size_t key_count; +}; + static void load_link_keys_complete(uint8_t status, uint16_t length, const void *param, void *user_data) { - bt_bluetooth_ready cb = user_data; + struct load_link_keys_userdata *ud = user_data; int err; - if (status) { + if (status && !((status == MGMT_STATUS_NOT_SUPPORTED && ud->key_count == 0))) { error("Failed to load link keys for index %u: %s (0x%02x)", adapter.index, mgmt_errstr(status), status); err = -EIO; @@ -2546,17 +2551,20 @@ static void load_link_keys_complete(uint8_t status, uint16_t length, DBG("status %u", status); - cb(0, &adapter.bdaddr); + ud->cb(0, &adapter.bdaddr); + g_free(ud); return; failed: - cb(err, NULL); + ud->cb(err, NULL); + g_free(ud); } static void load_link_keys(GSList *keys, bt_bluetooth_ready cb) { struct mgmt_cp_load_link_keys *cp; struct mgmt_link_key_info *key; + struct load_link_keys_userdata *req_ud; size_t key_count, cp_size; unsigned int id; @@ -2578,13 +2586,18 @@ static void load_link_keys(GSList *keys, bt_bluetooth_ready cb) for (key = cp->keys; keys != NULL; keys = g_slist_next(keys), key++) memcpy(key, keys->data, sizeof(*key)); + req_ud = g_malloc0(sizeof(*req_ud)); + req_ud->cb = cb; + req_ud->key_count = key_count; + id = mgmt_send(mgmt_if, MGMT_OP_LOAD_LINK_KEYS, adapter.index, - cp_size, cp, load_link_keys_complete, cb, NULL); + cp_size, cp, load_link_keys_complete, req_ud, NULL); g_free(cp); if (id == 0) { error("Failed to load link keys"); + g_free(req_ud); cb(-EIO, NULL); } } -- To unsubscribe from this list: send the line "unsubscribe linux-bluetooth" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html