13#ifdef USE_BLUETOOTH_PROXY_CONNECTIONS
43 backend->set_listener(
this);
70 if (this->
state_ == ClientState::DISCONNECTING && this->
backend_->cancel_gatt_disconnect()) {
71 this->
state_ = ClientState::CONNECTING;
93 this->
backend_->set_connection_type(ct);
186 if constexpr (
requires { backend->stream_service_batch(*
this); }) {
187 backend->stream_service_batch(*
this);
224 uint16_t
mtu_{ble_device_base::DEFAULT_ATT_MTU};
243 static_assert(
static_cast<uint8_t
>(ClientState::ESTABLISHED) < (1 << 3),
"state_ bitfield too narrow");
244 static_assert(
static_cast<uint8_t
>(ConnectionType::V3_WITHOUT_CACHE) < (1 << 2),
245 "connection_type_ bitfield too narrow");
249 static_assert(SERVICES_DONE_RETRY_LIMIT < (1 << 5),
"counter bitfield too narrow");
263 static_assert(PENDING_ACK_RETRY_LIMIT <= 0xFF,
"retry counter too narrow");
269static_assert(
sizeof(
void *) != 4 ||
sizeof(BluetoothConnection) <= 56,
270 "BluetoothConnection layout regressed on a 32-bit target");
The event surface a backend delivers completions through - the one place with genuine runtime polymor...
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 on_read_result(uint16_t handle, const uint8_t *data, uint16_t len, int error) override
void initiate_connection(uint8_t address_type)
Start connecting with the API address type (BLE_ADDR_TYPE_* code space).
void latch_pending_ack_(PendingAck kind, uint16_t handle, conn_err_t error=0)
Latch a refused reply for the proxy drain.
void on_service_discovery_done(int error) override
conn_err_t write_descriptor(uint16_t handle, const uint8_t *data, size_t length, bool response)
void reset_connection_(conn_err_t reason)
uint64_t get_address() const
bool connected_reply_owed_
An owed connected=true reply; the proxy's paced drain re-offers it.
ConnectionType connection_type_
void on_pairing_result(int status) override
bool has_gatt_services() const
bool has_pending_ack_() const
void set_connection_type(ConnectionType ct)
const char * address_str() const
uint16_t pending_ack_handle_
void supersede_pending_ack_(uint16_t handle, PendingAck kind)
Drop an owed reply this re-ask makes stale.
void latch_pending_error_(conn_err_t err)
First cause wins: a later, less specific error must not overwrite it.
void abort_service_stream(conn_err_t err)
Streamer abort: latch the GATT cause, park the cursor, tear down.
void age_pending_ack_()
Advance the retry budget and abandon at the limit, without sending.
void set_backend(ble_device_base::BLEGattConnection *backend)
Wire the platform backend. Called from codegen before setup.
void send_gatt_error_(uint16_t handle, conn_err_t error)
Report a rejected request.
conn_err_t check_connected_op_(const char *action, const char *type) const
void age_services_done_()
Advance the retry budget and abandon at the limit, without sending.
void process_pending_services()
Stream any pending service-discovery batch (proxy loop; the backend owns the disconnect safety timer)...
uint8_t services_done_retries_
void log_gatt_operation_error_(const char *operation, uint16_t handle, int status)
void on_write_result(uint16_t handle, int error) override
void set_state(ClientState st)
bool batch_stalled_
Set while a refused batch is retrying, so only the first one warns.
conn_err_t pending_error_
void send_service_for_discovery_()
void flush_pending_ack_()
Re-offer the owed reply; clears on success, stays owed on a refusal.
void on_notify_state(uint16_t handle, bool enabled, int error) override
bool cancel_teardown()
A connect request racing a scheduled teardown: true when the backend had not started closing - the in...
uint8_t get_connection_index() const
void stream_pending_(Backend *backend)
ClientState state() const
void set_address(uint64_t address)
conn_err_t notify_characteristic(uint16_t handle, bool enable)
void on_connection_state(bool connected, uint16_t mtu, int error) override
void send_services_done_()
Send services-done and settle the cursor: DONE when it lands (or no subscriber), SERVICES_DONE_PENDIN...
conn_err_t pending_ack_error_
void park_service_stream_()
Park the stream without services-done and free any held table: an interrupted stream must never be de...
ble_device_base::BLEGattConnection * backend_
bluetooth_proxy::BluetoothProxy * proxy_
uint8_t connection_index_
void flush_owed_replies_()
Re-offer everything this slot owes.
void note_batch_stalled_()
Warn on the stall's leading edge only.
char address_str_[MAC_ADDRESS_PRETTY_BUFFER_SIZE]
conn_err_t read_descriptor(uint16_t handle)
conn_err_t write_characteristic(uint16_t handle, const uint8_t *data, size_t length, bool response)
void on_notify_data(uint16_t handle, const uint8_t *data, uint16_t len) override
bool services_discovered_
conn_err_t read_characteristic(uint16_t handle)
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 clear_pending_ack_()
void send_connected_reply_()
Send the connected=true reply, latching it if the API refuses.
conn_err_t update_connection_params(uint16_t min_interval, uint16_t max_interval, uint16_t latency, uint16_t timeout)
uint8_t pending_ack_retries_
void clear_owed_flags_()
Drop everything this slot owes, in one write to the shared tail byte.
ESPHOME_BLE_GATT_CONNECTION_TYPE BLEGattConnection
PendingAck
A refused GATT reply owed to the current subscriber.
spi_device_handle_t handle