3 * Copyright (c) 2021 Project CHIP Authors
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 // THIS FILE IS GENERATED BY ZAP
23 #include "af-structs.h"
24 #include "app/util/util.h"
25 #include "call-command-handler.h"
27 #include "cluster-id.h"
28 #include "command-id.h"
30 #include <app/InteractionModelEngine.h>
32 // Currently we need some work to keep compatible with ember lib.
33 #include <util/ember-compatibility-functions.h>
38 // Cluster specific command parsing
42 namespace NetworkCommissioning {
44 void DispatchServerCommand(app::Command * command, CommandId commandId, EndpointId endpointId, TLV::TLVReader & dataTlv)
49 case ZCL_ADD_THREAD_NETWORK_COMMAND_ID: {
50 CHIP_ERROR TLVError = CHIP_NO_ERROR;
51 chip::ByteSpan operationalDataset;
55 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
57 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
60 const uint8_t * data = nullptr;
61 TLVError = dataTlv.GetDataPtr(data);
62 operationalDataset = chip::ByteSpan(data, dataTlv.GetLength());
66 TLVError = dataTlv.Get(breadcrumb);
69 TLVError = dataTlv.Get(timeoutMs);
72 // Unsupported tag, ignore it.
73 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
76 if (TLVError != CHIP_NO_ERROR)
78 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
79 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
82 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
83 emberAfNetworkCommissioningClusterAddThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
86 case ZCL_ADD_WI_FI_NETWORK_COMMAND_ID: {
87 CHIP_ERROR TLVError = CHIP_NO_ERROR;
89 chip::ByteSpan credentials;
93 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
95 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
98 const uint8_t * data = nullptr;
99 TLVError = dataTlv.GetDataPtr(data);
100 ssid = chip::ByteSpan(data, dataTlv.GetLength());
104 const uint8_t * data = nullptr;
105 TLVError = dataTlv.GetDataPtr(data);
106 credentials = chip::ByteSpan(data, dataTlv.GetLength());
110 TLVError = dataTlv.Get(breadcrumb);
113 TLVError = dataTlv.Get(timeoutMs);
116 // Unsupported tag, ignore it.
117 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
120 if (TLVError != CHIP_NO_ERROR)
122 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
123 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
126 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
127 emberAfNetworkCommissioningClusterAddWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
130 case ZCL_DISABLE_NETWORK_COMMAND_ID: {
131 CHIP_ERROR TLVError = CHIP_NO_ERROR;
132 chip::ByteSpan networkID;
136 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
138 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
141 const uint8_t * data = nullptr;
142 TLVError = dataTlv.GetDataPtr(data);
143 networkID = chip::ByteSpan(data, dataTlv.GetLength());
147 TLVError = dataTlv.Get(breadcrumb);
150 TLVError = dataTlv.Get(timeoutMs);
153 // Unsupported tag, ignore it.
154 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
157 if (TLVError != CHIP_NO_ERROR)
159 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
160 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
163 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
164 emberAfNetworkCommissioningClusterDisableNetworkCallback(networkID, breadcrumb, timeoutMs);
167 case ZCL_ENABLE_NETWORK_COMMAND_ID: {
168 CHIP_ERROR TLVError = CHIP_NO_ERROR;
169 chip::ByteSpan networkID;
173 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
175 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
178 const uint8_t * data = nullptr;
179 TLVError = dataTlv.GetDataPtr(data);
180 networkID = chip::ByteSpan(data, dataTlv.GetLength());
184 TLVError = dataTlv.Get(breadcrumb);
187 TLVError = dataTlv.Get(timeoutMs);
190 // Unsupported tag, ignore it.
191 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
194 if (TLVError != CHIP_NO_ERROR)
196 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
197 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
200 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
201 emberAfNetworkCommissioningClusterEnableNetworkCallback(networkID, breadcrumb, timeoutMs);
204 case ZCL_GET_LAST_NETWORK_COMMISSIONING_RESULT_COMMAND_ID: {
205 CHIP_ERROR TLVError = CHIP_NO_ERROR;
208 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
210 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
213 TLVError = dataTlv.Get(timeoutMs);
216 // Unsupported tag, ignore it.
217 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
220 if (TLVError != CHIP_NO_ERROR)
222 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
223 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
226 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
227 emberAfNetworkCommissioningClusterGetLastNetworkCommissioningResultCallback(timeoutMs);
230 case ZCL_REMOVE_NETWORK_COMMAND_ID: {
231 CHIP_ERROR TLVError = CHIP_NO_ERROR;
232 chip::ByteSpan NetworkID;
236 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
238 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
241 const uint8_t * data = nullptr;
242 TLVError = dataTlv.GetDataPtr(data);
243 NetworkID = chip::ByteSpan(data, dataTlv.GetLength());
247 TLVError = dataTlv.Get(Breadcrumb);
250 TLVError = dataTlv.Get(TimeoutMs);
253 // Unsupported tag, ignore it.
254 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
257 if (TLVError != CHIP_NO_ERROR)
259 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
260 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
263 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
264 emberAfNetworkCommissioningClusterRemoveNetworkCallback(NetworkID, Breadcrumb, TimeoutMs);
267 case ZCL_SCAN_NETWORKS_COMMAND_ID: {
268 CHIP_ERROR TLVError = CHIP_NO_ERROR;
273 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
275 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
278 const uint8_t * data = nullptr;
279 TLVError = dataTlv.GetDataPtr(data);
280 ssid = chip::ByteSpan(data, dataTlv.GetLength());
284 TLVError = dataTlv.Get(breadcrumb);
287 TLVError = dataTlv.Get(timeoutMs);
290 // Unsupported tag, ignore it.
291 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
294 if (TLVError != CHIP_NO_ERROR)
296 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
297 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
300 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
301 emberAfNetworkCommissioningClusterScanNetworksCallback(ssid, breadcrumb, timeoutMs);
304 case ZCL_UPDATE_THREAD_NETWORK_COMMAND_ID: {
305 CHIP_ERROR TLVError = CHIP_NO_ERROR;
306 chip::ByteSpan operationalDataset;
310 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
312 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
315 const uint8_t * data = nullptr;
316 TLVError = dataTlv.GetDataPtr(data);
317 operationalDataset = chip::ByteSpan(data, dataTlv.GetLength());
321 TLVError = dataTlv.Get(breadcrumb);
324 TLVError = dataTlv.Get(timeoutMs);
327 // Unsupported tag, ignore it.
328 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
331 if (TLVError != CHIP_NO_ERROR)
333 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
334 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
337 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
338 emberAfNetworkCommissioningClusterUpdateThreadNetworkCallback(operationalDataset, breadcrumb, timeoutMs);
341 case ZCL_UPDATE_WI_FI_NETWORK_COMMAND_ID: {
342 CHIP_ERROR TLVError = CHIP_NO_ERROR;
344 chip::ByteSpan credentials;
348 while ((TLVError = dataTlv.Next()) == CHIP_NO_ERROR)
350 switch (TLV::TagNumFromTag(dataTlv.GetTag()))
353 const uint8_t * data = nullptr;
354 TLVError = dataTlv.GetDataPtr(data);
355 ssid = chip::ByteSpan(data, dataTlv.GetLength());
359 const uint8_t * data = nullptr;
360 TLVError = dataTlv.GetDataPtr(data);
361 credentials = chip::ByteSpan(data, dataTlv.GetLength());
365 TLVError = dataTlv.Get(breadcrumb);
368 TLVError = dataTlv.Get(timeoutMs);
371 // Unsupported tag, ignore it.
372 ChipLogProgress(Zcl, "Unknown TLV tag during processing.");
375 if (TLVError != CHIP_NO_ERROR)
377 ChipLogProgress(Zcl, "Failed to decode TLV data with tag %" PRIx32 ": %" PRId32,
378 TLV::TagNumFromTag(dataTlv.GetTag()), TLVError);
381 // TODO(#5098) We should pass the Command Object and EndpointId to the cluster callbacks.
382 emberAfNetworkCommissioningClusterUpdateWiFiNetworkCallback(ssid, credentials, breadcrumb, timeoutMs);
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);
395 } // namespace NetworkCommissioning
397 } // namespace clusters
399 void DispatchSingleClusterCommand(chip::ClusterId aClusterId, chip::CommandId aCommandId, chip::EndpointId aEndPointId,
400 chip::TLV::TLVReader & aReader, Command * apCommandObj)
402 ChipLogDetail(Zcl, "Received Cluster Command: Cluster=%" PRIx16 " Command=%" PRIx8 " Endpoint=%" PRIx8, aClusterId, aCommandId,
404 Compatibility::SetupEmberAfObjects(apCommandObj, aClusterId, aCommandId, aEndPointId);
407 case ZCL_NETWORK_COMMISSIONING_CLUSTER_ID:
408 clusters::NetworkCommissioning::DispatchServerCommand(apCommandObj, aCommandId, aEndPointId, aReader);
411 // Unrecognized cluster ID, error status will apply.
412 // TODO: Encode response for Cluster not found
413 ChipLogError(Zcl, "Unknown cluster %" PRIx16, aClusterId);
416 Compatibility::ResetEmberAfObjects();