OSDN Git Service

Add ATT stub to prevent stack from crashing
authorJakub Pawlowski <jpawlowski@google.com>
Tue, 28 Jan 2020 15:53:20 +0000 (16:53 +0100)
committerJakub Pawlowski <jpawlowski@google.com>
Tue, 28 Jan 2020 18:47:27 +0000 (19:47 +0100)
Bug: 142341141
Test: Connect to LE device, verify no crash happen when ATT packet is
      received
Change-Id: Ia5e0352288565cd578fd163fe821b4d779ed762a

gd/Android.bp
gd/att/Android.bp [new file with mode: 0644]
gd/att/att_module.cc [new file with mode: 0644]
gd/att/att_module.h [new file with mode: 0644]
gd/shim/stack.cc

index e5c98ed..f2f8571 100644 (file)
@@ -103,6 +103,7 @@ cc_library {
     srcs: [
         "stack_manager.cc",
         "module.cc",
+        ":BluetoothAttSources",
         ":BluetoothCommonSources",
         ":BluetoothCryptoToolboxSources",
         ":BluetoothHalSources",
@@ -246,6 +247,7 @@ cc_test {
     srcs: [
         "module_unittest.cc",
         "stack_manager_unittest.cc",
+        ":BluetoothAttTestSources",
         ":BluetoothCommonTestSources",
         ":BluetoothCryptoToolboxTestSources",
         ":BluetoothHciTestSources",
diff --git a/gd/att/Android.bp b/gd/att/Android.bp
new file mode 100644 (file)
index 0000000..b7af1ef
--- /dev/null
@@ -0,0 +1,12 @@
+filegroup {
+    name: "BluetoothAttSources",
+    srcs: [
+        "att_module.cc",
+    ],
+}
+
+filegroup {
+    name: "BluetoothAttTestSources",
+    srcs: [
+    ],
+}
diff --git a/gd/att/att_module.cc b/gd/att/att_module.cc
new file mode 100644 (file)
index 0000000..2d1c3b1
--- /dev/null
@@ -0,0 +1,85 @@
+/*
+ * Copyright 2020 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 "att"
+
+#include <memory>
+#include "module.h"
+#include "os/handler.h"
+#include "os/log.h"
+
+#include "att/att_module.h"
+#include "l2cap/classic/l2cap_classic_module.h"
+#include "l2cap/le/l2cap_le_module.h"
+
+namespace bluetooth {
+namespace att {
+
+const ModuleFactory AttModule::Factory = ModuleFactory([]() { return new AttModule(); });
+
+namespace {
+void OnAttRegistrationCompleteLe(l2cap::le::FixedChannelManager::RegistrationResult result,
+                                 std::unique_ptr<l2cap::le::FixedChannelService> le_smp_service) {
+  LOG_INFO("ATT channel registration complete");
+}
+
+void OnAttConnectionOpenLe(std::unique_ptr<l2cap::le::FixedChannel> channel) {
+  LOG_INFO("ATT conneciton opened");
+}
+}  // namespace
+
+struct AttModule::impl {
+  impl(os::Handler* att_handler, l2cap::le::L2capLeModule* l2cap_le_module,
+       l2cap::classic::L2capClassicModule* l2cap_classic_module)
+      : att_handler_(att_handler), l2cap_le_module_(l2cap_le_module), l2cap_classic_module_(l2cap_classic_module) {
+    // TODO: move that into a ATT manager, or other proper place
+    std::unique_ptr<bluetooth::l2cap::le::FixedChannelManager> l2cap_manager_le_(
+        l2cap_le_module_->GetFixedChannelManager());
+    l2cap_manager_le_->RegisterService(bluetooth::l2cap::kLeAttributeCid, {},
+                                       common::BindOnce(&OnAttRegistrationCompleteLe),
+                                       common::Bind(&OnAttConnectionOpenLe), att_handler_);
+  }
+
+  os::Handler* att_handler_;
+  l2cap::le::L2capLeModule* l2cap_le_module_;
+  l2cap::classic::L2capClassicModule* l2cap_classic_module_;
+};
+
+void AttModule::ListDependencies(ModuleList* list) {
+  list->add<l2cap::le::L2capLeModule>();
+  list->add<l2cap::classic::L2capClassicModule>();
+}
+
+void AttModule::Start() {
+  pimpl_ = std::make_unique<impl>(GetHandler(), GetDependency<l2cap::le::L2capLeModule>(),
+                                  GetDependency<l2cap::classic::L2capClassicModule>());
+}
+
+void AttModule::Stop() {
+  pimpl_.reset();
+}
+
+std::string AttModule::ToString() const {
+  return "Att Module";
+}
+
+// std::unique_ptr<AttManager> AttModule::GetAttManager() {
+//   return std::unique_ptr<AttManager>(
+//       new AttManager(pimpl_->att_handler_, &pimpl_->att_manager_impl));
+// }
+
+}  // namespace att
+}  // namespace bluetooth
\ No newline at end of file
diff --git a/gd/att/att_module.h b/gd/att/att_module.h
new file mode 100644 (file)
index 0000000..3501d64
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * Copyright 2020 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 "module.h"
+
+namespace bluetooth {
+namespace att {
+
+class AttModule : public bluetooth::Module {
+ public:
+  AttModule() = default;
+  ~AttModule() = default;
+
+  static const ModuleFactory Factory;
+
+ protected:
+  void ListDependencies(ModuleList* list) override;
+
+  void Start() override;
+
+  void Stop() override;
+
+  std::string ToString() const override;
+
+ private:
+  struct impl;
+  std::unique_ptr<impl> pimpl_;
+  DISALLOW_COPY_AND_ASSIGN(AttModule);
+};
+
+}  // namespace att
+}  // namespace bluetooth
index 3ed3236..8ab6f7a 100644 (file)
@@ -17,6 +17,7 @@
 #define LOG_TAG "bt_gd_shim"
 
 #include "shim/stack.h"
+#include "att/att_module.h"
 #include "hal/hci_hal.h"
 #include "hci/acl_manager.h"
 #include "hci/classic_security_manager.h"
@@ -60,6 +61,7 @@ struct bluetooth::shim::Stack::impl {
 
     LOG_INFO("%s Starting Gd stack", __func__);
     ModuleList modules;
+    modules.add<::bluetooth::att::AttModule>();
     modules.add<::bluetooth::hal::HciHal>();
     modules.add<::bluetooth::hci::AclManager>();
     modules.add<::bluetooth::hci::LeAdvertisingManager>();