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

Commit 94d0afcd authored by Myles Watson's avatar Myles Watson Committed by Gerrit Code Review
Browse files

Merge "Register for InquiryComplete in Inquiry" into main

parents 739ba89b b906fffa
Loading
Loading
Loading
Loading
+0 −1
Original line number Diff line number Diff line
@@ -63,7 +63,6 @@ namespace {
bool register_event_code(bluetooth::hci::EventCode event_code) {
  switch (event_code) {
    // Inquiry
    case bluetooth::hci::EventCode::INQUIRY_COMPLETE:
    case bluetooth::hci::EventCode::INQUIRY_RESULT:
    case bluetooth::hci::EventCode::INQUIRY_RESULT_WITH_RSSI:
    case bluetooth::hci::EventCode::EXTENDED_INQUIRY_RESULT:
+44 −0
Original line number Diff line number Diff line
@@ -25,6 +25,8 @@
 *
 ******************************************************************************/

#include "hci_error_code.h"
#include "neighbor_inquiry.h"
#define LOG_TAG "bluetooth"

#include <base/logging.h>
@@ -253,6 +255,7 @@ void SendRemoteNameRequest(const RawAddress& raw_address) {
                          HCI_MANDATARY_PAGE_SCAN_MODE, 0);
}
static void btm_process_cancel_complete(tHCI_STATUS status, uint8_t mode);
static void on_incoming_hci_event(bluetooth::hci::EventView event);
/*******************************************************************************
 *
 * Function         BTM_SetDiscoverability
@@ -635,6 +638,16 @@ tBTM_STATUS BTM_StartInquiry(tBTM_INQ_RESULTS_CB* p_results_cb,
    return BTM_BUSY;
  }

  if (btm_cb.btm_inq_vars.registered_for_hci_events == false) {
    bluetooth::shim::GetHciLayer()->RegisterEventHandler(
        bluetooth::hci::EventCode::INQUIRY_COMPLETE,
        get_main_thread()->Bind([](bluetooth::hci::EventView event) {
          on_incoming_hci_event(event);
        }));

    btm_cb.btm_inq_vars.registered_for_hci_events = true;
  }

  /*** Make sure the device is ready ***/
  if (!BTM_IsDeviceUp()) {
    log::error("adapter is not up");
@@ -2183,6 +2196,37 @@ void btm_set_eir_uuid(const uint8_t* p_eir, tBTM_INQ_RESULTS* p_results) {
  }
}

static void on_inquiry_complete(bluetooth::hci::EventView event) {
  auto complete = bluetooth::hci::InquiryCompleteView::Create(event);
  ASSERT(complete.IsValid());
  auto status = to_hci_status_code(static_cast<uint8_t>(complete.GetStatus()));

  btm_process_inq_complete(status, BTM_BR_INQUIRY_MASK);
}
/*******************************************************************************
 *
 * Function         on_incoming_hci_event
 *
 * Description      This function is called to process events from the HCI layer
 *
 * Parameters       event - an EventView with the specific event
 *
 * Returns          None
 *
 ******************************************************************************/
static void on_incoming_hci_event(bluetooth::hci::EventView event) {
  ASSERT(event.IsValid());
  auto event_code = event.GetEventCode();
  switch (event_code) {
    case bluetooth::hci::EventCode::INQUIRY_COMPLETE:
      on_inquiry_complete(event);
      break;
    default:
      LOG_WARN("Dropping unhandled event: %s",
               bluetooth::hci::EventCodeText(event_code).c_str());
  }
}

namespace bluetooth {
namespace legacy {
namespace testing {
+3 −0
Original line number Diff line number Diff line
@@ -266,6 +266,8 @@ struct tBTM_INQUIRY_VAR_ST {
  uint8_t inq_active; /* Bit Mask indicating type of inquiry is active */
  bool no_inc_ssp;    /* true, to stop inquiry on incoming SSP */

  bool registered_for_hci_events;

  void Init() {
    p_remname_cmpl_cb = nullptr;

@@ -299,6 +301,7 @@ struct tBTM_INQUIRY_VAR_ST {
    state = BTM_INQ_INACTIVE_STATE;
    inq_active = 0;
    no_inc_ssp = BTM_NO_SSP_ON_INQUIRY;
    registered_for_hci_events = false;
  }
  void Free() {
    alarm_free(remote_name_timer);