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

Commit d39aab17 authored by Chris Manton's avatar Chris Manton
Browse files

Move btm_cb.pm_mode_db to btm_cb.acl_cb_.pm_mode_db

The btm power modes are implemented on a per
ACL link basis, so moving it to acl.

Working towards encapsulation of tACL_CONN

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I102fd14b2835f2f398fe371b5853071641b37986
parent 5d7732a7
Loading
Loading
Loading
Loading
+18 −0
Original line number Diff line number Diff line
@@ -79,6 +79,23 @@ typedef struct {

} tACL_CONN;

typedef uint8_t tBTM_PM_STATE;
typedef struct {
  tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS + 1]; /* the desired mode and
                                                      parameters of the
                                                      connection*/
  tBTM_PM_PWR_MD
      set_mode; /* the mode and parameters sent down to the host controller. */
  uint16_t interval; /* the interval from last mode change event. */
#if (BTM_SSR_INCLUDED == TRUE)
  uint16_t max_lat;    /* stored SSR maximum latency */
  uint16_t min_rmt_to; /* stored SSR minimum remote timeout */
  uint16_t min_loc_to; /* stored SSR minimum local timeout */
#endif
  tBTM_PM_STATE state; /* contains the current mode of the connection */
  bool chg_ind;        /* a request change indication */
} tBTM_PM_MCB;

