Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / src / app / clusters / zll-level-control-server / zll-level-control-server.c
1 /**
2  *
3  *    Copyright (c) 2020 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 /**
19  *
20  *    Copyright (c) 2020 Silicon Labs
21  *
22  *    Licensed under the Apache License, Version 2.0 (the "License");
23  *    you may not use this file except in compliance with the License.
24  *    You may obtain a copy of the License at
25  *
26  *        http://www.apache.org/licenses/LICENSE-2.0
27  *
28  *    Unless required by applicable law or agreed to in writing, software
29  *    distributed under the License is distributed on an "AS IS" BASIS,
30  *    WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  *    See the License for the specific language governing permissions and
32  *    limitations under the License.
33  */
34
35 /**
36  * @file
37  * @brief Routines for the ZLL Level Control Server plugin.
38  *******************************************************************************
39  * # License
40  * <b>Copyright 2018 Silicon Laboratories Inc.
41  * www.silabs.com</b>
42  *******************************************************************************
43  *
44  * The licensor of this software is Silicon
45  * Laboratories Inc. Your use of this software is
46  * governed by the terms of Silicon Labs Master
47  * Software License Agreement (MSLA) available at
48  * www.silabs.com/about-us/legal/master-software-license-agreement.
49  * This software is distributed to you in Source Code
50  * format and is governed by the sections of the MSLA
51  * applicable to Source Code.
52  *
53  ******************************************************************************/
54
55 #include "zll-level-control-server.h"
56 #include "../../include/af.h"
57
58 EmberAfStatus emberAfPluginZllLevelControlServerMoveToLevelWithOnOffZllExtensions(const EmberAfClusterCommand * cmd)
59 {
60     bool globalSceneControl = true;
61     EmberAfStatus status    = emberAfWriteServerAttribute(cmd->apsFrame->destinationEndpoint, ZCL_ON_OFF_CLUSTER_ID,
62                                                        ZCL_GLOBAL_SCENE_CONTROL_ATTRIBUTE_ID, (uint8_t *) &globalSceneControl,
63                                                        ZCL_BOOLEAN_ATTRIBUTE_TYPE);
64     if (status != EMBER_ZCL_STATUS_SUCCESS)
65     {
66         emberAfLevelControlClusterPrintln("ERR: writing global scene control %x", status);
67     }
68     return status;
69 }
70
71 bool emberAfPluginZllLevelControlServerIgnoreMoveToLevelMoveStepStop(uint8_t endpoint, uint8_t commandId)
72 {
73     // If a MoveToLevel, Move, Step, or Stop command is received while the device
74     // is in its off state (i.e., the OnOff attribute of the On/Off cluster is
75     // equal to false), the command shall be ignored.
76     bool onOff = true;
77 #ifdef ZCL_USING_ON_OFF_CLUSTER_SERVER
78     if ((commandId == ZCL_MOVE_TO_LEVEL_COMMAND_ID || commandId == ZCL_MOVE_COMMAND_ID || commandId == ZCL_STEP_COMMAND_ID ||
79          commandId == ZCL_STOP_COMMAND_ID) &&
80         emberAfContainsServer(endpoint, ZCL_ON_OFF_CLUSTER_ID))
81     {
82         EmberAfStatus status =
83             emberAfReadServerAttribute(endpoint, ZCL_ON_OFF_CLUSTER_ID, ZCL_ON_OFF_ATTRIBUTE_ID, (uint8_t *) &onOff, sizeof(onOff));
84         if (status != EMBER_ZCL_STATUS_SUCCESS)
85         {
86             emberAfLevelControlClusterPrintln("ERR: reading on/off %x", status);
87         }
88     }
89 #endif
90     return !onOff;
91 }