OSDN Git Service

Initial Entry for shim layer
authorChris Manton <cmanton@google.com>
Tue, 10 Sep 2019 04:11:59 +0000 (21:11 -0700)
committerChris Manton <cmanton@google.com>
Tue, 10 Sep 2019 04:13:42 +0000 (21:13 -0700)
Test: Build and run sdp query on target walleye with Gd disabled
Bug: 140304485

Change-Id: I1628e44f7916528ec83d8d1fac4bf3b6e08e1583

13 files changed:
gd/Android.bp
gd/shim/Android.bp [new file with mode: 0644]
gd/shim/istack.h [new file with mode: 0644]
gd/shim/only_include_this_file_into_legacy_stack___ever.h [new file with mode: 0644]
gd/shim/stack.cc [new file with mode: 0644]
gd/shim/stack.h [new file with mode: 0644]
main/Android.bp
main/bte_main.cc
main/shim/entry.cc [new file with mode: 0644]
main/shim/entry.h [new file with mode: 0644]
main/shim/entry_for_test.cc [new file with mode: 0644]
main/shim/shim.cc [new file with mode: 0644]
main/shim/shim.h [new file with mode: 0644]

index ddefdd5..0e82547 100644 (file)
@@ -110,6 +110,7 @@ cc_library {
         ":BluetoothHciSources",
         ":BluetoothL2capSources",
         ":BluetoothPacketSources",
+        ":BluetoothShimSources",
         ":BluetoothSmpSources",
     ],
     generated_headers: [
diff --git a/gd/shim/Android.bp b/gd/shim/Android.bp
new file mode 100644 (file)
index 0000000..ad26494
--- /dev/null
@@ -0,0 +1,6 @@
+filegroup {
+    name: "BluetoothShimSources",
+    srcs: [
+            "stack.cc",
+    ],
+}
diff --git a/gd/shim/istack.h b/gd/shim/istack.h
new file mode 100644 (file)
index 0000000..b9bc258
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * 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
diff --git a/gd/shim/only_include_this_file_into_legacy_stack___ever.h b/gd/shim/only_include_this_file_into_legacy_stack___ever.h
new file mode 100644 (file)
index 0000000..e9eddec
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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"
diff --git a/gd/shim/stack.cc b/gd/shim/stack.cc
new file mode 100644 (file)
index 0000000..4c70e70
--- /dev/null
@@ -0,0 +1,86 @@
+/*
+ * 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;
+}
diff --git a/gd/shim/stack.h b/gd/shim/stack.h
new file mode 100644 (file)
index 0000000..7b8d479
--- /dev/null
@@ -0,0 +1,45 @@
+/*
+ * 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 "shim/istack.h"
+
+/**
+ * The shim layer implementation on the Gd stack side.
+ */
+namespace bluetooth {
+namespace shim {
+
+class Stack : public IStack {
+ public:
+  Stack();
+  ~Stack() = default;
+
+  void Start() override;  // IStack
+  void Stop() override;   // IStack
+
+ private:
+  struct impl;
+  std::unique_ptr<impl> pimpl_;
+
+  Stack(const Stack&) = delete;
+  void operator=(const Stack&) = delete;
+};
+
+}  // namespace shim
+}  // namespace bluetooth
index 4430fba..ca81230 100644 (file)
@@ -1,18 +1,26 @@
 // Bluetooth main HW module / shared library for target
 // ========================================================
-cc_library_shared {
-    name: "libbluetooth",
-    defaults: ["fluoride_defaults"],
-    header_libs: ["libbluetooth_headers"],
-    export_header_lib_headers: ["libbluetooth_headers"],
+filegroup {
+    name: "LibBluetoothSources",
     srcs: [
-        // platform specific
         "bte_conf.cc",
         "bte_init.cc",
         "bte_init_cpp_logging.cc",
         "bte_logmsg.cc",
         "bte_main.cc",
+        "shim/entry.cc",
+        "shim/shim.cc",
         "stack_config.cc",
+    ]
+}
+
+cc_library_shared {
+    name: "libbluetooth",
+    defaults: ["fluoride_defaults"],
+    header_libs: ["libbluetooth_headers"],
+    export_header_lib_headers: ["libbluetooth_headers"],
+    srcs: [
+        ":LibBluetoothSources",
     ],
     include_dirs: [
         "system/bt",
@@ -67,6 +75,7 @@ cc_library_shared {
         "libFraunhoferAAC",
         "libg722codec",
         "libudrv-uipc",
+        "libbluetooth_gd", // Gabeldorsche
     ],
     whole_static_libs: [
         "libbt-bta",
@@ -105,12 +114,8 @@ cc_library_static {
     defaults: ["fluoride_defaults"],
 
     srcs: [
-        "bte_conf.cc",
-        "bte_init.cc",
-        "bte_init_cpp_logging.cc",
-        "bte_logmsg.cc",
-        "bte_main.cc",
-        "stack_config.cc",
+        ":LibBluetoothSources",
+        "shim/entry_for_test.cc",
     ],
     include_dirs: [
         "system/bt",
index 0498439..054b229 100644 (file)
@@ -53,6 +53,7 @@
 #include "osi/include/future.h"
 #include "osi/include/log.h"
 #include "osi/include/osi.h"
+#include "shim/shim.h"
 #include "stack_config.h"
 
 /*******************************************************************************
@@ -155,8 +156,12 @@ void bte_main_cleanup() {
 void bte_main_enable() {
   APPL_TRACE_DEBUG("%s", __func__);
 
-  module_start_up(get_module(BTSNOOP_MODULE));
-  module_start_up(get_module(HCI_MODULE));
+  if (bluetooth::shim::is_gd_shim_enabled()) {
+    LOG_INFO(LOG_TAG, "%s Gd shim module enabled", __func__);
+  } else {
+    module_start_up(get_module(BTSNOOP_MODULE));
+    module_start_up(get_module(HCI_MODULE));
+  }
 
   BTU_StartUp();
 }
@@ -174,8 +179,13 @@ void bte_main_enable() {
 void bte_main_disable(void) {
   APPL_TRACE_DEBUG("%s", __func__);
 
-  module_shut_down(get_module(HCI_MODULE));
-  module_shut_down(get_module(BTSNOOP_MODULE));
+  if (bluetooth::shim::is_gd_shim_enabled()) {
+    LOG_INFO(LOG_TAG, "%s Gd shim module enabled", __func__);
+    module_shut_down(get_module(GD_SHIM_MODULE));
+  } else {
+    module_shut_down(get_module(HCI_MODULE));
+    module_shut_down(get_module(BTSNOOP_MODULE));
+  }
 
   BTU_ShutDown();
 }
diff --git a/main/shim/entry.cc b/main/shim/entry.cc
new file mode 100644 (file)
index 0000000..4d91566
--- /dev/null
@@ -0,0 +1,31 @@
+/*
+ * 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 "main/shim/entry.h"
+#include "gd/shim/only_include_this_file_into_legacy_stack___ever.h"
+#include "osi/include/future.h"
+
+using bluetooth::shim::GetGabeldorscheStack;
+
+future_t* bluetooth::shim::StartGabeldorscheStack() {
+  GetGabeldorscheStack()->Start();
+  return (future_t*)nullptr;
+}
+
+future_t* bluetooth::shim::StopGabeldorscheStack() {
+  GetGabeldorscheStack()->Stop();
+  return (future_t*)nullptr;
+}
diff --git a/main/shim/entry.h b/main/shim/entry.h
new file mode 100644 (file)
index 0000000..eaa1b60
--- /dev/null
@@ -0,0 +1,42 @@
+/*
+ * 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
+
+/**
+ * Entrypoints called into Gabeldorsche from legacy stack
+ *
+ * Any marshalling/unmarshalling, data transformation of APIs to
+ * or from the Gabeldorsche stack may be placed here.
+ *
+ * The idea is to effectively provide a binary interface to prevent cross
+ * contamination of data structures and the like between the stacks.
+ *
+ * **ABSOLUTELY** No reference to Gabeldorsche stack other than well defined
+ * interfaces may be made here
+ */
+
+#include "gd/shim/only_include_this_file_into_legacy_stack___ever.h"
+#include "osi/include/future.h"
+
+namespace bluetooth {
+namespace shim {
+
+future_t* StartGabeldorscheStack();
+future_t* StopGabeldorscheStack();
+
+}  // namespace shim
+}  // namespace bluetooth
diff --git a/main/shim/entry_for_test.cc b/main/shim/entry_for_test.cc
new file mode 100644 (file)
index 0000000..26b9b22
--- /dev/null
@@ -0,0 +1,27 @@
+/*
+ * 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 "gd/shim/only_include_this_file_into_legacy_stack___ever.h"
+#include "main/shim/entry.h"
+
+/**
+ * Entrypoints for stubbed bluetooth test library
+ *
+ * Gd stack is not supported using legacy test modes
+ */
+bluetooth::shim::IStack* bluetooth::shim::GetGabeldorscheStack() {
+  return (bluetooth::shim::IStack*)nullptr;
+}
diff --git a/main/shim/shim.cc b/main/shim/shim.cc
new file mode 100644 (file)
index 0000000..c72a6dd
--- /dev/null
@@ -0,0 +1,37 @@
+/******************************************************************************
+ *
+ *  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 "main/shim/shim.h"
+#include "main/shim/entry.h"
+
+// TODO(cmanton) Connect this flag to an external input
+#if 1
+static bool gd_shim_enabled_ = false;
+#else
+static bool gd_shim_enabled_ = true;
+#endif
+
+EXPORT_SYMBOL extern const module_t gd_shim_module = {
+    .name = GD_SHIM_MODULE,
+    .init = NULL,
+    .start_up = bluetooth::shim::StartGabeldorscheStack,
+    .shut_down = bluetooth::shim::StopGabeldorscheStack,
+    .clean_up = NULL,
+    .dependencies = {NULL}};
+
+bool bluetooth::shim::is_gd_shim_enabled() { return gd_shim_enabled_; }
diff --git a/main/shim/shim.h b/main/shim/shim.h
new file mode 100644 (file)
index 0000000..809d169
--- /dev/null
@@ -0,0 +1,35 @@
+/******************************************************************************
+ *
+ *  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
+
+/**
+ * Gabeldorsche related legacy-only-stack-side expansion and support code.
+ */
+#include "btcore/include/module.h"
+#include "main/shim/entry.h"
+
+static const char GD_SHIM_MODULE[] = "gd_shim_module";
+
+namespace bluetooth {
+namespace shim {
+
+bool is_gd_shim_enabled();
+
+}  // namespace shim
+}  // namespace bluetooth