connection_manager::direct_connect_remove(CONN_MGR_ID_L2CAP, rem_bda);
/* Do not remove lcb if an LE link is already up as a peripheral */
- if (p_lcb != NULL && !(p_lcb->link_role == HCI_ROLE_SLAVE &&
+ if (p_lcb != NULL && !(p_lcb->IsLinkRoleSlave() &&
BTM_IsAclConnectionUp(rem_bda, BT_TRANSPORT_LE))) {
p_lcb->disc_reason = L2CAP_CONN_CANCEL;
l2cu_release_lcb(p_lcb);
if (p_lcb->transport != BT_TRANSPORT_LE) {
LOG(WARNING) << __func__ << " - BD_ADDR " << rem_bda
- << " not LE, link role " << p_lcb->link_role;
+ << " not LE, link role " << p_lcb->LinkRole();
return false;
}
tL2C_LCB* p_lcb;
p_lcb = l2cu_find_lcb_by_bd_addr(bd_addr, BT_TRANSPORT_LE);
- if (p_lcb != NULL) role = p_lcb->link_role;
+ if (p_lcb != NULL) role = p_lcb->LinkRole();
return role;
}
/* Connected OK. Change state to connected, we were scanning so we are master
*/
- p_lcb->link_role = role;
+ if (role == HCI_ROLE_MASTER) {
+ p_lcb->SetLinkRoleAsMaster();
+ } else {
+ p_lcb->SetLinkRoleAsSlave();
+ }
+
p_lcb->transport = BT_TRANSPORT_LE;
/* update link parameter, set slave link as non-spec default upon link up */
/* Tell BTM Acl management about the link */
tBTM_SEC_DEV_REC* p_dev_rec = btm_find_or_alloc_dev(bda);
- btm_acl_created(bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->link_role,
+ btm_acl_created(bda, NULL, p_dev_rec->sec_bd_name, handle, p_lcb->LinkRole(),
BT_TRANSPORT_LE);
p_lcb->peer_chnl_mask[0] = L2CAP_FIXED_CHNL_ATT_BIT |
supervision_tout = BTM_BLE_CONN_TIMEOUT_DEF;
/* if both side 4.1, or we are master device, send HCI command */
- if (p_lcb->link_role == HCI_ROLE_MASTER
+ if (p_lcb->IsLinkRoleMaster()
#if (BLE_LLT_INCLUDED == TRUE)
|| (controller_get_interface()
->supports_ble_connection_parameter_request() &&
/* application allows to do update, if we were delaying one do it now */
if (p_lcb->conn_update_mask & L2C_BLE_NEW_CONN_PARAM) {
/* if both side 4.1, or we are master device, send HCI command */
- if (p_lcb->link_role == HCI_ROLE_MASTER
+ if (p_lcb->IsLinkRoleMaster()
#if (BLE_LLT_INCLUDED == TRUE)
|| (controller_get_interface()
->supports_ble_connection_parameter_request() &&
STREAM_TO_UINT16(latency, p); /* 0x0000 - 0x03E8 */
STREAM_TO_UINT16(timeout, p); /* 0x000A - 0x0C80 */
/* If we are a master, the slave wants to update the parameters */
- if (p_lcb->link_role == HCI_ROLE_MASTER) {
+ if (p_lcb->IsLinkRoleMaster()) {
L2CA_AdjustConnectionIntervals(&min_interval, &max_interval,
BTM_BLE_CONN_INT_MIN_LIMIT);
alarm_t* info_resp_timer; /* Timer entry for info resp timeout evt */
RawAddress remote_bd_addr; /* The BD address of the remote */
- uint8_t link_role; /* Master or slave */
+ private:
+ uint8_t link_role_{HCI_ROLE_MASTER}; /* Master or slave */
+ public:
+ uint8_t LinkRole() const { return link_role_; }
+ bool IsLinkRoleMaster() const { return link_role_ == HCI_ROLE_MASTER; }
+ bool IsLinkRoleSlave() const { return link_role_ == HCI_ROLE_SLAVE; }
+ void SetLinkRoleAsMaster() { link_role_ = HCI_ROLE_MASTER; }
+ void SetLinkRoleAsSlave() { link_role_ = HCI_ROLE_SLAVE; }
+
uint8_t id;
uint8_t cur_echo_id; /* Current id value for echo request */
uint16_t idle_timeout; /* Idle timeout */
if (p_lcb_cur->in_use) {
no_links = false;
- p_lcb->link_role = HCI_ROLE_MASTER;
+ p_lcb->SetLinkRoleAsMaster();
break;
}
}
if (no_links) {
if (!btm_dev_support_role_switch(bd_addr))
- p_lcb->link_role = HCI_ROLE_SLAVE;
+ p_lcb->SetLinkRoleAsSlave();
else
- p_lcb->link_role = HCI_ROLE_MASTER;
+ p_lcb->SetLinkRoleAsMaster();
}
/* Tell the other side we accept the connection */
- btsnd_hcic_accept_conn(bd_addr, p_lcb->link_role);
+ btsnd_hcic_accept_conn(bd_addr, p_lcb->LinkRole());
p_lcb->link_state = LST_CONNECTING;
if ((p_lcb->link_state == LST_CONNECTING) ||
(p_lcb->link_state == LST_CONNECT_HOLDING)) {
if (!btm_dev_support_role_switch(bd_addr))
- p_lcb->link_role = HCI_ROLE_SLAVE;
+ p_lcb->SetLinkRoleAsSlave();
else
- p_lcb->link_role = HCI_ROLE_MASTER;
+ p_lcb->SetLinkRoleAsMaster();
- btsnd_hcic_accept_conn(bd_addr, p_lcb->link_role);
+ btsnd_hcic_accept_conn(bd_addr, p_lcb->LinkRole());
p_lcb->link_state = LST_CONNECTING;
} else if (p_lcb->link_state == LST_DISCONNECTING) {
p_dev_info = btm_find_dev(p_bda);
if (p_dev_info != NULL)
btm_acl_created(ci.bd_addr, p_dev_info->dev_class,
- p_dev_info->sec_bd_name, handle, p_lcb->link_role,
+ p_dev_info->sec_bd_name, handle, p_lcb->LinkRole(),
BT_TRANSPORT_BR_EDR);
else
- btm_acl_created(ci.bd_addr, NULL, NULL, handle, p_lcb->link_role,
+ btm_acl_created(ci.bd_addr, NULL, NULL, handle, p_lcb->LinkRole(),
BT_TRANSPORT_BR_EDR);
BTM_SetLinkSuperTout(ci.bd_addr, acl_get_link_supervision_timeout());
/* Check for BLE and handle that differently */
if (p_lcb->transport == BT_TRANSPORT_LE)
- btm_ble_update_link_topology_mask(p_lcb->link_role, false);
+ btm_ble_update_link_topology_mask(p_lcb->LinkRole(), false);
/* Link is disconnected. For all channels, send the event through */
/* their FSMs. The CCBs should remove themselves from the LCB */
for (p_ccb = p_lcb->ccb_queue.p_first_ccb; p_ccb;) {
"%d",
__func__, xx, p_lcb->remote_bd_addr.ToString().c_str(), p_lcb,
p_lcb->in_use, p_lcb->link_state, p_lcb->handle,
- p_lcb->link_role, p_lcb->IsBonding(), p_lcb->disc_reason,
+ p_lcb->LinkRole(), p_lcb->IsBonding(), p_lcb->disc_reason,
p_lcb->transport);
}
CHECK(p_lcb->p_fixed_ccbs[xx] != NULL);
/* If here came form hci role change event */
p_lcb = l2cu_find_lcb_by_bd_addr(*bd_addr, BT_TRANSPORT_BR_EDR);
if (p_lcb) {
- p_lcb->link_role = new_role;
+ if (new_role == HCI_ROLE_MASTER) {
+ p_lcb->SetLinkRoleAsMaster();
+ } else {
+ p_lcb->SetLinkRoleAsSlave();
+ }
/* Reset high priority link if needed */
if (hci_status == HCI_SUCCESS)
xx++, p_lcb_cur++) {
if (p_lcb_cur == p_lcb) continue;
- if ((p_lcb_cur->in_use) && (p_lcb_cur->link_role == HCI_ROLE_SLAVE)) {
+ if ((p_lcb_cur->in_use) && (p_lcb_cur->IsLinkRoleSlave())) {
/* The LMP_switch_req shall be sent only if the ACL logical transport
is in active mode, when encryption is disabled, and all synchronous
logical transports on the same physical link are disabled." */
/* mark this lcb waiting for switch to be completed and
start switch on the other one */
p_lcb->link_state = LST_CONNECTING_WAIT_SWITCH;
- p_lcb->link_role = HCI_ROLE_MASTER;
+ p_lcb->SetLinkRoleAsMaster();
if (BTM_SwitchRole(p_lcb_cur->remote_bd_addr, HCI_ROLE_MASTER) ==
BTM_CMD_STARTED) {