Keep sec_dev_rec in list instead of static array

This reduces the computational complexity of most BLE operations.

Change-Id: Ife35a50d9ef3467abdc5259c2712bf5d85b8f909
diff --git a/stack/btm/btm_ble_privacy.c b/stack/btm/btm_ble_privacy.c
index df9e23e..e613ffb 100644
--- a/stack/btm/btm_ble_privacy.c
+++ b/stack/btm/btm_ble_privacy.c
@@ -214,6 +214,13 @@
     }
 }
 
+bool clear_resolving_list_bit(void *data, void *context)
+{
+    tBTM_SEC_DEV_REC *p_dev_rec = data;
+    p_dev_rec->ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT;
+    return true;
+}
+
 /*******************************************************************************
 **
 ** Function         btm_ble_clear_resolving_list_complete
@@ -256,8 +263,7 @@
         BTM_TRACE_DEBUG("%s resolving_list_avail_size=%d",
                         __func__, btm_cb.ble_ctr_cb.resolving_list_avail_size);
 
-        for (UINT8 i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; ++i)
-            btm_cb.sec_dev_rec[i].ble.in_controller_list &= ~BTM_RESOLVING_LIST_BIT;
+        list_foreach(btm_cb.sec_dev_rec, clear_resolving_list_bit, NULL);
     }
 }
 
@@ -769,7 +775,6 @@
 
     /* only add RPA enabled device into resolving list */
     if (p_dev_rec != NULL && /* RPA is being used and PID is known */
-       (p_dev_rec->sec_flags & BTM_SEC_IN_USE) != 0 &&
        ((p_dev_rec->ble.key_type & BTM_LE_KEY_PID) != 0 ||
        (p_dev_rec->ble.key_type & BTM_LE_KEY_LID) != 0))
     {
@@ -922,6 +927,18 @@
             btm_cb.ble_ctr_cb.resolving_list_avail_size);
 }
 
+
+bool is_on_resolving_list(void *data, void *context)
+{
+    tBTM_SEC_DEV_REC *p_dev = data;
+    if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) &&
+        (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT))
+        return false;
+
+    return true;
+}
+
+
 /*******************************************************************************
 **
 ** Function         btm_ble_enable_resolving_list_for_platform
@@ -949,17 +966,11 @@
         return;
     }
 
-    tBTM_SEC_DEV_REC *p_dev = &btm_cb.sec_dev_rec[0];
-    for (UINT8 i = 0; i < BTM_SEC_MAX_DEVICE_RECORDS; i ++, p_dev ++)
-    {
-        if ((p_dev->ble.in_controller_list & BTM_RESOLVING_LIST_BIT) &&
-            (p_dev->ble.in_controller_list & BTM_WHITE_LIST_BIT))
-        {
-            btm_ble_enable_resolving_list(rl_mask);
-            return;
-        }
-    }
-    btm_ble_disable_resolving_list(rl_mask, TRUE);
+    list_node_t *n = list_foreach(btm_cb.sec_dev_rec, is_on_resolving_list, NULL);
+    if (n)
+        btm_ble_enable_resolving_list(rl_mask);
+    else
+        btm_ble_disable_resolving_list(rl_mask, TRUE);
 }
 
 /*******************************************************************************