/* * * Copyright (c) 2020-2021 Project CHIP Authors * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ /** * @file * Provides an generic implementation of ConnectivityManager features * for use on platforms that support WiFi. */ #pragma once #include #include #include #include namespace chip { namespace DeviceLayer { namespace Internal { /** * Provides a generic implementation of WiFi-specific ConnectivityManager features for * platforms that don't support WiFi. * * This class is intended to be inherited (directly or indirectly) by the ConnectivityManagerImpl * class, which also appears as the template's ImplClass parameter. * * The members of this class are all inlined methods that do nothing, and return static return * values. This allows the compiler to optimize away dead code without the use of \#ifdef's. * For example: * * ``` * if (ConnectivityMgr().GetWiFiStationMode() != ConnectivityManager::kWiFiStationMode_NotSupported) * { * // ... do something on devices that support WiFi ... * } * ``` */ template class GenericConnectivityManagerImpl_WiFi { public: // ===== Methods that implement the ConnectivityManager abstract interface. ConnectivityManager::WiFiStationMode _GetWiFiStationMode(); CHIP_ERROR _SetWiFiStationMode(ConnectivityManager::WiFiStationMode val); bool _IsWiFiStationEnabled(); bool _IsWiFiStationApplicationControlled(); System::Clock::Timeout _GetWiFiStationReconnectInterval(); CHIP_ERROR _SetWiFiStationReconnectInterval(System::Clock::Timeout val); bool _IsWiFiStationProvisioned(); void _ClearWiFiStationProvision(); ConnectivityManager::WiFiAPMode _GetWiFiAPMode(); CHIP_ERROR _SetWiFiAPMode(ConnectivityManager::WiFiAPMode val); bool _IsWiFiAPActive(); bool _IsWiFiAPApplicationControlled(); void _DemandStartWiFiAP(); void _StopOnDemandWiFiAP(); void _MaintainOnDemandWiFiAP(); System::Clock::Timeout _GetWiFiAPIdleTimeout(); void _SetWiFiAPIdleTimeout(System::Clock::Timeout val); CHIP_ERROR _GetAndLogWiFiStatsCounters(); bool _CanStartWiFiScan(); void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); // TODO ICD rework: ambiguous declaration of _SetPollingInterval when thread and wifi are both build together #if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); #endif static const char * _WiFiStationModeToStr(ConnectivityManager::WiFiStationMode mode); static const char * _WiFiAPModeToStr(ConnectivityManager::WiFiAPMode mode); static const char * _WiFiStationStateToStr(ConnectivityManager::WiFiStationState state); static const char * _WiFiAPStateToStr(ConnectivityManager::WiFiAPState state); protected: enum class ConnectivityFlags : uint16_t { kHaveIPv4InternetConnectivity = 0x0001, kHaveIPv6InternetConnectivity = 0x0002, kAwaitingConnectivity = 0x0010, }; private: ImplClass * Impl() { return static_cast(this); } }; template inline System::Clock::Timeout GenericConnectivityManagerImpl_WiFi::_GetWiFiStationReconnectInterval() { return System::Clock::kZero; } template inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_SetWiFiStationReconnectInterval(System::Clock::Timeout val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline bool GenericConnectivityManagerImpl_WiFi::_IsWiFiStationProvisioned() { return false; } template inline void GenericConnectivityManagerImpl_WiFi::_ClearWiFiStationProvision() {} template inline ConnectivityManager::WiFiAPMode GenericConnectivityManagerImpl_WiFi::_GetWiFiAPMode() { return ConnectivityManager::kWiFiAPMode_NotSupported; } template inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_SetWiFiAPMode(ConnectivityManager::WiFiAPMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline bool GenericConnectivityManagerImpl_WiFi::_IsWiFiAPActive() { return false; } template inline bool GenericConnectivityManagerImpl_WiFi::_IsWiFiAPApplicationControlled() { return false; } template inline void GenericConnectivityManagerImpl_WiFi::_DemandStartWiFiAP() {} template inline void GenericConnectivityManagerImpl_WiFi::_StopOnDemandWiFiAP() {} template inline void GenericConnectivityManagerImpl_WiFi::_MaintainOnDemandWiFiAP() {} template inline System::Clock::Timeout GenericConnectivityManagerImpl_WiFi::_GetWiFiAPIdleTimeout() { return System::Clock::kZero; } template inline void GenericConnectivityManagerImpl_WiFi::_SetWiFiAPIdleTimeout(System::Clock::Timeout val) {} template inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_GetAndLogWiFiStatsCounters() { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline bool GenericConnectivityManagerImpl_WiFi::_CanStartWiFiScan() { return false; } template inline void GenericConnectivityManagerImpl_WiFi::_OnWiFiScanDone() {} template inline void GenericConnectivityManagerImpl_WiFi::_OnWiFiStationProvisionChange() {} #if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD template inline CHIP_ERROR GenericConnectivityManagerImpl_WiFi::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) { return CHIP_ERROR_NOT_IMPLEMENTED; } #endif } // namespace Internal } // namespace DeviceLayer } // namespace chip