OSDN Git Service

Refactor BTM_SwitchRole
authorHansong Zhang <hsz@google.com>
Wed, 4 Nov 2020 22:46:14 +0000 (14:46 -0800)
committerHansong Zhang <hsz@google.com>
Thu, 5 Nov 2020 19:59:22 +0000 (11:59 -0800)
We always want to switch to central.

Bug: 159815595
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I945720e2e55f32cc15bd1e4c09b5b11d26fc7f4a

bta/av/bta_av_main.cc
bta/dm/bta_dm_act.cc
stack/acl/acl.h
stack/acl/btm_acl.cc
stack/include/acl_api.h
stack/l2cap/l2c_utils.cc

index aa85851..2f7d144 100644 (file)
@@ -1015,12 +1015,12 @@ 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",
-                  __func__, p_scb->PeerAddress().ToString().c_str(), status);
+        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) {
         is_ok = false;
index 941ed0d..17429c6 100644 (file)
@@ -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,
index 86e0353..168c9a6 100644 (file)
@@ -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 */
index 9841314..abf79ef 100644 (file)
@@ -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;
     }
index 06d8388..32fccff 100644 (file)
@@ -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);
 
 /*******************************************************************************
  *
index b7b2bbc..95b566e 100644 (file)
@@ -2069,7 +2069,7 @@ void l2cu_create_conn_br_edr(tL2C_LCB* p_lcb) {
       p_lcb->link_state = LST_CONNECTING_WAIT_SWITCH;
       p_lcb->SetLinkRoleAsCentral();
 
-      if (BTM_SwitchRole(p_lcb_cur->remote_bd_addr, HCI_ROLE_CENTRAL) ==
+      if (BTM_SwitchRoleToCentral(p_lcb_cur->remote_bd_addr) ==
           BTM_CMD_STARTED) {
         alarm_set_on_mloop(p_lcb->l2c_lcb_timer,
                            L2CAP_LINK_ROLE_SWITCH_TIMEOUT_MS,