Skip to content

Commit

Permalink
Align values of EmberAfStatus and InteractionModel::Status. (#14351)
Browse files Browse the repository at this point in the history
This is step 1 of #12868

Notable changes to align both lists with the spec:
* Fix the value of Status::ConstraintError.
* Add DataVersionMismatch/DATA_VERSION_MISMATCH.
* Add UnsupportedEvent/UNSUPPORTED_EVENT.
* Remove deprecated EmberAfStatus names with few+simple consumers
  (EMBER_ZCL_STATUS_UNSUP_COMMAND, EMBER_ZCL_STATUS_ACTION_DENIED,
  EMBER_ZCL_STATUS_WRITE_ONLY) and replace them with the corresponding
  spec-defined preferred names or values.
  • Loading branch information
bzbarsky-apple authored and pull[bot] committed Aug 29, 2023
1 parent fd98a21 commit 0d5812d
Show file tree
Hide file tree
Showing 8 changed files with 135 additions and 263 deletions.
2 changes: 1 addition & 1 deletion src/app/clusters/ota-provider/ota-provider.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ bool SendStatusIfDelegateNull(EndpointId endpoint)
if (GetDelegate(endpoint) == nullptr)
{
ChipLogError(Zcl, "No OTAProviderDelegate set for ep:%" PRIu16, endpoint);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_UNSUP_COMMAND);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_UNSUPPORTED_COMMAND);
return true;
}
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -551,7 +551,7 @@ bool emberAfWindowCoveringClusterGoToLiftValueCallback(app::CommandHandler * com
else
{
emberAfWindowCoveringClusterPrint("Err Device is not PA LF");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_ACTION_DENIED);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
return true;
}
Expand Down Expand Up @@ -585,7 +585,7 @@ bool emberAfWindowCoveringClusterGoToLiftPercentageCallback(app::CommandHandler
else
{
emberAfWindowCoveringClusterPrint("Err Device is not PA LF");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_ACTION_DENIED);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
return true;
}
Expand All @@ -610,7 +610,7 @@ bool emberAfWindowCoveringClusterGoToTiltValueCallback(app::CommandHandler * com
else
{
emberAfWindowCoveringClusterPrint("Err Device is not PA TL");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_ACTION_DENIED);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
return true;
}
Expand Down Expand Up @@ -644,7 +644,7 @@ bool emberAfWindowCoveringClusterGoToTiltPercentageCallback(app::CommandHandler
else
{
emberAfWindowCoveringClusterPrint("Err Device is not PA TL");
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_ACTION_DENIED);
emberAfSendImmediateDefaultResponse(EMBER_ZCL_STATUS_FAILURE);
}
return true;
}
Expand Down
85 changes: 45 additions & 40 deletions src/app/util/af-enums.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,44 +24,49 @@

