From 16684525589120960d73a77756ee5925e3eacb96 Mon Sep 17 00:00:00 2001 From: Wang Qixiang <43193572+wqx6@users.noreply.github.com> Date: Fri, 16 Jun 2023 22:13:30 +0800 Subject: [PATCH] ESP32: Do not read the ap record if esp_wifi_scan_start() is not called by NetworkCommissioningDriver (#27161) --- .../ESP32/NetworkCommissioningDriver.cpp | 32 ++++++++++--------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/src/platform/ESP32/NetworkCommissioningDriver.cpp b/src/platform/ESP32/NetworkCommissioningDriver.cpp index 148704eeeeef2a..7e080f5246256e 100644 --- a/src/platform/ESP32/NetworkCommissioningDriver.cpp +++ b/src/platform/ESP32/NetworkCommissioningDriver.cpp @@ -297,27 +297,26 @@ CHIP_ERROR ESPWiFiDriver::StartScanWiFiNetworks(ByteSpan ssid) void ESPWiFiDriver::OnScanWiFiNetworkDone() { + if (!mpScanCallback) + { + ChipLogProgress(DeviceLayer, "No scan callback"); + return; + } uint16_t ap_number; esp_wifi_scan_get_ap_num(&ap_number); if (!ap_number) { ChipLogProgress(DeviceLayer, "No AP found"); - if (mpScanCallback != nullptr) - { - mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), nullptr); - mpScanCallback = nullptr; - } + mpScanCallback->OnFinished(Status::kSuccess, CharSpan(), nullptr); + mpScanCallback = nullptr; return; } std::unique_ptr ap_buffer_ptr(new wifi_ap_record_t[ap_number]); if (ap_buffer_ptr == NULL) { ChipLogError(DeviceLayer, "can't malloc memory for ap_list_buffer"); - if (mpScanCallback) - { - mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); - mpScanCallback = nullptr; - } + mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); + mpScanCallback = nullptr; return; } wifi_ap_record_t * ap_list_buffer = ap_buffer_ptr.get(); @@ -339,16 +338,19 @@ void ESPWiFiDriver::OnScanWiFiNetworkDone() { ap_buffer_ptr.release(); } - } - else - { - ChipLogError(DeviceLayer, "can't get ap_records "); - if (mpScanCallback) + else { + ChipLogError(DeviceLayer, "can't schedule the scan result processing"); mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); mpScanCallback = nullptr; } } + else + { + ChipLogError(DeviceLayer, "can't get ap_records "); + mpScanCallback->OnFinished(Status::kUnknownError, CharSpan(), nullptr); + mpScanCallback = nullptr; + } } void ESPWiFiDriver::OnNetworkStatusChange()