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

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

Make BTM_PM almost modular am: 32286a02

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

MUST ONLY BE SUBMITTED BY AUTOMERGER

Change-Id: I9f2707488ba87da81c095d74101531a10b0a0b59
parents 6ce18611 32286a02
Loading
Loading
Loading
Loading
+25 −16
Original line number Original line Diff line number Diff line
@@ -119,42 +119,47 @@ bool bluetooth::shim::UnregisterLinkPolicyClient(tBTM_PM_STATUS_CBACK* p_cb) {
  return true;
  return true;
}
}


tBTM_STATUS bluetooth::shim::BTM_SetPowerMode(tACL_CONN& p_acl,
tBTM_STATUS bluetooth::shim::BTM_SetPowerMode(uint16_t handle,
                                              const tBTM_PM_PWR_MD& new_mode) {
                                              const tBTM_PM_PWR_MD& new_mode) {
  tACL_CONN* p_acl = acl_get_connection_from_handle(handle);
  if (p_acl == nullptr) {
    return BTM_UNKNOWN_ADDR;
  }

  if (!controller_supports_link_policy_mode(
  if (!controller_supports_link_policy_mode(
          new_mode.mode,
          new_mode.mode,
          interop_match_addr(INTEROP_DISABLE_SNIFF, &p_acl.remote_addr))) {
          interop_match_addr(INTEROP_DISABLE_SNIFF, &p_acl->remote_addr))) {
    return BTM_MODE_UNSUPPORTED;
    return BTM_MODE_UNSUPPORTED;
  }
  }


  if (p_acl.policy.Mode() == new_mode.mode) {
  if (p_acl->policy.Mode() == new_mode.mode) {
    LOG_INFO("Controller already in mode:%s[0x%02x]",
    LOG_INFO("Controller already in mode:%s[0x%02x]",
             power_mode_state_text(p_acl.policy.Mode()).c_str(),
             power_mode_state_text(p_acl->policy.Mode()).c_str(),
             p_acl.policy.Mode());
             p_acl->policy.Mode());
  }
  }


  if (p_acl.policy.mode.IsPending()) {
  if (p_acl->policy.mode.IsPending()) {
    LOG_INFO("Link policy mode is pending");
    LOG_INFO("Link policy mode is pending");
  }
  }


  LOG_INFO("Switching mode from %s(0x%x) to %s(0x%x)",
  LOG_INFO("Switching mode from %s(0x%x) to %s(0x%x)",
           power_mode_state_text(p_acl.policy.Mode()).c_str(),
           power_mode_state_text(p_acl->policy.Mode()).c_str(),
           p_acl.policy.Mode(), power_mode_state_text(new_mode.mode).c_str(),
           p_acl->policy.Mode(), power_mode_state_text(new_mode.mode).c_str(),
           new_mode.mode);
           new_mode.mode);


  p_acl.policy.mode.pending_ = new_mode.mode;
  p_acl->policy.mode.pending_ = new_mode.mode;
  switch (new_mode.mode) {
  switch (new_mode.mode) {
    case BTM_PM_MD_ACTIVE:
    case BTM_PM_MD_ACTIVE:
      set_active_mode(p_acl);
      set_active_mode(*p_acl);
      return BTM_SUCCESS;
      return BTM_SUCCESS;
      break;
      break;
    case BTM_PM_MD_SNIFF:
    case BTM_PM_MD_SNIFF:
      set_sniff_mode(p_acl, new_mode.max, new_mode.min, new_mode.attempt,
      set_sniff_mode(*p_acl, new_mode.max, new_mode.min, new_mode.attempt,
                     new_mode.timeout);
                     new_mode.timeout);
      return BTM_SUCCESS;
      return BTM_SUCCESS;
      break;
      break;
    case BTM_PM_MD_HOLD:
    case BTM_PM_MD_HOLD:
      return set_hold_mode(p_acl, new_mode.max, new_mode.min);
      return set_hold_mode(*p_acl, new_mode.max, new_mode.min);
      break;
      break;
  }
  }
  return BTM_MODE_UNSUPPORTED;
  return BTM_MODE_UNSUPPORTED;
@@ -234,14 +239,18 @@ void bluetooth::shim::btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
      PRIVATE_ADDRESS(p_acl->remote_addr), hci_error_code_text(status).c_str());
      PRIVATE_ADDRESS(p_acl->remote_addr), hci_error_code_text(status).c_str());
}
}


