James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 1 | /* |
Ed Tanous | 6be832e | 2024-09-10 11:44:48 -0700 | [diff] [blame] | 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. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 15 | */ |
| 16 | #pragma once |
| 17 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 18 | #include "app.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 19 | #include "async_resp.hpp" |
| 20 | #include "dbus_utility.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 21 | #include "generated/enums/chassis.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 22 | #include "redfish_util.hpp" |
| 23 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 24 | #include <sdbusplus/asio/property.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 25 | |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 26 | namespace redfish |
| 27 | { |
| 28 | /** |
| 29 | * @brief Retrieves identify led group properties over dbus |
| 30 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 31 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 32 | * |
| 33 | * @return None. |
| 34 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 35 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 36 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 37 | getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 38 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 39 | BMCWEB_LOG_DEBUG("Get led groups"); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame^] | 40 | dbus::utility::getProperty<bool>( |
| 41 | "xyz.openbmc_project.LED.GroupManager", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 42 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 43 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 44 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 45 | // 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 48 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 49 | BMCWEB_LOG_DEBUG( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 50 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 51 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 52 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 53 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 54 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 55 | // Blinking ON, no need to check enclosure_identify assert. |
| 56 | if (!ec && blinking) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 57 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 58 | asyncResp->res.jsonValue["IndicatorLED"] = |
| 59 | chassis::IndicatorLED::Blinking; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 60 | return; |
| 61 | } |
| 62 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame^] | 63 | dbus::utility::getProperty<bool>( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 64 | "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 Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 93 | }); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 94 | } |
| 95 | |
| 96 | /** |
| 97 | * @brief Sets identify led group properties |
| 98 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 99 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 100 | * @param[in] ledState LED state passed from request |
| 101 | * |
| 102 | * @return None. |
| 103 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 104 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 105 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 106 | setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 107 | const std::string& ledState) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 108 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 109 | BMCWEB_LOG_DEBUG("Set led groups"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 110 | 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 Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 123 | messages::propertyValueNotInList(asyncResp->res, ledState, |
| 124 | "IndicatorLED"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 125 | return; |
| 126 | } |
| 127 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 128 | 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 Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 132 | [asyncResp, ledOn, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 133 | ledBlinkng](const boost::system::error_code& ec) mutable { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 134 | if (ec) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 135 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 136 | // 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 143 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 144 | 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 Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 151 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 152 | |
| 153 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 154 | * @brief Retrieves identify system led group properties over dbus |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 155 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 156 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 157 | * |
| 158 | * @return None. |
| 159 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 160 | inline void getSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 161 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 162 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 163 | BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame^] | 164 | dbus::utility::getProperty<bool>( |
| 165 | "xyz.openbmc_project.LED.GroupManager", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 166 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 167 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 168 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 169 | // 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 Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 172 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 173 | BMCWEB_LOG_DEBUG( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 174 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 175 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 176 | return; |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 177 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 178 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 179 | // Blinking ON, no need to check enclosure_identify assert. |
| 180 | if (!ec && blinking) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 181 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 182 | asyncResp->res.jsonValue["LocationIndicatorActive"] = true; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 183 | return; |
| 184 | } |
| 185 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame^] | 186 | dbus::utility::getProperty<bool>( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 187 | "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 Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 207 | }); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 208 | } |
| 209 | |
| 210 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 211 | * @brief Sets identify system led group properties |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 212 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 213 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 214 | * @param[in] ledState LED state passed from request |
| 215 | * |
| 216 | * @return None. |
| 217 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 218 | inline void setSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 219 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 220 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 221 | BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 222 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 223 | 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 Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 228 | 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 Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 241 | } |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 242 | } // namespace redfish |