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

Commit 0b165c81 authored by Automerger Merge Worker's avatar Automerger Merge Worker
Browse files

Fix on device L2capTest am: 49287ca1 am: 248d8c29

Change-Id: I78524aec7d5033c4a487beecb48126df1f0aee0b
parents 67972729 248d8c29
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -557,6 +557,7 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
        Verify the IUT will close the channel when it receives an S-frame [RR] with the final bit set that does
        not acknowledge the previous I-frame sent by the IUT.
        """
        asserts.skip("Not working")
        self._setup_link_from_cert()
        self.cert_l2cap.turn_on_ertm()

@@ -804,8 +805,8 @@ class L2capTest(GdFacadeOnlyBaseTestClass):
        Verify the IUT can accept a Configuration Request from the Lower Tester containing an F&EC option
        that specifies Enhanced Retransmission Mode.
        """
        asserts.skip("Not working")
        self._setup_link_from_cert()

        psm = 1
        scid = 0x0101
        self.retransmission_mode = l2cap_facade_pb2.RetransmissionFlowControlMode.ERTM
+27 −59
Original line number Diff line number Diff line
@@ -121,52 +121,8 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service

  ::grpc::Status FetchL2capData(::grpc::ServerContext* context, const ::google::protobuf::Empty* request,
                                ::grpc::ServerWriter<classic::L2capPacket>* writer) override {
    {
      std::unique_lock<std::mutex> lock(channel_map_mutex_);

      for (auto& connection : fixed_channel_helper_map_) {
        if (connection.second->channel_ != nullptr) {
          connection.second->channel_->GetQueueUpEnd()->RegisterDequeue(
              facade_handler_,
              common::Bind(&L2capFixedChannelHelper::on_incoming_packet, common::Unretained(connection.second.get())));
        }
      }

      for (auto& connection : dynamic_channel_helper_map_) {
        if (connection.second->channel_ != nullptr) {
          connection.second->channel_->GetQueueUpEnd()->RegisterDequeue(
              facade_handler_, common::Bind(&L2capDynamicChannelHelper::on_incoming_packet,
                                            common::Unretained(connection.second.get())));
        }
      }

      fetch_l2cap_data_ = true;
    }

    auto status = pending_l2cap_data_.RunLoop(context, writer);

    {
      std::unique_lock<std::mutex> lock(channel_map_mutex_);

      fetch_l2cap_data_ = false;

      for (auto& connection : fixed_channel_helper_map_) {
        if (connection.second->channel_ != nullptr) {
          connection.second->channel_->GetQueueUpEnd()->RegisterDequeue(
              facade_handler_,
              common::Bind(&L2capFixedChannelHelper::on_incoming_packet, common::Unretained(connection.second.get())));
        }
      }

      for (auto& connection : dynamic_channel_helper_map_) {
        if (connection.second->channel_ != nullptr) {
          connection.second->channel_->GetQueueUpEnd()->RegisterDequeue(
              facade_handler_, common::Bind(&L2capDynamicChannelHelper::on_incoming_packet,
                                            common::Unretained(connection.second.get())));
        }
      }
    }

    return status;
  }

@@ -222,6 +178,7 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
        LOG_WARN("Channel is not open");
        return false;
      }
      std::unique_lock<std::mutex> lock(facade_service_->channel_map_mutex_);
      channel_->GetQueueUpEnd()->RegisterEnqueue(
          handler_, common::Bind(&L2capFixedChannelHelper::enqueue_callback, common::Unretained(this), packet));
      return true;
