diff --git a/src/include/platform/CHIPDeviceEvent.h b/src/include/platform/CHIPDeviceEvent.h index 57445433d8ef76..63d456dd2e33ff 100644 --- a/src/include/platform/CHIPDeviceEvent.h +++ b/src/include/platform/CHIPDeviceEvent.h @@ -197,6 +197,11 @@ enum PublicEventTypes * wifi/ethernet interface. */ kInterfaceIpAddressChanged, + + /** + * Commissioning has completed either through timer expiry or by a call to the general commissioning cluster command. + */ + kCommissioningComplete, }; /** @@ -401,6 +406,11 @@ struct ChipDeviceEvent final { InterfaceIpChangeType Type; } InterfaceIpAddressChanged; + + struct + { + CHIP_ERROR status; + } CommissioningComplete; }; void Clear() { memset(this, 0, sizeof(*this)); } diff --git a/src/include/platform/PlatformManager.h b/src/include/platform/PlatformManager.h index cee2d60a1e60c8..63b988bb404134 100644 --- a/src/include/platform/PlatformManager.h +++ b/src/include/platform/PlatformManager.h @@ -50,6 +50,7 @@ class TraitManager; class ThreadStackManagerImpl; class TimeSyncManager; namespace Internal { +class DeviceControlServer; class FabricProvisioningServer; class ServiceProvisioningServer; class BLEManagerImpl; @@ -109,6 +110,7 @@ class PlatformManager friend class TraitManager; friend class ThreadStackManagerImpl; friend class TimeSyncManager; + friend class Internal::DeviceControlServer; friend class Internal::FabricProvisioningServer; friend class Internal::ServiceProvisioningServer; friend class Internal::BLEManagerImpl; diff --git a/src/include/platform/internal/DeviceControlServer.h b/src/include/platform/internal/DeviceControlServer.h index 6e62eb345275eb..92809464fe46a1 100644 --- a/src/include/platform/internal/DeviceControlServer.h +++ b/src/include/platform/internal/DeviceControlServer.h @@ -43,6 +43,8 @@ class DeviceControlServer final private: // ===== Members for internal use by the following friends. static DeviceControlServer sInstance; + friend void CommissioningTimerFunction(System::Layer * layer, void * aAppState, System::Error aError); + void CommissioningFailedTimerComplete(System::Error aErrror); // ===== Private members reserved for use by this class only. diff --git a/src/platform/DeviceControlServer.cpp b/src/platform/DeviceControlServer.cpp index 8a26d9d754e47c..bb307eb1a0085b 100644 --- a/src/platform/DeviceControlServer.cpp +++ b/src/platform/DeviceControlServer.cpp @@ -28,6 +28,12 @@ namespace chip { namespace DeviceLayer { namespace Internal { +void CommissioningTimerFunction(System::Layer * layer, void * aAppState, System::Error aError) +{ + DeviceControlServer * server = reinterpret_cast(aAppState); + server->CommissioningFailedTimerComplete(aError); +} + DeviceControlServer DeviceControlServer::sInstance; DeviceControlServer & DeviceControlServer::DeviceControlSvr() @@ -35,10 +41,19 @@ DeviceControlServer & DeviceControlServer::DeviceControlSvr() return sInstance; } +void DeviceControlServer::CommissioningFailedTimerComplete(System::Error aError) +{ + ChipDeviceEvent event; + event.Type = DeviceEventType::kCommissioningComplete; + event.CommissioningComplete.status = CHIP_ERROR_TIMEOUT; + PlatformMgr().PostEvent(&event); +} + CHIP_ERROR DeviceControlServer::ArmFailSafe(uint16_t expiryLengthSeconds) { - // TODO - return CHIP_ERROR_NOT_IMPLEMENTED; + uint32_t timerMs = expiryLengthSeconds * 1000; + SystemLayer.StartTimer(timerMs, CommissioningTimerFunction, this); + return CHIP_NO_ERROR; } CHIP_ERROR DeviceControlServer::DisarmFailSafe() @@ -49,8 +64,12 @@ CHIP_ERROR DeviceControlServer::DisarmFailSafe() CHIP_ERROR DeviceControlServer::CommissioningComplete() { - // TODO - return CHIP_ERROR_NOT_IMPLEMENTED; + SystemLayer.CancelTimer(CommissioningTimerFunction, this); + ChipDeviceEvent event; + event.Type = DeviceEventType::kCommissioningComplete; + event.CommissioningComplete.status = CHIP_NO_ERROR; + PlatformMgr().PostEvent(&event); + return CHIP_NO_ERROR; } CHIP_ERROR DeviceControlServer::SetRegulatoryConfig(uint8_t location, const char * countryCode, uint64_t breadcrumb)