OSDN Git Service

android: Make load_link_keys function load keys
authorSzymon Janc <szymon.janc@gmail.com>
Thu, 31 Oct 2013 02:55:44 +0000 (02:55 +0000)
committerJohan Hedberg <johan.hedberg@intel.com>
Thu, 31 Oct 2013 08:46:56 +0000 (10:46 +0200)
GSlist passed is expected to hold mgmt_link_key_info structures.

android/adapter.c

index 4b4905b..d55a070 100644 (file)
@@ -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,