11c8fba97SJames Feist /* 21c8fba97SJames Feist // Copyright (c) 2019 Intel Corporation 31c8fba97SJames Feist // 41c8fba97SJames Feist // Licensed under the Apache License, Version 2.0 (the "License"); 51c8fba97SJames Feist // you may not use this file except in compliance with the License. 61c8fba97SJames Feist // You may obtain a copy of the License at 71c8fba97SJames Feist // 81c8fba97SJames Feist // http://www.apache.org/licenses/LICENSE-2.0 91c8fba97SJames Feist // 101c8fba97SJames Feist // Unless required by applicable law or agreed to in writing, software 111c8fba97SJames Feist // distributed under the License is distributed on an "AS IS" BASIS, 121c8fba97SJames Feist // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 131c8fba97SJames Feist // See the License for the specific language governing permissions and 141c8fba97SJames Feist // limitations under the License. 151c8fba97SJames Feist */ 161c8fba97SJames Feist #pragma once 171c8fba97SJames Feist 181c8fba97SJames Feist #include "async_resp.hpp" 191c8fba97SJames Feist #include "dbus_utility.hpp" 201c8fba97SJames Feist #include "redfish_util.hpp" 211c8fba97SJames Feist 227e860f15SJohn Edward Broadbent #include <app.hpp> 237e860f15SJohn Edward Broadbent 241c8fba97SJames Feist namespace redfish 251c8fba97SJames Feist { 261c8fba97SJames Feist /** 271c8fba97SJames Feist * @brief Retrieves identify led group properties over dbus 281c8fba97SJames Feist * 291c8fba97SJames Feist * @param[in] aResp Shared pointer for generating response message. 301c8fba97SJames Feist * 311c8fba97SJames Feist * @return None. 321c8fba97SJames Feist */ 339f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 348d1b46d7Szhanghch05 inline void 358d1b46d7Szhanghch05 getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 361c8fba97SJames Feist { 371c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Get led groups"; 381c8fba97SJames Feist crow::connections::systemBus->async_method_call( 391c8fba97SJames Feist [aResp](const boost::system::error_code ec, 40*168e20c1SEd Tanous const dbus::utility::DbusVariantType asserted) { 411c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 421c8fba97SJames Feist // proceed to get enclosure_identify state. 431c8fba97SJames Feist if (!ec) 441c8fba97SJames Feist { 451c8fba97SJames Feist const bool* blinking = std::get_if<bool>(&asserted); 461c8fba97SJames Feist if (!blinking) 471c8fba97SJames Feist { 481c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; 491c8fba97SJames Feist messages::internalError(aResp->res); 501c8fba97SJames Feist return; 511c8fba97SJames Feist } 521c8fba97SJames Feist // Blinking ON, no need to check enclosure_identify assert. 531c8fba97SJames Feist if (*blinking) 541c8fba97SJames Feist { 551c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Blinking"; 561c8fba97SJames Feist return; 571c8fba97SJames Feist } 581c8fba97SJames Feist } 591c8fba97SJames Feist crow::connections::systemBus->async_method_call( 6023a21a1cSEd Tanous [aResp](const boost::system::error_code ec2, 61*168e20c1SEd Tanous const dbus::utility::DbusVariantType asserted2) { 6223a21a1cSEd Tanous if (!ec2) 631c8fba97SJames Feist { 6423a21a1cSEd Tanous const bool* ledOn = std::get_if<bool>(&asserted2); 651c8fba97SJames Feist if (!ledOn) 661c8fba97SJames Feist { 671c8fba97SJames Feist BMCWEB_LOG_DEBUG 681c8fba97SJames Feist << "Get enclosure identity led failed"; 691c8fba97SJames Feist messages::internalError(aResp->res); 701c8fba97SJames Feist return; 711c8fba97SJames Feist } 721c8fba97SJames Feist 731c8fba97SJames Feist if (*ledOn) 741c8fba97SJames Feist { 751c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Lit"; 761c8fba97SJames Feist } 771c8fba97SJames Feist else 781c8fba97SJames Feist { 791c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Off"; 801c8fba97SJames Feist } 811c8fba97SJames Feist } 821c8fba97SJames Feist return; 831c8fba97SJames Feist }, 841c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 851c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify", 861c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Get", 871c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted"); 881c8fba97SJames Feist }, 891c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 901c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 911c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Get", 921c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted"); 931c8fba97SJames Feist } 941c8fba97SJames Feist 951c8fba97SJames Feist /** 961c8fba97SJames Feist * @brief Sets identify led group properties 971c8fba97SJames Feist * 981c8fba97SJames Feist * @param[in] aResp Shared pointer for generating response message. 991c8fba97SJames Feist * @param[in] ledState LED state passed from request 1001c8fba97SJames Feist * 1011c8fba97SJames Feist * @return None. 1021c8fba97SJames Feist */ 1039f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed 1048d1b46d7Szhanghch05 inline void 1058d1b46d7Szhanghch05 setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1061c8fba97SJames Feist const std::string& ledState) 1071c8fba97SJames Feist { 1081c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Set led groups"; 1091c8fba97SJames Feist bool ledOn = false; 1101c8fba97SJames Feist bool ledBlinkng = false; 1111c8fba97SJames Feist 1121c8fba97SJames Feist if (ledState == "Lit") 1131c8fba97SJames Feist { 1141c8fba97SJames Feist ledOn = true; 1151c8fba97SJames Feist } 1161c8fba97SJames Feist else if (ledState == "Blinking") 1171c8fba97SJames Feist { 1181c8fba97SJames Feist ledBlinkng = true; 1191c8fba97SJames Feist } 1201c8fba97SJames Feist else if (ledState != "Off") 1211c8fba97SJames Feist { 1221c8fba97SJames Feist messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED"); 1231c8fba97SJames Feist return; 1241c8fba97SJames Feist } 1251c8fba97SJames Feist 1261c8fba97SJames Feist crow::connections::systemBus->async_method_call( 127cb13a392SEd Tanous [aResp, ledOn, ledBlinkng](const boost::system::error_code ec) mutable { 1281c8fba97SJames Feist if (ec) 1291c8fba97SJames Feist { 1301c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 1311c8fba97SJames Feist // Lets set enclosure_identify state to true if Blinking is 1321c8fba97SJames Feist // true. 1331c8fba97SJames Feist if (ledBlinkng) 1341c8fba97SJames Feist { 1351c8fba97SJames Feist ledOn = true; 1361c8fba97SJames Feist } 1371c8fba97SJames Feist } 1381c8fba97SJames Feist crow::connections::systemBus->async_method_call( 139cb13a392SEd Tanous [aResp](const boost::system::error_code ec2) { 14023a21a1cSEd Tanous if (ec2) 1411c8fba97SJames Feist { 14223a21a1cSEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 1431c8fba97SJames Feist messages::internalError(aResp->res); 1441c8fba97SJames Feist return; 1451c8fba97SJames Feist } 1461d40ef69SJayaprakash Mutyala messages::success(aResp->res); 1471c8fba97SJames Feist }, 1481c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 1491c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify", 1501c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Set", 1511c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted", 152*168e20c1SEd Tanous dbus::utility::DbusVariantType(ledOn)); 1531c8fba97SJames Feist }, 1541c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 1551c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 1561c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Set", 1571c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted", 158*168e20c1SEd Tanous dbus::utility::DbusVariantType(ledBlinkng)); 1591c8fba97SJames Feist } 1609f8bfa7cSGunnar Mills 1619f8bfa7cSGunnar Mills /** 1629f8bfa7cSGunnar Mills * @brief Retrieves identify led group properties over dbus 1639f8bfa7cSGunnar Mills * 1649f8bfa7cSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 1659f8bfa7cSGunnar Mills * 1669f8bfa7cSGunnar Mills * @return None. 1679f8bfa7cSGunnar Mills */ 1688d1b46d7Szhanghch05 inline void 1698d1b46d7Szhanghch05 getLocationIndicatorActive(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 1709f8bfa7cSGunnar Mills { 1719f8bfa7cSGunnar Mills BMCWEB_LOG_DEBUG << "Get LocationIndicatorActive"; 1729f8bfa7cSGunnar Mills crow::connections::systemBus->async_method_call( 1739f8bfa7cSGunnar Mills [aResp](const boost::system::error_code ec, 174*168e20c1SEd Tanous const dbus::utility::DbusVariantType asserted) { 1759f8bfa7cSGunnar Mills // Some systems may not have enclosure_identify_blink object so 1769f8bfa7cSGunnar Mills // proceed to get enclosure_identify state. 1779f8bfa7cSGunnar Mills if (!ec) 1789f8bfa7cSGunnar Mills { 1799f8bfa7cSGunnar Mills const bool* blinking = std::get_if<bool>(&asserted); 1809f8bfa7cSGunnar Mills if (!blinking) 1819f8bfa7cSGunnar Mills { 1829f8bfa7cSGunnar Mills BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; 1839f8bfa7cSGunnar Mills messages::internalError(aResp->res); 1849f8bfa7cSGunnar Mills return; 1859f8bfa7cSGunnar Mills } 1869f8bfa7cSGunnar Mills // Blinking ON, no need to check enclosure_identify assert. 1879f8bfa7cSGunnar Mills if (*blinking) 1889f8bfa7cSGunnar Mills { 1899f8bfa7cSGunnar Mills aResp->res.jsonValue["LocationIndicatorActive"] = true; 1909f8bfa7cSGunnar Mills return; 1919f8bfa7cSGunnar Mills } 1929f8bfa7cSGunnar Mills } 1939f8bfa7cSGunnar Mills crow::connections::systemBus->async_method_call( 1949f8bfa7cSGunnar Mills [aResp](const boost::system::error_code ec2, 195*168e20c1SEd Tanous const dbus::utility::DbusVariantType asserted2) { 1969f8bfa7cSGunnar Mills if (!ec2) 1979f8bfa7cSGunnar Mills { 1989f8bfa7cSGunnar Mills const bool* ledOn = std::get_if<bool>(&asserted2); 1999f8bfa7cSGunnar Mills if (!ledOn) 2009f8bfa7cSGunnar Mills { 2019f8bfa7cSGunnar Mills BMCWEB_LOG_DEBUG 2029f8bfa7cSGunnar Mills << "Get enclosure identity led failed"; 2039f8bfa7cSGunnar Mills messages::internalError(aResp->res); 2049f8bfa7cSGunnar Mills return; 2059f8bfa7cSGunnar Mills } 2069f8bfa7cSGunnar Mills 2079f8bfa7cSGunnar Mills if (*ledOn) 2089f8bfa7cSGunnar Mills { 2099f8bfa7cSGunnar Mills aResp->res.jsonValue["LocationIndicatorActive"] = 2109f8bfa7cSGunnar Mills true; 2119f8bfa7cSGunnar Mills } 2129f8bfa7cSGunnar Mills else 2139f8bfa7cSGunnar Mills { 2149f8bfa7cSGunnar Mills aResp->res.jsonValue["LocationIndicatorActive"] = 2159f8bfa7cSGunnar Mills false; 2169f8bfa7cSGunnar Mills } 2179f8bfa7cSGunnar Mills } 2189f8bfa7cSGunnar Mills return; 2199f8bfa7cSGunnar Mills }, 2209f8bfa7cSGunnar Mills "xyz.openbmc_project.LED.GroupManager", 2219f8bfa7cSGunnar Mills "/xyz/openbmc_project/led/groups/enclosure_identify", 2229f8bfa7cSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 2239f8bfa7cSGunnar Mills "xyz.openbmc_project.Led.Group", "Asserted"); 2249f8bfa7cSGunnar Mills }, 2259f8bfa7cSGunnar Mills "xyz.openbmc_project.LED.GroupManager", 2269f8bfa7cSGunnar Mills "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 2279f8bfa7cSGunnar Mills "org.freedesktop.DBus.Properties", "Get", 2289f8bfa7cSGunnar Mills "xyz.openbmc_project.Led.Group", "Asserted"); 2299f8bfa7cSGunnar Mills } 2309f8bfa7cSGunnar Mills 2319f8bfa7cSGunnar Mills /** 2329f8bfa7cSGunnar Mills * @brief Sets identify led group properties 2339f8bfa7cSGunnar Mills * 2349f8bfa7cSGunnar Mills * @param[in] aResp Shared pointer for generating response message. 2359f8bfa7cSGunnar Mills * @param[in] ledState LED state passed from request 2369f8bfa7cSGunnar Mills * 2379f8bfa7cSGunnar Mills * @return None. 2389f8bfa7cSGunnar Mills */ 2398d1b46d7Szhanghch05 inline void 2408d1b46d7Szhanghch05 setLocationIndicatorActive(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 2419f8bfa7cSGunnar Mills const bool ledState) 2429f8bfa7cSGunnar Mills { 2439f8bfa7cSGunnar Mills BMCWEB_LOG_DEBUG << "Set LocationIndicatorActive"; 2449f8bfa7cSGunnar Mills 2459f8bfa7cSGunnar Mills crow::connections::systemBus->async_method_call( 2469f8bfa7cSGunnar Mills [aResp, ledState](const boost::system::error_code ec) mutable { 2479f8bfa7cSGunnar Mills if (ec) 2489f8bfa7cSGunnar Mills { 2499f8bfa7cSGunnar Mills // Some systems may not have enclosure_identify_blink object so 2509f8bfa7cSGunnar Mills // lets set enclosure_identify state also if 2519f8bfa7cSGunnar Mills // enclosure_identify_blink failed 2529f8bfa7cSGunnar Mills crow::connections::systemBus->async_method_call( 2539f8bfa7cSGunnar Mills [aResp](const boost::system::error_code ec2) { 2549f8bfa7cSGunnar Mills if (ec2) 2559f8bfa7cSGunnar Mills { 2569f8bfa7cSGunnar Mills BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 2579f8bfa7cSGunnar Mills messages::internalError(aResp->res); 2589f8bfa7cSGunnar Mills return; 2599f8bfa7cSGunnar Mills } 2609f8bfa7cSGunnar Mills }, 2619f8bfa7cSGunnar Mills "xyz.openbmc_project.LED.GroupManager", 2629f8bfa7cSGunnar Mills "/xyz/openbmc_project/led/groups/enclosure_identify", 2639f8bfa7cSGunnar Mills "org.freedesktop.DBus.Properties", "Set", 2649f8bfa7cSGunnar Mills "xyz.openbmc_project.Led.Group", "Asserted", 265*168e20c1SEd Tanous dbus::utility::DbusVariantType(ledState)); 2669f8bfa7cSGunnar Mills } 2679f8bfa7cSGunnar Mills }, 2689f8bfa7cSGunnar Mills "xyz.openbmc_project.LED.GroupManager", 2699f8bfa7cSGunnar Mills "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 2709f8bfa7cSGunnar Mills "org.freedesktop.DBus.Properties", "Set", 2719f8bfa7cSGunnar Mills "xyz.openbmc_project.Led.Group", "Asserted", 272*168e20c1SEd Tanous dbus::utility::DbusVariantType(ledState)); 2739f8bfa7cSGunnar Mills } 2741c8fba97SJames Feist } // namespace redfish 275