Buffered HCI Logging API

src/hci_dump_buffered.h : Buffer HCI packets in memory and flush them later via another hci_dump_t implementation.

Using this wrapper can be helpful in debugging issues that magically disappear when HCI logging is turned on.

By logging first into a buffer, the critical steps should run mostly as before but still provide an HCI log of the issue afterwards.

Example Usage with 10kB buffer and flush after 100 ms inactivity

Existing code:

const hci_dump_t * hci_dump_impl = hci_dump_embedded_stdout_get_instance(); hci_dump_init(hci_dump_impl);

Buffered version:

static byte_t hci_dump_buffer[10000] = {0};

const hci_dump_t * hci_dump_impl = hci_dump_embedded_stdout_get_instance(); const hci_dump_t * hci_dump_buffered = hci_dump_buffered_init(hci_dump_impl, hci_dump_buffer, sizeof(hci_dump_buffer), 100); hci_dump_init(hci_dump_buffered);

/**
 * @brief Configure buffered HCI dump instance
 * @param hci_dump_impl target hci_dump_t implementation used during flush
 * @param buffer caller-provided buffer used to store packet metadata and payload
 * @param buffer_size size of buffer in bytes
 * @param flush_timeout_ms maximum time in ms to keep buffered packets before flushing, 0 to disable timeout-based flushing
 *
 * @note If a single packet does not fit into the provided buffer, pending packets are flushed first and the packet is
 *       forwarded directly to hci_dump_impl.
 */
void hci_dump_buffered_init(const hci_dump_t * hci_dump_impl, uint8_t * buffer, uint32_t buffer_size, uint32_t flush_timeout_ms);

/**
 * @brief Flush buffered packets immediately
 */
void hci_dump_buffered_flush(void);

/**
 * @brief Get buffered HCI dump instance
 * @return hci_dump_impl
 */
const hci_dump_t * hci_dump_buffered_get_instance(void);