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 | |
| 18 | #include "async_resp.hpp" |
| 19 | #include "dbus_utility.hpp" |
| 20 | #include "redfish_util.hpp" |
| 21 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 22 | #include <app.hpp> |
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", |
| 43 | [aResp](const boost::system::error_code ec, const bool blinking) { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 44 | // Some systems may not have enclosure_identify_blink object so |
| 45 | // proceed to get enclosure_identify state. |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 46 | if (ec == boost::system::errc::invalid_argument) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 47 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 48 | BMCWEB_LOG_DEBUG |
| 49 | << "Get identity blinking LED failed, missmatch in property type"; |
| 50 | messages::internalError(aResp->res); |
| 51 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 52 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 53 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 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, |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 63 | "xyz.openbmc_project.LED.GroupManager", |
| 64 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 65 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 66 | [aResp](const boost::system::error_code ec2, const bool ledOn) { |
| 67 | if (ec2 == boost::system::errc::invalid_argument) |
| 68 | { |
| 69 | BMCWEB_LOG_DEBUG |
| 70 | << "Get enclosure identity led failed, missmatch in property type"; |
| 71 | messages::internalError(aResp->res); |
| 72 | return; |
| 73 | } |
| 74 | |
| 75 | if (ec2) |
| 76 | { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | if (ledOn) |
| 81 | { |
| 82 | aResp->res.jsonValue["IndicatorLED"] = "Lit"; |
| 83 | } |
| 84 | else |
| 85 | { |
| 86 | aResp->res.jsonValue["IndicatorLED"] = "Off"; |
| 87 | } |
| 88 | }); |
| 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 | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 124 | [aResp, ledOn, ledBlinkng](const boost::system::error_code ec) mutable { |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 125 | if (ec) |
| 126 | { |
| 127 | // Some systems may not have enclosure_identify_blink object so |
| 128 | // Lets set enclosure_identify state to true if Blinking is |
| 129 | // true. |
| 130 | if (ledBlinkng) |
| 131 | { |
| 132 | ledOn = true; |
| 133 | } |
| 134 | } |
| 135 | crow::connections::systemBus->async_method_call( |
Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 136 | [aResp](const boost::system::error_code ec2) { |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 137 | if (ec2) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 138 | { |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 139 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 140 | messages::internalError(aResp->res); |
| 141 | return; |
| 142 | } |
Jayaprakash Mutyala | 1d40ef6 | 2021-02-26 13:06:03 +0000 | [diff] [blame] | 143 | messages::success(aResp->res); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 144 | }, |
| 145 | "xyz.openbmc_project.LED.GroupManager", |
| 146 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 147 | "org.freedesktop.DBus.Properties", "Set", |
| 148 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 149 | dbus::utility::DbusVariantType(ledOn)); |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 150 | }, |
| 151 | "xyz.openbmc_project.LED.GroupManager", |
| 152 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 153 | "org.freedesktop.DBus.Properties", "Set", |
| 154 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 155 | dbus::utility::DbusVariantType(ledBlinkng)); |
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 | /** |
| 159 | * @brief Retrieves identify led group properties over dbus |
| 160 | * |
| 161 | * @param[in] aResp Shared pointer for generating response message. |
| 162 | * |
| 163 | * @return None. |
| 164 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 165 | inline void |
| 166 | getLocationIndicatorActive(const std::shared_ptr<bmcweb::AsyncResp>& aResp) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 167 | { |
| 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", |
| 173 | [aResp](const boost::system::error_code ec, const bool blinking) { |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 174 | // Some systems may not have enclosure_identify_blink object so |
| 175 | // proceed to get enclosure_identify state. |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 176 | if (ec == boost::system::errc::invalid_argument) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 177 | { |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 178 | BMCWEB_LOG_DEBUG |
| 179 | << "Get identity blinking LED failed, missmatch in property type"; |
| 180 | messages::internalError(aResp->res); |
| 181 | return; |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 182 | } |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 183 | |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 184 | // Blinking ON, no need to check enclosure_identify assert. |
| 185 | if (!ec && blinking) |
| 186 | { |
| 187 | aResp->res.jsonValue["LocationIndicatorActive"] = true; |
| 188 | return; |
| 189 | } |
| 190 | |
| 191 | sdbusplus::asio::getProperty<bool>( |
| 192 | *crow::connections::systemBus, |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 193 | "xyz.openbmc_project.LED.GroupManager", |
| 194 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 195 | "xyz.openbmc_project.Led.Group", "Asserted", |
| 196 | [aResp](const boost::system::error_code ec2, const bool ledOn) { |
| 197 | if (ec2 == boost::system::errc::invalid_argument) |
| 198 | { |
| 199 | BMCWEB_LOG_DEBUG |
| 200 | << "Get enclosure identity led failed, missmatch in property type"; |
| 201 | messages::internalError(aResp->res); |
| 202 | return; |
| 203 | } |
| 204 | |
| 205 | if (ec2) |
| 206 | { |
| 207 | return; |
| 208 | } |
| 209 | |
| 210 | aResp->res.jsonValue["LocationIndicatorActive"] = ledOn; |
| 211 | }); |
| 212 | }); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 213 | } |
| 214 | |
| 215 | /** |
| 216 | * @brief Sets identify led group properties |
| 217 | * |
| 218 | * @param[in] aResp Shared pointer for generating response message. |
| 219 | * @param[in] ledState LED state passed from request |
| 220 | * |
| 221 | * @return None. |
| 222 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 223 | inline void |
| 224 | setLocationIndicatorActive(const std::shared_ptr<bmcweb::AsyncResp>& aResp, |
| 225 | const bool ledState) |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 226 | { |
| 227 | BMCWEB_LOG_DEBUG << "Set LocationIndicatorActive"; |
| 228 | |
| 229 | crow::connections::systemBus->async_method_call( |
| 230 | [aResp, ledState](const boost::system::error_code ec) mutable { |
| 231 | if (ec) |
| 232 | { |
| 233 | // Some systems may not have enclosure_identify_blink object so |
| 234 | // lets set enclosure_identify state also if |
| 235 | // enclosure_identify_blink failed |
| 236 | crow::connections::systemBus->async_method_call( |
| 237 | [aResp](const boost::system::error_code ec2) { |
| 238 | if (ec2) |
| 239 | { |
| 240 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; |
| 241 | messages::internalError(aResp->res); |
| 242 | return; |
| 243 | } |
| 244 | }, |
| 245 | "xyz.openbmc_project.LED.GroupManager", |
| 246 | "/xyz/openbmc_project/led/groups/enclosure_identify", |
| 247 | "org.freedesktop.DBus.Properties", "Set", |
| 248 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 249 | dbus::utility::DbusVariantType(ledState)); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 250 | } |
| 251 | }, |
| 252 | "xyz.openbmc_project.LED.GroupManager", |
| 253 | "/xyz/openbmc_project/led/groups/enclosure_identify_blink", |
| 254 | "org.freedesktop.DBus.Properties", "Set", |
| 255 | "xyz.openbmc_project.Led.Group", "Asserted", |
Ed Tanous | 168e20c | 2021-12-13 14:39:53 -0800 | [diff] [blame] | 256 | dbus::utility::DbusVariantType(ledState)); |
Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 257 | } |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 258 | } // namespace redfish |