diff --git a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp index a81de5670f24c2..990f8c3465ce08 100644 --- a/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp +++ b/src/app/clusters/general-commissioning-server/general-commissioning-server.cpp @@ -66,7 +66,8 @@ class GeneralCommissioningAttrAccess : public AttributeAccessInterface CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override; private: - CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(uint8_t &), AttributeValueEncoder & aEncoder); + template + CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(T &), AttributeValueEncoder & aEncoder); CHIP_ERROR ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder); CHIP_ERROR ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder); }; @@ -95,17 +96,29 @@ CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath case SupportsConcurrentConnection::Id: { return ReadSupportsConcurrentConnection(aEncoder); } - default: { - break; + case TCAcceptedVersion::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCAcceptedVersion, aEncoder); + } + case TCMinRequiredVersion::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCMinRequiredVersion, aEncoder); } + case TCAcknowledgements::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgements, aEncoder); + } + case TCAcknowledgementsRequired::Id: { + return ReadIfSupported(&ConfigurationManager::GetTCAcknowledgementsRequired, aEncoder); + } + default: + break; } return CHIP_NO_ERROR; } -CHIP_ERROR GeneralCommissioningAttrAccess::ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(uint8_t &), +template +CHIP_ERROR GeneralCommissioningAttrAccess::ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(T &), AttributeValueEncoder & aEncoder) { - uint8_t data; + T data; CHIP_ERROR err = (DeviceLayer::ConfigurationMgr().*getter)(data); if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE) { @@ -332,6 +345,21 @@ bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(app::CommandH return true; } +bool emberAfGeneralCommissioningClusterSetTCAcknowledgementsCallback( + chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath, + const chip::app::Clusters::GeneralCommissioning::Commands::SetTCAcknowledgements::DecodableType & commandData) +{ + MATTER_TRACE_SCOPE("SetTCAcknowledgements", "GeneralCommissioning"); + DeviceControlServer * server = &DeviceLayer::DeviceControlServer::DeviceControlSvr(); + Commands::SetTCAcknowledgementsResponse::Type response; + + CheckSuccess(server->SetTCAcknowledgements(commandData.TCVersion, commandData.TCUserResponse), Failure); + response.errorCode = CommissioningErrorEnum::kOk; + + commandObj->AddResponse(commandPath, response); + return true; +} + namespace { void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t arg) { diff --git a/src/include/platform/ConfigurationManager.h b/src/include/platform/ConfigurationManager.h index 7e891fedc2149b..1b34b95c696b6b 100644 --- a/src/include/platform/ConfigurationManager.h +++ b/src/include/platform/ConfigurationManager.h @@ -132,10 +132,11 @@ class ConfigurationManager virtual CHIP_ERROR GetFailSafeArmed(bool & val) = 0; virtual CHIP_ERROR SetFailSafeArmed(bool val) = 0; - virtual CHIP_ERROR GetTCAcceptedVersion(uint16_t &value) = 0; - virtual CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value) = 0; - virtual CHIP_ERROR GetTCAcknowledgements(uint16_t &value) = 0; - virtual CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value) = 0; + virtual CHIP_ERROR GetTCAcceptedVersion(uint16_t &value) = 0; + virtual CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value) = 0; + virtual CHIP_ERROR GetTCAcknowledgements(uint16_t &value) = 0; + virtual CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value) = 0; + virtual CHIP_ERROR StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) = 0; virtual CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) = 0; diff --git a/src/include/platform/DeviceControlServer.h b/src/include/platform/DeviceControlServer.h index 2d292cfee261f4..06e588ea752235 100644 --- a/src/include/platform/DeviceControlServer.h +++ b/src/include/platform/DeviceControlServer.h @@ -35,6 +35,7 @@ class DeviceControlServer final CHIP_ERROR PostCommissioningCompleteEvent(NodeId peerNodeId, FabricIndex accessingFabricIndex); CHIP_ERROR SetRegulatoryConfig(uint8_t location, const CharSpan & countryCode); + CHIP_ERROR SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse); CHIP_ERROR PostConnectedToOperationalNetworkEvent(ByteSpan networkID); CHIP_ERROR PostCloseAllBLEConnectionsToOperationalNetworkEvent(); CHIP_ERROR PostWiFiDeviceAvailableNetworkEvent(); diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.h b/src/include/platform/internal/GenericConfigurationManagerImpl.h index e3cb2d4d38d025..5d438f9d822fb1 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.h +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.h @@ -82,11 +82,6 @@ class GenericConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR GetFailSafeArmed(bool & val) override; CHIP_ERROR SetFailSafeArmed(bool val) override; - CHIP_ERROR GetTCAcceptedVersion(uint16_t &value) override; - CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value) override; - CHIP_ERROR GetTCAcknowledgements(uint16_t &value) override; - CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value) override; - CHIP_ERROR GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) override; bool IsCommissionableDeviceTypeEnabled() override; CHIP_ERROR GetDeviceTypeId(uint32_t & deviceType) override; @@ -100,6 +95,11 @@ class GenericConfigurationManagerImpl : public ConfigurationManager CHIP_ERROR StoreRegulatoryLocation(uint8_t location) override; CHIP_ERROR GetCountryCode(char * buf, size_t bufSize, size_t & codeLen) override; CHIP_ERROR StoreCountryCode(const char * code, size_t codeLen) override; + CHIP_ERROR GetTCAcceptedVersion(uint16_t &value) override; + CHIP_ERROR GetTCMinRequiredVersion(uint16_t &value) override; + CHIP_ERROR GetTCAcknowledgements(uint16_t &value) override; + CHIP_ERROR GetTCAcknowledgementsRequired(uint16_t &value) override; + CHIP_ERROR StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse); CHIP_ERROR GetRebootCount(uint32_t & rebootCount) override; CHIP_ERROR StoreRebootCount(uint32_t rebootCount) override; CHIP_ERROR GetTotalOperationalHours(uint32_t & totalOperationalHours) override; diff --git a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp index 200411399770eb..cdc0b22c921b9c 100644 --- a/src/include/platform/internal/GenericConfigurationManagerImpl.ipp +++ b/src/include/platform/internal/GenericConfigurationManagerImpl.ipp @@ -583,25 +583,47 @@ CHIP_ERROR GenericConfigurationManagerImpl::SetFailSafeArmed(bool v } template -CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcceptedVersion(uint16_t &value) { +CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcceptedVersion(uint16_t & value) +{ return ReadConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, value); } template -CHIP_ERROR GenericConfigurationManagerImpl::GetTCMinRequiredVersion(uint16_t &value) { +CHIP_ERROR GenericConfigurationManagerImpl::GetTCMinRequiredVersion(uint16_t & value) +{ return ReadConfigValue(ConfigClass::kConfigKey_TCMinRequiredVersion, value); } template -CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcknowledgements(uint16_t &value) { +CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcknowledgements(uint16_t & value) +{ return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgements, value); } template -CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcknowledgementsRequired(uint16_t &value) { +CHIP_ERROR GenericConfigurationManagerImpl::GetTCAcknowledgementsRequired(uint16_t & value) +{ return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgementsRequired, value); } +template +CHIP_ERROR GenericConfigurationManagerImpl::StoreTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) +{ + CHIP_ERROR err; + + err = WriteConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, 0U); + SuccessOrExit(err); + + err = WriteConfigValue(ConfigClass::kConfigKey_TCAcknowledgements, tcUserResponse); + SuccessOrExit(err); + + err = WriteConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, tcVersion); + SuccessOrExit(err); + +exit: + return err; +} + template CHIP_ERROR GenericConfigurationManagerImpl::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo) diff --git a/src/platform/DeviceControlServer.cpp b/src/platform/DeviceControlServer.cpp index ec348669aec213..25960c8fe95cec 100644 --- a/src/platform/DeviceControlServer.cpp +++ b/src/platform/DeviceControlServer.cpp @@ -64,6 +64,21 @@ CHIP_ERROR DeviceControlServer::SetRegulatoryConfig(uint8_t location, const Char return err; } +CHIP_ERROR DeviceControlServer::SetTCAcknowledgements(uint16_t tcVersion, uint16_t tcUserResponse) +{ + CHIP_ERROR err = CHIP_NO_ERROR; + + err = ConfigurationMgr().StoreTCAcknowledgements(tcVersion, tcUserResponse); + SuccessOrExit(err); + +exit: + if (err != CHIP_NO_ERROR) + { + ChipLogError(DeviceLayer, "SetTCAcknowledgements failed with error: %s", ErrorStr(err)); + } + return err; +} + CHIP_ERROR DeviceControlServer::PostConnectedToOperationalNetworkEvent(ByteSpan networkID) { ChipDeviceEvent event;