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

Commit fb838d54 authored by Jack He's avatar Jack He
Browse files

GD HCI: Pipe VSEs up in shim layer

* Register known Android VSEs in shim layer
* Pipeline them through data callbacks so that they will
  be handled by btu_hcif_process_event() after beging posted
  to main thread by post_to_main_message_loop()

Tag: #gd-refactor
Bug: 183057550
Test: make, manual test BQR events
Change-Id: I849f02eec35f739f27d16803cea639c5e1ee1147
parent 0e54b03c
Loading
Loading
Loading
Loading
+43 −0
Original line number Diff line number Diff line
@@ -161,6 +161,19 @@ bool is_valid_subevent_code(uint8_t subevent_code_raw) {
  }
}

bool is_valid_vendor_specific_event(uint8_t vse_code_raw) {
  auto vse_code = static_cast<bluetooth::hci::VseSubeventCode>(vse_code_raw);
  switch (vse_code) {
    case bluetooth::hci::VseSubeventCode::BQR_EVENT:
    case bluetooth::hci::VseSubeventCode::BLE_THRESHOLD:
    case bluetooth::hci::VseSubeventCode::BLE_TRACKING:
    case bluetooth::hci::VseSubeventCode::DEBUG_INFO:
      return true;
    default:
      return false;
  }
}

static bool event_already_registered_in_hci_layer(
    bluetooth::hci::EventCode event_code) {
  switch (event_code) {
@@ -341,6 +354,16 @@ static void subevent_callback(
                                                     &le_meta_event_view));
}

static void vendor_specific_event_callback(
    bluetooth::hci::VendorSpecificEventView vendor_specific_event_view) {
  if (!send_data_upwards) {
    return;
  }
  send_data_upwards.Run(
      FROM_HERE,
      WrapPacketAndCopy(MSG_HC_TO_STACK_HCI_EVT, &vendor_specific_event_view));
}

void OnTransmitPacketCommandComplete(command_complete_cb complete_callback,
                                     void* context,
                                     bluetooth::hci::CommandCompleteView view) {
@@ -430,6 +453,13 @@ static void register_le_event(bluetooth::hci::SubeventCode subevent_code) {
      subevent_code, handler->Bind(subevent_callback));
}

static void register_vendor_specific_event(
    bluetooth::hci::VseSubeventCode vse_code) {
  auto handler = bluetooth::shim::GetGdShimHandler();
  bluetooth::shim::GetHciLayer()->RegisterVendorSpecificEventHandler(
      vse_code, handler->Bind(vendor_specific_event_callback));
}

static void acl_data_callback() {
  if (hci_queue_end == nullptr) {
    return;
@@ -759,6 +789,19 @@ void bluetooth::shim::hci_on_reset_complete() {
    }
  }

  for (uint8_t vse_code_raw = 0; vse_code_raw < 0xFF; vse_code_raw++) {
    if (!is_valid_vendor_specific_event(vse_code_raw)) {
      continue;
    }
    auto vse_code = static_cast<bluetooth::hci::VseSubeventCode>(vse_code_raw);
    if (bluetooth::common::init_flags::gd_rust_is_enabled()) {
      // TODO(b/183057550): Need Rust HCI implementation for VSE
      // ::rust::register_vendor_specific_event(vse_code_raw);
    } else {
      cpp::register_vendor_specific_event(vse_code);
    }
  }

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