diff --git a/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp b/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp index f6a9b9f3ae..f8a5bdb79b 100644 --- a/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp +++ b/src/platform/nrfconnect/wifi/NrfWiFiDriver.cpp @@ -124,12 +124,18 @@ void NrfWiFiDriver::OnNetworkStatusChanged(int connStatus) if (mpNetworkStatusChangeCallback) { WiFiManager::WiFiInfo wifiInfo; + WiFiManager::WiFiNetwork wantedWifiInfo; if (CHIP_NO_ERROR == WiFiManager::Instance().GetWiFiInfo(wifiInfo)) { mpNetworkStatusChangeCallback->OnNetworkingStatusChange(status, - MakeOptional(ByteSpan(wifiInfo.mSsid, wifiInfo.mSsidLen)), - connStatus ? MakeOptional(connStatus) : NullOptional); + MakeOptional(ByteSpan(wifiInfo.mSsid, wifiInfo.mSsidLen)), + connStatus ? MakeOptional(connStatus) : NullOptional); + } + else if (CHIP_NO_ERROR == WiFiManager::Instance().GetWantedNetwork(wantedWifiInfo)) + { + mpNetworkStatusChangeCallback->OnNetworkingStatusChange(status, MakeOptional(wantedWifiInfo.GetSsidSpan()), + connStatus ? MakeOptional(connStatus) : NullOptional); } } @@ -258,8 +264,7 @@ void NrfWiFiDriver::LoadFromStorage() void NrfWiFiDriver::OnScanWiFiNetworkDone(const wifi_status & status) { VerifyOrReturn(mScanCallback != nullptr); - mScanCallback->OnFinished(status.status ? Status::kUnknownError : Status::kSuccess, - CharSpan(), &mScanResponseIterator); + mScanCallback->OnFinished(status.status ? Status::kUnknownError : Status::kSuccess, CharSpan(), &mScanResponseIterator); mScanCallback = nullptr; } diff --git a/src/platform/nrfconnect/wifi/WiFiManager.cpp b/src/platform/nrfconnect/wifi/WiFiManager.cpp index ce17308bf4..a19bc31926 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.cpp +++ b/src/platform/nrfconnect/wifi/WiFiManager.cpp @@ -210,8 +210,7 @@ CHIP_ERROR WiFiManager::Connect(const ByteSpan & ssid, const ByteSpan & credenti { ChipLogDetail(DeviceLayer, "Connecting to WiFi network: %*s", ssid.size(), ssid.data()); - mHandling.mOnConnectionDone = handling.mOnConnectionDone; - mHandling.mConnectionTimeout = handling.mConnectionTimeout; + mHandling = handling; mWiFiState = WIFI_STATE_ASSOCIATING; @@ -278,6 +277,22 @@ CHIP_ERROR WiFiManager::GetWiFiInfo(WiFiInfo & info) const return CHIP_ERROR_INTERNAL; } +CHIP_ERROR WiFiManager::GetWantedNetwork(WiFiNetwork & info) const +{ + + if (mWantedNetwork.IsConfigured()) + { + info.ssidLen = mWantedNetwork.ssidLen; + info.passLen = mWantedNetwork.passLen; + memcpy(info.ssid, mWantedNetwork.ssid, mWantedNetwork.ssidLen); + memcpy(info.pass, mWantedNetwork.pass, mWantedNetwork.passLen); + + return CHIP_NO_ERROR; + } + + return CHIP_ERROR_INTERNAL; +} + CHIP_ERROR WiFiManager::GetNetworkStatistics(NetworkStatistics & stats) const { net_stats_wifi data{}; @@ -420,8 +435,8 @@ void WiFiManager::ConnectHandler(Platform::UniquePtr data) { CHIP_ERROR err = SystemLayer().ScheduleLambda([capturedData = data.get()] { Platform::UniquePtr safePtr(capturedData); - uint8_t * rawData = safePtr.get(); - const wifi_status * status = reinterpret_cast(rawData); + uint8_t * rawData = safePtr.get(); + const wifi_status * status = reinterpret_cast(rawData); if (status->status) { diff --git a/src/platform/nrfconnect/wifi/WiFiManager.h b/src/platform/nrfconnect/wifi/WiFiManager.h index 9ddb5dea27..a918be1ac7 100644 --- a/src/platform/nrfconnect/wifi/WiFiManager.h +++ b/src/platform/nrfconnect/wifi/WiFiManager.h @@ -174,6 +174,7 @@ class WiFiManager CHIP_ERROR ClearStationProvisioningData(); CHIP_ERROR Disconnect(); CHIP_ERROR GetWiFiInfo(WiFiInfo & info) const; + CHIP_ERROR GetWantedNetwork(WiFiNetwork & info) const; CHIP_ERROR GetNetworkStatistics(NetworkStatistics & stats) const; void AbortConnectionRecovery(); CHIP_ERROR SetLowPowerMode(bool onoff);