blob: b54edb03c728b8f1bb3923318b11cd5a2a36b8a5 [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"
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");
Jonathan Doman1e1e5982021-06-11 09:36:17 -070040 sdbusplus::asio::getProperty<bool>(
41 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
42 "/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) {
Ed Tanous002d39b2022-05-31 08:59:27 -070045 // 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)
48 {
Ed Tanous62598e32023-07-17 17:06:25 -070049 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -080050 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -070051 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -070052 return;
53 }
54
55 // Blinking ON, no need to check enclosure_identify assert.
56 if (!ec && blinking)
57 {
Ed Tanous539d8c62024-06-19 14:38:27 -070058 asyncResp->res.jsonValue["IndicatorLED"] =
59 chassis::IndicatorLED::Blinking;
Ed Tanous002d39b2022-05-31 08:59:27 -070060 return;
61 }
62
63 sdbusplus::asio::getProperty<bool>(
64 *crow::connections::systemBus,
65 "xyz.openbmc_project.LED.GroupManager",
66 "/xyz/openbmc_project/led/groups/enclosure_identify",
67 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -070068 [asyncResp](const boost::system::error_code& ec2,
69 const bool ledOn) {
Ed Tanous002d39b2022-05-31 08:59:27 -070070 if (ec2 == boost::system::errc::invalid_argument)
James Feist1c8fba92019-12-20 15:12:07 -080071 {
Ed Tanous62598e32023-07-17 17:06:25 -070072 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -080073 "Get enclosure identity led failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -070074 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -070075 return;
James Feist1c8fba92019-12-20 15:12:07 -080076 }
James Feist1c8fba92019-12-20 15:12:07 -080077
Ed Tanous002d39b2022-05-31 08:59:27 -070078 if (ec2)
Jonathan Doman1e1e5982021-06-11 09:36:17 -070079 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -070080 return;
81 }
82
Ed Tanous002d39b2022-05-31 08:59:27 -070083 if (ledOn)
84 {
Ed Tanous539d8c62024-06-19 14:38:27 -070085 asyncResp->res.jsonValue["IndicatorLED"] =
86 chassis::IndicatorLED::Lit;
Ed Tanous002d39b2022-05-31 08:59:27 -070087 }
88 else
89 {
Ed Tanous539d8c62024-06-19 14:38:27 -070090 asyncResp->res.jsonValue["IndicatorLED"] =
91 chassis::IndicatorLED::Off;
Ed Tanous002d39b2022-05-31 08:59:27 -070092 }
Jonathan Doman1e1e5982021-06-11 09:36:17 -070093 });
Patrick Williams5a39f772023-10-20 11:20:21 -050094 });
James Feist1c8fba92019-12-20 15:12:07 -080095}
96
97/**
98 * @brief Sets identify led group properties
99 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700100 * @param[in] asyncResp Shared pointer for generating response message.
James Feist1c8fba92019-12-20 15:12:07 -0800101 * @param[in] ledState LED state passed from request
102 *
103 * @return None.
104 */
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500105// TODO (Gunnar): Remove IndicatorLED after enough time has passed
zhanghch058d1b46d2021-04-01 11:18:24 +0800106inline void
Ed Tanousac106bf2023-06-07 09:24:59 -0700107 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
zhanghch058d1b46d2021-04-01 11:18:24 +0800108 const std::string& ledState)
James Feist1c8fba92019-12-20 15:12:07 -0800109{
Ed Tanous62598e32023-07-17 17:06:25 -0700110 BMCWEB_LOG_DEBUG("Set led groups");
James Feist1c8fba92019-12-20 15:12:07 -0800111 bool ledOn = false;
112 bool ledBlinkng = false;
113
114 if (ledState == "Lit")
115 {
116 ledOn = true;
117 }
118 else if (ledState == "Blinking")
119 {
120 ledBlinkng = true;
121 }
122 else if (ledState != "Off")
123 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700124 messages::propertyValueNotInList(asyncResp->res, ledState,
125 "IndicatorLED");
James Feist1c8fba92019-12-20 15:12:07 -0800126 return;
127 }
128
George Liu9ae226f2023-06-21 17:56:46 +0800129 sdbusplus::asio::setProperty(
130 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
131 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
132 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
Ed Tanousac106bf2023-06-07 09:24:59 -0700133 [asyncResp, ledOn,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800134 ledBlinkng](const boost::system::error_code& ec) mutable {
Ed Tanous002d39b2022-05-31 08:59:27 -0700135 if (ec)
136 {
137 // Some systems may not have enclosure_identify_blink object so
138 // Lets set enclosure_identify state to true if Blinking is
139 // true.
140 if (ledBlinkng)
James Feist1c8fba92019-12-20 15:12:07 -0800141 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700142 ledOn = true;
James Feist1c8fba92019-12-20 15:12:07 -0800143 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700144 }
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000145 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530146 asyncResp, "IndicatorLED", "xyz.openbmc_project.LED.GroupManager",
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000147 sdbusplus::message::object_path(
148 "/xyz/openbmc_project/led/groups/enclosure_identify"),
Ginu Georgee93abac2024-06-14 17:35:27 +0530149 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
Patrick Williams5a39f772023-10-20 11:20:21 -0500150 });
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");
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700164 sdbusplus::asio::getProperty<bool>(
165 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
166 "/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) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700169 // 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)
172 {
Ed Tanous62598e32023-07-17 17:06:25 -0700173 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -0800174 "Get identity blinking LED failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700175 messages::internalError(asyncResp->res);
Ed Tanous002d39b2022-05-31 08:59:27 -0700176 return;
177 }
178
179 // Blinking ON, no need to check enclosure_identify assert.
180 if (!ec && blinking)
181 {
Ed Tanousac106bf2023-06-07 09:24:59 -0700182 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
Ed Tanous002d39b2022-05-31 08:59:27 -0700183 return;
184 }
185
186 sdbusplus::asio::getProperty<bool>(
187 *crow::connections::systemBus,
188 "xyz.openbmc_project.LED.GroupManager",
189 "/xyz/openbmc_project/led/groups/enclosure_identify",
190 "xyz.openbmc_project.Led.Group", "Asserted",
Ed Tanousac106bf2023-06-07 09:24:59 -0700191 [asyncResp](const boost::system::error_code& ec2,
192 const bool ledOn) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700193 if (ec2 == boost::system::errc::invalid_argument)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500194 {
Ed Tanous62598e32023-07-17 17:06:25 -0700195 BMCWEB_LOG_DEBUG(
Ed Tanous8ece0e42024-01-02 13:16:50 -0800196 "Get enclosure identity led failed, mismatch in property type");
Ed Tanousac106bf2023-06-07 09:24:59 -0700197 messages::internalError(asyncResp->res);
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700198 return;
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500199 }
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500200
Ed Tanous002d39b2022-05-31 08:59:27 -0700201 if (ec2)
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700202 {
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700203 return;
204 }
205
Ed Tanousac106bf2023-06-07 09:24:59 -0700206 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
Jonathan Doman1e1e5982021-06-11 09:36:17 -0700207 });
Patrick Williams5a39f772023-10-20 11:20:21 -0500208 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500209}
210
211/**
George Liu59a17e42022-10-08 09:27:47 +0800212 * @brief Sets identify system led group properties
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500213 *
Ed Tanousac106bf2023-06-07 09:24:59 -0700214 * @param[in] asyncResp Shared pointer for generating response message.
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500215 * @param[in] ledState LED state passed from request
216 *
217 * @return None.
218 */
George Liu59a17e42022-10-08 09:27:47 +0800219inline void setSystemLocationIndicatorActive(
Ed Tanousac106bf2023-06-07 09:24:59 -0700220 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500221{
Ed Tanous62598e32023-07-17 17:06:25 -0700222 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500223
George Liu9ae226f2023-06-21 17:56:46 +0800224 sdbusplus::asio::setProperty(
225 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
226 "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
227 "xyz.openbmc_project.Led.Group", "Asserted", ledState,
228 [asyncResp, ledState](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700229 if (ec)
230 {
231 // Some systems may not have enclosure_identify_blink object so
232 // lets set enclosure_identify state also if
233 // enclosure_identify_blink failed
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000234 setDbusProperty(
Ginu Georgee93abac2024-06-14 17:35:27 +0530235 asyncResp, "LocationIndicatorActive",
236 "xyz.openbmc_project.LED.GroupManager",
Asmitha Karunanithi87c44962024-04-04 18:28:33 +0000237 sdbusplus::message::object_path(
238 "/xyz/openbmc_project/led/groups/enclosure_identify"),
Ginu Georgee93abac2024-06-14 17:35:27 +0530239 "xyz.openbmc_project.Led.Group", "Asserted", ledState);
Ed Tanous002d39b2022-05-31 08:59:27 -0700240 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500241 });
Gunnar Mills9f8bfa72020-09-28 13:45:19 -0500242}
Ed Tanous23a21a12020-07-25 04:45:05 +0000243} // namespace redfish