Skip to content

Commit

Permalink
Fix error code for the Set User command (#21281)
Browse files Browse the repository at this point in the history
* [#19991] Fix error code for the Set User command

* Update auto-generated files
  • Loading branch information
Morozov-5F authored and pull[bot] committed Nov 2, 2023
1 parent 7c1a6e6 commit 3319617
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 23 deletions.
41 changes: 30 additions & 11 deletions src/app/clusters/door-lock-server/door-lock-server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <app/server/Server.h>
#include <app/util/af-event.h>
#include <app/util/af.h>
#include <app/util/error-mapping.h>
#include <cinttypes>

#include <app/CommandHandler.h>
Expand Down Expand Up @@ -246,7 +247,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
if (!SupportsUSR(commandPath.mEndpointId))
{
emberAfDoorLockClusterPrintln("[SetUser] User management is not supported [endpointId=%d]", commandPath.mEndpointId);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_UNSUPPORTED_COMMAND);
sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_UNSUPPORTED_COMMAND);
return;
}

Expand All @@ -255,7 +256,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
{
ChipLogError(Zcl, "[SetUser] Unable to get the fabric IDX [endpointId=%d,userIndex=%d]", commandPath.mEndpointId,
userIndex);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_FAILURE);
return;
}

Expand All @@ -264,7 +265,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
{
ChipLogError(Zcl, "[SetUser] Unable to get the source node index [endpointId=%d,userIndex=%d]", commandPath.mEndpointId,
userIndex);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_FAILURE);
return;
}

Expand All @@ -279,7 +280,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
{
emberAfDoorLockClusterPrintln("[SetUser] User index out of bounds [endpointId=%d,userIndex=%d]", commandPath.mEndpointId,
userIndex);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_INVALID_COMMAND);
return;
}

Expand All @@ -290,7 +291,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
"[SetUser] Unable to set user: userName too long [endpointId=%d,userIndex=%d,userNameSize=%u]", commandPath.mEndpointId,
userIndex, static_cast<unsigned int>(userName.Value().size()));

emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_INVALID_COMMAND);
return;
}

Expand All @@ -301,7 +302,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
"[SetUser] Unable to set the user: user status is out of range [endpointId=%d,userIndex=%d,userStatus=%u]",
commandPath.mEndpointId, userIndex, to_underlying(userStatus.Value()));

emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_INVALID_COMMAND);
return;
}

Expand All @@ -311,7 +312,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
"[SetUser] Unable to set the user: user type is out of range [endpointId=%d,userIndex=%d,userType=%u]",
commandPath.mEndpointId, userIndex, to_underlying(userType.Value()));

emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_INVALID_COMMAND);
sendClusterResponse(commandObj, commandPath, EMBER_ZCL_STATUS_INVALID_COMMAND);
return;
}

Expand All @@ -336,7 +337,7 @@ void DoorLockServer::setUserCommandHandler(chip::app::CommandHandler * commandOb
break;
}

emberAfSendImmediateDefaultResponse(status);
sendClusterResponse(commandObj, commandPath, status);
}

void DoorLockServer::getUserCommandHandler(chip::app::CommandHandler * commandObj,
Expand Down Expand Up @@ -1669,8 +1670,7 @@ EmberAfStatus DoorLockServer::createUser(chip::EndpointId endpointId, chip::Fabr
{
emberAfDoorLockClusterPrintln("[createUser] Unable to overwrite existing user [endpointId=%d,userIndex=%d]", endpointId,
userIndex);
// TODO: Add cluster-specific failure of DlStatus::kOccupied
return EMBER_ZCL_STATUS_FAILURE;
return static_cast<EmberAfStatus>(DlStatus::kOccupied);
}

const auto & newUserName = !userName.IsNull() ? userName.Value() : chip::CharSpan::fromCharString("");
Expand Down Expand Up @@ -2380,7 +2380,7 @@ DlStatus DoorLockServer::clearSchedules(chip::EndpointId endpointId, uint16_t us
return status;
}

// TODO: Clear holiday schedules when they're implemented
// No need to clear the holiday schedules here as they are not specific for user.
return DlStatus::kSuccess;
}

Expand Down Expand Up @@ -3117,6 +3117,25 @@ bool DoorLockServer::RemoteOperationEnabled(chip::EndpointId endpointId) const
mode != DlOperatingMode::kPrivacy && mode != DlOperatingMode::kNoRemoteLockUnlock;
}

CHIP_ERROR DoorLockServer::sendClusterResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, EmberAfStatus status)
{
VerifyOrDie(nullptr != commandObj);

auto err = CHIP_NO_ERROR;
auto statusAsInteger = to_underlying(status);
if (statusAsInteger == to_underlying(DlStatus::kOccupied) || statusAsInteger == to_underlying(DlStatus::kDuplicate))
{
err = commandObj->AddClusterSpecificFailure(commandPath, static_cast<chip::ClusterStatus>(status));
}
else
{
err = commandObj->AddStatus(commandPath, ToInteractionModelStatus(status));
}

return err;
}

bool DoorLockServer::HandleRemoteLockOperation(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, DlLockOperationType opType,
RemoteLockOpHandler opHandler, const Optional<ByteSpan> & pinCode)
Expand Down
3 changes: 3 additions & 0 deletions src/app/clusters/door-lock-server/door-lock-server.h
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,9 @@ class DoorLockServer

bool RemoteOperationEnabled(chip::EndpointId endpointId) const;

static CHIP_ERROR sendClusterResponse(chip::app::CommandHandler * commandObj,
const chip::app::ConcreteCommandPath & commandPath, EmberAfStatus status);

/**
* @brief Common handler for LockDoor, UnlockDoor, UnlockWithTimeout commands
*
Expand Down
3 changes: 1 addition & 2 deletions src/app/tests/suites/DL_UsersAndCredentials.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,7 @@ tests:
- name: "credentialRule"
value: null
response:
# So far there's no way to verify cluster-specific error codes so we're just checking generic failure here
error: 0x01
error: FAILURE

- label: "Modify userName for existing user"
command: "SetUser"
Expand Down
2 changes: 1 addition & 1 deletion zzz_generated/chip-tool/zap-generated/test/Commands.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 3319617

Please sign in to comment.