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

Commit 1f3e6276 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "legacy: Remove INIT_FLAG is_gd_acl"

parents 71f5d6f1 a8ce6dc1
Loading
Loading
Loading
Loading
+2 −4
Original line number Diff line number Diff line
@@ -505,10 +505,8 @@ static void bta_dm_wait_for_acl_to_drain_cback(void* data) {
    }
  } else {
    // No ACL links were up or is second pass at ACL closure
    if (bluetooth::shim::is_gd_acl_enabled()) {
    LOG_INFO("Ensuring all ACL connections have been properly flushed");
    bluetooth::shim::ACL_Shutdown();
    }

    bta_dm_cb.disabling = false;

+3 −8
Original line number Diff line number Diff line
@@ -1606,7 +1606,7 @@ void bta_hh_le_open_fail(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
    bta_hh_clear_service_cache(p_cb);
  }

  if (bluetooth::shim::is_gd_acl_enabled() && p_cb->is_le_device) {
  if (p_cb->is_le_device) {
    LOG_DEBUG("gd_acl: Re-adding HID device to acceptlist");
    // gd removes from bg list after failed connection
    // Correct the cached state to allow re-add to acceptlist.
@@ -1666,7 +1666,7 @@ void bta_hh_gatt_close(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
  /* if no connection is active and HH disable is signaled, disable service */
  if (bta_hh_cb.cnt_num == 0 && bta_hh_cb.w4_disable) {
    bta_hh_disc_cmpl();
  } else if (bluetooth::shim::is_gd_acl_enabled()) {
  } else {
    switch (le_close->reason) {
      case GATT_CONN_FAILED_ESTABLISHMENT:
      case GATT_CONN_TERMINATE_PEER_USER:
@@ -1694,8 +1694,6 @@ void bta_hh_gatt_close(tBTA_HH_DEV_CB* p_cb, const tBTA_HH_DATA* p_data) {
            gatt_disconnection_reason_text(le_close->reason).c_str());
        break;
    }
  } else if (kBTA_HH_LE_RECONN && le_close->reason == GATT_CONN_TIMEOUT) {
    bta_hh_le_add_dev_bg_conn(p_cb, false);
  }
}

@@ -2007,14 +2005,11 @@ static void bta_hh_le_add_dev_bg_conn(tBTA_HH_DEV_CB* p_cb, bool check_bond) {
    /* add device into BG connection to accept remote initiated connection */
    BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, false, false);
    p_cb->in_bg_conn = true;
  } else if (bluetooth::shim::is_gd_acl_enabled()) {
  } else {
    // Let the lower layers manage acceptlist and do not cache
    // at the higher layer
    p_cb->in_bg_conn = true;
    BTA_GATTC_Open(bta_hh_cb.gatt_if, p_cb->addr, false, false);
  } else {
    LOG_WARN("Unable to add device into bg in_bg_conn:%u to_add:%u",
             p_cb->in_bg_conn, to_add);
  }
}

+4 −71
Original line number Diff line number Diff line
@@ -168,11 +168,9 @@ static bool event_already_registered_in_hci_layer(
    case bluetooth::hci::EventCode::PAGE_SCAN_REPETITION_MODE_CHANGE:
    case bluetooth::hci::EventCode::MAX_SLOTS_CHANGE:
    case bluetooth::hci::EventCode::LE_META_EVENT:
      return true;
    case bluetooth::hci::EventCode::DISCONNECTION_COMPLETE:
    case bluetooth::hci::EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE:
      return bluetooth::shim::is_gd_acl_enabled() ||
             bluetooth::shim::is_gd_l2cap_enabled();
      return true;
    default:
      return false;
  }
@@ -182,8 +180,7 @@ static bool event_already_registered_in_controller_layer(
    bluetooth::hci::EventCode event_code) {
  switch (event_code) {
    case bluetooth::hci::EventCode::NUMBER_OF_COMPLETED_PACKETS:
      return bluetooth::shim::is_gd_acl_enabled() ||
             bluetooth::shim::is_gd_l2cap_enabled();
      return true;
    default:
      return false;
  }
@@ -193,8 +190,7 @@ static bool event_already_registered_in_acl_layer(
    bluetooth::hci::EventCode event_code) {
  for (auto event : bluetooth::hci::AclConnectionEvents) {
    if (event == event_code) {
      return bluetooth::shim::is_gd_acl_enabled() ||
             bluetooth::shim::is_gd_l2cap_enabled();
      return true;
    }
  }
  return false;
@@ -209,15 +205,9 @@ static bool subevent_already_registered_in_le_hci_layer(
    case bluetooth::hci::SubeventCode::ENHANCED_CONNECTION_COMPLETE:
    case bluetooth::hci::SubeventCode::PHY_UPDATE_COMPLETE:
    case bluetooth::hci::SubeventCode::REMOTE_CONNECTION_PARAMETER_REQUEST:
      return bluetooth::shim::is_gd_acl_enabled() ||
             bluetooth::shim::is_gd_l2cap_enabled() ||
             bluetooth::shim::is_gd_advertising_enabled() ||
             bluetooth::shim::is_gd_scanning_enabled();
    case bluetooth::hci::SubeventCode::ADVERTISING_SET_TERMINATED:
    case bluetooth::hci::SubeventCode::SCAN_REQUEST_RECEIVED:
      return bluetooth::shim::is_gd_acl_enabled() ||
             bluetooth::shim::is_gd_l2cap_enabled() ||
             bluetooth::shim::is_gd_advertising_enabled();
      return true;
    case bluetooth::hci::SubeventCode::SCAN_TIMEOUT:
    case bluetooth::hci::SubeventCode::ADVERTISING_REPORT:
    case bluetooth::hci::SubeventCode::DIRECTED_ADVERTISING_REPORT:
@@ -470,23 +460,6 @@ static void register_le_event(bluetooth::hci::SubeventCode subevent_code) {
      subevent_code, handler->Bind(subevent_callback));
}

static void acl_data_callback() {
  if (hci_queue_end == nullptr) {
    return;
  }
  auto packet = hci_queue_end->TryDequeue();
  ASSERT(packet != nullptr);
  if (!packet->IsValid()) {
    LOG_INFO("Dropping invalid packet of size %zu", packet->size());
    return;
  }
  if (!send_data_upwards) {
    return;
  }
  auto data = WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_ACL, packet.get());
  packet_fragmenter->reassemble_and_dispatch(data);
}

static void sco_data_callback() {
  if (hci_sco_queue_end == nullptr) {
    return;
@@ -521,22 +494,6 @@ static void iso_data_callback() {
  packet_fragmenter->reassemble_and_dispatch(data);
}

static void register_for_acl() {
  hci_queue_end = bluetooth::shim::GetHciLayer()->GetAclQueueEnd();

  // if gd advertising/scanning enabled, hci_queue_end will be register in
  // AclManager::impl::Start
  if (!bluetooth::shim::is_gd_advertising_enabled() &&
      !bluetooth::shim::is_gd_scanning_enabled() &&
      !bluetooth::shim::is_gd_l2cap_enabled()) {
    hci_queue_end->RegisterDequeue(bluetooth::shim::GetGdShimHandler(),
                                   bluetooth::common::Bind(acl_data_callback));
  }

  pending_data = new bluetooth::os::EnqueueBuffer<bluetooth::hci::AclBuilder>(
      hci_queue_end);
}

static void register_for_sco() {
  hci_sco_queue_end = bluetooth::shim::GetHciLayer()->GetScoQueueEnd();
  hci_sco_queue_end->RegisterDequeue(
@@ -629,14 +586,6 @@ static BT_HDR* WrapRustPacketAndCopy(uint16_t event,
  return packet;
}

static void on_acl(::rust::Slice<const uint8_t> data) {
  if (!send_data_upwards) {
    return;
  }
  auto legacy_data = WrapRustPacketAndCopy(MSG_HC_TO_STACK_HCI_ACL, &data);
  packet_fragmenter->reassemble_and_dispatch(legacy_data);
}

static void on_sco(::rust::Slice<const uint8_t> data) {
  if (!send_data_upwards) {
    return;
@@ -748,12 +697,6 @@ static void hci_on_reset_complete() {
      std::make_unique<u8SliceCallback>(Bind(rust::on_event)));
}

static void register_for_acl() {
  bluetooth::shim::rust::hci_set_acl_callback(
      **bluetooth::shim::Stack::GetInstance()->GetRustHci(),
      std::make_unique<u8SliceCallback>(Bind(rust::on_acl)));
}

static void register_for_sco() {
  bluetooth::shim::rust::hci_set_sco_callback(
      **bluetooth::shim::Stack::GetInstance()->GetRustHci(),
@@ -951,16 +894,6 @@ void bluetooth::shim::hci_on_reset_complete() {
  } else {
    cpp::register_for_iso();
  }

  if (bluetooth::shim::is_gd_acl_enabled()) {
    return;
  }

  if (bluetooth::common::init_flags::gd_rust_is_enabled()) {
    ::rust::register_for_acl();
  } else {
    cpp::register_for_acl();
  }
}

void bluetooth::shim::hci_on_shutting_down() {
+6 −85
Original line number Diff line number Diff line
@@ -174,8 +174,6 @@ void NotifyAclRoleSwitchComplete(const RawAddress& bda, tHCI_ROLE new_role,

void NotifyAclFeaturesReadComplete(tACL_CONN& p_acl,
                                   UNUSED_ATTR uint8_t max_page_number) {
  ASSERT_LOG(bluetooth::shim::is_gd_acl_enabled(),
             "For right now only called with gd_acl support");
  btm_process_remote_ext_features(&p_acl, max_page_number);
  btm_set_link_policy(&p_acl, btm_cb.acl_cb_.DefaultLinkPolicy());
  BTA_dm_notify_remote_features_complete(p_acl.remote_addr);
@@ -189,13 +187,8 @@ static void hci_btsnd_hcic_disconnect(tACL_CONN& p_acl, tHCI_STATUS reason) {
           hci_error_code_text(reason).c_str());
  p_acl.disconnect_reason = reason;

  if (bluetooth::shim::is_gd_acl_enabled()) {
  return bluetooth::shim::ACL_Disconnect(p_acl.hci_handle,
                                         p_acl.is_transport_br_edr(), reason);
  } else {
    GetLegacyHciInterface().Disconnect(p_acl.hci_handle,
                                       static_cast<uint16_t>(reason));
  }
}

void StackAclBtmAcl::hci_start_role_switch_to_central(tACL_CONN& p_acl) {
@@ -416,11 +409,6 @@ void btm_acl_created(const RawAddress& bda, uint16_t hci_handle,
  /* if BR/EDR do something more */
  if (transport == BT_TRANSPORT_BR_EDR) {
    btsnd_hcic_read_rmt_clk_offset(hci_handle);
    if (!bluetooth::shim::is_gd_l2cap_enabled() &&
        !bluetooth::shim::is_gd_acl_enabled()) {
      // GD L2cap and GD Acl read this automatically
      btsnd_hcic_rmt_ver_req(hci_handle);
    }
  }

  if (transport == BT_TRANSPORT_LE) {
@@ -784,11 +772,6 @@ static void maybe_chain_more_commands_after_read_remote_version_complete(
       * read commands.  Skip when gd_acl is enabled because that
       * module handles all remote read functionality.
       */
      if (!bluetooth::shim::is_gd_acl_enabled()) {
        if (status == HCI_SUCCESS) {
          internal_.btm_read_remote_features(p_acl_cb->hci_handle);
        }
      }
      break;
    default:
      LOG_ERROR("Unable to determine transport:%s device:%s",
@@ -835,8 +818,7 @@ void btm_read_remote_version_complete_raw(uint8_t* p) {
  STREAM_TO_UINT16(manufacturer, p);
  STREAM_TO_UINT16(lmp_subversion, p);

  ASSERT_LOG(!bluetooth::shim::is_gd_acl_enabled(),
             "gd acl layer should be receiving this completion");
  ASSERT_LOG(false, "gd acl layer should be receiving this completion");
  btm_read_remote_version_complete(static_cast<tHCI_STATUS>(status), handle,
                                   lmp_version, manufacturer, lmp_version);
}
@@ -2593,10 +2575,8 @@ void on_acl_br_edr_connected(const RawAddress& bda, uint16_t handle,
   * The GD code path has ownership of the read_remote_ commands
   * and thus may inform the upper layers about the connection.
   */
  if (bluetooth::shim::is_gd_acl_enabled()) {
  NotifyAclLinkUp(*p_acl);
}
}

void on_acl_br_edr_failed(const RawAddress& bda, tHCI_STATUS status) {
  ASSERT_LOG(status != HCI_SUCCESS,
@@ -2651,48 +2631,12 @@ void btm_acl_disconnected(tHCI_STATUS status, uint16_t handle,
  btm_sec_disconnected(handle, reason);
}

constexpr uint16_t kDefaultPacketTypes =
    HCI_PKT_TYPES_MASK_DM1 | HCI_PKT_TYPES_MASK_DH1 | HCI_PKT_TYPES_MASK_DM3 |
    HCI_PKT_TYPES_MASK_DH3 | HCI_PKT_TYPES_MASK_DM5 | HCI_PKT_TYPES_MASK_DH5;

void acl_create_classic_connection(const RawAddress& bd_addr,
                                   bool there_are_high_priority_channels,
                                   bool is_bonding) {
  if (bluetooth::shim::is_gd_acl_enabled()) {
  return bluetooth::shim::ACL_CreateClassicConnection(bd_addr);
}

  const bool controller_supports_role_switch =
      controller_get_interface()->supports_role_switch();
  const bool acl_allows_role_switch = acl_is_role_switch_allowed();

  /* FW team says that we can participant in 4 piconets
   * typically 3 piconet + 1 for scanning.
   * We can enhance the code to count the number of piconets later. */
  uint8_t allow_role_switch = HCI_CR_CONN_NOT_ALLOW_SWITCH;
  if (((acl_allows_role_switch && (BTM_GetNumAclLinks() < 3)) ||
       (is_bonding && !there_are_high_priority_channels &&
        controller_supports_role_switch)))
    allow_role_switch = HCI_CR_CONN_ALLOW_SWITCH;

  /* Check with the BT manager if details about remote device are known */
  uint8_t page_scan_rep_mode{HCI_PAGE_SCAN_REP_MODE_R1};
  uint8_t page_scan_mode{HCI_MANDATARY_PAGE_SCAN_MODE};
  uint16_t clock_offset = BTM_GetClockOffset(bd_addr);

  tBTM_INQ_INFO* p_inq_info = BTM_InqDbRead(bd_addr);
  if (p_inq_info != nullptr &&
      (p_inq_info->results.inq_result_type & BTM_INQ_RESULT_BR)) {
    page_scan_rep_mode = p_inq_info->results.page_scan_rep_mode;
    page_scan_mode = p_inq_info->results.page_scan_mode;
    clock_offset = p_inq_info->results.clock_offset;
  }

  btsnd_hcic_create_conn(bd_addr, kDefaultPacketTypes, page_scan_rep_mode,
                         page_scan_mode, clock_offset, allow_role_switch);
  btm_acl_set_paging(true);
}

void btm_acl_connection_request(const RawAddress& bda, uint8_t* dc) {
  btm_sec_conn_req(bda, dc);
  l2c_link_hci_conn_req(bda);
@@ -2734,12 +2678,7 @@ void acl_disconnect_after_role_switch(uint16_t conn_handle,
  }
}

constexpr uint16_t kDataPacketEventBrEdr = (BT_EVT_TO_LM_HCI_ACL);
constexpr uint16_t kDataPacketEventBle =
    (BT_EVT_TO_LM_HCI_ACL | LOCAL_BLE_CONTROLLER_ID);

void acl_send_data_packet_br_edr(const RawAddress& bd_addr, BT_HDR* p_buf) {
  if (bluetooth::shim::is_gd_acl_enabled()) {
    tACL_CONN* p_acl = internal_.btm_bda_to_acl(bd_addr, BT_TRANSPORT_BR_EDR);
    if (p_acl == nullptr) {
      LOG_WARN("Acl br_edr data write for unknown device:%s",
@@ -2749,11 +2688,8 @@ void acl_send_data_packet_br_edr(const RawAddress& bd_addr, BT_HDR* p_buf) {
    }
    return bluetooth::shim::ACL_WriteData(p_acl->hci_handle, p_buf);
}
  bte_main_hci_send(p_buf, kDataPacketEventBrEdr);
}

void acl_send_data_packet_ble(const RawAddress& bd_addr, BT_HDR* p_buf) {
  if (bluetooth::shim::is_gd_acl_enabled()) {
    tACL_CONN* p_acl = internal_.btm_bda_to_acl(bd_addr, BT_TRANSPORT_LE);
    if (p_acl == nullptr) {
      LOG_WARN("Acl le data write for unknown device:%s",
@@ -2763,8 +2699,6 @@ void acl_send_data_packet_ble(const RawAddress& bd_addr, BT_HDR* p_buf) {
    }
    return bluetooth::shim::ACL_WriteData(p_acl->hci_handle, p_buf);
}
  bte_main_hci_send(p_buf, kDataPacketEventBle);
}

void acl_write_automatic_flush_timeout(const RawAddress& bd_addr,
                                       uint16_t flush_timeout_in_ticks) {
@@ -2785,7 +2719,6 @@ void acl_write_automatic_flush_timeout(const RawAddress& bd_addr,
}

bool acl_create_le_connection_with_id(uint8_t id, const RawAddress& bd_addr) {
  if (bluetooth::shim::is_gd_acl_enabled()) {
    tBLE_BD_ADDR address_with_type{
        .bda = bd_addr,
        .type = BLE_ADDR_RANDOM,
@@ -2797,8 +2730,6 @@ bool acl_create_le_connection_with_id(uint8_t id, const RawAddress& bd_addr) {
                                                /* is_direct */ true);
    return true;
}
  return connection_manager::direct_connect_add(id, bd_addr);
}

bool acl_create_le_connection(const RawAddress& bd_addr) {
  return acl_create_le_connection_with_id(CONN_MGR_ID_L2CAP, bd_addr);
@@ -2860,18 +2791,11 @@ static void acl_parse_num_completed_pkts(uint8_t* p, uint8_t evt_len) {
}

void acl_process_num_completed_pkts(uint8_t* p, uint8_t evt_len) {
  if (bluetooth::shim::is_gd_acl_enabled()) {
  acl_parse_num_completed_pkts(p, evt_len);
  } else {
    l2c_link_process_num_completed_pkts(p, evt_len);
  }
  bluetooth::hci::IsoManager::GetInstance()->HandleNumComplDataPkts(p, evt_len);
}

void acl_process_supported_features(uint16_t handle, uint64_t features) {
  ASSERT_LOG(bluetooth::shim::is_gd_acl_enabled(),
             "Should only be called when gd_acl enabled");

  tACL_CONN* p_acl = internal_.acl_get_connection_from_handle(handle);
  if (p_acl == nullptr) {
    LOG_WARN("Unable to find active acl");
@@ -2902,9 +2826,6 @@ void acl_process_supported_features(uint16_t handle, uint64_t features) {

void acl_process_extended_features(uint16_t handle, uint8_t current_page_number,
                                   uint8_t max_page_number, uint64_t features) {
  ASSERT_LOG(bluetooth::shim::is_gd_acl_enabled(),
             "Should only be called when gd_acl enabled");

  if (current_page_number > HCI_EXT_FEATURES_PAGE_MAX) {
    LOG_WARN("Unable to process current_page_number:%hhu", current_page_number);
    return;
+2 −2
Original line number Diff line number Diff line
@@ -50,7 +50,7 @@ void btm_send_hci_create_connection(
    tBLE_ADDR_TYPE addr_type_own, uint16_t conn_int_min, uint16_t conn_int_max,
    uint16_t conn_latency, uint16_t conn_timeout, uint16_t min_ce_len,
    uint16_t max_ce_len, uint8_t initiating_phys) {
  ASSERT_LOG(!bluetooth::shim::is_gd_acl_enabled(),
  ASSERT_LOG(false,
             "When gd_acl enabled this code path should not be exercised");

  if (controller_get_interface()->supports_ble_extended_advertising()) {
@@ -209,7 +209,7 @@ void btm_ble_conn_complete(uint8_t* p, UNUSED_ATTR uint16_t evt_len,
}

void btm_ble_create_conn_cancel() {
  ASSERT_LOG(!bluetooth::shim::is_gd_acl_enabled(),
  ASSERT_LOG(false,
             "When gd_acl enabled this code path should not be exercised");

  btsnd_hcic_ble_create_conn_cancel();
Loading