aboutsummaryrefslogtreecommitdiff
path: root/stack/btm/btm_ble_bgconn.cc
blob: 80ba1cd045f3e358395eb6c516ca9ee8fe40bf6a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
/******************************************************************************
 *
 *  Copyright 1999-2012 Broadcom Corporation
 *
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at:
 *
 *  http://www.apache.org/licenses/LICENSE-2.0
 *
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 *
 ******************************************************************************/

/******************************************************************************
 *
 *  This file contains functions for BLE acceptlist operation.
 *
 ******************************************************************************/

#include <base/bind.h>
#include <base/logging.h>
#include <cstdint>
#include <unordered_map>

#include "device/include/controller.h"
#include "main/shim/acl_api.h"
#include "main/shim/shim.h"
#include "stack/btm/btm_dev.h"
#include "stack/btm/btm_int_types.h"
#include "stack/btm/security_device_record.h"
#include "stack/include/bt_types.h"
#include "types/raw_address.h"

extern tBTM_CB btm_cb;

extern void btm_send_hci_create_connection(
    uint16_t scan_int, uint16_t scan_win, uint8_t init_filter_policy,
    uint8_t addr_type_peer, const RawAddress& bda_peer, uint8_t addr_type_own,
    uint16_t conn_int_min, uint16_t conn_int_max, uint16_t conn_latency,
    uint16_t conn_timeout, uint16_t min_ce_len, uint16_t max_ce_len,
    uint8_t phy);
extern void btm_ble_create_conn_cancel();

namespace {

constexpr char kAcceptlistAdd[] = "AcceptlistAdd";
constexpr char kAcceptlistRemove[] = "AcceptlistRemove";
constexpr char kAcceptlistClear[] = "AcceptlistClear";

}  // namespace

// Unfortunately (for now?) we have to maintain a copy of the device acceptlist
// on the host to determine if a device is pending to be connected or not. This
// controls whether the host should keep trying to scan for acceptlisted
// peripherals or not.
// TODO: Move all of this to controller/le/background_list or similar?
struct BackgroundConnection {
  RawAddress address;
  uint8_t addr_type;
  bool in_controller_wl;
  uint8_t addr_type_in_wl;
  bool pending_removal;
};

struct BgConnHash {
  std::size_t operator()(const RawAddress& x) const {
    const uint8_t* a = x.address;
    return a[0] ^ (a[1] << 8) ^ (a[2] << 16) ^ (a[3] << 24) ^ a[4] ^
           (a[5] << 8);
  }
};

static std::unordered_map<RawAddress, BackgroundConnection, BgConnHash>
    background_connections;

static void acceptlist_command_complete(tHCI_STATUS status, const char* msg) {
  switch (status) {
    case HCI_SUCCESS:
      return;
    default:
      LOG_WARN(
          "Received unexpected accept list completion command:%s status:%s",
          msg, hci_error_code_text(status).c_str());
  }
}

static void acceptlist_add_command_complete(uint8_t* p_data, uint16_t evt_len) {
  if (evt_len < sizeof(uint8_t)) {
    LOG_ERROR("Received bogus acceptlist add complete length:%hu", evt_len);
    return;
  }
  uint8_t status;
  STREAM_TO_UINT8(status, p_data);
  acceptlist_command_complete(static_cast<tHCI_STATUS>(status), kAcceptlistAdd);
}

static void acceptlist_remove_command_complete(uint8_t* p_data,
                                               uint16_t evt_len) {
  if (evt_len < sizeof(uint8_t)) {
    LOG_ERROR("Received bogus acceptlist remove complete length:%hu", evt_len);
    return;
  }
  uint8_t status;
  STREAM_TO_UINT8(status, p_data);
  acceptlist_command_complete(static_cast<tHCI_STATUS>(status),
                              kAcceptlistRemove);
}

static void acceptlist_clear_command_complete(uint8_t* p_data,
                                              uint16_t evt_len) {
  if (evt_len < sizeof(uint8_t)) {
    LOG_ERROR("Received bogus acceptlist remove complete length:%hu", evt_len);
    return;
  }
  uint8_t status;
  STREAM_TO_UINT8(status, p_data);
  acceptlist_command_complete(static_cast<tHCI_STATUS>(status),
                              kAcceptlistClear);
}

