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" 18d7857201SEd Tanous #include "persistent_data.hpp" 19a51fc2d2SSui Chen #include "query.hpp" 20c1a75ebcSrohitpai #include "redfish.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 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 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 */ 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 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 */ 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 */ 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 */ 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 */ 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 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 */ 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 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 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 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 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 6447e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 6457e860f15SJohn Edward Broadbent // supports BMC reboot. 6467e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 6477e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 648bd79bce8SPatrick Williams managerReset["target"] = boost::urls::format( 649bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/Actions/Manager.Reset", 650253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 6517e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 652253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo", 653253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 6547e860f15SJohn Edward Broadbent 6557e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 6567e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 6577e860f15SJohn Edward Broadbent // on OpenBMC 6587e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 6597e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 660253f11b8SEd Tanous resetToDefaults["target"] = boost::urls::format( 661253f11b8SEd Tanous "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults", 662253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 663613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] = 664613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"}); 6657e860f15SJohn Edward Broadbent 6667c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 6672b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 6687c8c4058STejas Patil 6697c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 6707c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 6717c8c4058STejas Patil redfishDateTimeOffset.second; 6727e860f15SJohn Edward Broadbent 67325b54dbaSEd Tanous if constexpr (BMCWEB_KVM) 67425b54dbaSEd Tanous { 6757e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 67625b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = 67725b54dbaSEd Tanous true; 67825b54dbaSEd Tanous asyncResp->res 67925b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; 68025b54dbaSEd Tanous asyncResp->res 68125b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 682613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 68325b54dbaSEd Tanous } 68425b54dbaSEd Tanous if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 6857f3e84a1SEd Tanous { 686bd79bce8SPatrick Williams asyncResp->res 687bd79bce8SPatrick Williams .jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 6881476687dSEd Tanous 6891476687dSEd Tanous nlohmann::json::array_t managerForServers; 6901476687dSEd Tanous nlohmann::json::object_t manager; 691bd79bce8SPatrick Williams manager["@odata.id"] = std::format( 692bd79bce8SPatrick Williams "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); 693ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager)); 6941476687dSEd Tanous 6951476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 6961476687dSEd Tanous std::move(managerForServers); 6977f3e84a1SEd Tanous } 6987e860f15SJohn Edward Broadbent 699eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 7007e860f15SJohn Edward Broadbent "FirmwareVersion", true); 7017e860f15SJohn Edward Broadbent 7027e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 7037e860f15SJohn Edward Broadbent 704a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 705a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 706a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 707bd79bce8SPatrick Williams managerDiagnosticData["@odata.id"] = boost::urls::format( 708bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/ManagerDiagnosticData", 709253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 710a51fc2d2SSui Chen 711bd79bce8SPatrick Williams getMainChassisId(asyncResp, [](const std::string& chassisId, 712bd79bce8SPatrick Williams const std::shared_ptr< 713bd79bce8SPatrick Williams bmcweb::AsyncResp>& aRsp) { 714bd79bce8SPatrick Williams aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 715bd79bce8SPatrick Williams 1; 7161476687dSEd Tanous nlohmann::json::array_t managerForChassis; 7178a592810SEd Tanous nlohmann::json::object_t managerObj; 718ef4c65b7SEd Tanous boost::urls::url chassiUrl = 719ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 720eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl; 721ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj)); 7221476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 7231476687dSEd Tanous std::move(managerForChassis); 7241476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 725eddfc437SWilly Tu chassiUrl; 7267e860f15SJohn Edward Broadbent }); 7277e860f15SJohn Edward Broadbent 728deae6a78SEd Tanous dbus::utility::getProperty<double>( 729deae6a78SEd Tanous "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 730deae6a78SEd Tanous "org.freedesktop.systemd1.Manager", "Progress", 73175815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, double val) { 7327e860f15SJohn Edward Broadbent if (ec) 7331abe55efSEd Tanous { 73462598e31SEd Tanous BMCWEB_LOG_ERROR("Error while getting progress"); 7357e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 7367e860f15SJohn Edward Broadbent return; 7377e860f15SJohn Edward Broadbent } 7381e1e598dSJonathan Doman if (val < 1.0) 7397e860f15SJohn Edward Broadbent { 740539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = 741539d8c6bSEd Tanous resource::Health::OK; 742539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 743539d8c6bSEd Tanous resource::State::Starting; 74475815e5cSEd Tanous return; 7457e860f15SJohn Edward Broadbent } 74675815e5cSEd Tanous checkForQuiesced(asyncResp); 7471e1e598dSJonathan Doman }); 7489c310685SBorawski.Lukasz 749e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 750e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"}; 751e99073f5SGeorge Liu dbus::utility::getSubTree( 752e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 7537e860f15SJohn Edward Broadbent [asyncResp]( 754e99073f5SGeorge Liu const boost::system::error_code& ec, 755b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 7567e860f15SJohn Edward Broadbent if (ec) 7571abe55efSEd Tanous { 758bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG( 759bd79bce8SPatrick Williams "D-Bus response error on GetSubTree {}", ec); 7607e860f15SJohn Edward Broadbent return; 7617e860f15SJohn Edward Broadbent } 76226f6976fSEd Tanous if (subtree.empty()) 7637e860f15SJohn Edward Broadbent { 76462598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); 7657e860f15SJohn Edward Broadbent return; 7667e860f15SJohn Edward Broadbent } 7677e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 7687e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 7697e860f15SJohn Edward Broadbent if (subtree.size() > 1) 7707e860f15SJohn Edward Broadbent { 77162598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!"); 7727e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 7737e860f15SJohn Edward Broadbent return; 7747e860f15SJohn Edward Broadbent } 7757e860f15SJohn Edward Broadbent 776bd79bce8SPatrick Williams if (subtree[0].first.empty() || 777bd79bce8SPatrick Williams subtree[0].second.size() != 1) 7787e860f15SJohn Edward Broadbent { 77962598e31SEd Tanous BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); 7807e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 7817e860f15SJohn Edward Broadbent return; 7827e860f15SJohn Edward Broadbent } 7837e860f15SJohn Edward Broadbent 7847e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 785bd79bce8SPatrick Williams const std::string& connectionName = 786bd79bce8SPatrick Williams subtree[0].second[0].first; 7877e860f15SJohn Edward Broadbent 788bd79bce8SPatrick Williams for (const auto& interfaceName : 789bd79bce8SPatrick Williams subtree[0].second[0].second) 7907e860f15SJohn Edward Broadbent { 7917e860f15SJohn Edward Broadbent if (interfaceName == 7927e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 7937e860f15SJohn Edward Broadbent { 794deae6a78SEd Tanous dbus::utility::getAllProperties( 795bd79bce8SPatrick Williams *crow::connections::systemBus, connectionName, 796bd79bce8SPatrick Williams path, 797fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 798bd79bce8SPatrick Williams [asyncResp]( 799bd79bce8SPatrick Williams const boost::system::error_code& ec2, 800b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 8017e860f15SJohn Edward Broadbent propertiesList) { 8028a592810SEd Tanous if (ec2) 8037e860f15SJohn Edward Broadbent { 804bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG( 805bd79bce8SPatrick Williams "Can't get bmc asset!"); 8067e860f15SJohn Edward Broadbent return; 8077e860f15SJohn Edward Broadbent } 8087e860f15SJohn Edward Broadbent 809fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr; 810fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr; 811fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr; 812fac6e53bSKrzysztof Grobelny const std::string* model = nullptr; 813bd79bce8SPatrick Williams const std::string* sparePartNumber = 814bd79bce8SPatrick Williams nullptr; 815fac6e53bSKrzysztof Grobelny 816bd79bce8SPatrick Williams const bool success = 817bd79bce8SPatrick Williams sdbusplus::unpackPropertiesNoThrow( 818bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), 819bd79bce8SPatrick Williams propertiesList, "PartNumber", 820bd79bce8SPatrick Williams partNumber, "SerialNumber", 821bd79bce8SPatrick Williams serialNumber, "Manufacturer", 822bd79bce8SPatrick Williams manufacturer, "Model", model, 823bd79bce8SPatrick Williams "SparePartNumber", sparePartNumber); 824fac6e53bSKrzysztof Grobelny 825fac6e53bSKrzysztof Grobelny if (!success) 8267e860f15SJohn Edward Broadbent { 827002d39b4SEd Tanous messages::internalError(asyncResp->res); 8287e860f15SJohn Edward Broadbent return; 8297e860f15SJohn Edward Broadbent } 830fac6e53bSKrzysztof Grobelny 831fac6e53bSKrzysztof Grobelny if (partNumber != nullptr) 832fac6e53bSKrzysztof Grobelny { 833fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = 834fac6e53bSKrzysztof Grobelny *partNumber; 8357e860f15SJohn Edward Broadbent } 836fac6e53bSKrzysztof Grobelny 837fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr) 838fac6e53bSKrzysztof Grobelny { 839bd79bce8SPatrick Williams asyncResp->res 840bd79bce8SPatrick Williams .jsonValue["SerialNumber"] = 841fac6e53bSKrzysztof Grobelny *serialNumber; 8427e860f15SJohn Edward Broadbent } 843fac6e53bSKrzysztof Grobelny 844fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr) 845fac6e53bSKrzysztof Grobelny { 846bd79bce8SPatrick Williams asyncResp->res 847bd79bce8SPatrick Williams .jsonValue["Manufacturer"] = 848fac6e53bSKrzysztof Grobelny *manufacturer; 849fac6e53bSKrzysztof Grobelny } 850fac6e53bSKrzysztof Grobelny 851fac6e53bSKrzysztof Grobelny if (model != nullptr) 852fac6e53bSKrzysztof Grobelny { 853bd79bce8SPatrick Williams asyncResp->res.jsonValue["Model"] = 854bd79bce8SPatrick Williams *model; 855fac6e53bSKrzysztof Grobelny } 856fac6e53bSKrzysztof Grobelny 857fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr) 858fac6e53bSKrzysztof Grobelny { 859bd79bce8SPatrick Williams asyncResp->res 860bd79bce8SPatrick Williams .jsonValue["SparePartNumber"] = 861fac6e53bSKrzysztof Grobelny *sparePartNumber; 862fac6e53bSKrzysztof Grobelny } 863fac6e53bSKrzysztof Grobelny }); 8647e860f15SJohn Edward Broadbent } 865bd79bce8SPatrick Williams else if ( 866bd79bce8SPatrick Williams interfaceName == 8670fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 8687e860f15SJohn Edward Broadbent { 8697e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 8707e860f15SJohn Edward Broadbent } 8717e860f15SJohn Edward Broadbent } 872e99073f5SGeorge Liu }); 873c1a75ebcSrohitpai 874c1a75ebcSrohitpai RedfishService::getInstance(app).handleSubRoute(req, asyncResp); 8757e860f15SJohn Edward Broadbent }); 8767e860f15SJohn Edward Broadbent 877253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") 878ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 87945ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 88045ca1b86SEd Tanous [&app](const crow::Request& req, 881253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 882253f11b8SEd Tanous const std::string& managerId) { 8833ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 88445ca1b86SEd Tanous { 88545ca1b86SEd Tanous return; 88645ca1b86SEd Tanous } 887253f11b8SEd Tanous 888253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 889253f11b8SEd Tanous { 890bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 891bd79bce8SPatrick Williams managerId); 892253f11b8SEd Tanous return; 893253f11b8SEd Tanous } 894253f11b8SEd Tanous 8959e9b6049SEd Tanous std::optional<std::string> activeSoftwareImageOdataId; 8967e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 8979e9b6049SEd Tanous std::optional<nlohmann::json::object_t> pidControllers; 8989e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanControllers; 8999e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanZones; 9009e9b6049SEd Tanous std::optional<nlohmann::json::object_t> stepwiseControllers; 9019e9b6049SEd Tanous std::optional<std::string> profile; 9027e860f15SJohn Edward Broadbent 903afc474aeSMyung Bae if (!json_util::readJsonPatch( // 904afc474aeSMyung Bae req, asyncResp->res, // 905afc474aeSMyung Bae "DateTime", datetime, // 906afc474aeSMyung Bae "Links/ActiveSoftwareImage/@odata.id", 907afc474aeSMyung Bae activeSoftwareImageOdataId, // 908afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanControllers", fanControllers, // 909afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanZones", fanZones, // 910afc474aeSMyung Bae "Oem/OpenBmc/Fan/PidControllers", pidControllers, // 911afc474aeSMyung Bae "Oem/OpenBmc/Fan/Profile", profile, // 912afc474aeSMyung Bae "Oem/OpenBmc/Fan/StepwiseControllers", 913afc474aeSMyung Bae stepwiseControllers // 9149e9b6049SEd Tanous )) 9157e860f15SJohn Edward Broadbent { 9167e860f15SJohn Edward Broadbent return; 9177e860f15SJohn Edward Broadbent } 9187e860f15SJohn Edward Broadbent 9199e9b6049SEd Tanous if (activeSoftwareImageOdataId) 9207e860f15SJohn Edward Broadbent { 921bd79bce8SPatrick Williams setActiveFirmwareImage(asyncResp, 922bd79bce8SPatrick Williams *activeSoftwareImageOdataId); 9237e860f15SJohn Edward Broadbent } 9247e860f15SJohn Edward Broadbent 9257e860f15SJohn Edward Broadbent if (datetime) 9267e860f15SJohn Edward Broadbent { 927c51afd54SEd Tanous setDateTime(asyncResp, *datetime); 9287e860f15SJohn Edward Broadbent } 929*84aad24dSrohitpai 930*84aad24dSrohitpai RedfishService::getInstance(app).handleSubRoute(req, asyncResp); 9317e860f15SJohn Edward Broadbent }); 9327e860f15SJohn Edward Broadbent } 9337e860f15SJohn Edward Broadbent 9347e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 9357e860f15SJohn Edward Broadbent { 9367e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 937ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 9387e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 93945ca1b86SEd Tanous [&app](const crow::Request& req, 9407e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 9413ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 94245ca1b86SEd Tanous { 94345ca1b86SEd Tanous return; 94445ca1b86SEd Tanous } 94583ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 94683ff9ab6SJames Feist // because it has a duplicate entry for members 9478d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 9488d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 9498d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 9508d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 9518d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 9521476687dSEd Tanous nlohmann::json::array_t members; 9531476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 954bd79bce8SPatrick Williams bmc["@odata.id"] = boost::urls::format( 955bd79bce8SPatrick Williams "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); 9561476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 9577e860f15SJohn Edward Broadbent }); 9589c310685SBorawski.Lukasz } 9599c310685SBorawski.Lukasz } // namespace redfish 960