tBTM_STATUS bluetooth::shim::BTM_SetSsrParams(tACL_CONN& p_acl,
tBTM_STATUS bluetooth::shim::BTM_SetSsrParams(uint16_t handle, uint16_t max_lat,
                                              uint16_t max_lat,
                                              uint16_t min_rmt_to,
                                              uint16_t min_rmt_to,
                                              uint16_t min_loc_to) {
                                              uint16_t min_loc_to) {
  LOG_DEBUG("Sending gd power mode SSR Params");
  LOG_DEBUG("Sending gd power mode SSR Params");
  p_acl.policy.sniff_subrating.pending_ = true;
  tACL_CONN* p_acl = acl_get_connection_from_handle(handle);
  if (p_acl == nullptr) {
    return BTM_UNKNOWN_ADDR;
  }

  p_acl->policy.sniff_subrating.pending_ = true;
  bluetooth::shim::Stack::GetInstance()->LinkPolicy()->SniffSubrating(
  bluetooth::shim::Stack::GetInstance()->LinkPolicy()->SniffSubrating(
      p_acl.hci_handle, max_lat, min_rmt_to, min_loc_to);
      handle, max_lat, min_rmt_to, min_loc_to);
  return BTM_SUCCESS;
  return BTM_SUCCESS;
}
}


+2 −2
Original line number Original line Diff line number Diff line
@@ -35,11 +35,11 @@ bool SetSniffSubrating(uint16_t handle, uint16_t maximum_latency,
                       uint16_t minimum_remote_timeout,
                       uint16_t minimum_remote_timeout,
                       uint16_t minimum_local_timeout);
                       uint16_t minimum_local_timeout);


tBTM_STATUS BTM_SetPowerMode(tACL_CONN& acl_conn, const tBTM_PM_PWR_MD& mode);
tBTM_STATUS BTM_SetPowerMode(uint16_t handle, const tBTM_PM_PWR_MD& mode);
void btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
void btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
                           tHCI_MODE current_mode, uint16_t interval);
                           tHCI_MODE current_mode, uint16_t interval);


tBTM_STATUS BTM_SetSsrParams(tACL_CONN& acl_conn, uint16_t max_lat,
tBTM_STATUS BTM_SetSsrParams(uint16_t handle, uint16_t max_lat,
                             uint16_t min_rmt_to, uint16_t min_loc_to);
                             uint16_t min_rmt_to, uint16_t min_loc_to);
