blob: 2bb2cc842daf6ad4c5879bf83b0fb052f996d684 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
3// SPDX-FileCopyrightText: Copyright 2019 Intel Corporation
James Feist1c8fba92019-12-20 15:12:07 -08004#pragma once
5
6#include "async_resp.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08007#include "dbus_singleton.hpp"
James Feist1c8fba92019-12-20 15:12:07 -08008#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08009#include "error_messages.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -070010#include "generated/enums/chassis.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080011#include "logging.hpp"
12#include "utils/dbus_utils.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080013
Jonathan Doman1e1e5982021-06-11 09:36:17 -070014#include <sdbusplus/asio/property.hpp>
Ed Tanousd7857202025-01-28 15:32:26 -080015#include <sdbusplus/message/native_types.hpp>
16
17#include <memory>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070018
James Feist1c8fba92019-12-20 15:12:07 -080019namespace redfish
20{
21/**
22 * @brief Retrieves identify led group properties over dbus
23 *
Ed Tanousac106bf2023-06-07 09:24:59 -070024 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080025 *
26 * @return None.
27 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -050028// TODO (Gunnar): Remove IndicatorLED after enough time has passed
Patrick Williams504af5a2025-02-03 14:29:03 -050029inline void getIndicatorLedState(
30 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist1c8fba92019-12-20 15:12:07 -080031{
Ed Tanous62598e32023-07-17 17:06:25 -070032 BMCWEB_LOG_DEBUG("Get led groups");
Ed Tanousdeae6a72024-11-11 21:58:57 -080033 dbus::utility::getProperty<bool>(
34 "xyz.openbmc_project.LED.GroupManager",
Jonathan Doman1e1e5982021-06-11 09:36:17 -070035 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
36 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -070037 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040038 // Some systems may not have enclosure_identify_blink object so
39 // proceed to get enclosure_identify state.
40 if (ec == boost::system::errc::invalid_argument)
James Feist1c8fba92019-12-20 15:12:07 -080041 {
Ed Tanous62598e32023-07-17 17:06:25 -070042 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -040043 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -070044 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -070045 return;
James Feist1c8fba92019-12-20 15:12:07 -080046 }
James Feist1c8fba92019-12-20 15:12:07 -080047
Patrick Williamsbd79bce2024-08-16 15:22:20 -040048 // Blinking ON, no need to check enclosure_identify assert.
49 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -070050 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040051 asyncResp->res.jsonValue["IndicatorLED"] =
52 chassis::IndicatorLED::Blinking;
Jonathan Doman1e1e5982021-06-11 09:36:17 -070053 return;
54 }
55
Ed Tanousdeae6a72024-11-11 21:58:57 -080056 dbus::utility::getProperty<bool>(
Patrick Williamsbd79bce2024-08-16 15:22:20 -040057 "xyz.openbmc_project.LED.GroupManager",
58 "/xyz/openbmc_project/led/groups/enclosure_identify",
59 "xyz.openbmc_project.Led.Group", "Asserted",
60 [asyncResp](const boost::system::error_code& ec2,
61 const bool ledOn) {
62 if (ec2 == boost::system::errc::invalid_argument)
63 {
64 BMCWEB_LOG_DEBUG(
65 "Get enclosure identity led failed, mismatch in property type");
66 messages::internalError(asyncResp->res);
67 return;
68 }
69
70 if (ec2)
71 {
72 return;
73 }
74
75 if (ledOn)
76 {
77 asyncResp->res.jsonValue["IndicatorLED"] =
78 chassis::IndicatorLED::Lit;
79 }
80 else
81 {
82 asyncResp->res.jsonValue["IndicatorLED"] =
83 chassis::IndicatorLED::Off;
84 }
85 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -070086 });
James Feist1c8fba92019-12-20 15:12:07 -080087}
88
89/**
90 * @brief Sets identify led group properties
91 *
Ed Tanousac106bf2023-06-07 09:24:59 -070092 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080093 * @param[in] ledState LED state passed from request
94 *
95 * @return None.
96 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -050097// TODO (Gunnar): Remove IndicatorLED after enough time has passed
Patrick Williams504af5a2025-02-03 14:29:03 -050098inline void setIndicatorLedState(
99 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
100 const std::string& ledState)
James Feist1c8fba92019-12-20 15:12:07 -0800101{
Ed Tanous62598e32023-07-17 17:06:25 -0700102 BMCWEB_LOG_DEBUG("Set led groups");
James Feist1c8fba92019-12-20 15:12:07 -0800103 bool ledOn = false;
104 bool ledBlinkng = false;
105
106 if (ledState == "Lit")
107 {
108 ledOn = true;
109 }
110 else if (ledState == "Blinking")
111 {
112 ledBlinkng = true;
113 }
114 else if (ledState != "Off")
115 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700116 messages::propertyValueNotInList(asyncResp->res, ledState,
117 "IndicatorLED");
James Feist1c8fba92019-12-20 15:12:07 -0800118 return;
119 }
120
George Liu9ae226f2023-06-21 17:56:46 +0800121 sdbusplus::asio::setProperty(
122 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
123 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
124 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
Ed Tanousac106bf2023-06-07 09:24:59 -0700125 [asyncResp, ledOn,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800126 ledBlinkng](const boost::system::error_code& ec) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400127 if (ec)
James Feist1c8fba92019-12-20 15:12:07 -0800128 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400129 // Some systems may not have enclosure_identify_blink object so
130 // Lets set enclosure_identify state to true if Blinking is
131 // true.
132 if (ledBlinkng)
133 {
134 ledOn = true;
135 }
James Feist1c8fba92019-12-20 15:12:07 -0800136 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400137 setDbusProperty(
138 asyncResp, "IndicatorLED",
139 "xyz.openbmc_project.LED.GroupManager",
140 sdbusplus::message::object_path(
141 "/xyz/openbmc_project/led/groups/enclosure_identify"),
142 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
143 });
James Feist1c8fba92019-12-20 15:12:07 -0800144}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500145
146/**
George Liu59a17e42022-10-08 09:27:47 +0800147 * @brief Retrieves identify system led group properties over dbus
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500148 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700149 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500150 *
151 * @return None.
152 */
George Liu59a17e42022-10-08 09:27:47 +0800153inline void getSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700154 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500155{
Ed Tanous62598e32023-07-17 17:06:25 -0700156 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800157 dbus::utility::getProperty<bool>(
158 "xyz.openbmc_project.LED.GroupManager",
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700159 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
160 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700161 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400162 // Some systems may not have enclosure_identify_blink object so
163 // proceed to get enclosure_identify state.
164 if (ec == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500165 {
Ed Tanous62598e32023-07-17 17:06:25 -0700166 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400167 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700168 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700169 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500170 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500171
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400172 // Blinking ON, no need to check enclosure_identify assert.
173 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700174 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400175 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700176 return;
177 }
178
Ed Tanousdeae6a72024-11-11 21:58:57 -0800179 dbus::utility::getProperty<bool>(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400180 "xyz.openbmc_project.LED.GroupManager",
181 "/xyz/openbmc_project/led/groups/enclosure_identify",
182 "xyz.openbmc_project.Led.Group", "Asserted",
183 [asyncResp](const boost::system::error_code& ec2,
184 const bool ledOn) {
185 if (ec2 == boost::system::errc::invalid_argument)
186 {
187 BMCWEB_LOG_DEBUG(
188 "Get enclosure identity led failed, mismatch in property type");
189 messages::internalError(asyncResp->res);
190 return;
191 }
192
193 if (ec2)
194 {
195 return;
196 }
197
198 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
199 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700200 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500201}
202
203/**
George Liu59a17e42022-10-08 09:27:47 +0800204 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500205 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700206 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500207 * @param[in] ledState LED state passed from request
208 *
209 * @return None.
210 */
George Liu59a17e42022-10-08 09:27:47 +0800211inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700212 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500213{
Ed Tanous62598e32023-07-17 17:06:25 -0700214 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500215
George Liu9ae226f2023-06-21 17:56:46 +0800216 sdbusplus::asio::setProperty(
217 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
218 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
219 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
220 [asyncResp, ledState](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400221 if (ec)
222 {
223 // Some systems may not have enclosure_identify_blink object so
224 // lets set enclosure_identify state also if
225 // enclosure_identify_blink failed
226 setDbusProperty(
227 asyncResp, "LocationIndicatorActive",
228 "xyz.openbmc_project.LED.GroupManager",
229 sdbusplus::message::object_path(
230 "/xyz/openbmc_project/led/groups/enclosure_identify"),
231 "xyz.openbmc_project.Led.Group", "Asserted", ledState);
232 }
233 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500234}
Ed Tanous23a21a12020-07-25 04:45:05 +0000235} // namespace redfish