| /* | |
| * | |
| * 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 | |
| #if CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT | |
| #include "ThreadStackManagerImpl_OpenThread.h" | |
| #else | |
| #include <memory> | |
| #include <vector> | |
| #include <app/icd/server/ICDServerConfig.h> | |
| #include <lib/core/Optional.h> | |
| #include <lib/support/ThreadOperationalDataset.h> | |
| #include <platform/GLibTypeDeleter.h> | |
| #include <platform/Linux/dbus/openthread/DBusOpenthread.h> | |
| #include <platform/NetworkCommissioning.h> | |
| #include <platform/internal/CHIPDeviceLayerInternal.h> | |
| #include <platform/internal/DeviceNetworkInfo.h> | |
| namespace chip { | |
| template <> | |
| struct GAutoPtrDeleter<OpenthreadBorderRouter> | |
| { | |
| using deleter = GObjectDeleter; | |
| }; | |
| namespace DeviceLayer { | |
| class ThreadStackManagerImpl : public ThreadStackManager | |
| { | |
| public: | |
| ThreadStackManagerImpl(); | |
| #if CONFIG_BUILD_FOR_HOST_UNIT_TEST | |
| void SetThreadEnabledForTest(bool enabled) { mThreadEnabledForTest.SetValue(enabled); } | |
| void SetThreadAttachedForTest(bool attached) { mAttached = attached; } | |
| void ResetThreadStateForTest() | |
| { | |
| mThreadEnabledForTest.ClearValue(); | |
| mAttached = false; | |
| } | |
| #endif | |
| void | |
| SetNetworkStatusChangeCallback(NetworkCommissioning::Internal::BaseDriver::NetworkStatusChangeCallback * statusChangeCallback) | |
| { | |
| mpStatusChangeCallback = statusChangeCallback; | |
| } | |
| CHIP_ERROR _InitThreadStack(); | |
| void _ProcessThreadActivity(); | |
| CHIP_ERROR _StartThreadTask() { return CHIP_NO_ERROR; } // Intentionally left blank | |
| void _LockThreadStack() {} // Intentionally left blank | |
| bool _TryLockThreadStack() { return false; } // Intentionally left blank | |
| void _UnlockThreadStack() {} // Intentionally left blank | |
| #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT | |
| void _WaitOnSrpClearAllComplete() {} | |
| void _NotifySrpClearAllComplete() {} | |
| #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD_SRP_CLIENT | |
| bool _HaveRouteToAddress(const Inet::IPAddress & destAddr); | |
| void _OnPlatformEvent(const ChipDeviceEvent * event); | |
| CHIP_ERROR _GetThreadProvision(Thread::OperationalDataset & dataset); | |
| CHIP_ERROR _SetThreadProvision(ByteSpan netInfo); | |
| void _OnNetworkScanFinished(GAsyncResult * res); | |
| static void _OnNetworkScanFinished(GObject * source_object, GAsyncResult * res, gpointer user_data); | |
| CHIP_ERROR GetExtendedPanId(uint8_t extPanId[Thread::kSizeExtendedPanId]); | |
| void _ErasePersistentInfo(); | |
| bool _IsThreadProvisioned(); | |
| bool _IsThreadEnabled(); | |
| bool _IsThreadAttached() const; | |
| CHIP_ERROR _AttachToThreadNetwork(const Thread::OperationalDataset & dataset, | |
| NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * callback); | |
| CHIP_ERROR _SetThreadEnabled(bool val); | |
| void _OnThreadAttachFinished(void); | |
| void _UpdateNetworkStatus(); | |
| static void _OnThreadBrAttachFinished(GObject * source_object, GAsyncResult * res, gpointer user_data); | |
| ConnectivityManager::ThreadDeviceType _GetThreadDeviceType(); | |
| CHIP_ERROR _SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType); | |
| #if CHIP_CONFIG_ENABLE_ICD_SERVER | |
| CHIP_ERROR _SetPollingInterval(System::Clock::Milliseconds32 pollingInterval); | |
| #endif /* CHIP_CONFIG_ENABLE_ICD_SERVER */ | |
| CHIP_ERROR _GetPrimary802154MACAddress(uint8_t * buf); | |
| CHIP_ERROR _GetThreadVersion(uint16_t & version); | |
| #if CHIP_DEVICE_CONFIG_ENABLE_THREAD_MESHCOP | |
| CHIP_ERROR _RendezvousStart(RendezvousAnnouncementRequestCallback announcementRequest, void * context) | |
| { | |
| return CHIP_ERROR_NOT_IMPLEMENTED; | |
| } | |
| void _CancelRendezvousAnnouncement() {} | |
| void _RendezvousStop() {} | |
| #endif | |
| void _ResetThreadNetworkDiagnosticsCounts(); | |
| CHIP_ERROR _StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback); | |
| ~ThreadStackManagerImpl() = default; | |
| static ThreadStackManagerImpl sInstance; | |
| private: | |
| static constexpr char kDBusOpenThreadService[] = "io.openthread.BorderRouter.wpan0"; | |
| static constexpr char kDBusOpenThreadObjectPath[] = "/io/openthread/BorderRouter/wpan0"; | |
| static constexpr char kOpenthreadDeviceRoleDisabled[] = "disabled"; | |
| static constexpr char kOpenthreadDeviceRoleDetached[] = "detached"; | |
| static constexpr char kOpenthreadDeviceRoleChild[] = "child"; | |
| static constexpr char kOpenthreadDeviceRoleRouter[] = "router"; | |
| static constexpr char kOpenthreadDeviceRoleLeader[] = "leader"; | |
| static constexpr char kPropertyDeviceRole[] = "DeviceRole"; | |
| struct ThreadNetworkScanned | |
| { | |
| uint16_t panId; | |
| uint64_t extendedPanId; | |
| uint8_t networkName[16]; | |
| uint8_t networkNameLen; | |
| uint16_t channel; | |
| uint8_t version; | |
| uint64_t extendedAddress; | |
| int8_t rssi; | |
| uint8_t lqi; | |
| }; | |
| GAutoPtr<OpenthreadBorderRouter> mProxy; | |
| static CHIP_ERROR GLibMatterContextInitThreadStack(ThreadStackManagerImpl * self); | |
| static CHIP_ERROR GLibMatterContextCallAttach(ThreadStackManagerImpl * self); | |
| static CHIP_ERROR GLibMatterContextCallScan(ThreadStackManagerImpl * self); | |
| static void OnDbusPropertiesChanged(OpenthreadBorderRouter * proxy, GVariant * changed_properties, | |
| const gchar * const * invalidated_properties, gpointer user_data); | |
| void ThreadDeviceRoleChangedHandler(const gchar * role); | |
| Thread::OperationalDataset mDataset = {}; | |
| NetworkCommissioning::ThreadDriver::ScanCallback * mpScanCallback; | |
| NetworkCommissioning::Internal::WirelessDriver::ConnectCallback * mpConnectCallback; | |
| NetworkCommissioning::Internal::BaseDriver::NetworkStatusChangeCallback * mpStatusChangeCallback = nullptr; | |
| bool mAttached; | |
| #if CONFIG_BUILD_FOR_HOST_UNIT_TEST | |
| chip::Optional<bool> mThreadEnabledForTest; | |
| #endif | |
| uint8_t mExtendedAddress[8]; | |
| }; | |
| inline void ThreadStackManagerImpl::_OnThreadAttachFinished(void) | |
| { | |
| // stub for ThreadStackManager.h | |
| } | |
| } // namespace DeviceLayer | |
| } // namespace chip | |
| #endif // CHIP_SYSTEM_CONFIG_USE_OPENTHREAD_ENDPOINT |