Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Set Pairing Delegate via Pairing State Const
Browse files Browse the repository at this point in the history
Update SecureSimplePairingState and LegacyPairingState to be able to
initialize the pairing delegate through the pairing state constructors.

Test: fx test //src/connectivity/bluetooth
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1099938
GitOrigin-RevId: 09c5b596a8c0fc687095ae24e49774b4aa651247
Change-Id: I46404107e8745f956161b231ae04728dbee8a75e
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230580
Reviewed-by: Ben Lawson <[email protected]>
Lint: Lint 🤖 <[email protected]>
Reviewed-by: Jason Graffius <[email protected]>
Pigweed-Auto-Submit: Ben Lawson <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Commit-Queue: Jason Graffius <[email protected]>
  • Loading branch information
Lulu Wang authored and CQ Bot Account committed Aug 29, 2024
1 parent 6b75bf4 commit 8ddf630
Show file tree
Hide file tree
Showing 8 changed files with 301 additions and 196 deletions.
10 changes: 4 additions & 6 deletions pw_bluetooth_sapphire/host/gap/bredr_connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1390,6 +1390,7 @@ BrEdrConnectionManager::OnLinkKeyRequest(const hci::EmbossEventPacket& event) {
// are initialized in |PairingStateManager|'s constructor.
std::unique_ptr<LegacyPairingState> legacy_pairing_state =
std::make_unique<LegacyPairingState>(peer->GetWeakPtr(),
std::move(pairing_delegate_),
outgoing_connection);

connection_req.value()->set_legacy_pairing_state(
Expand Down Expand Up @@ -1737,12 +1738,9 @@ BrEdrConnectionManager::OnPinCodeRequest(const hci::EmbossEventPacket& event) {
// |status_cb| are not created yet. After the connection is complete, they
// are initialized in |PairingStateManager|'s constructor.
std::unique_ptr<LegacyPairingState> legacy_pairing_state =
std::make_unique<LegacyPairingState>(
peer->GetWeakPtr(),
/*link=*/hci::BrEdrConnection::WeakPtr(),
outgoing_connection,
/*auth_cb=*/nullptr,
/*status_cb=*/nullptr);
std::make_unique<LegacyPairingState>(peer->GetWeakPtr(),
std::move(pairing_delegate_),
outgoing_connection);

connection_req.value()->set_legacy_pairing_state(
std::move(legacy_pairing_state));
Expand Down
38 changes: 28 additions & 10 deletions pw_bluetooth_sapphire/host/gap/legacy_pairing_state.cc
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,36 @@ const char* const kInspectSecurityPropertiesPropertyName =
"security_properties";
} // namespace

LegacyPairingState::LegacyPairingState(Peer::WeakPtr peer,
bool outgoing_connection)
LegacyPairingState::LegacyPairingState(
Peer::WeakPtr peer,
PairingDelegate::WeakPtr pairing_delegate,
bool outgoing_connection)
: peer_id_(peer->identifier()),
peer_(std::move(peer)),
outgoing_connection_(outgoing_connection) {}

LegacyPairingState::LegacyPairingState(Peer::WeakPtr peer,
WeakPtr<hci::BrEdrConnection> link,
bool outgoing_connection,
fit::closure auth_cb,
StatusCallback status_cb)
: LegacyPairingState(std::move(peer), outgoing_connection) {
outgoing_connection_(outgoing_connection) {
if (!pairing_delegate.is_alive()) {
bt_log(WARN,
"gap-bredr",
"No pairing delegate set for peer id %s",
bt_str(peer_id_));
// We set the state_ to Idle instead of Failed because it is possible that a
// PairingDelegate will be set before the next pairing attempt, allowing it
// to succeed.
state_ = State::kIdle;
return;
}
pairing_delegate_ = std::move(pairing_delegate);
}

LegacyPairingState::LegacyPairingState(
Peer::WeakPtr peer,
PairingDelegate::WeakPtr pairing_delegate,
WeakPtr<hci::BrEdrConnection> link,
bool outgoing_connection,
fit::closure auth_cb,
StatusCallback status_cb)
: LegacyPairingState(
std::move(peer), std::move(pairing_delegate), outgoing_connection) {
// We can only populate |link_|, |send_auth_request_callback_|, and
// |status_callback_| if the ACL connection is complete.
BT_ASSERT(link.is_alive());
Expand Down
Loading

0 comments on commit 8ddf630

Please sign in to comment.