Skip to content

Commit

Permalink
Use the XML defined response or the one assigned from ZAP instead of …
Browse files Browse the repository at this point in the history
…a custom heuristic (project-chip#10606)
  • Loading branch information
vivien-apple authored Oct 23, 2021
1 parent e0e8088 commit afd63a1
Show file tree
Hide file tree
Showing 13 changed files with 319 additions and 58 deletions.
70 changes: 27 additions & 43 deletions src/app/zap-templates/common/ClustersHelper.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,22 @@ function loadClusters()
.then(clusters => clusters.filter(cluster => cluster.enabled == 1));
}

function loadCommandResponse(command, packageId)
{
const { db, sessionId } = this.global;
return queryCommand.selectCommandById(db, command.id, packageId).then(commandDetails => {
if (commandDetails.responseRef == null) {
command.response = null;
return command;
}

return queryCommand.selectCommandById(db, commandDetails.responseRef, packageId).then(response => {
command.response = response;
return command;
});
});
}

function loadCommandArguments(command, packageId)
{
const { db, sessionId } = this.global;
Expand All @@ -101,6 +117,7 @@ function loadCommands(packageId)
.then(endpointTypes => queryEndpointType.selectClustersAndEndpointDetailsFromEndpointTypes(db, endpointTypes))
.then(endpointTypesAndClusters => queryCommand.selectCommandDetailsFromAllEndpointTypesAndClusters(
db, endpointTypesAndClusters, true))
.then(commands => Promise.all(commands.map(command => loadCommandResponse.call(this, command, packageId))))
.then(commands => Promise.all(commands.map(command => loadCommandArguments.call(this, command, packageId))));
}

Expand Down Expand Up @@ -377,51 +394,18 @@ function enhancedCommands(commands, types)
commands.forEach(command => {
command.isResponse = command.name.includes('Response');
command.isManufacturerSpecificCommand = !!this.mfgCode;
});

commands.forEach(command => {
// This filter uses the assumption that a response to a command has a well defined name, such as
// (response name) == (command name + 'Response') or s/Request/Response. This is very often the case,
// but this is not always true since some clusters use the same response to answer different commands, such as the
// operational cluster.
const automaticFilter = response => {
if (!response.isResponse) {
return false;
}

if (response.clusterName != command.clusterName) {
return false;
}

if (response.name == command.name) {
return false;
}

return (response.name == (command.name + 'Response')) || (response.name == (command.name.replace('Request', 'Response')));
};

const manualFilter = response => {
switch (command.name) {
case 'AddNOC':
case 'UpdateNOC':
case 'UpdateFabricLabel':
case 'RemoveFabric':
return response.name == 'NOCResponse';
default:
return false;
}
};
const filter = response => automaticFilter(response) || manualFilter(response);

const response = commands.find(filter);
if (response) {
command.hasSpecificResponse = true;
command.responseName = response.name;
command.response = response;
command.hasSpecificResponse = !!command.response;
if (command.response) {
const responseName = command.response.name;
command.responseName = responseName;
// The 'response' property contains the response returned by the `selectCommandById`
// helper. But this one does not contains all the metadata informations added by
// `enhancedItem`, so instead of using the one from ZAP, retrieve the enhanced version.
command.response = commands.find(command => command.name == responseName);
} else {
command.hasSpecificResponse = false;
command.responseName = 'DefaultSuccess';
command.response = { arguments : [] };
command.responseName = 'DefaultSuccess';
command.response = { arguments : [] };
}
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ limitations under the License.
<arg name="AttestationSignature" type="OCTET_STRING"/>
</command>

<command source="client" code="0x06" name="AddNOC" optional="false">
<command source="client" code="0x06" name="AddNOC" response="NOCResponse" optional="false">
<description>Sender is requesting to add the new node operational certificates.</description>
<arg name="NOCValue" type="OCTET_STRING"/>
<arg name="ICACValue" type="OCTET_STRING" optional="true"/>
Expand All @@ -102,7 +102,7 @@ limitations under the License.
<arg name="AdminVendorId" type="INT16U"/>
</command>

<command source="client" code="0x07" name="UpdateNOC" optional="false">
<command source="client" code="0x07" name="UpdateNOC" response="NOCResponse" optional="false">
<description>Sender is requesting to update the node operational certificates.</description>
<arg name="NOCValue" type="OCTET_STRING"/>
<arg name="ICACValue" type="OCTET_STRING" optional="true"/>
Expand All @@ -115,12 +115,12 @@ limitations under the License.
<arg name="DebugText" type="CHAR_STRING"/>
</command>

<command source="client" code="0x09" name="UpdateFabricLabel" optional="false">
<command source="client" code="0x09" name="UpdateFabricLabel" response="NOCResponse" optional="false">
<description>This command SHALL be used by an Administrative Node to set the user-visible Label field for a given Fabric, as reflected by entries in the Fabrics attribute.</description>
<arg name="Label" type="CHAR_STRING" length="32"/>
</command>

<command source="client" code="0x0a" name="RemoveFabric" optional="false">
<command source="client" code="0x0a" name="RemoveFabric" response="NOCResponse" optional="false">
<description>This command is used by Administrative Nodes to remove a given fabric index and delete all associated fabric-scoped data.</description>
<arg name="FabricIndex" type="INT8U"/>
</command>
Expand Down
19 changes: 19 additions & 0 deletions src/controller/data_model/controller-clusters.zap
Original file line number Diff line number Diff line change
Expand Up @@ -2772,6 +2772,25 @@
],
"attributes": []
},
{
"name": "Diagnostic Logs",
"code": 50,
"mfgCode": null,
"define": "DIAGNOSTIC_LOGS_CLUSTER",
"side": "server",
"enabled": 0,
"commands": [
{
"name": "RetrieveLogsResponse",
"code": 1,
"mfgCode": null,
"source": "server",
"incoming": 1,
"outgoing": 0
}
],
"attributes": []
},
{
"name": "General Diagnostics",
"code": 51,
Expand Down
85 changes: 83 additions & 2 deletions src/controller/java/zap-generated/CHIPClusters-JNI.cpp

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.

11 changes: 11 additions & 0 deletions src/darwin/Framework/CHIP/zap-generated/CHIPCallbackBridge.mm

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.

9 changes: 5 additions & 4 deletions src/darwin/Framework/CHIP/zap-generated/CHIPClustersObjc.mm

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

15 changes: 14 additions & 1 deletion zzz_generated/chip-tool/zap-generated/cluster/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.

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

Loading

0 comments on commit afd63a1

Please sign in to comment.