diff --git a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp index 21c44dd00279e3..707e1f710743ec 100644 --- a/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp +++ b/src/platform/OpenThread/GenericThreadStackManagerImpl_OpenThread.hpp @@ -149,6 +149,7 @@ void GenericThreadStackManagerImpl_OpenThread::_ProcessThreadActivity template bool GenericThreadStackManagerImpl_OpenThread::_HaveRouteToAddress(const Inet::IPAddress & destAddr) { + VerifyOrReturnValue(mOTInst, false); bool res = false; // Lock OpenThread @@ -233,6 +234,7 @@ void GenericThreadStackManagerImpl_OpenThread::_OnPlatformEvent(const template bool GenericThreadStackManagerImpl_OpenThread::_IsThreadEnabled(void) { + VerifyOrReturnValue(mOTInst, false); otDeviceRole curRole; Impl()->LockThreadStack(); @@ -245,6 +247,7 @@ bool GenericThreadStackManagerImpl_OpenThread::_IsThreadEnabled(void) template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadEnabled(bool val) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); otError otErr = OT_ERROR_NONE; Impl()->LockThreadStack(); @@ -279,6 +282,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadEnable template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadProvision(ByteSpan netInfo) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); otError otErr = OT_ERROR_FAILED; otOperationalDatasetTlvs tlvs; @@ -305,6 +309,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadProvis template bool GenericThreadStackManagerImpl_OpenThread::_IsThreadProvisioned(void) { + VerifyOrReturnValue(mOTInst, false); bool provisioned; Impl()->LockThreadStack(); @@ -317,6 +322,7 @@ bool GenericThreadStackManagerImpl_OpenThread::_IsThreadProvisioned(v template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetThreadProvision(Thread::OperationalDataset & dataset) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); VerifyOrReturnError(Impl()->IsThreadProvisioned(), CHIP_ERROR_INCORRECT_STATE); otOperationalDatasetTlvs datasetTlv; @@ -336,6 +342,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetThreadProvis template bool GenericThreadStackManagerImpl_OpenThread::_IsThreadAttached(void) { + VerifyOrReturnValue(mOTInst, false); otDeviceRole curRole; Impl()->LockThreadStack(); @@ -380,6 +387,7 @@ template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_StartThreadScan(NetworkCommissioning::ThreadDriver::ScanCallback * callback) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR error = CHIP_NO_ERROR; #if CHIP_CONFIG_ENABLE_ICD_SERVER otLinkModeConfig linkMode; @@ -488,6 +496,7 @@ void GenericThreadStackManagerImpl_OpenThread::_OnNetworkScanFinished template ConnectivityManager::ThreadDeviceType GenericThreadStackManagerImpl_OpenThread::_GetThreadDeviceType(void) { + VerifyOrReturnValue(mOTInst, ConnectivityManager::kThreadDeviceType_NotSupported); ConnectivityManager::ThreadDeviceType deviceType; Impl()->LockThreadStack(); @@ -524,6 +533,7 @@ template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(ConnectivityManager::ThreadDeviceType deviceType) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; otLinkModeConfig linkMode; @@ -612,6 +622,7 @@ GenericThreadStackManagerImpl_OpenThread::_SetThreadDeviceType(Connec template bool GenericThreadStackManagerImpl_OpenThread::_HaveMeshConnectivity(void) { + VerifyOrReturnValue(mOTInst, false); bool res; otDeviceRole curRole; @@ -660,6 +671,7 @@ bool GenericThreadStackManagerImpl_OpenThread::_HaveMeshConnectivity( template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThreadStatsCounters(void) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; otError otErr; otOperationalDataset activeDataset; @@ -754,6 +766,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThread template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThreadTopologyMinimal(void) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; #if CHIP_PROGRESS_LOGGING @@ -822,6 +835,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThread template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThreadTopologyFull() { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; #if CHIP_PROGRESS_LOGGING @@ -991,6 +1005,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetAndLogThread template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetPrimary802154MACAddress(uint8_t * buf) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); const otExtAddress * extendedAddr = otLinkGetExtendedAddress(mOTInst); memcpy(buf, extendedAddr, sizeof(otExtAddress)); return CHIP_NO_ERROR; @@ -999,6 +1014,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetPrimary80215 template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetExternalIPv6Address(chip::Inet::IPAddress & addr) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); const otNetifAddress * otAddresses = otIp6GetUnicastAddresses(mOTInst); // Look only for the global unicast addresses, not internally assigned by Thread. @@ -1034,6 +1050,7 @@ void GenericThreadStackManagerImpl_OpenThread::_ResetThreadNetworkDia template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_GetPollPeriod(uint32_t & buf) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); Impl()->LockThreadStack(); buf = otLinkGetPollPeriod(mOTInst); Impl()->UnlockThreadStack(); @@ -1121,6 +1138,7 @@ bool GenericThreadStackManagerImpl_OpenThread::IsThreadInterfaceUpNoL template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetPollingInterval(System::Clock::Milliseconds32 pollingInterval) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR err = CHIP_NO_ERROR; Impl()->LockThreadStack(); @@ -1173,6 +1191,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetPollingInter template void GenericThreadStackManagerImpl_OpenThread::_ErasePersistentInfo(void) { + VerifyOrReturn(mOTInst); ChipLogProgress(DeviceLayer, "Erasing Thread persistent info..."); Impl()->LockThreadStack(); otThreadSetEnabled(mOTInst, false); @@ -1205,6 +1224,7 @@ void GenericThreadStackManagerImpl_OpenThread::OnJoinerComplete(otErr template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_JoinerStart(void) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR error = CHIP_NO_ERROR; Impl()->LockThreadStack(); @@ -1254,6 +1274,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_JoinerStart(voi template void GenericThreadStackManagerImpl_OpenThread::_UpdateNetworkStatus() { + VerifyOrReturn(mOTInst); // Thread is not enabled, then we are not trying to connect to the network. VerifyOrReturn(ThreadStackMgrImpl().IsThreadEnabled() && mpStatusChangeCallback != nullptr); @@ -1636,6 +1657,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_RemoveInvalidSr template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_ClearAllSrpHostAndServices() { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR error = CHIP_NO_ERROR; Impl()->LockThreadStack(); if (!mIsSrpClearAllRequested) @@ -1684,6 +1706,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_SetupSrpHost(co template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_ClearSrpHost(const char * aHostName) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR error = CHIP_NO_ERROR; Impl()->LockThreadStack(); @@ -1798,6 +1821,7 @@ CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::FromOtDnsRespons template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::ResolveAddress(intptr_t context, otDnsAddressCallback callback) { + VerifyOrReturnError(ThreadStackMgrImpl().OTInstance(), CHIP_ERROR_INCORRECT_STATE); DnsResult * dnsResult = reinterpret_cast(context); ThreadStackMgrImpl().LockThreadStack(); @@ -1952,6 +1976,7 @@ template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_DnsBrowse(const char * aServiceName, DnsBrowseCallback aCallback, void * aContext) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR error = CHIP_NO_ERROR; Impl()->LockThreadStack(); @@ -2062,6 +2087,7 @@ template CHIP_ERROR GenericThreadStackManagerImpl_OpenThread::_DnsResolve(const char * aServiceName, const char * aInstanceName, DnsResolveCallback aCallback, void * aContext) { + VerifyOrReturnError(mOTInst, CHIP_ERROR_INCORRECT_STATE); CHIP_ERROR error = CHIP_NO_ERROR; Impl()->LockThreadStack();