-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathApplicationSleepManager.h
189 lines (161 loc) · 8.6 KB
/
ApplicationSleepManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
/*******************************************************************************
* @file ApplicationSleepManager.h
* @brief Header for the buisness logic around Optimizing Wi-Fi sleep states
*******************************************************************************
* # License
* <b>Copyright 2024 Silicon Laboratories Inc. www.silabs.com</b>
*******************************************************************************
*
* The licensor of this software is Silicon Laboratories Inc. Your use of this
* software is governed by the terms of Silicon Labs Master Software License
* Agreement (MSLA) available at
* www.silabs.com/about-us/legal/master-software-license-agreement. This
* software is distributed to you in Source Code format and is governed by the
* sections of the MSLA applicable to Source Code.
*
******************************************************************************/
#pragma once
#include <app/ReadHandler.h>
#include <app/SubscriptionsInfoProvider.h>
#include <app/icd/server/ICDStateObserver.h>
#include <app/server/CommissioningWindowManager.h>
#include <credentials/FabricTable.h>
#include <platform/silabs/wifi/icd/WifiSleepManager.h>
namespace chip {
namespace app {
namespace Silabs {
class ApplicationSleepManager : public chip::app::ReadHandler::ApplicationCallback,
public chip::DeviceLayer::Silabs::WifiSleepManager::ApplicationCallback,
public chip::FabricTable::Delegate,
public chip::app::ICDStateObserver
{
public:
static ApplicationSleepManager & GetInstance() { return mInstance; }
/**
* @brief Init function validates that the necessary pointers where correctly set
* before registering the object with the FabricTable and the WifiSleepManager.
*
* Init function does not register with the InteractionModelEngine since depending on the whole interation model engine
* complexifies unit testing when we can use the SubscriptionInfoProvider which provides the necessary APIs.
*
*
* @return CHIP_ERROR CHIP_NO_ERROR if the init succeed
* CHIP_ERROR_INVALID_ARGUMENT, if the fabricTable, subscriptionsInfoProvider or commissioningWindowManager,
* wifiSleepManager were not set correctly
* other, if the FabricTable::AddFabricDelegate failed
*/
CHIP_ERROR Init();
ApplicationSleepManager & SetFabricTable(chip::FabricTable * fabricTable)
{
mFabricTable = fabricTable;
return *this;
}
ApplicationSleepManager & SetSubscriptionInfoProvider(chip::app::SubscriptionsInfoProvider * subscriptionsInfoProvider)
{
mSubscriptionsInfoProvider = subscriptionsInfoProvider;
return *this;
}
ApplicationSleepManager & SetWifiSleepManager(chip::DeviceLayer::Silabs::WifiSleepManager * wifiSleepManager)
{
mWifiSleepManager = wifiSleepManager;
return *this;
}
/**
* @brief Sets the commissioning window state to open and calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnCommissioningWindowOpened();
/**
* @brief Sets the commissioning window state to open and calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnCommissioningWindowClosed();
// ReadHandler::ApplicationCallback implementation
/**
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnSubscriptionTerminated(chip::app::ReadHandler & aReadHandler);
/**
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of then queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnSubscriptionEstablished(chip::app::ReadHandler & aReadHandler);
CHIP_ERROR OnSubscriptionRequested(chip::app::ReadHandler & aReadHandler, chip::Transport::SecureSession & aSecureSession);
// WifiSleepManager::ApplicationCallback implementation
/**
* @brief Function encapsulates the application logic to determine if the Wi-Fi device can go into LI based sleep.
*
* - 1. Check if the commissioning window is open. If it is open, the Wi-Fi device cannot go to LI based sleep.
* - 2. Check if all Fabrics have at least 1 subscription. If there is at least one fabric without a subscription, the
* Wi-Fi cannot go to LI based sleep.
*
* @return true if the device can go to LI sleep
* false if the device cannot go to LI sleep
*/
bool CanGoToLIBasedSleep() override;
bool CanGoToDeepSleep() override;
// FabricTable::Delegate implementation
/**
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnFabricRemoved(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override;
/**
* @brief Calls the WifiSleepManager VerifyAndTransitionToLowPowerMode.
* The VerifyAndTransitionToLowPowerMode function is responsible of queriyng the ApplicationSleepManager to
* determine in which low power state the Wi-Fi device can transition to.
*/
void OnFabricCommitted(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override;
void OnFabricUpdated(const chip::FabricTable & fabricTable, chip::FabricIndex fabricIndex) override {}
// ICDStateObserver implementation
void OnEnterActiveMode() override;
void OnEnterIdleMode() override;
void OnTransitionToIdle() override;
void OnICDModeChange() override;
private:
ApplicationSleepManager() = default;
~ApplicationSleepManager() = default;
ApplicationSleepManager(const ApplicationSleepManager &) = delete;
ApplicationSleepManager & operator=(const ApplicationSleepManager &) = delete;
/**
* @brief Processes special cases based on the vendor ID.
*
* This method checks if the given vendor ID has any special cases that allow
* the device to go to LI based sleep when the fabric associated to the vendor ID does not have an active subscription.
*
* @param vendorId The vendor ID to check for special cases.
* @return true if the vendor ID has a special case that allows LI based sleep, false otherwise.
*/
bool ProcessSpecialVendorIDCase(chip::VendorId vendorId);
/**
* @brief Processes the Apple Keychain edge case.
*
* Apple, when commissioning, adds two fabric to the device. One for Apple Home and one for the Appley Keychain.
* Apple Home is the active fabric which is used to communication with the device. The associated fabric also has the active
* subcription. Applye Keychain fabric acts as a safety and doesn't have an active fabric with the device. As such, we need an
* alternate method to check if the device can go to LI based sleep.
*
* This method checks if there is any fabric with the Apple Home vendor ID that
* has at least one active subscription. If such a fabric is found, it allows
* the device to go to LI based sleep.
*
* @return true if the Apple Keychain edge case allows low-power mode, false otherwise.
*/
bool ProcessKeychainEdgeCase();
static ApplicationSleepManager mInstance;
chip::FabricTable * mFabricTable = nullptr;
chip::app::SubscriptionsInfoProvider * mSubscriptionsInfoProvider = nullptr;
chip::CommissioningWindowManager * mCommissioningWindowManager = nullptr;
chip::DeviceLayer::Silabs::WifiSleepManager * mWifiSleepManager = nullptr;
bool mIsCommissionningWindowOpen = false;
bool mIsInActiveMode = false;
};
} // namespace Silabs
} // namespace app
} // namespace chip