BTM_ACL_ENCRYPT_STATE_ENCRYPT_ON = 3,
};
+enum btm_acl_swkey_state_t {
+ BTM_ACL_SWKEY_STATE_IDLE = 0,
+ BTM_ACL_SWKEY_STATE_MODE_CHANGE = 1,
+ BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF = 2,
+ BTM_ACL_SWKEY_STATE_SWITCHING = 3,
+ BTM_ACL_SWKEY_STATE_ENCRYPTION_ON = 4,
+ BTM_ACL_SWKEY_STATE_IN_PROGRESS = 5,
+};
+
/* Structure returned with Role Switch information (in tBTM_CMPL_CB callback
* function) in response to BTM_SwitchRole call.
*/
uint8_t lmp_version;
uint8_t num_read_pages;
uint8_t switch_role_failed_attempts;
- uint8_t switch_role_state;
+
+ private:
+ uint8_t switch_role_state_;
+
+ public:
+ void reset_switch_role() { switch_role_state_ = BTM_ACL_SWKEY_STATE_IDLE; }
+ void set_switch_role_changing() {
+ switch_role_state_ = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
+ }
+ void set_switch_role_encryption_off() {
+ switch_role_state_ = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
+ }
+ void set_switch_role_encryption_on() {
+ switch_role_state_ = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
+ }
+ void set_switch_role_in_progress() {
+ switch_role_state_ = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
+ }
+ void set_switch_role_switching() {
+ switch_role_state_ = BTM_ACL_SWKEY_STATE_SWITCHING;
+ }
+
+ bool is_switch_role_idle() const {
+ return switch_role_state_ != BTM_ACL_SWKEY_STATE_IDLE;
+ }
+ bool is_switch_role_encryption_off() const {
+ return switch_role_state_ == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
+ }
+ bool is_switch_role_encryption_on() const {
+ return switch_role_state_ == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
+ }
+ bool is_switch_role_switching() const {
+ return switch_role_state_ == BTM_ACL_SWKEY_STATE_SWITCHING;
+ }
+ bool is_switch_role_in_progress() const {
+ return switch_role_state_ == BTM_ACL_SWKEY_STATE_IN_PROGRESS;
+ }
+ bool is_switch_role_mode_change() const {
+ return switch_role_state_ == BTM_ACL_SWKEY_STATE_MODE_CHANGE;
+ }
+ bool is_switch_role_switching_or_in_progress() const {
+ return is_switch_role_switching() || is_switch_role_in_progress();
+ }
+
+ public:
uint8_t sca; /* Sleep clock accuracy */
} tACL_CONN;
StackAclBtmAcl internal_;
}
-#define BTM_ACL_SWKEY_STATE_IDLE 0
-#define BTM_ACL_SWKEY_STATE_MODE_CHANGE 1
-#define BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF 2
-#define BTM_ACL_SWKEY_STATE_SWITCHING 3
-#define BTM_ACL_SWKEY_STATE_ENCRYPTION_ON 4
-#define BTM_ACL_SWKEY_STATE_IN_PROGRESS 5
-
#define BTM_MAX_SW_ROLE_FAILED_ATTEMPTS 3
extern tBTM_CB btm_cb;
btm_ble_refresh_local_resolvable_private_addr(
bda, btm_cb.ble_ctr_cb.addr_mgnt_cb.private_addr);
p->switch_role_failed_attempts = 0;
- p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
+ p->reset_switch_role();
/*******************************************************************************
*
if (is_sco_active) return (BTM_NO_RESOURCES);
/* Ignore role switch request if the previous request was not completed */
- if (p->switch_role_state != BTM_ACL_SWKEY_STATE_IDLE) {
- BTM_TRACE_DEBUG("BTM_SwitchRole busy: %d", p->switch_role_state);
- return (BTM_BUSY);
+ if (!p->is_switch_role_idle()) {
+ LOG_DEBUG("%s switch role in progress", __func__);
+ return BTM_BUSY;
}
if (interop_match_addr(INTEROP_DYNAMIC_ROLE_SWITCH, &remote_bd_addr)) {
status = BTM_SetPowerMode(BTM_PM_SET_ONLY_ID, p->remote_addr, &settings);
if (status != BTM_CMD_STARTED) return (BTM_WRONG_MODE);
- p->switch_role_state = BTM_ACL_SWKEY_STATE_MODE_CHANGE;
+ p->set_switch_role_changing();
}
/* some devices do not support switch while encryption is on */
else {
!BTM_EPR_AVAILABLE(p)) {
/* bypass turning off encryption if change link key is already doing it */
p->set_encryption_off();
- p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
+ p->set_switch_role_encryption_off();
} else {
btsnd_hcic_switch_role(remote_bd_addr, new_role);
- p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
-
+ p->set_switch_role_in_progress();
if (p_dev_rec) p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
}
}
return;
/* Process Role Switch if active */
- if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF) {
+ if (p->is_switch_role_encryption_off()) {
/* if encryption turn off failed we still will try to switch role */
if (encr_enable) {
- p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
p->set_encryption_idle();
+ p->reset_switch_role();
} else {
- p->switch_role_state = BTM_ACL_SWKEY_STATE_SWITCHING;
p->set_encryption_switching();
+ p->set_switch_role_switching();
}
btsnd_hcic_switch_role(p->remote_addr, (uint8_t)!p->link_role);
}
/* Finished enabling Encryption after role switch */
- else if (p->switch_role_state == BTM_ACL_SWKEY_STATE_ENCRYPTION_ON) {
- p->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
+ else if (p->is_switch_role_encryption_on()) {
+ p->reset_switch_role();
p->set_encryption_idle();
auto new_role = btm_cb.acl_cb_.switch_role_ref_data.role;
auto hci_status = btm_cb.acl_cb_.switch_role_ref_data.hci_status;
btm_cb.acl_cb_.switch_role_ref_data.remote_bd_addr, new_role,
hci_status);
- BTM_TRACE_DEBUG(
- "%s: Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, rs_st:%d",
- __func__, new_role, hci_status, p->switch_role_state);
+ BTM_TRACE_DEBUG("%s: Role Switch Event: new_role 0x%02x, HCI Status 0x%02x",
+ __func__, new_role, hci_status);
/* If a disconnect is pending, issue it now that role switch has completed
*/
p_dev_rec->dev_class[2]) &
0xffffff;
if ((hci_status != HCI_SUCCESS) &&
- ((p->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) ||
- (p->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS)) &&
+ (p->is_switch_role_switching_or_in_progress()) &&
((cod & cod_audio_device) == cod_audio_device) &&
(!interop_match_addr(INTEROP_DYNAMIC_ROLE_SWITCH, &bd_addr))) {
p->switch_role_failed_attempts++;
/* if switching state is switching we need to turn encryption on */
/* if idle, we did not change encryption */
- if (p_acl->switch_role_state == BTM_ACL_SWKEY_STATE_SWITCHING) {
+ if (p_acl->is_switch_role_switching()) {
p_acl->set_encryption_on();
- p_acl->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_ON;
+ p_acl->set_switch_role_encryption_on();
return;
}
/* Set the switch_role_state to IDLE since the reply received from HCI */
/* regardless of its result either success or failed. */
- if (p_acl->switch_role_state == BTM_ACL_SWKEY_STATE_IN_PROGRESS) {
- p_acl->switch_role_state = BTM_ACL_SWKEY_STATE_IDLE;
+ if (p_acl->is_switch_role_in_progress()) {
p_acl->set_encryption_idle();
+ p_acl->reset_switch_role();
}
BTA_dm_report_role_change(bd_addr, new_role, hci_status);
BTM_TRACE_DEBUG(
- "%s: peer %s Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, "
- "rs_st:%d",
- __func__, bd_addr.ToString().c_str(), p_switch_role->role,
- p_switch_role->hci_status, p_acl->switch_role_state);
+ "%s: peer %s Role Switch Event: new_role 0x%02x, HCI Status 0x%02x, ",
+ __func__, bd_addr.ToString().c_str(), new_role, hci_status);
/* If a disconnect is pending, issue it now that role switch has completed */
tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
BTM_TRACE_DEBUG("btm_cont_rswitch");
/* Check to see if encryption needs to be turned off if pending
change of link key or role switch */
- if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
+ if (p->is_switch_role_mode_change()) {
/* Must turn off Encryption first if necessary */
/* Some devices do not support switch or change of link key while encryption
* is on */
((p_dev_rec->sec_flags & BTM_SEC_ENCRYPTED) != 0) &&
!BTM_EPR_AVAILABLE(p)) {
p->set_encryption_off();
- if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE)
- p->switch_role_state = BTM_ACL_SWKEY_STATE_ENCRYPTION_OFF;
+ if (p->is_switch_role_mode_change()) {
+ p->set_switch_role_encryption_off();
+ }
} else /* Encryption not used or EPR supported, continue with switch
and/or change of link key */
{
- if (p->switch_role_state == BTM_ACL_SWKEY_STATE_MODE_CHANGE) {
- p->switch_role_state = BTM_ACL_SWKEY_STATE_IN_PROGRESS;
+ if (p->is_switch_role_mode_change()) {
+ p->set_switch_role_in_progress();
if (p_dev_rec) p_dev_rec->rs_disc_pending = BTM_SEC_RS_PENDING;
btsnd_hcic_switch_role(p->remote_addr, (uint8_t)!p->link_role);
}
if (p_acl == nullptr) {
return false;
}
- return p_acl->switch_role_state == BTM_ACL_SWKEY_STATE_IDLE;
+ return p_acl->is_switch_role_idle();
}
/*******************************************************************************