blob: 74a22d435580c60cc864ca04bee86735e32d73bc [file] [log] [blame]
Carol Wangd82a3ac2019-11-21 13:56:38 +08001#pragma once
2
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08003#include "app.hpp"
4#include "query.hpp"
5#include "registries/privilege_registry.hpp"
6#include "utils/sw_utils.hpp"
Ed Tanous45ca1b82022-03-25 13:07:27 -07007
Carol Wangd82a3ac2019-11-21 13:56:38 +08008namespace redfish
9{
10/**
11 * BiosService class supports handle get method for bios.
12 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070013inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070014 handleBiosServiceGet(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070015 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
16 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070017{
Carson Labrado3ba00072022-06-06 19:40:56 +000018 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070019 {
20 return;
21 }
Ed Tanous22d268c2022-05-19 09:39:07 -070022 if (systemName != "system")
23 {
24 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
25 systemName);
26 return;
27 }
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070028 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
29 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
30 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
31 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
32 asyncResp->res.jsonValue["Id"] = "BIOS";
33 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
34 {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
35
36 // Get the ActiveSoftwareImage and SoftwareImages
Willy Tueee00132022-06-14 14:53:17 -070037 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070038 true);
39}
Ed Tanous45ca1b82022-03-25 13:07:27 -070040
John Edward Broadbent7e860f12021-04-08 15:57:16 -070041inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080042{
Ed Tanous22d268c2022-05-19 09:39:07 -070043 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070044 .privileges(redfish::privileges::getBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070045 .methods(boost::beast::http::verb::get)(
46 std::bind_front(handleBiosServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070047}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070048
Carol Wangd82a3ac2019-11-21 13:56:38 +080049/**
50 * BiosReset class supports handle POST method for Reset bios.
51 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070052 *
53 * Function handles POST method request.
54 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080055 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070056inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070057 handleBiosResetPost(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070058 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
59 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070060{
Carson Labrado3ba00072022-06-06 19:40:56 +000061 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070062 {
63 return;
64 }
Ed Tanous22d268c2022-05-19 09:39:07 -070065
66 if (systemName != "system")
67 {
68 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
69 systemName);
70 return;
71 }
72
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070073 crow::connections::systemBus->async_method_call(
74 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070075 if (ec)
76 {
77 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
78 messages::internalError(asyncResp->res);
79 return;
80 }
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070081 },
82 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
83 "xyz.openbmc_project.Common.FactoryReset", "Reset");
84}
John Edward Broadbent7e860f12021-04-08 15:57:16 -070085
86inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080087{
Ed Tanous22d268c2022-05-19 09:39:07 -070088 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -070089 .privileges(redfish::privileges::postBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070090 .methods(boost::beast::http::verb::post)(
91 std::bind_front(handleBiosResetPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070092}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070093
Gunnar Mills72d566d2020-07-21 12:44:00 -050094} // namespace redfish