xref: /openbmc/bmcweb/features/redfish/lib/bios.hpp (revision 40e9b92ec19acffb46f83a6e55b18974da5d708e)
1*40e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
2*40e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
3d82a3acdSCarol Wang #pragma once
4d82a3acdSCarol Wang 
53ccb3adbSEd Tanous #include "app.hpp"
63ccb3adbSEd Tanous #include "query.hpp"
73ccb3adbSEd Tanous #include "registries/privilege_registry.hpp"
83ccb3adbSEd Tanous #include "utils/sw_utils.hpp"
945ca1b86SEd Tanous 
10253f11b8SEd Tanous #include <boost/url/format.hpp>
11253f11b8SEd Tanous 
12d82a3acdSCarol Wang namespace redfish
13d82a3acdSCarol Wang {
14d82a3acdSCarol Wang /**
15d82a3acdSCarol Wang  * BiosService class supports handle get method for bios.
16d82a3acdSCarol Wang  */
1758eaf5f0SJohn Edward Broadbent inline void
1845ca1b86SEd Tanous     handleBiosServiceGet(crow::App& app, const crow::Request& req,
1922d268cbSEd Tanous                          const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
2022d268cbSEd Tanous                          const std::string& systemName)
2158eaf5f0SJohn Edward Broadbent {
223ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
2345ca1b86SEd Tanous     {
2445ca1b86SEd Tanous         return;
2545ca1b86SEd Tanous     }
2625b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
277f3e84a1SEd Tanous     {
287f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
297f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
307f3e84a1SEd Tanous                                    systemName);
317f3e84a1SEd Tanous         return;
327f3e84a1SEd Tanous     }
33253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
3422d268cbSEd Tanous     {
3522d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
3622d268cbSEd Tanous                                    systemName);
3722d268cbSEd Tanous         return;
3822d268cbSEd Tanous     }
39253f11b8SEd Tanous     asyncResp->res.jsonValue["@odata.id"] = std::format(
40253f11b8SEd Tanous         "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME);
4158eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
4258eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
4358eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
4458eaf5f0SJohn Edward Broadbent     asyncResp->res.jsonValue["Id"] = "BIOS";
4520fa6a2cSEd Tanous     asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] =
46253f11b8SEd Tanous         std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
4720fa6a2cSEd Tanous                     BMCWEB_REDFISH_SYSTEM_URI_NAME);
4858eaf5f0SJohn Edward Broadbent 
4958eaf5f0SJohn Edward Broadbent     // Get the ActiveSoftwareImage and SoftwareImages
50eee0013eSWilly Tu     sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
5158eaf5f0SJohn Edward Broadbent                                          true);
5258eaf5f0SJohn Edward Broadbent }
5345ca1b86SEd Tanous 
547e860f15SJohn Edward Broadbent inline void requestRoutesBiosService(App& app)
55d82a3acdSCarol Wang {
5622d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
57ed398213SEd Tanous         .privileges(redfish::privileges::getBios)
5845ca1b86SEd Tanous         .methods(boost::beast::http::verb::get)(
5945ca1b86SEd Tanous             std::bind_front(handleBiosServiceGet, std::ref(app)));
60d82a3acdSCarol Wang }
6158eaf5f0SJohn Edward Broadbent 
62d82a3acdSCarol Wang /**
63d82a3acdSCarol Wang  * BiosReset class supports handle POST method for Reset bios.
64d82a3acdSCarol Wang  * The class retrieves and sends data directly to D-Bus.
657e860f15SJohn Edward Broadbent  *
66d82a3acdSCarol Wang  * Function handles POST method request.
67d82a3acdSCarol Wang  * Analyzes POST body message before sends Reset request data to D-Bus.
68d82a3acdSCarol Wang  */
6958eaf5f0SJohn Edward Broadbent inline void
7045ca1b86SEd Tanous     handleBiosResetPost(crow::App& app, const crow::Request& req,
7122d268cbSEd Tanous                         const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
7222d268cbSEd Tanous                         const std::string& systemName)
737e860f15SJohn Edward Broadbent {
743ba00073SCarson Labrado     if (!redfish::setUpRedfishRoute(app, req, asyncResp))
7545ca1b86SEd Tanous     {
7645ca1b86SEd Tanous         return;
7745ca1b86SEd Tanous     }
7822d268cbSEd Tanous 
7925b54dbaSEd Tanous     if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
807f3e84a1SEd Tanous     {
817f3e84a1SEd Tanous         // Option currently returns no systems.  TBD
827f3e84a1SEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
837f3e84a1SEd Tanous                                    systemName);
847f3e84a1SEd Tanous         return;
857f3e84a1SEd Tanous     }
867f3e84a1SEd Tanous 
87253f11b8SEd Tanous     if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
8822d268cbSEd Tanous     {
8922d268cbSEd Tanous         messages::resourceNotFound(asyncResp->res, "ComputerSystem",
9022d268cbSEd Tanous                                    systemName);
9122d268cbSEd Tanous         return;
9222d268cbSEd Tanous     }
9322d268cbSEd Tanous 
94d82a3acdSCarol Wang     crow::connections::systemBus->async_method_call(
955e7e2dc5SEd Tanous         [asyncResp](const boost::system::error_code& ec) {
96d82a3acdSCarol Wang             if (ec)
97d82a3acdSCarol Wang             {
9862598e31SEd Tanous                 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
99d82a3acdSCarol Wang                 messages::internalError(asyncResp->res);
100d82a3acdSCarol Wang                 return;
101d82a3acdSCarol Wang             }
102d82a3acdSCarol Wang         },
10358eaf5f0SJohn Edward Broadbent         "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
104d82a3acdSCarol Wang         "xyz.openbmc_project.Common.FactoryReset", "Reset");
105d82a3acdSCarol Wang }
10658eaf5f0SJohn Edward Broadbent 
10758eaf5f0SJohn Edward Broadbent inline void requestRoutesBiosReset(App& app)
10858eaf5f0SJohn Edward Broadbent {
10922d268cbSEd Tanous     BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
110b7ff3445SJohn Edward Broadbent         .privileges(redfish::privileges::postBios)
11145ca1b86SEd Tanous         .methods(boost::beast::http::verb::post)(
11245ca1b86SEd Tanous             std::bind_front(handleBiosResetPost, std::ref(app)));
11358eaf5f0SJohn Edward Broadbent }
11458eaf5f0SJohn Edward Broadbent 
115d82a3acdSCarol Wang } // namespace redfish
116