Skip to content

Commit 087efb5

Browse files
Pull request #1966: Applied changes to prevent loss of data when unlatching 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 <louis-philip.beliveau@silabs.com> Date: Fri Jun 7 14:11:31 2024 -0400 Applied changes to prevent loss of data when unlatching on 917
1 parent 934ac68 commit 087efb5

File tree

2 files changed

+25
-10
lines changed

2 files changed

+25
-10
lines changed

examples/lock-app/silabs/include/LockManager.h

+15-7
Original file line numberDiff line numberDiff line change
@@ -199,10 +199,12 @@ class LockManager
199199
private:
200200
struct UnlatchContext
201201
{
202+
static constexpr uint8_t kMaxPinLength = UINT8_MAX;
203+
uint8_t mPinBuffer[kMaxPinLenght];
204+
uint8_t mPinLength;
202205
chip::EndpointId mEndpointId;
203206
Nullable<chip::FabricIndex> mFabricIdx;
204207
Nullable<chip::NodeId> mNodeId;
205-
Optional<chip::ByteSpan> mPin;
206208
OperationErrorEnum mErr;
207209

208210
void Update(chip::EndpointId endpointId, const Nullable<chip::FabricIndex> & fabricIdx,
@@ -211,8 +213,18 @@ class LockManager
211213
mEndpointId = endpointId;
212214
mFabricIdx = fabricIdx;
213215
mNodeId = nodeId;
214-
mPin = pin;
215216
mErr = err;
217+
218+
if (pin.HasValue())
219+
{
220+
memcpy(mPinBuffer, pin.Value().data(), pin.Value().size());
221+
mPinLength = static_cast<uint8_t>(pin.Value().size());
222+
}
223+
else
224+
{
225+
memset(mPinBuffer, 0, kMaxPinLenght);
226+
mPinLength = 0;
227+
}
216228
}
217229
};
218230
UnlatchContext mUnlatchContext;
@@ -242,11 +254,7 @@ class LockManager
242254
uint8_t mCredentialData[kNumCredentialTypes][kMaxCredentials][kMaxCredentialSize];
243255
CredentialStruct mCredentials[kMaxUsers][kMaxCredentials];
244256

245-
static LockManager sLock;
246257
EFR32DoorLock::LockInitParams::LockParam LockParams;
247258
};
248259

249-
inline LockManager & LockMgr()
250-
{
251-
return LockManager::sLock;
252-
}
260+
LockManager & LockMgr();

examples/lock-app/silabs/src/LockManager.cpp

+10-3
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,18 @@
2525
#include <cstring>
2626
#include <lib/support/logging/CHIPLogging.h>
2727

28-
LockManager LockManager::sLock;
29-
3028
using namespace ::chip::DeviceLayer::Internal;
3129
using namespace EFR32DoorLock::LockInitParams;
3230

31+
namespace {
32+
LockManager sLock;
33+
} // namespace
34+
35+
LockManager & LockMgr()
36+
{
37+
return sLock;
38+
}
39+
3340
CHIP_ERROR LockManager::Init(chip::app::DataModel::Nullable<chip::app::Clusters::DoorLock::DlLockState> state, LockParam lockParam)
3441
{
3542

@@ -258,7 +265,7 @@ void LockManager::UnlockAfterUnlatch()
258265
if (mUnlatchContext.mEndpointId != kInvalidEndpointId)
259266
{
260267
succes = setLockState(mUnlatchContext.mEndpointId, mUnlatchContext.mFabricIdx, mUnlatchContext.mNodeId,
261-
DlLockState::kUnlocked, mUnlatchContext.mPin, mUnlatchContext.mErr);
268+
DlLockState::kUnlocked, MakeOptional(chip::ByteSpan(mUnlatchContext.mPinBuffer, mUnlatchContext.mPinLength)), mUnlatchContext.mErr);
262269
}
263270

264271
if (!succes)

0 commit comments

Comments
 (0)