From 9f1db8a21a3006d84c20c143f02c57f42dfc093e Mon Sep 17 00:00:00 2001 From: Devendra Tewari Date: Mon, 30 Aug 2021 08:06:43 -0300 Subject: [PATCH] Wait for Wi-Fi management to start up (#8834) --- examples/platform/linux/AppMain.cpp | 14 ++++++++++++++ src/platform/Linux/ConnectivityManagerImpl.cpp | 5 +++++ src/platform/Linux/ConnectivityManagerImpl.h | 1 + 3 files changed, 20 insertions(+) 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: