/* * * Copyright (c) 2020 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. */ #pragma once #include #include #include #include #if INET_CONFIG_ENABLE_TCP_ENDPOINT #include #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI #include #include #else #include #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #include #else #include #endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #if CHIP_DEVICE_CONFIG_ENABLE_THREAD #include #else #include #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD namespace chip { namespace DeviceLayer { /** * Concrete implementation of the ConnectivityManager singleton object for mbed platforms. */ class ConnectivityManagerImpl final : public ConnectivityManager, public Internal::GenericConnectivityManagerImpl, public Internal::GenericConnectivityManagerImpl_UDP, #if INET_CONFIG_ENABLE_TCP_ENDPOINT public Internal::GenericConnectivityManagerImpl_TCP, #endif #if CHIP_DEVICE_CONFIG_ENABLE_WIFI public Internal::GenericConnectivityManagerImpl_WiFi, #else public Internal::GenericConnectivityManagerImpl_NoWiFi, #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI #if CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE public Internal::GenericConnectivityManagerImpl_BLE, #else public Internal::GenericConnectivityManagerImpl_NoBLE, #endif // CHIP_DEVICE_CONFIG_ENABLE_CHIPOBLE #if CHIP_DEVICE_CONFIG_ENABLE_THREAD public Internal::GenericConnectivityManagerImpl_Thread, #else public Internal::GenericConnectivityManagerImpl_NoThread #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD { // Allow the ConnectivityManager interface class to delegate method calls to // the implementation methods provided by this class. friend class ConnectivityManager; private: CHIP_ERROR _Init(void); void _OnPlatformEvent(const ChipDeviceEvent * event); #if CHIP_DEVICE_CONFIG_ENABLE_WIFI private: CHIP_ERROR InitWiFi(void); void OnWiFiPlatformEvent(const ChipDeviceEvent * event); void ChangeWiFiStationState(WiFiStationState newState); WiFiStationMode _GetWiFiStationMode(); CHIP_ERROR _SetWiFiStationMode(WiFiStationMode val); bool _IsWiFiStationEnabled(); bool _IsWiFiStationApplicationControlled(); System::Clock::Timeout _GetWiFiStationReconnectInterval(); CHIP_ERROR _SetWiFiStationReconnectInterval(System::Clock::Timeout val); bool _IsWiFiStationProvisioned(); bool _IsWiFiStationConnected(void); void _ClearWiFiStationProvision(); // ===== Members for internal use by the following friends. WiFiStationMode mWiFiStationMode = kWiFiStationMode_NotSupported; WiFiStationState mWiFiStationState = kWiFiStationState_NotConnected; System::Clock::Timeout mWiFiStationReconnectInterval = System::Clock::Milliseconds32(CHIP_DEVICE_CONFIG_WIFI_STATION_RECONNECT_INTERVAL); bool mIsProvisioned = false; #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI friend ConnectivityManager & ConnectivityMgr(void); friend ConnectivityManagerImpl & ConnectivityMgrImpl(void); static ConnectivityManagerImpl sInstance; public: CHIP_ERROR PostEvent(const ChipDeviceEvent * event, bool die); void AddTask(AsyncWorkFunct workFunct, intptr_t arg); void AddQueueEvent(void (*func)(nsapi_event_t, intptr_t), nsapi_event_t event, intptr_t data); }; #if CHIP_DEVICE_CONFIG_ENABLE_WIFI inline ConnectivityManager::WiFiStationMode ConnectivityManagerImpl::_GetWiFiStationMode(void) { return mWiFiStationMode; } inline bool ConnectivityManagerImpl::_IsWiFiStationEnabled(void) { return mWiFiStationMode == kWiFiStationMode_Enabled; } inline bool ConnectivityManagerImpl::_IsWiFiStationApplicationControlled(void) { return mWiFiStationMode == kWiFiStationMode_ApplicationControlled; } inline System::Clock::Timeout ConnectivityManagerImpl::_GetWiFiStationReconnectInterval(void) { return mWiFiStationReconnectInterval; } inline bool ConnectivityManagerImpl::_IsWiFiStationProvisioned(void) { return mIsProvisioned; } inline bool ConnectivityManagerImpl::_IsWiFiStationConnected(void) { return mWiFiStationState == kWiFiStationState_Connected; } #endif // CHIP_DEVICE_CONFIG_ENABLE_WIFI /** * Returns the public interface of the ConnectivityManager singleton object. * * chip applications should use this to access features of the ConnectivityManager object * that are common to all platforms. */ inline ConnectivityManager & ConnectivityMgr(void) { return ConnectivityManagerImpl::sInstance; } /** * Returns the platform-specific implementation of the ConnectivityManager singleton object. * * chip applications can use this to gain access to features of the ConnectivityManager * that are specific to the mbed platform. */ inline ConnectivityManagerImpl & ConnectivityMgrImpl(void) { return ConnectivityManagerImpl::sInstance; } } // namespace DeviceLayer } // namespace chip