140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0 240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors 340e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2019 Intel Corporation 41c8fba97SJames Feist #pragma once 51c8fba97SJames Feist 61c8fba97SJames Feist #include "async_resp.hpp" 7*d7857201SEd Tanous #include "dbus_singleton.hpp" 81c8fba97SJames Feist #include "dbus_utility.hpp" 9*d7857201SEd Tanous #include "error_messages.hpp" 10539d8c6bSEd Tanous #include "generated/enums/chassis.hpp" 11*d7857201SEd Tanous #include "logging.hpp" 12*d7857201SEd Tanous #include "utils/dbus_utils.hpp" 131c8fba97SJames Feist 141e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp> 15*d7857201SEd Tanous #include <sdbusplus/message/native_types.hpp> 16*d7857201SEd Tanous 17*d7857201SEd Tanous #include <memory> 187e860f15SJohn Edward Broadbent 191c8fba97SJames Feist namespace redfish 201c8fba97SJames Feist { 211c8fba97SJames Feist /** 221c8fba97SJames Feist * @brief Retrieves identify led group properties over dbus 231c8fba97SJames Feist * 24ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 251c8fba97SJames Feist * 261c8fba97SJames Feist * @return None. 271c8fba97SJames Feist */ 289f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 298d1b46d7Szhanghch05 inline void 30ac106bf6SEd Tanous getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 311c8fba97SJames Feist { 3262598e31SEd Tanous BMCWEB_LOG_DEBUG("Get led groups"); 33deae6a78SEd Tanous dbus::utility::getProperty<bool>( 34deae6a78SEd Tanous "xyz.openbmc_project.LED.GroupManager", 351e1e598dSJonathan Doman "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 361e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 37ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, const bool blinking) { 381c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 391c8fba97SJames Feist // proceed to get enclosure_identify state. 401e1e598dSJonathan Doman if (ec == boost::system::errc::invalid_argument) 411c8fba97SJames Feist { 4262598e31SEd Tanous BMCWEB_LOG_DEBUG( 438ece0e45SEd Tanous "Get identity blinking LED failed, mismatch in property type"); 44ac106bf6SEd Tanous messages::internalError(asyncResp->res); 451c8fba97SJames Feist return; 461c8fba97SJames Feist } 471c8fba97SJames Feist 481e1e598dSJonathan Doman // Blinking ON, no need to check enclosure_identify assert. 491e1e598dSJonathan Doman if (!ec && blinking) 501e1e598dSJonathan Doman { 51539d8c6bSEd Tanous asyncResp->res.jsonValue["IndicatorLED"] = 52539d8c6bSEd Tanous chassis::IndicatorLED::Blinking; 531e1e598dSJonathan Doman return; 541e1e598dSJonathan Doman } 551e1e598dSJonathan Doman 56deae6a78SEd Tanous dbus::utility::getProperty<bool>( 571e1e598dSJonathan Doman "xyz.openbmc_project.LED.GroupManager", 581e1e598dSJonathan Doman "/xyz/openbmc_project/led/groups/enclosure_identify", 591e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 60ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 61ac106bf6SEd Tanous const bool ledOn) { 621e1e598dSJonathan Doman if (ec2 == boost::system::errc::invalid_argument) 631e1e598dSJonathan Doman { 6462598e31SEd Tanous BMCWEB_LOG_DEBUG( 658ece0e45SEd Tanous "Get enclosure identity led failed, mismatch in property type"); 66ac106bf6SEd Tanous messages::internalError(asyncResp->res); 671e1e598dSJonathan Doman return; 681e1e598dSJonathan Doman } 691e1e598dSJonathan Doman 701e1e598dSJonathan Doman if (ec2) 711e1e598dSJonathan Doman { 721e1e598dSJonathan Doman return; 731e1e598dSJonathan Doman } 741e1e598dSJonathan Doman 751e1e598dSJonathan Doman if (ledOn) 761c8fba97SJames Feist { 77539d8c6bSEd Tanous asyncResp->res.jsonValue["IndicatorLED"] = 78539d8c6bSEd Tanous chassis::IndicatorLED::Lit; 791c8fba97SJames Feist } 801c8fba97SJames Feist else 811c8fba97SJames Feist { 82539d8c6bSEd Tanous asyncResp->res.jsonValue["IndicatorLED"] = 83539d8c6bSEd Tanous chassis::IndicatorLED::Off; 841c8fba97SJames Feist } 851e1e598dSJonathan Doman }); 861e1e598dSJonathan Doman }); 871c8fba97SJames Feist } 881c8fba97SJames Feist 891c8fba97SJames Feist /** 901c8fba97SJames Feist * @brief Sets identify led group properties 911c8fba97SJames Feist * 92ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 931c8fba97SJames Feist * @param[in] ledState LED state passed from request 941c8fba97SJames Feist * 951c8fba97SJames Feist * @return None. 961c8fba97SJames Feist */ 979f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 988d1b46d7Szhanghch05 inline void 99ac106bf6SEd Tanous setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1001c8fba97SJames Feist const std::string& ledState) 1011c8fba97SJames Feist { 10262598e31SEd Tanous BMCWEB_LOG_DEBUG("Set led groups"); 1031c8fba97SJames Feist bool ledOn = false; 1041c8fba97SJames Feist bool ledBlinkng = false; 1051c8fba97SJames Feist 1061c8fba97SJames Feist if (ledState == "Lit") 1071c8fba97SJames Feist { 1081c8fba97SJames Feist ledOn = true; 1091c8fba97SJames Feist } 1101c8fba97SJames Feist else if (ledState == "Blinking") 1111c8fba97SJames Feist { 1121c8fba97SJames Feist ledBlinkng = true; 1131c8fba97SJames Feist } 1141c8fba97SJames Feist else if (ledState != "Off") 1151c8fba97SJames Feist { 116ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, ledState, 117ac106bf6SEd Tanous "IndicatorLED"); 1181c8fba97SJames Feist return; 1191c8fba97SJames Feist } 1201c8fba97SJames Feist 1219ae226faSGeorge Liu sdbusplus::asio::setProperty( 1229ae226faSGeorge Liu *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", 1239ae226faSGeorge Liu "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 1249ae226faSGeorge Liu "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng, 125ac106bf6SEd Tanous [asyncResp, ledOn, 1265e7e2dc5SEd Tanous ledBlinkng](const boost::system::error_code& ec) mutable { 1271c8fba97SJames Feist if (ec) 1281c8fba97SJames Feist { 1291c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 1301c8fba97SJames Feist // Lets set enclosure_identify state to true if Blinking is 1311c8fba97SJames Feist // true. 1321c8fba97SJames Feist if (ledBlinkng) 1331c8fba97SJames Feist { 1341c8fba97SJames Feist ledOn = true; 1351c8fba97SJames Feist } 1361c8fba97SJames Feist } 13787c44966SAsmitha Karunanithi setDbusProperty( 138bd79bce8SPatrick Williams asyncResp, "IndicatorLED", 139bd79bce8SPatrick Williams "xyz.openbmc_project.LED.GroupManager", 14087c44966SAsmitha Karunanithi sdbusplus::message::object_path( 14187c44966SAsmitha Karunanithi "/xyz/openbmc_project/led/groups/enclosure_identify"), 142e93abac6SGinu George "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng); 1439ae226faSGeorge Liu }); 1441c8fba97SJames Feist } 1459f8bfa7cSGunnar Mills 1469f8bfa7cSGunnar Mills /** 14759a17e4fSGeorge Liu * @brief Retrieves identify system led group properties over dbus 1489f8bfa7cSGunnar Mills * 149ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 1509f8bfa7cSGunnar Mills * 1519f8bfa7cSGunnar Mills * @return None. 1529f8bfa7cSGunnar Mills */ 15359a17e4fSGeorge Liu inline void getSystemLocationIndicatorActive( 154ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 1559f8bfa7cSGunnar Mills { 15662598e31SEd Tanous BMCWEB_LOG_DEBUG("Get LocationIndicatorActive"); 157deae6a78SEd Tanous dbus::utility::getProperty<bool>( 158deae6a78SEd Tanous "xyz.openbmc_project.LED.GroupManager", 1591e1e598dSJonathan Doman "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 1601e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 161ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, const bool blinking) { 1629f8bfa7cSGunnar Mills // Some systems may not have enclosure_identify_blink object so 1639f8bfa7cSGunnar Mills // proceed to get enclosure_identify state. 1641e1e598dSJonathan Doman if (ec == boost::system::errc::invalid_argument) 1659f8bfa7cSGunnar Mills { 16662598e31SEd Tanous BMCWEB_LOG_DEBUG( 1678ece0e45SEd Tanous "Get identity blinking LED failed, mismatch in property type"); 168ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1699f8bfa7cSGunnar Mills return; 1709f8bfa7cSGunnar Mills } 1719f8bfa7cSGunnar Mills 1721e1e598dSJonathan Doman // Blinking ON, no need to check enclosure_identify assert. 1731e1e598dSJonathan Doman if (!ec && blinking) 1749f8bfa7cSGunnar Mills { 175ac106bf6SEd Tanous asyncResp->res.jsonValue["LocationIndicatorActive"] = true; 1769f8bfa7cSGunnar Mills return; 1771e1e598dSJonathan Doman } 1781e1e598dSJonathan Doman 179deae6a78SEd Tanous dbus::utility::getProperty<bool>( 1809f8bfa7cSGunnar Mills "xyz.openbmc_project.LED.GroupManager", 1819f8bfa7cSGunnar Mills "/xyz/openbmc_project/led/groups/enclosure_identify", 1821e1e598dSJonathan Doman "xyz.openbmc_project.Led.Group", "Asserted", 183ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2, 184ac106bf6SEd Tanous const bool ledOn) { 1851e1e598dSJonathan Doman if (ec2 == boost::system::errc::invalid_argument) 1861e1e598dSJonathan Doman { 18762598e31SEd Tanous BMCWEB_LOG_DEBUG( 1888ece0e45SEd Tanous "Get enclosure identity led failed, mismatch in property type"); 189ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1901e1e598dSJonathan Doman return; 1911e1e598dSJonathan Doman } 1921e1e598dSJonathan Doman 1931e1e598dSJonathan Doman if (ec2) 1941e1e598dSJonathan Doman { 1951e1e598dSJonathan Doman return; 1961e1e598dSJonathan Doman } 1971e1e598dSJonathan Doman 198ac106bf6SEd Tanous asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn; 1991e1e598dSJonathan Doman }); 2001e1e598dSJonathan Doman }); 2019f8bfa7cSGunnar Mills } 2029f8bfa7cSGunnar Mills 2039f8bfa7cSGunnar Mills /** 20459a17e4fSGeorge Liu * @brief Sets identify system led group properties 2059f8bfa7cSGunnar Mills * 206ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for generating response message. 2079f8bfa7cSGunnar Mills * @param[in] ledState LED state passed from request 2089f8bfa7cSGunnar Mills * 2099f8bfa7cSGunnar Mills * @return None. 2109f8bfa7cSGunnar Mills */ 21159a17e4fSGeorge Liu inline void setSystemLocationIndicatorActive( 212ac106bf6SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState) 2139f8bfa7cSGunnar Mills { 21462598e31SEd Tanous BMCWEB_LOG_DEBUG("Set LocationIndicatorActive"); 2159f8bfa7cSGunnar Mills 2169ae226faSGeorge Liu sdbusplus::asio::setProperty( 2179ae226faSGeorge Liu *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager", 2189ae226faSGeorge Liu "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 2199ae226faSGeorge Liu "xyz.openbmc_project.Led.Group", "Asserted", ledState, 2209ae226faSGeorge Liu [asyncResp, ledState](const boost::system::error_code& ec) { 2219f8bfa7cSGunnar Mills if (ec) 2229f8bfa7cSGunnar Mills { 2239f8bfa7cSGunnar Mills // Some systems may not have enclosure_identify_blink object so 2249f8bfa7cSGunnar Mills // lets set enclosure_identify state also if 2259f8bfa7cSGunnar Mills // enclosure_identify_blink failed 22687c44966SAsmitha Karunanithi setDbusProperty( 227e93abac6SGinu George asyncResp, "LocationIndicatorActive", 228e93abac6SGinu George "xyz.openbmc_project.LED.GroupManager", 22987c44966SAsmitha Karunanithi sdbusplus::message::object_path( 23087c44966SAsmitha Karunanithi "/xyz/openbmc_project/led/groups/enclosure_identify"), 231e93abac6SGinu George "xyz.openbmc_project.Led.Group", "Asserted", ledState); 2329f8bfa7cSGunnar Mills } 2339ae226faSGeorge Liu }); 2349f8bfa7cSGunnar Mills } 2351c8fba97SJames Feist } // namespace redfish 236