xref: /openbmc/bmcweb/redfish-core/lib/led.hpp (revision 6be832e2)
11c8fba97SJames Feist /*
2*6be832e2SEd Tanous Copyright (c) 2019 Intel Corporation
3*6be832e2SEd Tanous 
4*6be832e2SEd Tanous Licensed under the Apache License, Version 2.0 (the "License");
5*6be832e2SEd Tanous you may not use this file except in compliance with the License.
6*6be832e2SEd Tanous You may obtain a copy of the License at
7*6be832e2SEd Tanous 
8*6be832e2SEd Tanous       http://www.apache.org/licenses/LICENSE-2.0
9*6be832e2SEd Tanous 
10*6be832e2SEd Tanous Unless required by applicable law or agreed to in writing, software
11*6be832e2SEd Tanous distributed under the License is distributed on an "AS IS" BASIS,
12*6be832e2SEd Tanous WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13*6be832e2SEd Tanous See the License for the specific language governing permissions and
14*6be832e2SEd Tanous limitations under the License.
151c8fba97SJames Feist */
161c8fba97SJames Feist #pragma once
171c8fba97SJames Feist 
183ccb3adbSEd Tanous #include "app.hpp"
191c8fba97SJames Feist #include "async_resp.hpp"
201c8fba97SJames Feist #include "dbus_utility.hpp"
21539d8c6bSEd Tanous #include "generated/enums/chassis.hpp"
221c8fba97SJames Feist #include "redfish_util.hpp"
231c8fba97SJames Feist 
241e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp>
257e860f15SJohn Edward Broadbent 
261c8fba97SJames Feist namespace redfish
271c8fba97SJames Feist {
281c8fba97SJames Feist /**
291c8fba97SJames Feist  * @brief Retrieves identify led group properties over dbus
301c8fba97SJames Feist  *
31ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
321c8fba97SJames Feist  *
331c8fba97SJames Feist  * @return None.
341c8fba97SJames Feist  */
359f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed
368d1b46d7Szhanghch05 inline void
getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)37ac106bf6SEd Tanous     getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
381c8fba97SJames Feist {
3962598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get led groups");
401e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
411e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
421e1e598dSJonathan Doman         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
431e1e598dSJonathan Doman         "xyz.openbmc_project.Led.Group", "Asserted",
44ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool blinking) {
451c8fba97SJames Feist             // Some systems may not have enclosure_identify_blink object so
461c8fba97SJames Feist             // proceed to get enclosure_identify state.
471e1e598dSJonathan Doman             if (ec == boost::system::errc::invalid_argument)
481c8fba97SJames Feist             {
4962598e31SEd Tanous                 BMCWEB_LOG_DEBUG(
508ece0e45SEd Tanous                     "Get identity blinking LED failed, mismatch in property type");
51ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
521c8fba97SJames Feist                 return;
531c8fba97SJames Feist             }
541c8fba97SJames Feist 
551e1e598dSJonathan Doman             // Blinking ON, no need to check enclosure_identify assert.
561e1e598dSJonathan Doman             if (!ec && blinking)
571e1e598dSJonathan Doman             {
58539d8c6bSEd Tanous                 asyncResp->res.jsonValue["IndicatorLED"] =
59539d8c6bSEd Tanous                     chassis::IndicatorLED::Blinking;
601e1e598dSJonathan Doman                 return;
611e1e598dSJonathan Doman             }
621e1e598dSJonathan Doman 
631e1e598dSJonathan Doman             sdbusplus::asio::getProperty<bool>(
641e1e598dSJonathan Doman                 *crow::connections::systemBus,
651e1e598dSJonathan Doman                 "xyz.openbmc_project.LED.GroupManager",
661e1e598dSJonathan Doman                 "/xyz/openbmc_project/led/groups/enclosure_identify",
671e1e598dSJonathan Doman                 "xyz.openbmc_project.Led.Group", "Asserted",
68ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2,
69ac106bf6SEd Tanous                             const bool ledOn) {
701e1e598dSJonathan Doman                     if (ec2 == boost::system::errc::invalid_argument)
711e1e598dSJonathan Doman                     {
7262598e31SEd Tanous                         BMCWEB_LOG_DEBUG(
738ece0e45SEd Tanous                             "Get enclosure identity led failed, mismatch in property type");
74ac106bf6SEd Tanous                         messages::internalError(asyncResp->res);
751e1e598dSJonathan Doman                         return;
761e1e598dSJonathan Doman                     }
771e1e598dSJonathan Doman 
781e1e598dSJonathan Doman                     if (ec2)
791e1e598dSJonathan Doman                     {
801e1e598dSJonathan Doman                         return;
811e1e598dSJonathan Doman                     }
821e1e598dSJonathan Doman 
831e1e598dSJonathan Doman                     if (ledOn)
841c8fba97SJames Feist                     {
85539d8c6bSEd Tanous                         asyncResp->res.jsonValue["IndicatorLED"] =
86539d8c6bSEd Tanous                             chassis::IndicatorLED::Lit;
871c8fba97SJames Feist                     }
881c8fba97SJames Feist                     else
891c8fba97SJames Feist                     {
90539d8c6bSEd Tanous                         asyncResp->res.jsonValue["IndicatorLED"] =
91539d8c6bSEd Tanous                             chassis::IndicatorLED::Off;
921c8fba97SJames Feist                     }
931e1e598dSJonathan Doman                 });
941e1e598dSJonathan Doman         });
951c8fba97SJames Feist }
961c8fba97SJames Feist 
971c8fba97SJames Feist /**
981c8fba97SJames Feist  * @brief Sets identify led group properties
991c8fba97SJames Feist  *
100ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1011c8fba97SJames Feist  * @param[in] ledState  LED state passed from request
1021c8fba97SJames Feist  *
1031c8fba97SJames Feist  * @return None.
1041c8fba97SJames Feist  */
1059f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed
1068d1b46d7Szhanghch05 inline void
setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & ledState)107ac106bf6SEd Tanous     setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1081c8fba97SJames Feist                          const std::string& ledState)
1091c8fba97SJames Feist {
11062598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set led groups");
1111c8fba97SJames Feist     bool ledOn = false;
1121c8fba97SJames Feist     bool ledBlinkng = false;
1131c8fba97SJames Feist 
1141c8fba97SJames Feist     if (ledState == "Lit")
1151c8fba97SJames Feist     {
1161c8fba97SJames Feist         ledOn = true;
1171c8fba97SJames Feist     }
1181c8fba97SJames Feist     else if (ledState == "Blinking")
1191c8fba97SJames Feist     {
1201c8fba97SJames Feist         ledBlinkng = true;
1211c8fba97SJames Feist     }
1221c8fba97SJames Feist     else if (ledState != "Off")
1231c8fba97SJames Feist     {
124ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, ledState,
125ac106bf6SEd Tanous                                          "IndicatorLED");
1261c8fba97SJames Feist         return;
1271c8fba97SJames Feist     }
1281c8fba97SJames Feist 
1299ae226faSGeorge Liu     sdbusplus::asio::setProperty(
1309ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
1319ae226faSGeorge Liu         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
1329ae226faSGeorge Liu         "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
133ac106bf6SEd Tanous         [asyncResp, ledOn,
1345e7e2dc5SEd Tanous          ledBlinkng](const boost::system::error_code& ec) mutable {
1351c8fba97SJames Feist             if (ec)
1361c8fba97SJames Feist             {
1371c8fba97SJames Feist                 // Some systems may not have enclosure_identify_blink object so
1381c8fba97SJames Feist                 // Lets set enclosure_identify state to true if Blinking is
1391c8fba97SJames Feist                 // true.
1401c8fba97SJames Feist                 if (ledBlinkng)
1411c8fba97SJames Feist                 {
1421c8fba97SJames Feist                     ledOn = true;
1431c8fba97SJames Feist                 }
1441c8fba97SJames Feist             }
14587c44966SAsmitha Karunanithi             setDbusProperty(
146bd79bce8SPatrick Williams                 asyncResp, "IndicatorLED",
147bd79bce8SPatrick Williams                 "xyz.openbmc_project.LED.GroupManager",
14887c44966SAsmitha Karunanithi                 sdbusplus::message::object_path(
14987c44966SAsmitha Karunanithi                     "/xyz/openbmc_project/led/groups/enclosure_identify"),
150e93abac6SGinu George                 "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
1519ae226faSGeorge Liu         });
1521c8fba97SJames Feist }
1539f8bfa7cSGunnar Mills 
1549f8bfa7cSGunnar Mills /**
15559a17e4fSGeorge Liu  * @brief Retrieves identify system led group properties over dbus
1569f8bfa7cSGunnar Mills  *
157ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1589f8bfa7cSGunnar Mills  *
1599f8bfa7cSGunnar Mills  * @return None.
1609f8bfa7cSGunnar Mills  */
getSystemLocationIndicatorActive(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)16159a17e4fSGeorge Liu inline void getSystemLocationIndicatorActive(
162ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1639f8bfa7cSGunnar Mills {
16462598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
1651e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
1661e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
1671e1e598dSJonathan Doman         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
1681e1e598dSJonathan Doman         "xyz.openbmc_project.Led.Group", "Asserted",
169ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool blinking) {
1709f8bfa7cSGunnar Mills             // Some systems may not have enclosure_identify_blink object so
1719f8bfa7cSGunnar Mills             // proceed to get enclosure_identify state.
1721e1e598dSJonathan Doman             if (ec == boost::system::errc::invalid_argument)
1739f8bfa7cSGunnar Mills             {
17462598e31SEd Tanous                 BMCWEB_LOG_DEBUG(
1758ece0e45SEd Tanous                     "Get identity blinking LED failed, mismatch in property type");
176ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
1779f8bfa7cSGunnar Mills                 return;
1789f8bfa7cSGunnar Mills             }
1799f8bfa7cSGunnar Mills 
1801e1e598dSJonathan Doman             // Blinking ON, no need to check enclosure_identify assert.
1811e1e598dSJonathan Doman             if (!ec && blinking)
1829f8bfa7cSGunnar Mills             {
183ac106bf6SEd Tanous                 asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
1849f8bfa7cSGunnar Mills                 return;
1851e1e598dSJonathan Doman             }
1861e1e598dSJonathan Doman 
1871e1e598dSJonathan Doman             sdbusplus::asio::getProperty<bool>(
1881e1e598dSJonathan Doman                 *crow::connections::systemBus,
1899f8bfa7cSGunnar Mills                 "xyz.openbmc_project.LED.GroupManager",
1909f8bfa7cSGunnar Mills                 "/xyz/openbmc_project/led/groups/enclosure_identify",
1911e1e598dSJonathan Doman                 "xyz.openbmc_project.Led.Group", "Asserted",
192ac106bf6SEd Tanous                 [asyncResp](const boost::system::error_code& ec2,
193ac106bf6SEd Tanous                             const bool ledOn) {
1941e1e598dSJonathan Doman                     if (ec2 == boost::system::errc::invalid_argument)
1951e1e598dSJonathan Doman                     {
19662598e31SEd Tanous                         BMCWEB_LOG_DEBUG(
1978ece0e45SEd Tanous                             "Get enclosure identity led failed, mismatch in property type");
198ac106bf6SEd Tanous                         messages::internalError(asyncResp->res);
1991e1e598dSJonathan Doman                         return;
2001e1e598dSJonathan Doman                     }
2011e1e598dSJonathan Doman 
2021e1e598dSJonathan Doman                     if (ec2)
2031e1e598dSJonathan Doman                     {
2041e1e598dSJonathan Doman                         return;
2051e1e598dSJonathan Doman                     }
2061e1e598dSJonathan Doman 
207ac106bf6SEd Tanous                     asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
2081e1e598dSJonathan Doman                 });
2091e1e598dSJonathan Doman         });
2109f8bfa7cSGunnar Mills }
2119f8bfa7cSGunnar Mills 
2129f8bfa7cSGunnar Mills /**
21359a17e4fSGeorge Liu  * @brief Sets identify system led group properties
2149f8bfa7cSGunnar Mills  *
215ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
2169f8bfa7cSGunnar Mills  * @param[in] ledState  LED state passed from request
2179f8bfa7cSGunnar Mills  *
2189f8bfa7cSGunnar Mills  * @return None.
2199f8bfa7cSGunnar Mills  */
setSystemLocationIndicatorActive(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const bool ledState)22059a17e4fSGeorge Liu inline void setSystemLocationIndicatorActive(
221ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
2229f8bfa7cSGunnar Mills {
22362598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
2249f8bfa7cSGunnar Mills 
2259ae226faSGeorge Liu     sdbusplus::asio::setProperty(
2269ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
2279ae226faSGeorge Liu         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
2289ae226faSGeorge Liu         "xyz.openbmc_project.Led.Group", "Asserted", ledState,
2299ae226faSGeorge Liu         [asyncResp, ledState](const boost::system::error_code& ec) {
2309f8bfa7cSGunnar Mills             if (ec)
2319f8bfa7cSGunnar Mills             {
2329f8bfa7cSGunnar Mills                 // Some systems may not have enclosure_identify_blink object so
2339f8bfa7cSGunnar Mills                 // lets set enclosure_identify state also if
2349f8bfa7cSGunnar Mills                 // enclosure_identify_blink failed
23587c44966SAsmitha Karunanithi                 setDbusProperty(
236e93abac6SGinu George                     asyncResp, "LocationIndicatorActive",
237e93abac6SGinu George                     "xyz.openbmc_project.LED.GroupManager",
23887c44966SAsmitha Karunanithi                     sdbusplus::message::object_path(
23987c44966SAsmitha Karunanithi                         "/xyz/openbmc_project/led/groups/enclosure_identify"),
240e93abac6SGinu George                     "xyz.openbmc_project.Led.Group", "Asserted", ledState);
2419f8bfa7cSGunnar Mills             }
2429ae226faSGeorge Liu         });
2439f8bfa7cSGunnar Mills }
2441c8fba97SJames Feist } // namespace redfish
245