/** This function is to stop auto connection procedure */
static bool btm_ble_stop_auto_conn() {
  BTM_TRACE_EVENT("%s", __func__);

  if (!btm_cb.ble_ctr_cb.is_connection_state_connecting()) {
    LOG_DEBUG(
        "No need to stop auto connection procedure that is not connecting");
    return false;
  }

  btm_ble_create_conn_cancel();

  btm_cb.ble_ctr_cb.reset_acceptlist_process_in_progress();
  return true;
}

static void background_connection_add(tBLE_ADDR_TYPE addr_type,
                                      const RawAddress& address) {
  auto map_iter = background_connections.find(address);
  if (map_iter == background_connections.end()) {
    background_connections[address] =
        BackgroundConnection{address, addr_type, false, 0, false};
  } else {
    BackgroundConnection* connection = &map_iter->second;
    if (addr_type != connection->addr_type) {
      LOG(INFO) << __func__ << " Addr type mismatch " << address;
      btsnd_hcic_ble_remove_from_acceptlist(
          connection->addr_type_in_wl, connection->address,
          base::Bind(&acceptlist_remove_command_complete));
      connection->addr_type = addr_type;
      connection->in_controller_wl = false;
    }
    connection->pending_removal = false;
  }
}

static void background_connection_remove(const RawAddress& address) {
  auto map_iter = background_connections.find(address);
  if (map_iter != background_connections.end()) {
    if (map_iter->second.in_controller_wl) {
      map_iter->second.pending_removal = true;
    } else {
      background_connections.erase(map_iter);
    }
  }
}

static void background_connections_clear() { background_connections.clear(); }

static bool background_connections_pending() {
  for (auto& map_el : background_connections) {
    BackgroundConnection* connection = &map_el.second;
    if (connection->pending_removal) continue;
    const bool connected =
        BTM_IsAclConnectionUp(connection->address, BT_TRANSPORT_LE);
    if (!connected) {
      return true;
    }
  }
  return false;
}

static int background_connections_count() {
  int count = 0;
  for (auto& map_el : background_connections) {
    if (!map_el.second.pending_removal) ++count;
  }
  return count;
}

const tBLE_BD_ADDR convert_to_address_with_type(
    const RawAddress& bd_addr, const tBTM_SEC_DEV_REC* p_dev_rec) {
  if (p_dev_rec == nullptr || !p_dev_rec->is_device_type_has_ble()) {
    return {
        .type = BLE_ADDR_PUBLIC,
        .bda = bd_addr,
    };
  }

  if (p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
    return {
        .type = p_dev_rec->ble.ble_addr_type,
        .bda = bd_addr,
    };
  } else {
    return p_dev_rec->ble.identity_address_with_type;
  }
}

/*******************************************************************************
 *
 * Function         btm_add_dev_to_controller
 *
 * Description      This function load the device into controller acceptlist
 ******************************************************************************/
static bool btm_add_dev_to_controller(bool to_add, const RawAddress& bd_addr) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);

  if (p_dev_rec != NULL && p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) {
    if (to_add) {
      if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
        LOG_DEBUG(
            "Adding known device record into acceptlist with identity "
            "device:%s",
            PRIVATE_ADDRESS(p_dev_rec->ble.identity_address_with_type));
        background_connection_add(
            p_dev_rec->ble.identity_address_with_type.type,
            p_dev_rec->ble.identity_address_with_type.bda);
      } else {
        LOG_DEBUG(
            "Adding known device record into acceptlist without identity "
            "device:%s",
            PRIVATE_ADDRESS(bd_addr));
        background_connection_add(p_dev_rec->ble.ble_addr_type, bd_addr);

        if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM &&
            BTM_BLE_IS_RESOLVE_BDA(bd_addr)) {
          LOG(INFO) << __func__ << " adding RPA into acceptlist";
        }
      }

      p_dev_rec->ble.in_controller_list |= BTM_ACCEPTLIST_BIT;
    } else {
      if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
        LOG_DEBUG(
            "Removing known device record into acceptlist with identity "
            "device:%s",
            PRIVATE_ADDRESS(p_dev_rec->ble.identity_address_with_type));
        background_connection_remove(
            p_dev_rec->ble.identity_address_with_type.bda);
      } else {
        LOG_DEBUG(
            "Removing known device record into acceptlist without identity "
            "device:%s",
            PRIVATE_ADDRESS(bd_addr));
        background_connection_remove(bd_addr);

        if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_RANDOM &&
            BTM_BLE_IS_RESOLVE_BDA(bd_addr)) {
          LOG(INFO) << __func__ << " removing RPA from acceptlist";
        }
      }

      p_dev_rec->ble.in_controller_list &= ~BTM_ACCEPTLIST_BIT;
    }
  } else {
    /* not a known device, i.e. attempt to connect to device never seen before
     */
    if (to_add) {
      background_connection_add(BLE_ADDR_PUBLIC, bd_addr);
    } else {
      background_connection_remove(bd_addr);
    }
  }

  return true;
}

