Skip to content

Commit 3972630

Browse files
committed
1 parent eee6d8b commit 3972630

8 files changed

+103
-133
lines changed

src/app/clusters/general-commissioning-server/general-commissioning-server.cpp

+78-107
Original file line numberDiff line numberDiff line change
@@ -59,133 +59,105 @@ using Transport::Session;
5959
namespace {
6060

6161
template <typename Provider, typename T>
62-
static CHIP_ERROR ReadInternal(Provider* const provider, CHIP_ERROR (Provider::*const getter)(T&), AttributeValueEncoder& aEncoder)
62+
static CHIP_ERROR ReadIfSupported(Provider * const provider, CHIP_ERROR (Provider::*const nonConstGetter)(T &),
63+
AttributeValueEncoder & aEncoder)
6364
{
64-
T data;
65-
6665
if (nullptr == provider)
6766
{
6867
return CHIP_ERROR_PERSISTED_STORAGE_FAILED;
6968
}
7069

71-
CHIP_ERROR err = (provider->*getter)(data);
72-
if (err == CHIP_ERROR_UNSUPPORTED_CHIP_FEATURE)
73-
{
74-
data = 0;
75-
}
76-
else if (err != CHIP_NO_ERROR)
70+
T value;
71+
CHIP_ERROR err = (provider->*nonConstGetter)(value);
72+
if (err != CHIP_NO_ERROR)
7773
{
7874
return err;
7975
}
8076

81-
return aEncoder.Encode(data);
77+
return aEncoder.Encode(value);
8278
}
8379

8480
template <typename Provider, typename T>
85-
static CHIP_ERROR ReadInternal(Provider* const provider, CHIP_ERROR (Provider::*const getter)(T&) const, AttributeValueEncoder& aEncoder)
81+
static CHIP_ERROR ReadIfSupported(Provider * const provider, CHIP_ERROR (Provider::*const getter)(T &) const,
82+
AttributeValueEncoder & aEncoder)
8683
{
87-
// Removing the const qualifier from the getter function pointer because there are a handful of getter functions that are not correctly marked as const.
88-
using NonConstGetter = CHIP_ERROR (Provider::*)(T&);
84+
// Removing the const qualifier from the getter function pointer because there are a handful of getter functions that are not
85+
// correctly marked as const.
86+
using NonConstGetter = CHIP_ERROR (Provider::*)(T &);
8987
NonConstGetter nonConstGetter = reinterpret_cast<NonConstGetter>(getter);
90-
91-
return ReadInternal(provider, nonConstGetter, aEncoder);
88+
return ReadIfSupported(provider, nonConstGetter, aEncoder);
9289
}
9390

94-
template <typename... Args>
95-
static CHIP_ERROR ReadIfSupported(Args &&... args)
96-
{
97-
return ReadInternal(std::forward<Args>(args)...);
98-
}
99-
100-
class GeneralCommissioningAttrAccess : public AttributeAccessInterface
91+
class _ : public AttributeAccessInterface
10192
{
10293
public:
103-
// Register for the GeneralCommissioning cluster on all endpoints.
104-
GeneralCommissioningAttrAccess() : AttributeAccessInterface(Optional<EndpointId>::Missing(), GeneralCommissioning::Id) {}
105-
106-
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder) override;
107-
108-
private:
109-
CHIP_ERROR ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder);
110-
CHIP_ERROR ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder);
111-
};
112-
113-
GeneralCommissioningAttrAccess gAttrAccess;
114-
115-
CHIP_ERROR GeneralCommissioningAttrAccess::Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
116-
{
117-
if (aPath.mClusterId != GeneralCommissioning::Id)
118-
{
119-
// We shouldn't have been called at all.
120-
return CHIP_ERROR_INVALID_ARGUMENT;
121-
}
94+
_() : AttributeAccessInterface(Optional<EndpointId>::Missing(), GeneralCommissioning::Id) {}
12295

123-
switch (aPath.mAttributeId)
96+
CHIP_ERROR Read(const ConcreteReadAttributePath & aPath, AttributeValueEncoder & aEncoder)
12497
{
125-
case RegulatoryConfig::Id: {
126-
return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetRegulatoryLocation, aEncoder);
127-
}
128-
case LocationCapability::Id: {
129-
return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetLocationCapability, aEncoder);
130-
}
131-
case BasicCommissioningInfo::Id: {
132-
return ReadBasicCommissioningInfo(aEncoder);
133-
}
134-
case SupportsConcurrentConnection::Id: {
135-
return ReadSupportsConcurrentConnection(aEncoder);
136-
}
137-
#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
138-
case TCAcceptedVersion::Id: {
139-
app::EnhancedSetupFlowProvider * provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
140-
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgementsVersion;
141-
return ReadIfSupported(provider, getter, aEncoder);
142-
}
143-
case TCMinRequiredVersion::Id: {
144-
auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
145-
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgementsVersion;
146-
return ReadIfSupported(provider, getter, aEncoder);
147-
}
148-
case TCAcknowledgements::Id: {
149-
auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
150-
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgements;
151-
return ReadIfSupported(provider, getter, aEncoder);
152-
}
153-
case TCAcknowledgementsRequired::Id: {
154-
auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
155-
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgements;
156-
return ReadIfSupported(provider, getter, aEncoder);
157-
}
158-
#endif
159-
default:
160-
break;
161-
}
162-
return CHIP_NO_ERROR;
163-
}
164-
165-
CHIP_ERROR GeneralCommissioningAttrAccess::ReadBasicCommissioningInfo(AttributeValueEncoder & aEncoder)
166-
{
167-
BasicCommissioningInfo::TypeInfo::Type basicCommissioningInfo;
98+
if (aPath.mClusterId != GeneralCommissioning::Id)
99+
{
100+
// We shouldn't have been called at all.
101+
return CHIP_ERROR_INVALID_ARGUMENT;
102+
}
168103

169-
// TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
170-
// the CommissioningParameters at the beginning of commissioning flow.
171-
basicCommissioningInfo.failSafeExpiryLengthSeconds = CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC;
172-
basicCommissioningInfo.maxCumulativeFailsafeSeconds = CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC;
173-
static_assert(CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC >= CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC,
174-
"Max cumulative failsafe seconds must be larger than failsafe expiry length seconds");
104+
switch (aPath.mAttributeId)
105+
{
106+
case RegulatoryConfig::Id: {
107+
return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetRegulatoryLocation, aEncoder);
108+
}
109+
case LocationCapability::Id: {
110+
return ReadIfSupported(&DeviceLayer::ConfigurationMgr(), &ConfigurationManager::GetLocationCapability, aEncoder);
111+
}
112+
case BasicCommissioningInfo::Id: {
113+
BasicCommissioningInfo::TypeInfo::Type basicCommissioningInfo;
175114

176-
return aEncoder.Encode(basicCommissioningInfo);
177-
}
115+
// TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
116+
// the CommissioningParameters at the beginning of commissioning flow.
117+
basicCommissioningInfo.failSafeExpiryLengthSeconds = CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC;
118+
basicCommissioningInfo.maxCumulativeFailsafeSeconds = CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC;
119+
static_assert(CHIP_DEVICE_CONFIG_MAX_CUMULATIVE_FAILSAFE_SEC >= CHIP_DEVICE_CONFIG_FAILSAFE_EXPIRY_LENGTH_SEC,
120+
"Max cumulative failsafe seconds must be larger than failsafe expiry length seconds");
178121

179-
CHIP_ERROR GeneralCommissioningAttrAccess::ReadSupportsConcurrentConnection(AttributeValueEncoder & aEncoder)
180-
{
181-
SupportsConcurrentConnection::TypeInfo::Type supportsConcurrentConnection;
122+
return aEncoder.Encode(basicCommissioningInfo);
123+
}
124+
case SupportsConcurrentConnection::Id: {
125+
SupportsConcurrentConnection::TypeInfo::Type supportsConcurrentConnection;
182126

183-
// TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
184-
// the CommissioningParameters at the beginning of commissioning flow.
185-
supportsConcurrentConnection = (CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION) != 0;
127+
// TODO: The commissioner might use the critical parameters in BasicCommissioningInfo to initialize
128+
// the CommissioningParameters at the beginning of commissioning flow.
129+
supportsConcurrentConnection = (CHIP_DEVICE_CONFIG_SUPPORTS_CONCURRENT_CONNECTION) != 0;
186130

187-
return aEncoder.Encode(supportsConcurrentConnection);
188-
}
131+
return aEncoder.Encode(supportsConcurrentConnection);
132+
}
133+
#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
134+
case TCAcceptedVersion::Id: {
135+
auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
136+
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgementsVersion;
137+
return ReadIfSupported(provider, getter, aEncoder);
138+
}
139+
case TCMinRequiredVersion::Id: {
140+
auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
141+
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgementsVersion;
142+
return ReadIfSupported(provider, getter, aEncoder);
143+
}
144+
case TCAcknowledgements::Id: {
145+
auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
146+
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsAcceptedAcknowledgements;
147+
return ReadIfSupported(provider, getter, aEncoder);
148+
}
149+
case TCAcknowledgementsRequired::Id: {
150+
auto provider = Server::GetInstance().GetEnhancedSetupFlowProvider();
151+
auto getter = &EnhancedSetupFlowProvider::GetTermsAndConditionsRequiredAcknowledgements;
152+
return ReadIfSupported(provider, getter, aEncoder);
153+
}
154+
#endif
155+
default:
156+
break;
157+
}
158+
return CHIP_NO_ERROR;
159+
}
160+
} gAttributeAccessInstance;
189161

