blob: 8cbe86ac94e56e1c4407667a5e45056523d83bc9 [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(
Ginu Georgee93abac2024-06-14 17:35:27 +0530142 asyncResp, "IndicatorLED", "xyz.openbmc_project.LED.GroupManager",
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000143 sdbusplus::message::object_path(
144 "/xyz/openbmc_project/led/groups/enclosure_identify"),
Ginu Georgee93abac2024-06-14 17:35:27 +0530145 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
Patrick Williams5a39f772023-10-20 11:20:21 -0500146 });
James Feist1c8fba92019-12-20 15:12:07 -0800147}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500148
149/**
George Liu59a17e42022-10-08 09:27:47 +0800150 * @brief Retrieves identify system led group properties over dbus
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500151 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700152 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500153 *
154 * @return None.
155 */
George Liu59a17e42022-10-08 09:27:47 +0800156inline void getSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700157 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500158{
Ed Tanous62598e32023-07-17 17:06:25 -0700159 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700160 sdbusplus::asio::getProperty<bool>(
161 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
162 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
163 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700164 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700165 // Some systems may not have enclosure_identify_blink object so
166 // proceed to get enclosure_identify state.
167 if (ec == boost::system::errc::invalid_argument)
168 {
Ed Tanous62598e32023-07-17 17:06:25 -0700169 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -0800170 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700171 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700172 return;
173 }
174
175 // Blinking ON, no need to check enclosure_identify assert.
176 if (!ec && blinking)
177 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700178 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Ed Tanous002d39b2022-05-31 08:59:27 -0700179 return;
180 }
181
182 sdbusplus::asio::getProperty<bool>(
183 *crow::connections::systemBus,
184 "xyz.openbmc_project.LED.GroupManager",
185 "/xyz/openbmc_project/led/groups/enclosure_identify",
186 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700187 [asyncResp](const boost::system::error_code& ec2,
188 const bool ledOn) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700189 if (ec2 == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500190 {
Ed Tanous62598e32023-07-17 17:06:25 -0700191 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -0800192 "Get enclosure identity led failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700193 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700194 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500195 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500196
Ed Tanous002d39b2022-05-31 08:59:27 -0700197 if (ec2)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700198 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700199 return;
200 }
201
Ed Tanousac106bf2023-06-07 09:24:59 -0700202 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700203 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500204 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500205}
206
207/**
George Liu59a17e42022-10-08 09:27:47 +0800208 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500209 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700210 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500211 * @param[in] ledState LED state passed from request
212 *
213 * @return None.
214 */
George Liu59a17e42022-10-08 09:27:47 +0800215inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700216 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500217{
Ed Tanous62598e32023-07-17 17:06:25 -0700218 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500219
George Liu9ae226f2023-06-21 17:56:46 +0800220 sdbusplus::asio::setProperty(
221 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
222 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
223 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
224 [asyncResp, ledState](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700225 if (ec)
226 {
227 // Some systems may not have enclosure_identify_blink object so
228 // lets set enclosure_identify state also if
229 // enclosure_identify_blink failed
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000230 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530231 asyncResp, "LocationIndicatorActive",
232 "xyz.openbmc_project.LED.GroupManager",
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000233 sdbusplus::message::object_path(
234 "/xyz/openbmc_project/led/groups/enclosure_identify"),
Ginu Georgee93abac2024-06-14 17:35:27 +0530235 "xyz.openbmc_project.Led.Group", "Asserted", ledState);
Ed Tanous002d39b2022-05-31 08:59:27 -0700236 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500237 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500238}
Ed Tanous23a21a12020-07-25 04:45:05 +0000239} // namespace redfish