blob: 64b097a360def9c03af64320fabe9a6c313ab0df [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"
21#include "redfish_util.hpp"
22
Jonathan Doman1e1e5982021-06-11 09:36:17 -070023#include <sdbusplus/asio/property.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070024
James Feist1c8fba92019-12-20 15:12:07 -080025namespace redfish
26{
27/**
28 * @brief Retrieves identify led group properties over dbus
29 *
Ed Tanousac106bf2023-06-07 09:24:59 -070030 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080031 *
32 * @return None.
33 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -050034// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +080035inline void
Ed Tanousac106bf2023-06-07 09:24:59 -070036 getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist1c8fba92019-12-20 15:12:07 -080037{
38 BMCWEB_LOG_DEBUG << "Get led groups";
Jonathan Doman1e1e5982021-06-11 09:36:17 -070039 sdbusplus::asio::getProperty<bool>(
40 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
41 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
42 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -070043 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Ed Tanous002d39b2022-05-31 08:59:27 -070044 // Some systems may not have enclosure_identify_blink object so
45 // proceed to get enclosure_identify state.
46 if (ec == boost::system::errc::invalid_argument)
47 {
48 BMCWEB_LOG_DEBUG
49 << "Get identity blinking LED failed, missmatch in property type";
Ed Tanousac106bf2023-06-07 09:24:59 -070050 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -070051 return;
52 }
53
54 // Blinking ON, no need to check enclosure_identify assert.
55 if (!ec && blinking)
56 {
Ed Tanousac106bf2023-06-07 09:24:59 -070057 asyncResp->res.jsonValue["IndicatorLED"] = "Blinking";
Ed Tanous002d39b2022-05-31 08:59:27 -070058 return;
59 }
60
61 sdbusplus::asio::getProperty<bool>(
62 *crow::connections::systemBus,
63 "xyz.openbmc_project.LED.GroupManager",
64 "/xyz/openbmc_project/led/groups/enclosure_identify",
65 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -070066 [asyncResp](const boost::system::error_code& ec2,
67 const bool ledOn) {
Ed Tanous002d39b2022-05-31 08:59:27 -070068 if (ec2 == boost::system::errc::invalid_argument)
James Feist1c8fba92019-12-20 15:12:07 -080069 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -070070 BMCWEB_LOG_DEBUG
Ed Tanous002d39b2022-05-31 08:59:27 -070071 << "Get enclosure identity led failed, missmatch in property type";
Ed Tanousac106bf2023-06-07 09:24:59 -070072 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -070073 return;
James Feist1c8fba92019-12-20 15:12:07 -080074 }
James Feist1c8fba92019-12-20 15:12:07 -080075
Ed Tanous002d39b2022-05-31 08:59:27 -070076 if (ec2)
Jonathan Doman1e1e5982021-06-11 09:36:17 -070077 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -070078 return;
79 }
80
Ed Tanous002d39b2022-05-31 08:59:27 -070081 if (ledOn)
82 {
Ed Tanousac106bf2023-06-07 09:24:59 -070083 asyncResp->res.jsonValue["IndicatorLED"] = "Lit";
Ed Tanous002d39b2022-05-31 08:59:27 -070084 }
85 else
86 {
Ed Tanousac106bf2023-06-07 09:24:59 -070087 asyncResp->res.jsonValue["IndicatorLED"] = "Off";
Ed Tanous002d39b2022-05-31 08:59:27 -070088 }
89 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -070090 });
James Feist1c8fba92019-12-20 15:12:07 -080091}
92
93/**
94 * @brief Sets identify led group properties
95 *
Ed Tanousac106bf2023-06-07 09:24:59 -070096 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080097 * @param[in] ledState LED state passed from request
98 *
99 * @return None.
100 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500101// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +0800102inline void
Ed Tanousac106bf2023-06-07 09:24:59 -0700103 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800104 const std::string& ledState)
James Feist1c8fba92019-12-20 15:12:07 -0800105{
106 BMCWEB_LOG_DEBUG << "Set led groups";
107 bool ledOn = false;
108 bool ledBlinkng = false;
109
110 if (ledState == "Lit")
111 {
112 ledOn = true;
113 }
114 else if (ledState == "Blinking")
115 {
116 ledBlinkng = true;
117 }
118 else if (ledState != "Off")
119 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700120 messages::propertyValueNotInList(asyncResp->res, ledState,
121 "IndicatorLED");
James Feist1c8fba92019-12-20 15:12:07 -0800122 return;
123 }
124
125 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -0700126 [asyncResp, ledOn,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800127 ledBlinkng](const boost::system::error_code& ec) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -0700128 if (ec)
129 {
130 // Some systems may not have enclosure_identify_blink object so
131 // Lets set enclosure_identify state to true if Blinking is
132 // true.
133 if (ledBlinkng)
James Feist1c8fba92019-12-20 15:12:07 -0800134 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700135 ledOn = true;
James Feist1c8fba92019-12-20 15:12:07 -0800136 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700137 }
138 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -0700139 [asyncResp](const boost::system::error_code& ec2) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700140 if (ec2)
141 {
142 BMCWEB_LOG_DEBUG << "DBUS response error " << ec2;
Ed Tanousac106bf2023-06-07 09:24:59 -0700143 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700144 return;
145 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700146 messages::success(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700147 },
148 "xyz.openbmc_project.LED.GroupManager",
149 "/xyz/openbmc_project/led/groups/enclosure_identify",
150 "org.freedesktop.DBus.Properties", "Set",
151 "xyz.openbmc_project.Led.Group", "Asserted",
152 dbus::utility::DbusVariantType(ledOn));
James Feist1c8fba92019-12-20 15:12:07 -0800153 },
154 "xyz.openbmc_project.LED.GroupManager",
155 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
156 "org.freedesktop.DBus.Properties", "Set",
157 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanous168e20c2021-12-13 14:39:53 -0800158 dbus::utility::DbusVariantType(ledBlinkng));
James Feist1c8fba92019-12-20 15:12:07 -0800159}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500160
161/**
162 * @brief Retrieves identify led group properties over dbus
163 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700164 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500165 *
166 * @return None.
167 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700168inline void getLocationIndicatorActive(
169 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500170{
171 BMCWEB_LOG_DEBUG << "Get LocationIndicatorActive";
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700172 sdbusplus::asio::getProperty<bool>(
173 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
174 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
175 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700176 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700177 // Some systems may not have enclosure_identify_blink object so
178 // proceed to get enclosure_identify state.
179 if (ec == boost::system::errc::invalid_argument)
180 {
181 BMCWEB_LOG_DEBUG
182 << "Get identity blinking LED failed, missmatch in property type";
Ed Tanousac106bf2023-06-07 09:24:59 -0700183 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700184 return;
185 }
186
187 // Blinking ON, no need to check enclosure_identify assert.
188 if (!ec && blinking)
189 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700190 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Ed Tanous002d39b2022-05-31 08:59:27 -0700191 return;
192 }
193
194 sdbusplus::asio::getProperty<bool>(
195 *crow::connections::systemBus,
196 "xyz.openbmc_project.LED.GroupManager",
197 "/xyz/openbmc_project/led/groups/enclosure_identify",
198 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700199 [asyncResp](const boost::system::error_code& ec2,
200 const bool ledOn) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700201 if (ec2 == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500202 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700203 BMCWEB_LOG_DEBUG
Ed Tanous002d39b2022-05-31 08:59:27 -0700204 << "Get enclosure identity led failed, missmatch in property type";
Ed Tanousac106bf2023-06-07 09:24:59 -0700205 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700206 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500207 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500208
Ed Tanous002d39b2022-05-31 08:59:27 -0700209 if (ec2)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700210 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700211 return;
212 }
213
Ed Tanousac106bf2023-06-07 09:24:59 -0700214 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
Ed Tanous002d39b2022-05-31 08:59:27 -0700215 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700216 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500217}
218
219/**
220 * @brief Sets identify led group properties
221 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700222 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500223 * @param[in] ledState LED state passed from request
224 *
225 * @return None.
226 */
Ed Tanousac106bf2023-06-07 09:24:59 -0700227inline void setLocationIndicatorActive(
228 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500229{
230 BMCWEB_LOG_DEBUG << "Set LocationIndicatorActive";
231
232 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -0700233 [asyncResp, ledState](const boost::system::error_code& ec) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -0700234 if (ec)
235 {
236 // Some systems may not have enclosure_identify_blink object so
237 // lets set enclosure_identify state also if
238 // enclosure_identify_blink failed
239 crow::connections::systemBus->async_method_call(
Ed Tanousac106bf2023-06-07 09:24:59 -0700240 [asyncResp](const boost::system::error_code& ec2) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700241 if (ec2)
242 {
243 BMCWEB_LOG_DEBUG << "DBUS response error " << ec2;
Ed Tanousac106bf2023-06-07 09:24:59 -0700244 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700245 return;
246 }
247 },
248 "xyz.openbmc_project.LED.GroupManager",
249 "/xyz/openbmc_project/led/groups/enclosure_identify",
250 "org.freedesktop.DBus.Properties", "Set",
251 "xyz.openbmc_project.Led.Group", "Asserted",
252 dbus::utility::DbusVariantType(ledState));
253 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500254 },
255 "xyz.openbmc_project.LED.GroupManager",
256 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
257 "org.freedesktop.DBus.Properties", "Set",
258 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanous168e20c2021-12-13 14:39:53 -0800259 dbus::utility::DbusVariantType(ledState));
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500260}
Ed Tanous23a21a12020-07-25 04:45:05 +0000261} // namespace redfish