Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / examples / temperature-measurement-app / esp32 / main / 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 NetworkCommissioning {
43
44 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
45 {
46     {
47         switch (commandId)
48         {
49         case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
50             CHIP_ERROR TLVError = CHIP_NO_ERROR;
51             chip::ByteSpan operationalDataset;
52             uint64_t breadcrumb;
53             uint32_t timeoutMs;
54
55             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
56             {
57                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
58                 {
59                 case 0: {
60                     const uint8_t * data = nullptr;
61                     TLVError             = dataTlv.GetDataPtr(data);
62                     operationalDataset   = chip::ByteSpan(data, dataTlv.GetLength());
63                 }
64                 break;
65                 case 1:
66                     TLVError = dataTlv.Get(breadcrumb);
67                     break;
68                 case 2:
69                     TLVError = dataTlv.Get(timeoutMs);
70                     break;
71                 default:
72                     // Unsupported tag, ignore it.
73                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
74                     break;
75                 }
76                 if (TLVError != CHIP_NO_ERROR)
77                 {
78                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
79                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
80                 }
81             }
82             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
83             emberAfNetworkCommissioningClusterAddThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
84             break;
85         }
86         case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
87             CHIP_ERROR TLVError = CHIP_NO_ERROR;
88             chip::ByteSpan ssid;
89             chip::ByteSpan credentials;
90             uint64_t breadcrumb;
91             uint32_t timeoutMs;
92
93             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
94             {
95                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
96                 {
97                 case 0: {
98                     const uint8_t * data = nullptr;
99                     TLVError             = dataTlv.GetDataPtr(data);
100                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
101                 }
102                 break;
103                 case 1: {
104                     const uint8_t * data = nullptr;
105                     TLVError             = dataTlv.GetDataPtr(data);
106                     credentials          = chip::ByteSpan(data, dataTlv.GetLength());
107                 }
108                 break;
109                 case 2:
110                     TLVError = dataTlv.Get(breadcrumb);
111                     break;
112                 case 3:
113                     TLVError = dataTlv.Get(timeoutMs);
114                     break;
115                 default:
116                     // Unsupported tag, ignore it.
117                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
118                     break;
119                 }
120                 if (TLVError != CHIP_NO_ERROR)
121                 {
122                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
123                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
124                 }
125             }
126             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
127             emberAfNetworkCommissioningClusterAddWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
128             break;
129         }
130         case ZCL_DISABLE_NETWORK_COMMAND_ID: {
131             CHIP_ERROR TLVError = CHIP_NO_ERROR;
132             chip::ByteSpan networkID;
133             uint64_t breadcrumb;
134             uint32_t timeoutMs;
135
136             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
137             {
138                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
139                 {
140                 case 0: {
141                     const uint8_t * data = nullptr;
142                     TLVError             = dataTlv.GetDataPtr(data);
143                     networkID            = chip::ByteSpan(data, dataTlv.GetLength());
144                 }
145                 break;
146                 case 1:
147                     TLVError = dataTlv.Get(breadcrumb);
148                     break;
149                 case 2:
150                     TLVError = dataTlv.Get(timeoutMs);
151                     break;
152                 default:
153                     // Unsupported tag, ignore it.
154                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
155                     break;
156                 }
157                 if (TLVError != CHIP_NO_ERROR)
158                 {
159                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
160                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
161                 }
162             }
163             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
164             emberAfNetworkCommissioningClusterDisableNetworkCallback(networkID, breadcrumb, timeoutMs);
165             break;
166         }
167         case ZCL_ENABLE_NETWORK_COMMAND_ID: {
168             CHIP_ERROR TLVError = CHIP_NO_ERROR;
169             chip::ByteSpan networkID;
170             uint64_t breadcrumb;
171             uint32_t timeoutMs;
172
173             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
174             {
175                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
176                 {
177                 case 0: {
178                     const uint8_t * data = nullptr;
179                     TLVError             = dataTlv.GetDataPtr(data);
180                     networkID            = chip::ByteSpan(data, dataTlv.GetLength());
181                 }
182                 break;
183                 case 1:
184                     TLVError = dataTlv.Get(breadcrumb);
185                     break;
186                 case 2:
187                     TLVError = dataTlv.Get(timeoutMs);
188                     break;
189                 default:
190                     // Unsupported tag, ignore it.
191                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
192                     break;
193                 }
194                 if (TLVError != CHIP_NO_ERROR)
195                 {
196                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
197                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
198                 }
199             }
200             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
201             emberAfNetworkCommissioningClusterEnableNetworkCallback(networkID, breadcrumb, timeoutMs);
202             break;
203         }
204         case ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID: {
205             CHIP_ERROR TLVError = CHIP_NO_ERROR;
206             uint32_t timeoutMs;
207
208             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
209             {
210                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
211                 {
212                 case 0:
213                     TLVError = dataTlv.Get(timeoutMs);
214                     break;
215                 default:
216                     // Unsupported tag, ignore it.
217                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
218                     break;
219                 }
220                 if (TLVError != CHIP_NO_ERROR)
221                 {
222                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
223                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
224                 }
225             }
226             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
227             emberAfNetworkCommissioningClusterGetLastNetworkCommissioningResultCallback(timeoutMs);
228             break;
229         }
230         case ZCL_REMOVE_NETWORK_COMMAND_ID: {
231             CHIP_ERROR TLVError = CHIP_NO_ERROR;
232             chip::ByteSpan NetworkID;
233             uint64_t Breadcrumb;
234             uint32_t TimeoutMs;
235
236             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
237             {
238                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
239                 {
240                 case 0: {
241                     const uint8_t * data = nullptr;
242                     TLVError             = dataTlv.GetDataPtr(data);
243                     NetworkID            = chip::ByteSpan(data, dataTlv.GetLength());
244                 }
245                 break;
246                 case 1:
247                     TLVError = dataTlv.Get(Breadcrumb);
248                     break;
249                 case 2:
250                     TLVError = dataTlv.Get(TimeoutMs);
251                     break;
252                 default:
253                     // Unsupported tag, ignore it.
254                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
255                     break;
256                 }
257                 if (TLVError != CHIP_NO_ERROR)
258                 {
259                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
260                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
261                 }
262             }
263             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
264             emberAfNetworkCommissioningClusterRemoveNetworkCallback(NetworkID, Breadcrumb, TimeoutMs);
265             break;
266         }
267         case ZCL_SCAN_NETWORKS_COMMAND_ID: {
268             CHIP_ERROR TLVError = CHIP_NO_ERROR;
269             chip::ByteSpan ssid;
270             uint64_t breadcrumb;
271             uint32_t timeoutMs;
272
273             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
274             {
275                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
276                 {
277                 case 0: {
278                     const uint8_t * data = nullptr;
279                     TLVError             = dataTlv.GetDataPtr(data);
280                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
281                 }
282                 break;
283                 case 1:
284                     TLVError = dataTlv.Get(breadcrumb);
285                     break;
286                 case 2:
287                     TLVError = dataTlv.Get(timeoutMs);
288                     break;
289                 default:
290                     // Unsupported tag, ignore it.
291                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
292                     break;
293                 }
294                 if (TLVError != CHIP_NO_ERROR)
295                 {
296                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
297                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
298                 }
299             }
300             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
301             emberAfNetworkCommissioningClusterScanNetworksCallback(ssid, breadcrumb, timeoutMs);
302             break;
303         }
304         case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
305             CHIP_ERROR TLVError = CHIP_NO_ERROR;
306             chip::ByteSpan operationalDataset;
307             uint64_t breadcrumb;
308             uint32_t timeoutMs;
309
310             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
311             {
312                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
313                 {
314                 case 0: {
315                     const uint8_t * data = nullptr;
316                     TLVError             = dataTlv.GetDataPtr(data);
317                     operationalDataset   = chip::ByteSpan(data, dataTlv.GetLength());
318                 }
319                 break;
320                 case 1:
321                     TLVError = dataTlv.Get(breadcrumb);
322                     break;
323                 case 2:
324                     TLVError = dataTlv.Get(timeoutMs);
325                     break;
326                 default:
327                     // Unsupported tag, ignore it.
328                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
329                     break;
330                 }
331                 if (TLVError != CHIP_NO_ERROR)
332                 {
333                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
334                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
335                 }
336             }
337             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
338             emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
339             break;
340         }
341         case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
342             CHIP_ERROR TLVError = CHIP_NO_ERROR;
343             chip::ByteSpan ssid;
344             chip::ByteSpan credentials;
345             uint64_t breadcrumb;
346             uint32_t timeoutMs;
347
348             while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
349             {
350                 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
351                 {
352                 case 0: {
353                     const uint8_t * data = nullptr;
354                     TLVError             = dataTlv.GetDataPtr(data);
355                     ssid                 = chip::ByteSpan(data, dataTlv.GetLength());
356                 }
357                 break;
358                 case 1: {
359                     const uint8_t * data = nullptr;
360                     TLVError             = dataTlv.GetDataPtr(data);
361                     credentials          = chip::ByteSpan(data, dataTlv.GetLength());
362                 }
363                 break;
364                 case 2:
365                     TLVError = dataTlv.Get(breadcrumb);
366                     break;
367                 case 3:
368                     TLVError = dataTlv.Get(timeoutMs);
369                     break;
370                 default:
371                     // Unsupported tag, ignore it.
372                     ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
373                     break;
374                 }
375                 if (TLVError != CHIP_NO_ERROR)
376                 {
377                     ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
378                                     TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
379                 }
380             }
381             // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
382             emberAfNetworkCommissioningClusterUpdateWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
383             break;
384         }
385         default: {
386             // Unrecognized command ID, error status will apply.
387             // TODO: Encode response for command not found
388             ChipLogError(Zcl, "Unknown command %" PRIx16 " for cluster %" PRIx16, commandId, ZCL_NETWORK_COMMISSIONING_CLUSTER_ID);
389             break;
390         }
391         }
392     }
393 }
394
395 } // namespace NetworkCommissioning
396
397 } // namespace clusters
398
399 void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aCommandId, chip::EndpointId aEndPointId,
400                                   chip::TLV::TLVReader & aReader, Command * apCommandObj)
401 {
402     ChipLogDetail(Zcl, "Received Cluster Command: Cluster=%" PRIx16 " Command=%" PRIx8 " Endpoint=%" PRIx8, aClusterId, aCommandId,
403                   aEndPointId);
404     Compatibility::SetupEmberAfObjects(apCommandObj, aClusterId, aCommandId, aEndPointId);
405     switch (aClusterId)
406     {
407     case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
408         clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
409         break;
410     default:
411         // Unrecognized cluster ID, error status will apply.
412         // TODO: Encode response for Cluster not found
413         ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
414         break;
415     }
416     Compatibility::ResetEmberAfObjects();
417 }
418
419 } // namespace app
420 } // namespace chip