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

Commit 5fc26449 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "pass CS config parameters to hal" into main

parents 5ca46201 ec562c33
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -116,7 +116,7 @@ cc_defaults {
            ],
            whole_static_libs: [
                "android.hardware.bluetooth-V1-ndk",
                "android.hardware.bluetooth.ranging-V1-ndk",
                "android.hardware.bluetooth.ranging-V2-ndk",
            ],
        },
    },
+8 −1
Original line number Diff line number Diff line
@@ -18,11 +18,11 @@

#include <complex>

#include "hci/hci_packets.h"
#include "module.h"

namespace bluetooth {
namespace hal {

enum RangingHalVersion {
  V_UNKNOWN = 0,
  V_1 = 1,
@@ -70,6 +70,7 @@ public:

  virtual ~RangingHal() = default;
  virtual bool IsBound() = 0;
  virtual RangingHalVersion GetRangingHalVersion() = 0;
  virtual void RegisterCallback(RangingHalCallback* callback) = 0;
  virtual std::vector<VendorSpecificCharacteristic> GetVendorSpecificCharacteristics() = 0;
  virtual void OpenSession(
@@ -79,6 +80,12 @@ public:
          uint16_t connection_handle,
          const std::vector<hal::VendorSpecificCharacteristic>& vendor_specific_reply) = 0;
  virtual void WriteRawData(uint16_t connection_handle, const ChannelSoundingRawData& raw_data) = 0;
  virtual void UpdateChannelSoundingConfig(
          uint16_t connection_handle,
          const hci::LeCsConfigCompleteView& leCsConfigCompleteView) = 0;
  virtual void UpdateProcedureEnableConfig(
          uint16_t connection_handle,
          const hci::LeCsProcedureEnableCompleteView& leCsProcedureEnableCompleteView) = 0;
};

}  // namespace hal
+86 −0
Original line number Diff line number Diff line
@@ -32,13 +32,24 @@

using aidl::android::hardware::bluetooth::ranging::BluetoothChannelSoundingParameters;
using aidl::android::hardware::bluetooth::ranging::BnBluetoothChannelSoundingSessionCallback;
using aidl::android::hardware::bluetooth::ranging::Ch3cShapeType;
using aidl::android::hardware::bluetooth::ranging::ChannelSelectionType;
using aidl::android::hardware::bluetooth::ranging::ChannelSoudingRawData;
using aidl::android::hardware::bluetooth::ranging::ChannelSoundingProcedureData;
using aidl::android::hardware::bluetooth::ranging::ComplexNumber;
using aidl::android::hardware::bluetooth::ranging::Config;
using aidl::android::hardware::bluetooth::ranging::CsSyncPhyType;
using aidl::android::hardware::bluetooth::ranging::IBluetoothChannelSounding;
using aidl::android::hardware::bluetooth::ranging::IBluetoothChannelSoundingSession;
using aidl::android::hardware::bluetooth::ranging::IBluetoothChannelSoundingSessionCallback;
using aidl::android::hardware::bluetooth::ranging::ModeType;
using aidl::android::hardware::bluetooth::ranging::ProcedureEnableConfig;
using aidl::android::hardware::bluetooth::ranging::Role;
using aidl::android::hardware::bluetooth::ranging::RttType;
using aidl::android::hardware::bluetooth::ranging::StepTonePct;
using aidl::android::hardware::bluetooth::ranging::SubModeType;
using aidl::android::hardware::bluetooth::ranging::VendorSpecificData;
// using aidl::android::hardware::bluetooth::ranging::

namespace bluetooth {
namespace hal {
@@ -236,6 +247,81 @@ public:
    session_trackers_[connection_handle]->GetSession()->writeRawData(hal_raw_data);
  }

  void UpdateChannelSoundingConfig(
          uint16_t connection_handle,
          const hci::LeCsConfigCompleteView& leCsConfigCompleteView) override {
    auto it = session_trackers_.find(connection_handle);
    if (it == session_trackers_.end()) {
      log::error("Can't find session for connection_handle:0x{:04x}", connection_handle);
      return;
    } else if (it->second->GetSession() == nullptr) {
      log::error("Session not opened");
      return;
    }

    Config csConfig{
            .modeType = static_cast<ModeType>(
                    static_cast<int>(leCsConfigCompleteView.GetMainModeType())),
            .subModeType = static_cast<SubModeType>(
                    static_cast<int>(leCsConfigCompleteView.GetSubModeType())),
            .rttType = static_cast<RttType>(static_cast<int>(leCsConfigCompleteView.GetRttType())),
            .channelMap = leCsConfigCompleteView.GetChannelMap(),
            .minMainModeSteps = leCsConfigCompleteView.GetMinMainModeSteps(),
            .maxMainModeSteps = leCsConfigCompleteView.GetMaxMainModeSteps(),
            .mainModeRepetition =
                    static_cast<int8_t>(leCsConfigCompleteView.GetMainModeRepetition()),
            .mode0Steps = static_cast<int8_t>(leCsConfigCompleteView.GetMode0Steps()),
            .role = static_cast<Role>(static_cast<int>(leCsConfigCompleteView.GetRole())),
            .csSyncPhyType = static_cast<CsSyncPhyType>(
                    static_cast<int>(leCsConfigCompleteView.GetCsSyncPhy())),
            .channelSelectionType = static_cast<ChannelSelectionType>(
                    static_cast<int>(leCsConfigCompleteView.GetChannelSelectionType())),
            .ch3cShapeType = static_cast<Ch3cShapeType>(
                    static_cast<int>(leCsConfigCompleteView.GetCh3cShape())),
            .ch3cJump = static_cast<int8_t>(leCsConfigCompleteView.GetCh3cJump()),
            .channelMapRepetition = leCsConfigCompleteView.GetChannelMapRepetition(),
            .tIp1TimeUs = leCsConfigCompleteView.GetTIp1Time(),
            .tIp2TimeUs = leCsConfigCompleteView.GetTIp2Time(),
            .tFcsTimeUs = leCsConfigCompleteView.GetTFcsTime(),
            .tPmTimeUs = static_cast<int8_t>(leCsConfigCompleteView.GetTPmTime()),
            // TODO(b/378942784): specify the following values.
            .tSwTimeUsSupportedByLocal = 0,
            .tSwTimeUsSupportedByRemote = 0,
            .bleConnInterval = 0,
    };
    it->second->GetSession()->updateChannelSoundingConfig(csConfig);
  }

