mirror of
https://github.com/espressif/esp-idf.git
synced 2026-10-02 03:00:34 +03:00
feat(ble/bluedroid): Support bluedroid dual identity
This commit is contained in:
@@ -36,7 +36,7 @@
|
||||
#include "stack/hcidefs.h"
|
||||
#include "stack/l2c_api.h"
|
||||
|
||||
static tBTM_SEC_DEV_REC *btm_find_oldest_dev (void);
|
||||
static tBTM_SEC_DEV_REC *btm_find_oldest_dev_ex (tBTM_SEC_DEV_REC *exclude_rec);
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
@@ -330,6 +330,22 @@ BOOLEAN btm_find_sec_dev_in_list (void *p_node_data, void *context)
|
||||
**
|
||||
*******************************************************************************/
|
||||
tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
|
||||
{
|
||||
return btm_sec_alloc_dev_ex(bd_addr, NULL);
|
||||
}
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_sec_alloc_dev_ex
|
||||
**
|
||||
** Description Same as btm_sec_alloc_dev(), but exclude_rec will never be
|
||||
** recycled when the device table is full and an existing entry
|
||||
** must be reused.
|
||||
**
|
||||
** Returns Pointer to the record or NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
tBTM_SEC_DEV_REC *btm_sec_alloc_dev_ex (BD_ADDR bd_addr, tBTM_SEC_DEV_REC *exclude_rec)
|
||||
{
|
||||
tBTM_SEC_DEV_REC *p_dev_rec = NULL;
|
||||
tBTM_SEC_DEV_REC *p_dev_new_rec = NULL;
|
||||
@@ -339,7 +355,7 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
|
||||
BOOLEAN new_entry_found = FALSE;
|
||||
BOOLEAN old_entry_found = FALSE;
|
||||
BOOLEAN malloc_new_entry = FALSE;
|
||||
BTM_TRACE_EVENT ("btm_sec_alloc_dev - start alloc for device %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
BTM_TRACE_EVENT ("btm_sec_alloc_dev_ex - start alloc for device %02x:%02x:%02x:%02x:%02x:%02x",
|
||||
bd_addr[0], bd_addr[1], bd_addr[2], bd_addr[3], bd_addr[4], bd_addr[5]);
|
||||
for (p_node = list_begin(btm_cb.p_sec_dev_rec_list); p_node; p_node = list_next(p_node)) {
|
||||
p_dev_old_rec = list_node(p_node);
|
||||
@@ -374,13 +390,16 @@ tBTM_SEC_DEV_REC *btm_sec_alloc_dev (BD_ADDR bd_addr)
|
||||
}
|
||||
}
|
||||
if (!new_entry_found) {
|
||||
p_dev_rec = btm_find_oldest_dev();
|
||||
p_dev_rec = btm_find_oldest_dev_ex(exclude_rec);
|
||||
#if (BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE)
|
||||
// If device record exists and contains identity key, remove it from resolving list
|
||||
if (p_dev_rec && (p_dev_rec->ble.key_type & SMP_SEC_KEY_TYPE_ID)) {
|
||||
btm_ble_resolving_list_remove_dev(p_dev_rec);
|
||||
}
|
||||
#endif // (BLE_INCLUDED == TRUE) && (SMP_INCLUDED == TRUE)
|
||||
if (p_dev_rec == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
} else {
|
||||
/* if the old device entry not present go with new entry */
|
||||
if (old_entry_found) {
|
||||
@@ -654,16 +673,17 @@ tBTM_SEC_DEV_REC *btm_find_or_alloc_dev (BD_ADDR bd_addr)
|
||||
|
||||
/*******************************************************************************
|
||||
**
|
||||
** Function btm_find_oldest_dev
|
||||
** Function btm_find_oldest_dev_ex
|
||||
**
|
||||
** Description Locates the oldest device in use. It first looks for
|
||||
** the oldest non-paired device. If all devices are paired it
|
||||
** deletes the oldest paired device.
|
||||
** deletes the oldest paired device. exclude_rec is never
|
||||
** returned when non-NULL.
|
||||
**
|
||||
** Returns Pointer to the record or NULL
|
||||
**
|
||||
*******************************************************************************/
|
||||
tBTM_SEC_DEV_REC *btm_find_oldest_dev (void)
|
||||
static tBTM_SEC_DEV_REC *btm_find_oldest_dev_ex (tBTM_SEC_DEV_REC *exclude_rec)
|
||||
{
|
||||
tBTM_SEC_DEV_REC *p_dev_rec = NULL;
|
||||
tBTM_SEC_DEV_REC *p_oldest = NULL;
|
||||
@@ -673,6 +693,9 @@ tBTM_SEC_DEV_REC *btm_find_oldest_dev (void)
|
||||
/* First look for the non-paired devices for the oldest entry */
|
||||
for (p_node = list_begin(btm_cb.p_sec_dev_rec_list); p_node; p_node = list_next(p_node)) {
|
||||
p_dev_rec = list_node(p_node);
|
||||
if (p_dev_rec == exclude_rec) {
|
||||
continue;
|
||||
}
|
||||
if (((p_dev_rec->sec_flags & BTM_SEC_IN_USE) == 0)
|
||||
|| ((p_dev_rec->sec_flags & (BTM_SEC_LINK_KEY_KNOWN | BTM_SEC_LE_LINK_KEY_KNOWN)) != 0)) {
|
||||
continue; /* Device is paired so skip it */
|
||||
@@ -689,8 +712,12 @@ tBTM_SEC_DEV_REC *btm_find_oldest_dev (void)
|
||||
}
|
||||
|
||||
/* All devices are paired; find the oldest */
|
||||
old_ts = 0xFFFFFFFF;
|
||||
for (p_node = list_begin(btm_cb.p_sec_dev_rec_list); p_node; p_node = list_next(p_node)) {
|
||||
p_dev_rec = list_node(p_node);
|
||||
if (p_dev_rec == exclude_rec) {
|
||||
continue;
|
||||
}
|
||||
if ((p_dev_rec->sec_flags & BTM_SEC_IN_USE) == 0) {
|
||||
continue;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user