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 "app.hpp" 19 #include "async_resp.hpp" 20 #include "dbus_utility.hpp" 21 #include "generated/enums/chassis.hpp" 22 #include "redfish_util.hpp" 23 24 #include <sdbusplus/asio/property.hpp> 25 26 namespace redfish 27 { 28 /** 29 * @brief Retrieves identify led group properties over dbus 30 * 31 * @param[in] asyncResp Shared pointer for generating response message. 32 * 33 * @return None. 34 */ 35 // TODO (Gunnar): Remove IndicatorLED after enough time has passed 36 inline void 37 getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 38 { 39 BMCWEB_LOG_DEBUG("Get led groups"); 40 dbus::utility::getProperty<bool>( 41 "xyz.openbmc_project.LED.GroupManager", 42 "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 43 "xyz.openbmc_project.Led.Group", "Asserted", 44 [asyncResp](const boost::system::error_code& ec, const bool blinking) { 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) 48 { 49 BMCWEB_LOG_DEBUG( 50 "Get identity blinking LED failed, mismatch in property type"); 51 messages::internalError(asyncResp->res); 52 return; 53 } 54 55 // Blinking ON, no need to check enclosure_identify assert. 56 if (!ec && blinking) 57 { 58 asyncResp->res.jsonValue["IndicatorLED"] = 59 chassis::IndicatorLED::Blinking; 60 return; 61 } 62 63 dbus::utility::getProperty<bool>( 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 }); 93 }); 94 } 95 96 /** 97 * @brief Sets identify led group properties 98 * 99 * @param[in] asyncResp Shared pointer for generating response message. 100 * @param[in] ledState LED state passed from request 101 * 102 * @return None. 103 */ 104 // TODO (Gunnar): Remove IndicatorLED after enough time has passed 105 inline void 106 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 107 const std::string& ledState) 108 { 109 BMCWEB_LOG_DEBUG("Set led groups"); 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 { 123 messages::propertyValueNotInList(asyncResp->res, ledState, 124 "IndicatorLED"); 125 return; 126 } 127 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, 132 [asyncResp, ledOn, 133 ledBlinkng](const boost::system::error_code& ec) mutable { 134 if (ec) 135 { 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 } 143 } 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 }); 151 } 152 153 /** 154 * @brief Retrieves identify system led group properties over dbus 155 * 156 * @param[in] asyncResp Shared pointer for generating response message. 157 * 158 * @return None. 159 */ 160 inline void getSystemLocationIndicatorActive( 161 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 162 { 163 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); 164 dbus::utility::getProperty<bool>( 165 "xyz.openbmc_project.LED.GroupManager", 166 "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 167 "xyz.openbmc_project.Led.Group", "Asserted", 168 [asyncResp](const boost::system::error_code& ec, const bool blinking) { 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) 172 { 173 BMCWEB_LOG_DEBUG( 174 "Get identity blinking LED failed, mismatch in property type"); 175 messages::internalError(asyncResp->res); 176 return; 177 } 178 179 // Blinking ON, no need to check enclosure_identify assert. 180 if (!ec && blinking) 181 { 182 asyncResp->res.jsonValue["LocationIndicatorActive"] = true; 183 return; 184 } 185 186 dbus::utility::getProperty<bool>( 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 }); 207 }); 208 } 209 210 /** 211 * @brief Sets identify system led group properties 212 * 213 * @param[in] asyncResp Shared pointer for generating response message. 214 * @param[in] ledState LED state passed from request 215 * 216 * @return None. 217 */ 218 inline void setSystemLocationIndicatorActive( 219 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) 220 { 221 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); 222 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) { 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 }); 241 } 242 } // namespace redfish 243