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 "call-command-handler.h"
26 #include "cluster-id.h"
27 #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
44 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
49 case ZCL_RESET_TO_FACTORY_DEFAULTS_COMMAND_ID: {
50 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
51 emberAfBasicClusterResetToFactoryDefaultsCallback();
55 // Unrecognized command ID, error status will apply.
56 // TODO: Encode response for command not found
57 ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_BASIC_CLUSTER_ID);
66 namespace LevelControl {
68 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
73 case ZCL_MOVE_COMMAND_ID: {
74 CHIP_ERROR TLVError = CHIP_NO_ERROR;
78 uint8_t optionOverride;
80 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
82 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
85 TLVError = dataTlv.Get(moveMode);
88 TLVError = dataTlv.Get(rate);
91 TLVError = dataTlv.Get(optionMask);
94 TLVError = dataTlv.Get(optionOverride);
97 // Unsupported tag, ignore it.
98 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
101 if (TLVError != CHIP_NO_ERROR)
103 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
104 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
107 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
108 emberAfLevelControlClusterMoveCallback(moveMode, rate, optionMask, optionOverride);
111 case ZCL_MOVE_TO_LEVEL_COMMAND_ID: {
112 CHIP_ERROR TLVError = CHIP_NO_ERROR;
114 uint16_t transitionTime;
116 uint8_t optionOverride;
118 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
120 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
123 TLVError = dataTlv.Get(level);
126 TLVError = dataTlv.Get(transitionTime);
129 TLVError = dataTlv.Get(optionMask);
132 TLVError = dataTlv.Get(optionOverride);
135 // Unsupported tag, ignore it.
136 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
139 if (TLVError != CHIP_NO_ERROR)
141 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
142 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
145 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
146 emberAfLevelControlClusterMoveToLevelCallback(level, transitionTime, optionMask, optionOverride);
149 case ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID: {
150 CHIP_ERROR TLVError = CHIP_NO_ERROR;
152 uint16_t transitionTime;
154 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
156 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
159 TLVError = dataTlv.Get(level);
162 TLVError = dataTlv.Get(transitionTime);
165 // Unsupported tag, ignore it.
166 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
169 if (TLVError != CHIP_NO_ERROR)
171 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
172 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
175 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
176 emberAfLevelControlClusterMoveToLevelWithOnOffCallback(level, transitionTime);
179 case ZCL_MOVE_WITH_ON_OFF_COMMAND_ID: {
180 CHIP_ERROR TLVError = CHIP_NO_ERROR;
184 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
186 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
189 TLVError = dataTlv.Get(moveMode);
192 TLVError = dataTlv.Get(rate);
195 // Unsupported tag, ignore it.
196 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
199 if (TLVError != CHIP_NO_ERROR)
201 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
202 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
205 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
206 emberAfLevelControlClusterMoveWithOnOffCallback(moveMode, rate);
209 case ZCL_STEP_COMMAND_ID: {
210 CHIP_ERROR TLVError = CHIP_NO_ERROR;
213 uint16_t transitionTime;
215 uint8_t optionOverride;
217 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
219 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
222 TLVError = dataTlv.Get(stepMode);
225 TLVError = dataTlv.Get(stepSize);
228 TLVError = dataTlv.Get(transitionTime);
231 TLVError = dataTlv.Get(optionMask);
234 TLVError = dataTlv.Get(optionOverride);
237 // Unsupported tag, ignore it.
238 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
241 if (TLVError != CHIP_NO_ERROR)
243 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
244 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
247 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
248 emberAfLevelControlClusterStepCallback(stepMode, stepSize, transitionTime, optionMask, optionOverride);
251 case ZCL_STEP_WITH_ON_OFF_COMMAND_ID: {
252 CHIP_ERROR TLVError = CHIP_NO_ERROR;
255 uint16_t transitionTime;
257 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
259 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
262 TLVError = dataTlv.Get(stepMode);
265 TLVError = dataTlv.Get(stepSize);
268 TLVError = dataTlv.Get(transitionTime);
271 // Unsupported tag, ignore it.
272 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
275 if (TLVError != CHIP_NO_ERROR)
277 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
278 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
281 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
282 emberAfLevelControlClusterStepWithOnOffCallback(stepMode, stepSize, transitionTime);
285 case ZCL_STOP_COMMAND_ID: {
286 CHIP_ERROR TLVError = CHIP_NO_ERROR;
288 uint8_t optionOverride;
290 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
292 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
295 TLVError = dataTlv.Get(optionMask);
298 TLVError = dataTlv.Get(optionOverride);
301 // Unsupported tag, ignore it.
302 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
305 if (TLVError != CHIP_NO_ERROR)
307 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
308 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
311 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
312 emberAfLevelControlClusterStopCallback(optionMask, optionOverride);
315 case ZCL_STOP_WITH_ON_OFF_COMMAND_ID: {
316 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
317 emberAfLevelControlClusterStopWithOnOffCallback();
321 // Unrecognized command ID, error status will apply.
322 // TODO: Encode response for command not found
323 ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_LEVEL_CONTROL_CLUSTER_ID);
330 } // namespace LevelControl
334 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
339 case ZCL_OFF_COMMAND_ID: {
340 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
341 emberAfOnOffClusterOffCallback();
344 case ZCL_ON_COMMAND_ID: {
345 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
346 emberAfOnOffClusterOnCallback();
349 case ZCL_TOGGLE_COMMAND_ID: {
350 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
351 emberAfOnOffClusterToggleCallback();
355 // Unrecognized command ID, error status will apply.
356 // TODO: Encode response for command not found
357 ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_ON_OFF_CLUSTER_ID);
366 } // namespace clusters
368 void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aCommandId, chip::EndpointId aEndPointId,
369 chip::TLV::TLVReader & aReader, Command * apCommandObj)
371 ChipLogDetail(Zcl, "Received Cluster Command: Cluster=%" PRIx16 " Command=%" PRIx8 " Endpoint=%" PRIx8, aClusterId, aCommandId,
373 Compatibility::SetupEmberAfObjects(apCommandObj, aClusterId, aCommandId, aEndPointId);
376 case ZCL_BASIC_CLUSTER_ID:
377 clusters::Basic::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
379 case ZCL_LEVEL_CONTROL_CLUSTER_ID:
380 clusters::LevelControl::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
382 case ZCL_ON_OFF_CLUSTER_ID:
383 clusters::OnOff::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
386 // Unrecognized cluster ID, error status will apply.
387 // TODO: Encode response for Cluster not found
388 ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
391 Compatibility::ResetEmberAfObjects();