@@ -860,10 +860,27 @@ void DoorLockServer::getCredentialStatusCommandHandler(chip::app::CommandHandler
860
860
return ;
861
861
}
862
862
863
+ // Our response will need to include the index of the next occupied credential slot
864
+ // after credentialIndex, if there is one.
865
+ //
866
+ // We want to figure this out before we call emberAfPluginDoorLockGetCredential, because to do
867
+ // so we will also need to call emberAfPluginDoorLockGetCredential, and the
868
+ // EmberAfPluginDoorLockCredentialInfo we get might be pointing into some application-static
869
+ // buffers (for its credential data and whatnot).
870
+ DataModel::Nullable<uint16_t > nextCredentialIndex;
871
+ {
872
+ uint16_t foundNextCredentialIndex;
873
+ if (findOccupiedCredentialSlot (commandPath.mEndpointId , credentialType, static_cast <uint16_t >(credentialIndex + 1 ),
874
+ foundNextCredentialIndex))
875
+ {
876
+ nextCredentialIndex.SetNonNull (foundNextCredentialIndex);
877
+ }
878
+ }
879
+
863
880
uint16_t maxNumberOfCredentials = 0 ;
864
881
if (!credentialIndexValid (commandPath.mEndpointId , credentialType, credentialIndex, maxNumberOfCredentials))
865
882
{
866
- sendGetCredentialResponse (commandObj, commandPath, credentialType, credentialIndex, 0 , nullptr , false );
883
+ sendGetCredentialResponse (commandObj, commandPath, credentialType, credentialIndex, nextCredentialIndex, 0 , nullptr , false );
867
884
return ;
868
885
}
869
886
@@ -896,8 +913,8 @@ void DoorLockServer::getCredentialStatusCommandHandler(chip::app::CommandHandler
896
913
}
897
914
}
898
915
899
- sendGetCredentialResponse (commandObj, commandPath, credentialType, credentialIndex, userIndexWithCredential, &credentialInfo ,
900
- credentialExists);
916
+ sendGetCredentialResponse (commandObj, commandPath, credentialType, credentialIndex, nextCredentialIndex ,
917
+ userIndexWithCredential, &credentialInfo, credentialExists);
901
918
}
902
919
903
920
namespace {
@@ -918,9 +935,12 @@ bool IsAliroCredentialType(CredentialTypeEnum credentialType)
918
935
void DoorLockServer::sendGetCredentialResponse (chip::app::CommandHandler * commandObj,
919
936
const chip::app::ConcreteCommandPath & commandPath,
920
937
CredentialTypeEnum credentialType, uint16_t credentialIndex,
921
- uint16_t userIndexWithCredential,
938
+ DataModel::Nullable< uint16_t > nextCredentialIndex, uint16_t userIndexWithCredential,
922
939
EmberAfPluginDoorLockCredentialInfo * credentialInfo, bool credentialExists)
923
940
{
941
+ // Important: We have to make sure nothing in this function calls
942
+ // emberAfPluginDoorLockGetCredential, because that might stomp on the data
943
+ // pointed to by credentialInfo.
924
944
Commands::GetCredentialStatusResponse::Type response{ .credentialExists = credentialExists };
925
945
if (credentialExists && !(nullptr == credentialInfo))
926
946
{
@@ -949,19 +969,14 @@ void DoorLockServer::sendGetCredentialResponse(chip::app::CommandHandler * comma
949
969
response.credentialData .Emplace (NullNullable);
950
970
}
951
971
}
952
- uint16_t nextCredentialIndex = 0 ;
953
- if (findOccupiedCredentialSlot (commandPath.mEndpointId , credentialType, static_cast <uint16_t >(credentialIndex + 1 ),
954
- nextCredentialIndex))
955
- {
956
- response.nextCredentialIndex .SetNonNull (nextCredentialIndex);
957
- }
972
+ response.nextCredentialIndex = nextCredentialIndex;
958
973
commandObj->AddResponse (commandPath, response);
959
974
960
975
ChipLogProgress (Zcl,
961
976
" [GetCredentialStatus] Prepared credential status "
962
977
" [endpointId=%d,credentialType=%u,credentialIndex=%d,userIndex=%d,nextCredentialIndex=%d]" ,
963
978
commandPath.mEndpointId , to_underlying (credentialType), credentialIndex, userIndexWithCredential,
964
- nextCredentialIndex);
979
+ nextCredentialIndex. ValueOr ( 0 ) );
965
980
}
966
981
967
982
void DoorLockServer::clearCredentialCommandHandler (
0 commit comments