190162
} // anonymous namespace
191163

@@ -257,7 +229,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
257229
{
258230
MATTER_TRACE_SCOPE("CommissioningComplete", "GeneralCommissioning");
259231

260-
#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
232+
#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
261233
EnhancedSetupFlowProvider * enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider();
262234
#endif
263235
DeviceControlServer * const devCtrl = &DeviceLayer::DeviceControlServer::DeviceControlSvr();
@@ -287,7 +259,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
287259
{
288260
CHIP_ERROR err;
289261

290-
#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
262+
#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
291263

292264
uint16_t termsAndConditionsAcceptedAcknowledgements;
293265
bool hasRequiredTermAccepted;
@@ -297,8 +269,7 @@ bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(
297269
termsAndConditionsAcceptedAcknowledgements);
298270
CheckSuccess(err, Failure);
299271

300-
err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(
301-
hasRequiredTermAccepted);
272+
err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsBeenAccepted(hasRequiredTermAccepted);
302273
CheckSuccess(err, Failure);
303274

304275
err = enhancedSetupFlowProvider->HasTermsAndConditionsRequiredAcknowledgementsVersionBeenAccepted(
@@ -408,7 +379,7 @@ bool emberAfGeneralCommissioningClusterSetTCAcknowledgementsCallback(
408379
chip::app::CommandHandler * commandObj, const chip::app::ConcreteCommandPath & commandPath,
409380
const chip::app::Clusters::GeneralCommissioning::Commands::SetTCAcknowledgements::DecodableType & commandData)
410381
{
411-
#if defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined (CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
382+
#if defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS) && defined(CHIP_CONFIG_TC_REQUIRED_ACKNOWLEDGEMENTS_VERSION)
412383
MATTER_TRACE_SCOPE("SetTCAcknowledgements", "GeneralCommissioning");
413384
Commands::SetTCAcknowledgementsResponse::Type response;
414385
EnhancedSetupFlowProvider * const enhancedSetupFlowProvider = Server::GetInstance().GetEnhancedSetupFlowProvider();
@@ -437,7 +408,7 @@ void OnPlatformEventHandler(const DeviceLayer::ChipDeviceEvent * event, intptr_t
437408
void MatterGeneralCommissioningPluginServerInitCallback()
438409
{
439410
Breadcrumb::Set(0, 0);
440-
registerAttributeAccessOverride(&gAttrAccess);
411+
registerAttributeAccessOverride(&gAttributeAccessInstance);
441412
DeviceLayer::PlatformMgrImpl().AddEventHandler(OnPlatformEventHandler);
442413
}
443414

src/app/server/DefaultEnhancedSetupFlowProvider.cpp

-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222

2323
#include <lib/core/CHIPConfig.h>
2424
#include <lib/support/CodeUtils.h>
25-
#include <platform/KeyValueStoreManager.h>
2625

2726
CHIP_ERROR chip::app::DefaultEnhancedSetupFlowProvider::Init(TermsAndConditionsProvider * const inTermsAndConditionsProvider)
2827
{

src/app/server/DefaultEnhancedSetupFlowProvider.h

+1-1
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ class DefaultEnhancedSetupFlowProvider : public EnhancedSetupFlowProvider
7474
/**
7575
* @copydoc EnhancedSetupFlowProvider::SetTermsAndConditionsAcceptance
7676
*/
77-
CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t aTCAcknowledgements, uint16_t aTCAcknowledgementsVersion) override;
77+
CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t aTCAcknowledgements, uint16_t inTCAcknowledgementsVersionValue) override;
7878

7979
/**
8080
* @copydoc EnhancedSetupFlowProvider::ClearTermsAndConditionsAcceptance

src/app/server/DefaultTermsAndConditionsProvider.cpp

+8-8
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,13 @@
2323
#include <lib/core/TLVTypes.h>
2424
#include <lib/support/CodeUtils.h>
2525
#include <lib/support/DefaultStorageKeyAllocator.h>
26-
#include <platform/KeyValueStoreManager.h>
2726

2827
namespace {
29-
static constexpr chip::TLV::Tag kAcceptedAcknowledgementsTag = chip::TLV::ContextTag(1);
30-
static constexpr chip::TLV::Tag kAcceptedAcknowledgementsVersionTag = chip::TLV::ContextTag(2);
31-
static constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(sizeof(uint16_t), sizeof(uint16_t));
28+
constexpr chip::TLV::Tag kSerializationVersionTag = chip::TLV::ContextTag(1);
29+
constexpr chip::TLV::Tag kAcceptedAcknowledgementsTag = chip::TLV::ContextTag(2);
30+
constexpr chip::TLV::Tag kAcceptedAcknowledgementsVersionTag = chip::TLV::ContextTag(3);
31+
constexpr uint8_t kSerializationVersion = 1;
32+
constexpr size_t kEstimatedTlvBufferSize = chip::TLV::EstimateStructOverhead(sizeof(uint8_t), sizeof(uint16_t), sizeof(uint16_t));
3233
}; // namespace
3334

3435
CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate,
@@ -83,11 +84,9 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::GetAcceptance(uint16_t
8384
tlvReader.Init(buffer);
8485
ReturnErrorOnFailure(tlvReader.Next(chip::TLV::kTLVType_Structure, chip::TLV::AnonymousTag()));
8586
ReturnErrorOnFailure(tlvReader.EnterContainer(tlvContainer));
86-
ReturnErrorOnFailure(tlvReader.Next());
87-
ReturnErrorOnFailure(tlvReader.Expect(kAcceptedAcknowledgementsTag));
87+
ReturnErrorOnFailure(tlvReader.Next(kAcceptedAcknowledgementsTag));
8888
ReturnErrorOnFailure(tlvReader.Get(acknowledgements));
89-
ReturnErrorOnFailure(tlvReader.Next());
90-
ReturnErrorOnFailure(tlvReader.Expect(kAcceptedAcknowledgementsVersionTag));
89+
ReturnErrorOnFailure(tlvReader.Next(kAcceptedAcknowledgementsVersionTag));
9190
ReturnErrorOnFailure(tlvReader.Get(acknowledgementsVersion));
9291
ReturnErrorOnFailure(tlvReader.ExitContainer(tlvContainer));
9392

@@ -117,6 +116,7 @@ CHIP_ERROR chip::app::DefaultTermsAndConditionsProvider::SetAcceptance(uint16_t
117116

118117
tlvWriter.Init(buffer, sizeof(buffer));
119118
ReturnErrorOnFailure(tlvWriter.StartContainer(chip::TLV::AnonymousTag(), chip::TLV::kTLVType_Structure, tlvContainer));
119+
ReturnErrorOnFailure(tlvWriter.Put(kSerializationVersionTag, kSerializationVersion));
120120
ReturnErrorOnFailure(tlvWriter.Put(kAcceptedAcknowledgementsTag, inAcceptedAcknowledgementsValue));
121121
ReturnErrorOnFailure(tlvWriter.Put(kAcceptedAcknowledgementsVersionTag, inAcceptedAcknowledgementsVersionValue));
122122
ReturnErrorOnFailure(tlvWriter.EndContainer(tlvContainer));

src/app/server/DefaultTermsAndConditionsProvider.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
4040
* @param[in] inRequiredAcknowledgementsVersionValue The version of the required acknowledgements.
4141
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
4242
*/
43-
CHIP_ERROR Init(chip::PersistentStorageDelegate * const inPersistentStorageDelegate, uint16_t inRequiredAcknowledgementsValue,
43+
CHIP_ERROR Init(PersistentStorageDelegate * const inPersistentStorageDelegate, uint16_t inRequiredAcknowledgementsValue,
4444
uint16_t inRequiredAcknowledgementsVersionValue);
4545

4646
/**
@@ -64,7 +64,7 @@ class DefaultTermsAndConditionsProvider : public TermsAndConditionsProvider
6464
CHIP_ERROR SetAcceptance(uint16_t inAcknowledgementsValue, uint16_t inAcknowledgementsVersionValue) override;
6565

6666
private:
67-
chip::PersistentStorageDelegate * mPersistentStorageDelegate;
67+
PersistentStorageDelegate * mPersistentStorageDelegate;
6868
uint16_t mRequiredAcknowledgementsValue;
6969
uint16_t mRequiredAcknowledgementsVersionValue;
7070
};

src/app/server/EnhancedSetupFlowProvider.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -92,11 +92,11 @@ class EnhancedSetupFlowProvider
9292
* @brief Sets the acceptance status of the terms and conditions.
9393
*
9494
* @param[in] inTCAcknowledgements The acknowledgements to accept.
95-
* @param[in] inTCAcknowledgementsoutValue The version of the acknowledgements to accept.
95+
* @param[in] inTCAcknowledgementsVersionValue The version of the acknowledgements to accept.
9696
* @return CHIP_ERROR On success returns CHIP_NO_ERROR, otherwise returns an error code.
9797
*/
9898
virtual CHIP_ERROR SetTermsAndConditionsAcceptance(uint16_t inTCAcknowledgementsValue,
99-
uint16_t inTCAcknowledgementsoutValue) = 0;
99+
uint16_t inTCAcknowledgementsVersionValue) = 0;
100100

101101
/**
102102
* @brief Clears the acceptance status of the terms and conditions.

0 commit comments

Comments
 (0)