140e9b92eSEd Tanous // SPDX-License-Identifier: Apache-2.0
240e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright OpenBMC Authors
340e9b92eSEd Tanous // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation
49c310685SBorawski.Lukasz #pragma once
59c310685SBorawski.Lukasz
613451e39SWilly Tu #include "bmcweb_config.h"
713451e39SWilly Tu
8a51fc2d2SSui Chen #include "app.hpp"
9d7857201SEd Tanous #include "async_resp.hpp"
10d7857201SEd Tanous #include "dbus_singleton.hpp"
11a51fc2d2SSui Chen #include "dbus_utility.hpp"
12d7857201SEd Tanous #include "error_messages.hpp"
13539d8c6bSEd Tanous #include "generated/enums/action_info.hpp"
14539d8c6bSEd Tanous #include "generated/enums/manager.hpp"
15539d8c6bSEd Tanous #include "generated/enums/resource.hpp"
16d7857201SEd Tanous #include "http_request.hpp"
17d7857201SEd Tanous #include "logging.hpp"
18*cc67d0a0Srohitpai #include "openbmc/openbmc_managers.hpp"
19d7857201SEd Tanous #include "persistent_data.hpp"
20a51fc2d2SSui Chen #include "query.hpp"
21c5d03ff4SJennifer Lee #include "redfish_util.hpp"
22a51fc2d2SSui Chen #include "registries/privilege_registry.hpp"
23fac6e53bSKrzysztof Grobelny #include "utils/dbus_utils.hpp"
243ccb3adbSEd Tanous #include "utils/json_utils.hpp"
25a51fc2d2SSui Chen #include "utils/sw_utils.hpp"
26a51fc2d2SSui Chen #include "utils/systemd_utils.hpp"
272b82937eSEd Tanous #include "utils/time_utils.hpp"
289c310685SBorawski.Lukasz
29d7857201SEd Tanous #include <systemd/sd-bus.h>
30d7857201SEd Tanous
31d7857201SEd Tanous #include <boost/beast/http/status.hpp>
32d7857201SEd Tanous #include <boost/beast/http/verb.hpp>
33e99073f5SGeorge Liu #include <boost/system/error_code.hpp>
34ef4c65b7SEd Tanous #include <boost/url/format.hpp>
35d7857201SEd Tanous #include <boost/url/url.hpp>
36d7857201SEd Tanous #include <nlohmann/json.hpp>
37fac6e53bSKrzysztof Grobelny #include <sdbusplus/asio/property.hpp>
38d7857201SEd Tanous #include <sdbusplus/message.hpp>
39d7857201SEd Tanous #include <sdbusplus/message/native_types.hpp>
40fac6e53bSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp>
411214b7e7SGunnar Mills
42e99073f5SGeorge Liu #include <array>
43d7857201SEd Tanous #include <cstddef>
444bfefa74SGunnar Mills #include <cstdint>
45d7857201SEd Tanous #include <format>
46d7857201SEd Tanous #include <functional>
47d7857201SEd Tanous #include <map>
481214b7e7SGunnar Mills #include <memory>
499970e93fSKonstantin Aladyshev #include <optional>
503544d2a7SEd Tanous #include <ranges>
519970e93fSKonstantin Aladyshev #include <string>
52e99073f5SGeorge Liu #include <string_view>
53d7857201SEd Tanous #include <utility>
54d7857201SEd Tanous #include <vector>
555b4aa86bSJames Feist
561abe55efSEd Tanous namespace redfish
571abe55efSEd Tanous {
58ed5befbdSJennifer Lee
getBMCUpdateServiceName()59d27c31e9SJagpal Singh Gill inline std::string getBMCUpdateServiceName()
60d27c31e9SJagpal Singh Gill {
61d27c31e9SJagpal Singh Gill if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
62d27c31e9SJagpal Singh Gill {
63d27c31e9SJagpal Singh Gill return "xyz.openbmc_project.Software.Manager";
64d27c31e9SJagpal Singh Gill }
65d27c31e9SJagpal Singh Gill return "xyz.openbmc_project.Software.BMC.Updater";
66d27c31e9SJagpal Singh Gill }
67d27c31e9SJagpal Singh Gill
getBMCUpdateServicePath()68d27c31e9SJagpal Singh Gill inline std::string getBMCUpdateServicePath()
69d27c31e9SJagpal Singh Gill {
70d27c31e9SJagpal Singh Gill if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS)
71d27c31e9SJagpal Singh Gill {
72d27c31e9SJagpal Singh Gill return "/xyz/openbmc_project/software/bmc";
73d27c31e9SJagpal Singh Gill }
74d27c31e9SJagpal Singh Gill return "/xyz/openbmc_project/software";
75d27c31e9SJagpal Singh Gill }
76d27c31e9SJagpal Singh Gill
77ed5befbdSJennifer Lee /**
782a5c4407SGunnar Mills * Function reboots the BMC.
792a5c4407SGunnar Mills *
802a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls
81ed5befbdSJennifer Lee */
doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)82504af5a0SPatrick Williams inline void doBMCGracefulRestart(
83504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
84ed5befbdSJennifer Lee {
85ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC";
86ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0";
87ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC";
88ed5befbdSJennifer Lee const std::string& propertyValue =
89ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot";
90ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition";
91ed5befbdSJennifer Lee
92ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call.
939ae226faSGeorge Liu sdbusplus::asio::setProperty(
949ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName,
959ae226faSGeorge Liu destProperty, propertyValue,
965e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) {
97ed5befbdSJennifer Lee // Use "Set" method to set the property value.
98ed5befbdSJennifer Lee if (ec)
99ed5befbdSJennifer Lee {
10062598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
101ed5befbdSJennifer Lee messages::internalError(asyncResp->res);
102ed5befbdSJennifer Lee return;
103ed5befbdSJennifer Lee }
104ed5befbdSJennifer Lee
105ed5befbdSJennifer Lee messages::success(asyncResp->res);
1069ae226faSGeorge Liu });
107ed5befbdSJennifer Lee }
1082a5c4407SGunnar Mills
doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)109504af5a0SPatrick Williams inline void doBMCForceRestart(
110504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
111f92af389SJayaprakash Mutyala {
112f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC";
113f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0";
114f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC";
115f92af389SJayaprakash Mutyala const std::string& propertyValue =
116f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot";
117f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition";
118f92af389SJayaprakash Mutyala
119f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call.
1209ae226faSGeorge Liu sdbusplus::asio::setProperty(
1219ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName,
1229ae226faSGeorge Liu destProperty, propertyValue,
1235e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) {
124f92af389SJayaprakash Mutyala // Use "Set" method to set the property value.
125f92af389SJayaprakash Mutyala if (ec)
126f92af389SJayaprakash Mutyala {
12762598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec);
128f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res);
129f92af389SJayaprakash Mutyala return;
130f92af389SJayaprakash Mutyala }
131f92af389SJayaprakash Mutyala
132f92af389SJayaprakash Mutyala messages::success(asyncResp->res);
1339ae226faSGeorge Liu });
134f92af389SJayaprakash Mutyala }
135f92af389SJayaprakash Mutyala
1362a5c4407SGunnar Mills /**
1372a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot)
1382a5c4407SGunnar Mills * action.
1392a5c4407SGunnar Mills */
requestRoutesManagerResetAction(App & app)1407e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app)
1412a5c4407SGunnar Mills {
1422a5c4407SGunnar Mills /**
1432a5c4407SGunnar Mills * Function handles POST method request.
1442a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
145f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
1462a5c4407SGunnar Mills */
1477e860f15SJohn Edward Broadbent
148253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/")
149ed398213SEd Tanous .privileges(redfish::privileges::postManager)
1507e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)(
15145ca1b86SEd Tanous [&app](const crow::Request& req,
152253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
153253f11b8SEd Tanous const std::string& managerId) {
1543ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
15545ca1b86SEd Tanous {
15645ca1b86SEd Tanous return;
15745ca1b86SEd Tanous }
158253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
159253f11b8SEd Tanous {
160bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager",
161bd79bce8SPatrick Williams managerId);
162253f11b8SEd Tanous return;
163253f11b8SEd Tanous }
164253f11b8SEd Tanous
16562598e31SEd Tanous BMCWEB_LOG_DEBUG("Post Manager Reset.");
1662a5c4407SGunnar Mills
1672a5c4407SGunnar Mills std::string resetType;
1682a5c4407SGunnar Mills
16915ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
1707e860f15SJohn Edward Broadbent resetType))
1712a5c4407SGunnar Mills {
1722a5c4407SGunnar Mills return;
1732a5c4407SGunnar Mills }
1742a5c4407SGunnar Mills
175f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart")
176f92af389SJayaprakash Mutyala {
17762598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
178f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp);
179f92af389SJayaprakash Mutyala return;
180f92af389SJayaprakash Mutyala }
1813174e4dfSEd Tanous if (resetType == "ForceRestart")
182f92af389SJayaprakash Mutyala {
18362598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType);
184f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp);
185f92af389SJayaprakash Mutyala return;
186f92af389SJayaprakash Mutyala }
187bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
188bd79bce8SPatrick Williams resetType);
1892a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType,
1902a5c4407SGunnar Mills "ResetType");
1912a5c4407SGunnar Mills
1922a5c4407SGunnar Mills return;
1937e860f15SJohn Edward Broadbent });
1942a5c4407SGunnar Mills }
195ed5befbdSJennifer Lee
1963e40fc74SGunnar Mills /**
1973e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset
1983e40fc74SGunnar Mills * action.
1993e40fc74SGunnar Mills */
requestRoutesManagerResetToDefaultsAction(App & app)2007e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app)
2013e40fc74SGunnar Mills {
2023e40fc74SGunnar Mills /**
2033e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request.
2043e40fc74SGunnar Mills *
2053e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling
2063e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot.
2073e40fc74SGunnar Mills *
2083e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write
2093e40fc74SGunnar Mills * filesystem which includes things like the network settings.
2103e40fc74SGunnar Mills *
2113e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll".
2123e40fc74SGunnar Mills */
2137e860f15SJohn Edward Broadbent
2147e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app,
215253f11b8SEd Tanous "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/")
216ed398213SEd Tanous .privileges(redfish::privileges::postManager)
217bd79bce8SPatrick Williams .methods(
218bd79bce8SPatrick Williams boost::beast::http::verb::
219bd79bce8SPatrick Williams post)([&app](
220bd79bce8SPatrick Williams const crow::Request& req,
221253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
222253f11b8SEd Tanous const std::string& managerId) {
2233ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
22445ca1b86SEd Tanous {
22545ca1b86SEd Tanous return;
22645ca1b86SEd Tanous }
227253f11b8SEd Tanous
228253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
229253f11b8SEd Tanous {
230bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager",
231bd79bce8SPatrick Williams managerId);
232253f11b8SEd Tanous return;
233253f11b8SEd Tanous }
234253f11b8SEd Tanous
23562598e31SEd Tanous BMCWEB_LOG_DEBUG("Post ResetToDefaults.");
2363e40fc74SGunnar Mills
2379970e93fSKonstantin Aladyshev std::optional<std::string> resetType;
2389970e93fSKonstantin Aladyshev std::optional<std::string> resetToDefaultsType;
2393e40fc74SGunnar Mills
240afc474aeSMyung Bae if (!json_util::readJsonAction( //
241afc474aeSMyung Bae req, asyncResp->res, //
242afc474aeSMyung Bae "ResetToDefaultsType", resetToDefaultsType, //
243afc474aeSMyung Bae "ResetType", resetType //
244afc474aeSMyung Bae ))
2453e40fc74SGunnar Mills {
2469970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Missing property ResetType.");
2473e40fc74SGunnar Mills
248bd79bce8SPatrick Williams messages::actionParameterMissing(
249bd79bce8SPatrick Williams asyncResp->res, "ResetToDefaults", "ResetType");
2503e40fc74SGunnar Mills return;
2513e40fc74SGunnar Mills }
2523e40fc74SGunnar Mills
2539970e93fSKonstantin Aladyshev if (resetToDefaultsType && !resetType)
2549970e93fSKonstantin Aladyshev {
2559970e93fSKonstantin Aladyshev BMCWEB_LOG_WARNING(
2569970e93fSKonstantin Aladyshev "Using deprecated ResetToDefaultsType, should be ResetType."
2579970e93fSKonstantin Aladyshev "Support for the ResetToDefaultsType will be dropped in 2Q24");
2589970e93fSKonstantin Aladyshev resetType = resetToDefaultsType;
2599970e93fSKonstantin Aladyshev }
2609970e93fSKonstantin Aladyshev
2613e40fc74SGunnar Mills if (resetType != "ResetAll")
2623e40fc74SGunnar Mills {
2639970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}",
2649970e93fSKonstantin Aladyshev *resetType);
265bd79bce8SPatrick Williams messages::actionParameterNotSupported(asyncResp->res,
266bd79bce8SPatrick Williams *resetType, "ResetType");
2673e40fc74SGunnar Mills return;
2683e40fc74SGunnar Mills }
2693e40fc74SGunnar Mills
2703e40fc74SGunnar Mills crow::connections::systemBus->async_method_call(
2715e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) {
2723e40fc74SGunnar Mills if (ec)
2733e40fc74SGunnar Mills {
27462598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec);
2753e40fc74SGunnar Mills messages::internalError(asyncResp->res);
2763e40fc74SGunnar Mills return;
2773e40fc74SGunnar Mills }
2783e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot
2793e40fc74SGunnar Mills // Can't erase what the BMC is running on
2803e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp);
2813e40fc74SGunnar Mills },
282d27c31e9SJagpal Singh Gill getBMCUpdateServiceName(), getBMCUpdateServicePath(),
2833e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset");
2847e860f15SJohn Edward Broadbent });
2853e40fc74SGunnar Mills }
2863e40fc74SGunnar Mills
2871cb1a9e6SAppaRao Puli /**
2881cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager
2891cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema.
2901cb1a9e6SAppaRao Puli */
requestRoutesManagerResetActionInfo(App & app)2917e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app)
2921cb1a9e6SAppaRao Puli {
2931cb1a9e6SAppaRao Puli /**
2941cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus
2951cb1a9e6SAppaRao Puli */
2967e860f15SJohn Edward Broadbent
297253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/")
298ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo)
2997e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)(
30045ca1b86SEd Tanous [&app](const crow::Request& req,
301253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
302253f11b8SEd Tanous const std::string& managerId) {
3033ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
30445ca1b86SEd Tanous {
30545ca1b86SEd Tanous return;
30645ca1b86SEd Tanous }
3071476687dSEd Tanous
308253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
309253f11b8SEd Tanous {
310bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager",
311bd79bce8SPatrick Williams managerId);
312253f11b8SEd Tanous return;
313253f11b8SEd Tanous }
314253f11b8SEd Tanous
3151476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] =
3161476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo";
317bd79bce8SPatrick Williams asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
318bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/ResetActionInfo",
319253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
3201476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info";
3211476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
3221476687dSEd Tanous nlohmann::json::object_t parameter;
3231476687dSEd Tanous parameter["Name"] = "ResetType";
3241476687dSEd Tanous parameter["Required"] = true;
325539d8c6bSEd Tanous parameter["DataType"] = action_info::ParameterTypes::String;
3261476687dSEd Tanous
3271476687dSEd Tanous nlohmann::json::array_t allowableValues;
328ad539545SPatrick Williams allowableValues.emplace_back("GracefulRestart");
329ad539545SPatrick Williams allowableValues.emplace_back("ForceRestart");
3301476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues);
3311476687dSEd Tanous
3321476687dSEd Tanous nlohmann::json::array_t parameters;
333ad539545SPatrick Williams parameters.emplace_back(std::move(parameter));
3341476687dSEd Tanous
3351476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
3367e860f15SJohn Edward Broadbent });
3371cb1a9e6SAppaRao Puli }
3381cb1a9e6SAppaRao Puli
339071d8fdfSSunnySrivastava1984 /**
340071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus
341071d8fdfSSunnySrivastava1984 *
342ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls
343071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name
344071d8fdfSSunnySrivastava1984 * @param[in] path - object path
345071d8fdfSSunnySrivastava1984 * @return none
346071d8fdfSSunnySrivastava1984 */
getLocation(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & connectionName,const std::string & path)347ac106bf6SEd Tanous inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
348071d8fdfSSunnySrivastava1984 const std::string& connectionName,
349071d8fdfSSunnySrivastava1984 const std::string& path)
350071d8fdfSSunnySrivastava1984 {
35162598e31SEd Tanous BMCWEB_LOG_DEBUG("Get BMC manager Location data.");
352071d8fdfSSunnySrivastava1984
353deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
354deae6a78SEd Tanous connectionName, path,
3551e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
356ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
3571e1e598dSJonathan Doman const std::string& property) {
358071d8fdfSSunnySrivastava1984 if (ec)
359071d8fdfSSunnySrivastava1984 {
36062598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error for "
36162598e31SEd Tanous "Location");
362ac106bf6SEd Tanous messages::internalError(asyncResp->res);
363071d8fdfSSunnySrivastava1984 return;
364071d8fdfSSunnySrivastava1984 }
365071d8fdfSSunnySrivastava1984
366bd79bce8SPatrick Williams asyncResp->res
367bd79bce8SPatrick Williams .jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
3681e1e598dSJonathan Doman property;
3691e1e598dSJonathan Doman });
370071d8fdfSSunnySrivastava1984 }
3717e860f15SJohn Edward Broadbent // avoid name collision systems.hpp
managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)372504af5a0SPatrick Williams inline void managerGetLastResetTime(
373504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
3744bf2b033SGunnar Mills {
37562598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time");
3764bf2b033SGunnar Mills
377deae6a78SEd Tanous dbus::utility::getProperty<uint64_t>(
378deae6a78SEd Tanous "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0",
379deae6a78SEd Tanous "xyz.openbmc_project.State.BMC", "LastRebootTime",
380ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec,
3811e1e598dSJonathan Doman const uint64_t lastResetTime) {
3824bf2b033SGunnar Mills if (ec)
3834bf2b033SGunnar Mills {
38462598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec);
3854bf2b033SGunnar Mills return;
3864bf2b033SGunnar Mills }
3874bf2b033SGunnar Mills
3884bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds
3894bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
3901e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000;
3914bf2b033SGunnar Mills
3924bf2b033SGunnar Mills // Convert to ISO 8601 standard
393ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] =
3942b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
3951e1e598dSJonathan Doman });
3964bf2b033SGunnar Mills }
3974bf2b033SGunnar Mills
3984bfefa74SGunnar Mills /**
3994bfefa74SGunnar Mills * @brief Set the running firmware image
4004bfefa74SGunnar Mills *
401ac106bf6SEd Tanous * @param[i,o] asyncResp - Async response object
4024bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image
4034bfefa74SGunnar Mills *
4044bfefa74SGunnar Mills * @return void
4054bfefa74SGunnar Mills */
setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & runningFirmwareTarget)406504af5a0SPatrick Williams inline void setActiveFirmwareImage(
407504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
408f23b7296SEd Tanous const std::string& runningFirmwareTarget)
4094bfefa74SGunnar Mills {
4104bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
411f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/');
4124bfefa74SGunnar Mills if (idPos == std::string::npos)
4134bfefa74SGunnar Mills {
414ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
4154bfefa74SGunnar Mills "@odata.id");
41662598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't parse firmware ID!");
4174bfefa74SGunnar Mills return;
4184bfefa74SGunnar Mills }
4194bfefa74SGunnar Mills idPos++;
4204bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size())
4214bfefa74SGunnar Mills {
422ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget,
4234bfefa74SGunnar Mills "@odata.id");
42462598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID.");
4254bfefa74SGunnar Mills return;
4264bfefa74SGunnar Mills }
4274bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos);
4284bfefa74SGunnar Mills
4294bfefa74SGunnar Mills // Make sure the image is valid before setting priority
4305eb468daSGeorge Liu sdbusplus::message::object_path objPath("/xyz/openbmc_project/software");
4315eb468daSGeorge Liu dbus::utility::getManagedObjects(
432d27c31e9SJagpal Singh Gill getBMCUpdateServiceName(), objPath,
4335eb468daSGeorge Liu [asyncResp, firmwareId, runningFirmwareTarget](
4345eb468daSGeorge Liu const boost::system::error_code& ec,
4355eb468daSGeorge Liu const dbus::utility::ManagedObjectType& subtree) {
4364bfefa74SGunnar Mills if (ec)
4374bfefa74SGunnar Mills {
43862598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error getting objects.");
439ac106bf6SEd Tanous messages::internalError(asyncResp->res);
4404bfefa74SGunnar Mills return;
4414bfefa74SGunnar Mills }
4424bfefa74SGunnar Mills
44326f6976fSEd Tanous if (subtree.empty())
4444bfefa74SGunnar Mills {
44562598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find image!");
446ac106bf6SEd Tanous messages::internalError(asyncResp->res);
4474bfefa74SGunnar Mills return;
4484bfefa74SGunnar Mills }
4494bfefa74SGunnar Mills
4504bfefa74SGunnar Mills bool foundImage = false;
45102cad96eSEd Tanous for (const auto& object : subtree)
4524bfefa74SGunnar Mills {
4534bfefa74SGunnar Mills const std::string& path =
4544bfefa74SGunnar Mills static_cast<const std::string&>(object.first);
455f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/');
4564bfefa74SGunnar Mills
4574bfefa74SGunnar Mills if (idPos2 == std::string::npos)
4584bfefa74SGunnar Mills {
4594bfefa74SGunnar Mills continue;
4604bfefa74SGunnar Mills }
4614bfefa74SGunnar Mills
4624bfefa74SGunnar Mills idPos2++;
4634bfefa74SGunnar Mills if (idPos2 >= path.size())
4644bfefa74SGunnar Mills {
4654bfefa74SGunnar Mills continue;
4664bfefa74SGunnar Mills }
4674bfefa74SGunnar Mills
4684bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId)
4694bfefa74SGunnar Mills {
4704bfefa74SGunnar Mills foundImage = true;
4714bfefa74SGunnar Mills break;
4724bfefa74SGunnar Mills }
4734bfefa74SGunnar Mills }
4744bfefa74SGunnar Mills
4754bfefa74SGunnar Mills if (!foundImage)
4764bfefa74SGunnar Mills {
477ac106bf6SEd Tanous messages::propertyValueNotInList(
478ac106bf6SEd Tanous asyncResp->res, runningFirmwareTarget, "@odata.id");
47962598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID.");
4804bfefa74SGunnar Mills return;
4814bfefa74SGunnar Mills }
4824bfefa74SGunnar Mills
48362598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.",
48462598e31SEd Tanous firmwareId);
4854bfefa74SGunnar Mills
4864bfefa74SGunnar Mills // Only support Immediate
4874bfefa74SGunnar Mills // An addition could be a Redfish Setting like
4884bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset
4899ae226faSGeorge Liu sdbusplus::asio::setProperty(
490d27c31e9SJagpal Singh Gill *crow::connections::systemBus, getBMCUpdateServiceName(),
4919ae226faSGeorge Liu "/xyz/openbmc_project/software/" + firmwareId,
4929ae226faSGeorge Liu "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
4939ae226faSGeorge Liu static_cast<uint8_t>(0),
494ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2) {
4958a592810SEd Tanous if (ec2)
4964bfefa74SGunnar Mills {
49762598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error setting.");
498ac106bf6SEd Tanous messages::internalError(asyncResp->res);
4994bfefa74SGunnar Mills return;
5004bfefa74SGunnar Mills }
501ac106bf6SEd Tanous doBMCGracefulRestart(asyncResp);
5029ae226faSGeorge Liu });
5035eb468daSGeorge Liu });
5044bfefa74SGunnar Mills }
5054bfefa74SGunnar Mills
afterSetDateTime(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const boost::system::error_code & ec,const sdbusplus::message_t & msg)506bd79bce8SPatrick Williams inline void afterSetDateTime(
507bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
508bd79bce8SPatrick Williams const boost::system::error_code& ec, const sdbusplus::message_t& msg)
509c51afd54SEd Tanous {
510c51afd54SEd Tanous if (ec)
511c51afd54SEd Tanous {
512c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}",
513c51afd54SEd Tanous ec);
514c51afd54SEd Tanous const sd_bus_error* dbusError = msg.get_error();
515c51afd54SEd Tanous if (dbusError != nullptr)
516c51afd54SEd Tanous {
517c51afd54SEd Tanous std::string_view errorName(dbusError->name);
518c51afd54SEd Tanous if (errorName ==
519c51afd54SEd Tanous "org.freedesktop.timedate1.AutomaticTimeSyncEnabled")
520c51afd54SEd Tanous {
521c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Setting conflict");
522c51afd54SEd Tanous messages::propertyValueConflict(
523c51afd54SEd Tanous asyncResp->res, "DateTime",
524c51afd54SEd Tanous "Managers/NetworkProtocol/NTPProcotolEnabled");
525c51afd54SEd Tanous return;
526c51afd54SEd Tanous }
527c51afd54SEd Tanous }
528c51afd54SEd Tanous messages::internalError(asyncResp->res);
529c51afd54SEd Tanous return;
530c51afd54SEd Tanous }
531c51afd54SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content);
532c51afd54SEd Tanous }
533c51afd54SEd Tanous
setDateTime(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp,const std::string & datetime)534c51afd54SEd Tanous inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
535c51afd54SEd Tanous const std::string& datetime)
536af5d6058SSantosh Puranik {
53762598e31SEd Tanous BMCWEB_LOG_DEBUG("Set date time: {}", datetime);
538af5d6058SSantosh Puranik
539c2e32007SEd Tanous std::optional<redfish::time_utils::usSinceEpoch> us =
540c2e32007SEd Tanous redfish::time_utils::dateStringToEpoch(datetime);
541c2e32007SEd Tanous if (!us)
542af5d6058SSantosh Puranik {
543ac106bf6SEd Tanous messages::propertyValueFormatError(asyncResp->res, datetime,
544ac106bf6SEd Tanous "DateTime");
545c2e32007SEd Tanous return;
546c2e32007SEd Tanous }
547c51afd54SEd Tanous // Set the absolute datetime
548c51afd54SEd Tanous bool relative = false;
549c51afd54SEd Tanous bool interactive = false;
550c51afd54SEd Tanous crow::connections::systemBus->async_method_call(
551c51afd54SEd Tanous [asyncResp](const boost::system::error_code& ec,
552c51afd54SEd Tanous const sdbusplus::message_t& msg) {
553c51afd54SEd Tanous afterSetDateTime(asyncResp, ec, msg);
554c51afd54SEd Tanous },
555c51afd54SEd Tanous "org.freedesktop.timedate1", "/org/freedesktop/timedate1",
556c51afd54SEd Tanous "org.freedesktop.timedate1", "SetTime", us->count(), relative,
557c51afd54SEd Tanous interactive);
55883ff9ab6SJames Feist }
5599c310685SBorawski.Lukasz
checkForQuiesced(const std::shared_ptr<bmcweb::AsyncResp> & asyncResp)560504af5a0SPatrick Williams inline void checkForQuiesced(
561504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
56275815e5cSEd Tanous {
563deae6a78SEd Tanous dbus::utility::getProperty<std::string>(
564deae6a78SEd Tanous "org.freedesktop.systemd1",
56575815e5cSEd Tanous "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target",
56675815e5cSEd Tanous "org.freedesktop.systemd1.Unit", "ActiveState",
56775815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec,
56875815e5cSEd Tanous const std::string& val) {
56975815e5cSEd Tanous if (!ec)
57075815e5cSEd Tanous {
57175815e5cSEd Tanous if (val == "active")
57275815e5cSEd Tanous {
573539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] =
574539d8c6bSEd Tanous resource::Health::Critical;
575539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
576539d8c6bSEd Tanous resource::State::Quiesced;
57775815e5cSEd Tanous return;
57875815e5cSEd Tanous }
57975815e5cSEd Tanous }
580539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK;
581bd79bce8SPatrick Williams asyncResp->res.jsonValue["Status"]["State"] =
582bd79bce8SPatrick Williams resource::State::Enabled;
58375815e5cSEd Tanous });
58475815e5cSEd Tanous }
58575815e5cSEd Tanous
requestRoutesManager(App & app)5867e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app)
5877e860f15SJohn Edward Broadbent {
5887e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid;
5899c310685SBorawski.Lukasz
590253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
591ed398213SEd Tanous .privileges(redfish::privileges::getManager)
592bd79bce8SPatrick Williams .methods(
593bd79bce8SPatrick Williams boost::beast::http::verb::
594bd79bce8SPatrick Williams get)([&app,
595bd79bce8SPatrick Williams uuid](const crow::Request& req,
596253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
597253f11b8SEd Tanous const std::string& managerId) {
5983ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
59945ca1b86SEd Tanous {
60045ca1b86SEd Tanous return;
60145ca1b86SEd Tanous }
602253f11b8SEd Tanous
603253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
604253f11b8SEd Tanous {
605bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager",
606bd79bce8SPatrick Williams managerId);
607253f11b8SEd Tanous return;
608253f11b8SEd Tanous }
609253f11b8SEd Tanous
610253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format(
611253f11b8SEd Tanous "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
612bd79bce8SPatrick Williams asyncResp->res.jsonValue["@odata.type"] =
613bd79bce8SPatrick Williams "#Manager.v1_14_0.Manager";
614253f11b8SEd Tanous asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME;
6157e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
6167e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] =
6177e860f15SJohn Edward Broadbent "Baseboard Management Controller";
618539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On;
6191476687dSEd Tanous
620539d8c6bSEd Tanous asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC;
6217e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
6227e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
623bd79bce8SPatrick Williams asyncResp->res.jsonValue["Model"] =
624bd79bce8SPatrick Williams "OpenBmc"; // TODO(ed), get model
6257e860f15SJohn Edward Broadbent
6261476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
627253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/LogServices",
628253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
6291476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
630253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol",
631253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
6321476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
633bd79bce8SPatrick Williams boost::urls::format(
634bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/EthernetInterfaces",
635253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
6367e860f15SJohn Edward Broadbent
63725b54dbaSEd Tanous if constexpr (BMCWEB_VM_NBDPROXY)
63836c0f2a3SEd Tanous {
6391476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
640253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia",
641253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
64236c0f2a3SEd Tanous }
6437e860f15SJohn Edward Broadbent
644*cc67d0a0Srohitpai getHandleOemOpenBmc(req, asyncResp, managerId);
6457e860f15SJohn Edward Broadbent
6467e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only
6477e860f15SJohn Edward Broadbent // supports BMC reboot.
6487e860f15SJohn Edward Broadbent nlohmann::json& managerReset =
6497e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
650bd79bce8SPatrick Williams managerReset["target"] = boost::urls::format(
651bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/Actions/Manager.Reset",
652253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
6537e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] =
654253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo",
655253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
6567e860f15SJohn Edward Broadbent
6577e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like
6587e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
6597e860f15SJohn Edward Broadbent // on OpenBMC
6607e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults =
6617e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
662253f11b8SEd Tanous resetToDefaults["target"] = boost::urls::format(
663253f11b8SEd Tanous "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults",
664253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
665613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] =
666613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"});
6677e860f15SJohn Edward Broadbent
6687c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset =
6692b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow();
6707c8c4058STejas Patil
6717c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
6727c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] =
6737c8c4058STejas Patil redfishDateTimeOffset.second;
6747e860f15SJohn Edward Broadbent
67525b54dbaSEd Tanous if constexpr (BMCWEB_KVM)
67625b54dbaSEd Tanous {
6777e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info
67825b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] =
67925b54dbaSEd Tanous true;
68025b54dbaSEd Tanous asyncResp->res
68125b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4;
68225b54dbaSEd Tanous asyncResp->res
68325b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
684613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"});
68525b54dbaSEd Tanous }
68625b54dbaSEd Tanous if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM)
6877f3e84a1SEd Tanous {
688bd79bce8SPatrick Williams asyncResp->res
689bd79bce8SPatrick Williams .jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
6901476687dSEd Tanous
6911476687dSEd Tanous nlohmann::json::array_t managerForServers;
6921476687dSEd Tanous nlohmann::json::object_t manager;
693bd79bce8SPatrick Williams manager["@odata.id"] = std::format(
694bd79bce8SPatrick Williams "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME);
695ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager));
6961476687dSEd Tanous
6971476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
6981476687dSEd Tanous std::move(managerForServers);
6997f3e84a1SEd Tanous }
7007e860f15SJohn Edward Broadbent
701eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
7027e860f15SJohn Edward Broadbent "FirmwareVersion", true);
7037e860f15SJohn Edward Broadbent
7047e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp);
7057e860f15SJohn Edward Broadbent
706a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs.
707a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData =
708a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"];
709bd79bce8SPatrick Williams managerDiagnosticData["@odata.id"] = boost::urls::format(
710bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/ManagerDiagnosticData",
711253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME);
712a51fc2d2SSui Chen
71325b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA)
71425b54dbaSEd Tanous {
7157e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp);
7167e860f15SJohn Edward Broadbent pids->run();
71725b54dbaSEd Tanous }
7187e860f15SJohn Edward Broadbent
719bd79bce8SPatrick Williams getMainChassisId(asyncResp, [](const std::string& chassisId,
720bd79bce8SPatrick Williams const std::shared_ptr<
721bd79bce8SPatrick Williams bmcweb::AsyncResp>& aRsp) {
722bd79bce8SPatrick Williams aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] =
723bd79bce8SPatrick Williams 1;
7241476687dSEd Tanous nlohmann::json::array_t managerForChassis;
7258a592810SEd Tanous nlohmann::json::object_t managerObj;
726ef4c65b7SEd Tanous boost::urls::url chassiUrl =
727ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId);
728eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl;
729ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj));
7301476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
7311476687dSEd Tanous std::move(managerForChassis);
7321476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
733eddfc437SWilly Tu chassiUrl;
7347e860f15SJohn Edward Broadbent });
7357e860f15SJohn Edward Broadbent
736deae6a78SEd Tanous dbus::utility::getProperty<double>(
737deae6a78SEd Tanous "org.freedesktop.systemd1", "/org/freedesktop/systemd1",
738deae6a78SEd Tanous "org.freedesktop.systemd1.Manager", "Progress",
73975815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, double val) {
7407e860f15SJohn Edward Broadbent if (ec)
7411abe55efSEd Tanous {
74262598e31SEd Tanous BMCWEB_LOG_ERROR("Error while getting progress");
7437e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res);
7447e860f15SJohn Edward Broadbent return;
7457e860f15SJohn Edward Broadbent }
7461e1e598dSJonathan Doman if (val < 1.0)
7477e860f15SJohn Edward Broadbent {
748539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] =
749539d8c6bSEd Tanous resource::Health::OK;
750539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] =
751539d8c6bSEd Tanous resource::State::Starting;
75275815e5cSEd Tanous return;
7537e860f15SJohn Edward Broadbent }
75475815e5cSEd Tanous checkForQuiesced(asyncResp);
7551e1e598dSJonathan Doman });
7569c310685SBorawski.Lukasz
757e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = {
758e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"};
759e99073f5SGeorge Liu dbus::utility::getSubTree(
760e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces,
7617e860f15SJohn Edward Broadbent [asyncResp](
762e99073f5SGeorge Liu const boost::system::error_code& ec,
763b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) {
7647e860f15SJohn Edward Broadbent if (ec)
7651abe55efSEd Tanous {
766bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG(
767bd79bce8SPatrick Williams "D-Bus response error on GetSubTree {}", ec);
7687e860f15SJohn Edward Broadbent return;
7697e860f15SJohn Edward Broadbent }
77026f6976fSEd Tanous if (subtree.empty())
7717e860f15SJohn Edward Broadbent {
77262598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!");
7737e860f15SJohn Edward Broadbent return;
7747e860f15SJohn Edward Broadbent }
7757e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object
7767e860f15SJohn Edward Broadbent // Throw an error if there is more than 1
7777e860f15SJohn Edward Broadbent if (subtree.size() > 1)
7787e860f15SJohn Edward Broadbent {
77962598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!");
7807e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res);
7817e860f15SJohn Edward Broadbent return;
7827e860f15SJohn Edward Broadbent }
7837e860f15SJohn Edward Broadbent
784bd79bce8SPatrick Williams if (subtree[0].first.empty() ||
785bd79bce8SPatrick Williams subtree[0].second.size() != 1)
7867e860f15SJohn Edward Broadbent {
78762598e31SEd Tanous BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!");
7887e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res);
7897e860f15SJohn Edward Broadbent return;
7907e860f15SJohn Edward Broadbent }
7917e860f15SJohn Edward Broadbent
7927e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first;
793bd79bce8SPatrick Williams const std::string& connectionName =
794bd79bce8SPatrick Williams subtree[0].second[0].first;
7957e860f15SJohn Edward Broadbent
796bd79bce8SPatrick Williams for (const auto& interfaceName :
797bd79bce8SPatrick Williams subtree[0].second[0].second)
7987e860f15SJohn Edward Broadbent {
7997e860f15SJohn Edward Broadbent if (interfaceName ==
8007e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset")
8017e860f15SJohn Edward Broadbent {
802deae6a78SEd Tanous dbus::utility::getAllProperties(
803bd79bce8SPatrick Williams *crow::connections::systemBus, connectionName,
804bd79bce8SPatrick Williams path,
805fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset",
806bd79bce8SPatrick Williams [asyncResp](
807bd79bce8SPatrick Williams const boost::system::error_code& ec2,
808b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap&
8097e860f15SJohn Edward Broadbent propertiesList) {
8108a592810SEd Tanous if (ec2)
8117e860f15SJohn Edward Broadbent {
812bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG(
813bd79bce8SPatrick Williams "Can't get bmc asset!");
8147e860f15SJohn Edward Broadbent return;
8157e860f15SJohn Edward Broadbent }
8167e860f15SJohn Edward Broadbent
817fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr;
818fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr;
819fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr;
820fac6e53bSKrzysztof Grobelny const std::string* model = nullptr;
821bd79bce8SPatrick Williams const std::string* sparePartNumber =
822bd79bce8SPatrick Williams nullptr;
823fac6e53bSKrzysztof Grobelny
824bd79bce8SPatrick Williams const bool success =
825bd79bce8SPatrick Williams sdbusplus::unpackPropertiesNoThrow(
826bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(),
827bd79bce8SPatrick Williams propertiesList, "PartNumber",
828bd79bce8SPatrick Williams partNumber, "SerialNumber",
829bd79bce8SPatrick Williams serialNumber, "Manufacturer",
830bd79bce8SPatrick Williams manufacturer, "Model", model,
831bd79bce8SPatrick Williams "SparePartNumber", sparePartNumber);
832fac6e53bSKrzysztof Grobelny
833fac6e53bSKrzysztof Grobelny if (!success)
8347e860f15SJohn Edward Broadbent {
835002d39b4SEd Tanous messages::internalError(asyncResp->res);
8367e860f15SJohn Edward Broadbent return;
8377e860f15SJohn Edward Broadbent }
838fac6e53bSKrzysztof Grobelny
839fac6e53bSKrzysztof Grobelny if (partNumber != nullptr)
840fac6e53bSKrzysztof Grobelny {
841fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] =
842fac6e53bSKrzysztof Grobelny *partNumber;
8437e860f15SJohn Edward Broadbent }
844fac6e53bSKrzysztof Grobelny
845fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr)
846fac6e53bSKrzysztof Grobelny {
847bd79bce8SPatrick Williams asyncResp->res
848bd79bce8SPatrick Williams .jsonValue["SerialNumber"] =
849fac6e53bSKrzysztof Grobelny *serialNumber;
8507e860f15SJohn Edward Broadbent }
851fac6e53bSKrzysztof Grobelny
852fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr)
853fac6e53bSKrzysztof Grobelny {
854bd79bce8SPatrick Williams asyncResp->res
855bd79bce8SPatrick Williams .jsonValue["Manufacturer"] =
856fac6e53bSKrzysztof Grobelny *manufacturer;
857fac6e53bSKrzysztof Grobelny }
858fac6e53bSKrzysztof Grobelny
859fac6e53bSKrzysztof Grobelny if (model != nullptr)
860fac6e53bSKrzysztof Grobelny {
861bd79bce8SPatrick Williams asyncResp->res.jsonValue["Model"] =
862bd79bce8SPatrick Williams *model;
863fac6e53bSKrzysztof Grobelny }
864fac6e53bSKrzysztof Grobelny
865fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr)
866fac6e53bSKrzysztof Grobelny {
867bd79bce8SPatrick Williams asyncResp->res
868bd79bce8SPatrick Williams .jsonValue["SparePartNumber"] =
869fac6e53bSKrzysztof Grobelny *sparePartNumber;
870fac6e53bSKrzysztof Grobelny }
871fac6e53bSKrzysztof Grobelny });
8727e860f15SJohn Edward Broadbent }
873bd79bce8SPatrick Williams else if (
874bd79bce8SPatrick Williams interfaceName ==
8750fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode")
8767e860f15SJohn Edward Broadbent {
8777e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path);
8787e860f15SJohn Edward Broadbent }
8797e860f15SJohn Edward Broadbent }
880e99073f5SGeorge Liu });
8817e860f15SJohn Edward Broadbent });
8827e860f15SJohn Edward Broadbent
883253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/")
884ed398213SEd Tanous .privileges(redfish::privileges::patchManager)
88545ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)(
88645ca1b86SEd Tanous [&app](const crow::Request& req,
887253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
888253f11b8SEd Tanous const std::string& managerId) {
8893ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
89045ca1b86SEd Tanous {
89145ca1b86SEd Tanous return;
89245ca1b86SEd Tanous }
893253f11b8SEd Tanous
894253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME)
895253f11b8SEd Tanous {
896bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager",
897bd79bce8SPatrick Williams managerId);
898253f11b8SEd Tanous return;
899253f11b8SEd Tanous }
900253f11b8SEd Tanous
9019e9b6049SEd Tanous std::optional<std::string> activeSoftwareImageOdataId;
9027e860f15SJohn Edward Broadbent std::optional<std::string> datetime;
9039e9b6049SEd Tanous std::optional<nlohmann::json::object_t> pidControllers;
9049e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanControllers;
9059e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanZones;
9069e9b6049SEd Tanous std::optional<nlohmann::json::object_t> stepwiseControllers;
9079e9b6049SEd Tanous std::optional<std::string> profile;
9087e860f15SJohn Edward Broadbent
909afc474aeSMyung Bae if (!json_util::readJsonPatch( //
910afc474aeSMyung Bae req, asyncResp->res, //
911afc474aeSMyung Bae "DateTime", datetime, //
912afc474aeSMyung Bae "Links/ActiveSoftwareImage/@odata.id",
913afc474aeSMyung Bae activeSoftwareImageOdataId, //
914afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanControllers", fanControllers, //
915afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanZones", fanZones, //
916afc474aeSMyung Bae "Oem/OpenBmc/Fan/PidControllers", pidControllers, //
917afc474aeSMyung Bae "Oem/OpenBmc/Fan/Profile", profile, //
918afc474aeSMyung Bae "Oem/OpenBmc/Fan/StepwiseControllers",
919afc474aeSMyung Bae stepwiseControllers //
9209e9b6049SEd Tanous ))
9217e860f15SJohn Edward Broadbent {
9227e860f15SJohn Edward Broadbent return;
9237e860f15SJohn Edward Broadbent }
9247e860f15SJohn Edward Broadbent
9259e9b6049SEd Tanous if (pidControllers || fanControllers || fanZones ||
9269e9b6049SEd Tanous stepwiseControllers || profile)
9277e860f15SJohn Edward Broadbent {
92825b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA)
92925b54dbaSEd Tanous {
930bd79bce8SPatrick Williams std::vector<
931bd79bce8SPatrick Williams std::pair<std::string,
93225b54dbaSEd Tanous std::optional<nlohmann::json::object_t>>>
9339e9b6049SEd Tanous configuration;
9349e9b6049SEd Tanous if (pidControllers)
9357e860f15SJohn Edward Broadbent {
936bd79bce8SPatrick Williams configuration.emplace_back(
937bd79bce8SPatrick Williams "PidControllers", std::move(pidControllers));
9387e860f15SJohn Edward Broadbent }
9399e9b6049SEd Tanous if (fanControllers)
9407e860f15SJohn Edward Broadbent {
941bd79bce8SPatrick Williams configuration.emplace_back(
942bd79bce8SPatrick Williams "FanControllers", std::move(fanControllers));
9437e860f15SJohn Edward Broadbent }
9449e9b6049SEd Tanous if (fanZones)
9457e860f15SJohn Edward Broadbent {
946bd79bce8SPatrick Williams configuration.emplace_back("FanZones",
947bd79bce8SPatrick Williams std::move(fanZones));
9489e9b6049SEd Tanous }
9499e9b6049SEd Tanous if (stepwiseControllers)
9509e9b6049SEd Tanous {
951bd79bce8SPatrick Williams configuration.emplace_back(
952bd79bce8SPatrick Williams "StepwiseControllers",
9539e9b6049SEd Tanous std::move(stepwiseControllers));
9549e9b6049SEd Tanous }
9559e9b6049SEd Tanous auto pid = std::make_shared<SetPIDValues>(
9569e9b6049SEd Tanous asyncResp, std::move(configuration), profile);
9577e860f15SJohn Edward Broadbent pid->run();
95825b54dbaSEd Tanous }
95925b54dbaSEd Tanous else
96025b54dbaSEd Tanous {
96154dce7f5SGunnar Mills messages::propertyUnknown(asyncResp->res, "Oem");
96254dce7f5SGunnar Mills return;
96325b54dbaSEd Tanous }
9647e860f15SJohn Edward Broadbent }
9659e9b6049SEd Tanous
9669e9b6049SEd Tanous if (activeSoftwareImageOdataId)
9677e860f15SJohn Edward Broadbent {
968bd79bce8SPatrick Williams setActiveFirmwareImage(asyncResp,
969bd79bce8SPatrick Williams *activeSoftwareImageOdataId);
9707e860f15SJohn Edward Broadbent }
9717e860f15SJohn Edward Broadbent
9727e860f15SJohn Edward Broadbent if (datetime)
9737e860f15SJohn Edward Broadbent {
974c51afd54SEd Tanous setDateTime(asyncResp, *datetime);
9757e860f15SJohn Edward Broadbent }
9767e860f15SJohn Edward Broadbent });
9777e860f15SJohn Edward Broadbent }
9787e860f15SJohn Edward Broadbent
requestRoutesManagerCollection(App & app)9797e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app)
9807e860f15SJohn Edward Broadbent {
9817e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
982ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection)
9837e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)(
98445ca1b86SEd Tanous [&app](const crow::Request& req,
9857e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
9863ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp))
98745ca1b86SEd Tanous {
98845ca1b86SEd Tanous return;
98945ca1b86SEd Tanous }
99083ff9ab6SJames Feist // Collections don't include the static data added by SubRoute
99183ff9ab6SJames Feist // because it has a duplicate entry for members
9928d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
9938d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] =
9948d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection";
9958d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection";
9968d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1;
9971476687dSEd Tanous nlohmann::json::array_t members;
9981476687dSEd Tanous nlohmann::json& bmc = members.emplace_back();
999bd79bce8SPatrick Williams bmc["@odata.id"] = boost::urls::format(
1000bd79bce8SPatrick Williams "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME);
10011476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members);
10027e860f15SJohn Edward Broadbent });
10039c310685SBorawski.Lukasz }
10049c310685SBorawski.Lukasz } // namespace redfish
1005