Skip to content

Commit

Permalink
ESP32: Do not read the ap record if esp_wifi_scan_start() is not call…
Browse files Browse the repository at this point in the history
…ed by NetworkCommissioningDriver (#27161)
  • Loading branch information
wqx6 authored and pull[bot] committed Nov 14, 2023
1 parent 533f7d0 commit 1410862
Showing 1 changed file with 17 additions and 15 deletions.
32 changes: 17 additions & 15 deletions src/platform/ESP32/NetworkCommissioningDriver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<wifi_ap_record_t[]> 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();
Expand All @@ -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()
Expand Down

0 comments on commit 1410862

Please sign in to comment.