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

Commit 434a11ce authored by Chris Manton's avatar Chris Manton
Browse files

Wrap tL2C_LCB::link_role in API

Towards proper interfaces

Bug: 163134718
Tag: #refactor
Test: compile & verify basic functions working
Change-Id: I4a10763a8107f0a9dbc0ddf62d0671fe9b41a63f
parent dff0bbf1
Loading
Loading
Loading
Loading
+13 −8
Original line number Diff line number Diff line
@@ -69,7 +69,7 @@ bool L2CA_CancelBleConnectReq(const RawAddress& rem_bda) {
  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);
@@ -168,7 +168,7 @@ bool L2CA_EnableUpdateBleConnParams(const RawAddress& rem_bda, bool enable) {

  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;
  }

@@ -197,7 +197,7 @@ uint8_t L2CA_GetBleConnRole(const RawAddress& bd_addr) {
  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;
}
@@ -300,7 +300,12 @@ void l2cble_conn_comp(uint16_t handle, uint8_t role, const RawAddress& bda,

  /* 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 */
@@ -311,7 +316,7 @@ void l2cble_conn_comp(uint16_t handle, uint8_t role, const RawAddress& bda,

  /* 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 |
@@ -374,7 +379,7 @@ static void l2cble_start_conn_update(tL2C_LCB* p_lcb) {
      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() &&
@@ -397,7 +402,7 @@ static void l2cble_start_conn_update(tL2C_LCB* p_lcb) {
    /* 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() &&
@@ -520,7 +525,7 @@ void l2cble_process_sig_cmd(tL2C_LCB* p_lcb, uint8_t* p, uint16_t pkt_len) {
      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);

+9 −1
Original line number Diff line number Diff line
@@ -342,7 +342,15 @@ typedef struct t_l2c_linkcb {
  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 */
+16 −12
Original line number Diff line number Diff line
@@ -72,20 +72,20 @@ void l2c_link_hci_conn_req(const RawAddress& bd_addr) {

      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;

@@ -100,11 +100,11 @@ void l2c_link_hci_conn_req(const RawAddress& bd_addr) {
  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) {
@@ -170,10 +170,10 @@ void l2c_link_hci_conn_comp(uint8_t status, uint16_t handle,
    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());
@@ -344,7 +344,7 @@ bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason) {

    /* 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;) {
@@ -405,7 +405,7 @@ bool l2c_link_hci_disc_comp(uint16_t handle, uint8_t reason) {
                  "%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);
@@ -764,7 +764,11 @@ void l2c_link_role_changed(const RawAddress* bd_addr, uint8_t new_role,
    /* 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)
+2 −2
Original line number Diff line number Diff line
@@ -2052,7 +2052,7 @@ void l2cu_create_conn_br_edr(tL2C_LCB* p_lcb) {
       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." */
@@ -2071,7 +2071,7 @@ void l2cu_create_conn_br_edr(tL2C_LCB* p_lcb) {
        /* 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) {