enum EmberAfStatus : uint8_t
{
EMBER_ZCL_STATUS_SUCCESS = 0x00,
EMBER_ZCL_STATUS_FAILURE = 0x01,
EMBER_ZCL_STATUS_UNSUPPORTED_ACCESS = 0x7E,
EMBER_ZCL_STATUS_NOT_AUTHORIZED = 0x7E, // Deprecated; same as UNSUPPORTED_ACCESS
EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT = 0x7F,
EMBER_ZCL_STATUS_MALFORMED_COMMAND = 0x80,
EMBER_ZCL_STATUS_UNSUPPORTED_COMMAND = 0x81,
EMBER_ZCL_STATUS_UNSUP_COMMAND = 0x81, // Deprecated; same as UNSUPPORTED_COMMAND
EMBER_ZCL_STATUS_UNSUP_GENERAL_COMMAND = 0x82,
EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND = 0x83,
EMBER_ZCL_STATUS_UNSUP_MANUF_GENERAL_COMMAND = 0x84,
EMBER_ZCL_STATUS_INVALID_COMMAND = 0x85,
EMBER_ZCL_STATUS_INVALID_FIELD = 0x85, // Deprecated; same as INVALID_COMMAND
EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE = 0x86,
EMBER_ZCL_STATUS_CONSTRAINT_ERROR = 0x87,
EMBER_ZCL_STATUS_INVALID_VALUE = 0x87, // Deprecated; same as CONSTRAINT_ERROR
EMBER_ZCL_STATUS_UNSUPPORTED_WRITE = 0x88,
EMBER_ZCL_STATUS_READ_ONLY = 0x88, // Deprecated; same as UNSUPPORTED_WRITE
EMBER_ZCL_STATUS_INSUFFICIENT_SPACE = 0x89,
EMBER_ZCL_STATUS_DUPLICATE_EXISTS = 0x8A,
EMBER_ZCL_STATUS_NOT_FOUND = 0x8B,
EMBER_ZCL_STATUS_UNREPORTABLE_ATTRIBUTE = 0x8C,
EMBER_ZCL_STATUS_INVALID_DATA_TYPE = 0x8D,
EMBER_ZCL_STATUS_INVALID_SELECTOR = 0x8E,
EMBER_ZCL_STATUS_WRITE_ONLY = 0x8F,
EMBER_ZCL_STATUS_INCONSISTENT_STARTUP_STATE = 0x90,
EMBER_ZCL_STATUS_DEFINED_OUT_OF_BAND = 0x91,
EMBER_ZCL_STATUS_ACTION_DENIED = 0x93,
EMBER_ZCL_STATUS_TIMEOUT = 0x94,
EMBER_ZCL_STATUS_ABORT = 0x95,
EMBER_ZCL_STATUS_INVALID_IMAGE = 0x96,
EMBER_ZCL_STATUS_WAIT_FOR_DATA = 0x97,
EMBER_ZCL_STATUS_NO_IMAGE_AVAILABLE = 0x98,
EMBER_ZCL_STATUS_REQUIRE_MORE_IMAGE = 0x99,
EMBER_ZCL_STATUS_NOTIFICATION_PENDING = 0x9A,
EMBER_ZCL_STATUS_HARDWARE_FAILURE = 0xC0,
EMBER_ZCL_STATUS_SOFTWARE_FAILURE = 0xC1,
EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER = 0xC3,
EMBER_ZCL_STATUS_LIMIT_REACHED = 0xC4,
EMBER_ZCL_STATUS_NEEDS_TIMED_INTERACTION = 0xC6,
EMBER_ZCL_STATUS_SUCCESS = 0x00,
EMBER_ZCL_STATUS_FAILURE = 0x01,
EMBER_ZCL_STATUS_INVALID_SUBSCRIPTION = 0x7D,
EMBER_ZCL_STATUS_UNSUPPORTED_ACCESS = 0x7E,
EMBER_ZCL_STATUS_NOT_AUTHORIZED = 0x7E, // Deprecated; same as UNSUPPORTED_ACCESS
EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT = 0x7F,
EMBER_ZCL_STATUS_MALFORMED_COMMAND = 0x80,
EMBER_ZCL_STATUS_UNSUPPORTED_COMMAND = 0x81,
EMBER_ZCL_STATUS_DEPRECATED82 = 0x82,
EMBER_ZCL_STATUS_DEPRECATED83 = 0x83,
EMBER_ZCL_STATUS_DEPRECATED84 = 0x84,
EMBER_ZCL_STATUS_INVALID_COMMAND = 0x85,
EMBER_ZCL_STATUS_INVALID_FIELD = 0x85, // Deprecated; same as INVALID_COMMAND
EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE = 0x86,
EMBER_ZCL_STATUS_CONSTRAINT_ERROR = 0x87,
EMBER_ZCL_STATUS_INVALID_VALUE = 0x87, // Deprecated; same as CONSTRAINT_ERROR
EMBER_ZCL_STATUS_UNSUPPORTED_WRITE = 0x88,
EMBER_ZCL_STATUS_READ_ONLY = 0x88, // Deprecated; same as UNSUPPORTED_WRITE
EMBER_ZCL_STATUS_RESOURCE_EXHAUSTED = 0x89,
EMBER_ZCL_STATUS_INSUFFICIENT_SPACE = 0x89, // Deprecated; same as RESOURCE_EXHAUSTED
EMBER_ZCL_STATUS_DUPLICATE_EXISTS = 0x8A,
EMBER_ZCL_STATUS_NOT_FOUND = 0x8B,
EMBER_ZCL_STATUS_UNREPORTABLE_ATTRIBUTE = 0x8C,
EMBER_ZCL_STATUS_INVALID_DATA_TYPE = 0x8D,
EMBER_ZCL_STATUS_DEPRECATED8E = 0x8E,
EMBER_ZCL_STATUS_UNSUPPORTED_READ = 0x8F,
EMBER_ZCL_STATUS_DEPRECATED90 = 0x90,
EMBER_ZCL_STATUS_DEPRECATED91 = 0x91,
EMBER_ZCL_STATUS_DATA_VERSION_MISMATCH = 0x92,
EMBER_ZCL_STATUS_DEPRECATED93 = 0x93,
EMBER_ZCL_STATUS_TIMEOUT = 0x94,
EMBER_ZCL_STATUS_RESERVED95 = 0x95,
EMBER_ZCL_STATUS_RESERVED96 = 0x96,
EMBER_ZCL_STATUS_RESERVED97 = 0x97,
EMBER_ZCL_STATUS_RESERVED98 = 0x98,
EMBER_ZCL_STATUS_RESERVED99 = 0x99,
EMBER_ZCL_STATUS_RESERVED9A = 0x9A,
EMBER_ZCL_STATUS_BUSY = 0x9C,
EMBER_ZCL_STATUS_DEPRECATEDC0 = 0xC0,
EMBER_ZCL_STATUS_DEPRECATEDC1 = 0xC1,
EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER = 0xC3,
EMBER_ZCL_STATUS_DEPRECATEDC4 = 0xC4,
EMBER_ZCL_STATUS_NO_UPSTREAM_SUBSCRIPTION = 0xC5,
EMBER_ZCL_STATUS_NEEDS_TIMED_INTERACTION = 0xC6,
EMBER_ZCL_STATUS_UNSUPPORTED_EVENT = 0xC7,
};
2 changes: 1 addition & 1 deletion src/app/util/ember-compatibility-functions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -647,7 +647,7 @@ CHIP_ERROR ReadSingleClusterData(const SubjectDescriptor & aSubjectDescriptor, b
}
default:
ChipLogError(DataManagement, "Attribute type 0x%x not handled", static_cast<int>(attributeType));
emberStatus = EMBER_ZCL_STATUS_WRITE_ONLY;
emberStatus = EMBER_ZCL_STATUS_UNSUPPORTED_READ;
}
}

