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

Commit 5fb6589e authored by Chris Manton's avatar Chris Manton Committed by android-build-merger
Browse files

Add remote cid insertion to packet for transmission am: 8b518cd2

am: 21b804f2

Change-Id: I72c273bf490d2b23bd6c8092c514db08f50956e3
parents b7c8e50e 21b804f2
Loading
Loading
Loading
Loading
+3 −3
Original line number Diff line number Diff line
@@ -58,7 +58,7 @@ void Link::Disconnect() {

std::shared_ptr<FixedChannelImpl> Link::AllocateFixedChannel(Cid cid, SecurityPolicy security_policy) {
  auto channel = fixed_channel_allocator_.AllocateChannel(cid, security_policy);
  scheduler_->AttachChannel(cid, channel->GetQueueDownEnd());
  scheduler_->AttachChannel(cid, channel->GetQueueDownEnd(), cid);
  return channel;
}

@@ -86,7 +86,7 @@ std::shared_ptr<DynamicChannelImpl> Link::AllocateDynamicChannel(Psm psm, Cid re
                                                                 SecurityPolicy security_policy) {
  auto channel = dynamic_channel_allocator_.AllocateChannel(psm, remote_cid, security_policy);
  if (channel != nullptr) {
    scheduler_->AttachChannel(channel->GetCid(), channel->GetQueueDownEnd());
    scheduler_->AttachChannel(channel->GetCid(), channel->GetQueueDownEnd(), channel->GetRemoteCid());
  }
  return channel;
}
@@ -95,7 +95,7 @@ std::shared_ptr<DynamicChannelImpl> Link::AllocateReservedDynamicChannel(Cid res
                                                                         SecurityPolicy security_policy) {
  auto channel = dynamic_channel_allocator_.AllocateReservedChannel(reserved_cid, psm, remote_cid, security_policy);
  if (channel != nullptr) {
    scheduler_->AttachChannel(channel->GetCid(), channel->GetQueueDownEnd());
    scheduler_->AttachChannel(channel->GetCid(), channel->GetQueueDownEnd(), channel->GetRemoteCid());
  }
  return channel;
}
+2 −1
Original line number Diff line number Diff line
@@ -48,8 +48,9 @@ class Scheduler {
   *
   * @param cid The channel to attach to the scheduler.
   * @param channel_down_end The ChannelQueueDownEnd associated with the channel to attach to the scheduler.
   * @param remote_cid The destination endpoint of the packet.
   */
  virtual void AttachChannel(Cid cid, UpperQueueDownEnd* channel_down_end) {}
  virtual void AttachChannel(Cid cid, UpperQueueDownEnd* channel_down_end, Cid remote_cid) {}

  /**
   * Detach the channel from the scheduler.
+4 −3
Original line number Diff line number Diff line
@@ -30,10 +30,10 @@ Fifo::~Fifo() {
  }
}

void Fifo::AttachChannel(Cid cid, UpperQueueDownEnd* channel_down_end) {
void Fifo::AttachChannel(Cid cid, UpperQueueDownEnd* channel_down_end, Cid remote_cid) {
  ASSERT(channel_queue_end_map_.find(cid) == channel_queue_end_map_.end());
  channel_queue_end_map_.emplace(std::piecewise_construct, std::forward_as_tuple(cid),
                                 std::forward_as_tuple(handler_, channel_down_end, this, cid));
                                 std::forward_as_tuple(handler_, channel_down_end, this, cid, remote_cid));
}

void Fifo::DetachChannel(Cid cid) {
@@ -55,7 +55,8 @@ std::unique_ptr<Fifo::UpperDequeue> Fifo::link_queue_enqueue_callback() {
    link_queue_up_end_->UnregisterEnqueue();
    link_queue_enqueue_registered_ = false;
  }
  return BasicFrameBuilder::Create(channel_id, std::move(packet));
  Cid remote_channel_id = channel_queue_end_map_.find(channel_id)->second.remote_channel_id_;
  return BasicFrameBuilder::Create(remote_channel_id, std::move(packet));
}

void Fifo::try_register_link_queue_enqueue() {
+5 −3
Original line number Diff line number Diff line
@@ -42,7 +42,7 @@ class Fifo : public Scheduler {
  }

  ~Fifo() override;
  void AttachChannel(Cid cid, UpperQueueDownEnd* channel_down_end) override;
  void AttachChannel(Cid cid, UpperQueueDownEnd* channel_down_end, Cid remote_cid) override;
  void DetachChannel(Cid cid) override;
  LowerQueueUpEnd* GetLowerQueueUpEnd() const override {
    return link_queue_up_end_;
@@ -53,9 +53,10 @@ class Fifo : public Scheduler {
  os::Handler* handler_;

  struct ChannelQueueEndAndBuffer {
    ChannelQueueEndAndBuffer(os::Handler* handler, UpperQueueDownEnd* queue_end, Fifo* scheduler, Cid channel_id)
    ChannelQueueEndAndBuffer(os::Handler* handler, UpperQueueDownEnd* queue_end, Fifo* scheduler, Cid channel_id,
                             Cid remote_channel_id)
        : handler_(handler), queue_end_(queue_end), enqueue_buffer_(queue_end), scheduler_(scheduler),
          channel_id_(channel_id) {
          channel_id_(channel_id), remote_channel_id_(remote_channel_id) {
      try_register_dequeue();
    }
    os::Handler* handler_;
@@ -65,6 +66,7 @@ class Fifo : public Scheduler {
    std::queue<std::unique_ptr<UpperDequeue>> dequeue_buffer_;
    Fifo* scheduler_;
    Cid channel_id_;
    Cid remote_channel_id_;
    bool is_dequeue_registered_ = false;

    void try_register_dequeue();
+4 −4
Original line number Diff line number Diff line
@@ -78,8 +78,8 @@ class L2capSchedulerFifoTest : public ::testing::Test {
TEST_F(L2capSchedulerFifoTest, receive_packet) {
  common::BidiQueue<Scheduler::UpperEnqueue, Scheduler::UpperDequeue> channel_one_queue_{10};
  common::BidiQueue<Scheduler::UpperEnqueue, Scheduler::UpperDequeue> channel_two_queue_{10};
  fifo_->AttachChannel(1, channel_one_queue_.GetDownEnd());
  fifo_->AttachChannel(2, channel_two_queue_.GetDownEnd());
  fifo_->AttachChannel(1, channel_one_queue_.GetDownEnd(), 1);
  fifo_->AttachChannel(2, channel_two_queue_.GetDownEnd(), 2);
  os::EnqueueBuffer<Scheduler::UpperEnqueue> link_queue_enqueue_buffer{link_queue_.GetDownEnd()};
  auto packet_one = CreateSampleL2capPacket(1, {1, 2, 3});
  auto packet_two = CreateSampleL2capPacket(2, {4, 5, 6, 7});
@@ -103,8 +103,8 @@ TEST_F(L2capSchedulerFifoTest, receive_packet) {
TEST_F(L2capSchedulerFifoTest, send_packet) {
  common::BidiQueue<Scheduler::UpperEnqueue, Scheduler::UpperDequeue> channel_one_queue_{10};
  common::BidiQueue<Scheduler::UpperEnqueue, Scheduler::UpperDequeue> channel_two_queue_{10};
  fifo_->AttachChannel(1, channel_one_queue_.GetDownEnd());
  fifo_->AttachChannel(2, channel_two_queue_.GetDownEnd());
  fifo_->AttachChannel(1, channel_one_queue_.GetDownEnd(), 1);
  fifo_->AttachChannel(2, channel_two_queue_.GetDownEnd(), 2);
  os::EnqueueBuffer<Scheduler::UpperDequeue> channel_one_enqueue_buffer{channel_one_queue_.GetUpEnd()};
  os::EnqueueBuffer<Scheduler::UpperDequeue> channel_two_enqueue_buffer{channel_two_queue_.GetUpEnd()};
  auto packet_one = std::make_unique<packet::RawBuilder>();
Loading