Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Setup ISO Data Path
Browse files Browse the repository at this point in the history
* Plumb access to the transport layer up to the IsoStreamManager,
  so we can register our connections.
* Implement IsoStream support for setting up an Iso data path
  and, on success, registering it with the IsoDataChannel.

Bug: b/311639690
Test: fx test //src/connectivity/bluetooth/core/bt-host
Reviewed-on: https://fuchsia-review.googlesource.com/c/fuchsia/+/1004454
GitOrigin-RevId: 092c6a0820d7049622abd4afdaab3f2b8adea994
Change-Id: I6d1248d6354730342772b3da01c1bdd43b410d1d
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/230532
Commit-Queue: Jason Graffius <[email protected]>
Reviewed-by: Josh Conner <[email protected]>
Lint: Lint 🤖 <[email protected]>
  • Loading branch information
josh-conner authored and CQ Bot Account committed Aug 23, 2024
1 parent 9a6adf1 commit 769ce8f
Show file tree
Hide file tree
Showing 20 changed files with 488 additions and 79 deletions.
2 changes: 1 addition & 1 deletion pw_bluetooth_sapphire/host/gap/adapter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1494,7 +1494,7 @@ void AdapterImpl::InitializeStep4() {
fit::bind_member<&AdapterImpl::OnLeAutoConnectRequest>(this));