Expand Down
169 changes: 5 additions & 164 deletions src/app/util/error-mapping.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,176 +20,17 @@
namespace chip {
namespace app {

EmberAfStatus ToEmberAfStatus(Protocols::InteractionModel::Status code)
{
using imcode = Protocols::InteractionModel::Status;
switch (code)
{
case imcode::Success: // 0x00
return EMBER_ZCL_STATUS_SUCCESS;
case imcode::Failure: // 0x01
return EMBER_ZCL_STATUS_FAILURE;
case imcode::InvalidSubscription: // 0x7d
return EMBER_ZCL_STATUS_FAILURE;
case imcode::UnsupportedAccess: // 0x7e
return EMBER_ZCL_STATUS_NOT_AUTHORIZED;
case imcode::UnsupportedEndpoint: // 0x7f
return EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT;
case imcode::InvalidAction: // 0x80
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
case imcode::UnsupportedCommand: // 0x81
return EMBER_ZCL_STATUS_UNSUP_COMMAND;
case imcode::Deprecated82: // 0x82
return EMBER_ZCL_STATUS_UNSUP_COMMAND;
case imcode::Deprecated83: // 0x83
return EMBER_ZCL_STATUS_UNSUP_COMMAND;
case imcode::Deprecated84: // 0x84
return EMBER_ZCL_STATUS_UNSUP_COMMAND;
case imcode::InvalidCommand: // 0x85
return EMBER_ZCL_STATUS_INVALID_FIELD;
case imcode::UnsupportedAttribute: // 0x86
return EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE;
case imcode::InvalidValue: // 0x87
return EMBER_ZCL_STATUS_INVALID_VALUE;
case imcode::UnsupportedWrite: // 0x88
return EMBER_ZCL_STATUS_READ_ONLY;
case imcode::ResourceExhausted: // 0x89
return EMBER_ZCL_STATUS_INSUFFICIENT_SPACE;
case imcode::Deprecated8a:
return EMBER_ZCL_STATUS_SUCCESS;
case imcode::NotFound: // 0x8b
return EMBER_ZCL_STATUS_NOT_FOUND;
case imcode::UnreportableAttribute: // 0x8c
return EMBER_ZCL_STATUS_UNREPORTABLE_ATTRIBUTE;
case imcode::InvalidDataType: // 0x8d
return EMBER_ZCL_STATUS_INVALID_DATA_TYPE;
case imcode::Deprecated8e: // 0x8e
return EMBER_ZCL_STATUS_UNREPORTABLE_ATTRIBUTE;
case imcode::UnsupportedRead: // 0x8f
return EMBER_ZCL_STATUS_WRITE_ONLY;
case imcode::Deprecated90: // 0x90
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Deprecated91: // 0x91
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Reserved92: // 0x92
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Deprecated93: // 0x93
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Timeout: // 0x94
return EMBER_ZCL_STATUS_TIMEOUT;
case imcode::Reserved95: // 0x95
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Reserved96: // 0x96
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Reserved97: // 0x97
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Reserved98: // 0x98
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Reserved99: // 0x99
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Reserved9a: // 0x9a
return EMBER_ZCL_STATUS_FAILURE;
case imcode::ConstraintError: // 0x9b
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Busy: // 0x9c
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Deprecatedc0: // 0xc0
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Deprecatedc1: // 0xc1
return EMBER_ZCL_STATUS_FAILURE;
case imcode::Deprecatedc2: // 0xc2
return EMBER_ZCL_STATUS_FAILURE;
case imcode::UnsupportedCluster: // 0xc3
return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
case imcode::Deprecatedc4: // 0xc4
return EMBER_ZCL_STATUS_SUCCESS;
case imcode::NoUpstreamSubscription: // 0xc5
return EMBER_ZCL_STATUS_FAILURE;
case imcode::NeedsTimedInteraction: // 0xc6
return EMBER_ZCL_STATUS_NEEDS_TIMED_INTERACTION;
// Default case is omitted intentionally so we can guarantee that we exhaust all of the error codes.
}
return EMBER_ZCL_STATUS_FAILURE;
}

Protocols::InteractionModel::Status ToInteractionModelStatus(EmberAfStatus code)
{
using imcode = Protocols::InteractionModel::Status;
switch (code)
if (code == EMBER_ZCL_STATUS_DUPLICATE_EXISTS /* 0x8A */)
{
case EMBER_ZCL_STATUS_SUCCESS: // 0x00
return imcode::Success;
case EMBER_ZCL_STATUS_FAILURE: // 0x01
return imcode::Failure;
case EMBER_ZCL_STATUS_NOT_AUTHORIZED: // 0x7E
return imcode::UnsupportedAccess;
case EMBER_ZCL_STATUS_UNSUPPORTED_ENDPOINT: // 0x7F
return imcode::UnsupportedEndpoint;
case EMBER_ZCL_STATUS_MALFORMED_COMMAND: // 0x80
return imcode::InvalidAction;
case EMBER_ZCL_STATUS_UNSUP_COMMAND: // 0x81
return imcode::UnsupportedCommand;
case EMBER_ZCL_STATUS_UNSUP_GENERAL_COMMAND: // 0x82
return imcode::UnsupportedCommand;
case EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND: // 0x83
return imcode::UnsupportedCommand;
case EMBER_ZCL_STATUS_UNSUP_MANUF_GENERAL_COMMAND: // 0x84
return imcode::UnsupportedCommand;
case EMBER_ZCL_STATUS_INVALID_FIELD: // 0x85
return imcode::InvalidCommand;
case EMBER_ZCL_STATUS_UNSUPPORTED_ATTRIBUTE: // 0x86
return imcode::UnsupportedAttribute;
case EMBER_ZCL_STATUS_INVALID_VALUE: // 0x87
return imcode::InvalidValue;
case EMBER_ZCL_STATUS_READ_ONLY: // 0x88
return imcode::UnsupportedWrite;
case EMBER_ZCL_STATUS_INSUFFICIENT_SPACE: // 0x89
return imcode::ResourceExhausted;
case EMBER_ZCL_STATUS_DUPLICATE_EXISTS: // 0x8A
// For now, this is still used, and should be mapped to success. Once
// we update bindings to no longer use it, this case can go away.
return imcode::Success;
case EMBER_ZCL_STATUS_NOT_FOUND: // 0x8B
return imcode::NotFound;
case EMBER_ZCL_STATUS_UNREPORTABLE_ATTRIBUTE: // 0x8C
return imcode::UnreportableAttribute;
case EMBER_ZCL_STATUS_INVALID_DATA_TYPE: // 0x8D
return imcode::InvalidDataType;
case EMBER_ZCL_STATUS_INVALID_SELECTOR: // 0x8E
return imcode::Failure;
case EMBER_ZCL_STATUS_WRITE_ONLY: // 0x8F
return imcode::UnsupportedRead;
case EMBER_ZCL_STATUS_INCONSISTENT_STARTUP_STATE: // 0x90
return imcode::Failure;
case EMBER_ZCL_STATUS_DEFINED_OUT_OF_BAND: // 0x91
return imcode::Failure;
case EMBER_ZCL_STATUS_ACTION_DENIED: // 0x93
return imcode::Failure;
case EMBER_ZCL_STATUS_TIMEOUT: // 0x94
return imcode::Timeout;
case EMBER_ZCL_STATUS_ABORT: // 0x95
return imcode::Failure;
case EMBER_ZCL_STATUS_INVALID_IMAGE: // 0x96
return imcode::Failure;
case EMBER_ZCL_STATUS_WAIT_FOR_DATA: // 0x97
return imcode::Failure;
case EMBER_ZCL_STATUS_NO_IMAGE_AVAILABLE: // 0x98
return imcode::Failure;
case EMBER_ZCL_STATUS_REQUIRE_MORE_IMAGE: // 0x99
return imcode::Failure;
case EMBER_ZCL_STATUS_NOTIFICATION_PENDING: // 0x9A
return imcode::Failure;
case EMBER_ZCL_STATUS_HARDWARE_FAILURE: // 0xC0
return imcode::Failure;
case EMBER_ZCL_STATUS_SOFTWARE_FAILURE: // 0xC1
return imcode::Failure;
case EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER: // 0xC3
return imcode::UnsupportedCluster;
case EMBER_ZCL_STATUS_LIMIT_REACHED: // 0xC4
return imcode::Success;
case EMBER_ZCL_STATUS_NEEDS_TIMED_INTERACTION: // 0xC6
return imcode::NeedsTimedInteraction;
default:
return imcode::Failure;
}

return static_cast<imcode>(code);
}

} // namespace app
Expand Down
6 changes: 5 additions & 1 deletion src/app/util/error-mapping.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@
namespace chip {
namespace app {

EmberAfStatus ToEmberAfStatus(Protocols::InteractionModel::Status code);
inline EmberAfStatus ToEmberAfStatus(Protocols::InteractionModel::Status code)
{
return static_cast<EmberAfStatus>(code);
}

Protocols::InteractionModel::Status ToInteractionModelStatus(EmberAfStatus code);

} // namespace app
Expand Down
Loading

0 comments on commit 0d5812d

Please sign in to comment.