Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Reduce scope of security_manager
Browse files Browse the repository at this point in the history
This adds some forward declarations and removes unnecessary includes
from a few `sm` and `gap` headers to limit the amount of inter-component
dependencies on the `sm` component.

Bug: b/337315598
Test: fx build --default \
  //src/connectivity/bluetooth/core/bt-host/testing
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1084665
GitOrigin-RevId: 41625b11ecfee1b2ec8bb86f0ac72b8d42ad43d3
Change-Id: I5dddc4c007e7283f68c45847bcd527efc26df6c3
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/225036
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Eric Rahm <[email protected]>
Commit-Queue: Jason Graffius <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
  • Loading branch information
EricRahm authored and CQ Bot Account committed Jul 20, 2024
1 parent f3360d6 commit 3b0403f
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 29 deletions.
3 changes: 2 additions & 1 deletion pw_bluetooth_sapphire/host/gap/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ cc_library(
"//pw_bluetooth_sapphire/host/l2cap",
"//pw_bluetooth_sapphire/host/sco",
"//pw_bluetooth_sapphire/host/sdp",
"//pw_bluetooth_sapphire/host/sm",
"//pw_bluetooth_sapphire/host/sm:definitions",
"@pigweed//pw_async:heap_dispatcher",
"@pigweed//pw_bluetooth",
"@pigweed//third_party/fuchsia:fit",
Expand Down Expand Up @@ -136,6 +136,7 @@ fuchsia_cc_test(
"//pw_bluetooth_sapphire/host/gatt:testing",
"//pw_bluetooth_sapphire/host/hci:testing",
"//pw_bluetooth_sapphire/host/l2cap:testing",
"//pw_bluetooth_sapphire/host/sm",
"//pw_bluetooth_sapphire/host/sm:testing",
"//pw_bluetooth_sapphire/host/testing",
"//pw_bluetooth_sapphire/host/testing:gtest_main",
Expand Down
5 changes: 4 additions & 1 deletion pw_bluetooth_sapphire/host/gap/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,8 @@ pw_source_set("gap") {
"types.cc",
]

deps = [ "$dir_pw_bluetooth_sapphire/host/sm" ]

public_deps = [
":definitions",
"$dir_pw_async:heap_dispatcher",
Expand All @@ -98,7 +100,7 @@ pw_source_set("gap") {
"$dir_pw_bluetooth_sapphire/host/l2cap",
"$dir_pw_bluetooth_sapphire/host/sco",
"$dir_pw_bluetooth_sapphire/host/sdp",
"$dir_pw_bluetooth_sapphire/host/sm",
"$dir_pw_bluetooth_sapphire/host/sm:definitions",
"$dir_pw_third_party/fuchsia:fit",
]

Expand Down Expand Up @@ -154,6 +156,7 @@ pw_test("gap_tests") {
"$dir_pw_bluetooth_sapphire/host/gatt:testing",
"$dir_pw_bluetooth_sapphire/host/hci:testing",
"$dir_pw_bluetooth_sapphire/host/l2cap:testing",
"$dir_pw_bluetooth_sapphire/host/sm",
"$dir_pw_bluetooth_sapphire/host/sm:testing",
"$dir_pw_bluetooth_sapphire/host/testing",
]
Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/host/gap/adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
#include "pw_bluetooth_sapphire/internal/host/hci/low_energy_connector.h"
#include "pw_bluetooth_sapphire/internal/host/hci/sequential_command_runner.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/channel_manager.h"
#include "pw_bluetooth_sapphire/internal/host/sm/security_manager.h"
#include "pw_bluetooth_sapphire/internal/host/transport/emboss_control_packets.h"
#include "pw_bluetooth_sapphire/internal/host/transport/transport.h"

Expand Down
16 changes: 16 additions & 0 deletions pw_bluetooth_sapphire/host/gap/low_energy_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "pw_bluetooth_sapphire/internal/host/gap/low_energy_connection.h"

#include "pw_bluetooth_sapphire/internal/host/gap/low_energy_connection_manager.h"
#include "pw_bluetooth_sapphire/internal/host/sm/security_manager.h"

namespace bt::gap::internal {

Expand Down Expand Up @@ -271,6 +272,21 @@ void LowEnergyConnection::UpgradeSecurity(sm::SecurityLevel level,
OnSecurityRequest(level, std::move(cb));
}

void LowEnergyConnection::set_security_mode(LESecurityMode mode) {
BT_ASSERT(sm_);
sm_->set_security_mode(mode);
}

sm::BondableMode LowEnergyConnection::bondable_mode() const {
BT_ASSERT(sm_);
return sm_->bondable_mode();
}

sm::SecurityProperties LowEnergyConnection::security() const {
BT_ASSERT(sm_);
return sm_->security();
}

// Cancels any on-going pairing procedures and sets up SMP to use the provided
// new I/O capabilities for future pairing procedures.
void LowEnergyConnection::ResetSecurityManager(sm::IOCapability ioc) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@
#include "pw_bluetooth_sapphire/internal/host/hci/local_address_delegate.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/channel_manager.h"
#include "pw_bluetooth_sapphire/internal/host/sm/error.h"
#include "pw_bluetooth_sapphire/internal/host/sm/security_manager.h"
#include "pw_bluetooth_sapphire/internal/host/sm/smp.h"
#include "pw_bluetooth_sapphire/internal/host/sm/types.h"
#include "pw_bluetooth_sapphire/internal/host/sm/util.h"
Expand Down
4 changes: 4 additions & 0 deletions pw_bluetooth_sapphire/host/sm/security_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@
#include "pw_bluetooth_sapphire/internal/host/hci/low_energy_connection.h"
#include "pw_bluetooth_sapphire/internal/host/sm/error.h"
#include "pw_bluetooth_sapphire/internal/host/sm/packet.h"
#include "pw_bluetooth_sapphire/internal/host/sm/pairing_phase.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_1.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_2_legacy.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_2_secure_connections.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_3.h"
#include "pw_bluetooth_sapphire/internal/host/sm/security_request_phase.h"
#include "pw_bluetooth_sapphire/internal/host/sm/smp.h"
#include "pw_bluetooth_sapphire/internal/host/sm/types.h"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,13 @@
#include "pw_bluetooth_sapphire/internal/host/iso/iso_stream_manager.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/channel_manager.h"
#include "pw_bluetooth_sapphire/internal/host/sm/delegate.h"
#include "pw_bluetooth_sapphire/internal/host/sm/security_manager.h"
#include "pw_bluetooth_sapphire/internal/host/sm/types.h"
#include "pw_bluetooth_sapphire/internal/host/transport/command_channel.h"

namespace bt::sm {
class SecurityManager;
}

namespace bt::gap {

namespace internal {
Expand Down Expand Up @@ -113,10 +116,7 @@ class LowEnergyConnection final : public sm::Delegate {
// Attach connection as child node of |parent| with specified |name|.
void AttachInspect(inspect::Node& parent, std::string name);

void set_security_mode(LESecurityMode mode) {
BT_ASSERT(sm_);
sm_->set_security_mode(mode);
}
void set_security_mode(LESecurityMode mode);

// Sets a callback that will be called when the peer disconnects.
void set_peer_disconnect_callback(PeerDisconnectCallback cb) {
Expand All @@ -143,15 +143,9 @@ class LowEnergyConnection final : public sm::Delegate {
PeerId peer_id() const { return peer_->identifier(); }
hci_spec::ConnectionHandle handle() const { return link_->handle(); }
hci::LowEnergyConnection* link() const { return link_.get(); }
sm::BondableMode bondable_mode() const {
BT_ASSERT(sm_);
return sm_->bondable_mode();
}
sm::BondableMode bondable_mode() const;

sm::SecurityProperties security() const {
BT_ASSERT(sm_);
return sm_->security();
}
sm::SecurityProperties security() const;

pw::bluetooth::emboss::ConnectionRole role() const { return link()->role(); }

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,17 @@

namespace bt {

namespace sm {
using SecurityManagerFactory = std::function<std::unique_ptr<SecurityManager>(
hci::LowEnergyConnection::WeakPtr,
l2cap::Channel::WeakPtr,
IOCapability,
Delegate::WeakPtr,
BondableMode,
gap::LESecurityMode,
pw::async::Dispatcher&)>;
} // namespace sm

namespace hci {
class LocalAddressDelegate;
} // namespace hci
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
#include "pw_bluetooth_sapphire/internal/host/gap/peer_metrics.h"
#include "pw_bluetooth_sapphire/internal/host/gatt/persisted_data.h"
#include "pw_bluetooth_sapphire/internal/host/hci-spec/constants.h"
#include "pw_bluetooth_sapphire/internal/host/hci-spec/le_connection_parameters.h"
#include "pw_bluetooth_sapphire/internal/host/hci-spec/lmp_feature_set.h"
#include "pw_bluetooth_sapphire/internal/host/hci/connection.h"
#include "pw_bluetooth_sapphire/internal/host/sm/security_manager.h"
#include "pw_bluetooth_sapphire/internal/host/sm/types.h"

#pragma clang diagnostic ignored "-Wshadow"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,12 @@

#pragma once
#include <memory>
#include <queue>
#include <variant>

#include "pw_bluetooth_sapphire/internal/host/common/assert.h"
#include "pw_bluetooth_sapphire/internal/host/common/device_address.h"
#include "pw_bluetooth_sapphire/internal/host/common/uint128.h"
#include "pw_bluetooth_sapphire/internal/host/gap/gap.h"
#include "pw_bluetooth_sapphire/internal/host/hci-spec/link_key.h"
#include "pw_bluetooth_sapphire/internal/host/hci/low_energy_connection.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/channel.h"
#include "pw_bluetooth_sapphire/internal/host/sm/delegate.h"
#include "pw_bluetooth_sapphire/internal/host/sm/error.h"
#include "pw_bluetooth_sapphire/internal/host/sm/pairing_phase.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_1.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_2_legacy.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_2_secure_connections.h"
#include "pw_bluetooth_sapphire/internal/host/sm/phase_3.h"
#include "pw_bluetooth_sapphire/internal/host/sm/security_request_phase.h"
#include "pw_bluetooth_sapphire/internal/host/sm/smp.h"
#include "pw_bluetooth_sapphire/internal/host/sm/types.h"
#include "pw_bluetooth_sapphire/internal/host/sm/util.h"
Expand Down

0 comments on commit 3b0403f

Please sign in to comment.