Skip to content

Commit

Permalink
pw_bluetooth_proxy: Allow Write(MultiBuf) for gatt notify
Browse files Browse the repository at this point in the history
Allow clients to use MultiBuf for passing attribute to gatt notify. Also
update all tests to use Write(MultiBuf).

Passing span is deprecated. Later CL will remove it once downstreams
have moved to MultiBuf.

Bug: 388082771, 379337272
Change-Id: I5a0665cc5f582e239eccb9cbe7d82ec342c0fd88
Reviewed-on: https://pigweed-review.googlesource.com/c/pigweed/pigweed/+/258772
Reviewed-by: Ali Saeed <[email protected]>
Lint: Lint 🤖 <[email protected]>
Presubmit-Verified: CQ Bot Account <[email protected]>
Docs-Not-Needed: David Rees <[email protected]>
Commit-Queue: David Rees <[email protected]>
  • Loading branch information
studgeek authored and CQ Bot Account committed Jan 8, 2025
1 parent 56d9d44 commit b03ff49
Show file tree
Hide file tree
Showing 5 changed files with 216 additions and 76 deletions.
43 changes: 36 additions & 7 deletions pw_bluetooth_proxy/proxy_host.cc
Original file line number Diff line number Diff line change
Expand Up @@ -543,18 +543,47 @@ pw::Result<BasicL2capChannel> ProxyHost::AcquireBasicL2capChannel(
/*event_fn=*/std::move(event_fn));
}

namespace {

pw::Result<GattNotifyChannel> CreateGattNotifyChannel(
AclDataChannel& acl_data_channel,
L2capChannelManager& l2cap_channel_manager,
uint16_t connection_handle,
uint16_t attribute_handle) {
Status status = acl_data_channel.CreateAclConnection(connection_handle,
AclTransportType::kLe);
if (status != OkStatus() && status != Status::AlreadyExists()) {
return pw::Status::Unavailable();
}
return GattNotifyChannelInternal::Create(
l2cap_channel_manager, connection_handle, attribute_handle);
}
} // namespace

StatusWithMultiBuf ProxyHost::SendGattNotify(uint16_t connection_handle,
uint16_t attribute_handle,
pw::multibuf::MultiBuf&& payload) {
// TODO: https://pwbug.dev/369709521 - Migrate clients to channel API.
pw::Result<GattNotifyChannel> channel_result =
CreateGattNotifyChannel(acl_data_channel_,
l2cap_channel_manager_,
connection_handle,
attribute_handle);
if (!channel_result.ok()) {
return {channel_result.status(), std::move(payload)};
}
return channel_result->Write(std::move(payload));
}

pw::Status ProxyHost::SendGattNotify(uint16_t connection_handle,
uint16_t attribute_handle,
pw::span<const uint8_t> attribute_value) {
// TODO: https://pwbug.dev/369709521 - Migrate clients to channel API.
Status status = acl_data_channel_.CreateAclConnection(connection_handle,
AclTransportType::kLe);
if (status != OkStatus() && status != Status::AlreadyExists()) {
return pw::Status::Unavailable();
}
pw::Result<GattNotifyChannel> channel_result =
GattNotifyChannelInternal::Create(
l2cap_channel_manager_, connection_handle, attribute_handle);
CreateGattNotifyChannel(acl_data_channel_,
l2cap_channel_manager_,
connection_handle,
attribute_handle);
if (!channel_result.ok()) {
return channel_result.status();
}
Expand Down
Loading

0 comments on commit b03ff49

Please sign in to comment.