le_connection_manager_ = std::make_unique<LowEnergyConnectionManager>(
hci_->command_channel()->AsWeakPtr(),
hci_->GetWeakPtr(),
le_address_manager_.get(),
hci_le_connector_.get(),
&peer_cache_,
Expand Down
15 changes: 9 additions & 6 deletions pw_bluetooth_sapphire/host/gap/low_energy_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ std::unique_ptr<LowEnergyConnection> LowEnergyConnection::Create(
WeakSelf<LowEnergyConnectionManager>::WeakPtr conn_mgr,
l2cap::ChannelManager* l2cap,
gatt::GATT::WeakPtr gatt,
hci::CommandChannel::WeakPtr cmd_channel,
hci::Transport::WeakPtr hci,
pw::async::Dispatcher& dispatcher) {
// Catch any errors/disconnects during connection initialization so that they
// are reported by returning a nullptr. This is less error-prone than calling
Expand All @@ -56,7 +56,8 @@ std::unique_ptr<LowEnergyConnection> LowEnergyConnection::Create(
// TODO(fxbug.dev/325646523): Only create an IsoStreamManager
// instance if our adapter supports Isochronous streams.
std::unique_ptr<iso::IsoStreamManager> iso_mgr =
std::make_unique<iso::IsoStreamManager>(link->handle(), cmd_channel);
std::make_unique<iso::IsoStreamManager>(link->handle(),
hci->GetWeakPtr());
std::unique_ptr<LowEnergyConnection> connection(
new LowEnergyConnection(std::move(peer),
std::move(link),
Expand All @@ -67,7 +68,7 @@ std::unique_ptr<LowEnergyConnection> LowEnergyConnection::Create(
std::move(iso_mgr),
l2cap,
std::move(gatt),
std::move(cmd_channel),
std::move(hci),
dispatcher));

// This looks strange, but it is possible for InitializeFixedChannels() to
Expand All @@ -94,7 +95,7 @@ LowEnergyConnection::LowEnergyConnection(
std::unique_ptr<iso::IsoStreamManager> iso_mgr,
l2cap::ChannelManager* l2cap,
gatt::GATT::WeakPtr gatt,
hci::CommandChannel::WeakPtr cmd_channel,
hci::Transport::WeakPtr hci,
pw::async::Dispatcher& dispatcher)
: dispatcher_(dispatcher),
peer_(std::move(peer)),
Expand All @@ -104,7 +105,7 @@ LowEnergyConnection::LowEnergyConnection(
iso_mgr_(std::move(iso_mgr)),
l2cap_(l2cap),
gatt_(std::move(gatt)),
cmd_(std::move(cmd_channel)),
hci_(std::move(hci)),
peer_disconnect_callback_(std::move(peer_disconnect_cb)),
error_callback_(std::move(error_cb)),
refs_(/*convert=*/[](const auto& refs) { return refs.size(); }),
Expand All @@ -114,9 +115,11 @@ LowEnergyConnection::LowEnergyConnection(
BT_ASSERT(link_);
BT_ASSERT(conn_mgr_.is_alive());
BT_ASSERT(gatt_.is_alive());
BT_ASSERT(cmd_.is_alive());
BT_ASSERT(hci_.is_alive());
BT_ASSERT(peer_disconnect_callback_);
BT_ASSERT(error_callback_);
cmd_ = hci_->command_channel()->AsWeakPtr();
BT_ASSERT(cmd_.is_alive());

link_->set_peer_disconnect_callback(
[this](const auto&, auto reason) { peer_disconnect_callback_(reason); });
Expand Down
10 changes: 5 additions & 5 deletions pw_bluetooth_sapphire/host/gap/low_energy_connection_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ const char* kInspectDisconnectRemoteDisconnectionNodeName =
} // namespace

LowEnergyConnectionManager::LowEnergyConnectionManager(
hci::CommandChannel::WeakPtr cmd_channel,
hci::Transport::WeakPtr hci,
hci::LocalAddressDelegate* addr_delegate,
hci::LowEnergyConnector* connector,
PeerCache* peer_cache,
Expand All @@ -118,7 +118,7 @@ LowEnergyConnectionManager::LowEnergyConnectionManager(
const AdapterState& adapter_state,
pw::async::Dispatcher& dispatcher)
: dispatcher_(dispatcher),
cmd_(std::move(cmd_channel)),
hci_(std::move(hci)),
security_mode_(LESecurityMode::Mode1),
sm_factory_func_(std::move(sm_creator)),
request_timeout_(kLECreateConnectionTimeout),
Expand All @@ -133,7 +133,7 @@ LowEnergyConnectionManager::LowEnergyConnectionManager(
BT_DEBUG_ASSERT(peer_cache_);
BT_DEBUG_ASSERT(l2cap_);
BT_DEBUG_ASSERT(gatt_.is_alive());
BT_DEBUG_ASSERT(cmd_.is_alive());
BT_DEBUG_ASSERT(hci_.is_alive());
BT_DEBUG_ASSERT(hci_connector_);
BT_DEBUG_ASSERT(local_address_delegate_);
}
Expand Down Expand Up @@ -429,7 +429,7 @@ void LowEnergyConnectionManager::RegisterRemoteInitiatedLink(
std::unique_ptr<internal::LowEnergyConnector> connector =
std::make_unique<internal::LowEnergyConnector>(peer_id,
connection_options,
cmd_,
hci_,
peer_cache_,
weak_self_.GetWeakPtr(),
l2cap_,
Expand Down Expand Up @@ -516,7 +516,7 @@ void LowEnergyConnectionManager::TryCreateNextConnection() {
std::make_unique<internal::LowEnergyConnector>(
peer_id,
request.connection_options(),
cmd_,
hci_,
peer_cache_,
weak_self_.GetWeakPtr(),
l2cap_,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class LowEnergyConnectionManagerTest : public TestingBase {
discovery_manager_ = std::make_unique<LowEnergyDiscoveryManager>(
scanner_.get(), peer_cache_.get(), dispatcher());
conn_mgr_ = std::make_unique<LowEnergyConnectionManager>(
cmd_weak,
transport()->GetWeakPtr(),
&addr_delegate_,
connector_.get(),
peer_cache_.get(),
Expand Down
11 changes: 7 additions & 4 deletions pw_bluetooth_sapphire/host/gap/low_energy_connector.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ constexpr const char* kInspectIsOutboundPropertyName = "is_outbound";
LowEnergyConnector::LowEnergyConnector(
PeerId peer_id,
LowEnergyConnectionOptions options,
hci::CommandChannel::WeakPtr cmd_channel,
hci::Transport::WeakPtr hci,
PeerCache* peer_cache,
WeakSelf<LowEnergyConnectionManager>::WeakPtr conn_mgr,
l2cap::ChannelManager* l2cap,
Expand All @@ -60,14 +60,17 @@ LowEnergyConnector::LowEnergyConnector(
gatt_(std::move(gatt)),
adapter_state_(adapter_state),
options_(options),
cmd_(std::move(cmd_channel)),
hci_(std::move(hci)),
le_connection_manager_(std::move(conn_mgr)) {
BT_ASSERT(cmd_.is_alive());
BT_ASSERT(peer_cache_);
BT_ASSERT(l2cap_);
BT_ASSERT(gatt_.is_alive());
BT_ASSERT(hci_.is_alive());
BT_ASSERT(le_connection_manager_.is_alive());

cmd_ = hci_->command_channel()->AsWeakPtr();
BT_ASSERT(cmd_.is_alive());

auto peer = peer_cache_->FindById(peer_id_);
BT_ASSERT(peer);
peer_address_ = peer->address();
Expand Down Expand Up @@ -380,7 +383,7 @@ bool LowEnergyConnector::InitializeConnection(
le_connection_manager_,
l2cap_,
gatt_,
cmd_,
hci_,
dispatcher_);
if (!connection) {
bt_log(WARN,
Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/host/iso/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ cc_library(
deps = [
"//pw_bluetooth_sapphire:public",
"//pw_bluetooth_sapphire/host/common",
"//pw_bluetooth_sapphire/host/hci",
"//pw_bluetooth_sapphire/host/transport",
],
)
Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/host/iso/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ pw_source_set("iso") {

public_deps = [
"$dir_pw_bluetooth_sapphire/host/common",
"$dir_pw_bluetooth_sapphire/host/hci",
"$dir_pw_bluetooth_sapphire/host/transport",
]
}
Expand Down
Loading

0 comments on commit 769ce8f

Please sign in to comment.