ESPHome 2026.12.0-dev
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, so they are skipped where the headers are unreachable.
13#if defined(USE_ESP32_BLE_BLUEDROID_HEADERS) && __has_include("btc/btc_config.h")
14#define ESPHOME_BLUEDROID_DRIFT_CHECKS
15#include <type_traits>
16// stack/bt_types.h redefines PACKED from esphome/core/helpers.h; nothing below uses it.
17#undef PACKED
18extern "C" {
19#include "btc/btc_config.h"
20#include "device/bdaddr.h"
21#include "stack/btm_api.h"
22}
23#endif
24
25namespace esphome::esp32_ble {}
26
27// NOLINTBEGIN(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
28extern "C" {
29
30bool btc_config_get_str(const char *section, const char *key, char *value, int *size_bytes);
31
32bool __wrap_btc_config_get_bin(const char *section, const char *key, uint8_t *value, size_t *length) {
34}
35
36// bt_bdaddr_t is a struct holding uint8_t address[6]
37bool __wrap_string_to_bdaddr(const char *string, uint8_t *addr) {
38 return esphome::esp32_ble::parse_bdaddr(string, addr);
39}
40
41} // extern "C"
42// NOLINTEND(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
43
44#ifdef ESPHOME_BLUEDROID_DRIFT_CHECKS
45// ESP-IDF drift checks: if one fails, re-check the wraps against espressif/esp-idf#19235 and Bluedroid's sources.
46static_assert(std::is_same_v<decltype(&btc_config_get_bin), decltype(&__wrap_btc_config_get_bin)>,
47 "btc_config_get_bin signature changed");
48static_assert(std::is_same_v<decltype(&btc_config_get_str), bool (*)(const char *, const char *, char *, int *)>,
49 "btc_config_get_str signature changed");
50static_assert(std::is_same_v<decltype(&string_to_bdaddr), bool (*)(const char *, bt_bdaddr_t *)>,
51 "string_to_bdaddr signature changed");
52static_assert(sizeof(bt_bdaddr_t) == 6 && sizeof(bt_bdaddr_t::address) == 6,
53 "bt_bdaddr_t is no longer uint8_t address[6]");
54static_assert(sizeof(tBTM_LE_KEY_VALUE) <= esphome::esp32_ble::CONFIG_BIN_STACK_BYTES,
55 "Bluetooth LE keys outgrew the stack buffer of config_get_bin");
56#endif
57
58#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