/*******************************************************************************
 *
 * Function         btm_execute_wl_dev_operation
 *
 * Description      execute the pending acceptlist device operation (loading or
 *                                                                  removing)
 ******************************************************************************/
static bool btm_execute_wl_dev_operation(void) {
  // handle removals first to avoid filling up controller's acceptlist
  for (auto map_it = background_connections.begin();
       map_it != background_connections.end();) {
    BackgroundConnection* connection = &map_it->second;
    if (connection->pending_removal) {
      btsnd_hcic_ble_remove_from_acceptlist(
          connection->addr_type_in_wl, connection->address,
          base::BindOnce(&acceptlist_remove_command_complete));
      map_it = background_connections.erase(map_it);
    } else
      ++map_it;
  }
  for (auto& map_el : background_connections) {
    BackgroundConnection* connection = &map_el.second;
    const bool connected =
        BTM_IsAclConnectionUp(connection->address, BT_TRANSPORT_LE);
    if (!connection->in_controller_wl && !connected) {
      btsnd_hcic_ble_add_acceptlist(
          connection->addr_type, connection->address,
          base::BindOnce(&acceptlist_add_command_complete));
      connection->in_controller_wl = true;
      connection->addr_type_in_wl = connection->addr_type;
    } else if (connection->in_controller_wl && connected) {
      /* Bluetooth Core 4.2 as well as ESR08 disallows more than one
         connection between two LE addresses. Not all controllers handle this
         correctly, therefore we must make sure connected devices are not in
         the acceptlist when bg connection attempt is active. */
      btsnd_hcic_ble_remove_from_acceptlist(
          connection->addr_type_in_wl, connection->address,
          base::BindOnce(&acceptlist_remove_command_complete));
      connection->in_controller_wl = false;
    }
  }
  return true;
}

/** This function is to start auto connection procedure */
static bool btm_ble_start_auto_conn() {
  tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
  ASSERT(p_cb != nullptr);

  const uint16_t scan_int = (p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF)
                                ? BTM_BLE_SCAN_SLOW_INT_1
                                : p_cb->scan_int;
  const uint16_t scan_win = (p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF)
                                ? BTM_BLE_SCAN_SLOW_WIN_1
                                : p_cb->scan_win;
  tBLE_ADDR_TYPE own_addr_type = p_cb->addr_mgnt_cb.own_addr_type;
  tBLE_ADDR_TYPE peer_addr_type = BLE_ADDR_PUBLIC;

  uint8_t phy = PHY_LE_1M;
  if (controller_get_interface()->supports_ble_2m_phy()) phy |= PHY_LE_2M;
  if (controller_get_interface()->supports_ble_coded_phy()) phy |= PHY_LE_CODED;

  if (!btm_ble_topology_check(BTM_BLE_STATE_INIT)) {
    LOG_INFO(
        "Unable to initiate background connection due to topology limitation");
    return false;
  }

  if (!btm_cb.ble_ctr_cb.is_connection_state_idle() ||
      !background_connections_pending()) {
    LOG_DEBUG(
        "Connection state not idle or already have background connection "
        "pending");
    return false;
  }

  p_cb->wl_state |= BTM_BLE_ACCEPTLIST_INIT;

  btm_execute_wl_dev_operation();

  btm_ble_enable_resolving_list_for_platform(BTM_BLE_RL_INIT);
  if (btm_cb.ble_ctr_cb.rl_state != BTM_BLE_RL_IDLE &&
      controller_get_interface()->supports_ble_privacy()) {
    own_addr_type |= BLE_ADDR_TYPE_ID_BIT;
    peer_addr_type |= BLE_ADDR_TYPE_ID_BIT;
  }

  btm_send_hci_create_connection(
      scan_int,                       /* uint16_t scan_int      */
      scan_win,                       /* uint16_t scan_win      */
      0x01,                           /* uint8_t acceptlist     */
      peer_addr_type,                 /* uint8_t addr_type_peer */
      RawAddress::kEmpty,             /* BD_ADDR bda_peer     */
      own_addr_type,                  /* uint8_t addr_type_own */
      BTM_BLE_CONN_INT_MIN_DEF,       /* uint16_t conn_int_min  */
      BTM_BLE_CONN_INT_MAX_DEF,       /* uint16_t conn_int_max  */
      BTM_BLE_CONN_PERIPHERAL_LATENCY_DEF, /* uint16_t conn_latency  */
      BTM_BLE_CONN_TIMEOUT_DEF,       /* uint16_t conn_timeout  */
      0,                              /* uint16_t min_len       */
      0,                              /* uint16_t max_len       */
      phy);
  return true;
}

