xref: /openbmc/bmcweb/features/redfish/lib/led.hpp (revision 87c449664e5375abb040af6fad63ef965c311bec)
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"
211c8fba97SJames Feist #include "redfish_util.hpp"
221c8fba97SJames Feist 
231e1e598dSJonathan Doman #include <sdbusplus/asio/property.hpp>
247e860f15SJohn Edward Broadbent 
251c8fba97SJames Feist namespace redfish
261c8fba97SJames Feist {
271c8fba97SJames Feist /**
281c8fba97SJames Feist  * @brief Retrieves identify led group properties over dbus
291c8fba97SJames Feist  *
30ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
311c8fba97SJames Feist  *
321c8fba97SJames Feist  * @return None.
331c8fba97SJames Feist  */
349f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed
358d1b46d7Szhanghch05 inline void
36ac106bf6SEd Tanous     getIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
371c8fba97SJames Feist {
3862598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get led groups");
391e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
401e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
411e1e598dSJonathan Doman         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
421e1e598dSJonathan Doman         "xyz.openbmc_project.Led.Group", "Asserted",
43ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool blinking) {
441c8fba97SJames Feist         // Some systems may not have enclosure_identify_blink object so
451c8fba97SJames Feist         // proceed to get enclosure_identify state.
461e1e598dSJonathan Doman         if (ec == boost::system::errc::invalid_argument)
471c8fba97SJames Feist         {
4862598e31SEd Tanous             BMCWEB_LOG_DEBUG(
498ece0e45SEd Tanous                 "Get identity blinking LED failed, mismatch in property type");
50ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
511c8fba97SJames Feist             return;
521c8fba97SJames Feist         }
531c8fba97SJames Feist 
541e1e598dSJonathan Doman         // Blinking ON, no need to check enclosure_identify assert.
551e1e598dSJonathan Doman         if (!ec && blinking)
561e1e598dSJonathan Doman         {
57ac106bf6SEd Tanous             asyncResp->res.jsonValue["IndicatorLED"] = "Blinking";
581e1e598dSJonathan Doman             return;
591e1e598dSJonathan Doman         }
601e1e598dSJonathan Doman 
611e1e598dSJonathan Doman         sdbusplus::asio::getProperty<bool>(
621e1e598dSJonathan Doman             *crow::connections::systemBus,
631e1e598dSJonathan Doman             "xyz.openbmc_project.LED.GroupManager",
641e1e598dSJonathan Doman             "/xyz/openbmc_project/led/groups/enclosure_identify",
651e1e598dSJonathan Doman             "xyz.openbmc_project.Led.Group", "Asserted",
66ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2,
67ac106bf6SEd Tanous                         const bool ledOn) {
681e1e598dSJonathan Doman             if (ec2 == boost::system::errc::invalid_argument)
691e1e598dSJonathan Doman             {
7062598e31SEd Tanous                 BMCWEB_LOG_DEBUG(
718ece0e45SEd Tanous                     "Get enclosure identity led failed, mismatch in property type");
72ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
731e1e598dSJonathan Doman                 return;
741e1e598dSJonathan Doman             }
751e1e598dSJonathan Doman 
761e1e598dSJonathan Doman             if (ec2)
771e1e598dSJonathan Doman             {
781e1e598dSJonathan Doman                 return;
791e1e598dSJonathan Doman             }
801e1e598dSJonathan Doman 
811e1e598dSJonathan Doman             if (ledOn)
821c8fba97SJames Feist             {
83ac106bf6SEd Tanous                 asyncResp->res.jsonValue["IndicatorLED"] = "Lit";
841c8fba97SJames Feist             }
851c8fba97SJames Feist             else
861c8fba97SJames Feist             {
87ac106bf6SEd Tanous                 asyncResp->res.jsonValue["IndicatorLED"] = "Off";
881c8fba97SJames Feist             }
891e1e598dSJonathan Doman         });
901e1e598dSJonathan Doman     });
911c8fba97SJames Feist }
921c8fba97SJames Feist 
931c8fba97SJames Feist /**
941c8fba97SJames Feist  * @brief Sets identify led group properties
951c8fba97SJames Feist  *
96ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
971c8fba97SJames Feist  * @param[in] ledState  LED state passed from request
981c8fba97SJames Feist  *
991c8fba97SJames Feist  * @return None.
1001c8fba97SJames Feist  */
1019f8bfa7cSGunnar Mills // TODO (Gunnar): Remove IndicatorLED after enough time has passed
1028d1b46d7Szhanghch05 inline void
103ac106bf6SEd Tanous     setIndicatorLedState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1041c8fba97SJames Feist                          const std::string& ledState)
1051c8fba97SJames Feist {
10662598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set led groups");
1071c8fba97SJames Feist     bool ledOn = false;
1081c8fba97SJames Feist     bool ledBlinkng = false;
1091c8fba97SJames Feist 
1101c8fba97SJames Feist     if (ledState == "Lit")
1111c8fba97SJames Feist     {
1121c8fba97SJames Feist         ledOn = true;
1131c8fba97SJames Feist     }
1141c8fba97SJames Feist     else if (ledState == "Blinking")
1151c8fba97SJames Feist     {
1161c8fba97SJames Feist         ledBlinkng = true;
1171c8fba97SJames Feist     }
1181c8fba97SJames Feist     else if (ledState != "Off")
1191c8fba97SJames Feist     {
120ac106bf6SEd Tanous         messages::propertyValueNotInList(asyncResp->res, ledState,
121ac106bf6SEd Tanous                                          "IndicatorLED");
1221c8fba97SJames Feist         return;
1231c8fba97SJames Feist     }
1241c8fba97SJames Feist 
1259ae226faSGeorge Liu     sdbusplus::asio::setProperty(
1269ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
1279ae226faSGeorge Liu         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
1289ae226faSGeorge Liu         "xyz.openbmc_project.Led.Group", "Asserted", ledBlinkng,
129ac106bf6SEd Tanous         [asyncResp, ledOn,
1305e7e2dc5SEd Tanous          ledBlinkng](const boost::system::error_code& ec) mutable {
1311c8fba97SJames Feist         if (ec)
1321c8fba97SJames Feist         {
1331c8fba97SJames Feist             // Some systems may not have enclosure_identify_blink object so
1341c8fba97SJames Feist             // Lets set enclosure_identify state to true if Blinking is
1351c8fba97SJames Feist             // true.
1361c8fba97SJames Feist             if (ledBlinkng)
1371c8fba97SJames Feist             {
1381c8fba97SJames Feist                 ledOn = true;
1391c8fba97SJames Feist             }
1401c8fba97SJames Feist         }
141*87c44966SAsmitha Karunanithi         setDbusProperty(
142*87c44966SAsmitha Karunanithi             asyncResp, "xyz.openbmc_project.LED.GroupManager",
143*87c44966SAsmitha Karunanithi             sdbusplus::message::object_path(
144*87c44966SAsmitha Karunanithi                 "/xyz/openbmc_project/led/groups/enclosure_identify"),
145*87c44966SAsmitha Karunanithi             "xyz.openbmc_project.Led.Group", "Asserted", "IndicatorLED",
146*87c44966SAsmitha Karunanithi             ledBlinkng);
1479ae226faSGeorge Liu     });
1481c8fba97SJames Feist }
1499f8bfa7cSGunnar Mills 
1509f8bfa7cSGunnar Mills /**
15159a17e4fSGeorge Liu  * @brief Retrieves identify system led group properties over dbus
1529f8bfa7cSGunnar Mills  *
153ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
1549f8bfa7cSGunnar Mills  *
1559f8bfa7cSGunnar Mills  * @return None.
1569f8bfa7cSGunnar Mills  */
15759a17e4fSGeorge Liu inline void getSystemLocationIndicatorActive(
158ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1599f8bfa7cSGunnar Mills {
16062598e31SEd Tanous     BMCWEB_LOG_DEBUG("Get LocationIndicatorActive");
1611e1e598dSJonathan Doman     sdbusplus::asio::getProperty<bool>(
1621e1e598dSJonathan Doman         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
1631e1e598dSJonathan Doman         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
1641e1e598dSJonathan Doman         "xyz.openbmc_project.Led.Group", "Asserted",
165ac106bf6SEd Tanous         [asyncResp](const boost::system::error_code& ec, const bool blinking) {
1669f8bfa7cSGunnar Mills         // Some systems may not have enclosure_identify_blink object so
1679f8bfa7cSGunnar Mills         // proceed to get enclosure_identify state.
1681e1e598dSJonathan Doman         if (ec == boost::system::errc::invalid_argument)
1699f8bfa7cSGunnar Mills         {
17062598e31SEd Tanous             BMCWEB_LOG_DEBUG(
1718ece0e45SEd Tanous                 "Get identity blinking LED failed, mismatch in property type");
172ac106bf6SEd Tanous             messages::internalError(asyncResp->res);
1739f8bfa7cSGunnar Mills             return;
1749f8bfa7cSGunnar Mills         }
1759f8bfa7cSGunnar Mills 
1761e1e598dSJonathan Doman         // Blinking ON, no need to check enclosure_identify assert.
1771e1e598dSJonathan Doman         if (!ec && blinking)
1789f8bfa7cSGunnar Mills         {
179ac106bf6SEd Tanous             asyncResp->res.jsonValue["LocationIndicatorActive"] = true;
1809f8bfa7cSGunnar Mills             return;
1811e1e598dSJonathan Doman         }
1821e1e598dSJonathan Doman 
1831e1e598dSJonathan Doman         sdbusplus::asio::getProperty<bool>(
1841e1e598dSJonathan Doman             *crow::connections::systemBus,
1859f8bfa7cSGunnar Mills             "xyz.openbmc_project.LED.GroupManager",
1869f8bfa7cSGunnar Mills             "/xyz/openbmc_project/led/groups/enclosure_identify",
1871e1e598dSJonathan Doman             "xyz.openbmc_project.Led.Group", "Asserted",
188ac106bf6SEd Tanous             [asyncResp](const boost::system::error_code& ec2,
189ac106bf6SEd Tanous                         const bool ledOn) {
1901e1e598dSJonathan Doman             if (ec2 == boost::system::errc::invalid_argument)
1911e1e598dSJonathan Doman             {
19262598e31SEd Tanous                 BMCWEB_LOG_DEBUG(
1938ece0e45SEd Tanous                     "Get enclosure identity led failed, mismatch in property type");
194ac106bf6SEd Tanous                 messages::internalError(asyncResp->res);
1951e1e598dSJonathan Doman                 return;
1961e1e598dSJonathan Doman             }
1971e1e598dSJonathan Doman 
1981e1e598dSJonathan Doman             if (ec2)
1991e1e598dSJonathan Doman             {
2001e1e598dSJonathan Doman                 return;
2011e1e598dSJonathan Doman             }
2021e1e598dSJonathan Doman 
203ac106bf6SEd Tanous             asyncResp->res.jsonValue["LocationIndicatorActive"] = ledOn;
2041e1e598dSJonathan Doman         });
2051e1e598dSJonathan Doman     });
2069f8bfa7cSGunnar Mills }
2079f8bfa7cSGunnar Mills 
2089f8bfa7cSGunnar Mills /**
20959a17e4fSGeorge Liu  * @brief Sets identify system led group properties
2109f8bfa7cSGunnar Mills  *
211ac106bf6SEd Tanous  * @param[in] asyncResp     Shared pointer for generating response message.
2129f8bfa7cSGunnar Mills  * @param[in] ledState  LED state passed from request
2139f8bfa7cSGunnar Mills  *
2149f8bfa7cSGunnar Mills  * @return None.
2159f8bfa7cSGunnar Mills  */
21659a17e4fSGeorge Liu inline void setSystemLocationIndicatorActive(
217ac106bf6SEd Tanous     const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool ledState)
2189f8bfa7cSGunnar Mills {
21962598e31SEd Tanous     BMCWEB_LOG_DEBUG("Set LocationIndicatorActive");
2209f8bfa7cSGunnar Mills 
2219ae226faSGeorge Liu     sdbusplus::asio::setProperty(
2229ae226faSGeorge Liu         *crow::connections::systemBus, "xyz.openbmc_project.LED.GroupManager",
2239ae226faSGeorge Liu         "/xyz/openbmc_project/led/groups/enclosure_identify_blink",
2249ae226faSGeorge Liu         "xyz.openbmc_project.Led.Group", "Asserted", ledState,
2259ae226faSGeorge Liu         [asyncResp, ledState](const boost::system::error_code& ec) {
2269f8bfa7cSGunnar Mills         if (ec)
2279f8bfa7cSGunnar Mills         {
2289f8bfa7cSGunnar Mills             // Some systems may not have enclosure_identify_blink object so
2299f8bfa7cSGunnar Mills             // lets set enclosure_identify state also if
2309f8bfa7cSGunnar Mills             // enclosure_identify_blink failed
231*87c44966SAsmitha Karunanithi             setDbusProperty(
232*87c44966SAsmitha Karunanithi                 asyncResp, "xyz.openbmc_project.LED.GroupManager",
233*87c44966SAsmitha Karunanithi                 sdbusplus::message::object_path(
234*87c44966SAsmitha Karunanithi                     "/xyz/openbmc_project/led/groups/enclosure_identify"),
235*87c44966SAsmitha Karunanithi                 "xyz.openbmc_project.Led.Group", "Asserted",
236*87c44966SAsmitha Karunanithi                 "LocationIndicatorActive", ledState);
2379f8bfa7cSGunnar Mills         }
2389ae226faSGeorge Liu     });
2399f8bfa7cSGunnar Mills }
2401c8fba97SJames Feist } // namespace redfish
241