blob: d8475aec1f905847392982172f30c5e93ecbf015 [file] [log] [blame]
Carol Wangd82a3ac2019-11-21 13:56:38 +08001#pragma once
2
John Edward Broadbent7e860f12021-04-08 15:57:16 -07003#include <app.hpp>
Ed Tanoused398212021-06-09 17:05:54 -07004#include <registries/privilege_registry.hpp>
Gunnar Mills72d566d2020-07-21 12:44:00 -05005#include <utils/fw_utils.hpp>
Carol Wangd82a3ac2019-11-21 13:56:38 +08006namespace redfish
7{
8/**
9 * BiosService class supports handle get method for bios.
10 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070011inline void
Ed Tanous104f09c2022-01-25 09:56:04 -080012 handleBiosServiceGet(const crow::Request& /*req*/,
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070013 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
14{
15 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
16 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
17 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
18 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
19 asyncResp->res.jsonValue["Id"] = "BIOS";
20 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
21 {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
22
23 // Get the ActiveSoftwareImage and SoftwareImages
24 fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose, "",
25 true);
26}
John Edward Broadbent7e860f12021-04-08 15:57:16 -070027inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080028{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070029 BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070030 .privileges(redfish::privileges::getBios)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070031 .methods(boost::beast::http::verb::get)(handleBiosServiceGet);
John Edward Broadbent7e860f12021-04-08 15:57:16 -070032}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070033
Carol Wangd82a3ac2019-11-21 13:56:38 +080034/**
35 * BiosReset class supports handle POST method for Reset bios.
36 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070037 *
38 * Function handles POST method request.
39 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080040 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070041inline void
Ed Tanous104f09c2022-01-25 09:56:04 -080042 handleBiosResetPost(const crow::Request& /*req*/,
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070043 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
44{
45 crow::connections::systemBus->async_method_call(
46 [asyncResp](const boost::system::error_code ec) {
47 if (ec)
48 {
49 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
50 messages::internalError(asyncResp->res);
51 return;
52 }
53 },
54 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
55 "xyz.openbmc_project.Common.FactoryReset", "Reset");
56}
John Edward Broadbent7e860f12021-04-08 15:57:16 -070057
58inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080059{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070060 BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -070061 .privileges(redfish::privileges::postBios)
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070062 .methods(boost::beast::http::verb::post)(handleBiosResetPost);
John Edward Broadbent7e860f12021-04-08 15:57:16 -070063}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070064
Gunnar Mills72d566d2020-07-21 12:44:00 -050065} // namespace redfish