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

Commit 23b83cc0 authored by Treehugger Robot's avatar Treehugger Robot Committed by Gerrit Code Review
Browse files

Merge "correct the operations before and after sending cs security enable" into main

parents 4bd18ce9 8d26ee09
Loading
Loading
Loading
Loading
+27 −9
Original line number Diff line number Diff line
@@ -673,11 +673,25 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
            handler_->BindOnceOn(this, &impl::on_cs_setup_command_status_cb, connection_handle));
  }

  void send_le_cs_security_enable(uint16_t connection_handle) {
    if (cs_requester_trackers_.find(connection_handle) == cs_requester_trackers_.end()) {
      log::warn("no cs tracker found for {}", connection_handle);
  void send_le_cs_security_enable(uint16_t connection_handle, bool local_start) {
    if (local_start) {
      auto req_it = cs_requester_trackers_.find(connection_handle);
      if (req_it != cs_requester_trackers_.end() &&
          req_it->second.state == CsTrackerState::WAIT_FOR_CONFIG_COMPLETE) {
        req_it->second.state = CsTrackerState::WAIT_FOR_SECURITY_ENABLED;
      } else {
        log::error("no requester tracker. something wrong.");
      }
    } else {
      auto res_it = cs_responder_trackers_.find(connection_handle);
      if (res_it != cs_requester_trackers_.end() &&
          res_it->second.state == CsTrackerState::WAIT_FOR_CONFIG_COMPLETE) {
        res_it->second.state = CsTrackerState::WAIT_FOR_SECURITY_ENABLED;
      } else {
        log::error("no responder tracker. something wrong.");
      }
    cs_requester_trackers_[connection_handle].state = CsTrackerState::WAIT_FOR_SECURITY_ENABLED;
    }

    hci_layer_->EnqueueCommand(
            LeCsSecurityEnableBuilder::Create(connection_handle),
            handler_->BindOnceOn(this, &impl::on_cs_setup_command_status_cb, connection_handle));
@@ -911,7 +925,8 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
      return;
    }
    auto req_it = cs_requester_trackers_.find(connection_handle);
    if (req_it != cs_requester_trackers_.end() && req_it->second.measurement_ongoing) {
    if (req_it != cs_requester_trackers_.end() &&
        req_it->second.state == CsTrackerState::WAIT_FOR_SECURITY_ENABLED) {
      send_le_cs_set_procedure_parameters(event_view.GetConnectionHandle(),
                                          req_it->second.used_config_id,
                                          req_it->second.remote_num_antennas_supported_);
@@ -965,6 +980,10 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
      log::warn("Can't find cs tracker for connection_handle {}", connection_handle);
      return;
    }
    if (!live_tracker->local_start) {
      // reset the responder state, as no other event to set the state.
      live_tracker->state = CsTrackerState::WAIT_FOR_CONFIG_COMPLETE;
    }

    live_tracker->used_config_id = config_id;
    log::info("Get {}", event_view.ToString());
@@ -979,10 +998,9 @@ struct DistanceMeasurementManager::impl : bluetooth::hal::RangingHalCallback {
    }
    if (live_tracker->local_hci_role == hci::Role::CENTRAL) {
      // send the cmd from the BLE central only.
      send_le_cs_security_enable(connection_handle);
    }
      send_le_cs_security_enable(connection_handle, live_tracker->local_start);
    } else {
      // TODO: else set a timeout alarm to make sure the remote would trigger the cmd.
    if (!live_tracker->local_start) {
      live_tracker->state = CsTrackerState::WAIT_FOR_SECURITY_ENABLED;
    }
  }