@@ -436,82 +436,58 @@ void DoorLockServer::getUserCommandHandler(chip::app::CommandHandler * commandOb
436
436
return ;
437
437
}
438
438
439
- CHIP_ERROR err = CHIP_NO_ERROR;
440
439
EmberAfPluginDoorLockUserInfo user;
441
- VerifyOrExit ( emberAfPluginDoorLockGetUser (commandPath.mEndpointId , userIndex, user), err = CHIP_ERROR_INTERNAL);
440
+ if (! emberAfPluginDoorLockGetUser (commandPath.mEndpointId , userIndex, user))
442
441
{
443
- chip::app::ConcreteCommandPath path = { emberAfCurrentEndpoint (), ::Id, Commands::GetUserResponse::Id };
444
- chip::TLV::TLVWriter * writer;
445
- SuccessOrExit (err = commandObj->PrepareCommand (path));
446
- VerifyOrExit ((writer = commandObj->GetCommandDataIBTLVWriter ()) != nullptr , err = CHIP_ERROR_INCORRECT_STATE);
447
- SuccessOrExit (
448
- err = writer->Put (chip::TLV::ContextTag (to_underlying (Commands::GetUserResponse::Fields::kUserIndex )), userIndex));
442
+ emberAfDoorLockClusterPrintln (" [GetUser] Could not get user info [userIndex=%d]" , userIndex);
443
+ commandObj->AddStatus (commandPath, Status::Failure);
444
+ return ;
445
+ }
449
446
450
- using ResponseFields = Commands::GetUserResponse::Fields;
447
+ Commands::GetUserResponse::Type response;
448
+ response.userIndex = userIndex;
451
449
452
- // appclusters, 5.2.4.36: we should not add user-specific field if the user status is set to Available
453
- if (UserStatusEnum::kAvailable != user.userStatus )
454
- {
455
- emberAfDoorLockClusterPrintln (" Found user in storage: "
456
- " [userIndex=%d,userName=\" %.*s\" ,userStatus=%u,userType=%u"
457
- " ,credentialRule=%u,createdBy=%u,modifiedBy=%u]" ,
458
- userIndex, static_cast <int >(user.userName .size ()), user.userName .data (),
459
- to_underlying (user.userStatus ), to_underlying (user.userType ),
460
- to_underlying (user.credentialRule ), user.createdBy , user.lastModifiedBy );
450
+ // appclusters, 5.2.4.36: we should not set user-specific fields to non-null if the user status is set to Available
451
+ if (UserStatusEnum::kAvailable != user.userStatus )
452
+ {
453
+ emberAfDoorLockClusterPrintln (" Found user in storage: "
454
+ " [userIndex=%d,userName=\" %.*s\" ,userStatus=%u,userType=%u"
455
+ " ,credentialRule=%u,createdBy=%u,modifiedBy=%u]" ,
456
+ userIndex, static_cast <int >(user.userName .size ()), user.userName .data (),
457
+ to_underlying (user.userStatus ), to_underlying (user.userType ),
458
+ to_underlying (user.credentialRule ), user.createdBy , user.lastModifiedBy );
461
459
462
- SuccessOrExit (err = writer->PutString (TLV::ContextTag (to_underlying (ResponseFields::kUserName )), user.userName ));
463
- if (0xFFFFFFFFU != user.userUniqueId )
464
- {
465
- SuccessOrExit (err = writer->Put (TLV::ContextTag (to_underlying (ResponseFields::kUserUniqueID )), user.userUniqueId ));
466
- }
467
- SuccessOrExit (err = writer->Put (TLV::ContextTag (to_underlying (ResponseFields::kUserStatus )), user.userStatus ));
468
- SuccessOrExit (err = writer->Put (TLV::ContextTag (to_underlying (ResponseFields::kUserType )), user.userType ));
469
- SuccessOrExit (err = writer->Put (TLV::ContextTag (to_underlying (ResponseFields::kCredentialRule )), user.credentialRule ));
470
- if (!user.credentials .empty ())
471
- {
472
- TLV::TLVType credentialsContainer;
473
- SuccessOrExit (err = writer->StartContainer (TLV::ContextTag (to_underlying (ResponseFields::kCredentials )),
474
- TLV::kTLVType_Array , credentialsContainer));
475
- for (size_t i = 0 ; i < user.credentials .size (); ++i)
476
- {
477
- SuccessOrExit (err = user.credentials .data ()[i].Encode (*writer, TLV::AnonymousTag ()));
478
- }
479
- SuccessOrExit (err = writer->EndContainer (credentialsContainer));
480
- }
481
- // Append fabric IDs only if the user was created/modified by matter
482
- if (user.creationSource == DlAssetSource::kMatterIM )
483
- {
484
- SuccessOrExit (err =
485
- writer->Put (TLV::ContextTag (to_underlying (ResponseFields::kCreatorFabricIndex )), user.createdBy ));
486
- }
487
- if (user.modificationSource == DlAssetSource::kMatterIM )
488
- {
489
- SuccessOrExit (err = writer->Put (TLV::ContextTag (to_underlying (ResponseFields::kLastModifiedFabricIndex )),
490
- user.lastModifiedBy ));
491
- }
460
+ response.userName .SetNonNull (user.userName );
461
+ if (0xFFFFFFFFU != user.userUniqueId )
462
+ {
463
+ response.userUniqueID .SetNonNull (user.userUniqueId );
492
464
}
493
- else
465
+ response.userStatus .SetNonNull (user.userStatus );
466
+ response.userType .SetNonNull (user.userType );
467
+ response.credentialRule .SetNonNull (user.credentialRule );
468
+ response.credentials .SetNonNull (user.credentials );
469
+ // Set fabric indices only if the user was created/modified by matter.
470
+ if (user.creationSource == DlAssetSource::kMatterIM )
494
471
{
495
- emberAfDoorLockClusterPrintln ( " [GetUser] User not found [userIndex=%d] " , userIndex );
472
+ response. creatorFabricIndex . SetNonNull (user. createdBy );
496
473
}
497
-
498
- // appclusters, 5.2.4.36.1: We need to add next occupied user after userIndex if any.
499
- uint16_t nextAvailableUserIndex = 0 ;
500
- if (findOccupiedUserSlot (commandPath.mEndpointId , static_cast <uint16_t >(userIndex + 1 ), nextAvailableUserIndex))
474
+ if (user.modificationSource == DlAssetSource::kMatterIM )
501
475
{
502
- SuccessOrExit (err =
503
- writer->Put (TLV::ContextTag (to_underlying (ResponseFields::kNextUserIndex )), nextAvailableUserIndex));
476
+ response.lastModifiedFabricIndex .SetNonNull (user.lastModifiedBy );
504
477
}
505
- SuccessOrExit (err = commandObj->FinishCommand ());
478
+ }
479
+ else
480
+ {
481
+ emberAfDoorLockClusterPrintln (" [GetUser] User not found [userIndex=%d]" , userIndex);
506
482
}
507
483
508
- exit :
509
- if (CHIP_NO_ERROR != err)
484
+ // appclusters, 5.2.4.36.1: We need to add next occupied user after userIndex if any.
485
+ uint16_t nextAvailableUserIndex = 0 ;
486
+ if (findOccupiedUserSlot (commandPath.mEndpointId , static_cast <uint16_t >(userIndex + 1 ), nextAvailableUserIndex))
510
487
{
511
- ChipLogError (Zcl, " [GetUser] Command processing failed [endpointId=%d,userIndex=%d,err=\" %s\" ]" , commandPath.mEndpointId ,
512
- userIndex, err.AsString ());
513
- commandObj->AddStatus (commandPath, Status::Failure);
488
+ response.nextUserIndex .SetNonNull (nextAvailableUserIndex);
514
489
}
490
+ commandObj->AddResponse (commandPath, response);
515
491
}
516
492
517
493
void DoorLockServer::clearUserCommandHandler (chip::app::CommandHandler * commandObj,
0 commit comments