diff --git a/src/controller/AutoCommissioner.cpp b/src/controller/AutoCommissioner.cpp index 72470edec40edc..85367d4532ccc7 100644 --- a/src/controller/AutoCommissioner.cpp +++ b/src/controller/AutoCommissioner.cpp @@ -85,7 +85,9 @@ CHIP_ERROR AutoCommissioner::SetCommissioningParameters(const CommissioningParam IsUnsafeSpan(params.GetIcac(), mParams.GetIcac()) || IsUnsafeSpan(params.GetIpk(), mParams.GetIpk()) || IsUnsafeSpan(params.GetAttestationElements(), mParams.GetAttestationElements()) || IsUnsafeSpan(params.GetAttestationSignature(), mParams.GetAttestationSignature()) || - IsUnsafeSpan(params.GetPAI(), mParams.GetPAI()) || IsUnsafeSpan(params.GetDAC(), mParams.GetDAC())); + IsUnsafeSpan(params.GetPAI(), mParams.GetPAI()) || IsUnsafeSpan(params.GetDAC(), mParams.GetDAC()) || + IsUnsafeSpan(params.GetTimeZone(), mParams.GetTimeZone()) || + IsUnsafeSpan(params.GetDSTOffsets(), mParams.GetDSTOffsets())); mParams = params; @@ -174,6 +176,33 @@ CHIP_ERROR AutoCommissioner::SetCommissioningParameters(const CommissioningParam } mParams.SetCSRNonce(ByteSpan(mCSRNonce, sizeof(mCSRNonce))); + if (params.GetDSTOffsets().HasValue()) + { + ChipLogProgress(Controller, "Setting DST offsets from parameters"); + size_t size = std::min(params.GetDSTOffsets().Value().size(), kMaxSupportedDstStructs); + for (size_t i = 0; i < size; ++i) + { + mDstOffsetsBuf[i] = params.GetDSTOffsets().Value()[i]; + } + auto list = app::DataModel::List(mDstOffsetsBuf, size); + mParams.SetDSTOffsets(list); + } + if (params.GetTimeZone().HasValue()) + { + ChipLogProgress(Controller, "Setting Time Zone from parameters"); + size_t size = std::min(params.GetTimeZone().Value().size(), kMaxSupportedTimeZones); + for (size_t i = 0; i < size; ++i) + { + mTimeZoneBuf[i] = params.GetTimeZone().Value()[i]; + if (mTimeZoneBuf[i].name.HasValue()) + { + auto span = MutableCharSpan(mTimeZoneNames[i], kMaxTimeZoneNameLen); + CopyCharSpanToMutableCharSpan(mTimeZoneBuf[i].name.Value(), span); + mTimeZoneBuf[i].name.SetValue(span); + } + } + } + return CHIP_NO_ERROR; } diff --git a/src/controller/AutoCommissioner.h b/src/controller/AutoCommissioner.h index 66dafeef6851cb..4bf6217ee4c019 100644 --- a/src/controller/AutoCommissioner.h +++ b/src/controller/AutoCommissioner.h @@ -102,6 +102,17 @@ class AutoCommissioner : public CommissioningDelegate uint8_t mThreadOperationalDataset[CommissioningParameters::kMaxThreadDatasetLen]; char mCountryCode[CommissioningParameters::kMaxCountryCodeLen]; + // Time zone is statically allocated because it is max 2 and not trivially destructible + static constexpr size_t kMaxSupportedTimeZones = 2; + app::Clusters::TimeSynchronization::Structs::TimeZoneStruct::Type mTimeZoneBuf[kMaxSupportedTimeZones]; + static constexpr size_t kMaxTimeZoneNameLen = 64; + char mTimeZoneNames[kMaxTimeZoneNameLen][kMaxSupportedTimeZones]; + + // DSTOffsetStructs are similarly not trivially destructible. They don't have a defined size, but we're + // going to do static allocation of the buffers anyway until we replace chip::Optional with std::optional. + static constexpr size_t kMaxSupportedDstStructs = 10; + app::Clusters::TimeSynchronization::Structs::DSTOffsetStruct::Type mDstOffsetsBuf[kMaxSupportedDstStructs]; + bool mNeedsNetworkSetup = false; ReadCommissioningInfo mDeviceCommissioningInfo; bool mNeedsDST = false; diff --git a/src/controller/CommissioningDelegate.h b/src/controller/CommissioningDelegate.h index 47ca12166ec8bf..3ccfd87084dab2 100644 --- a/src/controller/CommissioningDelegate.h +++ b/src/controller/CommissioningDelegate.h @@ -511,6 +511,8 @@ class CommissioningParameters mAttestationSignature.ClearValue(); mPAI.ClearValue(); mDAC.ClearValue(); + mTimeZone.ClearValue(); + mDSTOffsets.ClearValue(); } private: