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