xref: /openbmc/bmcweb/redfish-core/lib/bios.hpp (revision 45ca1b86)
1d82a3acdSCarol Wang #pragma once
2d82a3acdSCarol Wang 
37e860f15SJohn Edward Broadbent #include <app.hpp>
4*45ca1b86SEd Tanous #include <query.hpp>
5ed398213SEd Tanous #include <registries/privilege_registry.hpp>
672d566d9SGunnar Mills #include <utils/fw_utils.hpp>
7*45ca1b86SEd 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
14*45ca1b86SEd Tanous     handleBiosServiceGet(crow::App& app, const crow::Request& req,
1558eaf5f0SJohn Edward Broadbent                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
1658eaf5f0SJohn Edward Broadbent {
17*45ca1b86SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
18*45ca1b86SEd Tanous     {
19*45ca1b86SEd Tanous         return;
20*45ca1b86SEd Tanous     }
2158eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
2258eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
2358eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
2458eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
2558eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Id"] = "BIOS";
2658eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
2758eaf5f0SJohn Edward Broadbent         {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
2858eaf5f0SJohn Edward Broadbent 
2958eaf5f0SJohn Edward Broadbent     // Get the ActiveSoftwareImage and SoftwareImages
3058eaf5f0SJohn Edward Broadbent     fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose, "",
3158eaf5f0SJohn Edward Broadbent                                          true);
3258eaf5f0SJohn Edward Broadbent }
33*45ca1b86SEd Tanous 
347e860f15SJohn Edward Broadbent inline void requestRoutesBiosService(App& app)
35d82a3acdSCarol Wang {
367e860f15SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/")
37ed398213SEd Tanous         .privileges(redfish::privileges::getBios)
38*45ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
39*45ca1b86SEd Tanous             std::bind_front(handleBiosServiceGet, std::ref(app)));
40d82a3acdSCarol Wang }
4158eaf5f0SJohn Edward Broadbent 
42d82a3acdSCarol Wang /**
43d82a3acdSCarol Wang  * BiosReset class supports handle POST method for Reset bios.
44d82a3acdSCarol Wang  * The class retrieves and sends data directly to D-Bus.
457e860f15SJohn Edward Broadbent  *
46d82a3acdSCarol Wang  * Function handles POST method request.
47d82a3acdSCarol Wang  * Analyzes POST body message before sends Reset request data to D-Bus.
48d82a3acdSCarol Wang  */
4958eaf5f0SJohn Edward Broadbent inline void
50*45ca1b86SEd Tanous     handleBiosResetPost(crow::App& app, const crow::Request& req,
5158eaf5f0SJohn Edward Broadbent                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
527e860f15SJohn Edward Broadbent {
53*45ca1b86SEd Tanous     if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
54*45ca1b86SEd Tanous     {
55*45ca1b86SEd Tanous         return;
56*45ca1b86SEd Tanous     }
57d82a3acdSCarol Wang     crow::connections::systemBus->async_method_call(
58d82a3acdSCarol Wang         [asyncResp](const boost::system::error_code ec) {
59d82a3acdSCarol Wang             if (ec)
60d82a3acdSCarol Wang             {
61d82a3acdSCarol Wang                 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
62d82a3acdSCarol Wang                 messages::internalError(asyncResp->res);
63d82a3acdSCarol Wang                 return;
64d82a3acdSCarol Wang             }
65d82a3acdSCarol Wang         },
6658eaf5f0SJohn Edward Broadbent         "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
67d82a3acdSCarol Wang         "xyz.openbmc_project.Common.FactoryReset", "Reset");
68d82a3acdSCarol Wang }
6958eaf5f0SJohn Edward Broadbent 
7058eaf5f0SJohn Edward Broadbent inline void requestRoutesBiosReset(App& app)
7158eaf5f0SJohn Edward Broadbent {
7258eaf5f0SJohn Edward Broadbent     BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
73b7ff3445SJohn Edward Broadbent         .privileges(redfish::privileges::postBios)
74*45ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
75*45ca1b86SEd Tanous             std::bind_front(handleBiosResetPost, std::ref(app)));
7658eaf5f0SJohn Edward Broadbent }
7758eaf5f0SJohn Edward Broadbent 
78d82a3acdSCarol Wang } // namespace redfish
79