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

Commit 8e2416eb authored by Hansong Zhang's avatar Hansong Zhang Committed by Automerger Merge Worker
Browse files

BTM_PM refactor am: 2f14b11f

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1558771

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I831216089d711d4a16e508fd3977e6c66d7ff01e
parents 3320015a 2f14b11f
Loading
Loading
Loading
Loading
+0 −4
Original line number Diff line number Diff line
@@ -692,7 +692,6 @@ void DumpsysAcl(int fd) {

  for (int i = 0; i < MAX_L2CAP_LINKS; i++) {
    const tACL_CONN& acl_conn = acl_cb.acl_db[i];
    const tBTM_PM_MCB& btm_pm_mcb = acl_cb.pm_mode_db[i];
    if (!acl_conn.in_use) continue;

    LOG_DUMPSYS(fd, "    peer_le_features valid:%s data:%s",
@@ -728,10 +727,7 @@ void DumpsysAcl(int fd) {
                ticks_to_seconds(acl_conn.link_super_tout));
    LOG_DUMPSYS(fd, "    pkt_types_mask:0x%04x", acl_conn.pkt_types_mask);
    LOG_DUMPSYS(fd, "    disconnect_reason:0x%02x", acl_conn.disconnect_reason);
    LOG_DUMPSYS(fd, "    chg_ind:%s", (btm_pm_mcb.chg_ind) ? "true" : "false");
    LOG_DUMPSYS(fd, "    role:%s", RoleText(acl_conn.link_role).c_str());
    LOG_DUMPSYS(fd, "    power_mode_state:%s",
                power_mode_state_text(btm_pm_mcb.State()).c_str());
  }
}
#undef DUMPSYS_TAG
+2 −0
Original line number Diff line number Diff line
@@ -443,6 +443,7 @@ class SecurityListenerShim
    uint16_t handle = interface->GetAclHandle();
    address_to_handle_[bda] = handle;
    btm_sec_connected(bda, handle, HCI_SUCCESS, 0);
    BTM_PM_OnConnected(handle, bda);
    BTA_dm_acl_up(bda, BT_TRANSPORT_BR_EDR);
    address_to_interface_[bda] = std::move(interface);
  }
@@ -461,6 +462,7 @@ class SecurityListenerShim
    address_to_interface_.erase(bda);
    btm_sec_disconnected(handle, HCI_ERR_PEER_USER);
    BTA_dm_acl_down(bda, BT_TRANSPORT_BR_EDR);
    BTM_PM_OnDisconnected(handle);
  }

  void OnEncryptionChange(bluetooth::hci::Address remote,
+14 −33
Original line number Diff line number Diff line
@@ -152,32 +152,22 @@ typedef struct {
  uint8_t role;              /* HCI_ROLE_CENTRAL or HCI_ROLE_PERIPHERAL */
} tBTM_ROLE_SWITCH_CMPL;

typedef struct {
  bool chg_ind;
struct tBTM_PM_MCB {
  bool chg_ind = false;
  tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS + 1];
  tBTM_PM_PWR_MD set_mode;

 private:
  friend tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id,
                                      const RawAddress& remote_bda,
                                      const tBTM_PM_PWR_MD* p_mode);
  friend tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda,
                                      uint16_t max_lat, uint16_t min_rmt_to,
                                      uint16_t min_loc_to);
  friend void btm_pm_proc_cmd_status(tHCI_STATUS status);
  friend void btm_pm_proc_mode_change(tHCI_STATUS hci_status,
                                      uint16_t hci_handle, tHCI_MODE mode,
                                      uint16_t interval);
  tBTM_PM_STATE state;

 public:
  tBTM_PM_STATE State() const { return state; }
  uint16_t interval;
  uint16_t max_lat;
  uint16_t min_loc_to;
  uint16_t min_rmt_to;
  void Init() { state = BTM_PM_ST_ACTIVE; }
} tBTM_PM_MCB;
  tBTM_PM_STATE state = BTM_PM_ST_ACTIVE;  // 0
  uint16_t interval = 0;
  uint16_t max_lat = 0;
  uint16_t min_loc_to = 0;
  uint16_t min_rmt_to = 0;
  void Init(RawAddress bda, uint16_t handle) {
    bda_ = bda;
    handle_ = handle;
  }
  RawAddress bda_;
  uint16_t handle_;
};

