1 /******************************************************************************
2  *
3  *  Copyright 1999-2012 Broadcom Corporation
4  *
5  *  Licensed under the Apache License, Version 2.0 (the "License");
6  *  you may not use this file except in compliance with the License.
7  *  You may obtain a copy of the License at:
8  *
9  *  http://www.apache.org/licenses/LICENSE-2.0
10  *
11  *  Unless required by applicable law or agreed to in writing, software
12  *  distributed under the License is distributed on an "AS IS" BASIS,
13  *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  *  See the License for the specific language governing permissions and
15  *  limitations under the License.
16  *
17  ******************************************************************************/
18 
19 /******************************************************************************
20  *
21  *  This file contains functions for BLE acceptlist operation.
22  *
23  ******************************************************************************/
24 
25 #include <base/bind.h>
26 #include <cstdint>
27 #include <unordered_map>
28 
29 #include "device/include/controller.h"
30 #include "main/shim/acl_api.h"
31 #include "main/shim/shim.h"
32 #include "stack/btm/btm_dev.h"
33 #include "stack/btm/btm_int_types.h"
34 #include "stack/btm/security_device_record.h"
35 #include "stack/include/bt_types.h"
36 #include "stack/include/hcimsgs.h"
37 #include "types/raw_address.h"
38 
39 extern tBTM_CB btm_cb;
40 
41 extern void btm_send_hci_create_connection(
42     uint16_t scan_int, uint16_t scan_win, uint8_t init_filter_policy,
43     uint8_t addr_type_peer, const RawAddress& bda_peer, uint8_t addr_type_own,
44     uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency,
45     uint16_t conn_timeout, uint16_t min_ce_len, uint16_t max_ce_len,
46     uint8_t phy);
47 extern void btm_ble_create_conn_cancel();
48 
49 namespace {
50 
51 constexpr char kAcceptlistAdd[] = "AcceptlistAdd";
52 constexpr char kAcceptlistRemove[] = "AcceptlistRemove";
53 constexpr char kAcceptlistClear[] = "AcceptlistClear";
54 
55 }  // namespace
56 
57 // Unfortunately (for now?) we have to maintain a copy of the device acceptlist
58 // on the host to determine if a device is pending to be connected or not. This
59 // controls whether the host should keep trying to scan for acceptlisted
60 // peripherals or not.
61 // TODO: Move all of this to controller/le/background_list or similar?
62 struct BackgroundConnection {
63   RawAddress address;
64   uint8_t addr_type;
65   bool in_controller_wl;
66   uint8_t addr_type_in_wl;
67   bool pending_removal;
68 };
69 
70 struct BgConnHash {
operator ()BgConnHash71   std::size_t operator()(const RawAddress& x) const {
72     const uint8_t* a = x.address;
73     return a[0] ^ (a[1] << 8) ^ (a[2] << 16) ^ (a[3] << 24) ^ a[4] ^
74            (a[5] << 8);
75   }
76 };
77 
78 static std::unordered_map<RawAddress, BackgroundConnection, BgConnHash>
79     background_connections;
80 
acceptlist_command_complete(tHCI_STATUS status,const char * msg)81 static void acceptlist_command_complete(tHCI_STATUS status, const char* msg) {
82   switch (status) {
83     case HCI_SUCCESS:
84       return;
85     default:
86       LOG_WARN(
87           "Received unexpected accept list completion command:%s status:%s",
88           msg, hci_error_code_text(status).c_str());
89   }
90 }
91 
acceptlist_add_command_complete(uint8_t * p_data,uint16_t evt_len)92 static void acceptlist_add_command_complete(uint8_t* p_data, uint16_t evt_len) {
93   if (evt_len < sizeof(uint8_t)) {
94     LOG_ERROR("Received bogus acceptlist add complete length:%hu", evt_len);
95     return;
96   }
97   uint8_t status;
98   STREAM_TO_UINT8(status, p_data);
99   acceptlist_command_complete(static_cast<tHCI_STATUS>(status), kAcceptlistAdd);
100 }
101 
acceptlist_remove_command_complete(uint8_t * p_data,uint16_t evt_len)102 static void acceptlist_remove_command_complete(uint8_t* p_data,
103                                                uint16_t evt_len) {
104   if (evt_len < sizeof(uint8_t)) {
105     LOG_ERROR("Received bogus acceptlist remove complete length:%hu", evt_len);
106     return;
107   }
108   uint8_t status;
109   STREAM_TO_UINT8(status, p_data);
110   acceptlist_command_complete(static_cast<tHCI_STATUS>(status),
111                               kAcceptlistRemove);
112 }
113 
acceptlist_clear_command_complete(uint8_t * p_data,uint16_t evt_len)114 static void acceptlist_clear_command_complete(uint8_t* p_data,
115                                               uint16_t evt_len) {
116   if (evt_len < sizeof(uint8_t)) {
117     LOG_ERROR("Received bogus acceptlist remove complete length:%hu", evt_len);
118     return;
119   }
120   uint8_t status;
121   STREAM_TO_UINT8(status, p_data);
122   acceptlist_command_complete(static_cast<tHCI_STATUS>(status),
123                               kAcceptlistClear);
124 }
125 
126 /** This function is to stop auto connection procedure */
btm_ble_stop_auto_conn()127 static bool btm_ble_stop_auto_conn() {
128   BTM_TRACE_EVENT("%s", __func__);
129 
130   if (!btm_cb.ble_ctr_cb.is_connection_state_connecting()) {
131     LOG_DEBUG(
132         "No need to stop auto connection procedure that is not connecting");
133     return false;
134   }
135 
136   btm_ble_create_conn_cancel();
137 
138   btm_cb.ble_ctr_cb.reset_acceptlist_process_in_progress();
139   return true;
140 }
141 
background_connection_add(uint8_t addr_type,const RawAddress & address)142 static void background_connection_add(uint8_t addr_type,
143                                       const RawAddress& address) {
144   auto map_iter = background_connections.find(address);
145   if (map_iter == background_connections.end()) {
146     background_connections[address] =
147         BackgroundConnection{address, addr_type, false, 0, false};
148   } else {
149     BackgroundConnection* connection = &map_iter->second;
150     if (addr_type != connection->addr_type) {
151       LOG(INFO) << __func__ << " Addr type mismatch " << address;
152       btsnd_hcic_ble_remove_from_acceptlist(
153           connection->addr_type_in_wl, connection->address,
154           base::Bind(&acceptlist_remove_command_complete));
155       connection->addr_type = addr_type;
156       connection->in_controller_wl = false;
157     }
158     connection->pending_removal = false;
159   }
160 }
161 
background_connection_remove(const RawAddress & address)162 static void background_connection_remove(const RawAddress& address) {
163   auto map_iter = background_connections.find(address);
164   if (map_iter != background_connections.end()) {
165     if (map_iter->second.in_controller_wl) {
166       map_iter->second.pending_removal = true;
167     } else {
168       background_connections.erase(map_iter);
169     }
170   }
171 }
172 
background_connections_clear()173 static void background_connections_clear() { background_connections.clear(); }
174 
background_connections_pending()175 static bool background_connections_pending() {
176   for (auto& map_el : background_connections) {
177     BackgroundConnection* connection = &map_el.second;
178     if (connection->pending_removal) continue;
179     const bool connected =
180         BTM_IsAclConnectionUp(connection->address, BT_TRANSPORT_LE);
181     if (!connected) {
182       return true;
183     }
184   }
185   return false;
186 }
187 
background_connections_count()188 static int background_connections_count() {
189   int count = 0;
190   for (auto& map_el : background_connections) {
191     if (!map_el.second.pending_removal) ++count;
192   }
193   return count;
194 }
195 
convert_to_address_with_type(const RawAddress & bd_addr,const tBTM_SEC_DEV_REC * p_dev_rec)196 const tBLE_BD_ADDR convert_to_address_with_type(
197     const RawAddress& bd_addr, const tBTM_SEC_DEV_REC* p_dev_rec) {
198   if (p_dev_rec == nullptr || !p_dev_rec->is_device_type_has_ble()) {
199     return {
200         .type = BLE_ADDR_PUBLIC,
201         .bda = bd_addr,
202     };
203   }
204 
205   if (p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
206     return {
207         .type = p_dev_rec->ble.ble_addr_type,
208         .bda = bd_addr,
209     };
210   } else {
211     return p_dev_rec->ble.identity_address_with_type;
212   }
213 }
214 
215 /*******************************************************************************
216  *
217  * Function         btm_add_dev_to_controller
218  *
219  * Description      This function load the device into controller acceptlist
220  ******************************************************************************/
btm_add_dev_to_controller(bool to_add,const RawAddress & bd_addr)221 static bool btm_add_dev_to_controller(bool to_add, const RawAddress& bd_addr) {
222   tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
223 
224   if (p_dev_rec != NULL && p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) {
225     if (to_add) {
226       if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
227         LOG_DEBUG(
228             "Adding known device record into acceptlist with identity "
229             "device:%s",
230             PRIVATE_ADDRESS(p_dev_rec->ble.identity_address_with_type));
231         background_connection_add(
232             p_dev_rec->ble.identity_address_with_type.type,
233             p_dev_rec->ble.identity_address_with_type.bda);
234       } else {
235         LOG_DEBUG(
236             "Adding known device record into acceptlist without identity "
237             "device:%s",
238             PRIVATE_ADDRESS(bd_addr));
239         background_connection_add(p_dev_rec->ble.ble_addr_type, bd_addr);
240 
241         if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM &&
242             BTM_BLE_IS_RESOLVE_BDA(bd_addr)) {
243           LOG(INFO) << __func__ << " adding RPA into acceptlist";
244         }
245       }
246 
247       p_dev_rec->ble.in_controller_list |= BTM_ACCEPTLIST_BIT;
248     } else {
249       if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
250         LOG_DEBUG(
251             "Removing known device record into acceptlist with identity "
252             "device:%s",
253             PRIVATE_ADDRESS(p_dev_rec->ble.identity_address_with_type));
254         background_connection_remove(
255             p_dev_rec->ble.identity_address_with_type.bda);
256       } else {
257         LOG_DEBUG(
258             "Removing known device record into acceptlist without identity "
259             "device:%s",
260             PRIVATE_ADDRESS(bd_addr));
261         background_connection_remove(bd_addr);
262 
263         if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM &&
264             BTM_BLE_IS_RESOLVE_BDA(bd_addr)) {
265           LOG(INFO) << __func__ << " removing RPA from acceptlist";
266         }
267       }
268 
269       p_dev_rec->ble.in_controller_list &= ~BTM_ACCEPTLIST_BIT;
270     }
271   } else {
272     /* not a known device, i.e. attempt to connect to device never seen before
273      */
274     if (to_add) {
275       background_connection_add(BLE_ADDR_PUBLIC, bd_addr);
276     } else {
277       background_connection_remove(bd_addr);
278     }
279   }
280 
281   return true;
282 }
283 
284 /*******************************************************************************
285  *
286  * Function         btm_execute_wl_dev_operation
287  *
288  * Description      execute the pending acceptlist device operation (loading or
289  *                                                                  removing)
290  ******************************************************************************/
btm_execute_wl_dev_operation(void)291 static bool btm_execute_wl_dev_operation(void) {
292   // handle removals first to avoid filling up controller's acceptlist
293   for (auto map_it = background_connections.begin();
294        map_it != background_connections.end();) {
295     BackgroundConnection* connection = &map_it->second;
296     if (connection->pending_removal) {
297       btsnd_hcic_ble_remove_from_acceptlist(
298           connection->addr_type_in_wl, connection->address,
299           base::BindOnce(&acceptlist_remove_command_complete));
300       map_it = background_connections.erase(map_it);
301     } else
302       ++map_it;
303   }
304   for (auto& map_el : background_connections) {
305     BackgroundConnection* connection = &map_el.second;
306     const bool connected =
307         BTM_IsAclConnectionUp(connection->address, BT_TRANSPORT_LE);
308     if (!connection->in_controller_wl && !connected) {
309       btsnd_hcic_ble_add_acceptlist(
310           connection->addr_type, connection->address,
311           base::BindOnce(&acceptlist_add_command_complete));
312       connection->in_controller_wl = true;
313       connection->addr_type_in_wl = connection->addr_type;
314     } else if (connection->in_controller_wl && connected) {
315       /* Bluetooth Core 4.2 as well as ESR08 disallows more than one
316          connection between two LE addresses. Not all controllers handle this
317          correctly, therefore we must make sure connected devices are not in
318          the acceptlist when bg connection attempt is active. */
319       btsnd_hcic_ble_remove_from_acceptlist(
320           connection->addr_type_in_wl, connection->address,
321           base::BindOnce(&acceptlist_remove_command_complete));
322       connection->in_controller_wl = false;
323     }
324   }
325   return true;
326 }
327 
328 /** This function is to start auto connection procedure */
btm_ble_start_auto_conn()329 static bool btm_ble_start_auto_conn() {
330   tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
331   ASSERT(p_cb != nullptr);
332 
333   const uint16_t scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF)
334                                 ? BTM_BLE_SCAN_SLOW_INT_1
335                                 : p_cb->scan_int;
336   const uint16_t scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF)
337                                 ? BTM_BLE_SCAN_SLOW_WIN_1
338                                 : p_cb->scan_win;
339   uint8_t own_addr_type = p_cb->addr_mgnt_cb.own_addr_type;
340   uint8_t peer_addr_type = BLE_ADDR_PUBLIC;
341 
342   uint8_t phy = PHY_LE_1M;
343   if (controller_get_interface()->supports_ble_2m_phy()) phy |= PHY_LE_2M;
344   if (controller_get_interface()->supports_ble_coded_phy()) phy |= PHY_LE_CODED;
345 
346   if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) {
347     LOG_INFO(
348         "Unable to initiate background connection due to topology limitation");
349     return false;
350   }
351 
352   if (!btm_cb.ble_ctr_cb.is_connection_state_idle() ||
353       !background_connections_pending()) {
354     LOG_DEBUG(
355         "Connection state not idle or already have background connection "
356         "pending");
357     return false;
358   }
359 
360   p_cb->wl_state |= BTM_BLE_ACCEPTLIST_INIT;
361 
362   btm_execute_wl_dev_operation();
363 
364   btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_INIT);
365   if (btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE &&
366       controller_get_interface()->supports_ble_privacy()) {
367     own_addr_type |= BLE_ADDR_TYPE_ID_BIT;
368     peer_addr_type |= BLE_ADDR_TYPE_ID_BIT;
369   }
370 
371   btm_send_hci_create_connection(
372       scan_int,                       /* uint16_t scan_int      */
373       scan_win,                       /* uint16_t scan_win      */
374       0x01,                           /* uint8_t acceptlist     */
375       peer_addr_type,                 /* uint8_t addr_type_peer */
376       RawAddress::kEmpty,             /* BD_ADDR bda_peer     */
377       own_addr_type,                  /* uint8_t addr_type_own */
378       BTM_BLE_CONN_INT_MIN_DEF,       /* uint16_t conn_int_min  */
379       BTM_BLE_CONN_INT_MAX_DEF,       /* uint16_t conn_int_max  */
380       BTM_BLE_CONN_PERIPHERAL_LATENCY_DEF, /* uint16_t conn_latency  */
381       BTM_BLE_CONN_TIMEOUT_DEF,       /* uint16_t conn_timeout  */
382       0,                              /* uint16_t min_len       */
383       0,                              /* uint16_t max_len       */
384       phy);
385   return true;
386 }
387 
388 /*******************************************************************************
389  *
390  * Function         btm_update_scanner_filter_policy
391  *
392  * Description      This function updates the filter policy of scanner
393  ******************************************************************************/
btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy)394 void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) {
395   tBTM_BLE_INQ_CB* p_inq = &btm_cb.ble_ctr_cb.inq_var;
396 
397   uint32_t scan_interval =
398       !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval;
399   uint32_t scan_window =
400       !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window;
401 
402   BTM_TRACE_EVENT("%s", __func__);
403 
404   p_inq->sfp = scan_policy;
405   p_inq->scan_type = p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE
406                          ? BTM_BLE_SCAN_MODE_ACTI
407                          : p_inq->scan_type;
408 
409   btm_send_hci_set_scan_params(
410       p_inq->scan_type, (uint16_t)scan_interval, (uint16_t)scan_window,
411       btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, scan_policy);
412 }
413 
414 /*******************************************************************************
415  *
416  * Function         btm_ble_bgconn_cancel_if_disconnected
417  *
418  * Description      If a device has been disconnected, it must be re-added to
419  *                  the acceptlist. If needed, this function cancels a pending
420  *                  initiate command in order to trigger restart of the initiate
421  *                  command which in turn updates the acceptlist.
422  *
423  * Parameters       bd_addr: updated device
424  *
425  ******************************************************************************/
btm_ble_bgconn_cancel_if_disconnected(const RawAddress & bd_addr)426 void btm_ble_bgconn_cancel_if_disconnected(const RawAddress& bd_addr) {
427   if (!btm_cb.ble_ctr_cb.is_connection_state_connecting()) return;
428 
429   auto map_it = background_connections.find(bd_addr);
430   if (map_it != background_connections.end()) {
431     BackgroundConnection* connection = &map_it->second;
432     if (!connection->in_controller_wl && !connection->pending_removal &&
433         !BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
434       btm_ble_stop_auto_conn();
435     }
436   }
437 }
438 
439 /*******************************************************************************
440  *
441  * Function         btm_ble_suspend_bg_conn
442  *
443  * Description      This function is to suspend an active background connection
444  *                  procedure.
445  *
446  * Parameters       none.
447  *
448  * Returns          none.
449  *
450  ******************************************************************************/
btm_ble_suspend_bg_conn(void)451 bool btm_ble_suspend_bg_conn(void) {
452   if (bluetooth::shim::is_gd_acl_enabled()) {
453     LOG_DEBUG("Gd acl_manager handles sync of background connections");
454     return true;
455   }
456   return btm_ble_stop_auto_conn();
457 }
458 
459 /*******************************************************************************
460  *
461  * Function         btm_ble_resume_bg_conn
462  *
463  * Description      This function is to resume a background auto connection
464  *                  procedure.
465  *
466  * Parameters       none.
467  *
468  * Returns          none.
469  *
470  ******************************************************************************/
btm_ble_resume_bg_conn(void)471 bool btm_ble_resume_bg_conn(void) {
472   if (bluetooth::shim::is_gd_acl_enabled()) {
473     LOG_DEBUG("Gd acl_manager handles sync of background connections");
474     return true;
475   }
476   return btm_ble_start_auto_conn();
477 }
478 
BTM_BackgroundConnectAddressKnown(const RawAddress & address)479 bool BTM_BackgroundConnectAddressKnown(const RawAddress& address) {
480   tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address);
481 
482   //  not a known device, or a classic device, we assume public address
483   if (p_dev_rec == NULL || (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == 0)
484     return true;
485 
486   // bonded device with identity address known
487   if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
488     return true;
489   }
490 
491   // Public address, Random Static, or Random Non-Resolvable Address known
492   if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC ||
493       !BTM_BLE_IS_RESOLVE_BDA(address)) {
494     return true;
495   }
496 
497   // Only Resolvable Private Address (RPA) is known, we don't allow it into
498   // the background connection procedure.
499   return false;
500 }
501 
BTM_SetLeConnectionModeToFast()502 bool BTM_SetLeConnectionModeToFast() {
503   VLOG(2) << __func__;
504   tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
505   if ((p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF &&
506        p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ||
507       (p_cb->scan_int == BTM_BLE_SCAN_SLOW_INT_1 &&
508        p_cb->scan_win == BTM_BLE_SCAN_SLOW_WIN_1)) {
509     p_cb->scan_int = BTM_BLE_SCAN_FAST_INT;
510     p_cb->scan_win = BTM_BLE_SCAN_FAST_WIN;
511     return true;
512   }
513   return false;
514 }
515 
BTM_SetLeConnectionModeToSlow()516 void BTM_SetLeConnectionModeToSlow() {
517   VLOG(2) << __func__;
518   tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
519   if ((p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF &&
520        p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ||
521       (p_cb->scan_int == BTM_BLE_SCAN_FAST_INT &&
522        p_cb->scan_win == BTM_BLE_SCAN_FAST_WIN)) {
523     p_cb->scan_int = BTM_BLE_SCAN_SLOW_INT_1;
524     p_cb->scan_win = BTM_BLE_SCAN_SLOW_WIN_1;
525   }
526 }
527 
528 /** Adds the device into acceptlist. Returns false if acceptlist is full and
529  * device can't be added, true otherwise. */
BTM_AcceptlistAdd(const RawAddress & address)530 bool BTM_AcceptlistAdd(const RawAddress& address) {
531   if (!controller_get_interface()->supports_ble()) {
532     LOG_WARN("Controller does not support Le");
533     return false;
534   }
535 
536   if (bluetooth::shim::is_gd_acl_enabled()) {
537     if (acl_check_and_clear_ignore_auto_connect_after_disconnect(address)) {
538       LOG_WARN(
539           "Unexpectedly found device address already in ignore auto connect "
540           "device:%s",
541           PRIVATE_ADDRESS(address));
542     }
543     return bluetooth::shim::ACL_AcceptLeConnectionFrom(
544         convert_to_address_with_type(address, btm_find_dev(address)),
545         /* is_direct */ false);
546   }
547 
548   if (background_connections_count() ==
549       controller_get_interface()->get_ble_acceptlist_size()) {
550     LOG_ERROR("Unable to add device to acceptlist since it is full");
551     return false;
552   }
553 
554   if (btm_cb.ble_ctr_cb.wl_state & BTM_BLE_ACCEPTLIST_INIT) {
555     btm_ble_stop_auto_conn();
556   }
557   btm_add_dev_to_controller(true, address);
558   btm_ble_resume_bg_conn();
559   LOG_DEBUG("Added to Le acceptlist device:%s", PRIVATE_ADDRESS(address));
560   return true;
561 }
562 
563 /** Removes the device from acceptlist */
BTM_AcceptlistRemove(const RawAddress & address)564 void BTM_AcceptlistRemove(const RawAddress& address) {
565   if (!controller_get_interface()->supports_ble()) {
566     LOG_WARN("Controller does not support Le");
567     return;
568   }
569 
570   if (bluetooth::shim::is_gd_acl_enabled()) {
571     bluetooth::shim::ACL_IgnoreLeConnectionFrom(
572         convert_to_address_with_type(address, btm_find_dev(address)));
573     return;
574   }
575 
576   if (btm_cb.ble_ctr_cb.wl_state & BTM_BLE_ACCEPTLIST_INIT) {
577     btm_ble_stop_auto_conn();
578   }
579   btm_add_dev_to_controller(false, address);
580   btm_ble_resume_bg_conn();
581   LOG_DEBUG("Removed from Le acceptlist device:%s", PRIVATE_ADDRESS(address));
582 }
583 
584 /** Clear the acceptlist, end any pending acceptlist connections */
BTM_AcceptlistClear()585 void BTM_AcceptlistClear() {
586   if (!controller_get_interface()->supports_ble()) {
587     LOG_WARN("Controller does not support Le");
588     return;
589   }
590 
591   if (bluetooth::shim::is_gd_acl_enabled()) {
592     acl_clear_all_ignore_auto_connect_after_disconnect();
593     bluetooth::shim::ACL_IgnoreAllLeConnections();
594     return;
595   }
596 
597   btm_ble_stop_auto_conn();
598   btsnd_hcic_ble_clear_acceptlist(
599       base::BindOnce(&acceptlist_clear_command_complete));
600   background_connections_clear();
601   LOG_DEBUG("Cleared Le acceptlist");
602 }
603