Skip to content

Enable Wi-Fi Management only when required #39172

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

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
10 changes: 7 additions & 3 deletions examples/platform/linux/AppMain.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -440,16 +440,20 @@ int ChipLinuxAppInit(int argc, char * const argv[], OptionSet * customOptions,
#ifdef CONFIG_RENDEZVOUS_MODE
rendezvousFlags = static_cast<RendezvousInformationFlags>(CONFIG_RENDEZVOUS_MODE);
#endif
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
rendezvousFlags.Set(RendezvousInformationFlag::kWiFiPAF);
#endif

err = Platform::MemoryInit();
SuccessOrExit(err);

err = ParseArguments(argc, argv, customOptions);
SuccessOrExit(err);

#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
if (LinuxDeviceOptions::GetInstance().mWiFiPAF)
{
rendezvousFlags.Set(RendezvousInformationFlag::kWiFiPAF);
}
#endif

sSecondaryNetworkCommissioningEndpoint = secondaryNetworkCommissioningEndpoint;

#ifdef CHIP_CONFIG_KVS_PATH
Expand Down
7 changes: 4 additions & 3 deletions scripts/build/build/targets.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,11 @@ def BuildHostTarget():
TargetPart('shell', app=HostApp.SHELL),
TargetPart('ota-provider', app=HostApp.OTA_PROVIDER, enable_ble=False),
TargetPart('ota-requestor', app=HostApp.OTA_REQUESTOR,
enable_ble=False),
enable_ble=False, enable_wifipaf=False),
TargetPart('simulated-app1', app=HostApp.SIMULATED_APP1,
enable_ble=False),
enable_ble=False, enable_wifipaf=False),
TargetPart('simulated-app2', app=HostApp.SIMULATED_APP2,
enable_ble=False),
enable_ble=False, enable_wifipaf=False),
TargetPart('python-bindings', app=HostApp.PYTHON_BINDINGS),
TargetPart('tv-app', app=HostApp.TV_APP),
TargetPart('tv-casting-app', app=HostApp.TV_CASTING),
Expand Down Expand Up @@ -173,6 +173,7 @@ def BuildHostTarget():
'no-interactive', interactive_mode=False).OnlyIfRe('-chip-tool')
target.AppendModifier("ipv6only", enable_ipv4=False)
target.AppendModifier("no-ble", enable_ble=False)
target.AppendModifier("no-wifipaf", enable_wifipaf=False)
target.AppendModifier("no-wifi", enable_wifi=False)
target.AppendModifier("no-thread", enable_thread=False)
target.AppendModifier('no-shell', disable_shell=True)
Expand Down
5 changes: 4 additions & 1 deletion scripts/build/builders/host.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,7 @@ def PlatformName(self):
class HostBuilder(GnBuilder):

