blob: 560fe7fbc569affb4128a54e3aeac014a229a0d3 [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 Tanousd7857202025-01-28 15:32:26 -08005#include "bmcweb_config.h"
6
Ed Tanous3ccb3ad2023-01-13 17:40:03 -08007#include "app.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -08008#include "async_resp.hpp"
Ed Tanous177612a2025-02-14 15:16:09 -08009#include "dbus_utility.hpp"
Ed Tanousd7857202025-01-28 15:32:26 -080010#include "error_messages.hpp"
11#include "http_request.hpp"
12#include "logging.hpp"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080013#include "query.hpp"
14#include "registries/privilege_registry.hpp"
15#include "utils/sw_utils.hpp"
Ed Tanous45ca1b82022-03-25 13:07:27 -070016
Ed Tanousd7857202025-01-28 15:32:26 -080017#include <boost/beast/http/verb.hpp>
18
19#include <format>
20#include <functional>
21#include <memory>
22#include <string>
Ed Tanous253f11b2024-05-16 09:38:31 -070023
Carol Wangd82a3ac2019-11-21 13:56:38 +080024namespace redfish
25{
26/**
27 * BiosService class supports handle get method for bios.
28 */
Patrick Williams504af5a2025-02-03 14:29:03 -050029inline void handleBiosServiceGet(
30 crow::App& app, const crow::Request& req,
31 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
32 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070033{
Carson Labrado3ba00072022-06-06 19:40:56 +000034 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070035 {
36 return;
37 }
Ed Tanous25b54db2024-04-17 15:40:31 -070038 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -080039 {
40 // Option currently returns no systems. TBD
41 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
42 systemName);
43 return;
44 }
Ed Tanous253f11b2024-05-16 09:38:31 -070045 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -070046 {
47 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
48 systemName);
49 return;
50 }
Ed Tanous253f11b2024-05-16 09:38:31 -070051 asyncResp->res.jsonValue["@odata.id"] = std::format(
52 "/redfish/v1/Systems/{}/Bios", BMCWEB_REDFISH_SYSTEM_URI_NAME);
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070053 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
54 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
55 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
56 asyncResp->res.jsonValue["Id"] = "BIOS";
Ed Tanous20fa6a22024-05-20 18:02:58 -070057 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"]["target"] =
58 std::format("/redfish/v1/Systems/{}/Bios/Actions/Bios.ResetBios",
59 BMCWEB_REDFISH_SYSTEM_URI_NAME);
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070060
61 // Get the ActiveSoftwareImage and SoftwareImages
Willy Tueee00132022-06-14 14:53:17 -070062 sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, "",
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070063 true);
64}
Ed Tanous45ca1b82022-03-25 13:07:27 -070065
John Edward Broadbent7e860f12021-04-08 15:57:16 -070066inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080067{
Ed Tanous22d268c2022-05-19 09:39:07 -070068 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070069 .privileges(redfish::privileges::getBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070070 .methods(boost::beast::http::verb::get)(
71 std::bind_front(handleBiosServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070072}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070073
Carol Wangd82a3ac2019-11-21 13:56:38 +080074/**
75 * BiosReset class supports handle POST method for Reset bios.
76 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070077 *
78 * Function handles POST method request.
79 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080080 */
Patrick Williams504af5a2025-02-03 14:29:03 -050081inline void handleBiosResetPost(
82 crow::App& app, const crow::Request& req,
83 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
84 const std::string& systemName)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070085{
Carson Labrado3ba00072022-06-06 19:40:56 +000086 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous45ca1b82022-03-25 13:07:27 -070087 {
88 return;
89 }
Ed Tanous22d268c2022-05-19 09:39:07 -070090
Ed Tanous25b54db2024-04-17 15:40:31 -070091 if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
Ed Tanous7f3e84a2022-12-28 16:22:54 -080092 {
93 // Option currently returns no systems. TBD
94 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
95 systemName);
96 return;
97 }
98
Ed Tanous253f11b2024-05-16 09:38:31 -070099 if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME)
Ed Tanous22d268c2022-05-19 09:39:07 -0700100 {
101 messages::resourceNotFound(asyncResp->res, "ComputerSystem",
102 systemName);
103 return;
104 }
105
Ed Tanous177612a2025-02-14 15:16:09 -0800106 dbus::utility::async_method_call(
107 asyncResp,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800108 [asyncResp](const boost::system::error_code& ec) {
Patrick Williamsbd79bce2024-08-16 15:22:20 -0400109 if (ec)
110 {
111 BMCWEB_LOG_ERROR("Failed to reset bios: {}", ec);
112 messages::internalError(asyncResp->res);
113 return;
114 }
115 },
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700116 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
117 "xyz.openbmc_project.Common.FactoryReset", "Reset");
118}
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700119
120inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +0800121{
Ed Tanous22d268c2022-05-19 09:39:07 -0700122 BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -0700123 .privileges(redfish::privileges::postBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -0700124 .methods(boost::beast::http::verb::post)(
125 std::bind_front(handleBiosResetPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700126}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -0700127
Gunnar Mills72d566d2020-07-21 12:44:00 -0500128} // namespace redfish