xref: /openbmc/bmcweb/features/redfish/lib/bios.hpp (revision 22d268cb2c0bc00676d08c79f6ab8958bee74a25)
1d82a3acdSCarol Wang #pragma once
2d82a3acdSCarol Wang 
37e860f15SJohn Edward Broadbent #include <app.hpp>
445ca1b86SEd Tanous #include <query.hpp>
5ed398213SEd Tanous #include <registries/privilege_registry.hpp>
6eee0013eSWilly Tu #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,
15*22d268cbSEd Tanous                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
16*22d268cbSEd Tanous                          const std::string& systemName)
1758eaf5f0SJohn Edward Broadbent {
183ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
1945ca1b86SEd Tanous     {
2045ca1b86SEd Tanous         return;
2145ca1b86SEd Tanous     }
22*22d268cbSEd Tanous     if (systemName != "system")
23*22d268cbSEd Tanous     {
24*22d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
25*22d268cbSEd Tanous                                    systemName);
26*22d268cbSEd Tanous         return;
27*22d268cbSEd Tanous     }
2858eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
2958eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
3058eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
3158eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
3258eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Id"] = "BIOS";
3358eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
3458eaf5f0SJohn Edward Broadbent         {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
3558eaf5f0SJohn Edward Broadbent 
3658eaf5f0SJohn Edward Broadbent     // Get the ActiveSoftwareImage and SoftwareImages
37eee0013eSWilly Tu     sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
3858eaf5f0SJohn Edward Broadbent                                          true);
3958eaf5f0SJohn Edward Broadbent }
4045ca1b86SEd Tanous 
417e860f15SJohn Edward Broadbent inline void requestRoutesBiosService(App& app)
42d82a3acdSCarol Wang {
43*22d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
44ed398213SEd Tanous         .privileges(redfish::privileges::getBios)
4545ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
4645ca1b86SEd Tanous             std::bind_front(handleBiosServiceGet, std::ref(app)));
47d82a3acdSCarol Wang }
4858eaf5f0SJohn Edward Broadbent 
49d82a3acdSCarol Wang /**
50d82a3acdSCarol Wang  * BiosReset class supports handle POST method for Reset bios.
51d82a3acdSCarol Wang  * The class retrieves and sends data directly to D-Bus.
527e860f15SJohn Edward Broadbent  *
53d82a3acdSCarol Wang  * Function handles POST method request.
54d82a3acdSCarol Wang  * Analyzes POST body message before sends Reset request data to D-Bus.
55d82a3acdSCarol Wang  */
5658eaf5f0SJohn Edward Broadbent inline void
5745ca1b86SEd Tanous     handleBiosResetPost(crow::App& app, const crow::Request& req,
58*22d268cbSEd Tanous                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
59*22d268cbSEd Tanous                         const std::string& systemName)
607e860f15SJohn Edward Broadbent {
613ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
6245ca1b86SEd Tanous     {
6345ca1b86SEd Tanous         return;
6445ca1b86SEd Tanous     }
65*22d268cbSEd Tanous 
66*22d268cbSEd Tanous     if (systemName != "system")
67*22d268cbSEd Tanous     {
68*22d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
69*22d268cbSEd Tanous                                    systemName);
70*22d268cbSEd Tanous         return;
71*22d268cbSEd Tanous     }
72*22d268cbSEd Tanous 
73d82a3acdSCarol Wang     crow::connections::systemBus->async_method_call(
74d82a3acdSCarol Wang         [asyncResp](const boost::system::error_code ec) {
75d82a3acdSCarol Wang         if (ec)
76d82a3acdSCarol Wang         {
77d82a3acdSCarol Wang             BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
78d82a3acdSCarol Wang             messages::internalError(asyncResp->res);
79d82a3acdSCarol Wang             return;
80d82a3acdSCarol Wang         }
81d82a3acdSCarol Wang         },
8258eaf5f0SJohn Edward Broadbent         "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
83d82a3acdSCarol Wang         "xyz.openbmc_project.Common.FactoryReset", "Reset");
84d82a3acdSCarol Wang }
8558eaf5f0SJohn Edward Broadbent 
8658eaf5f0SJohn Edward Broadbent inline void requestRoutesBiosReset(App& app)
8758eaf5f0SJohn Edward Broadbent {
88*22d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
89b7ff3445SJohn Edward Broadbent         .privileges(redfish::privileges::postBios)
9045ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
9145ca1b86SEd Tanous             std::bind_front(handleBiosResetPost, std::ref(app)));
9258eaf5f0SJohn Edward Broadbent }
9358eaf5f0SJohn Edward Broadbent 
94d82a3acdSCarol Wang } // namespace redfish
95