#include <proxy_host.h>
Public Member Functions | |
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) | |
ProxyHost (const ProxyHost &)=delete | |
ProxyHost & | operator= (const ProxyHost &)=delete |
ProxyHost (ProxyHost &&)=delete | |
ProxyHost & | operator= (ProxyHost &&)=delete |
~ProxyHost () | |
void | HandleH4HciFromHost (H4PacketWithH4 &&h4_packet) |
void | HandleH4HciFromController (H4PacketWithHci &&h4_packet) |
void | Reset () |
void | RegisterL2capStatusDelegate (L2capStatusDelegate &delegate) |
void | UnregisterL2capStatusDelegate (L2capStatusDelegate &delegate) |
pw::Result< L2capCoc > | AcquireL2capCoc (pw::multibuf::MultiBufAllocator &rx_multibuf_allocator, uint16_t connection_handle, L2capCoc::CocConfig rx_config, L2capCoc::CocConfig tx_config, Function< void(multibuf::MultiBuf &&payload)> &&receive_fn, ChannelEventCallback &&event_fn) |
pw::Status | SendAdditionalRxCredits (uint16_t connection_handle, uint16_t local_cid, uint16_t additional_rx_credits) |
pw::Result< BasicL2capChannel > | AcquireBasicL2capChannel (multibuf::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) |
pw::Result< GattNotifyChannel > | AcquireGattNotifyChannel (int16_t connection_handle, uint16_t attribute_handle, ChannelEventCallback &&event_fn) |
StatusWithMultiBuf | SendGattNotify (uint16_t connection_handle, uint16_t attribute_handle, pw::multibuf::MultiBuf &&payload) |
pw::Status | SendGattNotify (uint16_t connection_handle, uint16_t attribute_handle, pw::span< const uint8_t > attribute_value) |
pw::Result< RfcommChannel > | AcquireRfcommChannel (multibuf::MultiBufAllocator &rx_multibuf_allocator, uint16_t connection_handle, RfcommChannel::Config rx_config, RfcommChannel::Config tx_config, uint8_t channel_number, Function< void(multibuf::MultiBuf &&payload)> &&payload_from_controller_fn, ChannelEventCallback &&event_fn) |
bool | HasSendLeAclCapability () const |
bool | HasSendBrEdrAclCapability () const |
uint16_t | GetNumFreeLeAclPackets () const |
uint16_t | GetNumFreeBrEdrAclPackets () const |
Static Public Member Functions | |
static constexpr size_t | GetNumSimultaneousAclSendsSupported () |
static constexpr size_t | GetMaxAclSendSize () |
Returns the max LE ACL packet size supported to be sent. | |
static constexpr size_t | GetMaxNumAclConnections () |
Returns the max number of simultaneous LE ACL connections supported. | |
ProxyHost
acts as the main coordinator for proxy functionality. After creation, the container then passes packets through the proxy.
pw::bluetooth::proxy::ProxyHost::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 | ||
) |
Creates an ProxyHost
that will process HCI packets.
[in] | send_to_host_fn | Callback that will be called when proxy wants to send HCI packet towards the host. |
[in] | send_to_controller_fn | - Callback that will be called when proxy wants to send HCI packet towards the controller. |
[in] | le_acl_credits_to_reserve | - How many buffers to reserve for the proxy out of any LE ACL buffers received from controller. |
[in] | br_edr_acl_credits_to_reserve | - How many buffers to reserve for the proxy out of any BR/EDR ACL buffers received from controller. |
pw::bluetooth::proxy::ProxyHost::~ProxyHost | ( | ) |
Deregisters all channels, and if any channels are not yet closed, closes them and sends L2capChannelEvent::kChannelClosedByOther
.
pw::Result< BasicL2capChannel > pw::bluetooth::proxy::ProxyHost::AcquireBasicL2capChannel | ( | multibuf::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 | ||
) |
Returns an L2CAP channel operating in basic mode that supports writing to and reading from a remote peer.
[in] | rx_multibuf_allocator | Provides the allocator the channel will use for its Rx buffers (for both queueing and returning to the client). |
[in] | connection_handle | The connection handle of the remote peer. |
[in] | local_cid | L2CAP channel ID of the local endpoint. |
[in] | remote_cid | L2CAP channel ID of the remote endpoint. |
[in] | transport | Logical link transport type. |
[in] | payload_from_controller_fn | Read callback to be invoked on Rx SDUs. Return value of passed-in multibuf indicates the packet should be forwarded on to host. |
[in] | payload_from_host_fn | Read callback to be invoked on Tx SDUs. Return value of passed-in multibuf indicates the packet should be forwarded on to the controller. |
[in] | event_fn | Handle asynchronous events such as errors encountered by the channel. See l2cap_channel_common.h . |
embed:rst:leading-asterisk * * .. pw-status-codes:: * INVALID_ARGUMENT: If arguments are invalid (check logs). * UNAVAILABLE: If channel could not be created because no memory was * available to accommodate an additional ACL connection. *
pw::Result< GattNotifyChannel > pw::bluetooth::proxy::ProxyHost::AcquireGattNotifyChannel | ( | int16_t | connection_handle, |
uint16_t | attribute_handle, | ||
ChannelEventCallback && | event_fn | ||
) |
Returns a GATT Notify channel channel that supports sending notifications to a particular connection handle and attribute.
[in] | connection_handle | The connection handle of the peer to notify. Maximum valid connection handle is 0x0EFF. |
[in] | attribute_handle | The attribute handle the notify should be sent on. Cannot be 0. |
[in] | event_fn | Handle asynchronous events such as errors and flow control events encountered by the channel. See l2cap_channel_event.h . |
embed:rst:leading-asterisk * * .. pw-status-codes:: * INVALID_ARGUMENT: If arguments are invalid (check logs). * UNAVAILABLE: If channel could not be created because no memory was * available to accommodate an additional ACL connection. *
pw::Result< L2capCoc > pw::bluetooth::proxy::ProxyHost::AcquireL2capCoc | ( | pw::multibuf::MultiBufAllocator & | rx_multibuf_allocator, |
uint16_t | connection_handle, | ||
L2capCoc::CocConfig | rx_config, | ||
L2capCoc::CocConfig | tx_config, | ||
Function< void(multibuf::MultiBuf &&payload)> && | receive_fn, | ||
ChannelEventCallback && | event_fn | ||
) |
Returns an L2CAP connection-oriented channel that supports writing to and reading from a remote peer.
[in] | rx_multibuf_allocator | Provides the allocator the channel will use for its Rx buffers (for both queueing and returning to the client). |
[in] | connection_handle | The connection handle of the remote peer. |
[in] | rx_config | Parameters applying to reading packets. See l2cap_coc.h for details. |
[in] | tx_config | Parameters applying to writing packets. See l2cap_coc.h for details. |
[in] | receive_fn | Read callback to be invoked on Rx SDUs. |
[in] | event_fn | Handle asynchronous events such as errors and flow control events encountered by the channel. See l2cap_channel_event.h . |
embed:rst:leading-asterisk * * .. pw-status-codes:: * INVALID_ARGUMENT: If arguments are invalid (check logs). * UNAVAILABLE: If channel could not be created because no memory was * available to accommodate an additional ACL connection. *
pw::Result< RfcommChannel > pw::bluetooth::proxy::ProxyHost::AcquireRfcommChannel | ( | multibuf::MultiBufAllocator & | rx_multibuf_allocator, |
uint16_t | connection_handle, | ||
RfcommChannel::Config | rx_config, | ||
RfcommChannel::Config | tx_config, | ||
uint8_t | channel_number, | ||
Function< void(multibuf::MultiBuf &&payload)> && | payload_from_controller_fn, | ||
ChannelEventCallback && | event_fn | ||
) |
Returns an RFCOMM channel that supports writing to and reading from a remote peer.
[in] | rx_multibuf_allocator | Provides the allocator the channel will use for its Rx buffers (for both queueing and returning to the client). |
[in] | connection_handle | The connection handle of the remote peer. |
[in] | rx_config | Parameters applying to reading packets. See rfcomm_channel.h for details. |
[in] | tx_config | Parameters applying to writing packets. See rfcomm_channel.h for details. |
[in] | channel_number | RFCOMM channel number to use. |
[in] | payload_from_controller_fn | Read callback to be invoked on Rx frames. |
[in] | event_fn | Handle asynchronous events such as errors encountered by the channel. See l2cap_channel_common.h . |
embed:rst:leading-asterisk * * .. pw-status-codes:: * INVALID_ARGUMENT: If arguments are invalid (check logs). * UNAVAILABLE: If channel could not be created. *
uint16_t pw::bluetooth::proxy::ProxyHost::GetNumFreeBrEdrAclPackets | ( | ) | const |
Returns the number of available BR/EDR ACL send credits for the proxy. Can be zero if the controller has not yet been initialized by the host.
uint16_t pw::bluetooth::proxy::ProxyHost::GetNumFreeLeAclPackets | ( | ) | const |
Returns the number of available LE ACL send credits for the proxy. Can be zero if the controller has not yet been initialized by the host.
|
inlinestaticconstexpr |
Returns the max number of LE ACL sends that can be in-flight at one time. That is, ACL packets that have been sent and not yet released.
void pw::bluetooth::proxy::ProxyHost::HandleH4HciFromController | ( | H4PacketWithHci && | h4_packet | ) |
Called by container to ask proxy to handle a H4 packet sent from the controller side towards the host side. Proxy will in turn call the send_to_host_fn
provided during construction to pass the packet on to the host. Some packets may be modified, added, or removed.
To support all of its current functionality, the proxy host needs at least the following from-controller packets passed through it. It will pass on all other packets, so containers can choose to just pass all from-controller packets through the proxy host.
All packets of this type:
HCI_Command_Complete events (7.7.14) containing return parameters for these commands:
These HCI event packets:
Container is required to call this function synchronously (one packet at a time).
void pw::bluetooth::proxy::ProxyHost::HandleH4HciFromHost | ( | H4PacketWithH4 && | h4_packet | ) |
Called by container to ask proxy to handle a H4 HCI packet sent from the host side towards the controller side. Proxy will in turn call the send_to_controller_fn
provided during construction to pass the packet on to the controller. Some packets may be modified, added, or removed.
The proxy host currently does not require any from-host packets to support its current functionality. It will pass on all packets, so containers can choose to just pass all from-host packets through it.
Container is required to call this function synchronously (one packet at a time).
bool pw::bluetooth::proxy::ProxyHost::HasSendBrEdrAclCapability | ( | ) | const |
Indicates whether the proxy has the capability of sending BR/EDR ACL packets. Note that this indicates intention, so it can be true even if the proxy has not yet or has been unable to reserve credits from the host.
bool pw::bluetooth::proxy::ProxyHost::HasSendLeAclCapability | ( | ) | const |
Indicates whether the proxy has the capability of sending LE ACL packets. Note that this indicates intention, so it can be true even if the proxy has not yet or has been unable to reserve credits from the host.
void pw::bluetooth::proxy::ProxyHost::RegisterL2capStatusDelegate | ( | L2capStatusDelegate & | delegate | ) |
Register for notifications of connection and disconnection for a particular L2cap service identified by its PSM.
[in] | delegate | A delegate that will be notified when a successful L2cap connection is made on its PSM. Note: This must outlive the ProxyHost. |
void pw::bluetooth::proxy::ProxyHost::Reset | ( | ) |
Called when an HCI_Reset Command packet is observed. Proxy resets its internal state. Deregisters all channels, and if any channels are not yet closed, closes them and sends L2capChannelEvent::kReset
.
May also be called by container to notify proxy that the Bluetooth system is being otherwise reset.
Warning: Outstanding H4 packets are not invalidated upon reset. If they are destructed post-reset, packets generated post-reset are liable to be overwritten prematurely.
pw::Status pw::bluetooth::proxy::ProxyHost::SendAdditionalRxCredits | ( | uint16_t | connection_handle, |
uint16_t | local_cid, | ||
uint16_t | additional_rx_credits | ||
) |
TODO: https://pwbug.dev/380076024 - Delete after downstream client uses this method on L2capCoc
.
StatusWithMultiBuf pw::bluetooth::proxy::ProxyHost::SendGattNotify | ( | uint16_t | connection_handle, |
uint16_t | attribute_handle, | ||
pw::multibuf::MultiBuf && | payload | ||
) |
Send a GATT Notify to the indicated connection.
[in] | connection_handle | The connection handle of the peer to notify. Maximum valid connection handle is 0x0EFF. |
[in] | attribute_handle | The attribute handle the notify should be sent on. Cannot be 0. |
[in] | attribute_value | The client payload to be sent. Payload will be destroyed once its data has been used. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * OK: If notify was successfully queued for send. * UNAVAILABLE: If CHRE doesn't have resources to queue the send at this * time (transient error). * * INVALID_ARGUMENT: If arguments are invalid (check logs). *
ProxyHost::AcquireGattNotifyChannel
and then call GattNotifyChannel::Write
on that. pw::Status pw::bluetooth::proxy::ProxyHost::SendGattNotify | ( | uint16_t | connection_handle, |
uint16_t | attribute_handle, | ||
pw::span< const uint8_t > | attribute_value | ||
) |
Send a GATT Notify to the indicated connection.
Deprecated, use MultiBuf version above instead.
[in] | connection_handle | The connection handle of the peer to notify. Maximum valid connection handle is 0x0EFF. |
[in] | attribute_handle | The attribute handle the notify should be sent on. Cannot be 0. |
[in] | attribute_value | The data to be sent. Data will be copied before function completes. |
embed:rst:leading-asterisk * * .. pw-status-codes:: * OK: If notify was successfully queued for send. * UNAVAILABLE: If CHRE doesn't have resources to queue the send * at this time (transient error). * INVALID_ARGUMENT: If arguments are invalid (check logs). *
ProxyHost::AcquireGattNotifyChannel
and then call GattNotifyChannel::Write
on that. void pw::bluetooth::proxy::ProxyHost::UnregisterL2capStatusDelegate | ( | L2capStatusDelegate & | delegate | ) |
Unregister a service delegate.
[in] | delegate | The delegate to unregister. Must have been previously registered. |