11c8fba97SJames Feist /* 26be832e2SEd Tanous Copyright (c) 2019 Intel Corporation 36be832e2SEd Tanous 46be832e2SEd Tanous Licensed under the Apache License, Version 2.0 (the "License"); 56be832e2SEd Tanous you may not use this file except in compliance with the License. 66be832e2SEd Tanous You may obtain a copy of the License at 76be832e2SEd Tanous 86be832e2SEd Tanous http://www.apache.org/licenses/LICENSE-2.0 96be832e2SEd Tanous 106be832e2SEd Tanous Unless required by applicable law or agreed to in writing, software 116be832e2SEd Tanous distributed under the License is distributed on an "AS IS" BASIS, 126be832e2SEd Tanous WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 136be832e2SEd Tanous See the License for the specific language governing permissions and 146be832e2SEd Tanous limitations under the License. 151c8fba97SJames Feist */ 161c8fba97SJames Feist #pragma once 171c8fba97SJames Feist 183ccb3adbSEd Tanous #include "app.hpp" 191c8fba97SJames Feist #include "async_resp.hpp" 201c8fba97SJames Feist #include "dbus_utility.hpp" 21539d8c6bSEd Tanous #include "generated/enums/chassis.hpp" 221c8fba97SJames Feist #include "redfish_util.hpp" 231c8fba97SJames Feist 241e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 257e860f15SJohn Edward Broadbent 261c8fba97SJames Feist namespace redfish 271c8fba97SJames Feist { 281c8fba97SJames Feist /** 291c8fba97SJames Feist * @brief Retrieves identify led group properties over dbus 301c8fba97SJames Feist * 31ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 321c8fba97SJames Feist * 331c8fba97SJames Feist * @return None. 341c8fba97SJames Feist */ 359f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 368d1b46d7Szhanghch05 inline void 37ac106bf6SEd Tanous getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 381c8fba97SJames Feist { 3962598e31SEd Tanous BMCWEB_LOG_DEBUG("Get led groups"); 40*deae6a78SEd Tanous dbus::utility::getProperty<bool>( 41*deae6a78SEd Tanous "xyz.openbmc_project.LED.GroupManager", 421e1e598dSJonathan Doman "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 431e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 44ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, const bool blinking) { 451c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 461c8fba97SJames Feist // proceed to get enclosure_identify state. 471e1e598dSJonathan Doman if (ec == boost::system::errc::invalid_argument) 481c8fba97SJames Feist { 4962598e31SEd Tanous BMCWEB_LOG_DEBUG( 508ece0e45SEd Tanous "Get identity blinking LED failed, mismatch in property type"); 51ac106bf6SEd Tanous messages::internalError(asyncResp->res); 521c8fba97SJames Feist return; 531c8fba97SJames Feist } 541c8fba97SJames Feist 551e1e598dSJonathan Doman // Blinking ON, no need to check enclosure_identify assert. 561e1e598dSJonathan Doman if (!ec && blinking) 571e1e598dSJonathan Doman { 58539d8c6bSEd Tanous asyncResp->res.jsonValue["IndicatorLED"] = 59539d8c6bSEd Tanous chassis::IndicatorLED::Blinking; 601e1e598dSJonathan Doman return; 611e1e598dSJonathan Doman } 621e1e598dSJonathan Doman 63*deae6a78SEd Tanous dbus::utility::getProperty<bool>( 641e1e598dSJonathan Doman "xyz.openbmc_project.LED.GroupManager", 651e1e598dSJonathan Doman "/xyz/openbmc_project/led/groups/enclosure_identify", 661e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 67ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 68ac106bf6SEd Tanous const bool ledOn) { 691e1e598dSJonathan Doman if (ec2 == boost::system::errc::invalid_argument) 701e1e598dSJonathan Doman { 7162598e31SEd Tanous BMCWEB_LOG_DEBUG( 728ece0e45SEd Tanous "Get enclosure identity led failed, mismatch in property type"); 73ac106bf6SEd Tanous messages::internalError(asyncResp->res); 741e1e598dSJonathan Doman return; 751e1e598dSJonathan Doman } 761e1e598dSJonathan Doman 771e1e598dSJonathan Doman if (ec2) 781e1e598dSJonathan Doman { 791e1e598dSJonathan Doman return; 801e1e598dSJonathan Doman } 811e1e598dSJonathan Doman 821e1e598dSJonathan Doman if (ledOn) 831c8fba97SJames Feist { 84539d8c6bSEd Tanous asyncResp->res.jsonValue["IndicatorLED"] = 85539d8c6bSEd Tanous chassis::IndicatorLED::Lit; 861c8fba97SJames Feist } 871c8fba97SJames Feist else 881c8fba97SJames Feist { 89539d8c6bSEd Tanous asyncResp->res.jsonValue["IndicatorLED"] = 90539d8c6bSEd Tanous chassis::IndicatorLED::Off; 911c8fba97SJames Feist } 921e1e598dSJonathan Doman }); 931e1e598dSJonathan Doman }); 941c8fba97SJames Feist } 951c8fba97SJames Feist 961c8fba97SJames Feist /** 971c8fba97SJames Feist * @brief Sets identify led group properties 981c8fba97SJames Feist * 99ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1001c8fba97SJames Feist * @param[in] ledState LED state passed from request 1011c8fba97SJames Feist * 1021c8fba97SJames Feist * @return None. 1031c8fba97SJames Feist */ 1049f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 1058d1b46d7Szhanghch05 inline void 106ac106bf6SEd Tanous setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1071c8fba97SJames Feist const std::string& ledState) 1081c8fba97SJames Feist { 10962598e31SEd Tanous BMCWEB_LOG_DEBUG("Set led groups"); 1101c8fba97SJames Feist bool ledOn = false; 1111c8fba97SJames Feist bool ledBlinkng = false; 1121c8fba97SJames Feist 1131c8fba97SJames Feist if (ledState == "Lit") 1141c8fba97SJames Feist { 1151c8fba97SJames Feist ledOn = true; 1161c8fba97SJames Feist } 1171c8fba97SJames Feist else if (ledState == "Blinking") 1181c8fba97SJames Feist { 1191c8fba97SJames Feist ledBlinkng = true; 1201c8fba97SJames Feist } 1211c8fba97SJames Feist else if (ledState != "Off") 1221c8fba97SJames Feist { 123ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, ledState, 124ac106bf6SEd Tanous "IndicatorLED"); 1251c8fba97SJames Feist return; 1261c8fba97SJames Feist } 1271c8fba97SJames Feist 1289ae226faSGeorge Liu sdbusplus::asio::setProperty( 1299ae226faSGeorge Liu *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", 1309ae226faSGeorge Liu "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 1319ae226faSGeorge Liu "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng, 132ac106bf6SEd Tanous [asyncResp, ledOn, 1335e7e2dc5SEd Tanous ledBlinkng](const boost::system::error_code& ec) mutable { 1341c8fba97SJames Feist if (ec) 1351c8fba97SJames Feist { 1361c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 1371c8fba97SJames Feist // Lets set enclosure_identify state to true if Blinking is 1381c8fba97SJames Feist // true. 1391c8fba97SJames Feist if (ledBlinkng) 1401c8fba97SJames Feist { 1411c8fba97SJames Feist ledOn = true; 1421c8fba97SJames Feist } 1431c8fba97SJames Feist } 14487c44966SAsmitha Karunanithi setDbusProperty( 145bd79bce8SPatrick Williams asyncResp, "IndicatorLED", 146bd79bce8SPatrick Williams "xyz.openbmc_project.LED.GroupManager", 14787c44966SAsmitha Karunanithi sdbusplus::message::object_path( 14887c44966SAsmitha Karunanithi "/xyz/openbmc_project/led/groups/enclosure_identify"), 149e93abac6SGinu George "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng); 1509ae226faSGeorge Liu }); 1511c8fba97SJames Feist } 1529f8bfa7cSGunnar Mills 1539f8bfa7cSGunnar Mills /** 15459a17e4fSGeorge Liu * @brief Retrieves identify system led group properties over dbus 1559f8bfa7cSGunnar Mills * 156ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1579f8bfa7cSGunnar Mills * 1589f8bfa7cSGunnar Mills * @return None. 1599f8bfa7cSGunnar Mills */ 16059a17e4fSGeorge Liu inline void getSystemLocationIndicatorActive( 161ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1629f8bfa7cSGunnar Mills { 16362598e31SEd Tanous BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); 164*deae6a78SEd Tanous dbus::utility::getProperty<bool>( 165*deae6a78SEd Tanous "xyz.openbmc_project.LED.GroupManager", 1661e1e598dSJonathan Doman "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 1671e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 168ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, const bool blinking) { 1699f8bfa7cSGunnar Mills // Some systems may not have enclosure_identify_blink object so 1709f8bfa7cSGunnar Mills // proceed to get enclosure_identify state. 1711e1e598dSJonathan Doman if (ec == boost::system::errc::invalid_argument) 1729f8bfa7cSGunnar Mills { 17362598e31SEd Tanous BMCWEB_LOG_DEBUG( 1748ece0e45SEd Tanous "Get identity blinking LED failed, mismatch in property type"); 175ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1769f8bfa7cSGunnar Mills return; 1779f8bfa7cSGunnar Mills } 1789f8bfa7cSGunnar Mills 1791e1e598dSJonathan Doman // Blinking ON, no need to check enclosure_identify assert. 1801e1e598dSJonathan Doman if (!ec && blinking) 1819f8bfa7cSGunnar Mills { 182ac106bf6SEd Tanous asyncResp->res.jsonValue["LocationIndicatorActive"] = true; 1839f8bfa7cSGunnar Mills return; 1841e1e598dSJonathan Doman } 1851e1e598dSJonathan Doman 186*deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1879f8bfa7cSGunnar Mills "xyz.openbmc_project.LED.GroupManager", 1889f8bfa7cSGunnar Mills "/xyz/openbmc_project/led/groups/enclosure_identify", 1891e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 190ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 191ac106bf6SEd Tanous const bool ledOn) { 1921e1e598dSJonathan Doman if (ec2 == boost::system::errc::invalid_argument) 1931e1e598dSJonathan Doman { 19462598e31SEd Tanous BMCWEB_LOG_DEBUG( 1958ece0e45SEd Tanous "Get enclosure identity led failed, mismatch in property type"); 196ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1971e1e598dSJonathan Doman return; 1981e1e598dSJonathan Doman } 1991e1e598dSJonathan Doman 2001e1e598dSJonathan Doman if (ec2) 2011e1e598dSJonathan Doman { 2021e1e598dSJonathan Doman return; 2031e1e598dSJonathan Doman } 2041e1e598dSJonathan Doman 205ac106bf6SEd Tanous asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn; 2061e1e598dSJonathan Doman }); 2071e1e598dSJonathan Doman }); 2089f8bfa7cSGunnar Mills } 2099f8bfa7cSGunnar Mills 2109f8bfa7cSGunnar Mills /** 21159a17e4fSGeorge Liu * @brief Sets identify system led group properties 2129f8bfa7cSGunnar Mills * 213ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2149f8bfa7cSGunnar Mills * @param[in] ledState LED state passed from request 2159f8bfa7cSGunnar Mills * 2169f8bfa7cSGunnar Mills * @return None. 2179f8bfa7cSGunnar Mills */ 21859a17e4fSGeorge Liu inline void setSystemLocationIndicatorActive( 219ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) 2209f8bfa7cSGunnar Mills { 22162598e31SEd Tanous BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); 2229f8bfa7cSGunnar Mills 2239ae226faSGeorge Liu sdbusplus::asio::setProperty( 2249ae226faSGeorge Liu *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", 2259ae226faSGeorge Liu "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 2269ae226faSGeorge Liu "xyz.openbmc_project.Led.Group", "Asserted", ledState, 2279ae226faSGeorge Liu [asyncResp, ledState](const boost::system::error_code& ec) { 2289f8bfa7cSGunnar Mills if (ec) 2299f8bfa7cSGunnar Mills { 2309f8bfa7cSGunnar Mills // Some systems may not have enclosure_identify_blink object so 2319f8bfa7cSGunnar Mills // lets set enclosure_identify state also if 2329f8bfa7cSGunnar Mills // enclosure_identify_blink failed 23387c44966SAsmitha Karunanithi setDbusProperty( 234e93abac6SGinu George asyncResp, "LocationIndicatorActive", 235e93abac6SGinu George "xyz.openbmc_project.LED.GroupManager", 23687c44966SAsmitha Karunanithi sdbusplus::message::object_path( 23787c44966SAsmitha Karunanithi "/xyz/openbmc_project/led/groups/enclosure_identify"), 238e93abac6SGinu George "xyz.openbmc_project.Led.Group", "Asserted", ledState); 2399f8bfa7cSGunnar Mills } 2409ae226faSGeorge Liu }); 2419f8bfa7cSGunnar Mills } 2421c8fba97SJames Feist } // namespace redfish 243