xref: /openbmc/bmcweb/redfish-core/lib/bios.hpp (revision 5e7e2dc5)
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     }
2222d268cbSEd Tanous     if (systemName != "system")
2322d268cbSEd Tanous     {
2422d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
2522d268cbSEd Tanous                                    systemName);
2622d268cbSEd Tanous         return;
2722d268cbSEd 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 {
4322d268cbSEd 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,
5822d268cbSEd Tanous                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
5922d268cbSEd Tanous                         const std::string& systemName)
607e860f15SJohn Edward Broadbent {
613ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
6245ca1b86SEd Tanous     {
6345ca1b86SEd Tanous         return;
6445ca1b86SEd Tanous     }
6522d268cbSEd Tanous 
6622d268cbSEd Tanous     if (systemName != "system")
6722d268cbSEd Tanous     {
6822d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
6922d268cbSEd Tanous                                    systemName);
7022d268cbSEd Tanous         return;
7122d268cbSEd Tanous     }
7222d268cbSEd Tanous 
73d82a3acdSCarol Wang     crow::connections::systemBus->async_method_call(
74*5e7e2dc5SEd Tanous         [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 {
8822d268cbSEd 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