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

Commit 1532341a authored by Chris Manton's avatar Chris Manton
Browse files

Encapsulate tBTM_CB::tBTM_BLE_CB::tBTM_BLE_CONN_ST

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I6100f228605af31be29a6ab69d59a57a35b547b0
parent 4ee1dbcf
Loading
Loading
Loading
Loading
+2 −3
Original line number Diff line number Diff line
@@ -23,8 +23,6 @@
#include "stack/include/hcidefs.h"
#include "stack/include/l2cap_hci_link_interface.h"

void btm_ble_set_conn_st(tBTM_BLE_CONN_ST new_st);  // TODO link internally

void btm_ble_advertiser_notify_terminated_legacy(uint8_t status,
                                                 uint16_t connection_handle);

@@ -72,7 +70,8 @@ void acl_ble_enhanced_connection_complete(
void acl_ble_connection_fail(const tBLE_BD_ADDR& address_with_type,
                             uint16_t handle, bool enhanced, uint8_t status) {
  if (status != HCI_ERR_ADVERTISING_TIMEOUT) {
    btm_ble_set_conn_st(BLE_CONN_IDLE);
    btm_cb.ble_ctr_cb.set_connection_state_idle();
    btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
    btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true);
  } else {
    btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE;
+2 −2
Original line number Diff line number Diff line
@@ -798,8 +798,8 @@ bool btm_pm_device_in_active_or_sniff_mode(void) {
  }

  /* Check BLE states */
  if (btm_ble_get_conn_st() != BLE_CONN_IDLE) {
    BTM_TRACE_DEBUG("%s - BLE state: %x", __func__, btm_ble_get_conn_st());
  if (!btm_cb.ble_ctr_cb.is_connection_state_idle()) {
    BTM_TRACE_DEBUG("%s - BLE state is not idle", __func__);
    return true;
  }

+4 −5
Original line number Diff line number Diff line
@@ -159,7 +159,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_CONNECTING) return;
  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()) {
@@ -370,7 +370,7 @@ bool btm_ble_start_auto_conn() {
    return false;
  }

  if (btm_ble_get_conn_st() != BLE_CONN_IDLE ||
  if (!btm_cb.ble_ctr_cb.is_connection_state_idle() ||
      !background_connections_pending()) {
    return false;
  }
@@ -407,9 +407,8 @@ bool btm_ble_start_auto_conn() {
bool btm_ble_stop_auto_conn() {
  BTM_TRACE_EVENT("%s", __func__);

  if (btm_ble_get_conn_st() != BLE_CONNECTING) {
    BTM_TRACE_DEBUG("conn_st = %d, not in auto conn state, cannot stop",
                    btm_ble_get_conn_st());
  if (!btm_cb.ble_ctr_cb.is_connection_state_connecting()) {
    BTM_TRACE_DEBUG("%s not in auto conn state, cannot stop", __func__);
    return false;
  }

+15 −23
Original line number Diff line number Diff line
@@ -31,21 +31,6 @@
extern void btm_ble_advertiser_notify_terminated_legacy(
    uint8_t status, uint16_t connection_handle);

/** This function get BLE connection state */
tBTM_BLE_CONN_ST btm_ble_get_conn_st(void) {
  return btm_cb.ble_ctr_cb.conn_state;
}

/** This function set BLE connection state */
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_CONNECTING)
    btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT);
  else
    btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
}

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,
@@ -83,7 +68,8 @@ void btm_send_hci_create_connection(
                                  conn_timeout, min_ce_len, max_ce_len);
  }

  btm_ble_set_conn_st(BLE_CONNECTING);
  btm_cb.ble_ctr_cb.set_connection_state_connecting();
  btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT);
}

/** LE connection complete. */
@@ -94,10 +80,12 @@ void btm_ble_create_ll_conn_complete(uint8_t status) {
               << loghex(status);

  if (status == HCI_ERR_COMMAND_DISALLOWED) {
    btm_ble_set_conn_st(BLE_CONNECTING);
    btm_cb.ble_ctr_cb.set_connection_state_connecting();
    btm_ble_set_topology_mask(BTM_BLE_STATE_INIT_BIT);
    LOG(ERROR) << "LE Create Connection - command disallowed";
  } else {
    btm_ble_set_conn_st(BLE_CONN_IDLE);
    btm_cb.ble_ctr_cb.set_connection_state_idle();
    btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
    btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, NULL, status);
  }
}
@@ -173,7 +161,8 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
        android::bluetooth::hci::STATUS_UNKNOWN);

    if (role == HCI_ROLE_MASTER) {
      btm_ble_set_conn_st(BLE_CONN_IDLE);
      btm_cb.ble_ctr_cb.set_connection_state_idle();
      btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
    }

    connection_manager::on_connection_complete(bda);
@@ -200,7 +189,8 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,

    role = HCI_ROLE_UNKNOWN;
    if (status != HCI_ERR_ADVERTISING_TIMEOUT) {
      btm_ble_set_conn_st(BLE_CONN_IDLE);
      btm_cb.ble_ctr_cb.set_connection_state_idle();
      btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
      btm_ble_disable_resolving_list(BTM_BLE_RL_INIT, true);
    } else {
      btm_cb.ble_ctr_cb.inq_var.adv_mode = BTM_BLE_ADV_DISABLE;
@@ -216,7 +206,8 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,

void btm_ble_create_conn_cancel() {
  btsnd_hcic_ble_create_conn_cancel();
  btm_ble_set_conn_st(BLE_CONN_CANCEL);
  btm_cb.ble_ctr_cb.set_connection_state_cancelled();
  btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
}

void btm_ble_create_conn_cancel_complete(uint8_t* p) {
@@ -238,8 +229,9 @@ void btm_ble_create_conn_cancel_complete(uint8_t* p) {
    /* This is a sign that logic around keeping connection state is broken */
    LOG(ERROR)
        << "Attempt to cancel LE connection, when no connection is pending.";
    if (btm_ble_get_conn_st() == BLE_CONN_CANCEL) {
      btm_ble_set_conn_st(BLE_CONN_IDLE);
    if (btm_cb.ble_ctr_cb.is_connection_state_cancelled()) {
      btm_cb.ble_ctr_cb.set_connection_state_idle();
      btm_ble_clear_topology_mask(BTM_BLE_STATE_INIT_BIT);
      btm_ble_update_mode_operation(HCI_ROLE_UNKNOWN, nullptr, status);
    }
  }
+1 −1
Original line number Diff line number Diff line
@@ -2340,7 +2340,7 @@ void btm_ble_update_mode_operation(uint8_t link_role, const RawAddress* bd_addr,
     due to resource limitation, start next direct connection or background
     connection
     now in order */
  if (btm_ble_get_conn_st() == BLE_CONN_IDLE &&
  if (btm_cb.ble_ctr_cb.is_connection_state_idle() &&
      status != HCI_ERR_HOST_REJECT_RESOURCES &&
      status != HCI_ERR_MAX_NUM_OF_CONNECTIONS) {
    btm_ble_resume_bg_conn();
Loading