[wifi] Connect LN882x to the BSSID asked for (#20174)

This commit is contained in:
J. Nick Koston
2026-10-05 10:55:11 -05:00
committed by GitHub
parent f334b9ea11
commit bb8c23805a
2 changed files with 15 additions and 0 deletions
+4
View File
@@ -734,6 +734,10 @@ async def to_code(config):
if not config[CONF_ENABLE_ON_BOOT]:
cg.add(var.set_enable_on_boot(False))
# LN882x: hand the SDK the BSSID LibreTiny 1.13 drops (see wifi_component_libretiny.cpp); remove once fixed upstream.
if CORE.is_ln882x:
cg.add_build_flag("-Wl,--wrap=wifi_sta_connect")
# post_connect_roaming defaults to true in C++ - disable if user disabled it
# or if 802.11k/v is enabled (driver handles roaming natively)
if (
@@ -31,6 +31,17 @@ extern "C" {
#ifdef USE_LN882X
#include <WiFiPrivate.h>
#undef DATA // clashes with setup_priority::DATA
// LibreTiny 1.13's LN882H reconnect() gives the SDK a NULL bssid; pass on the requested one. Remove once it passes
// info.bssid. Safe without a BSSID: begin() frees sta.bssid (resetNetworkInfo), so it stays NULL.
// NOLINTBEGIN(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
// Names are mandated by the --wrap linker mechanism.
extern "C" int __real_wifi_sta_connect(wifi_sta_connect_t *connect, wifi_scan_cfg_t *scan_cfg);
extern "C" int __wrap_wifi_sta_connect(wifi_sta_connect_t *connect, wifi_scan_cfg_t *scan_cfg) {
if (connect->bssid == nullptr)
connect->bssid = static_cast<WiFiData *>(WiFi.data)->sta.bssid;
return __real_wifi_sta_connect(connect, scan_cfg);
}
// NOLINTEND(bugprone-reserved-identifier,cert-dcl37-c,cert-dcl51-cpp,readability-identifier-naming)
#endif
#include "esphome/core/application.h"