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 221c8fba97SJames Feist #include <variant> 231c8fba97SJames Feist 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 */ 33*23a21a1cSEd Tanous inline void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) 341c8fba97SJames Feist { 351c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Get led groups"; 361c8fba97SJames Feist crow::connections::systemBus->async_method_call( 371c8fba97SJames Feist [aResp](const boost::system::error_code ec, 381c8fba97SJames Feist const std::variant<bool> asserted) { 391c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 401c8fba97SJames Feist // proceed to get enclosure_identify state. 411c8fba97SJames Feist if (!ec) 421c8fba97SJames Feist { 431c8fba97SJames Feist const bool* blinking = std::get_if<bool>(&asserted); 441c8fba97SJames Feist if (!blinking) 451c8fba97SJames Feist { 461c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; 471c8fba97SJames Feist messages::internalError(aResp->res); 481c8fba97SJames Feist return; 491c8fba97SJames Feist } 501c8fba97SJames Feist // Blinking ON, no need to check enclosure_identify assert. 511c8fba97SJames Feist if (*blinking) 521c8fba97SJames Feist { 531c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Blinking"; 541c8fba97SJames Feist return; 551c8fba97SJames Feist } 561c8fba97SJames Feist } 571c8fba97SJames Feist crow::connections::systemBus->async_method_call( 58*23a21a1cSEd Tanous [aResp](const boost::system::error_code ec2, 59*23a21a1cSEd Tanous const std::variant<bool> asserted2) { 60*23a21a1cSEd Tanous if (!ec2) 611c8fba97SJames Feist { 62*23a21a1cSEd Tanous const bool* ledOn = std::get_if<bool>(&asserted2); 631c8fba97SJames Feist if (!ledOn) 641c8fba97SJames Feist { 651c8fba97SJames Feist BMCWEB_LOG_DEBUG 661c8fba97SJames Feist << "Get enclosure identity led failed"; 671c8fba97SJames Feist messages::internalError(aResp->res); 681c8fba97SJames Feist return; 691c8fba97SJames Feist } 701c8fba97SJames Feist 711c8fba97SJames Feist if (*ledOn) 721c8fba97SJames Feist { 731c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Lit"; 741c8fba97SJames Feist } 751c8fba97SJames Feist else 761c8fba97SJames Feist { 771c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Off"; 781c8fba97SJames Feist } 791c8fba97SJames Feist } 801c8fba97SJames Feist return; 811c8fba97SJames Feist }, 821c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 831c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify", 841c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Get", 851c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted"); 861c8fba97SJames Feist }, 871c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 881c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 891c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Get", 901c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted"); 911c8fba97SJames Feist } 921c8fba97SJames Feist 931c8fba97SJames Feist /** 941c8fba97SJames Feist * @brief Sets identify led group properties 951c8fba97SJames Feist * 961c8fba97SJames Feist * @param[in] aResp Shared pointer for generating response message. 971c8fba97SJames Feist * @param[in] ledState LED state passed from request 981c8fba97SJames Feist * 991c8fba97SJames Feist * @return None. 1001c8fba97SJames Feist */ 101*23a21a1cSEd Tanous inline void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, 1021c8fba97SJames Feist const std::string& ledState) 1031c8fba97SJames Feist { 1041c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Set led groups"; 1051c8fba97SJames Feist bool ledOn = false; 1061c8fba97SJames Feist bool ledBlinkng = false; 1071c8fba97SJames Feist 1081c8fba97SJames Feist if (ledState == "Lit") 1091c8fba97SJames Feist { 1101c8fba97SJames Feist ledOn = true; 1111c8fba97SJames Feist } 1121c8fba97SJames Feist else if (ledState == "Blinking") 1131c8fba97SJames Feist { 1141c8fba97SJames Feist ledBlinkng = true; 1151c8fba97SJames Feist } 1161c8fba97SJames Feist else if (ledState != "Off") 1171c8fba97SJames Feist { 1181c8fba97SJames Feist messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED"); 1191c8fba97SJames Feist return; 1201c8fba97SJames Feist } 1211c8fba97SJames Feist 1221c8fba97SJames Feist crow::connections::systemBus->async_method_call( 1231c8fba97SJames Feist [aResp, ledOn, ledBlinkng](const boost::system::error_code ec, 1241c8fba97SJames Feist const std::variant<bool> asserted) mutable { 1251c8fba97SJames Feist if (ec) 1261c8fba97SJames Feist { 1271c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 1281c8fba97SJames Feist // Lets set enclosure_identify state to true if Blinking is 1291c8fba97SJames Feist // true. 1301c8fba97SJames Feist if (ledBlinkng) 1311c8fba97SJames Feist { 1321c8fba97SJames Feist ledOn = true; 1331c8fba97SJames Feist } 1341c8fba97SJames Feist } 1351c8fba97SJames Feist crow::connections::systemBus->async_method_call( 136*23a21a1cSEd Tanous [aResp](const boost::system::error_code ec2, 137*23a21a1cSEd Tanous const std::variant<bool> asserted2) { 138*23a21a1cSEd Tanous if (ec2) 1391c8fba97SJames Feist { 140*23a21a1cSEd Tanous BMCWEB_LOG_DEBUG << "DBUS response error " << ec2; 1411c8fba97SJames Feist messages::internalError(aResp->res); 1421c8fba97SJames Feist return; 1431c8fba97SJames Feist } 1441c8fba97SJames Feist }, 1451c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 1461c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify", 1471c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Set", 1481c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted", 1491c8fba97SJames Feist std::variant<bool>(ledOn)); 1501c8fba97SJames Feist }, 1511c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 1521c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 1531c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Set", 1541c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted", 1551c8fba97SJames Feist std::variant<bool>(ledBlinkng)); 1561c8fba97SJames Feist } 1571c8fba97SJames Feist } // namespace redfish 158