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

Commit ec056927 authored by Treehugger Robot's avatar Treehugger Robot Committed by Automerger Merge Worker
Browse files

Merge "HCI: Add connection management interfaces" am: 8150918d

Change-Id: Ibfb3c79a782850b21f0e1f1c94bb76383cd188d6
parents fe485bf3 8150918d
Loading
Loading
Loading
Loading
+60 −0
Original line number Diff line number Diff line
/*
 * 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 "common/callback.h"
#include "hci/hci_packets.h"
#include "os/utils.h"

namespace bluetooth {
namespace hci {

class AclConnectionInterface {
 public:
  AclConnectionInterface() = default;
  virtual ~AclConnectionInterface() = default;
  DISALLOW_COPY_AND_ASSIGN(AclConnectionInterface);

  virtual void EnqueueCommand(std::unique_ptr<ConnectionManagementCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) = 0;

  virtual void EnqueueCommand(std::unique_ptr<ConnectionManagementCommandBuilder> command,
                              common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) = 0;

  static constexpr EventCode AclConnectionEvents[] = {
      EventCode::CONNECTION_PACKET_TYPE_CHANGED,
      EventCode::ROLE_CHANGE,
      EventCode::CONNECTION_COMPLETE,
      EventCode::DISCONNECTION_COMPLETE,
      EventCode::CONNECTION_REQUEST,
      EventCode::CONNECTION_PACKET_TYPE_CHANGED,
      EventCode::AUTHENTICATION_COMPLETE,
      EventCode::READ_CLOCK_OFFSET_COMPLETE,
      EventCode::MODE_CHANGE,
      EventCode::QOS_SETUP_COMPLETE,
      EventCode::ROLE_CHANGE,
      EventCode::FLOW_SPECIFICATION_COMPLETE,
      EventCode::FLUSH_OCCURRED,
      EventCode::READ_REMOTE_SUPPORTED_FEATURES_COMPLETE,
      EventCode::READ_REMOTE_EXTENDED_FEATURES_COMPLETE,
      EventCode::READ_REMOTE_VERSION_INFORMATION_COMPLETE,
      EventCode::ENCRYPTION_CHANGE,
      EventCode::LINK_SUPERVISION_TIMEOUT_CHANGED,
  };
};
}  // namespace hci
}  // namespace bluetooth
+80 −32
Original line number Diff line number Diff line
@@ -97,18 +97,51 @@ void on_hci_timeout(OpCode op_code) {
}
}  // namespace

class AclConnectionManagerInterfaceImpl : public AclConnectionInterface {
 public:
  explicit AclConnectionManagerInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  ~AclConnectionManagerInterfaceImpl() override = default;

  void EnqueueCommand(std::unique_ptr<ConnectionManagementCommandBuilder> command,
                      common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  void EnqueueCommand(std::unique_ptr<ConnectionManagementCommandBuilder> command,
                      common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
  HciLayer& hci_;
};

class SecurityInterfaceImpl : public SecurityInterface {
 public:
  SecurityInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  virtual ~SecurityInterfaceImpl() = default;
  explicit SecurityInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  ~SecurityInterfaceImpl() override = default;

  virtual void EnqueueCommand(std::unique_ptr<SecurityCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete,
                              os::Handler* handler) override {
  void EnqueueCommand(std::unique_ptr<SecurityCommandBuilder> command,
                      common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  virtual void EnqueueCommand(std::unique_ptr<SecurityCommandBuilder> command,
  void EnqueueCommand(std::unique_ptr<SecurityCommandBuilder> command,
                      common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
  HciLayer& hci_;
};

class LeAclConnectionManagerInterfaceImpl : public LeAclConnectionInterface {
 public:
  explicit LeAclConnectionManagerInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  ~LeAclConnectionManagerInterfaceImpl() override = default;

  void EnqueueCommand(std::unique_ptr<LeConnectionManagementCommandBuilder> command,
                      common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  void EnqueueCommand(std::unique_ptr<LeConnectionManagementCommandBuilder> command,
                      common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
@@ -117,16 +150,15 @@ class SecurityInterfaceImpl : public SecurityInterface {

class LeSecurityInterfaceImpl : public LeSecurityInterface {
 public:
  LeSecurityInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  virtual ~LeSecurityInterfaceImpl() = default;
  explicit LeSecurityInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  ~LeSecurityInterfaceImpl() override = default;

  virtual void EnqueueCommand(std::unique_ptr<LeSecurityCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete,
                              os::Handler* handler) override {
  void EnqueueCommand(std::unique_ptr<LeSecurityCommandBuilder> command,
                      common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  virtual void EnqueueCommand(std::unique_ptr<LeSecurityCommandBuilder> command,
  void EnqueueCommand(std::unique_ptr<LeSecurityCommandBuilder> command,
                      common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
@@ -135,16 +167,15 @@ class LeSecurityInterfaceImpl : public LeSecurityInterface {

class LeAdvertisingInterfaceImpl : public LeAdvertisingInterface {
 public:
  LeAdvertisingInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  virtual ~LeAdvertisingInterfaceImpl() = default;
  explicit LeAdvertisingInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  ~LeAdvertisingInterfaceImpl() override = default;

  virtual void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete,
                              os::Handler* handler) override {
  void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
                      common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  virtual void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
  void EnqueueCommand(std::unique_ptr<LeAdvertisingCommandBuilder> command,
                      common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
@@ -153,16 +184,15 @@ class LeAdvertisingInterfaceImpl : public LeAdvertisingInterface {

class LeScanningInterfaceImpl : public LeScanningInterface {
 public:
  LeScanningInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  virtual ~LeScanningInterfaceImpl() = default;
  explicit LeScanningInterfaceImpl(HciLayer& hci) : hci_(hci) {}
  ~LeScanningInterfaceImpl() override = default;

  virtual void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete,
                              os::Handler* handler) override {
  void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
                      common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_complete), handler);
  }

  virtual void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
  void EnqueueCommand(std::unique_ptr<LeScanningCommandBuilder> command,
                      common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) override {
    hci_.EnqueueCommand(std::move(command), std::move(on_status), handler);
  }
@@ -382,8 +412,7 @@ struct HciLayer::impl : public hal::HciHalCallbacks {
                                     os::Handler* handler) {
    ASSERT_LOG(event_handlers_.count(event_code) == 0, "Can not register a second handler for event_code %02hhx (%s)",
               event_code, EventCodeText(event_code).c_str());
    EventHandler to_save(event_handler, handler);
    event_handlers_[event_code] = to_save;
    event_handlers_[event_code] = EventHandler(event_handler, handler);
  }

  void UnregisterEventHandler(EventCode event_code) {
@@ -406,8 +435,7 @@ struct HciLayer::impl : public hal::HciHalCallbacks {
    ASSERT_LOG(subevent_handlers_.count(subevent_code) == 0,
               "Can not register a second handler for subevent_code %02hhx (%s)", subevent_code,
               SubeventCodeText(subevent_code).c_str());
    SubeventHandler to_save(subevent_handler, handler);
    subevent_handlers_[subevent_code] = to_save;
    subevent_handlers_[subevent_code] = SubeventHandler(subevent_handler, handler);
  }

  void UnregisterLeEventHandler(SubeventCode subevent_code) {
@@ -426,6 +454,8 @@ struct HciLayer::impl : public hal::HciHalCallbacks {
  HciLayer& module_;

  // Interfaces
  AclConnectionManagerInterfaceImpl acl_connection_manager_interface_{module_};
  LeAclConnectionManagerInterfaceImpl le_acl_connection_manager_interface_{module_};
  SecurityInterfaceImpl security_interface{module_};
  LeSecurityInterfaceImpl le_security_interface{module_};
  LeAdvertisingInterfaceImpl le_advertising_interface{module_};
@@ -483,6 +513,24 @@ void HciLayer::UnregisterLeEventHandler(SubeventCode subevent_code) {
  impl_->UnregisterLeEventHandler(subevent_code);
}

AclConnectionInterface* HciLayer::GetAclConnectionInterface(common::Callback<void(EventPacketView)> event_handler,
                                                            common::Callback<void(uint16_t, ErrorCode)> on_disconnect,
                                                            os::Handler* handler) {
  for (const auto event : AclConnectionInterface::AclConnectionEvents) {
    RegisterEventHandler(event, event_handler, handler);
  }
  return &impl_->acl_connection_manager_interface_;
}

LeAclConnectionInterface* HciLayer::GetLeAclConnectionInterface(
    common::Callback<void(LeMetaEventView)> event_handler, common::Callback<void(uint16_t, ErrorCode)> on_disconnect,
    os::Handler* handler) {
  for (const auto event : LeAclConnectionInterface::LeConnectionManagementEvents) {
    RegisterLeEventHandler(event, event_handler, handler);
  }
  return &impl_->le_acl_connection_manager_interface_;
}

SecurityInterface* HciLayer::GetSecurityInterface(common::Callback<void(EventPacketView)> event_handler,
                                                  os::Handler* handler) {
  for (const auto event : SecurityInterface::SecurityEvents) {
+10 −0
Original line number Diff line number Diff line
@@ -24,7 +24,9 @@
#include "common/bidi_queue.h"
#include "common/callback.h"
#include "hal/hci_hal.h"
#include "hci/acl_connection_interface.h"
#include "hci/hci_packets.h"
#include "hci/le_acl_connection_interface.h"
#include "hci/le_advertising_interface.h"
#include "hci/le_scanning_interface.h"
#include "hci/le_security_interface.h"
@@ -64,6 +66,14 @@ class HciLayer : public Module {
  LeSecurityInterface* GetLeSecurityInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                              os::Handler* handler);

  AclConnectionInterface* GetAclConnectionInterface(common::Callback<void(EventPacketView)> event_handler,
                                                    common::Callback<void(uint16_t, hci::ErrorCode)> on_disconnect,
                                                    os::Handler* handler);

  LeAclConnectionInterface* GetLeAclConnectionInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                                        common::Callback<void(uint16_t, hci::ErrorCode)> on_disconnect,
                                                        os::Handler* handler);

  LeAdvertisingInterface* GetLeAdvertisingInterface(common::Callback<void(LeMetaEventView)> event_handler,
                                                    os::Handler* handler);

+3 −3
Original line number Diff line number Diff line
@@ -1034,7 +1034,7 @@ packet RemoteNameRequestCancelComplete : CommandComplete (command_op_code = REMO
  bd_addr : Address,
}

packet ReadRemoteSupportedFeatures : DiscoveryCommand (op_code = READ_REMOTE_SUPPORTED_FEATURES) {
packet ReadRemoteSupportedFeatures : ConnectionManagementCommand (op_code = READ_REMOTE_SUPPORTED_FEATURES) {
  connection_handle : 12,
  _reserved_ : 4,
}
@@ -1042,7 +1042,7 @@ packet ReadRemoteSupportedFeatures : DiscoveryCommand (op_code = READ_REMOTE_SUP
packet ReadRemoteSupportedFeaturesStatus : CommandStatus (command_op_code = READ_REMOTE_SUPPORTED_FEATURES) {
}

packet ReadRemoteExtendedFeatures : DiscoveryCommand (op_code = READ_REMOTE_EXTENDED_FEATURES) {
packet ReadRemoteExtendedFeatures : ConnectionManagementCommand (op_code = READ_REMOTE_EXTENDED_FEATURES) {
  connection_handle : 12,
  _reserved_ : 4,
  page_number : 8,
@@ -1051,7 +1051,7 @@ packet ReadRemoteExtendedFeatures : DiscoveryCommand (op_code = READ_REMOTE_EXTE
packet ReadRemoteExtendedFeaturesStatus : CommandStatus (command_op_code = READ_REMOTE_EXTENDED_FEATURES) {
}

packet ReadRemoteVersionInformation : DiscoveryCommand (op_code = READ_REMOTE_VERSION_INFORMATION) {
packet ReadRemoteVersionInformation : ConnectionManagementCommand (op_code = READ_REMOTE_VERSION_INFORMATION) {
  connection_handle : 12,
  _reserved_ : 4,
}
+46 −0
Original line number Diff line number Diff line
/*
 * 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 "common/callback.h"
#include "hci/hci_packets.h"
#include "os/handler.h"
#include "os/utils.h"

namespace bluetooth {
namespace hci {

class LeAclConnectionInterface {
 public:
  LeAclConnectionInterface() = default;
  virtual ~LeAclConnectionInterface() = default;
  DISALLOW_COPY_AND_ASSIGN(LeAclConnectionInterface);

  virtual void EnqueueCommand(std::unique_ptr<LeConnectionManagementCommandBuilder> command,
                              common::OnceCallback<void(CommandCompleteView)> on_complete, os::Handler* handler) = 0;

  virtual void EnqueueCommand(std::unique_ptr<LeConnectionManagementCommandBuilder> command,
                              common::OnceCallback<void(CommandStatusView)> on_status, os::Handler* handler) = 0;

  static constexpr SubeventCode LeConnectionManagementEvents[] = {
      SubeventCode::CONNECTION_COMPLETE,
      SubeventCode::ENHANCED_CONNECTION_COMPLETE,
      SubeventCode::CONNECTION_UPDATE_COMPLETE,
  };
};
}  // namespace hci
}  // namespace bluetooth
Loading