blob: 2f10584e7003377e087cdc2fb0d53eebdaf21c67 [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
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08006#include "app.hpp"
James Feist1c8fba92019-12-20 15:12:07 -08007#include "async_resp.hpp"
8#include "dbus_utility.hpp"
Ed Tanous539d8c62024-06-19 14:38:27 -07009#include "generated/enums/chassis.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080010#include "redfish_util.hpp"
11
Jonathan Doman1e1e5982021-06-11 09:36:17 -070012#include <sdbusplus/asio/property.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070013
James Feist1c8fba92019-12-20 15:12:07 -080014namespace redfish
15{
16/**
17 * @brief Retrieves identify led group properties over dbus
18 *
Ed Tanousac106bf2023-06-07 09:24:59 -070019 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080020 *
21 * @return None.
22 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -050023// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +080024inline void
Ed Tanousac106bf2023-06-07 09:24:59 -070025 getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist1c8fba92019-12-20 15:12:07 -080026{
Ed Tanous62598e32023-07-17 17:06:25 -070027 BMCWEB_LOG_DEBUG("Get led groups");
Ed Tanousdeae6a72024-11-11 21:58:57 -080028 dbus::utility::getProperty<bool>(
29 "xyz.openbmc_project.LED.GroupManager",
Jonathan Doman1e1e5982021-06-11 09:36:17 -070030 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
31 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -070032 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040033 // Some systems may not have enclosure_identify_blink object so
34 // proceed to get enclosure_identify state.
35 if (ec == boost::system::errc::invalid_argument)
James Feist1c8fba92019-12-20 15:12:07 -080036 {
Ed Tanous62598e32023-07-17 17:06:25 -070037 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -040038 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -070039 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -070040 return;
James Feist1c8fba92019-12-20 15:12:07 -080041 }
James Feist1c8fba92019-12-20 15:12:07 -080042
Patrick Williamsbd79bce2024-08-16 15:22:20 -040043 // Blinking ON, no need to check enclosure_identify assert.
44 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -070045 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040046 asyncResp->res.jsonValue["IndicatorLED"] =
47 chassis::IndicatorLED::Blinking;
Jonathan Doman1e1e5982021-06-11 09:36:17 -070048 return;
49 }
50
Ed Tanousdeae6a72024-11-11 21:58:57 -080051 dbus::utility::getProperty<bool>(
Patrick Williamsbd79bce2024-08-16 15:22:20 -040052 "xyz.openbmc_project.LED.GroupManager",
53 "/xyz/openbmc_project/led/groups/enclosure_identify",
54 "xyz.openbmc_project.Led.Group", "Asserted",
55 [asyncResp](const boost::system::error_code& ec2,
56 const bool ledOn) {
57 if (ec2 == boost::system::errc::invalid_argument)
58 {
59 BMCWEB_LOG_DEBUG(
60 "Get enclosure identity led failed, mismatch in property type");
61 messages::internalError(asyncResp->res);
62 return;
63 }
64
65 if (ec2)
66 {
67 return;
68 }
69
70 if (ledOn)
71 {
72 asyncResp->res.jsonValue["IndicatorLED"] =
73 chassis::IndicatorLED::Lit;
74 }
75 else
76 {
77 asyncResp->res.jsonValue["IndicatorLED"] =
78 chassis::IndicatorLED::Off;
79 }
80 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -070081 });
James Feist1c8fba92019-12-20 15:12:07 -080082}
83
84/**
85 * @brief Sets identify led group properties
86 *
Ed Tanousac106bf2023-06-07 09:24:59 -070087 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080088 * @param[in] ledState LED state passed from request
89 *
90 * @return None.
91 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -050092// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +080093inline void
Ed Tanousac106bf2023-06-07 09:24:59 -070094 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +080095 const std::string& ledState)
James Feist1c8fba92019-12-20 15:12:07 -080096{
Ed Tanous62598e32023-07-17 17:06:25 -070097 BMCWEB_LOG_DEBUG("Set led groups");
James Feist1c8fba92019-12-20 15:12:07 -080098 bool ledOn = false;
99 bool ledBlinkng = false;
100
101 if (ledState == "Lit")
102 {
103 ledOn = true;
104 }
105 else if (ledState == "Blinking")
106 {
107 ledBlinkng = true;
108 }
109 else if (ledState != "Off")
110 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700111 messages::propertyValueNotInList(asyncResp->res, ledState,
112 "IndicatorLED");
James Feist1c8fba92019-12-20 15:12:07 -0800113 return;
114 }
115
George Liu9ae226f2023-06-21 17:56:46 +0800116 sdbusplus::asio::setProperty(
117 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
118 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
119 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
Ed Tanousac106bf2023-06-07 09:24:59 -0700120 [asyncResp, ledOn,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800121 ledBlinkng](const boost::system::error_code& ec) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400122 if (ec)
James Feist1c8fba92019-12-20 15:12:07 -0800123 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400124 // Some systems may not have enclosure_identify_blink object so
125 // Lets set enclosure_identify state to true if Blinking is
126 // true.
127 if (ledBlinkng)
128 {
129 ledOn = true;
130 }
James Feist1c8fba92019-12-20 15:12:07 -0800131 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400132 setDbusProperty(
133 asyncResp, "IndicatorLED",
134 "xyz.openbmc_project.LED.GroupManager",
135 sdbusplus::message::object_path(
136 "/xyz/openbmc_project/led/groups/enclosure_identify"),
137 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
138 });
James Feist1c8fba92019-12-20 15:12:07 -0800139}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500140
141/**
George Liu59a17e42022-10-08 09:27:47 +0800142 * @brief Retrieves identify system led group properties over dbus
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500143 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700144 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500145 *
146 * @return None.
147 */
George Liu59a17e42022-10-08 09:27:47 +0800148inline void getSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700149 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500150{
Ed Tanous62598e32023-07-17 17:06:25 -0700151 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800152 dbus::utility::getProperty<bool>(
153 "xyz.openbmc_project.LED.GroupManager",
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700154 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
155 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700156 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400157 // Some systems may not have enclosure_identify_blink object so
158 // proceed to get enclosure_identify state.
159 if (ec == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500160 {
Ed Tanous62598e32023-07-17 17:06:25 -0700161 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400162 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700163 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700164 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500165 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500166
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400167 // Blinking ON, no need to check enclosure_identify assert.
168 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700169 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400170 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700171 return;
172 }
173
Ed Tanousdeae6a72024-11-11 21:58:57 -0800174 dbus::utility::getProperty<bool>(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400175 "xyz.openbmc_project.LED.GroupManager",
176 "/xyz/openbmc_project/led/groups/enclosure_identify",
177 "xyz.openbmc_project.Led.Group", "Asserted",
178 [asyncResp](const boost::system::error_code& ec2,
179 const bool ledOn) {
180 if (ec2 == boost::system::errc::invalid_argument)
181 {
182 BMCWEB_LOG_DEBUG(
183 "Get enclosure identity led failed, mismatch in property type");
184 messages::internalError(asyncResp->res);
185 return;
186 }
187
188 if (ec2)
189 {
190 return;
191 }
192
193 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
194 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700195 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500196}
197
198/**
George Liu59a17e42022-10-08 09:27:47 +0800199 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500200 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700201 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500202 * @param[in] ledState LED state passed from request
203 *
204 * @return None.
205 */
George Liu59a17e42022-10-08 09:27:47 +0800206inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700207 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500208{
Ed Tanous62598e32023-07-17 17:06:25 -0700209 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500210
George Liu9ae226f2023-06-21 17:56:46 +0800211 sdbusplus::asio::setProperty(
212 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
213 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
214 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
215 [asyncResp, ledState](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400216 if (ec)
217 {
218 // Some systems may not have enclosure_identify_blink object so
219 // lets set enclosure_identify state also if
220 // enclosure_identify_blink failed
221 setDbusProperty(
222 asyncResp, "LocationIndicatorActive",
223 "xyz.openbmc_project.LED.GroupManager",
224 sdbusplus::message::object_path(
225 "/xyz/openbmc_project/led/groups/enclosure_identify"),
226 "xyz.openbmc_project.Led.Group", "Asserted", ledState);
227 }
228 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500229}
Ed Tanous23a21a12020-07-25 04:45:05 +0000230} // namespace redfish