/*******************************************************************************
 *
 * Function         btm_update_scanner_filter_policy
 *
 * Description      This function updates the filter policy of scanner
 ******************************************************************************/
void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) {
  tBTM_BLE_INQ_CB* p_inq = &btm_cb.ble_ctr_cb.inq_var;

  uint32_t scan_interval =
      !p_inq->scan_interval ? BTM_BLE_GAP_DISC_SCAN_INT : p_inq->scan_interval;
  uint32_t scan_window =
      !p_inq->scan_window ? BTM_BLE_GAP_DISC_SCAN_WIN : p_inq->scan_window;

  BTM_TRACE_EVENT("%s", __func__);

  p_inq->sfp = scan_policy;
  p_inq->scan_type = p_inq->scan_type == BTM_BLE_SCAN_MODE_NONE
                         ? BTM_BLE_SCAN_MODE_ACTI
                         : p_inq->scan_type;

  btm_send_hci_set_scan_params(
      p_inq->scan_type, (uint16_t)scan_interval, (uint16_t)scan_window,
      btm_cb.ble_ctr_cb.addr_mgnt_cb.own_addr_type, scan_policy);
}

/*******************************************************************************
 *
 * Function         btm_ble_bgconn_cancel_if_disconnected
 *
 * Description      If a device has been disconnected, it must be re-added to
 *                  the acceptlist. If needed, this function cancels a pending
 *                  initiate command in order to trigger restart of the initiate
 *                  command which in turn updates the acceptlist.
 *
 * Parameters       bd_addr: updated device
 *
 ******************************************************************************/
void btm_ble_bgconn_cancel_if_disconnected(const RawAddress& bd_addr) {
  if (!btm_cb.ble_ctr_cb.is_connection_state_connecting()) return;

  auto map_it = background_connections.find(bd_addr);
  if (map_it != background_connections.end()) {
    BackgroundConnection* connection = &map_it->second;
    if (!connection->in_controller_wl && !connection->pending_removal &&
        !BTM_IsAclConnectionUp(bd_addr, BT_TRANSPORT_LE)) {
      btm_ble_stop_auto_conn();
    }
  }
}

/*******************************************************************************
 *
 * Function         btm_ble_suspend_bg_conn
 *
 * Description      This function is to suspend an active background connection
 *                  procedure.
 *
 * Parameters       none.
 *
 * Returns          none.
 *
 ******************************************************************************/
bool btm_ble_suspend_bg_conn(void) {
  if (bluetooth::shim::is_gd_acl_enabled()) {
    LOG_DEBUG("Gd acl_manager handles sync of background connections");
    return true;
  }
  return btm_ble_stop_auto_conn();
}

/*******************************************************************************
 *
 * Function         btm_ble_resume_bg_conn
 *
 * Description      This function is to resume a background auto connection
 *                  procedure.
 *
 * Parameters       none.
 *
 * Returns          none.
 *
 ******************************************************************************/
bool btm_ble_resume_bg_conn(void) {
  if (bluetooth::shim::is_gd_acl_enabled()) {
    LOG_DEBUG("Gd acl_manager handles sync of background connections");
    return true;
  }
  return btm_ble_start_auto_conn();
}

