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 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 6 | #include "app.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 7 | #include "async_resp.hpp" |
| 8 | #include "dbus_utility.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 9 | #include "generated/enums/chassis.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 10 | #include "redfish_util.hpp" |
| 11 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 12 | #include <sdbusplus/asio/property.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 13 | |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 14 | namespace redfish |
| 15 | { |
| 16 | /** |
| 17 | * @brief Retrieves identify led group properties over dbus |
| 18 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 19 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 20 | * |
| 21 | * @return None. |
| 22 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 23 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 24 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 25 | getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 26 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 27 | BMCWEB_LOG_DEBUG("Get led groups"); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 28 | dbus::utility::getProperty<bool>( |
| 29 | "xyz.openbmc_project.LED.GroupManager", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 30 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 31 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 32 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 33 | // 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 36 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 37 | BMCWEB_LOG_DEBUG( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 38 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 39 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 40 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 41 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 42 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 43 | // Blinking ON, no need to check enclosure_identify assert. |
| 44 | if (!ec && blinking) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 45 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 46 | asyncResp->res.jsonValue["IndicatorLED"] = |
| 47 | chassis::IndicatorLED::Blinking; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 48 | return; |
| 49 | } |
| 50 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 51 | dbus::utility::getProperty<bool>( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 52 | "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 Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 81 | }); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** |
| 85 | * @brief Sets identify led group properties |
| 86 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 87 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 88 | * @param[in] ledState LED state passed from request |
| 89 | * |
| 90 | * @return None. |
| 91 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 92 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 93 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 94 | setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 95 | const std::string& ledState) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 96 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 97 | BMCWEB_LOG_DEBUG("Set led groups"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 98 | 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 Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 111 | messages::propertyValueNotInList(asyncResp->res, ledState, |
| 112 | "IndicatorLED"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 113 | return; |
| 114 | } |
| 115 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 116 | 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 Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 120 | [asyncResp, ledOn, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 121 | ledBlinkng](const boost::system::error_code& ec) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 122 | if (ec) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 123 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 124 | // 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 131 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 132 | 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 139 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 140 | |
| 141 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 142 | * @brief Retrieves identify system led group properties over dbus |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 143 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 144 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 145 | * |
| 146 | * @return None. |
| 147 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 148 | inline void getSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 149 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 150 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 151 | BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 152 | dbus::utility::getProperty<bool>( |
| 153 | "xyz.openbmc_project.LED.GroupManager", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 154 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 155 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 156 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 157 | // 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 Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 160 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 161 | BMCWEB_LOG_DEBUG( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 162 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 163 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 164 | return; |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 165 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 166 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 167 | // Blinking ON, no need to check enclosure_identify assert. |
| 168 | if (!ec && blinking) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 169 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 170 | asyncResp->res.jsonValue["LocationIndicatorActive"] = true; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 171 | return; |
| 172 | } |
| 173 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 174 | dbus::utility::getProperty<bool>( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 175 | "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 Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 195 | }); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 196 | } |
| 197 | |
| 198 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 199 | * @brief Sets identify system led group properties |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 200 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 201 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 202 | * @param[in] ledState LED state passed from request |
| 203 | * |
| 204 | * @return None. |
| 205 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 206 | inline void setSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 207 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 208 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 209 | BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 210 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 211 | 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 Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 216 | 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 Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 229 | } |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 230 | } // namespace redfish |