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

Commit 5583de15 authored by Steven Liu's avatar Steven Liu
Browse files

handle the CS capabilities

1. handle the result of local capabilities command failure;
2. pass the remote and local SW time(antenna switch)

Flag: com.android.bluetooth.flags.channel_sounding_25q2_apis
Bug: 367409858
Bug: 378942784
Test: m com.android.btservices
Change-Id: I73550041321a4d0b3540891feb89e61b0b02701b
parent 4292d792
Loading
Loading
Loading
Loading
+2 −2
Original line number Diff line number Diff line
@@ -313,8 +313,8 @@ public:
          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;
          uint16_t connection_handle, const hci::LeCsConfigCompleteView& leCsConfigCompleteView,
          uint8_t local_supported_sw_time, uint8_t remote_supported_sw_time) = 0;
  virtual void UpdateProcedureEnableConfig(
          uint16_t connection_handle,
          const hci::LeCsProcedureEnableCompleteView& leCsProcedureEnableCompleteView) = 0;
+8 −6
Original line number Diff line number Diff line
@@ -262,9 +262,10 @@ public:
    session_trackers_[connection_handle]->GetSession()->writeRawData(hal_raw_data);
  }

  void UpdateChannelSoundingConfig(
          uint16_t connection_handle,
          const hci::LeCsConfigCompleteView& leCsConfigCompleteView) override {
  void UpdateChannelSoundingConfig(uint16_t connection_handle,
                                   const hci::LeCsConfigCompleteView& leCsConfigCompleteView,
                                   uint8_t local_supported_sw_time,
                                   uint8_t remote_supported_sw_time) 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);
@@ -299,11 +300,12 @@ public:
            .tIp2TimeUs = leCsConfigCompleteView.GetTIp2Time(),
            .tFcsTimeUs = leCsConfigCompleteView.GetTFcsTime(),
            .tPmTimeUs = static_cast<int8_t>(leCsConfigCompleteView.GetTPmTime()),
            // TODO(b/378942784): specify the following values.
            .tSwTimeUsSupportedByLocal = 0,
            .tSwTimeUsSupportedByRemote = 0,
            .tSwTimeUsSupportedByLocal = static_cast<int8_t>(local_supported_sw_time),
            .tSwTimeUsSupportedByRemote = static_cast<int8_t>(remote_supported_sw_time),
            // TODO(b/378942784): specify the ble connection interval.
            .bleConnInterval = 0,
    };

    it->second->GetSession()->updateChannelSoundingConfig(csConfig);
  }

+4 −3
Original line number Diff line number Diff line
@@ -45,9 +45,10 @@ public:
  void WriteRawData(uint16_t /* connection_handle */,
                    const ChannelSoundingRawData& /* raw_data */) override {}

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

  void UpdateProcedureEnableConfig(
          uint16_t /* connection_handle */,
+11 −3
Original line number Diff line number Diff line
@@ -187,10 +187,11 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
    CsRttType rtt_type = CsRttType::RTT_AA_ONLY;
    bool remote_support_phase_based_ranging = false;
    uint8_t remote_num_antennas_supported_ = 0x01;
    uint8_t remote_supported_sw_time_ = 0;
    // sending from host to controller with CS config command, request the controller to use it.
    uint8_t requesting_config_id = kInvalidConfigId;
    // received from controller to host with CS config complete event, it will be used
    // for the following measruement.
    // for the following measurement.
    uint8_t used_config_id = kInvalidConfigId;
    uint8_t selected_tx_power = 0;
    std::vector<CsProcedureData> procedure_data_list = {};
@@ -406,7 +407,7 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
  void start_distance_measurement_with_cs(const Address& cs_remote_address,
                                          uint16_t connection_handle) {
    log::info("connection_handle: {}, address: {}", connection_handle, cs_remote_address);
    if (!com::android::bluetooth::flags::channel_sounding_in_stack()) {
    if (!com::android::bluetooth::flags::channel_sounding_in_stack() && !is_local_cs_ready_) {
      log::error("Channel Sounding is not enabled");
      distance_measurement_callbacks_->OnDistanceMeasurementStopped(
              cs_remote_address, REASON_INTERNAL_ERROR, METHOD_CS);
@@ -812,6 +813,8 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
    cs_subfeature_supported_ = complete_view.GetOptionalSubfeaturesSupported();
    num_antennas_supported_ = complete_view.GetNumAntennasSupported();
    local_support_phase_based_ranging_ = cs_subfeature_supported_.phase_based_ranging_ == 0x01;
    local_supported_sw_time_ = complete_view.GetTSwTimeSupported();
    is_local_cs_ready_ = true;
  }

  void on_cs_read_remote_supported_capabilities_complete(
@@ -844,6 +847,7 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
      log::info("Setup phase complete, connection_handle: {}, address: {}", connection_handle,
                req_it->second.address);
      req_it->second.retry_counter_for_create_config = 0;
      req_it->second.remote_supported_sw_time_ = event_view.GetTSwTimeSupported();
      send_le_cs_create_config(connection_handle, req_it->second.requesting_config_id);
    }
    log::info(
@@ -944,7 +948,9 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
    live_tracker->sub_mode_type = event_view.GetSubModeType();
    live_tracker->rtt_type = event_view.GetRttType();
    if (live_tracker->local_start && is_hal_v2()) {
      ranging_hal_->UpdateChannelSoundingConfig(connection_handle, event_view);
      ranging_hal_->UpdateChannelSoundingConfig(connection_handle, event_view,
                                                local_supported_sw_time_,
                                                live_tracker->remote_supported_sw_time_);
    }
    if (live_tracker->local_hci_role == hci::Role::CENTRAL) {
      // send the cmd from the BLE central only.
@@ -2386,6 +2392,8 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
  CsOptionalSubfeaturesSupported cs_subfeature_supported_;
  uint8_t num_antennas_supported_ = 0x01;
  bool local_support_phase_based_ranging_ = false;
  uint8_t local_supported_sw_time_ = 0;
  bool is_local_cs_ready_ = false;
  // A table that maps num_antennas_supported and remote_num_antennas_supported to Antenna
  // Configuration Index.
  uint8_t cs_tone_antenna_config_mapping_table_[4][4] = {