Skip to content

Commit

Permalink
feat: Add templatized ReadIfSupported function and support for TC att…
Browse files Browse the repository at this point in the history
…ributes

This commit introduces a template version of the ReadIfSupported
function in the GeneralCommissioningAttrAccess class, allowing it to
support multiple types of getter functions. Additionally, support for
reading TC (Thread Commissioning) attributes has been added. The
ReadIfSupported function is now used to read TC attributes when
appropriate. The ConfigurationManager interface has been extended with a
new method, StoreTCAcknowledgements, to store TC acknowledgements. The
DeviceControlServer class has been updated to support setting TC
acknowledgements.
  • Loading branch information
swan-amazon committed May 7, 2024
1 parent e6865d7 commit 108c6a3
Show file tree
Hide file tree
Showing 6 changed files with 85 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 <typename T>
CHIP_ERROR ReadIfSupported(CHIP_ERROR (ConfigurationManager::*getter)(T &), AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder);
CHIP_ERROR ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder);
};
Expand Down Expand Up @@ -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 <typename T>
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)
{
Expand Down Expand Up @@ -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)
{
Expand Down
9 changes: 5 additions & 4 deletions src/include/platform/ConfigurationManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
1 change: 1 addition & 0 deletions src/include/platform/DeviceControlServer.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
10 changes: 5 additions & 5 deletions src/include/platform/internal/GenericConfigurationManagerImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down
30 changes: 26 additions & 4 deletions src/include/platform/internal/GenericConfigurationManagerImpl.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -583,25 +583,47 @@ CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::SetFailSafeArmed(bool v
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcceptedVersion(uint16_t &value) {
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcceptedVersion(uint16_t & value)
{
return ReadConfigValue(ConfigClass::kConfigKey_TCAcceptedVersion, value);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCMinRequiredVersion(uint16_t &value) {
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCMinRequiredVersion(uint16_t & value)
{
return ReadConfigValue(ConfigClass::kConfigKey_TCMinRequiredVersion, value);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcknowledgements(uint16_t &value) {
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcknowledgements(uint16_t & value)
{
return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgements, value);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcknowledgementsRequired(uint16_t &value) {
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::GetTCAcknowledgementsRequired(uint16_t & value)
{
return ReadConfigValue(ConfigClass::kConfigKey_TCAcknowledgementsRequired, value);
}

template <class ConfigClass>
CHIP_ERROR GenericConfigurationManagerImpl<ConfigClass>::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 <class ConfigClass>
CHIP_ERROR
GenericConfigurationManagerImpl<ConfigClass>::GetBLEDeviceIdentificationInfo(Ble::ChipBLEDeviceIdentificationInfo & deviceIdInfo)
Expand Down
15 changes: 15 additions & 0 deletions src/platform/DeviceControlServer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 108c6a3

Please sign in to comment.