xref: /openbmc/bmcweb/redfish-core/lib/bios.hpp (revision 25b54dba)
1d82a3acdSCarol Wang #pragma once
2d82a3acdSCarol Wang 
33ccb3adbSEd Tanous #include "app.hpp"
43ccb3adbSEd Tanous #include "query.hpp"
53ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
63ccb3adbSEd Tanous #include "utils/sw_utils.hpp"
745ca1b86SEd Tanous 
8d82a3acdSCarol Wang namespace redfish
9d82a3acdSCarol Wang {
10d82a3acdSCarol Wang /**
11d82a3acdSCarol Wang  * BiosService class supports handle get method for bios.
12d82a3acdSCarol Wang  */
1358eaf5f0SJohn Edward Broadbent inline void
1445ca1b86SEd Tanous     handleBiosServiceGet(crow::App& app, const crow::Request& req,
1522d268cbSEd Tanous                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1622d268cbSEd Tanous                          const std::string& systemName)
1758eaf5f0SJohn Edward Broadbent {
183ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1945ca1b86SEd Tanous     {
2045ca1b86SEd Tanous         return;
2145ca1b86SEd Tanous     }
22*25b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
237f3e84a1SEd Tanous     {
247f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
257f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
267f3e84a1SEd Tanous                                    systemName);
277f3e84a1SEd Tanous         return;
287f3e84a1SEd Tanous     }
2922d268cbSEd Tanous     if (systemName != "system")
3022d268cbSEd Tanous     {
3122d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3222d268cbSEd Tanous                                    systemName);
3322d268cbSEd Tanous         return;
3422d268cbSEd Tanous     }
3558eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
3658eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
3758eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
3858eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
3958eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Id"] = "BIOS";
4058eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
4158eaf5f0SJohn Edward Broadbent         {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
4258eaf5f0SJohn Edward Broadbent 
4358eaf5f0SJohn Edward Broadbent     // Get the ActiveSoftwareImage and SoftwareImages
44eee0013eSWilly Tu     sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
4558eaf5f0SJohn Edward Broadbent                                          true);
4658eaf5f0SJohn Edward Broadbent }
4745ca1b86SEd Tanous 
487e860f15SJohn Edward Broadbent inline void requestRoutesBiosService(App& app)
49d82a3acdSCarol Wang {
5022d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
51ed398213SEd Tanous         .privileges(redfish::privileges::getBios)
5245ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
5345ca1b86SEd Tanous             std::bind_front(handleBiosServiceGet, std::ref(app)));
54d82a3acdSCarol Wang }
5558eaf5f0SJohn Edward Broadbent 
56d82a3acdSCarol Wang /**
57d82a3acdSCarol Wang  * BiosReset class supports handle POST method for Reset bios.
58d82a3acdSCarol Wang  * The class retrieves and sends data directly to D-Bus.
597e860f15SJohn Edward Broadbent  *
60d82a3acdSCarol Wang  * Function handles POST method request.
61d82a3acdSCarol Wang  * Analyzes POST body message before sends Reset request data to D-Bus.
62d82a3acdSCarol Wang  */
6358eaf5f0SJohn Edward Broadbent inline void
6445ca1b86SEd Tanous     handleBiosResetPost(crow::App& app, const crow::Request& req,
6522d268cbSEd Tanous                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
6622d268cbSEd Tanous                         const std::string& systemName)
677e860f15SJohn Edward Broadbent {
683ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
6945ca1b86SEd Tanous     {
7045ca1b86SEd Tanous         return;
7145ca1b86SEd Tanous     }
7222d268cbSEd Tanous 
73*25b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
747f3e84a1SEd Tanous     {
757f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
767f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
777f3e84a1SEd Tanous                                    systemName);
787f3e84a1SEd Tanous         return;
797f3e84a1SEd Tanous     }
807f3e84a1SEd Tanous 
8122d268cbSEd Tanous     if (systemName != "system")
8222d268cbSEd Tanous     {
8322d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
8422d268cbSEd Tanous                                    systemName);
8522d268cbSEd Tanous         return;
8622d268cbSEd Tanous     }
8722d268cbSEd Tanous 
88d82a3acdSCarol Wang     crow::connections::systemBus->async_method_call(
895e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
90d82a3acdSCarol Wang         if (ec)
91d82a3acdSCarol Wang         {
9262598e31SEd Tanous             BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
93d82a3acdSCarol Wang             messages::internalError(asyncResp->res);
94d82a3acdSCarol Wang             return;
95d82a3acdSCarol Wang         }
96d82a3acdSCarol Wang     },
9758eaf5f0SJohn Edward Broadbent         "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
98d82a3acdSCarol Wang         "xyz.openbmc_project.Common.FactoryReset", "Reset");
99d82a3acdSCarol Wang }
10058eaf5f0SJohn Edward Broadbent 
10158eaf5f0SJohn Edward Broadbent inline void requestRoutesBiosReset(App& app)
10258eaf5f0SJohn Edward Broadbent {
10322d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
104b7ff3445SJohn Edward Broadbent         .privileges(redfish::privileges::postBios)
10545ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
10645ca1b86SEd Tanous             std::bind_front(handleBiosResetPost, std::ref(app)));
10758eaf5f0SJohn Edward Broadbent }
10858eaf5f0SJohn Edward Broadbent 
109d82a3acdSCarol Wang } // namespace redfish
110