xref: /openbmc/bmcweb/features/redfish/lib/led.hpp (revision 40e9b92ec19acffb46f83a6e55b18974da5d708e)
1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2019 Intel Corporation
41c8fba97SJames Feist #pragma once
51c8fba97SJames Feist 
63ccb3adbSEd Tanous #include "app.hpp"
71c8fba97SJames Feist #include "async_resp.hpp"
81c8fba97SJames Feist #include "dbus_utility.hpp"
9539d8c6bSEd Tanous #include "generated/enums/chassis.hpp"
101c8fba97SJames Feist #include "redfish_util.hpp"
111c8fba97SJames Feist 
121e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp>
137e860f15SJohn Edward Broadbent 
141c8fba97SJames Feist namespace redfish
151c8fba97SJames Feist {
161c8fba97SJames Feist /**
171c8fba97SJames Feist  * @brief Retrieves identify led group properties over dbus
181c8fba97SJames Feist  *
19ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
201c8fba97SJames Feist  *
211c8fba97SJames Feist  * @return None.
221c8fba97SJames Feist  */
239f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed
248d1b46d7Szhanghch05 inline void
25ac106bf6SEd Tanous     getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
261c8fba97SJames Feist {
2762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get led groups");
28deae6a78SEd Tanous     dbus::utility::getProperty<bool>(
29deae6a78SEd Tanous         "xyz.openbmc_project.LED.GroupManager",
301e1e598dSJonathan Doman         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
311e1e598dSJonathan Doman         "xyz.openbmc_project.Led.Group", "Asserted",
32ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool blinking) {
331c8fba97SJames Feist             // Some systems may not have enclosure_identify_blink object so
341c8fba97SJames Feist             // proceed to get enclosure_identify state.
351e1e598dSJonathan Doman             if (ec == boost::system::errc::invalid_argument)
361c8fba97SJames Feist             {
3762598e31SEd Tanous                 BMCWEB_LOG_DEBUG(
388ece0e45SEd Tanous                     "Get identity blinking LED failed, mismatch in property type");
39ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
401c8fba97SJames Feist                 return;
411c8fba97SJames Feist             }
421c8fba97SJames Feist 
431e1e598dSJonathan Doman             // Blinking ON, no need to check enclosure_identify assert.
441e1e598dSJonathan Doman             if (!ec && blinking)
451e1e598dSJonathan Doman             {
46539d8c6bSEd Tanous                 asyncResp->res.jsonValue["IndicatorLED"] =
47539d8c6bSEd Tanous                     chassis::IndicatorLED::Blinking;
481e1e598dSJonathan Doman                 return;
491e1e598dSJonathan Doman             }
501e1e598dSJonathan Doman 
51deae6a78SEd Tanous             dbus::utility::getProperty<bool>(
521e1e598dSJonathan Doman                 "xyz.openbmc_project.LED.GroupManager",
531e1e598dSJonathan Doman                 "/xyz/openbmc_project/led/groups/enclosure_identify",
541e1e598dSJonathan Doman                 "xyz.openbmc_project.Led.Group", "Asserted",
55ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2,
56ac106bf6SEd Tanous                             const bool ledOn) {
571e1e598dSJonathan Doman                     if (ec2 == boost::system::errc::invalid_argument)
581e1e598dSJonathan Doman                     {
5962598e31SEd Tanous                         BMCWEB_LOG_DEBUG(
608ece0e45SEd Tanous                             "Get enclosure identity led failed, mismatch in property type");
61ac106bf6SEd Tanous                         messages::internalError(asyncResp->res);
621e1e598dSJonathan Doman                         return;
631e1e598dSJonathan Doman                     }
641e1e598dSJonathan Doman 
651e1e598dSJonathan Doman                     if (ec2)
661e1e598dSJonathan Doman                     {
671e1e598dSJonathan Doman                         return;
681e1e598dSJonathan Doman                     }
691e1e598dSJonathan Doman 
701e1e598dSJonathan Doman                     if (ledOn)
711c8fba97SJames Feist                     {
72539d8c6bSEd Tanous                         asyncResp->res.jsonValue["IndicatorLED"] =
73539d8c6bSEd Tanous                             chassis::IndicatorLED::Lit;
741c8fba97SJames Feist                     }
751c8fba97SJames Feist                     else
761c8fba97SJames Feist                     {
77539d8c6bSEd Tanous                         asyncResp->res.jsonValue["IndicatorLED"] =
78539d8c6bSEd Tanous                             chassis::IndicatorLED::Off;
791c8fba97SJames Feist                     }
801e1e598dSJonathan Doman                 });
811e1e598dSJonathan Doman         });
821c8fba97SJames Feist }
831c8fba97SJames Feist 
841c8fba97SJames Feist /**
851c8fba97SJames Feist  * @brief Sets identify led group properties
861c8fba97SJames Feist  *
87ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
881c8fba97SJames Feist  * @param[in] ledState  LED state passed from request
891c8fba97SJames Feist  *
901c8fba97SJames Feist  * @return None.
911c8fba97SJames Feist  */
929f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed
938d1b46d7Szhanghch05 inline void
94ac106bf6SEd Tanous     setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
951c8fba97SJames Feist                          const std::string& ledState)
961c8fba97SJames Feist {
9762598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set led groups");
981c8fba97SJames Feist     bool ledOn = false;
991c8fba97SJames Feist     bool ledBlinkng = false;
1001c8fba97SJames Feist 
1011c8fba97SJames Feist     if (ledState == "Lit")
1021c8fba97SJames Feist     {
1031c8fba97SJames Feist         ledOn = true;
1041c8fba97SJames Feist     }
1051c8fba97SJames Feist     else if (ledState == "Blinking")
1061c8fba97SJames Feist     {
1071c8fba97SJames Feist         ledBlinkng = true;
1081c8fba97SJames Feist     }
1091c8fba97SJames Feist     else if (ledState != "Off")
1101c8fba97SJames Feist     {
111ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, ledState,
112ac106bf6SEd Tanous                                          "IndicatorLED");
1131c8fba97SJames Feist         return;
1141c8fba97SJames Feist     }
1151c8fba97SJames Feist 
1169ae226faSGeorge Liu     sdbusplus::asio::setProperty(
1179ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
1189ae226faSGeorge Liu         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
1199ae226faSGeorge Liu         "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
120ac106bf6SEd Tanous         [asyncResp, ledOn,
1215e7e2dc5SEd Tanous          ledBlinkng](const boost::system::error_code& ec) mutable {
1221c8fba97SJames Feist             if (ec)
1231c8fba97SJames Feist             {
1241c8fba97SJames Feist                 // Some systems may not have enclosure_identify_blink object so
1251c8fba97SJames Feist                 // Lets set enclosure_identify state to true if Blinking is
1261c8fba97SJames Feist                 // true.
1271c8fba97SJames Feist                 if (ledBlinkng)
1281c8fba97SJames Feist                 {
1291c8fba97SJames Feist                     ledOn = true;
1301c8fba97SJames Feist                 }
1311c8fba97SJames Feist             }
13287c44966SAsmitha Karunanithi             setDbusProperty(
133bd79bce8SPatrick Williams                 asyncResp, "IndicatorLED",
134bd79bce8SPatrick Williams                 "xyz.openbmc_project.LED.GroupManager",
13587c44966SAsmitha Karunanithi                 sdbusplus::message::object_path(
13687c44966SAsmitha Karunanithi                     "/xyz/openbmc_project/led/groups/enclosure_identify"),
137e93abac6SGinu George                 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
1389ae226faSGeorge Liu         });
1391c8fba97SJames Feist }
1409f8bfa7cSGunnar Mills 
1419f8bfa7cSGunnar Mills /**
14259a17e4fSGeorge Liu  * @brief Retrieves identify system led group properties over dbus
1439f8bfa7cSGunnar Mills  *
144ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1459f8bfa7cSGunnar Mills  *
1469f8bfa7cSGunnar Mills  * @return None.
1479f8bfa7cSGunnar Mills  */
14859a17e4fSGeorge Liu inline void getSystemLocationIndicatorActive(
149ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1509f8bfa7cSGunnar Mills {
15162598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
152deae6a78SEd Tanous     dbus::utility::getProperty<bool>(
153deae6a78SEd Tanous         "xyz.openbmc_project.LED.GroupManager",
1541e1e598dSJonathan Doman         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
1551e1e598dSJonathan Doman         "xyz.openbmc_project.Led.Group", "Asserted",
156ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool blinking) {
1579f8bfa7cSGunnar Mills             // Some systems may not have enclosure_identify_blink object so
1589f8bfa7cSGunnar Mills             // proceed to get enclosure_identify state.
1591e1e598dSJonathan Doman             if (ec == boost::system::errc::invalid_argument)
1609f8bfa7cSGunnar Mills             {
16162598e31SEd Tanous                 BMCWEB_LOG_DEBUG(
1628ece0e45SEd Tanous                     "Get identity blinking LED failed, mismatch in property type");
163ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
1649f8bfa7cSGunnar Mills                 return;
1659f8bfa7cSGunnar Mills             }
1669f8bfa7cSGunnar Mills 
1671e1e598dSJonathan Doman             // Blinking ON, no need to check enclosure_identify assert.
1681e1e598dSJonathan Doman             if (!ec && blinking)
1699f8bfa7cSGunnar Mills             {
170ac106bf6SEd Tanous                 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
1719f8bfa7cSGunnar Mills                 return;
1721e1e598dSJonathan Doman             }
1731e1e598dSJonathan Doman 
174deae6a78SEd Tanous             dbus::utility::getProperty<bool>(
1759f8bfa7cSGunnar Mills                 "xyz.openbmc_project.LED.GroupManager",
1769f8bfa7cSGunnar Mills                 "/xyz/openbmc_project/led/groups/enclosure_identify",
1771e1e598dSJonathan Doman                 "xyz.openbmc_project.Led.Group", "Asserted",
178ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2,
179ac106bf6SEd Tanous                             const bool ledOn) {
1801e1e598dSJonathan Doman                     if (ec2 == boost::system::errc::invalid_argument)
1811e1e598dSJonathan Doman                     {
18262598e31SEd Tanous                         BMCWEB_LOG_DEBUG(
1838ece0e45SEd Tanous                             "Get enclosure identity led failed, mismatch in property type");
184ac106bf6SEd Tanous                         messages::internalError(asyncResp->res);
1851e1e598dSJonathan Doman                         return;
1861e1e598dSJonathan Doman                     }
1871e1e598dSJonathan Doman 
1881e1e598dSJonathan Doman                     if (ec2)
1891e1e598dSJonathan Doman                     {
1901e1e598dSJonathan Doman                         return;
1911e1e598dSJonathan Doman                     }
1921e1e598dSJonathan Doman 
193ac106bf6SEd Tanous                     asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
1941e1e598dSJonathan Doman                 });
1951e1e598dSJonathan Doman         });
1969f8bfa7cSGunnar Mills }
1979f8bfa7cSGunnar Mills 
1989f8bfa7cSGunnar Mills /**
19959a17e4fSGeorge Liu  * @brief Sets identify system led group properties
2009f8bfa7cSGunnar Mills  *
201ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
2029f8bfa7cSGunnar Mills  * @param[in] ledState  LED state passed from request
2039f8bfa7cSGunnar Mills  *
2049f8bfa7cSGunnar Mills  * @return None.
2059f8bfa7cSGunnar Mills  */
20659a17e4fSGeorge Liu inline void setSystemLocationIndicatorActive(
207ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
2089f8bfa7cSGunnar Mills {
20962598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
2109f8bfa7cSGunnar Mills 
2119ae226faSGeorge Liu     sdbusplus::asio::setProperty(
2129ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
2139ae226faSGeorge Liu         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
2149ae226faSGeorge Liu         "xyz.openbmc_project.Led.Group", "Asserted", ledState,
2159ae226faSGeorge Liu         [asyncResp, ledState](const boost::system::error_code& ec) {
2169f8bfa7cSGunnar Mills             if (ec)
2179f8bfa7cSGunnar Mills             {
2189f8bfa7cSGunnar Mills                 // Some systems may not have enclosure_identify_blink object so
2199f8bfa7cSGunnar Mills                 // lets set enclosure_identify state also if
2209f8bfa7cSGunnar Mills                 // enclosure_identify_blink failed
22187c44966SAsmitha Karunanithi                 setDbusProperty(
222e93abac6SGinu George                     asyncResp, "LocationIndicatorActive",
223e93abac6SGinu George                     "xyz.openbmc_project.LED.GroupManager",
22487c44966SAsmitha Karunanithi                     sdbusplus::message::object_path(
22587c44966SAsmitha Karunanithi                         "/xyz/openbmc_project/led/groups/enclosure_identify"),
226e93abac6SGinu George                     "xyz.openbmc_project.Led.Group", "Asserted", ledState);
2279f8bfa7cSGunnar Mills             }
2289ae226faSGeorge Liu         });
2299f8bfa7cSGunnar Mills }
2301c8fba97SJames Feist } // namespace redfish
231