1*1c8fba97SJames Feist /* 2*1c8fba97SJames Feist // Copyright (c) 2019 Intel Corporation 3*1c8fba97SJames Feist // 4*1c8fba97SJames Feist // Licensed under the Apache License, Version 2.0 (the "License"); 5*1c8fba97SJames Feist // you may not use this file except in compliance with the License. 6*1c8fba97SJames Feist // You may obtain a copy of the License at 7*1c8fba97SJames Feist // 8*1c8fba97SJames Feist // http://www.apache.org/licenses/LICENSE-2.0 9*1c8fba97SJames Feist // 10*1c8fba97SJames Feist // Unless required by applicable law or agreed to in writing, software 11*1c8fba97SJames Feist // distributed under the License is distributed on an "AS IS" BASIS, 12*1c8fba97SJames Feist // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13*1c8fba97SJames Feist // See the License for the specific language governing permissions and 14*1c8fba97SJames Feist // limitations under the License. 15*1c8fba97SJames Feist */ 16*1c8fba97SJames Feist #pragma once 17*1c8fba97SJames Feist 18*1c8fba97SJames Feist #include "async_resp.hpp" 19*1c8fba97SJames Feist #include "dbus_utility.hpp" 20*1c8fba97SJames Feist #include "redfish_util.hpp" 21*1c8fba97SJames Feist 22*1c8fba97SJames Feist #include <variant> 23*1c8fba97SJames Feist 24*1c8fba97SJames Feist namespace redfish 25*1c8fba97SJames Feist { 26*1c8fba97SJames Feist /** 27*1c8fba97SJames Feist * @brief Retrieves identify led group properties over dbus 28*1c8fba97SJames Feist * 29*1c8fba97SJames Feist * @param[in] aResp Shared pointer for generating response message. 30*1c8fba97SJames Feist * 31*1c8fba97SJames Feist * @return None. 32*1c8fba97SJames Feist */ 33*1c8fba97SJames Feist void getIndicatorLedState(std::shared_ptr<AsyncResp> aResp) 34*1c8fba97SJames Feist { 35*1c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Get led groups"; 36*1c8fba97SJames Feist crow::connections::systemBus->async_method_call( 37*1c8fba97SJames Feist [aResp](const boost::system::error_code ec, 38*1c8fba97SJames Feist const std::variant<bool> asserted) { 39*1c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 40*1c8fba97SJames Feist // proceed to get enclosure_identify state. 41*1c8fba97SJames Feist if (!ec) 42*1c8fba97SJames Feist { 43*1c8fba97SJames Feist const bool *blinking = std::get_if<bool>(&asserted); 44*1c8fba97SJames Feist if (!blinking) 45*1c8fba97SJames Feist { 46*1c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Get identity blinking LED failed"; 47*1c8fba97SJames Feist messages::internalError(aResp->res); 48*1c8fba97SJames Feist return; 49*1c8fba97SJames Feist } 50*1c8fba97SJames Feist // Blinking ON, no need to check enclosure_identify assert. 51*1c8fba97SJames Feist if (*blinking) 52*1c8fba97SJames Feist { 53*1c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Blinking"; 54*1c8fba97SJames Feist return; 55*1c8fba97SJames Feist } 56*1c8fba97SJames Feist } 57*1c8fba97SJames Feist crow::connections::systemBus->async_method_call( 58*1c8fba97SJames Feist [aResp](const boost::system::error_code ec, 59*1c8fba97SJames Feist const std::variant<bool> asserted) { 60*1c8fba97SJames Feist if (!ec) 61*1c8fba97SJames Feist { 62*1c8fba97SJames Feist const bool *ledOn = std::get_if<bool>(&asserted); 63*1c8fba97SJames Feist if (!ledOn) 64*1c8fba97SJames Feist { 65*1c8fba97SJames Feist BMCWEB_LOG_DEBUG 66*1c8fba97SJames Feist << "Get enclosure identity led failed"; 67*1c8fba97SJames Feist messages::internalError(aResp->res); 68*1c8fba97SJames Feist return; 69*1c8fba97SJames Feist } 70*1c8fba97SJames Feist 71*1c8fba97SJames Feist if (*ledOn) 72*1c8fba97SJames Feist { 73*1c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Lit"; 74*1c8fba97SJames Feist } 75*1c8fba97SJames Feist else 76*1c8fba97SJames Feist { 77*1c8fba97SJames Feist aResp->res.jsonValue["IndicatorLED"] = "Off"; 78*1c8fba97SJames Feist } 79*1c8fba97SJames Feist } 80*1c8fba97SJames Feist return; 81*1c8fba97SJames Feist }, 82*1c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 83*1c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify", 84*1c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Get", 85*1c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted"); 86*1c8fba97SJames Feist }, 87*1c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 88*1c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 89*1c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Get", 90*1c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted"); 91*1c8fba97SJames Feist } 92*1c8fba97SJames Feist 93*1c8fba97SJames Feist /** 94*1c8fba97SJames Feist * @brief Sets identify led group properties 95*1c8fba97SJames Feist * 96*1c8fba97SJames Feist * @param[in] aResp Shared pointer for generating response message. 97*1c8fba97SJames Feist * @param[in] ledState LED state passed from request 98*1c8fba97SJames Feist * 99*1c8fba97SJames Feist * @return None. 100*1c8fba97SJames Feist */ 101*1c8fba97SJames Feist void setIndicatorLedState(std::shared_ptr<AsyncResp> aResp, 102*1c8fba97SJames Feist const std::string &ledState) 103*1c8fba97SJames Feist { 104*1c8fba97SJames Feist BMCWEB_LOG_DEBUG << "Set led groups"; 105*1c8fba97SJames Feist bool ledOn = false; 106*1c8fba97SJames Feist bool ledBlinkng = false; 107*1c8fba97SJames Feist 108*1c8fba97SJames Feist if (ledState == "Lit") 109*1c8fba97SJames Feist { 110*1c8fba97SJames Feist ledOn = true; 111*1c8fba97SJames Feist } 112*1c8fba97SJames Feist else if (ledState == "Blinking") 113*1c8fba97SJames Feist { 114*1c8fba97SJames Feist ledBlinkng = true; 115*1c8fba97SJames Feist } 116*1c8fba97SJames Feist else if (ledState != "Off") 117*1c8fba97SJames Feist { 118*1c8fba97SJames Feist messages::propertyValueNotInList(aResp->res, ledState, "IndicatorLED"); 119*1c8fba97SJames Feist return; 120*1c8fba97SJames Feist } 121*1c8fba97SJames Feist 122*1c8fba97SJames Feist crow::connections::systemBus->async_method_call( 123*1c8fba97SJames Feist [aResp, ledOn, ledBlinkng](const boost::system::error_code ec, 124*1c8fba97SJames Feist const std::variant<bool> asserted) mutable { 125*1c8fba97SJames Feist if (ec) 126*1c8fba97SJames Feist { 127*1c8fba97SJames Feist // Some systems may not have enclosure_identify_blink object so 128*1c8fba97SJames Feist // Lets set enclosure_identify state to true if Blinking is 129*1c8fba97SJames Feist // true. 130*1c8fba97SJames Feist if (ledBlinkng) 131*1c8fba97SJames Feist { 132*1c8fba97SJames Feist ledOn = true; 133*1c8fba97SJames Feist } 134*1c8fba97SJames Feist } 135*1c8fba97SJames Feist crow::connections::systemBus->async_method_call( 136*1c8fba97SJames Feist [aResp](const boost::system::error_code ec, 137*1c8fba97SJames Feist const std::variant<bool> asserted) { 138*1c8fba97SJames Feist if (ec) 139*1c8fba97SJames Feist { 140*1c8fba97SJames Feist BMCWEB_LOG_DEBUG << "DBUS response error " << ec; 141*1c8fba97SJames Feist messages::internalError(aResp->res); 142*1c8fba97SJames Feist return; 143*1c8fba97SJames Feist } 144*1c8fba97SJames Feist }, 145*1c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 146*1c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify", 147*1c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Set", 148*1c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted", 149*1c8fba97SJames Feist std::variant<bool>(ledOn)); 150*1c8fba97SJames Feist }, 151*1c8fba97SJames Feist "xyz.openbmc_project.LED.GroupManager", 152*1c8fba97SJames Feist "/xyz/openbmc_project/led/groups/enclosure_identify_blink", 153*1c8fba97SJames Feist "org.freedesktop.DBus.Properties", "Set", 154*1c8fba97SJames Feist "xyz.openbmc_project.Led.Group", "Asserted", 155*1c8fba97SJames Feist std::variant<bool>(ledBlinkng)); 156*1c8fba97SJames Feist } 157*1c8fba97SJames Feist } // namespace redfish