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 sdbusplus::asio::getProperty<bool>( 41 *crow::connections::systemBus, "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 sdbusplus::asio::getProperty<bool>( 64 *crow::connections::systemBus, 65 "xyz.openbmc_project.LED.GroupManager", 66 "/xyz/openbmc_project/led/groups/enclosure_identify", 67 "xyz.openbmc_project.Led.Group", "Asserted", 68 [asyncResp](const boost::system::error_code& ec2, 69 const bool ledOn) { 70 if (ec2 == boost::system::errc::invalid_argument) 71 { 72 BMCWEB_LOG_DEBUG( 73 "Get enclosure identity led failed, mismatch in property type"); 74 messages::internalError(asyncResp->res); 75 return; 76 } 77 78 if (ec2) 79 { 80 return; 81 } 82 83 if (ledOn) 84 { 85 asyncResp->res.jsonValue["IndicatorLED"] = 86 chassis::IndicatorLED::Lit; 87 } 88 else 89 { 90 asyncResp->res.jsonValue["IndicatorLED"] = 91 chassis::IndicatorLED::Off; 92 } 93 }); 94 }); 95 } 96 97 /** 98 * @brief Sets identify led group properties 99 * 100 * @param[in] asyncResp Shared pointer for generating response message. 101 * @param[in] ledState LED state passed from request 102 * 103 * @return None. 104 */ 105 // TODO (Gunnar): Remove IndicatorLED after enough time has passed 106 inline void 107 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 108 const std::string& ledState) 109 { 110 BMCWEB_LOG_DEBUG("Set led groups"); 111 bool ledOn = false; 112 bool ledBlinkng = false; 113 114 if (ledState == "Lit") 115 { 116 ledOn = true; 117 } 118 else if (ledState == "Blinking") 119 { 120 ledBlinkng = true; 121 } 122 else if (ledState != "Off") 123 { 124 messages::propertyValueNotInList(asyncResp->res, ledState, 125 "IndicatorLED"); 126 return; 127 } 128 129 sdbusplus::asio::setProperty( 130 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", 131 "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 132 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng, 133 [asyncResp, ledOn, 134 ledBlinkng](const boost::system::error_code& ec) mutable { 135 if (ec) 136 { 137 // Some systems may not have enclosure_identify_blink object so 138 // Lets set enclosure_identify state to true if Blinking is 139 // true. 140 if (ledBlinkng) 141 { 142 ledOn = true; 143 } 144 } 145 setDbusProperty( 146 asyncResp, "IndicatorLED", 147 "xyz.openbmc_project.LED.GroupManager", 148 sdbusplus::message::object_path( 149 "/xyz/openbmc_project/led/groups/enclosure_identify"), 150 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng); 151 }); 152 } 153 154 /** 155 * @brief Retrieves identify system led group properties over dbus 156 * 157 * @param[in] asyncResp Shared pointer for generating response message. 158 * 159 * @return None. 160 */ 161 inline void getSystemLocationIndicatorActive( 162 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 163 { 164 BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); 165 sdbusplus::asio::getProperty<bool>( 166 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", 167 "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 168 "xyz.openbmc_project.Led.Group", "Asserted", 169 [asyncResp](const boost::system::error_code& ec, const bool blinking) { 170 // Some systems may not have enclosure_identify_blink object so 171 // proceed to get enclosure_identify state. 172 if (ec == boost::system::errc::invalid_argument) 173 { 174 BMCWEB_LOG_DEBUG( 175 "Get identity blinking LED failed, mismatch in property type"); 176 messages::internalError(asyncResp->res); 177 return; 178 } 179 180 // Blinking ON, no need to check enclosure_identify assert. 181 if (!ec && blinking) 182 { 183 asyncResp->res.jsonValue["LocationIndicatorActive"] = true; 184 return; 185 } 186 187 sdbusplus::asio::getProperty<bool>( 188 *crow::connections::systemBus, 189 "xyz.openbmc_project.LED.GroupManager", 190 "/xyz/openbmc_project/led/groups/enclosure_identify", 191 "xyz.openbmc_project.Led.Group", "Asserted", 192 [asyncResp](const boost::system::error_code& ec2, 193 const bool ledOn) { 194 if (ec2 == boost::system::errc::invalid_argument) 195 { 196 BMCWEB_LOG_DEBUG( 197 "Get enclosure identity led failed, mismatch in property type"); 198 messages::internalError(asyncResp->res); 199 return; 200 } 201 202 if (ec2) 203 { 204 return; 205 } 206 207 asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn; 208 }); 209 }); 210 } 211 212 /** 213 * @brief Sets identify system led group properties 214 * 215 * @param[in] asyncResp Shared pointer for generating response message. 216 * @param[in] ledState LED state passed from request 217 * 218 * @return None. 219 */ 220 inline void setSystemLocationIndicatorActive( 221 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) 222 { 223 BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); 224 225 sdbusplus::asio::setProperty( 226 *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", 227 "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 228 "xyz.openbmc_project.Led.Group", "Asserted", ledState, 229 [asyncResp, ledState](const boost::system::error_code& ec) { 230 if (ec) 231 { 232 // Some systems may not have enclosure_identify_blink object so 233 // lets set enclosure_identify state also if 234 // enclosure_identify_blink failed 235 setDbusProperty( 236 asyncResp, "LocationIndicatorActive", 237 "xyz.openbmc_project.LED.GroupManager", 238 sdbusplus::message::object_path( 239 "/xyz/openbmc_project/led/groups/enclosure_identify"), 240 "xyz.openbmc_project.Led.Group", "Asserted", ledState); 241 } 242 }); 243 } 244 } // namespace redfish 245