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 18a51fc2d2SSui Chen #include "app.hpp" 19a51fc2d2SSui Chen #include "dbus_utility.hpp" 20b49ac873SJames Feist #include "health.hpp" 21a51fc2d2SSui Chen #include "query.hpp" 22c5d03ff4SJennifer Lee #include "redfish_util.hpp" 23a51fc2d2SSui Chen #include "registries/privilege_registry.hpp" 24fac6e53bSKrzysztof Grobelny #include "utils/dbus_utils.hpp" 253ccb3adbSEd Tanous #include "utils/json_utils.hpp" 26a51fc2d2SSui Chen #include "utils/sw_utils.hpp" 27a51fc2d2SSui Chen #include "utils/systemd_utils.hpp" 282b82937eSEd Tanous #include "utils/time_utils.hpp" 299c310685SBorawski.Lukasz 30e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 31*ef4c65b7SEd Tanous #include <boost/url/format.hpp> 32fac6e53bSKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 33fac6e53bSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 341214b7e7SGunnar Mills 35a170f275SEd Tanous #include <algorithm> 36e99073f5SGeorge Liu #include <array> 374bfefa74SGunnar Mills #include <cstdint> 381214b7e7SGunnar Mills #include <memory> 391214b7e7SGunnar Mills #include <sstream> 40e99073f5SGeorge Liu #include <string_view> 41abf2add6SEd Tanous #include <variant> 425b4aa86bSJames Feist 431abe55efSEd Tanous namespace redfish 441abe55efSEd Tanous { 45ed5befbdSJennifer Lee 46ed5befbdSJennifer Lee /** 472a5c4407SGunnar Mills * Function reboots the BMC. 482a5c4407SGunnar Mills * 492a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls 50ed5befbdSJennifer Lee */ 518d1b46d7Szhanghch05 inline void 528d1b46d7Szhanghch05 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 53ed5befbdSJennifer Lee { 54ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 55ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 56ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 57ed5befbdSJennifer Lee const std::string& propertyValue = 58ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 59ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 60ed5befbdSJennifer Lee 61ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 62168e20c1SEd Tanous dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); 63ed5befbdSJennifer Lee 64ed5befbdSJennifer Lee crow::connections::systemBus->async_method_call( 655e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 66ed5befbdSJennifer Lee // Use "Set" method to set the property value. 67ed5befbdSJennifer Lee if (ec) 68ed5befbdSJennifer Lee { 692a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 70ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 71ed5befbdSJennifer Lee return; 72ed5befbdSJennifer Lee } 73ed5befbdSJennifer Lee 74ed5befbdSJennifer Lee messages::success(asyncResp->res); 75ed5befbdSJennifer Lee }, 76ed5befbdSJennifer Lee processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 77ed5befbdSJennifer Lee interfaceName, destProperty, dbusPropertyValue); 78ed5befbdSJennifer Lee } 792a5c4407SGunnar Mills 808d1b46d7Szhanghch05 inline void 818d1b46d7Szhanghch05 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 82f92af389SJayaprakash Mutyala { 83f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC"; 84f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 85f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC"; 86f92af389SJayaprakash Mutyala const std::string& propertyValue = 87f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 88f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition"; 89f92af389SJayaprakash Mutyala 90f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call. 91168e20c1SEd Tanous dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); 92f92af389SJayaprakash Mutyala 93f92af389SJayaprakash Mutyala crow::connections::systemBus->async_method_call( 945e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 95f92af389SJayaprakash Mutyala // Use "Set" method to set the property value. 96f92af389SJayaprakash Mutyala if (ec) 97f92af389SJayaprakash Mutyala { 98f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 99f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res); 100f92af389SJayaprakash Mutyala return; 101f92af389SJayaprakash Mutyala } 102f92af389SJayaprakash Mutyala 103f92af389SJayaprakash Mutyala messages::success(asyncResp->res); 104f92af389SJayaprakash Mutyala }, 105f92af389SJayaprakash Mutyala processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 106f92af389SJayaprakash Mutyala interfaceName, destProperty, dbusPropertyValue); 107f92af389SJayaprakash Mutyala } 108f92af389SJayaprakash Mutyala 1092a5c4407SGunnar Mills /** 1102a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot) 1112a5c4407SGunnar Mills * action. 1122a5c4407SGunnar Mills */ 1137e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app) 1142a5c4407SGunnar Mills { 1152a5c4407SGunnar Mills /** 1162a5c4407SGunnar Mills * Function handles POST method request. 1172a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 118f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 1192a5c4407SGunnar Mills */ 1207e860f15SJohn Edward Broadbent 1217e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") 122ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1237e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 12445ca1b86SEd Tanous [&app](const crow::Request& req, 1257e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1263ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 12745ca1b86SEd Tanous { 12845ca1b86SEd Tanous return; 12945ca1b86SEd Tanous } 1302a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Post Manager Reset."; 1312a5c4407SGunnar Mills 1322a5c4407SGunnar Mills std::string resetType; 1332a5c4407SGunnar Mills 13415ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 1357e860f15SJohn Edward Broadbent resetType)) 1362a5c4407SGunnar Mills { 1372a5c4407SGunnar Mills return; 1382a5c4407SGunnar Mills } 1392a5c4407SGunnar Mills 140f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart") 141f92af389SJayaprakash Mutyala { 142f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 143f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp); 144f92af389SJayaprakash Mutyala return; 145f92af389SJayaprakash Mutyala } 1463174e4dfSEd Tanous if (resetType == "ForceRestart") 147f92af389SJayaprakash Mutyala { 148f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 149f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp); 150f92af389SJayaprakash Mutyala return; 151f92af389SJayaprakash Mutyala } 1522a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 1532a5c4407SGunnar Mills << resetType; 1542a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType, 1552a5c4407SGunnar Mills "ResetType"); 1562a5c4407SGunnar Mills 1572a5c4407SGunnar Mills return; 1587e860f15SJohn Edward Broadbent }); 1592a5c4407SGunnar Mills } 160ed5befbdSJennifer Lee 1613e40fc74SGunnar Mills /** 1623e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset 1633e40fc74SGunnar Mills * action. 1643e40fc74SGunnar Mills */ 1657e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app) 1663e40fc74SGunnar Mills { 1673e40fc74SGunnar Mills /** 1683e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request. 1693e40fc74SGunnar Mills * 1703e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling 1713e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot. 1723e40fc74SGunnar Mills * 1733e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write 1743e40fc74SGunnar Mills * filesystem which includes things like the network settings. 1753e40fc74SGunnar Mills * 1763e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll". 1773e40fc74SGunnar Mills */ 1787e860f15SJohn Edward Broadbent 1797e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 1807e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/") 181ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1827e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 18345ca1b86SEd Tanous [&app](const crow::Request& req, 1847e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1853ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 18645ca1b86SEd Tanous { 18745ca1b86SEd Tanous return; 18845ca1b86SEd Tanous } 1893e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Post ResetToDefaults."; 1903e40fc74SGunnar Mills 1913e40fc74SGunnar Mills std::string resetType; 1923e40fc74SGunnar Mills 193002d39b4SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, 194002d39b4SEd Tanous "ResetToDefaultsType", resetType)) 1953e40fc74SGunnar Mills { 1963e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType."; 1973e40fc74SGunnar Mills 198002d39b4SEd Tanous messages::actionParameterMissing(asyncResp->res, "ResetToDefaults", 1993e40fc74SGunnar Mills "ResetToDefaultsType"); 2003e40fc74SGunnar Mills return; 2013e40fc74SGunnar Mills } 2023e40fc74SGunnar Mills 2033e40fc74SGunnar Mills if (resetType != "ResetAll") 2043e40fc74SGunnar Mills { 2050fda0f12SGeorge Liu BMCWEB_LOG_DEBUG 2060fda0f12SGeorge Liu << "Invalid property value for ResetToDefaultsType: " 2073e40fc74SGunnar Mills << resetType; 208002d39b4SEd Tanous messages::actionParameterNotSupported(asyncResp->res, resetType, 209002d39b4SEd Tanous "ResetToDefaultsType"); 2103e40fc74SGunnar Mills return; 2113e40fc74SGunnar Mills } 2123e40fc74SGunnar Mills 2133e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 2145e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 2153e40fc74SGunnar Mills if (ec) 2163e40fc74SGunnar Mills { 217002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec; 2183e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2193e40fc74SGunnar Mills return; 2203e40fc74SGunnar Mills } 2213e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2223e40fc74SGunnar Mills // Can't erase what the BMC is running on 2233e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2243e40fc74SGunnar Mills }, 2253e40fc74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 2263e40fc74SGunnar Mills "/xyz/openbmc_project/software", 2273e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2287e860f15SJohn Edward Broadbent }); 2293e40fc74SGunnar Mills } 2303e40fc74SGunnar Mills 2311cb1a9e6SAppaRao Puli /** 2321cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2331cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2341cb1a9e6SAppaRao Puli */ 2357e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2361cb1a9e6SAppaRao Puli { 2371cb1a9e6SAppaRao Puli /** 2381cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2391cb1a9e6SAppaRao Puli */ 2407e860f15SJohn Edward Broadbent 2417e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/") 242ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 2437e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24445ca1b86SEd Tanous [&app](const crow::Request& req, 2457e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2463ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 24745ca1b86SEd Tanous { 24845ca1b86SEd Tanous return; 24945ca1b86SEd Tanous } 2501476687dSEd Tanous 2511476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 2521476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 2531476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2541476687dSEd Tanous "/redfish/v1/Managers/bmc/ResetActionInfo"; 2551476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 2561476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 2571476687dSEd Tanous nlohmann::json::object_t parameter; 2581476687dSEd Tanous parameter["Name"] = "ResetType"; 2591476687dSEd Tanous parameter["Required"] = true; 2601476687dSEd Tanous parameter["DataType"] = "String"; 2611476687dSEd Tanous 2621476687dSEd Tanous nlohmann::json::array_t allowableValues; 263ad539545SPatrick Williams allowableValues.emplace_back("GracefulRestart"); 264ad539545SPatrick Williams allowableValues.emplace_back("ForceRestart"); 2651476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues); 2661476687dSEd Tanous 2671476687dSEd Tanous nlohmann::json::array_t parameters; 268ad539545SPatrick Williams parameters.emplace_back(std::move(parameter)); 2691476687dSEd Tanous 2701476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 2717e860f15SJohn Edward Broadbent }); 2721cb1a9e6SAppaRao Puli } 2731cb1a9e6SAppaRao Puli 2745b4aa86bSJames Feist static constexpr const char* objectManagerIface = 2755b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 2765b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 2775b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 2785b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 2795b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 280b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 281b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 28273df0db0SJames Feist static constexpr const char* thermalModeIface = 28373df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 2849c310685SBorawski.Lukasz 2858d1b46d7Szhanghch05 inline void 2868d1b46d7Szhanghch05 asyncPopulatePid(const std::string& connection, const std::string& path, 28773df0db0SJames Feist const std::string& currentProfile, 28873df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 2898d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2905b4aa86bSJames Feist { 2915b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 29273df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 2935e7e2dc5SEd Tanous const boost::system::error_code& ec, 2945b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 2955b4aa86bSJames Feist if (ec) 2965b4aa86bSJames Feist { 2975b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 2985b4aa86bSJames Feist asyncResp->res.jsonValue.clear(); 299f12894f8SJason M. Bills messages::internalError(asyncResp->res); 3005b4aa86bSJames Feist return; 3015b4aa86bSJames Feist } 3025b4aa86bSJames Feist nlohmann::json& configRoot = 3035b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 3045b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 3055b4aa86bSJames Feist fans["@odata.type"] = "#OemManager.FanControllers"; 3060fda0f12SGeorge Liu fans["@odata.id"] = 3070fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers"; 3085b4aa86bSJames Feist 3095b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 3105b4aa86bSJames Feist pids["@odata.type"] = "#OemManager.PidControllers"; 3115b4aa86bSJames Feist pids["@odata.id"] = 3125b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; 3135b4aa86bSJames Feist 314b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 315b7a08d04SJames Feist stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; 316b7a08d04SJames Feist stepwise["@odata.id"] = 317b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; 318b7a08d04SJames Feist 3195b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 3205b4aa86bSJames Feist zones["@odata.id"] = 3215b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; 3225b4aa86bSJames Feist zones["@odata.type"] = "#OemManager.FanZones"; 323002d39b4SEd Tanous configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; 3245b4aa86bSJames Feist configRoot["@odata.type"] = "#OemManager.Fan"; 32573df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 32673df0db0SJames Feist 32773df0db0SJames Feist if (!currentProfile.empty()) 32873df0db0SJames Feist { 32973df0db0SJames Feist configRoot["Profile"] = currentProfile; 33073df0db0SJames Feist } 33173df0db0SJames Feist BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !"; 3325b4aa86bSJames Feist 3335b4aa86bSJames Feist for (const auto& pathPair : managedObj) 3345b4aa86bSJames Feist { 3355b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 3365b4aa86bSJames Feist { 3375b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 338b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 339b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 3405b4aa86bSJames Feist { 3415b4aa86bSJames Feist continue; 3425b4aa86bSJames Feist } 34373df0db0SJames Feist 344711ac7a9SEd Tanous std::string name; 345711ac7a9SEd Tanous 346711ac7a9SEd Tanous for (const std::pair<std::string, 347002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 348002d39b4SEd Tanous intfPair.second) 349711ac7a9SEd Tanous { 350711ac7a9SEd Tanous if (propPair.first == "Name") 351711ac7a9SEd Tanous { 3525b4aa86bSJames Feist const std::string* namePtr = 353711ac7a9SEd Tanous std::get_if<std::string>(&propPair.second); 3545b4aa86bSJames Feist if (namePtr == nullptr) 3555b4aa86bSJames Feist { 3565b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Name Field illegal"; 357b7a08d04SJames Feist messages::internalError(asyncResp->res); 3585b4aa86bSJames Feist return; 3595b4aa86bSJames Feist } 360db697703SWilly Tu name = *namePtr; 3615b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 362711ac7a9SEd Tanous } 363711ac7a9SEd Tanous else if (propPair.first == "Profiles") 36473df0db0SJames Feist { 36573df0db0SJames Feist const std::vector<std::string>* profiles = 36673df0db0SJames Feist std::get_if<std::vector<std::string>>( 367711ac7a9SEd Tanous &propPair.second); 36873df0db0SJames Feist if (profiles == nullptr) 36973df0db0SJames Feist { 370002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Pid Profiles Field illegal"; 37173df0db0SJames Feist messages::internalError(asyncResp->res); 37273df0db0SJames Feist return; 37373df0db0SJames Feist } 37473df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 37573df0db0SJames Feist currentProfile) == profiles->end()) 37673df0db0SJames Feist { 37773df0db0SJames Feist BMCWEB_LOG_INFO 378002d39b4SEd Tanous << name << " not supported in current profile"; 37973df0db0SJames Feist continue; 38073df0db0SJames Feist } 38173df0db0SJames Feist } 382711ac7a9SEd Tanous } 383b7a08d04SJames Feist nlohmann::json* config = nullptr; 384c33a90ecSJames Feist const std::string* classPtr = nullptr; 385711ac7a9SEd Tanous 386711ac7a9SEd Tanous for (const std::pair<std::string, 387002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 388002d39b4SEd Tanous intfPair.second) 389c33a90ecSJames Feist { 390727dc83fSLei YU if (propPair.first == "Class") 391711ac7a9SEd Tanous { 392002d39b4SEd Tanous classPtr = std::get_if<std::string>(&propPair.second); 393711ac7a9SEd Tanous } 394c33a90ecSJames Feist } 395c33a90ecSJames Feist 396*ef4c65b7SEd Tanous boost::urls::url url("/redfish/v1/Managers/bmc"); 3975b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 3985b4aa86bSJames Feist { 3995b4aa86bSJames Feist std::string chassis; 400002d39b4SEd Tanous if (!dbus::utility::getNthStringFromPath(pathPair.first.str, 401002d39b4SEd Tanous 5, chassis)) 4025b4aa86bSJames Feist { 4035b4aa86bSJames Feist chassis = "#IllegalValue"; 4045b4aa86bSJames Feist } 4055b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 406*ef4c65b7SEd Tanous zone["Chassis"]["@odata.id"] = 407*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis); 408eddfc437SWilly Tu url.set_fragment( 409eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name) 410eddfc437SWilly Tu .to_string()); 411eddfc437SWilly Tu zone["@odata.id"] = std::move(url); 4125b4aa86bSJames Feist zone["@odata.type"] = "#OemManager.FanZone"; 413b7a08d04SJames Feist config = &zone; 4145b4aa86bSJames Feist } 4155b4aa86bSJames Feist 416b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 4175b4aa86bSJames Feist { 418c33a90ecSJames Feist if (classPtr == nullptr) 419c33a90ecSJames Feist { 420c33a90ecSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 421c33a90ecSJames Feist messages::internalError(asyncResp->res); 422c33a90ecSJames Feist return; 423c33a90ecSJames Feist } 424c33a90ecSJames Feist 425b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 426b7a08d04SJames Feist config = &controller; 427eddfc437SWilly Tu url.set_fragment( 428eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/StepwiseControllers"_json_pointer / 429eddfc437SWilly Tu name) 430eddfc437SWilly Tu .to_string()); 431eddfc437SWilly Tu controller["@odata.id"] = std::move(url); 432b7a08d04SJames Feist controller["@odata.type"] = 433b7a08d04SJames Feist "#OemManager.StepwiseController"; 434b7a08d04SJames Feist 435c33a90ecSJames Feist controller["Direction"] = *classPtr; 4365b4aa86bSJames Feist } 4375b4aa86bSJames Feist 4385b4aa86bSJames Feist // pid and fans are off the same configuration 439b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 4405b4aa86bSJames Feist { 4415b4aa86bSJames Feist if (classPtr == nullptr) 4425b4aa86bSJames Feist { 4435b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 444a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 4455b4aa86bSJames Feist return; 4465b4aa86bSJames Feist } 4475b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 448002d39b4SEd Tanous nlohmann::json& element = isFan ? fans[name] : pids[name]; 449b7a08d04SJames Feist config = &element; 4505b4aa86bSJames Feist if (isFan) 4515b4aa86bSJames Feist { 452eddfc437SWilly Tu url.set_fragment( 453eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanControllers"_json_pointer / 454eddfc437SWilly Tu name) 455eddfc437SWilly Tu .to_string()); 456eddfc437SWilly Tu element["@odata.id"] = std::move(url); 457002d39b4SEd Tanous element["@odata.type"] = "#OemManager.FanController"; 4585b4aa86bSJames Feist } 4595b4aa86bSJames Feist else 4605b4aa86bSJames Feist { 461eddfc437SWilly Tu url.set_fragment( 462eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/PidControllers"_json_pointer / 463eddfc437SWilly Tu name) 464eddfc437SWilly Tu .to_string()); 465eddfc437SWilly Tu element["@odata.id"] = std::move(url); 466002d39b4SEd Tanous element["@odata.type"] = "#OemManager.PidController"; 4675b4aa86bSJames Feist } 468b7a08d04SJames Feist } 469b7a08d04SJames Feist else 470b7a08d04SJames Feist { 471b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Unexpected configuration"; 472b7a08d04SJames Feist messages::internalError(asyncResp->res); 473b7a08d04SJames Feist return; 474b7a08d04SJames Feist } 475b7a08d04SJames Feist 476b7a08d04SJames Feist // used for making maps out of 2 vectors 477b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 478b7a08d04SJames Feist const std::vector<double>* values = nullptr; 479b7a08d04SJames Feist 480b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 481b7a08d04SJames Feist { 482b7a08d04SJames Feist if (propertyPair.first == "Type" || 483b7a08d04SJames Feist propertyPair.first == "Class" || 484b7a08d04SJames Feist propertyPair.first == "Name") 485b7a08d04SJames Feist { 486b7a08d04SJames Feist continue; 487b7a08d04SJames Feist } 488b7a08d04SJames Feist 489b7a08d04SJames Feist // zones 490b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 491b7a08d04SJames Feist { 492b7a08d04SJames Feist const double* ptr = 493abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 494b7a08d04SJames Feist if (ptr == nullptr) 495b7a08d04SJames Feist { 496b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 497b7a08d04SJames Feist << propertyPair.first; 498b7a08d04SJames Feist messages::internalError(asyncResp->res); 499b7a08d04SJames Feist return; 500b7a08d04SJames Feist } 501b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 502b7a08d04SJames Feist } 503b7a08d04SJames Feist 504b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 505b7a08d04SJames Feist { 506b7a08d04SJames Feist if (propertyPair.first == "Reading" || 507b7a08d04SJames Feist propertyPair.first == "Output") 508b7a08d04SJames Feist { 509b7a08d04SJames Feist const std::vector<double>* ptr = 510abf2add6SEd Tanous std::get_if<std::vector<double>>( 511b7a08d04SJames Feist &propertyPair.second); 512b7a08d04SJames Feist 513b7a08d04SJames Feist if (ptr == nullptr) 514b7a08d04SJames Feist { 515b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 516b7a08d04SJames Feist << propertyPair.first; 517b7a08d04SJames Feist messages::internalError(asyncResp->res); 518b7a08d04SJames Feist return; 519b7a08d04SJames Feist } 520b7a08d04SJames Feist 521b7a08d04SJames Feist if (propertyPair.first == "Reading") 522b7a08d04SJames Feist { 523b7a08d04SJames Feist keys = ptr; 524b7a08d04SJames Feist } 525b7a08d04SJames Feist else 526b7a08d04SJames Feist { 527b7a08d04SJames Feist values = ptr; 528b7a08d04SJames Feist } 529e662eae8SEd Tanous if (keys != nullptr && values != nullptr) 530b7a08d04SJames Feist { 531b7a08d04SJames Feist if (keys->size() != values->size()) 532b7a08d04SJames Feist { 533b7a08d04SJames Feist BMCWEB_LOG_ERROR 5340fda0f12SGeorge Liu << "Reading and Output size don't match "; 535b7a08d04SJames Feist messages::internalError(asyncResp->res); 536b7a08d04SJames Feist return; 537b7a08d04SJames Feist } 538b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 539b7a08d04SJames Feist steps = nlohmann::json::array(); 540b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 541b7a08d04SJames Feist { 5421476687dSEd Tanous nlohmann::json::object_t step; 5431476687dSEd Tanous step["Target"] = (*keys)[ii]; 5441476687dSEd Tanous step["Output"] = (*values)[ii]; 545b2ba3072SPatrick Williams steps.emplace_back(std::move(step)); 546b7a08d04SJames Feist } 547b7a08d04SJames Feist } 548b7a08d04SJames Feist } 549b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 550b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 551b7a08d04SJames Feist { 552b7a08d04SJames Feist const double* ptr = 553abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 554b7a08d04SJames Feist if (ptr == nullptr) 555b7a08d04SJames Feist { 556b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 557b7a08d04SJames Feist << propertyPair.first; 558b7a08d04SJames Feist messages::internalError(asyncResp->res); 559b7a08d04SJames Feist return; 560b7a08d04SJames Feist } 561b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 562b7a08d04SJames Feist } 563b7a08d04SJames Feist } 564b7a08d04SJames Feist 565b7a08d04SJames Feist // pid and fans are off the same configuration 566b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 567b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 568b7a08d04SJames Feist { 5695b4aa86bSJames Feist if (propertyPair.first == "Zones") 5705b4aa86bSJames Feist { 5715b4aa86bSJames Feist const std::vector<std::string>* inputs = 572abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5731b6b96c5SEd Tanous &propertyPair.second); 5745b4aa86bSJames Feist 5755b4aa86bSJames Feist if (inputs == nullptr) 5765b4aa86bSJames Feist { 577002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Zones Pid Field Illegal"; 578a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 5795b4aa86bSJames Feist return; 5805b4aa86bSJames Feist } 581b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5825b4aa86bSJames Feist data = nlohmann::json::array(); 5835b4aa86bSJames Feist for (std::string itemCopy : *inputs) 5845b4aa86bSJames Feist { 5855b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 5861476687dSEd Tanous nlohmann::json::object_t input; 587*ef4c65b7SEd Tanous boost::urls::url managerUrl = boost::urls::format( 588*ef4c65b7SEd Tanous "/redfish/v1/Managers/bmc#{}", 589eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / 590eddfc437SWilly Tu itemCopy) 591eddfc437SWilly Tu .to_string()); 592eddfc437SWilly Tu input["@odata.id"] = std::move(managerUrl); 593b2ba3072SPatrick Williams data.emplace_back(std::move(input)); 5945b4aa86bSJames Feist } 5955b4aa86bSJames Feist } 5965b4aa86bSJames Feist // todo(james): may never happen, but this 5975b4aa86bSJames Feist // assumes configuration data referenced in the 5985b4aa86bSJames Feist // PID config is provided by the same daemon, we 5995b4aa86bSJames Feist // could add another loop to cover all cases, 6005b4aa86bSJames Feist // but I'm okay kicking this can down the road a 6015b4aa86bSJames Feist // bit 6025b4aa86bSJames Feist 6035b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 6045b4aa86bSJames Feist propertyPair.first == "Outputs") 6055b4aa86bSJames Feist { 606b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 6075b4aa86bSJames Feist const std::vector<std::string>* inputs = 608abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 6091b6b96c5SEd Tanous &propertyPair.second); 6105b4aa86bSJames Feist 6115b4aa86bSJames Feist if (inputs == nullptr) 6125b4aa86bSJames Feist { 6135b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 6145b4aa86bSJames Feist << propertyPair.first; 615f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6165b4aa86bSJames Feist return; 6175b4aa86bSJames Feist } 6185b4aa86bSJames Feist data = *inputs; 619b943aaefSJames Feist } 620b943aaefSJames Feist else if (propertyPair.first == "SetPointOffset") 621b943aaefSJames Feist { 622b943aaefSJames Feist const std::string* ptr = 623002d39b4SEd Tanous std::get_if<std::string>(&propertyPair.second); 624b943aaefSJames Feist 625b943aaefSJames Feist if (ptr == nullptr) 626b943aaefSJames Feist { 627b943aaefSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 628b943aaefSJames Feist << propertyPair.first; 629b943aaefSJames Feist messages::internalError(asyncResp->res); 630b943aaefSJames Feist return; 631b943aaefSJames Feist } 632b943aaefSJames Feist // translate from dbus to redfish 633b943aaefSJames Feist if (*ptr == "WarningHigh") 634b943aaefSJames Feist { 635b943aaefSJames Feist (*config)["SetPointOffset"] = 636b943aaefSJames Feist "UpperThresholdNonCritical"; 637b943aaefSJames Feist } 638b943aaefSJames Feist else if (*ptr == "WarningLow") 639b943aaefSJames Feist { 640b943aaefSJames Feist (*config)["SetPointOffset"] = 641b943aaefSJames Feist "LowerThresholdNonCritical"; 642b943aaefSJames Feist } 643b943aaefSJames Feist else if (*ptr == "CriticalHigh") 644b943aaefSJames Feist { 645b943aaefSJames Feist (*config)["SetPointOffset"] = 646b943aaefSJames Feist "UpperThresholdCritical"; 647b943aaefSJames Feist } 648b943aaefSJames Feist else if (*ptr == "CriticalLow") 649b943aaefSJames Feist { 650b943aaefSJames Feist (*config)["SetPointOffset"] = 651b943aaefSJames Feist "LowerThresholdCritical"; 652b943aaefSJames Feist } 653b943aaefSJames Feist else 654b943aaefSJames Feist { 655002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Value Illegal " << *ptr; 656b943aaefSJames Feist messages::internalError(asyncResp->res); 657b943aaefSJames Feist return; 658b943aaefSJames Feist } 659b943aaefSJames Feist } 660b943aaefSJames Feist // doubles 661002d39b4SEd Tanous else if (propertyPair.first == "FFGainCoefficient" || 6625b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 6635b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 6645b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 6655b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 666002d39b4SEd Tanous propertyPair.first == "PositiveHysteresis" || 667002d39b4SEd Tanous propertyPair.first == "NegativeHysteresis" || 6685b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 6695b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 6705b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 6717625cb81SJames Feist propertyPair.first == "SetPoint" || 6725b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 6735b4aa86bSJames Feist propertyPair.first == "SlewPos") 6745b4aa86bSJames Feist { 6755b4aa86bSJames Feist const double* ptr = 676abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 6775b4aa86bSJames Feist if (ptr == nullptr) 6785b4aa86bSJames Feist { 6795b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 6805b4aa86bSJames Feist << propertyPair.first; 681f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6825b4aa86bSJames Feist return; 6835b4aa86bSJames Feist } 684b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 6855b4aa86bSJames Feist } 6865b4aa86bSJames Feist } 6875b4aa86bSJames Feist } 6885b4aa86bSJames Feist } 6895b4aa86bSJames Feist } 6905b4aa86bSJames Feist }, 6915b4aa86bSJames Feist connection, path, objectManagerIface, "GetManagedObjects"); 6925b4aa86bSJames Feist } 693ca537928SJennifer Lee 69483ff9ab6SJames Feist enum class CreatePIDRet 69583ff9ab6SJames Feist { 69683ff9ab6SJames Feist fail, 69783ff9ab6SJames Feist del, 69883ff9ab6SJames Feist patch 69983ff9ab6SJames Feist }; 70083ff9ab6SJames Feist 7018d1b46d7Szhanghch05 inline bool 7028d1b46d7Szhanghch05 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response, 7035f2caaefSJames Feist std::vector<nlohmann::json>& config, 7045f2caaefSJames Feist std::vector<std::string>& zones) 7055f2caaefSJames Feist { 706b6baeaa4SJames Feist if (config.empty()) 707b6baeaa4SJames Feist { 708b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Empty Zones"; 7091668ce6dSEd Tanous messages::propertyValueFormatError(response->res, "[]", "Zones"); 710b6baeaa4SJames Feist return false; 711b6baeaa4SJames Feist } 7125f2caaefSJames Feist for (auto& odata : config) 7135f2caaefSJames Feist { 7145f2caaefSJames Feist std::string path; 7155f2caaefSJames Feist if (!redfish::json_util::readJson(odata, response->res, "@odata.id", 7165f2caaefSJames Feist path)) 7175f2caaefSJames Feist { 7185f2caaefSJames Feist return false; 7195f2caaefSJames Feist } 7205f2caaefSJames Feist std::string input; 72161adbda3SJames Feist 72261adbda3SJames Feist // 8 below comes from 72361adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 72461adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 72561adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 7265f2caaefSJames Feist { 7275f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << path; 7285f2caaefSJames Feist BMCWEB_LOG_ERROR << "Illegal Type Zones"; 7295f2caaefSJames Feist messages::propertyValueFormatError(response->res, odata.dump(), 7305f2caaefSJames Feist "Zones"); 7315f2caaefSJames Feist return false; 7325f2caaefSJames Feist } 733a170f275SEd Tanous std::replace(input.begin(), input.end(), '_', ' '); 7345f2caaefSJames Feist zones.emplace_back(std::move(input)); 7355f2caaefSJames Feist } 7365f2caaefSJames Feist return true; 7375f2caaefSJames Feist } 7385f2caaefSJames Feist 739711ac7a9SEd Tanous inline const dbus::utility::ManagedObjectType::value_type* 74073df0db0SJames Feist findChassis(const dbus::utility::ManagedObjectType& managedObj, 741b6baeaa4SJames Feist const std::string& value, std::string& chassis) 742b6baeaa4SJames Feist { 743b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n"; 744b6baeaa4SJames Feist 745a170f275SEd Tanous std::string escaped = value; 7466ce82fabSYaswanth Reddy M std::replace(escaped.begin(), escaped.end(), ' ', '_'); 747b6baeaa4SJames Feist escaped = "/" + escaped; 748002d39b4SEd Tanous auto it = std::find_if(managedObj.begin(), managedObj.end(), 749002d39b4SEd Tanous [&escaped](const auto& obj) { 750b6baeaa4SJames Feist if (boost::algorithm::ends_with(obj.first.str, escaped)) 751b6baeaa4SJames Feist { 752b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n"; 753b6baeaa4SJames Feist return true; 754b6baeaa4SJames Feist } 755b6baeaa4SJames Feist return false; 756b6baeaa4SJames Feist }); 757b6baeaa4SJames Feist 758b6baeaa4SJames Feist if (it == managedObj.end()) 759b6baeaa4SJames Feist { 76073df0db0SJames Feist return nullptr; 761b6baeaa4SJames Feist } 762b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 763b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 76473df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 76573df0db0SJames Feist { 76673df0db0SJames Feist return &(*it); 76773df0db0SJames Feist } 76873df0db0SJames Feist 76973df0db0SJames Feist return nullptr; 770b6baeaa4SJames Feist } 771b6baeaa4SJames Feist 77223a21a1cSEd Tanous inline CreatePIDRet createPidInterface( 7738d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, 774b5a76932SEd Tanous const nlohmann::json::iterator& it, const std::string& path, 77583ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 776b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap& output, std::string& chassis, 777b9d36b47SEd Tanous const std::string& profile) 77883ff9ab6SJames Feist { 7795f2caaefSJames Feist // common deleter 780b6baeaa4SJames Feist if (it.value() == nullptr) 7815f2caaefSJames Feist { 7825f2caaefSJames Feist std::string iface; 7835f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 7845f2caaefSJames Feist { 7855f2caaefSJames Feist iface = pidConfigurationIface; 7865f2caaefSJames Feist } 7875f2caaefSJames Feist else if (type == "FanZones") 7885f2caaefSJames Feist { 7895f2caaefSJames Feist iface = pidZoneConfigurationIface; 7905f2caaefSJames Feist } 7915f2caaefSJames Feist else if (type == "StepwiseControllers") 7925f2caaefSJames Feist { 7935f2caaefSJames Feist iface = stepwiseConfigurationIface; 7945f2caaefSJames Feist } 7955f2caaefSJames Feist else 7965f2caaefSJames Feist { 797a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 7985f2caaefSJames Feist messages::propertyUnknown(response->res, type); 7995f2caaefSJames Feist return CreatePIDRet::fail; 8005f2caaefSJames Feist } 8016ee7f774SJames Feist 8026ee7f774SJames Feist BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n"; 8035f2caaefSJames Feist // delete interface 8045f2caaefSJames Feist crow::connections::systemBus->async_method_call( 8055e7e2dc5SEd Tanous [response, path](const boost::system::error_code& ec) { 8065f2caaefSJames Feist if (ec) 8075f2caaefSJames Feist { 8085f2caaefSJames Feist BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec; 8095f2caaefSJames Feist messages::internalError(response->res); 810b6baeaa4SJames Feist return; 8115f2caaefSJames Feist } 812b6baeaa4SJames Feist messages::success(response->res); 8135f2caaefSJames Feist }, 8145f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 8155f2caaefSJames Feist return CreatePIDRet::del; 8165f2caaefSJames Feist } 8175f2caaefSJames Feist 818711ac7a9SEd Tanous const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr; 819b6baeaa4SJames Feist if (!createNewObject) 820b6baeaa4SJames Feist { 821b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 822b6baeaa4SJames Feist // d-bus 82373df0db0SJames Feist managedItem = findChassis(managedObj, it.key(), chassis); 82473df0db0SJames Feist if (managedItem == nullptr) 825b6baeaa4SJames Feist { 826b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 827*ef4c65b7SEd Tanous messages::invalidObject( 828*ef4c65b7SEd Tanous response->res, 829*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 830b6baeaa4SJames Feist return CreatePIDRet::fail; 831b6baeaa4SJames Feist } 832b6baeaa4SJames Feist } 833b6baeaa4SJames Feist 83426f6976fSEd Tanous if (!profile.empty() && 83573df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 83673df0db0SJames Feist type == "StepwiseControllers")) 83773df0db0SJames Feist { 83873df0db0SJames Feist if (managedItem == nullptr) 83973df0db0SJames Feist { 840b9d36b47SEd Tanous output.emplace_back("Profiles", std::vector<std::string>{profile}); 84173df0db0SJames Feist } 84273df0db0SJames Feist else 84373df0db0SJames Feist { 84473df0db0SJames Feist std::string interface; 84573df0db0SJames Feist if (type == "StepwiseControllers") 84673df0db0SJames Feist { 84773df0db0SJames Feist interface = stepwiseConfigurationIface; 84873df0db0SJames Feist } 84973df0db0SJames Feist else 85073df0db0SJames Feist { 85173df0db0SJames Feist interface = pidConfigurationIface; 85273df0db0SJames Feist } 853711ac7a9SEd Tanous bool ifaceFound = false; 854711ac7a9SEd Tanous for (const auto& iface : managedItem->second) 855711ac7a9SEd Tanous { 856711ac7a9SEd Tanous if (iface.first == interface) 857711ac7a9SEd Tanous { 858711ac7a9SEd Tanous ifaceFound = true; 859711ac7a9SEd Tanous for (const auto& prop : iface.second) 860711ac7a9SEd Tanous { 861711ac7a9SEd Tanous if (prop.first == "Profiles") 862711ac7a9SEd Tanous { 863711ac7a9SEd Tanous const std::vector<std::string>* curProfiles = 864711ac7a9SEd Tanous std::get_if<std::vector<std::string>>( 865711ac7a9SEd Tanous &(prop.second)); 866711ac7a9SEd Tanous if (curProfiles == nullptr) 867711ac7a9SEd Tanous { 868711ac7a9SEd Tanous BMCWEB_LOG_ERROR 869711ac7a9SEd Tanous << "Illegal profiles in managed object"; 870711ac7a9SEd Tanous messages::internalError(response->res); 871711ac7a9SEd Tanous return CreatePIDRet::fail; 872711ac7a9SEd Tanous } 873711ac7a9SEd Tanous if (std::find(curProfiles->begin(), 874711ac7a9SEd Tanous curProfiles->end(), 875711ac7a9SEd Tanous profile) == curProfiles->end()) 876711ac7a9SEd Tanous { 877711ac7a9SEd Tanous std::vector<std::string> newProfiles = 878711ac7a9SEd Tanous *curProfiles; 879711ac7a9SEd Tanous newProfiles.push_back(profile); 880b9d36b47SEd Tanous output.emplace_back("Profiles", newProfiles); 881711ac7a9SEd Tanous } 882711ac7a9SEd Tanous } 883711ac7a9SEd Tanous } 884711ac7a9SEd Tanous } 885711ac7a9SEd Tanous } 886711ac7a9SEd Tanous 887711ac7a9SEd Tanous if (!ifaceFound) 88873df0db0SJames Feist { 88973df0db0SJames Feist BMCWEB_LOG_ERROR 89073df0db0SJames Feist << "Failed to find interface in managed object"; 89173df0db0SJames Feist messages::internalError(response->res); 89273df0db0SJames Feist return CreatePIDRet::fail; 89373df0db0SJames Feist } 89473df0db0SJames Feist } 89573df0db0SJames Feist } 89673df0db0SJames Feist 89783ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 89883ff9ab6SJames Feist { 89983ff9ab6SJames Feist if (createNewObject) 90083ff9ab6SJames Feist { 901b9d36b47SEd Tanous output.emplace_back("Class", 902b9d36b47SEd Tanous type == "PidControllers" ? "temp" : "fan"); 903b9d36b47SEd Tanous output.emplace_back("Type", "Pid"); 90483ff9ab6SJames Feist } 9055f2caaefSJames Feist 9065f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 9075f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 9085f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 9095f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 910b943aaefSJames Feist std::optional<std::string> setpointOffset; 9115f2caaefSJames Feist if (!redfish::json_util::readJson( 912b6baeaa4SJames Feist it.value(), response->res, "Inputs", inputs, "Outputs", outputs, 9135f2caaefSJames Feist "Zones", zones, "FFGainCoefficient", 9145f2caaefSJames Feist doubles["FFGainCoefficient"], "FFOffCoefficient", 9155f2caaefSJames Feist doubles["FFOffCoefficient"], "ICoefficient", 9165f2caaefSJames Feist doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], 9175f2caaefSJames Feist "ILimitMin", doubles["ILimitMin"], "OutLimitMax", 9185f2caaefSJames Feist doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], 9195f2caaefSJames Feist "PCoefficient", doubles["PCoefficient"], "SetPoint", 920b943aaefSJames Feist doubles["SetPoint"], "SetPointOffset", setpointOffset, 921b943aaefSJames Feist "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"], 922b943aaefSJames Feist "PositiveHysteresis", doubles["PositiveHysteresis"], 923b943aaefSJames Feist "NegativeHysteresis", doubles["NegativeHysteresis"])) 92483ff9ab6SJames Feist { 9255f2caaefSJames Feist return CreatePIDRet::fail; 92683ff9ab6SJames Feist } 9275f2caaefSJames Feist if (zones) 9285f2caaefSJames Feist { 9295f2caaefSJames Feist std::vector<std::string> zonesStr; 9305f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 9315f2caaefSJames Feist { 932a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 9335f2caaefSJames Feist return CreatePIDRet::fail; 9345f2caaefSJames Feist } 935b6baeaa4SJames Feist if (chassis.empty() && 936e662eae8SEd Tanous findChassis(managedObj, zonesStr[0], chassis) == nullptr) 937b6baeaa4SJames Feist { 938b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 939ace85d60SEd Tanous messages::invalidObject( 940*ef4c65b7SEd Tanous response->res, 941*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 942b6baeaa4SJames Feist return CreatePIDRet::fail; 943b6baeaa4SJames Feist } 944b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStr)); 9455f2caaefSJames Feist } 946afb9ee06SEd Tanous 947afb9ee06SEd Tanous if (inputs) 9485f2caaefSJames Feist { 949afb9ee06SEd Tanous for (std::string& value : *inputs) 95083ff9ab6SJames Feist { 951a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 95283ff9ab6SJames Feist } 953afb9ee06SEd Tanous output.emplace_back("Inputs", *inputs); 954afb9ee06SEd Tanous } 955afb9ee06SEd Tanous 956afb9ee06SEd Tanous if (outputs) 9575f2caaefSJames Feist { 958afb9ee06SEd Tanous for (std::string& value : *outputs) 9595f2caaefSJames Feist { 960afb9ee06SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 9615f2caaefSJames Feist } 962afb9ee06SEd Tanous output.emplace_back("Outputs", *outputs); 96383ff9ab6SJames Feist } 96483ff9ab6SJames Feist 965b943aaefSJames Feist if (setpointOffset) 966b943aaefSJames Feist { 967b943aaefSJames Feist // translate between redfish and dbus names 968b943aaefSJames Feist if (*setpointOffset == "UpperThresholdNonCritical") 969b943aaefSJames Feist { 970b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningLow"); 971b943aaefSJames Feist } 972b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdNonCritical") 973b943aaefSJames Feist { 974b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningHigh"); 975b943aaefSJames Feist } 976b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdCritical") 977b943aaefSJames Feist { 978b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalLow"); 979b943aaefSJames Feist } 980b943aaefSJames Feist else if (*setpointOffset == "UpperThresholdCritical") 981b943aaefSJames Feist { 982b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalHigh"); 983b943aaefSJames Feist } 984b943aaefSJames Feist else 985b943aaefSJames Feist { 986b943aaefSJames Feist BMCWEB_LOG_ERROR << "Invalid setpointoffset " 987b943aaefSJames Feist << *setpointOffset; 988ace85d60SEd Tanous messages::propertyValueNotInList(response->res, it.key(), 989ace85d60SEd Tanous "SetPointOffset"); 990b943aaefSJames Feist return CreatePIDRet::fail; 991b943aaefSJames Feist } 992b943aaefSJames Feist } 993b943aaefSJames Feist 99483ff9ab6SJames Feist // doubles 9955f2caaefSJames Feist for (const auto& pairs : doubles) 99683ff9ab6SJames Feist { 9975f2caaefSJames Feist if (!pairs.second) 99883ff9ab6SJames Feist { 9995f2caaefSJames Feist continue; 100083ff9ab6SJames Feist } 10015f2caaefSJames Feist BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second; 1002b9d36b47SEd Tanous output.emplace_back(pairs.first, *pairs.second); 10035f2caaefSJames Feist } 100483ff9ab6SJames Feist } 100583ff9ab6SJames Feist 100683ff9ab6SJames Feist else if (type == "FanZones") 100783ff9ab6SJames Feist { 1008b9d36b47SEd Tanous output.emplace_back("Type", "Pid.Zone"); 100983ff9ab6SJames Feist 10105f2caaefSJames Feist std::optional<nlohmann::json> chassisContainer; 10115f2caaefSJames Feist std::optional<double> failSafePercent; 1012d3ec07f8SJames Feist std::optional<double> minThermalOutput; 1013b6baeaa4SJames Feist if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", 10145f2caaefSJames Feist chassisContainer, "FailSafePercent", 1015d3ec07f8SJames Feist failSafePercent, "MinThermalOutput", 1016d3ec07f8SJames Feist minThermalOutput)) 101783ff9ab6SJames Feist { 101883ff9ab6SJames Feist return CreatePIDRet::fail; 101983ff9ab6SJames Feist } 10205f2caaefSJames Feist 10215f2caaefSJames Feist if (chassisContainer) 102283ff9ab6SJames Feist { 10235f2caaefSJames Feist std::string chassisId; 10245f2caaefSJames Feist if (!redfish::json_util::readJson(*chassisContainer, response->res, 10255f2caaefSJames Feist "@odata.id", chassisId)) 10265f2caaefSJames Feist { 102783ff9ab6SJames Feist return CreatePIDRet::fail; 102883ff9ab6SJames Feist } 102983ff9ab6SJames Feist 1030717794d5SAppaRao Puli // /redfish/v1/chassis/chassis_name/ 10315f2caaefSJames Feist if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) 103283ff9ab6SJames Feist { 10335f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << chassisId; 1034ace85d60SEd Tanous messages::invalidObject( 1035*ef4c65b7SEd Tanous response->res, 1036*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId)); 103783ff9ab6SJames Feist return CreatePIDRet::fail; 103883ff9ab6SJames Feist } 103983ff9ab6SJames Feist } 1040d3ec07f8SJames Feist if (minThermalOutput) 104183ff9ab6SJames Feist { 1042b9d36b47SEd Tanous output.emplace_back("MinThermalOutput", *minThermalOutput); 10435f2caaefSJames Feist } 10445f2caaefSJames Feist if (failSafePercent) 104583ff9ab6SJames Feist { 1046b9d36b47SEd Tanous output.emplace_back("FailSafePercent", *failSafePercent); 10475f2caaefSJames Feist } 10485f2caaefSJames Feist } 10495f2caaefSJames Feist else if (type == "StepwiseControllers") 10505f2caaefSJames Feist { 1051b9d36b47SEd Tanous output.emplace_back("Type", "Stepwise"); 10525f2caaefSJames Feist 10535f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 10545f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> steps; 10555f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 10565f2caaefSJames Feist std::optional<double> positiveHysteresis; 10575f2caaefSJames Feist std::optional<double> negativeHysteresis; 1058c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 10595f2caaefSJames Feist if (!redfish::json_util::readJson( 1060b6baeaa4SJames Feist it.value(), response->res, "Zones", zones, "Steps", steps, 1061b6baeaa4SJames Feist "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, 1062c33a90ecSJames Feist "NegativeHysteresis", negativeHysteresis, "Direction", 1063c33a90ecSJames Feist direction)) 10645f2caaefSJames Feist { 106583ff9ab6SJames Feist return CreatePIDRet::fail; 106683ff9ab6SJames Feist } 10675f2caaefSJames Feist 10685f2caaefSJames Feist if (zones) 106983ff9ab6SJames Feist { 1070b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 1071b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 10725f2caaefSJames Feist { 1073a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 107483ff9ab6SJames Feist return CreatePIDRet::fail; 107583ff9ab6SJames Feist } 1076b6baeaa4SJames Feist if (chassis.empty() && 1077e662eae8SEd Tanous findChassis(managedObj, zonesStrs[0], chassis) == nullptr) 1078b6baeaa4SJames Feist { 1079b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 1080ace85d60SEd Tanous messages::invalidObject( 1081*ef4c65b7SEd Tanous response->res, 1082*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 1083b6baeaa4SJames Feist return CreatePIDRet::fail; 1084b6baeaa4SJames Feist } 1085b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStrs)); 10865f2caaefSJames Feist } 10875f2caaefSJames Feist if (steps) 10885f2caaefSJames Feist { 10895f2caaefSJames Feist std::vector<double> readings; 10905f2caaefSJames Feist std::vector<double> outputs; 10915f2caaefSJames Feist for (auto& step : *steps) 10925f2caaefSJames Feist { 1093543f4400SEd Tanous double target = 0.0; 1094543f4400SEd Tanous double out = 0.0; 10955f2caaefSJames Feist 10965f2caaefSJames Feist if (!redfish::json_util::readJson(step, response->res, "Target", 109723a21a1cSEd Tanous target, "Output", out)) 10985f2caaefSJames Feist { 10995f2caaefSJames Feist return CreatePIDRet::fail; 11005f2caaefSJames Feist } 11015f2caaefSJames Feist readings.emplace_back(target); 110223a21a1cSEd Tanous outputs.emplace_back(out); 11035f2caaefSJames Feist } 1104b9d36b47SEd Tanous output.emplace_back("Reading", std::move(readings)); 1105b9d36b47SEd Tanous output.emplace_back("Output", std::move(outputs)); 11065f2caaefSJames Feist } 11075f2caaefSJames Feist if (inputs) 11085f2caaefSJames Feist { 11095f2caaefSJames Feist for (std::string& value : *inputs) 11105f2caaefSJames Feist { 1111a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 11125f2caaefSJames Feist } 1113b9d36b47SEd Tanous output.emplace_back("Inputs", std::move(*inputs)); 11145f2caaefSJames Feist } 11155f2caaefSJames Feist if (negativeHysteresis) 11165f2caaefSJames Feist { 1117b9d36b47SEd Tanous output.emplace_back("NegativeHysteresis", *negativeHysteresis); 11185f2caaefSJames Feist } 11195f2caaefSJames Feist if (positiveHysteresis) 11205f2caaefSJames Feist { 1121b9d36b47SEd Tanous output.emplace_back("PositiveHysteresis", *positiveHysteresis); 112283ff9ab6SJames Feist } 1123c33a90ecSJames Feist if (direction) 1124c33a90ecSJames Feist { 1125c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 1126c33a90ecSJames Feist "Ceiling", "Floor"}; 1127c33a90ecSJames Feist if (std::find(allowedDirections.begin(), allowedDirections.end(), 1128c33a90ecSJames Feist *direction) == allowedDirections.end()) 1129c33a90ecSJames Feist { 1130c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 1131c33a90ecSJames Feist *direction); 1132c33a90ecSJames Feist return CreatePIDRet::fail; 1133c33a90ecSJames Feist } 1134b9d36b47SEd Tanous output.emplace_back("Class", *direction); 1135c33a90ecSJames Feist } 113683ff9ab6SJames Feist } 113783ff9ab6SJames Feist else 113883ff9ab6SJames Feist { 1139a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 114035a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 114183ff9ab6SJames Feist return CreatePIDRet::fail; 114283ff9ab6SJames Feist } 114383ff9ab6SJames Feist return CreatePIDRet::patch; 114483ff9ab6SJames Feist } 114573df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 114673df0db0SJames Feist { 11476936afe4SEd Tanous struct CompletionValues 11486936afe4SEd Tanous { 11496936afe4SEd Tanous std::vector<std::string> supportedProfiles; 11506936afe4SEd Tanous std::string currentProfile; 11516936afe4SEd Tanous dbus::utility::MapperGetSubTreeResponse subtree; 11526936afe4SEd Tanous }; 115383ff9ab6SJames Feist 11544e23a444SEd Tanous explicit GetPIDValues( 11554e23a444SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : 115623a21a1cSEd Tanous asyncResp(asyncRespIn) 115773df0db0SJames Feist 11581214b7e7SGunnar Mills {} 11599c310685SBorawski.Lukasz 116073df0db0SJames Feist void run() 11615b4aa86bSJames Feist { 116273df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 116373df0db0SJames Feist 116473df0db0SJames Feist // get all configurations 1165e99073f5SGeorge Liu constexpr std::array<std::string_view, 4> interfaces = { 1166e99073f5SGeorge Liu pidConfigurationIface, pidZoneConfigurationIface, 1167e99073f5SGeorge Liu objectManagerIface, stepwiseConfigurationIface}; 1168e99073f5SGeorge Liu dbus::utility::getSubTree( 1169e99073f5SGeorge Liu "/", 0, interfaces, 1170b9d36b47SEd Tanous [self]( 1171e99073f5SGeorge Liu const boost::system::error_code& ec, 1172b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 11735b4aa86bSJames Feist if (ec) 11745b4aa86bSJames Feist { 11755b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 117673df0db0SJames Feist messages::internalError(self->asyncResp->res); 117773df0db0SJames Feist return; 117873df0db0SJames Feist } 11796936afe4SEd Tanous self->complete.subtree = subtreeLocal; 1180e99073f5SGeorge Liu }); 118173df0db0SJames Feist 118273df0db0SJames Feist // at the same time get the selected profile 1183e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1184e99073f5SGeorge Liu thermalModeIface}; 1185e99073f5SGeorge Liu dbus::utility::getSubTree( 1186e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1187b9d36b47SEd Tanous [self]( 1188e99073f5SGeorge Liu const boost::system::error_code& ec, 1189b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 119023a21a1cSEd Tanous if (ec || subtreeLocal.empty()) 119173df0db0SJames Feist { 119273df0db0SJames Feist return; 119373df0db0SJames Feist } 119423a21a1cSEd Tanous if (subtreeLocal[0].second.size() != 1) 119573df0db0SJames Feist { 119673df0db0SJames Feist // invalid mapper response, should never happen 119773df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error"; 119873df0db0SJames Feist messages::internalError(self->asyncResp->res); 11995b4aa86bSJames Feist return; 12005b4aa86bSJames Feist } 12015b4aa86bSJames Feist 120223a21a1cSEd Tanous const std::string& path = subtreeLocal[0].first; 120323a21a1cSEd Tanous const std::string& owner = subtreeLocal[0].second[0].first; 1204fac6e53bSKrzysztof Grobelny 1205fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1206fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 1207168e20c1SEd Tanous [path, owner, 12085e7e2dc5SEd Tanous self](const boost::system::error_code& ec2, 1209b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 121023a21a1cSEd Tanous if (ec2) 121173df0db0SJames Feist { 12120fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1213002d39b4SEd Tanous << "GetPIDValues: Can't get thermalModeIface " << path; 121473df0db0SJames Feist messages::internalError(self->asyncResp->res); 121573df0db0SJames Feist return; 121673df0db0SJames Feist } 1217fac6e53bSKrzysztof Grobelny 1218271584abSEd Tanous const std::string* current = nullptr; 1219271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1220fac6e53bSKrzysztof Grobelny 1221fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1222fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Current", current, 1223fac6e53bSKrzysztof Grobelny "Supported", supported); 1224fac6e53bSKrzysztof Grobelny 1225fac6e53bSKrzysztof Grobelny if (!success) 122673df0db0SJames Feist { 1227002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 122873df0db0SJames Feist return; 122973df0db0SJames Feist } 1230fac6e53bSKrzysztof Grobelny 123173df0db0SJames Feist if (current == nullptr || supported == nullptr) 123273df0db0SJames Feist { 12330fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1234002d39b4SEd Tanous << "GetPIDValues: thermal mode iface invalid " << path; 123573df0db0SJames Feist messages::internalError(self->asyncResp->res); 123673df0db0SJames Feist return; 123773df0db0SJames Feist } 12386936afe4SEd Tanous self->complete.currentProfile = *current; 12396936afe4SEd Tanous self->complete.supportedProfiles = *supported; 1240fac6e53bSKrzysztof Grobelny }); 1241e99073f5SGeorge Liu }); 124273df0db0SJames Feist } 124373df0db0SJames Feist 12446936afe4SEd Tanous static void 12456936afe4SEd Tanous processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12466936afe4SEd Tanous const CompletionValues& completion) 124773df0db0SJames Feist { 124873df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 124973df0db0SJames Feist { 125073df0db0SJames Feist return; 125173df0db0SJames Feist } 12525b4aa86bSJames Feist // create map of <connection, path to objMgr>> 12536936afe4SEd Tanous boost::container::flat_map< 12546936afe4SEd Tanous std::string, std::string, std::less<>, 12556936afe4SEd Tanous std::vector<std::pair<std::string, std::string>>> 12566936afe4SEd Tanous objectMgrPaths; 12576936afe4SEd Tanous boost::container::flat_set<std::string, std::less<>, 12586936afe4SEd Tanous std::vector<std::string>> 12596936afe4SEd Tanous calledConnections; 12606936afe4SEd Tanous for (const auto& pathGroup : completion.subtree) 12615b4aa86bSJames Feist { 12625b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 12635b4aa86bSJames Feist { 12646bce33bcSJames Feist auto findConnection = 12656bce33bcSJames Feist calledConnections.find(connectionGroup.first); 12666bce33bcSJames Feist if (findConnection != calledConnections.end()) 12676bce33bcSJames Feist { 12686bce33bcSJames Feist break; 12696bce33bcSJames Feist } 127073df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 12715b4aa86bSJames Feist { 12725b4aa86bSJames Feist if (interface == objectManagerIface) 12735b4aa86bSJames Feist { 127473df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 12755b4aa86bSJames Feist } 12765b4aa86bSJames Feist // this list is alphabetical, so we 12775b4aa86bSJames Feist // should have found the objMgr by now 12785b4aa86bSJames Feist if (interface == pidConfigurationIface || 1279b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1280b7a08d04SJames Feist interface == stepwiseConfigurationIface) 12815b4aa86bSJames Feist { 12825b4aa86bSJames Feist auto findObjMgr = 12835b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 12845b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 12855b4aa86bSJames Feist { 12865b4aa86bSJames Feist BMCWEB_LOG_DEBUG << connectionGroup.first 12875b4aa86bSJames Feist << "Has no Object Manager"; 12885b4aa86bSJames Feist continue; 12895b4aa86bSJames Feist } 12906bce33bcSJames Feist 12916bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 12926bce33bcSJames Feist 129373df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 12946936afe4SEd Tanous completion.currentProfile, 12956936afe4SEd Tanous completion.supportedProfiles, 129673df0db0SJames Feist asyncResp); 12975b4aa86bSJames Feist break; 12985b4aa86bSJames Feist } 12995b4aa86bSJames Feist } 13005b4aa86bSJames Feist } 13015b4aa86bSJames Feist } 130273df0db0SJames Feist } 130373df0db0SJames Feist 13046936afe4SEd Tanous ~GetPIDValues() 13056936afe4SEd Tanous { 13066936afe4SEd Tanous boost::asio::post(crow::connections::systemBus->get_io_context(), 13076936afe4SEd Tanous std::bind_front(&processingComplete, asyncResp, 13086936afe4SEd Tanous std::move(complete))); 13096936afe4SEd Tanous } 13106936afe4SEd Tanous 1311ecd6a3a2SEd Tanous GetPIDValues(const GetPIDValues&) = delete; 1312ecd6a3a2SEd Tanous GetPIDValues(GetPIDValues&&) = delete; 1313ecd6a3a2SEd Tanous GetPIDValues& operator=(const GetPIDValues&) = delete; 1314ecd6a3a2SEd Tanous GetPIDValues& operator=(GetPIDValues&&) = delete; 1315ecd6a3a2SEd Tanous 13168d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 13176936afe4SEd Tanous CompletionValues complete; 131873df0db0SJames Feist }; 131973df0db0SJames Feist 132073df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 132173df0db0SJames Feist { 13228d1b46d7Szhanghch05 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, 132373df0db0SJames Feist nlohmann::json& data) : 1324271584abSEd Tanous asyncResp(asyncRespIn) 132573df0db0SJames Feist { 132673df0db0SJames Feist std::optional<nlohmann::json> pidControllers; 132773df0db0SJames Feist std::optional<nlohmann::json> fanControllers; 132873df0db0SJames Feist std::optional<nlohmann::json> fanZones; 132973df0db0SJames Feist std::optional<nlohmann::json> stepwiseControllers; 133073df0db0SJames Feist 133173df0db0SJames Feist if (!redfish::json_util::readJson( 133273df0db0SJames Feist data, asyncResp->res, "PidControllers", pidControllers, 133373df0db0SJames Feist "FanControllers", fanControllers, "FanZones", fanZones, 133473df0db0SJames Feist "StepwiseControllers", stepwiseControllers, "Profile", profile)) 133573df0db0SJames Feist { 133673df0db0SJames Feist return; 133773df0db0SJames Feist } 133873df0db0SJames Feist configuration.emplace_back("PidControllers", std::move(pidControllers)); 133973df0db0SJames Feist configuration.emplace_back("FanControllers", std::move(fanControllers)); 134073df0db0SJames Feist configuration.emplace_back("FanZones", std::move(fanZones)); 134173df0db0SJames Feist configuration.emplace_back("StepwiseControllers", 134273df0db0SJames Feist std::move(stepwiseControllers)); 134373df0db0SJames Feist } 1344ecd6a3a2SEd Tanous 1345ecd6a3a2SEd Tanous SetPIDValues(const SetPIDValues&) = delete; 1346ecd6a3a2SEd Tanous SetPIDValues(SetPIDValues&&) = delete; 1347ecd6a3a2SEd Tanous SetPIDValues& operator=(const SetPIDValues&) = delete; 1348ecd6a3a2SEd Tanous SetPIDValues& operator=(SetPIDValues&&) = delete; 1349ecd6a3a2SEd Tanous 135073df0db0SJames Feist void run() 135173df0db0SJames Feist { 135273df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 135373df0db0SJames Feist { 135473df0db0SJames Feist return; 135573df0db0SJames Feist } 135673df0db0SJames Feist 135773df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 135873df0db0SJames Feist 135973df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 136073df0db0SJames Feist // interface gets more traction 136173df0db0SJames Feist crow::connections::systemBus->async_method_call( 13625e7e2dc5SEd Tanous [self](const boost::system::error_code& ec, 1363914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& mObj) { 136473df0db0SJames Feist if (ec) 136573df0db0SJames Feist { 136673df0db0SJames Feist BMCWEB_LOG_ERROR << "Error communicating to Entity Manager"; 136773df0db0SJames Feist messages::internalError(self->asyncResp->res); 136873df0db0SJames Feist return; 136973df0db0SJames Feist } 1370e69d9de2SJames Feist const std::array<const char*, 3> configurations = { 1371e69d9de2SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 1372e69d9de2SJames Feist stepwiseConfigurationIface}; 1373e69d9de2SJames Feist 137414b0b8d5SJames Feist for (const auto& [path, object] : mObj) 1375e69d9de2SJames Feist { 137614b0b8d5SJames Feist for (const auto& [interface, _] : object) 1377e69d9de2SJames Feist { 1378002d39b4SEd Tanous if (std::find(configurations.begin(), configurations.end(), 1379e69d9de2SJames Feist interface) != configurations.end()) 1380e69d9de2SJames Feist { 138114b0b8d5SJames Feist self->objectCount++; 1382e69d9de2SJames Feist break; 1383e69d9de2SJames Feist } 1384e69d9de2SJames Feist } 1385e69d9de2SJames Feist } 1386914e2d5dSEd Tanous self->managedObj = mObj; 138773df0db0SJames Feist }, 1388c106b67aSNan Zhou "xyz.openbmc_project.EntityManager", 1389c106b67aSNan Zhou "/xyz/openbmc_project/inventory", objectManagerIface, 139073df0db0SJames Feist "GetManagedObjects"); 139173df0db0SJames Feist 139273df0db0SJames Feist // at the same time get the profile information 1393e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1394e99073f5SGeorge Liu thermalModeIface}; 1395e99073f5SGeorge Liu dbus::utility::getSubTree( 1396e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1397e99073f5SGeorge Liu [self](const boost::system::error_code& ec, 1398b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 139973df0db0SJames Feist if (ec || subtree.empty()) 140073df0db0SJames Feist { 140173df0db0SJames Feist return; 140273df0db0SJames Feist } 140373df0db0SJames Feist if (subtree[0].second.empty()) 140473df0db0SJames Feist { 140573df0db0SJames Feist // invalid mapper response, should never happen 140673df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error"; 140773df0db0SJames Feist messages::internalError(self->asyncResp->res); 140873df0db0SJames Feist return; 140973df0db0SJames Feist } 141073df0db0SJames Feist 141173df0db0SJames Feist const std::string& path = subtree[0].first; 141273df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 1413fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1414fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 14155e7e2dc5SEd Tanous [self, path, owner](const boost::system::error_code& ec2, 1416b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& r) { 1417cb13a392SEd Tanous if (ec2) 141873df0db0SJames Feist { 14190fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1420002d39b4SEd Tanous << "SetPIDValues: Can't get thermalModeIface " << path; 142173df0db0SJames Feist messages::internalError(self->asyncResp->res); 142273df0db0SJames Feist return; 142373df0db0SJames Feist } 1424271584abSEd Tanous const std::string* current = nullptr; 1425271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1426fac6e53bSKrzysztof Grobelny 1427fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1428fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), r, "Current", current, 1429fac6e53bSKrzysztof Grobelny "Supported", supported); 1430fac6e53bSKrzysztof Grobelny 1431fac6e53bSKrzysztof Grobelny if (!success) 143273df0db0SJames Feist { 1433002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 143473df0db0SJames Feist return; 143573df0db0SJames Feist } 1436fac6e53bSKrzysztof Grobelny 143773df0db0SJames Feist if (current == nullptr || supported == nullptr) 143873df0db0SJames Feist { 14390fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1440002d39b4SEd Tanous << "SetPIDValues: thermal mode iface invalid " << path; 144173df0db0SJames Feist messages::internalError(self->asyncResp->res); 144273df0db0SJames Feist return; 144373df0db0SJames Feist } 144473df0db0SJames Feist self->currentProfile = *current; 144573df0db0SJames Feist self->supportedProfiles = *supported; 144673df0db0SJames Feist self->profileConnection = owner; 144773df0db0SJames Feist self->profilePath = path; 1448fac6e53bSKrzysztof Grobelny }); 1449e99073f5SGeorge Liu }); 145073df0db0SJames Feist } 145124b2fe81SEd Tanous void pidSetDone() 145273df0db0SJames Feist { 145373df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 145473df0db0SJames Feist { 145573df0db0SJames Feist return; 14565b4aa86bSJames Feist } 14578d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; 145873df0db0SJames Feist if (profile) 145973df0db0SJames Feist { 146073df0db0SJames Feist if (std::find(supportedProfiles.begin(), supportedProfiles.end(), 146173df0db0SJames Feist *profile) == supportedProfiles.end()) 146273df0db0SJames Feist { 146373df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 146473df0db0SJames Feist *profile); 146573df0db0SJames Feist return; 146673df0db0SJames Feist } 146773df0db0SJames Feist currentProfile = *profile; 146873df0db0SJames Feist crow::connections::systemBus->async_method_call( 14695e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 147073df0db0SJames Feist if (ec) 147173df0db0SJames Feist { 147273df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching profile" << ec; 147373df0db0SJames Feist messages::internalError(response->res); 147473df0db0SJames Feist } 147573df0db0SJames Feist }, 147673df0db0SJames Feist profileConnection, profilePath, 147773df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", thermalModeIface, 1478168e20c1SEd Tanous "Current", dbus::utility::DbusVariantType(*profile)); 147973df0db0SJames Feist } 148073df0db0SJames Feist 148173df0db0SJames Feist for (auto& containerPair : configuration) 148273df0db0SJames Feist { 148373df0db0SJames Feist auto& container = containerPair.second; 148473df0db0SJames Feist if (!container) 148573df0db0SJames Feist { 148673df0db0SJames Feist continue; 148773df0db0SJames Feist } 14886ee7f774SJames Feist BMCWEB_LOG_DEBUG << *container; 14896ee7f774SJames Feist 149002cad96eSEd Tanous const std::string& type = containerPair.first; 149173df0db0SJames Feist 149273df0db0SJames Feist for (nlohmann::json::iterator it = container->begin(); 149317a897dfSManojkiran Eda it != container->end(); ++it) 149473df0db0SJames Feist { 149573df0db0SJames Feist const auto& name = it.key(); 1496cddbf3dfSPotin Lai std::string dbusObjName = name; 1497cddbf3dfSPotin Lai std::replace(dbusObjName.begin(), dbusObjName.end(), ' ', '_'); 14986ee7f774SJames Feist BMCWEB_LOG_DEBUG << "looking for " << name; 14996ee7f774SJames Feist 150089492a15SPatrick Williams auto pathItr = std::find_if(managedObj.begin(), 150189492a15SPatrick Williams managedObj.end(), 1502cddbf3dfSPotin Lai [&dbusObjName](const auto& obj) { 1503002d39b4SEd Tanous return boost::algorithm::ends_with(obj.first.str, 1504cddbf3dfSPotin Lai "/" + dbusObjName); 150573df0db0SJames Feist }); 1506b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap output; 150773df0db0SJames Feist 150873df0db0SJames Feist output.reserve(16); // The pid interface length 150973df0db0SJames Feist 151073df0db0SJames Feist // determines if we're patching entity-manager or 151173df0db0SJames Feist // creating a new object 151273df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 15136ee7f774SJames Feist BMCWEB_LOG_DEBUG << "Found = " << !createNewObject; 15146ee7f774SJames Feist 151573df0db0SJames Feist std::string iface; 1516ea2b670dSEd Tanous if (!createNewObject) 1517ea2b670dSEd Tanous { 15188be2b5b6SPotin Lai bool findInterface = false; 1519ea2b670dSEd Tanous for (const auto& interface : pathItr->second) 1520ea2b670dSEd Tanous { 1521ea2b670dSEd Tanous if (interface.first == pidConfigurationIface) 1522ea2b670dSEd Tanous { 1523ea2b670dSEd Tanous if (type == "PidControllers" || 1524ea2b670dSEd Tanous type == "FanControllers") 152573df0db0SJames Feist { 152673df0db0SJames Feist iface = pidConfigurationIface; 15278be2b5b6SPotin Lai findInterface = true; 15288be2b5b6SPotin Lai break; 152973df0db0SJames Feist } 153073df0db0SJames Feist } 1531ea2b670dSEd Tanous else if (interface.first == pidZoneConfigurationIface) 153273df0db0SJames Feist { 1533ea2b670dSEd Tanous if (type == "FanZones") 153473df0db0SJames Feist { 1535ea2b670dSEd Tanous iface = pidConfigurationIface; 15368be2b5b6SPotin Lai findInterface = true; 15378be2b5b6SPotin Lai break; 153873df0db0SJames Feist } 153973df0db0SJames Feist } 1540ea2b670dSEd Tanous else if (interface.first == stepwiseConfigurationIface) 1541ea2b670dSEd Tanous { 1542ea2b670dSEd Tanous if (type == "StepwiseControllers") 154373df0db0SJames Feist { 154473df0db0SJames Feist iface = stepwiseConfigurationIface; 15458be2b5b6SPotin Lai findInterface = true; 15468be2b5b6SPotin Lai break; 15478be2b5b6SPotin Lai } 15488be2b5b6SPotin Lai } 15498be2b5b6SPotin Lai } 15508be2b5b6SPotin Lai 15518be2b5b6SPotin Lai // create new object if interface not found 15528be2b5b6SPotin Lai if (!findInterface) 15538be2b5b6SPotin Lai { 155473df0db0SJames Feist createNewObject = true; 155573df0db0SJames Feist } 1556ea2b670dSEd Tanous } 15576ee7f774SJames Feist 15586ee7f774SJames Feist if (createNewObject && it.value() == nullptr) 15596ee7f774SJames Feist { 15604e0453b1SGunnar Mills // can't delete a non-existent object 15611668ce6dSEd Tanous messages::propertyValueNotInList(response->res, 15621668ce6dSEd Tanous it.value().dump(), name); 15636ee7f774SJames Feist continue; 15646ee7f774SJames Feist } 15656ee7f774SJames Feist 15666ee7f774SJames Feist std::string path; 15676ee7f774SJames Feist if (pathItr != managedObj.end()) 15686ee7f774SJames Feist { 15696ee7f774SJames Feist path = pathItr->first.str; 15706ee7f774SJames Feist } 15716ee7f774SJames Feist 157273df0db0SJames Feist BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n"; 1573e69d9de2SJames Feist 1574e69d9de2SJames Feist // arbitrary limit to avoid attacks 1575e69d9de2SJames Feist constexpr const size_t controllerLimit = 500; 157614b0b8d5SJames Feist if (createNewObject && objectCount >= controllerLimit) 1577e69d9de2SJames Feist { 1578e69d9de2SJames Feist messages::resourceExhaustion(response->res, type); 1579e69d9de2SJames Feist continue; 1580e69d9de2SJames Feist } 1581a170f275SEd Tanous std::string escaped = name; 1582a170f275SEd Tanous std::replace(escaped.begin(), escaped.end(), '_', ' '); 1583a170f275SEd Tanous output.emplace_back("Name", escaped); 158473df0db0SJames Feist 158573df0db0SJames Feist std::string chassis; 158673df0db0SJames Feist CreatePIDRet ret = createPidInterface( 15876ee7f774SJames Feist response, type, it, path, managedObj, createNewObject, 15886ee7f774SJames Feist output, chassis, currentProfile); 158973df0db0SJames Feist if (ret == CreatePIDRet::fail) 159073df0db0SJames Feist { 159173df0db0SJames Feist return; 159273df0db0SJames Feist } 15933174e4dfSEd Tanous if (ret == CreatePIDRet::del) 159473df0db0SJames Feist { 159573df0db0SJames Feist continue; 159673df0db0SJames Feist } 159773df0db0SJames Feist 159873df0db0SJames Feist if (!createNewObject) 159973df0db0SJames Feist { 160073df0db0SJames Feist for (const auto& property : output) 160173df0db0SJames Feist { 160273df0db0SJames Feist crow::connections::systemBus->async_method_call( 160373df0db0SJames Feist [response, 160473df0db0SJames Feist propertyName{std::string(property.first)}]( 16055e7e2dc5SEd Tanous const boost::system::error_code& ec) { 160673df0db0SJames Feist if (ec) 160773df0db0SJames Feist { 160873df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching " 1609002d39b4SEd Tanous << propertyName << ": " << ec; 161073df0db0SJames Feist messages::internalError(response->res); 161173df0db0SJames Feist return; 161273df0db0SJames Feist } 161373df0db0SJames Feist messages::success(response->res); 161473df0db0SJames Feist }, 16156ee7f774SJames Feist "xyz.openbmc_project.EntityManager", path, 161673df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", iface, 161773df0db0SJames Feist property.first, property.second); 161873df0db0SJames Feist } 161973df0db0SJames Feist } 162073df0db0SJames Feist else 162173df0db0SJames Feist { 162273df0db0SJames Feist if (chassis.empty()) 162373df0db0SJames Feist { 162473df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config"; 1625ace85d60SEd Tanous messages::internalError(response->res); 162673df0db0SJames Feist return; 162773df0db0SJames Feist } 162873df0db0SJames Feist 162973df0db0SJames Feist bool foundChassis = false; 163073df0db0SJames Feist for (const auto& obj : managedObj) 163173df0db0SJames Feist { 163273df0db0SJames Feist if (boost::algorithm::ends_with(obj.first.str, chassis)) 163373df0db0SJames Feist { 163473df0db0SJames Feist chassis = obj.first.str; 163573df0db0SJames Feist foundChassis = true; 163673df0db0SJames Feist break; 163773df0db0SJames Feist } 163873df0db0SJames Feist } 163973df0db0SJames Feist if (!foundChassis) 164073df0db0SJames Feist { 164173df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to find chassis on dbus"; 164273df0db0SJames Feist messages::resourceMissingAtURI( 1643ace85d60SEd Tanous response->res, 1644*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", 1645*ef4c65b7SEd Tanous chassis)); 164673df0db0SJames Feist return; 164773df0db0SJames Feist } 164873df0db0SJames Feist 164973df0db0SJames Feist crow::connections::systemBus->async_method_call( 16505e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 165173df0db0SJames Feist if (ec) 165273df0db0SJames Feist { 165373df0db0SJames Feist BMCWEB_LOG_ERROR << "Error Adding Pid Object " 165473df0db0SJames Feist << ec; 165573df0db0SJames Feist messages::internalError(response->res); 165673df0db0SJames Feist return; 165773df0db0SJames Feist } 165873df0db0SJames Feist messages::success(response->res); 165973df0db0SJames Feist }, 166073df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 166173df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 166273df0db0SJames Feist } 166373df0db0SJames Feist } 166473df0db0SJames Feist } 166573df0db0SJames Feist } 166624b2fe81SEd Tanous 166724b2fe81SEd Tanous ~SetPIDValues() 166824b2fe81SEd Tanous { 166924b2fe81SEd Tanous try 167024b2fe81SEd Tanous { 167124b2fe81SEd Tanous pidSetDone(); 167224b2fe81SEd Tanous } 167324b2fe81SEd Tanous catch (...) 167424b2fe81SEd Tanous { 167524b2fe81SEd Tanous BMCWEB_LOG_CRITICAL << "pidSetDone threw exception"; 167624b2fe81SEd Tanous } 167724b2fe81SEd Tanous } 167824b2fe81SEd Tanous 16798d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 168073df0db0SJames Feist std::vector<std::pair<std::string, std::optional<nlohmann::json>>> 168173df0db0SJames Feist configuration; 168273df0db0SJames Feist std::optional<std::string> profile; 168373df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 168473df0db0SJames Feist std::vector<std::string> supportedProfiles; 168573df0db0SJames Feist std::string currentProfile; 168673df0db0SJames Feist std::string profileConnection; 168773df0db0SJames Feist std::string profilePath; 168814b0b8d5SJames Feist size_t objectCount = 0; 168973df0db0SJames Feist }; 169073df0db0SJames Feist 1691071d8fdfSSunnySrivastava1984 /** 1692071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 1693071d8fdfSSunnySrivastava1984 * 1694071d8fdfSSunnySrivastava1984 * @param[in] aResp Shared pointer for completing asynchronous calls 1695071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 1696071d8fdfSSunnySrivastava1984 * @param[in] path - object path 1697071d8fdfSSunnySrivastava1984 * @return none 1698071d8fdfSSunnySrivastava1984 */ 16998d1b46d7Szhanghch05 inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1700071d8fdfSSunnySrivastava1984 const std::string& connectionName, 1701071d8fdfSSunnySrivastava1984 const std::string& path) 1702071d8fdfSSunnySrivastava1984 { 1703071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Get BMC manager Location data."; 1704071d8fdfSSunnySrivastava1984 17051e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 17061e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 17071e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 17085e7e2dc5SEd Tanous [aResp](const boost::system::error_code& ec, 17091e1e598dSJonathan Doman const std::string& property) { 1710071d8fdfSSunnySrivastava1984 if (ec) 1711071d8fdfSSunnySrivastava1984 { 1712071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "DBUS response error for " 1713071d8fdfSSunnySrivastava1984 "Location"; 1714071d8fdfSSunnySrivastava1984 messages::internalError(aResp->res); 1715071d8fdfSSunnySrivastava1984 return; 1716071d8fdfSSunnySrivastava1984 } 1717071d8fdfSSunnySrivastava1984 1718071d8fdfSSunnySrivastava1984 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 17191e1e598dSJonathan Doman property; 17201e1e598dSJonathan Doman }); 1721071d8fdfSSunnySrivastava1984 } 17227e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 17237e860f15SJohn Edward Broadbent inline void 17247e860f15SJohn Edward Broadbent managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 17254bf2b033SGunnar Mills { 17264bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time"; 17274bf2b033SGunnar Mills 17281e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint64_t>( 17291e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.BMC", 17301e1e598dSJonathan Doman "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC", 17311e1e598dSJonathan Doman "LastRebootTime", 17325e7e2dc5SEd Tanous [aResp](const boost::system::error_code& ec, 17331e1e598dSJonathan Doman const uint64_t lastResetTime) { 17344bf2b033SGunnar Mills if (ec) 17354bf2b033SGunnar Mills { 17364bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 17374bf2b033SGunnar Mills return; 17384bf2b033SGunnar Mills } 17394bf2b033SGunnar Mills 17404bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 17414bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 17421e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 17434bf2b033SGunnar Mills 17444bf2b033SGunnar Mills // Convert to ISO 8601 standard 17454bf2b033SGunnar Mills aResp->res.jsonValue["LastResetTime"] = 17462b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 17471e1e598dSJonathan Doman }); 17484bf2b033SGunnar Mills } 17494bf2b033SGunnar Mills 17504bfefa74SGunnar Mills /** 17514bfefa74SGunnar Mills * @brief Set the running firmware image 17524bfefa74SGunnar Mills * 17534bfefa74SGunnar Mills * @param[i,o] aResp - Async response object 17544bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 17554bfefa74SGunnar Mills * 17564bfefa74SGunnar Mills * @return void 17574bfefa74SGunnar Mills */ 17587e860f15SJohn Edward Broadbent inline void 17597e860f15SJohn Edward Broadbent setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1760f23b7296SEd Tanous const std::string& runningFirmwareTarget) 17614bfefa74SGunnar Mills { 17624bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 1763f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 17644bfefa74SGunnar Mills if (idPos == std::string::npos) 17654bfefa74SGunnar Mills { 17664bfefa74SGunnar Mills messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 17674bfefa74SGunnar Mills "@odata.id"); 17684bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't parse firmware ID!"; 17694bfefa74SGunnar Mills return; 17704bfefa74SGunnar Mills } 17714bfefa74SGunnar Mills idPos++; 17724bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 17734bfefa74SGunnar Mills { 17744bfefa74SGunnar Mills messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 17754bfefa74SGunnar Mills "@odata.id"); 17764bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 17774bfefa74SGunnar Mills return; 17784bfefa74SGunnar Mills } 17794bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 17804bfefa74SGunnar Mills 17814bfefa74SGunnar Mills // Make sure the image is valid before setting priority 17824bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 1783711ac7a9SEd Tanous [aResp, firmwareId, 17845e7e2dc5SEd Tanous runningFirmwareTarget](const boost::system::error_code& ec, 1785711ac7a9SEd Tanous dbus::utility::ManagedObjectType& subtree) { 17864bfefa74SGunnar Mills if (ec) 17874bfefa74SGunnar Mills { 17884bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error getting objects."; 17894bfefa74SGunnar Mills messages::internalError(aResp->res); 17904bfefa74SGunnar Mills return; 17914bfefa74SGunnar Mills } 17924bfefa74SGunnar Mills 179326f6976fSEd Tanous if (subtree.empty()) 17944bfefa74SGunnar Mills { 17954bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't find image!"; 17964bfefa74SGunnar Mills messages::internalError(aResp->res); 17974bfefa74SGunnar Mills return; 17984bfefa74SGunnar Mills } 17994bfefa74SGunnar Mills 18004bfefa74SGunnar Mills bool foundImage = false; 180102cad96eSEd Tanous for (const auto& object : subtree) 18024bfefa74SGunnar Mills { 18034bfefa74SGunnar Mills const std::string& path = 18044bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 1805f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 18064bfefa74SGunnar Mills 18074bfefa74SGunnar Mills if (idPos2 == std::string::npos) 18084bfefa74SGunnar Mills { 18094bfefa74SGunnar Mills continue; 18104bfefa74SGunnar Mills } 18114bfefa74SGunnar Mills 18124bfefa74SGunnar Mills idPos2++; 18134bfefa74SGunnar Mills if (idPos2 >= path.size()) 18144bfefa74SGunnar Mills { 18154bfefa74SGunnar Mills continue; 18164bfefa74SGunnar Mills } 18174bfefa74SGunnar Mills 18184bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 18194bfefa74SGunnar Mills { 18204bfefa74SGunnar Mills foundImage = true; 18214bfefa74SGunnar Mills break; 18224bfefa74SGunnar Mills } 18234bfefa74SGunnar Mills } 18244bfefa74SGunnar Mills 18254bfefa74SGunnar Mills if (!foundImage) 18264bfefa74SGunnar Mills { 1827002d39b4SEd Tanous messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 1828002d39b4SEd Tanous "@odata.id"); 18294bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 18304bfefa74SGunnar Mills return; 18314bfefa74SGunnar Mills } 18324bfefa74SGunnar Mills 18338cc8edecSEd Tanous BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId 18348cc8edecSEd Tanous << " to priority 0."; 18354bfefa74SGunnar Mills 18364bfefa74SGunnar Mills // Only support Immediate 18374bfefa74SGunnar Mills // An addition could be a Redfish Setting like 18384bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 18394bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 18405e7e2dc5SEd Tanous [aResp](const boost::system::error_code& ec2) { 18418a592810SEd Tanous if (ec2) 18424bfefa74SGunnar Mills { 18434bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error setting."; 18444bfefa74SGunnar Mills messages::internalError(aResp->res); 18454bfefa74SGunnar Mills return; 18464bfefa74SGunnar Mills } 18474bfefa74SGunnar Mills doBMCGracefulRestart(aResp); 18484bfefa74SGunnar Mills }, 18494bfefa74SGunnar Mills 18504bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18514bfefa74SGunnar Mills "/xyz/openbmc_project/software/" + firmwareId, 18524bfefa74SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 18537e860f15SJohn Edward Broadbent "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 1854168e20c1SEd Tanous dbus::utility::DbusVariantType(static_cast<uint8_t>(0))); 18554bfefa74SGunnar Mills }, 18564bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18577e860f15SJohn Edward Broadbent "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager", 18587e860f15SJohn Edward Broadbent "GetManagedObjects"); 18594bfefa74SGunnar Mills } 18604bfefa74SGunnar Mills 18617e860f15SJohn Edward Broadbent inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp, 18627e860f15SJohn Edward Broadbent std::string datetime) 1863af5d6058SSantosh Puranik { 1864af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Set date time: " << datetime; 1865af5d6058SSantosh Puranik 1866c2e32007SEd Tanous std::optional<redfish::time_utils::usSinceEpoch> us = 1867c2e32007SEd Tanous redfish::time_utils::dateStringToEpoch(datetime); 1868c2e32007SEd Tanous if (!us) 1869af5d6058SSantosh Puranik { 1870c2e32007SEd Tanous messages::propertyValueFormatError(aResp->res, datetime, "DateTime"); 1871c2e32007SEd Tanous return; 1872c2e32007SEd Tanous } 1873af5d6058SSantosh Puranik crow::connections::systemBus->async_method_call( 1874c2e32007SEd Tanous [aResp{std::move(aResp)}, 18755e7e2dc5SEd Tanous datetime{std::move(datetime)}](const boost::system::error_code& ec) { 1876af5d6058SSantosh Puranik if (ec) 1877af5d6058SSantosh Puranik { 1878af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Failed to set elapsed time. " 1879af5d6058SSantosh Puranik "DBUS response error " 1880af5d6058SSantosh Puranik << ec; 1881af5d6058SSantosh Puranik messages::internalError(aResp->res); 1882af5d6058SSantosh Puranik return; 1883af5d6058SSantosh Puranik } 1884af5d6058SSantosh Puranik aResp->res.jsonValue["DateTime"] = datetime; 1885af5d6058SSantosh Puranik }, 18867e860f15SJohn Edward Broadbent "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc", 1887af5d6058SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1888af5d6058SSantosh Puranik "xyz.openbmc_project.Time.EpochTime", "Elapsed", 1889c2e32007SEd Tanous dbus::utility::DbusVariantType(us->count())); 189083ff9ab6SJames Feist } 18919c310685SBorawski.Lukasz 18927e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 18937e860f15SJohn Edward Broadbent { 18947e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 18959c310685SBorawski.Lukasz 18967e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 1897ed398213SEd Tanous .privileges(redfish::privileges::getManager) 1898002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1899002d39b4SEd Tanous [&app, uuid](const crow::Request& req, 190045ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 19013ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 190245ca1b86SEd Tanous { 190345ca1b86SEd Tanous return; 190445ca1b86SEd Tanous } 19057e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; 1906a51fc2d2SSui Chen asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager"; 19077e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "bmc"; 19087e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 19097e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 19107e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 19117e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["PowerState"] = "On"; 19121476687dSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 19131476687dSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 19141476687dSEd Tanous 19157e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ManagerType"] = "BMC"; 19167e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 19177e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 1918002d39b4SEd Tanous asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model 19197e860f15SJohn Edward Broadbent 19201476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 19211476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices"; 19221476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 19231476687dSEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol"; 19241476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 19251476687dSEd Tanous "/redfish/v1/Managers/bmc/EthernetInterfaces"; 19267e860f15SJohn Edward Broadbent 19277e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_VM_NBDPROXY 19281476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 19291476687dSEd Tanous "/redfish/v1/Managers/bmc/VirtualMedia"; 19307e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_VM_NBDPROXY 19317e860f15SJohn Edward Broadbent 19327e860f15SJohn Edward Broadbent // default oem data 19337e860f15SJohn Edward Broadbent nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; 19347e860f15SJohn Edward Broadbent nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 19357e860f15SJohn Edward Broadbent oem["@odata.type"] = "#OemManager.Oem"; 19367e860f15SJohn Edward Broadbent oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; 19377e860f15SJohn Edward Broadbent oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; 19387e860f15SJohn Edward Broadbent oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; 19391476687dSEd Tanous 19401476687dSEd Tanous nlohmann::json::object_t certificates; 19411476687dSEd Tanous certificates["@odata.id"] = 19421476687dSEd Tanous "/redfish/v1/Managers/bmc/Truststore/Certificates"; 19431476687dSEd Tanous oemOpenbmc["Certificates"] = std::move(certificates); 19447e860f15SJohn Edward Broadbent 19457e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 19467e860f15SJohn Edward Broadbent // supports BMC reboot. 19477e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 19487e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 19497e860f15SJohn Edward Broadbent managerReset["target"] = 19507e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; 19517e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 19527e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/ResetActionInfo"; 19537e860f15SJohn Edward Broadbent 19547e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 19557e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 19567e860f15SJohn Edward Broadbent // on OpenBMC 19577e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 19587e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 19597e860f15SJohn Edward Broadbent resetToDefaults["target"] = 19607e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults"; 1961613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] = 1962613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"}); 19637e860f15SJohn Edward Broadbent 19647c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 19652b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 19667c8c4058STejas Patil 19677c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 19687c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 19697c8c4058STejas Patil redfishDateTimeOffset.second; 19707e860f15SJohn Edward Broadbent 19710e8ac5e7SGunnar Mills // TODO (Gunnar): Remove these one day since moved to ComputerSystem 19720e8ac5e7SGunnar Mills // Still used by OCP profiles 19730e8ac5e7SGunnar Mills // https://github.com/opencomputeproject/OCP-Profiles/issues/23 19747e860f15SJohn Edward Broadbent // Fill in SerialConsole info 19757e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; 1976002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 1977613dabeaSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = 1978613dabeaSEd Tanous nlohmann::json::array_t({"IPMI", "SSH"}); 19797e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_KVM 19807e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 1981002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 1982002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 1983002d39b4SEd Tanous 4; 1984613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 1985613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 19867e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_KVM 19877e860f15SJohn Edward Broadbent 1988002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 19891476687dSEd Tanous 19901476687dSEd Tanous nlohmann::json::array_t managerForServers; 19911476687dSEd Tanous nlohmann::json::object_t manager; 19921476687dSEd Tanous manager["@odata.id"] = "/redfish/v1/Systems/system"; 1993ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager)); 19941476687dSEd Tanous 19951476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 19961476687dSEd Tanous std::move(managerForServers); 19977e860f15SJohn Edward Broadbent 19987e860f15SJohn Edward Broadbent auto health = std::make_shared<HealthPopulate>(asyncResp); 19997e860f15SJohn Edward Broadbent health->isManagersHealth = true; 20007e860f15SJohn Edward Broadbent health->populate(); 20017e860f15SJohn Edward Broadbent 2002eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 20037e860f15SJohn Edward Broadbent "FirmwareVersion", true); 20047e860f15SJohn Edward Broadbent 20057e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 20067e860f15SJohn Edward Broadbent 2007a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 2008a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 2009a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 2010a51fc2d2SSui Chen managerDiagnosticData["@odata.id"] = 2011a51fc2d2SSui Chen "/redfish/v1/Managers/bmc/ManagerDiagnosticData"; 2012a51fc2d2SSui Chen 201354dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 20147e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp); 20157e860f15SJohn Edward Broadbent pids->run(); 201654dce7f5SGunnar Mills #endif 20177e860f15SJohn Edward Broadbent 2018002d39b4SEd Tanous getMainChassisId(asyncResp, 2019002d39b4SEd Tanous [](const std::string& chassisId, 2020002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2021002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1; 20221476687dSEd Tanous nlohmann::json::array_t managerForChassis; 20238a592810SEd Tanous nlohmann::json::object_t managerObj; 2024*ef4c65b7SEd Tanous boost::urls::url chassiUrl = 2025*ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 2026eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl; 2027ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj)); 20281476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 20291476687dSEd Tanous std::move(managerForChassis); 20301476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 2031eddfc437SWilly Tu chassiUrl; 20327e860f15SJohn Edward Broadbent }); 20337e860f15SJohn Edward Broadbent 20347e860f15SJohn Edward Broadbent static bool started = false; 20357e860f15SJohn Edward Broadbent 20367e860f15SJohn Edward Broadbent if (!started) 20371abe55efSEd Tanous { 20381e1e598dSJonathan Doman sdbusplus::asio::getProperty<double>( 20391e1e598dSJonathan Doman *crow::connections::systemBus, "org.freedesktop.systemd1", 2040002d39b4SEd Tanous "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", 2041002d39b4SEd Tanous "Progress", 20425e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec, 20431e1e598dSJonathan Doman const double& val) { 20447e860f15SJohn Edward Broadbent if (ec) 20451abe55efSEd Tanous { 20467e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Error while getting progress"; 20477e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20487e860f15SJohn Edward Broadbent return; 20497e860f15SJohn Edward Broadbent } 20501e1e598dSJonathan Doman if (val < 1.0) 20517e860f15SJohn Edward Broadbent { 2052002d39b4SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Starting"; 20537e860f15SJohn Edward Broadbent started = true; 20547e860f15SJohn Edward Broadbent } 20551e1e598dSJonathan Doman }); 20569c310685SBorawski.Lukasz } 20579c310685SBorawski.Lukasz 2058e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2059e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"}; 2060e99073f5SGeorge Liu dbus::utility::getSubTree( 2061e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 20627e860f15SJohn Edward Broadbent [asyncResp]( 2063e99073f5SGeorge Liu const boost::system::error_code& ec, 2064b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 20657e860f15SJohn Edward Broadbent if (ec) 20661abe55efSEd Tanous { 2067002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 20687e860f15SJohn Edward Broadbent return; 20697e860f15SJohn Edward Broadbent } 207026f6976fSEd Tanous if (subtree.empty()) 20717e860f15SJohn Edward Broadbent { 20727e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!"; 20737e860f15SJohn Edward Broadbent return; 20747e860f15SJohn Edward Broadbent } 20757e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 20767e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 20777e860f15SJohn Edward Broadbent if (subtree.size() > 1) 20787e860f15SJohn Edward Broadbent { 2079002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Found more than 1 bmc D-Bus object!"; 20807e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20817e860f15SJohn Edward Broadbent return; 20827e860f15SJohn Edward Broadbent } 20837e860f15SJohn Edward Broadbent 2084002d39b4SEd Tanous if (subtree[0].first.empty() || subtree[0].second.size() != 1) 20857e860f15SJohn Edward Broadbent { 20867e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!"; 20877e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20887e860f15SJohn Edward Broadbent return; 20897e860f15SJohn Edward Broadbent } 20907e860f15SJohn Edward Broadbent 20917e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 2092002d39b4SEd Tanous const std::string& connectionName = subtree[0].second[0].first; 20937e860f15SJohn Edward Broadbent 2094002d39b4SEd Tanous for (const auto& interfaceName : subtree[0].second[0].second) 20957e860f15SJohn Edward Broadbent { 20967e860f15SJohn Edward Broadbent if (interfaceName == 20977e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 20987e860f15SJohn Edward Broadbent { 2099fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2100fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, connectionName, path, 2101fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 21025e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec2, 2103b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 21047e860f15SJohn Edward Broadbent propertiesList) { 21058a592810SEd Tanous if (ec2) 21067e860f15SJohn Edward Broadbent { 2107002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Can't get bmc asset!"; 21087e860f15SJohn Edward Broadbent return; 21097e860f15SJohn Edward Broadbent } 21107e860f15SJohn Edward Broadbent 2111fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr; 2112fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr; 2113fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr; 2114fac6e53bSKrzysztof Grobelny const std::string* model = nullptr; 2115fac6e53bSKrzysztof Grobelny const std::string* sparePartNumber = nullptr; 2116fac6e53bSKrzysztof Grobelny 2117fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2118fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), propertiesList, 2119fac6e53bSKrzysztof Grobelny "PartNumber", partNumber, "SerialNumber", 2120fac6e53bSKrzysztof Grobelny serialNumber, "Manufacturer", manufacturer, "Model", 2121fac6e53bSKrzysztof Grobelny model, "SparePartNumber", sparePartNumber); 2122fac6e53bSKrzysztof Grobelny 2123fac6e53bSKrzysztof Grobelny if (!success) 21247e860f15SJohn Edward Broadbent { 2125002d39b4SEd Tanous messages::internalError(asyncResp->res); 21267e860f15SJohn Edward Broadbent return; 21277e860f15SJohn Edward Broadbent } 2128fac6e53bSKrzysztof Grobelny 2129fac6e53bSKrzysztof Grobelny if (partNumber != nullptr) 2130fac6e53bSKrzysztof Grobelny { 2131fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = 2132fac6e53bSKrzysztof Grobelny *partNumber; 21337e860f15SJohn Edward Broadbent } 2134fac6e53bSKrzysztof Grobelny 2135fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr) 2136fac6e53bSKrzysztof Grobelny { 2137fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SerialNumber"] = 2138fac6e53bSKrzysztof Grobelny *serialNumber; 21397e860f15SJohn Edward Broadbent } 2140fac6e53bSKrzysztof Grobelny 2141fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr) 2142fac6e53bSKrzysztof Grobelny { 2143fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Manufacturer"] = 2144fac6e53bSKrzysztof Grobelny *manufacturer; 2145fac6e53bSKrzysztof Grobelny } 2146fac6e53bSKrzysztof Grobelny 2147fac6e53bSKrzysztof Grobelny if (model != nullptr) 2148fac6e53bSKrzysztof Grobelny { 2149fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Model"] = *model; 2150fac6e53bSKrzysztof Grobelny } 2151fac6e53bSKrzysztof Grobelny 2152fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr) 2153fac6e53bSKrzysztof Grobelny { 2154fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SparePartNumber"] = 2155fac6e53bSKrzysztof Grobelny *sparePartNumber; 2156fac6e53bSKrzysztof Grobelny } 2157fac6e53bSKrzysztof Grobelny }); 21587e860f15SJohn Edward Broadbent } 2159002d39b4SEd Tanous else if (interfaceName == 21600fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 21617e860f15SJohn Edward Broadbent { 21627e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 21637e860f15SJohn Edward Broadbent } 21647e860f15SJohn Edward Broadbent } 2165e99073f5SGeorge Liu }); 21667e860f15SJohn Edward Broadbent }); 21677e860f15SJohn Edward Broadbent 21687e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 2169ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 217045ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 217145ca1b86SEd Tanous [&app](const crow::Request& req, 21727e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21733ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 217445ca1b86SEd Tanous { 217545ca1b86SEd Tanous return; 217645ca1b86SEd Tanous } 21777e860f15SJohn Edward Broadbent std::optional<nlohmann::json> oem; 21787e860f15SJohn Edward Broadbent std::optional<nlohmann::json> links; 21797e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 21807e860f15SJohn Edward Broadbent 218115ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem, 2182002d39b4SEd Tanous "DateTime", datetime, "Links", links)) 21837e860f15SJohn Edward Broadbent { 21847e860f15SJohn Edward Broadbent return; 21857e860f15SJohn Edward Broadbent } 21867e860f15SJohn Edward Broadbent 21877e860f15SJohn Edward Broadbent if (oem) 21887e860f15SJohn Edward Broadbent { 218954dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 21907e860f15SJohn Edward Broadbent std::optional<nlohmann::json> openbmc; 2191002d39b4SEd Tanous if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc", 2192002d39b4SEd Tanous openbmc)) 21937e860f15SJohn Edward Broadbent { 21947e860f15SJohn Edward Broadbent return; 21957e860f15SJohn Edward Broadbent } 21967e860f15SJohn Edward Broadbent if (openbmc) 21977e860f15SJohn Edward Broadbent { 21987e860f15SJohn Edward Broadbent std::optional<nlohmann::json> fan; 2199002d39b4SEd Tanous if (!redfish::json_util::readJson(*openbmc, asyncResp->res, 2200002d39b4SEd Tanous "Fan", fan)) 22017e860f15SJohn Edward Broadbent { 22027e860f15SJohn Edward Broadbent return; 22037e860f15SJohn Edward Broadbent } 22047e860f15SJohn Edward Broadbent if (fan) 22057e860f15SJohn Edward Broadbent { 2206002d39b4SEd Tanous auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan); 22077e860f15SJohn Edward Broadbent pid->run(); 22087e860f15SJohn Edward Broadbent } 22097e860f15SJohn Edward Broadbent } 221054dce7f5SGunnar Mills #else 221154dce7f5SGunnar Mills messages::propertyUnknown(asyncResp->res, "Oem"); 221254dce7f5SGunnar Mills return; 221354dce7f5SGunnar Mills #endif 22147e860f15SJohn Edward Broadbent } 22157e860f15SJohn Edward Broadbent if (links) 22167e860f15SJohn Edward Broadbent { 22177e860f15SJohn Edward Broadbent std::optional<nlohmann::json> activeSoftwareImage; 22187e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*links, asyncResp->res, 22197e860f15SJohn Edward Broadbent "ActiveSoftwareImage", 22207e860f15SJohn Edward Broadbent activeSoftwareImage)) 22217e860f15SJohn Edward Broadbent { 22227e860f15SJohn Edward Broadbent return; 22237e860f15SJohn Edward Broadbent } 22247e860f15SJohn Edward Broadbent if (activeSoftwareImage) 22257e860f15SJohn Edward Broadbent { 22267e860f15SJohn Edward Broadbent std::optional<std::string> odataId; 2227002d39b4SEd Tanous if (!json_util::readJson(*activeSoftwareImage, asyncResp->res, 2228002d39b4SEd Tanous "@odata.id", odataId)) 22297e860f15SJohn Edward Broadbent { 22307e860f15SJohn Edward Broadbent return; 22317e860f15SJohn Edward Broadbent } 22327e860f15SJohn Edward Broadbent 22337e860f15SJohn Edward Broadbent if (odataId) 22347e860f15SJohn Edward Broadbent { 22357e860f15SJohn Edward Broadbent setActiveFirmwareImage(asyncResp, *odataId); 22367e860f15SJohn Edward Broadbent } 22377e860f15SJohn Edward Broadbent } 22387e860f15SJohn Edward Broadbent } 22397e860f15SJohn Edward Broadbent if (datetime) 22407e860f15SJohn Edward Broadbent { 22417e860f15SJohn Edward Broadbent setDateTime(asyncResp, std::move(*datetime)); 22427e860f15SJohn Edward Broadbent } 22437e860f15SJohn Edward Broadbent }); 22447e860f15SJohn Edward Broadbent } 22457e860f15SJohn Edward Broadbent 22467e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 22477e860f15SJohn Edward Broadbent { 22487e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 2249ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 22507e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 225145ca1b86SEd Tanous [&app](const crow::Request& req, 22527e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22533ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 225445ca1b86SEd Tanous { 225545ca1b86SEd Tanous return; 225645ca1b86SEd Tanous } 225783ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 225883ff9ab6SJames Feist // because it has a duplicate entry for members 22598d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 22608d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 22618d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 22628d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 22638d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 22641476687dSEd Tanous nlohmann::json::array_t members; 22651476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 22661476687dSEd Tanous bmc["@odata.id"] = "/redfish/v1/Managers/bmc"; 22671476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 22687e860f15SJohn Edward Broadbent }); 22699c310685SBorawski.Lukasz } 22709c310685SBorawski.Lukasz } // namespace redfish 2271