blob: b5d12fb8656e16aafa2dc17a01975a37c607c437 [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{
Ed Tanous62598e32023-07-17 17:06:25 -070038 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 {
Ed Tanous62598e32023-07-17 17:06:25 -070048 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 {
Ed Tanous62598e32023-07-17 17:06:25 -070070 BMCWEB_LOG_DEBUG(
71 "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 }
Jonathan Doman1e1e5982021-06-11 09:36:17 -070089 });
Patrick Williams5a39f772023-10-20 11:20:21 -050090 });
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{
Ed Tanous62598e32023-07-17 17:06:25 -0700106 BMCWEB_LOG_DEBUG("Set led groups");
James Feist1c8fba92019-12-20 15:12:07 -0800107 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
George Liu9ae226f2023-06-21 17:56:46 +0800125 sdbusplus::asio::setProperty(
126 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
127 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
128 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
Ed Tanousac106bf2023-06-07 09:24:59 -0700129 [asyncResp, ledOn,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800130 ledBlinkng](const boost::system::error_code& ec) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -0700131 if (ec)
132 {
133 // Some systems may not have enclosure_identify_blink object so
134 // Lets set enclosure_identify state to true if Blinking is
135 // true.
136 if (ledBlinkng)
James Feist1c8fba92019-12-20 15:12:07 -0800137 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700138 ledOn = true;
James Feist1c8fba92019-12-20 15:12:07 -0800139 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700140 }
George Liu9ae226f2023-06-21 17:56:46 +0800141 sdbusplus::asio::setProperty(
142 *crow::connections::systemBus,
143 "xyz.openbmc_project.LED.GroupManager",
144 "/xyz/openbmc_project/led/groups/enclosure_identify",
145 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
Ed Tanousac106bf2023-06-07 09:24:59 -0700146 [asyncResp](const boost::system::error_code& ec2) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700147 if (ec2)
148 {
Ed Tanous62598e32023-07-17 17:06:25 -0700149 BMCWEB_LOG_DEBUG("DBUS response error {}", ec2);
Ed Tanousac106bf2023-06-07 09:24:59 -0700150 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700151 return;
152 }
Ed Tanousac106bf2023-06-07 09:24:59 -0700153 messages::success(asyncResp->res);
George Liu9ae226f2023-06-21 17:56:46 +0800154 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500155 });
James Feist1c8fba92019-12-20 15:12:07 -0800156}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500157
158/**
George Liu59a17e42022-10-08 09:27:47 +0800159 * @brief Retrieves identify system led group properties over dbus
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500160 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700161 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500162 *
163 * @return None.
164 */
George Liu59a17e42022-10-08 09:27:47 +0800165inline void getSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700166 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500167{
Ed Tanous62598e32023-07-17 17:06:25 -0700168 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700169 sdbusplus::asio::getProperty<bool>(
170 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
171 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
172 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700173 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700174 // Some systems may not have enclosure_identify_blink object so
175 // proceed to get enclosure_identify state.
176 if (ec == boost::system::errc::invalid_argument)
177 {
Ed Tanous62598e32023-07-17 17:06:25 -0700178 BMCWEB_LOG_DEBUG(
179 "Get identity blinking LED failed, missmatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700180 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700181 return;
182 }
183
184 // Blinking ON, no need to check enclosure_identify assert.
185 if (!ec && blinking)
186 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700187 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Ed Tanous002d39b2022-05-31 08:59:27 -0700188 return;
189 }
190
191 sdbusplus::asio::getProperty<bool>(
192 *crow::connections::systemBus,
193 "xyz.openbmc_project.LED.GroupManager",
194 "/xyz/openbmc_project/led/groups/enclosure_identify",
195 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700196 [asyncResp](const boost::system::error_code& ec2,
197 const bool ledOn) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700198 if (ec2 == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500199 {
Ed Tanous62598e32023-07-17 17:06:25 -0700200 BMCWEB_LOG_DEBUG(
201 "Get enclosure identity led failed, missmatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700202 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700203 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500204 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500205
Ed Tanous002d39b2022-05-31 08:59:27 -0700206 if (ec2)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700207 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700208 return;
209 }
210
Ed Tanousac106bf2023-06-07 09:24:59 -0700211 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700212 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500213 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500214}
215
216/**
George Liu59a17e42022-10-08 09:27:47 +0800217 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500218 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700219 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500220 * @param[in] ledState LED state passed from request
221 *
222 * @return None.
223 */
George Liu59a17e42022-10-08 09:27:47 +0800224inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700225 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500226{
Ed Tanous62598e32023-07-17 17:06:25 -0700227 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500228
George Liu9ae226f2023-06-21 17:56:46 +0800229 sdbusplus::asio::setProperty(
230 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
231 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
232 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
233 [asyncResp, ledState](const boost::system::error_code& ec) {
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
George Liu9ae226f2023-06-21 17:56:46 +0800239 sdbusplus::asio::setProperty(
240 *crow::connections::systemBus,
241 "xyz.openbmc_project.LED.GroupManager",
242 "/xyz/openbmc_project/led/groups/enclosure_identify",
243 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
Ed Tanousac106bf2023-06-07 09:24:59 -0700244 [asyncResp](const boost::system::error_code& ec2) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700245 if (ec2)
246 {
Ed Tanous62598e32023-07-17 17:06:25 -0700247 BMCWEB_LOG_DEBUG("DBUS response error {}", ec2);
Ed Tanousac106bf2023-06-07 09:24:59 -0700248 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700249 return;
250 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500251 });
Ed Tanous002d39b2022-05-31 08:59:27 -0700252 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500253 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500254}
Ed Tanous23a21a12020-07-25 04:45:05 +0000255} // namespace redfish