Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support to Linux examples to report 5GHz Wi-Fi support #31670

Merged
merged 3 commits into from
Jan 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 16 additions & 15 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,23 +193,24 @@ void InitNetworkCommissioning()
emberAfEndpointEnableDisable(sSecondaryNetworkCommissioningEndpoint.Value(), false);
}

const bool kThreadEnabled = {
bool isThreadEnabled = false;
#if CHIP_APP_MAIN_HAS_THREAD_DRIVER
LinuxDeviceOptions::GetInstance().mThread
#else
false
#endif
};
isThreadEnabled = LinuxDeviceOptions::GetInstance().mThread;
#endif // CHIP_APP_MAIN_HAS_THREAD_DRIVER

const bool kWiFiEnabled = {
bool isWiFiEnabled = false;
#if CHIP_APP_MAIN_HAS_WIFI_DRIVER
LinuxDeviceOptions::GetInstance().mWiFi
#else
false
#endif
};
isWiFiEnabled = LinuxDeviceOptions::GetInstance().mWiFi;

// On Linux, command-line indicates whether Wi-Fi is supported since determining it from
// the OS level is not easily portable.
#if CHIP_DEVICE_LAYER_TARGET_LINUX
sWiFiDriver.Set5gSupport(LinuxDeviceOptions::GetInstance().wifiSupports5g);
#endif // CHIP_DEVICE_LAYER_TARGET_LINUX

#endif // CHIP_APP_MAIN_HAS_WIFI_DRIVER

if (kThreadEnabled && kWiFiEnabled)
if (isThreadEnabled && isWiFiEnabled)
{
if (sSecondaryNetworkCommissioningEndpoint.HasValue())
{
Expand All @@ -224,11 +225,11 @@ void InitNetworkCommissioning()
EnableThreadNetworkCommissioning();
}
}
else if (kThreadEnabled)
else if (isThreadEnabled)
{
EnableThreadNetworkCommissioning();
}
else if (kWiFiEnabled)
else if (isWiFiEnabled)
{
EnableWiFiNetworkCommissioning(kRootEndpointId);
}
Expand Down
13 changes: 12 additions & 1 deletion examples/platform/linux/Options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ enum
#if CONFIG_BUILD_FOR_HOST_UNIT_TEST
kDeviceOption_SubscriptionCapacity = 0x1024,
#endif
kDeviceOption_WiFiSupports5g = 0x1025
};

constexpr unsigned kAppUsageLength = 64;
Expand All @@ -100,6 +101,7 @@ OptionDef sDeviceOptionDefs[] = {
#endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
{ "wifi", kNoArgument, kDeviceOption_WiFi },
{ "wifi-supports-5g", kNoArgument, kDeviceOption_WiFiSupports5g },
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
#if CHIP_ENABLE_OPENTHREAD
{ "thread", kNoArgument, kDeviceOption_Thread },
Expand Down Expand Up @@ -161,8 +163,13 @@ const char * sDeviceOptionHelp =
#if CHIP_DEVICE_CONFIG_ENABLE_WPA
"\n"
" --wifi\n"
" Enable WiFi management via wpa_supplicant.\n"
" Enable Wi-Fi management via wpa_supplicant.\n"
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA
#if CHIP_DEVICE_CONFIG_ENABLE_WIFI
"\n"
" --wifi-supports-5g\n"
" Indicate that local Wi-Fi hardware should report 5GHz support.\n"
#endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI
#if CHIP_ENABLE_OPENTHREAD
"\n"
" --thread\n"
Expand Down Expand Up @@ -311,6 +318,10 @@ bool HandleOption(const char * aProgram, OptionSet * aOptions, int aIdentifier,
LinuxDeviceOptions::GetInstance().mWiFi = true;
break;

case kDeviceOption_WiFiSupports5g:
LinuxDeviceOptions::GetInstance().wifiSupports5g = true;
break;

case kDeviceOption_Thread:
LinuxDeviceOptions::GetInstance().mThread = true;
break;
Expand Down
1 change: 1 addition & 0 deletions examples/platform/linux/Options.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ struct LinuxDeviceOptions
chip::Optional<std::vector<uint8_t>> spake2pSalt;
uint32_t spake2pIterations = 0; // When not provided (0), will default elsewhere
uint32_t mBleDevice = 0;
bool wifiSupports5g = false;
bool mWiFi = false;
bool mThread = false;
#if CHIP_DEVICE_CONFIG_ENABLE_BOTH_COMMISSIONER_AND_COMMISSIONEE || CHIP_DEVICE_ENABLE_PORT_PARAMS
Expand Down
14 changes: 14 additions & 0 deletions src/platform/Linux/NetworkCommissioningDriver.h
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ class LinuxWiFiDriver final : public WiFiDriver
uint8_t credentialsLen = 0;
};

void Set5gSupport(bool is5gSupported) { mIs5gSupported = is5gSupported; }

// BaseDriver
NetworkIterator * GetNetworks() override { return new WiFiNetworkIterator(this); }
CHIP_ERROR Init(BaseDriver::NetworkStatusChangeCallback * networkStatusChangeCallback) override;
Expand All @@ -99,11 +101,23 @@ class LinuxWiFiDriver final : public WiFiDriver
uint8_t & outNetworkIndex) override;
void ScanNetworks(ByteSpan ssid, ScanCallback * callback) override;

uint32_t GetSupportedWiFiBandsMask() const override
{
uint32_t supportedBands = static_cast<uint32_t>(1UL << chip::to_underlying(WiFiBandEnum::k2g4));
if (mIs5gSupported)
{
supportedBands |= static_cast<uint32_t>(1UL << chip::to_underlying(WiFiBandEnum::k5g));
}
return supportedBands;
}

private:
bool NetworkMatch(const WiFiNetwork & network, ByteSpan networkId);

WiFiNetwork mSavedNetwork;
WiFiNetwork mStagingNetwork;
// Whether 5GHz band is supported, as claimed by callers (`Set5gSupport()`) rather than syscalls.
bool mIs5gSupported = false;
};
#endif // CHIP_DEVICE_CONFIG_ENABLE_WPA

Expand Down
Loading