Skip to content

Commit

Permalink
Commissioning time sync: copy parameters to autocommissioner (#29908)
Browse files Browse the repository at this point in the history
* Commissioning time sync: copy parameters to autocommissioner

* Restyled by clang-format

* use a min function rather than being crazy

---------

Co-authored-by: Restyled.io <[email protected]>
  • Loading branch information
2 people authored and pull[bot] committed Jan 16, 2024
1 parent 48773ae commit 2a44d39
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
31 changes: 30 additions & 1 deletion src/controller/AutoCommissioner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -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<app::Clusters::TimeSynchronization::Structs::DSTOffsetStruct::Type>(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;
}

Expand Down
11 changes: 11 additions & 0 deletions src/controller/AutoCommissioner.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/controller/CommissioningDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -511,6 +511,8 @@ class CommissioningParameters
mAttestationSignature.ClearValue();
mPAI.ClearValue();
mDAC.ClearValue();
mTimeZone.ClearValue();
mDSTOffsets.ClearValue();
}

private:
Expand Down

0 comments on commit 2a44d39

Please sign in to comment.