Skip to content

Commit

Permalink
pw_bluetooth_sapphire: Support creating LE dynamic channels in l2cap
Browse files Browse the repository at this point in the history
Support creating (outbound-only as of this commit) LE dynamic channels
in the L2CAP layer using the LE credit-based flow control.

Test: fx test l2cap_tests
Bug: 42178956
GitOrigin-RevId: 99cd566731a287e1e39f68332209969c89e21491
Change-Id: If319a741ce4382c20a69eba66e490e16606ba28f
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/240713
Docs-Not-Needed: Jason Graffius <[email protected]>
Reviewed-by: Ben Lawson <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Lint: Lint 🤖 <[email protected]>
Commit-Queue: Jason Graffius <[email protected]>
  • Loading branch information
jasongraffius authored and CQ Bot Account committed Oct 11, 2024
1 parent de832f1 commit 676147b
Show file tree
Hide file tree
Showing 16 changed files with 1,226 additions and 23 deletions.
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,7 @@ cc_library(
"public/pw_bluetooth_sapphire/internal/host/l2cap/fragmenter.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/frame_headers.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/l2cap_defs.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/le_dynamic_channel.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/le_signaling_channel.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/logical_link.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/low_energy_command_handler.h",
Expand Down
1 change: 1 addition & 0 deletions pw_bluetooth_sapphire/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,7 @@ pw_source_set("_public") {
"public/pw_bluetooth_sapphire/internal/host/l2cap/fragmenter.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/frame_headers.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/l2cap_defs.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/le_dynamic_channel.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/le_signaling_channel.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/logical_link.h",
"public/pw_bluetooth_sapphire/internal/host/l2cap/low_energy_command_handler.h",
Expand Down
2 changes: 2 additions & 0 deletions pw_bluetooth_sapphire/host/l2cap/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ cc_library(
"enhanced_retransmission_mode_tx_engine.cc",
"fcs.cc",
"fragmenter.cc",
"le_dynamic_channel.cc",
"le_signaling_channel.cc",
"logical_link.cc",
"low_energy_command_handler.cc",
Expand Down Expand Up @@ -139,6 +140,7 @@ pw_cc_test(
"fcs_test.cc",
"fragmenter_test.cc",
"frame_headers_test.cc",
"le_dynamic_channel_test.cc",
"le_signaling_channel_test.cc",
"logical_link_test.cc",
"low_energy_command_handler_test.cc",
Expand Down
3 changes: 3 additions & 0 deletions pw_bluetooth_sapphire/host/l2cap/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ pw_source_set("l2cap") {
"$dir_public_l2cap/enhanced_retransmission_mode_tx_engine.h",
"$dir_public_l2cap/fcs.h",
"$dir_public_l2cap/fragmenter.h",
"$dir_public_l2cap/le_dynamic_channel.h",
"$dir_public_l2cap/le_signaling_channel.h",
"$dir_public_l2cap/logical_link.h",
"$dir_public_l2cap/low_energy_command_handler.h",
Expand Down Expand Up @@ -85,6 +86,7 @@ pw_source_set("l2cap") {
"enhanced_retransmission_mode_tx_engine.cc",
"fcs.cc",
"fragmenter.cc",
"le_dynamic_channel.cc",
"le_signaling_channel.cc",
"logical_link.cc",
"low_energy_command_handler.cc",
Expand Down Expand Up @@ -191,6 +193,7 @@ pw_test("l2cap_tests") {
"fcs_test.cc",
"fragmenter_test.cc",
"frame_headers_test.cc",
"le_dynamic_channel_test.cc",
"le_signaling_channel_test.cc",
"logical_link_test.cc",
"low_energy_command_handler_test.cc",
Expand Down
31 changes: 23 additions & 8 deletions pw_bluetooth_sapphire/host/l2cap/channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
#include "pw_bluetooth_sapphire/internal/host/common/weak_self.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/basic_mode_rx_engine.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/basic_mode_tx_engine.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/credit_based_flow_control_rx_engine.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/credit_based_flow_control_tx_engine.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/enhanced_retransmission_mode_engines.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/l2cap_defs.h"
#include "pw_bluetooth_sapphire/internal/host/l2cap/logical_link.h"
Expand Down Expand Up @@ -135,22 +137,35 @@ ChannelImpl::ChannelImpl(pw::async::Dispatcher& dispatcher,
BT_ASSERT_MSG(
info_.mode == RetransmissionAndFlowControlMode::kBasic ||
info_.mode ==
RetransmissionAndFlowControlMode::kEnhancedRetransmission,
RetransmissionAndFlowControlMode::kEnhancedRetransmission ||
info.mode == CreditBasedFlowControlMode::kLeCreditBasedFlowControl,
"Channel constructed with unsupported mode: %s\n",
AnyChannelModeToString(info_.mode).c_str());

auto connection_failure_cb = [link] {
if (link.is_alive()) {
// |link| is expected to ignore this call if it has been closed.
link->SignalError();
}
};

if (info_.mode == RetransmissionAndFlowControlMode::kBasic) {
rx_engine_ = std::make_unique<BasicModeRxEngine>();
tx_engine_ =
std::make_unique<BasicModeTxEngine>(id, max_tx_sdu_size(), *this);
} else if (std::holds_alternative<CreditBasedFlowControlMode>(info_.mode)) {
BT_ASSERT(info_.remote_initial_credits.has_value());
auto mode = std::get<CreditBasedFlowControlMode>(info_.mode);
rx_engine_ = std::make_unique<CreditBasedFlowControlRxEngine>(
std::move(connection_failure_cb));
tx_engine_ = std::make_unique<CreditBasedFlowControlTxEngine>(
id,
max_tx_sdu_size(),
*this,
mode,
info_.max_tx_pdu_payload_size,
*info_.remote_initial_credits);
} else {
// Must capture |link| and not |link_| to avoid having to take |mutex_|.
auto connection_failure_cb = [link] {
if (link.is_alive()) {
// |link| is expected to ignore this call if it has been closed.
link->SignalError();
}
};
std::tie(rx_engine_, tx_engine_) =
MakeLinkedEnhancedRetransmissionModeEngines(
id,
Expand Down
Loading

0 comments on commit 676147b

Please sign in to comment.