Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2019 Intel Corporation |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 4 | #pragma once |
| 5 | |
| 6 | #include "async_resp.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 7 | #include "dbus_singleton.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 8 | #include "dbus_utility.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include "error_messages.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 10 | #include "generated/enums/chassis.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 11 | #include "logging.hpp" |
| 12 | #include "utils/dbus_utils.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 13 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 14 | #include <sdbusplus/asio/property.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 15 | #include <sdbusplus/message/native_types.hpp> |
| 16 | |
| 17 | #include <memory> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 18 | |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 19 | namespace redfish |
| 20 | { |
| 21 | /** |
| 22 | * @brief Retrieves identify led group properties over dbus |
| 23 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 24 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 25 | * |
| 26 | * @return None. |
| 27 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 28 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame^] | 29 | inline void getIndicatorLedState( |
| 30 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 31 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 32 | BMCWEB_LOG_DEBUG("Get led groups"); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 33 | dbus::utility::getProperty<bool>( |
| 34 | "xyz.openbmc_project.LED.GroupManager", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 35 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 36 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 37 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 38 | // 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 41 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 42 | BMCWEB_LOG_DEBUG( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 43 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 44 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 45 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 46 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 47 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 48 | // Blinking ON, no need to check enclosure_identify assert. |
| 49 | if (!ec && blinking) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 50 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 51 | asyncResp->res.jsonValue["IndicatorLED"] = |
| 52 | chassis::IndicatorLED::Blinking; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 53 | return; |
| 54 | } |
| 55 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 56 | dbus::utility::getProperty<bool>( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 57 | "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 Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 86 | }); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 87 | } |
| 88 | |
| 89 | /** |
| 90 | * @brief Sets identify led group properties |
| 91 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 92 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 93 | * @param[in] ledState LED state passed from request |
| 94 | * |
| 95 | * @return None. |
| 96 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 97 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame^] | 98 | inline void setIndicatorLedState( |
| 99 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 100 | const std::string& ledState) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 101 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 102 | BMCWEB_LOG_DEBUG("Set led groups"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 103 | 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 Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 116 | messages::propertyValueNotInList(asyncResp->res, ledState, |
| 117 | "IndicatorLED"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 118 | return; |
| 119 | } |
| 120 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 121 | 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 Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 125 | [asyncResp, ledOn, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 126 | ledBlinkng](const boost::system::error_code& ec) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 127 | if (ec) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 128 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 129 | // 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 136 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 137 | 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 144 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 145 | |
| 146 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 147 | * @brief Retrieves identify system led group properties over dbus |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 148 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 149 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 150 | * |
| 151 | * @return None. |
| 152 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 153 | inline void getSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 154 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 155 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 156 | BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 157 | dbus::utility::getProperty<bool>( |
| 158 | "xyz.openbmc_project.LED.GroupManager", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 159 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 160 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 161 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 162 | // 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 Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 165 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 166 | BMCWEB_LOG_DEBUG( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 167 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 168 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 169 | return; |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 170 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 171 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 172 | // Blinking ON, no need to check enclosure_identify assert. |
| 173 | if (!ec && blinking) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 174 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 175 | asyncResp->res.jsonValue["LocationIndicatorActive"] = true; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 176 | return; |
| 177 | } |
| 178 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 179 | dbus::utility::getProperty<bool>( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 180 | "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 Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 200 | }); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 201 | } |
| 202 | |
| 203 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 204 | * @brief Sets identify system led group properties |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 205 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 206 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 207 | * @param[in] ledState LED state passed from request |
| 208 | * |
| 209 | * @return None. |
| 210 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 211 | inline void setSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 212 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 213 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 214 | BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 215 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 216 | 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 Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 221 | 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 Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 234 | } |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 235 | } // namespace redfish |