19c310685SBorawski.Lukasz /* 29c310685SBorawski.Lukasz // Copyright (c) 2018 Intel Corporation 39c310685SBorawski.Lukasz // 49c310685SBorawski.Lukasz // Licensed under the Apache License, Version 2.0 (the "License"); 59c310685SBorawski.Lukasz // you may not use this file except in compliance with the License. 69c310685SBorawski.Lukasz // You may obtain a copy of the License at 79c310685SBorawski.Lukasz // 89c310685SBorawski.Lukasz // http://www.apache.org/licenses/LICENSE-2.0 99c310685SBorawski.Lukasz // 109c310685SBorawski.Lukasz // Unless required by applicable law or agreed to in writing, software 119c310685SBorawski.Lukasz // distributed under the License is distributed on an "AS IS" BASIS, 129c310685SBorawski.Lukasz // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 139c310685SBorawski.Lukasz // See the License for the specific language governing permissions and 149c310685SBorawski.Lukasz // limitations under the License. 159c310685SBorawski.Lukasz */ 169c310685SBorawski.Lukasz #pragma once 179c310685SBorawski.Lukasz 1813451e39SWilly Tu #include "bmcweb_config.h" 1913451e39SWilly Tu 20a51fc2d2SSui Chen #include "app.hpp" 21a51fc2d2SSui Chen #include "dbus_utility.hpp" 22b49ac873SJames Feist #include "health.hpp" 23a51fc2d2SSui Chen #include "query.hpp" 24c5d03ff4SJennifer Lee #include "redfish_util.hpp" 25a51fc2d2SSui Chen #include "registries/privilege_registry.hpp" 26fac6e53bSKrzysztof Grobelny #include "utils/dbus_utils.hpp" 273ccb3adbSEd Tanous #include "utils/json_utils.hpp" 28a51fc2d2SSui Chen #include "utils/sw_utils.hpp" 29a51fc2d2SSui Chen #include "utils/systemd_utils.hpp" 302b82937eSEd Tanous #include "utils/time_utils.hpp" 319c310685SBorawski.Lukasz 32e99073f5SGeorge Liu #include <boost/system/error_code.hpp> 33ef4c65b7SEd Tanous #include <boost/url/format.hpp> 34fac6e53bSKrzysztof Grobelny #include <sdbusplus/asio/property.hpp> 35fac6e53bSKrzysztof Grobelny #include <sdbusplus/unpack_properties.hpp> 361214b7e7SGunnar Mills 37a170f275SEd Tanous #include <algorithm> 38e99073f5SGeorge Liu #include <array> 394bfefa74SGunnar Mills #include <cstdint> 401214b7e7SGunnar Mills #include <memory> 411214b7e7SGunnar Mills #include <sstream> 42e99073f5SGeorge Liu #include <string_view> 43abf2add6SEd Tanous #include <variant> 445b4aa86bSJames Feist 451abe55efSEd Tanous namespace redfish 461abe55efSEd Tanous { 47ed5befbdSJennifer Lee 48ed5befbdSJennifer Lee /** 492a5c4407SGunnar Mills * Function reboots the BMC. 502a5c4407SGunnar Mills * 512a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls 52ed5befbdSJennifer Lee */ 538d1b46d7Szhanghch05 inline void 548d1b46d7Szhanghch05 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 55ed5befbdSJennifer Lee { 56ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 57ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 58ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 59ed5befbdSJennifer Lee const std::string& propertyValue = 60ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 61ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 62ed5befbdSJennifer Lee 63ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 64168e20c1SEd Tanous dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); 65ed5befbdSJennifer Lee 66ed5befbdSJennifer Lee crow::connections::systemBus->async_method_call( 675e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 68ed5befbdSJennifer Lee // Use "Set" method to set the property value. 69ed5befbdSJennifer Lee if (ec) 70ed5befbdSJennifer Lee { 712a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 72ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 73ed5befbdSJennifer Lee return; 74ed5befbdSJennifer Lee } 75ed5befbdSJennifer Lee 76ed5befbdSJennifer Lee messages::success(asyncResp->res); 77ed5befbdSJennifer Lee }, 78ed5befbdSJennifer Lee processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 79ed5befbdSJennifer Lee interfaceName, destProperty, dbusPropertyValue); 80ed5befbdSJennifer Lee } 812a5c4407SGunnar Mills 828d1b46d7Szhanghch05 inline void 838d1b46d7Szhanghch05 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 84f92af389SJayaprakash Mutyala { 85f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC"; 86f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 87f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC"; 88f92af389SJayaprakash Mutyala const std::string& propertyValue = 89f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 90f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition"; 91f92af389SJayaprakash Mutyala 92f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call. 93168e20c1SEd Tanous dbus::utility::DbusVariantType dbusPropertyValue(propertyValue); 94f92af389SJayaprakash Mutyala 95f92af389SJayaprakash Mutyala crow::connections::systemBus->async_method_call( 965e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 97f92af389SJayaprakash Mutyala // Use "Set" method to set the property value. 98f92af389SJayaprakash Mutyala if (ec) 99f92af389SJayaprakash Mutyala { 100f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 101f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res); 102f92af389SJayaprakash Mutyala return; 103f92af389SJayaprakash Mutyala } 104f92af389SJayaprakash Mutyala 105f92af389SJayaprakash Mutyala messages::success(asyncResp->res); 106f92af389SJayaprakash Mutyala }, 107f92af389SJayaprakash Mutyala processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 108f92af389SJayaprakash Mutyala interfaceName, destProperty, dbusPropertyValue); 109f92af389SJayaprakash Mutyala } 110f92af389SJayaprakash Mutyala 1112a5c4407SGunnar Mills /** 1122a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot) 1132a5c4407SGunnar Mills * action. 1142a5c4407SGunnar Mills */ 1157e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app) 1162a5c4407SGunnar Mills { 1172a5c4407SGunnar Mills /** 1182a5c4407SGunnar Mills * Function handles POST method request. 1192a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 120f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 1212a5c4407SGunnar Mills */ 1227e860f15SJohn Edward Broadbent 1237e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") 124ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1257e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 12645ca1b86SEd Tanous [&app](const crow::Request& req, 1277e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1283ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 12945ca1b86SEd Tanous { 13045ca1b86SEd Tanous return; 13145ca1b86SEd Tanous } 1322a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Post Manager Reset."; 1332a5c4407SGunnar Mills 1342a5c4407SGunnar Mills std::string resetType; 1352a5c4407SGunnar Mills 13615ed6780SWilly Tu if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 1377e860f15SJohn Edward Broadbent resetType)) 1382a5c4407SGunnar Mills { 1392a5c4407SGunnar Mills return; 1402a5c4407SGunnar Mills } 1412a5c4407SGunnar Mills 142f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart") 143f92af389SJayaprakash Mutyala { 144f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 145f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp); 146f92af389SJayaprakash Mutyala return; 147f92af389SJayaprakash Mutyala } 1483174e4dfSEd Tanous if (resetType == "ForceRestart") 149f92af389SJayaprakash Mutyala { 150f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 151f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp); 152f92af389SJayaprakash Mutyala return; 153f92af389SJayaprakash Mutyala } 1542a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 1552a5c4407SGunnar Mills << resetType; 1562a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType, 1572a5c4407SGunnar Mills "ResetType"); 1582a5c4407SGunnar Mills 1592a5c4407SGunnar Mills return; 1607e860f15SJohn Edward Broadbent }); 1612a5c4407SGunnar Mills } 162ed5befbdSJennifer Lee 1633e40fc74SGunnar Mills /** 1643e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset 1653e40fc74SGunnar Mills * action. 1663e40fc74SGunnar Mills */ 1677e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app) 1683e40fc74SGunnar Mills { 1693e40fc74SGunnar Mills /** 1703e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request. 1713e40fc74SGunnar Mills * 1723e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling 1733e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot. 1743e40fc74SGunnar Mills * 1753e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write 1763e40fc74SGunnar Mills * filesystem which includes things like the network settings. 1773e40fc74SGunnar Mills * 1783e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll". 1793e40fc74SGunnar Mills */ 1807e860f15SJohn Edward Broadbent 1817e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 1827e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/") 183ed398213SEd Tanous .privileges(redfish::privileges::postManager) 1847e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 18545ca1b86SEd Tanous [&app](const crow::Request& req, 1867e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1873ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 18845ca1b86SEd Tanous { 18945ca1b86SEd Tanous return; 19045ca1b86SEd Tanous } 1913e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Post ResetToDefaults."; 1923e40fc74SGunnar Mills 1933e40fc74SGunnar Mills std::string resetType; 1943e40fc74SGunnar Mills 195002d39b4SEd Tanous if (!json_util::readJsonAction(req, asyncResp->res, 196002d39b4SEd Tanous "ResetToDefaultsType", resetType)) 1973e40fc74SGunnar Mills { 1983e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType."; 1993e40fc74SGunnar Mills 200002d39b4SEd Tanous messages::actionParameterMissing(asyncResp->res, "ResetToDefaults", 2013e40fc74SGunnar Mills "ResetToDefaultsType"); 2023e40fc74SGunnar Mills return; 2033e40fc74SGunnar Mills } 2043e40fc74SGunnar Mills 2053e40fc74SGunnar Mills if (resetType != "ResetAll") 2063e40fc74SGunnar Mills { 2070fda0f12SGeorge Liu BMCWEB_LOG_DEBUG 2080fda0f12SGeorge Liu << "Invalid property value for ResetToDefaultsType: " 2093e40fc74SGunnar Mills << resetType; 210002d39b4SEd Tanous messages::actionParameterNotSupported(asyncResp->res, resetType, 211002d39b4SEd Tanous "ResetToDefaultsType"); 2123e40fc74SGunnar Mills return; 2133e40fc74SGunnar Mills } 2143e40fc74SGunnar Mills 2153e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 2165e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec) { 2173e40fc74SGunnar Mills if (ec) 2183e40fc74SGunnar Mills { 219002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec; 2203e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2213e40fc74SGunnar Mills return; 2223e40fc74SGunnar Mills } 2233e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2243e40fc74SGunnar Mills // Can't erase what the BMC is running on 2253e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2263e40fc74SGunnar Mills }, 2273e40fc74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 2283e40fc74SGunnar Mills "/xyz/openbmc_project/software", 2293e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2307e860f15SJohn Edward Broadbent }); 2313e40fc74SGunnar Mills } 2323e40fc74SGunnar Mills 2331cb1a9e6SAppaRao Puli /** 2341cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2351cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2361cb1a9e6SAppaRao Puli */ 2377e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2381cb1a9e6SAppaRao Puli { 2391cb1a9e6SAppaRao Puli /** 2401cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2411cb1a9e6SAppaRao Puli */ 2427e860f15SJohn Edward Broadbent 2437e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/") 244ed398213SEd Tanous .privileges(redfish::privileges::getActionInfo) 2457e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 24645ca1b86SEd Tanous [&app](const crow::Request& req, 2477e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2483ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 24945ca1b86SEd Tanous { 25045ca1b86SEd Tanous return; 25145ca1b86SEd Tanous } 2521476687dSEd Tanous 2531476687dSEd Tanous asyncResp->res.jsonValue["@odata.type"] = 2541476687dSEd Tanous "#ActionInfo.v1_1_2.ActionInfo"; 2551476687dSEd Tanous asyncResp->res.jsonValue["@odata.id"] = 2561476687dSEd Tanous "/redfish/v1/Managers/bmc/ResetActionInfo"; 2571476687dSEd Tanous asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 2581476687dSEd Tanous asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 2591476687dSEd Tanous nlohmann::json::object_t parameter; 2601476687dSEd Tanous parameter["Name"] = "ResetType"; 2611476687dSEd Tanous parameter["Required"] = true; 2621476687dSEd Tanous parameter["DataType"] = "String"; 2631476687dSEd Tanous 2641476687dSEd Tanous nlohmann::json::array_t allowableValues; 265ad539545SPatrick Williams allowableValues.emplace_back("GracefulRestart"); 266ad539545SPatrick Williams allowableValues.emplace_back("ForceRestart"); 2671476687dSEd Tanous parameter["AllowableValues"] = std::move(allowableValues); 2681476687dSEd Tanous 2691476687dSEd Tanous nlohmann::json::array_t parameters; 270ad539545SPatrick Williams parameters.emplace_back(std::move(parameter)); 2711476687dSEd Tanous 2721476687dSEd Tanous asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 2737e860f15SJohn Edward Broadbent }); 2741cb1a9e6SAppaRao Puli } 2751cb1a9e6SAppaRao Puli 2765b4aa86bSJames Feist static constexpr const char* objectManagerIface = 2775b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 2785b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 2795b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 2805b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 2815b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 282b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 283b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 28473df0db0SJames Feist static constexpr const char* thermalModeIface = 28573df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 2869c310685SBorawski.Lukasz 2878d1b46d7Szhanghch05 inline void 2888d1b46d7Szhanghch05 asyncPopulatePid(const std::string& connection, const std::string& path, 28973df0db0SJames Feist const std::string& currentProfile, 29073df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 2918d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2925b4aa86bSJames Feist { 2935b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 29473df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 2955e7e2dc5SEd Tanous const boost::system::error_code& ec, 2965b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 2975b4aa86bSJames Feist if (ec) 2985b4aa86bSJames Feist { 2995b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 300f12894f8SJason M. Bills messages::internalError(asyncResp->res); 3015b4aa86bSJames Feist return; 3025b4aa86bSJames Feist } 3035b4aa86bSJames Feist nlohmann::json& configRoot = 3045b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 3055b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 3065b4aa86bSJames Feist fans["@odata.type"] = "#OemManager.FanControllers"; 3070fda0f12SGeorge Liu fans["@odata.id"] = 3080fda0f12SGeorge Liu "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers"; 3095b4aa86bSJames Feist 3105b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 3115b4aa86bSJames Feist pids["@odata.type"] = "#OemManager.PidControllers"; 3125b4aa86bSJames Feist pids["@odata.id"] = 3135b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; 3145b4aa86bSJames Feist 315b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 316b7a08d04SJames Feist stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; 317b7a08d04SJames Feist stepwise["@odata.id"] = 318b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; 319b7a08d04SJames Feist 3205b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 3215b4aa86bSJames Feist zones["@odata.id"] = 3225b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; 3235b4aa86bSJames Feist zones["@odata.type"] = "#OemManager.FanZones"; 324002d39b4SEd Tanous configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; 3255b4aa86bSJames Feist configRoot["@odata.type"] = "#OemManager.Fan"; 32673df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 32773df0db0SJames Feist 32873df0db0SJames Feist if (!currentProfile.empty()) 32973df0db0SJames Feist { 33073df0db0SJames Feist configRoot["Profile"] = currentProfile; 33173df0db0SJames Feist } 33273df0db0SJames Feist BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !"; 3335b4aa86bSJames Feist 3345b4aa86bSJames Feist for (const auto& pathPair : managedObj) 3355b4aa86bSJames Feist { 3365b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 3375b4aa86bSJames Feist { 3385b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 339b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 340b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 3415b4aa86bSJames Feist { 3425b4aa86bSJames Feist continue; 3435b4aa86bSJames Feist } 34473df0db0SJames Feist 345711ac7a9SEd Tanous std::string name; 346711ac7a9SEd Tanous 347711ac7a9SEd Tanous for (const std::pair<std::string, 348002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 349002d39b4SEd Tanous intfPair.second) 350711ac7a9SEd Tanous { 351711ac7a9SEd Tanous if (propPair.first == "Name") 352711ac7a9SEd Tanous { 3535b4aa86bSJames Feist const std::string* namePtr = 354711ac7a9SEd Tanous std::get_if<std::string>(&propPair.second); 3555b4aa86bSJames Feist if (namePtr == nullptr) 3565b4aa86bSJames Feist { 3575b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Name Field illegal"; 358b7a08d04SJames Feist messages::internalError(asyncResp->res); 3595b4aa86bSJames Feist return; 3605b4aa86bSJames Feist } 361db697703SWilly Tu name = *namePtr; 3625b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 363711ac7a9SEd Tanous } 364711ac7a9SEd Tanous else if (propPair.first == "Profiles") 36573df0db0SJames Feist { 36673df0db0SJames Feist const std::vector<std::string>* profiles = 36773df0db0SJames Feist std::get_if<std::vector<std::string>>( 368711ac7a9SEd Tanous &propPair.second); 36973df0db0SJames Feist if (profiles == nullptr) 37073df0db0SJames Feist { 371002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Pid Profiles Field illegal"; 37273df0db0SJames Feist messages::internalError(asyncResp->res); 37373df0db0SJames Feist return; 37473df0db0SJames Feist } 37573df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 37673df0db0SJames Feist currentProfile) == profiles->end()) 37773df0db0SJames Feist { 37873df0db0SJames Feist BMCWEB_LOG_INFO 379002d39b4SEd Tanous << name << " not supported in current profile"; 38073df0db0SJames Feist continue; 38173df0db0SJames Feist } 38273df0db0SJames Feist } 383711ac7a9SEd Tanous } 384b7a08d04SJames Feist nlohmann::json* config = nullptr; 385c33a90ecSJames Feist const std::string* classPtr = nullptr; 386711ac7a9SEd Tanous 387711ac7a9SEd Tanous for (const std::pair<std::string, 388002d39b4SEd Tanous dbus::utility::DbusVariantType>& propPair : 389002d39b4SEd Tanous intfPair.second) 390c33a90ecSJames Feist { 391727dc83fSLei YU if (propPair.first == "Class") 392711ac7a9SEd Tanous { 393002d39b4SEd Tanous classPtr = std::get_if<std::string>(&propPair.second); 394711ac7a9SEd Tanous } 395c33a90ecSJames Feist } 396c33a90ecSJames Feist 397ef4c65b7SEd Tanous boost::urls::url url("/redfish/v1/Managers/bmc"); 3985b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 3995b4aa86bSJames Feist { 4005b4aa86bSJames Feist std::string chassis; 401002d39b4SEd Tanous if (!dbus::utility::getNthStringFromPath(pathPair.first.str, 402002d39b4SEd Tanous 5, chassis)) 4035b4aa86bSJames Feist { 4045b4aa86bSJames Feist chassis = "#IllegalValue"; 4055b4aa86bSJames Feist } 4065b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 407ef4c65b7SEd Tanous zone["Chassis"]["@odata.id"] = 408ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis); 409eddfc437SWilly Tu url.set_fragment( 410eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name) 411eddfc437SWilly Tu .to_string()); 412eddfc437SWilly Tu zone["@odata.id"] = std::move(url); 4135b4aa86bSJames Feist zone["@odata.type"] = "#OemManager.FanZone"; 414b7a08d04SJames Feist config = &zone; 4155b4aa86bSJames Feist } 4165b4aa86bSJames Feist 417b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 4185b4aa86bSJames Feist { 419c33a90ecSJames Feist if (classPtr == nullptr) 420c33a90ecSJames Feist { 421c33a90ecSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 422c33a90ecSJames Feist messages::internalError(asyncResp->res); 423c33a90ecSJames Feist return; 424c33a90ecSJames Feist } 425c33a90ecSJames Feist 426b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 427b7a08d04SJames Feist config = &controller; 428eddfc437SWilly Tu url.set_fragment( 429eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/StepwiseControllers"_json_pointer / 430eddfc437SWilly Tu name) 431eddfc437SWilly Tu .to_string()); 432eddfc437SWilly Tu controller["@odata.id"] = std::move(url); 433b7a08d04SJames Feist controller["@odata.type"] = 434b7a08d04SJames Feist "#OemManager.StepwiseController"; 435b7a08d04SJames Feist 436c33a90ecSJames Feist controller["Direction"] = *classPtr; 4375b4aa86bSJames Feist } 4385b4aa86bSJames Feist 4395b4aa86bSJames Feist // pid and fans are off the same configuration 440b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 4415b4aa86bSJames Feist { 4425b4aa86bSJames Feist if (classPtr == nullptr) 4435b4aa86bSJames Feist { 4445b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 445a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 4465b4aa86bSJames Feist return; 4475b4aa86bSJames Feist } 4485b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 449002d39b4SEd Tanous nlohmann::json& element = isFan ? fans[name] : pids[name]; 450b7a08d04SJames Feist config = &element; 4515b4aa86bSJames Feist if (isFan) 4525b4aa86bSJames Feist { 453eddfc437SWilly Tu url.set_fragment( 454eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanControllers"_json_pointer / 455eddfc437SWilly Tu name) 456eddfc437SWilly Tu .to_string()); 457eddfc437SWilly Tu element["@odata.id"] = std::move(url); 458002d39b4SEd Tanous element["@odata.type"] = "#OemManager.FanController"; 4595b4aa86bSJames Feist } 4605b4aa86bSJames Feist else 4615b4aa86bSJames Feist { 462eddfc437SWilly Tu url.set_fragment( 463eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/PidControllers"_json_pointer / 464eddfc437SWilly Tu name) 465eddfc437SWilly Tu .to_string()); 466eddfc437SWilly Tu element["@odata.id"] = std::move(url); 467002d39b4SEd Tanous element["@odata.type"] = "#OemManager.PidController"; 4685b4aa86bSJames Feist } 469b7a08d04SJames Feist } 470b7a08d04SJames Feist else 471b7a08d04SJames Feist { 472b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Unexpected configuration"; 473b7a08d04SJames Feist messages::internalError(asyncResp->res); 474b7a08d04SJames Feist return; 475b7a08d04SJames Feist } 476b7a08d04SJames Feist 477b7a08d04SJames Feist // used for making maps out of 2 vectors 478b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 479b7a08d04SJames Feist const std::vector<double>* values = nullptr; 480b7a08d04SJames Feist 481b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 482b7a08d04SJames Feist { 483b7a08d04SJames Feist if (propertyPair.first == "Type" || 484b7a08d04SJames Feist propertyPair.first == "Class" || 485b7a08d04SJames Feist propertyPair.first == "Name") 486b7a08d04SJames Feist { 487b7a08d04SJames Feist continue; 488b7a08d04SJames Feist } 489b7a08d04SJames Feist 490b7a08d04SJames Feist // zones 491b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 492b7a08d04SJames Feist { 493b7a08d04SJames Feist const double* ptr = 494abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 495b7a08d04SJames Feist if (ptr == nullptr) 496b7a08d04SJames Feist { 497b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 498b7a08d04SJames Feist << propertyPair.first; 499b7a08d04SJames Feist messages::internalError(asyncResp->res); 500b7a08d04SJames Feist return; 501b7a08d04SJames Feist } 502b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 503b7a08d04SJames Feist } 504b7a08d04SJames Feist 505b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 506b7a08d04SJames Feist { 507b7a08d04SJames Feist if (propertyPair.first == "Reading" || 508b7a08d04SJames Feist propertyPair.first == "Output") 509b7a08d04SJames Feist { 510b7a08d04SJames Feist const std::vector<double>* ptr = 511abf2add6SEd Tanous std::get_if<std::vector<double>>( 512b7a08d04SJames Feist &propertyPair.second); 513b7a08d04SJames Feist 514b7a08d04SJames Feist if (ptr == nullptr) 515b7a08d04SJames Feist { 516b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 517b7a08d04SJames Feist << propertyPair.first; 518b7a08d04SJames Feist messages::internalError(asyncResp->res); 519b7a08d04SJames Feist return; 520b7a08d04SJames Feist } 521b7a08d04SJames Feist 522b7a08d04SJames Feist if (propertyPair.first == "Reading") 523b7a08d04SJames Feist { 524b7a08d04SJames Feist keys = ptr; 525b7a08d04SJames Feist } 526b7a08d04SJames Feist else 527b7a08d04SJames Feist { 528b7a08d04SJames Feist values = ptr; 529b7a08d04SJames Feist } 530e662eae8SEd Tanous if (keys != nullptr && values != nullptr) 531b7a08d04SJames Feist { 532b7a08d04SJames Feist if (keys->size() != values->size()) 533b7a08d04SJames Feist { 534b7a08d04SJames Feist BMCWEB_LOG_ERROR 5350fda0f12SGeorge Liu << "Reading and Output size don't match "; 536b7a08d04SJames Feist messages::internalError(asyncResp->res); 537b7a08d04SJames Feist return; 538b7a08d04SJames Feist } 539b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 540b7a08d04SJames Feist steps = nlohmann::json::array(); 541b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 542b7a08d04SJames Feist { 5431476687dSEd Tanous nlohmann::json::object_t step; 5441476687dSEd Tanous step["Target"] = (*keys)[ii]; 5451476687dSEd Tanous step["Output"] = (*values)[ii]; 546b2ba3072SPatrick Williams steps.emplace_back(std::move(step)); 547b7a08d04SJames Feist } 548b7a08d04SJames Feist } 549b7a08d04SJames Feist } 550b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 551b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 552b7a08d04SJames Feist { 553b7a08d04SJames Feist const double* ptr = 554abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 555b7a08d04SJames Feist if (ptr == nullptr) 556b7a08d04SJames Feist { 557b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 558b7a08d04SJames Feist << propertyPair.first; 559b7a08d04SJames Feist messages::internalError(asyncResp->res); 560b7a08d04SJames Feist return; 561b7a08d04SJames Feist } 562b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 563b7a08d04SJames Feist } 564b7a08d04SJames Feist } 565b7a08d04SJames Feist 566b7a08d04SJames Feist // pid and fans are off the same configuration 567b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 568b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 569b7a08d04SJames Feist { 5705b4aa86bSJames Feist if (propertyPair.first == "Zones") 5715b4aa86bSJames Feist { 5725b4aa86bSJames Feist const std::vector<std::string>* inputs = 573abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5741b6b96c5SEd Tanous &propertyPair.second); 5755b4aa86bSJames Feist 5765b4aa86bSJames Feist if (inputs == nullptr) 5775b4aa86bSJames Feist { 578002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Zones Pid Field Illegal"; 579a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 5805b4aa86bSJames Feist return; 5815b4aa86bSJames Feist } 582b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5835b4aa86bSJames Feist data = nlohmann::json::array(); 5845b4aa86bSJames Feist for (std::string itemCopy : *inputs) 5855b4aa86bSJames Feist { 5865b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 5871476687dSEd Tanous nlohmann::json::object_t input; 588ef4c65b7SEd Tanous boost::urls::url managerUrl = boost::urls::format( 589ef4c65b7SEd Tanous "/redfish/v1/Managers/bmc#{}", 590eddfc437SWilly Tu ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / 591eddfc437SWilly Tu itemCopy) 592eddfc437SWilly Tu .to_string()); 593eddfc437SWilly Tu input["@odata.id"] = std::move(managerUrl); 594b2ba3072SPatrick Williams data.emplace_back(std::move(input)); 5955b4aa86bSJames Feist } 5965b4aa86bSJames Feist } 5975b4aa86bSJames Feist // todo(james): may never happen, but this 5985b4aa86bSJames Feist // assumes configuration data referenced in the 5995b4aa86bSJames Feist // PID config is provided by the same daemon, we 6005b4aa86bSJames Feist // could add another loop to cover all cases, 6015b4aa86bSJames Feist // but I'm okay kicking this can down the road a 6025b4aa86bSJames Feist // bit 6035b4aa86bSJames Feist 6045b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 6055b4aa86bSJames Feist propertyPair.first == "Outputs") 6065b4aa86bSJames Feist { 607b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 6085b4aa86bSJames Feist const std::vector<std::string>* inputs = 609abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 6101b6b96c5SEd Tanous &propertyPair.second); 6115b4aa86bSJames Feist 6125b4aa86bSJames Feist if (inputs == nullptr) 6135b4aa86bSJames Feist { 6145b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 6155b4aa86bSJames Feist << propertyPair.first; 616f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6175b4aa86bSJames Feist return; 6185b4aa86bSJames Feist } 6195b4aa86bSJames Feist data = *inputs; 620b943aaefSJames Feist } 621b943aaefSJames Feist else if (propertyPair.first == "SetPointOffset") 622b943aaefSJames Feist { 623b943aaefSJames Feist const std::string* ptr = 624002d39b4SEd Tanous std::get_if<std::string>(&propertyPair.second); 625b943aaefSJames Feist 626b943aaefSJames Feist if (ptr == nullptr) 627b943aaefSJames Feist { 628b943aaefSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 629b943aaefSJames Feist << propertyPair.first; 630b943aaefSJames Feist messages::internalError(asyncResp->res); 631b943aaefSJames Feist return; 632b943aaefSJames Feist } 633b943aaefSJames Feist // translate from dbus to redfish 634b943aaefSJames Feist if (*ptr == "WarningHigh") 635b943aaefSJames Feist { 636b943aaefSJames Feist (*config)["SetPointOffset"] = 637b943aaefSJames Feist "UpperThresholdNonCritical"; 638b943aaefSJames Feist } 639b943aaefSJames Feist else if (*ptr == "WarningLow") 640b943aaefSJames Feist { 641b943aaefSJames Feist (*config)["SetPointOffset"] = 642b943aaefSJames Feist "LowerThresholdNonCritical"; 643b943aaefSJames Feist } 644b943aaefSJames Feist else if (*ptr == "CriticalHigh") 645b943aaefSJames Feist { 646b943aaefSJames Feist (*config)["SetPointOffset"] = 647b943aaefSJames Feist "UpperThresholdCritical"; 648b943aaefSJames Feist } 649b943aaefSJames Feist else if (*ptr == "CriticalLow") 650b943aaefSJames Feist { 651b943aaefSJames Feist (*config)["SetPointOffset"] = 652b943aaefSJames Feist "LowerThresholdCritical"; 653b943aaefSJames Feist } 654b943aaefSJames Feist else 655b943aaefSJames Feist { 656002d39b4SEd Tanous BMCWEB_LOG_ERROR << "Value Illegal " << *ptr; 657b943aaefSJames Feist messages::internalError(asyncResp->res); 658b943aaefSJames Feist return; 659b943aaefSJames Feist } 660b943aaefSJames Feist } 661b943aaefSJames Feist // doubles 662002d39b4SEd Tanous else if (propertyPair.first == "FFGainCoefficient" || 6635b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 6645b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 6655b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 6665b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 667002d39b4SEd Tanous propertyPair.first == "PositiveHysteresis" || 668002d39b4SEd Tanous propertyPair.first == "NegativeHysteresis" || 6695b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 6705b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 6715b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 6727625cb81SJames Feist propertyPair.first == "SetPoint" || 6735b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 6745b4aa86bSJames Feist propertyPair.first == "SlewPos") 6755b4aa86bSJames Feist { 6765b4aa86bSJames Feist const double* ptr = 677abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 6785b4aa86bSJames Feist if (ptr == nullptr) 6795b4aa86bSJames Feist { 6805b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 6815b4aa86bSJames Feist << propertyPair.first; 682f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6835b4aa86bSJames Feist return; 6845b4aa86bSJames Feist } 685b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 6865b4aa86bSJames Feist } 6875b4aa86bSJames Feist } 6885b4aa86bSJames Feist } 6895b4aa86bSJames Feist } 6905b4aa86bSJames Feist } 6915b4aa86bSJames Feist }, 6925b4aa86bSJames Feist connection, path, objectManagerIface, "GetManagedObjects"); 6935b4aa86bSJames Feist } 694ca537928SJennifer Lee 69583ff9ab6SJames Feist enum class CreatePIDRet 69683ff9ab6SJames Feist { 69783ff9ab6SJames Feist fail, 69883ff9ab6SJames Feist del, 69983ff9ab6SJames Feist patch 70083ff9ab6SJames Feist }; 70183ff9ab6SJames Feist 7028d1b46d7Szhanghch05 inline bool 7038d1b46d7Szhanghch05 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response, 7045f2caaefSJames Feist std::vector<nlohmann::json>& config, 7055f2caaefSJames Feist std::vector<std::string>& zones) 7065f2caaefSJames Feist { 707b6baeaa4SJames Feist if (config.empty()) 708b6baeaa4SJames Feist { 709b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Empty Zones"; 7101668ce6dSEd Tanous messages::propertyValueFormatError(response->res, "[]", "Zones"); 711b6baeaa4SJames Feist return false; 712b6baeaa4SJames Feist } 7135f2caaefSJames Feist for (auto& odata : config) 7145f2caaefSJames Feist { 7155f2caaefSJames Feist std::string path; 7165f2caaefSJames Feist if (!redfish::json_util::readJson(odata, response->res, "@odata.id", 7175f2caaefSJames Feist path)) 7185f2caaefSJames Feist { 7195f2caaefSJames Feist return false; 7205f2caaefSJames Feist } 7215f2caaefSJames Feist std::string input; 72261adbda3SJames Feist 72361adbda3SJames Feist // 8 below comes from 72461adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 72561adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 72661adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 7275f2caaefSJames Feist { 7285f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << path; 7295f2caaefSJames Feist BMCWEB_LOG_ERROR << "Illegal Type Zones"; 7305f2caaefSJames Feist messages::propertyValueFormatError(response->res, odata.dump(), 7315f2caaefSJames Feist "Zones"); 7325f2caaefSJames Feist return false; 7335f2caaefSJames Feist } 734a170f275SEd Tanous std::replace(input.begin(), input.end(), '_', ' '); 7355f2caaefSJames Feist zones.emplace_back(std::move(input)); 7365f2caaefSJames Feist } 7375f2caaefSJames Feist return true; 7385f2caaefSJames Feist } 7395f2caaefSJames Feist 740711ac7a9SEd Tanous inline const dbus::utility::ManagedObjectType::value_type* 74173df0db0SJames Feist findChassis(const dbus::utility::ManagedObjectType& managedObj, 742b6baeaa4SJames Feist const std::string& value, std::string& chassis) 743b6baeaa4SJames Feist { 744b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n"; 745b6baeaa4SJames Feist 746a170f275SEd Tanous std::string escaped = value; 7476ce82fabSYaswanth Reddy M std::replace(escaped.begin(), escaped.end(), ' ', '_'); 748b6baeaa4SJames Feist escaped = "/" + escaped; 749002d39b4SEd Tanous auto it = std::find_if(managedObj.begin(), managedObj.end(), 750002d39b4SEd Tanous [&escaped](const auto& obj) { 751b6baeaa4SJames Feist if (boost::algorithm::ends_with(obj.first.str, escaped)) 752b6baeaa4SJames Feist { 753b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n"; 754b6baeaa4SJames Feist return true; 755b6baeaa4SJames Feist } 756b6baeaa4SJames Feist return false; 757b6baeaa4SJames Feist }); 758b6baeaa4SJames Feist 759b6baeaa4SJames Feist if (it == managedObj.end()) 760b6baeaa4SJames Feist { 76173df0db0SJames Feist return nullptr; 762b6baeaa4SJames Feist } 763b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 764b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 76573df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 76673df0db0SJames Feist { 76773df0db0SJames Feist return &(*it); 76873df0db0SJames Feist } 76973df0db0SJames Feist 77073df0db0SJames Feist return nullptr; 771b6baeaa4SJames Feist } 772b6baeaa4SJames Feist 77323a21a1cSEd Tanous inline CreatePIDRet createPidInterface( 7748d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, 775b5a76932SEd Tanous const nlohmann::json::iterator& it, const std::string& path, 77683ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 777b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap& output, std::string& chassis, 778b9d36b47SEd Tanous const std::string& profile) 77983ff9ab6SJames Feist { 7805f2caaefSJames Feist // common deleter 781b6baeaa4SJames Feist if (it.value() == nullptr) 7825f2caaefSJames Feist { 7835f2caaefSJames Feist std::string iface; 7845f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 7855f2caaefSJames Feist { 7865f2caaefSJames Feist iface = pidConfigurationIface; 7875f2caaefSJames Feist } 7885f2caaefSJames Feist else if (type == "FanZones") 7895f2caaefSJames Feist { 7905f2caaefSJames Feist iface = pidZoneConfigurationIface; 7915f2caaefSJames Feist } 7925f2caaefSJames Feist else if (type == "StepwiseControllers") 7935f2caaefSJames Feist { 7945f2caaefSJames Feist iface = stepwiseConfigurationIface; 7955f2caaefSJames Feist } 7965f2caaefSJames Feist else 7975f2caaefSJames Feist { 798a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 7995f2caaefSJames Feist messages::propertyUnknown(response->res, type); 8005f2caaefSJames Feist return CreatePIDRet::fail; 8015f2caaefSJames Feist } 8026ee7f774SJames Feist 8036ee7f774SJames Feist BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n"; 8045f2caaefSJames Feist // delete interface 8055f2caaefSJames Feist crow::connections::systemBus->async_method_call( 8065e7e2dc5SEd Tanous [response, path](const boost::system::error_code& ec) { 8075f2caaefSJames Feist if (ec) 8085f2caaefSJames Feist { 8095f2caaefSJames Feist BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec; 8105f2caaefSJames Feist messages::internalError(response->res); 811b6baeaa4SJames Feist return; 8125f2caaefSJames Feist } 813b6baeaa4SJames Feist messages::success(response->res); 8145f2caaefSJames Feist }, 8155f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 8165f2caaefSJames Feist return CreatePIDRet::del; 8175f2caaefSJames Feist } 8185f2caaefSJames Feist 819711ac7a9SEd Tanous const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr; 820b6baeaa4SJames Feist if (!createNewObject) 821b6baeaa4SJames Feist { 822b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 823b6baeaa4SJames Feist // d-bus 82473df0db0SJames Feist managedItem = findChassis(managedObj, it.key(), chassis); 82573df0db0SJames Feist if (managedItem == nullptr) 826b6baeaa4SJames Feist { 827b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 828ef4c65b7SEd Tanous messages::invalidObject( 829ef4c65b7SEd Tanous response->res, 830ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 831b6baeaa4SJames Feist return CreatePIDRet::fail; 832b6baeaa4SJames Feist } 833b6baeaa4SJames Feist } 834b6baeaa4SJames Feist 83526f6976fSEd Tanous if (!profile.empty() && 83673df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 83773df0db0SJames Feist type == "StepwiseControllers")) 83873df0db0SJames Feist { 83973df0db0SJames Feist if (managedItem == nullptr) 84073df0db0SJames Feist { 841b9d36b47SEd Tanous output.emplace_back("Profiles", std::vector<std::string>{profile}); 84273df0db0SJames Feist } 84373df0db0SJames Feist else 84473df0db0SJames Feist { 84573df0db0SJames Feist std::string interface; 84673df0db0SJames Feist if (type == "StepwiseControllers") 84773df0db0SJames Feist { 84873df0db0SJames Feist interface = stepwiseConfigurationIface; 84973df0db0SJames Feist } 85073df0db0SJames Feist else 85173df0db0SJames Feist { 85273df0db0SJames Feist interface = pidConfigurationIface; 85373df0db0SJames Feist } 854711ac7a9SEd Tanous bool ifaceFound = false; 855711ac7a9SEd Tanous for (const auto& iface : managedItem->second) 856711ac7a9SEd Tanous { 857711ac7a9SEd Tanous if (iface.first == interface) 858711ac7a9SEd Tanous { 859711ac7a9SEd Tanous ifaceFound = true; 860711ac7a9SEd Tanous for (const auto& prop : iface.second) 861711ac7a9SEd Tanous { 862711ac7a9SEd Tanous if (prop.first == "Profiles") 863711ac7a9SEd Tanous { 864711ac7a9SEd Tanous const std::vector<std::string>* curProfiles = 865711ac7a9SEd Tanous std::get_if<std::vector<std::string>>( 866711ac7a9SEd Tanous &(prop.second)); 867711ac7a9SEd Tanous if (curProfiles == nullptr) 868711ac7a9SEd Tanous { 869711ac7a9SEd Tanous BMCWEB_LOG_ERROR 870711ac7a9SEd Tanous << "Illegal profiles in managed object"; 871711ac7a9SEd Tanous messages::internalError(response->res); 872711ac7a9SEd Tanous return CreatePIDRet::fail; 873711ac7a9SEd Tanous } 874711ac7a9SEd Tanous if (std::find(curProfiles->begin(), 875711ac7a9SEd Tanous curProfiles->end(), 876711ac7a9SEd Tanous profile) == curProfiles->end()) 877711ac7a9SEd Tanous { 878711ac7a9SEd Tanous std::vector<std::string> newProfiles = 879711ac7a9SEd Tanous *curProfiles; 880711ac7a9SEd Tanous newProfiles.push_back(profile); 881b9d36b47SEd Tanous output.emplace_back("Profiles", newProfiles); 882711ac7a9SEd Tanous } 883711ac7a9SEd Tanous } 884711ac7a9SEd Tanous } 885711ac7a9SEd Tanous } 886711ac7a9SEd Tanous } 887711ac7a9SEd Tanous 888711ac7a9SEd Tanous if (!ifaceFound) 88973df0db0SJames Feist { 89073df0db0SJames Feist BMCWEB_LOG_ERROR 89173df0db0SJames Feist << "Failed to find interface in managed object"; 89273df0db0SJames Feist messages::internalError(response->res); 89373df0db0SJames Feist return CreatePIDRet::fail; 89473df0db0SJames Feist } 89573df0db0SJames Feist } 89673df0db0SJames Feist } 89773df0db0SJames Feist 89883ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 89983ff9ab6SJames Feist { 90083ff9ab6SJames Feist if (createNewObject) 90183ff9ab6SJames Feist { 902b9d36b47SEd Tanous output.emplace_back("Class", 903b9d36b47SEd Tanous type == "PidControllers" ? "temp" : "fan"); 904b9d36b47SEd Tanous output.emplace_back("Type", "Pid"); 90583ff9ab6SJames Feist } 9065f2caaefSJames Feist 9075f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 9085f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 9095f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 9105f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 911b943aaefSJames Feist std::optional<std::string> setpointOffset; 9125f2caaefSJames Feist if (!redfish::json_util::readJson( 913b6baeaa4SJames Feist it.value(), response->res, "Inputs", inputs, "Outputs", outputs, 9145f2caaefSJames Feist "Zones", zones, "FFGainCoefficient", 9155f2caaefSJames Feist doubles["FFGainCoefficient"], "FFOffCoefficient", 9165f2caaefSJames Feist doubles["FFOffCoefficient"], "ICoefficient", 9175f2caaefSJames Feist doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], 9185f2caaefSJames Feist "ILimitMin", doubles["ILimitMin"], "OutLimitMax", 9195f2caaefSJames Feist doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], 9205f2caaefSJames Feist "PCoefficient", doubles["PCoefficient"], "SetPoint", 921b943aaefSJames Feist doubles["SetPoint"], "SetPointOffset", setpointOffset, 922b943aaefSJames Feist "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"], 923b943aaefSJames Feist "PositiveHysteresis", doubles["PositiveHysteresis"], 924b943aaefSJames Feist "NegativeHysteresis", doubles["NegativeHysteresis"])) 92583ff9ab6SJames Feist { 9265f2caaefSJames Feist return CreatePIDRet::fail; 92783ff9ab6SJames Feist } 9285f2caaefSJames Feist if (zones) 9295f2caaefSJames Feist { 9305f2caaefSJames Feist std::vector<std::string> zonesStr; 9315f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 9325f2caaefSJames Feist { 933a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 9345f2caaefSJames Feist return CreatePIDRet::fail; 9355f2caaefSJames Feist } 936b6baeaa4SJames Feist if (chassis.empty() && 937e662eae8SEd Tanous findChassis(managedObj, zonesStr[0], chassis) == nullptr) 938b6baeaa4SJames Feist { 939b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 940ace85d60SEd Tanous messages::invalidObject( 941ef4c65b7SEd Tanous response->res, 942ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 943b6baeaa4SJames Feist return CreatePIDRet::fail; 944b6baeaa4SJames Feist } 945b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStr)); 9465f2caaefSJames Feist } 947afb9ee06SEd Tanous 948afb9ee06SEd Tanous if (inputs) 9495f2caaefSJames Feist { 950afb9ee06SEd Tanous for (std::string& value : *inputs) 95183ff9ab6SJames Feist { 952a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 95383ff9ab6SJames Feist } 954afb9ee06SEd Tanous output.emplace_back("Inputs", *inputs); 955afb9ee06SEd Tanous } 956afb9ee06SEd Tanous 957afb9ee06SEd Tanous if (outputs) 9585f2caaefSJames Feist { 959afb9ee06SEd Tanous for (std::string& value : *outputs) 9605f2caaefSJames Feist { 961afb9ee06SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 9625f2caaefSJames Feist } 963afb9ee06SEd Tanous output.emplace_back("Outputs", *outputs); 96483ff9ab6SJames Feist } 96583ff9ab6SJames Feist 966b943aaefSJames Feist if (setpointOffset) 967b943aaefSJames Feist { 968b943aaefSJames Feist // translate between redfish and dbus names 969b943aaefSJames Feist if (*setpointOffset == "UpperThresholdNonCritical") 970b943aaefSJames Feist { 971b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningLow"); 972b943aaefSJames Feist } 973b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdNonCritical") 974b943aaefSJames Feist { 975b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "WarningHigh"); 976b943aaefSJames Feist } 977b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdCritical") 978b943aaefSJames Feist { 979b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalLow"); 980b943aaefSJames Feist } 981b943aaefSJames Feist else if (*setpointOffset == "UpperThresholdCritical") 982b943aaefSJames Feist { 983b9d36b47SEd Tanous output.emplace_back("SetPointOffset", "CriticalHigh"); 984b943aaefSJames Feist } 985b943aaefSJames Feist else 986b943aaefSJames Feist { 987b943aaefSJames Feist BMCWEB_LOG_ERROR << "Invalid setpointoffset " 988b943aaefSJames Feist << *setpointOffset; 989ace85d60SEd Tanous messages::propertyValueNotInList(response->res, it.key(), 990ace85d60SEd Tanous "SetPointOffset"); 991b943aaefSJames Feist return CreatePIDRet::fail; 992b943aaefSJames Feist } 993b943aaefSJames Feist } 994b943aaefSJames Feist 99583ff9ab6SJames Feist // doubles 9965f2caaefSJames Feist for (const auto& pairs : doubles) 99783ff9ab6SJames Feist { 9985f2caaefSJames Feist if (!pairs.second) 99983ff9ab6SJames Feist { 10005f2caaefSJames Feist continue; 100183ff9ab6SJames Feist } 10025f2caaefSJames Feist BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second; 1003b9d36b47SEd Tanous output.emplace_back(pairs.first, *pairs.second); 10045f2caaefSJames Feist } 100583ff9ab6SJames Feist } 100683ff9ab6SJames Feist 100783ff9ab6SJames Feist else if (type == "FanZones") 100883ff9ab6SJames Feist { 1009b9d36b47SEd Tanous output.emplace_back("Type", "Pid.Zone"); 101083ff9ab6SJames Feist 10115f2caaefSJames Feist std::optional<nlohmann::json> chassisContainer; 10125f2caaefSJames Feist std::optional<double> failSafePercent; 1013d3ec07f8SJames Feist std::optional<double> minThermalOutput; 1014b6baeaa4SJames Feist if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", 10155f2caaefSJames Feist chassisContainer, "FailSafePercent", 1016d3ec07f8SJames Feist failSafePercent, "MinThermalOutput", 1017d3ec07f8SJames Feist minThermalOutput)) 101883ff9ab6SJames Feist { 101983ff9ab6SJames Feist return CreatePIDRet::fail; 102083ff9ab6SJames Feist } 10215f2caaefSJames Feist 10225f2caaefSJames Feist if (chassisContainer) 102383ff9ab6SJames Feist { 10245f2caaefSJames Feist std::string chassisId; 10255f2caaefSJames Feist if (!redfish::json_util::readJson(*chassisContainer, response->res, 10265f2caaefSJames Feist "@odata.id", chassisId)) 10275f2caaefSJames Feist { 102883ff9ab6SJames Feist return CreatePIDRet::fail; 102983ff9ab6SJames Feist } 103083ff9ab6SJames Feist 1031717794d5SAppaRao Puli // /redfish/v1/chassis/chassis_name/ 10325f2caaefSJames Feist if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) 103383ff9ab6SJames Feist { 10345f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << chassisId; 1035ace85d60SEd Tanous messages::invalidObject( 1036ef4c65b7SEd Tanous response->res, 1037ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId)); 103883ff9ab6SJames Feist return CreatePIDRet::fail; 103983ff9ab6SJames Feist } 104083ff9ab6SJames Feist } 1041d3ec07f8SJames Feist if (minThermalOutput) 104283ff9ab6SJames Feist { 1043b9d36b47SEd Tanous output.emplace_back("MinThermalOutput", *minThermalOutput); 10445f2caaefSJames Feist } 10455f2caaefSJames Feist if (failSafePercent) 104683ff9ab6SJames Feist { 1047b9d36b47SEd Tanous output.emplace_back("FailSafePercent", *failSafePercent); 10485f2caaefSJames Feist } 10495f2caaefSJames Feist } 10505f2caaefSJames Feist else if (type == "StepwiseControllers") 10515f2caaefSJames Feist { 1052b9d36b47SEd Tanous output.emplace_back("Type", "Stepwise"); 10535f2caaefSJames Feist 10545f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 10555f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> steps; 10565f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 10575f2caaefSJames Feist std::optional<double> positiveHysteresis; 10585f2caaefSJames Feist std::optional<double> negativeHysteresis; 1059c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 10605f2caaefSJames Feist if (!redfish::json_util::readJson( 1061b6baeaa4SJames Feist it.value(), response->res, "Zones", zones, "Steps", steps, 1062b6baeaa4SJames Feist "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, 1063c33a90ecSJames Feist "NegativeHysteresis", negativeHysteresis, "Direction", 1064c33a90ecSJames Feist direction)) 10655f2caaefSJames Feist { 106683ff9ab6SJames Feist return CreatePIDRet::fail; 106783ff9ab6SJames Feist } 10685f2caaefSJames Feist 10695f2caaefSJames Feist if (zones) 107083ff9ab6SJames Feist { 1071b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 1072b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 10735f2caaefSJames Feist { 1074a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 107583ff9ab6SJames Feist return CreatePIDRet::fail; 107683ff9ab6SJames Feist } 1077b6baeaa4SJames Feist if (chassis.empty() && 1078e662eae8SEd Tanous findChassis(managedObj, zonesStrs[0], chassis) == nullptr) 1079b6baeaa4SJames Feist { 1080b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 1081ace85d60SEd Tanous messages::invalidObject( 1082ef4c65b7SEd Tanous response->res, 1083ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassis)); 1084b6baeaa4SJames Feist return CreatePIDRet::fail; 1085b6baeaa4SJames Feist } 1086b9d36b47SEd Tanous output.emplace_back("Zones", std::move(zonesStrs)); 10875f2caaefSJames Feist } 10885f2caaefSJames Feist if (steps) 10895f2caaefSJames Feist { 10905f2caaefSJames Feist std::vector<double> readings; 10915f2caaefSJames Feist std::vector<double> outputs; 10925f2caaefSJames Feist for (auto& step : *steps) 10935f2caaefSJames Feist { 1094543f4400SEd Tanous double target = 0.0; 1095543f4400SEd Tanous double out = 0.0; 10965f2caaefSJames Feist 10975f2caaefSJames Feist if (!redfish::json_util::readJson(step, response->res, "Target", 109823a21a1cSEd Tanous target, "Output", out)) 10995f2caaefSJames Feist { 11005f2caaefSJames Feist return CreatePIDRet::fail; 11015f2caaefSJames Feist } 11025f2caaefSJames Feist readings.emplace_back(target); 110323a21a1cSEd Tanous outputs.emplace_back(out); 11045f2caaefSJames Feist } 1105b9d36b47SEd Tanous output.emplace_back("Reading", std::move(readings)); 1106b9d36b47SEd Tanous output.emplace_back("Output", std::move(outputs)); 11075f2caaefSJames Feist } 11085f2caaefSJames Feist if (inputs) 11095f2caaefSJames Feist { 11105f2caaefSJames Feist for (std::string& value : *inputs) 11115f2caaefSJames Feist { 1112a170f275SEd Tanous std::replace(value.begin(), value.end(), '_', ' '); 11135f2caaefSJames Feist } 1114b9d36b47SEd Tanous output.emplace_back("Inputs", std::move(*inputs)); 11155f2caaefSJames Feist } 11165f2caaefSJames Feist if (negativeHysteresis) 11175f2caaefSJames Feist { 1118b9d36b47SEd Tanous output.emplace_back("NegativeHysteresis", *negativeHysteresis); 11195f2caaefSJames Feist } 11205f2caaefSJames Feist if (positiveHysteresis) 11215f2caaefSJames Feist { 1122b9d36b47SEd Tanous output.emplace_back("PositiveHysteresis", *positiveHysteresis); 112383ff9ab6SJames Feist } 1124c33a90ecSJames Feist if (direction) 1125c33a90ecSJames Feist { 1126c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 1127c33a90ecSJames Feist "Ceiling", "Floor"}; 1128c33a90ecSJames Feist if (std::find(allowedDirections.begin(), allowedDirections.end(), 1129c33a90ecSJames Feist *direction) == allowedDirections.end()) 1130c33a90ecSJames Feist { 1131c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 1132c33a90ecSJames Feist *direction); 1133c33a90ecSJames Feist return CreatePIDRet::fail; 1134c33a90ecSJames Feist } 1135b9d36b47SEd Tanous output.emplace_back("Class", *direction); 1136c33a90ecSJames Feist } 113783ff9ab6SJames Feist } 113883ff9ab6SJames Feist else 113983ff9ab6SJames Feist { 1140a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 114135a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 114283ff9ab6SJames Feist return CreatePIDRet::fail; 114383ff9ab6SJames Feist } 114483ff9ab6SJames Feist return CreatePIDRet::patch; 114583ff9ab6SJames Feist } 114673df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 114773df0db0SJames Feist { 11486936afe4SEd Tanous struct CompletionValues 11496936afe4SEd Tanous { 11506936afe4SEd Tanous std::vector<std::string> supportedProfiles; 11516936afe4SEd Tanous std::string currentProfile; 11526936afe4SEd Tanous dbus::utility::MapperGetSubTreeResponse subtree; 11536936afe4SEd Tanous }; 115483ff9ab6SJames Feist 11554e23a444SEd Tanous explicit GetPIDValues( 11564e23a444SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : 115723a21a1cSEd Tanous asyncResp(asyncRespIn) 115873df0db0SJames Feist 11591214b7e7SGunnar Mills {} 11609c310685SBorawski.Lukasz 116173df0db0SJames Feist void run() 11625b4aa86bSJames Feist { 116373df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 116473df0db0SJames Feist 116573df0db0SJames Feist // get all configurations 1166e99073f5SGeorge Liu constexpr std::array<std::string_view, 4> interfaces = { 1167e99073f5SGeorge Liu pidConfigurationIface, pidZoneConfigurationIface, 1168e99073f5SGeorge Liu objectManagerIface, stepwiseConfigurationIface}; 1169e99073f5SGeorge Liu dbus::utility::getSubTree( 1170e99073f5SGeorge Liu "/", 0, interfaces, 1171b9d36b47SEd Tanous [self]( 1172e99073f5SGeorge Liu const boost::system::error_code& ec, 1173b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 11745b4aa86bSJames Feist if (ec) 11755b4aa86bSJames Feist { 11765b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 117773df0db0SJames Feist messages::internalError(self->asyncResp->res); 117873df0db0SJames Feist return; 117973df0db0SJames Feist } 11806936afe4SEd Tanous self->complete.subtree = subtreeLocal; 1181e99073f5SGeorge Liu }); 118273df0db0SJames Feist 118373df0db0SJames Feist // at the same time get the selected profile 1184e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1185e99073f5SGeorge Liu thermalModeIface}; 1186e99073f5SGeorge Liu dbus::utility::getSubTree( 1187e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1188b9d36b47SEd Tanous [self]( 1189e99073f5SGeorge Liu const boost::system::error_code& ec, 1190b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) { 119123a21a1cSEd Tanous if (ec || subtreeLocal.empty()) 119273df0db0SJames Feist { 119373df0db0SJames Feist return; 119473df0db0SJames Feist } 119523a21a1cSEd Tanous if (subtreeLocal[0].second.size() != 1) 119673df0db0SJames Feist { 119773df0db0SJames Feist // invalid mapper response, should never happen 119873df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error"; 119973df0db0SJames Feist messages::internalError(self->asyncResp->res); 12005b4aa86bSJames Feist return; 12015b4aa86bSJames Feist } 12025b4aa86bSJames Feist 120323a21a1cSEd Tanous const std::string& path = subtreeLocal[0].first; 120423a21a1cSEd Tanous const std::string& owner = subtreeLocal[0].second[0].first; 1205fac6e53bSKrzysztof Grobelny 1206fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1207fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 1208168e20c1SEd Tanous [path, owner, 12095e7e2dc5SEd Tanous self](const boost::system::error_code& ec2, 1210b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& resp) { 121123a21a1cSEd Tanous if (ec2) 121273df0db0SJames Feist { 12130fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1214002d39b4SEd Tanous << "GetPIDValues: Can't get thermalModeIface " << path; 121573df0db0SJames Feist messages::internalError(self->asyncResp->res); 121673df0db0SJames Feist return; 121773df0db0SJames Feist } 1218fac6e53bSKrzysztof Grobelny 1219271584abSEd Tanous const std::string* current = nullptr; 1220271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1221fac6e53bSKrzysztof Grobelny 1222fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1223fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), resp, "Current", current, 1224fac6e53bSKrzysztof Grobelny "Supported", supported); 1225fac6e53bSKrzysztof Grobelny 1226fac6e53bSKrzysztof Grobelny if (!success) 122773df0db0SJames Feist { 1228002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 122973df0db0SJames Feist return; 123073df0db0SJames Feist } 1231fac6e53bSKrzysztof Grobelny 123273df0db0SJames Feist if (current == nullptr || supported == nullptr) 123373df0db0SJames Feist { 12340fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1235002d39b4SEd Tanous << "GetPIDValues: thermal mode iface invalid " << path; 123673df0db0SJames Feist messages::internalError(self->asyncResp->res); 123773df0db0SJames Feist return; 123873df0db0SJames Feist } 12396936afe4SEd Tanous self->complete.currentProfile = *current; 12406936afe4SEd Tanous self->complete.supportedProfiles = *supported; 1241fac6e53bSKrzysztof Grobelny }); 1242e99073f5SGeorge Liu }); 124373df0db0SJames Feist } 124473df0db0SJames Feist 12456936afe4SEd Tanous static void 12466936afe4SEd Tanous processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 12476936afe4SEd Tanous const CompletionValues& completion) 124873df0db0SJames Feist { 124973df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 125073df0db0SJames Feist { 125173df0db0SJames Feist return; 125273df0db0SJames Feist } 12535b4aa86bSJames Feist // create map of <connection, path to objMgr>> 12546936afe4SEd Tanous boost::container::flat_map< 12556936afe4SEd Tanous std::string, std::string, std::less<>, 12566936afe4SEd Tanous std::vector<std::pair<std::string, std::string>>> 12576936afe4SEd Tanous objectMgrPaths; 12586936afe4SEd Tanous boost::container::flat_set<std::string, std::less<>, 12596936afe4SEd Tanous std::vector<std::string>> 12606936afe4SEd Tanous calledConnections; 12616936afe4SEd Tanous for (const auto& pathGroup : completion.subtree) 12625b4aa86bSJames Feist { 12635b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 12645b4aa86bSJames Feist { 12656bce33bcSJames Feist auto findConnection = 12666bce33bcSJames Feist calledConnections.find(connectionGroup.first); 12676bce33bcSJames Feist if (findConnection != calledConnections.end()) 12686bce33bcSJames Feist { 12696bce33bcSJames Feist break; 12706bce33bcSJames Feist } 127173df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 12725b4aa86bSJames Feist { 12735b4aa86bSJames Feist if (interface == objectManagerIface) 12745b4aa86bSJames Feist { 127573df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 12765b4aa86bSJames Feist } 12775b4aa86bSJames Feist // this list is alphabetical, so we 12785b4aa86bSJames Feist // should have found the objMgr by now 12795b4aa86bSJames Feist if (interface == pidConfigurationIface || 1280b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1281b7a08d04SJames Feist interface == stepwiseConfigurationIface) 12825b4aa86bSJames Feist { 12835b4aa86bSJames Feist auto findObjMgr = 12845b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 12855b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 12865b4aa86bSJames Feist { 12875b4aa86bSJames Feist BMCWEB_LOG_DEBUG << connectionGroup.first 12885b4aa86bSJames Feist << "Has no Object Manager"; 12895b4aa86bSJames Feist continue; 12905b4aa86bSJames Feist } 12916bce33bcSJames Feist 12926bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 12936bce33bcSJames Feist 129473df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 12956936afe4SEd Tanous completion.currentProfile, 12966936afe4SEd Tanous completion.supportedProfiles, 129773df0db0SJames Feist asyncResp); 12985b4aa86bSJames Feist break; 12995b4aa86bSJames Feist } 13005b4aa86bSJames Feist } 13015b4aa86bSJames Feist } 13025b4aa86bSJames Feist } 130373df0db0SJames Feist } 130473df0db0SJames Feist 13056936afe4SEd Tanous ~GetPIDValues() 13066936afe4SEd Tanous { 13076936afe4SEd Tanous boost::asio::post(crow::connections::systemBus->get_io_context(), 13086936afe4SEd Tanous std::bind_front(&processingComplete, asyncResp, 13096936afe4SEd Tanous std::move(complete))); 13106936afe4SEd Tanous } 13116936afe4SEd Tanous 1312ecd6a3a2SEd Tanous GetPIDValues(const GetPIDValues&) = delete; 1313ecd6a3a2SEd Tanous GetPIDValues(GetPIDValues&&) = delete; 1314ecd6a3a2SEd Tanous GetPIDValues& operator=(const GetPIDValues&) = delete; 1315ecd6a3a2SEd Tanous GetPIDValues& operator=(GetPIDValues&&) = delete; 1316ecd6a3a2SEd Tanous 13178d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 13186936afe4SEd Tanous CompletionValues complete; 131973df0db0SJames Feist }; 132073df0db0SJames Feist 132173df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 132273df0db0SJames Feist { 13238d1b46d7Szhanghch05 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, 132473df0db0SJames Feist nlohmann::json& data) : 1325271584abSEd Tanous asyncResp(asyncRespIn) 132673df0db0SJames Feist { 132773df0db0SJames Feist std::optional<nlohmann::json> pidControllers; 132873df0db0SJames Feist std::optional<nlohmann::json> fanControllers; 132973df0db0SJames Feist std::optional<nlohmann::json> fanZones; 133073df0db0SJames Feist std::optional<nlohmann::json> stepwiseControllers; 133173df0db0SJames Feist 133273df0db0SJames Feist if (!redfish::json_util::readJson( 133373df0db0SJames Feist data, asyncResp->res, "PidControllers", pidControllers, 133473df0db0SJames Feist "FanControllers", fanControllers, "FanZones", fanZones, 133573df0db0SJames Feist "StepwiseControllers", stepwiseControllers, "Profile", profile)) 133673df0db0SJames Feist { 133773df0db0SJames Feist return; 133873df0db0SJames Feist } 133973df0db0SJames Feist configuration.emplace_back("PidControllers", std::move(pidControllers)); 134073df0db0SJames Feist configuration.emplace_back("FanControllers", std::move(fanControllers)); 134173df0db0SJames Feist configuration.emplace_back("FanZones", std::move(fanZones)); 134273df0db0SJames Feist configuration.emplace_back("StepwiseControllers", 134373df0db0SJames Feist std::move(stepwiseControllers)); 134473df0db0SJames Feist } 1345ecd6a3a2SEd Tanous 1346ecd6a3a2SEd Tanous SetPIDValues(const SetPIDValues&) = delete; 1347ecd6a3a2SEd Tanous SetPIDValues(SetPIDValues&&) = delete; 1348ecd6a3a2SEd Tanous SetPIDValues& operator=(const SetPIDValues&) = delete; 1349ecd6a3a2SEd Tanous SetPIDValues& operator=(SetPIDValues&&) = delete; 1350ecd6a3a2SEd Tanous 135173df0db0SJames Feist void run() 135273df0db0SJames Feist { 135373df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 135473df0db0SJames Feist { 135573df0db0SJames Feist return; 135673df0db0SJames Feist } 135773df0db0SJames Feist 135873df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 135973df0db0SJames Feist 136073df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 136173df0db0SJames Feist // interface gets more traction 136273df0db0SJames Feist crow::connections::systemBus->async_method_call( 13635e7e2dc5SEd Tanous [self](const boost::system::error_code& ec, 1364914e2d5dSEd Tanous const dbus::utility::ManagedObjectType& mObj) { 136573df0db0SJames Feist if (ec) 136673df0db0SJames Feist { 136773df0db0SJames Feist BMCWEB_LOG_ERROR << "Error communicating to Entity Manager"; 136873df0db0SJames Feist messages::internalError(self->asyncResp->res); 136973df0db0SJames Feist return; 137073df0db0SJames Feist } 1371e69d9de2SJames Feist const std::array<const char*, 3> configurations = { 1372e69d9de2SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 1373e69d9de2SJames Feist stepwiseConfigurationIface}; 1374e69d9de2SJames Feist 137514b0b8d5SJames Feist for (const auto& [path, object] : mObj) 1376e69d9de2SJames Feist { 137714b0b8d5SJames Feist for (const auto& [interface, _] : object) 1378e69d9de2SJames Feist { 1379002d39b4SEd Tanous if (std::find(configurations.begin(), configurations.end(), 1380e69d9de2SJames Feist interface) != configurations.end()) 1381e69d9de2SJames Feist { 138214b0b8d5SJames Feist self->objectCount++; 1383e69d9de2SJames Feist break; 1384e69d9de2SJames Feist } 1385e69d9de2SJames Feist } 1386e69d9de2SJames Feist } 1387914e2d5dSEd Tanous self->managedObj = mObj; 138873df0db0SJames Feist }, 1389c106b67aSNan Zhou "xyz.openbmc_project.EntityManager", 1390c106b67aSNan Zhou "/xyz/openbmc_project/inventory", objectManagerIface, 139173df0db0SJames Feist "GetManagedObjects"); 139273df0db0SJames Feist 139373df0db0SJames Feist // at the same time get the profile information 1394e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> thermalModeIfaces = { 1395e99073f5SGeorge Liu thermalModeIface}; 1396e99073f5SGeorge Liu dbus::utility::getSubTree( 1397e99073f5SGeorge Liu "/", 0, thermalModeIfaces, 1398e99073f5SGeorge Liu [self](const boost::system::error_code& ec, 1399b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 140073df0db0SJames Feist if (ec || subtree.empty()) 140173df0db0SJames Feist { 140273df0db0SJames Feist return; 140373df0db0SJames Feist } 140473df0db0SJames Feist if (subtree[0].second.empty()) 140573df0db0SJames Feist { 140673df0db0SJames Feist // invalid mapper response, should never happen 140773df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error"; 140873df0db0SJames Feist messages::internalError(self->asyncResp->res); 140973df0db0SJames Feist return; 141073df0db0SJames Feist } 141173df0db0SJames Feist 141273df0db0SJames Feist const std::string& path = subtree[0].first; 141373df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 1414fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 1415fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, owner, path, thermalModeIface, 14165e7e2dc5SEd Tanous [self, path, owner](const boost::system::error_code& ec2, 1417b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& r) { 1418cb13a392SEd Tanous if (ec2) 141973df0db0SJames Feist { 14200fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1421002d39b4SEd Tanous << "SetPIDValues: Can't get thermalModeIface " << path; 142273df0db0SJames Feist messages::internalError(self->asyncResp->res); 142373df0db0SJames Feist return; 142473df0db0SJames Feist } 1425271584abSEd Tanous const std::string* current = nullptr; 1426271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1427fac6e53bSKrzysztof Grobelny 1428fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 1429fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), r, "Current", current, 1430fac6e53bSKrzysztof Grobelny "Supported", supported); 1431fac6e53bSKrzysztof Grobelny 1432fac6e53bSKrzysztof Grobelny if (!success) 143373df0db0SJames Feist { 1434002d39b4SEd Tanous messages::internalError(self->asyncResp->res); 143573df0db0SJames Feist return; 143673df0db0SJames Feist } 1437fac6e53bSKrzysztof Grobelny 143873df0db0SJames Feist if (current == nullptr || supported == nullptr) 143973df0db0SJames Feist { 14400fda0f12SGeorge Liu BMCWEB_LOG_ERROR 1441002d39b4SEd Tanous << "SetPIDValues: thermal mode iface invalid " << path; 144273df0db0SJames Feist messages::internalError(self->asyncResp->res); 144373df0db0SJames Feist return; 144473df0db0SJames Feist } 144573df0db0SJames Feist self->currentProfile = *current; 144673df0db0SJames Feist self->supportedProfiles = *supported; 144773df0db0SJames Feist self->profileConnection = owner; 144873df0db0SJames Feist self->profilePath = path; 1449fac6e53bSKrzysztof Grobelny }); 1450e99073f5SGeorge Liu }); 145173df0db0SJames Feist } 145224b2fe81SEd Tanous void pidSetDone() 145373df0db0SJames Feist { 145473df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 145573df0db0SJames Feist { 145673df0db0SJames Feist return; 14575b4aa86bSJames Feist } 14588d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; 145973df0db0SJames Feist if (profile) 146073df0db0SJames Feist { 146173df0db0SJames Feist if (std::find(supportedProfiles.begin(), supportedProfiles.end(), 146273df0db0SJames Feist *profile) == supportedProfiles.end()) 146373df0db0SJames Feist { 146473df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 146573df0db0SJames Feist *profile); 146673df0db0SJames Feist return; 146773df0db0SJames Feist } 146873df0db0SJames Feist currentProfile = *profile; 146973df0db0SJames Feist crow::connections::systemBus->async_method_call( 14705e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 147173df0db0SJames Feist if (ec) 147273df0db0SJames Feist { 147373df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching profile" << ec; 147473df0db0SJames Feist messages::internalError(response->res); 147573df0db0SJames Feist } 147673df0db0SJames Feist }, 147773df0db0SJames Feist profileConnection, profilePath, 147873df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", thermalModeIface, 1479168e20c1SEd Tanous "Current", dbus::utility::DbusVariantType(*profile)); 148073df0db0SJames Feist } 148173df0db0SJames Feist 148273df0db0SJames Feist for (auto& containerPair : configuration) 148373df0db0SJames Feist { 148473df0db0SJames Feist auto& container = containerPair.second; 148573df0db0SJames Feist if (!container) 148673df0db0SJames Feist { 148773df0db0SJames Feist continue; 148873df0db0SJames Feist } 14896ee7f774SJames Feist BMCWEB_LOG_DEBUG << *container; 14906ee7f774SJames Feist 149102cad96eSEd Tanous const std::string& type = containerPair.first; 149273df0db0SJames Feist 149373df0db0SJames Feist for (nlohmann::json::iterator it = container->begin(); 149417a897dfSManojkiran Eda it != container->end(); ++it) 149573df0db0SJames Feist { 149673df0db0SJames Feist const auto& name = it.key(); 1497cddbf3dfSPotin Lai std::string dbusObjName = name; 1498cddbf3dfSPotin Lai std::replace(dbusObjName.begin(), dbusObjName.end(), ' ', '_'); 14996ee7f774SJames Feist BMCWEB_LOG_DEBUG << "looking for " << name; 15006ee7f774SJames Feist 150189492a15SPatrick Williams auto pathItr = std::find_if(managedObj.begin(), 150289492a15SPatrick Williams managedObj.end(), 1503cddbf3dfSPotin Lai [&dbusObjName](const auto& obj) { 1504002d39b4SEd Tanous return boost::algorithm::ends_with(obj.first.str, 1505cddbf3dfSPotin Lai "/" + dbusObjName); 150673df0db0SJames Feist }); 1507b9d36b47SEd Tanous dbus::utility::DBusPropertiesMap output; 150873df0db0SJames Feist 150973df0db0SJames Feist output.reserve(16); // The pid interface length 151073df0db0SJames Feist 151173df0db0SJames Feist // determines if we're patching entity-manager or 151273df0db0SJames Feist // creating a new object 151373df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 15146ee7f774SJames Feist BMCWEB_LOG_DEBUG << "Found = " << !createNewObject; 15156ee7f774SJames Feist 151673df0db0SJames Feist std::string iface; 1517ea2b670dSEd Tanous if (!createNewObject) 1518ea2b670dSEd Tanous { 15198be2b5b6SPotin Lai bool findInterface = false; 1520ea2b670dSEd Tanous for (const auto& interface : pathItr->second) 1521ea2b670dSEd Tanous { 1522ea2b670dSEd Tanous if (interface.first == pidConfigurationIface) 1523ea2b670dSEd Tanous { 1524ea2b670dSEd Tanous if (type == "PidControllers" || 1525ea2b670dSEd Tanous type == "FanControllers") 152673df0db0SJames Feist { 152773df0db0SJames Feist iface = pidConfigurationIface; 15288be2b5b6SPotin Lai findInterface = true; 15298be2b5b6SPotin Lai break; 153073df0db0SJames Feist } 153173df0db0SJames Feist } 1532ea2b670dSEd Tanous else if (interface.first == pidZoneConfigurationIface) 153373df0db0SJames Feist { 1534ea2b670dSEd Tanous if (type == "FanZones") 153573df0db0SJames Feist { 1536ea2b670dSEd Tanous iface = pidConfigurationIface; 15378be2b5b6SPotin Lai findInterface = true; 15388be2b5b6SPotin Lai break; 153973df0db0SJames Feist } 154073df0db0SJames Feist } 1541ea2b670dSEd Tanous else if (interface.first == stepwiseConfigurationIface) 1542ea2b670dSEd Tanous { 1543ea2b670dSEd Tanous if (type == "StepwiseControllers") 154473df0db0SJames Feist { 154573df0db0SJames Feist iface = stepwiseConfigurationIface; 15468be2b5b6SPotin Lai findInterface = true; 15478be2b5b6SPotin Lai break; 15488be2b5b6SPotin Lai } 15498be2b5b6SPotin Lai } 15508be2b5b6SPotin Lai } 15518be2b5b6SPotin Lai 15528be2b5b6SPotin Lai // create new object if interface not found 15538be2b5b6SPotin Lai if (!findInterface) 15548be2b5b6SPotin Lai { 155573df0db0SJames Feist createNewObject = true; 155673df0db0SJames Feist } 1557ea2b670dSEd Tanous } 15586ee7f774SJames Feist 15596ee7f774SJames Feist if (createNewObject && it.value() == nullptr) 15606ee7f774SJames Feist { 15614e0453b1SGunnar Mills // can't delete a non-existent object 15621668ce6dSEd Tanous messages::propertyValueNotInList(response->res, 15631668ce6dSEd Tanous it.value().dump(), name); 15646ee7f774SJames Feist continue; 15656ee7f774SJames Feist } 15666ee7f774SJames Feist 15676ee7f774SJames Feist std::string path; 15686ee7f774SJames Feist if (pathItr != managedObj.end()) 15696ee7f774SJames Feist { 15706ee7f774SJames Feist path = pathItr->first.str; 15716ee7f774SJames Feist } 15726ee7f774SJames Feist 157373df0db0SJames Feist BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n"; 1574e69d9de2SJames Feist 1575e69d9de2SJames Feist // arbitrary limit to avoid attacks 1576e69d9de2SJames Feist constexpr const size_t controllerLimit = 500; 157714b0b8d5SJames Feist if (createNewObject && objectCount >= controllerLimit) 1578e69d9de2SJames Feist { 1579e69d9de2SJames Feist messages::resourceExhaustion(response->res, type); 1580e69d9de2SJames Feist continue; 1581e69d9de2SJames Feist } 1582a170f275SEd Tanous std::string escaped = name; 1583a170f275SEd Tanous std::replace(escaped.begin(), escaped.end(), '_', ' '); 1584a170f275SEd Tanous output.emplace_back("Name", escaped); 158573df0db0SJames Feist 158673df0db0SJames Feist std::string chassis; 158773df0db0SJames Feist CreatePIDRet ret = createPidInterface( 15886ee7f774SJames Feist response, type, it, path, managedObj, createNewObject, 15896ee7f774SJames Feist output, chassis, currentProfile); 159073df0db0SJames Feist if (ret == CreatePIDRet::fail) 159173df0db0SJames Feist { 159273df0db0SJames Feist return; 159373df0db0SJames Feist } 15943174e4dfSEd Tanous if (ret == CreatePIDRet::del) 159573df0db0SJames Feist { 159673df0db0SJames Feist continue; 159773df0db0SJames Feist } 159873df0db0SJames Feist 159973df0db0SJames Feist if (!createNewObject) 160073df0db0SJames Feist { 160173df0db0SJames Feist for (const auto& property : output) 160273df0db0SJames Feist { 160373df0db0SJames Feist crow::connections::systemBus->async_method_call( 160473df0db0SJames Feist [response, 160573df0db0SJames Feist propertyName{std::string(property.first)}]( 16065e7e2dc5SEd Tanous const boost::system::error_code& ec) { 160773df0db0SJames Feist if (ec) 160873df0db0SJames Feist { 160973df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching " 1610002d39b4SEd Tanous << propertyName << ": " << ec; 161173df0db0SJames Feist messages::internalError(response->res); 161273df0db0SJames Feist return; 161373df0db0SJames Feist } 161473df0db0SJames Feist messages::success(response->res); 161573df0db0SJames Feist }, 16166ee7f774SJames Feist "xyz.openbmc_project.EntityManager", path, 161773df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", iface, 161873df0db0SJames Feist property.first, property.second); 161973df0db0SJames Feist } 162073df0db0SJames Feist } 162173df0db0SJames Feist else 162273df0db0SJames Feist { 162373df0db0SJames Feist if (chassis.empty()) 162473df0db0SJames Feist { 162573df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config"; 1626ace85d60SEd Tanous messages::internalError(response->res); 162773df0db0SJames Feist return; 162873df0db0SJames Feist } 162973df0db0SJames Feist 163073df0db0SJames Feist bool foundChassis = false; 163173df0db0SJames Feist for (const auto& obj : managedObj) 163273df0db0SJames Feist { 163373df0db0SJames Feist if (boost::algorithm::ends_with(obj.first.str, chassis)) 163473df0db0SJames Feist { 163573df0db0SJames Feist chassis = obj.first.str; 163673df0db0SJames Feist foundChassis = true; 163773df0db0SJames Feist break; 163873df0db0SJames Feist } 163973df0db0SJames Feist } 164073df0db0SJames Feist if (!foundChassis) 164173df0db0SJames Feist { 164273df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to find chassis on dbus"; 164373df0db0SJames Feist messages::resourceMissingAtURI( 1644ace85d60SEd Tanous response->res, 1645ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", 1646ef4c65b7SEd Tanous chassis)); 164773df0db0SJames Feist return; 164873df0db0SJames Feist } 164973df0db0SJames Feist 165073df0db0SJames Feist crow::connections::systemBus->async_method_call( 16515e7e2dc5SEd Tanous [response](const boost::system::error_code& ec) { 165273df0db0SJames Feist if (ec) 165373df0db0SJames Feist { 165473df0db0SJames Feist BMCWEB_LOG_ERROR << "Error Adding Pid Object " 165573df0db0SJames Feist << ec; 165673df0db0SJames Feist messages::internalError(response->res); 165773df0db0SJames Feist return; 165873df0db0SJames Feist } 165973df0db0SJames Feist messages::success(response->res); 166073df0db0SJames Feist }, 166173df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 166273df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 166373df0db0SJames Feist } 166473df0db0SJames Feist } 166573df0db0SJames Feist } 166673df0db0SJames Feist } 166724b2fe81SEd Tanous 166824b2fe81SEd Tanous ~SetPIDValues() 166924b2fe81SEd Tanous { 167024b2fe81SEd Tanous try 167124b2fe81SEd Tanous { 167224b2fe81SEd Tanous pidSetDone(); 167324b2fe81SEd Tanous } 167424b2fe81SEd Tanous catch (...) 167524b2fe81SEd Tanous { 167624b2fe81SEd Tanous BMCWEB_LOG_CRITICAL << "pidSetDone threw exception"; 167724b2fe81SEd Tanous } 167824b2fe81SEd Tanous } 167924b2fe81SEd Tanous 16808d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 168173df0db0SJames Feist std::vector<std::pair<std::string, std::optional<nlohmann::json>>> 168273df0db0SJames Feist configuration; 168373df0db0SJames Feist std::optional<std::string> profile; 168473df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 168573df0db0SJames Feist std::vector<std::string> supportedProfiles; 168673df0db0SJames Feist std::string currentProfile; 168773df0db0SJames Feist std::string profileConnection; 168873df0db0SJames Feist std::string profilePath; 168914b0b8d5SJames Feist size_t objectCount = 0; 169073df0db0SJames Feist }; 169173df0db0SJames Feist 1692071d8fdfSSunnySrivastava1984 /** 1693071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 1694071d8fdfSSunnySrivastava1984 * 1695*ac106bf6SEd Tanous * @param[in] asyncResp Shared pointer for completing asynchronous calls 1696071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 1697071d8fdfSSunnySrivastava1984 * @param[in] path - object path 1698071d8fdfSSunnySrivastava1984 * @return none 1699071d8fdfSSunnySrivastava1984 */ 1700*ac106bf6SEd Tanous inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1701071d8fdfSSunnySrivastava1984 const std::string& connectionName, 1702071d8fdfSSunnySrivastava1984 const std::string& path) 1703071d8fdfSSunnySrivastava1984 { 1704071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Get BMC manager Location data."; 1705071d8fdfSSunnySrivastava1984 17061e1e598dSJonathan Doman sdbusplus::asio::getProperty<std::string>( 17071e1e598dSJonathan Doman *crow::connections::systemBus, connectionName, path, 17081e1e598dSJonathan Doman "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 1709*ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 17101e1e598dSJonathan Doman const std::string& property) { 1711071d8fdfSSunnySrivastava1984 if (ec) 1712071d8fdfSSunnySrivastava1984 { 1713071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "DBUS response error for " 1714071d8fdfSSunnySrivastava1984 "Location"; 1715*ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1716071d8fdfSSunnySrivastava1984 return; 1717071d8fdfSSunnySrivastava1984 } 1718071d8fdfSSunnySrivastava1984 1719*ac106bf6SEd Tanous asyncResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 17201e1e598dSJonathan Doman property; 17211e1e598dSJonathan Doman }); 1722071d8fdfSSunnySrivastava1984 } 17237e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 17247e860f15SJohn Edward Broadbent inline void 1725*ac106bf6SEd Tanous managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 17264bf2b033SGunnar Mills { 17274bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time"; 17284bf2b033SGunnar Mills 17291e1e598dSJonathan Doman sdbusplus::asio::getProperty<uint64_t>( 17301e1e598dSJonathan Doman *crow::connections::systemBus, "xyz.openbmc_project.State.BMC", 17311e1e598dSJonathan Doman "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC", 17321e1e598dSJonathan Doman "LastRebootTime", 1733*ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec, 17341e1e598dSJonathan Doman const uint64_t lastResetTime) { 17354bf2b033SGunnar Mills if (ec) 17364bf2b033SGunnar Mills { 17374bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 17384bf2b033SGunnar Mills return; 17394bf2b033SGunnar Mills } 17404bf2b033SGunnar Mills 17414bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 17424bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 17431e1e598dSJonathan Doman uint64_t lastResetTimeStamp = lastResetTime / 1000; 17444bf2b033SGunnar Mills 17454bf2b033SGunnar Mills // Convert to ISO 8601 standard 1746*ac106bf6SEd Tanous asyncResp->res.jsonValue["LastResetTime"] = 17472b82937eSEd Tanous redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 17481e1e598dSJonathan Doman }); 17494bf2b033SGunnar Mills } 17504bf2b033SGunnar Mills 17514bfefa74SGunnar Mills /** 17524bfefa74SGunnar Mills * @brief Set the running firmware image 17534bfefa74SGunnar Mills * 1754*ac106bf6SEd Tanous * @param[i,o] asyncResp - Async response object 17554bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 17564bfefa74SGunnar Mills * 17574bfefa74SGunnar Mills * @return void 17584bfefa74SGunnar Mills */ 17597e860f15SJohn Edward Broadbent inline void 1760*ac106bf6SEd Tanous setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 1761f23b7296SEd Tanous const std::string& runningFirmwareTarget) 17624bfefa74SGunnar Mills { 17634bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 1764f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 17654bfefa74SGunnar Mills if (idPos == std::string::npos) 17664bfefa74SGunnar Mills { 1767*ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 17684bfefa74SGunnar Mills "@odata.id"); 17694bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't parse firmware ID!"; 17704bfefa74SGunnar Mills return; 17714bfefa74SGunnar Mills } 17724bfefa74SGunnar Mills idPos++; 17734bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 17744bfefa74SGunnar Mills { 1775*ac106bf6SEd Tanous messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 17764bfefa74SGunnar Mills "@odata.id"); 17774bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 17784bfefa74SGunnar Mills return; 17794bfefa74SGunnar Mills } 17804bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 17814bfefa74SGunnar Mills 17824bfefa74SGunnar Mills // Make sure the image is valid before setting priority 17834bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 1784*ac106bf6SEd Tanous [asyncResp, firmwareId, 17855e7e2dc5SEd Tanous runningFirmwareTarget](const boost::system::error_code& ec, 1786711ac7a9SEd Tanous dbus::utility::ManagedObjectType& subtree) { 17874bfefa74SGunnar Mills if (ec) 17884bfefa74SGunnar Mills { 17894bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error getting objects."; 1790*ac106bf6SEd Tanous messages::internalError(asyncResp->res); 17914bfefa74SGunnar Mills return; 17924bfefa74SGunnar Mills } 17934bfefa74SGunnar Mills 179426f6976fSEd Tanous if (subtree.empty()) 17954bfefa74SGunnar Mills { 17964bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't find image!"; 1797*ac106bf6SEd Tanous messages::internalError(asyncResp->res); 17984bfefa74SGunnar Mills return; 17994bfefa74SGunnar Mills } 18004bfefa74SGunnar Mills 18014bfefa74SGunnar Mills bool foundImage = false; 180202cad96eSEd Tanous for (const auto& object : subtree) 18034bfefa74SGunnar Mills { 18044bfefa74SGunnar Mills const std::string& path = 18054bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 1806f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 18074bfefa74SGunnar Mills 18084bfefa74SGunnar Mills if (idPos2 == std::string::npos) 18094bfefa74SGunnar Mills { 18104bfefa74SGunnar Mills continue; 18114bfefa74SGunnar Mills } 18124bfefa74SGunnar Mills 18134bfefa74SGunnar Mills idPos2++; 18144bfefa74SGunnar Mills if (idPos2 >= path.size()) 18154bfefa74SGunnar Mills { 18164bfefa74SGunnar Mills continue; 18174bfefa74SGunnar Mills } 18184bfefa74SGunnar Mills 18194bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 18204bfefa74SGunnar Mills { 18214bfefa74SGunnar Mills foundImage = true; 18224bfefa74SGunnar Mills break; 18234bfefa74SGunnar Mills } 18244bfefa74SGunnar Mills } 18254bfefa74SGunnar Mills 18264bfefa74SGunnar Mills if (!foundImage) 18274bfefa74SGunnar Mills { 1828*ac106bf6SEd Tanous messages::propertyValueNotInList( 1829*ac106bf6SEd Tanous asyncResp->res, runningFirmwareTarget, "@odata.id"); 18304bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 18314bfefa74SGunnar Mills return; 18324bfefa74SGunnar Mills } 18334bfefa74SGunnar Mills 18348cc8edecSEd Tanous BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId 18358cc8edecSEd Tanous << " to priority 0."; 18364bfefa74SGunnar Mills 18374bfefa74SGunnar Mills // Only support Immediate 18384bfefa74SGunnar Mills // An addition could be a Redfish Setting like 18394bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 18404bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 1841*ac106bf6SEd Tanous [asyncResp](const boost::system::error_code& ec2) { 18428a592810SEd Tanous if (ec2) 18434bfefa74SGunnar Mills { 18444bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error setting."; 1845*ac106bf6SEd Tanous messages::internalError(asyncResp->res); 18464bfefa74SGunnar Mills return; 18474bfefa74SGunnar Mills } 1848*ac106bf6SEd Tanous doBMCGracefulRestart(asyncResp); 18494bfefa74SGunnar Mills }, 18504bfefa74SGunnar Mills 18514bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18524bfefa74SGunnar Mills "/xyz/openbmc_project/software/" + firmwareId, 18534bfefa74SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 18547e860f15SJohn Edward Broadbent "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 1855168e20c1SEd Tanous dbus::utility::DbusVariantType(static_cast<uint8_t>(0))); 18564bfefa74SGunnar Mills }, 18574bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18587e860f15SJohn Edward Broadbent "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager", 18597e860f15SJohn Edward Broadbent "GetManagedObjects"); 18604bfefa74SGunnar Mills } 18614bfefa74SGunnar Mills 1862*ac106bf6SEd Tanous inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> asyncResp, 18637e860f15SJohn Edward Broadbent std::string datetime) 1864af5d6058SSantosh Puranik { 1865af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Set date time: " << datetime; 1866af5d6058SSantosh Puranik 1867c2e32007SEd Tanous std::optional<redfish::time_utils::usSinceEpoch> us = 1868c2e32007SEd Tanous redfish::time_utils::dateStringToEpoch(datetime); 1869c2e32007SEd Tanous if (!us) 1870af5d6058SSantosh Puranik { 1871*ac106bf6SEd Tanous messages::propertyValueFormatError(asyncResp->res, datetime, 1872*ac106bf6SEd Tanous "DateTime"); 1873c2e32007SEd Tanous return; 1874c2e32007SEd Tanous } 1875af5d6058SSantosh Puranik crow::connections::systemBus->async_method_call( 1876*ac106bf6SEd Tanous [asyncResp{std::move(asyncResp)}, 18775e7e2dc5SEd Tanous datetime{std::move(datetime)}](const boost::system::error_code& ec) { 1878af5d6058SSantosh Puranik if (ec) 1879af5d6058SSantosh Puranik { 1880af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Failed to set elapsed time. " 1881af5d6058SSantosh Puranik "DBUS response error " 1882af5d6058SSantosh Puranik << ec; 1883*ac106bf6SEd Tanous messages::internalError(asyncResp->res); 1884af5d6058SSantosh Puranik return; 1885af5d6058SSantosh Puranik } 1886*ac106bf6SEd Tanous asyncResp->res.jsonValue["DateTime"] = datetime; 1887af5d6058SSantosh Puranik }, 18887e860f15SJohn Edward Broadbent "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc", 1889af5d6058SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1890af5d6058SSantosh Puranik "xyz.openbmc_project.Time.EpochTime", "Elapsed", 1891c2e32007SEd Tanous dbus::utility::DbusVariantType(us->count())); 189283ff9ab6SJames Feist } 18939c310685SBorawski.Lukasz 189475815e5cSEd Tanous inline void 189575815e5cSEd Tanous checkForQuiesced(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 189675815e5cSEd Tanous { 189775815e5cSEd Tanous sdbusplus::asio::getProperty<std::string>( 189875815e5cSEd Tanous *crow::connections::systemBus, "org.freedesktop.systemd1", 189975815e5cSEd Tanous "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", 190075815e5cSEd Tanous "org.freedesktop.systemd1.Unit", "ActiveState", 190175815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, 190275815e5cSEd Tanous const std::string& val) { 190375815e5cSEd Tanous if (!ec) 190475815e5cSEd Tanous { 190575815e5cSEd Tanous if (val == "active") 190675815e5cSEd Tanous { 190775815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "Critical"; 190875815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Quiesced"; 190975815e5cSEd Tanous return; 191075815e5cSEd Tanous } 191175815e5cSEd Tanous } 191275815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 191375815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Enabled"; 191475815e5cSEd Tanous }); 191575815e5cSEd Tanous } 191675815e5cSEd Tanous 19177e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 19187e860f15SJohn Edward Broadbent { 19197e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 19209c310685SBorawski.Lukasz 19217e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 1922ed398213SEd Tanous .privileges(redfish::privileges::getManager) 1923002d39b4SEd Tanous .methods(boost::beast::http::verb::get)( 1924002d39b4SEd Tanous [&app, uuid](const crow::Request& req, 192545ca1b86SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 19263ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 192745ca1b86SEd Tanous { 192845ca1b86SEd Tanous return; 192945ca1b86SEd Tanous } 19307e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; 1931a51fc2d2SSui Chen asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager"; 19327e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "bmc"; 19337e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 19347e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 19357e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 19367e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["PowerState"] = "On"; 19371476687dSEd Tanous 19387e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ManagerType"] = "BMC"; 19397e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 19407e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 1941002d39b4SEd Tanous asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model 19427e860f15SJohn Edward Broadbent 19431476687dSEd Tanous asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 19441476687dSEd Tanous "/redfish/v1/Managers/bmc/LogServices"; 19451476687dSEd Tanous asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 19461476687dSEd Tanous "/redfish/v1/Managers/bmc/NetworkProtocol"; 19471476687dSEd Tanous asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 19481476687dSEd Tanous "/redfish/v1/Managers/bmc/EthernetInterfaces"; 19497e860f15SJohn Edward Broadbent 19507e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_VM_NBDPROXY 19511476687dSEd Tanous asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 19521476687dSEd Tanous "/redfish/v1/Managers/bmc/VirtualMedia"; 19537e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_VM_NBDPROXY 19547e860f15SJohn Edward Broadbent 19557e860f15SJohn Edward Broadbent // default oem data 19567e860f15SJohn Edward Broadbent nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; 19577e860f15SJohn Edward Broadbent nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 19587e860f15SJohn Edward Broadbent oem["@odata.type"] = "#OemManager.Oem"; 19597e860f15SJohn Edward Broadbent oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; 19607e860f15SJohn Edward Broadbent oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; 19617e860f15SJohn Edward Broadbent oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; 19621476687dSEd Tanous 19631476687dSEd Tanous nlohmann::json::object_t certificates; 19641476687dSEd Tanous certificates["@odata.id"] = 19651476687dSEd Tanous "/redfish/v1/Managers/bmc/Truststore/Certificates"; 19661476687dSEd Tanous oemOpenbmc["Certificates"] = std::move(certificates); 19677e860f15SJohn Edward Broadbent 19687e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 19697e860f15SJohn Edward Broadbent // supports BMC reboot. 19707e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 19717e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 19727e860f15SJohn Edward Broadbent managerReset["target"] = 19737e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; 19747e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 19757e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/ResetActionInfo"; 19767e860f15SJohn Edward Broadbent 19777e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 19787e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 19797e860f15SJohn Edward Broadbent // on OpenBMC 19807e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 19817e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 19827e860f15SJohn Edward Broadbent resetToDefaults["target"] = 19837e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults"; 1984613dabeaSEd Tanous resetToDefaults["ResetType@Redfish.AllowableValues"] = 1985613dabeaSEd Tanous nlohmann::json::array_t({"ResetAll"}); 19867e860f15SJohn Edward Broadbent 19877c8c4058STejas Patil std::pair<std::string, std::string> redfishDateTimeOffset = 19882b82937eSEd Tanous redfish::time_utils::getDateTimeOffsetNow(); 19897c8c4058STejas Patil 19907c8c4058STejas Patil asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 19917c8c4058STejas Patil asyncResp->res.jsonValue["DateTimeLocalOffset"] = 19927c8c4058STejas Patil redfishDateTimeOffset.second; 19937e860f15SJohn Edward Broadbent 19940e8ac5e7SGunnar Mills // TODO (Gunnar): Remove these one day since moved to ComputerSystem 19950e8ac5e7SGunnar Mills // Still used by OCP profiles 19960e8ac5e7SGunnar Mills // https://github.com/opencomputeproject/OCP-Profiles/issues/23 19977e860f15SJohn Edward Broadbent // Fill in SerialConsole info 19987e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; 1999002d39b4SEd Tanous asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; 2000613dabeaSEd Tanous asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = 2001613dabeaSEd Tanous nlohmann::json::array_t({"IPMI", "SSH"}); 20027e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_KVM 20037e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 2004002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; 2005002d39b4SEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 2006002d39b4SEd Tanous 4; 2007613dabeaSEd Tanous asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 2008613dabeaSEd Tanous nlohmann::json::array_t({"KVMIP"}); 20097e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_KVM 20107e860f15SJohn Edward Broadbent 2011002d39b4SEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 20121476687dSEd Tanous 20131476687dSEd Tanous nlohmann::json::array_t managerForServers; 20141476687dSEd Tanous nlohmann::json::object_t manager; 20151476687dSEd Tanous manager["@odata.id"] = "/redfish/v1/Systems/system"; 2016ad539545SPatrick Williams managerForServers.emplace_back(std::move(manager)); 20171476687dSEd Tanous 20181476687dSEd Tanous asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 20191476687dSEd Tanous std::move(managerForServers); 20207e860f15SJohn Edward Broadbent 202113451e39SWilly Tu if constexpr (bmcwebEnableHealthPopulate) 202213451e39SWilly Tu { 20237e860f15SJohn Edward Broadbent auto health = std::make_shared<HealthPopulate>(asyncResp); 20247e860f15SJohn Edward Broadbent health->isManagersHealth = true; 20257e860f15SJohn Edward Broadbent health->populate(); 202613451e39SWilly Tu } 20277e860f15SJohn Edward Broadbent 2028eee0013eSWilly Tu sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 20297e860f15SJohn Edward Broadbent "FirmwareVersion", true); 20307e860f15SJohn Edward Broadbent 20317e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 20327e860f15SJohn Edward Broadbent 2033a51fc2d2SSui Chen // ManagerDiagnosticData is added for all BMCs. 2034a51fc2d2SSui Chen nlohmann::json& managerDiagnosticData = 2035a51fc2d2SSui Chen asyncResp->res.jsonValue["ManagerDiagnosticData"]; 2036a51fc2d2SSui Chen managerDiagnosticData["@odata.id"] = 2037a51fc2d2SSui Chen "/redfish/v1/Managers/bmc/ManagerDiagnosticData"; 2038a51fc2d2SSui Chen 203954dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 20407e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp); 20417e860f15SJohn Edward Broadbent pids->run(); 204254dce7f5SGunnar Mills #endif 20437e860f15SJohn Edward Broadbent 2044002d39b4SEd Tanous getMainChassisId(asyncResp, 2045002d39b4SEd Tanous [](const std::string& chassisId, 2046002d39b4SEd Tanous const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 2047002d39b4SEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1; 20481476687dSEd Tanous nlohmann::json::array_t managerForChassis; 20498a592810SEd Tanous nlohmann::json::object_t managerObj; 2050ef4c65b7SEd Tanous boost::urls::url chassiUrl = 2051ef4c65b7SEd Tanous boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 2052eddfc437SWilly Tu managerObj["@odata.id"] = chassiUrl; 2053ad539545SPatrick Williams managerForChassis.emplace_back(std::move(managerObj)); 20541476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 20551476687dSEd Tanous std::move(managerForChassis); 20561476687dSEd Tanous aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 2057eddfc437SWilly Tu chassiUrl; 20587e860f15SJohn Edward Broadbent }); 20597e860f15SJohn Edward Broadbent 20601e1e598dSJonathan Doman sdbusplus::asio::getProperty<double>( 20611e1e598dSJonathan Doman *crow::connections::systemBus, "org.freedesktop.systemd1", 2062002d39b4SEd Tanous "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager", 2063002d39b4SEd Tanous "Progress", 206475815e5cSEd Tanous [asyncResp](const boost::system::error_code& ec, double val) { 20657e860f15SJohn Edward Broadbent if (ec) 20661abe55efSEd Tanous { 20677e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Error while getting progress"; 20687e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20697e860f15SJohn Edward Broadbent return; 20707e860f15SJohn Edward Broadbent } 20711e1e598dSJonathan Doman if (val < 1.0) 20727e860f15SJohn Edward Broadbent { 207375815e5cSEd Tanous asyncResp->res.jsonValue["Status"]["Health"] = "OK"; 2074002d39b4SEd Tanous asyncResp->res.jsonValue["Status"]["State"] = "Starting"; 207575815e5cSEd Tanous return; 20767e860f15SJohn Edward Broadbent } 207775815e5cSEd Tanous checkForQuiesced(asyncResp); 20781e1e598dSJonathan Doman }); 20799c310685SBorawski.Lukasz 2080e99073f5SGeorge Liu constexpr std::array<std::string_view, 1> interfaces = { 2081e99073f5SGeorge Liu "xyz.openbmc_project.Inventory.Item.Bmc"}; 2082e99073f5SGeorge Liu dbus::utility::getSubTree( 2083e99073f5SGeorge Liu "/xyz/openbmc_project/inventory", 0, interfaces, 20847e860f15SJohn Edward Broadbent [asyncResp]( 2085e99073f5SGeorge Liu const boost::system::error_code& ec, 2086b9d36b47SEd Tanous const dbus::utility::MapperGetSubTreeResponse& subtree) { 20877e860f15SJohn Edward Broadbent if (ec) 20881abe55efSEd Tanous { 2089002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; 20907e860f15SJohn Edward Broadbent return; 20917e860f15SJohn Edward Broadbent } 209226f6976fSEd Tanous if (subtree.empty()) 20937e860f15SJohn Edward Broadbent { 20947e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!"; 20957e860f15SJohn Edward Broadbent return; 20967e860f15SJohn Edward Broadbent } 20977e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 20987e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 20997e860f15SJohn Edward Broadbent if (subtree.size() > 1) 21007e860f15SJohn Edward Broadbent { 2101002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Found more than 1 bmc D-Bus object!"; 21027e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21037e860f15SJohn Edward Broadbent return; 21047e860f15SJohn Edward Broadbent } 21057e860f15SJohn Edward Broadbent 2106002d39b4SEd Tanous if (subtree[0].first.empty() || subtree[0].second.size() != 1) 21077e860f15SJohn Edward Broadbent { 21087e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!"; 21097e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21107e860f15SJohn Edward Broadbent return; 21117e860f15SJohn Edward Broadbent } 21127e860f15SJohn Edward Broadbent 21137e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 2114002d39b4SEd Tanous const std::string& connectionName = subtree[0].second[0].first; 21157e860f15SJohn Edward Broadbent 2116002d39b4SEd Tanous for (const auto& interfaceName : subtree[0].second[0].second) 21177e860f15SJohn Edward Broadbent { 21187e860f15SJohn Edward Broadbent if (interfaceName == 21197e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 21207e860f15SJohn Edward Broadbent { 2121fac6e53bSKrzysztof Grobelny sdbusplus::asio::getAllProperties( 2122fac6e53bSKrzysztof Grobelny *crow::connections::systemBus, connectionName, path, 2123fac6e53bSKrzysztof Grobelny "xyz.openbmc_project.Inventory.Decorator.Asset", 21245e7e2dc5SEd Tanous [asyncResp](const boost::system::error_code& ec2, 2125b9d36b47SEd Tanous const dbus::utility::DBusPropertiesMap& 21267e860f15SJohn Edward Broadbent propertiesList) { 21278a592810SEd Tanous if (ec2) 21287e860f15SJohn Edward Broadbent { 2129002d39b4SEd Tanous BMCWEB_LOG_DEBUG << "Can't get bmc asset!"; 21307e860f15SJohn Edward Broadbent return; 21317e860f15SJohn Edward Broadbent } 21327e860f15SJohn Edward Broadbent 2133fac6e53bSKrzysztof Grobelny const std::string* partNumber = nullptr; 2134fac6e53bSKrzysztof Grobelny const std::string* serialNumber = nullptr; 2135fac6e53bSKrzysztof Grobelny const std::string* manufacturer = nullptr; 2136fac6e53bSKrzysztof Grobelny const std::string* model = nullptr; 2137fac6e53bSKrzysztof Grobelny const std::string* sparePartNumber = nullptr; 2138fac6e53bSKrzysztof Grobelny 2139fac6e53bSKrzysztof Grobelny const bool success = sdbusplus::unpackPropertiesNoThrow( 2140fac6e53bSKrzysztof Grobelny dbus_utils::UnpackErrorPrinter(), propertiesList, 2141fac6e53bSKrzysztof Grobelny "PartNumber", partNumber, "SerialNumber", 2142fac6e53bSKrzysztof Grobelny serialNumber, "Manufacturer", manufacturer, "Model", 2143fac6e53bSKrzysztof Grobelny model, "SparePartNumber", sparePartNumber); 2144fac6e53bSKrzysztof Grobelny 2145fac6e53bSKrzysztof Grobelny if (!success) 21467e860f15SJohn Edward Broadbent { 2147002d39b4SEd Tanous messages::internalError(asyncResp->res); 21487e860f15SJohn Edward Broadbent return; 21497e860f15SJohn Edward Broadbent } 2150fac6e53bSKrzysztof Grobelny 2151fac6e53bSKrzysztof Grobelny if (partNumber != nullptr) 2152fac6e53bSKrzysztof Grobelny { 2153fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["PartNumber"] = 2154fac6e53bSKrzysztof Grobelny *partNumber; 21557e860f15SJohn Edward Broadbent } 2156fac6e53bSKrzysztof Grobelny 2157fac6e53bSKrzysztof Grobelny if (serialNumber != nullptr) 2158fac6e53bSKrzysztof Grobelny { 2159fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SerialNumber"] = 2160fac6e53bSKrzysztof Grobelny *serialNumber; 21617e860f15SJohn Edward Broadbent } 2162fac6e53bSKrzysztof Grobelny 2163fac6e53bSKrzysztof Grobelny if (manufacturer != nullptr) 2164fac6e53bSKrzysztof Grobelny { 2165fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Manufacturer"] = 2166fac6e53bSKrzysztof Grobelny *manufacturer; 2167fac6e53bSKrzysztof Grobelny } 2168fac6e53bSKrzysztof Grobelny 2169fac6e53bSKrzysztof Grobelny if (model != nullptr) 2170fac6e53bSKrzysztof Grobelny { 2171fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["Model"] = *model; 2172fac6e53bSKrzysztof Grobelny } 2173fac6e53bSKrzysztof Grobelny 2174fac6e53bSKrzysztof Grobelny if (sparePartNumber != nullptr) 2175fac6e53bSKrzysztof Grobelny { 2176fac6e53bSKrzysztof Grobelny asyncResp->res.jsonValue["SparePartNumber"] = 2177fac6e53bSKrzysztof Grobelny *sparePartNumber; 2178fac6e53bSKrzysztof Grobelny } 2179fac6e53bSKrzysztof Grobelny }); 21807e860f15SJohn Edward Broadbent } 2181002d39b4SEd Tanous else if (interfaceName == 21820fda0f12SGeorge Liu "xyz.openbmc_project.Inventory.Decorator.LocationCode") 21837e860f15SJohn Edward Broadbent { 21847e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 21857e860f15SJohn Edward Broadbent } 21867e860f15SJohn Edward Broadbent } 2187e99073f5SGeorge Liu }); 21887e860f15SJohn Edward Broadbent }); 21897e860f15SJohn Edward Broadbent 21907e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 2191ed398213SEd Tanous .privileges(redfish::privileges::patchManager) 219245ca1b86SEd Tanous .methods(boost::beast::http::verb::patch)( 219345ca1b86SEd Tanous [&app](const crow::Request& req, 21947e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21953ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 219645ca1b86SEd Tanous { 219745ca1b86SEd Tanous return; 219845ca1b86SEd Tanous } 21997e860f15SJohn Edward Broadbent std::optional<nlohmann::json> oem; 22007e860f15SJohn Edward Broadbent std::optional<nlohmann::json> links; 22017e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 22027e860f15SJohn Edward Broadbent 220315ed6780SWilly Tu if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem, 2204002d39b4SEd Tanous "DateTime", datetime, "Links", links)) 22057e860f15SJohn Edward Broadbent { 22067e860f15SJohn Edward Broadbent return; 22077e860f15SJohn Edward Broadbent } 22087e860f15SJohn Edward Broadbent 22097e860f15SJohn Edward Broadbent if (oem) 22107e860f15SJohn Edward Broadbent { 221154dce7f5SGunnar Mills #ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA 22127e860f15SJohn Edward Broadbent std::optional<nlohmann::json> openbmc; 2213002d39b4SEd Tanous if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc", 2214002d39b4SEd Tanous openbmc)) 22157e860f15SJohn Edward Broadbent { 22167e860f15SJohn Edward Broadbent return; 22177e860f15SJohn Edward Broadbent } 22187e860f15SJohn Edward Broadbent if (openbmc) 22197e860f15SJohn Edward Broadbent { 22207e860f15SJohn Edward Broadbent std::optional<nlohmann::json> fan; 2221002d39b4SEd Tanous if (!redfish::json_util::readJson(*openbmc, asyncResp->res, 2222002d39b4SEd Tanous "Fan", fan)) 22237e860f15SJohn Edward Broadbent { 22247e860f15SJohn Edward Broadbent return; 22257e860f15SJohn Edward Broadbent } 22267e860f15SJohn Edward Broadbent if (fan) 22277e860f15SJohn Edward Broadbent { 2228002d39b4SEd Tanous auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan); 22297e860f15SJohn Edward Broadbent pid->run(); 22307e860f15SJohn Edward Broadbent } 22317e860f15SJohn Edward Broadbent } 223254dce7f5SGunnar Mills #else 223354dce7f5SGunnar Mills messages::propertyUnknown(asyncResp->res, "Oem"); 223454dce7f5SGunnar Mills return; 223554dce7f5SGunnar Mills #endif 22367e860f15SJohn Edward Broadbent } 22377e860f15SJohn Edward Broadbent if (links) 22387e860f15SJohn Edward Broadbent { 22397e860f15SJohn Edward Broadbent std::optional<nlohmann::json> activeSoftwareImage; 22407e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*links, asyncResp->res, 22417e860f15SJohn Edward Broadbent "ActiveSoftwareImage", 22427e860f15SJohn Edward Broadbent activeSoftwareImage)) 22437e860f15SJohn Edward Broadbent { 22447e860f15SJohn Edward Broadbent return; 22457e860f15SJohn Edward Broadbent } 22467e860f15SJohn Edward Broadbent if (activeSoftwareImage) 22477e860f15SJohn Edward Broadbent { 22487e860f15SJohn Edward Broadbent std::optional<std::string> odataId; 2249002d39b4SEd Tanous if (!json_util::readJson(*activeSoftwareImage, asyncResp->res, 2250002d39b4SEd Tanous "@odata.id", odataId)) 22517e860f15SJohn Edward Broadbent { 22527e860f15SJohn Edward Broadbent return; 22537e860f15SJohn Edward Broadbent } 22547e860f15SJohn Edward Broadbent 22557e860f15SJohn Edward Broadbent if (odataId) 22567e860f15SJohn Edward Broadbent { 22577e860f15SJohn Edward Broadbent setActiveFirmwareImage(asyncResp, *odataId); 22587e860f15SJohn Edward Broadbent } 22597e860f15SJohn Edward Broadbent } 22607e860f15SJohn Edward Broadbent } 22617e860f15SJohn Edward Broadbent if (datetime) 22627e860f15SJohn Edward Broadbent { 22637e860f15SJohn Edward Broadbent setDateTime(asyncResp, std::move(*datetime)); 22647e860f15SJohn Edward Broadbent } 22657e860f15SJohn Edward Broadbent }); 22667e860f15SJohn Edward Broadbent } 22677e860f15SJohn Edward Broadbent 22687e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 22697e860f15SJohn Edward Broadbent { 22707e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 2271ed398213SEd Tanous .privileges(redfish::privileges::getManagerCollection) 22727e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 227345ca1b86SEd Tanous [&app](const crow::Request& req, 22747e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 22753ba00073SCarson Labrado if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 227645ca1b86SEd Tanous { 227745ca1b86SEd Tanous return; 227845ca1b86SEd Tanous } 227983ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 228083ff9ab6SJames Feist // because it has a duplicate entry for members 22818d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 22828d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 22838d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 22848d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 22858d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 22861476687dSEd Tanous nlohmann::json::array_t members; 22871476687dSEd Tanous nlohmann::json& bmc = members.emplace_back(); 22881476687dSEd Tanous bmc["@odata.id"] = "/redfish/v1/Managers/bmc"; 22891476687dSEd Tanous asyncResp->res.jsonValue["Members"] = std::move(members); 22907e860f15SJohn Edward Broadbent }); 22919c310685SBorawski.Lukasz } 22929c310685SBorawski.Lukasz } // namespace redfish 2293