void btm_pm_on_sniff_subrating(tHCI_STATUS status, uint16_t handle,
void btm_pm_on_sniff_subrating(tHCI_STATUS status, uint16_t handle,
                               uint16_t maximum_transmit_latency,
                               uint16_t maximum_transmit_latency,
+7 −12
Original line number Original line Diff line number Diff line
@@ -116,8 +116,8 @@ struct sACL_CONN;


namespace bluetooth {
namespace bluetooth {
namespace shim {
namespace shim {
tBTM_STATUS BTM_SetPowerMode(sACL_CONN& p_acl, const tBTM_PM_PWR_MD& new_mode);
tBTM_STATUS BTM_SetPowerMode(uint16_t handle, const tBTM_PM_PWR_MD& new_mode);
tBTM_STATUS BTM_SetSsrParams(sACL_CONN& p_acl, uint16_t max_lat,
tBTM_STATUS BTM_SetSsrParams(uint16_t handle, uint16_t max_lat,
                             uint16_t min_rmt_to, uint16_t min_loc_to);
                             uint16_t min_rmt_to, uint16_t min_loc_to);
void btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
void btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
                           tHCI_MODE hci_mode, uint16_t interval);
                           tHCI_MODE hci_mode, uint16_t interval);
@@ -138,9 +138,9 @@ typedef struct {


#define BTM_PM_REC_NOT_USED 0
#define BTM_PM_REC_NOT_USED 0
typedef struct {
typedef struct {
  tBTM_PM_STATUS_CBACK*
  tBTM_PM_STATUS_CBACK* cback =
      cback;    /* to notify the registered party of mode change event */
      nullptr;      /* to notify the registered party of mode change event */
  uint8_t mask; /* registered request mask. 0, if this entry is not used */
  uint8_t mask = 0; /* registered request mask. 0, if this entry is not used */
} tBTM_PM_RCB;
} tBTM_PM_RCB;


/* Structure returned with Role Switch information (in tBTM_CMPL_CB callback
/* Structure returned with Role Switch information (in tBTM_CMPL_CB callback
@@ -325,7 +325,7 @@ struct sACL_CONN {
      tBTM_PM_MODE pending_{BTM_PM_MD_UNKNOWN};
      tBTM_PM_MODE pending_{BTM_PM_MD_UNKNOWN};
      uint16_t interval_{0};
      uint16_t interval_{0};
      friend tBTM_STATUS bluetooth::shim::BTM_SetPowerMode(
      friend tBTM_STATUS bluetooth::shim::BTM_SetPowerMode(
          sACL_CONN& p_acl, const tBTM_PM_PWR_MD& new_mode);
          uint16_t, const tBTM_PM_PWR_MD& new_mode);
      friend void bluetooth::shim::btm_pm_on_mode_change(tHCI_STATUS status,
      friend void bluetooth::shim::btm_pm_on_mode_change(tHCI_STATUS status,
                                                         uint16_t handle,
                                                         uint16_t handle,
                                                         tHCI_MODE hci_mode,
                                                         tHCI_MODE hci_mode,
@@ -350,7 +350,7 @@ struct sACL_CONN {


     private:
     private:
      bool pending_{false};
      bool pending_{false};
      friend tBTM_STATUS bluetooth::shim::BTM_SetSsrParams(sACL_CONN& p_acl,
      friend tBTM_STATUS bluetooth::shim::BTM_SetSsrParams(uint16_t handle,
                                                           uint16_t max_lat,
                                                           uint16_t max_lat,
                                                           uint16_t min_rmt_to,
                                                           uint16_t min_rmt_to,
                                                           uint16_t min_loc_to);
                                                           uint16_t min_loc_to);
@@ -398,7 +398,6 @@ struct sACL_CB {
                                      uint16_t hci_handle, tHCI_MODE mode,
                                      uint16_t hci_handle, tHCI_MODE mode,
                                      uint16_t interval);
                                      uint16_t interval);
  friend void btm_pm_proc_ssr_evt(uint8_t* p, uint16_t evt_len);
  friend void btm_pm_proc_ssr_evt(uint8_t* p, uint16_t evt_len);
  friend void btm_pm_reset(void);
  friend void DumpsysL2cap(int fd);
  friend void DumpsysL2cap(int fd);
  friend void DumpsysAcl(int fd);
  friend void DumpsysAcl(int fd);


@@ -416,10 +415,6 @@ struct sACL_CB {
  uint16_t DefaultPacketTypes() const { return btm_acl_pkt_types_supported; }
  uint16_t DefaultPacketTypes() const { return btm_acl_pkt_types_supported; }
  uint16_t DefaultLinkPolicy() const { return btm_def_link_policy; }
  uint16_t DefaultLinkPolicy() const { return btm_def_link_policy; }


  tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS + 1]; /* per application/module */

  uint8_t pm_pend_id{0}; /* the id pf the module, which has a pending PM cmd */

  struct {
  struct {
    std::vector<tBTM_PM_STATUS_CBACK*> clients;
    std::vector<tBTM_PM_STATUS_CBACK*> clients;
  } link_policy;
  } link_policy;
+43 −52
Original line number Original line Diff line number Diff line
@@ -42,7 +42,6 @@
#include "main/shim/shim.h"
#include "main/shim/shim.h"
#include "osi/include/log.h"
#include "osi/include/log.h"
#include "stack/btm/btm_int_types.h"
#include "stack/btm/btm_int_types.h"
#include "stack/include/acl_api.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_api.h"
#include "stack/include/btm_api_types.h"
#include "stack/include/btm_api_types.h"
#include "stack/include/btm_status.h"
#include "stack/include/btm_status.h"
@@ -50,7 +49,7 @@


void l2c_OnHciModeChangeSendPendingPackets(RawAddress remote);
void l2c_OnHciModeChangeSendPendingPackets(RawAddress remote);
void btm_sco_chk_pend_unpark(tHCI_STATUS status, uint16_t handle);
void btm_sco_chk_pend_unpark(tHCI_STATUS status, uint16_t handle);

void btm_cont_rswitch_from_handle(uint16_t hci_handle);
extern tBTM_CB btm_cb;
extern tBTM_CB btm_cb;


namespace {
namespace {
@@ -67,6 +66,10 @@ tBTM_PM_MCB* btm_pm_get_power_manager_from_address(const RawAddress& bda) {
  return nullptr;
  return nullptr;
}
}


tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS + 1]; /* per application/module */

uint8_t pm_pend_id = 0; /* the id pf the module, which has a pending PM cmd */

constexpr char kBtmLogTag[] = "ACL";
constexpr char kBtmLogTag[] = "ACL";
}
}


@@ -79,9 +82,6 @@ constexpr char kBtmLogTag[] = "ACL";
#define BTM_PM_GET_MD2 2
#define BTM_PM_GET_MD2 2
#define BTM_PM_GET_COMP 3
#define BTM_PM_GET_COMP 3


tACL_CONN* acl_get_connection_from_address(const RawAddress& bd_addr,
                                           tBT_TRANSPORT transport);

const uint8_t
const uint8_t
    btm_pm_md_comp_matrix[BTM_PM_NUM_SET_MODES * BTM_PM_NUM_SET_MODES] = {
    btm_pm_md_comp_matrix[BTM_PM_NUM_SET_MODES * BTM_PM_NUM_SET_MODES] = {
        BTM_PM_GET_COMP, BTM_PM_GET_MD2,  BTM_PM_GET_MD2,
        BTM_PM_GET_COMP, BTM_PM_GET_MD2,  BTM_PM_GET_MD2,
@@ -139,19 +139,19 @@ tBTM_STATUS BTM_PmRegister(uint8_t mask, uint8_t* p_pm_id,
  /* de-register */
  /* de-register */
  if (mask & BTM_PM_DEREG) {
  if (mask & BTM_PM_DEREG) {
    if (*p_pm_id >= BTM_MAX_PM_RECORDS) return BTM_ILLEGAL_VALUE;
    if (*p_pm_id >= BTM_MAX_PM_RECORDS) return BTM_ILLEGAL_VALUE;
    btm_cb.acl_cb_.pm_reg_db[*p_pm_id].mask = BTM_PM_REC_NOT_USED;
    pm_reg_db[*p_pm_id].mask = BTM_PM_REC_NOT_USED;
    return BTM_SUCCESS;
    return BTM_SUCCESS;
  }
  }


  for (int xx = 0; xx < BTM_MAX_PM_RECORDS; xx++) {
  for (int xx = 0; xx < BTM_MAX_PM_RECORDS; xx++) {
    /* find an unused entry */
    /* find an unused entry */
    if (btm_cb.acl_cb_.pm_reg_db[xx].mask == BTM_PM_REC_NOT_USED) {
    if (pm_reg_db[xx].mask == BTM_PM_REC_NOT_USED) {
      /* if register for notification, should provide callback routine */
      /* if register for notification, should provide callback routine */
      if (mask & BTM_PM_REG_NOTIF) {
      if (mask & BTM_PM_REG_NOTIF) {
        if (p_cb == NULL) return BTM_ILLEGAL_VALUE;
        if (p_cb == NULL) return BTM_ILLEGAL_VALUE;
        btm_cb.acl_cb_.pm_reg_db[xx].cback = p_cb;
        pm_reg_db[xx].cback = p_cb;
      }
      }
      btm_cb.acl_cb_.pm_reg_db[xx].mask = mask;
      pm_reg_db[xx].mask = mask;
      *p_pm_id = xx;
      *p_pm_id = xx;
      return BTM_SUCCESS;
      return BTM_SUCCESS;
    }
    }
@@ -190,12 +190,14 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda,
    return BTM_ILLEGAL_VALUE;
    return BTM_ILLEGAL_VALUE;
  }
  }


  tACL_CONN* p_acl =
  // per ACL link
      acl_get_connection_from_address(remote_bda, BT_TRANSPORT_BR_EDR);
  auto* p_cb = btm_pm_get_power_manager_from_address(remote_bda);
  if (p_acl == nullptr) {
  if (p_cb == nullptr) {
    LOG_WARN("Unable to find acl");
    LOG_WARN("Unable to find power manager for peer: %s",
    return BTM_UNKNOWN_ADDR;
             PRIVATE_ADDRESS(remote_bda));
    return false;
  }
  }
  uint16_t handle = p_cb->handle_;


  tBTM_PM_MODE mode = p_mode->mode;
  tBTM_PM_MODE mode = p_mode->mode;
  if (!is_legal_power_mode(mode)) {
  if (!is_legal_power_mode(mode)) {
@@ -212,15 +214,7 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda,
  if (bluetooth::shim::is_gd_link_policy_enabled()) {
  if (bluetooth::shim::is_gd_link_policy_enabled()) {
    tBTM_PM_PWR_MD power_mode_request = *p_mode;
    tBTM_PM_PWR_MD power_mode_request = *p_mode;
    power_mode_request.mode &= (~BTM_PM_MD_FORCE);
    power_mode_request.mode &= (~BTM_PM_MD_FORCE);
    return bluetooth::shim::BTM_SetPowerMode(*p_acl, power_mode_request);
    return bluetooth::shim::BTM_SetPowerMode(handle, power_mode_request);
  }

  // per ACL link
  uint16_t handle = p_acl->Handle();
  auto* p_cb = btm_pm_get_power_manager_from_address(remote_bda);
  if (p_cb == nullptr) {
    LOG_WARN("Unable to find acl for %s", PRIVATE_ADDRESS(remote_bda));
    return false;
  }
  }


  if (mode != BTM_PM_MD_ACTIVE) {
  if (mode != BTM_PM_MD_ACTIVE) {
@@ -258,10 +252,10 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda,


  /* update mode database */
  /* update mode database */
  if (((pm_id != BTM_PM_SET_ONLY_ID) &&
  if (((pm_id != BTM_PM_SET_ONLY_ID) &&
       (btm_cb.acl_cb_.pm_reg_db[pm_id].mask & BTM_PM_REG_SET)) ||
       (pm_reg_db[pm_id].mask & BTM_PM_REG_SET)) ||
      ((pm_id == BTM_PM_SET_ONLY_ID) && (pm_pend_link != 0))) {
      ((pm_id == BTM_PM_SET_ONLY_ID) && (pm_pend_link != 0))) {
    /* Make sure mask is set to BTM_PM_REG_SET */
    /* Make sure mask is set to BTM_PM_REG_SET */
    btm_cb.acl_cb_.pm_reg_db[temp_pm_id].mask |= BTM_PM_REG_SET;
    pm_reg_db[temp_pm_id].mask |= BTM_PM_REG_SET;
    *(&p_cb->req_mode[temp_pm_id]) = *p_mode;
    *(&p_cb->req_mode[temp_pm_id]) = *p_mode;
    p_cb->chg_ind = true;
    p_cb->chg_ind = true;
  }
  }
@@ -338,16 +332,15 @@ bool BTM_ReadPowerMode(const RawAddress& remote_bda, tBTM_PM_MODE* p_mode) {
 ******************************************************************************/
 ******************************************************************************/
tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda, uint16_t max_lat,
tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda, uint16_t max_lat,
                             uint16_t min_rmt_to, uint16_t min_loc_to) {
                             uint16_t min_rmt_to, uint16_t min_loc_to) {
  tACL_CONN* p_acl =
  tBTM_PM_MCB* p_cb = btm_pm_get_power_manager_from_address(remote_bda);
      acl_get_connection_from_address(remote_bda, BT_TRANSPORT_BR_EDR);
  if (p_cb == nullptr) {
  if (p_acl == nullptr || pm_mode_db.count(p_acl->Handle()) == 0) {
    LOG_WARN("Unable to find power manager for peer:%s",
    LOG_WARN("Unable to find acl for peer:%s", PRIVATE_ADDRESS(remote_bda));
             PRIVATE_ADDRESS(remote_bda));
    return BTM_UNKNOWN_ADDR;
    return BTM_UNKNOWN_ADDR;
  }
  }
  tBTM_PM_MCB* p_cb = &pm_mode_db[p_acl->Handle()];


  if (bluetooth::shim::is_gd_link_policy_enabled()) {
  if (bluetooth::shim::is_gd_link_policy_enabled()) {
    return bluetooth::shim::BTM_SetSsrParams(*p_acl, max_lat, min_rmt_to,
    return bluetooth::shim::BTM_SetSsrParams(p_cb->handle_, max_lat, min_rmt_to,
                                             min_loc_to);
                                             min_loc_to);
  }
  }


@@ -358,7 +351,7 @@ tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda, uint16_t max_lat,
        " min_local_timeout:0x%04x",
        " min_local_timeout:0x%04x",
        power_mode_state_text(p_cb->state).c_str(), p_cb->state, max_lat,
        power_mode_state_text(p_cb->state).c_str(), p_cb->state, max_lat,
        min_rmt_to, min_loc_to);
        min_rmt_to, min_loc_to);
    send_sniff_subrating(p_acl->Handle(), remote_bda, max_lat, min_rmt_to,
    send_sniff_subrating(p_cb->handle_, remote_bda, max_lat, min_rmt_to,
                         min_loc_to);
                         min_loc_to);
    return BTM_SUCCESS;
    return BTM_SUCCESS;
  }
  }
@@ -383,15 +376,14 @@ void btm_pm_reset(void) {
  tBTM_PM_STATUS_CBACK* cb = NULL;
  tBTM_PM_STATUS_CBACK* cb = NULL;


  /* clear the pending request for application */
  /* clear the pending request for application */
  if ((btm_cb.acl_cb_.pm_pend_id != BTM_PM_SET_ONLY_ID) &&
  if ((pm_pend_id != BTM_PM_SET_ONLY_ID) &&
      (btm_cb.acl_cb_.pm_reg_db[btm_cb.acl_cb_.pm_pend_id].mask &
      (pm_reg_db[pm_pend_id].mask & BTM_PM_REG_NOTIF)) {
       BTM_PM_REG_NOTIF)) {
    cb = pm_reg_db[pm_pend_id].cback;
    cb = btm_cb.acl_cb_.pm_reg_db[btm_cb.acl_cb_.pm_pend_id].cback;
  }
  }


  /* clear the register record */
  /* clear the register record */
  for (xx = 0; xx < BTM_MAX_PM_RECORDS; xx++) {
  for (xx = 0; xx < BTM_MAX_PM_RECORDS; xx++) {
    btm_cb.acl_cb_.pm_reg_db[xx].mask = BTM_PM_REC_NOT_USED;
    pm_reg_db[xx].mask = BTM_PM_REC_NOT_USED;
  }
  }


  if (cb != NULL && pm_pend_link != 0) {
  if (cb != NULL && pm_pend_link != 0) {
@@ -401,6 +393,8 @@ void btm_pm_reset(void) {
  /* no command pending */
  /* no command pending */
  pm_pend_link = 0;
  pm_pend_link = 0;
  pm_mode_db.clear();
  pm_mode_db.clear();
  pm_pend_id = 0;
  memset(&pm_reg_db, 0, sizeof(pm_reg_db));
  LOG_INFO("reset pm");
  LOG_INFO("reset pm");
}
}


@@ -502,7 +496,7 @@ static tBTM_PM_MODE btm_pm_get_set_mode(uint8_t pm_id, tBTM_PM_MCB* p_cb,


  for (xx = 0; xx < loop_max; xx++) {
  for (xx = 0; xx < loop_max; xx++) {
    /* g through all the registered "set" parties */
    /* g through all the registered "set" parties */
    if (btm_cb.acl_cb_.pm_reg_db[xx].mask & BTM_PM_REG_SET) {
    if (pm_reg_db[xx].mask & BTM_PM_REG_SET) {
      if (p_cb->req_mode[xx].mode == BTM_PM_MD_ACTIVE) {
      if (p_cb->req_mode[xx].mode == BTM_PM_MD_ACTIVE) {
        /* if at least one registered (SET) party says ACTIVE, stay active */
        /* if at least one registered (SET) party says ACTIVE, stay active */
        return BTM_PM_MD_ACTIVE;
        return BTM_PM_MD_ACTIVE;
@@ -591,7 +585,7 @@ static tBTM_STATUS btm_pm_snd_md_req(uint16_t handle, uint8_t pm_id,
  pm_pend_link = 0;
  pm_pend_link = 0;


  /* send the appropriate HCI command */
  /* send the appropriate HCI command */
  btm_cb.acl_cb_.pm_pend_id = pm_id;
  pm_pend_id = pm_id;


  LOG_INFO("Switching from %s[0x%02x] to %s[0x%02x]",
  LOG_INFO("Switching from %s[0x%02x] to %s[0x%02x]",
           power_mode_state_text(p_cb->state).c_str(), p_cb->state,
           power_mode_state_text(p_cb->state).c_str(), p_cb->state,
@@ -676,14 +670,12 @@ void btm_pm_proc_cmd_status(tHCI_STATUS status) {
  }
  }


  /* notify the caller is appropriate */
  /* notify the caller is appropriate */
  if ((btm_cb.acl_cb_.pm_pend_id != BTM_PM_SET_ONLY_ID) &&
  if ((pm_pend_id != BTM_PM_SET_ONLY_ID) &&
      (btm_cb.acl_cb_.pm_reg_db[btm_cb.acl_cb_.pm_pend_id].mask &
      (pm_reg_db[pm_pend_id].mask & BTM_PM_REG_NOTIF)) {
       BTM_PM_REG_NOTIF)) {
    const RawAddress bd_addr = pm_mode_db[pm_pend_link].bda_;
    const RawAddress bd_addr = pm_mode_db[pm_pend_link].bda_;
    LOG_DEBUG("Notifying callback that link power mode is complete peer:%s",
    LOG_DEBUG("Notifying callback that link power mode is complete peer:%s",
              PRIVATE_ADDRESS(bd_addr));
              PRIVATE_ADDRESS(bd_addr));
    (*btm_cb.acl_cb_.pm_reg_db[btm_cb.acl_cb_.pm_pend_id].cback)(
    (*pm_reg_db[pm_pend_id].cback)(bd_addr, pm_status, 0, status);
        bd_addr, pm_status, 0, status);
  }
  }


  LOG_INFO("Clearing pending power mode link state:%s",
  LOG_INFO("Clearing pending power mode link state:%s",
@@ -766,9 +758,8 @@ void btm_pm_proc_mode_change(tHCI_STATUS hci_status, uint16_t hci_handle,


  /* notify registered parties */
  /* notify registered parties */
  for (int yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) {
  for (int yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) {
    if (btm_cb.acl_cb_.pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) {
    if (pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) {
      (*btm_cb.acl_cb_.pm_reg_db[yy].cback)(p_cb->bda_, mode, interval,
      (*pm_reg_db[yy].cback)(p_cb->bda_, mode, interval, hci_status);
                                            hci_status);
    }
    }
  }
  }
  /*check if sco disconnect  is waiting for the mode change */
  /*check if sco disconnect  is waiting for the mode change */
@@ -807,9 +798,9 @@ void process_ssr_event(tHCI_STATUS status, uint16_t handle,


  int cnt = 0;
  int cnt = 0;
  for (int yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) {
  for (int yy = 0; yy < BTM_MAX_PM_RECORDS; yy++) {
    if (btm_cb.acl_cb_.pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) {
    if (pm_reg_db[yy].mask & BTM_PM_REG_NOTIF) {
      (*btm_cb.acl_cb_.pm_reg_db[yy].cback)(bd_addr, BTM_PM_STS_SSR,
      (*pm_reg_db[yy].cback)(bd_addr, BTM_PM_STS_SSR, (use_ssr) ? 1 : 0,
                                            (use_ssr) ? 1 : 0, status);
                             status);
      cnt++;
      cnt++;
    }
    }
  }
  }
@@ -858,7 +849,7 @@ void btm_pm_proc_ssr_evt(uint8_t* p, UNUSED_ATTR uint16_t evt_len) {
 * Returns          true, if in active or sniff mode
 * Returns          true, if in active or sniff mode
 *
 *
 ******************************************************************************/
 ******************************************************************************/
bool btm_pm_device_in_active_or_sniff_mode(void) {
static bool btm_pm_device_in_active_or_sniff_mode(void) {
  /* The active state is the highest state-includes connected device and sniff
  /* The active state is the highest state-includes connected device and sniff
   * mode*/
   * mode*/


@@ -886,7 +877,7 @@ bool btm_pm_device_in_active_or_sniff_mode(void) {
 * Returns          true, if in paging, inquiry or connecting mode
 * Returns          true, if in paging, inquiry or connecting mode
 *
 *
 ******************************************************************************/
 ******************************************************************************/
bool btm_pm_device_in_scan_state(void) {
static bool btm_pm_device_in_scan_state(void) {
  /* Scan state-paging, inquiry, and trying to connect */
  /* Scan state-paging, inquiry, and trying to connect */


  /* Check for paging */
  /* Check for paging */
+2 −3
Original line number Original line Diff line number Diff line
@@ -441,8 +441,7 @@ void btm_api_process_inquiry_result_with_rssi(RawAddress raw_address,
                                              int8_t rssi) {
                                              int8_t rssi) {
  mock_function_count_map[__func__]++;
  mock_function_count_map[__func__]++;
}
}
tBTM_STATUS bluetooth::shim::BTM_SetPowerMode(tACL_CONN&,
tBTM_STATUS bluetooth::shim::BTM_SetPowerMode(uint16_t, tBTM_PM_PWR_MD const&) {
                                              tBTM_PM_PWR_MD const&) {
  mock_function_count_map[__func__]++;
  mock_function_count_map[__func__]++;
  return BTM_SUCCESS;
  return BTM_SUCCESS;
}
}
@@ -451,7 +450,7 @@ void bluetooth::shim::btm_pm_on_mode_change(tHCI_STATUS status, uint16_t handle,
                                            uint16_t interval) {
                                            uint16_t interval) {
  mock_function_count_map[__func__]++;
  mock_function_count_map[__func__]++;
}
}
tBTM_STATUS bluetooth::shim::BTM_SetSsrParams(tACL_CONN&, uint16_t max_lat,
tBTM_STATUS bluetooth::shim::BTM_SetSsrParams(uint16_t, uint16_t max_lat,
                                              uint16_t min_rmt_to,
                                              uint16_t min_rmt_to,
                                              uint16_t min_loc_to) {
                                              uint16_t min_loc_to) {
  mock_function_count_map[__func__]++;
  mock_function_count_map[__func__]++;