Skip to content

Commit e10beaa

Browse files
Refactor WifiSleepManager dependecies to enable unit-tests on the manager
1 parent 855de80 commit e10beaa

19 files changed

+595
-169
lines changed

examples/platform/silabs/BaseApplication.cpp

+2-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,8 @@
6969
#include <platform/silabs/wifi/WifiInterface.h>
7070

7171
#if CHIP_CONFIG_ENABLE_ICD_SERVER
72-
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
72+
#include <platform/silabs/wifi/icd/WifiSleepManager.h> // nogncheck
73+
7374
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
7475
#endif // SL_WIFI
7576

examples/platform/silabs/MatterConfig.cpp

+4-3
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
#include <platform/silabs/wifi/WifiInterface.h>
2929

3030
#if CHIP_CONFIG_ENABLE_ICD_SERVER
31-
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
32-
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
31+
#include <platform/silabs/wifi/icd/WifiSleepManager.h> // nogncheck
32+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
3333

3434
// TODO: We shouldn't need any platform specific includes in this file
3535
#if (defined(SLI_SI91X_MCU_INTERFACE) && SLI_SI91X_MCU_INTERFACE == 1)
@@ -234,7 +234,8 @@ CHIP_ERROR SilabsMatterConfig::InitMatter(const char * appName)
234234
ReturnErrorOnFailure(InitWiFi());
235235

236236
#if CHIP_CONFIG_ENABLE_ICD_SERVER
237-
ReturnErrorOnFailure(DeviceLayer::Silabs::WifiSleepManager::GetInstance().Init());
237+
ReturnErrorOnFailure(DeviceLayer::Silabs::WifiSleepManager::GetInstance().Init(
238+
&DeviceLayer::Silabs::WifiInterface::GetInstance(), &DeviceLayer::Silabs::WifiInterface::GetInstance()));
238239
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
239240
#endif
240241

src/platform/silabs/SiWx917/OTAImageProcessorImpl.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,8 @@
2323
#include <platform/silabs/wifi/WifiInterface.h>
2424

2525
#if CHIP_CONFIG_ENABLE_ICD_SERVER
26-
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
27-
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
26+
#include <platform/silabs/wifi/icd/WifiSleepManager.h> // nogncheck
27+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
2828

2929
#ifdef __cplusplus
3030
extern "C" {

src/platform/silabs/tests/BUILD.gn

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ chip_test_group("silabs_platform_tests") {
2323
tests = []
2424

2525
if (sl_build_unit_tests) {
26-
tests += [ "${chip_root}/examples/platform/silabs/tests:examples_tests" ]
26+
tests += [
27+
"${chip_root}/examples/platform/silabs/tests:examples_tests",
28+
"${chip_root}/src/platform/silabs/wifi/icd/tests:wifi_icd_tests",
29+
]
2730
}
2831
}

src/platform/silabs/wifi/BUILD.gn

+11-7
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,12 @@ config("wifi-platform-config") {
100100
}
101101
}
102102

