blob: c310e3f2cf264bb2ff870d11f3030f7659c6b386 [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(
Ed Tanous8ece0e42024-01-02 13:16:50 -080049 "Get identity blinking LED failed, mismatch 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(
Ed Tanous8ece0e42024-01-02 13:16:50 -080071 "Get enclosure identity led failed, mismatch 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 }
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000141 setDbusProperty(
142 asyncResp, "xyz.openbmc_project.LED.GroupManager",
143 sdbusplus::message::object_path(
144 "/xyz/openbmc_project/led/groups/enclosure_identify"),
145 "xyz.openbmc_project.Led.Group", "Asserted", "IndicatorLED",
146 ledBlinkng);
Patrick Williams5a39f772023-10-20 11:20:21 -0500147 });
James Feist1c8fba92019-12-20 15:12:07 -0800148}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500149
150/**
George Liu59a17e42022-10-08 09:27:47 +0800151 * @brief Retrieves identify system led group properties over dbus
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500152 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700153 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500154 *
155 * @return None.
156 */
George Liu59a17e42022-10-08 09:27:47 +0800157inline void getSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700158 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500159{
Ed Tanous62598e32023-07-17 17:06:25 -0700160 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700161 sdbusplus::asio::getProperty<bool>(
162 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
163 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
164 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700165 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700166 // Some systems may not have enclosure_identify_blink object so
167 // proceed to get enclosure_identify state.
168 if (ec == boost::system::errc::invalid_argument)
169 {
Ed Tanous62598e32023-07-17 17:06:25 -0700170 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -0800171 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700172 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700173 return;
174 }
175
176 // Blinking ON, no need to check enclosure_identify assert.
177 if (!ec && blinking)
178 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700179 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Ed Tanous002d39b2022-05-31 08:59:27 -0700180 return;
181 }
182
183 sdbusplus::asio::getProperty<bool>(
184 *crow::connections::systemBus,
185 "xyz.openbmc_project.LED.GroupManager",
186 "/xyz/openbmc_project/led/groups/enclosure_identify",
187 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700188 [asyncResp](const boost::system::error_code& ec2,
189 const bool ledOn) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700190 if (ec2 == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500191 {
Ed Tanous62598e32023-07-17 17:06:25 -0700192 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -0800193 "Get enclosure identity led failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700194 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700195 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500196 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500197
Ed Tanous002d39b2022-05-31 08:59:27 -0700198 if (ec2)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700199 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700200 return;
201 }
202
Ed Tanousac106bf2023-06-07 09:24:59 -0700203 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700204 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500205 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500206}
207
208/**
George Liu59a17e42022-10-08 09:27:47 +0800209 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500210 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700211 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500212 * @param[in] ledState LED state passed from request
213 *
214 * @return None.
215 */
George Liu59a17e42022-10-08 09:27:47 +0800216inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700217 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500218{
Ed Tanous62598e32023-07-17 17:06:25 -0700219 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500220
George Liu9ae226f2023-06-21 17:56:46 +0800221 sdbusplus::asio::setProperty(
222 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
223 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
224 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
225 [asyncResp, ledState](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700226 if (ec)
227 {
228 // Some systems may not have enclosure_identify_blink object so
229 // lets set enclosure_identify state also if
230 // enclosure_identify_blink failed
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000231 setDbusProperty(
232 asyncResp, "xyz.openbmc_project.LED.GroupManager",
233 sdbusplus::message::object_path(
234 "/xyz/openbmc_project/led/groups/enclosure_identify"),
235 "xyz.openbmc_project.Led.Group", "Asserted",
236 "LocationIndicatorActive", ledState);
Ed Tanous002d39b2022-05-31 08:59:27 -0700237 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500238 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500239}
Ed Tanous23a21a12020-07-25 04:45:05 +0000240} // namespace redfish