blob: 4ad58f38bc208601a1dfd5d25175903e65720434 [file] [log] [blame]
Ed Tanous40e9b922024-09-10 13:50:16 -07001// SPDX-License-Identifier: Apache-2.0
2// SPDX-FileCopyrightText: Copyright OpenBMC Authors
Carol Wangd82a3ac2019-11-21 13:56:38 +08003#pragma once
4
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08005#include "app.hpp"
6#include "query.hpp"
7#include "registries/privilege_registry.hpp"
8#include "utils/sw_utils.hpp"
Ed Tanous45ca1b82022-03-25 13:07:27 -07009
Ed Tanous253f11b2024-05-16 09:38:31 -070010#include <boost/url/format.hpp>
11
Carol Wangd82a3ac2019-11-21 13:56:38 +080012namespace redfish
13{
14/**
15 * BiosService class supports handle get method for bios.
16 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070017inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070018 handleBiosServiceGet(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070019 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
20 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070021{
Carson Labrado3ba00072022-06-06 19:40:56 +000022 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070023 {
24 return;
25 }
Ed Tanous25b54db2024-04-17 15:40:31 -070026 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -080027 {
28 // Option currently returns no systems. TBD
29 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
30 systemName);
31 return;
32 }
Ed Tanous253f11b2024-05-16 09:38:31 -070033 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -070034 {
35 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
36 systemName);
37 return;
38 }
Ed Tanous253f11b2024-05-16 09:38:31 -070039 asyncResp->res.jsonValue["@odata.id"] = std::format(
40 "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME);
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070041 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
42 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
43 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
44 asyncResp->res.jsonValue["Id"] = "BIOS";
Ed Tanous20fa6a22024-05-20 18:02:58 -070045 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] =
46 std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
47 BMCWEB_REDFISH_SYSTEM_URI_NAME);
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070048
49 // Get the ActiveSoftwareImage and SoftwareImages
Willy Tueee00132022-06-14 14:53:17 -070050 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070051 true);
52}
Ed Tanous45ca1b82022-03-25 13:07:27 -070053
John Edward Broadbent7e860f12021-04-08 15:57:16 -070054inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080055{
Ed Tanous22d268c2022-05-19 09:39:07 -070056 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070057 .privileges(redfish::privileges::getBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070058 .methods(boost::beast::http::verb::get)(
59 std::bind_front(handleBiosServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070060}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070061
Carol Wangd82a3ac2019-11-21 13:56:38 +080062/**
63 * BiosReset class supports handle POST method for Reset bios.
64 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070065 *
66 * Function handles POST method request.
67 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080068 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070069inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070070 handleBiosResetPost(crow::App& app, const crow::Request& req,
Ed Tanous22d268c2022-05-19 09:39:07 -070071 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
72 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070073{
Carson Labrado3ba00072022-06-06 19:40:56 +000074 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070075 {
76 return;
77 }
Ed Tanous22d268c2022-05-19 09:39:07 -070078
Ed Tanous25b54db2024-04-17 15:40:31 -070079 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -080080 {
81 // Option currently returns no systems. TBD
82 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
83 systemName);
84 return;
85 }
86
Ed Tanous253f11b2024-05-16 09:38:31 -070087 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -070088 {
89 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
90 systemName);
91 return;
92 }
93
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070094 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080095 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -040096 if (ec)
97 {
98 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
99 messages::internalError(asyncResp->res);
100 return;
101 }
102 },
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700103 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
104 "xyz.openbmc_project.Common.FactoryReset", "Reset");
105}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700106
107inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +0800108{
Ed Tanous22d268c2022-05-19 09:39:07 -0700109 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -0700110 .privileges(redfish::privileges::postBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700111 .methods(boost::beast::http::verb::post)(
112 std::bind_front(handleBiosResetPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700113}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700114
Gunnar Mills72d566d2020-07-21 12:44:00 -0500115} // namespace redfish