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

Commit 706e9560 authored by Joseph Hwang's avatar Joseph Hwang
Browse files

gd/hci: support handle_msft_events in msft

This patch supports the Microsoft advertisement monitor event, i.e.
MSFT_LE_MONITOR_DEVICE_EVENT.

Note that the first octet of the vendor prefix, which is unique in
a vendor controller, is registered via the vendor specific event
manager so that the the vendor specific event manager can dispatch
the Microsoft event properly.

Bug: 246404026
Tag: #floss
Test: ./build.py --target test
Test: mm
Test: Manual test on a ChromeOS devic
BYPASS_LONG_LINES_REASON: Bluetooth likes 120 lines

Change-Id: I79482297c640d4b89e9a7579d5a3b2190a175822
parent 5eef311f
Loading
Loading
Loading
Loading
+42 −13
Original line number Diff line number Diff line
@@ -78,22 +78,41 @@ struct MsftExtensionManager::impl {
    LOG_INFO("MsftExtensionManager stop()");
  }

  void handle_msft_events(VendorSpecificEventView event) {
    // TODO(b/246398494): MSFT events are vendor specific events with an event prefix.
  void handle_rssi_event(MsftRssiEventPayloadView view) {
    LOG_WARN("The Microsoft MSFT_RSSI_EVENT is not supported yet.");
  }

  void handle_le_monitor_device_event(MsftLeMonitorDeviceEventPayloadView view) {
    ASSERT(view.IsValid());
    LOG_WARN("The Microsoft MSFT_LE_MONITOR_DEVICE_EVENT is not supported yet.");
    // TODO: to call a callback here.
  }

    /* Myles suggested that the structure look like
    auto payload = event.GetPayload();
    for (size_t i = 0; i < msft_.prefix.size(); i++) {
      if (msft_.prefix[i] != payload[i]) {
        // Print a warning and return
  void handle_msft_events(VendorSpecificEventView view) {
    auto payload = view.GetPayload();
    for (size_t i = 0; i < msft_.prefix.size() - 1; i++) {
      if (msft_.prefix[i + 1] != payload[i]) {
        LOG_WARN("The Microsoft vendor event prefix does not match.");
        return;
      }
    }

    MsftEventPayloadView::Create(payload.GetLittleEndianSubview(msft_.prefix.size(), payload.size()));
    // Assert that it's valid
    // Check the type of event
    // Cast it, and handle it.
    */
    auto msft_view = MsftEventPayloadView::Create(
        payload.GetLittleEndianSubview(msft_.prefix.size() - 1, payload.size()));
    ASSERT(msft_view.IsValid());

    MsftEventCode ev_code = msft_view.GetMsftEventCode();
    switch (ev_code) {
      case MsftEventCode::MSFT_RSSI_EVENT:
        handle_rssi_event(MsftRssiEventPayloadView::Create(msft_view));
        break;
      case MsftEventCode::MSFT_LE_MONITOR_DEVICE_EVENT:
        handle_le_monitor_device_event(MsftLeMonitorDeviceEventPayloadView::Create(msft_view));
        break;
      default:
        LOG_WARN("Unknown MSFT event code %hhu", ev_code);
        break;
    }
  }

  bool supports_msft_extensions() {
@@ -183,6 +202,16 @@ struct MsftExtensionManager::impl {

    LOG_INFO(
        "MSFT features 0x%16.16llx prefix length %u", (unsigned long long)msft_.features, (unsigned int)prefix.size());

    // We are here because Microsoft Extension is supported. Hence, register the
    // first octet of the vendor prefix so that the vendor specific event manager
    // can dispatch the event correctly.
    // Note: registration of the first octet of the vendor prefix is sufficient
    //       because each vendor controller should ensure that the first octet
    //       is unique within the vendor's events.
    vendor_specific_event_manager_->RegisterEventHandler(
        static_cast<VseSubeventCode>(msft_.prefix[0]),
        module_handler_->BindOn(this, &impl::handle_msft_events));
  }

  void on_msft_adv_monitor_add_complete(CommandCompleteView view) {