blob: 2f677fe3afca2ba1ad2d723c40a40d2ed4023944 [file] [log] [blame]
James Feist1c8fba92019-12-20 15:12:07 -08001/*
2// Copyright (c) 2019 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080018#include "app.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080019#include "async_resp.hpp"
20#include "dbus_utility.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070021#include "generated/enums/chassis.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080022#include "redfish_util.hpp"
23
Jonathan Doman1e1e5982021-06-11 09:36:17 -070024#include <sdbusplus/asio/property.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070025
James Feist1c8fba92019-12-20 15:12:07 -080026namespace redfish
27{
28/**
29 * @brief Retrieves identify led group properties over dbus
30 *
Ed Tanousac106bf2023-06-07 09:24:59 -070031 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080032 *
33 * @return None.
34 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -050035// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +080036inline void
Ed Tanousac106bf2023-06-07 09:24:59 -070037 getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist1c8fba92019-12-20 15:12:07 -080038{
Ed Tanous62598e32023-07-17 17:06:25 -070039 BMCWEB_LOG_DEBUG("Get led groups");
Jonathan Doman1e1e5982021-06-11 09:36:17 -070040 sdbusplus::asio::getProperty<bool>(
41 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
42 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
43 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -070044 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040045 // Some systems may not have enclosure_identify_blink object so
46 // proceed to get enclosure_identify state.
47 if (ec == boost::system::errc::invalid_argument)
James Feist1c8fba92019-12-20 15:12:07 -080048 {
Ed Tanous62598e32023-07-17 17:06:25 -070049 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -040050 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -070051 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -070052 return;
James Feist1c8fba92019-12-20 15:12:07 -080053 }
James Feist1c8fba92019-12-20 15:12:07 -080054
Patrick Williamsbd79bce2024-08-16 15:22:20 -040055 // Blinking ON, no need to check enclosure_identify assert.
56 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -070057 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040058 asyncResp->res.jsonValue["IndicatorLED"] =
59 chassis::IndicatorLED::Blinking;
Jonathan Doman1e1e5982021-06-11 09:36:17 -070060 return;
61 }
62
Patrick Williamsbd79bce2024-08-16 15:22:20 -040063 sdbusplus::asio::getProperty<bool>(
64 *crow::connections::systemBus,
65 "xyz.openbmc_project.LED.GroupManager",
66 "/xyz/openbmc_project/led/groups/enclosure_identify",
67 "xyz.openbmc_project.Led.Group", "Asserted",
68 [asyncResp](const boost::system::error_code& ec2,
69 const bool ledOn) {
70 if (ec2 == boost::system::errc::invalid_argument)
71 {
72 BMCWEB_LOG_DEBUG(
73 "Get enclosure identity led failed, mismatch in property type");
74 messages::internalError(asyncResp->res);
75 return;
76 }
77
78 if (ec2)
79 {
80 return;
81 }
82
83 if (ledOn)
84 {
85 asyncResp->res.jsonValue["IndicatorLED"] =
86 chassis::IndicatorLED::Lit;
87 }
88 else
89 {
90 asyncResp->res.jsonValue["IndicatorLED"] =
91 chassis::IndicatorLED::Off;
92 }
93 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -070094 });
James Feist1c8fba92019-12-20 15:12:07 -080095}
96
97/**
98 * @brief Sets identify led group properties
99 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700100 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -0800101 * @param[in] ledState LED state passed from request
102 *
103 * @return None.
104 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500105// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +0800106inline void
Ed Tanousac106bf2023-06-07 09:24:59 -0700107 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800108 const std::string& ledState)
James Feist1c8fba92019-12-20 15:12:07 -0800109{
Ed Tanous62598e32023-07-17 17:06:25 -0700110 BMCWEB_LOG_DEBUG("Set led groups");
James Feist1c8fba92019-12-20 15:12:07 -0800111 bool ledOn = false;
112 bool ledBlinkng = false;
113
114 if (ledState == "Lit")
115 {
116 ledOn = true;
117 }
118 else if (ledState == "Blinking")
119 {
120 ledBlinkng = true;
121 }
122 else if (ledState != "Off")
123 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700124 messages::propertyValueNotInList(asyncResp->res, ledState,
125 "IndicatorLED");
James Feist1c8fba92019-12-20 15:12:07 -0800126 return;
127 }
128
George Liu9ae226f2023-06-21 17:56:46 +0800129 sdbusplus::asio::setProperty(
130 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
131 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
132 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
Ed Tanousac106bf2023-06-07 09:24:59 -0700133 [asyncResp, ledOn,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800134 ledBlinkng](const boost::system::error_code& ec) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400135 if (ec)
James Feist1c8fba92019-12-20 15:12:07 -0800136 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400137 // Some systems may not have enclosure_identify_blink object so
138 // Lets set enclosure_identify state to true if Blinking is
139 // true.
140 if (ledBlinkng)
141 {
142 ledOn = true;
143 }
James Feist1c8fba92019-12-20 15:12:07 -0800144 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400145 setDbusProperty(
146 asyncResp, "IndicatorLED",
147 "xyz.openbmc_project.LED.GroupManager",
148 sdbusplus::message::object_path(
149 "/xyz/openbmc_project/led/groups/enclosure_identify"),
150 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
151 });
James Feist1c8fba92019-12-20 15:12:07 -0800152}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500153
154/**
George Liu59a17e42022-10-08 09:27:47 +0800155 * @brief Retrieves identify system led group properties over dbus
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500156 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700157 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500158 *
159 * @return None.
160 */
George Liu59a17e42022-10-08 09:27:47 +0800161inline void getSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700162 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500163{
Ed Tanous62598e32023-07-17 17:06:25 -0700164 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700165 sdbusplus::asio::getProperty<bool>(
166 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
167 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
168 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700169 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400170 // Some systems may not have enclosure_identify_blink object so
171 // proceed to get enclosure_identify state.
172 if (ec == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500173 {
Ed Tanous62598e32023-07-17 17:06:25 -0700174 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400175 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700176 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700177 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500178 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500179
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400180 // Blinking ON, no need to check enclosure_identify assert.
181 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700182 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400183 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700184 return;
185 }
186
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400187 sdbusplus::asio::getProperty<bool>(
188 *crow::connections::systemBus,
189 "xyz.openbmc_project.LED.GroupManager",
190 "/xyz/openbmc_project/led/groups/enclosure_identify",
191 "xyz.openbmc_project.Led.Group", "Asserted",
192 [asyncResp](const boost::system::error_code& ec2,
193 const bool ledOn) {
194 if (ec2 == boost::system::errc::invalid_argument)
195 {
196 BMCWEB_LOG_DEBUG(
197 "Get enclosure identity led failed, mismatch in property type");
198 messages::internalError(asyncResp->res);
199 return;
200 }
201
202 if (ec2)
203 {
204 return;
205 }
206
207 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
208 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700209 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500210}
211
212/**
George Liu59a17e42022-10-08 09:27:47 +0800213 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500214 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700215 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500216 * @param[in] ledState LED state passed from request
217 *
218 * @return None.
219 */
George Liu59a17e42022-10-08 09:27:47 +0800220inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700221 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500222{
Ed Tanous62598e32023-07-17 17:06:25 -0700223 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500224
George Liu9ae226f2023-06-21 17:56:46 +0800225 sdbusplus::asio::setProperty(
226 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
227 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
228 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
229 [asyncResp, ledState](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400230 if (ec)
231 {
232 // Some systems may not have enclosure_identify_blink object so
233 // lets set enclosure_identify state also if
234 // enclosure_identify_blink failed
235 setDbusProperty(
236 asyncResp, "LocationIndicatorActive",
237 "xyz.openbmc_project.LED.GroupManager",
238 sdbusplus::message::object_path(
239 "/xyz/openbmc_project/led/groups/enclosure_identify"),
240 "xyz.openbmc_project.Led.Group", "Asserted", ledState);
241 }
242 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500243}
Ed Tanous23a21a12020-07-25 04:45:05 +0000244} // namespace redfish