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

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

Clean up BLE connection state state machine

* get rid of BLE_DIR_CONN - we never go into this state any more
* BLE_BG_CONN -> BLE_CONNECTING
* use btm_ble_get_conn_st instead of directly accessing control block

Test: compilation
Bug: 112827989
Change-Id: I4aa09a8b558c6f2161806a6d27bee0560fd19fd8
parent 991e8722
Loading
Loading
Loading
Loading
+1 −6
Original line number Diff line number Diff line
@@ -469,7 +469,7 @@ void BTM_BleSetConnScanParams(uint32_t scan_interval, uint32_t scan_window) {
      new_param = true;
    }

    if (new_param && p_ble_cb->conn_state == BLE_BG_CONN) {
    if (new_param && btm_ble_get_conn_st() == BLE_CONNECTING) {
      btm_ble_suspend_bg_conn();
    }
  } else {
@@ -2336,11 +2336,6 @@ void btm_ble_set_random_address(const RawAddress& random_bda) {
  bool adv_mode = btm_cb.ble_ctr_cb.inq_var.adv_mode;

  BTM_TRACE_DEBUG("%s", __func__);
  if (btm_ble_get_conn_st() == BLE_DIR_CONN) {
    BTM_TRACE_ERROR("%s: Cannot set random address. Direct conn ongoing",
                    __func__);
    return;
  }

  if (adv_mode == BTM_BLE_ADV_ENABLE)
    btsnd_hcic_ble_set_adv_enable(BTM_BLE_ADV_DISABLE);
+6 −7
Original line number Diff line number Diff line
@@ -150,7 +150,7 @@ void btm_update_scanner_filter_policy(tBTM_BLE_SFP scan_policy) {
 *
 ******************************************************************************/
void btm_ble_bgconn_cancel_if_disconnected(const RawAddress& bd_addr) {
  if (btm_ble_get_conn_st() != BLE_BG_CONN) return;
  if (btm_ble_get_conn_st() != BLE_CONNECTING) return;

  auto map_it = background_connections.find(bd_addr);
  if (map_it != background_connections.end()) {
@@ -356,8 +356,8 @@ bool btm_ble_start_auto_conn() {
    return false;
  }

  if (p_cb->conn_state != BLE_CONN_IDLE || !background_connections_pending() ||
      !l2cu_can_allocate_lcb()) {
  if (btm_ble_get_conn_st() != BLE_CONN_IDLE ||
      !background_connections_pending() || !l2cu_can_allocate_lcb()) {
    return false;
  }

@@ -395,16 +395,15 @@ bool btm_ble_start_auto_conn() {
bool btm_ble_stop_auto_conn() {
  BTM_TRACE_EVENT("%s", __func__);

  tBTM_BLE_CB* p_cb = &btm_cb.ble_ctr_cb;
  if (p_cb->conn_state != BLE_BG_CONN) {
  if (btm_ble_get_conn_st() != BLE_CONNECTING) {
    BTM_TRACE_DEBUG("conn_st = %d, not in auto conn state, cannot stop",
                    p_cb->conn_state);
                    btm_ble_get_conn_st());
    return false;
  }

  btm_ble_create_conn_cancel();

  p_cb->wl_state &= ~BTM_BLE_WL_INIT;
  btm_cb.ble_ctr_cb.wl_state &= ~BTM_BLE_WL_INIT;
  return true;
}

+2 −2
Original line number Diff line number Diff line
@@ -35,7 +35,7 @@ tBTM_BLE_CONN_ST btm_ble_get_conn_st(void) {
void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st) {
  btm_cb.ble_ctr_cb.conn_state = new_st;

  if (new_st == BLE_BG_CONN || new_st == BLE_DIR_CONN)
  if (new_st == BLE_CONNECTING)
    btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT);
  else
    btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
@@ -78,7 +78,7 @@ void btm_send_hci_create_connection(
                                  conn_timeout, min_ce_len, max_ce_len);
  }

  btm_ble_set_conn_st(BLE_BG_CONN);
  btm_ble_set_conn_st(BLE_CONNECTING);
}

/** LE connection complete. */
+1 −2
Original line number Diff line number Diff line
@@ -197,8 +197,7 @@ typedef uint8_t tBTM_BLE_RL_STATE;

/* BLE connection state */
#define BLE_CONN_IDLE 0
#define BLE_DIR_CONN 1
#define BLE_BG_CONN 2
#define BLE_CONNECTING 2
#define BLE_CONN_CANCEL 3
typedef uint8_t tBTM_BLE_CONN_ST;

+0 −6
Original line number Diff line number Diff line
@@ -514,12 +514,6 @@ bool btm_ble_suspend_resolving_list_activity(void) {
  /* if already suspended */
  if (p_ble_cb->suspended_rl_state != BTM_BLE_RL_IDLE) return true;

  /* direct connection active, wait until it completed */
  if (btm_ble_get_conn_st() == BLE_DIR_CONN) {
    BTM_TRACE_ERROR("resolving list can not be edited, EnQ now");
    return false;
  }

  p_ble_cb->suspended_rl_state = BTM_BLE_RL_IDLE;

  if (p_ble_cb->inq_var.adv_mode == BTM_BLE_ADV_ENABLE) {
Loading