103+
source_set("wifi-state-provider") {
104+
sources = [ "${silabs_platform_dir}/wifi/WifiStateProvider.h" ]
105+
106+
public_configs = [ ":wifi-platform-config" ]
107+
}
108+
103109
source_set("wifi-platform") {
104110
sources = [
105111
"${silabs_platform_dir}/wifi/WifiInterface.cpp",
@@ -110,9 +116,11 @@ source_set("wifi-platform") {
110116
public_configs = [ ":wifi-platform-config" ]
111117

112118
public_deps = [
119+
":wifi-state-provider",
113120
"${chip_root}/src/app/icd/server:icd-server-config",
114121
"${chip_root}/src/inet",
115122
"${chip_root}/src/lib/support",
123+
"${silabs_platform_dir}/wifi/icd:power-save-interface",
116124
]
117125

118126
if (use_rs9116) {
@@ -153,14 +161,10 @@ source_set("wifi-platform") {
153161
"${silabs_platform_dir}/wifi/lwip-support/lwip_netif.h",
154162
]
155163
}
156-
157-
# TODO: Once the WifiInterface refactor is done and becomes a class, we will inject an interface instead of having them in same source_set
158164
if (chip_enable_icd_server) {
159-
public_deps += [ "${chip_root}/src/app/icd/server:configuration-data" ]
160-
161-
sources += [
162-
"${silabs_platform_dir}/wifi/icd/WifiSleepManager.cpp",
163-
"${silabs_platform_dir}/wifi/icd/WifiSleepManager.h",
165+
public_deps += [
166+
"${chip_root}/src/app/icd/server:configuration-data",
167+
"${silabs_platform_dir}/wifi/icd:wifi-sleep-manager",
164168
]
165169
}
166170
}

src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.cpp

+39-6
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ extern "C" {
5656
#endif
5757

5858
#if CHIP_CONFIG_ENABLE_ICD_SERVER
59-
#include <app/icd/server/ICDConfigurationData.h> // nogncheck
60-
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
59+
#include <app/icd/server/ICDConfigurationData.h> // nogncheck
60+
#include <platform/silabs/wifi/icd/WifiSleepManager.h> // nogncheck
6161

6262
#if SLI_SI91X_MCU_INTERFACE // SoC Only
6363
#include "rsi_rom_power_save.h"
@@ -427,6 +427,40 @@ sl_status_t SetWifiConfigurations()
427427
return status;
428428
}
429429

430+
#if CHIP_CONFIG_ENABLE_ICD_SERVER
431+
/**
432+
* @brief Converts the Matter Power Save Configuration to the SiWx Power Save Configuration
433+
*
434+
* @param configuration Matter Power Save Configuration
435+
*
436+
* @return sl_si91x_performance_profile_t SiWx Power Save Configuration; Default value is High Performance
437+
* kHighPerformance: HIGH_PERFORMANCE
438+
* kConnectedSleep: ASSOCIATED_POWER_SAVE
439+
* kDeepSleep: DEEP_SLEEP_WITH_RAM_RETENTION
440+
*/
441+
sl_si91x_performance_profile_t ConvertPowerSaveConfiguration(PowerSaveInterface::PowerSaveConfiguration configuration)
442+
{
443+
sl_si91x_performance_profile_t profile = HIGH_PERFORMANCE;
444+
445+
switch (configuration)
446+
{
447+
case PowerSaveInterface::PowerSaveConfiguration::kHighPerformance:
448+
profile = HIGH_PERFORMANCE;
449+
break;
450+
case PowerSaveInterface::PowerSaveConfiguration::kConnectedSleep:
451+
profile = ASSOCIATED_POWER_SAVE;
452+
break;
453+
case PowerSaveInterface::PowerSaveConfiguration::kDeepSleep:
454+
profile = DEEP_SLEEP_WITH_RAM_RETENTION;
455+
break;
456+
default:
457+
break;
458+
}
459+
460+
return profile;
461+
}
462+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
463+
430464
} // namespace
431465

432466
namespace chip {
@@ -790,14 +824,13 @@ sl_status_t WifiInterfaceImpl::TriggerPlatformWifiDisconnection()
790824
}
791825

792826
#if CHIP_CONFIG_ENABLE_ICD_SERVER
793-
CHIP_ERROR WifiInterfaceImpl::ConfigurePowerSave(rsi_power_save_profile_mode_t sl_si91x_ble_state,
794-
sl_si91x_performance_profile_t sl_si91x_wifi_state, uint32_t listenInterval)
827+
CHIP_ERROR WifiInterfaceImpl::ConfigurePowerSave(PowerSaveInterface::PowerSaveConfiguration configuration, uint32_t listenInterval)
795828
{
796-
int32_t error = rsi_bt_power_save_profile(sl_si91x_ble_state, RSI_MAX_PSP);
829+
int32_t error = rsi_bt_power_save_profile(RSI_SLEEP_MODE_2, RSI_MAX_PSP);
797830
VerifyOrReturnError(error == RSI_SUCCESS, CHIP_ERROR_INTERNAL,
798831
ChipLogError(DeviceLayer, "rsi_bt_power_save_profile failed: %ld", error));
799832

800-
sl_wifi_performance_profile_t wifi_profile = { .profile = sl_si91x_wifi_state,
833+
sl_wifi_performance_profile_t wifi_profile = { .profile = ConvertPowerSaveConfiguration(configuration),
801834
// TODO: Performance profile fails if not alligned with DTIM
802835
.dtim_aligned_type = SL_SI91X_ALIGN_WITH_DTIM_BEACON,
803836
// TODO: Different types need to be fixed in the Wi-Fi SDK

src/platform/silabs/wifi/SiWx/WifiInterfaceImpl.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ class WifiInterfaceImpl final : public WiseconnectWifiInterface
4141
CHIP_ERROR GetAccessPointInfo(wfx_wifi_scan_result_t & info) override;
4242
CHIP_ERROR GetAccessPointExtendedInfo(wfx_wifi_scan_ext_t & info) override;
4343
CHIP_ERROR ResetCounters() override;
44+
4445
#if CHIP_CONFIG_ENABLE_ICD_SERVER
4546
CHIP_ERROR ConfigureBroadcastFilter(bool enableBroadcastFilter) override;
46-
CHIP_ERROR ConfigurePowerSave(rsi_power_save_profile_mode_t sl_si91x_ble_state,
47-
sl_si91x_performance_profile_t sl_si91x_wifi_state, uint32_t listenInterval) override;
47+
CHIP_ERROR ConfigurePowerSave(PowerSaveInterface::PowerSaveConfiguration configuration, uint32_t listenInterval) override;
4848
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
4949

5050
/**

src/platform/silabs/wifi/WifiInterface.cpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222
#include <lib/support/logging/CHIPLogging.h>
2323
#include <platform/silabs/wifi/WifiInterface.h>
2424
#if CHIP_CONFIG_ENABLE_ICD_SERVER
25-
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
26-
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
25+
#include <platform/silabs/wifi/icd/WifiSleepManager.h> // nogncheck
26+
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
2727

2828
using namespace chip;
2929
using namespace chip::DeviceLayer;

src/platform/silabs/wifi/WifiInterface.h

+3-76
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@
2121
#include <cmsis_os2.h>
2222
#include <lib/support/BitFlags.h>
2323
#include <lib/support/Span.h>
24+
#include <platform/silabs/wifi/WifiStateProvider.h>
25+
#include <platform/silabs/wifi/icd/PowerSaveInterface.h>
2426
#include <platform/silabs/wifi/wfx_msgs.h>
2527
#include <sl_cmsis_os2_common.h>
2628
#include <sl_status.h>
@@ -107,7 +109,7 @@ namespace Silabs {
107109
* @brief Public Interface for the Wi-Fi platform APIs
108110
*
109111
*/
110-
class WifiInterface
112+
class WifiInterface : public WifiStateProvider, public PowerSaveInterface
111113
{
112114
public:
113115
enum class WifiEvent : uint8_t
@@ -247,30 +249,6 @@ class WifiInterface
247249
*/
248250
virtual void ConfigureStationMode() = 0;
249251

250-
/**
251-
* @brief Returns the state of the Wi-Fi connection
252-
*
253-
* @return true, if the Wi-Fi device is connected to an AP
254-
* false, otherwise
255-
*/
256-
virtual bool IsStationConnected() = 0;
257-
258-
/**
259-
* @brief Returns the state of the Wi-Fi Station configuration of the Wi-Fi device
260-
*
261-
* @return true, if the Wi-Fi Station mode is enabled
262-
* false, otherwise
263-
*/
264-
virtual bool IsStationModeEnabled() = 0;
265-
266-
/**
267-
* @brief Returns the state of the Wi-Fi station initialization
268-
*
269-
* @return true, if the initialization was successful
270-
* false, otherwise
271-
*/
272-
virtual bool IsStationReady() = 0;
273-
274252
/**
275253
* @brief Triggers the device to disconnect from the connected Wi-Fi network
276254
*
@@ -339,15 +317,6 @@ class WifiInterface
339317
*/
340318
virtual CHIP_ERROR GetWifiCredentials(WifiCredentials & credentials) = 0;
341319

342-
/**
343-
* @brief Returns the state of the Wi-Fi network provisionning
344-
* Does the device has Wi-Fi credentials or not
345-
*
346-
* @return true, the device has Wi-Fi credentials
347-
* false, otherwise
348-
*/
349-
virtual bool IsWifiProvisioned() = 0;
350-
351320
/**
352321
* @brief Triggers a connection attempt the Access Point who's crendetials match the ones store with the SetWifiCredentials API.
353322
* The function triggers an async connection attempt. The upper layers are notified trought a platform event if the
@@ -362,48 +331,6 @@ class WifiInterface
362331
*/
363332
virtual CHIP_ERROR ConnectToAccessPoint(void) = 0;
364333

365-
/* Function to update */
366-
367-
// TODO: Harmonize the Power Save function inputs for all platforms
368-
#if CHIP_CONFIG_ENABLE_ICD_SERVER
369-
#if (SLI_SI91X_MCU_INTERFACE | EXP_BOARD)
370-
virtual CHIP_ERROR ConfigurePowerSave(rsi_power_save_profile_mode_t sl_si91x_ble_state,
371-
sl_si91x_performance_profile_t sl_si91x_wifi_state, uint32_t listenInterval) = 0;
372-
#else
373-
virtual CHIP_ERROR ConfigurePowerSave() = 0;
374-
#endif /* (SLI_SI91X_MCU_INTERFACE | EXP_BOARD) */
375-
376-
/**
377-
* @brief Configures the broadcast filter.
378-
*
379-
* @param[in] enableBroadcastFilter Boolean to enable or disable the broadcast filter.
380-
*
381-
* @return CHIP_ERROR CHIP_NO_ERROR, the counters were succesfully reset to 0.
382-
* CHIP_ERROR_INTERNAL, if there was an error when configuring the broadcast filter
383-
*/
384-
virtual CHIP_ERROR ConfigureBroadcastFilter(bool enableBroadcastFilter) = 0;
385-
#endif // CHIP_CONFIG_ENABLE_ICD_SERVER
386-
387-
#if CHIP_DEVICE_CONFIG_ENABLE_IPV4
388-
/**
389-
* @brief Returns IP assignment status
390-
*
391-
392-
* @return true, Wi-Fi station has an IPv4 address
393-
* false, otherwise
394-
*/
395-
virtual bool HasAnIPv4Address() = 0;
396-
#endif /* CHIP_DEVICE_CONFIG_ENABLE_IPV4 */
397-
398-
/**
399-
* @brief Returns IP assignment status
400-
*
401-
402-
* @return true, Wi-Fi station has an IPv6 address
403-
* false, otherwise
404-
*/
405-
virtual bool HasAnIPv6Address() = 0;
406-
407334
/**
408335
* @brief Cancels the on-going network scan operation.
409336
* If one isn't in-progress, function doesn't do anything
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
*
3+
* Copyright (c) 2025 Project CHIP Authors
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
#pragma once
18+
19+
#include <lib/core/CHIPError.h>
20+
21+
namespace chip {
22+
namespace DeviceLayer {
23+
namespace Silabs {
24+
25+
/**
26+
* @brief Wi-Fi state provider interface
27+
*
28+
*/
29+
class WifiStateProvider
30+
{
31+
public:
32+
virtual ~WifiStateProvider() = default;
33+
34+
/**
35+
* @brief Returns the state of the Wi-Fi connection
36+
*
37+
* @return true, if the Wi-Fi device is connected to an AP
38+
* false, otherwise
39+
*/
40+
virtual bool IsStationConnected() = 0;
41+
42+
/**
43+
* @brief Returns the state of the Wi-Fi Station configuration of the Wi-Fi device
44+
*
45+
* @return true, if the Wi-Fi Station mode is enabled
46+
* false, otherwise
47+
*/
48+
virtual bool IsStationModeEnabled() = 0;
49+
50+
/**
51+
* @brief Returns the state of the Wi-Fi station initialization
52+
*
53+
* @return true, if the initialization was successful
54+
* false, otherwise
55+
*/
56+
virtual bool IsStationReady() = 0;
57+
58+
/**
59+
* @brief Returns the state of the Wi-Fi network provisionning
60+
* Does the device has Wi-Fi credentials or not
61+
*
62+
* @return true, the device has Wi-Fi credentials
63+
* false, otherwise
64+
*/
65+
virtual bool IsWifiProvisioned() = 0;
66+
67+
/**
68+
* @brief Returns IP assignment status
69+
*
70+
71+
* @return true, Wi-Fi station has an IPv4 address
72+
* false, otherwise
73+
*/
74+
virtual bool HasAnIPv4Address() = 0;
75+
76+
/**
77+
* @brief Returns IP assignment status
78+
*
79+
80+
* @return true, Wi-Fi station has an IPv6 address
81+
* false, otherwise
82+
*/
83+
virtual bool HasAnIPv6Address() = 0;
84+
};
85+
86+
} // namespace Silabs
87+
} // namespace DeviceLayer
88+
} // namespace chip

0 commit comments

Comments
 (0)