struct sACL_CONN {
  BD_FEATURES peer_le_features;
@@ -388,8 +378,6 @@ struct controller_t;
 ****************************************************/
struct sACL_CB {
 private:
  friend int btm_pm_find_acl_ind(const RawAddress& remote_bda);
  friend tBTM_PM_MCB* acl_power_mode_from_handle(uint16_t hci_handle);
  friend tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id,
                                      const RawAddress& remote_bda,
                                      const tBTM_PM_PWR_MD* p_mode);
@@ -399,7 +387,6 @@ struct sACL_CB {
  friend uint16_t BTM_GetNumAclLinks(void);
  friend uint16_t acl_get_supported_packet_types();
  friend uint8_t btm_handle_to_acl_index(uint16_t hci_handle);
  friend void acl_initialize_power_mode(const tACL_CONN& p_acl);
  friend void acl_set_disconnect_reason(tHCI_STATUS acl_disc_reason);
  friend void btm_acl_created(const RawAddress& bda, uint16_t hci_handle,
                              uint8_t link_role, tBT_TRANSPORT transport);
@@ -416,18 +403,12 @@ struct sACL_CB {
  friend void DumpsysAcl(int fd);

  friend struct StackAclBtmAcl;
  friend struct StackAclBtmPm;

  tACL_CONN acl_db[MAX_L2CAP_LINKS];
  tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS];
  tBTM_ROLE_SWITCH_CMPL switch_role_ref_data;
  uint16_t btm_acl_pkt_types_supported;
  uint16_t btm_def_link_policy;
  tHCI_STATUS acl_disc_reason;
  uint8_t pm_pend_link;

 public:
  bool is_power_mode_pending() const { return pm_pend_link != MAX_L2CAP_LINKS; }

 public:
  tHCI_STATUS get_disconnect_reason() const { return acl_disc_reason; }
+2 −47
Original line number Diff line number Diff line
@@ -342,23 +342,6 @@ void btm_acl_process_sca_cmpl_pkt(uint8_t len, uint8_t* data) {
  p_acl->sca = sca;
}

/*******************************************************************************
 *
 * Function         btm_acl_created
 *
 * Description      This function is called by L2CAP when an ACL connection
 *                  is created.
 *
 * Returns          void
 *
 ******************************************************************************/
void acl_initialize_power_mode(const tACL_CONN& p_acl) {
  tBTM_PM_MCB* p_db =
      &btm_cb.acl_cb_.pm_mode_db[btm_handle_to_acl_index(p_acl.hci_handle)];
  memset(p_db, 0, sizeof(tBTM_PM_MCB));
  p_db->Init();
}

tACL_CONN* StackAclBtmAcl::acl_allocate_connection() {
  tACL_CONN* p_acl = &btm_cb.acl_cb_.acl_db[0];
  for (uint8_t xx = 0; xx < MAX_L2CAP_LINKS; xx++, p_acl++) {
@@ -401,7 +384,7 @@ void btm_acl_created(const RawAddress& bda, uint16_t hci_handle,
  p_acl->transport = transport;
  p_acl->switch_role_failed_attempts = 0;
  p_acl->reset_switch_role();
  acl_initialize_power_mode(*p_acl);
  BTM_PM_OnConnected(hci_handle, bda);

  LOG_DEBUG(
      "Created new ACL connection peer:%s role:%s handle:0x%04x transport:%s",
@@ -465,6 +448,7 @@ void btm_acl_removed(uint16_t handle) {
  p_acl->in_use = false;
  NotifyAclLinkDown(*p_acl);
  p_acl->Reset();
  BTM_PM_OnDisconnected(handle);
}

/*******************************************************************************
@@ -2381,35 +2365,6 @@ const RawAddress acl_address_from_handle(uint16_t handle) {
  return p_acl->remote_addr;
}

tBTM_PM_MCB* acl_power_mode_from_handle(uint16_t hci_handle) {
  uint8_t index = btm_handle_to_acl_index(hci_handle);
  if (index >= MAX_L2CAP_LINKS) {
    return nullptr;
  }
  return &btm_cb.acl_cb_.pm_mode_db[index];
}

/*******************************************************************************
 *
 * Function         btm_pm_find_acl_ind
 *
 * Description      This function initializes the control block of an ACL link.
 *                  It is called when an ACL connection is created.
 *
 * Returns          void
 *
 ******************************************************************************/
int btm_pm_find_acl_ind(const RawAddress& remote_bda) {
  tACL_CONN* p = &btm_cb.acl_cb_.acl_db[0];
  uint8_t xx;

  for (xx = 0; xx < MAX_L2CAP_LINKS; xx++, p++) {
    if (p->in_use && p->remote_addr == remote_bda && p->is_transport_br_edr())
      break;
  }
  return xx;
}

/*******************************************************************************
 *
 * Function         btm_ble_refresh_local_resolvable_private_addr
+115 −171

File changed.

Preview size limit exceeded, changes collapsed.

Loading