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

Commit e3b3b845 authored by Hieu Dang's avatar Hieu Dang Committed by Gerrit Code Review
Browse files

Merge "Separate default role logic and acl paging logic"

parents 6bb1127a ea2a2d15
Loading
Loading
Loading
Loading
+25 −15
Original line number Diff line number Diff line
@@ -1334,6 +1334,30 @@ void btm_rejectlist_role_change_device(const RawAddress& bd_addr,
  }
}

/*******************************************************************************
 *
 * Function         acl_cache_role
 *
 * Description      This function caches the role of the device associated
 *                  with the given address. This happens if we get a role change
 *                  before connection complete. The cached role is propagated
 *                  when ACL Link is created.
 *
 * Returns          void
 *
 ******************************************************************************/

void acl_cache_role(const RawAddress& bd_addr, tHCI_ROLE new_role,
                    bool overwrite_cache) {
  if (overwrite_cache || delayed_role_change_ == nullptr) {
    RoleChangeView role_change;
    role_change.new_role = new_role;
    role_change.bd_addr = bd_addr;
    delayed_role_change_ =
        std::make_unique<RoleChangeView>(std::move(role_change));
  }
}

/*******************************************************************************
 *
 * Function         btm_acl_role_changed
@@ -1353,11 +1377,7 @@ void StackAclBtmAcl::btm_acl_role_changed(tHCI_STATUS hci_status,
  if (p_acl == nullptr) {
    // If we get a role change before connection complete, we cache the new
    // role here and then propagate it when ACL Link is created.
    RoleChangeView role_change;
    role_change.new_role = new_role;
    role_change.bd_addr = bd_addr;
    delayed_role_change_ =
        std::make_unique<RoleChangeView>(std::move(role_change));
    acl_cache_role(bd_addr, new_role, /*overwrite_cache=*/true);
    LOG_WARN("Unable to find active acl");
    return;
  }
@@ -2163,16 +2183,6 @@ void btm_acl_reset_paging(void) {
 *
 ******************************************************************************/
void btm_acl_paging(BT_HDR* p, const RawAddress& bda) {
  // This function is called by the device initiating the connection.
  // If no role change is requested from the remote device, we want
  // to classify the connection initiator as the central device.
  if (delayed_role_change_ == nullptr) {
    RoleChangeView role_change;
    role_change.bd_addr = bda;
    role_change.new_role = HCI_ROLE_CENTRAL;
    delayed_role_change_ =
        std::make_unique<RoleChangeView>(std::move(role_change));
  }
  if (!BTM_IsAclConnectionUp(bda, BT_TRANSPORT_BR_EDR)) {
    VLOG(1) << "connecting_bda: " << btm_cb.connecting_bda;
    if (btm_cb.paging && bda == btm_cb.connecting_bda) {
+5 −0
Original line number Diff line number Diff line
@@ -561,6 +561,11 @@ void btsnd_hcic_create_conn(const RawAddress& dest, uint16_t packet_types,
  UINT8_TO_STREAM(pp, page_scan_mode);
  UINT16_TO_STREAM(pp, clock_offset);
  UINT8_TO_STREAM(pp, allow_switch);

  // If no role change is requested from the remote device, we want
  // to classify the connection initiator as the central device.
  acl_cache_role(dest, HCI_ROLE_CENTRAL, /*overwrite_cache=*/false);

  btm_acl_paging(p, dest);
}

+3 −0
Original line number Diff line number Diff line
@@ -79,3 +79,6 @@ void btm_pm_on_sniff_subrating(tHCI_STATUS status, uint16_t handle,
                               uint16_t maximum_receive_latency,
                               uint16_t minimum_remote_timeout,
                               uint16_t minimum_local_timeout);

void acl_cache_role(const RawAddress& bd_addr, tHCI_ROLE new_role,
                    bool overwrite_cache);
 No newline at end of file