19c310685SBorawski.Lukasz /* 29c310685SBorawski.Lukasz // Copyright (c) 2018 Intel Corporation 39c310685SBorawski.Lukasz // 49c310685SBorawski.Lukasz // Licensed under the Apache License, Version 2.0 (the "License"); 59c310685SBorawski.Lukasz // you may not use this file except in compliance with the License. 69c310685SBorawski.Lukasz // You may obtain a copy of the License at 79c310685SBorawski.Lukasz // 89c310685SBorawski.Lukasz // http://www.apache.org/licenses/LICENSE-2.0 99c310685SBorawski.Lukasz // 109c310685SBorawski.Lukasz // Unless required by applicable law or agreed to in writing, software 119c310685SBorawski.Lukasz // distributed under the License is distributed on an "AS IS" BASIS, 129c310685SBorawski.Lukasz // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139c310685SBorawski.Lukasz // See the License for the specific language governing permissions and 149c310685SBorawski.Lukasz // limitations under the License. 159c310685SBorawski.Lukasz */ 169c310685SBorawski.Lukasz #pragma once 179c310685SBorawski.Lukasz 1813451e39SWilly Tu #include "bmcweb_config.h" 1913451e39SWilly Tu 20a51fc2d2SSui Chen #include "app.hpp" 21a51fc2d2SSui Chen #include "dbus_utility.hpp" 22b49ac873SJames Feist #include "health.hpp" 23a51fc2d2SSui Chen #include "query.hpp" 24c5d03ff4SJennifer Lee #include "redfish_util.hpp" 25a51fc2d2SSui Chen #include "registries/privilege_registry.hpp" 26fac6e53bSKrzysztof Grobelny #include "utils/dbus_utils.hpp" 273ccb3adbSEd Tanous #include "utils/json_utils.hpp" 28a51fc2d2SSui Chen #include "utils/sw_utils.hpp" 29a51fc2d2SSui Chen #include "utils/systemd_utils.hpp" 302b82937eSEd Tanous #include "utils/time_utils.hpp" 319c310685SBorawski.Lukasz 32e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 33ef4c65b7SEd Tanous #include <boost/url/format.hpp> 34fac6e53bSKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 35fac6e53bSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 361214b7e7SGunnar Mills 37a170f275SEd Tanous #include <algorithm> 38e99073f5SGeorge Liu #include <array> 394bfefa74SGunnar Mills #include <cstdint> 401214b7e7SGunnar Mills #include <memory> 413544d2a7SEd Tanous #include <ranges> 421214b7e7SGunnar Mills #include <sstream> 43e99073f5SGeorge Liu #include <string_view> 44abf2add6SEd Tanous #include <variant> 455b4aa86bSJames Feist 461abe55efSEd Tanous namespace redfish 471abe55efSEd Tanous { 48ed5befbdSJennifer Lee 49ed5befbdSJennifer Lee /** 502a5c4407SGunnar Mills * Function reboots the BMC. 512a5c4407SGunnar Mills * 522a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls 53ed5befbdSJennifer Lee */ 548d1b46d7Szhanghch05 inline void 558d1b46d7Szhanghch05 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 56ed5befbdSJennifer Lee { 57ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 58ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 59ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 60ed5befbdSJennifer Lee const std::string& propertyValue = 61ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 62ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 63ed5befbdSJennifer Lee 64ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 659ae226faSGeorge Liu sdbusplus::asio::setProperty( 669ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName, 679ae226faSGeorge Liu destProperty, propertyValue, 685e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 69ed5befbdSJennifer Lee // Use "Set" method to set the property value. 70ed5befbdSJennifer Lee if (ec) 71ed5befbdSJennifer Lee { 7262598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 73ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 74ed5befbdSJennifer Lee return; 75ed5befbdSJennifer Lee } 76ed5befbdSJennifer Lee 77ed5befbdSJennifer Lee messages::success(asyncResp->res); 789ae226faSGeorge Liu }); 79ed5befbdSJennifer Lee } 802a5c4407SGunnar Mills 818d1b46d7Szhanghch05 inline void 828d1b46d7Szhanghch05 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 83f92af389SJayaprakash Mutyala { 84f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC"; 85f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 86f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC"; 87f92af389SJayaprakash Mutyala const std::string& propertyValue = 88f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 89f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition"; 90f92af389SJayaprakash Mutyala 91f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call. 929ae226faSGeorge Liu sdbusplus::asio::setProperty( 939ae226faSGeorge Liu *crow::connections::systemBus, processName, objectPath, interfaceName, 949ae226faSGeorge Liu destProperty, propertyValue, 955e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 96f92af389SJayaprakash Mutyala // Use "Set" method to set the property value. 97f92af389SJayaprakash Mutyala if (ec) 98f92af389SJayaprakash Mutyala { 9962598e31SEd Tanous BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 100f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res); 101f92af389SJayaprakash Mutyala return; 102f92af389SJayaprakash Mutyala } 103f92af389SJayaprakash Mutyala 104f92af389SJayaprakash Mutyala messages::success(asyncResp->res); 1059ae226faSGeorge Liu }); 106f92af389SJayaprakash Mutyala } 107f92af389SJayaprakash Mutyala 1082a5c4407SGunnar Mills /** 1092a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot) 1102a5c4407SGunnar Mills * action. 1112a5c4407SGunnar Mills */ 1127e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app) 1132a5c4407SGunnar Mills { 1142a5c4407SGunnar Mills /** 1152a5c4407SGunnar Mills * Function handles POST method request. 1162a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 117f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 1182a5c4407SGunnar Mills */ 1197e860f15SJohn Edward Broadbent 1207e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") 121ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1227e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 12345ca1b86SEd Tanous [&app](const crow::Request& req, 1247e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1253ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 12645ca1b86SEd Tanous { 12745ca1b86SEd Tanous return; 12845ca1b86SEd Tanous } 12962598e31SEd Tanous BMCWEB_LOG_DEBUG("Post Manager Reset."); 1302a5c4407SGunnar Mills 1312a5c4407SGunnar Mills std::string resetType; 1322a5c4407SGunnar Mills 13315ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 1347e860f15SJohn Edward Broadbent resetType)) 1352a5c4407SGunnar Mills { 1362a5c4407SGunnar Mills return; 1372a5c4407SGunnar Mills } 1382a5c4407SGunnar Mills 139f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart") 140f92af389SJayaprakash Mutyala { 14162598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 142f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp); 143f92af389SJayaprakash Mutyala return; 144f92af389SJayaprakash Mutyala } 1453174e4dfSEd Tanous if (resetType == "ForceRestart") 146f92af389SJayaprakash Mutyala { 14762598e31SEd Tanous BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 148f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp); 149f92af389SJayaprakash Mutyala return; 150f92af389SJayaprakash Mutyala } 15162598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", resetType); 1522a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType, 1532a5c4407SGunnar Mills "ResetType"); 1542a5c4407SGunnar Mills 1552a5c4407SGunnar Mills return; 1567e860f15SJohn Edward Broadbent }); 1572a5c4407SGunnar Mills } 158ed5befbdSJennifer Lee 1593e40fc74SGunnar Mills /** 1603e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset 1613e40fc74SGunnar Mills * action. 1623e40fc74SGunnar Mills */ 1637e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app) 1643e40fc74SGunnar Mills { 1653e40fc74SGunnar Mills /** 1663e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request. 1673e40fc74SGunnar Mills * 1683e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling 1693e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot. 1703e40fc74SGunnar Mills * 1713e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write 1723e40fc74SGunnar Mills * filesystem which includes things like the network settings. 1733e40fc74SGunnar Mills * 1743e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll". 1753e40fc74SGunnar Mills */ 1767e860f15SJohn Edward Broadbent 1777e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 1787e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/") 179ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1807e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 18145ca1b86SEd Tanous [&app](const crow::Request& req, 1827e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1833ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 18445ca1b86SEd Tanous { 18545ca1b86SEd Tanous return; 18645ca1b86SEd Tanous } 18762598e31SEd Tanous BMCWEB_LOG_DEBUG("Post ResetToDefaults."); 1883e40fc74SGunnar Mills 1893e40fc74SGunnar Mills std::string resetType; 1903e40fc74SGunnar Mills 191002d39b4SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, 192002d39b4SEd Tanous "ResetToDefaultsType", resetType)) 1933e40fc74SGunnar Mills { 19462598e31SEd Tanous BMCWEB_LOG_DEBUG("Missing property ResetToDefaultsType."); 1953e40fc74SGunnar Mills 196002d39b4SEd Tanous messages::actionParameterMissing(asyncResp->res, "ResetToDefaults", 1973e40fc74SGunnar Mills "ResetToDefaultsType"); 1983e40fc74SGunnar Mills return; 1993e40fc74SGunnar Mills } 2003e40fc74SGunnar Mills 2013e40fc74SGunnar Mills if (resetType != "ResetAll") 2023e40fc74SGunnar Mills { 20362598e31SEd Tanous BMCWEB_LOG_DEBUG( 20462598e31SEd Tanous "Invalid property value for ResetToDefaultsType: {}", 20562598e31SEd Tanous resetType); 206002d39b4SEd Tanous messages::actionParameterNotSupported(asyncResp->res, resetType, 207002d39b4SEd Tanous "ResetToDefaultsType"); 2083e40fc74SGunnar Mills return; 2093e40fc74SGunnar Mills } 2103e40fc74SGunnar Mills 2113e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 2125e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 2133e40fc74SGunnar Mills if (ec) 2143e40fc74SGunnar Mills { 21562598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", ec); 2163e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2173e40fc74SGunnar Mills return; 2183e40fc74SGunnar Mills } 2193e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2203e40fc74SGunnar Mills // Can't erase what the BMC is running on 2213e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2223e40fc74SGunnar Mills }, 2233e40fc74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 2243e40fc74SGunnar Mills "/xyz/openbmc_project/software", 2253e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2267e860f15SJohn Edward Broadbent }); 2273e40fc74SGunnar Mills } 2283e40fc74SGunnar Mills 2291cb1a9e6SAppaRao Puli /** 2301cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2311cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2321cb1a9e6SAppaRao Puli */ 2337e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2341cb1a9e6SAppaRao Puli { 2351cb1a9e6SAppaRao Puli /** 2361cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2371cb1a9e6SAppaRao Puli */ 2387e860f15SJohn Edward Broadbent 2397e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/") 240ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 2417e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24245ca1b86SEd Tanous [&app](const crow::Request& req, 2437e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2443ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 24545ca1b86SEd Tanous { 24645ca1b86SEd Tanous return; 24745ca1b86SEd Tanous } 2481476687dSEd Tanous 2491476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 2501476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 2511476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2521476687dSEd Tanous "/redfish/v1/Managers/bmc/ResetActionInfo"; 2531476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 2541476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 2551476687dSEd Tanous nlohmann::json::object_t parameter; 2561476687dSEd Tanous parameter["Name"] = "ResetType"; 2571476687dSEd Tanous parameter["Required"] = true; 2581476687dSEd Tanous parameter["DataType"] = "String"; 2591476687dSEd Tanous 2601476687dSEd Tanous nlohmann::json::array_t allowableValues; 261ad539545SPatrick Williams allowableValues.emplace_back("GracefulRestart"); 262ad539545SPatrick Williams allowableValues.emplace_back("ForceRestart"); 2631476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues); 2641476687dSEd Tanous 2651476687dSEd Tanous nlohmann::json::array_t parameters; 266ad539545SPatrick Williams parameters.emplace_back(std::move(parameter)); 2671476687dSEd Tanous 2681476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 2697e860f15SJohn Edward Broadbent }); 2701cb1a9e6SAppaRao Puli } 2711cb1a9e6SAppaRao Puli 2725b4aa86bSJames Feist static constexpr const char* objectManagerIface = 2735b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 2745b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 2755b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 2765b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 2775b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 278b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 279b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 28073df0db0SJames Feist static constexpr const char* thermalModeIface = 28173df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 2829c310685SBorawski.Lukasz 2838d1b46d7Szhanghch05 inline void 2848d1b46d7Szhanghch05 asyncPopulatePid(const std::string& connection, const std::string& path, 28573df0db0SJames Feist const std::string& currentProfile, 28673df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 2878d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2885b4aa86bSJames Feist { 2895eb468daSGeorge Liu sdbusplus::message::object_path objPath(path); 2905eb468daSGeorge Liu dbus::utility::getManagedObjects( 2915eb468daSGeorge Liu connection, objPath, 29273df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 2935e7e2dc5SEd Tanous const boost::system::error_code& ec, 2945b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 2955b4aa86bSJames Feist if (ec) 2965b4aa86bSJames Feist { 29762598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 298f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2995b4aa86bSJames Feist return; 3005b4aa86bSJames Feist } 3015b4aa86bSJames Feist nlohmann::json& configRoot = 3025b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 3035b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 3045b4aa86bSJames Feist fans["@odata.type"] = "#OemManager.FanControllers"; 3050fda0f12SGeorge Liu fans["@odata.id"] = 3060fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers"; 3075b4aa86bSJames Feist 3085b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 3095b4aa86bSJames Feist pids["@odata.type"] = "#OemManager.PidControllers"; 3105b4aa86bSJames Feist pids["@odata.id"] = 3115b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; 3125b4aa86bSJames Feist 313b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 314b7a08d04SJames Feist stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; 315b7a08d04SJames Feist stepwise["@odata.id"] = 316b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; 317b7a08d04SJames Feist 3185b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 3195b4aa86bSJames Feist zones["@odata.id"] = 3205b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; 3215b4aa86bSJames Feist zones["@odata.type"] = "#OemManager.FanZones"; 322002d39b4SEd Tanous configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; 3235b4aa86bSJames Feist configRoot["@odata.type"] = "#OemManager.Fan"; 32473df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 32573df0db0SJames Feist 32673df0db0SJames Feist if (!currentProfile.empty()) 32773df0db0SJames Feist { 32873df0db0SJames Feist configRoot["Profile"] = currentProfile; 32973df0db0SJames Feist } 330bf2ddedeSCarson Labrado BMCWEB_LOG_DEBUG("profile = {} !", currentProfile); 3315b4aa86bSJames Feist 3325b4aa86bSJames Feist for (const auto& pathPair : managedObj) 3335b4aa86bSJames Feist { 3345b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 3355b4aa86bSJames Feist { 3365b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 337b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 338b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 3395b4aa86bSJames Feist { 3405b4aa86bSJames Feist continue; 3415b4aa86bSJames Feist } 34273df0db0SJames Feist 343711ac7a9SEd Tanous std::string name; 344711ac7a9SEd Tanous 345711ac7a9SEd Tanous for (const std::pair<std::string, 346002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 347002d39b4SEd Tanous intfPair.second) 348711ac7a9SEd Tanous { 349711ac7a9SEd Tanous if (propPair.first == "Name") 350711ac7a9SEd Tanous { 3515b4aa86bSJames Feist const std::string* namePtr = 352711ac7a9SEd Tanous std::get_if<std::string>(&propPair.second); 3535b4aa86bSJames Feist if (namePtr == nullptr) 3545b4aa86bSJames Feist { 35562598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Name Field illegal"); 356b7a08d04SJames Feist messages::internalError(asyncResp->res); 3575b4aa86bSJames Feist return; 3585b4aa86bSJames Feist } 359db697703SWilly Tu name = *namePtr; 3605b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 361711ac7a9SEd Tanous } 362711ac7a9SEd Tanous else if (propPair.first == "Profiles") 36373df0db0SJames Feist { 36473df0db0SJames Feist const std::vector<std::string>* profiles = 36573df0db0SJames Feist std::get_if<std::vector<std::string>>( 366711ac7a9SEd Tanous &propPair.second); 36773df0db0SJames Feist if (profiles == nullptr) 36873df0db0SJames Feist { 36962598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Profiles Field illegal"); 37073df0db0SJames Feist messages::internalError(asyncResp->res); 37173df0db0SJames Feist return; 37273df0db0SJames Feist } 37373df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 37473df0db0SJames Feist currentProfile) == profiles->end()) 37573df0db0SJames Feist { 37662598e31SEd Tanous BMCWEB_LOG_INFO( 37762598e31SEd Tanous "{} not supported in current profile", name); 37873df0db0SJames Feist continue; 37973df0db0SJames Feist } 38073df0db0SJames Feist } 381711ac7a9SEd Tanous } 382b7a08d04SJames Feist nlohmann::json* config = nullptr; 383c33a90ecSJames Feist const std::string* classPtr = nullptr; 384711ac7a9SEd Tanous 385711ac7a9SEd Tanous for (const std::pair<std::string, 386002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 387002d39b4SEd Tanous intfPair.second) 388c33a90ecSJames Feist { 389727dc83fSLei YU if (propPair.first == "Class") 390711ac7a9SEd Tanous { 391002d39b4SEd Tanous classPtr = std::get_if<std::string>(&propPair.second); 392711ac7a9SEd Tanous } 393c33a90ecSJames Feist } 394c33a90ecSJames Feist 395ef4c65b7SEd Tanous boost::urls::url url("/redfish/v1/Managers/bmc"); 3965b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 3975b4aa86bSJames Feist { 3985b4aa86bSJames Feist std::string chassis; 399002d39b4SEd Tanous if (!dbus::utility::getNthStringFromPath(pathPair.first.str, 400002d39b4SEd Tanous 5, chassis)) 4015b4aa86bSJames Feist { 4025b4aa86bSJames Feist chassis = "#IllegalValue"; 4035b4aa86bSJames Feist } 4045b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 405ef4c65b7SEd Tanous zone["Chassis"]["@odata.id"] = 406ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis); 407eddfc437SWilly Tu url.set_fragment( 408eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name) 409eddfc437SWilly Tu .to_string()); 410eddfc437SWilly Tu zone["@odata.id"] = std::move(url); 4115b4aa86bSJames Feist zone["@odata.type"] = "#OemManager.FanZone"; 412b7a08d04SJames Feist config = &zone; 4135b4aa86bSJames Feist } 4145b4aa86bSJames Feist 415b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 4165b4aa86bSJames Feist { 417c33a90ecSJames Feist if (classPtr == nullptr) 418c33a90ecSJames Feist { 41962598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Class Field illegal"); 420c33a90ecSJames Feist messages::internalError(asyncResp->res); 421c33a90ecSJames Feist return; 422c33a90ecSJames Feist } 423c33a90ecSJames Feist 424b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 425b7a08d04SJames Feist config = &controller; 426eddfc437SWilly Tu url.set_fragment( 427eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/StepwiseControllers"_json_pointer / 428eddfc437SWilly Tu name) 429eddfc437SWilly Tu .to_string()); 430eddfc437SWilly Tu controller["@odata.id"] = std::move(url); 431b7a08d04SJames Feist controller["@odata.type"] = 432b7a08d04SJames Feist "#OemManager.StepwiseController"; 433b7a08d04SJames Feist 434c33a90ecSJames Feist controller["Direction"] = *classPtr; 4355b4aa86bSJames Feist } 4365b4aa86bSJames Feist 4375b4aa86bSJames Feist // pid and fans are off the same configuration 438b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 4395b4aa86bSJames Feist { 4405b4aa86bSJames Feist if (classPtr == nullptr) 4415b4aa86bSJames Feist { 44262598e31SEd Tanous BMCWEB_LOG_ERROR("Pid Class Field illegal"); 443a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 4445b4aa86bSJames Feist return; 4455b4aa86bSJames Feist } 4465b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 447002d39b4SEd Tanous nlohmann::json& element = isFan ? fans[name] : pids[name]; 448b7a08d04SJames Feist config = &element; 4495b4aa86bSJames Feist if (isFan) 4505b4aa86bSJames Feist { 451eddfc437SWilly Tu url.set_fragment( 452eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanControllers"_json_pointer / 453eddfc437SWilly Tu name) 454eddfc437SWilly Tu .to_string()); 455eddfc437SWilly Tu element["@odata.id"] = std::move(url); 456002d39b4SEd Tanous element["@odata.type"] = "#OemManager.FanController"; 4575b4aa86bSJames Feist } 4585b4aa86bSJames Feist else 4595b4aa86bSJames Feist { 460eddfc437SWilly Tu url.set_fragment( 461eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/PidControllers"_json_pointer / 462eddfc437SWilly Tu name) 463eddfc437SWilly Tu .to_string()); 464eddfc437SWilly Tu element["@odata.id"] = std::move(url); 465002d39b4SEd Tanous element["@odata.type"] = "#OemManager.PidController"; 4665b4aa86bSJames Feist } 467b7a08d04SJames Feist } 468b7a08d04SJames Feist else 469b7a08d04SJames Feist { 47062598e31SEd Tanous BMCWEB_LOG_ERROR("Unexpected configuration"); 471b7a08d04SJames Feist messages::internalError(asyncResp->res); 472b7a08d04SJames Feist return; 473b7a08d04SJames Feist } 474b7a08d04SJames Feist 475b7a08d04SJames Feist // used for making maps out of 2 vectors 476b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 477b7a08d04SJames Feist const std::vector<double>* values = nullptr; 478b7a08d04SJames Feist 479b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 480b7a08d04SJames Feist { 481b7a08d04SJames Feist if (propertyPair.first == "Type" || 482b7a08d04SJames Feist propertyPair.first == "Class" || 483b7a08d04SJames Feist propertyPair.first == "Name") 484b7a08d04SJames Feist { 485b7a08d04SJames Feist continue; 486b7a08d04SJames Feist } 487b7a08d04SJames Feist 488b7a08d04SJames Feist // zones 489b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 490b7a08d04SJames Feist { 491b7a08d04SJames Feist const double* ptr = 492abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 493b7a08d04SJames Feist if (ptr == nullptr) 494b7a08d04SJames Feist { 49562598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 49662598e31SEd Tanous propertyPair.first); 497b7a08d04SJames Feist messages::internalError(asyncResp->res); 498b7a08d04SJames Feist return; 499b7a08d04SJames Feist } 500b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 501b7a08d04SJames Feist } 502b7a08d04SJames Feist 503b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 504b7a08d04SJames Feist { 505b7a08d04SJames Feist if (propertyPair.first == "Reading" || 506b7a08d04SJames Feist propertyPair.first == "Output") 507b7a08d04SJames Feist { 508b7a08d04SJames Feist const std::vector<double>* ptr = 509abf2add6SEd Tanous std::get_if<std::vector<double>>( 510b7a08d04SJames Feist &propertyPair.second); 511b7a08d04SJames Feist 512b7a08d04SJames Feist if (ptr == nullptr) 513b7a08d04SJames Feist { 51462598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 51562598e31SEd Tanous propertyPair.first); 516b7a08d04SJames Feist messages::internalError(asyncResp->res); 517b7a08d04SJames Feist return; 518b7a08d04SJames Feist } 519b7a08d04SJames Feist 520b7a08d04SJames Feist if (propertyPair.first == "Reading") 521b7a08d04SJames Feist { 522b7a08d04SJames Feist keys = ptr; 523b7a08d04SJames Feist } 524b7a08d04SJames Feist else 525b7a08d04SJames Feist { 526b7a08d04SJames Feist values = ptr; 527b7a08d04SJames Feist } 528e662eae8SEd Tanous if (keys != nullptr && values != nullptr) 529b7a08d04SJames Feist { 530b7a08d04SJames Feist if (keys->size() != values->size()) 531b7a08d04SJames Feist { 53262598e31SEd Tanous BMCWEB_LOG_ERROR( 53362598e31SEd Tanous "Reading and Output size don't match "); 534b7a08d04SJames Feist messages::internalError(asyncResp->res); 535b7a08d04SJames Feist return; 536b7a08d04SJames Feist } 537b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 538b7a08d04SJames Feist steps = nlohmann::json::array(); 539b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 540b7a08d04SJames Feist { 5411476687dSEd Tanous nlohmann::json::object_t step; 5421476687dSEd Tanous step["Target"] = (*keys)[ii]; 5431476687dSEd Tanous step["Output"] = (*values)[ii]; 544b2ba3072SPatrick Williams steps.emplace_back(std::move(step)); 545b7a08d04SJames Feist } 546b7a08d04SJames Feist } 547b7a08d04SJames Feist } 548b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 549b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 550b7a08d04SJames Feist { 551b7a08d04SJames Feist const double* ptr = 552abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 553b7a08d04SJames Feist if (ptr == nullptr) 554b7a08d04SJames Feist { 55562598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 55662598e31SEd Tanous propertyPair.first); 557b7a08d04SJames Feist messages::internalError(asyncResp->res); 558b7a08d04SJames Feist return; 559b7a08d04SJames Feist } 560b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 561b7a08d04SJames Feist } 562b7a08d04SJames Feist } 563b7a08d04SJames Feist 564b7a08d04SJames Feist // pid and fans are off the same configuration 565b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 566b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 567b7a08d04SJames Feist { 5685b4aa86bSJames Feist if (propertyPair.first == "Zones") 5695b4aa86bSJames Feist { 5705b4aa86bSJames Feist const std::vector<std::string>* inputs = 571abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5721b6b96c5SEd Tanous &propertyPair.second); 5735b4aa86bSJames Feist 5745b4aa86bSJames Feist if (inputs == nullptr) 5755b4aa86bSJames Feist { 57662598e31SEd Tanous BMCWEB_LOG_ERROR("Zones Pid Field Illegal"); 577a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 5785b4aa86bSJames Feist return; 5795b4aa86bSJames Feist } 580b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5815b4aa86bSJames Feist data = nlohmann::json::array(); 5825b4aa86bSJames Feist for (std::string itemCopy : *inputs) 5835b4aa86bSJames Feist { 5845b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 5851476687dSEd Tanous nlohmann::json::object_t input; 586ef4c65b7SEd Tanous boost::urls::url managerUrl = boost::urls::format( 587ef4c65b7SEd Tanous "/redfish/v1/Managers/bmc#{}", 588eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / 589eddfc437SWilly Tu itemCopy) 590eddfc437SWilly Tu .to_string()); 591eddfc437SWilly Tu input["@odata.id"] = std::move(managerUrl); 592b2ba3072SPatrick Williams data.emplace_back(std::move(input)); 5935b4aa86bSJames Feist } 5945b4aa86bSJames Feist } 5955b4aa86bSJames Feist // todo(james): may never happen, but this 5965b4aa86bSJames Feist // assumes configuration data referenced in the 5975b4aa86bSJames Feist // PID config is provided by the same daemon, we 5985b4aa86bSJames Feist // could add another loop to cover all cases, 5995b4aa86bSJames Feist // but I'm okay kicking this can down the road a 6005b4aa86bSJames Feist // bit 6015b4aa86bSJames Feist 6025b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 6035b4aa86bSJames Feist propertyPair.first == "Outputs") 6045b4aa86bSJames Feist { 605b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 6065b4aa86bSJames Feist const std::vector<std::string>* inputs = 607abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 6081b6b96c5SEd Tanous &propertyPair.second); 6095b4aa86bSJames Feist 6105b4aa86bSJames Feist if (inputs == nullptr) 6115b4aa86bSJames Feist { 61262598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 61362598e31SEd Tanous propertyPair.first); 614f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6155b4aa86bSJames Feist return; 6165b4aa86bSJames Feist } 6175b4aa86bSJames Feist data = *inputs; 618b943aaefSJames Feist } 619b943aaefSJames Feist else if (propertyPair.first == "SetPointOffset") 620b943aaefSJames Feist { 621b943aaefSJames Feist const std::string* ptr = 622002d39b4SEd Tanous std::get_if<std::string>(&propertyPair.second); 623b943aaefSJames Feist 624b943aaefSJames Feist if (ptr == nullptr) 625b943aaefSJames Feist { 62662598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 62762598e31SEd Tanous propertyPair.first); 628b943aaefSJames Feist messages::internalError(asyncResp->res); 629b943aaefSJames Feist return; 630b943aaefSJames Feist } 631b943aaefSJames Feist // translate from dbus to redfish 632b943aaefSJames Feist if (*ptr == "WarningHigh") 633b943aaefSJames Feist { 634b943aaefSJames Feist (*config)["SetPointOffset"] = 635b943aaefSJames Feist "UpperThresholdNonCritical"; 636b943aaefSJames Feist } 637b943aaefSJames Feist else if (*ptr == "WarningLow") 638b943aaefSJames Feist { 639b943aaefSJames Feist (*config)["SetPointOffset"] = 640b943aaefSJames Feist "LowerThresholdNonCritical"; 641b943aaefSJames Feist } 642b943aaefSJames Feist else if (*ptr == "CriticalHigh") 643b943aaefSJames Feist { 644b943aaefSJames Feist (*config)["SetPointOffset"] = 645b943aaefSJames Feist "UpperThresholdCritical"; 646b943aaefSJames Feist } 647b943aaefSJames Feist else if (*ptr == "CriticalLow") 648b943aaefSJames Feist { 649b943aaefSJames Feist (*config)["SetPointOffset"] = 650b943aaefSJames Feist "LowerThresholdCritical"; 651b943aaefSJames Feist } 652b943aaefSJames Feist else 653b943aaefSJames Feist { 65462598e31SEd Tanous BMCWEB_LOG_ERROR("Value Illegal {}", *ptr); 655b943aaefSJames Feist messages::internalError(asyncResp->res); 656b943aaefSJames Feist return; 657b943aaefSJames Feist } 658b943aaefSJames Feist } 659b943aaefSJames Feist // doubles 660002d39b4SEd Tanous else if (propertyPair.first == "FFGainCoefficient" || 6615b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 6625b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 6635b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 6645b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 665002d39b4SEd Tanous propertyPair.first == "PositiveHysteresis" || 666002d39b4SEd Tanous propertyPair.first == "NegativeHysteresis" || 6675b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 6685b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 6695b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 6707625cb81SJames Feist propertyPair.first == "SetPoint" || 6715b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 6725b4aa86bSJames Feist propertyPair.first == "SlewPos") 6735b4aa86bSJames Feist { 6745b4aa86bSJames Feist const double* ptr = 675abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 6765b4aa86bSJames Feist if (ptr == nullptr) 6775b4aa86bSJames Feist { 67862598e31SEd Tanous BMCWEB_LOG_ERROR("Field Illegal {}", 67962598e31SEd Tanous propertyPair.first); 680f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6815b4aa86bSJames Feist return; 6825b4aa86bSJames Feist } 683b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 6845b4aa86bSJames Feist } 6855b4aa86bSJames Feist } 6865b4aa86bSJames Feist } 6875b4aa86bSJames Feist } 6885b4aa86bSJames Feist } 6895eb468daSGeorge Liu }); 6905b4aa86bSJames Feist } 691ca537928SJennifer Lee 69283ff9ab6SJames Feist enum class CreatePIDRet 69383ff9ab6SJames Feist { 69483ff9ab6SJames Feist fail, 69583ff9ab6SJames Feist del, 69683ff9ab6SJames Feist patch 69783ff9ab6SJames Feist }; 69883ff9ab6SJames Feist 6998d1b46d7Szhanghch05 inline bool 7008d1b46d7Szhanghch05 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response, 7015f2caaefSJames Feist std::vector<nlohmann::json>& config, 7025f2caaefSJames Feist std::vector<std::string>& zones) 7035f2caaefSJames Feist { 704b6baeaa4SJames Feist if (config.empty()) 705b6baeaa4SJames Feist { 70662598e31SEd Tanous BMCWEB_LOG_ERROR("Empty Zones"); 707f818b04dSEd Tanous messages::propertyValueFormatError(response->res, config, "Zones"); 708b6baeaa4SJames Feist return false; 709b6baeaa4SJames Feist } 7105f2caaefSJames Feist for (auto& odata : config) 7115f2caaefSJames Feist { 7125f2caaefSJames Feist std::string path; 7135f2caaefSJames Feist if (!redfish::json_util::readJson(odata, response->res, "@odata.id", 7145f2caaefSJames Feist path)) 7155f2caaefSJames Feist { 7165f2caaefSJames Feist return false; 7175f2caaefSJames Feist } 7185f2caaefSJames Feist std::string input; 71961adbda3SJames Feist 72061adbda3SJames Feist // 8 below comes from 72161adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 72261adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 72361adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 7245f2caaefSJames Feist { 72562598e31SEd Tanous BMCWEB_LOG_ERROR("Got invalid path {}", path); 72662598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type Zones"); 727f818b04dSEd Tanous messages::propertyValueFormatError(response->res, odata, "Zones"); 7285f2caaefSJames Feist return false; 7295f2caaefSJames Feist } 730a170f275SEd Tanous std::replace(input.begin(), input.end(), '_', ' '); 7315f2caaefSJames Feist zones.emplace_back(std::move(input)); 7325f2caaefSJames Feist } 7335f2caaefSJames Feist return true; 7345f2caaefSJames Feist } 7355f2caaefSJames Feist 736711ac7a9SEd Tanous inline const dbus::utility::ManagedObjectType::value_type* 73773df0db0SJames Feist findChassis(const dbus::utility::ManagedObjectType& managedObj, 738b6baeaa4SJames Feist const std::string& value, std::string& chassis) 739b6baeaa4SJames Feist { 74062598e31SEd Tanous BMCWEB_LOG_DEBUG("Find Chassis: {}", value); 741b6baeaa4SJames Feist 742a170f275SEd Tanous std::string escaped = value; 7436ce82fabSYaswanth Reddy M std::replace(escaped.begin(), escaped.end(), ' ', '_'); 744b6baeaa4SJames Feist escaped = "/" + escaped; 7453544d2a7SEd Tanous auto it = std::ranges::find_if(managedObj, [&escaped](const auto& obj) { 746b6baeaa4SJames Feist if (boost::algorithm::ends_with(obj.first.str, escaped)) 747b6baeaa4SJames Feist { 74862598e31SEd Tanous BMCWEB_LOG_DEBUG("Matched {}", obj.first.str); 749b6baeaa4SJames Feist return true; 750b6baeaa4SJames Feist } 751b6baeaa4SJames Feist return false; 752b6baeaa4SJames Feist }); 753b6baeaa4SJames Feist 754b6baeaa4SJames Feist if (it == managedObj.end()) 755b6baeaa4SJames Feist { 75673df0db0SJames Feist return nullptr; 757b6baeaa4SJames Feist } 758b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 759b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 76073df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 76173df0db0SJames Feist { 76273df0db0SJames Feist return &(*it); 76373df0db0SJames Feist } 76473df0db0SJames Feist 76573df0db0SJames Feist return nullptr; 766b6baeaa4SJames Feist } 767b6baeaa4SJames Feist 76823a21a1cSEd Tanous inline CreatePIDRet createPidInterface( 7698d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, 770b5a76932SEd Tanous const nlohmann::json::iterator& it, const std::string& path, 77183ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 772b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap& output, std::string& chassis, 773b9d36b47SEd Tanous const std::string& profile) 77483ff9ab6SJames Feist { 7755f2caaefSJames Feist // common deleter 776b6baeaa4SJames Feist if (it.value() == nullptr) 7775f2caaefSJames Feist { 7785f2caaefSJames Feist std::string iface; 7795f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 7805f2caaefSJames Feist { 7815f2caaefSJames Feist iface = pidConfigurationIface; 7825f2caaefSJames Feist } 7835f2caaefSJames Feist else if (type == "FanZones") 7845f2caaefSJames Feist { 7855f2caaefSJames Feist iface = pidZoneConfigurationIface; 7865f2caaefSJames Feist } 7875f2caaefSJames Feist else if (type == "StepwiseControllers") 7885f2caaefSJames Feist { 7895f2caaefSJames Feist iface = stepwiseConfigurationIface; 7905f2caaefSJames Feist } 7915f2caaefSJames Feist else 7925f2caaefSJames Feist { 79362598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type {}", type); 7945f2caaefSJames Feist messages::propertyUnknown(response->res, type); 7955f2caaefSJames Feist return CreatePIDRet::fail; 7965f2caaefSJames Feist } 7976ee7f774SJames Feist 79862598e31SEd Tanous BMCWEB_LOG_DEBUG("del {} {}", path, iface); 7995f2caaefSJames Feist // delete interface 8005f2caaefSJames Feist crow::connections::systemBus->async_method_call( 8015e7e2dc5SEd Tanous [response, path](const boost::system::error_code& ec) { 8025f2caaefSJames Feist if (ec) 8035f2caaefSJames Feist { 80462598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching {}: {}", path, ec); 8055f2caaefSJames Feist messages::internalError(response->res); 806b6baeaa4SJames Feist return; 8075f2caaefSJames Feist } 808b6baeaa4SJames Feist messages::success(response->res); 8095f2caaefSJames Feist }, 8105f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 8115f2caaefSJames Feist return CreatePIDRet::del; 8125f2caaefSJames Feist } 8135f2caaefSJames Feist 814711ac7a9SEd Tanous const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr; 815b6baeaa4SJames Feist if (!createNewObject) 816b6baeaa4SJames Feist { 817b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 818b6baeaa4SJames Feist // d-bus 81973df0db0SJames Feist managedItem = findChassis(managedObj, it.key(), chassis); 82073df0db0SJames Feist if (managedItem == nullptr) 821b6baeaa4SJames Feist { 82262598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 823ef4c65b7SEd Tanous messages::invalidObject( 824ef4c65b7SEd Tanous response->res, 825ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 826b6baeaa4SJames Feist return CreatePIDRet::fail; 827b6baeaa4SJames Feist } 828b6baeaa4SJames Feist } 829b6baeaa4SJames Feist 83026f6976fSEd Tanous if (!profile.empty() && 83173df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 83273df0db0SJames Feist type == "StepwiseControllers")) 83373df0db0SJames Feist { 83473df0db0SJames Feist if (managedItem == nullptr) 83573df0db0SJames Feist { 836b9d36b47SEd Tanous output.emplace_back("Profiles", std::vector<std::string>{profile}); 83773df0db0SJames Feist } 83873df0db0SJames Feist else 83973df0db0SJames Feist { 84073df0db0SJames Feist std::string interface; 84173df0db0SJames Feist if (type == "StepwiseControllers") 84273df0db0SJames Feist { 84373df0db0SJames Feist interface = stepwiseConfigurationIface; 84473df0db0SJames Feist } 84573df0db0SJames Feist else 84673df0db0SJames Feist { 84773df0db0SJames Feist interface = pidConfigurationIface; 84873df0db0SJames Feist } 849711ac7a9SEd Tanous bool ifaceFound = false; 850711ac7a9SEd Tanous for (const auto& iface : managedItem->second) 851711ac7a9SEd Tanous { 852711ac7a9SEd Tanous if (iface.first == interface) 853711ac7a9SEd Tanous { 854711ac7a9SEd Tanous ifaceFound = true; 855711ac7a9SEd Tanous for (const auto& prop : iface.second) 856711ac7a9SEd Tanous { 857711ac7a9SEd Tanous if (prop.first == "Profiles") 858711ac7a9SEd Tanous { 859711ac7a9SEd Tanous const std::vector<std::string>* curProfiles = 860711ac7a9SEd Tanous std::get_if<std::vector<std::string>>( 861711ac7a9SEd Tanous &(prop.second)); 862711ac7a9SEd Tanous if (curProfiles == nullptr) 863711ac7a9SEd Tanous { 86462598e31SEd Tanous BMCWEB_LOG_ERROR( 86562598e31SEd Tanous "Illegal profiles in managed object"); 866711ac7a9SEd Tanous messages::internalError(response->res); 867711ac7a9SEd Tanous return CreatePIDRet::fail; 868711ac7a9SEd Tanous } 869711ac7a9SEd Tanous if (std::find(curProfiles->begin(), 870711ac7a9SEd Tanous curProfiles->end(), 871711ac7a9SEd Tanous profile) == curProfiles->end()) 872711ac7a9SEd Tanous { 873711ac7a9SEd Tanous std::vector<std::string> newProfiles = 874711ac7a9SEd Tanous *curProfiles; 875711ac7a9SEd Tanous newProfiles.push_back(profile); 876b9d36b47SEd Tanous output.emplace_back("Profiles", newProfiles); 877711ac7a9SEd Tanous } 878711ac7a9SEd Tanous } 879711ac7a9SEd Tanous } 880711ac7a9SEd Tanous } 881711ac7a9SEd Tanous } 882711ac7a9SEd Tanous 883711ac7a9SEd Tanous if (!ifaceFound) 88473df0db0SJames Feist { 88562598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find interface in managed object"); 88673df0db0SJames Feist messages::internalError(response->res); 88773df0db0SJames Feist return CreatePIDRet::fail; 88873df0db0SJames Feist } 88973df0db0SJames Feist } 89073df0db0SJames Feist } 89173df0db0SJames Feist 89283ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 89383ff9ab6SJames Feist { 89483ff9ab6SJames Feist if (createNewObject) 89583ff9ab6SJames Feist { 896b9d36b47SEd Tanous output.emplace_back("Class", 897b9d36b47SEd Tanous type == "PidControllers" ? "temp" : "fan"); 898b9d36b47SEd Tanous output.emplace_back("Type", "Pid"); 89983ff9ab6SJames Feist } 9005f2caaefSJames Feist 9015f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 9025f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 9035f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 9045f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 905b943aaefSJames Feist std::optional<std::string> setpointOffset; 9065f2caaefSJames Feist if (!redfish::json_util::readJson( 907b6baeaa4SJames Feist it.value(), response->res, "Inputs", inputs, "Outputs", outputs, 9085f2caaefSJames Feist "Zones", zones, "FFGainCoefficient", 9095f2caaefSJames Feist doubles["FFGainCoefficient"], "FFOffCoefficient", 9105f2caaefSJames Feist doubles["FFOffCoefficient"], "ICoefficient", 9115f2caaefSJames Feist doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], 9125f2caaefSJames Feist "ILimitMin", doubles["ILimitMin"], "OutLimitMax", 9135f2caaefSJames Feist doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], 9145f2caaefSJames Feist "PCoefficient", doubles["PCoefficient"], "SetPoint", 915b943aaefSJames Feist doubles["SetPoint"], "SetPointOffset", setpointOffset, 916b943aaefSJames Feist "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"], 917b943aaefSJames Feist "PositiveHysteresis", doubles["PositiveHysteresis"], 918b943aaefSJames Feist "NegativeHysteresis", doubles["NegativeHysteresis"])) 91983ff9ab6SJames Feist { 9205f2caaefSJames Feist return CreatePIDRet::fail; 92183ff9ab6SJames Feist } 9225f2caaefSJames Feist if (zones) 9235f2caaefSJames Feist { 9245f2caaefSJames Feist std::vector<std::string> zonesStr; 9255f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 9265f2caaefSJames Feist { 92762598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Zones"); 9285f2caaefSJames Feist return CreatePIDRet::fail; 9295f2caaefSJames Feist } 930b6baeaa4SJames Feist if (chassis.empty() && 931e662eae8SEd Tanous findChassis(managedObj, zonesStr[0], chassis) == nullptr) 932b6baeaa4SJames Feist { 93362598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 934ace85d60SEd Tanous messages::invalidObject( 935ef4c65b7SEd Tanous response->res, 936ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 937b6baeaa4SJames Feist return CreatePIDRet::fail; 938b6baeaa4SJames Feist } 939b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStr)); 9405f2caaefSJames Feist } 941afb9ee06SEd Tanous 942afb9ee06SEd Tanous if (inputs) 9435f2caaefSJames Feist { 944afb9ee06SEd Tanous for (std::string& value : *inputs) 94583ff9ab6SJames Feist { 946a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 94783ff9ab6SJames Feist } 948afb9ee06SEd Tanous output.emplace_back("Inputs", *inputs); 949afb9ee06SEd Tanous } 950afb9ee06SEd Tanous 951afb9ee06SEd Tanous if (outputs) 9525f2caaefSJames Feist { 953afb9ee06SEd Tanous for (std::string& value : *outputs) 9545f2caaefSJames Feist { 955afb9ee06SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 9565f2caaefSJames Feist } 957afb9ee06SEd Tanous output.emplace_back("Outputs", *outputs); 95883ff9ab6SJames Feist } 95983ff9ab6SJames Feist 960b943aaefSJames Feist if (setpointOffset) 961b943aaefSJames Feist { 962b943aaefSJames Feist // translate between redfish and dbus names 963b943aaefSJames Feist if (*setpointOffset == "UpperThresholdNonCritical") 964b943aaefSJames Feist { 965b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningLow"); 966b943aaefSJames Feist } 967b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdNonCritical") 968b943aaefSJames Feist { 969b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningHigh"); 970b943aaefSJames Feist } 971b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdCritical") 972b943aaefSJames Feist { 973b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalLow"); 974b943aaefSJames Feist } 975b943aaefSJames Feist else if (*setpointOffset == "UpperThresholdCritical") 976b943aaefSJames Feist { 977b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalHigh"); 978b943aaefSJames Feist } 979b943aaefSJames Feist else 980b943aaefSJames Feist { 98162598e31SEd Tanous BMCWEB_LOG_ERROR("Invalid setpointoffset {}", *setpointOffset); 982ace85d60SEd Tanous messages::propertyValueNotInList(response->res, it.key(), 983ace85d60SEd Tanous "SetPointOffset"); 984b943aaefSJames Feist return CreatePIDRet::fail; 985b943aaefSJames Feist } 986b943aaefSJames Feist } 987b943aaefSJames Feist 98883ff9ab6SJames Feist // doubles 9895f2caaefSJames Feist for (const auto& pairs : doubles) 99083ff9ab6SJames Feist { 9915f2caaefSJames Feist if (!pairs.second) 99283ff9ab6SJames Feist { 9935f2caaefSJames Feist continue; 99483ff9ab6SJames Feist } 99562598e31SEd Tanous BMCWEB_LOG_DEBUG("{} = {}", pairs.first, *pairs.second); 996b9d36b47SEd Tanous output.emplace_back(pairs.first, *pairs.second); 9975f2caaefSJames Feist } 99883ff9ab6SJames Feist } 99983ff9ab6SJames Feist 100083ff9ab6SJames Feist else if (type == "FanZones") 100183ff9ab6SJames Feist { 1002b9d36b47SEd Tanous output.emplace_back("Type", "Pid.Zone"); 100383ff9ab6SJames Feist 10045f2caaefSJames Feist std::optional<nlohmann::json> chassisContainer; 10055f2caaefSJames Feist std::optional<double> failSafePercent; 1006d3ec07f8SJames Feist std::optional<double> minThermalOutput; 1007b6baeaa4SJames Feist if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", 10085f2caaefSJames Feist chassisContainer, "FailSafePercent", 1009d3ec07f8SJames Feist failSafePercent, "MinThermalOutput", 1010d3ec07f8SJames Feist minThermalOutput)) 101183ff9ab6SJames Feist { 101283ff9ab6SJames Feist return CreatePIDRet::fail; 101383ff9ab6SJames Feist } 10145f2caaefSJames Feist 10155f2caaefSJames Feist if (chassisContainer) 101683ff9ab6SJames Feist { 10175f2caaefSJames Feist std::string chassisId; 10185f2caaefSJames Feist if (!redfish::json_util::readJson(*chassisContainer, response->res, 10195f2caaefSJames Feist "@odata.id", chassisId)) 10205f2caaefSJames Feist { 102183ff9ab6SJames Feist return CreatePIDRet::fail; 102283ff9ab6SJames Feist } 102383ff9ab6SJames Feist 1024717794d5SAppaRao Puli // /redfish/v1/chassis/chassis_name/ 10255f2caaefSJames Feist if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) 102683ff9ab6SJames Feist { 102762598e31SEd Tanous BMCWEB_LOG_ERROR("Got invalid path {}", chassisId); 1028ace85d60SEd Tanous messages::invalidObject( 1029ef4c65b7SEd Tanous response->res, 1030ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId)); 103183ff9ab6SJames Feist return CreatePIDRet::fail; 103283ff9ab6SJames Feist } 103383ff9ab6SJames Feist } 1034d3ec07f8SJames Feist if (minThermalOutput) 103583ff9ab6SJames Feist { 1036b9d36b47SEd Tanous output.emplace_back("MinThermalOutput", *minThermalOutput); 10375f2caaefSJames Feist } 10385f2caaefSJames Feist if (failSafePercent) 103983ff9ab6SJames Feist { 1040b9d36b47SEd Tanous output.emplace_back("FailSafePercent", *failSafePercent); 10415f2caaefSJames Feist } 10425f2caaefSJames Feist } 10435f2caaefSJames Feist else if (type == "StepwiseControllers") 10445f2caaefSJames Feist { 1045b9d36b47SEd Tanous output.emplace_back("Type", "Stepwise"); 10465f2caaefSJames Feist 10475f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 10485f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> steps; 10495f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 10505f2caaefSJames Feist std::optional<double> positiveHysteresis; 10515f2caaefSJames Feist std::optional<double> negativeHysteresis; 1052c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 10535f2caaefSJames Feist if (!redfish::json_util::readJson( 1054b6baeaa4SJames Feist it.value(), response->res, "Zones", zones, "Steps", steps, 1055b6baeaa4SJames Feist "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, 1056c33a90ecSJames Feist "NegativeHysteresis", negativeHysteresis, "Direction", 1057c33a90ecSJames Feist direction)) 10585f2caaefSJames Feist { 105983ff9ab6SJames Feist return CreatePIDRet::fail; 106083ff9ab6SJames Feist } 10615f2caaefSJames Feist 10625f2caaefSJames Feist if (zones) 106383ff9ab6SJames Feist { 1064b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 1065b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 10665f2caaefSJames Feist { 106762598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Zones"); 106883ff9ab6SJames Feist return CreatePIDRet::fail; 106983ff9ab6SJames Feist } 1070b6baeaa4SJames Feist if (chassis.empty() && 1071e662eae8SEd Tanous findChassis(managedObj, zonesStrs[0], chassis) == nullptr) 1072b6baeaa4SJames Feist { 107362598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config patch"); 1074ace85d60SEd Tanous messages::invalidObject( 1075ef4c65b7SEd Tanous response->res, 1076ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 1077b6baeaa4SJames Feist return CreatePIDRet::fail; 1078b6baeaa4SJames Feist } 1079b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStrs)); 10805f2caaefSJames Feist } 10815f2caaefSJames Feist if (steps) 10825f2caaefSJames Feist { 10835f2caaefSJames Feist std::vector<double> readings; 10845f2caaefSJames Feist std::vector<double> outputs; 10855f2caaefSJames Feist for (auto& step : *steps) 10865f2caaefSJames Feist { 1087543f4400SEd Tanous double target = 0.0; 1088543f4400SEd Tanous double out = 0.0; 10895f2caaefSJames Feist 10905f2caaefSJames Feist if (!redfish::json_util::readJson(step, response->res, "Target", 109123a21a1cSEd Tanous target, "Output", out)) 10925f2caaefSJames Feist { 10935f2caaefSJames Feist return CreatePIDRet::fail; 10945f2caaefSJames Feist } 10955f2caaefSJames Feist readings.emplace_back(target); 109623a21a1cSEd Tanous outputs.emplace_back(out); 10975f2caaefSJames Feist } 1098b9d36b47SEd Tanous output.emplace_back("Reading", std::move(readings)); 1099b9d36b47SEd Tanous output.emplace_back("Output", std::move(outputs)); 11005f2caaefSJames Feist } 11015f2caaefSJames Feist if (inputs) 11025f2caaefSJames Feist { 11035f2caaefSJames Feist for (std::string& value : *inputs) 11045f2caaefSJames Feist { 1105a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 11065f2caaefSJames Feist } 1107b9d36b47SEd Tanous output.emplace_back("Inputs", std::move(*inputs)); 11085f2caaefSJames Feist } 11095f2caaefSJames Feist if (negativeHysteresis) 11105f2caaefSJames Feist { 1111b9d36b47SEd Tanous output.emplace_back("NegativeHysteresis", *negativeHysteresis); 11125f2caaefSJames Feist } 11135f2caaefSJames Feist if (positiveHysteresis) 11145f2caaefSJames Feist { 1115b9d36b47SEd Tanous output.emplace_back("PositiveHysteresis", *positiveHysteresis); 111683ff9ab6SJames Feist } 1117c33a90ecSJames Feist if (direction) 1118c33a90ecSJames Feist { 1119c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 1120c33a90ecSJames Feist "Ceiling", "Floor"}; 11213544d2a7SEd Tanous if (std::ranges::find(allowedDirections, *direction) == 11223544d2a7SEd Tanous allowedDirections.end()) 1123c33a90ecSJames Feist { 1124c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 1125c33a90ecSJames Feist *direction); 1126c33a90ecSJames Feist return CreatePIDRet::fail; 1127c33a90ecSJames Feist } 1128b9d36b47SEd Tanous output.emplace_back("Class", *direction); 1129c33a90ecSJames Feist } 113083ff9ab6SJames Feist } 113183ff9ab6SJames Feist else 113283ff9ab6SJames Feist { 113362598e31SEd Tanous BMCWEB_LOG_ERROR("Illegal Type {}", type); 113435a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 113583ff9ab6SJames Feist return CreatePIDRet::fail; 113683ff9ab6SJames Feist } 113783ff9ab6SJames Feist return CreatePIDRet::patch; 113883ff9ab6SJames Feist } 113973df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 114073df0db0SJames Feist { 11416936afe4SEd Tanous struct CompletionValues 11426936afe4SEd Tanous { 11436936afe4SEd Tanous std::vector<std::string> supportedProfiles; 11446936afe4SEd Tanous std::string currentProfile; 11456936afe4SEd Tanous dbus::utility::MapperGetSubTreeResponse subtree; 11466936afe4SEd Tanous }; 114783ff9ab6SJames Feist 11484e23a444SEd Tanous explicit GetPIDValues( 11494e23a444SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : 115023a21a1cSEd Tanous asyncResp(asyncRespIn) 115173df0db0SJames Feist 11521214b7e7SGunnar Mills {} 11539c310685SBorawski.Lukasz 115473df0db0SJames Feist void run() 11555b4aa86bSJames Feist { 115673df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 115773df0db0SJames Feist 115873df0db0SJames Feist // get all configurations 1159e99073f5SGeorge Liu constexpr std::array<std::string_view, 4> interfaces = { 1160e99073f5SGeorge Liu pidConfigurationIface, pidZoneConfigurationIface, 1161e99073f5SGeorge Liu objectManagerIface, stepwiseConfigurationIface}; 1162e99073f5SGeorge Liu dbus::utility::getSubTree( 1163e99073f5SGeorge Liu "/", 0, interfaces, 1164b9d36b47SEd Tanous [self]( 1165e99073f5SGeorge Liu const boost::system::error_code& ec, 1166b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 11675b4aa86bSJames Feist if (ec) 11685b4aa86bSJames Feist { 116962598e31SEd Tanous BMCWEB_LOG_ERROR("{}", ec); 117073df0db0SJames Feist messages::internalError(self->asyncResp->res); 117173df0db0SJames Feist return; 117273df0db0SJames Feist } 11736936afe4SEd Tanous self->complete.subtree = subtreeLocal; 1174e99073f5SGeorge Liu }); 117573df0db0SJames Feist 117673df0db0SJames Feist // at the same time get the selected profile 1177e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1178e99073f5SGeorge Liu thermalModeIface}; 1179e99073f5SGeorge Liu dbus::utility::getSubTree( 1180e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1181b9d36b47SEd Tanous [self]( 1182e99073f5SGeorge Liu const boost::system::error_code& ec, 1183b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 118423a21a1cSEd Tanous if (ec || subtreeLocal.empty()) 118573df0db0SJames Feist { 118673df0db0SJames Feist return; 118773df0db0SJames Feist } 118823a21a1cSEd Tanous if (subtreeLocal[0].second.size() != 1) 118973df0db0SJames Feist { 119073df0db0SJames Feist // invalid mapper response, should never happen 119162598e31SEd Tanous BMCWEB_LOG_ERROR("GetPIDValues: Mapper Error"); 119273df0db0SJames Feist messages::internalError(self->asyncResp->res); 11935b4aa86bSJames Feist return; 11945b4aa86bSJames Feist } 11955b4aa86bSJames Feist 119623a21a1cSEd Tanous const std::string& path = subtreeLocal[0].first; 119723a21a1cSEd Tanous const std::string& owner = subtreeLocal[0].second[0].first; 1198fac6e53bSKrzysztof Grobelny 1199fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1200fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 1201168e20c1SEd Tanous [path, owner, 12025e7e2dc5SEd Tanous self](const boost::system::error_code& ec2, 1203b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 120423a21a1cSEd Tanous if (ec2) 120573df0db0SJames Feist { 120662598e31SEd Tanous BMCWEB_LOG_ERROR( 120762598e31SEd Tanous "GetPIDValues: Can't get thermalModeIface {}", path); 120873df0db0SJames Feist messages::internalError(self->asyncResp->res); 120973df0db0SJames Feist return; 121073df0db0SJames Feist } 1211fac6e53bSKrzysztof Grobelny 1212271584abSEd Tanous const std::string* current = nullptr; 1213271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1214fac6e53bSKrzysztof Grobelny 1215fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1216fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Current", current, 1217fac6e53bSKrzysztof Grobelny "Supported", supported); 1218fac6e53bSKrzysztof Grobelny 1219fac6e53bSKrzysztof Grobelny if (!success) 122073df0db0SJames Feist { 1221002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 122273df0db0SJames Feist return; 122373df0db0SJames Feist } 1224fac6e53bSKrzysztof Grobelny 122573df0db0SJames Feist if (current == nullptr || supported == nullptr) 122673df0db0SJames Feist { 122762598e31SEd Tanous BMCWEB_LOG_ERROR( 122862598e31SEd Tanous "GetPIDValues: thermal mode iface invalid {}", path); 122973df0db0SJames Feist messages::internalError(self->asyncResp->res); 123073df0db0SJames Feist return; 123173df0db0SJames Feist } 12326936afe4SEd Tanous self->complete.currentProfile = *current; 12336936afe4SEd Tanous self->complete.supportedProfiles = *supported; 1234fac6e53bSKrzysztof Grobelny }); 1235e99073f5SGeorge Liu }); 123673df0db0SJames Feist } 123773df0db0SJames Feist 12386936afe4SEd Tanous static void 12396936afe4SEd Tanous processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12406936afe4SEd Tanous const CompletionValues& completion) 124173df0db0SJames Feist { 124273df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 124373df0db0SJames Feist { 124473df0db0SJames Feist return; 124573df0db0SJames Feist } 12465b4aa86bSJames Feist // create map of <connection, path to objMgr>> 12476936afe4SEd Tanous boost::container::flat_map< 12486936afe4SEd Tanous std::string, std::string, std::less<>, 12496936afe4SEd Tanous std::vector<std::pair<std::string, std::string>>> 12506936afe4SEd Tanous objectMgrPaths; 12516936afe4SEd Tanous boost::container::flat_set<std::string, std::less<>, 12526936afe4SEd Tanous std::vector<std::string>> 12536936afe4SEd Tanous calledConnections; 12546936afe4SEd Tanous for (const auto& pathGroup : completion.subtree) 12555b4aa86bSJames Feist { 12565b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 12575b4aa86bSJames Feist { 12586bce33bcSJames Feist auto findConnection = 12596bce33bcSJames Feist calledConnections.find(connectionGroup.first); 12606bce33bcSJames Feist if (findConnection != calledConnections.end()) 12616bce33bcSJames Feist { 12626bce33bcSJames Feist break; 12636bce33bcSJames Feist } 126473df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 12655b4aa86bSJames Feist { 12665b4aa86bSJames Feist if (interface == objectManagerIface) 12675b4aa86bSJames Feist { 126873df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 12695b4aa86bSJames Feist } 12705b4aa86bSJames Feist // this list is alphabetical, so we 12715b4aa86bSJames Feist // should have found the objMgr by now 12725b4aa86bSJames Feist if (interface == pidConfigurationIface || 1273b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1274b7a08d04SJames Feist interface == stepwiseConfigurationIface) 12755b4aa86bSJames Feist { 12765b4aa86bSJames Feist auto findObjMgr = 12775b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 12785b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 12795b4aa86bSJames Feist { 128062598e31SEd Tanous BMCWEB_LOG_DEBUG("{}Has no Object Manager", 128162598e31SEd Tanous connectionGroup.first); 12825b4aa86bSJames Feist continue; 12835b4aa86bSJames Feist } 12846bce33bcSJames Feist 12856bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 12866bce33bcSJames Feist 128773df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 12886936afe4SEd Tanous completion.currentProfile, 12896936afe4SEd Tanous completion.supportedProfiles, 129073df0db0SJames Feist asyncResp); 12915b4aa86bSJames Feist break; 12925b4aa86bSJames Feist } 12935b4aa86bSJames Feist } 12945b4aa86bSJames Feist } 12955b4aa86bSJames Feist } 129673df0db0SJames Feist } 129773df0db0SJames Feist 12986936afe4SEd Tanous ~GetPIDValues() 12996936afe4SEd Tanous { 13006936afe4SEd Tanous boost::asio::post(crow::connections::systemBus->get_io_context(), 13016936afe4SEd Tanous std::bind_front(&processingComplete, asyncResp, 13026936afe4SEd Tanous std::move(complete))); 13036936afe4SEd Tanous } 13046936afe4SEd Tanous 1305ecd6a3a2SEd Tanous GetPIDValues(const GetPIDValues&) = delete; 1306ecd6a3a2SEd Tanous GetPIDValues(GetPIDValues&&) = delete; 1307ecd6a3a2SEd Tanous GetPIDValues& operator=(const GetPIDValues&) = delete; 1308ecd6a3a2SEd Tanous GetPIDValues& operator=(GetPIDValues&&) = delete; 1309ecd6a3a2SEd Tanous 13108d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 13116936afe4SEd Tanous CompletionValues complete; 131273df0db0SJames Feist }; 131373df0db0SJames Feist 131473df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 131573df0db0SJames Feist { 13168d1b46d7Szhanghch05 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, 131773df0db0SJames Feist nlohmann::json& data) : 1318271584abSEd Tanous asyncResp(asyncRespIn) 131973df0db0SJames Feist { 132073df0db0SJames Feist std::optional<nlohmann::json> pidControllers; 132173df0db0SJames Feist std::optional<nlohmann::json> fanControllers; 132273df0db0SJames Feist std::optional<nlohmann::json> fanZones; 132373df0db0SJames Feist std::optional<nlohmann::json> stepwiseControllers; 132473df0db0SJames Feist 132573df0db0SJames Feist if (!redfish::json_util::readJson( 132673df0db0SJames Feist data, asyncResp->res, "PidControllers", pidControllers, 132773df0db0SJames Feist "FanControllers", fanControllers, "FanZones", fanZones, 132873df0db0SJames Feist "StepwiseControllers", stepwiseControllers, "Profile", profile)) 132973df0db0SJames Feist { 133073df0db0SJames Feist return; 133173df0db0SJames Feist } 133273df0db0SJames Feist configuration.emplace_back("PidControllers", std::move(pidControllers)); 133373df0db0SJames Feist configuration.emplace_back("FanControllers", std::move(fanControllers)); 133473df0db0SJames Feist configuration.emplace_back("FanZones", std::move(fanZones)); 133573df0db0SJames Feist configuration.emplace_back("StepwiseControllers", 133673df0db0SJames Feist std::move(stepwiseControllers)); 133773df0db0SJames Feist } 1338ecd6a3a2SEd Tanous 1339ecd6a3a2SEd Tanous SetPIDValues(const SetPIDValues&) = delete; 1340ecd6a3a2SEd Tanous SetPIDValues(SetPIDValues&&) = delete; 1341ecd6a3a2SEd Tanous SetPIDValues& operator=(const SetPIDValues&) = delete; 1342ecd6a3a2SEd Tanous SetPIDValues& operator=(SetPIDValues&&) = delete; 1343ecd6a3a2SEd Tanous 134473df0db0SJames Feist void run() 134573df0db0SJames Feist { 134673df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 134773df0db0SJames Feist { 134873df0db0SJames Feist return; 134973df0db0SJames Feist } 135073df0db0SJames Feist 135173df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 135273df0db0SJames Feist 135373df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 135473df0db0SJames Feist // interface gets more traction 13555eb468daSGeorge Liu sdbusplus::message::object_path objPath( 13565eb468daSGeorge Liu "/xyz/openbmc_project/inventory"); 13575eb468daSGeorge Liu dbus::utility::getManagedObjects( 13585eb468daSGeorge Liu "xyz.openbmc_project.EntityManager", objPath, 13595e7e2dc5SEd Tanous [self](const boost::system::error_code& ec, 1360914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& mObj) { 136173df0db0SJames Feist if (ec) 136273df0db0SJames Feist { 136362598e31SEd Tanous BMCWEB_LOG_ERROR("Error communicating to Entity Manager"); 136473df0db0SJames Feist messages::internalError(self->asyncResp->res); 136573df0db0SJames Feist return; 136673df0db0SJames Feist } 1367e69d9de2SJames Feist const std::array<const char*, 3> configurations = { 1368e69d9de2SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 1369e69d9de2SJames Feist stepwiseConfigurationIface}; 1370e69d9de2SJames Feist 137114b0b8d5SJames Feist for (const auto& [path, object] : mObj) 1372e69d9de2SJames Feist { 137314b0b8d5SJames Feist for (const auto& [interface, _] : object) 1374e69d9de2SJames Feist { 13753544d2a7SEd Tanous if (std::ranges::find(configurations, interface) != 13763544d2a7SEd Tanous configurations.end()) 1377e69d9de2SJames Feist { 137814b0b8d5SJames Feist self->objectCount++; 1379e69d9de2SJames Feist break; 1380e69d9de2SJames Feist } 1381e69d9de2SJames Feist } 1382e69d9de2SJames Feist } 1383914e2d5dSEd Tanous self->managedObj = mObj; 13845eb468daSGeorge Liu }); 138573df0db0SJames Feist 138673df0db0SJames Feist // at the same time get the profile information 1387e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1388e99073f5SGeorge Liu thermalModeIface}; 1389e99073f5SGeorge Liu dbus::utility::getSubTree( 1390e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1391e99073f5SGeorge Liu [self](const boost::system::error_code& ec, 1392b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 139373df0db0SJames Feist if (ec || subtree.empty()) 139473df0db0SJames Feist { 139573df0db0SJames Feist return; 139673df0db0SJames Feist } 139773df0db0SJames Feist if (subtree[0].second.empty()) 139873df0db0SJames Feist { 139973df0db0SJames Feist // invalid mapper response, should never happen 140062598e31SEd Tanous BMCWEB_LOG_ERROR("SetPIDValues: Mapper Error"); 140173df0db0SJames Feist messages::internalError(self->asyncResp->res); 140273df0db0SJames Feist return; 140373df0db0SJames Feist } 140473df0db0SJames Feist 140573df0db0SJames Feist const std::string& path = subtree[0].first; 140673df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 1407fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1408fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 14095e7e2dc5SEd Tanous [self, path, owner](const boost::system::error_code& ec2, 1410b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& r) { 1411cb13a392SEd Tanous if (ec2) 141273df0db0SJames Feist { 141362598e31SEd Tanous BMCWEB_LOG_ERROR( 141462598e31SEd Tanous "SetPIDValues: Can't get thermalModeIface {}", path); 141573df0db0SJames Feist messages::internalError(self->asyncResp->res); 141673df0db0SJames Feist return; 141773df0db0SJames Feist } 1418271584abSEd Tanous const std::string* current = nullptr; 1419271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1420fac6e53bSKrzysztof Grobelny 1421fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1422fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), r, "Current", current, 1423fac6e53bSKrzysztof Grobelny "Supported", supported); 1424fac6e53bSKrzysztof Grobelny 1425fac6e53bSKrzysztof Grobelny if (!success) 142673df0db0SJames Feist { 1427002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 142873df0db0SJames Feist return; 142973df0db0SJames Feist } 1430fac6e53bSKrzysztof Grobelny 143173df0db0SJames Feist if (current == nullptr || supported == nullptr) 143273df0db0SJames Feist { 143362598e31SEd Tanous BMCWEB_LOG_ERROR( 143462598e31SEd Tanous "SetPIDValues: thermal mode iface invalid {}", path); 143573df0db0SJames Feist messages::internalError(self->asyncResp->res); 143673df0db0SJames Feist return; 143773df0db0SJames Feist } 143873df0db0SJames Feist self->currentProfile = *current; 143973df0db0SJames Feist self->supportedProfiles = *supported; 144073df0db0SJames Feist self->profileConnection = owner; 144173df0db0SJames Feist self->profilePath = path; 1442fac6e53bSKrzysztof Grobelny }); 1443e99073f5SGeorge Liu }); 144473df0db0SJames Feist } 144524b2fe81SEd Tanous void pidSetDone() 144673df0db0SJames Feist { 144773df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 144873df0db0SJames Feist { 144973df0db0SJames Feist return; 14505b4aa86bSJames Feist } 14518d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; 145273df0db0SJames Feist if (profile) 145373df0db0SJames Feist { 14543544d2a7SEd Tanous if (std::ranges::find(supportedProfiles, *profile) == 14553544d2a7SEd Tanous supportedProfiles.end()) 145673df0db0SJames Feist { 145773df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 145873df0db0SJames Feist *profile); 145973df0db0SJames Feist return; 146073df0db0SJames Feist } 146173df0db0SJames Feist currentProfile = *profile; 14629ae226faSGeorge Liu sdbusplus::asio::setProperty( 14639ae226faSGeorge Liu *crow::connections::systemBus, profileConnection, profilePath, 14649ae226faSGeorge Liu thermalModeIface, "Current", *profile, 14655e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 146673df0db0SJames Feist if (ec) 146773df0db0SJames Feist { 146862598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching profile{}", ec); 146973df0db0SJames Feist messages::internalError(response->res); 147073df0db0SJames Feist } 14719ae226faSGeorge Liu }); 147273df0db0SJames Feist } 147373df0db0SJames Feist 147473df0db0SJames Feist for (auto& containerPair : configuration) 147573df0db0SJames Feist { 147673df0db0SJames Feist auto& container = containerPair.second; 147773df0db0SJames Feist if (!container) 147873df0db0SJames Feist { 147973df0db0SJames Feist continue; 148073df0db0SJames Feist } 148162598e31SEd Tanous BMCWEB_LOG_DEBUG("{}", *container); 14826ee7f774SJames Feist 148302cad96eSEd Tanous const std::string& type = containerPair.first; 148473df0db0SJames Feist 148573df0db0SJames Feist for (nlohmann::json::iterator it = container->begin(); 148617a897dfSManojkiran Eda it != container->end(); ++it) 148773df0db0SJames Feist { 148873df0db0SJames Feist const auto& name = it.key(); 1489cddbf3dfSPotin Lai std::string dbusObjName = name; 1490cddbf3dfSPotin Lai std::replace(dbusObjName.begin(), dbusObjName.end(), ' ', '_'); 149162598e31SEd Tanous BMCWEB_LOG_DEBUG("looking for {}", name); 14926ee7f774SJames Feist 14933544d2a7SEd Tanous auto pathItr = std::ranges::find_if( 14943544d2a7SEd Tanous managedObj, [&dbusObjName](const auto& obj) { 1495002d39b4SEd Tanous return boost::algorithm::ends_with(obj.first.str, 1496cddbf3dfSPotin Lai "/" + dbusObjName); 149773df0db0SJames Feist }); 1498b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap output; 149973df0db0SJames Feist 150073df0db0SJames Feist output.reserve(16); // The pid interface length 150173df0db0SJames Feist 150273df0db0SJames Feist // determines if we're patching entity-manager or 150373df0db0SJames Feist // creating a new object 150473df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 150562598e31SEd Tanous BMCWEB_LOG_DEBUG("Found = {}", !createNewObject); 15066ee7f774SJames Feist 150773df0db0SJames Feist std::string iface; 1508ea2b670dSEd Tanous if (!createNewObject) 1509ea2b670dSEd Tanous { 15108be2b5b6SPotin Lai bool findInterface = false; 1511ea2b670dSEd Tanous for (const auto& interface : pathItr->second) 1512ea2b670dSEd Tanous { 1513ea2b670dSEd Tanous if (interface.first == pidConfigurationIface) 1514ea2b670dSEd Tanous { 1515ea2b670dSEd Tanous if (type == "PidControllers" || 1516ea2b670dSEd Tanous type == "FanControllers") 151773df0db0SJames Feist { 151873df0db0SJames Feist iface = pidConfigurationIface; 15198be2b5b6SPotin Lai findInterface = true; 15208be2b5b6SPotin Lai break; 152173df0db0SJames Feist } 152273df0db0SJames Feist } 1523ea2b670dSEd Tanous else if (interface.first == pidZoneConfigurationIface) 152473df0db0SJames Feist { 1525ea2b670dSEd Tanous if (type == "FanZones") 152673df0db0SJames Feist { 1527ea2b670dSEd Tanous iface = pidConfigurationIface; 15288be2b5b6SPotin Lai findInterface = true; 15298be2b5b6SPotin Lai break; 153073df0db0SJames Feist } 153173df0db0SJames Feist } 1532ea2b670dSEd Tanous else if (interface.first == stepwiseConfigurationIface) 1533ea2b670dSEd Tanous { 1534ea2b670dSEd Tanous if (type == "StepwiseControllers") 153573df0db0SJames Feist { 153673df0db0SJames Feist iface = stepwiseConfigurationIface; 15378be2b5b6SPotin Lai findInterface = true; 15388be2b5b6SPotin Lai break; 15398be2b5b6SPotin Lai } 15408be2b5b6SPotin Lai } 15418be2b5b6SPotin Lai } 15428be2b5b6SPotin Lai 15438be2b5b6SPotin Lai // create new object if interface not found 15448be2b5b6SPotin Lai if (!findInterface) 15458be2b5b6SPotin Lai { 154673df0db0SJames Feist createNewObject = true; 154773df0db0SJames Feist } 1548ea2b670dSEd Tanous } 15496ee7f774SJames Feist 15506ee7f774SJames Feist if (createNewObject && it.value() == nullptr) 15516ee7f774SJames Feist { 15524e0453b1SGunnar Mills // can't delete a non-existent object 1553e2616cc5SEd Tanous messages::propertyValueNotInList(response->res, it.value(), 1554e2616cc5SEd Tanous name); 15556ee7f774SJames Feist continue; 15566ee7f774SJames Feist } 15576ee7f774SJames Feist 15586ee7f774SJames Feist std::string path; 15596ee7f774SJames Feist if (pathItr != managedObj.end()) 15606ee7f774SJames Feist { 15616ee7f774SJames Feist path = pathItr->first.str; 15626ee7f774SJames Feist } 15636ee7f774SJames Feist 156462598e31SEd Tanous BMCWEB_LOG_DEBUG("Create new = {}", createNewObject); 1565e69d9de2SJames Feist 1566e69d9de2SJames Feist // arbitrary limit to avoid attacks 1567e69d9de2SJames Feist constexpr const size_t controllerLimit = 500; 156814b0b8d5SJames Feist if (createNewObject && objectCount >= controllerLimit) 1569e69d9de2SJames Feist { 1570e69d9de2SJames Feist messages::resourceExhaustion(response->res, type); 1571e69d9de2SJames Feist continue; 1572e69d9de2SJames Feist } 1573a170f275SEd Tanous std::string escaped = name; 1574a170f275SEd Tanous std::replace(escaped.begin(), escaped.end(), '_', ' '); 1575a170f275SEd Tanous output.emplace_back("Name", escaped); 157673df0db0SJames Feist 157773df0db0SJames Feist std::string chassis; 157873df0db0SJames Feist CreatePIDRet ret = createPidInterface( 15796ee7f774SJames Feist response, type, it, path, managedObj, createNewObject, 15806ee7f774SJames Feist output, chassis, currentProfile); 158173df0db0SJames Feist if (ret == CreatePIDRet::fail) 158273df0db0SJames Feist { 158373df0db0SJames Feist return; 158473df0db0SJames Feist } 15853174e4dfSEd Tanous if (ret == CreatePIDRet::del) 158673df0db0SJames Feist { 158773df0db0SJames Feist continue; 158873df0db0SJames Feist } 158973df0db0SJames Feist 159073df0db0SJames Feist if (!createNewObject) 159173df0db0SJames Feist { 159273df0db0SJames Feist for (const auto& property : output) 159373df0db0SJames Feist { 1594*7a696974SPotin Lai crow::connections::systemBus->async_method_call( 159573df0db0SJames Feist [response, 159673df0db0SJames Feist propertyName{std::string(property.first)}]( 15975e7e2dc5SEd Tanous const boost::system::error_code& ec) { 159873df0db0SJames Feist if (ec) 159973df0db0SJames Feist { 160062598e31SEd Tanous BMCWEB_LOG_ERROR("Error patching {}: {}", 160162598e31SEd Tanous propertyName, ec); 160273df0db0SJames Feist messages::internalError(response->res); 160373df0db0SJames Feist return; 160473df0db0SJames Feist } 160573df0db0SJames Feist messages::success(response->res); 1606*7a696974SPotin Lai }, 1607*7a696974SPotin Lai "xyz.openbmc_project.EntityManager", path, 1608*7a696974SPotin Lai "org.freedesktop.DBus.Properties", "Set", iface, 1609*7a696974SPotin Lai property.first, property.second); 161073df0db0SJames Feist } 161173df0db0SJames Feist } 161273df0db0SJames Feist else 161373df0db0SJames Feist { 161473df0db0SJames Feist if (chassis.empty()) 161573df0db0SJames Feist { 161662598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to get chassis from config"); 1617ace85d60SEd Tanous messages::internalError(response->res); 161873df0db0SJames Feist return; 161973df0db0SJames Feist } 162073df0db0SJames Feist 162173df0db0SJames Feist bool foundChassis = false; 162273df0db0SJames Feist for (const auto& obj : managedObj) 162373df0db0SJames Feist { 162473df0db0SJames Feist if (boost::algorithm::ends_with(obj.first.str, chassis)) 162573df0db0SJames Feist { 162673df0db0SJames Feist chassis = obj.first.str; 162773df0db0SJames Feist foundChassis = true; 162873df0db0SJames Feist break; 162973df0db0SJames Feist } 163073df0db0SJames Feist } 163173df0db0SJames Feist if (!foundChassis) 163273df0db0SJames Feist { 163362598e31SEd Tanous BMCWEB_LOG_ERROR("Failed to find chassis on dbus"); 163473df0db0SJames Feist messages::resourceMissingAtURI( 1635ace85d60SEd Tanous response->res, 1636ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", 1637ef4c65b7SEd Tanous chassis)); 163873df0db0SJames Feist return; 163973df0db0SJames Feist } 164073df0db0SJames Feist 164173df0db0SJames Feist crow::connections::systemBus->async_method_call( 16425e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 164373df0db0SJames Feist if (ec) 164473df0db0SJames Feist { 164562598e31SEd Tanous BMCWEB_LOG_ERROR("Error Adding Pid Object {}", ec); 164673df0db0SJames Feist messages::internalError(response->res); 164773df0db0SJames Feist return; 164873df0db0SJames Feist } 164973df0db0SJames Feist messages::success(response->res); 165073df0db0SJames Feist }, 165173df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 165273df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 165373df0db0SJames Feist } 165473df0db0SJames Feist } 165573df0db0SJames Feist } 165673df0db0SJames Feist } 165724b2fe81SEd Tanous 165824b2fe81SEd Tanous ~SetPIDValues() 165924b2fe81SEd Tanous { 166024b2fe81SEd Tanous try 166124b2fe81SEd Tanous { 166224b2fe81SEd Tanous pidSetDone(); 166324b2fe81SEd Tanous } 166424b2fe81SEd Tanous catch (...) 166524b2fe81SEd Tanous { 166662598e31SEd Tanous BMCWEB_LOG_CRITICAL("pidSetDone threw exception"); 166724b2fe81SEd Tanous } 166824b2fe81SEd Tanous } 166924b2fe81SEd Tanous 16708d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 167173df0db0SJames Feist std::vector<std::pair<std::string, std::optional<nlohmann::json>>> 167273df0db0SJames Feist configuration; 167373df0db0SJames Feist std::optional<std::string> profile; 167473df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 167573df0db0SJames Feist std::vector<std::string> supportedProfiles; 167673df0db0SJames Feist std::string currentProfile; 167773df0db0SJames Feist std::string profileConnection; 167873df0db0SJames Feist std::string profilePath; 167914b0b8d5SJames Feist size_t objectCount = 0; 168073df0db0SJames Feist }; 168173df0db0SJames Feist 1682071d8fdfSSunnySrivastava1984 /** 1683071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 1684071d8fdfSSunnySrivastava1984 * 1685ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 1686071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 1687071d8fdfSSunnySrivastava1984 * @param[in] path - object path 1688071d8fdfSSunnySrivastava1984 * @return none 1689071d8fdfSSunnySrivastava1984 */ 1690ac106bf6SEd Tanous inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1691071d8fdfSSunnySrivastava1984 const std::string& connectionName, 1692071d8fdfSSunnySrivastava1984 const std::string& path) 1693071d8fdfSSunnySrivastava1984 { 169462598e31SEd Tanous BMCWEB_LOG_DEBUG("Get BMC manager Location data."); 1695071d8fdfSSunnySrivastava1984 16961e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 16971e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 16981e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 1699ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 17001e1e598dSJonathan Doman const std::string& property) { 1701071d8fdfSSunnySrivastava1984 if (ec) 1702071d8fdfSSunnySrivastava1984 { 170362598e31SEd Tanous BMCWEB_LOG_DEBUG("DBUS response error for " 170462598e31SEd Tanous "Location"); 1705ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1706071d8fdfSSunnySrivastava1984 return; 1707071d8fdfSSunnySrivastava1984 } 1708071d8fdfSSunnySrivastava1984 1709ac106bf6SEd Tanous asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 17101e1e598dSJonathan Doman property; 17111e1e598dSJonathan Doman }); 1712071d8fdfSSunnySrivastava1984 } 17137e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 17147e860f15SJohn Edward Broadbent inline void 1715ac106bf6SEd Tanous managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 17164bf2b033SGunnar Mills { 171762598e31SEd Tanous BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); 17184bf2b033SGunnar Mills 17191e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint64_t>( 17201e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.BMC", 17211e1e598dSJonathan Doman "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC", 17221e1e598dSJonathan Doman "LastRebootTime", 1723ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 17241e1e598dSJonathan Doman const uint64_t lastResetTime) { 17254bf2b033SGunnar Mills if (ec) 17264bf2b033SGunnar Mills { 172762598e31SEd Tanous BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 17284bf2b033SGunnar Mills return; 17294bf2b033SGunnar Mills } 17304bf2b033SGunnar Mills 17314bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 17324bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 17331e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 17344bf2b033SGunnar Mills 17354bf2b033SGunnar Mills // Convert to ISO 8601 standard 1736ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] = 17372b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 17381e1e598dSJonathan Doman }); 17394bf2b033SGunnar Mills } 17404bf2b033SGunnar Mills 17414bfefa74SGunnar Mills /** 17424bfefa74SGunnar Mills * @brief Set the running firmware image 17434bfefa74SGunnar Mills * 1744ac106bf6SEd Tanous * @param[i,o] asyncResp - Async response object 17454bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 17464bfefa74SGunnar Mills * 17474bfefa74SGunnar Mills * @return void 17484bfefa74SGunnar Mills */ 17497e860f15SJohn Edward Broadbent inline void 1750ac106bf6SEd Tanous setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1751f23b7296SEd Tanous const std::string& runningFirmwareTarget) 17524bfefa74SGunnar Mills { 17534bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 1754f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 17554bfefa74SGunnar Mills if (idPos == std::string::npos) 17564bfefa74SGunnar Mills { 1757ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 17584bfefa74SGunnar Mills "@odata.id"); 175962598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); 17604bfefa74SGunnar Mills return; 17614bfefa74SGunnar Mills } 17624bfefa74SGunnar Mills idPos++; 17634bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 17644bfefa74SGunnar Mills { 1765ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 17664bfefa74SGunnar Mills "@odata.id"); 176762598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 17684bfefa74SGunnar Mills return; 17694bfefa74SGunnar Mills } 17704bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 17714bfefa74SGunnar Mills 17724bfefa74SGunnar Mills // Make sure the image is valid before setting priority 17735eb468daSGeorge Liu sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); 17745eb468daSGeorge Liu dbus::utility::getManagedObjects( 17755eb468daSGeorge Liu "xyz.openbmc_project.Software.BMC.Updater", objPath, 17765eb468daSGeorge Liu [asyncResp, firmwareId, runningFirmwareTarget]( 17775eb468daSGeorge Liu const boost::system::error_code& ec, 17785eb468daSGeorge Liu const dbus::utility::ManagedObjectType& subtree) { 17794bfefa74SGunnar Mills if (ec) 17804bfefa74SGunnar Mills { 178162598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); 1782ac106bf6SEd Tanous messages::internalError(asyncResp->res); 17834bfefa74SGunnar Mills return; 17844bfefa74SGunnar Mills } 17854bfefa74SGunnar Mills 178626f6976fSEd Tanous if (subtree.empty()) 17874bfefa74SGunnar Mills { 178862598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find image!"); 1789ac106bf6SEd Tanous messages::internalError(asyncResp->res); 17904bfefa74SGunnar Mills return; 17914bfefa74SGunnar Mills } 17924bfefa74SGunnar Mills 17934bfefa74SGunnar Mills bool foundImage = false; 179402cad96eSEd Tanous for (const auto& object : subtree) 17954bfefa74SGunnar Mills { 17964bfefa74SGunnar Mills const std::string& path = 17974bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 1798f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 17994bfefa74SGunnar Mills 18004bfefa74SGunnar Mills if (idPos2 == std::string::npos) 18014bfefa74SGunnar Mills { 18024bfefa74SGunnar Mills continue; 18034bfefa74SGunnar Mills } 18044bfefa74SGunnar Mills 18054bfefa74SGunnar Mills idPos2++; 18064bfefa74SGunnar Mills if (idPos2 >= path.size()) 18074bfefa74SGunnar Mills { 18084bfefa74SGunnar Mills continue; 18094bfefa74SGunnar Mills } 18104bfefa74SGunnar Mills 18114bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 18124bfefa74SGunnar Mills { 18134bfefa74SGunnar Mills foundImage = true; 18144bfefa74SGunnar Mills break; 18154bfefa74SGunnar Mills } 18164bfefa74SGunnar Mills } 18174bfefa74SGunnar Mills 18184bfefa74SGunnar Mills if (!foundImage) 18194bfefa74SGunnar Mills { 1820ac106bf6SEd Tanous messages::propertyValueNotInList( 1821ac106bf6SEd Tanous asyncResp->res, runningFirmwareTarget, "@odata.id"); 182262598e31SEd Tanous BMCWEB_LOG_DEBUG("Invalid firmware ID."); 18234bfefa74SGunnar Mills return; 18244bfefa74SGunnar Mills } 18254bfefa74SGunnar Mills 182662598e31SEd Tanous BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.", 182762598e31SEd Tanous firmwareId); 18284bfefa74SGunnar Mills 18294bfefa74SGunnar Mills // Only support Immediate 18304bfefa74SGunnar Mills // An addition could be a Redfish Setting like 18314bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 18329ae226faSGeorge Liu sdbusplus::asio::setProperty( 18339ae226faSGeorge Liu *crow::connections::systemBus, 18349ae226faSGeorge Liu "xyz.openbmc_project.Software.BMC.Updater", 18359ae226faSGeorge Liu "/xyz/openbmc_project/software/" + firmwareId, 18369ae226faSGeorge Liu "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 18379ae226faSGeorge Liu static_cast<uint8_t>(0), 1838ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2) { 18398a592810SEd Tanous if (ec2) 18404bfefa74SGunnar Mills { 184162598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error setting."); 1842ac106bf6SEd Tanous messages::internalError(asyncResp->res); 18434bfefa74SGunnar Mills return; 18444bfefa74SGunnar Mills } 1845ac106bf6SEd Tanous doBMCGracefulRestart(asyncResp); 18469ae226faSGeorge Liu }); 18475eb468daSGeorge Liu }); 18484bfefa74SGunnar Mills } 18494bfefa74SGunnar Mills 1850ac106bf6SEd Tanous inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 18517e860f15SJohn Edward Broadbent std::string datetime) 1852af5d6058SSantosh Puranik { 185362598e31SEd Tanous BMCWEB_LOG_DEBUG("Set date time: {}", datetime); 1854af5d6058SSantosh Puranik 1855c2e32007SEd Tanous std::optional<redfish::time_utils::usSinceEpoch> us = 1856c2e32007SEd Tanous redfish::time_utils::dateStringToEpoch(datetime); 1857c2e32007SEd Tanous if (!us) 1858af5d6058SSantosh Puranik { 1859ac106bf6SEd Tanous messages::propertyValueFormatError(asyncResp->res, datetime, 1860ac106bf6SEd Tanous "DateTime"); 1861c2e32007SEd Tanous return; 1862c2e32007SEd Tanous } 18639ae226faSGeorge Liu sdbusplus::asio::setProperty( 18649ae226faSGeorge Liu *crow::connections::systemBus, "xyz.openbmc_project.Time.Manager", 18659ae226faSGeorge Liu "/xyz/openbmc_project/time/bmc", "xyz.openbmc_project.Time.EpochTime", 18669ae226faSGeorge Liu "Elapsed", us->count(), 1867ac106bf6SEd Tanous [asyncResp{std::move(asyncResp)}, 18685e7e2dc5SEd Tanous datetime{std::move(datetime)}](const boost::system::error_code& ec) { 1869af5d6058SSantosh Puranik if (ec) 1870af5d6058SSantosh Puranik { 187162598e31SEd Tanous BMCWEB_LOG_DEBUG("Failed to set elapsed time. " 187262598e31SEd Tanous "DBUS response error {}", 187362598e31SEd Tanous ec); 1874ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1875af5d6058SSantosh Puranik return; 1876af5d6058SSantosh Puranik } 1877ac106bf6SEd Tanous asyncResp->res.jsonValue["DateTime"] = datetime; 18789ae226faSGeorge Liu }); 187983ff9ab6SJames Feist } 18809c310685SBorawski.Lukasz 188175815e5cSEd Tanous inline void 188275815e5cSEd Tanous checkForQuiesced(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 188375815e5cSEd Tanous { 188475815e5cSEd Tanous sdbusplus::asio::getProperty<std::string>( 188575815e5cSEd Tanous *crow::connections::systemBus, "org.freedesktop.systemd1", 188675815e5cSEd Tanous "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", 188775815e5cSEd Tanous "org.freedesktop.systemd1.Unit", "ActiveState", 188875815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, 188975815e5cSEd Tanous const std::string& val) { 189075815e5cSEd Tanous if (!ec) 189175815e5cSEd Tanous { 189275815e5cSEd Tanous if (val == "active") 189375815e5cSEd Tanous { 189475815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; 189575815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Quiesced"; 189675815e5cSEd Tanous return; 189775815e5cSEd Tanous } 189875815e5cSEd Tanous } 189975815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 190075815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 190175815e5cSEd Tanous }); 190275815e5cSEd Tanous } 190375815e5cSEd Tanous 19047e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 19057e860f15SJohn Edward Broadbent { 19067e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 19079c310685SBorawski.Lukasz 19087e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 1909ed398213SEd Tanous .privileges(redfish::privileges::getManager) 1910002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1911002d39b4SEd Tanous [&app, uuid](const crow::Request& req, 191245ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 19133ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 191445ca1b86SEd Tanous { 191545ca1b86SEd Tanous return; 191645ca1b86SEd Tanous } 19177e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; 1918a51fc2d2SSui Chen asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager"; 19197e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "bmc"; 19207e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 19217e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 19227e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 19237e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["PowerState"] = "On"; 19241476687dSEd Tanous 19257e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ManagerType"] = "BMC"; 19267e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 19277e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 1928002d39b4SEd Tanous asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model 19297e860f15SJohn Edward Broadbent 19301476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 19311476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices"; 19321476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 19331476687dSEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol"; 19341476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 19351476687dSEd Tanous "/redfish/v1/Managers/bmc/EthernetInterfaces"; 19367e860f15SJohn Edward Broadbent 19377e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_VM_NBDPROXY 19381476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 19391476687dSEd Tanous "/redfish/v1/Managers/bmc/VirtualMedia"; 19407e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_VM_NBDPROXY 19417e860f15SJohn Edward Broadbent 19427e860f15SJohn Edward Broadbent // default oem data 19437e860f15SJohn Edward Broadbent nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; 19447e860f15SJohn Edward Broadbent nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 19457e860f15SJohn Edward Broadbent oem["@odata.type"] = "#OemManager.Oem"; 19467e860f15SJohn Edward Broadbent oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; 19477e860f15SJohn Edward Broadbent oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; 19487e860f15SJohn Edward Broadbent oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; 19491476687dSEd Tanous 19501476687dSEd Tanous nlohmann::json::object_t certificates; 19511476687dSEd Tanous certificates["@odata.id"] = 19521476687dSEd Tanous "/redfish/v1/Managers/bmc/Truststore/Certificates"; 19531476687dSEd Tanous oemOpenbmc["Certificates"] = std::move(certificates); 19547e860f15SJohn Edward Broadbent 19557e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 19567e860f15SJohn Edward Broadbent // supports BMC reboot. 19577e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 19587e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 19597e860f15SJohn Edward Broadbent managerReset["target"] = 19607e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; 19617e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 19627e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/ResetActionInfo"; 19637e860f15SJohn Edward Broadbent 19647e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 19657e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 19667e860f15SJohn Edward Broadbent // on OpenBMC 19677e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 19687e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 19697e860f15SJohn Edward Broadbent resetToDefaults["target"] = 19707e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults"; 1971613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] = 1972613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"}); 19737e860f15SJohn Edward Broadbent 19747c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 19752b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 19767c8c4058STejas Patil 19777c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 19787c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 19797c8c4058STejas Patil redfishDateTimeOffset.second; 19807e860f15SJohn Edward Broadbent 19810e8ac5e7SGunnar Mills // TODO (Gunnar): Remove these one day since moved to ComputerSystem 19820e8ac5e7SGunnar Mills // Still used by OCP profiles 19830e8ac5e7SGunnar Mills // https://github.com/opencomputeproject/OCP-Profiles/issues/23 19847e860f15SJohn Edward Broadbent // Fill in SerialConsole info 19857e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; 1986002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 1987613dabeaSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = 1988613dabeaSEd Tanous nlohmann::json::array_t({"IPMI", "SSH"}); 19897e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_KVM 19907e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 1991002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 1992002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 1993002d39b4SEd Tanous 4; 1994613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 1995613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 19967e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_KVM 19977f3e84a1SEd Tanous if constexpr (!bmcwebEnableMultiHost) 19987f3e84a1SEd Tanous { 19997f3e84a1SEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 20007f3e84a1SEd Tanous 1; 20011476687dSEd Tanous 20021476687dSEd Tanous nlohmann::json::array_t managerForServers; 20031476687dSEd Tanous nlohmann::json::object_t manager; 20041476687dSEd Tanous manager["@odata.id"] = "/redfish/v1/Systems/system"; 2005ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager)); 20061476687dSEd Tanous 20071476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 20081476687dSEd Tanous std::move(managerForServers); 20097f3e84a1SEd Tanous } 201013451e39SWilly Tu if constexpr (bmcwebEnableHealthPopulate) 201113451e39SWilly Tu { 20127e860f15SJohn Edward Broadbent auto health = std::make_shared<HealthPopulate>(asyncResp); 20137e860f15SJohn Edward Broadbent health->isManagersHealth = true; 20147e860f15SJohn Edward Broadbent health->populate(); 201513451e39SWilly Tu } 20167e860f15SJohn Edward Broadbent 2017eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 20187e860f15SJohn Edward Broadbent "FirmwareVersion", true); 20197e860f15SJohn Edward Broadbent 20207e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 20217e860f15SJohn Edward Broadbent 2022a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 2023a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 2024a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 2025a51fc2d2SSui Chen managerDiagnosticData["@odata.id"] = 2026a51fc2d2SSui Chen "/redfish/v1/Managers/bmc/ManagerDiagnosticData"; 2027a51fc2d2SSui Chen 202854dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 20297e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp); 20307e860f15SJohn Edward Broadbent pids->run(); 203154dce7f5SGunnar Mills #endif 20327e860f15SJohn Edward Broadbent 2033002d39b4SEd Tanous getMainChassisId(asyncResp, 2034002d39b4SEd Tanous [](const std::string& chassisId, 2035002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2036002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1; 20371476687dSEd Tanous nlohmann::json::array_t managerForChassis; 20388a592810SEd Tanous nlohmann::json::object_t managerObj; 2039ef4c65b7SEd Tanous boost::urls::url chassiUrl = 2040ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 2041eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl; 2042ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj)); 20431476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 20441476687dSEd Tanous std::move(managerForChassis); 20451476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 2046eddfc437SWilly Tu chassiUrl; 20477e860f15SJohn Edward Broadbent }); 20487e860f15SJohn Edward Broadbent 20491e1e598dSJonathan Doman sdbusplus::asio::getProperty<double>( 20501e1e598dSJonathan Doman *crow::connections::systemBus, "org.freedesktop.systemd1", 2051002d39b4SEd Tanous "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", 2052002d39b4SEd Tanous "Progress", 205375815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, double val) { 20547e860f15SJohn Edward Broadbent if (ec) 20551abe55efSEd Tanous { 205662598e31SEd Tanous BMCWEB_LOG_ERROR("Error while getting progress"); 20577e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20587e860f15SJohn Edward Broadbent return; 20597e860f15SJohn Edward Broadbent } 20601e1e598dSJonathan Doman if (val < 1.0) 20617e860f15SJohn Edward Broadbent { 206275815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 2063002d39b4SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Starting"; 206475815e5cSEd Tanous return; 20657e860f15SJohn Edward Broadbent } 206675815e5cSEd Tanous checkForQuiesced(asyncResp); 20671e1e598dSJonathan Doman }); 20689c310685SBorawski.Lukasz 2069e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2070e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"}; 2071e99073f5SGeorge Liu dbus::utility::getSubTree( 2072e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 20737e860f15SJohn Edward Broadbent [asyncResp]( 2074e99073f5SGeorge Liu const boost::system::error_code& ec, 2075b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 20767e860f15SJohn Edward Broadbent if (ec) 20771abe55efSEd Tanous { 207862598e31SEd Tanous BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec); 20797e860f15SJohn Edward Broadbent return; 20807e860f15SJohn Edward Broadbent } 208126f6976fSEd Tanous if (subtree.empty()) 20827e860f15SJohn Edward Broadbent { 208362598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); 20847e860f15SJohn Edward Broadbent return; 20857e860f15SJohn Edward Broadbent } 20867e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 20877e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 20887e860f15SJohn Edward Broadbent if (subtree.size() > 1) 20897e860f15SJohn Edward Broadbent { 209062598e31SEd Tanous BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!"); 20917e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20927e860f15SJohn Edward Broadbent return; 20937e860f15SJohn Edward Broadbent } 20947e860f15SJohn Edward Broadbent 2095002d39b4SEd Tanous if (subtree[0].first.empty() || subtree[0].second.size() != 1) 20967e860f15SJohn Edward Broadbent { 209762598e31SEd Tanous BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); 20987e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20997e860f15SJohn Edward Broadbent return; 21007e860f15SJohn Edward Broadbent } 21017e860f15SJohn Edward Broadbent 21027e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 2103002d39b4SEd Tanous const std::string& connectionName = subtree[0].second[0].first; 21047e860f15SJohn Edward Broadbent 2105002d39b4SEd Tanous for (const auto& interfaceName : subtree[0].second[0].second) 21067e860f15SJohn Edward Broadbent { 21077e860f15SJohn Edward Broadbent if (interfaceName == 21087e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 21097e860f15SJohn Edward Broadbent { 2110fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2111fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, connectionName, path, 2112fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 21135e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec2, 2114b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 21157e860f15SJohn Edward Broadbent propertiesList) { 21168a592810SEd Tanous if (ec2) 21177e860f15SJohn Edward Broadbent { 211862598e31SEd Tanous BMCWEB_LOG_DEBUG("Can't get bmc asset!"); 21197e860f15SJohn Edward Broadbent return; 21207e860f15SJohn Edward Broadbent } 21217e860f15SJohn Edward Broadbent 2122fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr; 2123fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr; 2124fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr; 2125fac6e53bSKrzysztof Grobelny const std::string* model = nullptr; 2126fac6e53bSKrzysztof Grobelny const std::string* sparePartNumber = nullptr; 2127fac6e53bSKrzysztof Grobelny 2128fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2129fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), propertiesList, 2130fac6e53bSKrzysztof Grobelny "PartNumber", partNumber, "SerialNumber", 2131fac6e53bSKrzysztof Grobelny serialNumber, "Manufacturer", manufacturer, "Model", 2132fac6e53bSKrzysztof Grobelny model, "SparePartNumber", sparePartNumber); 2133fac6e53bSKrzysztof Grobelny 2134fac6e53bSKrzysztof Grobelny if (!success) 21357e860f15SJohn Edward Broadbent { 2136002d39b4SEd Tanous messages::internalError(asyncResp->res); 21377e860f15SJohn Edward Broadbent return; 21387e860f15SJohn Edward Broadbent } 2139fac6e53bSKrzysztof Grobelny 2140fac6e53bSKrzysztof Grobelny if (partNumber != nullptr) 2141fac6e53bSKrzysztof Grobelny { 2142fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = 2143fac6e53bSKrzysztof Grobelny *partNumber; 21447e860f15SJohn Edward Broadbent } 2145fac6e53bSKrzysztof Grobelny 2146fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr) 2147fac6e53bSKrzysztof Grobelny { 2148fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SerialNumber"] = 2149fac6e53bSKrzysztof Grobelny *serialNumber; 21507e860f15SJohn Edward Broadbent } 2151fac6e53bSKrzysztof Grobelny 2152fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr) 2153fac6e53bSKrzysztof Grobelny { 2154fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Manufacturer"] = 2155fac6e53bSKrzysztof Grobelny *manufacturer; 2156fac6e53bSKrzysztof Grobelny } 2157fac6e53bSKrzysztof Grobelny 2158fac6e53bSKrzysztof Grobelny if (model != nullptr) 2159fac6e53bSKrzysztof Grobelny { 2160fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Model"] = *model; 2161fac6e53bSKrzysztof Grobelny } 2162fac6e53bSKrzysztof Grobelny 2163fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr) 2164fac6e53bSKrzysztof Grobelny { 2165fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SparePartNumber"] = 2166fac6e53bSKrzysztof Grobelny *sparePartNumber; 2167fac6e53bSKrzysztof Grobelny } 2168fac6e53bSKrzysztof Grobelny }); 21697e860f15SJohn Edward Broadbent } 2170002d39b4SEd Tanous else if (interfaceName == 21710fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 21727e860f15SJohn Edward Broadbent { 21737e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 21747e860f15SJohn Edward Broadbent } 21757e860f15SJohn Edward Broadbent } 2176e99073f5SGeorge Liu }); 21777e860f15SJohn Edward Broadbent }); 21787e860f15SJohn Edward Broadbent 21797e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 2180ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 218145ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 218245ca1b86SEd Tanous [&app](const crow::Request& req, 21837e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21843ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 218545ca1b86SEd Tanous { 218645ca1b86SEd Tanous return; 218745ca1b86SEd Tanous } 21887e860f15SJohn Edward Broadbent std::optional<nlohmann::json> oem; 21897e860f15SJohn Edward Broadbent std::optional<nlohmann::json> links; 21907e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 21917e860f15SJohn Edward Broadbent 219215ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem, 2193002d39b4SEd Tanous "DateTime", datetime, "Links", links)) 21947e860f15SJohn Edward Broadbent { 21957e860f15SJohn Edward Broadbent return; 21967e860f15SJohn Edward Broadbent } 21977e860f15SJohn Edward Broadbent 21987e860f15SJohn Edward Broadbent if (oem) 21997e860f15SJohn Edward Broadbent { 220054dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 22017e860f15SJohn Edward Broadbent std::optional<nlohmann::json> openbmc; 2202002d39b4SEd Tanous if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc", 2203002d39b4SEd Tanous openbmc)) 22047e860f15SJohn Edward Broadbent { 22057e860f15SJohn Edward Broadbent return; 22067e860f15SJohn Edward Broadbent } 22077e860f15SJohn Edward Broadbent if (openbmc) 22087e860f15SJohn Edward Broadbent { 22097e860f15SJohn Edward Broadbent std::optional<nlohmann::json> fan; 2210002d39b4SEd Tanous if (!redfish::json_util::readJson(*openbmc, asyncResp->res, 2211002d39b4SEd Tanous "Fan", fan)) 22127e860f15SJohn Edward Broadbent { 22137e860f15SJohn Edward Broadbent return; 22147e860f15SJohn Edward Broadbent } 22157e860f15SJohn Edward Broadbent if (fan) 22167e860f15SJohn Edward Broadbent { 2217002d39b4SEd Tanous auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan); 22187e860f15SJohn Edward Broadbent pid->run(); 22197e860f15SJohn Edward Broadbent } 22207e860f15SJohn Edward Broadbent } 222154dce7f5SGunnar Mills #else 222254dce7f5SGunnar Mills messages::propertyUnknown(asyncResp->res, "Oem"); 222354dce7f5SGunnar Mills return; 222454dce7f5SGunnar Mills #endif 22257e860f15SJohn Edward Broadbent } 22267e860f15SJohn Edward Broadbent if (links) 22277e860f15SJohn Edward Broadbent { 22287e860f15SJohn Edward Broadbent std::optional<nlohmann::json> activeSoftwareImage; 22297e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*links, asyncResp->res, 22307e860f15SJohn Edward Broadbent "ActiveSoftwareImage", 22317e860f15SJohn Edward Broadbent activeSoftwareImage)) 22327e860f15SJohn Edward Broadbent { 22337e860f15SJohn Edward Broadbent return; 22347e860f15SJohn Edward Broadbent } 22357e860f15SJohn Edward Broadbent if (activeSoftwareImage) 22367e860f15SJohn Edward Broadbent { 22377e860f15SJohn Edward Broadbent std::optional<std::string> odataId; 2238002d39b4SEd Tanous if (!json_util::readJson(*activeSoftwareImage, asyncResp->res, 2239002d39b4SEd Tanous "@odata.id", odataId)) 22407e860f15SJohn Edward Broadbent { 22417e860f15SJohn Edward Broadbent return; 22427e860f15SJohn Edward Broadbent } 22437e860f15SJohn Edward Broadbent 22447e860f15SJohn Edward Broadbent if (odataId) 22457e860f15SJohn Edward Broadbent { 22467e860f15SJohn Edward Broadbent setActiveFirmwareImage(asyncResp, *odataId); 22477e860f15SJohn Edward Broadbent } 22487e860f15SJohn Edward Broadbent } 22497e860f15SJohn Edward Broadbent } 22507e860f15SJohn Edward Broadbent if (datetime) 22517e860f15SJohn Edward Broadbent { 22527e860f15SJohn Edward Broadbent setDateTime(asyncResp, std::move(*datetime)); 22537e860f15SJohn Edward Broadbent } 22547e860f15SJohn Edward Broadbent }); 22557e860f15SJohn Edward Broadbent } 22567e860f15SJohn Edward Broadbent 22577e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 22587e860f15SJohn Edward Broadbent { 22597e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 2260ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 22617e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 226245ca1b86SEd Tanous [&app](const crow::Request& req, 22637e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22643ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 226545ca1b86SEd Tanous { 226645ca1b86SEd Tanous return; 226745ca1b86SEd Tanous } 226883ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 226983ff9ab6SJames Feist // because it has a duplicate entry for members 22708d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 22718d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 22728d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 22738d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 22748d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 22751476687dSEd Tanous nlohmann::json::array_t members; 22761476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 22771476687dSEd Tanous bmc["@odata.id"] = "/redfish/v1/Managers/bmc"; 22781476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 22797e860f15SJohn Edward Broadbent }); 22809c310685SBorawski.Lukasz } 22819c310685SBorawski.Lukasz } // namespace redfish 2282