ESPHome 2026.11.0-dev
Loading...
Searching...
No Matches
bluedroid_stubs.cpp
Go to the documentation of this file.
1/*
2 * Bluedroid queues outgoing BLE connections as raw link block pointers and does
3 * not drop them when the block is released, so btm_send_pending_direct_conn()
4 * can start a connect on a released block and l2c_link_timeout() later crashes
5 * on its null timer parameter. Mirrors espressif/esp-idf@82e71c1767; codegen
6 * only enables it for releases without that commit.
7 */
8
10
11#ifdef USE_ESP32_BLE_TRACKER_DIRECT_CONN_GUARD
12
13#include <esp_idf_version.h>
14#include <cstdint>
15#include "esphome/core/log.h"
16
18ESPHOME_LOG_TAG(TAG, "esp32_ble_tracker");
19} // namespace esphome::esp32_ble_tracker
20
21static_assert(ESP_IDF_VERSION < ESP_IDF_VERSION_VAL(6, 2, 0),
22 "ESP-IDF 6.2 and later have the fix, this guard should not be enabled (esphome/esphome#19373)");
23
24// NOLINTBEGIN(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
25extern "C" {
26
28void l2cu_release_lcb(void *p_lcb);
29
31 // in_use is the first member of the private tL2C_LCB (checked ESP-IDF 5.0 to 6.1)
32 const auto *in_use = static_cast<const uint8_t *>(p_lcb);
33 if (p_lcb == nullptr || *in_use == 0) {
34 ESP_LOGW(esphome::esp32_ble_tracker::TAG, "Dropped queued connect on a released link block");
35 return false;
36 }
37 const bool started = __real_l2cble_init_direct_conn(p_lcb);
38 // Every failure path releases the block except unknown device, also fixed upstream
39 if (!started && *in_use != 0) {
40 l2cu_release_lcb(p_lcb);
41 }
42 return started;
43}
44
45} // extern "C"
46// NOLINTEND(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
47
48#endif // USE_ESP32_BLE_TRACKER_DIRECT_CONN_GUARD
bool __real_l2cble_init_direct_conn(void *p_lcb)
void l2cu_release_lcb(void *p_lcb)
bool __wrap_l2cble_init_direct_conn(void *p_lcb)
ESPHOME_LOG_TAG(TAG, "esp32_ble")