typedef struct {
  /****************************************************
   **      ACL Management
@@ -94,4 +111,5 @@ typedef struct {
  uint16_t btm_acl_pkt_types_supported;

  uint8_t acl_disc_reason;
  tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS]; /* per ACL link */
} tACL_CB;  // NEW
+2 −2
Original line number Diff line number Diff line
@@ -2435,7 +2435,7 @@ void btm_acl_chk_peer_pkt_type_support(tACL_CONN* p, uint16_t* p_pkt_type) {
 *
 ******************************************************************************/
void btm_pm_sm_alloc(uint8_t ind) {
  tBTM_PM_MCB* p_db = &btm_cb.pm_mode_db[ind]; /* per ACL link */
  tBTM_PM_MCB* p_db = &btm_cb.acl_cb_.pm_mode_db[ind]; /* per ACL link */
  memset(p_db, 0, sizeof(tBTM_PM_MCB));
  p_db->state = BTM_PM_ST_ACTIVE;
#if (BTM_PM_DEBUG == TRUE)
@@ -2567,7 +2567,7 @@ tBTM_PM_MCB* acl_power_mode_from_handle(uint16_t hci_handle) {
  if (index >= MAX_L2CAP_LINKS) {
    return nullptr;
  }
  return &btm_cb.pm_mode_db[index];
  return &btm_cb.acl_cb_.pm_mode_db[index];
}

/*******************************************************************************
+13 −13
Original line number Diff line number Diff line
@@ -160,7 +160,7 @@ tBTM_STATUS BTM_SetPowerMode(uint8_t pm_id, const RawAddress& remote_bda,
  acl_ind = btm_pm_find_acl_ind(remote_bda);
  if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR);

  p_cb = &(btm_cb.pm_mode_db[acl_ind]);
  p_cb = &(btm_cb.acl_cb_.pm_mode_db[acl_ind]);

  if (mode != BTM_PM_MD_ACTIVE) {
    const controller_t* controller = controller_get_interface();
@@ -254,7 +254,7 @@ tBTM_STATUS BTM_ReadPowerMode(const RawAddress& remote_bda,
  acl_ind = btm_pm_find_acl_ind(remote_bda);
  if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR);

  *p_mode = btm_cb.pm_mode_db[acl_ind].state;
  *p_mode = btm_cb.acl_cb_.pm_mode_db[acl_ind].state;
  return BTM_SUCCESS;
}

@@ -285,7 +285,7 @@ tBTM_STATUS btm_read_power_mode_state(const RawAddress& remote_bda,

  if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR);

  *pmState = btm_cb.pm_mode_db[acl_ind].state;
  *pmState = btm_cb.acl_cb_.pm_mode_db[acl_ind].state;
  return BTM_SUCCESS;
}

@@ -316,13 +316,13 @@ tBTM_STATUS BTM_SetSsrParams(const RawAddress& remote_bda, uint16_t max_lat,
  acl_ind = btm_pm_find_acl_ind(remote_bda);
  if (acl_ind == MAX_L2CAP_LINKS) return (BTM_UNKNOWN_ADDR);

  if (BTM_PM_STS_ACTIVE == btm_cb.pm_mode_db[acl_ind].state ||
      BTM_PM_STS_SNIFF == btm_cb.pm_mode_db[acl_ind].state) {
  if (BTM_PM_STS_ACTIVE == btm_cb.acl_cb_.pm_mode_db[acl_ind].state ||
      BTM_PM_STS_SNIFF == btm_cb.acl_cb_.pm_mode_db[acl_ind].state) {
    btsnd_hcic_sniff_sub_rate(btm_cb.acl_cb_.acl_db[acl_ind].hci_handle,
                              max_lat, min_rmt_to, min_loc_to);
    return BTM_SUCCESS;
  }
  p_cb = &btm_cb.pm_mode_db[acl_ind];
  p_cb = &btm_cb.acl_cb_.pm_mode_db[acl_ind];
  p_cb->max_lat = max_lat;
  p_cb->min_rmt_to = min_rmt_to;
  p_cb->min_loc_to = min_loc_to;
@@ -505,7 +505,7 @@ static tBTM_STATUS btm_pm_snd_md_req(uint8_t pm_id, int link_ind,
                                     const tBTM_PM_PWR_MD* p_mode) {
  tBTM_PM_PWR_MD md_res;
  tBTM_PM_MODE mode;
  tBTM_PM_MCB* p_cb = &btm_cb.pm_mode_db[link_ind];
  tBTM_PM_MCB* p_cb = &btm_cb.acl_cb_.pm_mode_db[link_ind];
  bool chg_ind = false;

  mode = btm_pm_get_set_mode(pm_id, p_cb, p_mode, &md_res);
@@ -618,8 +618,8 @@ static tBTM_STATUS btm_pm_snd_md_req(uint8_t pm_id, int link_ind,
static void btm_pm_check_stored(void) {
  int xx;
  for (xx = 0; xx < MAX_L2CAP_LINKS; xx++) {
    if (btm_cb.pm_mode_db[xx].state & BTM_PM_STORED_MASK) {
      btm_cb.pm_mode_db[xx].state &= ~BTM_PM_STORED_MASK;
    if (btm_cb.acl_cb_.pm_mode_db[xx].state & BTM_PM_STORED_MASK) {
      btm_cb.acl_cb_.pm_mode_db[xx].state &= ~BTM_PM_STORED_MASK;
      BTM_TRACE_DEBUG("btm_pm_check_stored :%d", xx);
      btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, xx, NULL);
      break;
@@ -645,7 +645,7 @@ void btm_pm_proc_cmd_status(uint8_t status) {

  if (btm_cb.acl_cb_.pm_pend_link >= MAX_L2CAP_LINKS) return;

  p_cb = &btm_cb.pm_mode_db[btm_cb.acl_cb_.pm_pend_link];
  p_cb = &btm_cb.acl_cb_.pm_mode_db[btm_cb.acl_cb_.pm_pend_link];

  if (status == HCI_SUCCESS) {
    p_cb->state = BTM_PM_ST_PENDING;
@@ -707,7 +707,7 @@ void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle,
  const RawAddress bd_addr = acl_address_from_handle(hci_handle);

  /* update control block */
  p_cb = &(btm_cb.pm_mode_db[xx]);
  p_cb = &(btm_cb.acl_cb_.pm_mode_db[xx]);
  old_state = p_cb->state;
  p_cb->state = mode;
  p_cb->interval = interval;
@@ -735,7 +735,7 @@ void btm_pm_proc_mode_change(uint8_t hci_status, uint16_t hci_handle,
    btm_pm_snd_md_req(BTM_PM_SET_ONLY_ID, xx, NULL);
  } else {
    for (zz = 0; zz < MAX_L2CAP_LINKS; zz++) {
      if (btm_cb.pm_mode_db[zz].chg_ind) {
      if (btm_cb.acl_cb_.pm_mode_db[zz].chg_ind) {
#if (BTM_PM_DEBUG == TRUE)
        BTM_TRACE_DEBUG("btm_pm_proc_mode_change: Sending PM req :%d", zz);
#endif  // BTM_PM_DEBUG
@@ -786,7 +786,7 @@ void btm_pm_proc_ssr_evt(uint8_t* p, UNUSED_ATTR uint16_t evt_len) {

  p += 2;
  STREAM_TO_UINT16(max_rx_lat, p);
  p_cb = &(btm_cb.pm_mode_db[xx]);
  p_cb = &(btm_cb.acl_cb_.pm_mode_db[xx]);

  const RawAddress bd_addr = acl_address_from_handle(handle);
  if (bd_addr == RawAddress::kEmpty) {
+0 −18
Original line number Diff line number Diff line
@@ -517,23 +517,6 @@ enum {
  BTM_PM_ST_PENDING = BTM_PM_STS_PENDING,
  BTM_PM_ST_INVALID = 0xFF
};
typedef uint8_t tBTM_PM_STATE;

typedef struct {
  tBTM_PM_PWR_MD req_mode[BTM_MAX_PM_RECORDS + 1]; /* the desired mode and
                                                      parameters of the
                                                      connection*/
  tBTM_PM_PWR_MD
      set_mode; /* the mode and parameters sent down to the host controller. */
  uint16_t interval; /* the interval from last mode change event. */
#if (BTM_SSR_INCLUDED == TRUE)
  uint16_t max_lat;    /* stored SSR maximum latency */
  uint16_t min_rmt_to; /* stored SSR minimum remote timeout */
  uint16_t min_loc_to; /* stored SSR minimum local timeout */
#endif
  tBTM_PM_STATE state; /* contains the current mode of the connection */
  bool chg_ind;        /* a request change indication */
} tBTM_PM_MCB;

#define BTM_PM_REC_NOT_USED 0
typedef struct {
@@ -606,7 +589,6 @@ typedef struct {
  /****************************************************
  **      Power Management
  ****************************************************/
  tBTM_PM_MCB pm_mode_db[MAX_L2CAP_LINKS];       /* per ACL link */
  tBTM_PM_RCB pm_reg_db[BTM_MAX_PM_RECORDS + 1]; /* per application/module */

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