Pigweed
 
Loading...
Searching...
No Matches
pw::bluetooth::proxy::ProxyHost Class Reference

#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
 
ProxyHostoperator= (const ProxyHost &)=delete
 
 ProxyHost (ProxyHost &&)=delete
 
ProxyHostoperator= (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.
 

Detailed Description

ProxyHost acts as the main coordinator for proxy functionality. After creation, the container then passes packets through the proxy.

Constructor & Destructor Documentation

◆ ProxyHost()

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.

Parameters
[in]send_to_host_fnCallback 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.

◆ ~ProxyHost()

pw::bluetooth::proxy::ProxyHost::~ProxyHost ( )

Deregisters all channels, and if any channels are not yet closed, closes them and sends L2capChannelEvent::kChannelClosedByOther.

Member Function Documentation

◆ AcquireBasicL2capChannel()

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.

Parameters
[in]rx_multibuf_allocatorProvides the allocator the channel will use for its Rx buffers (for both queueing and returning to the client).
[in]connection_handleThe connection handle of the remote peer.
[in]local_cidL2CAP channel ID of the local endpoint.
[in]remote_cidL2CAP channel ID of the remote endpoint.
[in]transportLogical link transport type.
[in]payload_from_controller_fnRead 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_fnRead 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_fnHandle asynchronous events such as errors encountered by the channel. See l2cap_channel_common.h.
Returns
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.
*  

◆ AcquireGattNotifyChannel()

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.

Parameters
[in]connection_handleThe connection handle of the peer to notify. Maximum valid connection handle is 0x0EFF.
[in]attribute_handleThe attribute handle the notify should be sent on. Cannot be 0.
[in]event_fnHandle asynchronous events such as errors and flow control events encountered by the channel. See l2cap_channel_event.h.
Returns
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.
*  

◆ AcquireL2capCoc()

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.

Parameters
[in]rx_multibuf_allocatorProvides the allocator the channel will use for its Rx buffers (for both queueing and returning to the client).
[in]connection_handleThe connection handle of the remote peer.
[in]rx_configParameters applying to reading packets. See l2cap_coc.h for details.
[in]tx_configParameters applying to writing packets. See l2cap_coc.h for details.
[in]receive_fnRead callback to be invoked on Rx SDUs.
[in]event_fnHandle asynchronous events such as errors and flow control events encountered by the channel. See l2cap_channel_event.h.
Returns
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.
*  

◆ AcquireRfcommChannel()

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.

Parameters
[in]rx_multibuf_allocatorProvides the allocator the channel will use for its Rx buffers (for both queueing and returning to the client).
[in]connection_handleThe connection handle of the remote peer.
[in]rx_configParameters applying to reading packets. See rfcomm_channel.h for details.
[in]tx_configParameters applying to writing packets. See rfcomm_channel.h for details.
[in]channel_numberRFCOMM channel number to use.
[in]payload_from_controller_fnRead callback to be invoked on Rx frames.
[in]event_fnHandle asynchronous events such as errors encountered by the channel. See l2cap_channel_common.h.
Returns
embed:rst:leading-asterisk
 
* 
*  .. pw-status-codes::
*   INVALID_ARGUMENT: If arguments are invalid (check logs).
*   UNAVAILABLE: If channel could not be created.
*  

◆ GetNumFreeBrEdrAclPackets()

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.

◆ GetNumFreeLeAclPackets()

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.

◆ GetNumSimultaneousAclSendsSupported()

static constexpr size_t pw::bluetooth::proxy::ProxyHost::GetNumSimultaneousAclSendsSupported ( )
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.

◆ HandleH4HciFromController()

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:

  • L2CAP over ACL packets (specifically those addressed to channels managed by the proxy host, including signaling packets)

HCI_Command_Complete events (7.7.14) containing return parameters for these commands:

  • HCI_LE_Read_Buffer_Size [v1] command (7.8.2)
  • HCI_LE_Read_Buffer_Size [v2] command (7.8.2)

These HCI event packets:

  • HCI_Number_Of_Completed_Packets event (7.7.19)
  • HCI_Disconnection_Complete event (7.7.5)

Container is required to call this function synchronously (one packet at a time).

◆ HandleH4HciFromHost()

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).

◆ HasSendBrEdrAclCapability()

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.

◆ HasSendLeAclCapability()

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.

◆ RegisterL2capStatusDelegate()

void pw::bluetooth::proxy::ProxyHost::RegisterL2capStatusDelegate ( L2capStatusDelegate &  delegate)

Register for notifications of connection and disconnection for a particular L2cap service identified by its PSM.

Parameters
[in]delegateA delegate that will be notified when a successful L2cap connection is made on its PSM. Note: This must outlive the ProxyHost.

◆ Reset()

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.

◆ SendAdditionalRxCredits()

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.

Deprecated:
Use L2capCoc::SendAdditionalRxCredits instead.

◆ SendGattNotify() [1/2]

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.

Parameters
[in]connection_handleThe connection handle of the peer to notify. Maximum valid connection handle is 0x0EFF.
[in]attribute_handleThe attribute handle the notify should be sent on. Cannot be 0.
[in]attribute_valueThe client payload to be sent. Payload will be destroyed once its data has been used.
Returns
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).
*  
Deprecated:

◆ SendGattNotify() [2/2]

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.

Parameters
[in]connection_handleThe connection handle of the peer to notify. Maximum valid connection handle is 0x0EFF.
[in]attribute_handleThe attribute handle the notify should be sent on. Cannot be 0.
[in]attribute_valueThe data to be sent. Data will be copied before function completes.
Returns
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).
*  
Deprecated:

◆ UnregisterL2capStatusDelegate()

void pw::bluetooth::proxy::ProxyHost::UnregisterL2capStatusDelegate ( L2capStatusDelegate &  delegate)

Unregister a service delegate.

Parameters
[in]delegateThe delegate to unregister. Must have been previously registered.

The documentation for this class was generated from the following file: