From 80ee243109c1536289e185fd763c8f51d7ac7462 Mon Sep 17 00:00:00 2001 From: Boris Zbarsky Date: Wed, 15 Feb 2023 16:00:12 -0500 Subject: [PATCH] Remove the legacy CredentialStruct definition. (#25084) Switches consumers to Clusters::DoorLock::Structs::CredentialStruct::Type. af-structs.h is now empty, but will be removed in a separate PR to make things a bit easier to review. --- examples/lock-app/genio/src/LockManager.cpp | 6 +- .../infineon/cyw30739/src/LockManager.cpp | 9 +- .../infineon/psoc6/src/LockManager.cpp | 9 +- examples/lock-app/linux/src/LockEndpoint.cpp | 2 +- .../silabs/SiWx917/src/LockManager.cpp | 9 +- .../lock-app/silabs/efr32/src/LockManager.cpp | 9 +- .../platform/esp32/lock/BoltLockManager.cpp | 9 +- .../door-lock-server/door-lock-server.cpp | 89 +++++++++---------- .../door-lock-server/door-lock-server.h | 4 +- src/app/common/templates/config-data.yaml | 5 +- src/lib/support/ScopedBuffer.h | 29 +++++- .../app-common/zap-generated/af-structs.h | 7 -- 12 files changed, 107 insertions(+), 80 deletions(-) diff --git a/examples/lock-app/genio/src/LockManager.cpp b/examples/lock-app/genio/src/LockManager.cpp index 66e394bd00c744..f558bb1de96070 100644 --- a/examples/lock-app/genio/src/LockManager.cpp +++ b/examples/lock-app/genio/src/LockManager.cpp @@ -678,13 +678,13 @@ bool LockManager::setLockState(chip::EndpointId endpointId, DlLockState lockStat { for (uint8_t j = 0; j < kMaxCredentialsPerUser; j++) { - if (mLockCredentials[mCredentials[i][j].CredentialIndex - 1].credentialType != CredentialTypeEnum::kPin || - mLockCredentials[mCredentials[i][j].CredentialIndex - 1].status == DlCredentialStatus::kAvailable) + if (mLockCredentials[mCredentials[i][j].credentialIndex - 1].credentialType != CredentialTypeEnum::kPin || + mLockCredentials[mCredentials[i][j].credentialIndex - 1].status == DlCredentialStatus::kAvailable) { continue; } - if (mLockCredentials[mCredentials[i][j].CredentialIndex - 1].credentialData.data_equal(pin.Value()) && + if (mLockCredentials[mCredentials[i][j].credentialIndex - 1].credentialData.data_equal(pin.Value()) && mLockUsers[i].userStatus != UserStatusEnum::kOccupiedDisabled) { ChipLogDetail( diff --git a/examples/lock-app/infineon/cyw30739/src/LockManager.cpp b/examples/lock-app/infineon/cyw30739/src/LockManager.cpp index bc11e6128291a2..3e868f503a84c5 100644 --- a/examples/lock-app/infineon/cyw30739/src/LockManager.cpp +++ b/examples/lock-app/infineon/cyw30739/src/LockManager.cpp @@ -383,9 +383,12 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: for (size_t i = 0; i < totalCredentials; ++i) { - mCredentials[userIndex][i] = credentials[i]; - mCredentials[userIndex][i].CredentialType = 1; - mCredentials[userIndex][i].CredentialIndex = i + 1; + mCredentials[userIndex][i] = credentials[i]; + // TODO: Why are we modifying the passed-in credentials? + // https://github.com/project-chip/connectedhomeip/issues/25081 + // For now, preserve pre-existing behavior, which set credentialType to 1. + mCredentials[userIndex][i].credentialType = CredentialTypeEnum::kPin; + mCredentials[userIndex][i].credentialIndex = i + 1; } userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); diff --git a/examples/lock-app/infineon/psoc6/src/LockManager.cpp b/examples/lock-app/infineon/psoc6/src/LockManager.cpp index 6d218073cc97be..06de91f664a827 100644 --- a/examples/lock-app/infineon/psoc6/src/LockManager.cpp +++ b/examples/lock-app/infineon/psoc6/src/LockManager.cpp @@ -383,9 +383,12 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: for (size_t i = 0; i < totalCredentials; ++i) { - mCredentials[userIndex][i] = credentials[i]; - mCredentials[userIndex][i].CredentialType = 1; - mCredentials[userIndex][i].CredentialIndex = i + 1; + mCredentials[userIndex][i] = credentials[i]; + // TODO: Why are we modifying the passed-in credentials? + // https://github.com/project-chip/connectedhomeip/issues/25081 + // For now, preserve pre-existing behavior, which set credentialType to 1. + mCredentials[userIndex][i].credentialType = CredentialTypeEnum::kPin; + mCredentials[userIndex][i].credentialIndex = i + 1; } userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); diff --git a/examples/lock-app/linux/src/LockEndpoint.cpp b/examples/lock-app/linux/src/LockEndpoint.cpp index 672b2f32f9fb75..bb18cbe2263747 100644 --- a/examples/lock-app/linux/src/LockEndpoint.cpp +++ b/examples/lock-app/linux/src/LockEndpoint.cpp @@ -424,7 +424,7 @@ bool LockEndpoint::setLockState(DlLockState lockState, const Optional(credential - pinCredentials.begin()); auto user = std::find_if(mLockUsers.begin(), mLockUsers.end(), [credential, credentialIndex](const LockUserInfo & u) { return std::any_of(u.credentials.begin(), u.credentials.end(), [&credential, credentialIndex](const CredentialStruct & c) { - return c.CredentialIndex == credentialIndex && c.CredentialType == to_underlying(credential->credentialType); + return c.credentialIndex == credentialIndex && c.credentialType == credential->credentialType; }); }); if (user == mLockUsers.end()) diff --git a/examples/lock-app/silabs/SiWx917/src/LockManager.cpp b/examples/lock-app/silabs/SiWx917/src/LockManager.cpp index 3ceba52e8a6f5e..7417481372b6b3 100644 --- a/examples/lock-app/silabs/SiWx917/src/LockManager.cpp +++ b/examples/lock-app/silabs/SiWx917/src/LockManager.cpp @@ -378,9 +378,12 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: for (size_t i = 0; i < totalCredentials; ++i) { - mCredentials[userIndex][i] = credentials[i]; - mCredentials[userIndex][i].CredentialType = 1; - mCredentials[userIndex][i].CredentialIndex = i + 1; + mCredentials[userIndex][i] = credentials[i]; + // TODO: Why are we modifying the passed-in credentials? + // https://github.com/project-chip/connectedhomeip/issues/25082 + // For now, preserve pre-existing behavior, which set credentialType to 1. + mCredentials[userIndex][i].credentialType = CredentialTypeEnum::kPin; + mCredentials[userIndex][i].credentialIndex = i + 1; } userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); diff --git a/examples/lock-app/silabs/efr32/src/LockManager.cpp b/examples/lock-app/silabs/efr32/src/LockManager.cpp index 54bd876147d1c3..f01371bb5948f3 100644 --- a/examples/lock-app/silabs/efr32/src/LockManager.cpp +++ b/examples/lock-app/silabs/efr32/src/LockManager.cpp @@ -378,9 +378,12 @@ bool LockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, chip: for (size_t i = 0; i < totalCredentials; ++i) { - mCredentials[userIndex][i] = credentials[i]; - mCredentials[userIndex][i].CredentialType = 1; - mCredentials[userIndex][i].CredentialIndex = i + 1; + mCredentials[userIndex][i] = credentials[i]; + // TODO: Why are we modifying the passed-in credentials? + // https://github.com/project-chip/connectedhomeip/issues/25082 + // For now, preserve pre-existing behavior, which set credentialType to 1. + mCredentials[userIndex][i].credentialType = CredentialTypeEnum::kPin; + mCredentials[userIndex][i].credentialIndex = i + 1; } userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); diff --git a/examples/platform/esp32/lock/BoltLockManager.cpp b/examples/platform/esp32/lock/BoltLockManager.cpp index 657d38eb6a687f..5c4b3225f92d8e 100644 --- a/examples/platform/esp32/lock/BoltLockManager.cpp +++ b/examples/platform/esp32/lock/BoltLockManager.cpp @@ -430,9 +430,12 @@ bool BoltLockManager::SetUser(chip::EndpointId endpointId, uint16_t userIndex, c for (size_t i = 0; i < totalCredentials; ++i) { - mCredentials[userIndex][i] = credentials[i]; - mCredentials[userIndex][i].CredentialType = 1; - mCredentials[userIndex][i].CredentialIndex = i + 1; + mCredentials[userIndex][i] = credentials[i]; + // TODO: Why are we modifying the passed-in credentials? + // https://github.com/project-chip/connectedhomeip/issues/25083 + // For now, preserve pre-existing behavior, which set credentialType to 1. + mCredentials[userIndex][i].credentialType = CredentialTypeEnum::kPin; + mCredentials[userIndex][i].credentialIndex = i + 1; } userInStorage.credentials = chip::Span(mCredentials[userIndex], totalCredentials); diff --git a/src/app/clusters/door-lock-server/door-lock-server.cpp b/src/app/clusters/door-lock-server/door-lock-server.cpp index 197f105d13897a..2a475b6a02f485 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.cpp +++ b/src/app/clusters/door-lock-server/door-lock-server.cpp @@ -474,10 +474,7 @@ void DoorLockServer::getUserCommandHandler(chip::app::CommandHandler * commandOb TLV::kTLVType_Array, credentialsContainer)); for (size_t i = 0; i < user.credentials.size(); ++i) { - Structs::CredentialStruct::Type credential; - credential.credentialIndex = user.credentials.data()[i].CredentialIndex; - credential.credentialType = static_cast(user.credentials.data()[i].CredentialType); - SuccessOrExit(err = credential.Encode(*writer, TLV::AnonymousTag())); + SuccessOrExit(err = user.credentials.data()[i].Encode(*writer, TLV::AnonymousTag())); } SuccessOrExit(err = writer->EndContainer(credentialsContainer)); } @@ -1675,8 +1672,8 @@ bool DoorLockServer::findUserIndexByCredential(chip::EndpointId endpointId, Cred for (size_t j = 0; j < user.credentials.size(); ++j) { - if (user.credentials.data()[j].CredentialIndex == credentialIndex && - user.credentials.data()[j].CredentialType == to_underlying(credentialType)) + if (user.credentials.data()[j].credentialIndex == credentialIndex && + user.credentials.data()[j].credentialType == credentialType) { userIndex = i; return true; @@ -1713,18 +1710,18 @@ bool DoorLockServer::findUserIndexByCredential(chip::EndpointId endpointId, Cred for (const auto & credential : user.credentials) { - if (credential.CredentialType != to_underlying(credentialType)) + if (credential.credentialType != credentialType) { continue; } EmberAfPluginDoorLockCredentialInfo credentialInfo; - if (!emberAfPluginDoorLockGetCredential(endpointId, credential.CredentialIndex, credentialType, credentialInfo)) + if (!emberAfPluginDoorLockGetCredential(endpointId, credential.credentialIndex, credentialType, credentialInfo)) { ChipLogError(Zcl, "[findUserIndexByCredential] Unable to get credential: app error " "[userIndex=%d,credentialIndex=%d,credentialType=%u]", - i, credential.CredentialIndex, to_underlying(credentialType)); + i, credential.credentialIndex, to_underlying(credentialType)); return false; } @@ -1734,14 +1731,14 @@ bool DoorLockServer::findUserIndexByCredential(chip::EndpointId endpointId, Cred "[findUserIndexByCredential] Users/Credentials database error: credential index attached to user is " "not occupied " "[userIndex=%d,credentialIndex=%d,credentialType=%u]", - i, credential.CredentialIndex, to_underlying(credentialType)); + i, credential.credentialIndex, to_underlying(credentialType)); return false; } if (credentialInfo.credentialData.data_equal(credentialData)) { userIndex = i; - credentialIndex = credential.CredentialIndex; + credentialIndex = credential.credentialIndex; userInfo = user; return true; } @@ -1905,16 +1902,16 @@ Status DoorLockServer::clearUser(chip::EndpointId endpointId, chip::FabricIndex { emberAfDoorLockClusterPrintln( "[ClearUser] Clearing associated credential [endpointId=%d,userIndex=%d,credentialType=%u,credentialIndex=%d]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex); + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex); - if (!emberAfPluginDoorLockSetCredential(endpointId, credential.CredentialIndex, kUndefinedFabricIndex, - kUndefinedFabricIndex, DlCredentialStatus::kAvailable, - static_cast(credential.CredentialType), chip::ByteSpan())) + if (!emberAfPluginDoorLockSetCredential(endpointId, credential.credentialIndex, kUndefinedFabricIndex, + kUndefinedFabricIndex, DlCredentialStatus::kAvailable, credential.credentialType, + chip::ByteSpan())) { ChipLogError(Zcl, "[ClearUser] Unable to remove credentials associated with user - internal error " "[endpointId=%d,userIndex=%d,credentialIndex=%d,credentialType=%u]", - endpointId, userIndex, credential.CredentialIndex, credential.CredentialType); + endpointId, userIndex, credential.credentialIndex, to_underlying(credential.credentialType)); return Status::Failure; } } @@ -2002,7 +1999,7 @@ DlStatus DoorLockServer::createNewCredentialAndUser(chip::EndpointId endpointId, { emberAfDoorLockClusterPrintln("[SetCredential] Unable to create new user for credential: no available user slots " "[endpointId=%d,credentialIndex=%d]", - endpointId, credential.CredentialIndex); + endpointId, credential.credentialIndex); return DlStatus::kOccupied; } @@ -2013,24 +2010,23 @@ DlStatus DoorLockServer::createNewCredentialAndUser(chip::EndpointId endpointId, { emberAfDoorLockClusterPrintln("[SetCredential] Unable to create new user for credential: internal error " "[endpointId=%d,credentialIndex=%d,userIndex=%d,status=%d]", - endpointId, credential.CredentialIndex, availableUserIndex, status); + endpointId, credential.credentialIndex, availableUserIndex, status); return DlStatus::kFailure; } - if (!emberAfPluginDoorLockSetCredential(endpointId, credential.CredentialIndex, creatorFabricIdx, creatorFabricIdx, - DlCredentialStatus::kOccupied, - static_cast(credential.CredentialType), credentialData)) + if (!emberAfPluginDoorLockSetCredential(endpointId, credential.credentialIndex, creatorFabricIdx, creatorFabricIdx, + DlCredentialStatus::kOccupied, credential.credentialType, credentialData)) { emberAfDoorLockClusterPrintln("[SetCredential] Unable to set the credential: app error " "[endpointId=%d,credentialIndex=%d,credentialType=%u,dataLength=%u]", - endpointId, credential.CredentialIndex, credential.CredentialType, + endpointId, credential.credentialIndex, to_underlying(credential.credentialType), static_cast(credentialData.size())); return DlStatus::kFailure; } emberAfDoorLockClusterPrintln("[SetCredential] Credential and user were created " "[endpointId=%d,credentialIndex=%d,credentialType=%u,dataLength=%u,userIndex=%d]", - endpointId, credential.CredentialIndex, credential.CredentialType, + endpointId, credential.credentialIndex, to_underlying(credential.credentialType), static_cast(credentialData.size()), availableUserIndex); createdUserIndex = availableUserIndex; @@ -2045,7 +2041,7 @@ DlStatus DoorLockServer::createNewCredentialAndAddItToUser(chip::EndpointId endp { emberAfDoorLockClusterPrintln("[SetCredential] Unable to add new credential to user: user out of bounds " "[endpointId=%d,credentialIndex=%d,userIndex=%d]", - endpointId, credential.CredentialIndex, userIndex); + endpointId, credential.credentialIndex, userIndex); return DlStatus::kInvalidField; } @@ -2054,7 +2050,7 @@ DlStatus DoorLockServer::createNewCredentialAndAddItToUser(chip::EndpointId endp { emberAfDoorLockClusterPrintln( "[SetCredential] Unable to check if credential exists: app error [endpointId=%d,credentialIndex=%d,userIndex=%d]", - endpointId, credential.CredentialIndex, userIndex); + endpointId, credential.credentialIndex, userIndex); return DlStatus::kFailure; } @@ -2064,7 +2060,7 @@ DlStatus DoorLockServer::createNewCredentialAndAddItToUser(chip::EndpointId endp { emberAfDoorLockClusterPrintln("[SetCredential] Unable to add credential to user: user slot is empty " "[endpointId=%d,credentialIndex=%d,userIndex=%d]", - endpointId, credential.CredentialIndex, userIndex); + endpointId, credential.credentialIndex, userIndex); return DlStatus::kInvalidField; } @@ -2074,17 +2070,16 @@ DlStatus DoorLockServer::createNewCredentialAndAddItToUser(chip::EndpointId endp { emberAfDoorLockClusterPrintln("[SetCredential] Unable to add credential to a user: internal error " "[endpointId=%d,credentialIndex=%d,userIndex=%d,status=%u]", - endpointId, credential.CredentialIndex, userIndex, to_underlying(status)); + endpointId, credential.credentialIndex, userIndex, to_underlying(status)); return status; } - if (!emberAfPluginDoorLockSetCredential(endpointId, credential.CredentialIndex, modifierFabricIdx, modifierFabricIdx, - DlCredentialStatus::kOccupied, - static_cast(credential.CredentialType), credentialData)) + if (!emberAfPluginDoorLockSetCredential(endpointId, credential.credentialIndex, modifierFabricIdx, modifierFabricIdx, + DlCredentialStatus::kOccupied, credential.credentialType, credentialData)) { emberAfDoorLockClusterPrintln("[SetCredential] Unable to set the credential: app error " "[endpointId=%d,credentialIndex=%d,credentialType=%u,dataLength=%u]", - endpointId, credential.CredentialIndex, credential.CredentialType, + endpointId, credential.credentialIndex, to_underlying(credential.credentialType), static_cast(credentialData.size())); return DlStatus::kFailure; } @@ -2109,13 +2104,13 @@ DlStatus DoorLockServer::addCredentialToUser(chip::EndpointId endpointId, chip:: // appclusters, 5.2.4.40: CredentialIndex in CredentialStruct provided SHALL be for an available credential slot. // appclusters, 5.6.3.2: This is the index of the specific credential used to authorize // the lock operation in the list of credentials identified by CredentialType - if (user.credentials.data()[i].CredentialIndex == credential.CredentialIndex && - user.credentials.data()[i].CredentialType == credential.CredentialType) + if (user.credentials.data()[i].credentialIndex == credential.credentialIndex && + user.credentials.data()[i].credentialType == credential.credentialType) { emberAfDoorLockClusterPrintln( "[AddCredentialToUser] Unable to add credential to user: credential with this index is already associated " "with user [endpointId=%d,userIndex=%d,credentialType=%d,credentialIndex=%d]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex); + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex); return DlStatus::kInvalidField; } } @@ -2126,7 +2121,7 @@ DlStatus DoorLockServer::addCredentialToUser(chip::EndpointId endpointId, chip:: ChipLogError(Zcl, "[AddCredentialToUser] Unable to get the number of available credentials per user: internal error " "[endpointId=%d,userIndex=%d,credentialType=%d,credentialIndex=%d]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex); + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex); return DlStatus::kFailure; } @@ -2159,14 +2154,14 @@ DlStatus DoorLockServer::addCredentialToUser(chip::EndpointId endpointId, chip:: emberAfDoorLockClusterPrintln( "[AddCredentialToUser] Unable to add credential to user: credential with this index is already associated " "with user [endpointId=%d,userIndex=%d,credentialType=%d,credentialIndex=%d,userTotalCredentials=%u]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex, + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex, static_cast(user.credentials.size())); return DlStatus::kFailure; } emberAfDoorLockClusterPrintln("[AddCredentialToUser] Credential added to user " "[endpointId=%d,userIndex=%d,credentialType=%d,credentialIndex=%d,userTotalCredentials=%u]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex, + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex, static_cast(user.credentials.size() + 1)); return DlStatus::kSuccess; @@ -2187,7 +2182,7 @@ DlStatus DoorLockServer::modifyCredentialForUser(chip::EndpointId endpointId, ch for (size_t i = 0; i < user.credentials.size(); ++i) { // appclusters, 5.2.4.40: user should already be associated with given credentialIndex - if (user.credentials.data()[i].CredentialIndex == credential.CredentialIndex) + if (user.credentials.data()[i].credentialIndex == credential.credentialIndex) { chip::Platform::ScopedMemoryBuffer newCredentials; if (!newCredentials.Alloc(user.credentials.size())) @@ -2195,8 +2190,8 @@ DlStatus DoorLockServer::modifyCredentialForUser(chip::EndpointId endpointId, ch ChipLogError(Zcl, "[ModifyUserCredential] Unable to allocate the buffer for credentials " "[endpointId=%d,userIndex=%d,userTotalCredentials=%u,credentialType=%d,credentialIndex=%d]", - endpointId, userIndex, static_cast(user.credentials.size()), credential.CredentialType, - credential.CredentialIndex); + endpointId, userIndex, static_cast(user.credentials.size()), + to_underlying(credential.credentialType), credential.credentialIndex); return DlStatus::kFailure; } memcpy(newCredentials.Get(), user.credentials.data(), sizeof(CredentialStruct) * user.credentials.size()); @@ -2205,7 +2200,7 @@ DlStatus DoorLockServer::modifyCredentialForUser(chip::EndpointId endpointId, ch emberAfDoorLockClusterPrintln( "[ModifyUserCredential] Unable to add credential to user: credential with this index is already associated " "[endpointId=%d,userIndex=%d,credentialType=%d,credentialIndex=%d]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex); + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex); if (!emberAfPluginDoorLockSetUser(endpointId, userIndex, user.createdBy, modifierFabricIdx, user.userName, user.userUniqueId, user.userStatus, user.userType, user.credentialRule, @@ -2214,7 +2209,7 @@ DlStatus DoorLockServer::modifyCredentialForUser(chip::EndpointId endpointId, ch emberAfDoorLockClusterPrintln( "[ModifyUserCredential] Unable to modify user credential: credential with this index is already associated " "with user [endpointId=%d,userIndex=%d,credentialType=%d,credentialIndex=%d,userTotalCredentials=%u]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex, + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex, static_cast(user.credentials.size())); return DlStatus::kFailure; } @@ -2222,7 +2217,7 @@ DlStatus DoorLockServer::modifyCredentialForUser(chip::EndpointId endpointId, ch emberAfDoorLockClusterPrintln( "[ModifyUserCredential] User credential modified " "[endpointId=%d,userIndex=%d,credentialType=%d,credentialIndex=%d,userTotalCredentials=%u]", - endpointId, userIndex, credential.CredentialType, credential.CredentialIndex, + endpointId, userIndex, to_underlying(credential.credentialType), credential.credentialIndex, static_cast(user.credentials.size())); return DlStatus::kSuccess; @@ -2233,7 +2228,7 @@ DlStatus DoorLockServer::modifyCredentialForUser(chip::EndpointId endpointId, ch emberAfDoorLockClusterPrintln( "[ModifyUserCredential] Unable to modify user credential: user is not associated with credential index " "[endpointId=%d,userIndex=%d,credentialIndex=%d]", - endpointId, userIndex, credential.CredentialIndex); + endpointId, userIndex, credential.credentialIndex); return DlStatus::kInvalidField; } @@ -2264,7 +2259,7 @@ DlStatus DoorLockServer::createCredential(chip::EndpointId endpointId, chip::Fab return DlStatus::kInvalidField; } - CredentialStruct credential{ to_underlying(credentialType), credentialIndex }; + CredentialStruct credential{ credentialType, credentialIndex }; // appclusters, 5.2.4.40: if userIndex is not provided we should create new user DlStatus status = DlStatus::kSuccess; if (userIndex.IsNull()) @@ -2354,7 +2349,7 @@ DlStatus DoorLockServer::modifyCredential(chip::EndpointId endpointId, chip::Fab return DlStatus::kInvalidField; } - CredentialStruct credential{ to_underlying(credentialType), credentialIndex }; + CredentialStruct credential{ credentialType, credentialIndex }; auto status = modifyCredentialForUser(endpointId, modifierFabricIndex, userIndex, credential); if (DlStatus::kSuccess == status) @@ -2789,7 +2784,7 @@ Status DoorLockServer::clearCredential(chip::EndpointId endpointId, chip::Fabric size_t newCredentialsCount = 0; for (const auto & c : relatedUser.credentials) { - if (static_cast(c.CredentialType) == credentialType && c.CredentialIndex == credentialIndex) + if (c.credentialType == credentialType && c.credentialIndex == credentialIndex) { continue; } diff --git a/src/app/clusters/door-lock-server/door-lock-server.h b/src/app/clusters/door-lock-server/door-lock-server.h index d56ef343ff43f7..3eeb79eba043e5 100644 --- a/src/app/clusters/door-lock-server/door-lock-server.h +++ b/src/app/clusters/door-lock-server/door-lock-server.h @@ -24,7 +24,6 @@ #pragma once -#include #include #include #include @@ -56,7 +55,8 @@ using chip::app::Clusters::DoorLock::UserTypeEnum; using chip::app::DataModel::List; using chip::app::DataModel::Nullable; -using LockOpCredentials = chip::app::Clusters::DoorLock::Structs::CredentialStruct::Type; +using CredentialStruct = chip::app::Clusters::DoorLock::Structs::CredentialStruct::Type; +using LockOpCredentials = CredentialStruct; typedef bool (*RemoteLockOpHandler)(chip::EndpointId endpointId, const Optional & pinCode, OperationErrorEnum & err); diff --git a/src/app/common/templates/config-data.yaml b/src/app/common/templates/config-data.yaml index 32521d3798a7e5..0d725e6218310d 100644 --- a/src/app/common/templates/config-data.yaml +++ b/src/app/common/templates/config-data.yaml @@ -1,7 +1,4 @@ -LegacyStructs: - # List of structs for which we output a legacy definition in af-structs.h - # Ideally this list should become empty. - - CredentialStruct +LegacyStructs: [] # Will be removed together with af-structs.h WeakEnums: # Allow-list of enums that we generate as enums, not enum classes. diff --git a/src/lib/support/ScopedBuffer.h b/src/lib/support/ScopedBuffer.h index ffba6c08478839..0158ad4acd0d5d 100644 --- a/src/lib/support/ScopedBuffer.h +++ b/src/lib/support/ScopedBuffer.h @@ -137,7 +137,7 @@ class ScopedMemoryBuffer : public Impl::ScopedMemoryBufferBase public: using Base = Impl::ScopedMemoryBufferBase; - static_assert(std::is_trivial::value, "Constructors won't get run"); + static_assert(std::is_trivially_destructible::value, "Destructors won't get run"); inline T * Get() { return static_cast(Base::Ptr()); } inline T & operator[](size_t index) { return Get()[index]; } @@ -150,14 +150,41 @@ class ScopedMemoryBuffer : public Impl::ScopedMemoryBufferBase ScopedMemoryBuffer & Calloc(size_t elementCount) { Base::Calloc(elementCount, sizeof(T)); + ExecuteConstructors(elementCount); return *this; } ScopedMemoryBuffer & Alloc(size_t elementCount) { Base::Alloc(elementCount * sizeof(T)); + ExecuteConstructors(elementCount); return *this; } + +private: + template ::value, int> = 0> + void ExecuteConstructors(size_t elementCount) + { + // Do nothing if our type is trivial. In particular, if we are a buffer + // of integers, we should not go zero-initializing them here: either + // caller wants that and called Calloc(), or it doesn't and we shouldn't + // do it. + } + + template ::value, int> = 0> + void ExecuteConstructors(size_t elementCount) + { + T * elementPtr = Get(); + if (elementPtr == nullptr) + { + // Alloc failed, don't bother. + return; + } + for (size_t i = 0; i < elementCount; ++i) + { + new (&elementPtr[i]) T(); + } + } }; /** diff --git a/zzz_generated/app-common/app-common/zap-generated/af-structs.h b/zzz_generated/app-common/app-common/zap-generated/af-structs.h index 013c0a0246a95b..1d648ca289b391 100644 --- a/zzz_generated/app-common/app-common/zap-generated/af-structs.h +++ b/zzz_generated/app-common/app-common/zap-generated/af-structs.h @@ -29,10 +29,3 @@ #include #include "enums.h" - -// Struct for CredentialStruct -typedef struct _CredentialStruct -{ - uint8_t CredentialType; - uint16_t CredentialIndex; -} CredentialStruct;