xref: /openbmc/bmcweb/features/redfish/lib/led.hpp (revision 539d8c6bc399e516d39bcaa18262cf206f4c1035)
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 
183ccb3adbSEd Tanous #include "app.hpp"
191c8fba97SJames Feist #include "async_resp.hpp"
201c8fba97SJames Feist #include "dbus_utility.hpp"
21*539d8c6bSEd 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
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         {
58*539d8c6bSEd Tanous             asyncResp->res.jsonValue["IndicatorLED"] =
59*539d8c6bSEd 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             {
85*539d8c6bSEd Tanous                 asyncResp->res.jsonValue["IndicatorLED"] =
86*539d8c6bSEd Tanous                     chassis::IndicatorLED::Lit;
871c8fba97SJames Feist             }
881c8fba97SJames Feist             else
891c8fba97SJames Feist             {
90*539d8c6bSEd Tanous                 asyncResp->res.jsonValue["IndicatorLED"] =
91*539d8c6bSEd 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
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(
146e93abac6SGinu George             asyncResp, "IndicatorLED", "xyz.openbmc_project.LED.GroupManager",
14787c44966SAsmitha Karunanithi             sdbusplus::message::object_path(
14887c44966SAsmitha Karunanithi                 "/xyz/openbmc_project/led/groups/enclosure_identify"),
149e93abac6SGinu George             "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng);
1509ae226faSGeorge Liu     });
1511c8fba97SJames Feist }
1529f8bfa7cSGunnar Mills 
1539f8bfa7cSGunnar Mills /**
15459a17e4fSGeorge Liu  * @brief Retrieves identify system led group properties over dbus
1559f8bfa7cSGunnar Mills  *
156ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1579f8bfa7cSGunnar Mills  *
1589f8bfa7cSGunnar Mills  * @return None.
1599f8bfa7cSGunnar Mills  */
16059a17e4fSGeorge Liu inline void getSystemLocationIndicatorActive(
161ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1629f8bfa7cSGunnar Mills {
16362598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
1641e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
1651e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
1661e1e598dSJonathan Doman         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
1671e1e598dSJonathan Doman         "xyz.openbmc_project.Led.Group", "Asserted",
168ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool blinking) {
1699f8bfa7cSGunnar Mills         // Some systems may not have enclosure_identify_blink object so
1709f8bfa7cSGunnar Mills         // proceed to get enclosure_identify state.
1711e1e598dSJonathan Doman         if (ec == boost::system::errc::invalid_argument)
1729f8bfa7cSGunnar Mills         {
17362598e31SEd Tanous             BMCWEB_LOG_DEBUG(
1748ece0e45SEd Tanous                 "Get identity blinking LED failed, mismatch in property type");
175ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1769f8bfa7cSGunnar Mills             return;
1779f8bfa7cSGunnar Mills         }
1789f8bfa7cSGunnar Mills 
1791e1e598dSJonathan Doman         // Blinking ON, no need to check enclosure_identify assert.
1801e1e598dSJonathan Doman         if (!ec && blinking)
1819f8bfa7cSGunnar Mills         {
182ac106bf6SEd Tanous             asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
1839f8bfa7cSGunnar Mills             return;
1841e1e598dSJonathan Doman         }
1851e1e598dSJonathan Doman 
1861e1e598dSJonathan Doman         sdbusplus::asio::getProperty<bool>(
1871e1e598dSJonathan Doman             *crow::connections::systemBus,
1889f8bfa7cSGunnar Mills             "xyz.openbmc_project.LED.GroupManager",
1899f8bfa7cSGunnar Mills             "/xyz/openbmc_project/led/groups/enclosure_identify",
1901e1e598dSJonathan Doman             "xyz.openbmc_project.Led.Group", "Asserted",
191ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2,
192ac106bf6SEd Tanous                         const bool ledOn) {
1931e1e598dSJonathan Doman             if (ec2 == boost::system::errc::invalid_argument)
1941e1e598dSJonathan Doman             {
19562598e31SEd Tanous                 BMCWEB_LOG_DEBUG(
1968ece0e45SEd Tanous                     "Get enclosure identity led failed, mismatch in property type");
197ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
1981e1e598dSJonathan Doman                 return;
1991e1e598dSJonathan Doman             }
2001e1e598dSJonathan Doman 
2011e1e598dSJonathan Doman             if (ec2)
2021e1e598dSJonathan Doman             {
2031e1e598dSJonathan Doman                 return;
2041e1e598dSJonathan Doman             }
2051e1e598dSJonathan Doman 
206ac106bf6SEd Tanous             asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
2071e1e598dSJonathan Doman         });
2081e1e598dSJonathan Doman     });
2099f8bfa7cSGunnar Mills }
2109f8bfa7cSGunnar Mills 
2119f8bfa7cSGunnar Mills /**
21259a17e4fSGeorge Liu  * @brief Sets identify system led group properties
2139f8bfa7cSGunnar Mills  *
214ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
2159f8bfa7cSGunnar Mills  * @param[in] ledState  LED state passed from request
2169f8bfa7cSGunnar Mills  *
2179f8bfa7cSGunnar Mills  * @return None.
2189f8bfa7cSGunnar Mills  */
21959a17e4fSGeorge Liu inline void setSystemLocationIndicatorActive(
220ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
2219f8bfa7cSGunnar Mills {
22262598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
2239f8bfa7cSGunnar Mills 
2249ae226faSGeorge Liu     sdbusplus::asio::setProperty(
2259ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
2269ae226faSGeorge Liu         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
2279ae226faSGeorge Liu         "xyz.openbmc_project.Led.Group", "Asserted", ledState,
2289ae226faSGeorge Liu         [asyncResp, ledState](const boost::system::error_code& ec) {
2299f8bfa7cSGunnar Mills         if (ec)
2309f8bfa7cSGunnar Mills         {
2319f8bfa7cSGunnar Mills             // Some systems may not have enclosure_identify_blink object so
2329f8bfa7cSGunnar Mills             // lets set enclosure_identify state also if
2339f8bfa7cSGunnar Mills             // enclosure_identify_blink failed
23487c44966SAsmitha Karunanithi             setDbusProperty(
235e93abac6SGinu George                 asyncResp, "LocationIndicatorActive",
236e93abac6SGinu George                 "xyz.openbmc_project.LED.GroupManager",
23787c44966SAsmitha Karunanithi                 sdbusplus::message::object_path(
23887c44966SAsmitha Karunanithi                     "/xyz/openbmc_project/led/groups/enclosure_identify"),
239e93abac6SGinu George                 "xyz.openbmc_project.Led.Group", "Asserted", ledState);
2409f8bfa7cSGunnar Mills         }
2419ae226faSGeorge Liu     });
2429f8bfa7cSGunnar Mills }
2431c8fba97SJames Feist } // namespace redfish
244