blob: d4f4b654b79afd1648901e1b1f2fe8929d2347e6 [file] [log] [blame]
James Feist1c8fba92019-12-20 15:12:07 -08001/*
Ed Tanous6be832e2024-09-10 11:44:48 -07002Copyright (c) 2019 Intel Corporation
3
4Licensed under the Apache License, Version 2.0 (the "License");
5you may not use this file except in compliance with the License.
6You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10Unless required by applicable law or agreed to in writing, software
11distributed under the License is distributed on an "AS IS" BASIS,
12WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13See the License for the specific language governing permissions and
14limitations under the License.
James Feist1c8fba92019-12-20 15:12:07 -080015*/
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"
Ed Tanous539d8c62024-06-19 14:38:27 -070021#include "generated/enums/chassis.hpp"
James Feist1c8fba92019-12-20 15:12:07 -080022#include "redfish_util.hpp"
23
Jonathan Doman1e1e5982021-06-11 09:36:17 -070024#include <sdbusplus/asio/property.hpp>
John Edward Broadbent7e860f12021-04-08 15:57:16 -070025
James Feist1c8fba92019-12-20 15:12:07 -080026namespace redfish
27{
28/**
29 * @brief Retrieves identify led group properties over dbus
30 *
Ed Tanousac106bf2023-06-07 09:24:59 -070031 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -080032 *
33 * @return None.
34 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -050035// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +080036inline void
Ed Tanousac106bf2023-06-07 09:24:59 -070037 getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist1c8fba92019-12-20 15:12:07 -080038{
Ed Tanous62598e32023-07-17 17:06:25 -070039 BMCWEB_LOG_DEBUG("Get led groups");
Ed Tanousdeae6a72024-11-11 21:58:57 -080040 dbus::utility::getProperty<bool>(
41 "xyz.openbmc_project.LED.GroupManager",
Jonathan Doman1e1e5982021-06-11 09:36:17 -070042 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
43 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -070044 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040045 // Some systems may not have enclosure_identify_blink object so
46 // proceed to get enclosure_identify state.
47 if (ec == boost::system::errc::invalid_argument)
James Feist1c8fba92019-12-20 15:12:07 -080048 {
Ed Tanous62598e32023-07-17 17:06:25 -070049 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -040050 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -070051 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -070052 return;
James Feist1c8fba92019-12-20 15:12:07 -080053 }
James Feist1c8fba92019-12-20 15:12:07 -080054
Patrick Williamsbd79bce2024-08-16 15:22:20 -040055 // Blinking ON, no need to check enclosure_identify assert.
56 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -070057 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040058 asyncResp->res.jsonValue["IndicatorLED"] =
59 chassis::IndicatorLED::Blinking;
Jonathan Doman1e1e5982021-06-11 09:36:17 -070060 return;
61 }
62
Ed Tanousdeae6a72024-11-11 21:58:57 -080063 dbus::utility::getProperty<bool>(
Patrick Williamsbd79bce2024-08-16 15:22:20 -040064 "xyz.openbmc_project.LED.GroupManager",
65 "/xyz/openbmc_project/led/groups/enclosure_identify",
66 "xyz.openbmc_project.Led.Group", "Asserted",
67 [asyncResp](const boost::system::error_code& ec2,
68 const bool ledOn) {
69 if (ec2 == boost::system::errc::invalid_argument)
70 {
71 BMCWEB_LOG_DEBUG(
72 "Get enclosure identity led failed, mismatch in property type");
73 messages::internalError(asyncResp->res);
74 return;
75 }
76
77 if (ec2)
78 {
79 return;
80 }
81
82 if (ledOn)
83 {
84 asyncResp->res.jsonValue["IndicatorLED"] =
85 chassis::IndicatorLED::Lit;
86 }
87 else
88 {
89 asyncResp->res.jsonValue["IndicatorLED"] =
90 chassis::IndicatorLED::Off;
91 }
92 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -070093 });
James Feist1c8fba92019-12-20 15:12:07 -080094}
95
96/**
97 * @brief Sets identify led group properties
98 *
Ed Tanousac106bf2023-06-07 09:24:59 -070099 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -0800100 * @param[in] ledState LED state passed from request
101 *
102 * @return None.
103 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500104// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +0800105inline void
Ed Tanousac106bf2023-06-07 09:24:59 -0700106 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800107 const std::string& ledState)
James Feist1c8fba92019-12-20 15:12:07 -0800108{
Ed Tanous62598e32023-07-17 17:06:25 -0700109 BMCWEB_LOG_DEBUG("Set led groups");
James Feist1c8fba92019-12-20 15:12:07 -0800110 bool ledOn = false;
111 bool ledBlinkng = false;
112
113 if (ledState == "Lit")
114 {
115 ledOn = true;
116 }
117 else if (ledState == "Blinking")
118 {
119 ledBlinkng = true;
120 }
121 else if (ledState != "Off")
122 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700123 messages::propertyValueNotInList(asyncResp->res, ledState,
124 "IndicatorLED");
James Feist1c8fba92019-12-20 15:12:07 -0800125 return;
126 }
127
George Liu9ae226f2023-06-21 17:56:46 +0800128 sdbusplus::asio::setProperty(
129 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
130 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
131 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
Ed Tanousac106bf2023-06-07 09:24:59 -0700132 [asyncResp, ledOn,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800133 ledBlinkng](const boost::system::error_code& ec) mutable {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400134 if (ec)
James Feist1c8fba92019-12-20 15:12:07 -0800135 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400136 // Some systems may not have enclosure_identify_blink object so
137 // Lets set enclosure_identify state to true if Blinking is
138 // true.
139 if (ledBlinkng)
140 {
141 ledOn = true;
142 }
James Feist1c8fba92019-12-20 15:12:07 -0800143 }
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400144 setDbusProperty(
145 asyncResp, "IndicatorLED",
146 "xyz.openbmc_project.LED.GroupManager",
147 sdbusplus::message::object_path(
148 "/xyz/openbmc_project/led/groups/enclosure_identify"),
149 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
150 });
James Feist1c8fba92019-12-20 15:12:07 -0800151}
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500152
153/**
George Liu59a17e42022-10-08 09:27:47 +0800154 * @brief Retrieves identify system led group properties over dbus
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500155 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700156 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500157 *
158 * @return None.
159 */
George Liu59a17e42022-10-08 09:27:47 +0800160inline void getSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700161 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500162{
Ed Tanous62598e32023-07-17 17:06:25 -0700163 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
Ed Tanousdeae6a72024-11-11 21:58:57 -0800164 dbus::utility::getProperty<bool>(
165 "xyz.openbmc_project.LED.GroupManager",
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700166 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
167 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700168 [asyncResp](const boost::system::error_code& ec, const bool blinking) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400169 // Some systems may not have enclosure_identify_blink object so
170 // proceed to get enclosure_identify state.
171 if (ec == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500172 {
Ed Tanous62598e32023-07-17 17:06:25 -0700173 BMCWEB_LOG_DEBUG(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400174 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700175 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700176 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500177 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500178
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400179 // Blinking ON, no need to check enclosure_identify assert.
180 if (!ec && blinking)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700181 {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400182 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700183 return;
184 }
185
Ed Tanousdeae6a72024-11-11 21:58:57 -0800186 dbus::utility::getProperty<bool>(
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400187 "xyz.openbmc_project.LED.GroupManager",
188 "/xyz/openbmc_project/led/groups/enclosure_identify",
189 "xyz.openbmc_project.Led.Group", "Asserted",
190 [asyncResp](const boost::system::error_code& ec2,
191 const bool ledOn) {
192 if (ec2 == boost::system::errc::invalid_argument)
193 {
194 BMCWEB_LOG_DEBUG(
195 "Get enclosure identity led failed, mismatch in property type");
196 messages::internalError(asyncResp->res);
197 return;
198 }
199
200 if (ec2)
201 {
202 return;
203 }
204
205 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
206 });
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700207 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500208}
209
210/**
George Liu59a17e42022-10-08 09:27:47 +0800211 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500212 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700213 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500214 * @param[in] ledState LED state passed from request
215 *
216 * @return None.
217 */
George Liu59a17e42022-10-08 09:27:47 +0800218inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700219 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500220{
Ed Tanous62598e32023-07-17 17:06:25 -0700221 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500222
George Liu9ae226f2023-06-21 17:56:46 +0800223 sdbusplus::asio::setProperty(
224 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
225 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
226 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
227 [asyncResp, ledState](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400228 if (ec)
229 {
230 // Some systems may not have enclosure_identify_blink object so
231 // lets set enclosure_identify state also if
232 // enclosure_identify_blink failed
233 setDbusProperty(
234 asyncResp, "LocationIndicatorActive",
235 "xyz.openbmc_project.LED.GroupManager",
236 sdbusplus::message::object_path(
237 "/xyz/openbmc_project/led/groups/enclosure_identify"),
238 "xyz.openbmc_project.Led.Group", "Asserted", ledState);
239 }
240 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500241}
Ed Tanous23a21a12020-07-25 04:45:05 +0000242} // namespace redfish