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" 20c5d03ff4SJennifer Lee #include "redfish_util.hpp" 21a51fc2d2SSui Chen #include "registries/privilege_registry.hpp" 22fac6e53bSKrzysztof Grobelny #include "utils/dbus_utils.hpp" 233ccb3adbSEd Tanous #include "utils/json_utils.hpp" 24a51fc2d2SSui Chen #include "utils/sw_utils.hpp" 25a51fc2d2SSui Chen #include "utils/systemd_utils.hpp" 262b82937eSEd Tanous #include "utils/time_utils.hpp" 279c310685SBorawski.Lukasz 28d7857201SEd Tanous #include <systemd/sd-bus.h> 29d7857201SEd Tanous 30d7857201SEd Tanous #include <boost/asio/post.hpp> 31d7857201SEd Tanous #include <boost/beast/http/status.hpp> 32d7857201SEd Tanous #include <boost/beast/http/verb.hpp> 33d7857201SEd Tanous #include <boost/container/flat_map.hpp> 34d7857201SEd Tanous #include <boost/container/flat_set.hpp> 35e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 36ef4c65b7SEd Tanous #include <boost/url/format.hpp> 37d7857201SEd Tanous #include <boost/url/url.hpp> 38d7857201SEd Tanous #include <nlohmann/json.hpp> 39fac6e53bSKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 40d7857201SEd Tanous #include <sdbusplus/message.hpp> 41d7857201SEd Tanous #include <sdbusplus/message/native_types.hpp> 42fac6e53bSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 431214b7e7SGunnar Mills 44a170f275SEd Tanous #include <algorithm> 45e99073f5SGeorge Liu #include <array> 46d7857201SEd Tanous #include <cstddef> 474bfefa74SGunnar Mills #include <cstdint> 48d7857201SEd Tanous #include <format> 49d7857201SEd Tanous #include <functional> 50d7857201SEd Tanous #include <map> 511214b7e7SGunnar Mills #include <memory> 529970e93fSKonstantin Aladyshev #include <optional> 533544d2a7SEd Tanous #include <ranges> 549970e93fSKonstantin Aladyshev #include <string> 55e99073f5SGeorge Liu #include <string_view> 56d7857201SEd Tanous #include <utility> 57abf2add6SEd Tanous #include <variant> 58d7857201SEd Tanous #include <vector> 595b4aa86bSJames Feist 601abe55efSEd Tanous namespace redfish 611abe55efSEd Tanous { 62ed5befbdSJennifer Lee 63d27c31e9SJagpal Singh Gill inline std::string getBMCUpdateServiceName() 64d27c31e9SJagpal Singh Gill { 65d27c31e9SJagpal Singh Gill if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) 66d27c31e9SJagpal Singh Gill { 67d27c31e9SJagpal Singh Gill return "xyz.openbmc_project.Software.Manager"; 68d27c31e9SJagpal Singh Gill } 69d27c31e9SJagpal Singh Gill return "xyz.openbmc_project.Software.BMC.Updater"; 70d27c31e9SJagpal Singh Gill } 71d27c31e9SJagpal Singh Gill 72d27c31e9SJagpal Singh Gill inline std::string getBMCUpdateServicePath() 73d27c31e9SJagpal Singh Gill { 74d27c31e9SJagpal Singh Gill if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) 75d27c31e9SJagpal Singh Gill { 76d27c31e9SJagpal Singh Gill return "/xyz/openbmc_project/software/bmc"; 77d27c31e9SJagpal Singh Gill } 78d27c31e9SJagpal Singh Gill return "/xyz/openbmc_project/software"; 79d27c31e9SJagpal Singh Gill } 80d27c31e9SJagpal Singh Gill 81ed5befbdSJennifer Lee /** 822a5c4407SGunnar Mills * Function reboots the BMC. 832a5c4407SGunnar Mills * 842a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls 85ed5befbdSJennifer Lee */ 86*504af5a0SPatrick Williams inline void doBMCGracefulRestart( 87*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 88ed5befbdSJennifer Lee { 89ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 90ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 91ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 92ed5befbdSJennifer Lee const std::string& propertyValue = 93ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 94ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 95ed5befbdSJennifer Lee 96ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 979ae226faSGeorge Liu sdbusplus::asio::setProperty( 989ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName, 999ae226faSGeorge Liu destProperty, propertyValue, 1005e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 101ed5befbdSJennifer Lee // Use "Set" method to set the property value. 102ed5befbdSJennifer Lee if (ec) 103ed5befbdSJennifer Lee { 10462598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 105ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 106ed5befbdSJennifer Lee return; 107ed5befbdSJennifer Lee } 108ed5befbdSJennifer Lee 109ed5befbdSJennifer Lee messages::success(asyncResp->res); 1109ae226faSGeorge Liu }); 111ed5befbdSJennifer Lee } 1122a5c4407SGunnar Mills 113*504af5a0SPatrick Williams inline void doBMCForceRestart( 114*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 115f92af389SJayaprakash Mutyala { 116f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC"; 117f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 118f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC"; 119f92af389SJayaprakash Mutyala const std::string& propertyValue = 120f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 121f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition"; 122f92af389SJayaprakash Mutyala 123f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call. 1249ae226faSGeorge Liu sdbusplus::asio::setProperty( 1259ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName, 1269ae226faSGeorge Liu destProperty, propertyValue, 1275e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 128f92af389SJayaprakash Mutyala // Use "Set" method to set the property value. 129f92af389SJayaprakash Mutyala if (ec) 130f92af389SJayaprakash Mutyala { 13162598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 132f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res); 133f92af389SJayaprakash Mutyala return; 134f92af389SJayaprakash Mutyala } 135f92af389SJayaprakash Mutyala 136f92af389SJayaprakash Mutyala messages::success(asyncResp->res); 1379ae226faSGeorge Liu }); 138f92af389SJayaprakash Mutyala } 139f92af389SJayaprakash Mutyala 1402a5c4407SGunnar Mills /** 1412a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot) 1422a5c4407SGunnar Mills * action. 1432a5c4407SGunnar Mills */ 1447e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app) 1452a5c4407SGunnar Mills { 1462a5c4407SGunnar Mills /** 1472a5c4407SGunnar Mills * Function handles POST method request. 1482a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 149f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 1502a5c4407SGunnar Mills */ 1517e860f15SJohn Edward Broadbent 152253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/") 153ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1547e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 15545ca1b86SEd Tanous [&app](const crow::Request& req, 156253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 157253f11b8SEd Tanous const std::string& managerId) { 1583ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 15945ca1b86SEd Tanous { 16045ca1b86SEd Tanous return; 16145ca1b86SEd Tanous } 162253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 163253f11b8SEd Tanous { 164bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 165bd79bce8SPatrick Williams managerId); 166253f11b8SEd Tanous return; 167253f11b8SEd Tanous } 168253f11b8SEd Tanous 16962598e31SEd Tanous BMCWEB_LOG_DEBUG("Post Manager Reset."); 1702a5c4407SGunnar Mills 1712a5c4407SGunnar Mills std::string resetType; 1722a5c4407SGunnar Mills 17315ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 1747e860f15SJohn Edward Broadbent resetType)) 1752a5c4407SGunnar Mills { 1762a5c4407SGunnar Mills return; 1772a5c4407SGunnar Mills } 1782a5c4407SGunnar Mills 179f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart") 180f92af389SJayaprakash Mutyala { 18162598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 182f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp); 183f92af389SJayaprakash Mutyala return; 184f92af389SJayaprakash Mutyala } 1853174e4dfSEd Tanous if (resetType == "ForceRestart") 186f92af389SJayaprakash Mutyala { 18762598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 188f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp); 189f92af389SJayaprakash Mutyala return; 190f92af389SJayaprakash Mutyala } 191bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", 192bd79bce8SPatrick Williams resetType); 1932a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType, 1942a5c4407SGunnar Mills "ResetType"); 1952a5c4407SGunnar Mills 1962a5c4407SGunnar Mills return; 1977e860f15SJohn Edward Broadbent }); 1982a5c4407SGunnar Mills } 199ed5befbdSJennifer Lee 2003e40fc74SGunnar Mills /** 2013e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset 2023e40fc74SGunnar Mills * action. 2033e40fc74SGunnar Mills */ 2047e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app) 2053e40fc74SGunnar Mills { 2063e40fc74SGunnar Mills /** 2073e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request. 2083e40fc74SGunnar Mills * 2093e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling 2103e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot. 2113e40fc74SGunnar Mills * 2123e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write 2133e40fc74SGunnar Mills * filesystem which includes things like the network settings. 2143e40fc74SGunnar Mills * 2153e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll". 2163e40fc74SGunnar Mills */ 2177e860f15SJohn Edward Broadbent 2187e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 219253f11b8SEd Tanous "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/") 220ed398213SEd Tanous .privileges(redfish::privileges::postManager) 221bd79bce8SPatrick Williams .methods( 222bd79bce8SPatrick Williams boost::beast::http::verb:: 223bd79bce8SPatrick Williams post)([&app]( 224bd79bce8SPatrick Williams const crow::Request& req, 225253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 226253f11b8SEd Tanous const std::string& managerId) { 2273ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 22845ca1b86SEd Tanous { 22945ca1b86SEd Tanous return; 23045ca1b86SEd Tanous } 231253f11b8SEd Tanous 232253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 233253f11b8SEd Tanous { 234bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 235bd79bce8SPatrick Williams managerId); 236253f11b8SEd Tanous return; 237253f11b8SEd Tanous } 238253f11b8SEd Tanous 23962598e31SEd Tanous BMCWEB_LOG_DEBUG("Post ResetToDefaults."); 2403e40fc74SGunnar Mills 2419970e93fSKonstantin Aladyshev std::optional<std::string> resetType; 2429970e93fSKonstantin Aladyshev std::optional<std::string> resetToDefaultsType; 2433e40fc74SGunnar Mills 244afc474aeSMyung Bae if (!json_util::readJsonAction( // 245afc474aeSMyung Bae req, asyncResp->res, // 246afc474aeSMyung Bae "ResetToDefaultsType", resetToDefaultsType, // 247afc474aeSMyung Bae "ResetType", resetType // 248afc474aeSMyung Bae )) 2493e40fc74SGunnar Mills { 2509970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Missing property ResetType."); 2513e40fc74SGunnar Mills 252bd79bce8SPatrick Williams messages::actionParameterMissing( 253bd79bce8SPatrick Williams asyncResp->res, "ResetToDefaults", "ResetType"); 2543e40fc74SGunnar Mills return; 2553e40fc74SGunnar Mills } 2563e40fc74SGunnar Mills 2579970e93fSKonstantin Aladyshev if (resetToDefaultsType && !resetType) 2589970e93fSKonstantin Aladyshev { 2599970e93fSKonstantin Aladyshev BMCWEB_LOG_WARNING( 2609970e93fSKonstantin Aladyshev "Using deprecated ResetToDefaultsType, should be ResetType." 2619970e93fSKonstantin Aladyshev "Support for the ResetToDefaultsType will be dropped in 2Q24"); 2629970e93fSKonstantin Aladyshev resetType = resetToDefaultsType; 2639970e93fSKonstantin Aladyshev } 2649970e93fSKonstantin Aladyshev 2653e40fc74SGunnar Mills if (resetType != "ResetAll") 2663e40fc74SGunnar Mills { 2679970e93fSKonstantin Aladyshev BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", 2689970e93fSKonstantin Aladyshev *resetType); 269bd79bce8SPatrick Williams messages::actionParameterNotSupported(asyncResp->res, 270bd79bce8SPatrick Williams *resetType, "ResetType"); 2713e40fc74SGunnar Mills return; 2723e40fc74SGunnar Mills } 2733e40fc74SGunnar Mills 2743e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 2755e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 2763e40fc74SGunnar Mills if (ec) 2773e40fc74SGunnar Mills { 27862598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec); 2793e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2803e40fc74SGunnar Mills return; 2813e40fc74SGunnar Mills } 2823e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2833e40fc74SGunnar Mills // Can't erase what the BMC is running on 2843e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2853e40fc74SGunnar Mills }, 286d27c31e9SJagpal Singh Gill getBMCUpdateServiceName(), getBMCUpdateServicePath(), 2873e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2887e860f15SJohn Edward Broadbent }); 2893e40fc74SGunnar Mills } 2903e40fc74SGunnar Mills 2911cb1a9e6SAppaRao Puli /** 2921cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2931cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2941cb1a9e6SAppaRao Puli */ 2957e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2961cb1a9e6SAppaRao Puli { 2971cb1a9e6SAppaRao Puli /** 2981cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2991cb1a9e6SAppaRao Puli */ 3007e860f15SJohn Edward Broadbent 301253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/") 302ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 3037e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 30445ca1b86SEd Tanous [&app](const crow::Request& req, 305253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 306253f11b8SEd Tanous const std::string& managerId) { 3073ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 30845ca1b86SEd Tanous { 30945ca1b86SEd Tanous return; 31045ca1b86SEd Tanous } 3111476687dSEd Tanous 312253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 313253f11b8SEd Tanous { 314bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 315bd79bce8SPatrick Williams managerId); 316253f11b8SEd Tanous return; 317253f11b8SEd Tanous } 318253f11b8SEd Tanous 3191476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 3201476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 321bd79bce8SPatrick Williams asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 322bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/ResetActionInfo", 323253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 3241476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 3251476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 3261476687dSEd Tanous nlohmann::json::object_t parameter; 3271476687dSEd Tanous parameter["Name"] = "ResetType"; 3281476687dSEd Tanous parameter["Required"] = true; 329539d8c6bSEd Tanous parameter["DataType"] = action_info::ParameterTypes::String; 3301476687dSEd Tanous 3311476687dSEd Tanous nlohmann::json::array_t allowableValues; 332ad539545SPatrick Williams allowableValues.emplace_back("GracefulRestart"); 333ad539545SPatrick Williams allowableValues.emplace_back("ForceRestart"); 3341476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues); 3351476687dSEd Tanous 3361476687dSEd Tanous nlohmann::json::array_t parameters; 337ad539545SPatrick Williams parameters.emplace_back(std::move(parameter)); 3381476687dSEd Tanous 3391476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 3407e860f15SJohn Edward Broadbent }); 3411cb1a9e6SAppaRao Puli } 3421cb1a9e6SAppaRao Puli 3435b4aa86bSJames Feist static constexpr const char* objectManagerIface = 3445b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 3455b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 3465b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 3475b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 3485b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 349b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 350b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 35173df0db0SJames Feist static constexpr const char* thermalModeIface = 35273df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 3539c310685SBorawski.Lukasz 354*504af5a0SPatrick Williams inline void asyncPopulatePid( 355*504af5a0SPatrick Williams const std::string& connection, const std::string& path, 35673df0db0SJames Feist const std::string& currentProfile, 35773df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 3588d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 3595b4aa86bSJames Feist { 3605eb468daSGeorge Liu sdbusplus::message::object_path objPath(path); 3615eb468daSGeorge Liu dbus::utility::getManagedObjects( 3625eb468daSGeorge Liu connection, objPath, 36373df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 3645e7e2dc5SEd Tanous const boost::system::error_code& ec, 3655b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 3665b4aa86bSJames Feist if (ec) 3675b4aa86bSJames Feist { 36862598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 369f12894f8SJason M. Bills messages::internalError(asyncResp->res); 3705b4aa86bSJames Feist return; 3715b4aa86bSJames Feist } 3725b4aa86bSJames Feist nlohmann::json& configRoot = 3735b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 3745b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 375bd79bce8SPatrick Williams fans["@odata.type"] = 376bd79bce8SPatrick Williams "#OpenBMCManager.v1_0_0.Manager.FanControllers"; 377253f11b8SEd Tanous fans["@odata.id"] = boost::urls::format( 378253f11b8SEd Tanous "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/FanControllers", 379253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 3805b4aa86bSJames Feist 3815b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 382bd79bce8SPatrick Williams pids["@odata.type"] = 383bd79bce8SPatrick Williams "#OpenBMCManager.v1_0_0.Manager.PidControllers"; 384253f11b8SEd Tanous pids["@odata.id"] = boost::urls::format( 385253f11b8SEd Tanous "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/PidControllers", 386253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 3875b4aa86bSJames Feist 388b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 389fc1cdd14SEd Tanous stepwise["@odata.type"] = 390fc1cdd14SEd Tanous "#OpenBMCManager.v1_0_0.Manager.StepwiseControllers"; 391253f11b8SEd Tanous stepwise["@odata.id"] = boost::urls::format( 392253f11b8SEd Tanous "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/StepwiseControllers", 393253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 394b7a08d04SJames Feist 3955b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 396253f11b8SEd Tanous zones["@odata.id"] = boost::urls::format( 397253f11b8SEd Tanous "/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan/FanZones", 398253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 399fc1cdd14SEd Tanous zones["@odata.type"] = "#OpenBMCManager.v1_0_0.Manager.FanZones"; 400253f11b8SEd Tanous configRoot["@odata.id"] = 401253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}#/Oem/OpenBmc/Fan", 402253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 403fc1cdd14SEd Tanous configRoot["@odata.type"] = "#OpenBMCManager.v1_0_0.Manager.Fan"; 40473df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 40573df0db0SJames Feist 40673df0db0SJames Feist if (!currentProfile.empty()) 40773df0db0SJames Feist { 40873df0db0SJames Feist configRoot["Profile"] = currentProfile; 40973df0db0SJames Feist } 410bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("profile = {} !", currentProfile); 4115b4aa86bSJames Feist 4125b4aa86bSJames Feist for (const auto& pathPair : managedObj) 4135b4aa86bSJames Feist { 4145b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 4155b4aa86bSJames Feist { 4165b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 417b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 418b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 4195b4aa86bSJames Feist { 4205b4aa86bSJames Feist continue; 4215b4aa86bSJames Feist } 42273df0db0SJames Feist 423711ac7a9SEd Tanous std::string name; 424711ac7a9SEd Tanous 425711ac7a9SEd Tanous for (const std::pair<std::string, 426bd79bce8SPatrick Williams dbus::utility::DbusVariantType>& 427bd79bce8SPatrick Williams propPair : intfPair.second) 428711ac7a9SEd Tanous { 429711ac7a9SEd Tanous if (propPair.first == "Name") 430711ac7a9SEd Tanous { 4315b4aa86bSJames Feist const std::string* namePtr = 432711ac7a9SEd Tanous std::get_if<std::string>(&propPair.second); 4335b4aa86bSJames Feist if (namePtr == nullptr) 4345b4aa86bSJames Feist { 43562598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Name Field illegal"); 436b7a08d04SJames Feist messages::internalError(asyncResp->res); 4375b4aa86bSJames Feist return; 4385b4aa86bSJames Feist } 439db697703SWilly Tu name = *namePtr; 4405b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 441711ac7a9SEd Tanous } 442711ac7a9SEd Tanous else if (propPair.first == "Profiles") 44373df0db0SJames Feist { 44473df0db0SJames Feist const std::vector<std::string>* profiles = 44573df0db0SJames Feist std::get_if<std::vector<std::string>>( 446711ac7a9SEd Tanous &propPair.second); 44773df0db0SJames Feist if (profiles == nullptr) 44873df0db0SJames Feist { 44962598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Profiles Field illegal"); 45073df0db0SJames Feist messages::internalError(asyncResp->res); 45173df0db0SJames Feist return; 45273df0db0SJames Feist } 45373df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 45473df0db0SJames Feist currentProfile) == profiles->end()) 45573df0db0SJames Feist { 45662598e31SEd Tanous BMCWEB_LOG_INFO( 457bd79bce8SPatrick Williams "{} not supported in current profile", 458bd79bce8SPatrick Williams name); 45973df0db0SJames Feist continue; 46073df0db0SJames Feist } 46173df0db0SJames Feist } 462711ac7a9SEd Tanous } 463b7a08d04SJames Feist nlohmann::json* config = nullptr; 464c33a90ecSJames Feist const std::string* classPtr = nullptr; 465711ac7a9SEd Tanous 466711ac7a9SEd Tanous for (const std::pair<std::string, 467bd79bce8SPatrick Williams dbus::utility::DbusVariantType>& 468bd79bce8SPatrick Williams propPair : intfPair.second) 469c33a90ecSJames Feist { 470727dc83fSLei YU if (propPair.first == "Class") 471711ac7a9SEd Tanous { 472bd79bce8SPatrick Williams classPtr = 473bd79bce8SPatrick Williams std::get_if<std::string>(&propPair.second); 474711ac7a9SEd Tanous } 475c33a90ecSJames Feist } 476c33a90ecSJames Feist 477253f11b8SEd Tanous boost::urls::url url( 478253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}", 479253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME)); 4805b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 4815b4aa86bSJames Feist { 4825b4aa86bSJames Feist std::string chassis; 483bd79bce8SPatrick Williams if (!dbus::utility::getNthStringFromPath( 484bd79bce8SPatrick Williams pathPair.first.str, 5, chassis)) 4855b4aa86bSJames Feist { 4865b4aa86bSJames Feist chassis = "#IllegalValue"; 4875b4aa86bSJames Feist } 4885b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 489bd79bce8SPatrick Williams zone["Chassis"]["@odata.id"] = boost::urls::format( 490bd79bce8SPatrick Williams "/redfish/v1/Chassis/{}", chassis); 491eddfc437SWilly Tu url.set_fragment( 492eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name) 493eddfc437SWilly Tu .to_string()); 494eddfc437SWilly Tu zone["@odata.id"] = std::move(url); 495fc1cdd14SEd Tanous zone["@odata.type"] = 496fc1cdd14SEd Tanous "#OpenBMCManager.v1_0_0.Manager.FanZone"; 497b7a08d04SJames Feist config = &zone; 4985b4aa86bSJames Feist } 4995b4aa86bSJames Feist 500b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 5015b4aa86bSJames Feist { 502c33a90ecSJames Feist if (classPtr == nullptr) 503c33a90ecSJames Feist { 50462598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Class Field illegal"); 505c33a90ecSJames Feist messages::internalError(asyncResp->res); 506c33a90ecSJames Feist return; 507c33a90ecSJames Feist } 508c33a90ecSJames Feist 509b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 510b7a08d04SJames Feist config = &controller; 511eddfc437SWilly Tu url.set_fragment( 512eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/StepwiseControllers"_json_pointer / 513eddfc437SWilly Tu name) 514eddfc437SWilly Tu .to_string()); 515eddfc437SWilly Tu controller["@odata.id"] = std::move(url); 516b7a08d04SJames Feist controller["@odata.type"] = 517fc1cdd14SEd Tanous "#OpenBMCManager.v1_0_0.Manager.StepwiseController"; 518b7a08d04SJames Feist 519c33a90ecSJames Feist controller["Direction"] = *classPtr; 5205b4aa86bSJames Feist } 5215b4aa86bSJames Feist 5225b4aa86bSJames Feist // pid and fans are off the same configuration 523b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 5245b4aa86bSJames Feist { 5255b4aa86bSJames Feist if (classPtr == nullptr) 5265b4aa86bSJames Feist { 52762598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Class Field illegal"); 528a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 5295b4aa86bSJames Feist return; 5305b4aa86bSJames Feist } 5315b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 532bd79bce8SPatrick Williams nlohmann::json& element = 533bd79bce8SPatrick Williams isFan ? fans[name] : pids[name]; 534b7a08d04SJames Feist config = &element; 5355b4aa86bSJames Feist if (isFan) 5365b4aa86bSJames Feist { 537eddfc437SWilly Tu url.set_fragment( 538eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanControllers"_json_pointer / 539eddfc437SWilly Tu name) 540eddfc437SWilly Tu .to_string()); 541eddfc437SWilly Tu element["@odata.id"] = std::move(url); 542fc1cdd14SEd Tanous element["@odata.type"] = 543fc1cdd14SEd Tanous "#OpenBMCManager.v1_0_0.Manager.FanController"; 5445b4aa86bSJames Feist } 5455b4aa86bSJames Feist else 5465b4aa86bSJames Feist { 547eddfc437SWilly Tu url.set_fragment( 548eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/PidControllers"_json_pointer / 549eddfc437SWilly Tu name) 550eddfc437SWilly Tu .to_string()); 551eddfc437SWilly Tu element["@odata.id"] = std::move(url); 552fc1cdd14SEd Tanous element["@odata.type"] = 553fc1cdd14SEd Tanous "#OpenBMCManager.v1_0_0.Manager.PidController"; 5545b4aa86bSJames Feist } 555b7a08d04SJames Feist } 556b7a08d04SJames Feist else 557b7a08d04SJames Feist { 55862598e31SEd Tanous BMCWEB_LOG_ERROR("Unexpected configuration"); 559b7a08d04SJames Feist messages::internalError(asyncResp->res); 560b7a08d04SJames Feist return; 561b7a08d04SJames Feist } 562b7a08d04SJames Feist 563b7a08d04SJames Feist // used for making maps out of 2 vectors 564b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 565b7a08d04SJames Feist const std::vector<double>* values = nullptr; 566b7a08d04SJames Feist 567b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 568b7a08d04SJames Feist { 569b7a08d04SJames Feist if (propertyPair.first == "Type" || 570b7a08d04SJames Feist propertyPair.first == "Class" || 571b7a08d04SJames Feist propertyPair.first == "Name") 572b7a08d04SJames Feist { 573b7a08d04SJames Feist continue; 574b7a08d04SJames Feist } 575b7a08d04SJames Feist 576b7a08d04SJames Feist // zones 577b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 578b7a08d04SJames Feist { 579b7a08d04SJames Feist const double* ptr = 580abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 581b7a08d04SJames Feist if (ptr == nullptr) 582b7a08d04SJames Feist { 58362598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 58462598e31SEd Tanous propertyPair.first); 585b7a08d04SJames Feist messages::internalError(asyncResp->res); 586b7a08d04SJames Feist return; 587b7a08d04SJames Feist } 588b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 589b7a08d04SJames Feist } 590b7a08d04SJames Feist 591b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 592b7a08d04SJames Feist { 593b7a08d04SJames Feist if (propertyPair.first == "Reading" || 594b7a08d04SJames Feist propertyPair.first == "Output") 595b7a08d04SJames Feist { 596b7a08d04SJames Feist const std::vector<double>* ptr = 597abf2add6SEd Tanous std::get_if<std::vector<double>>( 598b7a08d04SJames Feist &propertyPair.second); 599b7a08d04SJames Feist 600b7a08d04SJames Feist if (ptr == nullptr) 601b7a08d04SJames Feist { 60262598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 60362598e31SEd Tanous propertyPair.first); 604b7a08d04SJames Feist messages::internalError(asyncResp->res); 605b7a08d04SJames Feist return; 606b7a08d04SJames Feist } 607b7a08d04SJames Feist 608b7a08d04SJames Feist if (propertyPair.first == "Reading") 609b7a08d04SJames Feist { 610b7a08d04SJames Feist keys = ptr; 611b7a08d04SJames Feist } 612b7a08d04SJames Feist else 613b7a08d04SJames Feist { 614b7a08d04SJames Feist values = ptr; 615b7a08d04SJames Feist } 616e662eae8SEd Tanous if (keys != nullptr && values != nullptr) 617b7a08d04SJames Feist { 618b7a08d04SJames Feist if (keys->size() != values->size()) 619b7a08d04SJames Feist { 62062598e31SEd Tanous BMCWEB_LOG_ERROR( 62162598e31SEd Tanous "Reading and Output size don't match "); 622b7a08d04SJames Feist messages::internalError(asyncResp->res); 623b7a08d04SJames Feist return; 624b7a08d04SJames Feist } 625b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 626b7a08d04SJames Feist steps = nlohmann::json::array(); 627b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 628b7a08d04SJames Feist { 6291476687dSEd Tanous nlohmann::json::object_t step; 6301476687dSEd Tanous step["Target"] = (*keys)[ii]; 6311476687dSEd Tanous step["Output"] = (*values)[ii]; 632b2ba3072SPatrick Williams steps.emplace_back(std::move(step)); 633b7a08d04SJames Feist } 634b7a08d04SJames Feist } 635b7a08d04SJames Feist } 636b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 637b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 638b7a08d04SJames Feist { 639b7a08d04SJames Feist const double* ptr = 640abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 641b7a08d04SJames Feist if (ptr == nullptr) 642b7a08d04SJames Feist { 64362598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 64462598e31SEd Tanous propertyPair.first); 645b7a08d04SJames Feist messages::internalError(asyncResp->res); 646b7a08d04SJames Feist return; 647b7a08d04SJames Feist } 648b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 649b7a08d04SJames Feist } 650b7a08d04SJames Feist } 651b7a08d04SJames Feist 652b7a08d04SJames Feist // pid and fans are off the same configuration 653b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 654b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 655b7a08d04SJames Feist { 6565b4aa86bSJames Feist if (propertyPair.first == "Zones") 6575b4aa86bSJames Feist { 6585b4aa86bSJames Feist const std::vector<std::string>* inputs = 659abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 6601b6b96c5SEd Tanous &propertyPair.second); 6615b4aa86bSJames Feist 6625b4aa86bSJames Feist if (inputs == nullptr) 6635b4aa86bSJames Feist { 66462598e31SEd Tanous BMCWEB_LOG_ERROR("Zones Pid Field Illegal"); 665a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 6665b4aa86bSJames Feist return; 6675b4aa86bSJames Feist } 668b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 6695b4aa86bSJames Feist data = nlohmann::json::array(); 6705b4aa86bSJames Feist for (std::string itemCopy : *inputs) 6715b4aa86bSJames Feist { 6725b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 6731476687dSEd Tanous nlohmann::json::object_t input; 674bd79bce8SPatrick Williams boost::urls::url managerUrl = 675bd79bce8SPatrick Williams boost::urls::format( 676253f11b8SEd Tanous "/redfish/v1/Managers/{}#{}", 677253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME, 678eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / 679eddfc437SWilly Tu itemCopy) 680eddfc437SWilly Tu .to_string()); 681eddfc437SWilly Tu input["@odata.id"] = std::move(managerUrl); 682b2ba3072SPatrick Williams data.emplace_back(std::move(input)); 6835b4aa86bSJames Feist } 6845b4aa86bSJames Feist } 6855b4aa86bSJames Feist // todo(james): may never happen, but this 6865b4aa86bSJames Feist // assumes configuration data referenced in the 6875b4aa86bSJames Feist // PID config is provided by the same daemon, we 6885b4aa86bSJames Feist // could add another loop to cover all cases, 6895b4aa86bSJames Feist // but I'm okay kicking this can down the road a 6905b4aa86bSJames Feist // bit 6915b4aa86bSJames Feist 6925b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 6935b4aa86bSJames Feist propertyPair.first == "Outputs") 6945b4aa86bSJames Feist { 695b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 6965b4aa86bSJames Feist const std::vector<std::string>* inputs = 697abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 6981b6b96c5SEd Tanous &propertyPair.second); 6995b4aa86bSJames Feist 7005b4aa86bSJames Feist if (inputs == nullptr) 7015b4aa86bSJames Feist { 70262598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 70362598e31SEd Tanous propertyPair.first); 704f12894f8SJason M. Bills messages::internalError(asyncResp->res); 7055b4aa86bSJames Feist return; 7065b4aa86bSJames Feist } 7075b4aa86bSJames Feist data = *inputs; 708b943aaefSJames Feist } 709b943aaefSJames Feist else if (propertyPair.first == "SetPointOffset") 710b943aaefSJames Feist { 711b943aaefSJames Feist const std::string* ptr = 712bd79bce8SPatrick Williams std::get_if<std::string>( 713bd79bce8SPatrick Williams &propertyPair.second); 714b943aaefSJames Feist 715b943aaefSJames Feist if (ptr == nullptr) 716b943aaefSJames Feist { 71762598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 71862598e31SEd Tanous propertyPair.first); 719b943aaefSJames Feist messages::internalError(asyncResp->res); 720b943aaefSJames Feist return; 721b943aaefSJames Feist } 722b943aaefSJames Feist // translate from dbus to redfish 723b943aaefSJames Feist if (*ptr == "WarningHigh") 724b943aaefSJames Feist { 725b943aaefSJames Feist (*config)["SetPointOffset"] = 726b943aaefSJames Feist "UpperThresholdNonCritical"; 727b943aaefSJames Feist } 728b943aaefSJames Feist else if (*ptr == "WarningLow") 729b943aaefSJames Feist { 730b943aaefSJames Feist (*config)["SetPointOffset"] = 731b943aaefSJames Feist "LowerThresholdNonCritical"; 732b943aaefSJames Feist } 733b943aaefSJames Feist else if (*ptr == "CriticalHigh") 734b943aaefSJames Feist { 735b943aaefSJames Feist (*config)["SetPointOffset"] = 736b943aaefSJames Feist "UpperThresholdCritical"; 737b943aaefSJames Feist } 738b943aaefSJames Feist else if (*ptr == "CriticalLow") 739b943aaefSJames Feist { 740b943aaefSJames Feist (*config)["SetPointOffset"] = 741b943aaefSJames Feist "LowerThresholdCritical"; 742b943aaefSJames Feist } 743b943aaefSJames Feist else 744b943aaefSJames Feist { 74562598e31SEd Tanous BMCWEB_LOG_ERROR("Value Illegal {}", *ptr); 746b943aaefSJames Feist messages::internalError(asyncResp->res); 747b943aaefSJames Feist return; 748b943aaefSJames Feist } 749b943aaefSJames Feist } 750b943aaefSJames Feist // doubles 751bd79bce8SPatrick Williams else if (propertyPair.first == 752bd79bce8SPatrick Williams "FFGainCoefficient" || 7535b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 7545b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 7555b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 7565b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 757bd79bce8SPatrick Williams propertyPair.first == 758bd79bce8SPatrick Williams "PositiveHysteresis" || 759bd79bce8SPatrick Williams propertyPair.first == 760bd79bce8SPatrick Williams "NegativeHysteresis" || 7615b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 7625b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 7635b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 7647625cb81SJames Feist propertyPair.first == "SetPoint" || 7655b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 7665b4aa86bSJames Feist propertyPair.first == "SlewPos") 7675b4aa86bSJames Feist { 7685b4aa86bSJames Feist const double* ptr = 769abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 7705b4aa86bSJames Feist if (ptr == nullptr) 7715b4aa86bSJames Feist { 77262598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 77362598e31SEd Tanous propertyPair.first); 774f12894f8SJason M. Bills messages::internalError(asyncResp->res); 7755b4aa86bSJames Feist return; 7765b4aa86bSJames Feist } 777b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 7785b4aa86bSJames Feist } 7795b4aa86bSJames Feist } 7805b4aa86bSJames Feist } 7815b4aa86bSJames Feist } 7825b4aa86bSJames Feist } 7835eb468daSGeorge Liu }); 7845b4aa86bSJames Feist } 785ca537928SJennifer Lee 78683ff9ab6SJames Feist enum class CreatePIDRet 78783ff9ab6SJames Feist { 78883ff9ab6SJames Feist fail, 78983ff9ab6SJames Feist del, 79083ff9ab6SJames Feist patch 79183ff9ab6SJames Feist }; 79283ff9ab6SJames Feist 793*504af5a0SPatrick Williams inline bool getZonesFromJsonReq( 794*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& response, 7959e9b6049SEd Tanous std::vector<nlohmann::json::object_t>& config, 7965f2caaefSJames Feist std::vector<std::string>& zones) 7975f2caaefSJames Feist { 798b6baeaa4SJames Feist if (config.empty()) 799b6baeaa4SJames Feist { 80062598e31SEd Tanous BMCWEB_LOG_ERROR("Empty Zones"); 801f818b04dSEd Tanous messages::propertyValueFormatError(response->res, config, "Zones"); 802b6baeaa4SJames Feist return false; 803b6baeaa4SJames Feist } 8045f2caaefSJames Feist for (auto& odata : config) 8055f2caaefSJames Feist { 8065f2caaefSJames Feist std::string path; 8079e9b6049SEd Tanous if (!redfish::json_util::readJsonObject(odata, response->res, 8089e9b6049SEd Tanous "@odata.id", path)) 8095f2caaefSJames Feist { 8105f2caaefSJames Feist return false; 8115f2caaefSJames Feist } 8125f2caaefSJames Feist std::string input; 81361adbda3SJames Feist 81461adbda3SJames Feist // 8 below comes from 81561adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 81661adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 81761adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 8185f2caaefSJames Feist { 81962598e31SEd Tanous BMCWEB_LOG_ERROR("Got invalid path {}", path); 82062598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type Zones"); 821f818b04dSEd Tanous messages::propertyValueFormatError(response->res, odata, "Zones"); 8225f2caaefSJames Feist return false; 8235f2caaefSJames Feist } 824a170f275SEd Tanous std::replace(input.begin(), input.end(), '_', ' '); 8255f2caaefSJames Feist zones.emplace_back(std::move(input)); 8265f2caaefSJames Feist } 8275f2caaefSJames Feist return true; 8285f2caaefSJames Feist } 8295f2caaefSJames Feist 830*504af5a0SPatrick Williams inline const dbus::utility::ManagedObjectType::value_type* findChassis( 831*504af5a0SPatrick Williams const dbus::utility::ManagedObjectType& managedObj, std::string_view value, 832*504af5a0SPatrick Williams std::string& chassis) 833b6baeaa4SJames Feist { 83462598e31SEd Tanous BMCWEB_LOG_DEBUG("Find Chassis: {}", value); 835b6baeaa4SJames Feist 8369e9b6049SEd Tanous std::string escaped(value); 8376ce82fabSYaswanth Reddy M std::replace(escaped.begin(), escaped.end(), ' ', '_'); 838b6baeaa4SJames Feist escaped = "/" + escaped; 8393544d2a7SEd Tanous auto it = std::ranges::find_if(managedObj, [&escaped](const auto& obj) { 84018f8f608SEd Tanous if (obj.first.str.ends_with(escaped)) 841b6baeaa4SJames Feist { 84262598e31SEd Tanous BMCWEB_LOG_DEBUG("Matched {}", obj.first.str); 843b6baeaa4SJames Feist return true; 844b6baeaa4SJames Feist } 845b6baeaa4SJames Feist return false; 846b6baeaa4SJames Feist }); 847b6baeaa4SJames Feist 848b6baeaa4SJames Feist if (it == managedObj.end()) 849b6baeaa4SJames Feist { 85073df0db0SJames Feist return nullptr; 851b6baeaa4SJames Feist } 852b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 853b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 85473df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 85573df0db0SJames Feist { 85673df0db0SJames Feist return &(*it); 85773df0db0SJames Feist } 85873df0db0SJames Feist 85973df0db0SJames Feist return nullptr; 860b6baeaa4SJames Feist } 861b6baeaa4SJames Feist 86223a21a1cSEd Tanous inline CreatePIDRet createPidInterface( 8638d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, 8649e9b6049SEd Tanous std::string_view name, nlohmann::json& jsonValue, const std::string& path, 86583ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 866b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap& output, std::string& chassis, 867b9d36b47SEd Tanous const std::string& profile) 86883ff9ab6SJames Feist { 8695f2caaefSJames Feist // common deleter 8709e9b6049SEd Tanous if (jsonValue == nullptr) 8715f2caaefSJames Feist { 8725f2caaefSJames Feist std::string iface; 8735f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 8745f2caaefSJames Feist { 8755f2caaefSJames Feist iface = pidConfigurationIface; 8765f2caaefSJames Feist } 8775f2caaefSJames Feist else if (type == "FanZones") 8785f2caaefSJames Feist { 8795f2caaefSJames Feist iface = pidZoneConfigurationIface; 8805f2caaefSJames Feist } 8815f2caaefSJames Feist else if (type == "StepwiseControllers") 8825f2caaefSJames Feist { 8835f2caaefSJames Feist iface = stepwiseConfigurationIface; 8845f2caaefSJames Feist } 8855f2caaefSJames Feist else 8865f2caaefSJames Feist { 88762598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type {}", type); 8885f2caaefSJames Feist messages::propertyUnknown(response->res, type); 8895f2caaefSJames Feist return CreatePIDRet::fail; 8905f2caaefSJames Feist } 8916ee7f774SJames Feist 89262598e31SEd Tanous BMCWEB_LOG_DEBUG("del {} {}", path, iface); 8935f2caaefSJames Feist // delete interface 8945f2caaefSJames Feist crow::connections::systemBus->async_method_call( 8955e7e2dc5SEd Tanous [response, path](const boost::system::error_code& ec) { 8965f2caaefSJames Feist if (ec) 8975f2caaefSJames Feist { 89862598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching {}: {}", path, ec); 8995f2caaefSJames Feist messages::internalError(response->res); 900b6baeaa4SJames Feist return; 9015f2caaefSJames Feist } 902b6baeaa4SJames Feist messages::success(response->res); 9035f2caaefSJames Feist }, 9045f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 9055f2caaefSJames Feist return CreatePIDRet::del; 9065f2caaefSJames Feist } 9075f2caaefSJames Feist 908711ac7a9SEd Tanous const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr; 909b6baeaa4SJames Feist if (!createNewObject) 910b6baeaa4SJames Feist { 911b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 912b6baeaa4SJames Feist // d-bus 9139e9b6049SEd Tanous managedItem = findChassis(managedObj, name, chassis); 91473df0db0SJames Feist if (managedItem == nullptr) 915b6baeaa4SJames Feist { 91662598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 917ef4c65b7SEd Tanous messages::invalidObject( 918ef4c65b7SEd Tanous response->res, 919ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 920b6baeaa4SJames Feist return CreatePIDRet::fail; 921b6baeaa4SJames Feist } 922b6baeaa4SJames Feist } 923b6baeaa4SJames Feist 92426f6976fSEd Tanous if (!profile.empty() && 92573df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 92673df0db0SJames Feist type == "StepwiseControllers")) 92773df0db0SJames Feist { 92873df0db0SJames Feist if (managedItem == nullptr) 92973df0db0SJames Feist { 930b9d36b47SEd Tanous output.emplace_back("Profiles", std::vector<std::string>{profile}); 93173df0db0SJames Feist } 93273df0db0SJames Feist else 93373df0db0SJames Feist { 93473df0db0SJames Feist std::string interface; 93573df0db0SJames Feist if (type == "StepwiseControllers") 93673df0db0SJames Feist { 93773df0db0SJames Feist interface = stepwiseConfigurationIface; 93873df0db0SJames Feist } 93973df0db0SJames Feist else 94073df0db0SJames Feist { 94173df0db0SJames Feist interface = pidConfigurationIface; 94273df0db0SJames Feist } 943711ac7a9SEd Tanous bool ifaceFound = false; 944711ac7a9SEd Tanous for (const auto& iface : managedItem->second) 945711ac7a9SEd Tanous { 946711ac7a9SEd Tanous if (iface.first == interface) 947711ac7a9SEd Tanous { 948711ac7a9SEd Tanous ifaceFound = true; 949711ac7a9SEd Tanous for (const auto& prop : iface.second) 950711ac7a9SEd Tanous { 951711ac7a9SEd Tanous if (prop.first == "Profiles") 952711ac7a9SEd Tanous { 953711ac7a9SEd Tanous const std::vector<std::string>* curProfiles = 954711ac7a9SEd Tanous std::get_if<std::vector<std::string>>( 955711ac7a9SEd Tanous &(prop.second)); 956711ac7a9SEd Tanous if (curProfiles == nullptr) 957711ac7a9SEd Tanous { 95862598e31SEd Tanous BMCWEB_LOG_ERROR( 95962598e31SEd Tanous "Illegal profiles in managed object"); 960711ac7a9SEd Tanous messages::internalError(response->res); 961711ac7a9SEd Tanous return CreatePIDRet::fail; 962711ac7a9SEd Tanous } 963711ac7a9SEd Tanous if (std::find(curProfiles->begin(), 964bd79bce8SPatrick Williams curProfiles->end(), profile) == 965bd79bce8SPatrick Williams curProfiles->end()) 966711ac7a9SEd Tanous { 967711ac7a9SEd Tanous std::vector<std::string> newProfiles = 968711ac7a9SEd Tanous *curProfiles; 969711ac7a9SEd Tanous newProfiles.push_back(profile); 970b9d36b47SEd Tanous output.emplace_back("Profiles", newProfiles); 971711ac7a9SEd Tanous } 972711ac7a9SEd Tanous } 973711ac7a9SEd Tanous } 974711ac7a9SEd Tanous } 975711ac7a9SEd Tanous } 976711ac7a9SEd Tanous 977711ac7a9SEd Tanous if (!ifaceFound) 97873df0db0SJames Feist { 97962598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find interface in managed object"); 98073df0db0SJames Feist messages::internalError(response->res); 98173df0db0SJames Feist return CreatePIDRet::fail; 98273df0db0SJames Feist } 98373df0db0SJames Feist } 98473df0db0SJames Feist } 98573df0db0SJames Feist 98683ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 98783ff9ab6SJames Feist { 98883ff9ab6SJames Feist if (createNewObject) 98983ff9ab6SJames Feist { 990b9d36b47SEd Tanous output.emplace_back("Class", 991b9d36b47SEd Tanous type == "PidControllers" ? "temp" : "fan"); 992b9d36b47SEd Tanous output.emplace_back("Type", "Pid"); 99383ff9ab6SJames Feist } 9945f2caaefSJames Feist 9959e9b6049SEd Tanous std::optional<std::vector<nlohmann::json::object_t>> zones; 9965f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 9975f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 9985f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 999b943aaefSJames Feist std::optional<std::string> setpointOffset; 1000afc474aeSMyung Bae if (!redfish::json_util::readJson( // 1001afc474aeSMyung Bae jsonValue, response->res, // 1002afc474aeSMyung Bae "FFGainCoefficient", doubles["FFGainCoefficient"], // 1003afc474aeSMyung Bae "FFOffCoefficient", doubles["FFOffCoefficient"], // 1004afc474aeSMyung Bae "ICoefficient", doubles["ICoefficient"], // 1005afc474aeSMyung Bae "ILimitMax", doubles["ILimitMax"], // 1006afc474aeSMyung Bae "ILimitMin", doubles["ILimitMin"], // 1007afc474aeSMyung Bae "Inputs", inputs, // 1008afc474aeSMyung Bae "NegativeHysteresis", doubles["NegativeHysteresis"], // 1009afc474aeSMyung Bae "OutLimitMax", doubles["OutLimitMax"], // 1010afc474aeSMyung Bae "OutLimitMin", doubles["OutLimitMin"], // 1011afc474aeSMyung Bae "Outputs", outputs, // 1012afc474aeSMyung Bae "PCoefficient", doubles["PCoefficient"], // 1013afc474aeSMyung Bae "PositiveHysteresis", doubles["PositiveHysteresis"], // 1014afc474aeSMyung Bae "SetPoint", doubles["SetPoint"], // 1015afc474aeSMyung Bae "SetPointOffset", setpointOffset, // 1016afc474aeSMyung Bae "SlewNeg", doubles["SlewNeg"], // 1017afc474aeSMyung Bae "SlewPos", doubles["SlewPos"], // 1018afc474aeSMyung Bae "Zones", zones // 1019afc474aeSMyung Bae )) 102083ff9ab6SJames Feist { 10215f2caaefSJames Feist return CreatePIDRet::fail; 102283ff9ab6SJames Feist } 1023afc474aeSMyung Bae 10245f2caaefSJames Feist if (zones) 10255f2caaefSJames Feist { 10265f2caaefSJames Feist std::vector<std::string> zonesStr; 10275f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 10285f2caaefSJames Feist { 102962598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Zones"); 10305f2caaefSJames Feist return CreatePIDRet::fail; 10315f2caaefSJames Feist } 1032b6baeaa4SJames Feist if (chassis.empty() && 1033e662eae8SEd Tanous findChassis(managedObj, zonesStr[0], chassis) == nullptr) 1034b6baeaa4SJames Feist { 103562598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 1036ace85d60SEd Tanous messages::invalidObject( 1037ef4c65b7SEd Tanous response->res, 1038ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 1039b6baeaa4SJames Feist return CreatePIDRet::fail; 1040b6baeaa4SJames Feist } 1041b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStr)); 10425f2caaefSJames Feist } 1043afb9ee06SEd Tanous 1044afb9ee06SEd Tanous if (inputs) 10455f2caaefSJames Feist { 1046afb9ee06SEd Tanous for (std::string& value : *inputs) 104783ff9ab6SJames Feist { 1048a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 104983ff9ab6SJames Feist } 1050afb9ee06SEd Tanous output.emplace_back("Inputs", *inputs); 1051afb9ee06SEd Tanous } 1052afb9ee06SEd Tanous 1053afb9ee06SEd Tanous if (outputs) 10545f2caaefSJames Feist { 1055afb9ee06SEd Tanous for (std::string& value : *outputs) 10565f2caaefSJames Feist { 1057afb9ee06SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 10585f2caaefSJames Feist } 1059afb9ee06SEd Tanous output.emplace_back("Outputs", *outputs); 106083ff9ab6SJames Feist } 106183ff9ab6SJames Feist 1062b943aaefSJames Feist if (setpointOffset) 1063b943aaefSJames Feist { 1064b943aaefSJames Feist // translate between redfish and dbus names 1065b943aaefSJames Feist if (*setpointOffset == "UpperThresholdNonCritical") 1066b943aaefSJames Feist { 1067b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningLow"); 1068b943aaefSJames Feist } 1069b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdNonCritical") 1070b943aaefSJames Feist { 1071b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningHigh"); 1072b943aaefSJames Feist } 1073b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdCritical") 1074b943aaefSJames Feist { 1075b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalLow"); 1076b943aaefSJames Feist } 1077b943aaefSJames Feist else if (*setpointOffset == "UpperThresholdCritical") 1078b943aaefSJames Feist { 1079b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalHigh"); 1080b943aaefSJames Feist } 1081b943aaefSJames Feist else 1082b943aaefSJames Feist { 108362598e31SEd Tanous BMCWEB_LOG_ERROR("Invalid setpointoffset {}", *setpointOffset); 10849e9b6049SEd Tanous messages::propertyValueNotInList(response->res, name, 1085ace85d60SEd Tanous "SetPointOffset"); 1086b943aaefSJames Feist return CreatePIDRet::fail; 1087b943aaefSJames Feist } 1088b943aaefSJames Feist } 1089b943aaefSJames Feist 109083ff9ab6SJames Feist // doubles 10915f2caaefSJames Feist for (const auto& pairs : doubles) 109283ff9ab6SJames Feist { 10935f2caaefSJames Feist if (!pairs.second) 109483ff9ab6SJames Feist { 10955f2caaefSJames Feist continue; 109683ff9ab6SJames Feist } 109762598e31SEd Tanous BMCWEB_LOG_DEBUG("{} = {}", pairs.first, *pairs.second); 1098b9d36b47SEd Tanous output.emplace_back(pairs.first, *pairs.second); 10995f2caaefSJames Feist } 110083ff9ab6SJames Feist } 110183ff9ab6SJames Feist 110283ff9ab6SJames Feist else if (type == "FanZones") 110383ff9ab6SJames Feist { 1104b9d36b47SEd Tanous output.emplace_back("Type", "Pid.Zone"); 110583ff9ab6SJames Feist 11069e9b6049SEd Tanous std::optional<std::string> chassisId; 11075f2caaefSJames Feist std::optional<double> failSafePercent; 1108d3ec07f8SJames Feist std::optional<double> minThermalOutput; 1109afc474aeSMyung Bae if (!redfish::json_util::readJson( // 1110afc474aeSMyung Bae jsonValue, response->res, // 1111afc474aeSMyung Bae "Chassis/@odata.id", chassisId, // 1112afc474aeSMyung Bae "FailSafePercent", failSafePercent, // 1113afc474aeSMyung Bae "MinThermalOutput", minThermalOutput)) 111483ff9ab6SJames Feist { 111583ff9ab6SJames Feist return CreatePIDRet::fail; 111683ff9ab6SJames Feist } 11175f2caaefSJames Feist 11189e9b6049SEd Tanous if (chassisId) 111983ff9ab6SJames Feist { 1120717794d5SAppaRao Puli // /redfish/v1/chassis/chassis_name/ 11219e9b6049SEd Tanous if (!dbus::utility::getNthStringFromPath(*chassisId, 3, chassis)) 112283ff9ab6SJames Feist { 11239e9b6049SEd Tanous BMCWEB_LOG_ERROR("Got invalid path {}", *chassisId); 1124ace85d60SEd Tanous messages::invalidObject( 1125ef4c65b7SEd Tanous response->res, 11269e9b6049SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", *chassisId)); 112783ff9ab6SJames Feist return CreatePIDRet::fail; 112883ff9ab6SJames Feist } 112983ff9ab6SJames Feist } 1130d3ec07f8SJames Feist if (minThermalOutput) 113183ff9ab6SJames Feist { 1132b9d36b47SEd Tanous output.emplace_back("MinThermalOutput", *minThermalOutput); 11335f2caaefSJames Feist } 11345f2caaefSJames Feist if (failSafePercent) 113583ff9ab6SJames Feist { 1136b9d36b47SEd Tanous output.emplace_back("FailSafePercent", *failSafePercent); 11375f2caaefSJames Feist } 11385f2caaefSJames Feist } 11395f2caaefSJames Feist else if (type == "StepwiseControllers") 11405f2caaefSJames Feist { 1141b9d36b47SEd Tanous output.emplace_back("Type", "Stepwise"); 11425f2caaefSJames Feist 11439e9b6049SEd Tanous std::optional<std::vector<nlohmann::json::object_t>> zones; 11449e9b6049SEd Tanous std::optional<std::vector<nlohmann::json::object_t>> steps; 11455f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 11465f2caaefSJames Feist std::optional<double> positiveHysteresis; 11475f2caaefSJames Feist std::optional<double> negativeHysteresis; 1148c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 1149afc474aeSMyung Bae if (!redfish::json_util::readJson( // 1150afc474aeSMyung Bae jsonValue, response->res, // 1151afc474aeSMyung Bae "Direction", direction, // 1152afc474aeSMyung Bae "Inputs", inputs, // 1153afc474aeSMyung Bae "NegativeHysteresis", negativeHysteresis, // 1154afc474aeSMyung Bae "PositiveHysteresis", positiveHysteresis, // 1155afc474aeSMyung Bae "Steps", steps, // 1156afc474aeSMyung Bae "Zones", zones // 1157afc474aeSMyung Bae )) 11585f2caaefSJames Feist { 115983ff9ab6SJames Feist return CreatePIDRet::fail; 116083ff9ab6SJames Feist } 11615f2caaefSJames Feist 11625f2caaefSJames Feist if (zones) 116383ff9ab6SJames Feist { 1164b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 1165b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 11665f2caaefSJames Feist { 116762598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Zones"); 116883ff9ab6SJames Feist return CreatePIDRet::fail; 116983ff9ab6SJames Feist } 1170b6baeaa4SJames Feist if (chassis.empty() && 1171e662eae8SEd Tanous findChassis(managedObj, zonesStrs[0], chassis) == nullptr) 1172b6baeaa4SJames Feist { 117362598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 1174ace85d60SEd Tanous messages::invalidObject( 1175ef4c65b7SEd Tanous response->res, 1176ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 1177b6baeaa4SJames Feist return CreatePIDRet::fail; 1178b6baeaa4SJames Feist } 1179b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStrs)); 11805f2caaefSJames Feist } 11815f2caaefSJames Feist if (steps) 11825f2caaefSJames Feist { 11835f2caaefSJames Feist std::vector<double> readings; 11845f2caaefSJames Feist std::vector<double> outputs; 11855f2caaefSJames Feist for (auto& step : *steps) 11865f2caaefSJames Feist { 1187543f4400SEd Tanous double target = 0.0; 1188543f4400SEd Tanous double out = 0.0; 11895f2caaefSJames Feist 1190afc474aeSMyung Bae if (!redfish::json_util::readJsonObject( // 1191afc474aeSMyung Bae step, response->res, // 1192afc474aeSMyung Bae "Output", out, // 1193afc474aeSMyung Bae "Target", target // 1194afc474aeSMyung Bae )) 11955f2caaefSJames Feist { 11965f2caaefSJames Feist return CreatePIDRet::fail; 11975f2caaefSJames Feist } 11985f2caaefSJames Feist readings.emplace_back(target); 119923a21a1cSEd Tanous outputs.emplace_back(out); 12005f2caaefSJames Feist } 1201b9d36b47SEd Tanous output.emplace_back("Reading", std::move(readings)); 1202b9d36b47SEd Tanous output.emplace_back("Output", std::move(outputs)); 12035f2caaefSJames Feist } 12045f2caaefSJames Feist if (inputs) 12055f2caaefSJames Feist { 12065f2caaefSJames Feist for (std::string& value : *inputs) 12075f2caaefSJames Feist { 1208a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 12095f2caaefSJames Feist } 1210b9d36b47SEd Tanous output.emplace_back("Inputs", std::move(*inputs)); 12115f2caaefSJames Feist } 12125f2caaefSJames Feist if (negativeHysteresis) 12135f2caaefSJames Feist { 1214b9d36b47SEd Tanous output.emplace_back("NegativeHysteresis", *negativeHysteresis); 12155f2caaefSJames Feist } 12165f2caaefSJames Feist if (positiveHysteresis) 12175f2caaefSJames Feist { 1218b9d36b47SEd Tanous output.emplace_back("PositiveHysteresis", *positiveHysteresis); 121983ff9ab6SJames Feist } 1220c33a90ecSJames Feist if (direction) 1221c33a90ecSJames Feist { 1222c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 1223c33a90ecSJames Feist "Ceiling", "Floor"}; 12243544d2a7SEd Tanous if (std::ranges::find(allowedDirections, *direction) == 12253544d2a7SEd Tanous allowedDirections.end()) 1226c33a90ecSJames Feist { 1227c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 1228c33a90ecSJames Feist *direction); 1229c33a90ecSJames Feist return CreatePIDRet::fail; 1230c33a90ecSJames Feist } 1231b9d36b47SEd Tanous output.emplace_back("Class", *direction); 1232c33a90ecSJames Feist } 123383ff9ab6SJames Feist } 123483ff9ab6SJames Feist else 123583ff9ab6SJames Feist { 123662598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type {}", type); 123735a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 123883ff9ab6SJames Feist return CreatePIDRet::fail; 123983ff9ab6SJames Feist } 124083ff9ab6SJames Feist return CreatePIDRet::patch; 124183ff9ab6SJames Feist } 124273df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 124373df0db0SJames Feist { 12446936afe4SEd Tanous struct CompletionValues 12456936afe4SEd Tanous { 12466936afe4SEd Tanous std::vector<std::string> supportedProfiles; 12476936afe4SEd Tanous std::string currentProfile; 12486936afe4SEd Tanous dbus::utility::MapperGetSubTreeResponse subtree; 12496936afe4SEd Tanous }; 125083ff9ab6SJames Feist 12514e23a444SEd Tanous explicit GetPIDValues( 12524e23a444SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : 125323a21a1cSEd Tanous asyncResp(asyncRespIn) 125473df0db0SJames Feist 12551214b7e7SGunnar Mills {} 12569c310685SBorawski.Lukasz 125773df0db0SJames Feist void run() 12585b4aa86bSJames Feist { 125973df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 126073df0db0SJames Feist 126173df0db0SJames Feist // get all configurations 1262e99073f5SGeorge Liu constexpr std::array<std::string_view, 4> interfaces = { 1263e99073f5SGeorge Liu pidConfigurationIface, pidZoneConfigurationIface, 1264e99073f5SGeorge Liu objectManagerIface, stepwiseConfigurationIface}; 1265e99073f5SGeorge Liu dbus::utility::getSubTree( 1266e99073f5SGeorge Liu "/", 0, interfaces, 1267b9d36b47SEd Tanous [self]( 1268e99073f5SGeorge Liu const boost::system::error_code& ec, 1269b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 12705b4aa86bSJames Feist if (ec) 12715b4aa86bSJames Feist { 127262598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 127373df0db0SJames Feist messages::internalError(self->asyncResp->res); 127473df0db0SJames Feist return; 127573df0db0SJames Feist } 12766936afe4SEd Tanous self->complete.subtree = subtreeLocal; 1277e99073f5SGeorge Liu }); 127873df0db0SJames Feist 127973df0db0SJames Feist // at the same time get the selected profile 1280e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1281e99073f5SGeorge Liu thermalModeIface}; 1282e99073f5SGeorge Liu dbus::utility::getSubTree( 1283e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1284b9d36b47SEd Tanous [self]( 1285e99073f5SGeorge Liu const boost::system::error_code& ec, 1286b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 128723a21a1cSEd Tanous if (ec || subtreeLocal.empty()) 128873df0db0SJames Feist { 128973df0db0SJames Feist return; 129073df0db0SJames Feist } 129123a21a1cSEd Tanous if (subtreeLocal[0].second.size() != 1) 129273df0db0SJames Feist { 129373df0db0SJames Feist // invalid mapper response, should never happen 129462598e31SEd Tanous BMCWEB_LOG_ERROR("GetPIDValues: Mapper Error"); 129573df0db0SJames Feist messages::internalError(self->asyncResp->res); 12965b4aa86bSJames Feist return; 12975b4aa86bSJames Feist } 12985b4aa86bSJames Feist 129923a21a1cSEd Tanous const std::string& path = subtreeLocal[0].first; 130023a21a1cSEd Tanous const std::string& owner = subtreeLocal[0].second[0].first; 1301fac6e53bSKrzysztof Grobelny 1302deae6a78SEd Tanous dbus::utility::getAllProperties( 1303bd79bce8SPatrick Williams *crow::connections::systemBus, owner, path, 1304bd79bce8SPatrick Williams thermalModeIface, 1305168e20c1SEd Tanous [path, owner, 13065e7e2dc5SEd Tanous self](const boost::system::error_code& ec2, 1307b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 130823a21a1cSEd Tanous if (ec2) 130973df0db0SJames Feist { 131062598e31SEd Tanous BMCWEB_LOG_ERROR( 1311bd79bce8SPatrick Williams "GetPIDValues: Can't get thermalModeIface {}", 1312bd79bce8SPatrick Williams path); 131373df0db0SJames Feist messages::internalError(self->asyncResp->res); 131473df0db0SJames Feist return; 131573df0db0SJames Feist } 1316fac6e53bSKrzysztof Grobelny 1317271584abSEd Tanous const std::string* current = nullptr; 1318271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1319fac6e53bSKrzysztof Grobelny 1320fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1321bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), resp, "Current", 1322bd79bce8SPatrick Williams current, "Supported", supported); 1323fac6e53bSKrzysztof Grobelny 1324fac6e53bSKrzysztof Grobelny if (!success) 132573df0db0SJames Feist { 1326002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 132773df0db0SJames Feist return; 132873df0db0SJames Feist } 1329fac6e53bSKrzysztof Grobelny 133073df0db0SJames Feist if (current == nullptr || supported == nullptr) 133173df0db0SJames Feist { 133262598e31SEd Tanous BMCWEB_LOG_ERROR( 1333bd79bce8SPatrick Williams "GetPIDValues: thermal mode iface invalid {}", 1334bd79bce8SPatrick Williams path); 133573df0db0SJames Feist messages::internalError(self->asyncResp->res); 133673df0db0SJames Feist return; 133773df0db0SJames Feist } 13386936afe4SEd Tanous self->complete.currentProfile = *current; 13396936afe4SEd Tanous self->complete.supportedProfiles = *supported; 1340fac6e53bSKrzysztof Grobelny }); 1341e99073f5SGeorge Liu }); 134273df0db0SJames Feist } 134373df0db0SJames Feist 1344*504af5a0SPatrick Williams static void processingComplete( 1345*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 13466936afe4SEd Tanous const CompletionValues& completion) 134773df0db0SJames Feist { 134873df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 134973df0db0SJames Feist { 135073df0db0SJames Feist return; 135173df0db0SJames Feist } 13525b4aa86bSJames Feist // create map of <connection, path to objMgr>> 13536936afe4SEd Tanous boost::container::flat_map< 13546936afe4SEd Tanous std::string, std::string, std::less<>, 13556936afe4SEd Tanous std::vector<std::pair<std::string, std::string>>> 13566936afe4SEd Tanous objectMgrPaths; 13576936afe4SEd Tanous boost::container::flat_set<std::string, std::less<>, 13586936afe4SEd Tanous std::vector<std::string>> 13596936afe4SEd Tanous calledConnections; 13606936afe4SEd Tanous for (const auto& pathGroup : completion.subtree) 13615b4aa86bSJames Feist { 13625b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 13635b4aa86bSJames Feist { 13646bce33bcSJames Feist auto findConnection = 13656bce33bcSJames Feist calledConnections.find(connectionGroup.first); 13666bce33bcSJames Feist if (findConnection != calledConnections.end()) 13676bce33bcSJames Feist { 13686bce33bcSJames Feist break; 13696bce33bcSJames Feist } 137073df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 13715b4aa86bSJames Feist { 13725b4aa86bSJames Feist if (interface == objectManagerIface) 13735b4aa86bSJames Feist { 137473df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 13755b4aa86bSJames Feist } 13765b4aa86bSJames Feist // this list is alphabetical, so we 13775b4aa86bSJames Feist // should have found the objMgr by now 13785b4aa86bSJames Feist if (interface == pidConfigurationIface || 1379b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1380b7a08d04SJames Feist interface == stepwiseConfigurationIface) 13815b4aa86bSJames Feist { 13825b4aa86bSJames Feist auto findObjMgr = 13835b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 13845b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 13855b4aa86bSJames Feist { 138662598e31SEd Tanous BMCWEB_LOG_DEBUG("{}Has no Object Manager", 138762598e31SEd Tanous connectionGroup.first); 13885b4aa86bSJames Feist continue; 13895b4aa86bSJames Feist } 13906bce33bcSJames Feist 13916bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 13926bce33bcSJames Feist 139373df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 13946936afe4SEd Tanous completion.currentProfile, 13956936afe4SEd Tanous completion.supportedProfiles, 139673df0db0SJames Feist asyncResp); 13975b4aa86bSJames Feist break; 13985b4aa86bSJames Feist } 13995b4aa86bSJames Feist } 14005b4aa86bSJames Feist } 14015b4aa86bSJames Feist } 140273df0db0SJames Feist } 140373df0db0SJames Feist 14046936afe4SEd Tanous ~GetPIDValues() 14056936afe4SEd Tanous { 14066936afe4SEd Tanous boost::asio::post(crow::connections::systemBus->get_io_context(), 14076936afe4SEd Tanous std::bind_front(&processingComplete, asyncResp, 14086936afe4SEd Tanous std::move(complete))); 14096936afe4SEd Tanous } 14106936afe4SEd Tanous 1411ecd6a3a2SEd Tanous GetPIDValues(const GetPIDValues&) = delete; 1412ecd6a3a2SEd Tanous GetPIDValues(GetPIDValues&&) = delete; 1413ecd6a3a2SEd Tanous GetPIDValues& operator=(const GetPIDValues&) = delete; 1414ecd6a3a2SEd Tanous GetPIDValues& operator=(GetPIDValues&&) = delete; 1415ecd6a3a2SEd Tanous 14168d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 14176936afe4SEd Tanous CompletionValues complete; 141873df0db0SJames Feist }; 141973df0db0SJames Feist 142073df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 142173df0db0SJames Feist { 14229e9b6049SEd Tanous SetPIDValues( 14239e9b6049SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, 14249e9b6049SEd Tanous std::vector< 14259e9b6049SEd Tanous std::pair<std::string, std::optional<nlohmann::json::object_t>>>&& 14269e9b6049SEd Tanous configurationsIn, 14279e9b6049SEd Tanous std::optional<std::string>& profileIn) : 1428bd79bce8SPatrick Williams asyncResp(asyncRespIn), configuration(std::move(configurationsIn)), 14299e9b6049SEd Tanous profile(std::move(profileIn)) 14309e9b6049SEd Tanous {} 1431ecd6a3a2SEd Tanous 1432ecd6a3a2SEd Tanous SetPIDValues(const SetPIDValues&) = delete; 1433ecd6a3a2SEd Tanous SetPIDValues(SetPIDValues&&) = delete; 1434ecd6a3a2SEd Tanous SetPIDValues& operator=(const SetPIDValues&) = delete; 1435ecd6a3a2SEd Tanous SetPIDValues& operator=(SetPIDValues&&) = delete; 1436ecd6a3a2SEd Tanous 143773df0db0SJames Feist void run() 143873df0db0SJames Feist { 143973df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 144073df0db0SJames Feist { 144173df0db0SJames Feist return; 144273df0db0SJames Feist } 144373df0db0SJames Feist 144473df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 144573df0db0SJames Feist 144673df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 144773df0db0SJames Feist // interface gets more traction 14485eb468daSGeorge Liu sdbusplus::message::object_path objPath( 14495eb468daSGeorge Liu "/xyz/openbmc_project/inventory"); 14505eb468daSGeorge Liu dbus::utility::getManagedObjects( 14515eb468daSGeorge Liu "xyz.openbmc_project.EntityManager", objPath, 14525e7e2dc5SEd Tanous [self](const boost::system::error_code& ec, 1453914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& mObj) { 145473df0db0SJames Feist if (ec) 145573df0db0SJames Feist { 145662598e31SEd Tanous BMCWEB_LOG_ERROR("Error communicating to Entity Manager"); 145773df0db0SJames Feist messages::internalError(self->asyncResp->res); 145873df0db0SJames Feist return; 145973df0db0SJames Feist } 1460e69d9de2SJames Feist const std::array<const char*, 3> configurations = { 1461e69d9de2SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 1462e69d9de2SJames Feist stepwiseConfigurationIface}; 1463e69d9de2SJames Feist 146414b0b8d5SJames Feist for (const auto& [path, object] : mObj) 1465e69d9de2SJames Feist { 146614b0b8d5SJames Feist for (const auto& [interface, _] : object) 1467e69d9de2SJames Feist { 14683544d2a7SEd Tanous if (std::ranges::find(configurations, interface) != 14693544d2a7SEd Tanous configurations.end()) 1470e69d9de2SJames Feist { 147114b0b8d5SJames Feist self->objectCount++; 1472e69d9de2SJames Feist break; 1473e69d9de2SJames Feist } 1474e69d9de2SJames Feist } 1475e69d9de2SJames Feist } 1476914e2d5dSEd Tanous self->managedObj = mObj; 14775eb468daSGeorge Liu }); 147873df0db0SJames Feist 147973df0db0SJames Feist // at the same time get the profile information 1480e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1481e99073f5SGeorge Liu thermalModeIface}; 1482e99073f5SGeorge Liu dbus::utility::getSubTree( 1483e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1484e99073f5SGeorge Liu [self](const boost::system::error_code& ec, 1485b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 148673df0db0SJames Feist if (ec || subtree.empty()) 148773df0db0SJames Feist { 148873df0db0SJames Feist return; 148973df0db0SJames Feist } 149073df0db0SJames Feist if (subtree[0].second.empty()) 149173df0db0SJames Feist { 149273df0db0SJames Feist // invalid mapper response, should never happen 149362598e31SEd Tanous BMCWEB_LOG_ERROR("SetPIDValues: Mapper Error"); 149473df0db0SJames Feist messages::internalError(self->asyncResp->res); 149573df0db0SJames Feist return; 149673df0db0SJames Feist } 149773df0db0SJames Feist 149873df0db0SJames Feist const std::string& path = subtree[0].first; 149973df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 1500deae6a78SEd Tanous dbus::utility::getAllProperties( 1501bd79bce8SPatrick Williams *crow::connections::systemBus, owner, path, 1502bd79bce8SPatrick Williams thermalModeIface, 1503bd79bce8SPatrick Williams [self, path, 1504bd79bce8SPatrick Williams owner](const boost::system::error_code& ec2, 1505b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& r) { 1506cb13a392SEd Tanous if (ec2) 150773df0db0SJames Feist { 150862598e31SEd Tanous BMCWEB_LOG_ERROR( 1509bd79bce8SPatrick Williams "SetPIDValues: Can't get thermalModeIface {}", 1510bd79bce8SPatrick Williams path); 151173df0db0SJames Feist messages::internalError(self->asyncResp->res); 151273df0db0SJames Feist return; 151373df0db0SJames Feist } 1514271584abSEd Tanous const std::string* current = nullptr; 1515271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1516fac6e53bSKrzysztof Grobelny 1517fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1518bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), r, "Current", 1519bd79bce8SPatrick Williams current, "Supported", supported); 1520fac6e53bSKrzysztof Grobelny 1521fac6e53bSKrzysztof Grobelny if (!success) 152273df0db0SJames Feist { 1523002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 152473df0db0SJames Feist return; 152573df0db0SJames Feist } 1526fac6e53bSKrzysztof Grobelny 152773df0db0SJames Feist if (current == nullptr || supported == nullptr) 152873df0db0SJames Feist { 152962598e31SEd Tanous BMCWEB_LOG_ERROR( 1530bd79bce8SPatrick Williams "SetPIDValues: thermal mode iface invalid {}", 1531bd79bce8SPatrick Williams path); 153273df0db0SJames Feist messages::internalError(self->asyncResp->res); 153373df0db0SJames Feist return; 153473df0db0SJames Feist } 153573df0db0SJames Feist self->currentProfile = *current; 153673df0db0SJames Feist self->supportedProfiles = *supported; 153773df0db0SJames Feist self->profileConnection = owner; 153873df0db0SJames Feist self->profilePath = path; 1539fac6e53bSKrzysztof Grobelny }); 1540e99073f5SGeorge Liu }); 154173df0db0SJames Feist } 154224b2fe81SEd Tanous void pidSetDone() 154373df0db0SJames Feist { 154473df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 154573df0db0SJames Feist { 154673df0db0SJames Feist return; 15475b4aa86bSJames Feist } 15488d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; 154973df0db0SJames Feist if (profile) 155073df0db0SJames Feist { 15513544d2a7SEd Tanous if (std::ranges::find(supportedProfiles, *profile) == 15523544d2a7SEd Tanous supportedProfiles.end()) 155373df0db0SJames Feist { 155473df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 155573df0db0SJames Feist *profile); 155673df0db0SJames Feist return; 155773df0db0SJames Feist } 155873df0db0SJames Feist currentProfile = *profile; 15599ae226faSGeorge Liu sdbusplus::asio::setProperty( 15609ae226faSGeorge Liu *crow::connections::systemBus, profileConnection, profilePath, 15619ae226faSGeorge Liu thermalModeIface, "Current", *profile, 15625e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 156373df0db0SJames Feist if (ec) 156473df0db0SJames Feist { 156562598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching profile{}", ec); 156673df0db0SJames Feist messages::internalError(response->res); 156773df0db0SJames Feist } 15689ae226faSGeorge Liu }); 156973df0db0SJames Feist } 157073df0db0SJames Feist 157173df0db0SJames Feist for (auto& containerPair : configuration) 157273df0db0SJames Feist { 157373df0db0SJames Feist auto& container = containerPair.second; 157473df0db0SJames Feist if (!container) 157573df0db0SJames Feist { 157673df0db0SJames Feist continue; 157773df0db0SJames Feist } 15786ee7f774SJames Feist 157902cad96eSEd Tanous const std::string& type = containerPair.first; 158073df0db0SJames Feist 15819e9b6049SEd Tanous for (auto& [name, value] : *container) 158273df0db0SJames Feist { 1583cddbf3dfSPotin Lai std::string dbusObjName = name; 1584cddbf3dfSPotin Lai std::replace(dbusObjName.begin(), dbusObjName.end(), ' ', '_'); 158562598e31SEd Tanous BMCWEB_LOG_DEBUG("looking for {}", name); 15866ee7f774SJames Feist 15873544d2a7SEd Tanous auto pathItr = std::ranges::find_if( 15883544d2a7SEd Tanous managedObj, [&dbusObjName](const auto& obj) { 158991f75cafSEd Tanous return obj.first.filename() == dbusObjName; 159073df0db0SJames Feist }); 1591b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap output; 159273df0db0SJames Feist 159373df0db0SJames Feist output.reserve(16); // The pid interface length 159473df0db0SJames Feist 159573df0db0SJames Feist // determines if we're patching entity-manager or 159673df0db0SJames Feist // creating a new object 159773df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 159862598e31SEd Tanous BMCWEB_LOG_DEBUG("Found = {}", !createNewObject); 15996ee7f774SJames Feist 160073df0db0SJames Feist std::string iface; 1601ea2b670dSEd Tanous if (!createNewObject) 1602ea2b670dSEd Tanous { 16038be2b5b6SPotin Lai bool findInterface = false; 1604ea2b670dSEd Tanous for (const auto& interface : pathItr->second) 1605ea2b670dSEd Tanous { 1606ea2b670dSEd Tanous if (interface.first == pidConfigurationIface) 1607ea2b670dSEd Tanous { 1608ea2b670dSEd Tanous if (type == "PidControllers" || 1609ea2b670dSEd Tanous type == "FanControllers") 161073df0db0SJames Feist { 161173df0db0SJames Feist iface = pidConfigurationIface; 16128be2b5b6SPotin Lai findInterface = true; 16138be2b5b6SPotin Lai break; 161473df0db0SJames Feist } 161573df0db0SJames Feist } 1616ea2b670dSEd Tanous else if (interface.first == pidZoneConfigurationIface) 161773df0db0SJames Feist { 1618ea2b670dSEd Tanous if (type == "FanZones") 161973df0db0SJames Feist { 1620da39350aSPavanKumarIntel iface = pidZoneConfigurationIface; 16218be2b5b6SPotin Lai findInterface = true; 16228be2b5b6SPotin Lai break; 162373df0db0SJames Feist } 162473df0db0SJames Feist } 1625ea2b670dSEd Tanous else if (interface.first == stepwiseConfigurationIface) 1626ea2b670dSEd Tanous { 1627ea2b670dSEd Tanous if (type == "StepwiseControllers") 162873df0db0SJames Feist { 162973df0db0SJames Feist iface = stepwiseConfigurationIface; 16308be2b5b6SPotin Lai findInterface = true; 16318be2b5b6SPotin Lai break; 16328be2b5b6SPotin Lai } 16338be2b5b6SPotin Lai } 16348be2b5b6SPotin Lai } 16358be2b5b6SPotin Lai 16368be2b5b6SPotin Lai // create new object if interface not found 16378be2b5b6SPotin Lai if (!findInterface) 16388be2b5b6SPotin Lai { 163973df0db0SJames Feist createNewObject = true; 164073df0db0SJames Feist } 1641ea2b670dSEd Tanous } 16426ee7f774SJames Feist 16439e9b6049SEd Tanous if (createNewObject && value == nullptr) 16446ee7f774SJames Feist { 16454e0453b1SGunnar Mills // can't delete a non-existent object 16469e9b6049SEd Tanous messages::propertyValueNotInList(response->res, value, 1647e2616cc5SEd Tanous name); 16486ee7f774SJames Feist continue; 16496ee7f774SJames Feist } 16506ee7f774SJames Feist 16516ee7f774SJames Feist std::string path; 16526ee7f774SJames Feist if (pathItr != managedObj.end()) 16536ee7f774SJames Feist { 16546ee7f774SJames Feist path = pathItr->first.str; 16556ee7f774SJames Feist } 16566ee7f774SJames Feist 165762598e31SEd Tanous BMCWEB_LOG_DEBUG("Create new = {}", createNewObject); 1658e69d9de2SJames Feist 1659e69d9de2SJames Feist // arbitrary limit to avoid attacks 1660e69d9de2SJames Feist constexpr const size_t controllerLimit = 500; 166114b0b8d5SJames Feist if (createNewObject && objectCount >= controllerLimit) 1662e69d9de2SJames Feist { 1663e69d9de2SJames Feist messages::resourceExhaustion(response->res, type); 1664e69d9de2SJames Feist continue; 1665e69d9de2SJames Feist } 1666a170f275SEd Tanous std::string escaped = name; 1667a170f275SEd Tanous std::replace(escaped.begin(), escaped.end(), '_', ' '); 1668a170f275SEd Tanous output.emplace_back("Name", escaped); 166973df0db0SJames Feist 167073df0db0SJames Feist std::string chassis; 167173df0db0SJames Feist CreatePIDRet ret = createPidInterface( 16729e9b6049SEd Tanous response, type, name, value, path, managedObj, 16739e9b6049SEd Tanous createNewObject, output, chassis, currentProfile); 167473df0db0SJames Feist if (ret == CreatePIDRet::fail) 167573df0db0SJames Feist { 167673df0db0SJames Feist return; 167773df0db0SJames Feist } 16783174e4dfSEd Tanous if (ret == CreatePIDRet::del) 167973df0db0SJames Feist { 168073df0db0SJames Feist continue; 168173df0db0SJames Feist } 168273df0db0SJames Feist 168373df0db0SJames Feist if (!createNewObject) 168473df0db0SJames Feist { 168573df0db0SJames Feist for (const auto& property : output) 168673df0db0SJames Feist { 16877a696974SPotin Lai crow::connections::systemBus->async_method_call( 168873df0db0SJames Feist [response, 168973df0db0SJames Feist propertyName{std::string(property.first)}]( 16905e7e2dc5SEd Tanous const boost::system::error_code& ec) { 169173df0db0SJames Feist if (ec) 169273df0db0SJames Feist { 169362598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching {}: {}", 169462598e31SEd Tanous propertyName, ec); 169573df0db0SJames Feist messages::internalError(response->res); 169673df0db0SJames Feist return; 169773df0db0SJames Feist } 169873df0db0SJames Feist messages::success(response->res); 16997a696974SPotin Lai }, 17007a696974SPotin Lai "xyz.openbmc_project.EntityManager", path, 17017a696974SPotin Lai "org.freedesktop.DBus.Properties", "Set", iface, 17027a696974SPotin Lai property.first, property.second); 170373df0db0SJames Feist } 170473df0db0SJames Feist } 170573df0db0SJames Feist else 170673df0db0SJames Feist { 170773df0db0SJames Feist if (chassis.empty()) 170873df0db0SJames Feist { 170962598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config"); 1710ace85d60SEd Tanous messages::internalError(response->res); 171173df0db0SJames Feist return; 171273df0db0SJames Feist } 171373df0db0SJames Feist 171473df0db0SJames Feist bool foundChassis = false; 171573df0db0SJames Feist for (const auto& obj : managedObj) 171673df0db0SJames Feist { 171791f75cafSEd Tanous if (obj.first.filename() == chassis) 171873df0db0SJames Feist { 171973df0db0SJames Feist chassis = obj.first.str; 172073df0db0SJames Feist foundChassis = true; 172173df0db0SJames Feist break; 172273df0db0SJames Feist } 172373df0db0SJames Feist } 172473df0db0SJames Feist if (!foundChassis) 172573df0db0SJames Feist { 172662598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find chassis on dbus"); 172773df0db0SJames Feist messages::resourceMissingAtURI( 1728ace85d60SEd Tanous response->res, 1729ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", 1730ef4c65b7SEd Tanous chassis)); 173173df0db0SJames Feist return; 173273df0db0SJames Feist } 173373df0db0SJames Feist 173473df0db0SJames Feist crow::connections::systemBus->async_method_call( 17355e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 173673df0db0SJames Feist if (ec) 173773df0db0SJames Feist { 1738bd79bce8SPatrick Williams BMCWEB_LOG_ERROR("Error Adding Pid Object {}", 1739bd79bce8SPatrick Williams ec); 174073df0db0SJames Feist messages::internalError(response->res); 174173df0db0SJames Feist return; 174273df0db0SJames Feist } 174373df0db0SJames Feist messages::success(response->res); 174473df0db0SJames Feist }, 174573df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 174673df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 174773df0db0SJames Feist } 174873df0db0SJames Feist } 174973df0db0SJames Feist } 175073df0db0SJames Feist } 175124b2fe81SEd Tanous 175224b2fe81SEd Tanous ~SetPIDValues() 175324b2fe81SEd Tanous { 175424b2fe81SEd Tanous try 175524b2fe81SEd Tanous { 175624b2fe81SEd Tanous pidSetDone(); 175724b2fe81SEd Tanous } 175824b2fe81SEd Tanous catch (...) 175924b2fe81SEd Tanous { 176062598e31SEd Tanous BMCWEB_LOG_CRITICAL("pidSetDone threw exception"); 176124b2fe81SEd Tanous } 176224b2fe81SEd Tanous } 176324b2fe81SEd Tanous 17648d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 17659e9b6049SEd Tanous std::vector<std::pair<std::string, std::optional<nlohmann::json::object_t>>> 176673df0db0SJames Feist configuration; 176773df0db0SJames Feist std::optional<std::string> profile; 176873df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 176973df0db0SJames Feist std::vector<std::string> supportedProfiles; 177073df0db0SJames Feist std::string currentProfile; 177173df0db0SJames Feist std::string profileConnection; 177273df0db0SJames Feist std::string profilePath; 177314b0b8d5SJames Feist size_t objectCount = 0; 177473df0db0SJames Feist }; 177573df0db0SJames Feist 1776071d8fdfSSunnySrivastava1984 /** 1777071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 1778071d8fdfSSunnySrivastava1984 * 1779ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 1780071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 1781071d8fdfSSunnySrivastava1984 * @param[in] path - object path 1782071d8fdfSSunnySrivastava1984 * @return none 1783071d8fdfSSunnySrivastava1984 */ 1784ac106bf6SEd Tanous inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1785071d8fdfSSunnySrivastava1984 const std::string& connectionName, 1786071d8fdfSSunnySrivastava1984 const std::string& path) 1787071d8fdfSSunnySrivastava1984 { 178862598e31SEd Tanous BMCWEB_LOG_DEBUG("Get BMC manager Location data."); 1789071d8fdfSSunnySrivastava1984 1790deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 1791deae6a78SEd Tanous connectionName, path, 17921e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 1793ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 17941e1e598dSJonathan Doman const std::string& property) { 1795071d8fdfSSunnySrivastava1984 if (ec) 1796071d8fdfSSunnySrivastava1984 { 179762598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error for " 179862598e31SEd Tanous "Location"); 1799ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1800071d8fdfSSunnySrivastava1984 return; 1801071d8fdfSSunnySrivastava1984 } 1802071d8fdfSSunnySrivastava1984 1803bd79bce8SPatrick Williams asyncResp->res 1804bd79bce8SPatrick Williams .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 18051e1e598dSJonathan Doman property; 18061e1e598dSJonathan Doman }); 1807071d8fdfSSunnySrivastava1984 } 18087e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 1809*504af5a0SPatrick Williams inline void managerGetLastResetTime( 1810*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 18114bf2b033SGunnar Mills { 181262598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); 18134bf2b033SGunnar Mills 1814deae6a78SEd Tanous dbus::utility::getProperty<uint64_t>( 1815deae6a78SEd Tanous "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", 1816deae6a78SEd Tanous "xyz.openbmc_project.State.BMC", "LastRebootTime", 1817ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 18181e1e598dSJonathan Doman const uint64_t lastResetTime) { 18194bf2b033SGunnar Mills if (ec) 18204bf2b033SGunnar Mills { 182162598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 18224bf2b033SGunnar Mills return; 18234bf2b033SGunnar Mills } 18244bf2b033SGunnar Mills 18254bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 18264bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 18271e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 18284bf2b033SGunnar Mills 18294bf2b033SGunnar Mills // Convert to ISO 8601 standard 1830ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] = 18312b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 18321e1e598dSJonathan Doman }); 18334bf2b033SGunnar Mills } 18344bf2b033SGunnar Mills 18354bfefa74SGunnar Mills /** 18364bfefa74SGunnar Mills * @brief Set the running firmware image 18374bfefa74SGunnar Mills * 1838ac106bf6SEd Tanous * @param[i,o] asyncResp - Async response object 18394bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 18404bfefa74SGunnar Mills * 18414bfefa74SGunnar Mills * @return void 18424bfefa74SGunnar Mills */ 1843*504af5a0SPatrick Williams inline void setActiveFirmwareImage( 1844*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1845f23b7296SEd Tanous const std::string& runningFirmwareTarget) 18464bfefa74SGunnar Mills { 18474bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 1848f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 18494bfefa74SGunnar Mills if (idPos == std::string::npos) 18504bfefa74SGunnar Mills { 1851ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 18524bfefa74SGunnar Mills "@odata.id"); 185362598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); 18544bfefa74SGunnar Mills return; 18554bfefa74SGunnar Mills } 18564bfefa74SGunnar Mills idPos++; 18574bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 18584bfefa74SGunnar Mills { 1859ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 18604bfefa74SGunnar Mills "@odata.id"); 186162598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 18624bfefa74SGunnar Mills return; 18634bfefa74SGunnar Mills } 18644bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 18654bfefa74SGunnar Mills 18664bfefa74SGunnar Mills // Make sure the image is valid before setting priority 18675eb468daSGeorge Liu sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); 18685eb468daSGeorge Liu dbus::utility::getManagedObjects( 1869d27c31e9SJagpal Singh Gill getBMCUpdateServiceName(), objPath, 18705eb468daSGeorge Liu [asyncResp, firmwareId, runningFirmwareTarget]( 18715eb468daSGeorge Liu const boost::system::error_code& ec, 18725eb468daSGeorge Liu const dbus::utility::ManagedObjectType& subtree) { 18734bfefa74SGunnar Mills if (ec) 18744bfefa74SGunnar Mills { 187562598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); 1876ac106bf6SEd Tanous messages::internalError(asyncResp->res); 18774bfefa74SGunnar Mills return; 18784bfefa74SGunnar Mills } 18794bfefa74SGunnar Mills 188026f6976fSEd Tanous if (subtree.empty()) 18814bfefa74SGunnar Mills { 188262598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find image!"); 1883ac106bf6SEd Tanous messages::internalError(asyncResp->res); 18844bfefa74SGunnar Mills return; 18854bfefa74SGunnar Mills } 18864bfefa74SGunnar Mills 18874bfefa74SGunnar Mills bool foundImage = false; 188802cad96eSEd Tanous for (const auto& object : subtree) 18894bfefa74SGunnar Mills { 18904bfefa74SGunnar Mills const std::string& path = 18914bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 1892f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 18934bfefa74SGunnar Mills 18944bfefa74SGunnar Mills if (idPos2 == std::string::npos) 18954bfefa74SGunnar Mills { 18964bfefa74SGunnar Mills continue; 18974bfefa74SGunnar Mills } 18984bfefa74SGunnar Mills 18994bfefa74SGunnar Mills idPos2++; 19004bfefa74SGunnar Mills if (idPos2 >= path.size()) 19014bfefa74SGunnar Mills { 19024bfefa74SGunnar Mills continue; 19034bfefa74SGunnar Mills } 19044bfefa74SGunnar Mills 19054bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 19064bfefa74SGunnar Mills { 19074bfefa74SGunnar Mills foundImage = true; 19084bfefa74SGunnar Mills break; 19094bfefa74SGunnar Mills } 19104bfefa74SGunnar Mills } 19114bfefa74SGunnar Mills 19124bfefa74SGunnar Mills if (!foundImage) 19134bfefa74SGunnar Mills { 1914ac106bf6SEd Tanous messages::propertyValueNotInList( 1915ac106bf6SEd Tanous asyncResp->res, runningFirmwareTarget, "@odata.id"); 191662598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 19174bfefa74SGunnar Mills return; 19184bfefa74SGunnar Mills } 19194bfefa74SGunnar Mills 192062598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.", 192162598e31SEd Tanous firmwareId); 19224bfefa74SGunnar Mills 19234bfefa74SGunnar Mills // Only support Immediate 19244bfefa74SGunnar Mills // An addition could be a Redfish Setting like 19254bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 19269ae226faSGeorge Liu sdbusplus::asio::setProperty( 1927d27c31e9SJagpal Singh Gill *crow::connections::systemBus, getBMCUpdateServiceName(), 19289ae226faSGeorge Liu "/xyz/openbmc_project/software/" + firmwareId, 19299ae226faSGeorge Liu "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 19309ae226faSGeorge Liu static_cast<uint8_t>(0), 1931ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2) { 19328a592810SEd Tanous if (ec2) 19334bfefa74SGunnar Mills { 193462598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error setting."); 1935ac106bf6SEd Tanous messages::internalError(asyncResp->res); 19364bfefa74SGunnar Mills return; 19374bfefa74SGunnar Mills } 1938ac106bf6SEd Tanous doBMCGracefulRestart(asyncResp); 19399ae226faSGeorge Liu }); 19405eb468daSGeorge Liu }); 19414bfefa74SGunnar Mills } 19424bfefa74SGunnar Mills 1943bd79bce8SPatrick Williams inline void afterSetDateTime( 1944bd79bce8SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1945bd79bce8SPatrick Williams const boost::system::error_code& ec, const sdbusplus::message_t& msg) 1946c51afd54SEd Tanous { 1947c51afd54SEd Tanous if (ec) 1948c51afd54SEd Tanous { 1949c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}", 1950c51afd54SEd Tanous ec); 1951c51afd54SEd Tanous const sd_bus_error* dbusError = msg.get_error(); 1952c51afd54SEd Tanous if (dbusError != nullptr) 1953c51afd54SEd Tanous { 1954c51afd54SEd Tanous std::string_view errorName(dbusError->name); 1955c51afd54SEd Tanous if (errorName == 1956c51afd54SEd Tanous "org.freedesktop.timedate1.AutomaticTimeSyncEnabled") 1957c51afd54SEd Tanous { 1958c51afd54SEd Tanous BMCWEB_LOG_DEBUG("Setting conflict"); 1959c51afd54SEd Tanous messages::propertyValueConflict( 1960c51afd54SEd Tanous asyncResp->res, "DateTime", 1961c51afd54SEd Tanous "Managers/NetworkProtocol/NTPProcotolEnabled"); 1962c51afd54SEd Tanous return; 1963c51afd54SEd Tanous } 1964c51afd54SEd Tanous } 1965c51afd54SEd Tanous messages::internalError(asyncResp->res); 1966c51afd54SEd Tanous return; 1967c51afd54SEd Tanous } 1968c51afd54SEd Tanous asyncResp->res.result(boost::beast::http::status::no_content); 1969c51afd54SEd Tanous } 1970c51afd54SEd Tanous 1971c51afd54SEd Tanous inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1972c51afd54SEd Tanous const std::string& datetime) 1973af5d6058SSantosh Puranik { 197462598e31SEd Tanous BMCWEB_LOG_DEBUG("Set date time: {}", datetime); 1975af5d6058SSantosh Puranik 1976c2e32007SEd Tanous std::optional<redfish::time_utils::usSinceEpoch> us = 1977c2e32007SEd Tanous redfish::time_utils::dateStringToEpoch(datetime); 1978c2e32007SEd Tanous if (!us) 1979af5d6058SSantosh Puranik { 1980ac106bf6SEd Tanous messages::propertyValueFormatError(asyncResp->res, datetime, 1981ac106bf6SEd Tanous "DateTime"); 1982c2e32007SEd Tanous return; 1983c2e32007SEd Tanous } 1984c51afd54SEd Tanous // Set the absolute datetime 1985c51afd54SEd Tanous bool relative = false; 1986c51afd54SEd Tanous bool interactive = false; 1987c51afd54SEd Tanous crow::connections::systemBus->async_method_call( 1988c51afd54SEd Tanous [asyncResp](const boost::system::error_code& ec, 1989c51afd54SEd Tanous const sdbusplus::message_t& msg) { 1990c51afd54SEd Tanous afterSetDateTime(asyncResp, ec, msg); 1991c51afd54SEd Tanous }, 1992c51afd54SEd Tanous "org.freedesktop.timedate1", "/org/freedesktop/timedate1", 1993c51afd54SEd Tanous "org.freedesktop.timedate1", "SetTime", us->count(), relative, 1994c51afd54SEd Tanous interactive); 199583ff9ab6SJames Feist } 19969c310685SBorawski.Lukasz 1997*504af5a0SPatrick Williams inline void checkForQuiesced( 1998*504af5a0SPatrick Williams const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 199975815e5cSEd Tanous { 2000deae6a78SEd Tanous dbus::utility::getProperty<std::string>( 2001deae6a78SEd Tanous "org.freedesktop.systemd1", 200275815e5cSEd Tanous "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", 200375815e5cSEd Tanous "org.freedesktop.systemd1.Unit", "ActiveState", 200475815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, 200575815e5cSEd Tanous const std::string& val) { 200675815e5cSEd Tanous if (!ec) 200775815e5cSEd Tanous { 200875815e5cSEd Tanous if (val == "active") 200975815e5cSEd Tanous { 2010539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = 2011539d8c6bSEd Tanous resource::Health::Critical; 2012539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 2013539d8c6bSEd Tanous resource::State::Quiesced; 201475815e5cSEd Tanous return; 201575815e5cSEd Tanous } 201675815e5cSEd Tanous } 2017539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; 2018bd79bce8SPatrick Williams asyncResp->res.jsonValue["Status"]["State"] = 2019bd79bce8SPatrick Williams resource::State::Enabled; 202075815e5cSEd Tanous }); 202175815e5cSEd Tanous } 202275815e5cSEd Tanous 20237e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 20247e860f15SJohn Edward Broadbent { 20257e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 20269c310685SBorawski.Lukasz 2027253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") 2028ed398213SEd Tanous .privileges(redfish::privileges::getManager) 2029bd79bce8SPatrick Williams .methods( 2030bd79bce8SPatrick Williams boost::beast::http::verb:: 2031bd79bce8SPatrick Williams get)([&app, 2032bd79bce8SPatrick Williams uuid](const crow::Request& req, 2033253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2034253f11b8SEd Tanous const std::string& managerId) { 20353ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 203645ca1b86SEd Tanous { 203745ca1b86SEd Tanous return; 203845ca1b86SEd Tanous } 2039253f11b8SEd Tanous 2040253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2041253f11b8SEd Tanous { 2042bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 2043bd79bce8SPatrick Williams managerId); 2044253f11b8SEd Tanous return; 2045253f11b8SEd Tanous } 2046253f11b8SEd Tanous 2047253f11b8SEd Tanous asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 2048253f11b8SEd Tanous "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); 2049bd79bce8SPatrick Williams asyncResp->res.jsonValue["@odata.type"] = 2050bd79bce8SPatrick Williams "#Manager.v1_14_0.Manager"; 2051253f11b8SEd Tanous asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME; 20527e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 20537e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 20547e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 2055539d8c6bSEd Tanous asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On; 20561476687dSEd Tanous 2057539d8c6bSEd Tanous asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC; 20587e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 20597e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 2060bd79bce8SPatrick Williams asyncResp->res.jsonValue["Model"] = 2061bd79bce8SPatrick Williams "OpenBmc"; // TODO(ed), get model 20627e860f15SJohn Edward Broadbent 20631476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 2064253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/LogServices", 2065253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 20661476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 2067253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol", 2068253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 20691476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 2070bd79bce8SPatrick Williams boost::urls::format( 2071bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/EthernetInterfaces", 2072253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 20737e860f15SJohn Edward Broadbent 207425b54dbaSEd Tanous if constexpr (BMCWEB_VM_NBDPROXY) 207536c0f2a3SEd Tanous { 20761476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 2077253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", 2078253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 207936c0f2a3SEd Tanous } 20807e860f15SJohn Edward Broadbent 20817e860f15SJohn Edward Broadbent // default oem data 20827e860f15SJohn Edward Broadbent nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; 20837e860f15SJohn Edward Broadbent nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 2084bd79bce8SPatrick Williams oem["@odata.id"] = 2085bd79bce8SPatrick Williams boost::urls::format("/redfish/v1/Managers/{}#/Oem", 2086253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2087fc1cdd14SEd Tanous oemOpenbmc["@odata.type"] = "#OpenBMCManager.v1_0_0.Manager"; 2088253f11b8SEd Tanous oemOpenbmc["@odata.id"] = 2089253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}#/Oem/OpenBmc", 2090253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 20911476687dSEd Tanous 20921476687dSEd Tanous nlohmann::json::object_t certificates; 2093253f11b8SEd Tanous certificates["@odata.id"] = boost::urls::format( 2094253f11b8SEd Tanous "/redfish/v1/Managers/{}/Truststore/Certificates", 2095253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 20961476687dSEd Tanous oemOpenbmc["Certificates"] = std::move(certificates); 20977e860f15SJohn Edward Broadbent 20987e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 20997e860f15SJohn Edward Broadbent // supports BMC reboot. 21007e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 21017e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 2102bd79bce8SPatrick Williams managerReset["target"] = boost::urls::format( 2103bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/Actions/Manager.Reset", 2104253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 21057e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 2106253f11b8SEd Tanous boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo", 2107253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 21087e860f15SJohn Edward Broadbent 21097e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 21107e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 21117e860f15SJohn Edward Broadbent // on OpenBMC 21127e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 21137e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 2114253f11b8SEd Tanous resetToDefaults["target"] = boost::urls::format( 2115253f11b8SEd Tanous "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults", 2116253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2117613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] = 2118613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"}); 21197e860f15SJohn Edward Broadbent 21207c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 21212b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 21227c8c4058STejas Patil 21237c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 21247c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 21257c8c4058STejas Patil redfishDateTimeOffset.second; 21267e860f15SJohn Edward Broadbent 212725b54dbaSEd Tanous if constexpr (BMCWEB_KVM) 212825b54dbaSEd Tanous { 21297e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 213025b54dbaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = 213125b54dbaSEd Tanous true; 213225b54dbaSEd Tanous asyncResp->res 213325b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; 213425b54dbaSEd Tanous asyncResp->res 213525b54dbaSEd Tanous .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 2136613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 213725b54dbaSEd Tanous } 213825b54dbaSEd Tanous if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 21397f3e84a1SEd Tanous { 2140bd79bce8SPatrick Williams asyncResp->res 2141bd79bce8SPatrick Williams .jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 21421476687dSEd Tanous 21431476687dSEd Tanous nlohmann::json::array_t managerForServers; 21441476687dSEd Tanous nlohmann::json::object_t manager; 2145bd79bce8SPatrick Williams manager["@odata.id"] = std::format( 2146bd79bce8SPatrick Williams "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); 2147ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager)); 21481476687dSEd Tanous 21491476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 21501476687dSEd Tanous std::move(managerForServers); 21517f3e84a1SEd Tanous } 21527e860f15SJohn Edward Broadbent 2153eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 21547e860f15SJohn Edward Broadbent "FirmwareVersion", true); 21557e860f15SJohn Edward Broadbent 21567e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 21577e860f15SJohn Edward Broadbent 2158a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 2159a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 2160a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 2161bd79bce8SPatrick Williams managerDiagnosticData["@odata.id"] = boost::urls::format( 2162bd79bce8SPatrick Williams "/redfish/v1/Managers/{}/ManagerDiagnosticData", 2163253f11b8SEd Tanous BMCWEB_REDFISH_MANAGER_URI_NAME); 2164a51fc2d2SSui Chen 216525b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA) 216625b54dbaSEd Tanous { 21677e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp); 21687e860f15SJohn Edward Broadbent pids->run(); 216925b54dbaSEd Tanous } 21707e860f15SJohn Edward Broadbent 2171bd79bce8SPatrick Williams getMainChassisId(asyncResp, [](const std::string& chassisId, 2172bd79bce8SPatrick Williams const std::shared_ptr< 2173bd79bce8SPatrick Williams bmcweb::AsyncResp>& aRsp) { 2174bd79bce8SPatrick Williams aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 2175bd79bce8SPatrick Williams 1; 21761476687dSEd Tanous nlohmann::json::array_t managerForChassis; 21778a592810SEd Tanous nlohmann::json::object_t managerObj; 2178ef4c65b7SEd Tanous boost::urls::url chassiUrl = 2179ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 2180eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl; 2181ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj)); 21821476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 21831476687dSEd Tanous std::move(managerForChassis); 21841476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 2185eddfc437SWilly Tu chassiUrl; 21867e860f15SJohn Edward Broadbent }); 21877e860f15SJohn Edward Broadbent 2188deae6a78SEd Tanous dbus::utility::getProperty<double>( 2189deae6a78SEd Tanous "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 2190deae6a78SEd Tanous "org.freedesktop.systemd1.Manager", "Progress", 219175815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, double val) { 21927e860f15SJohn Edward Broadbent if (ec) 21931abe55efSEd Tanous { 219462598e31SEd Tanous BMCWEB_LOG_ERROR("Error while getting progress"); 21957e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21967e860f15SJohn Edward Broadbent return; 21977e860f15SJohn Edward Broadbent } 21981e1e598dSJonathan Doman if (val < 1.0) 21997e860f15SJohn Edward Broadbent { 2200539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = 2201539d8c6bSEd Tanous resource::Health::OK; 2202539d8c6bSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = 2203539d8c6bSEd Tanous resource::State::Starting; 220475815e5cSEd Tanous return; 22057e860f15SJohn Edward Broadbent } 220675815e5cSEd Tanous checkForQuiesced(asyncResp); 22071e1e598dSJonathan Doman }); 22089c310685SBorawski.Lukasz 2209e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2210e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"}; 2211e99073f5SGeorge Liu dbus::utility::getSubTree( 2212e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 22137e860f15SJohn Edward Broadbent [asyncResp]( 2214e99073f5SGeorge Liu const boost::system::error_code& ec, 2215b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 22167e860f15SJohn Edward Broadbent if (ec) 22171abe55efSEd Tanous { 2218bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG( 2219bd79bce8SPatrick Williams "D-Bus response error on GetSubTree {}", ec); 22207e860f15SJohn Edward Broadbent return; 22217e860f15SJohn Edward Broadbent } 222226f6976fSEd Tanous if (subtree.empty()) 22237e860f15SJohn Edward Broadbent { 222462598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); 22257e860f15SJohn Edward Broadbent return; 22267e860f15SJohn Edward Broadbent } 22277e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 22287e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 22297e860f15SJohn Edward Broadbent if (subtree.size() > 1) 22307e860f15SJohn Edward Broadbent { 223162598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!"); 22327e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 22337e860f15SJohn Edward Broadbent return; 22347e860f15SJohn Edward Broadbent } 22357e860f15SJohn Edward Broadbent 2236bd79bce8SPatrick Williams if (subtree[0].first.empty() || 2237bd79bce8SPatrick Williams subtree[0].second.size() != 1) 22387e860f15SJohn Edward Broadbent { 223962598e31SEd Tanous BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); 22407e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 22417e860f15SJohn Edward Broadbent return; 22427e860f15SJohn Edward Broadbent } 22437e860f15SJohn Edward Broadbent 22447e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 2245bd79bce8SPatrick Williams const std::string& connectionName = 2246bd79bce8SPatrick Williams subtree[0].second[0].first; 22477e860f15SJohn Edward Broadbent 2248bd79bce8SPatrick Williams for (const auto& interfaceName : 2249bd79bce8SPatrick Williams subtree[0].second[0].second) 22507e860f15SJohn Edward Broadbent { 22517e860f15SJohn Edward Broadbent if (interfaceName == 22527e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 22537e860f15SJohn Edward Broadbent { 2254deae6a78SEd Tanous dbus::utility::getAllProperties( 2255bd79bce8SPatrick Williams *crow::connections::systemBus, connectionName, 2256bd79bce8SPatrick Williams path, 2257fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 2258bd79bce8SPatrick Williams [asyncResp]( 2259bd79bce8SPatrick Williams const boost::system::error_code& ec2, 2260b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 22617e860f15SJohn Edward Broadbent propertiesList) { 22628a592810SEd Tanous if (ec2) 22637e860f15SJohn Edward Broadbent { 2264bd79bce8SPatrick Williams BMCWEB_LOG_DEBUG( 2265bd79bce8SPatrick Williams "Can't get bmc asset!"); 22667e860f15SJohn Edward Broadbent return; 22677e860f15SJohn Edward Broadbent } 22687e860f15SJohn Edward Broadbent 2269fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr; 2270fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr; 2271fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr; 2272fac6e53bSKrzysztof Grobelny const std::string* model = nullptr; 2273bd79bce8SPatrick Williams const std::string* sparePartNumber = 2274bd79bce8SPatrick Williams nullptr; 2275fac6e53bSKrzysztof Grobelny 2276bd79bce8SPatrick Williams const bool success = 2277bd79bce8SPatrick Williams sdbusplus::unpackPropertiesNoThrow( 2278bd79bce8SPatrick Williams dbus_utils::UnpackErrorPrinter(), 2279bd79bce8SPatrick Williams propertiesList, "PartNumber", 2280bd79bce8SPatrick Williams partNumber, "SerialNumber", 2281bd79bce8SPatrick Williams serialNumber, "Manufacturer", 2282bd79bce8SPatrick Williams manufacturer, "Model", model, 2283bd79bce8SPatrick Williams "SparePartNumber", sparePartNumber); 2284fac6e53bSKrzysztof Grobelny 2285fac6e53bSKrzysztof Grobelny if (!success) 22867e860f15SJohn Edward Broadbent { 2287002d39b4SEd Tanous messages::internalError(asyncResp->res); 22887e860f15SJohn Edward Broadbent return; 22897e860f15SJohn Edward Broadbent } 2290fac6e53bSKrzysztof Grobelny 2291fac6e53bSKrzysztof Grobelny if (partNumber != nullptr) 2292fac6e53bSKrzysztof Grobelny { 2293fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = 2294fac6e53bSKrzysztof Grobelny *partNumber; 22957e860f15SJohn Edward Broadbent } 2296fac6e53bSKrzysztof Grobelny 2297fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr) 2298fac6e53bSKrzysztof Grobelny { 2299bd79bce8SPatrick Williams asyncResp->res 2300bd79bce8SPatrick Williams .jsonValue["SerialNumber"] = 2301fac6e53bSKrzysztof Grobelny *serialNumber; 23027e860f15SJohn Edward Broadbent } 2303fac6e53bSKrzysztof Grobelny 2304fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr) 2305fac6e53bSKrzysztof Grobelny { 2306bd79bce8SPatrick Williams asyncResp->res 2307bd79bce8SPatrick Williams .jsonValue["Manufacturer"] = 2308fac6e53bSKrzysztof Grobelny *manufacturer; 2309fac6e53bSKrzysztof Grobelny } 2310fac6e53bSKrzysztof Grobelny 2311fac6e53bSKrzysztof Grobelny if (model != nullptr) 2312fac6e53bSKrzysztof Grobelny { 2313bd79bce8SPatrick Williams asyncResp->res.jsonValue["Model"] = 2314bd79bce8SPatrick Williams *model; 2315fac6e53bSKrzysztof Grobelny } 2316fac6e53bSKrzysztof Grobelny 2317fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr) 2318fac6e53bSKrzysztof Grobelny { 2319bd79bce8SPatrick Williams asyncResp->res 2320bd79bce8SPatrick Williams .jsonValue["SparePartNumber"] = 2321fac6e53bSKrzysztof Grobelny *sparePartNumber; 2322fac6e53bSKrzysztof Grobelny } 2323fac6e53bSKrzysztof Grobelny }); 23247e860f15SJohn Edward Broadbent } 2325bd79bce8SPatrick Williams else if ( 2326bd79bce8SPatrick Williams interfaceName == 23270fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 23287e860f15SJohn Edward Broadbent { 23297e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 23307e860f15SJohn Edward Broadbent } 23317e860f15SJohn Edward Broadbent } 2332e99073f5SGeorge Liu }); 23337e860f15SJohn Edward Broadbent }); 23347e860f15SJohn Edward Broadbent 2335253f11b8SEd Tanous BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") 2336ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 233745ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 233845ca1b86SEd Tanous [&app](const crow::Request& req, 2339253f11b8SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 2340253f11b8SEd Tanous const std::string& managerId) { 23413ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 234245ca1b86SEd Tanous { 234345ca1b86SEd Tanous return; 234445ca1b86SEd Tanous } 2345253f11b8SEd Tanous 2346253f11b8SEd Tanous if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 2347253f11b8SEd Tanous { 2348bd79bce8SPatrick Williams messages::resourceNotFound(asyncResp->res, "Manager", 2349bd79bce8SPatrick Williams managerId); 2350253f11b8SEd Tanous return; 2351253f11b8SEd Tanous } 2352253f11b8SEd Tanous 23539e9b6049SEd Tanous std::optional<std::string> activeSoftwareImageOdataId; 23547e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 23559e9b6049SEd Tanous std::optional<nlohmann::json::object_t> pidControllers; 23569e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanControllers; 23579e9b6049SEd Tanous std::optional<nlohmann::json::object_t> fanZones; 23589e9b6049SEd Tanous std::optional<nlohmann::json::object_t> stepwiseControllers; 23599e9b6049SEd Tanous std::optional<std::string> profile; 23607e860f15SJohn Edward Broadbent 2361afc474aeSMyung Bae if (!json_util::readJsonPatch( // 2362afc474aeSMyung Bae req, asyncResp->res, // 2363afc474aeSMyung Bae "DateTime", datetime, // 2364afc474aeSMyung Bae "Links/ActiveSoftwareImage/@odata.id", 2365afc474aeSMyung Bae activeSoftwareImageOdataId, // 2366afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanControllers", fanControllers, // 2367afc474aeSMyung Bae "Oem/OpenBmc/Fan/FanZones", fanZones, // 2368afc474aeSMyung Bae "Oem/OpenBmc/Fan/PidControllers", pidControllers, // 2369afc474aeSMyung Bae "Oem/OpenBmc/Fan/Profile", profile, // 2370afc474aeSMyung Bae "Oem/OpenBmc/Fan/StepwiseControllers", 2371afc474aeSMyung Bae stepwiseControllers // 23729e9b6049SEd Tanous )) 23737e860f15SJohn Edward Broadbent { 23747e860f15SJohn Edward Broadbent return; 23757e860f15SJohn Edward Broadbent } 23767e860f15SJohn Edward Broadbent 23779e9b6049SEd Tanous if (pidControllers || fanControllers || fanZones || 23789e9b6049SEd Tanous stepwiseControllers || profile) 23797e860f15SJohn Edward Broadbent { 238025b54dbaSEd Tanous if constexpr (BMCWEB_REDFISH_OEM_MANAGER_FAN_DATA) 238125b54dbaSEd Tanous { 2382bd79bce8SPatrick Williams std::vector< 2383bd79bce8SPatrick Williams std::pair<std::string, 238425b54dbaSEd Tanous std::optional<nlohmann::json::object_t>>> 23859e9b6049SEd Tanous configuration; 23869e9b6049SEd Tanous if (pidControllers) 23877e860f15SJohn Edward Broadbent { 2388bd79bce8SPatrick Williams configuration.emplace_back( 2389bd79bce8SPatrick Williams "PidControllers", std::move(pidControllers)); 23907e860f15SJohn Edward Broadbent } 23919e9b6049SEd Tanous if (fanControllers) 23927e860f15SJohn Edward Broadbent { 2393bd79bce8SPatrick Williams configuration.emplace_back( 2394bd79bce8SPatrick Williams "FanControllers", std::move(fanControllers)); 23957e860f15SJohn Edward Broadbent } 23969e9b6049SEd Tanous if (fanZones) 23977e860f15SJohn Edward Broadbent { 2398bd79bce8SPatrick Williams configuration.emplace_back("FanZones", 2399bd79bce8SPatrick Williams std::move(fanZones)); 24009e9b6049SEd Tanous } 24019e9b6049SEd Tanous if (stepwiseControllers) 24029e9b6049SEd Tanous { 2403bd79bce8SPatrick Williams configuration.emplace_back( 2404bd79bce8SPatrick Williams "StepwiseControllers", 24059e9b6049SEd Tanous std::move(stepwiseControllers)); 24069e9b6049SEd Tanous } 24079e9b6049SEd Tanous auto pid = std::make_shared<SetPIDValues>( 24089e9b6049SEd Tanous asyncResp, std::move(configuration), profile); 24097e860f15SJohn Edward Broadbent pid->run(); 241025b54dbaSEd Tanous } 241125b54dbaSEd Tanous else 241225b54dbaSEd Tanous { 241354dce7f5SGunnar Mills messages::propertyUnknown(asyncResp->res, "Oem"); 241454dce7f5SGunnar Mills return; 241525b54dbaSEd Tanous } 24167e860f15SJohn Edward Broadbent } 24179e9b6049SEd Tanous 24189e9b6049SEd Tanous if (activeSoftwareImageOdataId) 24197e860f15SJohn Edward Broadbent { 2420bd79bce8SPatrick Williams setActiveFirmwareImage(asyncResp, 2421bd79bce8SPatrick Williams *activeSoftwareImageOdataId); 24227e860f15SJohn Edward Broadbent } 24237e860f15SJohn Edward Broadbent 24247e860f15SJohn Edward Broadbent if (datetime) 24257e860f15SJohn Edward Broadbent { 2426c51afd54SEd Tanous setDateTime(asyncResp, *datetime); 24277e860f15SJohn Edward Broadbent } 24287e860f15SJohn Edward Broadbent }); 24297e860f15SJohn Edward Broadbent } 24307e860f15SJohn Edward Broadbent 24317e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 24327e860f15SJohn Edward Broadbent { 24337e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 2434ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 24357e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 243645ca1b86SEd Tanous [&app](const crow::Request& req, 24377e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 24383ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 243945ca1b86SEd Tanous { 244045ca1b86SEd Tanous return; 244145ca1b86SEd Tanous } 244283ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 244383ff9ab6SJames Feist // because it has a duplicate entry for members 24448d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 24458d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 24468d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 24478d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 24488d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 24491476687dSEd Tanous nlohmann::json::array_t members; 24501476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 2451bd79bce8SPatrick Williams bmc["@odata.id"] = boost::urls::format( 2452bd79bce8SPatrick Williams "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); 24531476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 24547e860f15SJohn Edward Broadbent }); 24559c310685SBorawski.Lukasz } 24569c310685SBorawski.Lukasz } // namespace redfish 2457