Skip to content

Commit

Permalink
Wait for Wi-Fi management to start up (#8834)
Browse files Browse the repository at this point in the history
  • Loading branch information
tewarid committed Aug 30, 2021
1 parent f07ff95 commit 9f1db8a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
14 changes: 14 additions & 0 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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)
{
Expand All @@ -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<chip::RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE);
Expand Down Expand Up @@ -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

Expand Down
5 changes: 5 additions & 0 deletions src/platform/Linux/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
1 change: 1 addition & 0 deletions src/platform/Linux/ConnectivityManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,

#if CHIP_DEVICE_CONFIG_ENABLE_WPA
void StartWiFiManagement();
bool IsWiFiManagementStarted();
#endif

private:
Expand Down

0 comments on commit 9f1db8a

Please sign in to comment.