Skip to content

Commit

Permalink
Remove SetFabric command from General Commissioning Cluster to align …
Browse files Browse the repository at this point in the history
…with 0.7 spec (#6173)

* Update general commisioning cluster to align with 0.7 spec

* Update the build targets for general commisioning cluster

* Re-generate code with codegen
  • Loading branch information
yufengwangca authored Apr 22, 2021
1 parent ba9c503 commit 20ac5e1
Show file tree
Hide file tree
Showing 120 changed files with 4,457 additions and 2,582 deletions.
40 changes: 12 additions & 28 deletions examples/all-clusters-app/all-clusters-common/all-clusters-app.zap
Original file line number Diff line number Diff line change
Expand Up @@ -1107,15 +1107,15 @@
"enabled": 0,
"commands": [
{
"name": "SetFabric",
"name": "ArmFailSafe",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 1
},
{
"name": "ArmFailSafe",
"name": "SetRegulatoryConfig",
"code": 2,
"mfgCode": null,
"source": "client",
Expand All @@ -1124,11 +1124,11 @@
},
{
"name": "CommissioningComplete",
"code": 6,
"code": 4,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 1
"outgoing": 0
}
],
"attributes": [
Expand Down Expand Up @@ -1158,15 +1158,15 @@
"enabled": 1,
"commands": [
{
"name": "SetFabricResponse",
"name": "ArmFailSafeResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"incoming": 1,
"outgoing": 1
},
{
"name": "ArmFailSafeResponse",
"name": "SetRegulatoryConfigResponse",
"code": 3,
"mfgCode": null,
"source": "server",
Expand All @@ -1175,10 +1175,10 @@
},
{
"name": "CommissioningCompleteResponse",
"code": 7,
"code": 5,
"mfgCode": null,
"source": "server",
"incoming": 1,
"incoming": 0,
"outgoing": 1
}
],
Expand Down Expand Up @@ -4919,28 +4919,20 @@
"enabled": 0,
"commands": [
{
"name": "SetFabric",
"name": "ArmFailSafe",
"code": 0,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 1
},
{
"name": "ArmFailSafe",
"name": "SetRegulatoryConfig",
"code": 2,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 1
},
{
"name": "CommissioningComplete",
"code": 6,
"mfgCode": null,
"source": "client",
"incoming": 1,
"outgoing": 1
}
],
"attributes": [
Expand Down Expand Up @@ -4970,28 +4962,20 @@
"enabled": 0,
"commands": [
{
"name": "SetFabricResponse",
"name": "ArmFailSafeResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"incoming": 1,
"outgoing": 1
},
{
"name": "ArmFailSafeResponse",
"name": "SetRegulatoryConfigResponse",
"code": 3,
"mfgCode": null,
"source": "server",
"incoming": 1,
"outgoing": 1
},
{
"name": "CommissioningCompleteResponse",
"code": 7,
"mfgCode": null,
"source": "server",
"incoming": 1,
"outgoing": 1
}
],
"attributes": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4129,16 +4129,16 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
emberAfGeneralCommissioningClusterCommissioningCompleteCallback(apCommandObj);
break;
}
case ZCL_SET_FABRIC_COMMAND_ID: {
case ZCL_SET_REGULATORY_CONFIG_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;
chip::ByteSpan fabricId;
bool fabricIdExists = false;
chip::ByteSpan fabricSecret;
bool fabricSecretExists = false;
uint8_t location;
bool locationExists = false;
const uint8_t * countryCode;
bool countryCodeExists = false;
uint64_t breadcrumb;
bool breadcrumbExists = false;
uint32_t timeoutMs;
Expand All @@ -4150,38 +4150,31 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
switch (TLV::TagNumFromTag(aDataTlv.GetTag()))
{
case 0:
if (fabricIdExists)
if (locationExists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
{
const uint8_t * data = nullptr;
TLVUnpackError = aDataTlv.GetDataPtr(data);
fabricId = chip::ByteSpan(data, aDataTlv.GetLength());
}
TLVUnpackError = aDataTlv.Get(location);
if (CHIP_NO_ERROR == TLVUnpackError)
{
fabricIdExists = true;
locationExists = true;
validArgumentCount++;
}
break;
case 1:
if (fabricSecretExists)
if (countryCodeExists)
{
ChipLogProgress(Zcl, "Duplicate TLV tag %" PRIx32, TLV::TagNumFromTag(aDataTlv.GetTag()));
TLVUnpackError = CHIP_ERROR_IM_MALFORMED_COMMAND_DATA_ELEMENT;
break;
}
{
const uint8_t * data = nullptr;
TLVUnpackError = aDataTlv.GetDataPtr(data);
fabricSecret = chip::ByteSpan(data, aDataTlv.GetLength());
}
// TODO(#5542): The cluster handlers should accept a ByteSpan for all string types.
TLVUnpackError = aDataTlv.GetDataPtr(countryCode);
if (CHIP_NO_ERROR == TLVUnpackError)
{
fabricSecretExists = true;
countryCodeExists = true;
validArgumentCount++;
}
break;
Expand Down Expand Up @@ -4240,7 +4233,8 @@ void DispatchServerCommand(app::Command * apCommandObj, CommandId aCommandId, En
if (CHIP_NO_ERROR == TLVError && CHIP_NO_ERROR == TLVUnpackError && 4 == validArgumentCount)
{
// TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
emberAfGeneralCommissioningClusterSetFabricCallback(apCommandObj, fabricId, fabricSecret, breadcrumb, timeoutMs);
emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(
apCommandObj, location, const_cast<uint8_t *>(countryCode), breadcrumb, timeoutMs);
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ typedef struct _AudioOutputInfo
uint8_t * Name;
} EmberAfAudioOutputInfo;

// Struct for BasicCommissioningInfo
typedef struct _BasicCommissioningInfo
// Struct for BasicCommissioningInfoType
typedef struct _BasicCommissioningInfoType
{
uint32_t FailSafeExpiryLengthMs;
} EmberAfBasicCommissioningInfo;
} EmberAfBasicCommissioningInfoType;

// Struct for BlockThreshold
typedef struct _BlockThreshold
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1385,31 +1385,25 @@ EmberAfStatus emberAfGeneralCommissioningClusterServerCommandParse(EmberAfCluste
wasHandled = emberAfGeneralCommissioningClusterCommissioningCompleteCallback(nullptr);
break;
}
case ZCL_SET_FABRIC_COMMAND_ID: {
case ZCL_SET_REGULATORY_CONFIG_COMMAND_ID: {
uint16_t payloadOffset = cmd->payloadStartIndex;
chip::ByteSpan fabricId;
chip::ByteSpan fabricSecret;
uint8_t location;
uint8_t * countryCode;
uint64_t breadcrumb;
uint32_t timeoutMs;

if (cmd->bufLen < payloadOffset + 1u)
if (cmd->bufLen < payloadOffset + 1)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
fabricId = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + fabricId.size() + 1u);
location = emberAfGetInt8u(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + 1);
if (cmd->bufLen < payloadOffset + 1u)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
}
{
uint8_t * rawData = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
fabricSecret = chip::ByteSpan(rawData + 1u, emberAfStringLength(rawData));
}
payloadOffset = static_cast<uint16_t>(payloadOffset + fabricSecret.size() + 1u);
countryCode = emberAfGetString(cmd->buffer, payloadOffset, cmd->bufLen);
payloadOffset = static_cast<uint16_t>(payloadOffset + emberAfStringLength(countryCode) + 1u);
if (cmd->bufLen < payloadOffset + 8)
{
return EMBER_ZCL_STATUS_MALFORMED_COMMAND;
Expand All @@ -1422,8 +1416,8 @@ EmberAfStatus emberAfGeneralCommissioningClusterServerCommandParse(EmberAfCluste
}
timeoutMs = emberAfGetInt32u(cmd->buffer, payloadOffset, cmd->bufLen);

wasHandled =
emberAfGeneralCommissioningClusterSetFabricCallback(nullptr, fabricId, fabricSecret, breadcrumb, timeoutMs);
wasHandled = emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(nullptr, location, countryCode, breadcrumb,
timeoutMs);
break;
}
default: {
Expand Down
10 changes: 5 additions & 5 deletions examples/all-clusters-app/all-clusters-common/gen/callback.h
Original file line number Diff line number Diff line change
Expand Up @@ -2179,15 +2179,15 @@ bool emberAfGeneralCommissioningClusterArmFailSafeCallback(chip::app::Command *
bool emberAfGeneralCommissioningClusterCommissioningCompleteCallback(chip::app::Command * commandObj);

/**
* @brief General Commissioning Cluster SetFabric Command callback
* @param fabricId
* @param fabricSecret
* @brief General Commissioning Cluster SetRegulatoryConfig Command callback
* @param location
* @param countryCode
* @param breadcrumb
* @param timeoutMs
*/

bool emberAfGeneralCommissioningClusterSetFabricCallback(chip::app::Command * commandObj, chip::ByteSpan fabricId,
chip::ByteSpan fabricSecret, uint64_t breadcrumb, uint32_t timeoutMs);
bool emberAfGeneralCommissioningClusterSetRegulatoryConfigCallback(chip::app::Command * commandObj, uint8_t location,
uint8_t * countryCode, uint64_t breadcrumb, uint32_t timeoutMs);

/**
* @brief Groups Cluster AddGroup Command callback
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1906,32 +1906,6 @@
ZCL_ANNOUNCE_OTA_SERVER_COMMAND_ID, "uuuu", serverLocation, vendorId, announcementReason, \
metadataForNode);

/** @brief Command description for SetFabric
*
* Command: SetFabric
* @param fabricId OCTET_STRING
* @param fabricSecret OCTET_STRING
* @param breadcrumb INT64U
* @param timeoutMs INT32U
*/
#define emberAfFillCommandGeneral \
CommissioningClusterSetFabric(fabricId, fabricSecret, breadcrumb, timeoutMs) \
emberAfFillExternalBuffer(mask, \
\
ZCL_SET_FABRIC_COMMAND_ID, "uuuu", fabricId, fabricSecret, breadcrumb, timeoutMs);

/** @brief Command description for SetFabricResponse
*
* Command: SetFabricResponse
* @param errorCode INT8U
* @param debugText CHAR_STRING
*/
#define emberAfFillCommandGeneral \
CommissioningClusterSetFabricResponse(errorCode, debugText) \
emberAfFillExternalBuffer(mask, \
\
ZCL_SET_FABRIC_RESPONSE_COMMAND_ID, "uu", errorCode, debugText);

/** @brief Command description for ArmFailSafe
*
* Command: ArmFailSafe
Expand All @@ -1948,7 +1922,7 @@
/** @brief Command description for ArmFailSafeResponse
*
* Command: ArmFailSafeResponse
* @param errorCode INT8U
* @param errorCode GeneralCommissioningError
* @param debugText CHAR_STRING
*/
#define emberAfFillCommandGeneral \
Expand All @@ -1974,7 +1948,7 @@
/** @brief Command description for SetRegulatoryConfigResponse
*
* Command: SetRegulatoryConfigResponse
* @param errorCode INT8U
* @param errorCode GeneralCommissioningError
* @param debugText CHAR_STRING
*/
#define emberAfFillCommandGeneral \
Expand All @@ -1995,7 +1969,7 @@
/** @brief Command description for CommissioningCompleteResponse
*
* Command: CommissioningCompleteResponse
* @param errorCode INT8U
* @param errorCode GeneralCommissioningError
* @param debugText CHAR_STRING
*/
#define emberAfFillCommandGeneral \
Expand Down
14 changes: 6 additions & 8 deletions examples/all-clusters-app/all-clusters-common/gen/command-id.h
Original file line number Diff line number Diff line change
Expand Up @@ -239,14 +239,12 @@
#define ZCL_ANNOUNCE_OTA_SERVER_COMMAND_ID (0x00)

// Commands for cluster: General Commissioning
#define ZCL_SET_FABRIC_COMMAND_ID (0x00)
#define ZCL_SET_FABRIC_RESPONSE_COMMAND_ID (0x01)
#define ZCL_ARM_FAIL_SAFE_COMMAND_ID (0x02)
#define ZCL_ARM_FAIL_SAFE_RESPONSE_COMMAND_ID (0x03)
#define ZCL_SET_REGULATORY_CONFIG_COMMAND_ID (0x04)
#define ZCL_SET_REGULATORY_CONFIG_RESPONSE_COMMAND_ID (0x05)
#define ZCL_COMMISSIONING_COMPLETE_COMMAND_ID (0x06)
#define ZCL_COMMISSIONING_COMPLETE_RESPONSE_COMMAND_ID (0x07)
#define ZCL_ARM_FAIL_SAFE_COMMAND_ID (0x00)
#define ZCL_ARM_FAIL_SAFE_RESPONSE_COMMAND_ID (0x01)
#define ZCL_SET_REGULATORY_CONFIG_COMMAND_ID (0x02)
#define ZCL_SET_REGULATORY_CONFIG_RESPONSE_COMMAND_ID (0x03)
#define ZCL_COMMISSIONING_COMPLETE_COMMAND_ID (0x04)
#define ZCL_COMMISSIONING_COMPLETE_RESPONSE_COMMAND_ID (0x05)

// Commands for cluster: Network Commissioning
#define ZCL_SCAN_NETWORKS_COMMAND_ID (0x00)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -987,12 +987,16 @@
{ 0x0029, 0x04, \
ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* OTA Software Update Server (server): ApplyUpdateRequestResponse */ \
{ 0x002A, 0x00, ZAP_COMMAND_MASK(OUTGOING_SERVER) }, /* OTA Software Update Client (server): AnnounceOtaServer */ \
{ 0x0030, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* General Commissioning (server): SetFabric */ \
{ 0x0030, 0x01, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* General Commissioning (server): SetFabricResponse */ \
{ 0x0030, 0x02, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* General Commissioning (server): ArmFailSafe */ \
{ 0x0030, 0x03, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* General Commissioning (server): ArmFailSafeResponse */ \
{ 0x0030, 0x06, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* General Commissioning (server): CommissioningComplete */ \
{ 0x0030, 0x07, \
{ 0x0030, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* General Commissioning (server): ArmFailSafe */ \
{ 0x0030, 0x01, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* General Commissioning (server): ArmFailSafeResponse */ \
{ \
0x0030, 0x02, ZAP_COMMAND_MASK(INCOMING_SERVER) | ZAP_COMMAND_MASK(OUTGOING_SERVER) \
}, /* General Commissioning (server): SetRegulatoryConfig */ \
{ \
0x0030, 0x03, ZAP_COMMAND_MASK(INCOMING_SERVER) | ZAP_COMMAND_MASK(OUTGOING_SERVER) \
}, /* General Commissioning (server): SetRegulatoryConfigResponse */ \
{ 0x0030, 0x04, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* General Commissioning (server): CommissioningComplete */ \
{ 0x0030, 0x05, \
ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* General Commissioning (server): CommissioningCompleteResponse */ \
{ 0x0031, 0x00, ZAP_COMMAND_MASK(INCOMING_SERVER) }, /* Network Commissioning (server): ScanNetworks */ \
{ 0x0031, 0x01, ZAP_COMMAND_MASK(INCOMING_CLIENT) }, /* Network Commissioning (server): ScanNetworksResponse */ \
Expand Down
Loading

0 comments on commit 20ac5e1

Please sign in to comment.