def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
enable_ipv4=True, enable_ble=True, enable_wifi=True,
enable_ipv4=True, enable_ble=True, enable_wifi=True, enable_wifipaf=True,
enable_thread=True, use_tsan=False, use_asan=False, use_ubsan=False,
separate_event_loop=True, fuzzing_type: HostFuzzingType = HostFuzzingType.NONE, use_clang=False,
interactive_mode=True, extra_tests=False, use_nl_fault_injection=False, use_platform_mdns=False, enable_rpcs=False,
Expand Down Expand Up @@ -383,6 +383,9 @@ def __init__(self, root, runner, app: HostApp, board=HostBoard.NATIVE,
self.extra_gn_options.append('chip_config_network_layer_ble=false')
self.extra_gn_options.append('chip_enable_ble=false')

if not enable_wifipaf:
self.extra_gn_options.append('chip_device_config_enable_wifipaf=false')

if not enable_wifi:
self.extra_gn_options.append('chip_enable_wifi=false')

Expand Down
2 changes: 1 addition & 1 deletion scripts/build/testdata/all_targets_linux_x64.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ efr32-{brd2601b,brd2605a,brd2703a,brd2704b,brd4186a,brd4186c,brd4187a,brd4187c,b
esp32-{c3devkit,devkitc,m5stack,qemu}-{all-clusters,all-clusters-minimal,bridge,energy-gateway,energy-management,light,lock,ota-provider,ota-requestor,ota-requestor,shell,temperature-measurement,tests}[-ipv6only][-rpc][-tracing]
genio-lighting-app
linux-fake-tests[-asan][-boringssl][-clang][-coverage][-dmalloc][-libfuzzer][-mbedtls][-ossfuzz][-pw-fuzztest][-tsan][-ubsan]
linux-{arm64,x64}-{address-resolve-tool,air-purifier,air-quality-sensor,all-clusters,all-clusters-minimal,bridge,camera,camera-controller,chip-cert,chip-tool,contact-sensor,dishwasher,energy-gateway,energy-management,fabric-admin,fabric-bridge,fabric-sync,java-matter-controller,kotlin-matter-controller,light,light-data-model-no-unique-id,lit-icd,lock,microwave-oven,minmdns,network-manager,ota-provider,ota-requestor,python-bindings,refrigerator,rpc-console,rvc,shell,simulated-app1,simulated-app2,terms-and-conditions,tests,thermostat,tv-app,tv-casting-app,water-leak-detector}[-asan][-boringssl][-chip-casting-simplified][-clang][-coverage][-disable-dnssd-tests][-dmalloc][-enable-dnssd-tests][-evse-test-event][-googletest][-ipv6only][-libfuzzer][-libnl][-mbedtls][-minmdns-verbose][-nlfaultinject][-no-ble][-no-interactive][-no-shell][-no-thread][-no-wifi][-nodeps][-ossfuzz][-platform-mdns][-pw-fuzztest][-rpc][-same-event-loop][-terms-and-conditions][-test][-tsan][-ubsan][-with-ui]
linux-{arm64,x64}-{address-resolve-tool,air-purifier,air-quality-sensor,all-clusters,all-clusters-minimal,bridge,camera,camera-controller,chip-cert,chip-tool,contact-sensor,dishwasher,energy-gateway,energy-management,fabric-admin,fabric-bridge,fabric-sync,java-matter-controller,kotlin-matter-controller,light,light-data-model-no-unique-id,lit-icd,lock,microwave-oven,minmdns,network-manager,ota-provider,ota-requestor,python-bindings,refrigerator,rpc-console,rvc,shell,simulated-app1,simulated-app2,terms-and-conditions,tests,thermostat,tv-app,tv-casting-app,water-leak-detector}[-asan][-boringssl][-chip-casting-simplified][-clang][-coverage][-disable-dnssd-tests][-dmalloc][-enable-dnssd-tests][-evse-test-event][-googletest][-ipv6only][-libfuzzer][-libnl][-mbedtls][-minmdns-verbose][-nlfaultinject][-no-ble][-no-interactive][-no-shell][-no-thread][-no-wifi][-no-wifipaf][-nodeps][-ossfuzz][-platform-mdns][-pw-fuzztest][-rpc][-same-event-loop][-terms-and-conditions][-test][-tsan][-ubsan][-with-ui]
linux-x64-efr32-test-runner[-clang]
imx-{all-clusters-app,all-clusters-minimal-app,chip-tool,lighting-app,ota-provider-app,thermostat}[-release]
infineon-psoc6-{all-clusters,all-clusters-minimal,light,lock}[-ota][-trustm][-updateimage]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ cd "{root}"
# Generating linux-arm64-ota-requestor-nodeps-ipv6only
bash -c '
PKG_CONFIG_PATH="SYSROOT_AARCH64/lib/aarch64-linux-gnu/pkgconfig" \
gn gen --check --fail-on-unused-args '"'"'--add-export-compile-commands=*'"'"' --root={root}/examples/ota-requestor-app/linux '"'"'--args=chip_inet_config_enable_ipv4=false chip_config_network_layer_ble=false chip_enable_ble=false chip_enable_wifi=false chip_enable_openthread=false is_clang=true chip_crypto="mbedtls" target_cpu="arm64" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-ota-requestor-nodeps-ipv6only'
gn gen --check --fail-on-unused-args '"'"'--add-export-compile-commands=*'"'"' --root={root}/examples/ota-requestor-app/linux '"'"'--args=chip_inet_config_enable_ipv4=false chip_config_network_layer_ble=false chip_enable_ble=false chip_device_config_enable_wifipaf=false chip_enable_wifi=false chip_enable_openthread=false is_clang=true chip_crypto="mbedtls" target_cpu="arm64" sysroot="SYSROOT_AARCH64"'"'"' {out}/linux-arm64-ota-requestor-nodeps-ipv6only'

# Setting up Java deps
third_party/java_deps/set_up_java_deps.sh
Expand Down
1 change: 1 addition & 0 deletions scripts/examples/gn_build_test_example.sh
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ function runGN() {
GN_ARGS="chip_tests_zap_config=\"$APP_DIR\""
GN_ARGS+="chip_project_config_include_dirs=[\"$INPUT_DIR/apps/$APP_DIR/include\", \"$CHIP_ROOT/config/standalone\"]"
GN_ARGS+="chip_config_network_layer_ble=false"
GN_ARGS+="chip_device_config_enable_wifipaf=false"

gn gen --check --fail-on-unused-args --root=examples/placeholder/linux "$CHIP_ROOT/out/$APP_DIR" --args="$GN_ARGS"
}
Expand Down
5 changes: 0 additions & 5 deletions src/controller/CHIPDeviceController.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -832,11 +832,6 @@ CHIP_ERROR DeviceCommissioner::EstablishPASEConnection(NodeId remoteDeviceId, Re
{
ChipLogProgress(Controller, "WiFi-PAF: Subscribing to the NAN-USD devices, nodeId: %lu",
params.GetPeerAddress().GetRemoteId());
if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
ChipLogError(Controller, "Wi-Fi Management should have been started now.");
ExitNow(CHIP_ERROR_INTERNAL);
}
mRendezvousParametersForDeviceDiscoveredOverWiFiPAF = params;
auto nodeId = params.GetPeerAddress().GetRemoteId();
const SetupDiscriminator connDiscriminator(params.GetSetupDiscriminator().value());
Expand Down
33 changes: 33 additions & 0 deletions src/platform/Linux/ConnectivityManagerImpl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -759,6 +759,33 @@ void ConnectivityManagerImpl::StartWiFiManagement()
VerifyOrReturn(err == CHIP_NO_ERROR, ChipLogError(DeviceLayer, "Failed to start WiFi management"));
}

CHIP_ERROR ConnectivityManagerImpl::StartWiFiManagementSync()
{
if (IsWiFiManagementStarted())
{
return CHIP_NO_ERROR;
}
ChipLogProgress(DeviceLayer, "Start and sync Wi-Fi Management.");
static constexpr useconds_t kWiFiStartCheckTimeUsec = WIFI_START_CHECK_TIME_USEC;
static constexpr uint8_t kWiFiStartCheckAttempts = WIFI_START_CHECK_ATTEMPTS;
StartWiFiManagement();
for (int cnt = 0; cnt < kWiFiStartCheckAttempts; cnt++)
{
if (IsWiFiManagementStarted())
{
break;
}
usleep(kWiFiStartCheckTimeUsec);
}
if (!IsWiFiManagementStarted())
{
ChipLogError(DeviceLayer, "Wi-Fi Management can't be started.");
return CHIP_ERROR_INTERNAL;
}
ChipLogProgress(DeviceLayer, "Wi-Fi Management is started");
return CHIP_NO_ERROR;
}

bool ConnectivityManagerImpl::IsWiFiManagementStarted()
{
std::lock_guard<std::mutex> lock(mWpaSupplicantMutex);
Expand Down Expand Up @@ -794,6 +821,9 @@ enum nan_service_protocol_type

CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFPublish(ConnectivityManager::WiFiPAFAdvertiseParam & InArgs)
{
CHIP_ERROR result = StartWiFiManagementSync();
VerifyOrReturnError(result == CHIP_NO_ERROR, result);

GAutoPtr<GError> err;
guint publish_id;
enum nan_service_protocol_type srv_proto_type = nan_service_protocol_type::NAN_SRV_PROTO_CSA_MATTER;
Expand Down Expand Up @@ -1537,6 +1567,9 @@ void ConnectivityManagerImpl::OnNanSubscribeTerminated(guint subscribe_id, gchar
CHIP_ERROR ConnectivityManagerImpl::_WiFiPAFSubscribe(const uint16_t & connDiscriminator, void * appState,
OnConnectionCompleteFunct onSuccess, OnConnectionErrorFunct onError)
{
CHIP_ERROR result = StartWiFiManagementSync();
VerifyOrReturnError(result == CHIP_NO_ERROR, result);

ChipLogProgress(Controller, "WiFi-PAF: Try to subscribe the NAN-USD devices");

guint subscribe_id;
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 @@ -257,6 +257,7 @@ class ConnectivityManagerImpl final : public ConnectivityManager,
void _OnWpaInterfaceReady(GObject * sourceObject, GAsyncResult * res);
void _OnWpaInterfaceProxyReady(GObject * sourceObject, GAsyncResult * res);
void _OnWpaBssProxyReady(GObject * sourceObject, GAsyncResult * res);
CHIP_ERROR StartWiFiManagementSync();
#if CHIP_DEVICE_CONFIG_ENABLE_WIFIPAF
OnConnectionCompleteFunct mOnPafSubscribeComplete;
OnConnectionErrorFunct mOnPafSubscribeError;
Expand Down
9 changes: 6 additions & 3 deletions src/platform/device.gni
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,6 @@ declare_args() {

# Substitute fake platform when building with chip_device_platform=auto.
chip_fake_platform = false

# Include wifi-paf to commission the device or not
chip_device_config_enable_wifipaf = false
}

if (chip_device_platform == "auto") {
Expand Down Expand Up @@ -126,6 +123,12 @@ declare_args() {
declare_args() {
# Enable Joint Fabric features
chip_device_config_enable_joint_fabric = false

# Include wifi-paf to commission the device or not
# This is a feature of Wi-Fi spec that it can be enabled if wifi is enabled
# and the supplicant can support.
chip_device_config_enable_wifipaf =
chip_enable_wifi && chip_device_platform == "linux"
}

declare_args() {
Expand Down
23 changes: 0 additions & 23 deletions src/transport/raw/WiFiPAF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,6 @@ CHIP_ERROR WiFiPAFBase::Init(const WiFiPAFListenParameters & param)
mWiFiPAFLayer = DeviceLayer::ConnectivityMgr().GetWiFiPAF();
SetWiFiPAFLayerTransportToSelf();
mWiFiPAFLayer->SetWiFiPAFState(State::kInitialized);

if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
ChipLogError(Inet, "Wi-Fi Management has not started, do it now.");
static constexpr useconds_t kWiFiStartCheckTimeUsec = WIFI_START_CHECK_TIME_USEC;
static constexpr uint8_t kWiFiStartCheckAttempts = WIFI_START_CHECK_ATTEMPTS;
DeviceLayer::ConnectivityMgrImpl().StartWiFiManagement();
{
for (int cnt = 0; cnt < kWiFiStartCheckAttempts; cnt++)
{
if (DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
break;
}
usleep(kWiFiStartCheckTimeUsec);
}
}
if (!DeviceLayer::ConnectivityMgrImpl().IsWiFiManagementStarted())
{
ChipLogError(Inet, "Wi-Fi Management taking too long to start - device configuration will be reset.");
}
ChipLogProgress(Inet, "Wi-Fi Management is started");
}
return CHIP_NO_ERROR;
}

Expand Down
Loading