blob: a0e440b7ccf03ba2e4be37b715dfefcc21ddfe06 [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";
43 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
Ed Tanous253f11b2024-05-16 09:38:31 -070044 {"target",
45 std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
46 BMCWEB_REDFISH_SYSTEM_URI_NAME)}};
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070047
48 // Get the ActiveSoftwareImage and SoftwareImages
Willy Tueee00132022-06-14 14:53:17 -070049 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070050 true);
51}
Ed Tanous45ca1b82022-03-25 13:07:27 -070052
John Edward Broadbent7e860f12021-04-08 15:57:16 -070053inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080054{
Ed Tanous22d268c2022-05-19 09:39:07 -070055 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070056 .privileges(redfish::privileges::getBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070057 .methods(boost::beast::http::verb::get)(
58 std::bind_front(handleBiosServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070059}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070060
Carol Wangd82a3ac2019-11-21 13:56:38 +080061/**
62 * BiosReset class supports handle POST method for Reset bios.
63 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070064 *
65 * Function handles POST method request.
66 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080067 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070068inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070069 handleBiosResetPost(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070070 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
71 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070072{
Carson Labrado3ba00072022-06-06 19:40:56 +000073 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070074 {
75 return;
76 }
Ed Tanous22d268c2022-05-19 09:39:07 -070077
Ed Tanous25b54db2024-04-17 15:40:31 -070078 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -080079 {
80 // Option currently returns no systems. TBD
81 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
82 systemName);
83 return;
84 }
85
Ed Tanous253f11b2024-05-16 09:38:31 -070086 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -070087 {
88 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
89 systemName);
90 return;
91 }
92
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070093 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080094 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070095 if (ec)
96 {
Ed Tanous62598e32023-07-17 17:06:25 -070097 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -070098 messages::internalError(asyncResp->res);
99 return;
100 }
Patrick Williams5a39f772023-10-20 11:20:21 -0500101 },
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700102 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
103 "xyz.openbmc_project.Common.FactoryReset", "Reset");
104}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700105
106inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +0800107{
Ed Tanous22d268c2022-05-19 09:39:07 -0700108 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -0700109 .privileges(redfish::privileges::postBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700110 .methods(boost::beast::http::verb::post)(
111 std::bind_front(handleBiosResetPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700112}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700113
Gunnar Mills72d566d2020-07-21 12:44:00 -0500114} // namespace redfish