3 * Copyright (c) 2021 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 // THIS FILE IS GENERATED BY ZAP
23 #include "af-structs.h"
24 #include "app/util/util.h"
25 #include "call-command-handler.h"
27 #include "cluster-id.h"
28 #include "command-id.h"
30 #include <app/InteractionModelEngine.h>
32 // Currently we need some work to keep compatible with ember lib.
33 #include <util/ember-compatibility-functions.h>
38 // Cluster specific command parsing
42 namespace LevelControl {
44 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
49 case ZCL_MOVE_COMMAND_ID: {
50 CHIP_ERROR TLVError = CHIP_NO_ERROR;
54 uint8_t optionOverride;
56 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
58 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
61 TLVError = dataTlv.Get(moveMode);
64 TLVError = dataTlv.Get(rate);
67 TLVError = dataTlv.Get(optionMask);
70 TLVError = dataTlv.Get(optionOverride);
73 // Unsupported tag, ignore it.
74 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
77 if (TLVError != CHIP_NO_ERROR)
79 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
80 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
83 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
84 emberAfLevelControlClusterMoveCallback(moveMode, rate, optionMask, optionOverride);
87 case ZCL_MOVE_TO_LEVEL_COMMAND_ID: {
88 CHIP_ERROR TLVError = CHIP_NO_ERROR;
90 uint16_t transitionTime;
92 uint8_t optionOverride;
94 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
96 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
99 TLVError = dataTlv.Get(level);
102 TLVError = dataTlv.Get(transitionTime);
105 TLVError = dataTlv.Get(optionMask);
108 TLVError = dataTlv.Get(optionOverride);
111 // Unsupported tag, ignore it.
112 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
115 if (TLVError != CHIP_NO_ERROR)
117 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
118 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
121 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
122 emberAfLevelControlClusterMoveToLevelCallback(level, transitionTime, optionMask, optionOverride);
125 case ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID: {
126 CHIP_ERROR TLVError = CHIP_NO_ERROR;
128 uint16_t transitionTime;
130 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
132 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
135 TLVError = dataTlv.Get(level);
138 TLVError = dataTlv.Get(transitionTime);
141 // Unsupported tag, ignore it.
142 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
145 if (TLVError != CHIP_NO_ERROR)
147 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
148 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
151 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
152 emberAfLevelControlClusterMoveToLevelWithOnOffCallback(level, transitionTime);
155 case ZCL_MOVE_WITH_ON_OFF_COMMAND_ID: {
156 CHIP_ERROR TLVError = CHIP_NO_ERROR;
160 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
162 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
165 TLVError = dataTlv.Get(moveMode);
168 TLVError = dataTlv.Get(rate);
171 // Unsupported tag, ignore it.
172 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
175 if (TLVError != CHIP_NO_ERROR)
177 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
178 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
181 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
182 emberAfLevelControlClusterMoveWithOnOffCallback(moveMode, rate);
185 case ZCL_STEP_COMMAND_ID: {
186 CHIP_ERROR TLVError = CHIP_NO_ERROR;
189 uint16_t transitionTime;
191 uint8_t optionOverride;
193 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
195 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
198 TLVError = dataTlv.Get(stepMode);
201 TLVError = dataTlv.Get(stepSize);
204 TLVError = dataTlv.Get(transitionTime);
207 TLVError = dataTlv.Get(optionMask);
210 TLVError = dataTlv.Get(optionOverride);
213 // Unsupported tag, ignore it.
214 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
217 if (TLVError != CHIP_NO_ERROR)
219 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
220 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
223 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
224 emberAfLevelControlClusterStepCallback(stepMode, stepSize, transitionTime, optionMask, optionOverride);
227 case ZCL_STEP_WITH_ON_OFF_COMMAND_ID: {
228 CHIP_ERROR TLVError = CHIP_NO_ERROR;
231 uint16_t transitionTime;
233 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
235 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
238 TLVError = dataTlv.Get(stepMode);
241 TLVError = dataTlv.Get(stepSize);
244 TLVError = dataTlv.Get(transitionTime);
247 // Unsupported tag, ignore it.
248 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
251 if (TLVError != CHIP_NO_ERROR)
253 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
254 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
257 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
258 emberAfLevelControlClusterStepWithOnOffCallback(stepMode, stepSize, transitionTime);
261 case ZCL_STOP_COMMAND_ID: {
262 CHIP_ERROR TLVError = CHIP_NO_ERROR;
264 uint8_t optionOverride;
266 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
268 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
271 TLVError = dataTlv.Get(optionMask);
274 TLVError = dataTlv.Get(optionOverride);
277 // Unsupported tag, ignore it.
278 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
281 if (TLVError != CHIP_NO_ERROR)
283 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
284 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
287 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
288 emberAfLevelControlClusterStopCallback(optionMask, optionOverride);
291 case ZCL_STOP_WITH_ON_OFF_COMMAND_ID: {
292 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
293 emberAfLevelControlClusterStopWithOnOffCallback();
297 // Unrecognized command ID, error status will apply.
298 // TODO: Encode response for command not found
299 ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_LEVEL_CONTROL_CLUSTER_ID);
306 } // namespace LevelControl
308 namespace NetworkCommissioning {
310 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
315 case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
316 CHIP_ERROR TLVError = CHIP_NO_ERROR;
317 chip::ByteSpan operationalDataset;
321 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
323 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
326 const uint8_t * data = nullptr;
327 TLVError = dataTlv.GetDataPtr(data);
328 operationalDataset = chip::ByteSpan(data, dataTlv.GetLength());
332 TLVError = dataTlv.Get(breadcrumb);
335 TLVError = dataTlv.Get(timeoutMs);
338 // Unsupported tag, ignore it.
339 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
342 if (TLVError != CHIP_NO_ERROR)
344 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
345 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
348 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
349 emberAfNetworkCommissioningClusterAddThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
352 case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
353 CHIP_ERROR TLVError = CHIP_NO_ERROR;
355 chip::ByteSpan credentials;
359 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
361 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
364 const uint8_t * data = nullptr;
365 TLVError = dataTlv.GetDataPtr(data);
366 ssid = chip::ByteSpan(data, dataTlv.GetLength());
370 const uint8_t * data = nullptr;
371 TLVError = dataTlv.GetDataPtr(data);
372 credentials = chip::ByteSpan(data, dataTlv.GetLength());
376 TLVError = dataTlv.Get(breadcrumb);
379 TLVError = dataTlv.Get(timeoutMs);
382 // Unsupported tag, ignore it.
383 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
386 if (TLVError != CHIP_NO_ERROR)
388 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
389 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
392 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
393 emberAfNetworkCommissioningClusterAddWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
396 case ZCL_DISABLE_NETWORK_COMMAND_ID: {
397 CHIP_ERROR TLVError = CHIP_NO_ERROR;
398 chip::ByteSpan networkID;
402 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
404 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
407 const uint8_t * data = nullptr;
408 TLVError = dataTlv.GetDataPtr(data);
409 networkID = chip::ByteSpan(data, dataTlv.GetLength());
413 TLVError = dataTlv.Get(breadcrumb);
416 TLVError = dataTlv.Get(timeoutMs);
419 // Unsupported tag, ignore it.
420 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
423 if (TLVError != CHIP_NO_ERROR)
425 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
426 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
429 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
430 emberAfNetworkCommissioningClusterDisableNetworkCallback(networkID, breadcrumb, timeoutMs);
433 case ZCL_ENABLE_NETWORK_COMMAND_ID: {
434 CHIP_ERROR TLVError = CHIP_NO_ERROR;
435 chip::ByteSpan networkID;
439 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
441 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
444 const uint8_t * data = nullptr;
445 TLVError = dataTlv.GetDataPtr(data);
446 networkID = chip::ByteSpan(data, dataTlv.GetLength());
450 TLVError = dataTlv.Get(breadcrumb);
453 TLVError = dataTlv.Get(timeoutMs);
456 // Unsupported tag, ignore it.
457 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
460 if (TLVError != CHIP_NO_ERROR)
462 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
463 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
466 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
467 emberAfNetworkCommissioningClusterEnableNetworkCallback(networkID, breadcrumb, timeoutMs);
470 case ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID: {
471 CHIP_ERROR TLVError = CHIP_NO_ERROR;
474 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
476 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
479 TLVError = dataTlv.Get(timeoutMs);
482 // Unsupported tag, ignore it.
483 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
486 if (TLVError != CHIP_NO_ERROR)
488 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
489 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
492 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
493 emberAfNetworkCommissioningClusterGetLastNetworkCommissioningResultCallback(timeoutMs);
496 case ZCL_REMOVE_NETWORK_COMMAND_ID: {
497 CHIP_ERROR TLVError = CHIP_NO_ERROR;
498 chip::ByteSpan NetworkID;
502 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
504 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
507 const uint8_t * data = nullptr;
508 TLVError = dataTlv.GetDataPtr(data);
509 NetworkID = chip::ByteSpan(data, dataTlv.GetLength());
513 TLVError = dataTlv.Get(Breadcrumb);
516 TLVError = dataTlv.Get(TimeoutMs);
519 // Unsupported tag, ignore it.
520 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
523 if (TLVError != CHIP_NO_ERROR)
525 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
526 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
529 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
530 emberAfNetworkCommissioningClusterRemoveNetworkCallback(NetworkID, Breadcrumb, TimeoutMs);
533 case ZCL_SCAN_NETWORKS_COMMAND_ID: {
534 CHIP_ERROR TLVError = CHIP_NO_ERROR;
539 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
541 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
544 const uint8_t * data = nullptr;
545 TLVError = dataTlv.GetDataPtr(data);
546 ssid = chip::ByteSpan(data, dataTlv.GetLength());
550 TLVError = dataTlv.Get(breadcrumb);
553 TLVError = dataTlv.Get(timeoutMs);
556 // Unsupported tag, ignore it.
557 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
560 if (TLVError != CHIP_NO_ERROR)
562 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
563 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
566 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
567 emberAfNetworkCommissioningClusterScanNetworksCallback(ssid, breadcrumb, timeoutMs);
570 case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
571 CHIP_ERROR TLVError = CHIP_NO_ERROR;
572 chip::ByteSpan operationalDataset;
576 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
578 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
581 const uint8_t * data = nullptr;
582 TLVError = dataTlv.GetDataPtr(data);
583 operationalDataset = chip::ByteSpan(data, dataTlv.GetLength());
587 TLVError = dataTlv.Get(breadcrumb);
590 TLVError = dataTlv.Get(timeoutMs);
593 // Unsupported tag, ignore it.
594 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
597 if (TLVError != CHIP_NO_ERROR)
599 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
600 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
603 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
604 emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
607 case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
608 CHIP_ERROR TLVError = CHIP_NO_ERROR;
610 chip::ByteSpan credentials;
614 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
616 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
619 const uint8_t * data = nullptr;
620 TLVError = dataTlv.GetDataPtr(data);
621 ssid = chip::ByteSpan(data, dataTlv.GetLength());
625 const uint8_t * data = nullptr;
626 TLVError = dataTlv.GetDataPtr(data);
627 credentials = chip::ByteSpan(data, dataTlv.GetLength());
631 TLVError = dataTlv.Get(breadcrumb);
634 TLVError = dataTlv.Get(timeoutMs);
637 // Unsupported tag, ignore it.
638 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
641 if (TLVError != CHIP_NO_ERROR)
643 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
644 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
647 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
648 emberAfNetworkCommissioningClusterUpdateWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
652 // Unrecognized command ID, error status will apply.
653 // TODO: Encode response for command not found
654 ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_NETWORK_COMMISSIONING_CLUSTER_ID);
661 } // namespace NetworkCommissioning
665 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
670 case ZCL_OFF_COMMAND_ID: {
671 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
672 emberAfOnOffClusterOffCallback();
675 case ZCL_ON_COMMAND_ID: {
676 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
677 emberAfOnOffClusterOnCallback();
680 case ZCL_TOGGLE_COMMAND_ID: {
681 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
682 emberAfOnOffClusterToggleCallback();
686 // Unrecognized command ID, error status will apply.
687 // TODO: Encode response for command not found
688 ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_ON_OFF_CLUSTER_ID);
697 } // namespace clusters
699 void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aCommandId, chip::EndpointId aEndPointId,
700 chip::TLV::TLVReader & aReader, Command * apCommandObj)
702 ChipLogDetail(Zcl, "Received Cluster Command: Cluster=%" PRIx16 " Command=%" PRIx8 " Endpoint=%" PRIx8, aClusterId, aCommandId,
704 Compatibility::SetupEmberAfObjects(apCommandObj, aClusterId, aCommandId, aEndPointId);
707 case ZCL_LEVEL_CONTROL_CLUSTER_ID:
708 clusters::LevelControl::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
710 case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
711 clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
713 case ZCL_ON_OFF_CLUSTER_ID:
714 clusters::OnOff::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
717 // Unrecognized cluster ID, error status will apply.
718 // TODO: Encode response for Cluster not found
719 ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
722 Compatibility::ResetEmberAfObjects();