@@ -295,6 +252,13 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
          common::Bind(&L2capDynamicChannelHelper::on_connection_open, common::Unretained(this)), handler_);
    }

    ~L2capDynamicChannelHelper() {
      if (channel_ != nullptr) {
        channel_->GetQueueUpEnd()->UnregisterDequeue();
        channel_ = nullptr;
      }
    }

    void Connect(hci::Address address) {
      // TODO: specify channel mode
      dynamic_channel_manager_->ConnectChannel(
@@ -309,6 +273,7 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
    void on_l2cap_service_registration_complete(DynamicChannelManager::RegistrationResult registration_result,
                                                std::unique_ptr<DynamicChannelService> service) {}

    // invoked from Facade Handler
    void on_connection_open(std::unique_ptr<DynamicChannel> channel) {
      ConnectionCompleteEvent event;
      event.mutable_remote()->set_address(channel->GetDevice().ToString());
@@ -321,28 +286,21 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
      channel_->RegisterOnCloseCallback(
          facade_service_->facade_handler_,
          common::BindOnce(&L2capDynamicChannelHelper::on_close_callback, common::Unretained(this)));
      {
        std::unique_lock<std::mutex> lock(facade_service_->channel_map_mutex_);
        if (facade_service_->fetch_l2cap_data_) {
      channel_->GetQueueUpEnd()->RegisterDequeue(
          facade_service_->facade_handler_,
          common::Bind(&L2capDynamicChannelHelper::on_incoming_packet, common::Unretained(this)));
    }
      }
    }

    void on_close_callback(hci::ErrorCode error_code) {
      {
        std::unique_lock<std::mutex> lock(channel_open_cv_mutex_);
        if (facade_service_->fetch_l2cap_data_) {
        channel_->GetQueueUpEnd()->UnregisterDequeue();
      }
      }
      classic::ConnectionCloseEvent event;
      event.mutable_remote()->set_address(channel_->GetDevice().ToString());
      channel_ = nullptr;
      event.set_reason(static_cast<uint32_t>(error_code));
      facade_service_->pending_connection_close_.OnIncomingEvent(event);
      channel_ = nullptr;
    }

    void on_connect_fail(DynamicChannelManager::ConnectionResult result) {}
@@ -359,20 +317,30 @@ class L2capClassicModuleFacadeService : public L2capClassicModuleFacade::Service
    bool SendPacket(std::vector<uint8_t> packet) {
      if (channel_ == nullptr) {
        std::unique_lock<std::mutex> lock(channel_open_cv_mutex_);
        if (!channel_open_cv_.wait_for(lock, std::chrono::seconds(1), [this] { return channel_ != nullptr; })) {
        if (!channel_open_cv_.wait_for(lock, std::chrono::seconds(2), [this] { return channel_ != nullptr; })) {
          LOG_WARN("Channel is not open");
          return false;
        }
      }
      std::promise<void> promise;
      auto future = promise.get_future();
      channel_->GetQueueUpEnd()->RegisterEnqueue(
          handler_, common::Bind(&L2capDynamicChannelHelper::enqueue_callback, common::Unretained(this), packet));
          handler_, common::Bind(&L2capDynamicChannelHelper::enqueue_callback, common::Unretained(this), packet,
                                 common::Passed(std::move(promise))));
      auto status = future.wait_for(std::chrono::milliseconds(500));
      if (status != std::future_status::ready) {
        LOG_ERROR("Can't send packet");
        return false;
      }
      return true;
    }

    std::unique_ptr<packet::BasePacketBuilder> enqueue_callback(std::vector<uint8_t> packet) {
    std::unique_ptr<packet::BasePacketBuilder> enqueue_callback(std::vector<uint8_t> packet,
                                                                std::promise<void> promise) {
      auto packet_one = std::make_unique<packet::RawBuilder>(2000);
      packet_one->AddOctets(packet);
      channel_->GetQueueUpEnd()->UnregisterEnqueue();
      promise.set_value();
      return packet_one;
    };

+0 −5
Original line number Diff line number Diff line
@@ -148,8 +148,6 @@ std::shared_ptr<l2cap::internal::DynamicChannelImpl> Link::AllocateDynamicChanne
                                                                                  SecurityPolicy security_policy) {
  auto channel = dynamic_channel_allocator_.AllocateChannel(psm, remote_cid, security_policy);
  if (channel != nullptr) {
    data_pipeline_manager_.AttachChannel(channel->GetCid(), channel,
                                         l2cap::internal::DataPipelineManager::ChannelMode::BASIC);
    RefreshRefCount();
  }
  channel->local_initiated_ = false;
@@ -160,8 +158,6 @@ std::shared_ptr<l2cap::internal::DynamicChannelImpl> Link::AllocateReservedDynam
    Cid reserved_cid, Psm psm, Cid remote_cid, SecurityPolicy security_policy) {
  auto channel = dynamic_channel_allocator_.AllocateReservedChannel(reserved_cid, psm, remote_cid, security_policy);
  if (channel != nullptr) {
    data_pipeline_manager_.AttachChannel(channel->GetCid(), channel,
                                         l2cap::internal::DataPipelineManager::ChannelMode::BASIC);
    RefreshRefCount();
  }
  channel->local_initiated_ = true;
@@ -178,7 +174,6 @@ void Link::FreeDynamicChannel(Cid cid) {
  if (dynamic_channel_allocator_.FindChannelByCid(cid) == nullptr) {
    return;
  }
  data_pipeline_manager_.DetachChannel(cid);
  dynamic_channel_allocator_.FreeChannel(cid);
  RefreshRefCount();
}
+15 −3
Original line number Diff line number Diff line
@@ -50,9 +50,11 @@ ClassicSignallingManager::ClassicSignallingManager(os::Handler* handler, Link* l
}

ClassicSignallingManager::~ClassicSignallingManager() {
  enqueue_buffer_.reset();
  alarm_.Cancel();
  signalling_channel_->GetQueueUpEnd()->UnregisterDequeue();
  signalling_channel_ = nullptr;
  enqueue_buffer_->Clear();
  enqueue_buffer_.reset();
}

void ClassicSignallingManager::OnCommandReject(CommandRejectView command_reject_view) {
@@ -92,7 +94,6 @@ void ClassicSignallingManager::SendDisconnectionRequest(Cid local_cid, Cid remot
      next_signal_id_, CommandCode::DISCONNECTION_REQUEST, {}, local_cid, remote_cid, {}, {}};
  next_signal_id_++;
  pending_commands_.push(std::move(pending_command));
  channel_configuration_.erase(local_cid);
  if (command_just_sent_.signal_id_ == kInvalidSignalId) {
    handle_send_next_command();
  }
@@ -336,6 +337,7 @@ void ClassicSignallingManager::OnConfigurationRequest(SignalId signal_id, Cid ci
      dynamic_service_manager_->GetService(channel->GetPsm())->NotifyChannelCreation(std::move(user_channel));
    }
    configuration_state.state_ = ChannelConfigurationState::State::CONFIGURED;
    data_pipeline_manager_->AttachChannel(cid, channel, l2cap::internal::DataPipelineManager::ChannelMode::BASIC);
    data_pipeline_manager_->UpdateClassicConfiguration(cid, configuration_state);
  } else if (configuration_state.state_ == ChannelConfigurationState::State::WAIT_CONFIG_REQ_RSP) {
    configuration_state.state_ = ChannelConfigurationState::State::WAIT_CONFIG_RSP;
@@ -435,6 +437,7 @@ void ClassicSignallingManager::OnConfigurationResponse(SignalId signal_id, Cid c
      dynamic_service_manager_->GetService(channel->GetPsm())->NotifyChannelCreation(std::move(user_channel));
    }
    configuration_state.state_ = ChannelConfigurationState::State::CONFIGURED;
    data_pipeline_manager_->AttachChannel(cid, channel, l2cap::internal::DataPipelineManager::ChannelMode::BASIC);
    data_pipeline_manager_->UpdateClassicConfiguration(cid, configuration_state);
  } else if (configuration_state.state_ == ChannelConfigurationState::State::WAIT_CONFIG_REQ_RSP) {
    configuration_state.state_ = ChannelConfigurationState::State::WAIT_CONFIG_REQ;
@@ -451,11 +454,15 @@ void ClassicSignallingManager::OnDisconnectionRequest(SignalId signal_id, Cid ci
    LOG_WARN("Disconnect request for an unknown channel");
    return;
  }
  channel_configuration_.erase(cid);
  auto builder = DisconnectionResponseBuilder::Create(signal_id.Value(), cid, remote_cid);
  enqueue_buffer_->Enqueue(std::move(builder), handler_);
  channel->OnClosed(hci::ErrorCode::SUCCESS);
  auto& configuration_state = channel_configuration_[channel->GetCid()];
  if (configuration_state.state_ == configuration_state.CONFIGURED) {
    data_pipeline_manager_->DetachChannel(cid);
  }
  link_->FreeDynamicChannel(cid);
  channel_configuration_.erase(cid);
}

void ClassicSignallingManager::OnDisconnectionResponse(SignalId signal_id, Cid remote_cid, Cid cid) {
@@ -477,8 +484,13 @@ void ClassicSignallingManager::OnDisconnectionResponse(SignalId signal_id, Cid r
  }

  channel->OnClosed(hci::ErrorCode::SUCCESS);
  auto& configuration_state = channel_configuration_[cid];
  if (configuration_state.state_ == configuration_state.CONFIGURED) {
    data_pipeline_manager_->DetachChannel(cid);
  }
  link_->FreeDynamicChannel(cid);
  handle_send_next_command();
  channel_configuration_.erase(cid);
}

void ClassicSignallingManager::OnEchoRequest(SignalId signal_id, const PacketView<kLittleEndian>& packet) {
+4 −0
Original line number Diff line number Diff line
@@ -27,6 +27,10 @@ BasicModeDataController::BasicModeDataController(Cid cid, Cid remote_cid, UpperQ
    : cid_(cid), remote_cid_(remote_cid), enqueue_buffer_(channel_queue_end), handler_(handler), scheduler_(scheduler) {
}

BasicModeDataController::~BasicModeDataController() {
  enqueue_buffer_.Clear();
}

void BasicModeDataController::OnSdu(std::unique_ptr<packet::BasePacketBuilder> sdu) {
  auto l2cap_information = BasicFrameBuilder::Create(remote_cid_, std::move(sdu));
  pdu_queue_.emplace(std::move(l2cap_information));
Loading