Skip to content

Commit

Permalink
OpCreds Fabric Management functionality (#6233)
Browse files Browse the repository at this point in the history
* OpCreds Fabric Management functionality

    Adds functionality for reading the fabrics list attribute which gets updated after any updates to the admin pairing table.
    Adds functionary for removeFabric.
    Adds a setFabric command as a temporary command before AddOptCert is implemented. This allows the commissioner to set their vendorId for their fabric and returns to them their fabricId
    Remove the label field of FabricDescriptor struct because a bug in the generated code makes it that the whole list is corrupted if if is present (we need to fix whatever is wrong with OCTET_STRING in lists). This means that the UpdateFabricLabel implementation is not included in this patch.
    UI updates in the iOS demo app

* regen files

* Restyled by whitespace

* Restyled by clang-format

* Restyled by gn

* Restyled by whitespace

* Restyled by clang-format

* Fixing unused variable

Co-authored-by: Restyled.io <commits@restyled.io>
Co-authored-by: Justin Wood <woody@apple.com>
  • Loading branch information
3 people authored May 5, 2021
1 parent ae60b8d commit 3907f38
Show file tree
Hide file tree
Showing 96 changed files with 1,751 additions and 1,245 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7023,12 +7023,6 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
{
switch (aCommandId)
{
case ZCL_GET_FABRIC_ID_COMMAND_ID: {

// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfOperationalCredentialsClusterGetFabricIdCallback(apCommandObj);
break;
}
case ZCL_REMOVE_FABRIC_COMMAND_ID: {
// We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV
// When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error.
Expand Down Expand Up @@ -7128,6 +7122,73 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
}
break;
}
case ZCL_SET_FABRIC_COMMAND_ID: {
// We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV
// When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error.
// Any error value TLVUnpackError means we have received an illegal value.
CHIP_ERROR TLVError = CHIP_NO_ERROR;
CHIP_ERROR TLVUnpackError = CHIP_NO_ERROR;
uint16_t VendorId;
bool VendorIdExists = false;
uint32_t validArgumentCount = 0;

while ((TLVError = aDataTlv.Next()) == CHIP_NO_ERROR)
{
switch (TLV::TagNumFromTag(aDataTlv.GetTag()))
{
case 0:
if (VendorIdExists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
TLVUnpackError = aDataTlv.Get(VendorId);
if (CHIP_NO_ERROR == TLVUnpackError)
{
VendorIdExists = true;
validArgumentCount++;
}
break;
default:
// Unsupported tag, ignore it.
ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
break;
}
if (TLVUnpackError != CHIP_NO_ERROR)
{
ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
TLV::TagNumFromTag(aDataTlv.GetTag()), TLVUnpackError);
break;
}
}

if (CHIP_END_OF_TLV == TLVError)
{
// CHIP_END_OF_TLV means we have iterated all items in the structure, which is not a real error.
TLVError = CHIP_NO_ERROR;
}
else
{
ChipLogProgress(Zcl, "Failed to decode TLV data: %" PRId32, TLVError);
}

// TODO(#5590) We should encode a response of status code for invalid TLV.
if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 1 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfOperationalCredentialsClusterSetFabricCallback(apCommandObj, VendorId);
}
else
{
apCommandObj->AddStatusCode(nullptr, Protocols::SecureChannel::GeneralStatusCode::kBadRequest,
Protocols::SecureChannel::Id, Protocols::SecureChannel::kProtocolCodeGeneralFailure);
ChipLogProgress(
Zcl, "Failed to dispatch command, %d/%" PRIu32 " arguments parsed, TLVError=%" PRIu32 ", UnpackError=%" PRIu32,
1, validArgumentCount, TLVError, TLVUnpackError);
}
break;
}
case ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID: {
// We are using TLVUnpackError and TLVError here since both of them can be CHIP_END_OF_TLV
// When TLVError is CHIP_END_OF_TLV, it means we have iterated all of the items, which is not a real error.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ typedef struct _FabricDescriptor
{
chip::FabricId FabricId;
uint16_t VendorId;
chip::ByteSpan Label;
chip::NodeId NodeId;
} EmberAfFabricDescriptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
{
case 0x0001: // fabrics list
{
entryLength = 50;
entryLength = 18;
if (((index - 1) * entryLength) > (am->size - entryLength))
{
ChipLogError(Zcl, "Index %l is invalid.", index);
Expand All @@ -210,8 +210,6 @@ uint16_t emberAfCopyList(ClusterId clusterId, EmberAfAttributeMetadata * am, boo
&entryOffset, sizeof(entry->FabricId)); // FABRIC_ID
copyListMember(write ? dest : (uint8_t *) &entry->VendorId, write ? (uint8_t *) &entry->VendorId : src, write,
&entryOffset, sizeof(entry->VendorId)); // INT16U
copyListMember(write ? dest : (uint8_t *) &entry->Label, write ? (uint8_t *) &entry->Label : src, write, &entryOffset,
32); // OCTET_STRING
copyListMember(write ? dest : (uint8_t *) &entry->NodeId, write ? (uint8_t *) &entry->NodeId : src, write, &entryOffset,
sizeof(entry->NodeId)); // NODE_ID
break;
Expand Down Expand Up @@ -297,7 +295,7 @@ uint16_t emberAfAttributeValueListSize(ClusterId clusterId, AttributeId attribut
{
case 0x0001: // fabrics list
// Struct _FabricDescriptor
entryLength = 50;
entryLength = 18;
break;
}
break;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2310,10 +2310,6 @@ EmberAfStatus emberAfOperationalCredentialsClusterServerCommandParse(EmberAfClus
{
switch (cmd->commandId)
{
case ZCL_GET_FABRIC_ID_COMMAND_ID: {
wasHandled = emberAfOperationalCredentialsClusterGetFabricIdCallback(nullptr);
break;
}
case ZCL_REMOVE_FABRIC_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::FabricId FabricId;
Expand Down Expand Up @@ -2341,6 +2337,19 @@ EmberAfStatus emberAfOperationalCredentialsClusterServerCommandParse(EmberAfClus
wasHandled = emberAfOperationalCredentialsClusterRemoveFabricCallback(nullptr, FabricId, NodeId, VendorId);
break;
}
case ZCL_SET_FABRIC_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
uint16_t VendorId;

if (cmd->bufLen < payloadOffset + 2)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
VendorId = emberAfGetInt16u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled = emberAfOperationalCredentialsClusterSetFabricCallback(nullptr, VendorId);
break;
}
case ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
uint8_t * Label;
Expand Down
13 changes: 7 additions & 6 deletions examples/all-clusters-app/all-clusters-common/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -2718,12 +2718,6 @@ bool emberAfOnOffClusterOnCallback(chip::app::Command * commandObj);

bool emberAfOnOffClusterToggleCallback(chip::app::Command * commandObj);

/**
* @brief Operational Credentials Cluster GetFabricId Command callback
*/

bool emberAfOperationalCredentialsClusterGetFabricIdCallback(chip::app::Command * commandObj);

/**
* @brief Operational Credentials Cluster RemoveFabric Command callback
* @param fabricId
Expand All @@ -2734,6 +2728,13 @@ bool emberAfOperationalCredentialsClusterGetFabricIdCallback(chip::app::Command
bool emberAfOperationalCredentialsClusterRemoveFabricCallback(chip::app::Command * commandObj, chip::FabricId FabricId,
chip::NodeId NodeId, uint16_t VendorId);

/**
* @brief Operational Credentials Cluster SetFabric Command callback
* @param vendorId
*/

bool emberAfOperationalCredentialsClusterSetFabricCallback(chip::app::Command * commandObj, uint16_t VendorId);

/**
* @brief Operational Credentials Cluster UpdateFabricLabel Command callback
* @param label
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2197,25 +2197,25 @@
\
ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID, "u", timeoutMs);

/** @brief Command description for GetFabricId
/** @brief Command description for SetFabric
*
* Command: GetFabricId
* Command: SetFabric
* @param VendorId INT16U
*/
#define emberAfFillCommandOperational \
CredentialsClusterGetFabricId() emberAfFillExternalBuffer(mask, \
CredentialsClusterSetFabric(VendorId) emberAfFillExternalBuffer(mask, \
\
ZCL_GET_FABRIC_ID_COMMAND_ID, "", );
ZCL_SET_FABRIC_COMMAND_ID, "u", VendorId);

/** @brief Command description for GetFabricIdResponse
/** @brief Command description for SetFabricResponse
*
* Command: GetFabricIdResponse
* Command: SetFabricResponse
* @param FabricId FABRIC_ID
*/
#define emberAfFillCommandOperational \
CredentialsClusterGetFabricIdResponse(FabricId) \
emberAfFillExternalBuffer(mask, \
CredentialsClusterSetFabricResponse(FabricId) emberAfFillExternalBuffer(mask, \
\
ZCL_GET_FABRIC_ID_RESPONSE_COMMAND_ID, "u", FabricId);
ZCL_SET_FABRIC_RESPONSE_COMMAND_ID, "u", FabricId);

/** @brief Command description for UpdateFabricLabel
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@
#define ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID (0x10)

// Commands for cluster: Operational Credentials
#define ZCL_GET_FABRIC_ID_COMMAND_ID (0x00)
#define ZCL_GET_FABRIC_ID_RESPONSE_COMMAND_ID (0x01)
#define ZCL_SET_FABRIC_COMMAND_ID (0x00)
#define ZCL_SET_FABRIC_RESPONSE_COMMAND_ID (0x01)
#define ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID (0x09)
#define ZCL_REMOVE_FABRIC_COMMAND_ID (0x0A)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1302,8 +1302,8 @@
{ 0x0031, 0x10, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* GetLastNetworkCommissioningResult */ \
\
/* Endpoint: 0, Cluster: Operational Credentials (server) */ \
{ 0x003E, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* GetFabricId */ \
{ 0x003E, 0x01, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* GetFabricIdResponse */ \
{ 0x003E, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* SetFabric */ \
{ 0x003E, 0x01, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* SetFabricResponse */ \
{ 0x003E, 0x09, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* UpdateFabricLabel */ \
{ 0x003E, 0x0A, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* RemoveFabric */ \
\
Expand Down
2 changes: 1 addition & 1 deletion examples/all-clusters-app/esp32/main/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ idf_component_register(PRIV_INCLUDE_DIRS
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/groups-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/color-control-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/content-launch-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/operational-credentials-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/low-power-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/media-playback-server"
"${CMAKE_SOURCE_DIR}/third_party/connectedhomeip/src/app/clusters/ota-server"
Expand Down
2 changes: 1 addition & 1 deletion examples/all-clusters-app/esp32/main/component.mk
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ COMPONENT_SRCDIRS :=
../third_party/connectedhomeip/src/app/clusters/low-power-server \
../third_party/connectedhomeip/src/app/clusters/keypad-input-server \
../third_party/connectedhomeip/src/app/clusters/media-playback-server \
../third_party/connectedhomeip/src/app/clusters/operational-credentials \
../third_party/connectedhomeip/src/app/clusters/operational-credentials-server \
../third_party/connectedhomeip/src/app/clusters/media-input-server \
../third_party/connectedhomeip/src/app/clusters/network-commissioning \
../third_party/connectedhomeip/src/app/clusters/ota-server \
Expand Down
1 change: 0 additions & 1 deletion examples/bridge-app/bridge-common/gen/af-structs.h
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ typedef struct _FabricDescriptor
{
chip::FabricId FabricId;
uint16_t VendorId;
chip::ByteSpan Label;
chip::NodeId NodeId;
} EmberAfFabricDescriptor;

Expand Down
18 changes: 9 additions & 9 deletions examples/bridge-app/bridge-common/gen/client-command-macro.h
Original file line number Diff line number Diff line change
Expand Up @@ -2197,25 +2197,25 @@
\
ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID, "u", timeoutMs);

/** @brief Command description for GetFabricId
/** @brief Command description for SetFabric
*
* Command: GetFabricId
* Command: SetFabric
* @param VendorId INT16U
*/
#define emberAfFillCommandOperational \
CredentialsClusterGetFabricId() emberAfFillExternalBuffer(mask, \
CredentialsClusterSetFabric(VendorId) emberAfFillExternalBuffer(mask, \
\
ZCL_GET_FABRIC_ID_COMMAND_ID, "", );
ZCL_SET_FABRIC_COMMAND_ID, "u", VendorId);

/** @brief Command description for GetFabricIdResponse
/** @brief Command description for SetFabricResponse
*
* Command: GetFabricIdResponse
* Command: SetFabricResponse
* @param FabricId FABRIC_ID
*/
#define emberAfFillCommandOperational \
CredentialsClusterGetFabricIdResponse(FabricId) \
emberAfFillExternalBuffer(mask, \
CredentialsClusterSetFabricResponse(FabricId) emberAfFillExternalBuffer(mask, \
\
ZCL_GET_FABRIC_ID_RESPONSE_COMMAND_ID, "u", FabricId);
ZCL_SET_FABRIC_RESPONSE_COMMAND_ID, "u", FabricId);

/** @brief Command description for UpdateFabricLabel
*
Expand Down
4 changes: 2 additions & 2 deletions examples/bridge-app/bridge-common/gen/command-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -266,8 +266,8 @@
#define ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID (0x10)

// Commands for cluster: Operational Credentials
#define ZCL_GET_FABRIC_ID_COMMAND_ID (0x00)
#define ZCL_GET_FABRIC_ID_RESPONSE_COMMAND_ID (0x01)
#define ZCL_SET_FABRIC_COMMAND_ID (0x00)
#define ZCL_SET_FABRIC_RESPONSE_COMMAND_ID (0x01)
#define ZCL_UPDATE_FABRIC_LABEL_COMMAND_ID (0x09)
#define ZCL_REMOVE_FABRIC_COMMAND_ID (0x0A)

Expand Down
Loading

0 comments on commit 3907f38

Please sign in to comment.