Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / tv-app / tv-common / gen / IMClusterCommandHandler.cpp
1 /*
2  *
3  *    Copyright (c) 2021 Project CHIP Authors
4  *
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
8  *
9  *        http://www.apache.org/licenses/LICENSE-2.0
10  *
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.
16  */
17
18 // THIS FILE IS GENERATED BY ZAP
19
20 #include <cinttypes>
21 #include <cstdint>
22
23 #include "af-structs.h"
24 #include "app/util/util.h"
25 #include "call-command-handler.h"
26 #include "callback.h"
27 #include "cluster-id.h"
28 #include "command-id.h"
29
30 #include <app/InteractionModelEngine.h>
31
32 // Currently we need some work to keep compatible with ember lib.
33 #include <util/ember-compatibility-functions.h>
34
35 namespace chip {
36 namespace app {
37
38 // Cluster specific command parsing
39
40 namespace clusters {
41
42 namespace BarrierControl {
43
44 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
45 {
46     {
47         switch (commandId)
48         {
49         case ZCL_BARRIER_CONTROL_GO_TO_PERCENT_COMMAND_ID: {
50             CHIP_ERROR TLVError = CHIP_NO_ERROR;
51             uint8_t percentOpen;
52
53             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
54             {
55                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
56                 {
57                 case 0:
58                     TLVError = dataTlv.Get(percentOpen);
59                     break;
60                 default:
61                     // Unsupported tag, ignore it.
62                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
63                     break;
64                 }
65                 if (TLVError != CHIP_NO_ERROR)
66                 {
67                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
68                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
69                 }
70             }
71             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
72             emberAfBarrierControlClusterBarrierControlGoToPercentCallback(percentOpen);
73             break;
74         }
75         case ZCL_BARRIER_CONTROL_STOP_COMMAND_ID: {
76             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
77             emberAfBarrierControlClusterBarrierControlStopCallback();
78             break;
79         }
80         default: {
81             // Unrecognized command ID, error status will apply.
82             // TODO: Encode response for command not found
83             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_BARRIER_CONTROL_CLUSTER_ID);
84             break;
85         }
86         }
87     }
88 }
89
90 } // namespace BarrierControl
91
92 namespace ColorControl {
93
94 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
95 {
96     {
97         switch (commandId)
98         {
99         case ZCL_MOVE_COLOR_COMMAND_ID: {
100             CHIP_ERROR TLVError = CHIP_NO_ERROR;
101             int16_t rateX;
102             int16_t rateY;
103             uint8_t optionsMask;
104             uint8_t optionsOverride;
105
106             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
107             {
108                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
109                 {
110                 case 0:
111                     TLVError = dataTlv.Get(rateX);
112                     break;
113                 case 1:
114                     TLVError = dataTlv.Get(rateY);
115                     break;
116                 case 2:
117                     TLVError = dataTlv.Get(optionsMask);
118                     break;
119                 case 3:
120                     TLVError = dataTlv.Get(optionsOverride);
121                     break;
122                 default:
123                     // Unsupported tag, ignore it.
124                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
125                     break;
126                 }
127                 if (TLVError != CHIP_NO_ERROR)
128                 {
129                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
130                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
131                 }
132             }
133             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
134             emberAfColorControlClusterMoveColorCallback(rateX, rateY, optionsMask, optionsOverride);
135             break;
136         }
137         case ZCL_MOVE_COLOR_TEMPERATURE_COMMAND_ID: {
138             CHIP_ERROR TLVError = CHIP_NO_ERROR;
139             uint8_t moveMode;
140             uint16_t rate;
141             uint16_t colorTemperatureMinimum;
142             uint16_t colorTemperatureMaximum;
143             uint8_t optionsMask;
144             uint8_t optionsOverride;
145
146             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
147             {
148                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
149                 {
150                 case 0:
151                     TLVError = dataTlv.Get(moveMode);
152                     break;
153                 case 1:
154                     TLVError = dataTlv.Get(rate);
155                     break;
156                 case 2:
157                     TLVError = dataTlv.Get(colorTemperatureMinimum);
158                     break;
159                 case 3:
160                     TLVError = dataTlv.Get(colorTemperatureMaximum);
161                     break;
162                 case 4:
163                     TLVError = dataTlv.Get(optionsMask);
164                     break;
165                 case 5:
166                     TLVError = dataTlv.Get(optionsOverride);
167                     break;
168                 default:
169                     // Unsupported tag, ignore it.
170                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
171                     break;
172                 }
173                 if (TLVError != CHIP_NO_ERROR)
174                 {
175                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
176                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
177                 }
178             }
179             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
180             emberAfColorControlClusterMoveColorTemperatureCallback(moveMode, rate, colorTemperatureMinimum, colorTemperatureMaximum,
181                                                                    optionsMask, optionsOverride);
182             break;
183         }
184         case ZCL_MOVE_HUE_COMMAND_ID: {
185             CHIP_ERROR TLVError = CHIP_NO_ERROR;
186             uint8_t moveMode;
187             uint8_t rate;
188             uint8_t optionsMask;
189             uint8_t optionsOverride;
190
191             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
192             {
193                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
194                 {
195                 case 0:
196                     TLVError = dataTlv.Get(moveMode);
197                     break;
198                 case 1:
199                     TLVError = dataTlv.Get(rate);
200                     break;
201                 case 2:
202                     TLVError = dataTlv.Get(optionsMask);
203                     break;
204                 case 3:
205                     TLVError = dataTlv.Get(optionsOverride);
206                     break;
207                 default:
208                     // Unsupported tag, ignore it.
209                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
210                     break;
211                 }
212                 if (TLVError != CHIP_NO_ERROR)
213                 {
214                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
215                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
216                 }
217             }
218             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
219             emberAfColorControlClusterMoveHueCallback(moveMode, rate, optionsMask, optionsOverride);
220             break;
221         }
222         case ZCL_MOVE_SATURATION_COMMAND_ID: {
223             CHIP_ERROR TLVError = CHIP_NO_ERROR;
224             uint8_t moveMode;
225             uint8_t rate;
226             uint8_t optionsMask;
227             uint8_t optionsOverride;
228
229             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
230             {
231                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
232                 {
233                 case 0:
234                     TLVError = dataTlv.Get(moveMode);
235                     break;
236                 case 1:
237                     TLVError = dataTlv.Get(rate);
238                     break;
239                 case 2:
240                     TLVError = dataTlv.Get(optionsMask);
241                     break;
242                 case 3:
243                     TLVError = dataTlv.Get(optionsOverride);
244                     break;
245                 default:
246                     // Unsupported tag, ignore it.
247                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
248                     break;
249                 }
250                 if (TLVError != CHIP_NO_ERROR)
251                 {
252                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
253                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
254                 }
255             }
256             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
257             emberAfColorControlClusterMoveSaturationCallback(moveMode, rate, optionsMask, optionsOverride);
258             break;
259         }
260         case ZCL_MOVE_TO_COLOR_COMMAND_ID: {
261             CHIP_ERROR TLVError = CHIP_NO_ERROR;
262             uint16_t colorX;
263             uint16_t colorY;
264             uint16_t transitionTime;
265             uint8_t optionsMask;
266             uint8_t optionsOverride;
267
268             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
269             {
270                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
271                 {
272                 case 0:
273                     TLVError = dataTlv.Get(colorX);
274                     break;
275                 case 1:
276                     TLVError = dataTlv.Get(colorY);
277                     break;
278                 case 2:
279                     TLVError = dataTlv.Get(transitionTime);
280                     break;
281                 case 3:
282                     TLVError = dataTlv.Get(optionsMask);
283                     break;
284                 case 4:
285                     TLVError = dataTlv.Get(optionsOverride);
286                     break;
287                 default:
288                     // Unsupported tag, ignore it.
289                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
290                     break;
291                 }
292                 if (TLVError != CHIP_NO_ERROR)
293                 {
294                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
295                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
296                 }
297             }
298             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
299             emberAfColorControlClusterMoveToColorCallback(colorX, colorY, transitionTime, optionsMask, optionsOverride);
300             break;
301         }
302         case ZCL_MOVE_TO_COLOR_TEMPERATURE_COMMAND_ID: {
303             CHIP_ERROR TLVError = CHIP_NO_ERROR;
304             uint16_t colorTemperature;
305             uint16_t transitionTime;
306             uint8_t optionsMask;
307             uint8_t optionsOverride;
308
309             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
310             {
311                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
312                 {
313                 case 0:
314                     TLVError = dataTlv.Get(colorTemperature);
315                     break;
316                 case 1:
317                     TLVError = dataTlv.Get(transitionTime);
318                     break;
319                 case 2:
320                     TLVError = dataTlv.Get(optionsMask);
321                     break;
322                 case 3:
323                     TLVError = dataTlv.Get(optionsOverride);
324                     break;
325                 default:
326                     // Unsupported tag, ignore it.
327                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
328                     break;
329                 }
330                 if (TLVError != CHIP_NO_ERROR)
331                 {
332                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
333                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
334                 }
335             }
336             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
337             emberAfColorControlClusterMoveToColorTemperatureCallback(colorTemperature, transitionTime, optionsMask,
338                                                                      optionsOverride);
339             break;
340         }
341         case ZCL_MOVE_TO_HUE_COMMAND_ID: {
342             CHIP_ERROR TLVError = CHIP_NO_ERROR;
343             uint8_t hue;
344             uint8_t direction;
345             uint16_t transitionTime;
346             uint8_t optionsMask;
347             uint8_t optionsOverride;
348
349             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
350             {
351                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
352                 {
353                 case 0:
354                     TLVError = dataTlv.Get(hue);
355                     break;
356                 case 1:
357                     TLVError = dataTlv.Get(direction);
358                     break;
359                 case 2:
360                     TLVError = dataTlv.Get(transitionTime);
361                     break;
362                 case 3:
363                     TLVError = dataTlv.Get(optionsMask);
364                     break;
365                 case 4:
366                     TLVError = dataTlv.Get(optionsOverride);
367                     break;
368                 default:
369                     // Unsupported tag, ignore it.
370                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
371                     break;
372                 }
373                 if (TLVError != CHIP_NO_ERROR)
374                 {
375                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
376                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
377                 }
378             }
379             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
380             emberAfColorControlClusterMoveToHueCallback(hue, direction, transitionTime, optionsMask, optionsOverride);
381             break;
382         }
383         case ZCL_MOVE_TO_HUE_AND_SATURATION_COMMAND_ID: {
384             CHIP_ERROR TLVError = CHIP_NO_ERROR;
385             uint8_t hue;
386             uint8_t saturation;
387             uint16_t transitionTime;
388             uint8_t optionsMask;
389             uint8_t optionsOverride;
390
391             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
392             {
393                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
394                 {
395                 case 0:
396                     TLVError = dataTlv.Get(hue);
397                     break;
398                 case 1:
399                     TLVError = dataTlv.Get(saturation);
400                     break;
401                 case 2:
402                     TLVError = dataTlv.Get(transitionTime);
403                     break;
404                 case 3:
405                     TLVError = dataTlv.Get(optionsMask);
406                     break;
407                 case 4:
408                     TLVError = dataTlv.Get(optionsOverride);
409                     break;
410                 default:
411                     // Unsupported tag, ignore it.
412                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
413                     break;
414                 }
415                 if (TLVError != CHIP_NO_ERROR)
416                 {
417                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
418                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
419                 }
420             }
421             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
422             emberAfColorControlClusterMoveToHueAndSaturationCallback(hue, saturation, transitionTime, optionsMask, optionsOverride);
423             break;
424         }
425         case ZCL_MOVE_TO_SATURATION_COMMAND_ID: {
426             CHIP_ERROR TLVError = CHIP_NO_ERROR;
427             uint8_t saturation;
428             uint16_t transitionTime;
429             uint8_t optionsMask;
430             uint8_t optionsOverride;
431
432             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
433             {
434                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
435                 {
436                 case 0:
437                     TLVError = dataTlv.Get(saturation);
438                     break;
439                 case 1:
440                     TLVError = dataTlv.Get(transitionTime);
441                     break;
442                 case 2:
443                     TLVError = dataTlv.Get(optionsMask);
444                     break;
445                 case 3:
446                     TLVError = dataTlv.Get(optionsOverride);
447                     break;
448                 default:
449                     // Unsupported tag, ignore it.
450                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
451                     break;
452                 }
453                 if (TLVError != CHIP_NO_ERROR)
454                 {
455                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
456                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
457                 }
458             }
459             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
460             emberAfColorControlClusterMoveToSaturationCallback(saturation, transitionTime, optionsMask, optionsOverride);
461             break;
462         }
463         case ZCL_STEP_COLOR_COMMAND_ID: {
464             CHIP_ERROR TLVError = CHIP_NO_ERROR;
465             int16_t stepX;
466             int16_t stepY;
467             uint16_t transitionTime;
468             uint8_t optionsMask;
469             uint8_t optionsOverride;
470
471             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
472             {
473                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
474                 {
475                 case 0:
476                     TLVError = dataTlv.Get(stepX);
477                     break;
478                 case 1:
479                     TLVError = dataTlv.Get(stepY);
480                     break;
481                 case 2:
482                     TLVError = dataTlv.Get(transitionTime);
483                     break;
484                 case 3:
485                     TLVError = dataTlv.Get(optionsMask);
486                     break;
487                 case 4:
488                     TLVError = dataTlv.Get(optionsOverride);
489                     break;
490                 default:
491                     // Unsupported tag, ignore it.
492                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
493                     break;
494                 }
495                 if (TLVError != CHIP_NO_ERROR)
496                 {
497                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
498                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
499                 }
500             }
501             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
502             emberAfColorControlClusterStepColorCallback(stepX, stepY, transitionTime, optionsMask, optionsOverride);
503             break;
504         }
505         case ZCL_STEP_COLOR_TEMPERATURE_COMMAND_ID: {
506             CHIP_ERROR TLVError = CHIP_NO_ERROR;
507             uint8_t stepMode;
508             uint16_t stepSize;
509             uint16_t transitionTime;
510             uint16_t colorTemperatureMinimum;
511             uint16_t colorTemperatureMaximum;
512             uint8_t optionsMask;
513             uint8_t optionsOverride;
514
515             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
516             {
517                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
518                 {
519                 case 0:
520                     TLVError = dataTlv.Get(stepMode);
521                     break;
522                 case 1:
523                     TLVError = dataTlv.Get(stepSize);
524                     break;
525                 case 2:
526                     TLVError = dataTlv.Get(transitionTime);
527                     break;
528                 case 3:
529                     TLVError = dataTlv.Get(colorTemperatureMinimum);
530                     break;
531                 case 4:
532                     TLVError = dataTlv.Get(colorTemperatureMaximum);
533                     break;
534                 case 5:
535                     TLVError = dataTlv.Get(optionsMask);
536                     break;
537                 case 6:
538                     TLVError = dataTlv.Get(optionsOverride);
539                     break;
540                 default:
541                     // Unsupported tag, ignore it.
542                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
543                     break;
544                 }
545                 if (TLVError != CHIP_NO_ERROR)
546                 {
547                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
548                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
549                 }
550             }
551             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
552             emberAfColorControlClusterStepColorTemperatureCallback(stepMode, stepSize, transitionTime, colorTemperatureMinimum,
553                                                                    colorTemperatureMaximum, optionsMask, optionsOverride);
554             break;
555         }
556         case ZCL_STEP_HUE_COMMAND_ID: {
557             CHIP_ERROR TLVError = CHIP_NO_ERROR;
558             uint8_t stepMode;
559             uint8_t stepSize;
560             uint8_t transitionTime;
561             uint8_t optionsMask;
562             uint8_t optionsOverride;
563
564             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
565             {
566                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
567                 {
568                 case 0:
569                     TLVError = dataTlv.Get(stepMode);
570                     break;
571                 case 1:
572                     TLVError = dataTlv.Get(stepSize);
573                     break;
574                 case 2:
575                     TLVError = dataTlv.Get(transitionTime);
576                     break;
577                 case 3:
578                     TLVError = dataTlv.Get(optionsMask);
579                     break;
580                 case 4:
581                     TLVError = dataTlv.Get(optionsOverride);
582                     break;
583                 default:
584                     // Unsupported tag, ignore it.
585                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
586                     break;
587                 }
588                 if (TLVError != CHIP_NO_ERROR)
589                 {
590                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
591                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
592                 }
593             }
594             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
595             emberAfColorControlClusterStepHueCallback(stepMode, stepSize, transitionTime, optionsMask, optionsOverride);
596             break;
597         }
598         case ZCL_STEP_SATURATION_COMMAND_ID: {
599             CHIP_ERROR TLVError = CHIP_NO_ERROR;
600             uint8_t stepMode;
601             uint8_t stepSize;
602             uint8_t transitionTime;
603             uint8_t optionsMask;
604             uint8_t optionsOverride;
605
606             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
607             {
608                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
609                 {
610                 case 0:
611                     TLVError = dataTlv.Get(stepMode);
612                     break;
613                 case 1:
614                     TLVError = dataTlv.Get(stepSize);
615                     break;
616                 case 2:
617                     TLVError = dataTlv.Get(transitionTime);
618                     break;
619                 case 3:
620                     TLVError = dataTlv.Get(optionsMask);
621                     break;
622                 case 4:
623                     TLVError = dataTlv.Get(optionsOverride);
624                     break;
625                 default:
626                     // Unsupported tag, ignore it.
627                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
628                     break;
629                 }
630                 if (TLVError != CHIP_NO_ERROR)
631                 {
632                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
633                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
634                 }
635             }
636             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
637             emberAfColorControlClusterStepSaturationCallback(stepMode, stepSize, transitionTime, optionsMask, optionsOverride);
638             break;
639         }
640         case ZCL_STOP_MOVE_STEP_COMMAND_ID: {
641             CHIP_ERROR TLVError = CHIP_NO_ERROR;
642             uint8_t optionsMask;
643             uint8_t optionsOverride;
644
645             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
646             {
647                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
648                 {
649                 case 0:
650                     TLVError = dataTlv.Get(optionsMask);
651                     break;
652                 case 1:
653                     TLVError = dataTlv.Get(optionsOverride);
654                     break;
655                 default:
656                     // Unsupported tag, ignore it.
657                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
658                     break;
659                 }
660                 if (TLVError != CHIP_NO_ERROR)
661                 {
662                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
663                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
664                 }
665             }
666             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
667             emberAfColorControlClusterStopMoveStepCallback(optionsMask, optionsOverride);
668             break;
669         }
670         default: {
671             // Unrecognized command ID, error status will apply.
672             // TODO: Encode response for command not found
673             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_COLOR_CONTROL_CLUSTER_ID);
674             break;
675         }
676         }
677     }
678 }
679
680 } // namespace ColorControl
681
682 namespace DoorLock {
683
684 void DispatchClientCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
685 {
686     {
687         switch (commandId)
688         {
689         case ZCL_LOCK_DOOR_RESPONSE_COMMAND_ID: {
690             CHIP_ERROR TLVError = CHIP_NO_ERROR;
691             uint8_t status;
692
693             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
694             {
695                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
696                 {
697                 case 0:
698                     TLVError = dataTlv.Get(status);
699                     break;
700                 default:
701                     // Unsupported tag, ignore it.
702                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
703                     break;
704                 }
705                 if (TLVError != CHIP_NO_ERROR)
706                 {
707                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
708                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
709                 }
710             }
711             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
712             emberAfDoorLockClusterLockDoorResponseCallback(status);
713             break;
714         }
715         case ZCL_UNLOCK_DOOR_RESPONSE_COMMAND_ID: {
716             CHIP_ERROR TLVError = CHIP_NO_ERROR;
717             uint8_t status;
718
719             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
720             {
721                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
722                 {
723                 case 0:
724                     TLVError = dataTlv.Get(status);
725                     break;
726                 default:
727                     // Unsupported tag, ignore it.
728                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
729                     break;
730                 }
731                 if (TLVError != CHIP_NO_ERROR)
732                 {
733                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
734                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
735                 }
736             }
737             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
738             emberAfDoorLockClusterUnlockDoorResponseCallback(status);
739             break;
740         }
741         default: {
742             // Unrecognized command ID, error status will apply.
743             // TODO: Encode response for command not found
744             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_DOOR_LOCK_CLUSTER_ID);
745             break;
746         }
747         }
748     }
749 }
750
751 } // namespace DoorLock
752
753 namespace DoorLock {
754
755 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
756 {
757     {
758         switch (commandId)
759         {
760         case ZCL_CLEAR_ALL_PINS_COMMAND_ID: {
761             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
762             emberAfDoorLockClusterClearAllPinsCallback();
763             break;
764         }
765         case ZCL_CLEAR_ALL_RFIDS_COMMAND_ID: {
766             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
767             emberAfDoorLockClusterClearAllRfidsCallback();
768             break;
769         }
770         case ZCL_CLEAR_HOLIDAY_SCHEDULE_COMMAND_ID: {
771             CHIP_ERROR TLVError = CHIP_NO_ERROR;
772             uint8_t scheduleId;
773
774             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
775             {
776                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
777                 {
778                 case 0:
779                     TLVError = dataTlv.Get(scheduleId);
780                     break;
781                 default:
782                     // Unsupported tag, ignore it.
783                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
784                     break;
785                 }
786                 if (TLVError != CHIP_NO_ERROR)
787                 {
788                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
789                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
790                 }
791             }
792             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
793             emberAfDoorLockClusterClearHolidayScheduleCallback(scheduleId);
794             break;
795         }
796         case ZCL_CLEAR_PIN_COMMAND_ID: {
797             CHIP_ERROR TLVError = CHIP_NO_ERROR;
798             uint16_t userId;
799
800             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
801             {
802                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
803                 {
804                 case 0:
805                     TLVError = dataTlv.Get(userId);
806                     break;
807                 default:
808                     // Unsupported tag, ignore it.
809                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
810                     break;
811                 }
812                 if (TLVError != CHIP_NO_ERROR)
813                 {
814                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
815                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
816                 }
817             }
818             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
819             emberAfDoorLockClusterClearPinCallback(userId);
820             break;
821         }
822         case ZCL_CLEAR_RFID_COMMAND_ID: {
823             CHIP_ERROR TLVError = CHIP_NO_ERROR;
824             uint16_t userId;
825
826             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
827             {
828                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
829                 {
830                 case 0:
831                     TLVError = dataTlv.Get(userId);
832                     break;
833                 default:
834                     // Unsupported tag, ignore it.
835                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
836                     break;
837                 }
838                 if (TLVError != CHIP_NO_ERROR)
839                 {
840                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
841                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
842                 }
843             }
844             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
845             emberAfDoorLockClusterClearRfidCallback(userId);
846             break;
847         }
848         case ZCL_CLEAR_WEEKDAY_SCHEDULE_COMMAND_ID: {
849             CHIP_ERROR TLVError = CHIP_NO_ERROR;
850             uint8_t scheduleId;
851             uint16_t userId;
852
853             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
854             {
855                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
856                 {
857                 case 0:
858                     TLVError = dataTlv.Get(scheduleId);
859                     break;
860                 case 1:
861                     TLVError = dataTlv.Get(userId);
862                     break;
863                 default:
864                     // Unsupported tag, ignore it.
865                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
866                     break;
867                 }
868                 if (TLVError != CHIP_NO_ERROR)
869                 {
870                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
871                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
872                 }
873             }
874             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
875             emberAfDoorLockClusterClearWeekdayScheduleCallback(scheduleId, userId);
876             break;
877         }
878         case ZCL_CLEAR_YEARDAY_SCHEDULE_COMMAND_ID: {
879             CHIP_ERROR TLVError = CHIP_NO_ERROR;
880             uint8_t scheduleId;
881             uint16_t userId;
882
883             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
884             {
885                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
886                 {
887                 case 0:
888                     TLVError = dataTlv.Get(scheduleId);
889                     break;
890                 case 1:
891                     TLVError = dataTlv.Get(userId);
892                     break;
893                 default:
894                     // Unsupported tag, ignore it.
895                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
896                     break;
897                 }
898                 if (TLVError != CHIP_NO_ERROR)
899                 {
900                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
901                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
902                 }
903             }
904             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
905             emberAfDoorLockClusterClearYeardayScheduleCallback(scheduleId, userId);
906             break;
907         }
908         case ZCL_GET_HOLIDAY_SCHEDULE_COMMAND_ID: {
909             CHIP_ERROR TLVError = CHIP_NO_ERROR;
910             uint8_t scheduleId;
911
912             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
913             {
914                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
915                 {
916                 case 0:
917                     TLVError = dataTlv.Get(scheduleId);
918                     break;
919                 default:
920                     // Unsupported tag, ignore it.
921                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
922                     break;
923                 }
924                 if (TLVError != CHIP_NO_ERROR)
925                 {
926                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
927                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
928                 }
929             }
930             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
931             emberAfDoorLockClusterGetHolidayScheduleCallback(scheduleId);
932             break;
933         }
934         case ZCL_GET_LOG_RECORD_COMMAND_ID: {
935             CHIP_ERROR TLVError = CHIP_NO_ERROR;
936             uint16_t logIndex;
937
938             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
939             {
940                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
941                 {
942                 case 0:
943                     TLVError = dataTlv.Get(logIndex);
944                     break;
945                 default:
946                     // Unsupported tag, ignore it.
947                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
948                     break;
949                 }
950                 if (TLVError != CHIP_NO_ERROR)
951                 {
952                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
953                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
954                 }
955             }
956             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
957             emberAfDoorLockClusterGetLogRecordCallback(logIndex);
958             break;
959         }
960         case ZCL_GET_PIN_COMMAND_ID: {
961             CHIP_ERROR TLVError = CHIP_NO_ERROR;
962             uint16_t userId;
963
964             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
965             {
966                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
967                 {
968                 case 0:
969                     TLVError = dataTlv.Get(userId);
970                     break;
971                 default:
972                     // Unsupported tag, ignore it.
973                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
974                     break;
975                 }
976                 if (TLVError != CHIP_NO_ERROR)
977                 {
978                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
979                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
980                 }
981             }
982             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
983             emberAfDoorLockClusterGetPinCallback(userId);
984             break;
985         }
986         case ZCL_GET_RFID_COMMAND_ID: {
987             CHIP_ERROR TLVError = CHIP_NO_ERROR;
988             uint16_t userId;
989
990             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
991             {
992                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
993                 {
994                 case 0:
995                     TLVError = dataTlv.Get(userId);
996                     break;
997                 default:
998                     // Unsupported tag, ignore it.
999                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1000                     break;
1001                 }
1002                 if (TLVError != CHIP_NO_ERROR)
1003                 {
1004                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1005                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1006                 }
1007             }
1008             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1009             emberAfDoorLockClusterGetRfidCallback(userId);
1010             break;
1011         }
1012         case ZCL_GET_USER_TYPE_COMMAND_ID: {
1013             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1014             uint16_t userId;
1015
1016             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1017             {
1018                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1019                 {
1020                 case 0:
1021                     TLVError = dataTlv.Get(userId);
1022                     break;
1023                 default:
1024                     // Unsupported tag, ignore it.
1025                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1026                     break;
1027                 }
1028                 if (TLVError != CHIP_NO_ERROR)
1029                 {
1030                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1031                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1032                 }
1033             }
1034             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1035             emberAfDoorLockClusterGetUserTypeCallback(userId);
1036             break;
1037         }
1038         case ZCL_GET_WEEKDAY_SCHEDULE_COMMAND_ID: {
1039             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1040             uint8_t scheduleId;
1041             uint16_t userId;
1042
1043             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1044             {
1045                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1046                 {
1047                 case 0:
1048                     TLVError = dataTlv.Get(scheduleId);
1049                     break;
1050                 case 1:
1051                     TLVError = dataTlv.Get(userId);
1052                     break;
1053                 default:
1054                     // Unsupported tag, ignore it.
1055                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1056                     break;
1057                 }
1058                 if (TLVError != CHIP_NO_ERROR)
1059                 {
1060                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1061                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1062                 }
1063             }
1064             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1065             emberAfDoorLockClusterGetWeekdayScheduleCallback(scheduleId, userId);
1066             break;
1067         }
1068         case ZCL_GET_YEARDAY_SCHEDULE_COMMAND_ID: {
1069             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1070             uint8_t scheduleId;
1071             uint16_t userId;
1072
1073             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1074             {
1075                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1076                 {
1077                 case 0:
1078                     TLVError = dataTlv.Get(scheduleId);
1079                     break;
1080                 case 1:
1081                     TLVError = dataTlv.Get(userId);
1082                     break;
1083                 default:
1084                     // Unsupported tag, ignore it.
1085                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1086                     break;
1087                 }
1088                 if (TLVError != CHIP_NO_ERROR)
1089                 {
1090                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1091                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1092                 }
1093             }
1094             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1095             emberAfDoorLockClusterGetYeardayScheduleCallback(scheduleId, userId);
1096             break;
1097         }
1098         case ZCL_LOCK_DOOR_COMMAND_ID: {
1099             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1100             const uint8_t * PIN;
1101
1102             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1103             {
1104                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1105                 {
1106                 case 0:
1107                     TLVError = dataTlv.GetDataPtr(PIN);
1108                     break;
1109                 default:
1110                     // Unsupported tag, ignore it.
1111                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1112                     break;
1113                 }
1114                 if (TLVError != CHIP_NO_ERROR)
1115                 {
1116                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1117                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1118                 }
1119             }
1120             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1121             emberAfDoorLockClusterLockDoorCallback(const_cast<uint8_t *>(PIN));
1122             break;
1123         }
1124         case ZCL_SET_HOLIDAY_SCHEDULE_COMMAND_ID: {
1125             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1126             uint8_t scheduleId;
1127             uint32_t localStartTime;
1128             uint32_t localEndTime;
1129             uint8_t operatingModeDuringHoliday;
1130
1131             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1132             {
1133                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1134                 {
1135                 case 0:
1136                     TLVError = dataTlv.Get(scheduleId);
1137                     break;
1138                 case 1:
1139                     TLVError = dataTlv.Get(localStartTime);
1140                     break;
1141                 case 2:
1142                     TLVError = dataTlv.Get(localEndTime);
1143                     break;
1144                 case 3:
1145                     TLVError = dataTlv.Get(operatingModeDuringHoliday);
1146                     break;
1147                 default:
1148                     // Unsupported tag, ignore it.
1149                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1150                     break;
1151                 }
1152                 if (TLVError != CHIP_NO_ERROR)
1153                 {
1154                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1155                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1156                 }
1157             }
1158             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1159             emberAfDoorLockClusterSetHolidayScheduleCallback(scheduleId, localStartTime, localEndTime, operatingModeDuringHoliday);
1160             break;
1161         }
1162         case ZCL_SET_PIN_COMMAND_ID: {
1163             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1164             uint16_t userId;
1165             uint8_t userStatus;
1166             uint8_t userType;
1167             const uint8_t * pin;
1168
1169             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1170             {
1171                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1172                 {
1173                 case 0:
1174                     TLVError = dataTlv.Get(userId);
1175                     break;
1176                 case 1:
1177                     TLVError = dataTlv.Get(userStatus);
1178                     break;
1179                 case 2:
1180                     TLVError = dataTlv.Get(userType);
1181                     break;
1182                 case 3:
1183                     TLVError = dataTlv.GetDataPtr(pin);
1184                     break;
1185                 default:
1186                     // Unsupported tag, ignore it.
1187                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1188                     break;
1189                 }
1190                 if (TLVError != CHIP_NO_ERROR)
1191                 {
1192                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1193                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1194                 }
1195             }
1196             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1197             emberAfDoorLockClusterSetPinCallback(userId, userStatus, userType, const_cast<uint8_t *>(pin));
1198             break;
1199         }
1200         case ZCL_SET_RFID_COMMAND_ID: {
1201             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1202             uint16_t userId;
1203             uint8_t userStatus;
1204             uint8_t userType;
1205             const uint8_t * id;
1206
1207             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1208             {
1209                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1210                 {
1211                 case 0:
1212                     TLVError = dataTlv.Get(userId);
1213                     break;
1214                 case 1:
1215                     TLVError = dataTlv.Get(userStatus);
1216                     break;
1217                 case 2:
1218                     TLVError = dataTlv.Get(userType);
1219                     break;
1220                 case 3:
1221                     TLVError = dataTlv.GetDataPtr(id);
1222                     break;
1223                 default:
1224                     // Unsupported tag, ignore it.
1225                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1226                     break;
1227                 }
1228                 if (TLVError != CHIP_NO_ERROR)
1229                 {
1230                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1231                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1232                 }
1233             }
1234             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1235             emberAfDoorLockClusterSetRfidCallback(userId, userStatus, userType, const_cast<uint8_t *>(id));
1236             break;
1237         }
1238         case ZCL_SET_USER_TYPE_COMMAND_ID: {
1239             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1240             uint16_t userId;
1241             uint8_t userType;
1242
1243             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1244             {
1245                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1246                 {
1247                 case 0:
1248                     TLVError = dataTlv.Get(userId);
1249                     break;
1250                 case 1:
1251                     TLVError = dataTlv.Get(userType);
1252                     break;
1253                 default:
1254                     // Unsupported tag, ignore it.
1255                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1256                     break;
1257                 }
1258                 if (TLVError != CHIP_NO_ERROR)
1259                 {
1260                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1261                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1262                 }
1263             }
1264             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1265             emberAfDoorLockClusterSetUserTypeCallback(userId, userType);
1266             break;
1267         }
1268         case ZCL_SET_WEEKDAY_SCHEDULE_COMMAND_ID: {
1269             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1270             uint8_t scheduleId;
1271             uint16_t userId;
1272             uint8_t daysMask;
1273             uint8_t startHour;
1274             uint8_t startMinute;
1275             uint8_t endHour;
1276             uint8_t endMinute;
1277
1278             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1279             {
1280                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1281                 {
1282                 case 0:
1283                     TLVError = dataTlv.Get(scheduleId);
1284                     break;
1285                 case 1:
1286                     TLVError = dataTlv.Get(userId);
1287                     break;
1288                 case 2:
1289                     TLVError = dataTlv.Get(daysMask);
1290                     break;
1291                 case 3:
1292                     TLVError = dataTlv.Get(startHour);
1293                     break;
1294                 case 4:
1295                     TLVError = dataTlv.Get(startMinute);
1296                     break;
1297                 case 5:
1298                     TLVError = dataTlv.Get(endHour);
1299                     break;
1300                 case 6:
1301                     TLVError = dataTlv.Get(endMinute);
1302                     break;
1303                 default:
1304                     // Unsupported tag, ignore it.
1305                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1306                     break;
1307                 }
1308                 if (TLVError != CHIP_NO_ERROR)
1309                 {
1310                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1311                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1312                 }
1313             }
1314             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1315             emberAfDoorLockClusterSetWeekdayScheduleCallback(scheduleId, userId, daysMask, startHour, startMinute, endHour,
1316                                                              endMinute);
1317             break;
1318         }
1319         case ZCL_SET_YEARDAY_SCHEDULE_COMMAND_ID: {
1320             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1321             uint8_t scheduleId;
1322             uint16_t userId;
1323             uint32_t localStartTime;
1324             uint32_t localEndTime;
1325
1326             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1327             {
1328                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1329                 {
1330                 case 0:
1331                     TLVError = dataTlv.Get(scheduleId);
1332                     break;
1333                 case 1:
1334                     TLVError = dataTlv.Get(userId);
1335                     break;
1336                 case 2:
1337                     TLVError = dataTlv.Get(localStartTime);
1338                     break;
1339                 case 3:
1340                     TLVError = dataTlv.Get(localEndTime);
1341                     break;
1342                 default:
1343                     // Unsupported tag, ignore it.
1344                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1345                     break;
1346                 }
1347                 if (TLVError != CHIP_NO_ERROR)
1348                 {
1349                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1350                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1351                 }
1352             }
1353             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1354             emberAfDoorLockClusterSetYeardayScheduleCallback(scheduleId, userId, localStartTime, localEndTime);
1355             break;
1356         }
1357         case ZCL_UNLOCK_DOOR_COMMAND_ID: {
1358             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1359             const uint8_t * PIN;
1360
1361             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1362             {
1363                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1364                 {
1365                 case 0:
1366                     TLVError = dataTlv.GetDataPtr(PIN);
1367                     break;
1368                 default:
1369                     // Unsupported tag, ignore it.
1370                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1371                     break;
1372                 }
1373                 if (TLVError != CHIP_NO_ERROR)
1374                 {
1375                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1376                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1377                 }
1378             }
1379             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1380             emberAfDoorLockClusterUnlockDoorCallback(const_cast<uint8_t *>(PIN));
1381             break;
1382         }
1383         case ZCL_UNLOCK_WITH_TIMEOUT_COMMAND_ID: {
1384             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1385             uint16_t timeoutInSeconds;
1386             const uint8_t * pin;
1387
1388             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1389             {
1390                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1391                 {
1392                 case 0:
1393                     TLVError = dataTlv.Get(timeoutInSeconds);
1394                     break;
1395                 case 1:
1396                     TLVError = dataTlv.GetDataPtr(pin);
1397                     break;
1398                 default:
1399                     // Unsupported tag, ignore it.
1400                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1401                     break;
1402                 }
1403                 if (TLVError != CHIP_NO_ERROR)
1404                 {
1405                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1406                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1407                 }
1408             }
1409             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1410             emberAfDoorLockClusterUnlockWithTimeoutCallback(timeoutInSeconds, const_cast<uint8_t *>(pin));
1411             break;
1412         }
1413         default: {
1414             // Unrecognized command ID, error status will apply.
1415             // TODO: Encode response for command not found
1416             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_DOOR_LOCK_CLUSTER_ID);
1417             break;
1418         }
1419         }
1420     }
1421 }
1422
1423 } // namespace DoorLock
1424
1425 namespace Groups {
1426
1427 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
1428 {
1429     {
1430         switch (commandId)
1431         {
1432         case ZCL_ADD_GROUP_COMMAND_ID: {
1433             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1434             uint16_t groupId;
1435             const uint8_t * groupName;
1436
1437             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1438             {
1439                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1440                 {
1441                 case 0:
1442                     TLVError = dataTlv.Get(groupId);
1443                     break;
1444                 case 1:
1445                     TLVError = dataTlv.GetDataPtr(groupName);
1446                     break;
1447                 default:
1448                     // Unsupported tag, ignore it.
1449                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1450                     break;
1451                 }
1452                 if (TLVError != CHIP_NO_ERROR)
1453                 {
1454                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1455                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1456                 }
1457             }
1458             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1459             emberAfGroupsClusterAddGroupCallback(groupId, const_cast<uint8_t *>(groupName));
1460             break;
1461         }
1462         case ZCL_ADD_GROUP_IF_IDENTIFYING_COMMAND_ID: {
1463             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1464             uint16_t groupId;
1465             const uint8_t * groupName;
1466
1467             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1468             {
1469                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1470                 {
1471                 case 0:
1472                     TLVError = dataTlv.Get(groupId);
1473                     break;
1474                 case 1:
1475                     TLVError = dataTlv.GetDataPtr(groupName);
1476                     break;
1477                 default:
1478                     // Unsupported tag, ignore it.
1479                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1480                     break;
1481                 }
1482                 if (TLVError != CHIP_NO_ERROR)
1483                 {
1484                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1485                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1486                 }
1487             }
1488             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1489             emberAfGroupsClusterAddGroupIfIdentifyingCallback(groupId, const_cast<uint8_t *>(groupName));
1490             break;
1491         }
1492         case ZCL_GET_GROUP_MEMBERSHIP_COMMAND_ID: {
1493             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1494             uint8_t groupCount;
1495             /* TYPE WARNING: array array defaults to */ uint8_t * groupList;
1496
1497             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1498             {
1499                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1500                 {
1501                 case 0:
1502                     TLVError = dataTlv.Get(groupCount);
1503                     break;
1504                 case 1:
1505                     // Just for compatibility, we will add array type support in IM later.
1506                     TLVError = dataTlv.GetDataPtr(const_cast<const uint8_t *&>(groupList));
1507                     break;
1508                 default:
1509                     // Unsupported tag, ignore it.
1510                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1511                     break;
1512                 }
1513                 if (TLVError != CHIP_NO_ERROR)
1514                 {
1515                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1516                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1517                 }
1518             }
1519             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1520             emberAfGroupsClusterGetGroupMembershipCallback(groupCount, groupList);
1521             break;
1522         }
1523         case ZCL_REMOVE_ALL_GROUPS_COMMAND_ID: {
1524             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1525             emberAfGroupsClusterRemoveAllGroupsCallback();
1526             break;
1527         }
1528         case ZCL_REMOVE_GROUP_COMMAND_ID: {
1529             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1530             uint16_t groupId;
1531
1532             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1533             {
1534                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1535                 {
1536                 case 0:
1537                     TLVError = dataTlv.Get(groupId);
1538                     break;
1539                 default:
1540                     // Unsupported tag, ignore it.
1541                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1542                     break;
1543                 }
1544                 if (TLVError != CHIP_NO_ERROR)
1545                 {
1546                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1547                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1548                 }
1549             }
1550             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1551             emberAfGroupsClusterRemoveGroupCallback(groupId);
1552             break;
1553         }
1554         case ZCL_VIEW_GROUP_COMMAND_ID: {
1555             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1556             uint16_t groupId;
1557
1558             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1559             {
1560                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1561                 {
1562                 case 0:
1563                     TLVError = dataTlv.Get(groupId);
1564                     break;
1565                 default:
1566                     // Unsupported tag, ignore it.
1567                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1568                     break;
1569                 }
1570                 if (TLVError != CHIP_NO_ERROR)
1571                 {
1572                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1573                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1574                 }
1575             }
1576             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1577             emberAfGroupsClusterViewGroupCallback(groupId);
1578             break;
1579         }
1580         default: {
1581             // Unrecognized command ID, error status will apply.
1582             // TODO: Encode response for command not found
1583             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_GROUPS_CLUSTER_ID);
1584             break;
1585         }
1586         }
1587     }
1588 }
1589
1590 } // namespace Groups
1591
1592 namespace IasZone {
1593
1594 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
1595 {
1596     {
1597         switch (commandId)
1598         {
1599         case ZCL_ZONE_ENROLL_RESPONSE_COMMAND_ID: {
1600             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1601             uint8_t enrollResponseCode;
1602             uint8_t zoneId;
1603
1604             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1605             {
1606                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1607                 {
1608                 case 0:
1609                     TLVError = dataTlv.Get(enrollResponseCode);
1610                     break;
1611                 case 1:
1612                     TLVError = dataTlv.Get(zoneId);
1613                     break;
1614                 default:
1615                     // Unsupported tag, ignore it.
1616                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1617                     break;
1618                 }
1619                 if (TLVError != CHIP_NO_ERROR)
1620                 {
1621                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1622                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1623                 }
1624             }
1625             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1626             emberAfIasZoneClusterZoneEnrollResponseCallback(enrollResponseCode, zoneId);
1627             break;
1628         }
1629         default: {
1630             // Unrecognized command ID, error status will apply.
1631             // TODO: Encode response for command not found
1632             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_IAS_ZONE_CLUSTER_ID);
1633             break;
1634         }
1635         }
1636     }
1637 }
1638
1639 } // namespace IasZone
1640
1641 namespace Identify {
1642
1643 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
1644 {
1645     {
1646         switch (commandId)
1647         {
1648         case ZCL_IDENTIFY_COMMAND_ID: {
1649             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1650             uint16_t identifyTime;
1651
1652             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1653             {
1654                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1655                 {
1656                 case 0:
1657                     TLVError = dataTlv.Get(identifyTime);
1658                     break;
1659                 default:
1660                     // Unsupported tag, ignore it.
1661                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1662                     break;
1663                 }
1664                 if (TLVError != CHIP_NO_ERROR)
1665                 {
1666                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1667                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1668                 }
1669             }
1670             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1671             emberAfIdentifyClusterIdentifyCallback(identifyTime);
1672             break;
1673         }
1674         case ZCL_IDENTIFY_QUERY_COMMAND_ID: {
1675             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1676             emberAfIdentifyClusterIdentifyQueryCallback();
1677             break;
1678         }
1679         default: {
1680             // Unrecognized command ID, error status will apply.
1681             // TODO: Encode response for command not found
1682             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_IDENTIFY_CLUSTER_ID);
1683             break;
1684         }
1685         }
1686     }
1687 }
1688
1689 } // namespace Identify
1690
1691 namespace LevelControl {
1692
1693 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
1694 {
1695     {
1696         switch (commandId)
1697         {
1698         case ZCL_MOVE_COMMAND_ID: {
1699             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1700             uint8_t moveMode;
1701             uint8_t rate;
1702             uint8_t optionMask;
1703             uint8_t optionOverride;
1704
1705             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1706             {
1707                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1708                 {
1709                 case 0:
1710                     TLVError = dataTlv.Get(moveMode);
1711                     break;
1712                 case 1:
1713                     TLVError = dataTlv.Get(rate);
1714                     break;
1715                 case 2:
1716                     TLVError = dataTlv.Get(optionMask);
1717                     break;
1718                 case 3:
1719                     TLVError = dataTlv.Get(optionOverride);
1720                     break;
1721                 default:
1722                     // Unsupported tag, ignore it.
1723                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1724                     break;
1725                 }
1726                 if (TLVError != CHIP_NO_ERROR)
1727                 {
1728                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1729                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1730                 }
1731             }
1732             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1733             emberAfLevelControlClusterMoveCallback(moveMode, rate, optionMask, optionOverride);
1734             break;
1735         }
1736         case ZCL_MOVE_TO_LEVEL_COMMAND_ID: {
1737             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1738             uint8_t level;
1739             uint16_t transitionTime;
1740             uint8_t optionMask;
1741             uint8_t optionOverride;
1742
1743             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1744             {
1745                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1746                 {
1747                 case 0:
1748                     TLVError = dataTlv.Get(level);
1749                     break;
1750                 case 1:
1751                     TLVError = dataTlv.Get(transitionTime);
1752                     break;
1753                 case 2:
1754                     TLVError = dataTlv.Get(optionMask);
1755                     break;
1756                 case 3:
1757                     TLVError = dataTlv.Get(optionOverride);
1758                     break;
1759                 default:
1760                     // Unsupported tag, ignore it.
1761                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1762                     break;
1763                 }
1764                 if (TLVError != CHIP_NO_ERROR)
1765                 {
1766                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1767                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1768                 }
1769             }
1770             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1771             emberAfLevelControlClusterMoveToLevelCallback(level, transitionTime, optionMask, optionOverride);
1772             break;
1773         }
1774         case ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID: {
1775             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1776             uint8_t level;
1777             uint16_t transitionTime;
1778
1779             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1780             {
1781                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1782                 {
1783                 case 0:
1784                     TLVError = dataTlv.Get(level);
1785                     break;
1786                 case 1:
1787                     TLVError = dataTlv.Get(transitionTime);
1788                     break;
1789                 default:
1790                     // Unsupported tag, ignore it.
1791                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1792                     break;
1793                 }
1794                 if (TLVError != CHIP_NO_ERROR)
1795                 {
1796                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1797                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1798                 }
1799             }
1800             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1801             emberAfLevelControlClusterMoveToLevelWithOnOffCallback(level, transitionTime);
1802             break;
1803         }
1804         case ZCL_MOVE_WITH_ON_OFF_COMMAND_ID: {
1805             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1806             uint8_t moveMode;
1807             uint8_t rate;
1808
1809             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1810             {
1811                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1812                 {
1813                 case 0:
1814                     TLVError = dataTlv.Get(moveMode);
1815                     break;
1816                 case 1:
1817                     TLVError = dataTlv.Get(rate);
1818                     break;
1819                 default:
1820                     // Unsupported tag, ignore it.
1821                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1822                     break;
1823                 }
1824                 if (TLVError != CHIP_NO_ERROR)
1825                 {
1826                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1827                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1828                 }
1829             }
1830             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1831             emberAfLevelControlClusterMoveWithOnOffCallback(moveMode, rate);
1832             break;
1833         }
1834         case ZCL_STEP_COMMAND_ID: {
1835             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1836             uint8_t stepMode;
1837             uint8_t stepSize;
1838             uint16_t transitionTime;
1839             uint8_t optionMask;
1840             uint8_t optionOverride;
1841
1842             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1843             {
1844                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1845                 {
1846                 case 0:
1847                     TLVError = dataTlv.Get(stepMode);
1848                     break;
1849                 case 1:
1850                     TLVError = dataTlv.Get(stepSize);
1851                     break;
1852                 case 2:
1853                     TLVError = dataTlv.Get(transitionTime);
1854                     break;
1855                 case 3:
1856                     TLVError = dataTlv.Get(optionMask);
1857                     break;
1858                 case 4:
1859                     TLVError = dataTlv.Get(optionOverride);
1860                     break;
1861                 default:
1862                     // Unsupported tag, ignore it.
1863                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1864                     break;
1865                 }
1866                 if (TLVError != CHIP_NO_ERROR)
1867                 {
1868                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1869                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1870                 }
1871             }
1872             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1873             emberAfLevelControlClusterStepCallback(stepMode, stepSize, transitionTime, optionMask, optionOverride);
1874             break;
1875         }
1876         case ZCL_STEP_WITH_ON_OFF_COMMAND_ID: {
1877             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1878             uint8_t stepMode;
1879             uint8_t stepSize;
1880             uint16_t transitionTime;
1881
1882             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1883             {
1884                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1885                 {
1886                 case 0:
1887                     TLVError = dataTlv.Get(stepMode);
1888                     break;
1889                 case 1:
1890                     TLVError = dataTlv.Get(stepSize);
1891                     break;
1892                 case 2:
1893                     TLVError = dataTlv.Get(transitionTime);
1894                     break;
1895                 default:
1896                     // Unsupported tag, ignore it.
1897                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1898                     break;
1899                 }
1900                 if (TLVError != CHIP_NO_ERROR)
1901                 {
1902                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1903                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1904                 }
1905             }
1906             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1907             emberAfLevelControlClusterStepWithOnOffCallback(stepMode, stepSize, transitionTime);
1908             break;
1909         }
1910         case ZCL_STOP_COMMAND_ID: {
1911             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1912             uint8_t optionMask;
1913             uint8_t optionOverride;
1914
1915             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1916             {
1917                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1918                 {
1919                 case 0:
1920                     TLVError = dataTlv.Get(optionMask);
1921                     break;
1922                 case 1:
1923                     TLVError = dataTlv.Get(optionOverride);
1924                     break;
1925                 default:
1926                     // Unsupported tag, ignore it.
1927                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
1928                     break;
1929                 }
1930                 if (TLVError != CHIP_NO_ERROR)
1931                 {
1932                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
1933                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
1934                 }
1935             }
1936             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1937             emberAfLevelControlClusterStopCallback(optionMask, optionOverride);
1938             break;
1939         }
1940         case ZCL_STOP_WITH_ON_OFF_COMMAND_ID: {
1941             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1942             emberAfLevelControlClusterStopWithOnOffCallback();
1943             break;
1944         }
1945         default: {
1946             // Unrecognized command ID, error status will apply.
1947             // TODO: Encode response for command not found
1948             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_LEVEL_CONTROL_CLUSTER_ID);
1949             break;
1950         }
1951         }
1952     }
1953 }
1954
1955 } // namespace LevelControl
1956
1957 namespace LowPower {
1958
1959 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
1960 {
1961     {
1962         switch (commandId)
1963         {
1964         case ZCL_SLEEP_COMMAND_ID: {
1965             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
1966             emberAfLowPowerClusterSleepCallback();
1967             break;
1968         }
1969         default: {
1970             // Unrecognized command ID, error status will apply.
1971             // TODO: Encode response for command not found
1972             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_LOW_POWER_CLUSTER_ID);
1973             break;
1974         }
1975         }
1976     }
1977 }
1978
1979 } // namespace LowPower
1980
1981 namespace NetworkCommissioning {
1982
1983 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
1984 {
1985     {
1986         switch (commandId)
1987         {
1988         case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
1989             CHIP_ERROR TLVError = CHIP_NO_ERROR;
1990             chip::ByteSpan operationalDataset;
1991             uint64_t breadcrumb;
1992             uint32_t timeoutMs;
1993
1994             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
1995             {
1996                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
1997                 {
1998                 case 0: {
1999                     const uint8_t * data = nullptr;
2000                     TLVError             = dataTlv.GetDataPtr(data);
2001                     operationalDataset   = chip::ByteSpan(data, dataTlv.GetLength());
2002                 }
2003                 break;
2004                 case 1:
2005                     TLVError = dataTlv.Get(breadcrumb);
2006                     break;
2007                 case 2:
2008                     TLVError = dataTlv.Get(timeoutMs);
2009                     break;
2010                 default:
2011                     // Unsupported tag, ignore it.
2012                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2013                     break;
2014                 }
2015                 if (TLVError != CHIP_NO_ERROR)
2016                 {
2017                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2018                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2019                 }
2020             }
2021             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2022             emberAfNetworkCommissioningClusterAddThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
2023             break;
2024         }
2025         case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
2026             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2027             chip::ByteSpan ssid;
2028             chip::ByteSpan credentials;
2029             uint64_t breadcrumb;
2030             uint32_t timeoutMs;
2031
2032             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2033             {
2034                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2035                 {
2036                 case 0: {
2037                     const uint8_t * data = nullptr;
2038                     TLVError             = dataTlv.GetDataPtr(data);
2039                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
2040                 }
2041                 break;
2042                 case 1: {
2043                     const uint8_t * data = nullptr;
2044                     TLVError             = dataTlv.GetDataPtr(data);
2045                     credentials          = chip::ByteSpan(data, dataTlv.GetLength());
2046                 }
2047                 break;
2048                 case 2:
2049                     TLVError = dataTlv.Get(breadcrumb);
2050                     break;
2051                 case 3:
2052                     TLVError = dataTlv.Get(timeoutMs);
2053                     break;
2054                 default:
2055                     // Unsupported tag, ignore it.
2056                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2057                     break;
2058                 }
2059                 if (TLVError != CHIP_NO_ERROR)
2060                 {
2061                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2062                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2063                 }
2064             }
2065             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2066             emberAfNetworkCommissioningClusterAddWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
2067             break;
2068         }
2069         case ZCL_DISABLE_NETWORK_COMMAND_ID: {
2070             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2071             chip::ByteSpan networkID;
2072             uint64_t breadcrumb;
2073             uint32_t timeoutMs;
2074
2075             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2076             {
2077                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2078                 {
2079                 case 0: {
2080                     const uint8_t * data = nullptr;
2081                     TLVError             = dataTlv.GetDataPtr(data);
2082                     networkID            = chip::ByteSpan(data, dataTlv.GetLength());
2083                 }
2084                 break;
2085                 case 1:
2086                     TLVError = dataTlv.Get(breadcrumb);
2087                     break;
2088                 case 2:
2089                     TLVError = dataTlv.Get(timeoutMs);
2090                     break;
2091                 default:
2092                     // Unsupported tag, ignore it.
2093                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2094                     break;
2095                 }
2096                 if (TLVError != CHIP_NO_ERROR)
2097                 {
2098                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2099                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2100                 }
2101             }
2102             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2103             emberAfNetworkCommissioningClusterDisableNetworkCallback(networkID, breadcrumb, timeoutMs);
2104             break;
2105         }
2106         case ZCL_ENABLE_NETWORK_COMMAND_ID: {
2107             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2108             chip::ByteSpan networkID;
2109             uint64_t breadcrumb;
2110             uint32_t timeoutMs;
2111
2112             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2113             {
2114                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2115                 {
2116                 case 0: {
2117                     const uint8_t * data = nullptr;
2118                     TLVError             = dataTlv.GetDataPtr(data);
2119                     networkID            = chip::ByteSpan(data, dataTlv.GetLength());
2120                 }
2121                 break;
2122                 case 1:
2123                     TLVError = dataTlv.Get(breadcrumb);
2124                     break;
2125                 case 2:
2126                     TLVError = dataTlv.Get(timeoutMs);
2127                     break;
2128                 default:
2129                     // Unsupported tag, ignore it.
2130                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2131                     break;
2132                 }
2133                 if (TLVError != CHIP_NO_ERROR)
2134                 {
2135                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2136                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2137                 }
2138             }
2139             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2140             emberAfNetworkCommissioningClusterEnableNetworkCallback(networkID, breadcrumb, timeoutMs);
2141             break;
2142         }
2143         case ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID: {
2144             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2145             uint32_t timeoutMs;
2146
2147             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2148             {
2149                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2150                 {
2151                 case 0:
2152                     TLVError = dataTlv.Get(timeoutMs);
2153                     break;
2154                 default:
2155                     // Unsupported tag, ignore it.
2156                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2157                     break;
2158                 }
2159                 if (TLVError != CHIP_NO_ERROR)
2160                 {
2161                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2162                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2163                 }
2164             }
2165             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2166             emberAfNetworkCommissioningClusterGetLastNetworkCommissioningResultCallback(timeoutMs);
2167             break;
2168         }
2169         case ZCL_REMOVE_NETWORK_COMMAND_ID: {
2170             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2171             chip::ByteSpan NetworkID;
2172             uint64_t Breadcrumb;
2173             uint32_t TimeoutMs;
2174
2175             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2176             {
2177                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2178                 {
2179                 case 0: {
2180                     const uint8_t * data = nullptr;
2181                     TLVError             = dataTlv.GetDataPtr(data);
2182                     NetworkID            = chip::ByteSpan(data, dataTlv.GetLength());
2183                 }
2184                 break;
2185                 case 1:
2186                     TLVError = dataTlv.Get(Breadcrumb);
2187                     break;
2188                 case 2:
2189                     TLVError = dataTlv.Get(TimeoutMs);
2190                     break;
2191                 default:
2192                     // Unsupported tag, ignore it.
2193                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2194                     break;
2195                 }
2196                 if (TLVError != CHIP_NO_ERROR)
2197                 {
2198                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2199                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2200                 }
2201             }
2202             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2203             emberAfNetworkCommissioningClusterRemoveNetworkCallback(NetworkID, Breadcrumb, TimeoutMs);
2204             break;
2205         }
2206         case ZCL_SCAN_NETWORKS_COMMAND_ID: {
2207             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2208             chip::ByteSpan ssid;
2209             uint64_t breadcrumb;
2210             uint32_t timeoutMs;
2211
2212             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2213             {
2214                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2215                 {
2216                 case 0: {
2217                     const uint8_t * data = nullptr;
2218                     TLVError             = dataTlv.GetDataPtr(data);
2219                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
2220                 }
2221                 break;
2222                 case 1:
2223                     TLVError = dataTlv.Get(breadcrumb);
2224                     break;
2225                 case 2:
2226                     TLVError = dataTlv.Get(timeoutMs);
2227                     break;
2228                 default:
2229                     // Unsupported tag, ignore it.
2230                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2231                     break;
2232                 }
2233                 if (TLVError != CHIP_NO_ERROR)
2234                 {
2235                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2236                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2237                 }
2238             }
2239             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2240             emberAfNetworkCommissioningClusterScanNetworksCallback(ssid, breadcrumb, timeoutMs);
2241             break;
2242         }
2243         case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
2244             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2245             chip::ByteSpan operationalDataset;
2246             uint64_t breadcrumb;
2247             uint32_t timeoutMs;
2248
2249             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2250             {
2251                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2252                 {
2253                 case 0: {
2254                     const uint8_t * data = nullptr;
2255                     TLVError             = dataTlv.GetDataPtr(data);
2256                     operationalDataset   = chip::ByteSpan(data, dataTlv.GetLength());
2257                 }
2258                 break;
2259                 case 1:
2260                     TLVError = dataTlv.Get(breadcrumb);
2261                     break;
2262                 case 2:
2263                     TLVError = dataTlv.Get(timeoutMs);
2264                     break;
2265                 default:
2266                     // Unsupported tag, ignore it.
2267                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2268                     break;
2269                 }
2270                 if (TLVError != CHIP_NO_ERROR)
2271                 {
2272                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2273                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2274                 }
2275             }
2276             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2277             emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
2278             break;
2279         }
2280         case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
2281             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2282             chip::ByteSpan ssid;
2283             chip::ByteSpan credentials;
2284             uint64_t breadcrumb;
2285             uint32_t timeoutMs;
2286
2287             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2288             {
2289                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2290                 {
2291                 case 0: {
2292                     const uint8_t * data = nullptr;
2293                     TLVError             = dataTlv.GetDataPtr(data);
2294                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
2295                 }
2296                 break;
2297                 case 1: {
2298                     const uint8_t * data = nullptr;
2299                     TLVError             = dataTlv.GetDataPtr(data);
2300                     credentials          = chip::ByteSpan(data, dataTlv.GetLength());
2301                 }
2302                 break;
2303                 case 2:
2304                     TLVError = dataTlv.Get(breadcrumb);
2305                     break;
2306                 case 3:
2307                     TLVError = dataTlv.Get(timeoutMs);
2308                     break;
2309                 default:
2310                     // Unsupported tag, ignore it.
2311                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2312                     break;
2313                 }
2314                 if (TLVError != CHIP_NO_ERROR)
2315                 {
2316                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2317                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2318                 }
2319             }
2320             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2321             emberAfNetworkCommissioningClusterUpdateWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
2322             break;
2323         }
2324         default: {
2325             // Unrecognized command ID, error status will apply.
2326             // TODO: Encode response for command not found
2327             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_NETWORK_COMMISSIONING_CLUSTER_ID);
2328             break;
2329         }
2330         }
2331     }
2332 }
2333
2334 } // namespace NetworkCommissioning
2335
2336 namespace OnOff {
2337
2338 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
2339 {
2340     {
2341         switch (commandId)
2342         {
2343         case ZCL_OFF_COMMAND_ID: {
2344             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2345             emberAfOnOffClusterOffCallback();
2346             break;
2347         }
2348         case ZCL_ON_COMMAND_ID: {
2349             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2350             emberAfOnOffClusterOnCallback();
2351             break;
2352         }
2353         case ZCL_TOGGLE_COMMAND_ID: {
2354             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2355             emberAfOnOffClusterToggleCallback();
2356             break;
2357         }
2358         default: {
2359             // Unrecognized command ID, error status will apply.
2360             // TODO: Encode response for command not found
2361             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_ON_OFF_CLUSTER_ID);
2362             break;
2363         }
2364         }
2365     }
2366 }
2367
2368 } // namespace OnOff
2369
2370 namespace Scenes {
2371
2372 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
2373 {
2374     {
2375         switch (commandId)
2376         {
2377         case ZCL_ADD_SCENE_COMMAND_ID: {
2378             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2379             uint16_t groupId;
2380             uint8_t sceneId;
2381             uint16_t transitionTime;
2382             const uint8_t * sceneName;
2383             /* TYPE WARNING: array array defaults to */ uint8_t * extensionFieldSets;
2384
2385             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2386             {
2387                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2388                 {
2389                 case 0:
2390                     TLVError = dataTlv.Get(groupId);
2391                     break;
2392                 case 1:
2393                     TLVError = dataTlv.Get(sceneId);
2394                     break;
2395                 case 2:
2396                     TLVError = dataTlv.Get(transitionTime);
2397                     break;
2398                 case 3:
2399                     TLVError = dataTlv.GetDataPtr(sceneName);
2400                     break;
2401                 case 4:
2402                     // Just for compatibility, we will add array type support in IM later.
2403                     TLVError = dataTlv.GetDataPtr(const_cast<const uint8_t *&>(extensionFieldSets));
2404                     break;
2405                 default:
2406                     // Unsupported tag, ignore it.
2407                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2408                     break;
2409                 }
2410                 if (TLVError != CHIP_NO_ERROR)
2411                 {
2412                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2413                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2414                 }
2415             }
2416             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2417             emberAfScenesClusterAddSceneCallback(groupId, sceneId, transitionTime, const_cast<uint8_t *>(sceneName),
2418                                                  extensionFieldSets);
2419             break;
2420         }
2421         case ZCL_GET_SCENE_MEMBERSHIP_COMMAND_ID: {
2422             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2423             uint16_t groupId;
2424
2425             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2426             {
2427                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2428                 {
2429                 case 0:
2430                     TLVError = dataTlv.Get(groupId);
2431                     break;
2432                 default:
2433                     // Unsupported tag, ignore it.
2434                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2435                     break;
2436                 }
2437                 if (TLVError != CHIP_NO_ERROR)
2438                 {
2439                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2440                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2441                 }
2442             }
2443             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2444             emberAfScenesClusterGetSceneMembershipCallback(groupId);
2445             break;
2446         }
2447         case ZCL_RECALL_SCENE_COMMAND_ID: {
2448             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2449             uint16_t groupId;
2450             uint8_t sceneId;
2451             uint16_t transitionTime;
2452
2453             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2454             {
2455                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2456                 {
2457                 case 0:
2458                     TLVError = dataTlv.Get(groupId);
2459                     break;
2460                 case 1:
2461                     TLVError = dataTlv.Get(sceneId);
2462                     break;
2463                 case 2:
2464                     TLVError = dataTlv.Get(transitionTime);
2465                     break;
2466                 default:
2467                     // Unsupported tag, ignore it.
2468                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2469                     break;
2470                 }
2471                 if (TLVError != CHIP_NO_ERROR)
2472                 {
2473                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2474                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2475                 }
2476             }
2477             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2478             emberAfScenesClusterRecallSceneCallback(groupId, sceneId, transitionTime);
2479             break;
2480         }
2481         case ZCL_REMOVE_ALL_SCENES_COMMAND_ID: {
2482             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2483             uint16_t groupId;
2484
2485             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2486             {
2487                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2488                 {
2489                 case 0:
2490                     TLVError = dataTlv.Get(groupId);
2491                     break;
2492                 default:
2493                     // Unsupported tag, ignore it.
2494                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2495                     break;
2496                 }
2497                 if (TLVError != CHIP_NO_ERROR)
2498                 {
2499                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2500                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2501                 }
2502             }
2503             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2504             emberAfScenesClusterRemoveAllScenesCallback(groupId);
2505             break;
2506         }
2507         case ZCL_REMOVE_SCENE_COMMAND_ID: {
2508             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2509             uint16_t groupId;
2510             uint8_t sceneId;
2511
2512             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2513             {
2514                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2515                 {
2516                 case 0:
2517                     TLVError = dataTlv.Get(groupId);
2518                     break;
2519                 case 1:
2520                     TLVError = dataTlv.Get(sceneId);
2521                     break;
2522                 default:
2523                     // Unsupported tag, ignore it.
2524                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2525                     break;
2526                 }
2527                 if (TLVError != CHIP_NO_ERROR)
2528                 {
2529                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2530                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2531                 }
2532             }
2533             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2534             emberAfScenesClusterRemoveSceneCallback(groupId, sceneId);
2535             break;
2536         }
2537         case ZCL_STORE_SCENE_COMMAND_ID: {
2538             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2539             uint16_t groupId;
2540             uint8_t sceneId;
2541
2542             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2543             {
2544                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2545                 {
2546                 case 0:
2547                     TLVError = dataTlv.Get(groupId);
2548                     break;
2549                 case 1:
2550                     TLVError = dataTlv.Get(sceneId);
2551                     break;
2552                 default:
2553                     // Unsupported tag, ignore it.
2554                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2555                     break;
2556                 }
2557                 if (TLVError != CHIP_NO_ERROR)
2558                 {
2559                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2560                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2561                 }
2562             }
2563             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2564             emberAfScenesClusterStoreSceneCallback(groupId, sceneId);
2565             break;
2566         }
2567         case ZCL_VIEW_SCENE_COMMAND_ID: {
2568             CHIP_ERROR TLVError = CHIP_NO_ERROR;
2569             uint16_t groupId;
2570             uint8_t sceneId;
2571
2572             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
2573             {
2574                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
2575                 {
2576                 case 0:
2577                     TLVError = dataTlv.Get(groupId);
2578                     break;
2579                 case 1:
2580                     TLVError = dataTlv.Get(sceneId);
2581                     break;
2582                 default:
2583                     // Unsupported tag, ignore it.
2584                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
2585                     break;
2586                 }
2587                 if (TLVError != CHIP_NO_ERROR)
2588                 {
2589                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
2590                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
2591                 }
2592             }
2593             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
2594             emberAfScenesClusterViewSceneCallback(groupId, sceneId);
2595             break;
2596         }
2597         default: {
2598             // Unrecognized command ID, error status will apply.
2599             // TODO: Encode response for command not found
2600             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_SCENES_CLUSTER_ID);
2601             break;
2602         }
2603         }
2604     }
2605 }
2606
2607 } // namespace Scenes
2608
2609 } // namespace clusters
2610
2611 void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aCommandId, chip::EndpointId aEndPointId,
2612                                   chip::TLV::TLVReader & aReader, Command * apCommandObj)
2613 {
2614     ChipLogDetail(Zcl, "Received Cluster Command: Cluster=%" PRIx16 " Command=%" PRIx8 " Endpoint=%" PRIx8, aClusterId, aCommandId,
2615                   aEndPointId);
2616     Compatibility::SetupEmberAfObjects(apCommandObj, aClusterId, aCommandId, aEndPointId);
2617     switch (aClusterId)
2618     {
2619     case ZCL_BARRIER_CONTROL_CLUSTER_ID:
2620         clusters::BarrierControl::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2621         break;
2622     case ZCL_COLOR_CONTROL_CLUSTER_ID:
2623         clusters::ColorControl::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2624         break;
2625     case ZCL_DOOR_LOCK_CLUSTER_ID:
2626         clusters::DoorLock::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2627         break;
2628     case ZCL_GROUPS_CLUSTER_ID:
2629         clusters::Groups::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2630         break;
2631     case ZCL_IAS_ZONE_CLUSTER_ID:
2632         clusters::IasZone::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2633         break;
2634     case ZCL_IDENTIFY_CLUSTER_ID:
2635         clusters::Identify::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2636         break;
2637     case ZCL_LEVEL_CONTROL_CLUSTER_ID:
2638         clusters::LevelControl::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2639         break;
2640     case ZCL_LOW_POWER_CLUSTER_ID:
2641         clusters::LowPower::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2642         break;
2643     case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
2644         clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2645         break;
2646     case ZCL_ON_OFF_CLUSTER_ID:
2647         clusters::OnOff::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2648         break;
2649     case ZCL_SCENES_CLUSTER_ID:
2650         clusters::Scenes::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
2651         break;
2652     default:
2653         // Unrecognized cluster ID, error status will apply.
2654         // TODO: Encode response for Cluster not found
2655         ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
2656         break;
2657     }
2658     Compatibility::ResetEmberAfObjects();
2659 }
2660
2661 } // namespace app
2662 } // namespace chip