ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
bluedroid_hex_wraps.cpp
Go to the documentation of this file.
1// Linker wraps for the only two sscanf callers in Bluedroid, so the C library's scanf engine is not linked
2// (~16 KB with newlib, ~4 KB with picolibc).
3// Same parsing as espressif/esp-idf#19235; drop once ESPHome uses an ESP-IDF release that contains it.
4
6
7#if defined(USE_ESP_IDF) && defined(USE_ESP32_BLE_BLUEDROID_HEX_WRAPS)
8
9#include "bluedroid_hex.h"
10
11// Set with Bluedroid's private include dirs for this file only (native ESP-IDF toolchain).
12// The headers only feed the drift checks below. On Windows the include dirs come through with backslashes,
13// which GCC reads as escapes in the Ninja response file, so the checks are skipped where they are unreachable.
14#if defined(USE_ESP32_BLE_BLUEDROID_HEADERS) && __has_include("btc/btc_config.h")
15#define ESPHOME_BLUEDROID_DRIFT_CHECKS
16#include <type_traits>
17// stack/bt_types.h redefines PACKED from esphome/core/helpers.h; nothing below uses it.
18#undef PACKED
19extern "C" {
20#include "btc/btc_config.h"
21#include "device/bdaddr.h"
22#include "stack/btm_api.h"
23}
24#endif
25
26namespace esphome::esp32_ble {}
27
28// NOLINTBEGIN(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
29extern "C" {
30
31bool btc_config_get_str(const char *section, const char *key, char *value, int *size_bytes);
32
33bool __wrap_btc_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length) {
35}
36
37// bt_bdaddr_t is a struct holding uint8_t address[6]
38bool __wrap_string_to_bdaddr(const char *string, uint8_t *addr) {
39 return esphome::esp32_ble::parse_bdaddr(string, addr);
40}
41
42} // extern "C"
43// NOLINTEND(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
44
45#ifdef ESPHOME_BLUEDROID_DRIFT_CHECKS
46// ESP-IDF drift checks: if one fails, re-check the wraps against espressif/esp-idf#19235 and Bluedroid's sources.
47static_assert(std::is_same_v<decltype(&btc_config_get_bin), decltype(&__wrap_btc_config_get_bin)>,
48 "btc_config_get_bin signature changed");
49static_assert(std::is_same_v<decltype(&btc_config_get_str), bool (*)(const char *, const char *, char *, int *)>,
50 "btc_config_get_str signature changed");
51static_assert(std::is_same_v<decltype(&string_to_bdaddr), bool (*)(const char *, bt_bdaddr_t *)>,
52 "string_to_bdaddr signature changed");
53static_assert(sizeof(bt_bdaddr_t) == 6 && sizeof(bt_bdaddr_t::address) == 6,
54 "bt_bdaddr_t is no longer uint8_t address[6]");
55static_assert(sizeof(tBTM_LE_KEY_VALUE) <= esphome::esp32_ble::CONFIG_BIN_STACK_BYTES,
56 "Bluetooth LE keys outgrew the stack buffer of config_get_bin");
57#endif
58
59#endif // USE_ESP_IDF && USE_ESP32_BLE_BLUEDROID_HEX_WRAPS
bool __wrap_string_to_bdaddr(const char *string, uint8_t *addr)
bool __wrap_btc_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length)
bool btc_config_get_str(const char *section, const char *key, char *value, int *size_bytes)
const char * key
bool parse_bdaddr(const char *str, uint8_t *addr)
Parse "xx:xx:xx:xx:xx:xx" as Bluedroid's string_to_bdaddr does: one or two hex digits per byte,...
bool config_get_bin(GetStr get_str, const char *section, const char *key, uint8_t *value, size_t *length)
btc_config_get_bin on top of btc_config_get_str, passed as get_str, which strlcpy's the stored string...
uint16_t length
Definition tt21100.cpp:0