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 * 211*18bf4bf6SGunnar Mills * OpenBMC only supports ResetType "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) 217*18bf4bf6SGunnar Mills .methods(boost::beast::http::verb::post)( 218*18bf4bf6SGunnar Mills [&app](const crow::Request& req, 219253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 220253f11b8SEd Tanous const std::string& managerId) { 2213ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 22245ca1b86SEd Tanous { 22345ca1b86SEd Tanous return; 22445ca1b86SEd Tanous } 225253f11b8SEd Tanous 226253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 227253f11b8SEd Tanous { 228bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 229bd79bce8SPatrick Williams managerId); 230253f11b8SEd Tanous return; 231253f11b8SEd Tanous } 232253f11b8SEd Tanous 23362598e31SEd Tanous BMCWEB_LOG_DEBUG("Post ResetToDefaults."); 2343e40fc74SGunnar Mills 2359970e93fSKonstantin Aladyshev std::optional<std::string> resetType; 2363e40fc74SGunnar Mills 237afc474aeSMyung Bae if (!json_util::readJsonAction( // 238afc474aeSMyung Bae req, asyncResp->res, // 239afc474aeSMyung Bae "ResetType", resetType // 240afc474aeSMyung Bae )) 2413e40fc74SGunnar Mills { 2429970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Missing property ResetType."); 2433e40fc74SGunnar Mills 244bd79bce8SPatrick Williams messages::actionParameterMissing( 245bd79bce8SPatrick Williams asyncResp->res, "ResetToDefaults", "ResetType"); 2463e40fc74SGunnar Mills return; 2473e40fc74SGunnar Mills } 2483e40fc74SGunnar Mills 2493e40fc74SGunnar Mills if (resetType != "ResetAll") 2503e40fc74SGunnar Mills { 2519970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", 2529970e93fSKonstantin Aladyshev *resetType); 253*18bf4bf6SGunnar Mills messages::actionParameterNotSupported( 254*18bf4bf6SGunnar Mills asyncResp->res, *resetType, "ResetType"); 2553e40fc74SGunnar Mills return; 2563e40fc74SGunnar Mills } 2573e40fc74SGunnar Mills 2583e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 2595e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 2603e40fc74SGunnar Mills if (ec) 2613e40fc74SGunnar Mills { 262*18bf4bf6SGunnar Mills BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", 263*18bf4bf6SGunnar Mills ec); 2643e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2653e40fc74SGunnar Mills return; 2663e40fc74SGunnar Mills } 2673e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2683e40fc74SGunnar Mills // Can't erase what the BMC is running on 2693e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2703e40fc74SGunnar Mills }, 271d27c31e9SJagpal Singh Gill getBMCUpdateServiceName(), getBMCUpdateServicePath(), 2723e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2737e860f15SJohn Edward Broadbent }); 2743e40fc74SGunnar Mills } 2753e40fc74SGunnar Mills 2761cb1a9e6SAppaRao Puli /** 2771cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2781cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2791cb1a9e6SAppaRao Puli */ 2807e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2811cb1a9e6SAppaRao Puli { 2821cb1a9e6SAppaRao Puli /** 2831cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2841cb1a9e6SAppaRao Puli */ 2857e860f15SJohn Edward Broadbent 286253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/") 287ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 2887e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 28945ca1b86SEd Tanous [&app](const crow::Request& req, 290253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 291253f11b8SEd Tanous const std::string& managerId) { 2923ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 29345ca1b86SEd Tanous { 29445ca1b86SEd Tanous return; 29545ca1b86SEd Tanous } 2961476687dSEd Tanous 297253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 298253f11b8SEd Tanous { 299bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 300bd79bce8SPatrick Williams managerId); 301253f11b8SEd Tanous return; 302253f11b8SEd Tanous } 303253f11b8SEd Tanous 3041476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 3051476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 306bd79bce8SPatrick Williams asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 307bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/ResetActionInfo", 308253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 3091476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 3101476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 3111476687dSEd Tanous nlohmann::json::object_t parameter; 3121476687dSEd Tanous parameter["Name"] = "ResetType"; 3131476687dSEd Tanous parameter["Required"] = true; 314539d8c6bSEd Tanous parameter["DataType"] = action_info::ParameterTypes::String; 3151476687dSEd Tanous 3161476687dSEd Tanous nlohmann::json::array_t allowableValues; 317ad539545SPatrick Williams allowableValues.emplace_back("GracefulRestart"); 318ad539545SPatrick Williams allowableValues.emplace_back("ForceRestart"); 3191476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues); 3201476687dSEd Tanous 3211476687dSEd Tanous nlohmann::json::array_t parameters; 322ad539545SPatrick Williams parameters.emplace_back(std::move(parameter)); 3231476687dSEd Tanous 3241476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 3257e860f15SJohn Edward Broadbent }); 3261cb1a9e6SAppaRao Puli } 3271cb1a9e6SAppaRao Puli 328071d8fdfSSunnySrivastava1984 /** 329071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 330071d8fdfSSunnySrivastava1984 * 331ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 332071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 333071d8fdfSSunnySrivastava1984 * @param[in] path - object path 334071d8fdfSSunnySrivastava1984 * @return none 335071d8fdfSSunnySrivastava1984 */ 336ac106bf6SEd Tanous inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 337071d8fdfSSunnySrivastava1984 const std::string& connectionName, 338071d8fdfSSunnySrivastava1984 const std::string& path) 339071d8fdfSSunnySrivastava1984 { 34062598e31SEd Tanous BMCWEB_LOG_DEBUG("Get BMC manager Location data."); 341071d8fdfSSunnySrivastava1984 342deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 343deae6a78SEd Tanous connectionName, path, 3441e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 345ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 3461e1e598dSJonathan Doman const std::string& property) { 347071d8fdfSSunnySrivastava1984 if (ec) 348071d8fdfSSunnySrivastava1984 { 34962598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error for " 35062598e31SEd Tanous "Location"); 351ac106bf6SEd Tanous messages::internalError(asyncResp->res); 352071d8fdfSSunnySrivastava1984 return; 353071d8fdfSSunnySrivastava1984 } 354071d8fdfSSunnySrivastava1984 355bd79bce8SPatrick Williams asyncResp->res 356bd79bce8SPatrick Williams .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 3571e1e598dSJonathan Doman property; 3581e1e598dSJonathan Doman }); 359071d8fdfSSunnySrivastava1984 } 3607e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 361504af5a0SPatrick Williams inline void managerGetLastResetTime( 362504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3634bf2b033SGunnar Mills { 36462598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); 3654bf2b033SGunnar Mills 366deae6a78SEd Tanous dbus::utility::getProperty<uint64_t>( 367deae6a78SEd Tanous "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", 368deae6a78SEd Tanous "xyz.openbmc_project.State.BMC", "LastRebootTime", 369ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 3701e1e598dSJonathan Doman const uint64_t lastResetTime) { 3714bf2b033SGunnar Mills if (ec) 3724bf2b033SGunnar Mills { 37362598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 3744bf2b033SGunnar Mills return; 3754bf2b033SGunnar Mills } 3764bf2b033SGunnar Mills 3774bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 3784bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 3791e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 3804bf2b033SGunnar Mills 3814bf2b033SGunnar Mills // Convert to ISO 8601 standard 382ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] = 3832b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 3841e1e598dSJonathan Doman }); 3854bf2b033SGunnar Mills } 3864bf2b033SGunnar Mills 3874bfefa74SGunnar Mills /** 3884bfefa74SGunnar Mills * @brief Set the running firmware image 3894bfefa74SGunnar Mills * 390ac106bf6SEd Tanous * @param[i,o] asyncResp - Async response object 3914bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 3924bfefa74SGunnar Mills * 3934bfefa74SGunnar Mills * @return void 3944bfefa74SGunnar Mills */ 395504af5a0SPatrick Williams inline void setActiveFirmwareImage( 396504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 397f23b7296SEd Tanous const std::string& runningFirmwareTarget) 3984bfefa74SGunnar Mills { 3994bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 400f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 4014bfefa74SGunnar Mills if (idPos == std::string::npos) 4024bfefa74SGunnar Mills { 403ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 4044bfefa74SGunnar Mills "@odata.id"); 40562598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); 4064bfefa74SGunnar Mills return; 4074bfefa74SGunnar Mills } 4084bfefa74SGunnar Mills idPos++; 4094bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 4104bfefa74SGunnar Mills { 411ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 4124bfefa74SGunnar Mills "@odata.id"); 41362598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 4144bfefa74SGunnar Mills return; 4154bfefa74SGunnar Mills } 4164bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 4174bfefa74SGunnar Mills 4184bfefa74SGunnar Mills // Make sure the image is valid before setting priority 4195eb468daSGeorge Liu sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); 4205eb468daSGeorge Liu dbus::utility::getManagedObjects( 421d27c31e9SJagpal Singh Gill getBMCUpdateServiceName(), objPath, 4225eb468daSGeorge Liu [asyncResp, firmwareId, runningFirmwareTarget]( 4235eb468daSGeorge Liu const boost::system::error_code& ec, 4245eb468daSGeorge Liu const dbus::utility::ManagedObjectType& subtree) { 4254bfefa74SGunnar Mills if (ec) 4264bfefa74SGunnar Mills { 42762598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); 428ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4294bfefa74SGunnar Mills return; 4304bfefa74SGunnar Mills } 4314bfefa74SGunnar Mills 43226f6976fSEd Tanous if (subtree.empty()) 4334bfefa74SGunnar Mills { 43462598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find image!"); 435ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4364bfefa74SGunnar Mills return; 4374bfefa74SGunnar Mills } 4384bfefa74SGunnar Mills 4394bfefa74SGunnar Mills bool foundImage = false; 44002cad96eSEd Tanous for (const auto& object : subtree) 4414bfefa74SGunnar Mills { 4424bfefa74SGunnar Mills const std::string& path = 4434bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 444f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 4454bfefa74SGunnar Mills 4464bfefa74SGunnar Mills if (idPos2 == std::string::npos) 4474bfefa74SGunnar Mills { 4484bfefa74SGunnar Mills continue; 4494bfefa74SGunnar Mills } 4504bfefa74SGunnar Mills 4514bfefa74SGunnar Mills idPos2++; 4524bfefa74SGunnar Mills if (idPos2 >= path.size()) 4534bfefa74SGunnar Mills { 4544bfefa74SGunnar Mills continue; 4554bfefa74SGunnar Mills } 4564bfefa74SGunnar Mills 4574bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 4584bfefa74SGunnar Mills { 4594bfefa74SGunnar Mills foundImage = true; 4604bfefa74SGunnar Mills break; 4614bfefa74SGunnar Mills } 4624bfefa74SGunnar Mills } 4634bfefa74SGunnar Mills 4644bfefa74SGunnar Mills if (!foundImage) 4654bfefa74SGunnar Mills { 466ac106bf6SEd Tanous messages::propertyValueNotInList( 467ac106bf6SEd Tanous asyncResp->res, runningFirmwareTarget, "@odata.id"); 46862598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 4694bfefa74SGunnar Mills return; 4704bfefa74SGunnar Mills } 4714bfefa74SGunnar Mills 47262598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.", 47362598e31SEd Tanous firmwareId); 4744bfefa74SGunnar Mills 4754bfefa74SGunnar Mills // Only support Immediate 4764bfefa74SGunnar Mills // An addition could be a Redfish Setting like 4774bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 4789ae226faSGeorge Liu sdbusplus::asio::setProperty( 479d27c31e9SJagpal Singh Gill *crow::connections::systemBus, getBMCUpdateServiceName(), 4809ae226faSGeorge Liu "/xyz/openbmc_project/software/" + firmwareId, 4819ae226faSGeorge Liu "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 4829ae226faSGeorge Liu static_cast<uint8_t>(0), 483ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2) { 4848a592810SEd Tanous if (ec2) 4854bfefa74SGunnar Mills { 48662598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error setting."); 487ac106bf6SEd Tanous messages::internalError(asyncResp->res); 4884bfefa74SGunnar Mills return; 4894bfefa74SGunnar Mills } 490ac106bf6SEd Tanous doBMCGracefulRestart(asyncResp); 4919ae226faSGeorge Liu }); 4925eb468daSGeorge Liu }); 4934bfefa74SGunnar Mills } 4944bfefa74SGunnar Mills 495bd79bce8SPatrick Williams inline void afterSetDateTime( 496bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 497bd79bce8SPatrick Williams const boost::system::error_code& ec, const sdbusplus::message_t& msg) 498c51afd54SEd Tanous { 499c51afd54SEd Tanous if (ec) 500c51afd54SEd Tanous { 501c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}", 502c51afd54SEd Tanous ec); 503c51afd54SEd Tanous const sd_bus_error* dbusError = msg.get_error(); 504c51afd54SEd Tanous if (dbusError != nullptr) 505c51afd54SEd Tanous { 506c51afd54SEd Tanous std::string_view errorName(dbusError->name); 507c51afd54SEd Tanous if (errorName == 508c51afd54SEd Tanous "org.freedesktop.timedate1.AutomaticTimeSyncEnabled") 509c51afd54SEd Tanous { 510c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Setting conflict"); 511c51afd54SEd Tanous messages::propertyValueConflict( 512c51afd54SEd Tanous asyncResp->res, "DateTime", 513c51afd54SEd Tanous "Managers/NetworkProtocol/NTPProcotolEnabled"); 514c51afd54SEd Tanous return; 515c51afd54SEd Tanous } 516c51afd54SEd Tanous } 517c51afd54SEd Tanous messages::internalError(asyncResp->res); 518c51afd54SEd Tanous return; 519c51afd54SEd Tanous } 520c51afd54SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 521c51afd54SEd Tanous } 522c51afd54SEd Tanous 523c51afd54SEd Tanous inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 524c51afd54SEd Tanous const std::string& datetime) 525af5d6058SSantosh Puranik { 52662598e31SEd Tanous BMCWEB_LOG_DEBUG("Set date time: {}", datetime); 527af5d6058SSantosh Puranik 528c2e32007SEd Tanous std::optional<redfish::time_utils::usSinceEpoch> us = 529c2e32007SEd Tanous redfish::time_utils::dateStringToEpoch(datetime); 530c2e32007SEd Tanous if (!us) 531af5d6058SSantosh Puranik { 532ac106bf6SEd Tanous messages::propertyValueFormatError(asyncResp->res, datetime, 533ac106bf6SEd Tanous "DateTime"); 534c2e32007SEd Tanous return; 535c2e32007SEd Tanous } 536c51afd54SEd Tanous // Set the absolute datetime 537c51afd54SEd Tanous bool relative = false; 538c51afd54SEd Tanous bool interactive = false; 539c51afd54SEd Tanous crow::connections::systemBus->async_method_call( 540c51afd54SEd Tanous [asyncResp](const boost::system::error_code& ec, 541c51afd54SEd Tanous const sdbusplus::message_t& msg) { 542c51afd54SEd Tanous afterSetDateTime(asyncResp, ec, msg); 543c51afd54SEd Tanous }, 544c51afd54SEd Tanous "org.freedesktop.timedate1", "/org/freedesktop/timedate1", 545c51afd54SEd Tanous "org.freedesktop.timedate1", "SetTime", us->count(), relative, 546c51afd54SEd Tanous interactive); 54783ff9ab6SJames Feist } 5489c310685SBorawski.Lukasz 549504af5a0SPatrick Williams inline void checkForQuiesced( 550504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 55175815e5cSEd Tanous { 552deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 553deae6a78SEd Tanous "org.freedesktop.systemd1", 55475815e5cSEd Tanous "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", 55575815e5cSEd Tanous "org.freedesktop.systemd1.Unit", "ActiveState", 55675815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, 55775815e5cSEd Tanous const std::string& val) { 55875815e5cSEd Tanous if (!ec) 55975815e5cSEd Tanous { 56075815e5cSEd Tanous if (val == "active") 56175815e5cSEd Tanous { 562539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = 563539d8c6bSEd Tanous resource::Health::Critical; 564539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 565539d8c6bSEd Tanous resource::State::Quiesced; 56675815e5cSEd Tanous return; 56775815e5cSEd Tanous } 56875815e5cSEd Tanous } 569539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; 570bd79bce8SPatrick Williams asyncResp->res.jsonValue["Status"]["State"] = 571bd79bce8SPatrick Williams resource::State::Enabled; 57275815e5cSEd Tanous }); 57375815e5cSEd Tanous } 57475815e5cSEd Tanous 5757e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 5767e860f15SJohn Edward Broadbent { 5777e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 5789c310685SBorawski.Lukasz 579253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") 580ed398213SEd Tanous .privileges(redfish::privileges::getManager) 581bd79bce8SPatrick Williams .methods( 582bd79bce8SPatrick Williams boost::beast::http::verb:: 583bd79bce8SPatrick Williams get)([&app, 584bd79bce8SPatrick Williams uuid](const crow::Request& req, 585253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 586253f11b8SEd Tanous const std::string& managerId) { 5873ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 58845ca1b86SEd Tanous { 58945ca1b86SEd Tanous return; 59045ca1b86SEd Tanous } 591253f11b8SEd Tanous 592253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 593253f11b8SEd Tanous { 594bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 595bd79bce8SPatrick Williams managerId); 596253f11b8SEd Tanous return; 597253f11b8SEd Tanous } 598253f11b8SEd Tanous 599253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 600253f11b8SEd Tanous "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); 601bd79bce8SPatrick Williams asyncResp->res.jsonValue["@odata.type"] = 602bd79bce8SPatrick Williams "#Manager.v1_14_0.Manager"; 603253f11b8SEd Tanous asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME; 6047e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 6057e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 6067e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 607539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On; 6081476687dSEd Tanous 609539d8c6bSEd Tanous asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC; 6107e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 6117e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 612bd79bce8SPatrick Williams asyncResp->res.jsonValue["Model"] = 613bd79bce8SPatrick Williams "OpenBmc"; // TODO(ed), get model 6147e860f15SJohn Edward Broadbent 6151476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 616253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/LogServices", 617253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 6181476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 619253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol", 620253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 6211476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 622bd79bce8SPatrick Williams boost::urls::format( 623bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/EthernetInterfaces", 624253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 6257e860f15SJohn Edward Broadbent 62625b54dbaSEd Tanous if constexpr (BMCWEB_VM_NBDPROXY) 62736c0f2a3SEd Tanous { 6281476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 629253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", 630253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 63136c0f2a3SEd Tanous } 6327e860f15SJohn Edward Broadbent 6337e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 6347e860f15SJohn Edward Broadbent // supports BMC reboot. 6357e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 6367e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 637bd79bce8SPatrick Williams managerReset["target"] = boost::urls::format( 638bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/Actions/Manager.Reset", 639253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 6407e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 641253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo", 642253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 6437e860f15SJohn Edward Broadbent 6447e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 6457e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 6467e860f15SJohn Edward Broadbent // on OpenBMC 6477e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 6487e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 649253f11b8SEd Tanous resetToDefaults["target"] = boost::urls::format( 650253f11b8SEd Tanous "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults", 651253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 652613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] = 653613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"}); 6547e860f15SJohn Edward Broadbent 6557c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 6562b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 6577c8c4058STejas Patil 6587c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 6597c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 6607c8c4058STejas Patil redfishDateTimeOffset.second; 6617e860f15SJohn Edward Broadbent 66225b54dbaSEd Tanous if constexpr (BMCWEB_KVM) 66325b54dbaSEd Tanous { 6647e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 66525b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = 66625b54dbaSEd Tanous true; 66725b54dbaSEd Tanous asyncResp->res 66825b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; 66925b54dbaSEd Tanous asyncResp->res 67025b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 671613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 67225b54dbaSEd Tanous } 67325b54dbaSEd Tanous if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 6747f3e84a1SEd Tanous { 675bd79bce8SPatrick Williams asyncResp->res 676bd79bce8SPatrick Williams .jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 6771476687dSEd Tanous 6781476687dSEd Tanous nlohmann::json::array_t managerForServers; 6791476687dSEd Tanous nlohmann::json::object_t manager; 680bd79bce8SPatrick Williams manager["@odata.id"] = std::format( 681bd79bce8SPatrick Williams "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); 682ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager)); 6831476687dSEd Tanous 6841476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 6851476687dSEd Tanous std::move(managerForServers); 6867f3e84a1SEd Tanous } 6877e860f15SJohn Edward Broadbent 688eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 6897e860f15SJohn Edward Broadbent "FirmwareVersion", true); 6907e860f15SJohn Edward Broadbent 6917e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 6927e860f15SJohn Edward Broadbent 693a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 694a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 695a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 696bd79bce8SPatrick Williams managerDiagnosticData["@odata.id"] = boost::urls::format( 697bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/ManagerDiagnosticData", 698253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 699a51fc2d2SSui Chen 700bd79bce8SPatrick Williams getMainChassisId(asyncResp, [](const std::string& chassisId, 701bd79bce8SPatrick Williams const std::shared_ptr< 702bd79bce8SPatrick Williams bmcweb::AsyncResp>& aRsp) { 703bd79bce8SPatrick Williams aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 704bd79bce8SPatrick Williams 1; 7051476687dSEd Tanous nlohmann::json::array_t managerForChassis; 7068a592810SEd Tanous nlohmann::json::object_t managerObj; 707ef4c65b7SEd Tanous boost::urls::url chassiUrl = 708ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 709eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl; 710ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj)); 7111476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 7121476687dSEd Tanous std::move(managerForChassis); 7131476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 714eddfc437SWilly Tu chassiUrl; 7157e860f15SJohn Edward Broadbent }); 7167e860f15SJohn Edward Broadbent 717deae6a78SEd Tanous dbus::utility::getProperty<double>( 718deae6a78SEd Tanous "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 719deae6a78SEd Tanous "org.freedesktop.systemd1.Manager", "Progress", 72075815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, double val) { 7217e860f15SJohn Edward Broadbent if (ec) 7221abe55efSEd Tanous { 72362598e31SEd Tanous BMCWEB_LOG_ERROR("Error while getting progress"); 7247e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 7257e860f15SJohn Edward Broadbent return; 7267e860f15SJohn Edward Broadbent } 7271e1e598dSJonathan Doman if (val < 1.0) 7287e860f15SJohn Edward Broadbent { 729539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = 730539d8c6bSEd Tanous resource::Health::OK; 731539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 732539d8c6bSEd Tanous resource::State::Starting; 73375815e5cSEd Tanous return; 7347e860f15SJohn Edward Broadbent } 73575815e5cSEd Tanous checkForQuiesced(asyncResp); 7361e1e598dSJonathan Doman }); 7379c310685SBorawski.Lukasz 738e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 739e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"}; 740e99073f5SGeorge Liu dbus::utility::getSubTree( 741e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 7427e860f15SJohn Edward Broadbent [asyncResp]( 743e99073f5SGeorge Liu const boost::system::error_code& ec, 744b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 7457e860f15SJohn Edward Broadbent if (ec) 7461abe55efSEd Tanous { 747bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG( 748bd79bce8SPatrick Williams "D-Bus response error on GetSubTree {}", ec); 7497e860f15SJohn Edward Broadbent return; 7507e860f15SJohn Edward Broadbent } 75126f6976fSEd Tanous if (subtree.empty()) 7527e860f15SJohn Edward Broadbent { 75362598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); 7547e860f15SJohn Edward Broadbent return; 7557e860f15SJohn Edward Broadbent } 7567e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 7577e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 7587e860f15SJohn Edward Broadbent if (subtree.size() > 1) 7597e860f15SJohn Edward Broadbent { 76062598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!"); 7617e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 7627e860f15SJohn Edward Broadbent return; 7637e860f15SJohn Edward Broadbent } 7647e860f15SJohn Edward Broadbent 765bd79bce8SPatrick Williams if (subtree[0].first.empty() || 766bd79bce8SPatrick Williams subtree[0].second.size() != 1) 7677e860f15SJohn Edward Broadbent { 76862598e31SEd Tanous BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); 7697e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 7707e860f15SJohn Edward Broadbent return; 7717e860f15SJohn Edward Broadbent } 7727e860f15SJohn Edward Broadbent 7737e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 774bd79bce8SPatrick Williams const std::string& connectionName = 775bd79bce8SPatrick Williams subtree[0].second[0].first; 7767e860f15SJohn Edward Broadbent 777bd79bce8SPatrick Williams for (const auto& interfaceName : 778bd79bce8SPatrick Williams subtree[0].second[0].second) 7797e860f15SJohn Edward Broadbent { 7807e860f15SJohn Edward Broadbent if (interfaceName == 7817e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 7827e860f15SJohn Edward Broadbent { 783deae6a78SEd Tanous dbus::utility::getAllProperties( 784bd79bce8SPatrick Williams *crow::connections::systemBus, connectionName, 785bd79bce8SPatrick Williams path, 786fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 787bd79bce8SPatrick Williams [asyncResp]( 788bd79bce8SPatrick Williams const boost::system::error_code& ec2, 789b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 7907e860f15SJohn Edward Broadbent propertiesList) { 7918a592810SEd Tanous if (ec2) 7927e860f15SJohn Edward Broadbent { 793bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG( 794bd79bce8SPatrick Williams "Can't get bmc asset!"); 7957e860f15SJohn Edward Broadbent return; 7967e860f15SJohn Edward Broadbent } 7977e860f15SJohn Edward Broadbent 798fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr; 799fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr; 800fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr; 801fac6e53bSKrzysztof Grobelny const std::string* model = nullptr; 802bd79bce8SPatrick Williams const std::string* sparePartNumber = 803bd79bce8SPatrick Williams nullptr; 804fac6e53bSKrzysztof Grobelny 805bd79bce8SPatrick Williams const bool success = 806bd79bce8SPatrick Williams sdbusplus::unpackPropertiesNoThrow( 807bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), 808bd79bce8SPatrick Williams propertiesList, "PartNumber", 809bd79bce8SPatrick Williams partNumber, "SerialNumber", 810bd79bce8SPatrick Williams serialNumber, "Manufacturer", 811bd79bce8SPatrick Williams manufacturer, "Model", model, 812bd79bce8SPatrick Williams "SparePartNumber", sparePartNumber); 813fac6e53bSKrzysztof Grobelny 814fac6e53bSKrzysztof Grobelny if (!success) 8157e860f15SJohn Edward Broadbent { 816002d39b4SEd Tanous messages::internalError(asyncResp->res); 8177e860f15SJohn Edward Broadbent return; 8187e860f15SJohn Edward Broadbent } 819fac6e53bSKrzysztof Grobelny 820fac6e53bSKrzysztof Grobelny if (partNumber != nullptr) 821fac6e53bSKrzysztof Grobelny { 822fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = 823fac6e53bSKrzysztof Grobelny *partNumber; 8247e860f15SJohn Edward Broadbent } 825fac6e53bSKrzysztof Grobelny 826fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr) 827fac6e53bSKrzysztof Grobelny { 828bd79bce8SPatrick Williams asyncResp->res 829bd79bce8SPatrick Williams .jsonValue["SerialNumber"] = 830fac6e53bSKrzysztof Grobelny *serialNumber; 8317e860f15SJohn Edward Broadbent } 832fac6e53bSKrzysztof Grobelny 833fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr) 834fac6e53bSKrzysztof Grobelny { 835bd79bce8SPatrick Williams asyncResp->res 836bd79bce8SPatrick Williams .jsonValue["Manufacturer"] = 837fac6e53bSKrzysztof Grobelny *manufacturer; 838fac6e53bSKrzysztof Grobelny } 839fac6e53bSKrzysztof Grobelny 840fac6e53bSKrzysztof Grobelny if (model != nullptr) 841fac6e53bSKrzysztof Grobelny { 842bd79bce8SPatrick Williams asyncResp->res.jsonValue["Model"] = 843bd79bce8SPatrick Williams *model; 844fac6e53bSKrzysztof Grobelny } 845fac6e53bSKrzysztof Grobelny 846fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr) 847fac6e53bSKrzysztof Grobelny { 848bd79bce8SPatrick Williams asyncResp->res 849bd79bce8SPatrick Williams .jsonValue["SparePartNumber"] = 850fac6e53bSKrzysztof Grobelny *sparePartNumber; 851fac6e53bSKrzysztof Grobelny } 852fac6e53bSKrzysztof Grobelny }); 8537e860f15SJohn Edward Broadbent } 854bd79bce8SPatrick Williams else if ( 855bd79bce8SPatrick Williams interfaceName == 8560fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 8577e860f15SJohn Edward Broadbent { 8587e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 8597e860f15SJohn Edward Broadbent } 8607e860f15SJohn Edward Broadbent } 861e99073f5SGeorge Liu }); 862c1a75ebcSrohitpai 863c1a75ebcSrohitpai RedfishService::getInstance(app).handleSubRoute(req, asyncResp); 8647e860f15SJohn Edward Broadbent }); 8657e860f15SJohn Edward Broadbent 866253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") 867ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 86845ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 86945ca1b86SEd Tanous [&app](const crow::Request& req, 870253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 871253f11b8SEd Tanous const std::string& managerId) { 8723ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 87345ca1b86SEd Tanous { 87445ca1b86SEd Tanous return; 87545ca1b86SEd Tanous } 876253f11b8SEd Tanous 877253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 878253f11b8SEd Tanous { 879bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 880bd79bce8SPatrick Williams managerId); 881253f11b8SEd Tanous return; 882253f11b8SEd Tanous } 883253f11b8SEd Tanous 8849e9b6049SEd Tanous std::optional<std::string> activeSoftwareImageOdataId; 8857e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 8869e9b6049SEd Tanous std::optional<nlohmann::json::object_t> pidControllers; 8879e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanControllers; 8889e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanZones; 8899e9b6049SEd Tanous std::optional<nlohmann::json::object_t> stepwiseControllers; 8909e9b6049SEd Tanous std::optional<std::string> profile; 8917e860f15SJohn Edward Broadbent 892afc474aeSMyung Bae if (!json_util::readJsonPatch( // 893afc474aeSMyung Bae req, asyncResp->res, // 894afc474aeSMyung Bae "DateTime", datetime, // 895afc474aeSMyung Bae "Links/ActiveSoftwareImage/@odata.id", 896afc474aeSMyung Bae activeSoftwareImageOdataId, // 897afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanControllers", fanControllers, // 898afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanZones", fanZones, // 899afc474aeSMyung Bae "Oem/OpenBmc/Fan/PidControllers", pidControllers, // 900afc474aeSMyung Bae "Oem/OpenBmc/Fan/Profile", profile, // 901afc474aeSMyung Bae "Oem/OpenBmc/Fan/StepwiseControllers", 902afc474aeSMyung Bae stepwiseControllers // 9039e9b6049SEd Tanous )) 9047e860f15SJohn Edward Broadbent { 9057e860f15SJohn Edward Broadbent return; 9067e860f15SJohn Edward Broadbent } 9077e860f15SJohn Edward Broadbent 9089e9b6049SEd Tanous if (activeSoftwareImageOdataId) 9097e860f15SJohn Edward Broadbent { 910bd79bce8SPatrick Williams setActiveFirmwareImage(asyncResp, 911bd79bce8SPatrick Williams *activeSoftwareImageOdataId); 9127e860f15SJohn Edward Broadbent } 9137e860f15SJohn Edward Broadbent 9147e860f15SJohn Edward Broadbent if (datetime) 9157e860f15SJohn Edward Broadbent { 916c51afd54SEd Tanous setDateTime(asyncResp, *datetime); 9177e860f15SJohn Edward Broadbent } 91884aad24dSrohitpai 91984aad24dSrohitpai RedfishService::getInstance(app).handleSubRoute(req, asyncResp); 9207e860f15SJohn Edward Broadbent }); 9217e860f15SJohn Edward Broadbent } 9227e860f15SJohn Edward Broadbent 9237e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 9247e860f15SJohn Edward Broadbent { 9257e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 926ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 9277e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 92845ca1b86SEd Tanous [&app](const crow::Request& req, 9297e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 9303ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 93145ca1b86SEd Tanous { 93245ca1b86SEd Tanous return; 93345ca1b86SEd Tanous } 93483ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 93583ff9ab6SJames Feist // because it has a duplicate entry for members 9368d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 9378d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 9388d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 9398d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 9408d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 9411476687dSEd Tanous nlohmann::json::array_t members; 9421476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 943bd79bce8SPatrick Williams bmc["@odata.id"] = boost::urls::format( 944bd79bce8SPatrick Williams "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); 9451476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 9467e860f15SJohn Edward Broadbent }); 9479c310685SBorawski.Lukasz } 9489c310685SBorawski.Lukasz } // namespace redfish 949