bool BTM_BackgroundConnectAddressKnown(const RawAddress& address) {
  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(address);

  //  not a known device, or a classic device, we assume public address
  if (p_dev_rec == NULL || (p_dev_rec->device_type & BT_DEVICE_TYPE_BLE) == 0)
    return true;

  // bonded device with identity address known
  if (!p_dev_rec->ble.identity_address_with_type.bda.IsEmpty()) {
    return true;
  }

  // Public address, Random Static, or Random Non-Resolvable Address known
  if (p_dev_rec->ble.ble_addr_type == BLE_ADDR_PUBLIC ||
      !BTM_BLE_IS_RESOLVE_BDA(address)) {
    return true;
  }

  // Only Resolvable Private Address (RPA) is known, we don't allow it into
  // the background connection procedure.
  return false;
}

bool BTM_SetLeConnectionModeToFast() {
  VLOG(2) << __func__;
  tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
  if ((p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF &&
       p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ||
      (p_cb->scan_int == BTM_BLE_SCAN_SLOW_INT_1 &&
       p_cb->scan_win == BTM_BLE_SCAN_SLOW_WIN_1)) {
    p_cb->scan_int = BTM_BLE_SCAN_FAST_INT;
    p_cb->scan_win = BTM_BLE_SCAN_FAST_WIN;
    return true;
  }
  return false;
}

void BTM_SetLeConnectionModeToSlow() {
  VLOG(2) << __func__;
  tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
  if ((p_cb->scan_int == BTM_BLE_SCAN_PARAM_UNDEF &&
       p_cb->scan_win == BTM_BLE_SCAN_PARAM_UNDEF) ||
      (p_cb->scan_int == BTM_BLE_SCAN_FAST_INT &&
       p_cb->scan_win == BTM_BLE_SCAN_FAST_WIN)) {
    p_cb->scan_int = BTM_BLE_SCAN_SLOW_INT_1;
    p_cb->scan_win = BTM_BLE_SCAN_SLOW_WIN_1;
  }
}

/** Adds the device into acceptlist. Returns false if acceptlist is full and
 * device can't be added, true otherwise. */
bool BTM_AcceptlistAdd(const RawAddress& address) {
  if (!controller_get_interface()->supports_ble()) {
    LOG_WARN("Controller does not support Le");
    return false;
  }

  if (bluetooth::shim::is_gd_acl_enabled()) {
    return bluetooth::shim::ACL_AcceptLeConnectionFrom(
        convert_to_address_with_type(address, btm_find_dev(address)),
        /* is_direct */ false);
  }

  if (background_connections_count() ==
      controller_get_interface()->get_ble_acceptlist_size()) {
    LOG_ERROR("Unable to add device to acceptlist since it is full");
    return false;
  }

  if (btm_cb.ble_ctr_cb.wl_state & BTM_BLE_ACCEPTLIST_INIT) {
    btm_ble_stop_auto_conn();
  }
  btm_add_dev_to_controller(true, address);
  btm_ble_resume_bg_conn();
  LOG_DEBUG("Added to Le acceptlist device:%s", PRIVATE_ADDRESS(address));
  return true;
}

/** Removes the device from acceptlist */
void BTM_AcceptlistRemove(const RawAddress& address) {
  if (!controller_get_interface()->supports_ble()) {
    LOG_WARN("Controller does not support Le");
    return;
  }

  if (bluetooth::shim::is_gd_acl_enabled()) {
    bluetooth::shim::ACL_IgnoreLeConnectionFrom(
        convert_to_address_with_type(address, btm_find_dev(address)));
    return;
  }

  if (btm_cb.ble_ctr_cb.wl_state & BTM_BLE_ACCEPTLIST_INIT) {
    btm_ble_stop_auto_conn();
  }
  btm_add_dev_to_controller(false, address);
  btm_ble_resume_bg_conn();
  LOG_DEBUG("Removed from Le acceptlist device:%s", PRIVATE_ADDRESS(address));
}

/** Clear the acceptlist, end any pending acceptlist connections */
void BTM_AcceptlistClear() {
  if (!controller_get_interface()->supports_ble()) {
    LOG_WARN("Controller does not support Le");
    return;
  }

  if (bluetooth::shim::is_gd_acl_enabled()) {
    bluetooth::shim::ACL_IgnoreAllLeConnections();
    return;
  }

  btm_ble_stop_auto_conn();
  btsnd_hcic_ble_clear_acceptlist(
      base::BindOnce(&acceptlist_clear_command_complete));
  background_connections_clear();
  LOG_DEBUG("Cleared Le acceptlist");
}