Line data Source code
1 : /*
2 : *
3 : * Copyright (c) 2020-2021 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 :
18 : /**
19 : * @file
20 : * Provides an generic implementation of ConnectivityManager features
21 : * for use on platforms that support WiFi.
22 : */
23 :
24 : #pragma once
25 :
26 : #include <app/icd/server/ICDServerConfig.h>
27 : #include <lib/support/logging/CHIPLogging.h>
28 : #include <platform/ConnectivityManager.h>
29 : #include <platform/internal/DeviceNetworkInfo.h>
30 :
31 : namespace chip {
32 : namespace DeviceLayer {
33 : namespace Internal {
34 :
35 : /**
36 : * Provides a generic implementation of WiFi-specific ConnectivityManager features for
37 : * platforms that don't support WiFi.
38 : *
39 : * This class is intended to be inherited (directly or indirectly) by the ConnectivityManagerImpl
40 : * class, which also appears as the template's ImplClass parameter.
41 : *
42 : * The members of this class are all inlined methods that do nothing, and return static return
43 : * values. This allows the compiler to optimize away dead code without the use of \#ifdef's.
44 : * For example:
45 : *
46 : * ```
47 : * if (ConnectivityMgr().GetWiFiStationMode() != ConnectivityManager::kWiFiStationMode_NotSupported)
48 : * {
49 : * // ... do something on devices that support WiFi ...
50 : * }
51 : * ```
52 : */
53 : template <class ImplClass>
54 : class GenericConnectivityManagerImpl_WiFi
55 : {
56 : public:
57 : // ===== Methods that implement the ConnectivityManager abstract interface.
58 :
59 : ConnectivityManager::WiFiStationMode _GetWiFiStationMode();
60 : CHIP_ERROR _SetWiFiStationMode(ConnectivityManager::WiFiStationMode val);
61 : bool _IsWiFiStationEnabled();
62 : bool _IsWiFiStationApplicationControlled();
63 : System::Clock::Timeout _GetWiFiStationReconnectInterval();
64 : CHIP_ERROR _SetWiFiStationReconnectInterval(System::Clock::Timeout val);
65 : bool _IsWiFiStationProvisioned();
66 : void _ClearWiFiStationProvision();
67 : ConnectivityManager::WiFiAPMode _GetWiFiAPMode();
68 : CHIP_ERROR _SetWiFiAPMode(ConnectivityManager::WiFiAPMode val);
69 : bool _IsWiFiAPActive();
70 : bool _IsWiFiAPApplicationControlled();
71 : void _DemandStartWiFiAP();
72 : void _StopOnDemandWiFiAP();
73 : void _MaintainOnDemandWiFiAP();
74 : System::Clock::Timeout _GetWiFiAPIdleTimeout();
75 : void _SetWiFiAPIdleTimeout(System::Clock::Timeout val);
76 : CHIP_ERROR _GetAndLogWiFiStatsCounters();
77 : void _OnWiFiScanDone();
78 : void _OnWiFiStationProvisionChange();
79 : // TODO ICD rework: ambiguous declaration of _SetPollingInterval when thread and wifi are both build together
80 : #if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD
81 : CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval);
82 : #endif
83 : static const char * _WiFiStationModeToStr(ConnectivityManager::WiFiStationMode mode);
84 : static const char * _WiFiAPModeToStr(ConnectivityManager::WiFiAPMode mode);
85 : static const char * _WiFiStationStateToStr(ConnectivityManager::WiFiStationState state);
86 : static const char * _WiFiAPStateToStr(ConnectivityManager::WiFiAPState state);
87 :
88 : protected:
89 : enum class ConnectivityFlags : uint16_t
90 : {
91 : kHaveIPv4InternetConnectivity = 0x0001,
92 : kHaveIPv6InternetConnectivity = 0x0002,
93 : kAwaitingConnectivity = 0x0010,
94 : };
95 :
96 : private:
97 0 : ImplClass * Impl() { return static_cast<ImplClass *>(this); }
98 : };
99 :
100 : template <class ImplClass>
101 0 : inline System::Clock::Timeout GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetWiFiStationReconnectInterval()
102 : {
103 0 : return System::Clock::kZero;
104 : }
105 :
106 : template <class ImplClass>
107 0 : inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_SetWiFiStationReconnectInterval(System::Clock::Timeout val)
108 : {
109 0 : return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
110 : }
111 :
112 : template <class ImplClass>
113 0 : inline bool GenericConnectivityManagerImpl_WiFi<ImplClass>::_IsWiFiStationProvisioned()
114 : {
115 0 : return false;
116 : }
117 :
118 : template <class ImplClass>
119 0 : inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_ClearWiFiStationProvision()
120 0 : {}
121 :
122 : template <class ImplClass>
123 0 : inline ConnectivityManager::WiFiAPMode GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetWiFiAPMode()
124 : {
125 0 : return ConnectivityManager::kWiFiAPMode_NotSupported;
126 : }
127 :
128 : template <class ImplClass>
129 0 : inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_SetWiFiAPMode(ConnectivityManager::WiFiAPMode val)
130 : {
131 0 : return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
132 : }
133 :
134 : template <class ImplClass>
135 0 : inline bool GenericConnectivityManagerImpl_WiFi<ImplClass>::_IsWiFiAPActive()
136 : {
137 0 : return false;
138 : }
139 :
140 : template <class ImplClass>
141 0 : inline bool GenericConnectivityManagerImpl_WiFi<ImplClass>::_IsWiFiAPApplicationControlled()
142 : {
143 0 : return false;
144 : }
145 :
146 : template <class ImplClass>
147 0 : inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_DemandStartWiFiAP()
148 0 : {}
149 :
150 : template <class ImplClass>
151 0 : inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_StopOnDemandWiFiAP()
152 0 : {}
153 :
154 : template <class ImplClass>
155 0 : inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_MaintainOnDemandWiFiAP()
156 0 : {}
157 :
158 : template <class ImplClass>
159 0 : inline System::Clock::Timeout GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetWiFiAPIdleTimeout()
160 : {
161 0 : return System::Clock::kZero;
162 : }
163 :
164 : template <class ImplClass>
165 0 : inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_SetWiFiAPIdleTimeout(System::Clock::Timeout val)
166 0 : {}
167 :
168 : template <class ImplClass>
169 0 : inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_GetAndLogWiFiStatsCounters()
170 : {
171 0 : return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE;
172 : }
173 :
174 : template <class ImplClass>
175 0 : inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_OnWiFiScanDone()
176 0 : {}
177 :
178 : template <class ImplClass>
179 0 : inline void GenericConnectivityManagerImpl_WiFi<ImplClass>::_OnWiFiStationProvisionChange()
180 0 : {}
181 :
182 : #if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD
183 : template <class ImplClass>
184 : inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi<ImplClass>::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval)
185 : {
186 : return CHIP_ERROR_NOT_IMPLEMENTED;
187 : }
188 : #endif
189 :
190 : } // namespace Internal
191 : } // namespace DeviceLayer
192 : } // namespace chip
|