Skip to content

Commit 0cd97ce

Browse files
committed
Merge branch 'bugfix/btdm_error_when_add_device_to_whitelist_twice' into 'master'
component/bt: Fix bug when add device to whitelist twice See merge request !1700
2 parents f61dcf4 + e55b543 commit 0cd97ce

File tree

1 file changed

+25
-9
lines changed

1 file changed

+25
-9
lines changed

components/bt/bluedroid/stack/btm/btm_ble_bgconn.c

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ static void background_connections_lazy_init()
6969
}
7070
}
7171

72-
static void background_connection_add(bt_bdaddr_t *address)
72+
static BOOLEAN background_connection_add(bt_bdaddr_t *address)
7373
{
7474
assert(address);
7575
background_connections_lazy_init();
@@ -78,14 +78,17 @@ static void background_connection_add(bt_bdaddr_t *address)
7878
connection = osi_calloc(sizeof(background_connection_t));
7979
connection->address = *address;
8080
hash_map_set(background_connections, &(connection->address), connection);
81+
return TRUE;
8182
}
83+
return FALSE;
8284
}
8385

84-
static void background_connection_remove(bt_bdaddr_t *address)
86+
static BOOLEAN background_connection_remove(bt_bdaddr_t *address)
8587
{
8688
if (address && background_connections) {
87-
hash_map_erase(background_connections, address);
89+
return hash_map_erase(background_connections, address);
8890
}
91+
return FALSE;
8992
}
9093

9194
static void background_connections_clear()
@@ -265,17 +268,30 @@ BOOLEAN btm_update_dev_to_white_list(BOOLEAN to_add, BD_ADDR bd_addr, tBTM_ADD_W
265268
}
266269
return FALSE;
267270
}
268-
if (add_wl_cb){
269-
//save add whitelist complete callback
270-
p_cb->add_wl_cb = add_wl_cb;
271-
}
272271

273272
if (to_add) {
274273
/* added the bd_addr to the connection hash map queue */
275-
background_connection_add((bt_bdaddr_t *)bd_addr);
274+
if(!background_connection_add((bt_bdaddr_t *)bd_addr)) {
275+
/* if the bd_addr already exist in whitelist, just callback return TRUE */
276+
if (add_wl_cb){
277+
add_wl_cb(HCI_SUCCESS,to_add);
278+
}
279+
return TRUE;
280+
}
276281
} else {
277282
/* remove the bd_addr to the connection hash map queue */
278-
background_connection_remove((bt_bdaddr_t *)bd_addr);
283+
if(!background_connection_remove((bt_bdaddr_t *)bd_addr)){
284+
/* if the bd_addr don't exist in whitelist, just callback return TRUE */
285+
if (add_wl_cb){
286+
add_wl_cb(HCI_SUCCESS,to_add);
287+
}
288+
return TRUE;
289+
}
290+
}
291+
292+
if (add_wl_cb){
293+
//save add whitelist complete callback
294+
p_cb->add_wl_cb = add_wl_cb;
279295
}
280296
/* stop the auto connect */
281297
btm_suspend_wl_activity(p_cb->wl_state);

0 commit comments

Comments
 (0)