Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit e9b25d0c authored by Jakub Pawlowski's avatar Jakub Pawlowski
Browse files

Split BTM_BleUpdateBgConnDev into BTM_WhiteListAdd and BTM_WhiteListRemove

There is very little common code between both codepath. Having them
separate makes the code cleaner.

Test: compilation, no functional changes.
Bug: 112827989
Change-Id: I936f69a93366d3230df4435fc4b24962cc0bd4b2
parent dbe55155
Loading
Loading
Loading
Loading
+29 −26
Original line number Diff line number Diff line
@@ -245,32 +245,6 @@ bool btm_execute_wl_dev_operation(void) {
  return true;
}

/*******************************************************************************
 *
 * Function         btm_update_dev_to_white_list
 *
 * Description      This function adds or removes a device into/from
 *                  the white list.
 *
 ******************************************************************************/
bool btm_update_dev_to_white_list(bool to_add, const RawAddress& bd_addr) {
  tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;

  if (to_add &&
      background_connections_count() ==
          controller_get_interface()->get_ble_white_list_size()) {
    BTM_TRACE_ERROR("%s Whitelist full, unable to add device", __func__);
    return false;
  }

  if (p_cb->wl_state & BTM_BLE_WL_INIT) {
    btm_ble_stop_auto_conn();
  }
  btm_add_dev_to_controller(to_add, bd_addr);
  btm_ble_resume_bg_conn();
  return true;
}

/*******************************************************************************
 *
 * Function         btm_ble_clear_white_list
@@ -607,3 +581,32 @@ bool btm_send_pending_direct_conn(void) {

  return rt;
}

/** Adds the device into white list. Returns false if white list is full and
 * device can't be added, true otherwise. */
bool BTM_WhiteListAdd(const RawAddress& address) {
  VLOG(1) << __func__ << ": " << address;

  if (background_connections_count() ==
      controller_get_interface()->get_ble_white_list_size()) {
    BTM_TRACE_ERROR("%s Whitelist full, unable to add device", __func__);
    return false;
  }

  if (btm_cb.ble_ctr_cb.wl_state & BTM_BLE_WL_INIT) {
    btm_ble_stop_auto_conn();
  }
  btm_add_dev_to_controller(true, address);
  btm_ble_resume_bg_conn();
  return true;
}

/** Removes the device from white list */
void BTM_WhiteListRemove(const RawAddress& address) {
  VLOG(1) << __func__ << ": " << address;
  if (btm_cb.ble_ctr_cb.wl_state & BTM_BLE_WL_INIT) {
    btm_ble_stop_auto_conn();
  }
  btm_add_dev_to_controller(false, address);
  btm_ble_resume_bg_conn();
}
+3 −36
Original line number Diff line number Diff line
@@ -696,9 +696,7 @@ bool BTM_BleLocalPrivacyEnabled(void) {
#endif
}

/**
 * Set BLE connectable mode to auto connect
 */
/** Set BLE connectable mode to auto connect */
void BTM_BleStartAutoConn() {
  BTM_TRACE_EVENT("%s", __func__);
  if (!controller_get_interface()->supports_ble()) return;
@@ -709,19 +707,8 @@ void BTM_BleStartAutoConn() {
  }
}

/*******************************************************************************
 *
 * Function         BTM_BleClearBgConnDev
 *
 * Description      This function is called to clear the whitelist,
 *                  end any pending whitelist connections,
 *                  and reset the local bg device list.
 *
 * Parameters       void
 *
 * Returns          void
 *
 ******************************************************************************/
/** Clear the whitelist, end any pending whitelist connections, reset the local
 * bg device list */
