ESPHome 2026.11.0b6
Loading...
Searching...
No Matches
bluedroid_bond_keys.c
Go to the documentation of this file.
1// Linker wraps that keep a bonded device's keys when it re-encrypts without pairing again (ESP-IDF 5.5.6, 6.1.1).
2// Same guard as espressif/esp-idf#19322; drop once ESPHome uses an ESP-IDF release that contains it.
3// C, because Bluedroid's btm_ble_int.h does not close its extern "C" block.
4
5// Compiled only with Bluedroid's private headers (bluedroid_headers_cmake); static analysis skips it
6#ifdef USE_ESP32_BLE_BLUEDROID_HEADERS
7
8#include <stdbool.h>
9#include <stddef.h>
10
11#include "btm_int.h"
12#include "smp_int.h"
13
14// The device record whose keys smp_check_auth_req() must keep, or NULL
15static tBTM_SEC_DEV_REC *keep_keys_of = NULL;
16
17void __real_smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data);
18void __real_btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC *p_dev_rec);
19
20// Runs on the Bluetooth host task. Encryption that succeeded without a Pairing Request or Response reused the bond.
21void __wrap_smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data) {
22 const bool reused_bond = *(UINT8 *) p_data == 1 && !(p_cb->flags & SMP_PAIR_FLAG_ENC_AFTER_PAIR);
23 // The same lookup as smp_check_auth_req(): it also matches a pseudo or resolvable private address
24 keep_keys_of = reused_bond ? btm_find_dev(p_cb->pairing_bda) : NULL;
25 __real_smp_check_auth_req(p_cb, p_data);
26 keep_keys_of = NULL;
27}
28
29void __wrap_btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC *p_dev_rec) {
30 // Only the first clear, the one the upstream guard skips; later callers are not affected
31 if (keep_keys_of != NULL && p_dev_rec == keep_keys_of) {
32 keep_keys_of = NULL;
33 return;
34 }
36}
37
38#endif // USE_ESP32_BLE_BLUEDROID_HEADERS
void __real_btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC *p_dev_rec)
void __wrap_smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)
void __wrap_btm_sec_clear_ble_keys(tBTM_SEC_DEV_REC *p_dev_rec)
void __real_smp_check_auth_req(tSMP_CB *p_cb, tSMP_INT_DATA *p_data)