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

Commit 3e5b1268 authored by Hansong Zhang's avatar Hansong Zhang Committed by Automerger Merge Worker
Browse files

gd/shim/l2cap is unused am: 11d99975

Original change: https://android-review.googlesource.com/c/platform/system/bt/+/1510512

Change-Id: I839a60493697b9ac0aa840c4accd5db38c6c2c6d
parents a126bd6b 11d99975
Loading
Loading
Loading
Loading
+0 −2
Original line number Diff line number Diff line
@@ -46,7 +46,6 @@
#include "security/security_module.h"
#include "shim/dumpsys.h"
#include "shim/facade/facade.h"
#include "shim/l2cap.h"
#include "stack_manager.h"
#include "storage/storage_module.h"

@@ -115,7 +114,6 @@ class RootFacadeService : public ::bluetooth::facade::RootFacade::Service {
        break;
      case BluetoothModule::SHIM:
        modules.add<::bluetooth::shim::facade::ShimFacadeModule>();
        modules.add<::bluetooth::shim::L2cap>();
        break;
      default:
        return ::grpc::Status(::grpc::StatusCode::INVALID_ARGUMENT, "invalid module under test");
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
#pragma once

#include <gd/l2cap/classic/internal/dynamic_channel_service_manager_impl.h>
#include <gd/shim/l2cap.h>
#include <future>
#include <memory>

+13 −4
Original line number Diff line number Diff line
@@ -35,6 +35,17 @@ using l2cap::classic::internal::Link;

using shim::ShimL2capFuzz;

class FakeCommandInterface : public hci::CommandInterface<hci::AclCommandBuilder> {
 public:
  virtual void EnqueueCommand(
      std::unique_ptr<hci::AclCommandBuilder> command,
      common::ContextualOnceCallback<void(hci::CommandCompleteView)> on_complete) {}

  virtual void EnqueueCommand(
      std::unique_ptr<hci::AclCommandBuilder> command,
      common::ContextualOnceCallback<void(hci::CommandStatusView)> on_status) {}
} fake_command_interface;

extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  FuzzedDataProvider fdp = FuzzedDataProvider(data, size);
  ShimL2capFuzz l2shim(&fdp);
@@ -51,8 +62,8 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {

  // Associate a ClassicAclConnection so that we can grab a link.
  auto throwaway_queue = std::make_shared<AclConnection::Queue>(10);
  l2shim.link_manager->OnConnectSuccess(
      std::unique_ptr<ClassicAclConnection>(new ClassicAclConnection(throwaway_queue, nullptr, 0, myAddress)));
  l2shim.link_manager->OnConnectSuccess(std::unique_ptr<ClassicAclConnection>(
      new ClassicAclConnection(throwaway_queue, &fake_command_interface, 0, myAddress)));
  Link* link = l2shim.link_manager->GetLink(myAddress);

  // 0x0001-0x007F Fixed, 0x0080-0x00FF Dynamic
@@ -62,7 +73,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  dynamicPsm = 0x0101u ^ 0x0100u;

  // Open a connection and assign an ID
  uint16_t connectionId = l2shim.CreateConnection(psm, myAddress.ToString());
  Cid fixedCid = l2cap::kLeSignallingCid;

  // Fixed channels must be acquired.
@@ -93,7 +103,6 @@ extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
  // Cleanup stuff.
  fixedChannel->Release();
  dynamicChannel->Close();
  l2shim.shim_l2cap_->CloseClassicConnection(connectionId);
  l2shim.stopRegistry();
  link->OnAclDisconnected(hci::ErrorCode::SUCCESS);
  l2shim.link_manager->OnDisconnect(myAddress, hci::ErrorCode::SUCCESS);
+0 −1
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@
#pragma once

#include <fuzzer/FuzzedDataProvider.h>
#include <gd/shim/l2cap.h>

#include "l2cap/classic/dynamic_channel_manager.h"
#include "l2cap/classic/l2cap_classic_module.h"
+12 −27
Original line number Diff line number Diff line
@@ -23,7 +23,6 @@
#include <gd/l2cap/classic/internal/fixed_channel_service_manager_impl.h>
#include <gd/l2cap/classic/internal/link_manager.h>
#include <gd/l2cap/internal/parameter_provider.h>
#include <gd/shim/l2cap.h>
#include <future>
#include <memory>

@@ -39,43 +38,34 @@ namespace shim {
namespace {
class ShimL2capFuzz {
 public:
  void OnConnectionComplete(std::string string_address, uint16_t psm, uint16_t cid, bool connected) {
    connection_string_address_ = string_address;
    connection_psm_ = psm;
    connection_cid_ = cid;
    connection_connected_ = connected;
    connection_complete_promise_.set_value();
  }

  uint16_t CreateConnection(uint16_t psm, std::string device_address) {
  uint16_t CreateConnection(uint16_t psm, hci::Address device_address) {
    std::promise<uint16_t> promise;
    auto future = promise.get_future();

    shim_l2cap_->CreateClassicConnection(
        psm,
    fuzz_l2cap_classic_module_->GetDynamicChannelManager()->ConnectChannel(
        device_address,
        std::bind(
            &shim::ShimL2capFuzz::OnConnectionComplete,
            this,
            std::placeholders::_1,
            std::placeholders::_2,
            std::placeholders::_3,
            std::placeholders::_4),
        std::move(promise));
        {},
        psm,
        handler_->BindOn(this, &ShimL2capFuzz::OnConnectionComplete),
        handler_->BindOnceOn(this, &ShimL2capFuzz::OnConnectionFail));

    return future.get();
  }

  void OnConnectionComplete(std::unique_ptr<l2cap::classic::DynamicChannel> channel) {}

  void OnConnectionFail(l2cap::classic::DynamicChannelManager::ConnectionResult result) {}

  ShimL2capFuzz(FuzzedDataProvider* fdp) {
    hci::fuzz::FuzzHciLayer* fuzzHci = fake_registry_.Inject<hci::fuzz::FuzzHciLayer>(&hci::HciLayer::Factory);
    fuzz_l2cap_classic_module_ = new FuzzL2capClassicModule();
    fake_registry_.InjectTestModule(&l2cap::classic::L2capClassicModule::Factory, fuzz_l2cap_classic_module_);
    fake_registry_.Start<shim::L2cap>();
    fake_registry_.Start<l2cap::classic::L2capClassicModule>();

    // The autoreply is needed to prevent it from hanging.
    fuzzHci->TurnOnAutoReply(fdp);
    acl_manager_ = fake_registry_.Start<hci::AclManager>();
    fuzzHci->TurnOffAutoReply();
    shim_l2cap_ = static_cast<shim::L2cap*>(fake_registry_.GetModuleUnderTest(&shim::L2cap::Factory));

    // Create the LinkManager
    handler_ = std::unique_ptr<os::Handler>(new os::Handler(&thread_));
@@ -96,13 +86,8 @@ class ShimL2capFuzz {
    fake_registry_.WaitForIdleAndStopAll();
  }

  std::string connection_string_address_;
  uint16_t connection_psm_{0};
  uint16_t connection_cid_{1000};
  bool connection_connected_{false};
  std::promise<void> connection_complete_promise_;

  shim::L2cap* shim_l2cap_{nullptr};
  FuzzL2capClassicModule* fuzz_l2cap_classic_module_{nullptr};
  hci::AclManager* acl_manager_{nullptr};

Loading