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 18*a51fc2d2SSui Chen #include "app.hpp" 19*a51fc2d2SSui Chen #include "dbus_utility.hpp" 20b49ac873SJames Feist #include "health.hpp" 21*a51fc2d2SSui Chen #include "query.hpp" 22c5d03ff4SJennifer Lee #include "redfish_util.hpp" 23*a51fc2d2SSui Chen #include "registries/privilege_registry.hpp" 24*a51fc2d2SSui Chen #include "utils/sw_utils.hpp" 25*a51fc2d2SSui Chen #include "utils/systemd_utils.hpp" 269c310685SBorawski.Lukasz 275b4aa86bSJames Feist #include <boost/algorithm/string/replace.hpp> 28af5d6058SSantosh Puranik #include <boost/date_time.hpp> 291214b7e7SGunnar Mills 304bfefa74SGunnar Mills #include <cstdint> 311214b7e7SGunnar Mills #include <memory> 321214b7e7SGunnar Mills #include <sstream> 33abf2add6SEd Tanous #include <variant> 345b4aa86bSJames Feist 351abe55efSEd Tanous namespace redfish 361abe55efSEd Tanous { 37ed5befbdSJennifer Lee 38ed5befbdSJennifer Lee /** 392a5c4407SGunnar Mills * Function reboots the BMC. 402a5c4407SGunnar Mills * 412a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls 42ed5befbdSJennifer Lee */ 438d1b46d7Szhanghch05 inline void 448d1b46d7Szhanghch05 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 45ed5befbdSJennifer Lee { 46ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 47ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 48ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 49ed5befbdSJennifer Lee const std::string& propertyValue = 50ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 51ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 52ed5befbdSJennifer Lee 53ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 54168e20c1SEd Tanous dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); 55ed5befbdSJennifer Lee 56ed5befbdSJennifer Lee crow::connections::systemBus->async_method_call( 57ed5befbdSJennifer Lee [asyncResp](const boost::system::error_code ec) { 58ed5befbdSJennifer Lee // Use "Set" method to set the property value. 59ed5befbdSJennifer Lee if (ec) 60ed5befbdSJennifer Lee { 612a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 62ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 63ed5befbdSJennifer Lee return; 64ed5befbdSJennifer Lee } 65ed5befbdSJennifer Lee 66ed5befbdSJennifer Lee messages::success(asyncResp->res); 67ed5befbdSJennifer Lee }, 68ed5befbdSJennifer Lee processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 69ed5befbdSJennifer Lee interfaceName, destProperty, dbusPropertyValue); 70ed5befbdSJennifer Lee } 712a5c4407SGunnar Mills 728d1b46d7Szhanghch05 inline void 738d1b46d7Szhanghch05 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 74f92af389SJayaprakash Mutyala { 75f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC"; 76f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 77f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC"; 78f92af389SJayaprakash Mutyala const std::string& propertyValue = 79f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 80f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition"; 81f92af389SJayaprakash Mutyala 82f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call. 83168e20c1SEd Tanous dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); 84f92af389SJayaprakash Mutyala 85f92af389SJayaprakash Mutyala crow::connections::systemBus->async_method_call( 86f92af389SJayaprakash Mutyala [asyncResp](const boost::system::error_code ec) { 87f92af389SJayaprakash Mutyala // Use "Set" method to set the property value. 88f92af389SJayaprakash Mutyala if (ec) 89f92af389SJayaprakash Mutyala { 90f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 91f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res); 92f92af389SJayaprakash Mutyala return; 93f92af389SJayaprakash Mutyala } 94f92af389SJayaprakash Mutyala 95f92af389SJayaprakash Mutyala messages::success(asyncResp->res); 96f92af389SJayaprakash Mutyala }, 97f92af389SJayaprakash Mutyala processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 98f92af389SJayaprakash Mutyala interfaceName, destProperty, dbusPropertyValue); 99f92af389SJayaprakash Mutyala } 100f92af389SJayaprakash Mutyala 1012a5c4407SGunnar Mills /** 1022a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot) 1032a5c4407SGunnar Mills * action. 1042a5c4407SGunnar Mills */ 1057e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app) 1062a5c4407SGunnar Mills { 1072a5c4407SGunnar Mills /** 1082a5c4407SGunnar Mills * Function handles POST method request. 1092a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 110f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 1112a5c4407SGunnar Mills */ 1127e860f15SJohn Edward Broadbent 1137e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") 114ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1157e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 11645ca1b86SEd Tanous [&app](const crow::Request& req, 1177e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1183ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 11945ca1b86SEd Tanous { 12045ca1b86SEd Tanous return; 12145ca1b86SEd Tanous } 1222a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Post Manager Reset."; 1232a5c4407SGunnar Mills 1242a5c4407SGunnar Mills std::string resetType; 1252a5c4407SGunnar Mills 12615ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 1277e860f15SJohn Edward Broadbent resetType)) 1282a5c4407SGunnar Mills { 1292a5c4407SGunnar Mills return; 1302a5c4407SGunnar Mills } 1312a5c4407SGunnar Mills 132f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart") 133f92af389SJayaprakash Mutyala { 134f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 135f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp); 136f92af389SJayaprakash Mutyala return; 137f92af389SJayaprakash Mutyala } 1383174e4dfSEd Tanous if (resetType == "ForceRestart") 139f92af389SJayaprakash Mutyala { 140f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 141f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp); 142f92af389SJayaprakash Mutyala return; 143f92af389SJayaprakash Mutyala } 1442a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 1452a5c4407SGunnar Mills << resetType; 1462a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType, 1472a5c4407SGunnar Mills "ResetType"); 1482a5c4407SGunnar Mills 1492a5c4407SGunnar Mills return; 1507e860f15SJohn Edward Broadbent }); 1512a5c4407SGunnar Mills } 152ed5befbdSJennifer Lee 1533e40fc74SGunnar Mills /** 1543e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset 1553e40fc74SGunnar Mills * action. 1563e40fc74SGunnar Mills */ 1577e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app) 1583e40fc74SGunnar Mills { 1593e40fc74SGunnar Mills 1603e40fc74SGunnar Mills /** 1613e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request. 1623e40fc74SGunnar Mills * 1633e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling 1643e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot. 1653e40fc74SGunnar Mills * 1663e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write 1673e40fc74SGunnar Mills * filesystem which includes things like the network settings. 1683e40fc74SGunnar Mills * 1693e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll". 1703e40fc74SGunnar Mills */ 1717e860f15SJohn Edward Broadbent 1727e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 1737e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/") 174ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1757e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 17645ca1b86SEd Tanous [&app](const crow::Request& req, 1777e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1783ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 17945ca1b86SEd Tanous { 18045ca1b86SEd Tanous return; 18145ca1b86SEd Tanous } 1823e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Post ResetToDefaults."; 1833e40fc74SGunnar Mills 1843e40fc74SGunnar Mills std::string resetType; 1853e40fc74SGunnar Mills 186002d39b4SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, 187002d39b4SEd Tanous "ResetToDefaultsType", resetType)) 1883e40fc74SGunnar Mills { 1893e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType."; 1903e40fc74SGunnar Mills 191002d39b4SEd Tanous messages::actionParameterMissing(asyncResp->res, "ResetToDefaults", 1923e40fc74SGunnar Mills "ResetToDefaultsType"); 1933e40fc74SGunnar Mills return; 1943e40fc74SGunnar Mills } 1953e40fc74SGunnar Mills 1963e40fc74SGunnar Mills if (resetType != "ResetAll") 1973e40fc74SGunnar Mills { 1980fda0f12SGeorge Liu BMCWEB_LOG_DEBUG 1990fda0f12SGeorge Liu << "Invalid property value for ResetToDefaultsType: " 2003e40fc74SGunnar Mills << resetType; 201002d39b4SEd Tanous messages::actionParameterNotSupported(asyncResp->res, resetType, 202002d39b4SEd Tanous "ResetToDefaultsType"); 2033e40fc74SGunnar Mills return; 2043e40fc74SGunnar Mills } 2053e40fc74SGunnar Mills 2063e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 2073e40fc74SGunnar Mills [asyncResp](const boost::system::error_code ec) { 2083e40fc74SGunnar Mills if (ec) 2093e40fc74SGunnar Mills { 210002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec; 2113e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2123e40fc74SGunnar Mills return; 2133e40fc74SGunnar Mills } 2143e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2153e40fc74SGunnar Mills // Can't erase what the BMC is running on 2163e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2173e40fc74SGunnar Mills }, 2183e40fc74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 2193e40fc74SGunnar Mills "/xyz/openbmc_project/software", 2203e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2217e860f15SJohn Edward Broadbent }); 2223e40fc74SGunnar Mills } 2233e40fc74SGunnar Mills 2241cb1a9e6SAppaRao Puli /** 2251cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2261cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2271cb1a9e6SAppaRao Puli */ 2287e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2291cb1a9e6SAppaRao Puli { 2301cb1a9e6SAppaRao Puli /** 2311cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2321cb1a9e6SAppaRao Puli */ 2337e860f15SJohn Edward Broadbent 2347e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/") 235ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 2367e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 23745ca1b86SEd Tanous [&app](const crow::Request& req, 2387e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2393ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 24045ca1b86SEd Tanous { 24145ca1b86SEd Tanous return; 24245ca1b86SEd Tanous } 2431476687dSEd Tanous 2441476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 2451476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 2461476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2471476687dSEd Tanous "/redfish/v1/Managers/bmc/ResetActionInfo"; 2481476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 2491476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 2501476687dSEd Tanous nlohmann::json::object_t parameter; 2511476687dSEd Tanous parameter["Name"] = "ResetType"; 2521476687dSEd Tanous parameter["Required"] = true; 2531476687dSEd Tanous parameter["DataType"] = "String"; 2541476687dSEd Tanous 2551476687dSEd Tanous nlohmann::json::array_t allowableValues; 2561476687dSEd Tanous allowableValues.push_back("GracefulRestart"); 2571476687dSEd Tanous allowableValues.push_back("ForceRestart"); 2581476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues); 2591476687dSEd Tanous 2601476687dSEd Tanous nlohmann::json::array_t parameters; 2611476687dSEd Tanous parameters.push_back(std::move(parameter)); 2621476687dSEd Tanous 2631476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 2647e860f15SJohn Edward Broadbent }); 2651cb1a9e6SAppaRao Puli } 2661cb1a9e6SAppaRao Puli 2675b4aa86bSJames Feist static constexpr const char* objectManagerIface = 2685b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 2695b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 2705b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 2715b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 2725b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 273b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 274b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 27573df0db0SJames Feist static constexpr const char* thermalModeIface = 27673df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 2779c310685SBorawski.Lukasz 2788d1b46d7Szhanghch05 inline void 2798d1b46d7Szhanghch05 asyncPopulatePid(const std::string& connection, const std::string& path, 28073df0db0SJames Feist const std::string& currentProfile, 28173df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 2828d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2835b4aa86bSJames Feist { 2845b4aa86bSJames Feist 2855b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 28673df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 28773df0db0SJames Feist const boost::system::error_code ec, 2885b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 2895b4aa86bSJames Feist if (ec) 2905b4aa86bSJames Feist { 2915b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 2925b4aa86bSJames Feist asyncResp->res.jsonValue.clear(); 293f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2945b4aa86bSJames Feist return; 2955b4aa86bSJames Feist } 2965b4aa86bSJames Feist nlohmann::json& configRoot = 2975b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 2985b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 2995b4aa86bSJames Feist fans["@odata.type"] = "#OemManager.FanControllers"; 3000fda0f12SGeorge Liu fans["@odata.id"] = 3010fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers"; 3025b4aa86bSJames Feist 3035b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 3045b4aa86bSJames Feist pids["@odata.type"] = "#OemManager.PidControllers"; 3055b4aa86bSJames Feist pids["@odata.id"] = 3065b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; 3075b4aa86bSJames Feist 308b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 309b7a08d04SJames Feist stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; 310b7a08d04SJames Feist stepwise["@odata.id"] = 311b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; 312b7a08d04SJames Feist 3135b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 3145b4aa86bSJames Feist zones["@odata.id"] = 3155b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; 3165b4aa86bSJames Feist zones["@odata.type"] = "#OemManager.FanZones"; 317002d39b4SEd Tanous configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; 3185b4aa86bSJames Feist configRoot["@odata.type"] = "#OemManager.Fan"; 31973df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 32073df0db0SJames Feist 32173df0db0SJames Feist if (!currentProfile.empty()) 32273df0db0SJames Feist { 32373df0db0SJames Feist configRoot["Profile"] = currentProfile; 32473df0db0SJames Feist } 32573df0db0SJames Feist BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !"; 3265b4aa86bSJames Feist 3275b4aa86bSJames Feist for (const auto& pathPair : managedObj) 3285b4aa86bSJames Feist { 3295b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 3305b4aa86bSJames Feist { 3315b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 332b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 333b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 3345b4aa86bSJames Feist { 3355b4aa86bSJames Feist continue; 3365b4aa86bSJames Feist } 33773df0db0SJames Feist 338711ac7a9SEd Tanous std::string name; 339711ac7a9SEd Tanous 340711ac7a9SEd Tanous for (const std::pair<std::string, 341002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 342002d39b4SEd Tanous intfPair.second) 343711ac7a9SEd Tanous { 344711ac7a9SEd Tanous if (propPair.first == "Name") 345711ac7a9SEd Tanous { 3465b4aa86bSJames Feist const std::string* namePtr = 347711ac7a9SEd Tanous std::get_if<std::string>(&propPair.second); 3485b4aa86bSJames Feist if (namePtr == nullptr) 3495b4aa86bSJames Feist { 3505b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Name Field illegal"; 351b7a08d04SJames Feist messages::internalError(asyncResp->res); 3525b4aa86bSJames Feist return; 3535b4aa86bSJames Feist } 354db697703SWilly Tu name = *namePtr; 3555b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 356711ac7a9SEd Tanous } 357711ac7a9SEd Tanous else if (propPair.first == "Profiles") 35873df0db0SJames Feist { 35973df0db0SJames Feist const std::vector<std::string>* profiles = 36073df0db0SJames Feist std::get_if<std::vector<std::string>>( 361711ac7a9SEd Tanous &propPair.second); 36273df0db0SJames Feist if (profiles == nullptr) 36373df0db0SJames Feist { 364002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Pid Profiles Field illegal"; 36573df0db0SJames Feist messages::internalError(asyncResp->res); 36673df0db0SJames Feist return; 36773df0db0SJames Feist } 36873df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 36973df0db0SJames Feist currentProfile) == profiles->end()) 37073df0db0SJames Feist { 37173df0db0SJames Feist BMCWEB_LOG_INFO 372002d39b4SEd Tanous << name << " not supported in current profile"; 37373df0db0SJames Feist continue; 37473df0db0SJames Feist } 37573df0db0SJames Feist } 376711ac7a9SEd Tanous } 377b7a08d04SJames Feist nlohmann::json* config = nullptr; 378c33a90ecSJames Feist const std::string* classPtr = nullptr; 379711ac7a9SEd Tanous 380711ac7a9SEd Tanous for (const std::pair<std::string, 381002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 382002d39b4SEd Tanous intfPair.second) 383c33a90ecSJames Feist { 384727dc83fSLei YU if (propPair.first == "Class") 385711ac7a9SEd Tanous { 386002d39b4SEd Tanous classPtr = std::get_if<std::string>(&propPair.second); 387711ac7a9SEd Tanous } 388c33a90ecSJames Feist } 389c33a90ecSJames Feist 3905b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 3915b4aa86bSJames Feist { 3925b4aa86bSJames Feist std::string chassis; 393002d39b4SEd Tanous if (!dbus::utility::getNthStringFromPath(pathPair.first.str, 394002d39b4SEd Tanous 5, chassis)) 3955b4aa86bSJames Feist { 3965b4aa86bSJames Feist chassis = "#IllegalValue"; 3975b4aa86bSJames Feist } 3985b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 3995b4aa86bSJames Feist zone["Chassis"] = { 4005b4aa86bSJames Feist {"@odata.id", "/redfish/v1/Chassis/" + chassis}}; 4010fda0f12SGeorge Liu zone["@odata.id"] = 4020fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" + 4035b4aa86bSJames Feist name; 4045b4aa86bSJames Feist zone["@odata.type"] = "#OemManager.FanZone"; 405b7a08d04SJames Feist config = &zone; 4065b4aa86bSJames Feist } 4075b4aa86bSJames Feist 408b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 4095b4aa86bSJames Feist { 410c33a90ecSJames Feist if (classPtr == nullptr) 411c33a90ecSJames Feist { 412c33a90ecSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 413c33a90ecSJames Feist messages::internalError(asyncResp->res); 414c33a90ecSJames Feist return; 415c33a90ecSJames Feist } 416c33a90ecSJames Feist 417b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 418b7a08d04SJames Feist config = &controller; 4195b4aa86bSJames Feist 420b7a08d04SJames Feist controller["@odata.id"] = 4210fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers/" + 422271584abSEd Tanous name; 423b7a08d04SJames Feist controller["@odata.type"] = 424b7a08d04SJames Feist "#OemManager.StepwiseController"; 425b7a08d04SJames Feist 426c33a90ecSJames Feist controller["Direction"] = *classPtr; 4275b4aa86bSJames Feist } 4285b4aa86bSJames Feist 4295b4aa86bSJames Feist // pid and fans are off the same configuration 430b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 4315b4aa86bSJames Feist { 432c33a90ecSJames Feist 4335b4aa86bSJames Feist if (classPtr == nullptr) 4345b4aa86bSJames Feist { 4355b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 436a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 4375b4aa86bSJames Feist return; 4385b4aa86bSJames Feist } 4395b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 440002d39b4SEd Tanous nlohmann::json& element = isFan ? fans[name] : pids[name]; 441b7a08d04SJames Feist config = &element; 4425b4aa86bSJames Feist if (isFan) 4435b4aa86bSJames Feist { 4445b4aa86bSJames Feist element["@odata.id"] = 4450fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers/" + 446271584abSEd Tanous name; 447002d39b4SEd Tanous element["@odata.type"] = "#OemManager.FanController"; 4485b4aa86bSJames Feist } 4495b4aa86bSJames Feist else 4505b4aa86bSJames Feist { 4515b4aa86bSJames Feist element["@odata.id"] = 4520fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers/" + 453271584abSEd Tanous name; 454002d39b4SEd Tanous element["@odata.type"] = "#OemManager.PidController"; 4555b4aa86bSJames Feist } 456b7a08d04SJames Feist } 457b7a08d04SJames Feist else 458b7a08d04SJames Feist { 459b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Unexpected configuration"; 460b7a08d04SJames Feist messages::internalError(asyncResp->res); 461b7a08d04SJames Feist return; 462b7a08d04SJames Feist } 463b7a08d04SJames Feist 464b7a08d04SJames Feist // used for making maps out of 2 vectors 465b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 466b7a08d04SJames Feist const std::vector<double>* values = nullptr; 467b7a08d04SJames Feist 468b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 469b7a08d04SJames Feist { 470b7a08d04SJames Feist if (propertyPair.first == "Type" || 471b7a08d04SJames Feist propertyPair.first == "Class" || 472b7a08d04SJames Feist propertyPair.first == "Name") 473b7a08d04SJames Feist { 474b7a08d04SJames Feist continue; 475b7a08d04SJames Feist } 476b7a08d04SJames Feist 477b7a08d04SJames Feist // zones 478b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 479b7a08d04SJames Feist { 480b7a08d04SJames Feist const double* ptr = 481abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 482b7a08d04SJames Feist if (ptr == nullptr) 483b7a08d04SJames Feist { 484b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 485b7a08d04SJames Feist << propertyPair.first; 486b7a08d04SJames Feist messages::internalError(asyncResp->res); 487b7a08d04SJames Feist return; 488b7a08d04SJames Feist } 489b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 490b7a08d04SJames Feist } 491b7a08d04SJames Feist 492b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 493b7a08d04SJames Feist { 494b7a08d04SJames Feist if (propertyPair.first == "Reading" || 495b7a08d04SJames Feist propertyPair.first == "Output") 496b7a08d04SJames Feist { 497b7a08d04SJames Feist const std::vector<double>* ptr = 498abf2add6SEd Tanous std::get_if<std::vector<double>>( 499b7a08d04SJames Feist &propertyPair.second); 500b7a08d04SJames Feist 501b7a08d04SJames Feist if (ptr == nullptr) 502b7a08d04SJames Feist { 503b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 504b7a08d04SJames Feist << propertyPair.first; 505b7a08d04SJames Feist messages::internalError(asyncResp->res); 506b7a08d04SJames Feist return; 507b7a08d04SJames Feist } 508b7a08d04SJames Feist 509b7a08d04SJames Feist if (propertyPair.first == "Reading") 510b7a08d04SJames Feist { 511b7a08d04SJames Feist keys = ptr; 512b7a08d04SJames Feist } 513b7a08d04SJames Feist else 514b7a08d04SJames Feist { 515b7a08d04SJames Feist values = ptr; 516b7a08d04SJames Feist } 517e662eae8SEd Tanous if (keys != nullptr && values != nullptr) 518b7a08d04SJames Feist { 519b7a08d04SJames Feist if (keys->size() != values->size()) 520b7a08d04SJames Feist { 521b7a08d04SJames Feist BMCWEB_LOG_ERROR 5220fda0f12SGeorge Liu << "Reading and Output size don't match "; 523b7a08d04SJames Feist messages::internalError(asyncResp->res); 524b7a08d04SJames Feist return; 525b7a08d04SJames Feist } 526b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 527b7a08d04SJames Feist steps = nlohmann::json::array(); 528b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 529b7a08d04SJames Feist { 5301476687dSEd Tanous nlohmann::json::object_t step; 5311476687dSEd Tanous step["Target"] = (*keys)[ii]; 5321476687dSEd Tanous step["Output"] = (*values)[ii]; 5331476687dSEd Tanous steps.push_back(std::move(step)); 534b7a08d04SJames Feist } 535b7a08d04SJames Feist } 536b7a08d04SJames Feist } 537b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 538b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 539b7a08d04SJames Feist { 540b7a08d04SJames Feist const double* ptr = 541abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 542b7a08d04SJames Feist if (ptr == nullptr) 543b7a08d04SJames Feist { 544b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 545b7a08d04SJames Feist << propertyPair.first; 546b7a08d04SJames Feist messages::internalError(asyncResp->res); 547b7a08d04SJames Feist return; 548b7a08d04SJames Feist } 549b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 550b7a08d04SJames Feist } 551b7a08d04SJames Feist } 552b7a08d04SJames Feist 553b7a08d04SJames Feist // pid and fans are off the same configuration 554b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 555b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 556b7a08d04SJames Feist { 5575b4aa86bSJames Feist 5585b4aa86bSJames Feist if (propertyPair.first == "Zones") 5595b4aa86bSJames Feist { 5605b4aa86bSJames Feist const std::vector<std::string>* inputs = 561abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5621b6b96c5SEd Tanous &propertyPair.second); 5635b4aa86bSJames Feist 5645b4aa86bSJames Feist if (inputs == nullptr) 5655b4aa86bSJames Feist { 566002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Zones Pid Field Illegal"; 567a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 5685b4aa86bSJames Feist return; 5695b4aa86bSJames Feist } 570b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5715b4aa86bSJames Feist data = nlohmann::json::array(); 5725b4aa86bSJames Feist for (std::string itemCopy : *inputs) 5735b4aa86bSJames Feist { 5745b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 5751476687dSEd Tanous nlohmann::json::object_t input; 5761476687dSEd Tanous input["@odata.id"] = 5770fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" + 5781476687dSEd Tanous itemCopy; 5791476687dSEd Tanous data.push_back(std::move(input)); 5805b4aa86bSJames Feist } 5815b4aa86bSJames Feist } 5825b4aa86bSJames Feist // todo(james): may never happen, but this 5835b4aa86bSJames Feist // assumes configuration data referenced in the 5845b4aa86bSJames Feist // PID config is provided by the same daemon, we 5855b4aa86bSJames Feist // could add another loop to cover all cases, 5865b4aa86bSJames Feist // but I'm okay kicking this can down the road a 5875b4aa86bSJames Feist // bit 5885b4aa86bSJames Feist 5895b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 5905b4aa86bSJames Feist propertyPair.first == "Outputs") 5915b4aa86bSJames Feist { 592b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5935b4aa86bSJames Feist const std::vector<std::string>* inputs = 594abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5951b6b96c5SEd Tanous &propertyPair.second); 5965b4aa86bSJames Feist 5975b4aa86bSJames Feist if (inputs == nullptr) 5985b4aa86bSJames Feist { 5995b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 6005b4aa86bSJames Feist << propertyPair.first; 601f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6025b4aa86bSJames Feist return; 6035b4aa86bSJames Feist } 6045b4aa86bSJames Feist data = *inputs; 605b943aaefSJames Feist } 606b943aaefSJames Feist else if (propertyPair.first == "SetPointOffset") 607b943aaefSJames Feist { 608b943aaefSJames Feist const std::string* ptr = 609002d39b4SEd Tanous std::get_if<std::string>(&propertyPair.second); 610b943aaefSJames Feist 611b943aaefSJames Feist if (ptr == nullptr) 612b943aaefSJames Feist { 613b943aaefSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 614b943aaefSJames Feist << propertyPair.first; 615b943aaefSJames Feist messages::internalError(asyncResp->res); 616b943aaefSJames Feist return; 617b943aaefSJames Feist } 618b943aaefSJames Feist // translate from dbus to redfish 619b943aaefSJames Feist if (*ptr == "WarningHigh") 620b943aaefSJames Feist { 621b943aaefSJames Feist (*config)["SetPointOffset"] = 622b943aaefSJames Feist "UpperThresholdNonCritical"; 623b943aaefSJames Feist } 624b943aaefSJames Feist else if (*ptr == "WarningLow") 625b943aaefSJames Feist { 626b943aaefSJames Feist (*config)["SetPointOffset"] = 627b943aaefSJames Feist "LowerThresholdNonCritical"; 628b943aaefSJames Feist } 629b943aaefSJames Feist else if (*ptr == "CriticalHigh") 630b943aaefSJames Feist { 631b943aaefSJames Feist (*config)["SetPointOffset"] = 632b943aaefSJames Feist "UpperThresholdCritical"; 633b943aaefSJames Feist } 634b943aaefSJames Feist else if (*ptr == "CriticalLow") 635b943aaefSJames Feist { 636b943aaefSJames Feist (*config)["SetPointOffset"] = 637b943aaefSJames Feist "LowerThresholdCritical"; 638b943aaefSJames Feist } 639b943aaefSJames Feist else 640b943aaefSJames Feist { 641002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Value Illegal " << *ptr; 642b943aaefSJames Feist messages::internalError(asyncResp->res); 643b943aaefSJames Feist return; 644b943aaefSJames Feist } 645b943aaefSJames Feist } 646b943aaefSJames Feist // doubles 647002d39b4SEd Tanous else if (propertyPair.first == "FFGainCoefficient" || 6485b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 6495b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 6505b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 6515b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 652002d39b4SEd Tanous propertyPair.first == "PositiveHysteresis" || 653002d39b4SEd Tanous propertyPair.first == "NegativeHysteresis" || 6545b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 6555b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 6565b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 6577625cb81SJames Feist propertyPair.first == "SetPoint" || 6585b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 6595b4aa86bSJames Feist propertyPair.first == "SlewPos") 6605b4aa86bSJames Feist { 6615b4aa86bSJames Feist const double* ptr = 662abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 6635b4aa86bSJames Feist if (ptr == nullptr) 6645b4aa86bSJames Feist { 6655b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 6665b4aa86bSJames Feist << propertyPair.first; 667f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6685b4aa86bSJames Feist return; 6695b4aa86bSJames Feist } 670b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 6715b4aa86bSJames Feist } 6725b4aa86bSJames Feist } 6735b4aa86bSJames Feist } 6745b4aa86bSJames Feist } 6755b4aa86bSJames Feist } 6765b4aa86bSJames Feist }, 6775b4aa86bSJames Feist connection, path, objectManagerIface, "GetManagedObjects"); 6785b4aa86bSJames Feist } 679ca537928SJennifer Lee 68083ff9ab6SJames Feist enum class CreatePIDRet 68183ff9ab6SJames Feist { 68283ff9ab6SJames Feist fail, 68383ff9ab6SJames Feist del, 68483ff9ab6SJames Feist patch 68583ff9ab6SJames Feist }; 68683ff9ab6SJames Feist 6878d1b46d7Szhanghch05 inline bool 6888d1b46d7Szhanghch05 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response, 6895f2caaefSJames Feist std::vector<nlohmann::json>& config, 6905f2caaefSJames Feist std::vector<std::string>& zones) 6915f2caaefSJames Feist { 692b6baeaa4SJames Feist if (config.empty()) 693b6baeaa4SJames Feist { 694b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Empty Zones"; 6951668ce6dSEd Tanous messages::propertyValueFormatError(response->res, "[]", "Zones"); 696b6baeaa4SJames Feist return false; 697b6baeaa4SJames Feist } 6985f2caaefSJames Feist for (auto& odata : config) 6995f2caaefSJames Feist { 7005f2caaefSJames Feist std::string path; 7015f2caaefSJames Feist if (!redfish::json_util::readJson(odata, response->res, "@odata.id", 7025f2caaefSJames Feist path)) 7035f2caaefSJames Feist { 7045f2caaefSJames Feist return false; 7055f2caaefSJames Feist } 7065f2caaefSJames Feist std::string input; 70761adbda3SJames Feist 70861adbda3SJames Feist // 8 below comes from 70961adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 71061adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 71161adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 7125f2caaefSJames Feist { 7135f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << path; 7145f2caaefSJames Feist BMCWEB_LOG_ERROR << "Illegal Type Zones"; 7155f2caaefSJames Feist messages::propertyValueFormatError(response->res, odata.dump(), 7165f2caaefSJames Feist "Zones"); 7175f2caaefSJames Feist return false; 7185f2caaefSJames Feist } 7195f2caaefSJames Feist boost::replace_all(input, "_", " "); 7205f2caaefSJames Feist zones.emplace_back(std::move(input)); 7215f2caaefSJames Feist } 7225f2caaefSJames Feist return true; 7235f2caaefSJames Feist } 7245f2caaefSJames Feist 725711ac7a9SEd Tanous inline const dbus::utility::ManagedObjectType::value_type* 72673df0db0SJames Feist findChassis(const dbus::utility::ManagedObjectType& managedObj, 727b6baeaa4SJames Feist const std::string& value, std::string& chassis) 728b6baeaa4SJames Feist { 729b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n"; 730b6baeaa4SJames Feist 731b6baeaa4SJames Feist std::string escaped = boost::replace_all_copy(value, " ", "_"); 732b6baeaa4SJames Feist escaped = "/" + escaped; 733002d39b4SEd Tanous auto it = std::find_if(managedObj.begin(), managedObj.end(), 734002d39b4SEd Tanous [&escaped](const auto& obj) { 735b6baeaa4SJames Feist if (boost::algorithm::ends_with(obj.first.str, escaped)) 736b6baeaa4SJames Feist { 737b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n"; 738b6baeaa4SJames Feist return true; 739b6baeaa4SJames Feist } 740b6baeaa4SJames Feist return false; 741b6baeaa4SJames Feist }); 742b6baeaa4SJames Feist 743b6baeaa4SJames Feist if (it == managedObj.end()) 744b6baeaa4SJames Feist { 74573df0db0SJames Feist return nullptr; 746b6baeaa4SJames Feist } 747b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 748b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 74973df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 75073df0db0SJames Feist { 75173df0db0SJames Feist return &(*it); 75273df0db0SJames Feist } 75373df0db0SJames Feist 75473df0db0SJames Feist return nullptr; 755b6baeaa4SJames Feist } 756b6baeaa4SJames Feist 75723a21a1cSEd Tanous inline CreatePIDRet createPidInterface( 7588d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, 759b5a76932SEd Tanous const nlohmann::json::iterator& it, const std::string& path, 76083ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 761b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap& output, std::string& chassis, 762b9d36b47SEd Tanous const std::string& profile) 76383ff9ab6SJames Feist { 76483ff9ab6SJames Feist 7655f2caaefSJames Feist // common deleter 766b6baeaa4SJames Feist if (it.value() == nullptr) 7675f2caaefSJames Feist { 7685f2caaefSJames Feist std::string iface; 7695f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 7705f2caaefSJames Feist { 7715f2caaefSJames Feist iface = pidConfigurationIface; 7725f2caaefSJames Feist } 7735f2caaefSJames Feist else if (type == "FanZones") 7745f2caaefSJames Feist { 7755f2caaefSJames Feist iface = pidZoneConfigurationIface; 7765f2caaefSJames Feist } 7775f2caaefSJames Feist else if (type == "StepwiseControllers") 7785f2caaefSJames Feist { 7795f2caaefSJames Feist iface = stepwiseConfigurationIface; 7805f2caaefSJames Feist } 7815f2caaefSJames Feist else 7825f2caaefSJames Feist { 783a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 7845f2caaefSJames Feist messages::propertyUnknown(response->res, type); 7855f2caaefSJames Feist return CreatePIDRet::fail; 7865f2caaefSJames Feist } 7876ee7f774SJames Feist 7886ee7f774SJames Feist BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n"; 7895f2caaefSJames Feist // delete interface 7905f2caaefSJames Feist crow::connections::systemBus->async_method_call( 7915f2caaefSJames Feist [response, path](const boost::system::error_code ec) { 7925f2caaefSJames Feist if (ec) 7935f2caaefSJames Feist { 7945f2caaefSJames Feist BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec; 7955f2caaefSJames Feist messages::internalError(response->res); 796b6baeaa4SJames Feist return; 7975f2caaefSJames Feist } 798b6baeaa4SJames Feist messages::success(response->res); 7995f2caaefSJames Feist }, 8005f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 8015f2caaefSJames Feist return CreatePIDRet::del; 8025f2caaefSJames Feist } 8035f2caaefSJames Feist 804711ac7a9SEd Tanous const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr; 805b6baeaa4SJames Feist if (!createNewObject) 806b6baeaa4SJames Feist { 807b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 808b6baeaa4SJames Feist // d-bus 80973df0db0SJames Feist managedItem = findChassis(managedObj, it.key(), chassis); 81073df0db0SJames Feist if (managedItem == nullptr) 811b6baeaa4SJames Feist { 812b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 813ace85d60SEd Tanous messages::invalidObject(response->res, 814ace85d60SEd Tanous crow::utility::urlFromPieces( 815ace85d60SEd Tanous "redfish", "v1", "Chassis", chassis)); 816b6baeaa4SJames Feist return CreatePIDRet::fail; 817b6baeaa4SJames Feist } 818b6baeaa4SJames Feist } 819b6baeaa4SJames Feist 82026f6976fSEd Tanous if (!profile.empty() && 82173df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 82273df0db0SJames Feist type == "StepwiseControllers")) 82373df0db0SJames Feist { 82473df0db0SJames Feist if (managedItem == nullptr) 82573df0db0SJames Feist { 826b9d36b47SEd Tanous output.emplace_back("Profiles", std::vector<std::string>{profile}); 82773df0db0SJames Feist } 82873df0db0SJames Feist else 82973df0db0SJames Feist { 83073df0db0SJames Feist std::string interface; 83173df0db0SJames Feist if (type == "StepwiseControllers") 83273df0db0SJames Feist { 83373df0db0SJames Feist interface = stepwiseConfigurationIface; 83473df0db0SJames Feist } 83573df0db0SJames Feist else 83673df0db0SJames Feist { 83773df0db0SJames Feist interface = pidConfigurationIface; 83873df0db0SJames Feist } 839711ac7a9SEd Tanous bool ifaceFound = false; 840711ac7a9SEd Tanous for (const auto& iface : managedItem->second) 841711ac7a9SEd Tanous { 842711ac7a9SEd Tanous if (iface.first == interface) 843711ac7a9SEd Tanous { 844711ac7a9SEd Tanous ifaceFound = true; 845711ac7a9SEd Tanous for (const auto& prop : iface.second) 846711ac7a9SEd Tanous { 847711ac7a9SEd Tanous if (prop.first == "Profiles") 848711ac7a9SEd Tanous { 849711ac7a9SEd Tanous const std::vector<std::string>* curProfiles = 850711ac7a9SEd Tanous std::get_if<std::vector<std::string>>( 851711ac7a9SEd Tanous &(prop.second)); 852711ac7a9SEd Tanous if (curProfiles == nullptr) 853711ac7a9SEd Tanous { 854711ac7a9SEd Tanous BMCWEB_LOG_ERROR 855711ac7a9SEd Tanous << "Illegal profiles in managed object"; 856711ac7a9SEd Tanous messages::internalError(response->res); 857711ac7a9SEd Tanous return CreatePIDRet::fail; 858711ac7a9SEd Tanous } 859711ac7a9SEd Tanous if (std::find(curProfiles->begin(), 860711ac7a9SEd Tanous curProfiles->end(), 861711ac7a9SEd Tanous profile) == curProfiles->end()) 862711ac7a9SEd Tanous { 863711ac7a9SEd Tanous std::vector<std::string> newProfiles = 864711ac7a9SEd Tanous *curProfiles; 865711ac7a9SEd Tanous newProfiles.push_back(profile); 866b9d36b47SEd Tanous output.emplace_back("Profiles", newProfiles); 867711ac7a9SEd Tanous } 868711ac7a9SEd Tanous } 869711ac7a9SEd Tanous } 870711ac7a9SEd Tanous } 871711ac7a9SEd Tanous } 872711ac7a9SEd Tanous 873711ac7a9SEd Tanous if (!ifaceFound) 87473df0db0SJames Feist { 87573df0db0SJames Feist BMCWEB_LOG_ERROR 87673df0db0SJames Feist << "Failed to find interface in managed object"; 87773df0db0SJames Feist messages::internalError(response->res); 87873df0db0SJames Feist return CreatePIDRet::fail; 87973df0db0SJames Feist } 88073df0db0SJames Feist } 88173df0db0SJames Feist } 88273df0db0SJames Feist 88383ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 88483ff9ab6SJames Feist { 88583ff9ab6SJames Feist if (createNewObject) 88683ff9ab6SJames Feist { 887b9d36b47SEd Tanous output.emplace_back("Class", 888b9d36b47SEd Tanous type == "PidControllers" ? "temp" : "fan"); 889b9d36b47SEd Tanous output.emplace_back("Type", "Pid"); 89083ff9ab6SJames Feist } 8915f2caaefSJames Feist 8925f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 8935f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 8945f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 8955f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 896b943aaefSJames Feist std::optional<std::string> setpointOffset; 8975f2caaefSJames Feist if (!redfish::json_util::readJson( 898b6baeaa4SJames Feist it.value(), response->res, "Inputs", inputs, "Outputs", outputs, 8995f2caaefSJames Feist "Zones", zones, "FFGainCoefficient", 9005f2caaefSJames Feist doubles["FFGainCoefficient"], "FFOffCoefficient", 9015f2caaefSJames Feist doubles["FFOffCoefficient"], "ICoefficient", 9025f2caaefSJames Feist doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], 9035f2caaefSJames Feist "ILimitMin", doubles["ILimitMin"], "OutLimitMax", 9045f2caaefSJames Feist doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], 9055f2caaefSJames Feist "PCoefficient", doubles["PCoefficient"], "SetPoint", 906b943aaefSJames Feist doubles["SetPoint"], "SetPointOffset", setpointOffset, 907b943aaefSJames Feist "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"], 908b943aaefSJames Feist "PositiveHysteresis", doubles["PositiveHysteresis"], 909b943aaefSJames Feist "NegativeHysteresis", doubles["NegativeHysteresis"])) 91083ff9ab6SJames Feist { 91171f52d96SEd Tanous BMCWEB_LOG_ERROR 91271f52d96SEd Tanous << "Illegal Property " 91371f52d96SEd Tanous << it.value().dump(2, ' ', true, 91471f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 9155f2caaefSJames Feist return CreatePIDRet::fail; 91683ff9ab6SJames Feist } 9175f2caaefSJames Feist if (zones) 9185f2caaefSJames Feist { 9195f2caaefSJames Feist std::vector<std::string> zonesStr; 9205f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 9215f2caaefSJames Feist { 922a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 9235f2caaefSJames Feist return CreatePIDRet::fail; 9245f2caaefSJames Feist } 925b6baeaa4SJames Feist if (chassis.empty() && 926e662eae8SEd Tanous findChassis(managedObj, zonesStr[0], chassis) == nullptr) 927b6baeaa4SJames Feist { 928b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 929ace85d60SEd Tanous messages::invalidObject( 930ace85d60SEd Tanous response->res, crow::utility::urlFromPieces( 931ace85d60SEd Tanous "redfish", "v1", "Chassis", chassis)); 932b6baeaa4SJames Feist return CreatePIDRet::fail; 933b6baeaa4SJames Feist } 934b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStr)); 9355f2caaefSJames Feist } 9365f2caaefSJames Feist if (inputs || outputs) 9375f2caaefSJames Feist { 93802cad96eSEd Tanous std::array< 93902cad96eSEd Tanous std::reference_wrapper<std::optional<std::vector<std::string>>>, 94002cad96eSEd Tanous 2> 94102cad96eSEd Tanous containers = {inputs, outputs}; 9425f2caaefSJames Feist size_t index = 0; 94302cad96eSEd Tanous for (std::optional<std::vector<std::string>>& container : 94402cad96eSEd Tanous containers) 9455f2caaefSJames Feist { 9465f2caaefSJames Feist if (!container) 9475f2caaefSJames Feist { 9485f2caaefSJames Feist index++; 9495f2caaefSJames Feist continue; 95083ff9ab6SJames Feist } 9515f2caaefSJames Feist for (std::string& value : *container) 95283ff9ab6SJames Feist { 9535f2caaefSJames Feist boost::replace_all(value, "_", " "); 95483ff9ab6SJames Feist } 9555f2caaefSJames Feist std::string key; 9565f2caaefSJames Feist if (index == 0) 9575f2caaefSJames Feist { 9585f2caaefSJames Feist key = "Inputs"; 9595f2caaefSJames Feist } 9605f2caaefSJames Feist else 9615f2caaefSJames Feist { 9625f2caaefSJames Feist key = "Outputs"; 9635f2caaefSJames Feist } 964b9d36b47SEd Tanous output.emplace_back(key, *container); 9655f2caaefSJames Feist index++; 9665f2caaefSJames Feist } 96783ff9ab6SJames Feist } 96883ff9ab6SJames Feist 969b943aaefSJames Feist if (setpointOffset) 970b943aaefSJames Feist { 971b943aaefSJames Feist // translate between redfish and dbus names 972b943aaefSJames Feist if (*setpointOffset == "UpperThresholdNonCritical") 973b943aaefSJames Feist { 974b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningLow"); 975b943aaefSJames Feist } 976b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdNonCritical") 977b943aaefSJames Feist { 978b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningHigh"); 979b943aaefSJames Feist } 980b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdCritical") 981b943aaefSJames Feist { 982b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalLow"); 983b943aaefSJames Feist } 984b943aaefSJames Feist else if (*setpointOffset == "UpperThresholdCritical") 985b943aaefSJames Feist { 986b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalHigh"); 987b943aaefSJames Feist } 988b943aaefSJames Feist else 989b943aaefSJames Feist { 990b943aaefSJames Feist BMCWEB_LOG_ERROR << "Invalid setpointoffset " 991b943aaefSJames Feist << *setpointOffset; 992ace85d60SEd Tanous messages::propertyValueNotInList(response->res, it.key(), 993ace85d60SEd Tanous "SetPointOffset"); 994b943aaefSJames Feist return CreatePIDRet::fail; 995b943aaefSJames Feist } 996b943aaefSJames Feist } 997b943aaefSJames Feist 99883ff9ab6SJames Feist // doubles 9995f2caaefSJames Feist for (const auto& pairs : doubles) 100083ff9ab6SJames Feist { 10015f2caaefSJames Feist if (!pairs.second) 100283ff9ab6SJames Feist { 10035f2caaefSJames Feist continue; 100483ff9ab6SJames Feist } 10055f2caaefSJames Feist BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second; 1006b9d36b47SEd Tanous output.emplace_back(pairs.first, *pairs.second); 10075f2caaefSJames Feist } 100883ff9ab6SJames Feist } 100983ff9ab6SJames Feist 101083ff9ab6SJames Feist else if (type == "FanZones") 101183ff9ab6SJames Feist { 1012b9d36b47SEd Tanous output.emplace_back("Type", "Pid.Zone"); 101383ff9ab6SJames Feist 10145f2caaefSJames Feist std::optional<nlohmann::json> chassisContainer; 10155f2caaefSJames Feist std::optional<double> failSafePercent; 1016d3ec07f8SJames Feist std::optional<double> minThermalOutput; 1017b6baeaa4SJames Feist if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", 10185f2caaefSJames Feist chassisContainer, "FailSafePercent", 1019d3ec07f8SJames Feist failSafePercent, "MinThermalOutput", 1020d3ec07f8SJames Feist minThermalOutput)) 102183ff9ab6SJames Feist { 102271f52d96SEd Tanous BMCWEB_LOG_ERROR 102371f52d96SEd Tanous << "Illegal Property " 102471f52d96SEd Tanous << it.value().dump(2, ' ', true, 102571f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 102683ff9ab6SJames Feist return CreatePIDRet::fail; 102783ff9ab6SJames Feist } 10285f2caaefSJames Feist 10295f2caaefSJames Feist if (chassisContainer) 103083ff9ab6SJames Feist { 10315f2caaefSJames Feist 10325f2caaefSJames Feist std::string chassisId; 10335f2caaefSJames Feist if (!redfish::json_util::readJson(*chassisContainer, response->res, 10345f2caaefSJames Feist "@odata.id", chassisId)) 10355f2caaefSJames Feist { 103671f52d96SEd Tanous BMCWEB_LOG_ERROR 103771f52d96SEd Tanous << "Illegal Property " 103871f52d96SEd Tanous << chassisContainer->dump( 103971f52d96SEd Tanous 2, ' ', true, 104071f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 104183ff9ab6SJames Feist return CreatePIDRet::fail; 104283ff9ab6SJames Feist } 104383ff9ab6SJames Feist 1044717794d5SAppaRao Puli // /redfish/v1/chassis/chassis_name/ 10455f2caaefSJames Feist if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) 104683ff9ab6SJames Feist { 10475f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << chassisId; 1048ace85d60SEd Tanous messages::invalidObject( 1049ace85d60SEd Tanous response->res, crow::utility::urlFromPieces( 1050ace85d60SEd Tanous "redfish", "v1", "Chassis", chassisId)); 105183ff9ab6SJames Feist return CreatePIDRet::fail; 105283ff9ab6SJames Feist } 105383ff9ab6SJames Feist } 1054d3ec07f8SJames Feist if (minThermalOutput) 105583ff9ab6SJames Feist { 1056b9d36b47SEd Tanous output.emplace_back("MinThermalOutput", *minThermalOutput); 10575f2caaefSJames Feist } 10585f2caaefSJames Feist if (failSafePercent) 105983ff9ab6SJames Feist { 1060b9d36b47SEd Tanous output.emplace_back("FailSafePercent", *failSafePercent); 10615f2caaefSJames Feist } 10625f2caaefSJames Feist } 10635f2caaefSJames Feist else if (type == "StepwiseControllers") 10645f2caaefSJames Feist { 1065b9d36b47SEd Tanous output.emplace_back("Type", "Stepwise"); 10665f2caaefSJames Feist 10675f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 10685f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> steps; 10695f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 10705f2caaefSJames Feist std::optional<double> positiveHysteresis; 10715f2caaefSJames Feist std::optional<double> negativeHysteresis; 1072c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 10735f2caaefSJames Feist if (!redfish::json_util::readJson( 1074b6baeaa4SJames Feist it.value(), response->res, "Zones", zones, "Steps", steps, 1075b6baeaa4SJames Feist "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, 1076c33a90ecSJames Feist "NegativeHysteresis", negativeHysteresis, "Direction", 1077c33a90ecSJames Feist direction)) 10785f2caaefSJames Feist { 107971f52d96SEd Tanous BMCWEB_LOG_ERROR 108071f52d96SEd Tanous << "Illegal Property " 108171f52d96SEd Tanous << it.value().dump(2, ' ', true, 108271f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 108383ff9ab6SJames Feist return CreatePIDRet::fail; 108483ff9ab6SJames Feist } 10855f2caaefSJames Feist 10865f2caaefSJames Feist if (zones) 108783ff9ab6SJames Feist { 1088b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 1089b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 10905f2caaefSJames Feist { 1091a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 109283ff9ab6SJames Feist return CreatePIDRet::fail; 109383ff9ab6SJames Feist } 1094b6baeaa4SJames Feist if (chassis.empty() && 1095e662eae8SEd Tanous findChassis(managedObj, zonesStrs[0], chassis) == nullptr) 1096b6baeaa4SJames Feist { 1097b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 1098ace85d60SEd Tanous messages::invalidObject( 1099ace85d60SEd Tanous response->res, crow::utility::urlFromPieces( 1100ace85d60SEd Tanous "redfish", "v1", "Chassis", chassis)); 1101b6baeaa4SJames Feist return CreatePIDRet::fail; 1102b6baeaa4SJames Feist } 1103b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStrs)); 11045f2caaefSJames Feist } 11055f2caaefSJames Feist if (steps) 11065f2caaefSJames Feist { 11075f2caaefSJames Feist std::vector<double> readings; 11085f2caaefSJames Feist std::vector<double> outputs; 11095f2caaefSJames Feist for (auto& step : *steps) 11105f2caaefSJames Feist { 1111543f4400SEd Tanous double target = 0.0; 1112543f4400SEd Tanous double out = 0.0; 11135f2caaefSJames Feist 11145f2caaefSJames Feist if (!redfish::json_util::readJson(step, response->res, "Target", 111523a21a1cSEd Tanous target, "Output", out)) 11165f2caaefSJames Feist { 111771f52d96SEd Tanous BMCWEB_LOG_ERROR 111871f52d96SEd Tanous << "Illegal Property " 111971f52d96SEd Tanous << it.value().dump( 112071f52d96SEd Tanous 2, ' ', true, 112171f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 11225f2caaefSJames Feist return CreatePIDRet::fail; 11235f2caaefSJames Feist } 11245f2caaefSJames Feist readings.emplace_back(target); 112523a21a1cSEd Tanous outputs.emplace_back(out); 11265f2caaefSJames Feist } 1127b9d36b47SEd Tanous output.emplace_back("Reading", std::move(readings)); 1128b9d36b47SEd Tanous output.emplace_back("Output", std::move(outputs)); 11295f2caaefSJames Feist } 11305f2caaefSJames Feist if (inputs) 11315f2caaefSJames Feist { 11325f2caaefSJames Feist for (std::string& value : *inputs) 11335f2caaefSJames Feist { 11345f2caaefSJames Feist boost::replace_all(value, "_", " "); 11355f2caaefSJames Feist } 1136b9d36b47SEd Tanous output.emplace_back("Inputs", std::move(*inputs)); 11375f2caaefSJames Feist } 11385f2caaefSJames Feist if (negativeHysteresis) 11395f2caaefSJames Feist { 1140b9d36b47SEd Tanous output.emplace_back("NegativeHysteresis", *negativeHysteresis); 11415f2caaefSJames Feist } 11425f2caaefSJames Feist if (positiveHysteresis) 11435f2caaefSJames Feist { 1144b9d36b47SEd Tanous output.emplace_back("PositiveHysteresis", *positiveHysteresis); 114583ff9ab6SJames Feist } 1146c33a90ecSJames Feist if (direction) 1147c33a90ecSJames Feist { 1148c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 1149c33a90ecSJames Feist "Ceiling", "Floor"}; 1150c33a90ecSJames Feist if (std::find(allowedDirections.begin(), allowedDirections.end(), 1151c33a90ecSJames Feist *direction) == allowedDirections.end()) 1152c33a90ecSJames Feist { 1153c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 1154c33a90ecSJames Feist *direction); 1155c33a90ecSJames Feist return CreatePIDRet::fail; 1156c33a90ecSJames Feist } 1157b9d36b47SEd Tanous output.emplace_back("Class", *direction); 1158c33a90ecSJames Feist } 115983ff9ab6SJames Feist } 116083ff9ab6SJames Feist else 116183ff9ab6SJames Feist { 1162a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 116335a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 116483ff9ab6SJames Feist return CreatePIDRet::fail; 116583ff9ab6SJames Feist } 116683ff9ab6SJames Feist return CreatePIDRet::patch; 116783ff9ab6SJames Feist } 116873df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 116973df0db0SJames Feist { 117083ff9ab6SJames Feist 11714e23a444SEd Tanous explicit GetPIDValues( 11724e23a444SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : 117323a21a1cSEd Tanous asyncResp(asyncRespIn) 117473df0db0SJames Feist 11751214b7e7SGunnar Mills {} 11769c310685SBorawski.Lukasz 117773df0db0SJames Feist void run() 11785b4aa86bSJames Feist { 117973df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 118073df0db0SJames Feist 118173df0db0SJames Feist // get all configurations 11825b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 1183b9d36b47SEd Tanous [self]( 1184b9d36b47SEd Tanous const boost::system::error_code ec, 1185b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 11865b4aa86bSJames Feist if (ec) 11875b4aa86bSJames Feist { 11885b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 118973df0db0SJames Feist messages::internalError(self->asyncResp->res); 119073df0db0SJames Feist return; 119173df0db0SJames Feist } 119223a21a1cSEd Tanous self->subtree = subtreeLocal; 119373df0db0SJames Feist }, 119473df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", 119573df0db0SJames Feist "/xyz/openbmc_project/object_mapper", 119673df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 119773df0db0SJames Feist std::array<const char*, 4>{ 119873df0db0SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 119973df0db0SJames Feist objectManagerIface, stepwiseConfigurationIface}); 120073df0db0SJames Feist 120173df0db0SJames Feist // at the same time get the selected profile 120273df0db0SJames Feist crow::connections::systemBus->async_method_call( 1203b9d36b47SEd Tanous [self]( 1204b9d36b47SEd Tanous const boost::system::error_code ec, 1205b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 120623a21a1cSEd Tanous if (ec || subtreeLocal.empty()) 120773df0db0SJames Feist { 120873df0db0SJames Feist return; 120973df0db0SJames Feist } 121023a21a1cSEd Tanous if (subtreeLocal[0].second.size() != 1) 121173df0db0SJames Feist { 121273df0db0SJames Feist // invalid mapper response, should never happen 121373df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error"; 121473df0db0SJames Feist messages::internalError(self->asyncResp->res); 12155b4aa86bSJames Feist return; 12165b4aa86bSJames Feist } 12175b4aa86bSJames Feist 121823a21a1cSEd Tanous const std::string& path = subtreeLocal[0].first; 121923a21a1cSEd Tanous const std::string& owner = subtreeLocal[0].second[0].first; 122073df0db0SJames Feist crow::connections::systemBus->async_method_call( 1221168e20c1SEd Tanous [path, owner, 1222168e20c1SEd Tanous self](const boost::system::error_code ec2, 1223b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 122423a21a1cSEd Tanous if (ec2) 122573df0db0SJames Feist { 12260fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1227002d39b4SEd Tanous << "GetPIDValues: Can't get thermalModeIface " << path; 122873df0db0SJames Feist messages::internalError(self->asyncResp->res); 122973df0db0SJames Feist return; 123073df0db0SJames Feist } 1231271584abSEd Tanous const std::string* current = nullptr; 1232271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 12339eb808c1SEd Tanous for (const auto& [key, value] : resp) 123473df0db0SJames Feist { 123573df0db0SJames Feist if (key == "Current") 123673df0db0SJames Feist { 123773df0db0SJames Feist current = std::get_if<std::string>(&value); 123873df0db0SJames Feist if (current == nullptr) 123973df0db0SJames Feist { 124073df0db0SJames Feist BMCWEB_LOG_ERROR 12410fda0f12SGeorge Liu << "GetPIDValues: thermal mode iface invalid " 124273df0db0SJames Feist << path; 1243002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 124473df0db0SJames Feist return; 124573df0db0SJames Feist } 124673df0db0SJames Feist } 124773df0db0SJames Feist if (key == "Supported") 124873df0db0SJames Feist { 124973df0db0SJames Feist supported = 1250002d39b4SEd Tanous std::get_if<std::vector<std::string>>(&value); 125173df0db0SJames Feist if (supported == nullptr) 125273df0db0SJames Feist { 125373df0db0SJames Feist BMCWEB_LOG_ERROR 12540fda0f12SGeorge Liu << "GetPIDValues: thermal mode iface invalid" 125573df0db0SJames Feist << path; 1256002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 125773df0db0SJames Feist return; 125873df0db0SJames Feist } 125973df0db0SJames Feist } 126073df0db0SJames Feist } 126173df0db0SJames Feist if (current == nullptr || supported == nullptr) 126273df0db0SJames Feist { 12630fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1264002d39b4SEd Tanous << "GetPIDValues: thermal mode iface invalid " << path; 126573df0db0SJames Feist messages::internalError(self->asyncResp->res); 126673df0db0SJames Feist return; 126773df0db0SJames Feist } 126873df0db0SJames Feist self->currentProfile = *current; 126973df0db0SJames Feist self->supportedProfiles = *supported; 127073df0db0SJames Feist }, 127173df0db0SJames Feist owner, path, "org.freedesktop.DBus.Properties", "GetAll", 127273df0db0SJames Feist thermalModeIface); 127373df0db0SJames Feist }, 127473df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", 127573df0db0SJames Feist "/xyz/openbmc_project/object_mapper", 127673df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 127773df0db0SJames Feist std::array<const char*, 1>{thermalModeIface}); 127873df0db0SJames Feist } 127973df0db0SJames Feist 128073df0db0SJames Feist ~GetPIDValues() 128173df0db0SJames Feist { 128273df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 128373df0db0SJames Feist { 128473df0db0SJames Feist return; 128573df0db0SJames Feist } 12865b4aa86bSJames Feist // create map of <connection, path to objMgr>> 128773df0db0SJames Feist boost::container::flat_map<std::string, std::string> objectMgrPaths; 12886bce33bcSJames Feist boost::container::flat_set<std::string> calledConnections; 12895b4aa86bSJames Feist for (const auto& pathGroup : subtree) 12905b4aa86bSJames Feist { 12915b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 12925b4aa86bSJames Feist { 12936bce33bcSJames Feist auto findConnection = 12946bce33bcSJames Feist calledConnections.find(connectionGroup.first); 12956bce33bcSJames Feist if (findConnection != calledConnections.end()) 12966bce33bcSJames Feist { 12976bce33bcSJames Feist break; 12986bce33bcSJames Feist } 129973df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 13005b4aa86bSJames Feist { 13015b4aa86bSJames Feist if (interface == objectManagerIface) 13025b4aa86bSJames Feist { 130373df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 13045b4aa86bSJames Feist } 13055b4aa86bSJames Feist // this list is alphabetical, so we 13065b4aa86bSJames Feist // should have found the objMgr by now 13075b4aa86bSJames Feist if (interface == pidConfigurationIface || 1308b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1309b7a08d04SJames Feist interface == stepwiseConfigurationIface) 13105b4aa86bSJames Feist { 13115b4aa86bSJames Feist auto findObjMgr = 13125b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 13135b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 13145b4aa86bSJames Feist { 13155b4aa86bSJames Feist BMCWEB_LOG_DEBUG << connectionGroup.first 13165b4aa86bSJames Feist << "Has no Object Manager"; 13175b4aa86bSJames Feist continue; 13185b4aa86bSJames Feist } 13196bce33bcSJames Feist 13206bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 13216bce33bcSJames Feist 132273df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 132373df0db0SJames Feist currentProfile, supportedProfiles, 132473df0db0SJames Feist asyncResp); 13255b4aa86bSJames Feist break; 13265b4aa86bSJames Feist } 13275b4aa86bSJames Feist } 13285b4aa86bSJames Feist } 13295b4aa86bSJames Feist } 133073df0db0SJames Feist } 133173df0db0SJames Feist 1332ecd6a3a2SEd Tanous GetPIDValues(const GetPIDValues&) = delete; 1333ecd6a3a2SEd Tanous GetPIDValues(GetPIDValues&&) = delete; 1334ecd6a3a2SEd Tanous GetPIDValues& operator=(const GetPIDValues&) = delete; 1335ecd6a3a2SEd Tanous GetPIDValues& operator=(GetPIDValues&&) = delete; 1336ecd6a3a2SEd Tanous 133773df0db0SJames Feist std::vector<std::string> supportedProfiles; 133873df0db0SJames Feist std::string currentProfile; 1339b9d36b47SEd Tanous dbus::utility::MapperGetSubTreeResponse subtree; 13408d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 134173df0db0SJames Feist }; 134273df0db0SJames Feist 134373df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 134473df0db0SJames Feist { 134573df0db0SJames Feist 13468d1b46d7Szhanghch05 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, 134773df0db0SJames Feist nlohmann::json& data) : 1348271584abSEd Tanous asyncResp(asyncRespIn) 134973df0db0SJames Feist { 135073df0db0SJames Feist 135173df0db0SJames Feist std::optional<nlohmann::json> pidControllers; 135273df0db0SJames Feist std::optional<nlohmann::json> fanControllers; 135373df0db0SJames Feist std::optional<nlohmann::json> fanZones; 135473df0db0SJames Feist std::optional<nlohmann::json> stepwiseControllers; 135573df0db0SJames Feist 135673df0db0SJames Feist if (!redfish::json_util::readJson( 135773df0db0SJames Feist data, asyncResp->res, "PidControllers", pidControllers, 135873df0db0SJames Feist "FanControllers", fanControllers, "FanZones", fanZones, 135973df0db0SJames Feist "StepwiseControllers", stepwiseControllers, "Profile", profile)) 136073df0db0SJames Feist { 136171f52d96SEd Tanous BMCWEB_LOG_ERROR 136271f52d96SEd Tanous << "Illegal Property " 136371f52d96SEd Tanous << data.dump(2, ' ', true, 136471f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 136573df0db0SJames Feist return; 136673df0db0SJames Feist } 136773df0db0SJames Feist configuration.emplace_back("PidControllers", std::move(pidControllers)); 136873df0db0SJames Feist configuration.emplace_back("FanControllers", std::move(fanControllers)); 136973df0db0SJames Feist configuration.emplace_back("FanZones", std::move(fanZones)); 137073df0db0SJames Feist configuration.emplace_back("StepwiseControllers", 137173df0db0SJames Feist std::move(stepwiseControllers)); 137273df0db0SJames Feist } 1373ecd6a3a2SEd Tanous 1374ecd6a3a2SEd Tanous SetPIDValues(const SetPIDValues&) = delete; 1375ecd6a3a2SEd Tanous SetPIDValues(SetPIDValues&&) = delete; 1376ecd6a3a2SEd Tanous SetPIDValues& operator=(const SetPIDValues&) = delete; 1377ecd6a3a2SEd Tanous SetPIDValues& operator=(SetPIDValues&&) = delete; 1378ecd6a3a2SEd Tanous 137973df0db0SJames Feist void run() 138073df0db0SJames Feist { 138173df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 138273df0db0SJames Feist { 138373df0db0SJames Feist return; 138473df0db0SJames Feist } 138573df0db0SJames Feist 138673df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 138773df0db0SJames Feist 138873df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 138973df0db0SJames Feist // interface gets more traction 139073df0db0SJames Feist crow::connections::systemBus->async_method_call( 139173df0db0SJames Feist [self](const boost::system::error_code ec, 1392914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& mObj) { 139373df0db0SJames Feist if (ec) 139473df0db0SJames Feist { 139573df0db0SJames Feist BMCWEB_LOG_ERROR << "Error communicating to Entity Manager"; 139673df0db0SJames Feist messages::internalError(self->asyncResp->res); 139773df0db0SJames Feist return; 139873df0db0SJames Feist } 1399e69d9de2SJames Feist const std::array<const char*, 3> configurations = { 1400e69d9de2SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 1401e69d9de2SJames Feist stepwiseConfigurationIface}; 1402e69d9de2SJames Feist 140314b0b8d5SJames Feist for (const auto& [path, object] : mObj) 1404e69d9de2SJames Feist { 140514b0b8d5SJames Feist for (const auto& [interface, _] : object) 1406e69d9de2SJames Feist { 1407002d39b4SEd Tanous if (std::find(configurations.begin(), configurations.end(), 1408e69d9de2SJames Feist interface) != configurations.end()) 1409e69d9de2SJames Feist { 141014b0b8d5SJames Feist self->objectCount++; 1411e69d9de2SJames Feist break; 1412e69d9de2SJames Feist } 1413e69d9de2SJames Feist } 1414e69d9de2SJames Feist } 1415914e2d5dSEd Tanous self->managedObj = mObj; 141673df0db0SJames Feist }, 141773df0db0SJames Feist "xyz.openbmc_project.EntityManager", "/", objectManagerIface, 141873df0db0SJames Feist "GetManagedObjects"); 141973df0db0SJames Feist 142073df0db0SJames Feist // at the same time get the profile information 142173df0db0SJames Feist crow::connections::systemBus->async_method_call( 142273df0db0SJames Feist [self](const boost::system::error_code ec, 1423b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 142473df0db0SJames Feist if (ec || subtree.empty()) 142573df0db0SJames Feist { 142673df0db0SJames Feist return; 142773df0db0SJames Feist } 142873df0db0SJames Feist if (subtree[0].second.empty()) 142973df0db0SJames Feist { 143073df0db0SJames Feist // invalid mapper response, should never happen 143173df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error"; 143273df0db0SJames Feist messages::internalError(self->asyncResp->res); 143373df0db0SJames Feist return; 143473df0db0SJames Feist } 143573df0db0SJames Feist 143673df0db0SJames Feist const std::string& path = subtree[0].first; 143773df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 143873df0db0SJames Feist crow::connections::systemBus->async_method_call( 1439002d39b4SEd Tanous [self, path, owner](const boost::system::error_code ec2, 1440b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& r) { 1441cb13a392SEd Tanous if (ec2) 144273df0db0SJames Feist { 14430fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1444002d39b4SEd Tanous << "SetPIDValues: Can't get thermalModeIface " << path; 144573df0db0SJames Feist messages::internalError(self->asyncResp->res); 144673df0db0SJames Feist return; 144773df0db0SJames Feist } 1448271584abSEd Tanous const std::string* current = nullptr; 1449271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 14509eb808c1SEd Tanous for (const auto& [key, value] : r) 145173df0db0SJames Feist { 145273df0db0SJames Feist if (key == "Current") 145373df0db0SJames Feist { 145473df0db0SJames Feist current = std::get_if<std::string>(&value); 145573df0db0SJames Feist if (current == nullptr) 145673df0db0SJames Feist { 145773df0db0SJames Feist BMCWEB_LOG_ERROR 14580fda0f12SGeorge Liu << "SetPIDValues: thermal mode iface invalid " 145973df0db0SJames Feist << path; 1460002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 146173df0db0SJames Feist return; 146273df0db0SJames Feist } 146373df0db0SJames Feist } 146473df0db0SJames Feist if (key == "Supported") 146573df0db0SJames Feist { 146673df0db0SJames Feist supported = 1467002d39b4SEd Tanous std::get_if<std::vector<std::string>>(&value); 146873df0db0SJames Feist if (supported == nullptr) 146973df0db0SJames Feist { 147073df0db0SJames Feist BMCWEB_LOG_ERROR 14710fda0f12SGeorge Liu << "SetPIDValues: thermal mode iface invalid" 147273df0db0SJames Feist << path; 1473002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 147473df0db0SJames Feist return; 147573df0db0SJames Feist } 147673df0db0SJames Feist } 147773df0db0SJames Feist } 147873df0db0SJames Feist if (current == nullptr || supported == nullptr) 147973df0db0SJames Feist { 14800fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1481002d39b4SEd Tanous << "SetPIDValues: thermal mode iface invalid " << path; 148273df0db0SJames Feist messages::internalError(self->asyncResp->res); 148373df0db0SJames Feist return; 148473df0db0SJames Feist } 148573df0db0SJames Feist self->currentProfile = *current; 148673df0db0SJames Feist self->supportedProfiles = *supported; 148773df0db0SJames Feist self->profileConnection = owner; 148873df0db0SJames Feist self->profilePath = path; 148973df0db0SJames Feist }, 149073df0db0SJames Feist owner, path, "org.freedesktop.DBus.Properties", "GetAll", 149173df0db0SJames Feist thermalModeIface); 14925b4aa86bSJames Feist }, 14935b4aa86bSJames Feist "xyz.openbmc_project.ObjectMapper", 14945b4aa86bSJames Feist "/xyz/openbmc_project/object_mapper", 14955b4aa86bSJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 149673df0db0SJames Feist std::array<const char*, 1>{thermalModeIface}); 149773df0db0SJames Feist } 149824b2fe81SEd Tanous void pidSetDone() 149973df0db0SJames Feist { 150073df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 150173df0db0SJames Feist { 150273df0db0SJames Feist return; 15035b4aa86bSJames Feist } 15048d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; 150573df0db0SJames Feist if (profile) 150673df0db0SJames Feist { 150773df0db0SJames Feist if (std::find(supportedProfiles.begin(), supportedProfiles.end(), 150873df0db0SJames Feist *profile) == supportedProfiles.end()) 150973df0db0SJames Feist { 151073df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 151173df0db0SJames Feist *profile); 151273df0db0SJames Feist return; 151373df0db0SJames Feist } 151473df0db0SJames Feist currentProfile = *profile; 151573df0db0SJames Feist crow::connections::systemBus->async_method_call( 151673df0db0SJames Feist [response](const boost::system::error_code ec) { 151773df0db0SJames Feist if (ec) 151873df0db0SJames Feist { 151973df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching profile" << ec; 152073df0db0SJames Feist messages::internalError(response->res); 152173df0db0SJames Feist } 152273df0db0SJames Feist }, 152373df0db0SJames Feist profileConnection, profilePath, 152473df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", thermalModeIface, 1525168e20c1SEd Tanous "Current", dbus::utility::DbusVariantType(*profile)); 152673df0db0SJames Feist } 152773df0db0SJames Feist 152873df0db0SJames Feist for (auto& containerPair : configuration) 152973df0db0SJames Feist { 153073df0db0SJames Feist auto& container = containerPair.second; 153173df0db0SJames Feist if (!container) 153273df0db0SJames Feist { 153373df0db0SJames Feist continue; 153473df0db0SJames Feist } 15356ee7f774SJames Feist BMCWEB_LOG_DEBUG << *container; 15366ee7f774SJames Feist 153702cad96eSEd Tanous const std::string& type = containerPair.first; 153873df0db0SJames Feist 153973df0db0SJames Feist for (nlohmann::json::iterator it = container->begin(); 154017a897dfSManojkiran Eda it != container->end(); ++it) 154173df0db0SJames Feist { 154273df0db0SJames Feist const auto& name = it.key(); 15436ee7f774SJames Feist BMCWEB_LOG_DEBUG << "looking for " << name; 15446ee7f774SJames Feist 154573df0db0SJames Feist auto pathItr = 154673df0db0SJames Feist std::find_if(managedObj.begin(), managedObj.end(), 154773df0db0SJames Feist [&name](const auto& obj) { 1548002d39b4SEd Tanous return boost::algorithm::ends_with(obj.first.str, 1549002d39b4SEd Tanous "/" + name); 155073df0db0SJames Feist }); 1551b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap output; 155273df0db0SJames Feist 155373df0db0SJames Feist output.reserve(16); // The pid interface length 155473df0db0SJames Feist 155573df0db0SJames Feist // determines if we're patching entity-manager or 155673df0db0SJames Feist // creating a new object 155773df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 15586ee7f774SJames Feist BMCWEB_LOG_DEBUG << "Found = " << !createNewObject; 15596ee7f774SJames Feist 156073df0db0SJames Feist std::string iface; 1561711ac7a9SEd Tanous /* 156273df0db0SJames Feist if (type == "PidControllers" || type == "FanControllers") 156373df0db0SJames Feist { 156473df0db0SJames Feist iface = pidConfigurationIface; 156573df0db0SJames Feist if (!createNewObject && 156673df0db0SJames Feist pathItr->second.find(pidConfigurationIface) == 156773df0db0SJames Feist pathItr->second.end()) 156873df0db0SJames Feist { 156973df0db0SJames Feist createNewObject = true; 157073df0db0SJames Feist } 157173df0db0SJames Feist } 157273df0db0SJames Feist else if (type == "FanZones") 157373df0db0SJames Feist { 157473df0db0SJames Feist iface = pidZoneConfigurationIface; 157573df0db0SJames Feist if (!createNewObject && 157673df0db0SJames Feist pathItr->second.find(pidZoneConfigurationIface) == 157773df0db0SJames Feist pathItr->second.end()) 157873df0db0SJames Feist { 157973df0db0SJames Feist 158073df0db0SJames Feist createNewObject = true; 158173df0db0SJames Feist } 158273df0db0SJames Feist } 158373df0db0SJames Feist else if (type == "StepwiseControllers") 158473df0db0SJames Feist { 158573df0db0SJames Feist iface = stepwiseConfigurationIface; 158673df0db0SJames Feist if (!createNewObject && 158773df0db0SJames Feist pathItr->second.find(stepwiseConfigurationIface) == 158873df0db0SJames Feist pathItr->second.end()) 158973df0db0SJames Feist { 159073df0db0SJames Feist createNewObject = true; 159173df0db0SJames Feist } 1592711ac7a9SEd Tanous }*/ 15936ee7f774SJames Feist 15946ee7f774SJames Feist if (createNewObject && it.value() == nullptr) 15956ee7f774SJames Feist { 15964e0453b1SGunnar Mills // can't delete a non-existent object 15971668ce6dSEd Tanous messages::propertyValueNotInList(response->res, 15981668ce6dSEd Tanous it.value().dump(), name); 15996ee7f774SJames Feist continue; 16006ee7f774SJames Feist } 16016ee7f774SJames Feist 16026ee7f774SJames Feist std::string path; 16036ee7f774SJames Feist if (pathItr != managedObj.end()) 16046ee7f774SJames Feist { 16056ee7f774SJames Feist path = pathItr->first.str; 16066ee7f774SJames Feist } 16076ee7f774SJames Feist 160873df0db0SJames Feist BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n"; 1609e69d9de2SJames Feist 1610e69d9de2SJames Feist // arbitrary limit to avoid attacks 1611e69d9de2SJames Feist constexpr const size_t controllerLimit = 500; 161214b0b8d5SJames Feist if (createNewObject && objectCount >= controllerLimit) 1613e69d9de2SJames Feist { 1614e69d9de2SJames Feist messages::resourceExhaustion(response->res, type); 1615e69d9de2SJames Feist continue; 1616e69d9de2SJames Feist } 1617b9d36b47SEd Tanous output.emplace_back("Name", 1618b9d36b47SEd Tanous boost::replace_all_copy(name, "_", " ")); 161973df0db0SJames Feist 162073df0db0SJames Feist std::string chassis; 162173df0db0SJames Feist CreatePIDRet ret = createPidInterface( 16226ee7f774SJames Feist response, type, it, path, managedObj, createNewObject, 16236ee7f774SJames Feist output, chassis, currentProfile); 162473df0db0SJames Feist if (ret == CreatePIDRet::fail) 162573df0db0SJames Feist { 162673df0db0SJames Feist return; 162773df0db0SJames Feist } 16283174e4dfSEd Tanous if (ret == CreatePIDRet::del) 162973df0db0SJames Feist { 163073df0db0SJames Feist continue; 163173df0db0SJames Feist } 163273df0db0SJames Feist 163373df0db0SJames Feist if (!createNewObject) 163473df0db0SJames Feist { 163573df0db0SJames Feist for (const auto& property : output) 163673df0db0SJames Feist { 163773df0db0SJames Feist crow::connections::systemBus->async_method_call( 163873df0db0SJames Feist [response, 163973df0db0SJames Feist propertyName{std::string(property.first)}]( 164073df0db0SJames Feist const boost::system::error_code ec) { 164173df0db0SJames Feist if (ec) 164273df0db0SJames Feist { 164373df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching " 1644002d39b4SEd Tanous << propertyName << ": " << ec; 164573df0db0SJames Feist messages::internalError(response->res); 164673df0db0SJames Feist return; 164773df0db0SJames Feist } 164873df0db0SJames Feist messages::success(response->res); 164973df0db0SJames Feist }, 16506ee7f774SJames Feist "xyz.openbmc_project.EntityManager", path, 165173df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", iface, 165273df0db0SJames Feist property.first, property.second); 165373df0db0SJames Feist } 165473df0db0SJames Feist } 165573df0db0SJames Feist else 165673df0db0SJames Feist { 165773df0db0SJames Feist if (chassis.empty()) 165873df0db0SJames Feist { 165973df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config"; 1660ace85d60SEd Tanous messages::internalError(response->res); 166173df0db0SJames Feist return; 166273df0db0SJames Feist } 166373df0db0SJames Feist 166473df0db0SJames Feist bool foundChassis = false; 166573df0db0SJames Feist for (const auto& obj : managedObj) 166673df0db0SJames Feist { 166773df0db0SJames Feist if (boost::algorithm::ends_with(obj.first.str, chassis)) 166873df0db0SJames Feist { 166973df0db0SJames Feist chassis = obj.first.str; 167073df0db0SJames Feist foundChassis = true; 167173df0db0SJames Feist break; 167273df0db0SJames Feist } 167373df0db0SJames Feist } 167473df0db0SJames Feist if (!foundChassis) 167573df0db0SJames Feist { 167673df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to find chassis on dbus"; 167773df0db0SJames Feist messages::resourceMissingAtURI( 1678ace85d60SEd Tanous response->res, 1679ace85d60SEd Tanous crow::utility::urlFromPieces("redfish", "v1", 1680ace85d60SEd Tanous "Chassis", chassis)); 168173df0db0SJames Feist return; 168273df0db0SJames Feist } 168373df0db0SJames Feist 168473df0db0SJames Feist crow::connections::systemBus->async_method_call( 168573df0db0SJames Feist [response](const boost::system::error_code ec) { 168673df0db0SJames Feist if (ec) 168773df0db0SJames Feist { 168873df0db0SJames Feist BMCWEB_LOG_ERROR << "Error Adding Pid Object " 168973df0db0SJames Feist << ec; 169073df0db0SJames Feist messages::internalError(response->res); 169173df0db0SJames Feist return; 169273df0db0SJames Feist } 169373df0db0SJames Feist messages::success(response->res); 169473df0db0SJames Feist }, 169573df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 169673df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 169773df0db0SJames Feist } 169873df0db0SJames Feist } 169973df0db0SJames Feist } 170073df0db0SJames Feist } 170124b2fe81SEd Tanous 170224b2fe81SEd Tanous ~SetPIDValues() 170324b2fe81SEd Tanous { 170424b2fe81SEd Tanous try 170524b2fe81SEd Tanous { 170624b2fe81SEd Tanous pidSetDone(); 170724b2fe81SEd Tanous } 170824b2fe81SEd Tanous catch (...) 170924b2fe81SEd Tanous { 171024b2fe81SEd Tanous BMCWEB_LOG_CRITICAL << "pidSetDone threw exception"; 171124b2fe81SEd Tanous } 171224b2fe81SEd Tanous } 171324b2fe81SEd Tanous 17148d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 171573df0db0SJames Feist std::vector<std::pair<std::string, std::optional<nlohmann::json>>> 171673df0db0SJames Feist configuration; 171773df0db0SJames Feist std::optional<std::string> profile; 171873df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 171973df0db0SJames Feist std::vector<std::string> supportedProfiles; 172073df0db0SJames Feist std::string currentProfile; 172173df0db0SJames Feist std::string profileConnection; 172273df0db0SJames Feist std::string profilePath; 172314b0b8d5SJames Feist size_t objectCount = 0; 172473df0db0SJames Feist }; 172573df0db0SJames Feist 1726071d8fdfSSunnySrivastava1984 /** 1727071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 1728071d8fdfSSunnySrivastava1984 * 1729071d8fdfSSunnySrivastava1984 * @param[in] aResp Shared pointer for completing asynchronous calls 1730071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 1731071d8fdfSSunnySrivastava1984 * @param[in] path - object path 1732071d8fdfSSunnySrivastava1984 * @return none 1733071d8fdfSSunnySrivastava1984 */ 17348d1b46d7Szhanghch05 inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1735071d8fdfSSunnySrivastava1984 const std::string& connectionName, 1736071d8fdfSSunnySrivastava1984 const std::string& path) 1737071d8fdfSSunnySrivastava1984 { 1738071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Get BMC manager Location data."; 1739071d8fdfSSunnySrivastava1984 17401e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 17411e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 17421e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 1743071d8fdfSSunnySrivastava1984 [aResp](const boost::system::error_code ec, 17441e1e598dSJonathan Doman const std::string& property) { 1745071d8fdfSSunnySrivastava1984 if (ec) 1746071d8fdfSSunnySrivastava1984 { 1747071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "DBUS response error for " 1748071d8fdfSSunnySrivastava1984 "Location"; 1749071d8fdfSSunnySrivastava1984 messages::internalError(aResp->res); 1750071d8fdfSSunnySrivastava1984 return; 1751071d8fdfSSunnySrivastava1984 } 1752071d8fdfSSunnySrivastava1984 1753071d8fdfSSunnySrivastava1984 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 17541e1e598dSJonathan Doman property; 17551e1e598dSJonathan Doman }); 1756071d8fdfSSunnySrivastava1984 } 17577e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 17587e860f15SJohn Edward Broadbent inline void 17597e860f15SJohn Edward Broadbent managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 17604bf2b033SGunnar Mills { 17614bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time"; 17624bf2b033SGunnar Mills 17631e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint64_t>( 17641e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.BMC", 17651e1e598dSJonathan Doman "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC", 17661e1e598dSJonathan Doman "LastRebootTime", 17674bf2b033SGunnar Mills [aResp](const boost::system::error_code ec, 17681e1e598dSJonathan Doman const uint64_t lastResetTime) { 17694bf2b033SGunnar Mills if (ec) 17704bf2b033SGunnar Mills { 17714bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 17724bf2b033SGunnar Mills return; 17734bf2b033SGunnar Mills } 17744bf2b033SGunnar Mills 17754bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 17764bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 17771e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 17784bf2b033SGunnar Mills 17794bf2b033SGunnar Mills // Convert to ISO 8601 standard 17804bf2b033SGunnar Mills aResp->res.jsonValue["LastResetTime"] = 17811d8782e7SNan Zhou crow::utility::getDateTimeUint(lastResetTimeStamp); 17821e1e598dSJonathan Doman }); 17834bf2b033SGunnar Mills } 17844bf2b033SGunnar Mills 17854bfefa74SGunnar Mills /** 17864bfefa74SGunnar Mills * @brief Set the running firmware image 17874bfefa74SGunnar Mills * 17884bfefa74SGunnar Mills * @param[i,o] aResp - Async response object 17894bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 17904bfefa74SGunnar Mills * 17914bfefa74SGunnar Mills * @return void 17924bfefa74SGunnar Mills */ 17937e860f15SJohn Edward Broadbent inline void 17947e860f15SJohn Edward Broadbent setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1795f23b7296SEd Tanous const std::string& runningFirmwareTarget) 17964bfefa74SGunnar Mills { 17974bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 1798f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 17994bfefa74SGunnar Mills if (idPos == std::string::npos) 18004bfefa74SGunnar Mills { 18014bfefa74SGunnar Mills messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 18024bfefa74SGunnar Mills "@odata.id"); 18034bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't parse firmware ID!"; 18044bfefa74SGunnar Mills return; 18054bfefa74SGunnar Mills } 18064bfefa74SGunnar Mills idPos++; 18074bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 18084bfefa74SGunnar Mills { 18094bfefa74SGunnar Mills messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 18104bfefa74SGunnar Mills "@odata.id"); 18114bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 18124bfefa74SGunnar Mills return; 18134bfefa74SGunnar Mills } 18144bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 18154bfefa74SGunnar Mills 18164bfefa74SGunnar Mills // Make sure the image is valid before setting priority 18174bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 1818711ac7a9SEd Tanous [aResp, firmwareId, 1819711ac7a9SEd Tanous runningFirmwareTarget](const boost::system::error_code ec, 1820711ac7a9SEd Tanous dbus::utility::ManagedObjectType& subtree) { 18214bfefa74SGunnar Mills if (ec) 18224bfefa74SGunnar Mills { 18234bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error getting objects."; 18244bfefa74SGunnar Mills messages::internalError(aResp->res); 18254bfefa74SGunnar Mills return; 18264bfefa74SGunnar Mills } 18274bfefa74SGunnar Mills 182826f6976fSEd Tanous if (subtree.empty()) 18294bfefa74SGunnar Mills { 18304bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't find image!"; 18314bfefa74SGunnar Mills messages::internalError(aResp->res); 18324bfefa74SGunnar Mills return; 18334bfefa74SGunnar Mills } 18344bfefa74SGunnar Mills 18354bfefa74SGunnar Mills bool foundImage = false; 183602cad96eSEd Tanous for (const auto& object : subtree) 18374bfefa74SGunnar Mills { 18384bfefa74SGunnar Mills const std::string& path = 18394bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 1840f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 18414bfefa74SGunnar Mills 18424bfefa74SGunnar Mills if (idPos2 == std::string::npos) 18434bfefa74SGunnar Mills { 18444bfefa74SGunnar Mills continue; 18454bfefa74SGunnar Mills } 18464bfefa74SGunnar Mills 18474bfefa74SGunnar Mills idPos2++; 18484bfefa74SGunnar Mills if (idPos2 >= path.size()) 18494bfefa74SGunnar Mills { 18504bfefa74SGunnar Mills continue; 18514bfefa74SGunnar Mills } 18524bfefa74SGunnar Mills 18534bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 18544bfefa74SGunnar Mills { 18554bfefa74SGunnar Mills foundImage = true; 18564bfefa74SGunnar Mills break; 18574bfefa74SGunnar Mills } 18584bfefa74SGunnar Mills } 18594bfefa74SGunnar Mills 18604bfefa74SGunnar Mills if (!foundImage) 18614bfefa74SGunnar Mills { 1862002d39b4SEd Tanous messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 1863002d39b4SEd Tanous "@odata.id"); 18644bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 18654bfefa74SGunnar Mills return; 18664bfefa74SGunnar Mills } 18674bfefa74SGunnar Mills 18688cc8edecSEd Tanous BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId 18698cc8edecSEd Tanous << " to priority 0."; 18704bfefa74SGunnar Mills 18714bfefa74SGunnar Mills // Only support Immediate 18724bfefa74SGunnar Mills // An addition could be a Redfish Setting like 18734bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 18744bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 18758a592810SEd Tanous [aResp](const boost::system::error_code ec2) { 18768a592810SEd Tanous if (ec2) 18774bfefa74SGunnar Mills { 18784bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error setting."; 18794bfefa74SGunnar Mills messages::internalError(aResp->res); 18804bfefa74SGunnar Mills return; 18814bfefa74SGunnar Mills } 18824bfefa74SGunnar Mills doBMCGracefulRestart(aResp); 18834bfefa74SGunnar Mills }, 18844bfefa74SGunnar Mills 18854bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18864bfefa74SGunnar Mills "/xyz/openbmc_project/software/" + firmwareId, 18874bfefa74SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 18887e860f15SJohn Edward Broadbent "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 1889168e20c1SEd Tanous dbus::utility::DbusVariantType(static_cast<uint8_t>(0))); 18904bfefa74SGunnar Mills }, 18914bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18927e860f15SJohn Edward Broadbent "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager", 18937e860f15SJohn Edward Broadbent "GetManagedObjects"); 18944bfefa74SGunnar Mills } 18954bfefa74SGunnar Mills 18967e860f15SJohn Edward Broadbent inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp, 18977e860f15SJohn Edward Broadbent std::string datetime) 1898af5d6058SSantosh Puranik { 1899af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Set date time: " << datetime; 1900af5d6058SSantosh Puranik 1901af5d6058SSantosh Puranik std::stringstream stream(datetime); 1902af5d6058SSantosh Puranik // Convert from ISO 8601 to boost local_time 1903af5d6058SSantosh Puranik // (BMC only has time in UTC) 1904af5d6058SSantosh Puranik boost::posix_time::ptime posixTime; 1905af5d6058SSantosh Puranik boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); 1906af5d6058SSantosh Puranik // Facet gets deleted with the stringsteam 1907af5d6058SSantosh Puranik auto ifc = std::make_unique<boost::local_time::local_time_input_facet>( 1908af5d6058SSantosh Puranik "%Y-%m-%d %H:%M:%S%F %ZP"); 1909af5d6058SSantosh Puranik stream.imbue(std::locale(stream.getloc(), ifc.release())); 1910af5d6058SSantosh Puranik 19117e860f15SJohn Edward Broadbent boost::local_time::local_date_time ldt(boost::local_time::not_a_date_time); 1912af5d6058SSantosh Puranik 1913af5d6058SSantosh Puranik if (stream >> ldt) 1914af5d6058SSantosh Puranik { 1915af5d6058SSantosh Puranik posixTime = ldt.utc_time(); 1916af5d6058SSantosh Puranik boost::posix_time::time_duration dur = posixTime - epoch; 19177e860f15SJohn Edward Broadbent uint64_t durMicroSecs = static_cast<uint64_t>(dur.total_microseconds()); 1918af5d6058SSantosh Puranik crow::connections::systemBus->async_method_call( 1919af5d6058SSantosh Puranik [aResp{std::move(aResp)}, datetime{std::move(datetime)}]( 1920af5d6058SSantosh Puranik const boost::system::error_code ec) { 1921af5d6058SSantosh Puranik if (ec) 1922af5d6058SSantosh Puranik { 1923af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Failed to set elapsed time. " 1924af5d6058SSantosh Puranik "DBUS response error " 1925af5d6058SSantosh Puranik << ec; 1926af5d6058SSantosh Puranik messages::internalError(aResp->res); 1927af5d6058SSantosh Puranik return; 1928af5d6058SSantosh Puranik } 1929af5d6058SSantosh Puranik aResp->res.jsonValue["DateTime"] = datetime; 1930af5d6058SSantosh Puranik }, 19317e860f15SJohn Edward Broadbent "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc", 1932af5d6058SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1933af5d6058SSantosh Puranik "xyz.openbmc_project.Time.EpochTime", "Elapsed", 1934168e20c1SEd Tanous dbus::utility::DbusVariantType(durMicroSecs)); 1935af5d6058SSantosh Puranik } 1936af5d6058SSantosh Puranik else 1937af5d6058SSantosh Puranik { 19387e860f15SJohn Edward Broadbent messages::propertyValueFormatError(aResp->res, datetime, "DateTime"); 1939af5d6058SSantosh Puranik return; 1940af5d6058SSantosh Puranik } 194183ff9ab6SJames Feist } 19429c310685SBorawski.Lukasz 19437e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 19447e860f15SJohn Edward Broadbent { 19457e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 19469c310685SBorawski.Lukasz 19477e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 1948ed398213SEd Tanous .privileges(redfish::privileges::getManager) 1949002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1950002d39b4SEd Tanous [&app, uuid](const crow::Request& req, 195145ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 19523ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 195345ca1b86SEd Tanous { 195445ca1b86SEd Tanous return; 195545ca1b86SEd Tanous } 19567e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; 1957*a51fc2d2SSui Chen asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager"; 19587e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "bmc"; 19597e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 19607e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 19617e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 19627e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["PowerState"] = "On"; 19631476687dSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 19641476687dSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 19651476687dSEd Tanous 19667e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ManagerType"] = "BMC"; 19677e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 19687e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 1969002d39b4SEd Tanous asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model 19707e860f15SJohn Edward Broadbent 19711476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 19721476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices"; 19731476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 19741476687dSEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol"; 19751476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 19761476687dSEd Tanous "/redfish/v1/Managers/bmc/EthernetInterfaces"; 19777e860f15SJohn Edward Broadbent 19787e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_VM_NBDPROXY 19791476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 19801476687dSEd Tanous "/redfish/v1/Managers/bmc/VirtualMedia"; 19817e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_VM_NBDPROXY 19827e860f15SJohn Edward Broadbent 19837e860f15SJohn Edward Broadbent // default oem data 19847e860f15SJohn Edward Broadbent nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; 19857e860f15SJohn Edward Broadbent nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 19867e860f15SJohn Edward Broadbent oem["@odata.type"] = "#OemManager.Oem"; 19877e860f15SJohn Edward Broadbent oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; 19887e860f15SJohn Edward Broadbent oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; 19897e860f15SJohn Edward Broadbent oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; 19901476687dSEd Tanous 19911476687dSEd Tanous nlohmann::json::object_t certificates; 19921476687dSEd Tanous certificates["@odata.id"] = 19931476687dSEd Tanous "/redfish/v1/Managers/bmc/Truststore/Certificates"; 19941476687dSEd Tanous oemOpenbmc["Certificates"] = std::move(certificates); 19957e860f15SJohn Edward Broadbent 19967e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 19977e860f15SJohn Edward Broadbent // supports BMC reboot. 19987e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 19997e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 20007e860f15SJohn Edward Broadbent managerReset["target"] = 20017e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; 20027e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 20037e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/ResetActionInfo"; 20047e860f15SJohn Edward Broadbent 20057e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 20067e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 20077e860f15SJohn Edward Broadbent // on OpenBMC 20087e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 20097e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 20107e860f15SJohn Edward Broadbent resetToDefaults["target"] = 20117e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults"; 20127e860f15SJohn Edward Broadbent resetToDefaults["ResetType@Redfish.AllowableValues"] = {"ResetAll"}; 20137e860f15SJohn Edward Broadbent 20147c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 20157c8c4058STejas Patil crow::utility::getDateTimeOffsetNow(); 20167c8c4058STejas Patil 20177c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 20187c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 20197c8c4058STejas Patil redfishDateTimeOffset.second; 20207e860f15SJohn Edward Broadbent 20210e8ac5e7SGunnar Mills // TODO (Gunnar): Remove these one day since moved to ComputerSystem 20220e8ac5e7SGunnar Mills // Still used by OCP profiles 20230e8ac5e7SGunnar Mills // https://github.com/opencomputeproject/OCP-Profiles/issues/23 20247e860f15SJohn Edward Broadbent // Fill in SerialConsole info 20257e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; 2026002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 2027002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = { 2028002d39b4SEd Tanous "IPMI", "SSH"}; 20297e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_KVM 20307e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 2031002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 2032002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 2033002d39b4SEd Tanous 4; 20347e860f15SJohn Edward Broadbent asyncResp->res 2035002d39b4SEd Tanous .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = {"KVMIP"}; 20367e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_KVM 20377e860f15SJohn Edward Broadbent 2038002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 20391476687dSEd Tanous 20401476687dSEd Tanous nlohmann::json::array_t managerForServers; 20411476687dSEd Tanous nlohmann::json::object_t manager; 20421476687dSEd Tanous manager["@odata.id"] = "/redfish/v1/Systems/system"; 20431476687dSEd Tanous managerForServers.push_back(std::move(manager)); 20441476687dSEd Tanous 20451476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 20461476687dSEd Tanous std::move(managerForServers); 20477e860f15SJohn Edward Broadbent 20487e860f15SJohn Edward Broadbent auto health = std::make_shared<HealthPopulate>(asyncResp); 20497e860f15SJohn Edward Broadbent health->isManagersHealth = true; 20507e860f15SJohn Edward Broadbent health->populate(); 20517e860f15SJohn Edward Broadbent 2052eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 20537e860f15SJohn Edward Broadbent "FirmwareVersion", true); 20547e860f15SJohn Edward Broadbent 20557e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 20567e860f15SJohn Edward Broadbent 2057*a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 2058*a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 2059*a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 2060*a51fc2d2SSui Chen managerDiagnosticData["@odata.id"] = 2061*a51fc2d2SSui Chen "/redfish/v1/Managers/bmc/ManagerDiagnosticData"; 2062*a51fc2d2SSui Chen 20637e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp); 20647e860f15SJohn Edward Broadbent pids->run(); 20657e860f15SJohn Edward Broadbent 2066002d39b4SEd Tanous getMainChassisId(asyncResp, 2067002d39b4SEd Tanous [](const std::string& chassisId, 2068002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2069002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1; 20701476687dSEd Tanous nlohmann::json::array_t managerForChassis; 20718a592810SEd Tanous nlohmann::json::object_t managerObj; 20728a592810SEd Tanous managerObj["@odata.id"] = "/redfish/v1/Chassis/" + chassisId; 20738a592810SEd Tanous managerForChassis.push_back(std::move(managerObj)); 20741476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 20751476687dSEd Tanous std::move(managerForChassis); 20761476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 20771476687dSEd Tanous "/redfish/v1/Chassis/" + chassisId; 20787e860f15SJohn Edward Broadbent }); 20797e860f15SJohn Edward Broadbent 20807e860f15SJohn Edward Broadbent static bool started = false; 20817e860f15SJohn Edward Broadbent 20827e860f15SJohn Edward Broadbent if (!started) 20831abe55efSEd Tanous { 20841e1e598dSJonathan Doman sdbusplus::asio::getProperty<double>( 20851e1e598dSJonathan Doman *crow::connections::systemBus, "org.freedesktop.systemd1", 2086002d39b4SEd Tanous "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", 2087002d39b4SEd Tanous "Progress", 20887e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code ec, 20891e1e598dSJonathan Doman const double& val) { 20907e860f15SJohn Edward Broadbent if (ec) 20911abe55efSEd Tanous { 20927e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Error while getting progress"; 20937e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20947e860f15SJohn Edward Broadbent return; 20957e860f15SJohn Edward Broadbent } 20961e1e598dSJonathan Doman if (val < 1.0) 20977e860f15SJohn Edward Broadbent { 2098002d39b4SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Starting"; 20997e860f15SJohn Edward Broadbent started = true; 21007e860f15SJohn Edward Broadbent } 21011e1e598dSJonathan Doman }); 21029c310685SBorawski.Lukasz } 21039c310685SBorawski.Lukasz 21047e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 21057e860f15SJohn Edward Broadbent [asyncResp]( 21067e860f15SJohn Edward Broadbent const boost::system::error_code ec, 2107b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 21087e860f15SJohn Edward Broadbent if (ec) 21091abe55efSEd Tanous { 2110002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 21117e860f15SJohn Edward Broadbent return; 21127e860f15SJohn Edward Broadbent } 211326f6976fSEd Tanous if (subtree.empty()) 21147e860f15SJohn Edward Broadbent { 21157e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!"; 21167e860f15SJohn Edward Broadbent return; 21177e860f15SJohn Edward Broadbent } 21187e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 21197e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 21207e860f15SJohn Edward Broadbent if (subtree.size() > 1) 21217e860f15SJohn Edward Broadbent { 2122002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Found more than 1 bmc D-Bus object!"; 21237e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21247e860f15SJohn Edward Broadbent return; 21257e860f15SJohn Edward Broadbent } 21267e860f15SJohn Edward Broadbent 2127002d39b4SEd Tanous if (subtree[0].first.empty() || subtree[0].second.size() != 1) 21287e860f15SJohn Edward Broadbent { 21297e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!"; 21307e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21317e860f15SJohn Edward Broadbent return; 21327e860f15SJohn Edward Broadbent } 21337e860f15SJohn Edward Broadbent 21347e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 2135002d39b4SEd Tanous const std::string& connectionName = subtree[0].second[0].first; 21367e860f15SJohn Edward Broadbent 2137002d39b4SEd Tanous for (const auto& interfaceName : subtree[0].second[0].second) 21387e860f15SJohn Edward Broadbent { 21397e860f15SJohn Edward Broadbent if (interfaceName == 21407e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 21417e860f15SJohn Edward Broadbent { 21427e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 21438a592810SEd Tanous [asyncResp](const boost::system::error_code ec2, 2144b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 21457e860f15SJohn Edward Broadbent propertiesList) { 21468a592810SEd Tanous if (ec2) 21477e860f15SJohn Edward Broadbent { 2148002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Can't get bmc asset!"; 21497e860f15SJohn Edward Broadbent return; 21507e860f15SJohn Edward Broadbent } 2151002d39b4SEd Tanous for (const std::pair<std::string, 2152168e20c1SEd Tanous dbus::utility::DbusVariantType>& 21537e860f15SJohn Edward Broadbent property : propertiesList) 21547e860f15SJohn Edward Broadbent { 2155002d39b4SEd Tanous const std::string& propertyName = property.first; 21567e860f15SJohn Edward Broadbent 21577e860f15SJohn Edward Broadbent if ((propertyName == "PartNumber") || 21587e860f15SJohn Edward Broadbent (propertyName == "SerialNumber") || 21597e860f15SJohn Edward Broadbent (propertyName == "Manufacturer") || 21607e860f15SJohn Edward Broadbent (propertyName == "Model") || 21617e860f15SJohn Edward Broadbent (propertyName == "SparePartNumber")) 21627e860f15SJohn Edward Broadbent { 21637e860f15SJohn Edward Broadbent const std::string* value = 2164002d39b4SEd Tanous std::get_if<std::string>(&property.second); 21657e860f15SJohn Edward Broadbent if (value == nullptr) 21667e860f15SJohn Edward Broadbent { 21677e860f15SJohn Edward Broadbent // illegal property 2168002d39b4SEd Tanous messages::internalError(asyncResp->res); 21697e860f15SJohn Edward Broadbent return; 21707e860f15SJohn Edward Broadbent } 2171002d39b4SEd Tanous asyncResp->res.jsonValue[propertyName] = *value; 21727e860f15SJohn Edward Broadbent } 21737e860f15SJohn Edward Broadbent } 21747e860f15SJohn Edward Broadbent }, 2175002d39b4SEd Tanous connectionName, path, "org.freedesktop.DBus.Properties", 2176002d39b4SEd Tanous "GetAll", 21770fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.Asset"); 21787e860f15SJohn Edward Broadbent } 2179002d39b4SEd Tanous else if (interfaceName == 21800fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 21817e860f15SJohn Edward Broadbent { 21827e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 21837e860f15SJohn Edward Broadbent } 21847e860f15SJohn Edward Broadbent } 21857e860f15SJohn Edward Broadbent }, 21867e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", 21877e860f15SJohn Edward Broadbent "/xyz/openbmc_project/object_mapper", 21887e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", "GetSubTree", 21897e860f15SJohn Edward Broadbent "/xyz/openbmc_project/inventory", int32_t(0), 21907e860f15SJohn Edward Broadbent std::array<const char*, 1>{ 21917e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Item.Bmc"}); 21927e860f15SJohn Edward Broadbent }); 21937e860f15SJohn Edward Broadbent 21947e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 2195ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 219645ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 219745ca1b86SEd Tanous [&app](const crow::Request& req, 21987e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21993ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 220045ca1b86SEd Tanous { 220145ca1b86SEd Tanous return; 220245ca1b86SEd Tanous } 22037e860f15SJohn Edward Broadbent std::optional<nlohmann::json> oem; 22047e860f15SJohn Edward Broadbent std::optional<nlohmann::json> links; 22057e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 22067e860f15SJohn Edward Broadbent 220715ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem, 2208002d39b4SEd Tanous "DateTime", datetime, "Links", links)) 22097e860f15SJohn Edward Broadbent { 22107e860f15SJohn Edward Broadbent return; 22117e860f15SJohn Edward Broadbent } 22127e860f15SJohn Edward Broadbent 22137e860f15SJohn Edward Broadbent if (oem) 22147e860f15SJohn Edward Broadbent { 22157e860f15SJohn Edward Broadbent std::optional<nlohmann::json> openbmc; 2216002d39b4SEd Tanous if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc", 2217002d39b4SEd Tanous openbmc)) 22187e860f15SJohn Edward Broadbent { 22197e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR 22207e860f15SJohn Edward Broadbent << "Illegal Property " 2221002d39b4SEd Tanous << oem->dump(2, ' ', true, 22227e860f15SJohn Edward Broadbent nlohmann::json::error_handler_t::replace); 22237e860f15SJohn Edward Broadbent return; 22247e860f15SJohn Edward Broadbent } 22257e860f15SJohn Edward Broadbent if (openbmc) 22267e860f15SJohn Edward Broadbent { 22277e860f15SJohn Edward Broadbent std::optional<nlohmann::json> fan; 2228002d39b4SEd Tanous if (!redfish::json_util::readJson(*openbmc, asyncResp->res, 2229002d39b4SEd Tanous "Fan", fan)) 22307e860f15SJohn Edward Broadbent { 22317e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR 22327e860f15SJohn Edward Broadbent << "Illegal Property " 2233002d39b4SEd Tanous << openbmc->dump( 2234002d39b4SEd Tanous 2, ' ', true, 2235002d39b4SEd Tanous nlohmann::json::error_handler_t::replace); 22367e860f15SJohn Edward Broadbent return; 22377e860f15SJohn Edward Broadbent } 22387e860f15SJohn Edward Broadbent if (fan) 22397e860f15SJohn Edward Broadbent { 2240002d39b4SEd Tanous auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan); 22417e860f15SJohn Edward Broadbent pid->run(); 22427e860f15SJohn Edward Broadbent } 22437e860f15SJohn Edward Broadbent } 22447e860f15SJohn Edward Broadbent } 22457e860f15SJohn Edward Broadbent if (links) 22467e860f15SJohn Edward Broadbent { 22477e860f15SJohn Edward Broadbent std::optional<nlohmann::json> activeSoftwareImage; 22487e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*links, asyncResp->res, 22497e860f15SJohn Edward Broadbent "ActiveSoftwareImage", 22507e860f15SJohn Edward Broadbent activeSoftwareImage)) 22517e860f15SJohn Edward Broadbent { 22527e860f15SJohn Edward Broadbent return; 22537e860f15SJohn Edward Broadbent } 22547e860f15SJohn Edward Broadbent if (activeSoftwareImage) 22557e860f15SJohn Edward Broadbent { 22567e860f15SJohn Edward Broadbent std::optional<std::string> odataId; 2257002d39b4SEd Tanous if (!json_util::readJson(*activeSoftwareImage, asyncResp->res, 2258002d39b4SEd Tanous "@odata.id", odataId)) 22597e860f15SJohn Edward Broadbent { 22607e860f15SJohn Edward Broadbent return; 22617e860f15SJohn Edward Broadbent } 22627e860f15SJohn Edward Broadbent 22637e860f15SJohn Edward Broadbent if (odataId) 22647e860f15SJohn Edward Broadbent { 22657e860f15SJohn Edward Broadbent setActiveFirmwareImage(asyncResp, *odataId); 22667e860f15SJohn Edward Broadbent } 22677e860f15SJohn Edward Broadbent } 22687e860f15SJohn Edward Broadbent } 22697e860f15SJohn Edward Broadbent if (datetime) 22707e860f15SJohn Edward Broadbent { 22717e860f15SJohn Edward Broadbent setDateTime(asyncResp, std::move(*datetime)); 22727e860f15SJohn Edward Broadbent } 22737e860f15SJohn Edward Broadbent }); 22747e860f15SJohn Edward Broadbent } 22757e860f15SJohn Edward Broadbent 22767e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 22777e860f15SJohn Edward Broadbent { 22787e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 2279ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 22807e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 228145ca1b86SEd Tanous [&app](const crow::Request& req, 22827e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22833ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 228445ca1b86SEd Tanous { 228545ca1b86SEd Tanous return; 228645ca1b86SEd Tanous } 228783ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 228883ff9ab6SJames Feist // because it has a duplicate entry for members 22898d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 22908d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 22918d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 22928d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 22938d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 22941476687dSEd Tanous nlohmann::json::array_t members; 22951476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 22961476687dSEd Tanous bmc["@odata.id"] = "/redfish/v1/Managers/bmc"; 22971476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 22987e860f15SJohn Edward Broadbent }); 22999c310685SBorawski.Lukasz } 23009c310685SBorawski.Lukasz } // namespace redfish 2301