diff --git a/examples/all-clusters-app/esp32/main/main.cpp b/examples/all-clusters-app/esp32/main/main.cpp index 9e6693bca9c0c8..fbedc0b0b2e1d4 100644 --- a/examples/all-clusters-app/esp32/main/main.cpp +++ b/examples/all-clusters-app/esp32/main/main.cpp @@ -453,7 +453,7 @@ class SetupListModel : public TouchesMatterStackModel } else if (i == 1) { - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } else if (i == 2) { diff --git a/examples/light-switch-app/efr32/src/AppTask.cpp b/examples/light-switch-app/efr32/src/AppTask.cpp index 31ed0d912b41cc..c8bdd19efcefc3 100644 --- a/examples/light-switch-app/efr32/src/AppTask.cpp +++ b/examples/light-switch-app/efr32/src/AppTask.cpp @@ -411,7 +411,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lighting-app/efr32/src/AppTask.cpp b/examples/lighting-app/efr32/src/AppTask.cpp index 919472c5fd26e1..1ed50c2a8bb952 100644 --- a/examples/lighting-app/efr32/src/AppTask.cpp +++ b/examples/lighting-app/efr32/src/AppTask.cpp @@ -495,7 +495,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lighting-app/mbed/main/AppTask.cpp b/examples/lighting-app/mbed/main/AppTask.cpp index d34f25d2e58bd5..95499a67efbf1b 100644 --- a/examples/lighting-app/mbed/main/AppTask.cpp +++ b/examples/lighting-app/mbed/main/AppTask.cpp @@ -399,7 +399,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) // Actually trigger Factory Reset ChipLogProgress(NotSpecified, "Factory Reset initiated"); sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lighting-app/nrfconnect/main/AppTask.cpp b/examples/lighting-app/nrfconnect/main/AppTask.cpp index c2418d6b089d75..d2f65991daffd0 100644 --- a/examples/lighting-app/nrfconnect/main/AppTask.cpp +++ b/examples/lighting-app/nrfconnect/main/AppTask.cpp @@ -318,7 +318,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp index acf053e0ac2cd2..dc6e355423567d 100644 --- a/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/lighting-app/nxp/k32w/k32w0/main/AppTask.cpp @@ -384,7 +384,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) K32W_LOG("Device will factory reset..."); // Actually trigger Factory Reset - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } void AppTask::ResetActionEventHandler(AppEvent * aEvent) diff --git a/examples/lighting-app/p6/src/AppTask.cpp b/examples/lighting-app/p6/src/AppTask.cpp index 8e04f710716515..ab50aefb66f9c3 100644 --- a/examples/lighting-app/p6/src/AppTask.cpp +++ b/examples/lighting-app/p6/src/AppTask.cpp @@ -335,7 +335,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = Function::kNoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lighting-app/qpg/src/AppTask.cpp b/examples/lighting-app/qpg/src/AppTask.cpp index fb8f111c803b9b..9756e8f97cad7a 100644 --- a/examples/lighting-app/qpg/src/AppTask.cpp +++ b/examples/lighting-app/qpg/src/AppTask.cpp @@ -305,7 +305,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lighting-app/telink/src/AppTask.cpp b/examples/lighting-app/telink/src/AppTask.cpp index fc2be9cf84ab4a..5602acc36ca53d 100644 --- a/examples/lighting-app/telink/src/AppTask.cpp +++ b/examples/lighting-app/telink/src/AppTask.cpp @@ -215,7 +215,7 @@ void AppTask::FactoryResetButtonEventHandler(void) void AppTask::FactoryResetHandler(AppEvent * aEvent) { LOG_INF("Factory Reset triggered."); - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } void AppTask::StartThreadButtonEventHandler(void) diff --git a/examples/lock-app/efr32/src/AppTask.cpp b/examples/lock-app/efr32/src/AppTask.cpp index f12c1d02fa4874..59a5c7b22c6654 100644 --- a/examples/lock-app/efr32/src/AppTask.cpp +++ b/examples/lock-app/efr32/src/AppTask.cpp @@ -363,7 +363,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lock-app/esp32/main/AppTask.cpp b/examples/lock-app/esp32/main/AppTask.cpp index df3cd9cf3437c8..7b5a727b4dab54 100644 --- a/examples/lock-app/esp32/main/AppTask.cpp +++ b/examples/lock-app/esp32/main/AppTask.cpp @@ -298,7 +298,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lock-app/mbed/main/AppTask.cpp b/examples/lock-app/mbed/main/AppTask.cpp index 9ddcba2a9d820a..283efadca06fc6 100644 --- a/examples/lock-app/mbed/main/AppTask.cpp +++ b/examples/lock-app/mbed/main/AppTask.cpp @@ -395,7 +395,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) // Actually trigger Factory Reset ChipLogProgress(NotSpecified, "Factory Reset initiated"); sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lock-app/nrfconnect/main/AppTask.cpp b/examples/lock-app/nrfconnect/main/AppTask.cpp index c975c78c2f8f14..794102bf3d1ec8 100644 --- a/examples/lock-app/nrfconnect/main/AppTask.cpp +++ b/examples/lock-app/nrfconnect/main/AppTask.cpp @@ -268,7 +268,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp b/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp index fe96162c112cd9..43ec8f51af9080 100644 --- a/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/lock-app/nxp/k32w/k32w0/main/AppTask.cpp @@ -357,7 +357,7 @@ void AppTask::FunctionTimerEventHandler(void * aGenericEvent) K32W_LOG("Device will factory reset..."); // Actually trigger Factory Reset - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } void AppTask::ResetActionEventHandler(void * aGenericEvent) diff --git a/examples/lock-app/p6/src/AppTask.cpp b/examples/lock-app/p6/src/AppTask.cpp index 74c40151eefe95..a4e0cbb5e35739 100644 --- a/examples/lock-app/p6/src/AppTask.cpp +++ b/examples/lock-app/p6/src/AppTask.cpp @@ -331,7 +331,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * event) { // Actually trigger Factory Reset sAppTask.mFunction = Function::kNoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/lock-app/qpg/src/AppTask.cpp b/examples/lock-app/qpg/src/AppTask.cpp index 266b96a188dbf7..11e4cc0c067648 100644 --- a/examples/lock-app/qpg/src/AppTask.cpp +++ b/examples/lock-app/qpg/src/AppTask.cpp @@ -315,7 +315,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/ota-requestor-app/efr32/src/AppTask.cpp b/examples/ota-requestor-app/efr32/src/AppTask.cpp index 0c76c321c48698..4db969933f60a5 100644 --- a/examples/ota-requestor-app/efr32/src/AppTask.cpp +++ b/examples/ota-requestor-app/efr32/src/AppTask.cpp @@ -352,7 +352,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/ota-requestor-app/mbed/main/AppTask.cpp b/examples/ota-requestor-app/mbed/main/AppTask.cpp index 1518bacc8de181..f312c17f5690cd 100644 --- a/examples/ota-requestor-app/mbed/main/AppTask.cpp +++ b/examples/ota-requestor-app/mbed/main/AppTask.cpp @@ -416,7 +416,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) sAppTask.CancelTimer(kFunction_Button_1); sAppTask.mFunction[kFunction_Button_1] = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } break; case kFunction_Button_2: diff --git a/examples/platform/linux/AppMain.cpp b/examples/platform/linux/AppMain.cpp index c47a5b283c9a9f..5d0673560cac17 100644 --- a/examples/platform/linux/AppMain.cpp +++ b/examples/platform/linux/AppMain.cpp @@ -99,26 +99,26 @@ void OnSignalHandler(int signum) // The BootReason attribute SHALL indicate the reason for the Node’s most recent boot, the real usecase // for this attribute is embedded system. In Linux simulation, we use different signals to tell the current // running process to terminate with different reasons. - DiagnosticDataProvider::BootReasonType bootReason = DiagnosticDataProvider::BootReasonType::Unspecified; + BootReasonType bootReason = BootReasonType::Unspecified; switch (signum) { case SIGVTALRM: - bootReason = DiagnosticDataProvider::BootReasonType::PowerOnReboot; + bootReason = BootReasonType::PowerOnReboot; break; case SIGALRM: - bootReason = DiagnosticDataProvider::BootReasonType::BrownOutReset; + bootReason = BootReasonType::BrownOutReset; break; case SIGILL: - bootReason = DiagnosticDataProvider::BootReasonType::SoftwareWatchdogReset; + bootReason = BootReasonType::SoftwareWatchdogReset; break; case SIGTRAP: - bootReason = DiagnosticDataProvider::BootReasonType::HardwareWatchdogReset; + bootReason = BootReasonType::HardwareWatchdogReset; break; case SIGIO: - bootReason = DiagnosticDataProvider::BootReasonType::SoftwareUpdateCompleted; + bootReason = BootReasonType::SoftwareUpdateCompleted; break; case SIGINT: - bootReason = DiagnosticDataProvider::BootReasonType::SoftwareReset; + bootReason = BootReasonType::SoftwareReset; break; default: IgnoreUnusedVariable(bootReason); diff --git a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp index 199b8f593c9dd8..f4ed5ff6ff60f5 100644 --- a/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -352,7 +352,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } else if (AppEvent::kAppEventButtonType_LongPressed == aEvent->ButtonEvent.Type) { - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } break; diff --git a/examples/pump-app/nrfconnect/main/AppTask.cpp b/examples/pump-app/nrfconnect/main/AppTask.cpp index 50dbb5224b5533..832b103a68cac9 100644 --- a/examples/pump-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-app/nrfconnect/main/AppTask.cpp @@ -267,7 +267,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp index ee332a4dadbd10..e394f5574f58df 100644 --- a/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp +++ b/examples/pump-controller-app/cc13x2x7_26x2x7/main/AppTask.cpp @@ -335,7 +335,7 @@ void AppTask::DispatchEvent(AppEvent * aEvent) } else if (AppEvent::kAppEventButtonType_LongPressed == aEvent->ButtonEvent.Type) { - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } break; diff --git a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp index 267bfaf7fa5926..1d8d85b3955921 100644 --- a/examples/pump-controller-app/nrfconnect/main/AppTask.cpp +++ b/examples/pump-controller-app/nrfconnect/main/AppTask.cpp @@ -263,7 +263,8 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) { // Actually trigger Factory Reset sAppTask.mFunction = kFunction_NoneSelected; - ConfigurationMgr().InitiateFactoryReset(); + + chip::Server::GetInstance().ScheduleFactoryReset(); } } diff --git a/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp b/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp index 77c6107b63fed1..33eb5e72ccb29e 100644 --- a/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp +++ b/examples/shell/nxp/k32w/k32w0/main/AppTask.cpp @@ -286,7 +286,7 @@ void AppTask::FunctionTimerEventHandler(AppEvent * aEvent) K32W_LOG("Device will factory reset..."); // Actually trigger Factory Reset - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); } void AppTask::ResetActionEventHandler(AppEvent * aEvent) diff --git a/examples/window-app/common/src/WindowApp.cpp b/examples/window-app/common/src/WindowApp.cpp index 1fdb092bbd3861..921d171e960cb0 100644 --- a/examples/window-app/common/src/WindowApp.cpp +++ b/examples/window-app/common/src/WindowApp.cpp @@ -213,7 +213,7 @@ void WindowApp::DispatchEvent(const WindowApp::Event & event) break; case EventId::Reset: - ConfigurationMgr().InitiateFactoryReset(); + chip::Server::GetInstance().ScheduleFactoryReset(); break; case EventId::UpPressed: diff --git a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp index 9283182c9d9dcf..0a14cbf53e5055 100644 --- a/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp +++ b/src/app/clusters/general-diagnostics-server/general-diagnostics-server.cpp @@ -36,10 +36,10 @@ using chip::DeviceLayer::ConnectivityMgr; using chip::DeviceLayer::DiagnosticDataProvider; using chip::DeviceLayer::GetDiagnosticDataProvider; -static_assert(sizeof(DiagnosticDataProvider::BootReasonType) == sizeof(EmberAfBootReasonType), +static_assert(sizeof(chip::DeviceLayer::BootReasonType) == sizeof(EmberAfBootReasonType), "BootReasonType size doesn't match EmberAfBootReasonType size"); -static_assert(static_cast(DiagnosticDataProvider::BootReasonType::Unspecified) == EMBER_ZCL_BOOT_REASON_TYPE_UNSPECIFIED && - static_cast(DiagnosticDataProvider::BootReasonType::SoftwareReset) == +static_assert(static_cast(chip::DeviceLayer::BootReasonType::Unspecified) == EMBER_ZCL_BOOT_REASON_TYPE_UNSPECIFIED && + static_cast(chip::DeviceLayer::BootReasonType::SoftwareReset) == EMBER_ZCL_BOOT_REASON_TYPE_SOFTWARE_RESET, "BootReasonType and EmberAfBootReasonType values does not match."); @@ -195,11 +195,22 @@ class GeneralDiagnosticsDelegate : public DeviceLayer::ConnectivityManagerDelega } // Gets called when the device has been rebooted. - void OnDeviceRebooted() override + void OnDeviceRebooted(chip::DeviceLayer::BootReasonType bootReason) override { ChipLogProgress(Zcl, "GeneralDiagnosticsDelegate: OnDeviceRebooted"); ReportAttributeOnAllEndpoints(GeneralDiagnostics::Attributes::BootReasons::Id); + + // GeneralDiagnostics cluster should exist only for endpoint 0. + + Events::BootReason::Type event{ static_cast(bootReason) }; + EventNumber eventNumber; + + CHIP_ERROR err = LogEvent(event, 0, eventNumber, EventOptions::Type::kUrgent); + if (CHIP_NO_ERROR != err) + { + ChipLogError(Zcl, "GeneralDiagnosticsDelegate: Failed to record BootReason event: %" CHIP_ERROR_FORMAT, err.Format()); + } } // Get called when the Node detects a hardware fault has been raised. diff --git a/src/app/reporting/Engine.h b/src/app/reporting/Engine.h index 9b8c74e1c08ffb..c74cc26d881ad6 100644 --- a/src/app/reporting/Engine.h +++ b/src/app/reporting/Engine.h @@ -120,6 +120,8 @@ class Engine uint32_t GetNumReportsInFlight() { return mNumReportsInFlight; } + void ScheduleUrgentEventDeliverySync(); + private: friend class TestReportingEngine; /** @@ -165,7 +167,6 @@ class Engine CHIP_ERROR ScheduleUrgentEventDelivery(ConcreteEventPath & aPath); CHIP_ERROR ScheduleBufferPressureEventDelivery(uint32_t aBytesWritten); void GetMinEventLogPosition(uint32_t & aMinLogPosition); - void ScheduleUrgentEventDeliverySync(); /** * If the provided path is a superset of our of our existing paths, update that existing path to match the diff --git a/src/app/server/Server.cpp b/src/app/server/Server.cpp index 5c7bd05ca17ef8..499e8f6af1d490 100644 --- a/src/app/server/Server.cpp +++ b/src/app/server/Server.cpp @@ -301,6 +301,25 @@ void Server::DispatchShutDownAndStopEventLoop() chip::DeviceLayer::PlatformMgr().ScheduleWork(StopEventLoop); } +void Server::ScheduleFactoryReset() +{ + chip::DeviceLayer::PlatformMgr().ScheduleWork(FactoryReset); +} + +void Server::FactoryReset(intptr_t arg) +{ + // Delete all fabrics and emit Leave event. + GetInstance().GetFabricTable().DeleteAllFabrics(); + + // Emit Shutdown event, as shutdown will come after factory reset. + DispatchShutDownEvent(0); + + // Flush all dispatched events. + chip::app::InteractionModelEngine::GetInstance()->GetReportingEngine().ScheduleUrgentEventDeliverySync(); + + chip::DeviceLayer::ConfigurationMgr().InitiateFactoryReset(); +} + void Server::Shutdown() { chip::Dnssd::ServiceAdvertiser::Instance().Shutdown(); diff --git a/src/app/server/Server.h b/src/app/server/Server.h index 50e33fba05072a..29c41cdf4b85f0 100644 --- a/src/app/server/Server.h +++ b/src/app/server/Server.h @@ -95,6 +95,10 @@ class Server void Shutdown(); + void ScheduleFactoryReset(); + + static void FactoryReset(intptr_t arg); + static Server & GetInstance() { return sServer; } private: diff --git a/src/include/platform/DiagnosticDataProvider.h b/src/include/platform/DiagnosticDataProvider.h index 4c428d671edfd3..1c634f63a6ed67 100644 --- a/src/include/platform/DiagnosticDataProvider.h +++ b/src/include/platform/DiagnosticDataProvider.h @@ -41,6 +41,17 @@ constexpr size_t kMaxIPv6AddrSize = 16; constexpr size_t kMaxIPv4AddrCount = 4; constexpr size_t kMaxIPv6AddrCount = 8; +enum BootReasonType : uint8_t +{ + Unspecified = 0, + PowerOnReboot = 1, + BrownOutReset = 2, + SoftwareWatchdogReset = 3, + HardwareWatchdogReset = 4, + SoftwareUpdateCompleted = 5, + SoftwareReset = 6, +}; + struct ThreadMetrics : public app::Clusters::SoftwareDiagnostics::Structs::ThreadMetrics::Type { char NameBuf[kMaxThreadNameLength + 1]; @@ -70,7 +81,7 @@ class GeneralDiagnosticsDelegate * @brief * Called after the current device is rebooted. */ - virtual void OnDeviceRebooted() {} + virtual void OnDeviceRebooted(BootReasonType bootReason) {} /** * @brief @@ -142,17 +153,6 @@ class WiFiDiagnosticsDelegate class DiagnosticDataProvider { public: - enum BootReasonType : uint8_t - { - Unspecified = 0, - PowerOnReboot = 1, - BrownOutReset = 2, - SoftwareWatchdogReset = 3, - HardwareWatchdogReset = 4, - SoftwareUpdateCompleted = 5, - SoftwareReset = 6, - }; - void SetGeneralDiagnosticsDelegate(GeneralDiagnosticsDelegate * delegate) { mGeneralDiagnosticsDelegate = delegate; } GeneralDiagnosticsDelegate * GetGeneralDiagnosticsDelegate() const { return mGeneralDiagnosticsDelegate; } diff --git a/src/include/platform/internal/GenericPlatformManagerImpl.cpp b/src/include/platform/internal/GenericPlatformManagerImpl.cpp index 1f1f17172e059c..e9251982f99ffd 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl.cpp @@ -298,7 +298,10 @@ void GenericPlatformManagerImpl::HandleDeviceRebooted(intptr_t arg) if (generalDiagnosticsDelegate != nullptr) { - generalDiagnosticsDelegate->OnDeviceRebooted(); + uint8_t bootReason; + + if (GetDiagnosticDataProvider().GetBootReason(bootReason) == CHIP_NO_ERROR) + generalDiagnosticsDelegate->OnDeviceRebooted(static_cast(bootReason)); } // The StartUp event SHALL be emitted by a Node after completing a boot or reboot process @@ -306,8 +309,8 @@ void GenericPlatformManagerImpl::HandleDeviceRebooted(intptr_t arg) { uint32_t softwareVersion; - ReturnOnFailure(ConfigurationMgr().GetSoftwareVersion(softwareVersion)); - platformManagerDelegate->OnStartUp(softwareVersion); + if (ConfigurationMgr().GetSoftwareVersion(softwareVersion) == CHIP_NO_ERROR) + platformManagerDelegate->OnStartUp(softwareVersion); } } diff --git a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp index 6b4d5996d250be..606663face82f4 100644 --- a/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp +++ b/src/include/platform/internal/GenericPlatformManagerImpl_Zephyr.cpp @@ -35,6 +35,8 @@ #include #include +#include + #define DEFAULT_MIN_SLEEP_PERIOD (60 * 60 * 24 * 30) // Month [sec] namespace chip { @@ -46,6 +48,7 @@ System::LayerSocketsLoop & SystemLayerSocketsLoop() { return static_cast(DeviceLayer::SystemLayer()); } + } // anonymous namespace // Fully instantiate the generic implementation class in whatever compilation unit includes this file. @@ -106,7 +109,12 @@ CHIP_ERROR GenericPlatformManagerImpl_Zephyr::_StopEventLoopTask(void template CHIP_ERROR GenericPlatformManagerImpl_Zephyr::_Shutdown(void) { +#if CONFIG_REBOOT + sys_reboot(SYS_REBOOT_WARM); + return CHIP_NO_ERROR; +#else return CHIP_ERROR_NOT_IMPLEMENTED; +#endif } template diff --git a/src/platform/Ameba/ConfigurationManagerImpl.cpp b/src/platform/Ameba/ConfigurationManagerImpl.cpp index c9a3d91d5f5a9a..62d11252157c46 100644 --- a/src/platform/Ameba/ConfigurationManagerImpl.cpp +++ b/src/platform/Ameba/ConfigurationManagerImpl.cpp @@ -80,7 +80,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() if (!AmebaConfig::ConfigValueExists(AmebaConfig::kCounterKey_BootReason)) { - err = StoreBootReason(DiagnosticDataProvider::BootReasonType::Unspecified); + err = StoreBootReason(BootReasonType::Unspecified); SuccessOrExit(err); } diff --git a/src/platform/Darwin/ConfigurationManagerImpl.cpp b/src/platform/Darwin/ConfigurationManagerImpl.cpp index c4b5aa5b556a91..de77431e6d6184 100644 --- a/src/platform/Darwin/ConfigurationManagerImpl.cpp +++ b/src/platform/Darwin/ConfigurationManagerImpl.cpp @@ -160,7 +160,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() if (!PosixConfig::ConfigValueExists(PosixConfig::kCounterKey_BootReason)) { - ReturnErrorOnFailure(StoreBootReason(DiagnosticDataProvider::BootReasonType::Unspecified)); + ReturnErrorOnFailure(StoreBootReason(BootReasonType::Unspecified)); } if (!PosixConfig::ConfigValueExists(PosixConfig::kConfigKey_RegulatoryLocation)) diff --git a/src/platform/EFR32/ConfigurationManagerImpl.cpp b/src/platform/EFR32/ConfigurationManagerImpl.cpp index fccf7f6fd0f4de..b65d788465a918 100644 --- a/src/platform/EFR32/ConfigurationManagerImpl.cpp +++ b/src/platform/EFR32/ConfigurationManagerImpl.cpp @@ -111,50 +111,50 @@ uint32_t ConfigurationManagerImpl::GetBootReason(void) #if defined(_SILICON_LABS_32B_SERIES_1) if (rebootCause & RMU_RSTCAUSE_PORST || rebootCause & RMU_RSTCAUSE_EXTRST) // PowerOn or External pin reset { - matterBootCause = DiagnosticDataProvider::BootReasonType::PowerOnReboot; + matterBootCause = BootReasonType::PowerOnReboot; } else if (rebootCause & RMU_RSTCAUSE_AVDDBOD || rebootCause & RMU_RSTCAUSE_DVDDBOD || rebootCause & RMU_RSTCAUSE_DECBOD) { - matterBootCause = DiagnosticDataProvider::BootReasonType::BrownOutReset; + matterBootCause = BootReasonType::BrownOutReset; } else if (rebootCause & RMU_RSTCAUSE_SYSREQRST) { - matterBootCause = DiagnosticDataProvider::BootReasonType::SoftwareReset; + matterBootCause = BootReasonType::SoftwareReset; } else if (rebootCause & RMU_RSTCAUSE_WDOGRST) { - matterBootCause = DiagnosticDataProvider::BootReasonType::SoftwareWatchdogReset; + matterBootCause = BootReasonType::SoftwareWatchdogReset; } else { - matterBootCause = DiagnosticDataProvider::BootReasonType::Unspecified; + matterBootCause = BootReasonType::Unspecified; } // Not tracked HARDWARE_WATCHDOG_RESET && SOFTWARE_UPDATE_COMPLETED #elif defined(_SILICON_LABS_32B_SERIES_2) if (rebootCause & EMU_RSTCAUSE_POR || rebootCause & EMU_RSTCAUSE_PIN) // PowerOn or External pin reset { - matterBootCause = DiagnosticDataProvider::BootReasonType::PowerOnReboot; + matterBootCause = BootReasonType::PowerOnReboot; } else if (rebootCause & EMU_RSTCAUSE_AVDDBOD || rebootCause & EMU_RSTCAUSE_DVDDBOD || rebootCause & EMU_RSTCAUSE_DECBOD || rebootCause & EMU_RSTCAUSE_VREGIN || rebootCause & EMU_RSTCAUSE_IOVDD0BOD || rebootCause & EMU_RSTCAUSE_DVDDLEBOD) { - matterBootCause = DiagnosticDataProvider::BootReasonType::BrownOutReset; + matterBootCause = BootReasonType::BrownOutReset; } else if (rebootCause & EMU_RSTCAUSE_SYSREQ) { - matterBootCause = DiagnosticDataProvider::BootReasonType::SoftwareReset; + matterBootCause = BootReasonType::SoftwareReset; } else if (rebootCause & EMU_RSTCAUSE_WDOG0 || rebootCause & EMU_RSTCAUSE_WDOG1) { - matterBootCause = DiagnosticDataProvider::BootReasonType::SoftwareWatchdogReset; + matterBootCause = BootReasonType::SoftwareWatchdogReset; } else { - matterBootCause = DiagnosticDataProvider::BootReasonType::Unspecified; + matterBootCause = BootReasonType::Unspecified; } // Not tracked HARDWARE_WATCHDOG_RESET && SOFTWARE_UPDATE_COMPLETED #else - matterBootCause = DiagnosticDataProvider::BootReasonType::Unspecified; + matterBootCause = BootReasonType::Unspecified; #endif return matterBootCause; diff --git a/src/platform/Linux/ConfigurationManagerImpl.cpp b/src/platform/Linux/ConfigurationManagerImpl.cpp index d536cf672a9dec..c0f997ef1dd7e9 100644 --- a/src/platform/Linux/ConfigurationManagerImpl.cpp +++ b/src/platform/Linux/ConfigurationManagerImpl.cpp @@ -88,7 +88,7 @@ CHIP_ERROR ConfigurationManagerImpl::Init() if (!PosixConfig::ConfigValueExists(PosixConfig::kCounterKey_BootReason)) { - err = StoreBootReason(DiagnosticDataProvider::BootReasonType::Unspecified); + err = StoreBootReason(BootReasonType::Unspecified); SuccessOrExit(err); } diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.cpp b/src/platform/Zephyr/ConfigurationManagerImpl.cpp index 65f95d9c3c3e40..33add147262079 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.cpp +++ b/src/platform/Zephyr/ConfigurationManagerImpl.cpp @@ -36,8 +36,6 @@ #include #include -#include - namespace chip { namespace DeviceLayer { @@ -204,9 +202,7 @@ void ConfigurationManagerImpl::DoFactoryReset(intptr_t arg) ThreadStackMgr().ErasePersistentInfo(); #endif // CHIP_DEVICE_CONFIG_ENABLE_THREAD -#if CONFIG_REBOOT - sys_reboot(SYS_REBOOT_WARM); -#endif + PlatformMgr().Shutdown(); } } // namespace DeviceLayer diff --git a/src/platform/Zephyr/ConfigurationManagerImpl.h b/src/platform/Zephyr/ConfigurationManagerImpl.h index 44d66d3ab63e15..e678b5a5146868 100644 --- a/src/platform/Zephyr/ConfigurationManagerImpl.h +++ b/src/platform/Zephyr/ConfigurationManagerImpl.h @@ -81,7 +81,12 @@ inline bool ConfigurationManagerImpl::CanFactoryReset() inline CHIP_ERROR ConfigurationManagerImpl::ReadPersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t & value) { - return Internal::ZephyrConfig::ReadConfigValueCounter(key, value); + CHIP_ERROR err = Internal::ZephyrConfig::ReadConfigValueCounter(key, value); + if (err == CHIP_DEVICE_ERROR_CONFIG_NOT_FOUND) + { + err = CHIP_ERROR_PERSISTED_STORAGE_VALUE_NOT_FOUND; + } + return err; } inline CHIP_ERROR ConfigurationManagerImpl::WritePersistedStorageValue(::chip::Platform::PersistedStorage::Key key, uint32_t value)