blob: 025f4361c8eed5b6937e949012722dcdd59ef0d2 [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 Tanous7f3e84a2022-12-28 16:22:54 -080022 if constexpr (bmcwebEnableMultiHost)
23 {
24 // Option currently returns no systems. TBD
25 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
26 systemName);
27 return;
28 }
Ed Tanous22d268c2022-05-19 09:39:07 -070029 if (systemName != "system")
30 {
31 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
32 systemName);
33 return;
34 }
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070035 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
36 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
37 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
38 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
39 asyncResp->res.jsonValue["Id"] = "BIOS";
40 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
41 {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
42
43 // Get the ActiveSoftwareImage and SoftwareImages
Willy Tueee00132022-06-14 14:53:17 -070044 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070045 true);
46}
Ed Tanous45ca1b82022-03-25 13:07:27 -070047
John Edward Broadbent7e860f12021-04-08 15:57:16 -070048inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080049{
Ed Tanous22d268c2022-05-19 09:39:07 -070050 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070051 .privileges(redfish::privileges::getBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070052 .methods(boost::beast::http::verb::get)(
53 std::bind_front(handleBiosServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070054}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070055
Carol Wangd82a3ac2019-11-21 13:56:38 +080056/**
57 * BiosReset class supports handle POST method for Reset bios.
58 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070059 *
60 * Function handles POST method request.
61 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080062 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070063inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070064 handleBiosResetPost(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070065 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
66 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070067{
Carson Labrado3ba00072022-06-06 19:40:56 +000068 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070069 {
70 return;
71 }
Ed Tanous22d268c2022-05-19 09:39:07 -070072
Ed Tanous7f3e84a2022-12-28 16:22:54 -080073 if constexpr (bmcwebEnableMultiHost)
74 {
75 // Option currently returns no systems. TBD
76 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
77 systemName);
78 return;
79 }
80
Ed Tanous22d268c2022-05-19 09:39:07 -070081 if (systemName != "system")
82 {
83 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
84 systemName);
85 return;
86 }
87
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070088 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080089 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070090 if (ec)
91 {
Ed Tanous62598e32023-07-17 17:06:25 -070092 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
Ed Tanous002d39b2022-05-31 08:59:27 -070093 messages::internalError(asyncResp->res);
94 return;
95 }
Patrick Williams5a39f772023-10-20 11:20:21 -050096 },
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070097 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
98 "xyz.openbmc_project.Common.FactoryReset", "Reset");
99}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700100
101inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +0800102{
Ed Tanous22d268c2022-05-19 09:39:07 -0700103 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -0700104 .privileges(redfish::privileges::postBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700105 .methods(boost::beast::http::verb::post)(
106 std::bind_front(handleBiosResetPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700107}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700108
Gunnar Mills72d566d2020-07-21 12:44:00 -0500109} // namespace redfish