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