pw_bluetooth_proxy#

Lightweight proxy for augmenting Bluetooth functionality

Unstable C++17

The pw_bluetooth_proxy module provides a lightweight proxy host that can be placed between a Bluetooth host and Bluetooth controller to add additional functionality or inspection. All without modifying the host or the controller.

An example use case could be offloading some functionality from a main host located on the application processor to instead be handled on the MCU (to reduce power usage).

The proxy acts as a proxy of all host controller interface (HCI) packets between the host and the controller.

pw::bluetooth::proxy::ProxyHost acts as the main coordinator for proxy functionality.

#include "pw_bluetooth_proxy/proxy_host.h"

  // Container creates ProxyHost .
  ProxyHost proxy = ProxyHost(std::move(container_send_to_host_fn),
                              std::move(container_send_to_controller_fn),
                              2);

  // Container passes H4 packets from host through proxy. Proxy will in turn
  // call the container-provided `container_send_to_controller_fn` to pass them
  // on to the controller. Some packets may be modified, added, or removed.
  proxy.HandleH4HciFromHost(std::move(h4_packet_from_host));

  // Container passes H4 packets from controller through proxy. Proxy will in
  // turn call the container-provided `container_send_to_host_fn` to pass them
  // on to the controller. Some packets may be modified, added, or removed.
  proxy.HandleH4HciFromController(std::move(h4_packet_from_controller));
Get Started

How to set up in your build system

API Reference

Reference information about the API

Roadmap

Upcoming plans

Code size analysis

Understand code footprint and savings potential

Get started#

  1. Add Emboss to your project as described in Emboss.

Bazel isn’t supported yet.

2. Then add $dir_pw_bluetooth_proxy to the deps list in your pw_executable() build target:

pw_executable("...") {
  # ...
  deps = [
    # ...
    "$dir_pw_bluetooth_proxy",
    # ...
  ]
}

2. Then add pw_bluetooth_proxy to the DEPS list in your cmake target:

API reference#

pw::bluetooth::proxy::ProxyHost#

class ProxyHost#

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

Public 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,
)#

Creates an ProxyHost that will process HCI packets.

Parameters:
  • send_to_host_fn[in] Callback that will be called when proxy wants to send HCI packet towards the host.

  • send_to_controller_fn[in] - Callback that will be called when proxy wants to send HCI packet towards the controller.

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

void 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 events passed through it. It will pass on all other packets, so containers can choose to just pass all from-controller packets through it.

  • 7.7.14 Command Complete event (7.8.2 LE Read Buffer Size [v1] command)

  • 7.7.14 Command Complete event (7.8.2 LE Read Buffer Size [v2] command)

  • 7.7.19 Number Of Completed Packets event (v1.1)

  • 7.7.5 Disconnection Complete event (v1.1)

void Reset()#

Called by container to notify proxy that the Bluetooth system is being reset, so the proxy can reset its internal state. 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 SendGattNotify(uint16_t connection_handle, uint16_t attribute_handle, pw::span<const uint8_t> attribute_value)#

Send a GATT Notify to the indicated connection.

Parameters:
  • connection_handle[in] The connection handle of the peer to notify

  • attribute_handle[in] The attribute handle the notify should be sent on.

  • attribute_value[in] The data to be sent. Data will be copied before function completes.

Returns:

Code

Description

OK

If notify was successfully queued for send. UNAVAILABLE: If CHRE doesn’t have resources to queue the send at this time (transient error). UNIMPLEMENTED: If send is not supported by the current implementation. INVALID_ARGUMENT: If arguments are invalid.

bool HasSendAclCapability() const#

Indicates whether the proxy has the capability of sending 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.

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

Public Static Functions

static inline constexpr size_t GetNumSimultaneousAclSendsSupported()#

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.

Code size analysis#

Delta when constructing a proxy and just sending packets through.

Label

Segment

Delta

Emboss not configured.

(ALL)

0

Roadmap#

  • ACL flow control

  • Sending GATT notifications

  • CMake support

  • Receiving GATT notifications

  • Taking ownership of a L2CAP channel

  • Bazel support

  • And more…