From: Hansong Zhang Date: Wed, 4 Nov 2020 22:46:14 +0000 (-0800) Subject: Refactor BTM_SwitchRole X-Git-Url: http://git.osdn.net/view?a=commitdiff_plain;h=133c4b7067db1b3e030b14f9d5a15aea850181e0;p=android-x86%2Fsystem-bt.git Refactor BTM_SwitchRole We always want to switch to central. Bug: 159815595 Tag: #refactor Test: compile & verify basic functions working Change-Id: I945720e2e55f32cc15bd1e4c09b5b11d26fc7f4a --- diff --git a/bta/av/bta_av_main.cc b/bta/av/bta_av_main.cc index aa85851d2..2f7d14449 100644 --- a/bta/av/bta_av_main.cc +++ b/bta/av/bta_av_main.cc @@ -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; diff --git a/bta/dm/bta_dm_act.cc b/bta/dm/bta_dm_act.cc index 941ed0d91..17429c695 100644 --- a/bta/dm/bta_dm_act.cc +++ b/bta/dm/bta_dm_act.cc @@ -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, diff --git a/stack/acl/acl.h b/stack/acl/acl.h index 86e0353c9..168c9a66e 100644 --- a/stack/acl/acl.h +++ b/stack/acl/acl.h @@ -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 */ diff --git a/stack/acl/btm_acl.cc b/stack/acl/btm_acl.cc index 9841314d0..abf79efaf 100644 --- a/stack/acl/btm_acl.cc +++ b/stack/acl/btm_acl.cc @@ -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; } diff --git a/stack/include/acl_api.h b/stack/include/acl_api.h index 06d83889b..32fccffe2 100644 --- a/stack/include/acl_api.h +++ b/stack/include/acl_api.h @@ -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); /******************************************************************************* * diff --git a/stack/l2cap/l2c_utils.cc b/stack/l2cap/l2c_utils.cc index b7b2bbccb..95b566eae 100644 --- a/stack/l2cap/l2c_utils.cc +++ b/stack/l2cap/l2c_utils.cc @@ -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,