C/C++ API Reference
Loading...
Searching...
No Matches
proxy_host.h
1// Copyright 2024 The Pigweed Authors
2//
3// Licensed under the Apache License, Version 2.0 (the "License"); you may not
4// use this file except in compliance with the License. You may obtain a copy of
5// the License at
6//
7// https://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12// License for the specific language governing permissions and limitations under
13// the License.
14
15#pragma once
16
17#include "pw_bluetooth_proxy/gatt_notify_channel.h"
18#include "pw_bluetooth_proxy/internal/acl_data_channel.h"
19#include "pw_bluetooth_proxy/internal/hci_transport.h"
20#include "pw_bluetooth_proxy/internal/l2cap_channel_manager.h"
21#include "pw_bluetooth_proxy/internal/multibuf.h"
22#include "pw_bluetooth_proxy/l2cap_channel_common.h"
23#include "pw_bluetooth_proxy/l2cap_coc.h"
24#include "pw_bluetooth_proxy/l2cap_status_delegate.h"
25#include "pw_status/status.h"
26
28namespace pw::bluetooth::proxy {
29
31
34class ProxyHost {
35 public:
49 ProxyHost(pw::Function<void(H4PacketWithHci&& packet)>&& send_to_host_fn,
50 pw::Function<void(H4PacketWithH4&& packet)>&& send_to_controller_fn,
51 uint16_t le_acl_credits_to_reserve,
52 uint16_t br_edr_acl_credits_to_reserve,
53 pw::Allocator* allocator = nullptr);
54
55 ProxyHost() = delete;
56 ProxyHost(const ProxyHost&) = delete;
57 ProxyHost& operator=(const ProxyHost&) = delete;
58 ProxyHost(ProxyHost&&) = delete;
59 ProxyHost& operator=(ProxyHost&&) = delete;
63
64 // ##### Container API
65 // Containers are expected to call these functions (in addition to ctor).
66
79
106
117 void Reset();
118
119 // ##### Client APIs
120
127 void RegisterL2capStatusDelegate(L2capStatusDelegate& delegate);
128
133 void UnregisterL2capStatusDelegate(L2capStatusDelegate& delegate);
134
162 MultiBufAllocator& rx_multibuf_allocator,
163 uint16_t connection_handle,
164 L2capCoc::CocConfig rx_config,
165 L2capCoc::CocConfig tx_config,
166 Function<void(FlatConstMultiBuf&& payload)>&& receive_fn,
167 ChannelEventCallback&& event_fn);
168
207 MultiBufAllocator& rx_multibuf_allocator,
208 uint16_t connection_handle,
209 uint16_t local_cid,
210 uint16_t remote_cid,
211 AclTransportType transport,
212 OptionalPayloadReceiveCallback&& payload_from_controller_fn,
213 OptionalPayloadReceiveCallback&& payload_from_host_fn,
214 ChannelEventCallback&& event_fn);
215
234 int16_t connection_handle,
235 uint16_t attribute_handle,
236 ChannelEventCallback&& event_fn);
237
242
247
250 uint16_t GetNumFreeLeAclPackets() const;
251
255
257 static constexpr size_t GetMaxNumAclConnections() {
258 return AclDataChannel::GetMaxNumAclConnections();
259 }
260
261 private:
262 // Handle HCI Event packet from the controller.
263 void HandleEventFromController(H4PacketWithHci&& h4_packet);
264
265 // Handle HCI Event packet from the host.
266 void HandleEventFromHost(H4PacketWithH4&& h4_packet);
267
268 // Handle HCI ACL data packet from the controller.
269 void HandleAclFromController(H4PacketWithHci&& h4_packet);
270
271 // Process an LE_META_EVENT
272 void HandleLeMetaEvent(H4PacketWithHci&& h4_packet);
273
274 // Process a Command_Complete event.
275 void HandleCommandCompleteEvent(H4PacketWithHci&& h4_packet);
276
277 // Handle HCI Command packet from the host.
278 void HandleCommandFromHost(H4PacketWithH4&& h4_packet);
279
280 // Handle HCI ACL data packet from the host.
281 void HandleAclFromHost(H4PacketWithH4&& h4_packet);
282
283 // Called when any type of connection complete event is received.
284 void OnConnectionCompleteSuccess(uint16_t connection_handle,
285 AclTransportType transport);
286
287 // AclDataChannel callback for when new ACL TX credits are received and more
288 // L2CAP packets can be sent.
289 void OnAclTxCredits();
290
291 // For sending non-ACL data to the host and controller. ACL traffic shall be
292 // sent through the `acl_data_channel_`.
293 HciTransport hci_transport_;
294
295 // Owns management of the LE ACL data channel.
296 AclDataChannel acl_data_channel_;
297
298 // Keeps track of the L2CAP-based channels managed by the proxy.
299 L2capChannelManager l2cap_channel_manager_;
300};
301
302} // namespace pw::bluetooth::proxy
Definition: allocator.h:36
Definition: multibuf_v2.h:185
Definition: result.h:143
H4PacketWithH4 is an H4Packet backed by an H4 buffer.
Definition: h4_packet.h:97
H4PacketWithHci is an H4Packet backed by an HCI buffer.
Definition: h4_packet.h:66
Definition: proxy_host.h:34
static constexpr size_t GetMaxNumAclConnections()
Returns the max number of simultaneous LE ACL connections supported.
Definition: proxy_host.h:257
pw::Result< GattNotifyChannel > AcquireGattNotifyChannel(int16_t connection_handle, uint16_t attribute_handle, ChannelEventCallback &&event_fn)
void HandleH4HciFromHost(H4PacketWithH4 &&h4_packet)
void RegisterL2capStatusDelegate(L2capStatusDelegate &delegate)
pw::Result< BasicL2capChannel > AcquireBasicL2capChannel(MultiBufAllocator &rx_multibuf_allocator, uint16_t connection_handle, uint16_t local_cid, uint16_t remote_cid, AclTransportType transport, OptionalPayloadReceiveCallback &&payload_from_controller_fn, OptionalPayloadReceiveCallback &&payload_from_host_fn, ChannelEventCallback &&event_fn)
uint16_t GetNumFreeLeAclPackets() const
uint16_t GetNumFreeBrEdrAclPackets() const
ProxyHost(pw::Function< void(H4PacketWithHci &&packet)> &&send_to_host_fn, pw::Function< void(H4PacketWithH4 &&packet)> &&send_to_controller_fn, uint16_t le_acl_credits_to_reserve, uint16_t br_edr_acl_credits_to_reserve, pw::Allocator *allocator=nullptr)
void UnregisterL2capStatusDelegate(L2capStatusDelegate &delegate)
pw::Result< L2capCoc > AcquireL2capCoc(MultiBufAllocator &rx_multibuf_allocator, uint16_t connection_handle, L2capCoc::CocConfig rx_config, L2capCoc::CocConfig tx_config, Function< void(FlatConstMultiBuf &&payload)> &&receive_fn, ChannelEventCallback &&event_fn)
void HandleH4HciFromController(H4PacketWithHci &&h4_packet)
fit::function_impl< function_internal::config::kInlineCallableSize, !function_internal::config::kEnableDynamicAllocation, FunctionType, PW_FUNCTION_DEFAULT_ALLOCATOR_TYPE > Function
Definition: function.h:73
Lightweight proxy for augmenting Bluetooth functionality.
Definition: h4_packet.h:24