blob: 59cb2b30c2b072ecb7bb905a2531613c7b131d97 [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 Tanous45ca1b82022-03-25 13:07:27 -07004#include <query.hpp>
Ed Tanoused398212021-06-09 17:05:54 -07005#include <registries/privilege_registry.hpp>
Gunnar Mills72d566d2020-07-21 12:44:00 -05006#include <utils/fw_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,
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070015 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
16{
Ed Tanous45ca1b82022-03-25 13:07:27 -070017 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
18 {
19 return;
20 }
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070021 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system/Bios";
22 asyncResp->res.jsonValue["@odata.type"] = "#Bios.v1_1_0.Bios";
23 asyncResp->res.jsonValue["Name"] = "BIOS Configuration";
24 asyncResp->res.jsonValue["Description"] = "BIOS Configuration Service";
25 asyncResp->res.jsonValue["Id"] = "BIOS";
26 asyncResp->res.jsonValue["Actions"]["#Bios.ResetBios"] = {
27 {"target", "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios"}};
28
29 // Get the ActiveSoftwareImage and SoftwareImages
30 fw_util::populateFirmwareInformation(asyncResp, fw_util::biosPurpose, "",
31 true);
32}
Ed Tanous45ca1b82022-03-25 13:07:27 -070033
John Edward Broadbent7e860f12021-04-08 15:57:16 -070034inline void requestRoutesBiosService(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080035{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070036 BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/")
Ed Tanoused398212021-06-09 17:05:54 -070037 .privileges(redfish::privileges::getBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070038 .methods(boost::beast::http::verb::get)(
39 std::bind_front(handleBiosServiceGet, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070040}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070041
Carol Wangd82a3ac2019-11-21 13:56:38 +080042/**
43 * BiosReset class supports handle POST method for Reset bios.
44 * The class retrieves and sends data directly to D-Bus.
John Edward Broadbent7e860f12021-04-08 15:57:16 -070045 *
46 * Function handles POST method request.
47 * Analyzes POST body message before sends Reset request data to D-Bus.
Carol Wangd82a3ac2019-11-21 13:56:38 +080048 */
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070049inline void
Ed Tanous45ca1b82022-03-25 13:07:27 -070050 handleBiosResetPost(crow::App& app, const crow::Request& req,
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070051 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
52{
Ed Tanous45ca1b82022-03-25 13:07:27 -070053 if (!redfish::setUpRedfishRoute(app, req, asyncResp->res))
54 {
55 return;
56 }
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070057 crow::connections::systemBus->async_method_call(
58 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070059 if (ec)
60 {
61 BMCWEB_LOG_ERROR << "Failed to reset bios: " << ec;
62 messages::internalError(asyncResp->res);
63 return;
64 }
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070065 },
66 "org.open_power.Software.Host.Updater", "/xyz/openbmc_project/software",
67 "xyz.openbmc_project.Common.FactoryReset", "Reset");
68}
John Edward Broadbent7e860f12021-04-08 15:57:16 -070069
70inline void requestRoutesBiosReset(App& app)
Carol Wangd82a3ac2019-11-21 13:56:38 +080071{
John Edward Broadbent7e860f12021-04-08 15:57:16 -070072 BMCWEB_ROUTE(app, "/redfish/v1/Systems/system/Bios/Actions/Bios.ResetBios/")
John Edward Broadbentb7ff3442021-10-04 09:45:42 -070073 .privileges(redfish::privileges::postBios)
Ed Tanous45ca1b82022-03-25 13:07:27 -070074 .methods(boost::beast::http::verb::post)(
75 std::bind_front(handleBiosResetPost, std::ref(app)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -070076}
John Edward Broadbent58eaf5f2021-07-02 10:15:48 -070077
Gunnar Mills72d566d2020-07-21 12:44:00 -050078} // namespace redfish