Apply Upstream code (2021-03-15)
[platform/upstream/connectedhomeip.git] / examples / temperature-measurement-app / esp32 / main / gen / call-command-handler.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 <stdint.h>
21
22 #include "af-structs.h"
23 #include "call-command-handler.h"
24 #include "callback.h"
25 #include "cluster-id.h"
26 #include "command-id.h"
27 #include "util.h"
28
29 using namespace chip;
30
31 EmberAfStatus emberAfBasicClusterServerCommandParse(EmberAfClusterCommand * cmd);
32 EmberAfStatus emberAfTemperatureMeasurementClusterServerCommandParse(EmberAfClusterCommand * cmd);
33
34 static EmberAfStatus status(bool wasHandled, bool clusterExists, bool mfgSpecific)
35 {
36     if (wasHandled)
37     {
38         return EMBER_ZCL_STATUS_SUCCESS;
39     }
40     else if (mfgSpecific)
41     {
42         return EMBER_ZCL_STATUS_UNSUP_MANUF_CLUSTER_COMMAND;
43     }
44     else if (clusterExists)
45     {
46         return EMBER_ZCL_STATUS_UNSUP_COMMAND;
47     }
48     else
49     {
50         return EMBER_ZCL_STATUS_UNSUPPORTED_CLUSTER;
51     }
52 }
53
54 // Main command parsing controller.
55 EmberAfStatus emberAfClusterSpecificCommandParse(EmberAfClusterCommand * cmd)
56 {
57     EmberAfStatus result = status(false, false, cmd->mfgSpecific);
58     if (cmd->direction == (uint8_t) ZCL_DIRECTION_SERVER_TO_CLIENT &&
59         emberAfContainsClientWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
60     {
61         switch (cmd->apsFrame->clusterId)
62         {
63         default:
64             // Unrecognized cluster ID, error status will apply.
65             break;
66         }
67     }
68     else if (cmd->direction == (uint8_t) ZCL_DIRECTION_CLIENT_TO_SERVER &&
69              emberAfContainsServerWithMfgCode(cmd->apsFrame->destinationEndpoint, cmd->apsFrame->clusterId, cmd->mfgCode))
70     {
71         switch (cmd->apsFrame->clusterId)
72         {
73         case ZCL_BASIC_CLUSTER_ID:
74             // No commands are enabled for cluster Basic
75             result = status(false, true, cmd->mfgSpecific);
76             break;
77         case ZCL_TEMP_MEASUREMENT_CLUSTER_ID:
78             // No commands are enabled for cluster Temperature Measurement
79             result = status(false, true, cmd->mfgSpecific);
80             break;
81         default:
82             // Unrecognized cluster ID, error status will apply.
83             break;
84         }
85     }
86     return result;
87 }
88
89 // Cluster specific command parsing