void BTM_BleClearBgConnDev(void) {
  if (!controller_get_interface()->supports_ble()) return;
  btm_ble_stop_auto_conn();
@@ -729,26 +716,6 @@ void BTM_BleClearBgConnDev(void) {
  gatt_reset_bgdev_list();
}

/*******************************************************************************
 *
 * Function         BTM_BleUpdateBgConnDev
 *
 * Description      This function is called to add or remove a device into/from
 *                  background connection procedure. The background connection
 *                  procedure is decided by the background connection type, it
 *                  can be auto connection, or selective connection.
 *
 * Parameters       add_remove: true to add; false to remove.
 *                  remote_bda: device address to add/remove.
 *
 * Returns          void
 *
 ******************************************************************************/
bool BTM_BleUpdateBgConnDev(bool add_remove, const RawAddress& remote_bda) {
  BTM_TRACE_EVENT("%s() add=%d", __func__, add_remove);
  return btm_update_dev_to_white_list(add_remove, remote_bda);
}

/*******************************************************************************
 *
 * Function         BTM_BleSetConnectableMode
+0 −2
Original line number Diff line number Diff line
@@ -116,8 +116,6 @@ extern void btm_ble_update_sec_key_size(const RawAddress& bd_addr,
extern uint8_t btm_ble_read_sec_key_size(const RawAddress& bd_addr);

/* white list function */
extern bool btm_update_dev_to_white_list(bool to_add,
                                         const RawAddress& bd_addr);
extern void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy);
extern void btm_update_adv_filter_policy(tBTM_BLE_AFP adv_policy);
extern void btm_ble_clear_white_list(void);
+4 −4
Original line number Diff line number Diff line
@@ -1338,7 +1338,7 @@ bool gatt_add_bg_dev_list(tGATT_REG* p_reg, const RawAddress& bd_addr) {
  }
  // the device is not in the whitelist

  if (!BTM_BleUpdateBgConnDev(true, bd_addr)) return false;
  if (!BTM_WhiteListAdd(bd_addr)) return false;

  gatt_cb.bgconn_dev.emplace_back();
  tGATT_BG_CONN_DEV& dev = gatt_cb.bgconn_dev.back();
@@ -1353,7 +1353,7 @@ uint8_t gatt_clear_bg_dev_for_addr(const RawAddress& bd_addr) {
  auto dev_it = gatt_find_bg_dev_it(bd_addr);
  if (dev_it == gatt_cb.bgconn_dev.end()) return false;

  CHECK(BTM_BleUpdateBgConnDev(false, dev_it->remote_bda));
  BTM_WhiteListRemove(dev_it->remote_bda);
  gatt_cb.bgconn_dev.erase(dev_it);
  return true;
}
@@ -1371,7 +1371,7 @@ bool gatt_remove_bg_dev_from_list(tGATT_REG* p_reg, const RawAddress& bd_addr) {
  if (!dev_it->gatt_if.empty()) return true;

  // no more apps interested - remove from whitelist and delete record
  CHECK(BTM_BleUpdateBgConnDev(false, dev_it->remote_bda));
  BTM_WhiteListRemove(dev_it->remote_bda);
  gatt_cb.bgconn_dev.erase(dev_it);
  return true;
}
@@ -1388,7 +1388,7 @@ void gatt_deregister_bgdev_list(tGATT_IF gatt_if) {
      continue;
    }

    BTM_BleUpdateBgConnDev(false, it->remote_bda);
    BTM_WhiteListRemove(it->remote_bda);
    it = gatt_cb.bgconn_dev.erase(it);
  }
}
+9 −34
Original line number Diff line number Diff line
@@ -364,43 +364,18 @@ extern bool BTM_ReadRemoteConnectionAddr(const RawAddress& pseudo_addr,
 ******************************************************************************/
extern void BTM_BleLoadLocalKeys(uint8_t key_type, tBTM_BLE_LOCAL_KEYS* p_key);

/**
 * Set BLE connectable mode to auto connect
 */
/** Set BLE connectable mode to auto connect */
extern void BTM_BleStartAutoConn();

/*******************************************************************************
 *
 * Function         BTM_BleUpdateBgConnDev
 *
 * Description      This function is called to add or remove a device into/from
 *                  background connection procedure. The background connection
*                   procedure is decided by the background connection type, it
*can be
*                   auto connection, or selective connection.
 *
 * Parameters       add_remove: true to add; false to remove.
 *                  remote_bda: device address to add/remove.
 *
 * Returns          void
 *
 ******************************************************************************/
extern bool BTM_BleUpdateBgConnDev(bool add_remove,
                                   const RawAddress& remote_bda);
/** Adds the device into white list. Returns false if white list is full and
 * device can't be added, true otherwise. */
extern bool BTM_WhiteListAdd(const RawAddress& address);

/*******************************************************************************
 *
 * Function         BTM_BleClearBgConnDev
 *
 * Description      This function is called to clear the whitelist,
 *                  end any pending whitelist connections,
 *                  and reset the local bg device list.
 *
 * Parameters       void
 *
 * Returns          void
 *
 ******************************************************************************/
/** Removes the device from white list */
extern void BTM_WhiteListRemove(const RawAddress& address);

/** Clear the whitelist, end any pending whitelist connections, reset the local
 * bg device list */
extern void BTM_BleClearBgConnDev(void);

/********************************************************