James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 1 | /* |
| 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 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" |
| 21 | #include "redfish_util.hpp" |
| 22 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 23 | #include <sdbusplus/asio/property.hpp> |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 24 | |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 25 | namespace redfish |
| 26 | { |
| 27 | /** |
| 28 | * @brief Retrieves identify led group properties over dbus |
| 29 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 30 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 31 | * |
| 32 | * @return None. |
| 33 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 34 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 35 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 36 | getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 37 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 38 | BMCWEB_LOG_DEBUG("Get led groups"); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 39 | sdbusplus::asio::getProperty<bool>( |
| 40 | *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", |
| 41 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 42 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 43 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 44 | // Some systems may not have enclosure_identify_blink object so |
| 45 | // proceed to get enclosure_identify state. |
| 46 | if (ec == boost::system::errc::invalid_argument) |
| 47 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 48 | BMCWEB_LOG_DEBUG( |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 49 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 50 | messages::internalError(asyncResp->res); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 51 | return; |
| 52 | } |
| 53 | |
| 54 | // Blinking ON, no need to check enclosure_identify assert. |
| 55 | if (!ec && blinking) |
| 56 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 57 | asyncResp->res.jsonValue["IndicatorLED"] = "Blinking"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | |
| 61 | sdbusplus::asio::getProperty<bool>( |
| 62 | *crow::connections::systemBus, |
| 63 | "xyz.openbmc_project.LED.GroupManager", |
| 64 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 65 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 66 | [asyncResp](const boost::system::error_code& ec2, |
| 67 | const bool ledOn) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 68 | if (ec2 == boost::system::errc::invalid_argument) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 69 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 70 | BMCWEB_LOG_DEBUG( |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 71 | "Get enclosure identity led failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 72 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 73 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 74 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 75 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 76 | if (ec2) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 77 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 78 | return; |
| 79 | } |
| 80 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 81 | if (ledOn) |
| 82 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 83 | asyncResp->res.jsonValue["IndicatorLED"] = "Lit"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 84 | } |
| 85 | else |
| 86 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 87 | asyncResp->res.jsonValue["IndicatorLED"] = "Off"; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 88 | } |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 89 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 90 | }); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 91 | } |
| 92 | |
| 93 | /** |
| 94 | * @brief Sets identify led group properties |
| 95 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 96 | * @param[in] asyncResp Shared pointer for generating response message. |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 97 | * @param[in] ledState LED state passed from request |
| 98 | * |
| 99 | * @return None. |
| 100 | */ |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 101 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 102 | inline void |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 103 | setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 104 | const std::string& ledState) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 105 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 106 | BMCWEB_LOG_DEBUG("Set led groups"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 107 | bool ledOn = false; |
| 108 | bool ledBlinkng = false; |
| 109 | |
| 110 | if (ledState == "Lit") |
| 111 | { |
| 112 | ledOn = true; |
| 113 | } |
| 114 | else if (ledState == "Blinking") |
| 115 | { |
| 116 | ledBlinkng = true; |
| 117 | } |
| 118 | else if (ledState != "Off") |
| 119 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 120 | messages::propertyValueNotInList(asyncResp->res, ledState, |
| 121 | "IndicatorLED"); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 122 | return; |
| 123 | } |
| 124 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 125 | sdbusplus::asio::setProperty( |
| 126 | *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", |
| 127 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 128 | "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 129 | [asyncResp, ledOn, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 130 | ledBlinkng](const boost::system::error_code& ec) mutable { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 131 | if (ec) |
| 132 | { |
| 133 | // Some systems may not have enclosure_identify_blink object so |
| 134 | // Lets set enclosure_identify state to true if Blinking is |
| 135 | // true. |
| 136 | if (ledBlinkng) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 137 | { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 138 | ledOn = true; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 139 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 140 | } |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 141 | sdbusplus::asio::setProperty( |
| 142 | *crow::connections::systemBus, |
| 143 | "xyz.openbmc_project.LED.GroupManager", |
| 144 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 145 | "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 146 | [asyncResp](const boost::system::error_code& ec2) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 147 | if (ec2) |
| 148 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 149 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec2); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 150 | messages::internalError(asyncResp->res); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 151 | return; |
| 152 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 153 | messages::success(asyncResp->res); |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 154 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 155 | }); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 156 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 157 | |
| 158 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 159 | * @brief Retrieves identify system led group properties over dbus |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 160 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 161 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 162 | * |
| 163 | * @return None. |
| 164 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 165 | inline void getSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 166 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 167 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 168 | BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 169 | sdbusplus::asio::getProperty<bool>( |
| 170 | *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", |
| 171 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 172 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 173 | [asyncResp](const boost::system::error_code& ec, const bool blinking) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 174 | // Some systems may not have enclosure_identify_blink object so |
| 175 | // proceed to get enclosure_identify state. |
| 176 | if (ec == boost::system::errc::invalid_argument) |
| 177 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 178 | BMCWEB_LOG_DEBUG( |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 179 | "Get identity blinking LED failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 180 | messages::internalError(asyncResp->res); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 181 | return; |
| 182 | } |
| 183 | |
| 184 | // Blinking ON, no need to check enclosure_identify assert. |
| 185 | if (!ec && blinking) |
| 186 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 187 | asyncResp->res.jsonValue["LocationIndicatorActive"] = true; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 188 | return; |
| 189 | } |
| 190 | |
| 191 | sdbusplus::asio::getProperty<bool>( |
| 192 | *crow::connections::systemBus, |
| 193 | "xyz.openbmc_project.LED.GroupManager", |
| 194 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 195 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 196 | [asyncResp](const boost::system::error_code& ec2, |
| 197 | const bool ledOn) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 198 | if (ec2 == boost::system::errc::invalid_argument) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 199 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 200 | BMCWEB_LOG_DEBUG( |
Ed Tanous | 8ece0e4 | 2024-01-02 13:16:50 -0800 | [diff] [blame] | 201 | "Get enclosure identity led failed, mismatch in property type"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 202 | messages::internalError(asyncResp->res); |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 203 | return; |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 204 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 205 | |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 206 | if (ec2) |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 207 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 208 | return; |
| 209 | } |
| 210 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 211 | asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn; |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 212 | }); |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 213 | }); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 214 | } |
| 215 | |
| 216 | /** |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 217 | * @brief Sets identify system led group properties |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 218 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 219 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 220 | * @param[in] ledState LED state passed from request |
| 221 | * |
| 222 | * @return None. |
| 223 | */ |
George Liu | 59a17e4 | 2022-10-08 09:27:47 +0800 | [diff] [blame] | 224 | inline void setSystemLocationIndicatorActive( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 225 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 226 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 227 | BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 228 | |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 229 | sdbusplus::asio::setProperty( |
| 230 | *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", |
| 231 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 232 | "xyz.openbmc_project.Led.Group", "Asserted", ledState, |
| 233 | [asyncResp, ledState](const boost::system::error_code& ec) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 234 | if (ec) |
| 235 | { |
| 236 | // Some systems may not have enclosure_identify_blink object so |
| 237 | // lets set enclosure_identify state also if |
| 238 | // enclosure_identify_blink failed |
George Liu | 9ae226f | 2023-06-21 17:56:46 +0800 | [diff] [blame] | 239 | sdbusplus::asio::setProperty( |
| 240 | *crow::connections::systemBus, |
| 241 | "xyz.openbmc_project.LED.GroupManager", |
| 242 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 243 | "xyz.openbmc_project.Led.Group", "Asserted", ledState, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 244 | [asyncResp](const boost::system::error_code& ec2) { |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 245 | if (ec2) |
| 246 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 247 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec2); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 248 | messages::internalError(asyncResp->res); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 249 | return; |
| 250 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 251 | }); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 252 | } |
Patrick Williams | 5a39f77 | 2023-10-20 11:20:21 -0500 | [diff] [blame] | 253 | }); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 254 | } |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 255 | } // namespace redfish |