diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index 3b05fca8379973..422073e9ca0ec4 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -65,6 +65,9 @@ using namespace chip::Transport; using chip::Shell::Engine; #endif +static constexpr useconds_t kWifiStartCheckTime = 100*1000; // 100 ms +static constexpr uint8_t kWifiStartCheckAttempts = 5; + namespace { void EventHandler(const chip::DeviceLayer::ChipDeviceEvent * event, intptr_t arg) { @@ -80,6 +83,7 @@ int ChipLinuxAppInit(int argc, char ** argv) { CHIP_ERROR err = CHIP_NO_ERROR; chip::RendezvousInformationFlags rendezvousFlags = chip::RendezvousInformationFlag::kBLE; + int counter = 0; #ifdef CONFIG_RENDEZVOUS_MODE rendezvousFlags = static_cast(CONFIG_RENDEZVOUS_MODE); @@ -120,6 +124,16 @@ int ChipLinuxAppInit(int argc, char ** argv) if (LinuxDeviceOptions::GetInstance().mWiFi) { chip::DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement(); + while (chip::DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted() == false) + { + usleep(kWifiStartCheckTime); + counter++; + if (counter == kWifiStartCheckAttempts) + { + ChipLogError(NotSpecified, "Wi-Fi Management taking too long to start."); + break; + } + } } #endif // CHIP_DEVICE_CONFIG_ENABLE_WPA diff --git a/src/platform/Linux/ConnectivityManagerImpl.cpp b/src/platform/Linux/ConnectivityManagerImpl.cpp index a79fda4f5c0012..1e57cfebb6f73b 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.cpp +++ b/src/platform/Linux/ConnectivityManagerImpl.cpp @@ -633,6 +633,11 @@ void ConnectivityManagerImpl::StartWiFiManagement() kWpaSupplicantObjectPath, nullptr, _OnWpaProxyReady, nullptr); } +bool ConnectivityManagerImpl::IsWiFiManagementStarted() +{ + return mWpaSupplicant.state == GDBusWpaSupplicant::WPA_INTERFACE_CONNECTED; +} + void ConnectivityManagerImpl::DriveAPState() { CHIP_ERROR err = CHIP_NO_ERROR; diff --git a/src/platform/Linux/ConnectivityManagerImpl.h b/src/platform/Linux/ConnectivityManagerImpl.h index b850ad76c254e1..e2ef99d64b0438 100644 --- a/src/platform/Linux/ConnectivityManagerImpl.h +++ b/src/platform/Linux/ConnectivityManagerImpl.h @@ -108,6 +108,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager, #if CHIP_DEVICE_CONFIG_ENABLE_WPA void StartWiFiManagement(); + bool IsWiFiManagementStarted(); #endif private: