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

Commit 4ecdfda6 authored by Chris Manton's avatar Chris Manton
Browse files

Streamline stack/btm/btm_dev::btm_dev_support_switch

Bug: 162984360
Tag: #refactor
Test: compiles and devices pair and work

Change-Id: I838a258471b484c29dc3828e1c940065451a10b0
parent ec9702cb
Loading
Loading
Loading
Loading
+35 −25
Original line number Diff line number Diff line
@@ -275,40 +275,50 @@ tBTM_SEC_DEV_REC* btm_sec_alloc_dev(const RawAddress& bd_addr) {
 * Parameters:      bd_addr       - Address of the peer device
 *
 * Returns          true if device is known and role switch is supported
 *                  for the link.
 *
 ******************************************************************************/
bool btm_dev_support_switch(const RawAddress& bd_addr) {
  tBTM_SEC_DEV_REC* p_dev_rec;
  uint8_t xx;
  bool feature_empty = true;
  if (BTM_IsScoActiveByBdaddr(bd_addr)) {
    BTM_TRACE_DEBUG("%s Role switch is not allowed if a SCO is up", __func__);
    return false;
  }

  tBTM_SEC_DEV_REC* p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec == nullptr) {
    BTM_TRACE_DEBUG("%s Unknown address for role switch", __func__);
    return false;
  }

  if (!controller_get_interface()->supports_master_slave_role_switch()) {
    BTM_TRACE_DEBUG("%s Local controller does not support role switch",
                    __func__);
    return false;
  }

  /* Role switch is not allowed if a SCO is up */
  if (BTM_IsScoActiveByBdaddr(bd_addr)) return (false);
  p_dev_rec = btm_find_dev(bd_addr);
  if (p_dev_rec &&
      controller_get_interface()->supports_master_slave_role_switch()) {
  if (HCI_SWITCH_SUPPORTED(p_dev_rec->feature_pages[0])) {
      BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature found)");
      return (true);
    BTM_TRACE_DEBUG("%s Peer controller supports role switch", __func__);
    return true;
  }

  /* If the feature field is all zero, we never received them */
    for (xx = 0; xx < BD_FEATURES_LEN; xx++) {
  bool feature_empty = true;
  for (int xx = 0; xx < BD_FEATURES_LEN; xx++) {
    if (p_dev_rec->feature_pages[0][xx] != 0x00) {
      feature_empty = false; /* at least one is != 0 */
      break;
    }
  }

    /* If we don't know peer's capabilities, assume it supports Role-switch */
  if (feature_empty) {
      BTM_TRACE_DEBUG("btm_dev_support_switch return true (feature empty)");
      return (true);
    }
    BTM_TRACE_DEBUG(
        "%s Unknown peer capabilities, assuming peer supports role switch",
        __func__);
    return true;
  }

  BTM_TRACE_DEBUG("btm_dev_support_switch return false");
  return (false);
  BTM_TRACE_DEBUG("%s Peer controller does not support role switch", __func__);
  return false;
}

bool is_handle_equal(void* data, void* context) {