Diff between 7e0bc2f00da124f27215b7e94fb2a9e288fbabb9 and 21bf46e1684975f666eaf91f71e55ef8d4c17bb2

Changed Files

File Additions Deletions Status
android/adapter.c +24 -9 modified

Full Patch

diff --git a/android/adapter.c b/android/adapter.c
index 4b4905b..d55a070 100644
--- a/android/adapter.c
+++ b/android/adapter.c
@@ -290,22 +290,37 @@ failed:
 static void load_link_keys(GSList *keys)
 {
 	struct mgmt_cp_load_link_keys *cp;
-	size_t key_len = g_slist_length(keys);
 	struct mgmt_link_key_info *key;
-	size_t len;
+	size_t key_count, cp_size;
+	unsigned int id;
 
-	DBG("");
+	key_count = g_slist_length(keys);
+
+	DBG("keys %zu ", key_count);
+
+	cp_size = sizeof(*cp) + (key_count * sizeof(*key));
+
+	cp = g_malloc0(cp_size);
 
-	len = sizeof(*cp) + key_len * sizeof(*key);
-	cp = g_malloc0(len);
+	/*
+	 * Even if the list of stored keys is empty, it is important to
+	 * load an empty list into the kernel. That way it is ensured
+	 * that no old keys from a previous daemon are present.
+	 */
+	cp->key_count = htobs(key_count);
 
-	cp->debug_keys = 0;
-	cp->key_count = htobs(key_len);
+	for (key = cp->keys; keys != NULL; keys = g_slist_next(keys), key++)
+		memcpy(key, keys->data, sizeof(*key));
 
-	mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, adapter->index, len,
-				cp, load_link_keys_complete, NULL, NULL);
+	id = mgmt_send(adapter->mgmt, MGMT_OP_LOAD_LINK_KEYS, adapter->index,
+			cp_size, cp, load_link_keys_complete, NULL, NULL);
 
 	g_free(cp);
+
+	if (id == 0) {
+		error("Failed to load link keys");
+		adapter->ready(-EIO);
+	}
 }
 
 static void set_mode_complete(uint8_t status, uint16_t length,