  void UpdateProcedureEnableConfig(
          uint16_t connection_handle,
          const hci::LeCsProcedureEnableCompleteView& leCsProcedureEnableCompleteView) override {
    auto it = session_trackers_.find(connection_handle);
    if (it == session_trackers_.end()) {
      log::error("Can't find session for connection_handle:0x{:04x}", connection_handle);
      return;
    } else if (it->second->GetSession() == nullptr) {
      log::error("Session not opened");
      return;
    }

    ProcedureEnableConfig pConfig{
            .toneAntennaConfigSelection = static_cast<int8_t>(
                    leCsProcedureEnableCompleteView.GetToneAntennaConfigSelection()),
            .subeventLenUs = static_cast<int>(leCsProcedureEnableCompleteView.GetSubeventLen()),
            .subeventsPerEvent =
                    static_cast<int8_t>(leCsProcedureEnableCompleteView.GetSubeventsPerEvent()),
            .subeventInterval = leCsProcedureEnableCompleteView.GetSubeventInterval(),
            .eventInterval = leCsProcedureEnableCompleteView.GetEventInterval(),
            .procedureInterval = leCsProcedureEnableCompleteView.GetProcedureInterval(),
            .procedureCount = leCsProcedureEnableCompleteView.GetProcedureCount(),
            // TODO(b/378942784): update the max procedure len, the current complete view does not
            // have it.
            .maxProcedureLen = 0,
    };

    it->second->GetSession()->updateProcedureEnableConfig(pConfig);
  }

  void CopyVendorSpecificData(const std::vector<hal::VendorSpecificCharacteristic>& source,
                              std::optional<std::vector<std::optional<VendorSpecificData>>>& dist) {
    dist = std::make_optional<std::vector<std::optional<VendorSpecificData>>>();
+9 −0
Original line number Diff line number Diff line
@@ -45,6 +45,15 @@ public:
  void WriteRawData(uint16_t /* connection_handle */,
                    const ChannelSoundingRawData& /* raw_data */) override {}

  void UpdateChannelSoundingConfig(
          uint16_t /* connection_handle */,
          const hci::LeCsConfigCompleteView& /* leCsConfigCompleteView */) override {}

  void UpdateProcedureEnableConfig(
          uint16_t /* connection_handle */,
          const hci::LeCsProcedureEnableCompleteView& /* leCsProcedureEnableCompleteView */)
          override {}

protected:
  void ListDependencies(ModuleList* /*list*/) const {}

+8 −0
Original line number Diff line number Diff line
@@ -939,6 +939,10 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
    live_tracker->main_mode_type = event_view.GetMainModeType();
    live_tracker->sub_mode_type = event_view.GetSubModeType();
    live_tracker->rtt_type = event_view.GetRttType();
    if (com::android::bluetooth::flags::channel_sounding_25q2_apis() && live_tracker->local_start &&
        ranging_hal_->GetRangingHalVersion() == hal::V_2) {
      ranging_hal_->UpdateChannelSoundingConfig(connection_handle, event_view);
    }
    if (live_tracker->local_hci_role == hci::Role::CENTRAL) {
      // send the cmd from the BLE central only.
      send_le_cs_security_enable(connection_handle);
@@ -1091,6 +1095,10 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
        distance_measurement_callbacks_->OnDistanceMeasurementStarted(live_tracker->address,
                                                                      METHOD_CS);
      }
      if (com::android::bluetooth::flags::channel_sounding_25q2_apis() &&
          live_tracker->local_start && ranging_hal_->GetRangingHalVersion() == hal::V_2) {
        ranging_hal_->UpdateProcedureEnableConfig(connection_handle, event_view);
      }
    } else if (event_view.GetState() == Enable::DISABLED) {
      uint8_t valid_requester_states = static_cast<uint8_t>(CsTrackerState::STARTED);
      uint8_t valid_responder_states = static_cast<uint8_t>(CsTrackerState::STARTED);