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

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

Refactor BTM_SwitchRole am: b64b0a7f

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

Change-Id: I58778c757a1096201adeab5869df9898ea428ed0
parents b5413a99 b64b0a7f
Loading
Loading
Loading
Loading
+4 −4
Original line number Diff line number Diff line
@@ -1015,11 +1015,11 @@ bool bta_av_link_role_ok(tBTA_AV_SCB* p_scb, uint8_t bits) {
      if (bta_av_cb.features & BTA_AV_FEAT_CENTRAL)
        BTM_block_role_switch_for(p_scb->PeerAddress());

      tBTM_STATUS status =
          BTM_SwitchRole(p_scb->PeerAddress(), HCI_ROLE_CENTRAL);
      tBTM_STATUS status = BTM_SwitchRoleToCentral(p_scb->PeerAddress());
      if (status != BTM_CMD_STARTED) {
        /* can not switch role on SCB - start the timer on SCB */
        LOG_ERROR("%s: peer %s BTM_SwitchRole(HCI_ROLE_CENTRAL) error: %d",
        LOG_ERROR(
            "%s: peer %s BTM_SwitchRoleToCentral(HCI_ROLE_CENTRAL) error: %d",
            __func__, p_scb->PeerAddress().ToString().c_str(), status);
      }
      if (status != BTM_MODE_UNSUPPORTED && status != BTM_DEV_BLACKLISTED) {
+4 −4
Original line number Diff line number Diff line
@@ -2161,7 +2161,7 @@ static void handle_role_change(const RawAddress& bd_addr, uint8_t new_role,
      /* more than one connections and the AV connection is role switched
       * to peripheral
       * switch it back to central and remove the switch policy */
      BTM_SwitchRole(bd_addr, HCI_ROLE_CENTRAL);
      BTM_SwitchRoleToCentral(bd_addr);
      need_policy_change = true;
    } else if (p_bta_dm_cfg->avoid_scatter && (new_role == HCI_ROLE_CENTRAL)) {
      /* if the link updated to be central include AV activities, remove
@@ -2348,7 +2348,7 @@ static void bta_dm_check_av() {
      if ((p_dev->conn_state == BTA_DM_CONNECTED) &&
          (p_dev->info & BTA_DM_DI_AV_ACTIVE)) {
        /* make central and take away the role switch policy */
        BTM_SwitchRole(p_dev->peer_bdaddr, HCI_ROLE_CENTRAL);
        BTM_SwitchRoleToCentral(p_dev->peer_bdaddr);
        /* else either already central or can not switch for some reasons */
        BTM_block_role_switch_for(p_dev->peer_bdaddr);
        break;
@@ -2544,8 +2544,8 @@ static void bta_dm_adjust_roles(bool delay_role_switch) {
          if (bta_dm_cb.device_list.peer_device[i].pref_role !=
                  BTA_PERIPHERAL_ROLE_ONLY &&
              !delay_role_switch) {
            BTM_SwitchRole(bta_dm_cb.device_list.peer_device[i].peer_bdaddr,
                           HCI_ROLE_CENTRAL);
            BTM_SwitchRoleToCentral(
                bta_dm_cb.device_list.peer_device[i].peer_bdaddr);
          } else {
            alarm_set_on_mloop(bta_dm_cb.switch_delay_timer,
                               BTA_DM_SWITCH_DELAY_TIMER_MS,
+1 −1
Original line number Diff line number Diff line
@@ -43,7 +43,7 @@ enum btm_acl_swkey_state_t {
};

/* Structure returned with Role Switch information (in tBTM_CMPL_CB callback
 * function) in response to BTM_SwitchRole call.
 * function) in response to BTM_SwitchRoleToCentral call.
 */
typedef struct {
  RawAddress remote_bd_addr; /* Remote BD addr involved with the switch */
+4 −4
Original line number Diff line number Diff line
@@ -455,7 +455,7 @@ tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, uint8_t* p_role) {

/*******************************************************************************
 *
 * Function         BTM_SwitchRole
 * Function         BTM_SwitchRoleToCentral
 *
 * Description      This function is called to switch role between central and
 *                  peripheral.  If role is already set it will do nothing.
@@ -470,7 +470,7 @@ tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, uint8_t* p_role) {
 *                  BTM_BUSY if the previous command is not completed
 *
 ******************************************************************************/
tBTM_STATUS BTM_SwitchRole(const RawAddress& remote_bd_addr, uint8_t new_role) {
tBTM_STATUS BTM_SwitchRoleToCentral(const RawAddress& remote_bd_addr) {
  if (!controller_get_interface()->supports_central_peripheral_role_switch()) {
    LOG_INFO("Local controller does not support role switching");
    return BTM_MODE_UNSUPPORTED;
@@ -483,7 +483,7 @@ tBTM_STATUS BTM_SwitchRole(const RawAddress& remote_bd_addr, uint8_t new_role) {
    return BTM_UNKNOWN_ADDR;
  }

  if (p_acl->link_role == new_role) {
  if (p_acl->link_role == HCI_ROLE_CENTRAL) {
    LOG_INFO("Requested role is already in effect");
    return BTM_SUCCESS;
  }
@@ -530,7 +530,7 @@ tBTM_STATUS BTM_SwitchRole(const RawAddress& remote_bd_addr, uint8_t new_role) {
      p_acl->set_encryption_off();
      p_acl->set_switch_role_encryption_off();
    } else {
      btsnd_hcic_switch_role(remote_bd_addr, new_role);
      btsnd_hcic_switch_role(remote_bd_addr, HCI_ROLE_CENTRAL);
      p_acl->set_switch_role_in_progress();
      p_acl->rs_disc_pending = BTM_SEC_RS_PENDING;
    }
+2 −2
Original line number Diff line number Diff line
@@ -110,7 +110,7 @@ tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, uint8_t* p_role);

/*******************************************************************************
 *
 * Function         BTM_SwitchRole
 * Function         BTM_SwitchRoleToCentral
 *
 * Description      This function is called to switch role between central and
 *                  peripheral.  If role is already set it will do nothing.
@@ -124,7 +124,7 @@ tBTM_STATUS BTM_GetRole(const RawAddress& remote_bd_addr, uint8_t* p_role);
 *                                       role switching
 *
 ******************************************************************************/
tBTM_STATUS BTM_SwitchRole(const RawAddress& remote_bd_addr, uint8_t new_role);
tBTM_STATUS BTM_SwitchRoleToCentral(const RawAddress& remote_bd_addr);

/*******************************************************************************
 *
Loading