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

Commit 28c4c586 authored by Chris Manton's avatar Chris Manton
Browse files

Initial Entry for shim layer

Test: Build and run sdp query on target walleye with Gd disabled
Bug: 140304485

Change-Id: I1628e44f7916528ec83d8d1fac4bf3b6e08e1583
parent 84ef6ba9
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -110,6 +110,7 @@ cc_library {
        ":BluetoothHciSources",
        ":BluetoothL2capSources",
        ":BluetoothPacketSources",
        ":BluetoothShimSources",
        ":BluetoothSmpSources",
    ],
    generated_headers: [
+6 −0
Original line number Diff line number Diff line
filegroup {
    name: "BluetoothShimSources",
    srcs: [
            "stack.cc",
    ],
}
+35 −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

/**
 * Legacy stack manipulation methods to allow the legacy stack to start
 * and stop the stack, and to provide Gd shim stack module API access.
 */
namespace bluetooth {
namespace shim {

struct IStack {
  virtual void Start() = 0;
  virtual void Stop() = 0;

  virtual ~IStack() {}
};

IStack* GetGabeldorscheStack();

}  // namespace shim
}  // namespace bluetooth
+27 −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

/**
 * This common file provides the only visibility from the legacy stack into GD stack.
 *
 * Only interfaces or APIs should be exported.
 *
 * Only common data structures should be used to pass data between the stacks.
 *
 */
#include "gd/shim/istack.h"
+86 −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.
 */

#define LOG_TAG "bt_gd"

#include "shim/stack.h"
#include "hal/hci_hal.h"
#include "hci/acl_manager.h"
#include "hci/classic_security_manager.h"
#include "l2cap/l2cap_layer.h"
#include "os/log.h"
#include "os/thread.h"
#include "stack_manager.h"

using ::bluetooth::os::Thread;

struct bluetooth::shim::Stack::impl {
  void Start() {
    if (is_running_) {
      LOG_ERROR("%s Gd stack already running", __func__);
      return;
    }

    LOG_INFO("%s Starting Gd stack", __func__);
    ModuleList modules;
    modules.add<::bluetooth::hal::HciHal>();
    modules.add<::bluetooth::hci::AclManager>();
    modules.add<::bluetooth::hci::ClassicSecurityManager>();
    modules.add<::bluetooth::l2cap::L2capLayer>();

    stack_thread_ = new Thread("gd_stack_thread", Thread::Priority::NORMAL);
    stack_manager_.StartUp(&modules, stack_thread_);
    // TODO(cmanton) Gd stack has spun up another thread with no
    // ability to ascertain the completion
    is_running_ = true;
    LOG_INFO("%s Successfully toggled Gd stack", __func__);
  }

  void Stop() {
    if (!is_running_) {
      LOG_ERROR("%s Gd stack not running", __func__);
      return;
    }

    stack_manager_.ShutDown();
    delete stack_thread_;
    is_running_ = false;
    LOG_INFO("%s Successfully shut down Gd stack", __func__);
  }

 private:
  os::Thread* stack_thread_ = nullptr;
  bool is_running_ = false;
  StackManager stack_manager_;
};

bluetooth::shim::Stack::Stack() {
  pimpl_ = std::make_unique<impl>();
  LOG_INFO("%s Created gd stack", __func__);
}

void bluetooth::shim::Stack::Start() {
  pimpl_->Start();
}

void bluetooth::shim::Stack::Stop() {
  pimpl_->Stop();
}

bluetooth::shim::IStack* bluetooth::shim::GetGabeldorscheStack() {
  static IStack* instance = new Stack();
  return instance;
}
Loading