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

Commit 04d894a8 authored by Hansong Zhang's avatar Hansong Zhang Committed by android-build-merger
Browse files

Merge "L2CAP Data pipeline rework"

am: abfd6408

Change-Id: I693e59d703a5b329e377f8fb11e0f954b793c2cc
parents f4c7575a abfd6408
Loading
Loading
Loading
Loading
+6 −4
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@ filegroup {
        "classic/internal/link_manager.cc",
        "classic/internal/signalling_manager.cc",
        "classic/l2cap_classic_module.cc",
        "internal/reassembler.cc",
        "internal/basic_mode_channel_data_controller.cc",
        "internal/enhanced_retransmission_mode_channel_data_controller.cc",
        "internal/receiver.cc",
        "internal/scheduler_fifo.cc",
        "internal/segmenter.cc",
        "internal/sender.cc",
        "le/internal/fixed_channel_impl.cc",
        "le/internal/fixed_channel_service_manager_impl.cc",
        "le/internal/link_manager.cc",
@@ -41,9 +43,9 @@ filegroup {
        "classic/internal/link_manager_test.cc",
        "classic/internal/signalling_manager_test.cc",
        "internal/fixed_channel_allocator_test.cc",
        "internal/reassembler_test.cc",
        "internal/receiver_test.cc",
        "internal/scheduler_fifo_test.cc",
        "internal/segmenter_test.cc",
        "internal/sender_test.cc",
        "l2cap_packet_test.cc",
        "le/internal/fixed_channel_impl_test.cc",
        "le/internal/fixed_channel_service_manager_test.cc",
+10 −5
Original line number Diff line number Diff line
@@ -35,8 +35,8 @@ Link::Link(os::Handler* l2cap_handler, std::unique_ptr<hci::AclConnection> acl_c
           l2cap::internal::ParameterProvider* parameter_provider,
           DynamicChannelServiceManagerImpl* dynamic_service_manager,
           FixedChannelServiceManagerImpl* fixed_service_manager)
    : l2cap_handler_(l2cap_handler), acl_connection_(std::move(acl_connection)),
      reassembler_(acl_connection_->GetAclQueueEnd(), l2cap_handler_), scheduler_(std::move(scheduler)),
    : l2cap_handler_(l2cap_handler), acl_connection_(std::move(acl_connection)), scheduler_(std::move(scheduler)),
      receiver_(acl_connection_->GetAclQueueEnd(), l2cap_handler_, scheduler_.get()),
      parameter_provider_(parameter_provider), dynamic_service_manager_(dynamic_service_manager),
      fixed_service_manager_(fixed_service_manager),
      signalling_manager_(l2cap_handler_, this, dynamic_service_manager_, &dynamic_channel_allocator_,
@@ -61,7 +61,6 @@ 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);
  reassembler_.AttachChannel(cid, channel);
  return channel;
}

@@ -96,7 +95,6 @@ std::shared_ptr<DynamicChannelImpl> Link::AllocateDynamicChannel(Psm psm, Cid re
  auto channel = dynamic_channel_allocator_.AllocateChannel(psm, remote_cid, security_policy);
  if (channel != nullptr) {
    scheduler_->AttachChannel(channel->GetCid(), channel);
    reassembler_.AttachChannel(channel->GetCid(), channel);
  }
  channel->local_initiated_ = false;
  return channel;
@@ -107,12 +105,19 @@ std::shared_ptr<DynamicChannelImpl> Link::AllocateReservedDynamicChannel(Cid res
  auto channel = dynamic_channel_allocator_.AllocateReservedChannel(reserved_cid, psm, remote_cid, security_policy);
  if (channel != nullptr) {
    scheduler_->AttachChannel(channel->GetCid(), channel);
    reassembler_.AttachChannel(channel->GetCid(), channel);
  }
  channel->local_initiated_ = true;
  return channel;
}

void Link::SetChannelRetransmissionFlowControlMode(Cid cid, RetransmissionAndFlowControlModeOption mode) {
  if (dynamic_channel_allocator_.FindChannelByCid(cid) == nullptr) {
    LOG_ERROR("Channel doesn't exist: %d", cid);
    return;
  }
  scheduler_->SetChannelRetransmissionFlowControlMode(cid, mode);
}

void Link::FreeDynamicChannel(Cid cid) {
  if (dynamic_channel_allocator_.FindChannelByCid(cid) == nullptr) {
    return;
+4 −2
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@
#include "l2cap/classic/internal/fixed_channel_service_manager_impl.h"
#include "l2cap/internal/fixed_channel_allocator.h"
#include "l2cap/internal/parameter_provider.h"
#include "l2cap/internal/reassembler.h"
#include "l2cap/internal/receiver.h"
#include "l2cap/internal/scheduler.h"
#include "os/alarm.h"
#include "os/handler.h"
@@ -87,6 +87,8 @@ class Link {
  virtual std::shared_ptr<DynamicChannelImpl> AllocateReservedDynamicChannel(Cid reserved_cid, Psm psm, Cid remote_cid,
                                                                             SecurityPolicy security_policy);

  virtual void SetChannelRetransmissionFlowControlMode(Cid cid, RetransmissionAndFlowControlModeOption mode);

  virtual void FreeDynamicChannel(Cid cid);

  // Check how many channels are acquired or in use, if zero, start tear down timer, if non-zero, cancel tear down timer
@@ -100,8 +102,8 @@ class Link {
  l2cap::internal::FixedChannelAllocator<FixedChannelImpl, Link> fixed_channel_allocator_{this, l2cap_handler_};
  DynamicChannelAllocator dynamic_channel_allocator_{this, l2cap_handler_};
  std::unique_ptr<hci::AclConnection> acl_connection_;
  l2cap::internal::Reassembler reassembler_;
  std::unique_ptr<l2cap::internal::Scheduler> scheduler_;
  l2cap::internal::Receiver receiver_;
  l2cap::internal::ParameterProvider* parameter_provider_;
  DynamicChannelServiceManagerImpl* dynamic_service_manager_;
  FixedChannelServiceManagerImpl* fixed_service_manager_;
+46 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#include "l2cap/internal/basic_mode_channel_data_controller.h"

namespace bluetooth {
namespace l2cap {
namespace internal {

BasicModeDataController::BasicModeDataController(Cid cid, Cid remote_cid, UpperQueueDownEnd* channel_queue_end,
                                                 os::Handler* handler, Scheduler* scheduler)
    : cid_(cid), remote_cid_(remote_cid), enqueue_buffer_(channel_queue_end), handler_(handler), scheduler_(scheduler) {
}

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));
  scheduler_->OnPacketsReady(cid_, 1);
}

void BasicModeDataController::OnPdu(BasicFrameView pdu) {
  enqueue_buffer_.Enqueue(std::make_unique<PacketView<kLittleEndian>>(pdu.GetPayload()), handler_);
}

std::unique_ptr<BasicFrameBuilder> BasicModeDataController::GetNextPacket() {
  auto next = std::move(pdu_queue_.front());
  pdu_queue_.pop();
  return next;
}

}  // namespace internal
}  // namespace l2cap
}  // namespace bluetooth
+64 −0
Original line number Diff line number Diff line
/*
 * Copyright 2019 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

#pragma once

#include <memory>
#include <unordered_map>
#include <utility>

#include "common/bidi_queue.h"
#include "l2cap/cid.h"
#include "l2cap/internal/channel_impl.h"
#include "l2cap/internal/data_controller.h"
#include "l2cap/internal/scheduler.h"
#include "l2cap/l2cap_packets.h"
#include "l2cap/mtu.h"
#include "os/handler.h"
#include "os/queue.h"
#include "packet/base_packet_builder.h"
#include "packet/packet_view.h"

namespace bluetooth {
namespace l2cap {
namespace internal {

class BasicModeDataController : public DataController {
 public:
  using UpperEnqueue = packet::PacketView<packet::kLittleEndian>;
  using UpperDequeue = packet::BasePacketBuilder;
  using UpperQueueDownEnd = common::BidiQueueEnd<UpperEnqueue, UpperDequeue>;
  BasicModeDataController(Cid cid, Cid remote_cid, UpperQueueDownEnd* channel_queue_end, os::Handler* handler,
                          Scheduler* scheduler);

  void OnSdu(std::unique_ptr<packet::BasePacketBuilder> sdu) override;

  void OnPdu(BasicFrameView pdu) override;

  std::unique_ptr<BasicFrameBuilder> GetNextPacket() override;

 private:
  Cid cid_;
  Cid remote_cid_;
  os::EnqueueBuffer<UpperEnqueue> enqueue_buffer_;
  os::Handler* handler_;
  std::queue<std::unique_ptr<BasicFrameBuilder>> pdu_queue_;
  Scheduler* scheduler_;
};

}  // namespace internal
}  // namespace l2cap
}  // namespace bluetooth
Loading