Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / lighting-app / lighting-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 LevelControl {
43
44 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
45 {
46     {
47         switch (commandId)
48         {
49         case ZCL_MOVE_COMMAND_ID: {
50             CHIP_ERROR TLVError = CHIP_NO_ERROR;
51             uint8_t moveMode;
52             uint8_t rate;
53             uint8_t optionMask;
54             uint8_t optionOverride;
55
56             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
57             {
58                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
59                 {
60                 case 0:
61                     TLVError = dataTlv.Get(moveMode);
62                     break;
63                 case 1:
64                     TLVError = dataTlv.Get(rate);
65                     break;
66                 case 2:
67                     TLVError = dataTlv.Get(optionMask);
68                     break;
69                 case 3:
70                     TLVError = dataTlv.Get(optionOverride);
71                     break;
72                 default:
73                     // Unsupported tag, ignore it.
74                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
75                     break;
76                 }
77                 if (TLVError != CHIP_NO_ERROR)
78                 {
79                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
80                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
81                 }
82             }
83             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
84             emberAfLevelControlClusterMoveCallback(moveMode, rate, optionMask, optionOverride);
85             break;
86         }
87         case ZCL_MOVE_TO_LEVEL_COMMAND_ID: {
88             CHIP_ERROR TLVError = CHIP_NO_ERROR;
89             uint8_t level;
90             uint16_t transitionTime;
91             uint8_t optionMask;
92             uint8_t optionOverride;
93
94             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
95             {
96                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
97                 {
98                 case 0:
99                     TLVError = dataTlv.Get(level);
100                     break;
101                 case 1:
102                     TLVError = dataTlv.Get(transitionTime);
103                     break;
104                 case 2:
105                     TLVError = dataTlv.Get(optionMask);
106                     break;
107                 case 3:
108                     TLVError = dataTlv.Get(optionOverride);
109                     break;
110                 default:
111                     // Unsupported tag, ignore it.
112                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
113                     break;
114                 }
115                 if (TLVError != CHIP_NO_ERROR)
116                 {
117                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
118                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
119                 }
120             }
121             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
122             emberAfLevelControlClusterMoveToLevelCallback(level, transitionTime, optionMask, optionOverride);
123             break;
124         }
125         case ZCL_MOVE_TO_LEVEL_WITH_ON_OFF_COMMAND_ID: {
126             CHIP_ERROR TLVError = CHIP_NO_ERROR;
127             uint8_t level;
128             uint16_t transitionTime;
129
130             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
131             {
132                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
133                 {
134                 case 0:
135                     TLVError = dataTlv.Get(level);
136                     break;
137                 case 1:
138                     TLVError = dataTlv.Get(transitionTime);
139                     break;
140                 default:
141                     // Unsupported tag, ignore it.
142                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
143                     break;
144                 }
145                 if (TLVError != CHIP_NO_ERROR)
146                 {
147                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
148                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
149                 }
150             }
151             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
152             emberAfLevelControlClusterMoveToLevelWithOnOffCallback(level, transitionTime);
153             break;
154         }
155         case ZCL_MOVE_WITH_ON_OFF_COMMAND_ID: {
156             CHIP_ERROR TLVError = CHIP_NO_ERROR;
157             uint8_t moveMode;
158             uint8_t rate;
159
160             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
161             {
162                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
163                 {
164                 case 0:
165                     TLVError = dataTlv.Get(moveMode);
166                     break;
167                 case 1:
168                     TLVError = dataTlv.Get(rate);
169                     break;
170                 default:
171                     // Unsupported tag, ignore it.
172                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
173                     break;
174                 }
175                 if (TLVError != CHIP_NO_ERROR)
176                 {
177                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
178                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
179                 }
180             }
181             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
182             emberAfLevelControlClusterMoveWithOnOffCallback(moveMode, rate);
183             break;
184         }
185         case ZCL_STEP_COMMAND_ID: {
186             CHIP_ERROR TLVError = CHIP_NO_ERROR;
187             uint8_t stepMode;
188             uint8_t stepSize;
189             uint16_t transitionTime;
190             uint8_t optionMask;
191             uint8_t optionOverride;
192
193             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
194             {
195                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
196                 {
197                 case 0:
198                     TLVError = dataTlv.Get(stepMode);
199                     break;
200                 case 1:
201                     TLVError = dataTlv.Get(stepSize);
202                     break;
203                 case 2:
204                     TLVError = dataTlv.Get(transitionTime);
205                     break;
206                 case 3:
207                     TLVError = dataTlv.Get(optionMask);
208                     break;
209                 case 4:
210                     TLVError = dataTlv.Get(optionOverride);
211                     break;
212                 default:
213                     // Unsupported tag, ignore it.
214                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
215                     break;
216                 }
217                 if (TLVError != CHIP_NO_ERROR)
218                 {
219                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
220                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
221                 }
222             }
223             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
224             emberAfLevelControlClusterStepCallback(stepMode, stepSize, transitionTime, optionMask, optionOverride);
225             break;
226         }
227         case ZCL_STEP_WITH_ON_OFF_COMMAND_ID: {
228             CHIP_ERROR TLVError = CHIP_NO_ERROR;
229             uint8_t stepMode;
230             uint8_t stepSize;
231             uint16_t transitionTime;
232
233             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
234             {
235                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
236                 {
237                 case 0:
238                     TLVError = dataTlv.Get(stepMode);
239                     break;
240                 case 1:
241                     TLVError = dataTlv.Get(stepSize);
242                     break;
243                 case 2:
244                     TLVError = dataTlv.Get(transitionTime);
245                     break;
246                 default:
247                     // Unsupported tag, ignore it.
248                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
249                     break;
250                 }
251                 if (TLVError != CHIP_NO_ERROR)
252                 {
253                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
254                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
255                 }
256             }
257             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
258             emberAfLevelControlClusterStepWithOnOffCallback(stepMode, stepSize, transitionTime);
259             break;
260         }
261         case ZCL_STOP_COMMAND_ID: {
262             CHIP_ERROR TLVError = CHIP_NO_ERROR;
263             uint8_t optionMask;
264             uint8_t optionOverride;
265
266             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
267             {
268                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
269                 {
270                 case 0:
271                     TLVError = dataTlv.Get(optionMask);
272                     break;
273                 case 1:
274                     TLVError = dataTlv.Get(optionOverride);
275                     break;
276                 default:
277                     // Unsupported tag, ignore it.
278                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
279                     break;
280                 }
281                 if (TLVError != CHIP_NO_ERROR)
282                 {
283                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
284                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
285                 }
286             }
287             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
288             emberAfLevelControlClusterStopCallback(optionMask, optionOverride);
289             break;
290         }
291         case ZCL_STOP_WITH_ON_OFF_COMMAND_ID: {
292             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
293             emberAfLevelControlClusterStopWithOnOffCallback();
294             break;
295         }
296         default: {
297             // Unrecognized command ID, error status will apply.
298             // TODO: Encode response for command not found
299             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_LEVEL_CONTROL_CLUSTER_ID);
300             break;
301         }
302         }
303     }
304 }
305
306 } // namespace LevelControl
307
308 namespace NetworkCommissioning {
309
310 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
311 {
312     {
313         switch (commandId)
314         {
315         case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
316             CHIP_ERROR TLVError = CHIP_NO_ERROR;
317             chip::ByteSpan operationalDataset;
318             uint64_t breadcrumb;
319             uint32_t timeoutMs;
320
321             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
322             {
323                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
324                 {
325                 case 0: {
326                     const uint8_t * data = nullptr;
327                     TLVError             = dataTlv.GetDataPtr(data);
328                     operationalDataset   = chip::ByteSpan(data, dataTlv.GetLength());
329                 }
330                 break;
331                 case 1:
332                     TLVError = dataTlv.Get(breadcrumb);
333                     break;
334                 case 2:
335                     TLVError = dataTlv.Get(timeoutMs);
336                     break;
337                 default:
338                     // Unsupported tag, ignore it.
339                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
340                     break;
341                 }
342                 if (TLVError != CHIP_NO_ERROR)
343                 {
344                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
345                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
346                 }
347             }
348             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
349             emberAfNetworkCommissioningClusterAddThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
350             break;
351         }
352         case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
353             CHIP_ERROR TLVError = CHIP_NO_ERROR;
354             chip::ByteSpan ssid;
355             chip::ByteSpan credentials;
356             uint64_t breadcrumb;
357             uint32_t timeoutMs;
358
359             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
360             {
361                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
362                 {
363                 case 0: {
364                     const uint8_t * data = nullptr;
365                     TLVError             = dataTlv.GetDataPtr(data);
366                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
367                 }
368                 break;
369                 case 1: {
370                     const uint8_t * data = nullptr;
371                     TLVError             = dataTlv.GetDataPtr(data);
372                     credentials          = chip::ByteSpan(data, dataTlv.GetLength());
373                 }
374                 break;
375                 case 2:
376                     TLVError = dataTlv.Get(breadcrumb);
377                     break;
378                 case 3:
379                     TLVError = dataTlv.Get(timeoutMs);
380                     break;
381                 default:
382                     // Unsupported tag, ignore it.
383                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
384                     break;
385                 }
386                 if (TLVError != CHIP_NO_ERROR)
387                 {
388                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
389                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
390                 }
391             }
392             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
393             emberAfNetworkCommissioningClusterAddWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
394             break;
395         }
396         case ZCL_DISABLE_NETWORK_COMMAND_ID: {
397             CHIP_ERROR TLVError = CHIP_NO_ERROR;
398             chip::ByteSpan networkID;
399             uint64_t breadcrumb;
400             uint32_t timeoutMs;
401
402             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
403             {
404                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
405                 {
406                 case 0: {
407                     const uint8_t * data = nullptr;
408                     TLVError             = dataTlv.GetDataPtr(data);
409                     networkID            = chip::ByteSpan(data, dataTlv.GetLength());
410                 }
411                 break;
412                 case 1:
413                     TLVError = dataTlv.Get(breadcrumb);
414                     break;
415                 case 2:
416                     TLVError = dataTlv.Get(timeoutMs);
417                     break;
418                 default:
419                     // Unsupported tag, ignore it.
420                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
421                     break;
422                 }
423                 if (TLVError != CHIP_NO_ERROR)
424                 {
425                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
426                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
427                 }
428             }
429             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
430             emberAfNetworkCommissioningClusterDisableNetworkCallback(networkID, breadcrumb, timeoutMs);
431             break;
432         }
433         case ZCL_ENABLE_NETWORK_COMMAND_ID: {
434             CHIP_ERROR TLVError = CHIP_NO_ERROR;
435             chip::ByteSpan networkID;
436             uint64_t breadcrumb;
437             uint32_t timeoutMs;
438
439             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
440             {
441                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
442                 {
443                 case 0: {
444                     const uint8_t * data = nullptr;
445                     TLVError             = dataTlv.GetDataPtr(data);
446                     networkID            = chip::ByteSpan(data, dataTlv.GetLength());
447                 }
448                 break;
449                 case 1:
450                     TLVError = dataTlv.Get(breadcrumb);
451                     break;
452                 case 2:
453                     TLVError = dataTlv.Get(timeoutMs);
454                     break;
455                 default:
456                     // Unsupported tag, ignore it.
457                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
458                     break;
459                 }
460                 if (TLVError != CHIP_NO_ERROR)
461                 {
462                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
463                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
464                 }
465             }
466             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
467             emberAfNetworkCommissioningClusterEnableNetworkCallback(networkID, breadcrumb, timeoutMs);
468             break;
469         }
470         case ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID: {
471             CHIP_ERROR TLVError = CHIP_NO_ERROR;
472             uint32_t timeoutMs;
473
474             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
475             {
476                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
477                 {
478                 case 0:
479                     TLVError = dataTlv.Get(timeoutMs);
480                     break;
481                 default:
482                     // Unsupported tag, ignore it.
483                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
484                     break;
485                 }
486                 if (TLVError != CHIP_NO_ERROR)
487                 {
488                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
489                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
490                 }
491             }
492             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
493             emberAfNetworkCommissioningClusterGetLastNetworkCommissioningResultCallback(timeoutMs);
494             break;
495         }
496         case ZCL_REMOVE_NETWORK_COMMAND_ID: {
497             CHIP_ERROR TLVError = CHIP_NO_ERROR;
498             chip::ByteSpan NetworkID;
499             uint64_t Breadcrumb;
500             uint32_t TimeoutMs;
501
502             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
503             {
504                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
505                 {
506                 case 0: {
507                     const uint8_t * data = nullptr;
508                     TLVError             = dataTlv.GetDataPtr(data);
509                     NetworkID            = chip::ByteSpan(data, dataTlv.GetLength());
510                 }
511                 break;
512                 case 1:
513                     TLVError = dataTlv.Get(Breadcrumb);
514                     break;
515                 case 2:
516                     TLVError = dataTlv.Get(TimeoutMs);
517                     break;
518                 default:
519                     // Unsupported tag, ignore it.
520                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
521                     break;
522                 }
523                 if (TLVError != CHIP_NO_ERROR)
524                 {
525                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
526                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
527                 }
528             }
529             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
530             emberAfNetworkCommissioningClusterRemoveNetworkCallback(NetworkID, Breadcrumb, TimeoutMs);
531             break;
532         }
533         case ZCL_SCAN_NETWORKS_COMMAND_ID: {
534             CHIP_ERROR TLVError = CHIP_NO_ERROR;
535             chip::ByteSpan ssid;
536             uint64_t breadcrumb;
537             uint32_t timeoutMs;
538
539             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
540             {
541                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
542                 {
543                 case 0: {
544                     const uint8_t * data = nullptr;
545                     TLVError             = dataTlv.GetDataPtr(data);
546                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
547                 }
548                 break;
549                 case 1:
550                     TLVError = dataTlv.Get(breadcrumb);
551                     break;
552                 case 2:
553                     TLVError = dataTlv.Get(timeoutMs);
554                     break;
555                 default:
556                     // Unsupported tag, ignore it.
557                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
558                     break;
559                 }
560                 if (TLVError != CHIP_NO_ERROR)
561                 {
562                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
563                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
564                 }
565             }
566             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
567             emberAfNetworkCommissioningClusterScanNetworksCallback(ssid, breadcrumb, timeoutMs);
568             break;
569         }
570         case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
571             CHIP_ERROR TLVError = CHIP_NO_ERROR;
572             chip::ByteSpan operationalDataset;
573             uint64_t breadcrumb;
574             uint32_t timeoutMs;
575
576             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
577             {
578                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
579                 {
580                 case 0: {
581                     const uint8_t * data = nullptr;
582                     TLVError             = dataTlv.GetDataPtr(data);
583                     operationalDataset   = chip::ByteSpan(data, dataTlv.GetLength());
584                 }
585                 break;
586                 case 1:
587                     TLVError = dataTlv.Get(breadcrumb);
588                     break;
589                 case 2:
590                     TLVError = dataTlv.Get(timeoutMs);
591                     break;
592                 default:
593                     // Unsupported tag, ignore it.
594                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
595                     break;
596                 }
597                 if (TLVError != CHIP_NO_ERROR)
598                 {
599                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
600                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
601                 }
602             }
603             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
604             emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
605             break;
606         }
607         case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
608             CHIP_ERROR TLVError = CHIP_NO_ERROR;
609             chip::ByteSpan ssid;
610             chip::ByteSpan credentials;
611             uint64_t breadcrumb;
612             uint32_t timeoutMs;
613
614             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
615             {
616                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
617                 {
618                 case 0: {
619                     const uint8_t * data = nullptr;
620                     TLVError             = dataTlv.GetDataPtr(data);
621                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
622                 }
623                 break;
624                 case 1: {
625                     const uint8_t * data = nullptr;
626                     TLVError             = dataTlv.GetDataPtr(data);
627                     credentials          = chip::ByteSpan(data, dataTlv.GetLength());
628                 }
629                 break;
630                 case 2:
631                     TLVError = dataTlv.Get(breadcrumb);
632                     break;
633                 case 3:
634                     TLVError = dataTlv.Get(timeoutMs);
635                     break;
636                 default:
637                     // Unsupported tag, ignore it.
638                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
639                     break;
640                 }
641                 if (TLVError != CHIP_NO_ERROR)
642                 {
643                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
644                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
645                 }
646             }
647             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
648             emberAfNetworkCommissioningClusterUpdateWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
649             break;
650         }
651         default: {
652             // Unrecognized command ID, error status will apply.
653             // TODO: Encode response for command not found
654             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_NETWORK_COMMISSIONING_CLUSTER_ID);
655             break;
656         }
657         }
658     }
659 }
660
661 } // namespace NetworkCommissioning
662
663 namespace OnOff {
664
665 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
666 {
667     {
668         switch (commandId)
669         {
670         case ZCL_OFF_COMMAND_ID: {
671             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
672             emberAfOnOffClusterOffCallback();
673             break;
674         }
675         case ZCL_ON_COMMAND_ID: {
676             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
677             emberAfOnOffClusterOnCallback();
678             break;
679         }
680         case ZCL_TOGGLE_COMMAND_ID: {
681             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
682             emberAfOnOffClusterToggleCallback();
683             break;
684         }
685         default: {
686             // Unrecognized command ID, error status will apply.
687             // TODO: Encode response for command not found
688             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_ON_OFF_CLUSTER_ID);
689             break;
690         }
691         }
692     }
693 }
694
695 } // namespace OnOff
696
697 } // namespace clusters
698
699 void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aCommandId, chip::EndpointId aEndPointId,
700                                   chip::TLV::TLVReader & aReader, Command * apCommandObj)
701 {
702     ChipLogDetail(Zcl, "Received Cluster Command: Cluster=%" PRIx16 " Command=%" PRIx8 " Endpoint=%" PRIx8, aClusterId, aCommandId,
703                   aEndPointId);
704     Compatibility::SetupEmberAfObjects(apCommandObj, aClusterId, aCommandId, aEndPointId);
705     switch (aClusterId)
706     {
707     case ZCL_LEVEL_CONTROL_CLUSTER_ID:
708         clusters::LevelControl::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
709         break;
710     case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
711         clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
712         break;
713     case ZCL_ON_OFF_CLUSTER_ID:
714         clusters::OnOff::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
715         break;
716     default:
717         // Unrecognized cluster ID, error status will apply.
718         // TODO: Encode response for Cluster not found
719         ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
720         break;
721     }
722     Compatibility::ResetEmberAfObjects();
723 }
724
725 } // namespace app
726 } // namespace chip