Skip to content

Commit

Permalink
Pull request #1966: Applied changes to prevent loss of data when unla…
Browse files Browse the repository at this point in the history
…tching on 917

Merge in WMN_TOOLS/matter from bugfix/loosing_pin_unlatch_fix to silabs_slc_1.3

Squashed commit of the following:

commit 22e972cc134eb145aa3cf0e99c920975efbcf1e8
Author: lpbeliveau-silabs <[email protected]>
Date:   Fri Jun 7 14:11:31 2024 -0400

    Applied changes to prevent loss of data when unlatching on 917
  • Loading branch information
lpbeliveau-silabs committed Oct 29, 2024
1 parent 934ac68 commit 087efb5
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 10 deletions.
22 changes: 15 additions & 7 deletions examples/lock-app/silabs/include/LockManager.h
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,12 @@ class LockManager
private:
struct UnlatchContext
{
static constexpr uint8_t kMaxPinLength = UINT8_MAX;
uint8_t mPinBuffer[kMaxPinLenght];
uint8_t mPinLength;
chip::EndpointId mEndpointId;
Nullable<chip::FabricIndex> mFabricIdx;
Nullable<chip::NodeId> mNodeId;
Optional<chip::ByteSpan> mPin;
OperationErrorEnum mErr;

void Update(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
Expand All @@ -211,8 +213,18 @@ class LockManager
mEndpointId = endpointId;
mFabricIdx = fabricIdx;
mNodeId = nodeId;
mPin = pin;
mErr = err;

if (pin.HasValue())
{
memcpy(mPinBuffer, pin.Value().data(), pin.Value().size());
mPinLength = static_cast<uint8_t>(pin.Value().size());
}
else
{
memset(mPinBuffer, 0, kMaxPinLenght);
mPinLength = 0;
}
}
};
UnlatchContext mUnlatchContext;
Expand Down Expand Up @@ -242,11 +254,7 @@ class LockManager
uint8_t mCredentialData[kNumCredentialTypes][kMaxCredentials][kMaxCredentialSize];
CredentialStruct mCredentials[kMaxUsers][kMaxCredentials];

static LockManager sLock;
EFR32DoorLock::LockInitParams::LockParam LockParams;
};

inline LockManager & LockMgr()
{
return LockManager::sLock;
}
LockManager & LockMgr();
13 changes: 10 additions & 3 deletions examples/lock-app/silabs/src/LockManager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,18 @@
#include <cstring>
#include <lib/support/logging/CHIPLogging.h>

LockManager LockManager::sLock;

using namespace ::chip::DeviceLayer::Internal;
using namespace EFR32DoorLock::LockInitParams;

namespace {
LockManager sLock;
} // namespace

LockManager & LockMgr()
{
return sLock;
}

CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state, LockParam lockParam)
{

Expand Down Expand Up @@ -258,7 +265,7 @@ void LockManager::UnlockAfterUnlatch()
if (mUnlatchContext.mEndpointId != kInvalidEndpointId)
{
succes = setLockState(mUnlatchContext.mEndpointId, mUnlatchContext.mFabricIdx, mUnlatchContext.mNodeId,
DlLockState::kUnlocked, mUnlatchContext.mPin, mUnlatchContext.mErr);
DlLockState::kUnlocked, MakeOptional(chip::ByteSpan(mUnlatchContext.mPinBuffer, mUnlatchContext.mPinLength)), mUnlatchContext.mErr);
}

if (!succes)
Expand Down

0 comments on commit 087efb5

Please sign in to comment.