xref: /openbmc/bmcweb/redfish-core/lib/bios.hpp (revision bd79bce8)
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 
8253f11b8SEd Tanous #include <boost/url/format.hpp>
9253f11b8SEd Tanous 
10d82a3acdSCarol Wang namespace redfish
11d82a3acdSCarol Wang {
12d82a3acdSCarol Wang /**
13d82a3acdSCarol Wang  * BiosService class supports handle get method for bios.
14d82a3acdSCarol Wang  */
1558eaf5f0SJohn Edward Broadbent inline void
handleBiosServiceGet(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)1645ca1b86SEd Tanous     handleBiosServiceGet(crow::App& app, const crow::Request& req,
1722d268cbSEd Tanous                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1822d268cbSEd Tanous                          const std::string& systemName)
1958eaf5f0SJohn Edward Broadbent {
203ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2145ca1b86SEd Tanous     {
2245ca1b86SEd Tanous         return;
2345ca1b86SEd Tanous     }
2425b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
257f3e84a1SEd Tanous     {
267f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
277f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
287f3e84a1SEd Tanous                                    systemName);
297f3e84a1SEd Tanous         return;
307f3e84a1SEd Tanous     }
31253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3222d268cbSEd Tanous     {
3322d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3422d268cbSEd Tanous                                    systemName);
3522d268cbSEd Tanous         return;
3622d268cbSEd Tanous     }
37253f11b8SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = std::format(
38253f11b8SEd Tanous         "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME);
3958eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
4058eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
4158eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
4258eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Id"] = "BIOS";
43*20fa6a2cSEd Tanous     asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] =
44253f11b8SEd Tanous         std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
45*20fa6a2cSEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME);
4658eaf5f0SJohn Edward Broadbent 
4758eaf5f0SJohn Edward Broadbent     // Get the ActiveSoftwareImage and SoftwareImages
48eee0013eSWilly Tu     sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
4958eaf5f0SJohn Edward Broadbent                                          true);
5058eaf5f0SJohn Edward Broadbent }
5145ca1b86SEd Tanous 
requestRoutesBiosService(App & app)527e860f15SJohn Edward Broadbent inline void requestRoutesBiosService(App& app)
53d82a3acdSCarol Wang {
5422d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
55ed398213SEd Tanous         .privileges(redfish::privileges::getBios)
5645ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
5745ca1b86SEd Tanous             std::bind_front(handleBiosServiceGet, std::ref(app)));
58d82a3acdSCarol Wang }
5958eaf5f0SJohn Edward Broadbent 
60d82a3acdSCarol Wang /**
61d82a3acdSCarol Wang  * BiosReset class supports handle POST method for Reset bios.
62d82a3acdSCarol Wang  * The class retrieves and sends data directly to D-Bus.
637e860f15SJohn Edward Broadbent  *
64d82a3acdSCarol Wang  * Function handles POST method request.
65d82a3acdSCarol Wang  * Analyzes POST body message before sends Reset request data to D-Bus.
66d82a3acdSCarol Wang  */
6758eaf5f0SJohn Edward Broadbent inline void
handleBiosResetPost(crow::App & app,const crow::Request & req,const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & systemName)6845ca1b86SEd Tanous     handleBiosResetPost(crow::App& app, const crow::Request& req,
6922d268cbSEd Tanous                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
7022d268cbSEd Tanous                         const std::string& systemName)
717e860f15SJohn Edward Broadbent {
723ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
7345ca1b86SEd Tanous     {
7445ca1b86SEd Tanous         return;
7545ca1b86SEd Tanous     }
7622d268cbSEd Tanous 
7725b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
787f3e84a1SEd Tanous     {
797f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
807f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
817f3e84a1SEd Tanous                                    systemName);
827f3e84a1SEd Tanous         return;
837f3e84a1SEd Tanous     }
847f3e84a1SEd Tanous 
85253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
8622d268cbSEd Tanous     {
8722d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
8822d268cbSEd Tanous                                    systemName);
8922d268cbSEd Tanous         return;
9022d268cbSEd Tanous     }
9122d268cbSEd Tanous 
92d82a3acdSCarol Wang     crow::connections::systemBus->async_method_call(
935e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
94d82a3acdSCarol Wang             if (ec)
95d82a3acdSCarol Wang             {
9662598e31SEd Tanous                 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
97d82a3acdSCarol Wang                 messages::internalError(asyncResp->res);
98d82a3acdSCarol Wang                 return;
99d82a3acdSCarol Wang             }
100d82a3acdSCarol Wang         },
10158eaf5f0SJohn Edward Broadbent         "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
102d82a3acdSCarol Wang         "xyz.openbmc_project.Common.FactoryReset", "Reset");
103d82a3acdSCarol Wang }
10458eaf5f0SJohn Edward Broadbent 
requestRoutesBiosReset(App & app)10558eaf5f0SJohn Edward Broadbent inline void requestRoutesBiosReset(App& app)
10658eaf5f0SJohn Edward Broadbent {
10722d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
108b7ff3445SJohn Edward Broadbent         .privileges(redfish::privileges::postBios)
10945ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
11045ca1b86SEd Tanous             std::bind_front(handleBiosResetPost, std::ref(app)));
11158eaf5f0SJohn Edward Broadbent }
11258eaf5f0SJohn Edward Broadbent 
113d82a3acdSCarol Wang } // namespace redfish
114