Skip to content

Commit

Permalink
Send cluster specific errors from AdministratorCommissioning server (#…
Browse files Browse the repository at this point in the history
…11883)

* Send cluster specific errors from AdministratorCommissioning server

* address review comments

* initialize optional value
  • Loading branch information
pan-apple authored and pull[bot] committed Oct 21, 2023
1 parent 8a1212d commit 9119912
Show file tree
Hide file tree
Showing 6 changed files with 54 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,36 +46,41 @@ bool emberAfAdministratorCommissioningClusterOpenCommissioningWindowCallback(
auto & salt = commandData.salt;
auto & passcodeID = commandData.passcodeID;

EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
Optional<StatusCode> status = Optional<StatusCode>::Missing();
PASEVerifier verifier;
const uint8_t * verifierData = pakeVerifier.data();

ChipLogProgress(Zcl, "Received command to open commissioning window");

VerifyOrExit(!Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen(),
status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(sizeof(verifier) == pakeVerifier.size(), status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(iterations >= kPBKDFMinimumIterations, status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(iterations <= kPBKDFMaximumIterations, status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(salt.size() >= kPBKDFMinimumSaltLen, status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(salt.size() <= kPBKDFMaximumSaltLen, status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(commissioningTimeout <= kMaxCommissionioningTimeoutSeconds, status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(discriminator <= kMaxDiscriminatorValue, status = EMBER_ZCL_STATUS_FAILURE);
status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_BUSY));
VerifyOrExit(sizeof(verifier) == pakeVerifier.size(), status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
VerifyOrExit(iterations >= kPBKDFMinimumIterations, status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
VerifyOrExit(iterations <= kPBKDFMaximumIterations, status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
VerifyOrExit(salt.size() >= kPBKDFMinimumSaltLen, status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
VerifyOrExit(salt.size() <= kPBKDFMaximumSaltLen, status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
VerifyOrExit(commissioningTimeout <= kMaxCommissionioningTimeoutSeconds,
status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
VerifyOrExit(discriminator <= kMaxDiscriminatorValue, status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));

memcpy(verifier.mW0, &verifierData[0], kSpake2p_WS_Length);
memcpy(verifier.mL, &verifierData[kSpake2p_WS_Length], kSpake2p_WS_Length);

VerifyOrExit(Server::GetInstance().GetCommissioningWindowManager().OpenEnhancedCommissioningWindow(
commissioningTimeout, discriminator, verifier, iterations, salt, passcodeID) == CHIP_NO_ERROR,
status = EMBER_ZCL_STATUS_FAILURE);
status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
ChipLogProgress(Zcl, "Commissioning window is now open");

exit:
if (status != EMBER_ZCL_STATUS_SUCCESS)
if (status.HasValue())
{
ChipLogError(Zcl, "Failed to open commissioning window. Status %d", status);
ChipLogError(Zcl, "Failed to open commissioning window. Status %d", status.Value());
commandObj->AddClusterSpecificFailure(commandPath, status.Value());
}
else
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
}
emberAfSendImmediateDefaultResponse(status);
return true;
}

Expand All @@ -85,22 +90,27 @@ bool emberAfAdministratorCommissioningClusterOpenBasicCommissioningWindowCallbac
{
auto & commissioningTimeout = commandData.commissioningTimeout;

EmberAfStatus status = EMBER_ZCL_STATUS_SUCCESS;
Optional<StatusCode> status = Optional<StatusCode>::Missing();
ChipLogProgress(Zcl, "Received command to open basic commissioning window");
VerifyOrExit(!Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen(),
status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(commissioningTimeout <= kMaxCommissionioningTimeoutSeconds, status = EMBER_ZCL_STATUS_FAILURE);
status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_BUSY));
VerifyOrExit(commissioningTimeout <= kMaxCommissionioningTimeoutSeconds,
status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
VerifyOrExit(Server::GetInstance().GetCommissioningWindowManager().OpenBasicCommissioningWindow(commissioningTimeout) ==
CHIP_NO_ERROR,
status = EMBER_ZCL_STATUS_FAILURE);
status.Emplace(StatusCode::EMBER_ZCL_STATUS_CODE_PAKE_PARAMETER_ERROR));
ChipLogProgress(Zcl, "Commissioning window is now open");

exit:
if (status != EMBER_ZCL_STATUS_SUCCESS)
if (status.HasValue())
{
ChipLogError(Zcl, "Failed to open commissioning window. Status %d", status);
ChipLogError(Zcl, "Failed to open commissioning window. Status %d", status.Value());
commandObj->AddClusterSpecificFailure(commandPath, status.Value());
}
else
{
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
}
emberAfSendImmediateDefaultResponse(status);
return true;
}

Expand All @@ -109,9 +119,18 @@ bool emberAfAdministratorCommissioningClusterRevokeCommissioningCallback(
const Commands::RevokeCommissioning::DecodableType & commandData)
{
ChipLogProgress(Zcl, "Received command to close commissioning window");
Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow();
ChipLogProgress(Zcl, "Commissioning window is now closed");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);

if (!Server::GetInstance().GetCommissioningWindowManager().IsCommissioningWindowOpen())
{
ChipLogError(Zcl, "Commissioning window is currently not open");
commandObj->AddClusterSpecificFailure(commandPath, StatusCode::EMBER_ZCL_STATUS_CODE_WINDOW_NOT_OPEN);
}
else
{
Server::GetInstance().GetCommissioningWindowManager().CloseCommissioningWindow();
ChipLogProgress(Zcl, "Commissioning window is now closed");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_SUCCESS);
}
return true;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -679,11 +679,11 @@ bool emberAfOperationalCredentialsClusterAddTrustedRootCertificateCallback(

emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: commissioner has added a trusted root Cert");

VerifyOrExit(gFabricBeingCommissioned.SetRootCert(RootCertificate) == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_FAILURE);
VerifyOrExit(gFabricBeingCommissioned.SetRootCert(RootCertificate) == CHIP_NO_ERROR, status = EMBER_ZCL_STATUS_INVALID_FIELD);

exit:
emberAfSendImmediateDefaultResponse(status);
if (status == EMBER_ZCL_STATUS_FAILURE)
if (status != EMBER_ZCL_STATUS_SUCCESS)
{
gFabricBeingCommissioned.Reset();
emberAfPrintln(EMBER_AF_PRINT_DEBUG, "OpCreds: Failed AddTrustedRootCert request.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ limitations under the License.

<enum name="StatusCode" type="ENUM8">
<cluster code="0x003c"/>
<item name="Success" value="0x00"/>
<item name="Busy" value="0x01"/>
<item name="GeneralError" value="0x02"/>
<item name="PAKEParameterError" value="0x02"/>
<item name="WindowNotOpen" value="0x03"/>
</enum>

<cluster>
Expand Down
4 changes: 2 additions & 2 deletions src/controller/python/chip/clusters/Objects.py

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.

6 changes: 3 additions & 3 deletions zzz_generated/app-common/app-common/zap-generated/enums.h

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

0 comments on commit 9119912

Please sign in to comment.