/* * * Copyright (c) 2020 Project CHIP Authors * Copyright (c) 2019 Nest Labs, Inc. * * 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 don't have WiFi. */ #pragma once 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_NoWiFi { public: // ===== Methods that implement the ConnectivityManager abstract interface. ConnectivityManager::WiFiStationMode _GetWiFiStationMode(void); CHIP_ERROR _SetWiFiStationMode(ConnectivityManager::WiFiStationMode val); bool _IsWiFiStationEnabled(void); bool _IsWiFiStationApplicationControlled(void); bool _IsWiFiStationConnected(void); System::Clock::Timeout _GetWiFiStationReconnectInterval(void); CHIP_ERROR _SetWiFiStationReconnectInterval(System::Clock::Timeout val); bool _IsWiFiStationProvisioned(void); void _ClearWiFiStationProvision(void); ConnectivityManager::WiFiAPMode _GetWiFiAPMode(void); CHIP_ERROR _SetWiFiAPMode(ConnectivityManager::WiFiAPMode val); bool _IsWiFiAPActive(void); bool _IsWiFiAPApplicationControlled(void); void _DemandStartWiFiAP(void); void _StopOnDemandWiFiAP(void); void _MaintainOnDemandWiFiAP(void); System::Clock::Timeout _GetWiFiAPIdleTimeout(void); void _SetWiFiAPIdleTimeout(System::Clock::Timeout val); CHIP_ERROR _GetAndLogWiFiStatsCounters(void); bool _CanStartWiFiScan(); void _OnWiFiScanDone(); void _OnWiFiStationProvisionChange(); 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); // TODO ICD rework: ambiguous declaration of _SetPollingInterval when thread and no-wifi are both built together #if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); #endif private: ImplClass * Impl() { return static_cast(this); } }; template inline ConnectivityManager::WiFiStationMode GenericConnectivityManagerImpl_NoWiFi::_GetWiFiStationMode(void) { return ConnectivityManager::kWiFiStationMode_NotSupported; } template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_SetWiFiStationMode(ConnectivityManager::WiFiStationMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiStationEnabled(void) { return false; } template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiStationConnected(void) { return false; } template inline System::Clock::Timeout GenericConnectivityManagerImpl_NoWiFi::_GetWiFiStationReconnectInterval(void) { return System::Clock::kZero; } template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_SetWiFiStationReconnectInterval(System::Clock::Timeout val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiStationProvisioned(void) { return false; } template inline void GenericConnectivityManagerImpl_NoWiFi::_ClearWiFiStationProvision(void) {} template inline ConnectivityManager::WiFiAPMode GenericConnectivityManagerImpl_NoWiFi::_GetWiFiAPMode(void) { return ConnectivityManager::kWiFiAPMode_NotSupported; } template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_SetWiFiAPMode(ConnectivityManager::WiFiAPMode val) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiAPActive(void) { return false; } template inline bool GenericConnectivityManagerImpl_NoWiFi::_IsWiFiAPApplicationControlled(void) { return false; } template inline void GenericConnectivityManagerImpl_NoWiFi::_DemandStartWiFiAP(void) {} template inline void GenericConnectivityManagerImpl_NoWiFi::_StopOnDemandWiFiAP(void) {} template inline void GenericConnectivityManagerImpl_NoWiFi::_MaintainOnDemandWiFiAP(void) {} template inline System::Clock::Timeout GenericConnectivityManagerImpl_NoWiFi::_GetWiFiAPIdleTimeout(void) { return System::Clock::kZero; } template inline void GenericConnectivityManagerImpl_NoWiFi::_SetWiFiAPIdleTimeout(System::Clock::Timeout val) {} template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_GetAndLogWiFiStatsCounters(void) { return CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE; } template inline bool GenericConnectivityManagerImpl_NoWiFi::_CanStartWiFiScan() { return false; } template inline void GenericConnectivityManagerImpl_NoWiFi::_OnWiFiScanDone() {} template inline void GenericConnectivityManagerImpl_NoWiFi::_OnWiFiStationProvisionChange() {} template inline const char * GenericConnectivityManagerImpl_NoWiFi::_WiFiStationModeToStr(ConnectivityManager::WiFiStationMode mode) { return nullptr; } template inline const char * GenericConnectivityManagerImpl_NoWiFi::_WiFiAPModeToStr(ConnectivityManager::WiFiAPMode mode) { return nullptr; } template inline const char * GenericConnectivityManagerImpl_NoWiFi::_WiFiStationStateToStr(ConnectivityManager::WiFiStationState state) { return nullptr; } template inline const char * GenericConnectivityManagerImpl_NoWiFi::_WiFiAPStateToStr(ConnectivityManager::WiFiAPState state) { return nullptr; } #if CHIP_CONFIG_ENABLE_ICD_SERVER && !CHIP_DEVICE_CONFIG_ENABLE_THREAD template inline CHIP_ERROR GenericConnectivityManagerImpl_NoWiFi::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) { return CHIP_ERROR_NOT_IMPLEMENTED; } #endif } // namespace Internal } // namespace DeviceLayer } // namespace chip