blob: ee922af8546f64f92e7c5e739dbe8284d7d978a2 [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
Ed Tanous253f11b2024-05-16 09:38:31 -07008#include <boost/url/format.hpp>
9
Carol Wangd82a3ac2019-11-21 13:56:38 +080010namespace redfish
11{
12/**
13 * BiosService class supports handle get method for bios.
14 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070015inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070016 handleBiosServiceGet(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070017 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
18 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070019{
Carson Labrado3ba00072022-06-06 19:40:56 +000020 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070021 {
22 return;
23 }
Ed Tanous25b54db2024-04-17 15:40:31 -070024 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -080025 {
26 // Option currently returns no systems. TBD
27 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
28 systemName);
29 return;
30 }
Ed Tanous253f11b2024-05-16 09:38:31 -070031 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -070032 {
33 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
34 systemName);
35 return;
36 }
Ed Tanous253f11b2024-05-16 09:38:31 -070037 asyncResp->res.jsonValue["@odata.id"] = std::format(
38 "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME);
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070039 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
40 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
41 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
42 asyncResp->res.jsonValue["Id"] = "BIOS";
Ed Tanous20fa6a22024-05-20 18:02:58 -070043 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] =
44 std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
45 BMCWEB_REDFISH_SYSTEM_URI_NAME);
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070046
47 // Get the ActiveSoftwareImage and SoftwareImages
Willy Tueee00132022-06-14 14:53:17 -070048 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070049 true);
50}
Ed Tanous45ca1b82022-03-25 13:07:27 -070051
John Edward Broadbent7e860f12021-04-08 15:57:16 -070052inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080053{
Ed Tanous22d268c2022-05-19 09:39:07 -070054 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070055 .privileges(redfish::privileges::getBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070056 .methods(boost::beast::http::verb::get)(
57 std::bind_front(handleBiosServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070058}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070059
Carol Wangd82a3ac2019-11-21 13:56:38 +080060/**
61 * BiosReset class supports handle POST method for Reset bios.
62 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070063 *
64 * Function handles POST method request.
65 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080066 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070067inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070068 handleBiosResetPost(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070069 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
70 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070071{
Carson Labrado3ba00072022-06-06 19:40:56 +000072 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070073 {
74 return;
75 }
Ed Tanous22d268c2022-05-19 09:39:07 -070076
Ed Tanous25b54db2024-04-17 15:40:31 -070077 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -080078 {
79 // Option currently returns no systems. TBD
80 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
81 systemName);
82 return;
83 }
84
Ed Tanous253f11b2024-05-16 09:38:31 -070085 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -070086 {
87 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
88 systemName);
89 return;
90 }
91
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070092 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080093 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040094 if (ec)
95 {
96 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
97 messages::internalError(asyncResp->res);
98 return;
99 }
100 },
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700101 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
102 "xyz.openbmc_project.Common.FactoryReset", "Reset");
103}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700104
105inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +0800106{
Ed Tanous22d268c2022-05-19 09:39:07 -0700107 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -0700108 .privileges(redfish::privileges::postBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700109 .methods(boost::beast::http::verb::post)(
110 std::bind_front(handleBiosResetPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700111}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700112
Gunnar Mills72d566d2020-07-21 12:44:00 -0500113} // namespace redfish