|
ESPHome 2026.8.0b4
|
#include <bluetooth_connection_hub.h>
Public Member Functions | |
| void | set_backend (ble_device_base::BLEGattConnection *backend) |
| Wire the platform backend. Called from codegen before setup. | |
| conn_err_t | read_characteristic (uint16_t handle) |
| conn_err_t | write_characteristic (uint16_t handle, const uint8_t *data, size_t length, bool response) |
| conn_err_t | read_descriptor (uint16_t handle) |
| conn_err_t | write_descriptor (uint16_t handle, const uint8_t *data, size_t length, bool response) |
| conn_err_t | notify_characteristic (uint16_t handle, bool enable) |
| conn_err_t | update_connection_params (uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t timeout) |
| void | abort_service_stream (conn_err_t err) |
| Streamer abort: latch the GATT cause, park the cursor, tear down. | |
| void | initiate_connection (uint8_t address_type) |
| Start connecting with the API address type (BLE_ADDR_TYPE_* code space). | |
| void | disconnect () |
| bool | cancel_teardown () |
| A connect request racing a scheduled teardown: true when the backend had not started closing - the in-flight open resumes and reports connected. | |
| bool | is_paired () const |
| void | set_unpaired () |
| conn_err_t | pair () |
| void | set_address (uint64_t address) |
| uint64_t | get_address () const |
| const char * | address_str () const |
| uint8_t | get_connection_index () const |
| ClientState | state () const |
| void | set_state (ClientState st) |
| bool | connected () const |
| void | set_connection_type (ConnectionType ct) |
| bool | has_gatt_services () const |
| void | process_pending_services () |
| Stream any pending service-discovery batch (proxy loop; the backend owns the disconnect safety timer). | |
| void | on_connection_state (bool connected, uint16_t mtu, int error) override |
| void | on_service_discovery_done (int error) override |
| void | on_read_result (uint16_t handle, const uint8_t *data, uint16_t len, int error) override |
| void | on_write_result (uint16_t handle, int error) override |
| void | on_notify_state (uint16_t handle, bool enabled, int error) override |
| void | on_notify_data (uint16_t handle, const uint8_t *data, uint16_t len) override |
| void | on_pairing_result (int status) override |
Public Member Functions inherited from esphome::ble_device_base::GattClientListener | |
Protected Member Functions | |
| void | latch_pending_error_ (conn_err_t err) |
| First cause wins: a later, less specific error must not overwrite it. | |
| void | latch_pending_ack_ (PendingAck kind, uint16_t handle, conn_err_t error=0) |
| Latch a refused reply for the proxy drain. | |
| void | clear_pending_ack_ () |
| void | supersede_pending_ack_ (uint16_t handle, PendingAck kind) |
| Drop an owed reply this re-ask makes stale. | |
| bool | has_pending_ack_ () const |
| void | note_batch_stalled_ () |
| Warn on the stall's leading edge only. | |
| void | send_connected_reply_ () |
| Send the connected=true reply, latching it if the API refuses. | |
| void | flush_owed_replies_ () |
| Re-offer everything this slot owes. | |
| void | clear_owed_flags_ () |
| Drop everything this slot owes, in one write to the shared tail byte. | |
| bool | try_send_ack_ (PendingAck kind, uint16_t handle, conn_err_t error) |
| Sole construction site for these replies, shared by send and retry. | |
| void | send_ack_ (PendingAck kind, uint16_t handle, conn_err_t error=0) |
| First attempt: send, and latch it for the drain if the API refuses. | |
| void | send_gatt_error_ (uint16_t handle, conn_err_t error) |
| Report a rejected request. | |
| void | flush_pending_ack_ () |
| Re-offer the owed reply; clears on success, stays owed on a refusal. | |
| void | age_pending_ack_ () |
| Advance the retry budget and abandon at the limit, without sending. | |
| template<typename Backend > | |
| void | stream_pending_ (Backend *backend) |
| void | park_service_stream_ () |
| Park the stream without services-done and free any held table: an interrupted stream must never be declared complete (the client's timeout arbitrates), and an owed done is dropped with it. | |
| void | send_service_for_discovery_ () |
| void | send_services_done_ () |
| Send services-done and settle the cursor: DONE when it lands (or no subscriber), SERVICES_DONE_PENDING on a refused frame (proxy drain retries). | |
| void | age_services_done_ () |
| Advance the retry budget and abandon at the limit, without sending. | |
| void | reset_connection_ (conn_err_t reason) |
| conn_err_t | check_connected_op_ (const char *action, const char *type) const |
| void | log_gatt_operation_error_ (const char *operation, uint16_t handle, int status) |
Protected Attributes | |
| bluetooth_proxy::BluetoothProxy * | proxy_ {nullptr} |
| ble_device_base::BLEGattConnection * | backend_ {nullptr} |
| int16_t | send_service_ {INIT_SENDING_SERVICES} |
| uint16_t | mtu_ {ble_device_base::DEFAULT_ATT_MTU} |
| uint64_t | address_ {0} |
| conn_err_t | pending_error_ {0} |
| conn_err_t | pending_ack_error_ {0} |
| char | address_str_ [MAC_ADDRESS_PRETTY_BUFFER_SIZE] {} |
| uint16_t | pending_ack_handle_ {0} |
| ClientState | state_: 3 {ClientState::IDLE} |
| uint8_t | services_done_retries_: 5 {0} |
| uint8_t | connection_index_: 4 {0} |
| ConnectionType | connection_type_: 2 {ConnectionType::V1} |
| bool | paired_: 1 {false} |
| bool | services_discovered_: 1 {false} |
| PendingAck | pending_ack_: 2 {PendingAck::PENDING_ACK_NONE} |
| bool | batch_stalled_: 1 {false} |
| Set while a refused batch is retrying, so only the first one warns. | |
| bool | connected_reply_owed_: 1 {false} |
| An owed connected=true reply; the proxy's paced drain re-offers it. | |
| uint8_t | pending_ack_retries_ {0} |
Definition at line 38 of file bluetooth_connection_hub.h.
|
inline |
Streamer abort: latch the GATT cause, park the cursor, tear down.
Definition at line 55 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 82 of file bluetooth_connection_hub.h.
|
protected |
Advance the retry budget and abandon at the limit, without sending.
Definition at line 299 of file bluetooth_connection_hub.cpp.
|
protected |
Advance the retry budget and abandon at the limit, without sending.
Definition at line 454 of file bluetooth_connection_hub.cpp.
|
inline |
A connect request racing a scheduled teardown: true when the backend had not started closing - the in-flight open resumes and reports connected.
False once the teardown owns the link.
Definition at line 69 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 375 of file bluetooth_connection_hub.cpp.
|
inlineprotected |
Drop everything this slot owes, in one write to the shared tail byte.
Definition at line 163 of file bluetooth_connection_hub.h.
|
inlineprotected |
Definition at line 139 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 87 of file bluetooth_connection_hub.h.
| void esphome::bluetooth_connection::BluetoothConnection::disconnect | ( | ) |
Definition at line 63 of file bluetooth_connection_hub.cpp.
|
protected |
Re-offer everything this slot owes.
One entry point so the proxy drain does not have to know which latches exist.
Definition at line 190 of file bluetooth_connection_hub.cpp.
|
protected |
Re-offer the owed reply; clears on success, stays owed on a refusal.
Definition at line 289 of file bluetooth_connection_hub.cpp.
|
inline |
Definition at line 81 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 83 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 99 of file bluetooth_connection_hub.h.
|
inlineprotected |
Definition at line 149 of file bluetooth_connection_hub.h.
| void esphome::bluetooth_connection::BluetoothConnection::initiate_connection | ( | uint8_t | address_type | ) |
Start connecting with the API address type (BLE_ADDR_TYPE_* code space).
Failures report through the same reset path a failed open takes.
Definition at line 52 of file bluetooth_connection_hub.cpp.
|
inline |
Definition at line 76 of file bluetooth_connection_hub.h.
|
inlineprotected |
Latch a refused reply for the proxy drain.
One slot per connection, newest wins: a GATT client works one request at a time, and a discarded reply falls back to the timeout it would have hit anyway.
Definition at line 133 of file bluetooth_connection_hub.h.
|
inlineprotected |
First cause wins: a later, less specific error must not overwrite it.
Definition at line 124 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 229 of file bluetooth_connection_hub.cpp.
|
protected |
Warn on the stall's leading edge only.
The batch is never lost (the caller rewinds the cursor), and a warning per attempt would add traffic to the connection already refusing frames. Both streamers route here.
Definition at line 234 of file bluetooth_connection_hub.cpp.
| conn_err_t esphome::bluetooth_connection::BluetoothConnection::notify_characteristic | ( | uint16_t | handle, |
| bool | enable ) |
Definition at line 420 of file bluetooth_connection_hub.cpp.
|
overridevirtual |
Reimplemented from esphome::ble_device_base::GattClientListener.
Definition at line 107 of file bluetooth_connection_hub.cpp.
|
overridevirtual |
Reimplemented from esphome::ble_device_base::GattClientListener.
Definition at line 355 of file bluetooth_connection_hub.cpp.
|
overridevirtual |
Reimplemented from esphome::ble_device_base::GattClientListener.
Definition at line 343 of file bluetooth_connection_hub.cpp.
|
overridevirtual |
Reimplemented from esphome::ble_device_base::GattClientListener.
Definition at line 81 of file bluetooth_connection_hub.cpp.
|
overridevirtual |
Reimplemented from esphome::ble_device_base::GattClientListener.
Definition at line 309 of file bluetooth_connection_hub.cpp.
|
overridevirtual |
Reimplemented from esphome::ble_device_base::GattClientListener.
Definition at line 173 of file bluetooth_connection_hub.cpp.
|
overridevirtual |
Reimplemented from esphome::ble_device_base::GattClientListener.
Definition at line 332 of file bluetooth_connection_hub.cpp.
|
inline |
Definition at line 78 of file bluetooth_connection_hub.h.
|
inlineprotected |
Park the stream without services-done and free any held table: an interrupted stream must never be declared complete (the client's timeout arbitrates), and an owed done is dropped with it.
Definition at line 195 of file bluetooth_connection_hub.h.
|
inline |
Stream any pending service-discovery batch (proxy loop; the backend owns the disconnect safety timer).
Definition at line 103 of file bluetooth_connection_hub.h.
| conn_err_t esphome::bluetooth_connection::BluetoothConnection::read_characteristic | ( | uint16_t | handle | ) |
Definition at line 384 of file bluetooth_connection_hub.cpp.
| conn_err_t esphome::bluetooth_connection::BluetoothConnection::read_descriptor | ( | uint16_t | handle | ) |
Definition at line 401 of file bluetooth_connection_hub.cpp.
|
protected |
Definition at line 91 of file bluetooth_connection_hub.cpp.
|
protected |
First attempt: send, and latch it for the drain if the API refuses.
Definition at line 274 of file bluetooth_connection_hub.cpp.
|
protected |
Send the connected=true reply, latching it if the API refuses.
Rebuilt from address_ and mtu_, so the latch is one bit; a dropped confirmation leaves the client timing out while this slot holds a live link. No retry bound: the slot's lifetime is the bound (teardown clears the flag).
Definition at line 216 of file bluetooth_connection_hub.cpp.
|
inlineprotected |
Report a rejected request.
Latched like a completion reply, so a refused frame does not strand the client for its whole timeout.
Definition at line 174 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 462 of file bluetooth_connection_hub.cpp.
|
protected |
Send services-done and settle the cursor: DONE when it lands (or no subscriber), SERVICES_DONE_PENDING on a refused frame (proxy drain retries).
Callers release the table first; the message needs only the address.
Definition at line 438 of file bluetooth_connection_hub.cpp.
| void esphome::bluetooth_connection::BluetoothConnection::set_address | ( | uint64_t | address | ) |
Definition at line 36 of file bluetooth_connection_hub.cpp.
|
inline |
Wire the platform backend. Called from codegen before setup.
Definition at line 41 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 88 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 86 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 77 of file bluetooth_connection_hub.h.
|
inline |
Definition at line 85 of file bluetooth_connection_hub.h.
|
inlineprotected |
Definition at line 185 of file bluetooth_connection_hub.h.
|
inlineprotected |
Drop an owed reply this re-ask makes stale.
Clients match futures on response type as well as handle, so an owed error (which resolves any op on the handle) is cleared by any re-ask, other kinds only by their own.
Definition at line 143 of file bluetooth_connection_hub.h.
|
protected |
Sole construction site for these replies, shared by send and retry.
Sole construction site, so a re-offer cannot drift from the original.
Definition at line 252 of file bluetooth_connection_hub.cpp.
| conn_err_t esphome::bluetooth_connection::BluetoothConnection::update_connection_params | ( | uint16_t | min_interval, |
| uint16_t | max_interval, | ||
| uint16_t | latency, | ||
| uint16_t | timeout ) |
Definition at line 429 of file bluetooth_connection_hub.cpp.
| conn_err_t esphome::bluetooth_connection::BluetoothConnection::write_characteristic | ( | uint16_t | handle, |
| const uint8_t * | data, | ||
| size_t | length, | ||
| bool | response ) |
Definition at line 392 of file bluetooth_connection_hub.cpp.
| conn_err_t esphome::bluetooth_connection::BluetoothConnection::write_descriptor | ( | uint16_t | handle, |
| const uint8_t * | data, | ||
| size_t | length, | ||
| bool | response ) |
Definition at line 411 of file bluetooth_connection_hub.cpp.
|
protected |
Definition at line 227 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 234 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 219 of file bluetooth_connection_hub.h.
|
protected |
Set while a refused batch is retrying, so only the first one warns.
Definition at line 258 of file bluetooth_connection_hub.h.
|
protected |
An owed connected=true reply; the proxy's paced drain re-offers it.
Definition at line 260 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 251 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 252 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 224 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 253 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 256 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 231 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 237 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 264 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 228 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 218 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 223 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 254 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 250 of file bluetooth_connection_hub.h.
|
protected |
Definition at line 248 of file bluetooth_connection_hub.h.