Skip to content

Commit

Permalink
pw_bluetooth_proxy: Standardize on local/remote for l2cap cid names
Browse files Browse the repository at this point in the history
Change status tracker fields to use same local/remote terminology as
L2capChannel uses.

Bug: 385360470
Change-Id: Ie6744ce590f2d6b2ef753003cc1e29f1b699f2c8
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/256086
Docs-Not-Needed: Austin Foxley <[email protected]>
Commit-Queue: Auto-Submit <[email protected]>
Pigweed-Auto-Submit: Austin Foxley <[email protected]>
Lint: Lint 🤖 <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Reviewed-by: Ben Lawson <[email protected]>
  • Loading branch information
afoxley authored and CQ Bot Account committed Dec 21, 2024
1 parent 8b1d112 commit 34224ad
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 15 deletions.
2 changes: 1 addition & 1 deletion pw_bluetooth_proxy/l2cap_channel_manager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ void L2capChannelManager::HandleDisconnectionComplete(
void L2capChannelManager::HandleDisconnectionComplete(
const L2capStatusTracker::DisconnectParams& params) {
L2capChannel* channel =
FindChannelByLocalCid(params.connection_handle, params.destination_cid);
FindChannelByLocalCid(params.connection_handle, params.local_cid);
if (channel) {
channel->Close();
}
Expand Down
15 changes: 9 additions & 6 deletions pw_bluetooth_proxy/l2cap_signaling_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ void L2capSignalingChannel::HandleConnectionReq(
return;
}
pending_connections_.push_back({.direction = direction,
.source_cid = cmd.source_cid().Read(),
.remote_cid = cmd.source_cid().Read(),
.psm = cmd.psm().Read()});
}

Expand All @@ -170,14 +170,14 @@ void L2capSignalingChannel::HandleConnectionRsp(

struct {
Direction direction;
uint16_t source_cid;
uint16_t remote_cid;
} match_info = {.direction = request_direction,
.source_cid = cmd.source_cid().Read()};
.remote_cid = cmd.source_cid().Read()};

auto match = [&match_info](const PendingConnection& pending) {
// TODO: https://pwbug.dev/379558046 - Consider using identifier instead to
// match request to response
return pending.source_cid == match_info.source_cid &&
return pending.remote_cid == match_info.remote_cid &&
pending.direction == match_info.direction;
};
auto pending_it = std::find_if(
Expand All @@ -195,6 +195,9 @@ void L2capSignalingChannel::HandleConnectionRsp(
.direction = request_direction,
.psm = pending_it->psm,
.connection_handle = connection_handle(),
.remote_cid = cmd.source_cid().Read(),
.local_cid = cmd.destination_cid().Read(),

.source_cid = cmd.source_cid().Read(),
.destination_cid = cmd.destination_cid().Read(),
});
Expand Down Expand Up @@ -230,8 +233,8 @@ void L2capSignalingChannel::HandleDisconnectionRsp(
l2cap_channel_manager_.HandleDisconnectionComplete(
L2capStatusTracker::DisconnectParams{
.connection_handle = connection_handle(),
.source_cid = cmd.source_cid().Read(),
.destination_cid = cmd.destination_cid().Read()});
.remote_cid = cmd.source_cid().Read(),
.local_cid = cmd.destination_cid().Read()});
}

bool L2capSignalingChannel::HandleFlowControlCreditInd(
Expand Down
4 changes: 2 additions & 2 deletions pw_bluetooth_proxy/l2cap_status_tracker.cc
Original file line number Diff line number Diff line change
Expand Up @@ -84,8 +84,8 @@ void L2capStatusTracker::HandleDisconnectionComplete(
for (L2capStatusDelegate& delegate : delegates_) {
auto match = [&params](const L2capChannelConnectionInfo& i) {
return params.connection_handle == i.connection_handle &&
params.source_cid == i.source_cid &&
params.destination_cid == i.destination_cid;
params.remote_cid == i.remote_cid &&
params.local_cid == i.local_cid;
};
auto connection_it = std::find_if(connected_channel_infos_.begin(),
connected_channel_infos_.end(),
Expand Down
6 changes: 3 additions & 3 deletions pw_bluetooth_proxy/proxy_host_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2867,8 +2867,8 @@ TEST_F(ProxyHostConnectionEventTest, L2capEventsCalled) {
ASSERT_TRUE(info.has_value());
EXPECT_EQ(info->direction, i.direction);
EXPECT_EQ(info->connection_handle, i.connection_handle);
EXPECT_EQ(info->source_cid, i.source_cid);
EXPECT_EQ(info->destination_cid, i.destination_cid);
EXPECT_EQ(info->remote_cid, i.remote_cid);
EXPECT_EQ(info->local_cid, i.local_cid);
info.reset();
}

Expand Down Expand Up @@ -2925,7 +2925,7 @@ TEST_F(ProxyHostConnectionEventTest, L2capEventsCalled) {
kDestinationCid,
emboss::L2capConnectionRspResultCode::SUCCESSFUL));
EXPECT_TRUE(test_delegate.info.has_value());
EXPECT_EQ(test_delegate.info->destination_cid, kDestinationCid);
EXPECT_EQ(test_delegate.info->local_cid, kDestinationCid);

// Send disconnect
PW_TEST_EXPECT_OK(SendL2capDisconnectRsp(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class L2capSignalingChannel : public BasicL2capChannel {
private:
struct PendingConnection {
Direction direction;
uint16_t source_cid;
uint16_t remote_cid;
uint16_t psm;
};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ class L2capStatusTracker {

struct DisconnectParams {
uint16_t connection_handle;
uint16_t source_cid;
uint16_t destination_cid;
uint16_t remote_cid;
uint16_t local_cid;
};

void HandleDisconnectionComplete(uint16_t connection_handle)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,12 @@ struct L2capChannelConnectionInfo {
Direction direction;
uint16_t psm;
uint16_t connection_handle;
// Otherwise known as source_cid
uint16_t remote_cid;
// Otherwise known as destination_cid
uint16_t local_cid;

// TODO: https://pwbug.dev/385360470 - Remove after migration.
uint16_t source_cid;
uint16_t destination_cid;
};
Expand Down

0 comments on commit 34224ad

Please sign in to comment.