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 18b49ac873SJames Feist #include "health.hpp" 19c5d03ff4SJennifer Lee #include "redfish_util.hpp" 209c310685SBorawski.Lukasz 217e860f15SJohn Edward Broadbent #include <app.hpp> 225b4aa86bSJames Feist #include <boost/algorithm/string/replace.hpp> 23af5d6058SSantosh Puranik #include <boost/date_time.hpp> 245b4aa86bSJames Feist #include <dbus_utility.hpp> 25e90c5052SAndrew Geissler #include <utils/fw_utils.hpp> 267bffdb7eSBernard Wong #include <utils/systemd_utils.hpp> 271214b7e7SGunnar Mills 284bfefa74SGunnar Mills #include <cstdint> 291214b7e7SGunnar Mills #include <memory> 301214b7e7SGunnar Mills #include <sstream> 31abf2add6SEd Tanous #include <variant> 325b4aa86bSJames Feist 331abe55efSEd Tanous namespace redfish 341abe55efSEd Tanous { 35ed5befbdSJennifer Lee 36ed5befbdSJennifer Lee /** 372a5c4407SGunnar Mills * Function reboots the BMC. 382a5c4407SGunnar Mills * 392a5c4407SGunnar Mills * @param[in] asyncResp - Shared pointer for completing asynchronous calls 40ed5befbdSJennifer Lee */ 418d1b46d7Szhanghch05 inline void 428d1b46d7Szhanghch05 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 43ed5befbdSJennifer Lee { 44ed5befbdSJennifer Lee const char* processName = "xyz.openbmc_project.State.BMC"; 45ed5befbdSJennifer Lee const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 46ed5befbdSJennifer Lee const char* interfaceName = "xyz.openbmc_project.State.BMC"; 47ed5befbdSJennifer Lee const std::string& propertyValue = 48ed5befbdSJennifer Lee "xyz.openbmc_project.State.BMC.Transition.Reboot"; 49ed5befbdSJennifer Lee const char* destProperty = "RequestedBMCTransition"; 50ed5befbdSJennifer Lee 51ed5befbdSJennifer Lee // Create the D-Bus variant for D-Bus call. 52ed5befbdSJennifer Lee VariantType dbusPropertyValue(propertyValue); 53ed5befbdSJennifer Lee 54ed5befbdSJennifer Lee crow::connections::systemBus->async_method_call( 55ed5befbdSJennifer Lee [asyncResp](const boost::system::error_code ec) { 56ed5befbdSJennifer Lee // Use "Set" method to set the property value. 57ed5befbdSJennifer Lee if (ec) 58ed5befbdSJennifer Lee { 592a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 60ed5befbdSJennifer Lee messages::internalError(asyncResp->res); 61ed5befbdSJennifer Lee return; 62ed5befbdSJennifer Lee } 63ed5befbdSJennifer Lee 64ed5befbdSJennifer Lee messages::success(asyncResp->res); 65ed5befbdSJennifer Lee }, 66ed5befbdSJennifer Lee processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 67ed5befbdSJennifer Lee interfaceName, destProperty, dbusPropertyValue); 68ed5befbdSJennifer Lee } 692a5c4407SGunnar Mills 708d1b46d7Szhanghch05 inline void 718d1b46d7Szhanghch05 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 72f92af389SJayaprakash Mutyala { 73f92af389SJayaprakash Mutyala const char* processName = "xyz.openbmc_project.State.BMC"; 74f92af389SJayaprakash Mutyala const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 75f92af389SJayaprakash Mutyala const char* interfaceName = "xyz.openbmc_project.State.BMC"; 76f92af389SJayaprakash Mutyala const std::string& propertyValue = 77f92af389SJayaprakash Mutyala "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 78f92af389SJayaprakash Mutyala const char* destProperty = "RequestedBMCTransition"; 79f92af389SJayaprakash Mutyala 80f92af389SJayaprakash Mutyala // Create the D-Bus variant for D-Bus call. 81f92af389SJayaprakash Mutyala VariantType dbusPropertyValue(propertyValue); 82f92af389SJayaprakash Mutyala 83f92af389SJayaprakash Mutyala crow::connections::systemBus->async_method_call( 84f92af389SJayaprakash Mutyala [asyncResp](const boost::system::error_code ec) { 85f92af389SJayaprakash Mutyala // Use "Set" method to set the property value. 86f92af389SJayaprakash Mutyala if (ec) 87f92af389SJayaprakash Mutyala { 88f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec; 89f92af389SJayaprakash Mutyala messages::internalError(asyncResp->res); 90f92af389SJayaprakash Mutyala return; 91f92af389SJayaprakash Mutyala } 92f92af389SJayaprakash Mutyala 93f92af389SJayaprakash Mutyala messages::success(asyncResp->res); 94f92af389SJayaprakash Mutyala }, 95f92af389SJayaprakash Mutyala processName, objectPath, "org.freedesktop.DBus.Properties", "Set", 96f92af389SJayaprakash Mutyala interfaceName, destProperty, dbusPropertyValue); 97f92af389SJayaprakash Mutyala } 98f92af389SJayaprakash Mutyala 992a5c4407SGunnar Mills /** 1002a5c4407SGunnar Mills * ManagerResetAction class supports the POST method for the Reset (reboot) 1012a5c4407SGunnar Mills * action. 1022a5c4407SGunnar Mills */ 1037e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetAction(App& app) 1042a5c4407SGunnar Mills { 1052a5c4407SGunnar Mills /** 1062a5c4407SGunnar Mills * Function handles POST method request. 1072a5c4407SGunnar Mills * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 108f92af389SJayaprakash Mutyala * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 1092a5c4407SGunnar Mills */ 1107e860f15SJohn Edward Broadbent 1117e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/") 112*432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 1137e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 1147e860f15SJohn Edward Broadbent [](const crow::Request& req, 1157e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1162a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Post Manager Reset."; 1172a5c4407SGunnar Mills 1182a5c4407SGunnar Mills std::string resetType; 1192a5c4407SGunnar Mills 1207e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "ResetType", 1217e860f15SJohn Edward Broadbent resetType)) 1222a5c4407SGunnar Mills { 1232a5c4407SGunnar Mills return; 1242a5c4407SGunnar Mills } 1252a5c4407SGunnar Mills 126f92af389SJayaprakash Mutyala if (resetType == "GracefulRestart") 127f92af389SJayaprakash Mutyala { 128f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 129f92af389SJayaprakash Mutyala doBMCGracefulRestart(asyncResp); 130f92af389SJayaprakash Mutyala return; 131f92af389SJayaprakash Mutyala } 1323174e4dfSEd Tanous if (resetType == "ForceRestart") 133f92af389SJayaprakash Mutyala { 134f92af389SJayaprakash Mutyala BMCWEB_LOG_DEBUG << "Proceeding with " << resetType; 135f92af389SJayaprakash Mutyala doBMCForceRestart(asyncResp); 136f92af389SJayaprakash Mutyala return; 137f92af389SJayaprakash Mutyala } 1382a5c4407SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " 1392a5c4407SGunnar Mills << resetType; 1402a5c4407SGunnar Mills messages::actionParameterNotSupported(asyncResp->res, resetType, 1412a5c4407SGunnar Mills "ResetType"); 1422a5c4407SGunnar Mills 1432a5c4407SGunnar Mills return; 1447e860f15SJohn Edward Broadbent }); 1452a5c4407SGunnar Mills } 146ed5befbdSJennifer Lee 1473e40fc74SGunnar Mills /** 1483e40fc74SGunnar Mills * ManagerResetToDefaultsAction class supports POST method for factory reset 1493e40fc74SGunnar Mills * action. 1503e40fc74SGunnar Mills */ 1517e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetToDefaultsAction(App& app) 1523e40fc74SGunnar Mills { 1533e40fc74SGunnar Mills 1543e40fc74SGunnar Mills /** 1553e40fc74SGunnar Mills * Function handles ResetToDefaults POST method request. 1563e40fc74SGunnar Mills * 1573e40fc74SGunnar Mills * Analyzes POST body message and factory resets BMC by calling 1583e40fc74SGunnar Mills * BMC code updater factory reset followed by a BMC reboot. 1593e40fc74SGunnar Mills * 1603e40fc74SGunnar Mills * BMC code updater factory reset wipes the whole BMC read-write 1613e40fc74SGunnar Mills * filesystem which includes things like the network settings. 1623e40fc74SGunnar Mills * 1633e40fc74SGunnar Mills * OpenBMC only supports ResetToDefaultsType "ResetAll". 1643e40fc74SGunnar Mills */ 1657e860f15SJohn Edward Broadbent 1667e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, 1677e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/") 168*432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 1697e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::post)( 1707e860f15SJohn Edward Broadbent [](const crow::Request& req, 1717e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 1723e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Post ResetToDefaults."; 1733e40fc74SGunnar Mills 1743e40fc74SGunnar Mills std::string resetType; 1753e40fc74SGunnar Mills 1767e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, 1777e860f15SJohn Edward Broadbent "ResetToDefaultsType", resetType)) 1783e40fc74SGunnar Mills { 1793e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType."; 1803e40fc74SGunnar Mills 1817e860f15SJohn Edward Broadbent messages::actionParameterMissing(asyncResp->res, 1827e860f15SJohn Edward Broadbent "ResetToDefaults", 1833e40fc74SGunnar Mills "ResetToDefaultsType"); 1843e40fc74SGunnar Mills return; 1853e40fc74SGunnar Mills } 1863e40fc74SGunnar Mills 1873e40fc74SGunnar Mills if (resetType != "ResetAll") 1883e40fc74SGunnar Mills { 1893e40fc74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid property value for " 1903e40fc74SGunnar Mills "ResetToDefaultsType: " 1913e40fc74SGunnar Mills << resetType; 1927e860f15SJohn Edward Broadbent messages::actionParameterNotSupported( 1937e860f15SJohn Edward Broadbent asyncResp->res, resetType, "ResetToDefaultsType"); 1943e40fc74SGunnar Mills return; 1953e40fc74SGunnar Mills } 1963e40fc74SGunnar Mills 1973e40fc74SGunnar Mills crow::connections::systemBus->async_method_call( 1983e40fc74SGunnar Mills [asyncResp](const boost::system::error_code ec) { 1993e40fc74SGunnar Mills if (ec) 2003e40fc74SGunnar Mills { 2017e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " 2027e860f15SJohn Edward Broadbent << ec; 2033e40fc74SGunnar Mills messages::internalError(asyncResp->res); 2043e40fc74SGunnar Mills return; 2053e40fc74SGunnar Mills } 2063e40fc74SGunnar Mills // Factory Reset doesn't actually happen until a reboot 2073e40fc74SGunnar Mills // Can't erase what the BMC is running on 2083e40fc74SGunnar Mills doBMCGracefulRestart(asyncResp); 2093e40fc74SGunnar Mills }, 2103e40fc74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 2113e40fc74SGunnar Mills "/xyz/openbmc_project/software", 2123e40fc74SGunnar Mills "xyz.openbmc_project.Common.FactoryReset", "Reset"); 2137e860f15SJohn Edward Broadbent }); 2143e40fc74SGunnar Mills } 2153e40fc74SGunnar Mills 2161cb1a9e6SAppaRao Puli /** 2171cb1a9e6SAppaRao Puli * ManagerResetActionInfo derived class for delivering Manager 2181cb1a9e6SAppaRao Puli * ResetType AllowableValues using ResetInfo schema. 2191cb1a9e6SAppaRao Puli */ 2207e860f15SJohn Edward Broadbent inline void requestRoutesManagerResetActionInfo(App& app) 2211cb1a9e6SAppaRao Puli { 2221cb1a9e6SAppaRao Puli /** 2231cb1a9e6SAppaRao Puli * Functions triggers appropriate requests on DBus 2241cb1a9e6SAppaRao Puli */ 2257e860f15SJohn Edward Broadbent 2267e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/") 227*432a890cSEd Tanous .privileges({{"Login"}}) 2287e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 2297e860f15SJohn Edward Broadbent [](const crow::Request&, 2307e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 2318d1b46d7Szhanghch05 asyncResp->res.jsonValue = { 2321cb1a9e6SAppaRao Puli {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, 2331cb1a9e6SAppaRao Puli {"@odata.id", "/redfish/v1/Managers/bmc/ResetActionInfo"}, 2341cb1a9e6SAppaRao Puli {"Name", "Reset Action Info"}, 2351cb1a9e6SAppaRao Puli {"Id", "ResetActionInfo"}, 2361cb1a9e6SAppaRao Puli {"Parameters", 2371cb1a9e6SAppaRao Puli {{{"Name", "ResetType"}, 2381cb1a9e6SAppaRao Puli {"Required", true}, 2391cb1a9e6SAppaRao Puli {"DataType", "String"}, 2407e860f15SJohn Edward Broadbent {"AllowableValues", 2417e860f15SJohn Edward Broadbent {"GracefulRestart", "ForceRestart"}}}}}}; 2427e860f15SJohn Edward Broadbent }); 2431cb1a9e6SAppaRao Puli } 2441cb1a9e6SAppaRao Puli 2455b4aa86bSJames Feist static constexpr const char* objectManagerIface = 2465b4aa86bSJames Feist "org.freedesktop.DBus.ObjectManager"; 2475b4aa86bSJames Feist static constexpr const char* pidConfigurationIface = 2485b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid"; 2495b4aa86bSJames Feist static constexpr const char* pidZoneConfigurationIface = 2505b4aa86bSJames Feist "xyz.openbmc_project.Configuration.Pid.Zone"; 251b7a08d04SJames Feist static constexpr const char* stepwiseConfigurationIface = 252b7a08d04SJames Feist "xyz.openbmc_project.Configuration.Stepwise"; 25373df0db0SJames Feist static constexpr const char* thermalModeIface = 25473df0db0SJames Feist "xyz.openbmc_project.Control.ThermalMode"; 2559c310685SBorawski.Lukasz 2568d1b46d7Szhanghch05 inline void 2578d1b46d7Szhanghch05 asyncPopulatePid(const std::string& connection, const std::string& path, 25873df0db0SJames Feist const std::string& currentProfile, 25973df0db0SJames Feist const std::vector<std::string>& supportedProfiles, 2608d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 2615b4aa86bSJames Feist { 2625b4aa86bSJames Feist 2635b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 26473df0db0SJames Feist [asyncResp, currentProfile, supportedProfiles]( 26573df0db0SJames Feist const boost::system::error_code ec, 2665b4aa86bSJames Feist const dbus::utility::ManagedObjectType& managedObj) { 2675b4aa86bSJames Feist if (ec) 2685b4aa86bSJames Feist { 2695b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 2705b4aa86bSJames Feist asyncResp->res.jsonValue.clear(); 271f12894f8SJason M. Bills messages::internalError(asyncResp->res); 2725b4aa86bSJames Feist return; 2735b4aa86bSJames Feist } 2745b4aa86bSJames Feist nlohmann::json& configRoot = 2755b4aa86bSJames Feist asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"]; 2765b4aa86bSJames Feist nlohmann::json& fans = configRoot["FanControllers"]; 2775b4aa86bSJames Feist fans["@odata.type"] = "#OemManager.FanControllers"; 2785b4aa86bSJames Feist fans["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/" 2795b4aa86bSJames Feist "Fan/FanControllers"; 2805b4aa86bSJames Feist 2815b4aa86bSJames Feist nlohmann::json& pids = configRoot["PidControllers"]; 2825b4aa86bSJames Feist pids["@odata.type"] = "#OemManager.PidControllers"; 2835b4aa86bSJames Feist pids["@odata.id"] = 2845b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers"; 2855b4aa86bSJames Feist 286b7a08d04SJames Feist nlohmann::json& stepwise = configRoot["StepwiseControllers"]; 287b7a08d04SJames Feist stepwise["@odata.type"] = "#OemManager.StepwiseControllers"; 288b7a08d04SJames Feist stepwise["@odata.id"] = 289b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers"; 290b7a08d04SJames Feist 2915b4aa86bSJames Feist nlohmann::json& zones = configRoot["FanZones"]; 2925b4aa86bSJames Feist zones["@odata.id"] = 2935b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones"; 2945b4aa86bSJames Feist zones["@odata.type"] = "#OemManager.FanZones"; 2955b4aa86bSJames Feist configRoot["@odata.id"] = 2965b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan"; 2975b4aa86bSJames Feist configRoot["@odata.type"] = "#OemManager.Fan"; 29873df0db0SJames Feist configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles; 29973df0db0SJames Feist 30073df0db0SJames Feist if (!currentProfile.empty()) 30173df0db0SJames Feist { 30273df0db0SJames Feist configRoot["Profile"] = currentProfile; 30373df0db0SJames Feist } 30473df0db0SJames Feist BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !"; 3055b4aa86bSJames Feist 3065b4aa86bSJames Feist for (const auto& pathPair : managedObj) 3075b4aa86bSJames Feist { 3085b4aa86bSJames Feist for (const auto& intfPair : pathPair.second) 3095b4aa86bSJames Feist { 3105b4aa86bSJames Feist if (intfPair.first != pidConfigurationIface && 311b7a08d04SJames Feist intfPair.first != pidZoneConfigurationIface && 312b7a08d04SJames Feist intfPair.first != stepwiseConfigurationIface) 3135b4aa86bSJames Feist { 3145b4aa86bSJames Feist continue; 3155b4aa86bSJames Feist } 3165b4aa86bSJames Feist auto findName = intfPair.second.find("Name"); 3175b4aa86bSJames Feist if (findName == intfPair.second.end()) 3185b4aa86bSJames Feist { 3195b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Field missing Name"; 320a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 3215b4aa86bSJames Feist return; 3225b4aa86bSJames Feist } 32373df0db0SJames Feist 3245b4aa86bSJames Feist const std::string* namePtr = 325abf2add6SEd Tanous std::get_if<std::string>(&findName->second); 3265b4aa86bSJames Feist if (namePtr == nullptr) 3275b4aa86bSJames Feist { 3285b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Name Field illegal"; 329b7a08d04SJames Feist messages::internalError(asyncResp->res); 3305b4aa86bSJames Feist return; 3315b4aa86bSJames Feist } 3325b4aa86bSJames Feist std::string name = *namePtr; 3335b4aa86bSJames Feist dbus::utility::escapePathForDbus(name); 33473df0db0SJames Feist 33573df0db0SJames Feist auto findProfiles = intfPair.second.find("Profiles"); 33673df0db0SJames Feist if (findProfiles != intfPair.second.end()) 33773df0db0SJames Feist { 33873df0db0SJames Feist const std::vector<std::string>* profiles = 33973df0db0SJames Feist std::get_if<std::vector<std::string>>( 34073df0db0SJames Feist &findProfiles->second); 34173df0db0SJames Feist if (profiles == nullptr) 34273df0db0SJames Feist { 34373df0db0SJames Feist BMCWEB_LOG_ERROR << "Pid Profiles Field illegal"; 34473df0db0SJames Feist messages::internalError(asyncResp->res); 34573df0db0SJames Feist return; 34673df0db0SJames Feist } 34773df0db0SJames Feist if (std::find(profiles->begin(), profiles->end(), 34873df0db0SJames Feist currentProfile) == profiles->end()) 34973df0db0SJames Feist { 35073df0db0SJames Feist BMCWEB_LOG_INFO 35173df0db0SJames Feist << name << " not supported in current profile"; 35273df0db0SJames Feist continue; 35373df0db0SJames Feist } 35473df0db0SJames Feist } 355b7a08d04SJames Feist nlohmann::json* config = nullptr; 356c33a90ecSJames Feist 357c33a90ecSJames Feist const std::string* classPtr = nullptr; 358c33a90ecSJames Feist auto findClass = intfPair.second.find("Class"); 359c33a90ecSJames Feist if (findClass != intfPair.second.end()) 360c33a90ecSJames Feist { 361c33a90ecSJames Feist classPtr = std::get_if<std::string>(&findClass->second); 362c33a90ecSJames Feist } 363c33a90ecSJames Feist 3645b4aa86bSJames Feist if (intfPair.first == pidZoneConfigurationIface) 3655b4aa86bSJames Feist { 3665b4aa86bSJames Feist std::string chassis; 3675b4aa86bSJames Feist if (!dbus::utility::getNthStringFromPath( 3685b4aa86bSJames Feist pathPair.first.str, 5, chassis)) 3695b4aa86bSJames Feist { 3705b4aa86bSJames Feist chassis = "#IllegalValue"; 3715b4aa86bSJames Feist } 3725b4aa86bSJames Feist nlohmann::json& zone = zones[name]; 3735b4aa86bSJames Feist zone["Chassis"] = { 3745b4aa86bSJames Feist {"@odata.id", "/redfish/v1/Chassis/" + chassis}}; 3755b4aa86bSJames Feist zone["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/" 3765b4aa86bSJames Feist "OpenBmc/Fan/FanZones/" + 3775b4aa86bSJames Feist name; 3785b4aa86bSJames Feist zone["@odata.type"] = "#OemManager.FanZone"; 379b7a08d04SJames Feist config = &zone; 3805b4aa86bSJames Feist } 3815b4aa86bSJames Feist 382b7a08d04SJames Feist else if (intfPair.first == stepwiseConfigurationIface) 3835b4aa86bSJames Feist { 384c33a90ecSJames Feist if (classPtr == nullptr) 385c33a90ecSJames Feist { 386c33a90ecSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 387c33a90ecSJames Feist messages::internalError(asyncResp->res); 388c33a90ecSJames Feist return; 389c33a90ecSJames Feist } 390c33a90ecSJames Feist 391b7a08d04SJames Feist nlohmann::json& controller = stepwise[name]; 392b7a08d04SJames Feist config = &controller; 3935b4aa86bSJames Feist 394b7a08d04SJames Feist controller["@odata.id"] = 395b7a08d04SJames Feist "/redfish/v1/Managers/bmc#/Oem/" 396b7a08d04SJames Feist "OpenBmc/Fan/StepwiseControllers/" + 397271584abSEd Tanous name; 398b7a08d04SJames Feist controller["@odata.type"] = 399b7a08d04SJames Feist "#OemManager.StepwiseController"; 400b7a08d04SJames Feist 401c33a90ecSJames Feist controller["Direction"] = *classPtr; 4025b4aa86bSJames Feist } 4035b4aa86bSJames Feist 4045b4aa86bSJames Feist // pid and fans are off the same configuration 405b7a08d04SJames Feist else if (intfPair.first == pidConfigurationIface) 4065b4aa86bSJames Feist { 407c33a90ecSJames Feist 4085b4aa86bSJames Feist if (classPtr == nullptr) 4095b4aa86bSJames Feist { 4105b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Pid Class Field illegal"; 411a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 4125b4aa86bSJames Feist return; 4135b4aa86bSJames Feist } 4145b4aa86bSJames Feist bool isFan = *classPtr == "fan"; 4155b4aa86bSJames Feist nlohmann::json& element = 4165b4aa86bSJames Feist isFan ? fans[name] : pids[name]; 417b7a08d04SJames Feist config = &element; 4185b4aa86bSJames Feist if (isFan) 4195b4aa86bSJames Feist { 4205b4aa86bSJames Feist element["@odata.id"] = 4215b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/" 4225b4aa86bSJames Feist "OpenBmc/Fan/FanControllers/" + 423271584abSEd Tanous name; 4245b4aa86bSJames Feist element["@odata.type"] = 4255b4aa86bSJames Feist "#OemManager.FanController"; 4265b4aa86bSJames Feist } 4275b4aa86bSJames Feist else 4285b4aa86bSJames Feist { 4295b4aa86bSJames Feist element["@odata.id"] = 4305b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/" 4315b4aa86bSJames Feist "OpenBmc/Fan/PidControllers/" + 432271584abSEd Tanous name; 4335b4aa86bSJames Feist element["@odata.type"] = 4345b4aa86bSJames Feist "#OemManager.PidController"; 4355b4aa86bSJames Feist } 436b7a08d04SJames Feist } 437b7a08d04SJames Feist else 438b7a08d04SJames Feist { 439b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Unexpected configuration"; 440b7a08d04SJames Feist messages::internalError(asyncResp->res); 441b7a08d04SJames Feist return; 442b7a08d04SJames Feist } 443b7a08d04SJames Feist 444b7a08d04SJames Feist // used for making maps out of 2 vectors 445b7a08d04SJames Feist const std::vector<double>* keys = nullptr; 446b7a08d04SJames Feist const std::vector<double>* values = nullptr; 447b7a08d04SJames Feist 448b7a08d04SJames Feist for (const auto& propertyPair : intfPair.second) 449b7a08d04SJames Feist { 450b7a08d04SJames Feist if (propertyPair.first == "Type" || 451b7a08d04SJames Feist propertyPair.first == "Class" || 452b7a08d04SJames Feist propertyPair.first == "Name") 453b7a08d04SJames Feist { 454b7a08d04SJames Feist continue; 455b7a08d04SJames Feist } 456b7a08d04SJames Feist 457b7a08d04SJames Feist // zones 458b7a08d04SJames Feist if (intfPair.first == pidZoneConfigurationIface) 459b7a08d04SJames Feist { 460b7a08d04SJames Feist const double* ptr = 461abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 462b7a08d04SJames Feist if (ptr == nullptr) 463b7a08d04SJames Feist { 464b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 465b7a08d04SJames Feist << propertyPair.first; 466b7a08d04SJames Feist messages::internalError(asyncResp->res); 467b7a08d04SJames Feist return; 468b7a08d04SJames Feist } 469b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 470b7a08d04SJames Feist } 471b7a08d04SJames Feist 472b7a08d04SJames Feist if (intfPair.first == stepwiseConfigurationIface) 473b7a08d04SJames Feist { 474b7a08d04SJames Feist if (propertyPair.first == "Reading" || 475b7a08d04SJames Feist propertyPair.first == "Output") 476b7a08d04SJames Feist { 477b7a08d04SJames Feist const std::vector<double>* ptr = 478abf2add6SEd Tanous std::get_if<std::vector<double>>( 479b7a08d04SJames Feist &propertyPair.second); 480b7a08d04SJames Feist 481b7a08d04SJames Feist if (ptr == nullptr) 482b7a08d04SJames Feist { 483b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 484b7a08d04SJames Feist << propertyPair.first; 485b7a08d04SJames Feist messages::internalError(asyncResp->res); 486b7a08d04SJames Feist return; 487b7a08d04SJames Feist } 488b7a08d04SJames Feist 489b7a08d04SJames Feist if (propertyPair.first == "Reading") 490b7a08d04SJames Feist { 491b7a08d04SJames Feist keys = ptr; 492b7a08d04SJames Feist } 493b7a08d04SJames Feist else 494b7a08d04SJames Feist { 495b7a08d04SJames Feist values = ptr; 496b7a08d04SJames Feist } 497b7a08d04SJames Feist if (keys && values) 498b7a08d04SJames Feist { 499b7a08d04SJames Feist if (keys->size() != values->size()) 500b7a08d04SJames Feist { 501b7a08d04SJames Feist BMCWEB_LOG_ERROR 502b7a08d04SJames Feist << "Reading and Output size don't " 503b7a08d04SJames Feist "match "; 504b7a08d04SJames Feist messages::internalError(asyncResp->res); 505b7a08d04SJames Feist return; 506b7a08d04SJames Feist } 507b7a08d04SJames Feist nlohmann::json& steps = (*config)["Steps"]; 508b7a08d04SJames Feist steps = nlohmann::json::array(); 509b7a08d04SJames Feist for (size_t ii = 0; ii < keys->size(); ii++) 510b7a08d04SJames Feist { 511b7a08d04SJames Feist steps.push_back( 512b7a08d04SJames Feist {{"Target", (*keys)[ii]}, 513b7a08d04SJames Feist {"Output", (*values)[ii]}}); 514b7a08d04SJames Feist } 515b7a08d04SJames Feist } 516b7a08d04SJames Feist } 517b7a08d04SJames Feist if (propertyPair.first == "NegativeHysteresis" || 518b7a08d04SJames Feist propertyPair.first == "PositiveHysteresis") 519b7a08d04SJames Feist { 520b7a08d04SJames Feist const double* ptr = 521abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 522b7a08d04SJames Feist if (ptr == nullptr) 523b7a08d04SJames Feist { 524b7a08d04SJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 525b7a08d04SJames Feist << propertyPair.first; 526b7a08d04SJames Feist messages::internalError(asyncResp->res); 527b7a08d04SJames Feist return; 528b7a08d04SJames Feist } 529b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 530b7a08d04SJames Feist } 531b7a08d04SJames Feist } 532b7a08d04SJames Feist 533b7a08d04SJames Feist // pid and fans are off the same configuration 534b7a08d04SJames Feist if (intfPair.first == pidConfigurationIface || 535b7a08d04SJames Feist intfPair.first == stepwiseConfigurationIface) 536b7a08d04SJames Feist { 5375b4aa86bSJames Feist 5385b4aa86bSJames Feist if (propertyPair.first == "Zones") 5395b4aa86bSJames Feist { 5405b4aa86bSJames Feist const std::vector<std::string>* inputs = 541abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5421b6b96c5SEd Tanous &propertyPair.second); 5435b4aa86bSJames Feist 5445b4aa86bSJames Feist if (inputs == nullptr) 5455b4aa86bSJames Feist { 5465b4aa86bSJames Feist BMCWEB_LOG_ERROR 5475b4aa86bSJames Feist << "Zones Pid Field Illegal"; 548a08b46ccSJason M. Bills messages::internalError(asyncResp->res); 5495b4aa86bSJames Feist return; 5505b4aa86bSJames Feist } 551b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5525b4aa86bSJames Feist data = nlohmann::json::array(); 5535b4aa86bSJames Feist for (std::string itemCopy : *inputs) 5545b4aa86bSJames Feist { 5555b4aa86bSJames Feist dbus::utility::escapePathForDbus(itemCopy); 5565b4aa86bSJames Feist data.push_back( 5575b4aa86bSJames Feist {{"@odata.id", 5585b4aa86bSJames Feist "/redfish/v1/Managers/bmc#/Oem/" 5595b4aa86bSJames Feist "OpenBmc/Fan/FanZones/" + 5605b4aa86bSJames Feist itemCopy}}); 5615b4aa86bSJames Feist } 5625b4aa86bSJames Feist } 5635b4aa86bSJames Feist // todo(james): may never happen, but this 5645b4aa86bSJames Feist // assumes configuration data referenced in the 5655b4aa86bSJames Feist // PID config is provided by the same daemon, we 5665b4aa86bSJames Feist // could add another loop to cover all cases, 5675b4aa86bSJames Feist // but I'm okay kicking this can down the road a 5685b4aa86bSJames Feist // bit 5695b4aa86bSJames Feist 5705b4aa86bSJames Feist else if (propertyPair.first == "Inputs" || 5715b4aa86bSJames Feist propertyPair.first == "Outputs") 5725b4aa86bSJames Feist { 573b7a08d04SJames Feist auto& data = (*config)[propertyPair.first]; 5745b4aa86bSJames Feist const std::vector<std::string>* inputs = 575abf2add6SEd Tanous std::get_if<std::vector<std::string>>( 5761b6b96c5SEd Tanous &propertyPair.second); 5775b4aa86bSJames Feist 5785b4aa86bSJames Feist if (inputs == nullptr) 5795b4aa86bSJames Feist { 5805b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 5815b4aa86bSJames Feist << propertyPair.first; 582f12894f8SJason M. Bills messages::internalError(asyncResp->res); 5835b4aa86bSJames Feist return; 5845b4aa86bSJames Feist } 5855b4aa86bSJames Feist data = *inputs; 586b943aaefSJames Feist } 587b943aaefSJames Feist else if (propertyPair.first == "SetPointOffset") 588b943aaefSJames Feist { 589b943aaefSJames Feist const std::string* ptr = 590b943aaefSJames Feist std::get_if<std::string>( 591b943aaefSJames Feist &propertyPair.second); 592b943aaefSJames Feist 593b943aaefSJames Feist if (ptr == nullptr) 594b943aaefSJames Feist { 595b943aaefSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 596b943aaefSJames Feist << propertyPair.first; 597b943aaefSJames Feist messages::internalError(asyncResp->res); 598b943aaefSJames Feist return; 599b943aaefSJames Feist } 600b943aaefSJames Feist // translate from dbus to redfish 601b943aaefSJames Feist if (*ptr == "WarningHigh") 602b943aaefSJames Feist { 603b943aaefSJames Feist (*config)["SetPointOffset"] = 604b943aaefSJames Feist "UpperThresholdNonCritical"; 605b943aaefSJames Feist } 606b943aaefSJames Feist else if (*ptr == "WarningLow") 607b943aaefSJames Feist { 608b943aaefSJames Feist (*config)["SetPointOffset"] = 609b943aaefSJames Feist "LowerThresholdNonCritical"; 610b943aaefSJames Feist } 611b943aaefSJames Feist else if (*ptr == "CriticalHigh") 612b943aaefSJames Feist { 613b943aaefSJames Feist (*config)["SetPointOffset"] = 614b943aaefSJames Feist "UpperThresholdCritical"; 615b943aaefSJames Feist } 616b943aaefSJames Feist else if (*ptr == "CriticalLow") 617b943aaefSJames Feist { 618b943aaefSJames Feist (*config)["SetPointOffset"] = 619b943aaefSJames Feist "LowerThresholdCritical"; 620b943aaefSJames Feist } 621b943aaefSJames Feist else 622b943aaefSJames Feist { 623b943aaefSJames Feist BMCWEB_LOG_ERROR << "Value Illegal " 624b943aaefSJames Feist << *ptr; 625b943aaefSJames Feist messages::internalError(asyncResp->res); 626b943aaefSJames Feist return; 627b943aaefSJames Feist } 628b943aaefSJames Feist } 629b943aaefSJames Feist // doubles 6305b4aa86bSJames Feist else if (propertyPair.first == 6315b4aa86bSJames Feist "FFGainCoefficient" || 6325b4aa86bSJames Feist propertyPair.first == "FFOffCoefficient" || 6335b4aa86bSJames Feist propertyPair.first == "ICoefficient" || 6345b4aa86bSJames Feist propertyPair.first == "ILimitMax" || 6355b4aa86bSJames Feist propertyPair.first == "ILimitMin" || 636aad1a257SJames Feist propertyPair.first == 637aad1a257SJames Feist "PositiveHysteresis" || 638aad1a257SJames Feist propertyPair.first == 639aad1a257SJames Feist "NegativeHysteresis" || 6405b4aa86bSJames Feist propertyPair.first == "OutLimitMax" || 6415b4aa86bSJames Feist propertyPair.first == "OutLimitMin" || 6425b4aa86bSJames Feist propertyPair.first == "PCoefficient" || 6437625cb81SJames Feist propertyPair.first == "SetPoint" || 6445b4aa86bSJames Feist propertyPair.first == "SlewNeg" || 6455b4aa86bSJames Feist propertyPair.first == "SlewPos") 6465b4aa86bSJames Feist { 6475b4aa86bSJames Feist const double* ptr = 648abf2add6SEd Tanous std::get_if<double>(&propertyPair.second); 6495b4aa86bSJames Feist if (ptr == nullptr) 6505b4aa86bSJames Feist { 6515b4aa86bSJames Feist BMCWEB_LOG_ERROR << "Field Illegal " 6525b4aa86bSJames Feist << propertyPair.first; 653f12894f8SJason M. Bills messages::internalError(asyncResp->res); 6545b4aa86bSJames Feist return; 6555b4aa86bSJames Feist } 656b7a08d04SJames Feist (*config)[propertyPair.first] = *ptr; 6575b4aa86bSJames Feist } 6585b4aa86bSJames Feist } 6595b4aa86bSJames Feist } 6605b4aa86bSJames Feist } 6615b4aa86bSJames Feist } 6625b4aa86bSJames Feist }, 6635b4aa86bSJames Feist connection, path, objectManagerIface, "GetManagedObjects"); 6645b4aa86bSJames Feist } 665ca537928SJennifer Lee 66683ff9ab6SJames Feist enum class CreatePIDRet 66783ff9ab6SJames Feist { 66883ff9ab6SJames Feist fail, 66983ff9ab6SJames Feist del, 67083ff9ab6SJames Feist patch 67183ff9ab6SJames Feist }; 67283ff9ab6SJames Feist 6738d1b46d7Szhanghch05 inline bool 6748d1b46d7Szhanghch05 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response, 6755f2caaefSJames Feist std::vector<nlohmann::json>& config, 6765f2caaefSJames Feist std::vector<std::string>& zones) 6775f2caaefSJames Feist { 678b6baeaa4SJames Feist if (config.empty()) 679b6baeaa4SJames Feist { 680b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Empty Zones"; 681b6baeaa4SJames Feist messages::propertyValueFormatError(response->res, 682b6baeaa4SJames Feist nlohmann::json::array(), "Zones"); 683b6baeaa4SJames Feist return false; 684b6baeaa4SJames Feist } 6855f2caaefSJames Feist for (auto& odata : config) 6865f2caaefSJames Feist { 6875f2caaefSJames Feist std::string path; 6885f2caaefSJames Feist if (!redfish::json_util::readJson(odata, response->res, "@odata.id", 6895f2caaefSJames Feist path)) 6905f2caaefSJames Feist { 6915f2caaefSJames Feist return false; 6925f2caaefSJames Feist } 6935f2caaefSJames Feist std::string input; 69461adbda3SJames Feist 69561adbda3SJames Feist // 8 below comes from 69661adbda3SJames Feist // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left 69761adbda3SJames Feist // 0 1 2 3 4 5 6 7 8 69861adbda3SJames Feist if (!dbus::utility::getNthStringFromPath(path, 8, input)) 6995f2caaefSJames Feist { 7005f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << path; 7015f2caaefSJames Feist BMCWEB_LOG_ERROR << "Illegal Type Zones"; 7025f2caaefSJames Feist messages::propertyValueFormatError(response->res, odata.dump(), 7035f2caaefSJames Feist "Zones"); 7045f2caaefSJames Feist return false; 7055f2caaefSJames Feist } 7065f2caaefSJames Feist boost::replace_all(input, "_", " "); 7075f2caaefSJames Feist zones.emplace_back(std::move(input)); 7085f2caaefSJames Feist } 7095f2caaefSJames Feist return true; 7105f2caaefSJames Feist } 7115f2caaefSJames Feist 71223a21a1cSEd Tanous inline const dbus::utility::ManagedItem* 71373df0db0SJames Feist findChassis(const dbus::utility::ManagedObjectType& managedObj, 714b6baeaa4SJames Feist const std::string& value, std::string& chassis) 715b6baeaa4SJames Feist { 716b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n"; 717b6baeaa4SJames Feist 718b6baeaa4SJames Feist std::string escaped = boost::replace_all_copy(value, " ", "_"); 719b6baeaa4SJames Feist escaped = "/" + escaped; 720b6baeaa4SJames Feist auto it = std::find_if( 721b6baeaa4SJames Feist managedObj.begin(), managedObj.end(), [&escaped](const auto& obj) { 722b6baeaa4SJames Feist if (boost::algorithm::ends_with(obj.first.str, escaped)) 723b6baeaa4SJames Feist { 724b6baeaa4SJames Feist BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n"; 725b6baeaa4SJames Feist return true; 726b6baeaa4SJames Feist } 727b6baeaa4SJames Feist return false; 728b6baeaa4SJames Feist }); 729b6baeaa4SJames Feist 730b6baeaa4SJames Feist if (it == managedObj.end()) 731b6baeaa4SJames Feist { 73273df0db0SJames Feist return nullptr; 733b6baeaa4SJames Feist } 734b6baeaa4SJames Feist // 5 comes from <chassis-name> being the 5th element 735b6baeaa4SJames Feist // /xyz/openbmc_project/inventory/system/chassis/<chassis-name> 73673df0db0SJames Feist if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis)) 73773df0db0SJames Feist { 73873df0db0SJames Feist return &(*it); 73973df0db0SJames Feist } 74073df0db0SJames Feist 74173df0db0SJames Feist return nullptr; 742b6baeaa4SJames Feist } 743b6baeaa4SJames Feist 74423a21a1cSEd Tanous inline CreatePIDRet createPidInterface( 7458d1b46d7Szhanghch05 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type, 746b5a76932SEd Tanous const nlohmann::json::iterator& it, const std::string& path, 74783ff9ab6SJames Feist const dbus::utility::ManagedObjectType& managedObj, bool createNewObject, 74883ff9ab6SJames Feist boost::container::flat_map<std::string, dbus::utility::DbusVariantType>& 74983ff9ab6SJames Feist output, 75073df0db0SJames Feist std::string& chassis, const std::string& profile) 75183ff9ab6SJames Feist { 75283ff9ab6SJames Feist 7535f2caaefSJames Feist // common deleter 754b6baeaa4SJames Feist if (it.value() == nullptr) 7555f2caaefSJames Feist { 7565f2caaefSJames Feist std::string iface; 7575f2caaefSJames Feist if (type == "PidControllers" || type == "FanControllers") 7585f2caaefSJames Feist { 7595f2caaefSJames Feist iface = pidConfigurationIface; 7605f2caaefSJames Feist } 7615f2caaefSJames Feist else if (type == "FanZones") 7625f2caaefSJames Feist { 7635f2caaefSJames Feist iface = pidZoneConfigurationIface; 7645f2caaefSJames Feist } 7655f2caaefSJames Feist else if (type == "StepwiseControllers") 7665f2caaefSJames Feist { 7675f2caaefSJames Feist iface = stepwiseConfigurationIface; 7685f2caaefSJames Feist } 7695f2caaefSJames Feist else 7705f2caaefSJames Feist { 771a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 7725f2caaefSJames Feist messages::propertyUnknown(response->res, type); 7735f2caaefSJames Feist return CreatePIDRet::fail; 7745f2caaefSJames Feist } 7756ee7f774SJames Feist 7766ee7f774SJames Feist BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n"; 7775f2caaefSJames Feist // delete interface 7785f2caaefSJames Feist crow::connections::systemBus->async_method_call( 7795f2caaefSJames Feist [response, path](const boost::system::error_code ec) { 7805f2caaefSJames Feist if (ec) 7815f2caaefSJames Feist { 7825f2caaefSJames Feist BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec; 7835f2caaefSJames Feist messages::internalError(response->res); 784b6baeaa4SJames Feist return; 7855f2caaefSJames Feist } 786b6baeaa4SJames Feist messages::success(response->res); 7875f2caaefSJames Feist }, 7885f2caaefSJames Feist "xyz.openbmc_project.EntityManager", path, iface, "Delete"); 7895f2caaefSJames Feist return CreatePIDRet::del; 7905f2caaefSJames Feist } 7915f2caaefSJames Feist 79273df0db0SJames Feist const dbus::utility::ManagedItem* managedItem = nullptr; 793b6baeaa4SJames Feist if (!createNewObject) 794b6baeaa4SJames Feist { 795b6baeaa4SJames Feist // if we aren't creating a new object, we should be able to find it on 796b6baeaa4SJames Feist // d-bus 79773df0db0SJames Feist managedItem = findChassis(managedObj, it.key(), chassis); 79873df0db0SJames Feist if (managedItem == nullptr) 799b6baeaa4SJames Feist { 800b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 801b6baeaa4SJames Feist messages::invalidObject(response->res, it.key()); 802b6baeaa4SJames Feist return CreatePIDRet::fail; 803b6baeaa4SJames Feist } 804b6baeaa4SJames Feist } 805b6baeaa4SJames Feist 80673df0db0SJames Feist if (profile.size() && 80773df0db0SJames Feist (type == "PidControllers" || type == "FanControllers" || 80873df0db0SJames Feist type == "StepwiseControllers")) 80973df0db0SJames Feist { 81073df0db0SJames Feist if (managedItem == nullptr) 81173df0db0SJames Feist { 81273df0db0SJames Feist output["Profiles"] = std::vector<std::string>{profile}; 81373df0db0SJames Feist } 81473df0db0SJames Feist else 81573df0db0SJames Feist { 81673df0db0SJames Feist std::string interface; 81773df0db0SJames Feist if (type == "StepwiseControllers") 81873df0db0SJames Feist { 81973df0db0SJames Feist interface = stepwiseConfigurationIface; 82073df0db0SJames Feist } 82173df0db0SJames Feist else 82273df0db0SJames Feist { 82373df0db0SJames Feist interface = pidConfigurationIface; 82473df0db0SJames Feist } 82573df0db0SJames Feist auto findConfig = managedItem->second.find(interface); 82673df0db0SJames Feist if (findConfig == managedItem->second.end()) 82773df0db0SJames Feist { 82873df0db0SJames Feist BMCWEB_LOG_ERROR 82973df0db0SJames Feist << "Failed to find interface in managed object"; 83073df0db0SJames Feist messages::internalError(response->res); 83173df0db0SJames Feist return CreatePIDRet::fail; 83273df0db0SJames Feist } 83373df0db0SJames Feist auto findProfiles = findConfig->second.find("Profiles"); 83473df0db0SJames Feist if (findProfiles != findConfig->second.end()) 83573df0db0SJames Feist { 83673df0db0SJames Feist const std::vector<std::string>* curProfiles = 83773df0db0SJames Feist std::get_if<std::vector<std::string>>( 83873df0db0SJames Feist &(findProfiles->second)); 83973df0db0SJames Feist if (curProfiles == nullptr) 84073df0db0SJames Feist { 84173df0db0SJames Feist BMCWEB_LOG_ERROR << "Illegal profiles in managed object"; 84273df0db0SJames Feist messages::internalError(response->res); 84373df0db0SJames Feist return CreatePIDRet::fail; 84473df0db0SJames Feist } 84573df0db0SJames Feist if (std::find(curProfiles->begin(), curProfiles->end(), 84673df0db0SJames Feist profile) == curProfiles->end()) 84773df0db0SJames Feist { 84873df0db0SJames Feist std::vector<std::string> newProfiles = *curProfiles; 84973df0db0SJames Feist newProfiles.push_back(profile); 85073df0db0SJames Feist output["Profiles"] = newProfiles; 85173df0db0SJames Feist } 85273df0db0SJames Feist } 85373df0db0SJames Feist } 85473df0db0SJames Feist } 85573df0db0SJames Feist 85683ff9ab6SJames Feist if (type == "PidControllers" || type == "FanControllers") 85783ff9ab6SJames Feist { 85883ff9ab6SJames Feist if (createNewObject) 85983ff9ab6SJames Feist { 86083ff9ab6SJames Feist output["Class"] = type == "PidControllers" ? std::string("temp") 86183ff9ab6SJames Feist : std::string("fan"); 86283ff9ab6SJames Feist output["Type"] = std::string("Pid"); 86383ff9ab6SJames Feist } 8645f2caaefSJames Feist 8655f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 8665f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 8675f2caaefSJames Feist std::optional<std::vector<std::string>> outputs; 8685f2caaefSJames Feist std::map<std::string, std::optional<double>> doubles; 869b943aaefSJames Feist std::optional<std::string> setpointOffset; 8705f2caaefSJames Feist if (!redfish::json_util::readJson( 871b6baeaa4SJames Feist it.value(), response->res, "Inputs", inputs, "Outputs", outputs, 8725f2caaefSJames Feist "Zones", zones, "FFGainCoefficient", 8735f2caaefSJames Feist doubles["FFGainCoefficient"], "FFOffCoefficient", 8745f2caaefSJames Feist doubles["FFOffCoefficient"], "ICoefficient", 8755f2caaefSJames Feist doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"], 8765f2caaefSJames Feist "ILimitMin", doubles["ILimitMin"], "OutLimitMax", 8775f2caaefSJames Feist doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"], 8785f2caaefSJames Feist "PCoefficient", doubles["PCoefficient"], "SetPoint", 879b943aaefSJames Feist doubles["SetPoint"], "SetPointOffset", setpointOffset, 880b943aaefSJames Feist "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"], 881b943aaefSJames Feist "PositiveHysteresis", doubles["PositiveHysteresis"], 882b943aaefSJames Feist "NegativeHysteresis", doubles["NegativeHysteresis"])) 88383ff9ab6SJames Feist { 88471f52d96SEd Tanous BMCWEB_LOG_ERROR 88571f52d96SEd Tanous << "Illegal Property " 88671f52d96SEd Tanous << it.value().dump(2, ' ', true, 88771f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 8885f2caaefSJames Feist return CreatePIDRet::fail; 88983ff9ab6SJames Feist } 8905f2caaefSJames Feist if (zones) 8915f2caaefSJames Feist { 8925f2caaefSJames Feist std::vector<std::string> zonesStr; 8935f2caaefSJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStr)) 8945f2caaefSJames Feist { 895a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 8965f2caaefSJames Feist return CreatePIDRet::fail; 8975f2caaefSJames Feist } 898b6baeaa4SJames Feist if (chassis.empty() && 899b6baeaa4SJames Feist !findChassis(managedObj, zonesStr[0], chassis)) 900b6baeaa4SJames Feist { 901b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 902b6baeaa4SJames Feist messages::invalidObject(response->res, it.key()); 903b6baeaa4SJames Feist return CreatePIDRet::fail; 904b6baeaa4SJames Feist } 905b6baeaa4SJames Feist 9065f2caaefSJames Feist output["Zones"] = std::move(zonesStr); 9075f2caaefSJames Feist } 9085f2caaefSJames Feist if (inputs || outputs) 9095f2caaefSJames Feist { 9105f2caaefSJames Feist std::array<std::optional<std::vector<std::string>>*, 2> containers = 9115f2caaefSJames Feist {&inputs, &outputs}; 9125f2caaefSJames Feist size_t index = 0; 9135f2caaefSJames Feist for (const auto& containerPtr : containers) 9145f2caaefSJames Feist { 9155f2caaefSJames Feist std::optional<std::vector<std::string>>& container = 9165f2caaefSJames Feist *containerPtr; 9175f2caaefSJames Feist if (!container) 9185f2caaefSJames Feist { 9195f2caaefSJames Feist index++; 9205f2caaefSJames Feist continue; 92183ff9ab6SJames Feist } 92283ff9ab6SJames Feist 9235f2caaefSJames Feist for (std::string& value : *container) 92483ff9ab6SJames Feist { 9255f2caaefSJames Feist boost::replace_all(value, "_", " "); 92683ff9ab6SJames Feist } 9275f2caaefSJames Feist std::string key; 9285f2caaefSJames Feist if (index == 0) 9295f2caaefSJames Feist { 9305f2caaefSJames Feist key = "Inputs"; 9315f2caaefSJames Feist } 9325f2caaefSJames Feist else 9335f2caaefSJames Feist { 9345f2caaefSJames Feist key = "Outputs"; 9355f2caaefSJames Feist } 9365f2caaefSJames Feist output[key] = *container; 9375f2caaefSJames Feist index++; 9385f2caaefSJames Feist } 93983ff9ab6SJames Feist } 94083ff9ab6SJames Feist 941b943aaefSJames Feist if (setpointOffset) 942b943aaefSJames Feist { 943b943aaefSJames Feist // translate between redfish and dbus names 944b943aaefSJames Feist if (*setpointOffset == "UpperThresholdNonCritical") 945b943aaefSJames Feist { 946b943aaefSJames Feist output["SetPointOffset"] = std::string("WarningLow"); 947b943aaefSJames Feist } 948b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdNonCritical") 949b943aaefSJames Feist { 950b943aaefSJames Feist output["SetPointOffset"] = std::string("WarningHigh"); 951b943aaefSJames Feist } 952b943aaefSJames Feist else if (*setpointOffset == "LowerThresholdCritical") 953b943aaefSJames Feist { 954b943aaefSJames Feist output["SetPointOffset"] = std::string("CriticalLow"); 955b943aaefSJames Feist } 956b943aaefSJames Feist else if (*setpointOffset == "UpperThresholdCritical") 957b943aaefSJames Feist { 958b943aaefSJames Feist output["SetPointOffset"] = std::string("CriticalHigh"); 959b943aaefSJames Feist } 960b943aaefSJames Feist else 961b943aaefSJames Feist { 962b943aaefSJames Feist BMCWEB_LOG_ERROR << "Invalid setpointoffset " 963b943aaefSJames Feist << *setpointOffset; 964b943aaefSJames Feist messages::invalidObject(response->res, it.key()); 965b943aaefSJames Feist return CreatePIDRet::fail; 966b943aaefSJames Feist } 967b943aaefSJames Feist } 968b943aaefSJames Feist 96983ff9ab6SJames Feist // doubles 9705f2caaefSJames Feist for (const auto& pairs : doubles) 97183ff9ab6SJames Feist { 9725f2caaefSJames Feist if (!pairs.second) 97383ff9ab6SJames Feist { 9745f2caaefSJames Feist continue; 97583ff9ab6SJames Feist } 9765f2caaefSJames Feist BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second; 9775f2caaefSJames Feist output[pairs.first] = *(pairs.second); 9785f2caaefSJames Feist } 97983ff9ab6SJames Feist } 98083ff9ab6SJames Feist 98183ff9ab6SJames Feist else if (type == "FanZones") 98283ff9ab6SJames Feist { 98383ff9ab6SJames Feist output["Type"] = std::string("Pid.Zone"); 98483ff9ab6SJames Feist 9855f2caaefSJames Feist std::optional<nlohmann::json> chassisContainer; 9865f2caaefSJames Feist std::optional<double> failSafePercent; 987d3ec07f8SJames Feist std::optional<double> minThermalOutput; 988b6baeaa4SJames Feist if (!redfish::json_util::readJson(it.value(), response->res, "Chassis", 9895f2caaefSJames Feist chassisContainer, "FailSafePercent", 990d3ec07f8SJames Feist failSafePercent, "MinThermalOutput", 991d3ec07f8SJames Feist minThermalOutput)) 99283ff9ab6SJames Feist { 99371f52d96SEd Tanous BMCWEB_LOG_ERROR 99471f52d96SEd Tanous << "Illegal Property " 99571f52d96SEd Tanous << it.value().dump(2, ' ', true, 99671f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 99783ff9ab6SJames Feist return CreatePIDRet::fail; 99883ff9ab6SJames Feist } 9995f2caaefSJames Feist 10005f2caaefSJames Feist if (chassisContainer) 100183ff9ab6SJames Feist { 10025f2caaefSJames Feist 10035f2caaefSJames Feist std::string chassisId; 10045f2caaefSJames Feist if (!redfish::json_util::readJson(*chassisContainer, response->res, 10055f2caaefSJames Feist "@odata.id", chassisId)) 10065f2caaefSJames Feist { 100771f52d96SEd Tanous BMCWEB_LOG_ERROR 100871f52d96SEd Tanous << "Illegal Property " 100971f52d96SEd Tanous << chassisContainer->dump( 101071f52d96SEd Tanous 2, ' ', true, 101171f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 101283ff9ab6SJames Feist return CreatePIDRet::fail; 101383ff9ab6SJames Feist } 101483ff9ab6SJames Feist 1015717794d5SAppaRao Puli // /redfish/v1/chassis/chassis_name/ 10165f2caaefSJames Feist if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis)) 101783ff9ab6SJames Feist { 10185f2caaefSJames Feist BMCWEB_LOG_ERROR << "Got invalid path " << chassisId; 10195f2caaefSJames Feist messages::invalidObject(response->res, chassisId); 102083ff9ab6SJames Feist return CreatePIDRet::fail; 102183ff9ab6SJames Feist } 102283ff9ab6SJames Feist } 1023d3ec07f8SJames Feist if (minThermalOutput) 102483ff9ab6SJames Feist { 1025d3ec07f8SJames Feist output["MinThermalOutput"] = *minThermalOutput; 10265f2caaefSJames Feist } 10275f2caaefSJames Feist if (failSafePercent) 102883ff9ab6SJames Feist { 10295f2caaefSJames Feist output["FailSafePercent"] = *failSafePercent; 10305f2caaefSJames Feist } 10315f2caaefSJames Feist } 10325f2caaefSJames Feist else if (type == "StepwiseControllers") 10335f2caaefSJames Feist { 10345f2caaefSJames Feist output["Type"] = std::string("Stepwise"); 10355f2caaefSJames Feist 10365f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> zones; 10375f2caaefSJames Feist std::optional<std::vector<nlohmann::json>> steps; 10385f2caaefSJames Feist std::optional<std::vector<std::string>> inputs; 10395f2caaefSJames Feist std::optional<double> positiveHysteresis; 10405f2caaefSJames Feist std::optional<double> negativeHysteresis; 1041c33a90ecSJames Feist std::optional<std::string> direction; // upper clipping curve vs lower 10425f2caaefSJames Feist if (!redfish::json_util::readJson( 1043b6baeaa4SJames Feist it.value(), response->res, "Zones", zones, "Steps", steps, 1044b6baeaa4SJames Feist "Inputs", inputs, "PositiveHysteresis", positiveHysteresis, 1045c33a90ecSJames Feist "NegativeHysteresis", negativeHysteresis, "Direction", 1046c33a90ecSJames Feist direction)) 10475f2caaefSJames Feist { 104871f52d96SEd Tanous BMCWEB_LOG_ERROR 104971f52d96SEd Tanous << "Illegal Property " 105071f52d96SEd Tanous << it.value().dump(2, ' ', true, 105171f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 105283ff9ab6SJames Feist return CreatePIDRet::fail; 105383ff9ab6SJames Feist } 10545f2caaefSJames Feist 10555f2caaefSJames Feist if (zones) 105683ff9ab6SJames Feist { 1057b6baeaa4SJames Feist std::vector<std::string> zonesStrs; 1058b6baeaa4SJames Feist if (!getZonesFromJsonReq(response, *zones, zonesStrs)) 10595f2caaefSJames Feist { 1060a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Zones"; 106183ff9ab6SJames Feist return CreatePIDRet::fail; 106283ff9ab6SJames Feist } 1063b6baeaa4SJames Feist if (chassis.empty() && 1064b6baeaa4SJames Feist !findChassis(managedObj, zonesStrs[0], chassis)) 1065b6baeaa4SJames Feist { 1066b6baeaa4SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config patch"; 1067b6baeaa4SJames Feist messages::invalidObject(response->res, it.key()); 1068b6baeaa4SJames Feist return CreatePIDRet::fail; 1069b6baeaa4SJames Feist } 1070b6baeaa4SJames Feist output["Zones"] = std::move(zonesStrs); 10715f2caaefSJames Feist } 10725f2caaefSJames Feist if (steps) 10735f2caaefSJames Feist { 10745f2caaefSJames Feist std::vector<double> readings; 10755f2caaefSJames Feist std::vector<double> outputs; 10765f2caaefSJames Feist for (auto& step : *steps) 10775f2caaefSJames Feist { 10785f2caaefSJames Feist double target; 107923a21a1cSEd Tanous double out; 10805f2caaefSJames Feist 10815f2caaefSJames Feist if (!redfish::json_util::readJson(step, response->res, "Target", 108223a21a1cSEd Tanous target, "Output", out)) 10835f2caaefSJames Feist { 108471f52d96SEd Tanous BMCWEB_LOG_ERROR 108571f52d96SEd Tanous << "Illegal Property " 108671f52d96SEd Tanous << it.value().dump( 108771f52d96SEd Tanous 2, ' ', true, 108871f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 10895f2caaefSJames Feist return CreatePIDRet::fail; 10905f2caaefSJames Feist } 10915f2caaefSJames Feist readings.emplace_back(target); 109223a21a1cSEd Tanous outputs.emplace_back(out); 10935f2caaefSJames Feist } 10945f2caaefSJames Feist output["Reading"] = std::move(readings); 10955f2caaefSJames Feist output["Output"] = std::move(outputs); 10965f2caaefSJames Feist } 10975f2caaefSJames Feist if (inputs) 10985f2caaefSJames Feist { 10995f2caaefSJames Feist for (std::string& value : *inputs) 11005f2caaefSJames Feist { 11015f2caaefSJames Feist boost::replace_all(value, "_", " "); 11025f2caaefSJames Feist } 11035f2caaefSJames Feist output["Inputs"] = std::move(*inputs); 11045f2caaefSJames Feist } 11055f2caaefSJames Feist if (negativeHysteresis) 11065f2caaefSJames Feist { 11075f2caaefSJames Feist output["NegativeHysteresis"] = *negativeHysteresis; 11085f2caaefSJames Feist } 11095f2caaefSJames Feist if (positiveHysteresis) 11105f2caaefSJames Feist { 11115f2caaefSJames Feist output["PositiveHysteresis"] = *positiveHysteresis; 111283ff9ab6SJames Feist } 1113c33a90ecSJames Feist if (direction) 1114c33a90ecSJames Feist { 1115c33a90ecSJames Feist constexpr const std::array<const char*, 2> allowedDirections = { 1116c33a90ecSJames Feist "Ceiling", "Floor"}; 1117c33a90ecSJames Feist if (std::find(allowedDirections.begin(), allowedDirections.end(), 1118c33a90ecSJames Feist *direction) == allowedDirections.end()) 1119c33a90ecSJames Feist { 1120c33a90ecSJames Feist messages::propertyValueTypeError(response->res, "Direction", 1121c33a90ecSJames Feist *direction); 1122c33a90ecSJames Feist return CreatePIDRet::fail; 1123c33a90ecSJames Feist } 1124c33a90ecSJames Feist output["Class"] = *direction; 1125c33a90ecSJames Feist } 112683ff9ab6SJames Feist } 112783ff9ab6SJames Feist else 112883ff9ab6SJames Feist { 1129a0744d38SGunnar Mills BMCWEB_LOG_ERROR << "Illegal Type " << type; 113035a62c7cSJason M. Bills messages::propertyUnknown(response->res, type); 113183ff9ab6SJames Feist return CreatePIDRet::fail; 113283ff9ab6SJames Feist } 113383ff9ab6SJames Feist return CreatePIDRet::patch; 113483ff9ab6SJames Feist } 113573df0db0SJames Feist struct GetPIDValues : std::enable_shared_from_this<GetPIDValues> 113673df0db0SJames Feist { 113783ff9ab6SJames Feist 11388d1b46d7Szhanghch05 GetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) : 113923a21a1cSEd Tanous asyncResp(asyncRespIn) 114073df0db0SJames Feist 11411214b7e7SGunnar Mills {} 11429c310685SBorawski.Lukasz 114373df0db0SJames Feist void run() 11445b4aa86bSJames Feist { 114573df0db0SJames Feist std::shared_ptr<GetPIDValues> self = shared_from_this(); 114673df0db0SJames Feist 114773df0db0SJames Feist // get all configurations 11485b4aa86bSJames Feist crow::connections::systemBus->async_method_call( 114973df0db0SJames Feist [self](const boost::system::error_code ec, 115023a21a1cSEd Tanous const crow::openbmc_mapper::GetSubTreeType& subtreeLocal) { 11515b4aa86bSJames Feist if (ec) 11525b4aa86bSJames Feist { 11535b4aa86bSJames Feist BMCWEB_LOG_ERROR << ec; 115473df0db0SJames Feist messages::internalError(self->asyncResp->res); 115573df0db0SJames Feist return; 115673df0db0SJames Feist } 115723a21a1cSEd Tanous self->subtree = subtreeLocal; 115873df0db0SJames Feist }, 115973df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", 116073df0db0SJames Feist "/xyz/openbmc_project/object_mapper", 116173df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 116273df0db0SJames Feist std::array<const char*, 4>{ 116373df0db0SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 116473df0db0SJames Feist objectManagerIface, stepwiseConfigurationIface}); 116573df0db0SJames Feist 116673df0db0SJames Feist // at the same time get the selected profile 116773df0db0SJames Feist crow::connections::systemBus->async_method_call( 116873df0db0SJames Feist [self](const boost::system::error_code ec, 116923a21a1cSEd Tanous const crow::openbmc_mapper::GetSubTreeType& subtreeLocal) { 117023a21a1cSEd Tanous if (ec || subtreeLocal.empty()) 117173df0db0SJames Feist { 117273df0db0SJames Feist return; 117373df0db0SJames Feist } 117423a21a1cSEd Tanous if (subtreeLocal[0].second.size() != 1) 117573df0db0SJames Feist { 117673df0db0SJames Feist // invalid mapper response, should never happen 117773df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error"; 117873df0db0SJames Feist messages::internalError(self->asyncResp->res); 11795b4aa86bSJames Feist return; 11805b4aa86bSJames Feist } 11815b4aa86bSJames Feist 118223a21a1cSEd Tanous const std::string& path = subtreeLocal[0].first; 118323a21a1cSEd Tanous const std::string& owner = subtreeLocal[0].second[0].first; 118473df0db0SJames Feist crow::connections::systemBus->async_method_call( 118573df0db0SJames Feist [path, owner, self]( 118623a21a1cSEd Tanous const boost::system::error_code ec2, 118773df0db0SJames Feist const boost::container::flat_map< 118873df0db0SJames Feist std::string, std::variant<std::vector<std::string>, 118973df0db0SJames Feist std::string>>& resp) { 119023a21a1cSEd Tanous if (ec2) 119173df0db0SJames Feist { 119273df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: Can't get " 119373df0db0SJames Feist "thermalModeIface " 119473df0db0SJames Feist << path; 119573df0db0SJames Feist messages::internalError(self->asyncResp->res); 119673df0db0SJames Feist return; 119773df0db0SJames Feist } 1198271584abSEd Tanous const std::string* current = nullptr; 1199271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 120073df0db0SJames Feist for (auto& [key, value] : resp) 120173df0db0SJames Feist { 120273df0db0SJames Feist if (key == "Current") 120373df0db0SJames Feist { 120473df0db0SJames Feist current = std::get_if<std::string>(&value); 120573df0db0SJames Feist if (current == nullptr) 120673df0db0SJames Feist { 120773df0db0SJames Feist BMCWEB_LOG_ERROR 120873df0db0SJames Feist << "GetPIDValues: thermal mode " 120973df0db0SJames Feist "iface invalid " 121073df0db0SJames Feist << path; 121173df0db0SJames Feist messages::internalError( 121273df0db0SJames Feist self->asyncResp->res); 121373df0db0SJames Feist return; 121473df0db0SJames Feist } 121573df0db0SJames Feist } 121673df0db0SJames Feist if (key == "Supported") 121773df0db0SJames Feist { 121873df0db0SJames Feist supported = 121973df0db0SJames Feist std::get_if<std::vector<std::string>>( 122073df0db0SJames Feist &value); 122173df0db0SJames Feist if (supported == nullptr) 122273df0db0SJames Feist { 122373df0db0SJames Feist BMCWEB_LOG_ERROR 122473df0db0SJames Feist << "GetPIDValues: thermal mode " 122573df0db0SJames Feist "iface invalid" 122673df0db0SJames Feist << path; 122773df0db0SJames Feist messages::internalError( 122873df0db0SJames Feist self->asyncResp->res); 122973df0db0SJames Feist return; 123073df0db0SJames Feist } 123173df0db0SJames Feist } 123273df0db0SJames Feist } 123373df0db0SJames Feist if (current == nullptr || supported == nullptr) 123473df0db0SJames Feist { 123573df0db0SJames Feist BMCWEB_LOG_ERROR << "GetPIDValues: thermal mode " 123673df0db0SJames Feist "iface invalid " 123773df0db0SJames Feist << path; 123873df0db0SJames Feist messages::internalError(self->asyncResp->res); 123973df0db0SJames Feist return; 124073df0db0SJames Feist } 124173df0db0SJames Feist self->currentProfile = *current; 124273df0db0SJames Feist self->supportedProfiles = *supported; 124373df0db0SJames Feist }, 124473df0db0SJames Feist owner, path, "org.freedesktop.DBus.Properties", "GetAll", 124573df0db0SJames Feist thermalModeIface); 124673df0db0SJames Feist }, 124773df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", 124873df0db0SJames Feist "/xyz/openbmc_project/object_mapper", 124973df0db0SJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 125073df0db0SJames Feist std::array<const char*, 1>{thermalModeIface}); 125173df0db0SJames Feist } 125273df0db0SJames Feist 125373df0db0SJames Feist ~GetPIDValues() 125473df0db0SJames Feist { 125573df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 125673df0db0SJames Feist { 125773df0db0SJames Feist return; 125873df0db0SJames Feist } 12595b4aa86bSJames Feist // create map of <connection, path to objMgr>> 126073df0db0SJames Feist boost::container::flat_map<std::string, std::string> objectMgrPaths; 12616bce33bcSJames Feist boost::container::flat_set<std::string> calledConnections; 12625b4aa86bSJames Feist for (const auto& pathGroup : subtree) 12635b4aa86bSJames Feist { 12645b4aa86bSJames Feist for (const auto& connectionGroup : pathGroup.second) 12655b4aa86bSJames Feist { 12666bce33bcSJames Feist auto findConnection = 12676bce33bcSJames Feist calledConnections.find(connectionGroup.first); 12686bce33bcSJames Feist if (findConnection != calledConnections.end()) 12696bce33bcSJames Feist { 12706bce33bcSJames Feist break; 12716bce33bcSJames Feist } 127273df0db0SJames Feist for (const std::string& interface : connectionGroup.second) 12735b4aa86bSJames Feist { 12745b4aa86bSJames Feist if (interface == objectManagerIface) 12755b4aa86bSJames Feist { 127673df0db0SJames Feist objectMgrPaths[connectionGroup.first] = pathGroup.first; 12775b4aa86bSJames Feist } 12785b4aa86bSJames Feist // this list is alphabetical, so we 12795b4aa86bSJames Feist // should have found the objMgr by now 12805b4aa86bSJames Feist if (interface == pidConfigurationIface || 1281b7a08d04SJames Feist interface == pidZoneConfigurationIface || 1282b7a08d04SJames Feist interface == stepwiseConfigurationIface) 12835b4aa86bSJames Feist { 12845b4aa86bSJames Feist auto findObjMgr = 12855b4aa86bSJames Feist objectMgrPaths.find(connectionGroup.first); 12865b4aa86bSJames Feist if (findObjMgr == objectMgrPaths.end()) 12875b4aa86bSJames Feist { 12885b4aa86bSJames Feist BMCWEB_LOG_DEBUG << connectionGroup.first 12895b4aa86bSJames Feist << "Has no Object Manager"; 12905b4aa86bSJames Feist continue; 12915b4aa86bSJames Feist } 12926bce33bcSJames Feist 12936bce33bcSJames Feist calledConnections.insert(connectionGroup.first); 12946bce33bcSJames Feist 129573df0db0SJames Feist asyncPopulatePid(findObjMgr->first, findObjMgr->second, 129673df0db0SJames Feist currentProfile, supportedProfiles, 129773df0db0SJames Feist asyncResp); 12985b4aa86bSJames Feist break; 12995b4aa86bSJames Feist } 13005b4aa86bSJames Feist } 13015b4aa86bSJames Feist } 13025b4aa86bSJames Feist } 130373df0db0SJames Feist } 130473df0db0SJames Feist 130573df0db0SJames Feist std::vector<std::string> supportedProfiles; 130673df0db0SJames Feist std::string currentProfile; 130773df0db0SJames Feist crow::openbmc_mapper::GetSubTreeType subtree; 13088d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 130973df0db0SJames Feist }; 131073df0db0SJames Feist 131173df0db0SJames Feist struct SetPIDValues : std::enable_shared_from_this<SetPIDValues> 131273df0db0SJames Feist { 131373df0db0SJames Feist 13148d1b46d7Szhanghch05 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn, 131573df0db0SJames Feist nlohmann::json& data) : 1316271584abSEd Tanous asyncResp(asyncRespIn) 131773df0db0SJames Feist { 131873df0db0SJames Feist 131973df0db0SJames Feist std::optional<nlohmann::json> pidControllers; 132073df0db0SJames Feist std::optional<nlohmann::json> fanControllers; 132173df0db0SJames Feist std::optional<nlohmann::json> fanZones; 132273df0db0SJames Feist std::optional<nlohmann::json> stepwiseControllers; 132373df0db0SJames Feist 132473df0db0SJames Feist if (!redfish::json_util::readJson( 132573df0db0SJames Feist data, asyncResp->res, "PidControllers", pidControllers, 132673df0db0SJames Feist "FanControllers", fanControllers, "FanZones", fanZones, 132773df0db0SJames Feist "StepwiseControllers", stepwiseControllers, "Profile", profile)) 132873df0db0SJames Feist { 132971f52d96SEd Tanous BMCWEB_LOG_ERROR 133071f52d96SEd Tanous << "Illegal Property " 133171f52d96SEd Tanous << data.dump(2, ' ', true, 133271f52d96SEd Tanous nlohmann::json::error_handler_t::replace); 133373df0db0SJames Feist return; 133473df0db0SJames Feist } 133573df0db0SJames Feist configuration.emplace_back("PidControllers", std::move(pidControllers)); 133673df0db0SJames Feist configuration.emplace_back("FanControllers", std::move(fanControllers)); 133773df0db0SJames Feist configuration.emplace_back("FanZones", std::move(fanZones)); 133873df0db0SJames Feist configuration.emplace_back("StepwiseControllers", 133973df0db0SJames Feist std::move(stepwiseControllers)); 134073df0db0SJames Feist } 134173df0db0SJames Feist void run() 134273df0db0SJames Feist { 134373df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 134473df0db0SJames Feist { 134573df0db0SJames Feist return; 134673df0db0SJames Feist } 134773df0db0SJames Feist 134873df0db0SJames Feist std::shared_ptr<SetPIDValues> self = shared_from_this(); 134973df0db0SJames Feist 135073df0db0SJames Feist // todo(james): might make sense to do a mapper call here if this 135173df0db0SJames Feist // interface gets more traction 135273df0db0SJames Feist crow::connections::systemBus->async_method_call( 135373df0db0SJames Feist [self](const boost::system::error_code ec, 1354271584abSEd Tanous dbus::utility::ManagedObjectType& mObj) { 135573df0db0SJames Feist if (ec) 135673df0db0SJames Feist { 135773df0db0SJames Feist BMCWEB_LOG_ERROR << "Error communicating to Entity Manager"; 135873df0db0SJames Feist messages::internalError(self->asyncResp->res); 135973df0db0SJames Feist return; 136073df0db0SJames Feist } 1361e69d9de2SJames Feist const std::array<const char*, 3> configurations = { 1362e69d9de2SJames Feist pidConfigurationIface, pidZoneConfigurationIface, 1363e69d9de2SJames Feist stepwiseConfigurationIface}; 1364e69d9de2SJames Feist 136514b0b8d5SJames Feist for (const auto& [path, object] : mObj) 1366e69d9de2SJames Feist { 136714b0b8d5SJames Feist for (const auto& [interface, _] : object) 1368e69d9de2SJames Feist { 1369e69d9de2SJames Feist if (std::find(configurations.begin(), 1370e69d9de2SJames Feist configurations.end(), 1371e69d9de2SJames Feist interface) != configurations.end()) 1372e69d9de2SJames Feist { 137314b0b8d5SJames Feist self->objectCount++; 1374e69d9de2SJames Feist break; 1375e69d9de2SJames Feist } 1376e69d9de2SJames Feist } 1377e69d9de2SJames Feist } 1378271584abSEd Tanous self->managedObj = std::move(mObj); 137973df0db0SJames Feist }, 138073df0db0SJames Feist "xyz.openbmc_project.EntityManager", "/", objectManagerIface, 138173df0db0SJames Feist "GetManagedObjects"); 138273df0db0SJames Feist 138373df0db0SJames Feist // at the same time get the profile information 138473df0db0SJames Feist crow::connections::systemBus->async_method_call( 138573df0db0SJames Feist [self](const boost::system::error_code ec, 138673df0db0SJames Feist const crow::openbmc_mapper::GetSubTreeType& subtree) { 138773df0db0SJames Feist if (ec || subtree.empty()) 138873df0db0SJames Feist { 138973df0db0SJames Feist return; 139073df0db0SJames Feist } 139173df0db0SJames Feist if (subtree[0].second.empty()) 139273df0db0SJames Feist { 139373df0db0SJames Feist // invalid mapper response, should never happen 139473df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error"; 139573df0db0SJames Feist messages::internalError(self->asyncResp->res); 139673df0db0SJames Feist return; 139773df0db0SJames Feist } 139873df0db0SJames Feist 139973df0db0SJames Feist const std::string& path = subtree[0].first; 140073df0db0SJames Feist const std::string& owner = subtree[0].second[0].first; 140173df0db0SJames Feist crow::connections::systemBus->async_method_call( 140273df0db0SJames Feist [self, path, owner]( 1403cb13a392SEd Tanous const boost::system::error_code ec2, 140473df0db0SJames Feist const boost::container::flat_map< 140573df0db0SJames Feist std::string, std::variant<std::vector<std::string>, 1406271584abSEd Tanous std::string>>& r) { 1407cb13a392SEd Tanous if (ec2) 140873df0db0SJames Feist { 140973df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: Can't get " 141073df0db0SJames Feist "thermalModeIface " 141173df0db0SJames Feist << path; 141273df0db0SJames Feist messages::internalError(self->asyncResp->res); 141373df0db0SJames Feist return; 141473df0db0SJames Feist } 1415271584abSEd Tanous const std::string* current = nullptr; 1416271584abSEd Tanous const std::vector<std::string>* supported = nullptr; 1417271584abSEd Tanous for (auto& [key, value] : r) 141873df0db0SJames Feist { 141973df0db0SJames Feist if (key == "Current") 142073df0db0SJames Feist { 142173df0db0SJames Feist current = std::get_if<std::string>(&value); 142273df0db0SJames Feist if (current == nullptr) 142373df0db0SJames Feist { 142473df0db0SJames Feist BMCWEB_LOG_ERROR 142573df0db0SJames Feist << "SetPIDValues: thermal mode " 142673df0db0SJames Feist "iface invalid " 142773df0db0SJames Feist << path; 142873df0db0SJames Feist messages::internalError( 142973df0db0SJames Feist self->asyncResp->res); 143073df0db0SJames Feist return; 143173df0db0SJames Feist } 143273df0db0SJames Feist } 143373df0db0SJames Feist if (key == "Supported") 143473df0db0SJames Feist { 143573df0db0SJames Feist supported = 143673df0db0SJames Feist std::get_if<std::vector<std::string>>( 143773df0db0SJames Feist &value); 143873df0db0SJames Feist if (supported == nullptr) 143973df0db0SJames Feist { 144073df0db0SJames Feist BMCWEB_LOG_ERROR 144173df0db0SJames Feist << "SetPIDValues: thermal mode " 144273df0db0SJames Feist "iface invalid" 144373df0db0SJames Feist << path; 144473df0db0SJames Feist messages::internalError( 144573df0db0SJames Feist self->asyncResp->res); 144673df0db0SJames Feist return; 144773df0db0SJames Feist } 144873df0db0SJames Feist } 144973df0db0SJames Feist } 145073df0db0SJames Feist if (current == nullptr || supported == nullptr) 145173df0db0SJames Feist { 145273df0db0SJames Feist BMCWEB_LOG_ERROR << "SetPIDValues: thermal mode " 145373df0db0SJames Feist "iface invalid " 145473df0db0SJames Feist << path; 145573df0db0SJames Feist messages::internalError(self->asyncResp->res); 145673df0db0SJames Feist return; 145773df0db0SJames Feist } 145873df0db0SJames Feist self->currentProfile = *current; 145973df0db0SJames Feist self->supportedProfiles = *supported; 146073df0db0SJames Feist self->profileConnection = owner; 146173df0db0SJames Feist self->profilePath = path; 146273df0db0SJames Feist }, 146373df0db0SJames Feist owner, path, "org.freedesktop.DBus.Properties", "GetAll", 146473df0db0SJames Feist thermalModeIface); 14655b4aa86bSJames Feist }, 14665b4aa86bSJames Feist "xyz.openbmc_project.ObjectMapper", 14675b4aa86bSJames Feist "/xyz/openbmc_project/object_mapper", 14685b4aa86bSJames Feist "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0, 146973df0db0SJames Feist std::array<const char*, 1>{thermalModeIface}); 147073df0db0SJames Feist } 147173df0db0SJames Feist ~SetPIDValues() 147273df0db0SJames Feist { 147373df0db0SJames Feist if (asyncResp->res.result() != boost::beast::http::status::ok) 147473df0db0SJames Feist { 147573df0db0SJames Feist return; 14765b4aa86bSJames Feist } 14778d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp; 147873df0db0SJames Feist if (profile) 147973df0db0SJames Feist { 148073df0db0SJames Feist if (std::find(supportedProfiles.begin(), supportedProfiles.end(), 148173df0db0SJames Feist *profile) == supportedProfiles.end()) 148273df0db0SJames Feist { 148373df0db0SJames Feist messages::actionParameterUnknown(response->res, "Profile", 148473df0db0SJames Feist *profile); 148573df0db0SJames Feist return; 148673df0db0SJames Feist } 148773df0db0SJames Feist currentProfile = *profile; 148873df0db0SJames Feist crow::connections::systemBus->async_method_call( 148973df0db0SJames Feist [response](const boost::system::error_code ec) { 149073df0db0SJames Feist if (ec) 149173df0db0SJames Feist { 149273df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching profile" << ec; 149373df0db0SJames Feist messages::internalError(response->res); 149473df0db0SJames Feist } 149573df0db0SJames Feist }, 149673df0db0SJames Feist profileConnection, profilePath, 149773df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", thermalModeIface, 149873df0db0SJames Feist "Current", std::variant<std::string>(*profile)); 149973df0db0SJames Feist } 150073df0db0SJames Feist 150173df0db0SJames Feist for (auto& containerPair : configuration) 150273df0db0SJames Feist { 150373df0db0SJames Feist auto& container = containerPair.second; 150473df0db0SJames Feist if (!container) 150573df0db0SJames Feist { 150673df0db0SJames Feist continue; 150773df0db0SJames Feist } 15086ee7f774SJames Feist BMCWEB_LOG_DEBUG << *container; 15096ee7f774SJames Feist 151073df0db0SJames Feist std::string& type = containerPair.first; 151173df0db0SJames Feist 151273df0db0SJames Feist for (nlohmann::json::iterator it = container->begin(); 151317a897dfSManojkiran Eda it != container->end(); ++it) 151473df0db0SJames Feist { 151573df0db0SJames Feist const auto& name = it.key(); 15166ee7f774SJames Feist BMCWEB_LOG_DEBUG << "looking for " << name; 15176ee7f774SJames Feist 151873df0db0SJames Feist auto pathItr = 151973df0db0SJames Feist std::find_if(managedObj.begin(), managedObj.end(), 152073df0db0SJames Feist [&name](const auto& obj) { 152173df0db0SJames Feist return boost::algorithm::ends_with( 152273df0db0SJames Feist obj.first.str, "/" + name); 152373df0db0SJames Feist }); 152473df0db0SJames Feist boost::container::flat_map<std::string, 152573df0db0SJames Feist dbus::utility::DbusVariantType> 152673df0db0SJames Feist output; 152773df0db0SJames Feist 152873df0db0SJames Feist output.reserve(16); // The pid interface length 152973df0db0SJames Feist 153073df0db0SJames Feist // determines if we're patching entity-manager or 153173df0db0SJames Feist // creating a new object 153273df0db0SJames Feist bool createNewObject = (pathItr == managedObj.end()); 15336ee7f774SJames Feist BMCWEB_LOG_DEBUG << "Found = " << !createNewObject; 15346ee7f774SJames Feist 153573df0db0SJames Feist std::string iface; 153673df0db0SJames Feist if (type == "PidControllers" || type == "FanControllers") 153773df0db0SJames Feist { 153873df0db0SJames Feist iface = pidConfigurationIface; 153973df0db0SJames Feist if (!createNewObject && 154073df0db0SJames Feist pathItr->second.find(pidConfigurationIface) == 154173df0db0SJames Feist pathItr->second.end()) 154273df0db0SJames Feist { 154373df0db0SJames Feist createNewObject = true; 154473df0db0SJames Feist } 154573df0db0SJames Feist } 154673df0db0SJames Feist else if (type == "FanZones") 154773df0db0SJames Feist { 154873df0db0SJames Feist iface = pidZoneConfigurationIface; 154973df0db0SJames Feist if (!createNewObject && 155073df0db0SJames Feist pathItr->second.find(pidZoneConfigurationIface) == 155173df0db0SJames Feist pathItr->second.end()) 155273df0db0SJames Feist { 155373df0db0SJames Feist 155473df0db0SJames Feist createNewObject = true; 155573df0db0SJames Feist } 155673df0db0SJames Feist } 155773df0db0SJames Feist else if (type == "StepwiseControllers") 155873df0db0SJames Feist { 155973df0db0SJames Feist iface = stepwiseConfigurationIface; 156073df0db0SJames Feist if (!createNewObject && 156173df0db0SJames Feist pathItr->second.find(stepwiseConfigurationIface) == 156273df0db0SJames Feist pathItr->second.end()) 156373df0db0SJames Feist { 156473df0db0SJames Feist createNewObject = true; 156573df0db0SJames Feist } 156673df0db0SJames Feist } 15676ee7f774SJames Feist 15686ee7f774SJames Feist if (createNewObject && it.value() == nullptr) 15696ee7f774SJames Feist { 15704e0453b1SGunnar Mills // can't delete a non-existent object 15716ee7f774SJames Feist messages::invalidObject(response->res, name); 15726ee7f774SJames Feist continue; 15736ee7f774SJames Feist } 15746ee7f774SJames Feist 15756ee7f774SJames Feist std::string path; 15766ee7f774SJames Feist if (pathItr != managedObj.end()) 15776ee7f774SJames Feist { 15786ee7f774SJames Feist path = pathItr->first.str; 15796ee7f774SJames Feist } 15806ee7f774SJames Feist 158173df0db0SJames Feist BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n"; 1582e69d9de2SJames Feist 1583e69d9de2SJames Feist // arbitrary limit to avoid attacks 1584e69d9de2SJames Feist constexpr const size_t controllerLimit = 500; 158514b0b8d5SJames Feist if (createNewObject && objectCount >= controllerLimit) 1586e69d9de2SJames Feist { 1587e69d9de2SJames Feist messages::resourceExhaustion(response->res, type); 1588e69d9de2SJames Feist continue; 1589e69d9de2SJames Feist } 1590e69d9de2SJames Feist 159173df0db0SJames Feist output["Name"] = boost::replace_all_copy(name, "_", " "); 159273df0db0SJames Feist 159373df0db0SJames Feist std::string chassis; 159473df0db0SJames Feist CreatePIDRet ret = createPidInterface( 15956ee7f774SJames Feist response, type, it, path, managedObj, createNewObject, 15966ee7f774SJames Feist output, chassis, currentProfile); 159773df0db0SJames Feist if (ret == CreatePIDRet::fail) 159873df0db0SJames Feist { 159973df0db0SJames Feist return; 160073df0db0SJames Feist } 16013174e4dfSEd Tanous if (ret == CreatePIDRet::del) 160273df0db0SJames Feist { 160373df0db0SJames Feist continue; 160473df0db0SJames Feist } 160573df0db0SJames Feist 160673df0db0SJames Feist if (!createNewObject) 160773df0db0SJames Feist { 160873df0db0SJames Feist for (const auto& property : output) 160973df0db0SJames Feist { 161073df0db0SJames Feist crow::connections::systemBus->async_method_call( 161173df0db0SJames Feist [response, 161273df0db0SJames Feist propertyName{std::string(property.first)}]( 161373df0db0SJames Feist const boost::system::error_code ec) { 161473df0db0SJames Feist if (ec) 161573df0db0SJames Feist { 161673df0db0SJames Feist BMCWEB_LOG_ERROR << "Error patching " 161773df0db0SJames Feist << propertyName << ": " 161873df0db0SJames Feist << ec; 161973df0db0SJames Feist messages::internalError(response->res); 162073df0db0SJames Feist return; 162173df0db0SJames Feist } 162273df0db0SJames Feist messages::success(response->res); 162373df0db0SJames Feist }, 16246ee7f774SJames Feist "xyz.openbmc_project.EntityManager", path, 162573df0db0SJames Feist "org.freedesktop.DBus.Properties", "Set", iface, 162673df0db0SJames Feist property.first, property.second); 162773df0db0SJames Feist } 162873df0db0SJames Feist } 162973df0db0SJames Feist else 163073df0db0SJames Feist { 163173df0db0SJames Feist if (chassis.empty()) 163273df0db0SJames Feist { 163373df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to get chassis from config"; 163473df0db0SJames Feist messages::invalidObject(response->res, name); 163573df0db0SJames Feist return; 163673df0db0SJames Feist } 163773df0db0SJames Feist 163873df0db0SJames Feist bool foundChassis = false; 163973df0db0SJames Feist for (const auto& obj : managedObj) 164073df0db0SJames Feist { 164173df0db0SJames Feist if (boost::algorithm::ends_with(obj.first.str, chassis)) 164273df0db0SJames Feist { 164373df0db0SJames Feist chassis = obj.first.str; 164473df0db0SJames Feist foundChassis = true; 164573df0db0SJames Feist break; 164673df0db0SJames Feist } 164773df0db0SJames Feist } 164873df0db0SJames Feist if (!foundChassis) 164973df0db0SJames Feist { 165073df0db0SJames Feist BMCWEB_LOG_ERROR << "Failed to find chassis on dbus"; 165173df0db0SJames Feist messages::resourceMissingAtURI( 165273df0db0SJames Feist response->res, "/redfish/v1/Chassis/" + chassis); 165373df0db0SJames Feist return; 165473df0db0SJames Feist } 165573df0db0SJames Feist 165673df0db0SJames Feist crow::connections::systemBus->async_method_call( 165773df0db0SJames Feist [response](const boost::system::error_code ec) { 165873df0db0SJames Feist if (ec) 165973df0db0SJames Feist { 166073df0db0SJames Feist BMCWEB_LOG_ERROR << "Error Adding Pid Object " 166173df0db0SJames Feist << ec; 166273df0db0SJames Feist messages::internalError(response->res); 166373df0db0SJames Feist return; 166473df0db0SJames Feist } 166573df0db0SJames Feist messages::success(response->res); 166673df0db0SJames Feist }, 166773df0db0SJames Feist "xyz.openbmc_project.EntityManager", chassis, 166873df0db0SJames Feist "xyz.openbmc_project.AddObject", "AddObject", output); 166973df0db0SJames Feist } 167073df0db0SJames Feist } 167173df0db0SJames Feist } 167273df0db0SJames Feist } 16738d1b46d7Szhanghch05 std::shared_ptr<bmcweb::AsyncResp> asyncResp; 167473df0db0SJames Feist std::vector<std::pair<std::string, std::optional<nlohmann::json>>> 167573df0db0SJames Feist configuration; 167673df0db0SJames Feist std::optional<std::string> profile; 167773df0db0SJames Feist dbus::utility::ManagedObjectType managedObj; 167873df0db0SJames Feist std::vector<std::string> supportedProfiles; 167973df0db0SJames Feist std::string currentProfile; 168073df0db0SJames Feist std::string profileConnection; 168173df0db0SJames Feist std::string profilePath; 168214b0b8d5SJames Feist size_t objectCount = 0; 168373df0db0SJames Feist }; 168473df0db0SJames Feist 1685071d8fdfSSunnySrivastava1984 /** 1686071d8fdfSSunnySrivastava1984 * @brief Retrieves BMC manager location data over DBus 1687071d8fdfSSunnySrivastava1984 * 1688071d8fdfSSunnySrivastava1984 * @param[in] aResp Shared pointer for completing asynchronous calls 1689071d8fdfSSunnySrivastava1984 * @param[in] connectionName - service name 1690071d8fdfSSunnySrivastava1984 * @param[in] path - object path 1691071d8fdfSSunnySrivastava1984 * @return none 1692071d8fdfSSunnySrivastava1984 */ 16938d1b46d7Szhanghch05 inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1694071d8fdfSSunnySrivastava1984 const std::string& connectionName, 1695071d8fdfSSunnySrivastava1984 const std::string& path) 1696071d8fdfSSunnySrivastava1984 { 1697071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "Get BMC manager Location data."; 1698071d8fdfSSunnySrivastava1984 1699071d8fdfSSunnySrivastava1984 crow::connections::systemBus->async_method_call( 1700071d8fdfSSunnySrivastava1984 [aResp](const boost::system::error_code ec, 1701071d8fdfSSunnySrivastava1984 const std::variant<std::string>& property) { 1702071d8fdfSSunnySrivastava1984 if (ec) 1703071d8fdfSSunnySrivastava1984 { 1704071d8fdfSSunnySrivastava1984 BMCWEB_LOG_DEBUG << "DBUS response error for " 1705071d8fdfSSunnySrivastava1984 "Location"; 1706071d8fdfSSunnySrivastava1984 messages::internalError(aResp->res); 1707071d8fdfSSunnySrivastava1984 return; 1708071d8fdfSSunnySrivastava1984 } 1709071d8fdfSSunnySrivastava1984 1710071d8fdfSSunnySrivastava1984 const std::string* value = std::get_if<std::string>(&property); 1711071d8fdfSSunnySrivastava1984 1712071d8fdfSSunnySrivastava1984 if (value == nullptr) 1713071d8fdfSSunnySrivastava1984 { 1714071d8fdfSSunnySrivastava1984 // illegal value 1715071d8fdfSSunnySrivastava1984 messages::internalError(aResp->res); 1716071d8fdfSSunnySrivastava1984 return; 1717071d8fdfSSunnySrivastava1984 } 1718071d8fdfSSunnySrivastava1984 1719071d8fdfSSunnySrivastava1984 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 1720071d8fdfSSunnySrivastava1984 *value; 1721071d8fdfSSunnySrivastava1984 }, 1722071d8fdfSSunnySrivastava1984 connectionName, path, "org.freedesktop.DBus.Properties", "Get", 1723071d8fdfSSunnySrivastava1984 "xyz.openbmc_project.Inventory.Decorator." 1724071d8fdfSSunnySrivastava1984 "LocationCode", 1725071d8fdfSSunnySrivastava1984 "LocationCode"); 1726071d8fdfSSunnySrivastava1984 } 17277e860f15SJohn Edward Broadbent // avoid name collision systems.hpp 17287e860f15SJohn Edward Broadbent inline void 17297e860f15SJohn Edward Broadbent managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp) 17304bf2b033SGunnar Mills { 17314bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time"; 17324bf2b033SGunnar Mills 17334bf2b033SGunnar Mills crow::connections::systemBus->async_method_call( 17344bf2b033SGunnar Mills [aResp](const boost::system::error_code ec, 17354bf2b033SGunnar Mills std::variant<uint64_t>& lastResetTime) { 17364bf2b033SGunnar Mills if (ec) 17374bf2b033SGunnar Mills { 17384bf2b033SGunnar Mills BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; 17394bf2b033SGunnar Mills return; 17404bf2b033SGunnar Mills } 17414bf2b033SGunnar Mills 17424bf2b033SGunnar Mills const uint64_t* lastResetTimePtr = 17434bf2b033SGunnar Mills std::get_if<uint64_t>(&lastResetTime); 17444bf2b033SGunnar Mills 17454bf2b033SGunnar Mills if (!lastResetTimePtr) 17464bf2b033SGunnar Mills { 17474bf2b033SGunnar Mills messages::internalError(aResp->res); 17484bf2b033SGunnar Mills return; 17494bf2b033SGunnar Mills } 17504bf2b033SGunnar Mills // LastRebootTime is epoch time, in milliseconds 17514bf2b033SGunnar Mills // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 17524bf2b033SGunnar Mills time_t lastResetTimeStamp = 17534bf2b033SGunnar Mills static_cast<time_t>(*lastResetTimePtr / 1000); 17544bf2b033SGunnar Mills 17554bf2b033SGunnar Mills // Convert to ISO 8601 standard 17564bf2b033SGunnar Mills aResp->res.jsonValue["LastResetTime"] = 17574bf2b033SGunnar Mills crow::utility::getDateTime(lastResetTimeStamp); 17584bf2b033SGunnar Mills }, 17594bf2b033SGunnar Mills "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", 17604bf2b033SGunnar Mills "org.freedesktop.DBus.Properties", "Get", 17614bf2b033SGunnar Mills "xyz.openbmc_project.State.BMC", "LastRebootTime"); 17624bf2b033SGunnar Mills } 17634bf2b033SGunnar Mills 17644bfefa74SGunnar Mills /** 17654bfefa74SGunnar Mills * @brief Set the running firmware image 17664bfefa74SGunnar Mills * 17674bfefa74SGunnar Mills * @param[i,o] aResp - Async response object 17684bfefa74SGunnar Mills * @param[i] runningFirmwareTarget - Image to make the running image 17694bfefa74SGunnar Mills * 17704bfefa74SGunnar Mills * @return void 17714bfefa74SGunnar Mills */ 17727e860f15SJohn Edward Broadbent inline void 17737e860f15SJohn Edward Broadbent setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& aResp, 1774f23b7296SEd Tanous const std::string& runningFirmwareTarget) 17754bfefa74SGunnar Mills { 17764bfefa74SGunnar Mills // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 1777f23b7296SEd Tanous std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 17784bfefa74SGunnar Mills if (idPos == std::string::npos) 17794bfefa74SGunnar Mills { 17804bfefa74SGunnar Mills messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 17814bfefa74SGunnar Mills "@odata.id"); 17824bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't parse firmware ID!"; 17834bfefa74SGunnar Mills return; 17844bfefa74SGunnar Mills } 17854bfefa74SGunnar Mills idPos++; 17864bfefa74SGunnar Mills if (idPos >= runningFirmwareTarget.size()) 17874bfefa74SGunnar Mills { 17884bfefa74SGunnar Mills messages::propertyValueNotInList(aResp->res, runningFirmwareTarget, 17894bfefa74SGunnar Mills "@odata.id"); 17904bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 17914bfefa74SGunnar Mills return; 17924bfefa74SGunnar Mills } 17934bfefa74SGunnar Mills std::string firmwareId = runningFirmwareTarget.substr(idPos); 17944bfefa74SGunnar Mills 17954bfefa74SGunnar Mills // Make sure the image is valid before setting priority 17964bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 17977e860f15SJohn Edward Broadbent [aResp, firmwareId, runningFirmwareTarget]( 17987e860f15SJohn Edward Broadbent const boost::system::error_code ec, ManagedObjectType& subtree) { 17994bfefa74SGunnar Mills if (ec) 18004bfefa74SGunnar Mills { 18014bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error getting objects."; 18024bfefa74SGunnar Mills messages::internalError(aResp->res); 18034bfefa74SGunnar Mills return; 18044bfefa74SGunnar Mills } 18054bfefa74SGunnar Mills 18064bfefa74SGunnar Mills if (subtree.size() == 0) 18074bfefa74SGunnar Mills { 18084bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Can't find image!"; 18094bfefa74SGunnar Mills messages::internalError(aResp->res); 18104bfefa74SGunnar Mills return; 18114bfefa74SGunnar Mills } 18124bfefa74SGunnar Mills 18134bfefa74SGunnar Mills bool foundImage = false; 18144bfefa74SGunnar Mills for (auto& object : subtree) 18154bfefa74SGunnar Mills { 18164bfefa74SGunnar Mills const std::string& path = 18174bfefa74SGunnar Mills static_cast<const std::string&>(object.first); 1818f23b7296SEd Tanous std::size_t idPos2 = path.rfind('/'); 18194bfefa74SGunnar Mills 18204bfefa74SGunnar Mills if (idPos2 == std::string::npos) 18214bfefa74SGunnar Mills { 18224bfefa74SGunnar Mills continue; 18234bfefa74SGunnar Mills } 18244bfefa74SGunnar Mills 18254bfefa74SGunnar Mills idPos2++; 18264bfefa74SGunnar Mills if (idPos2 >= path.size()) 18274bfefa74SGunnar Mills { 18284bfefa74SGunnar Mills continue; 18294bfefa74SGunnar Mills } 18304bfefa74SGunnar Mills 18314bfefa74SGunnar Mills if (path.substr(idPos2) == firmwareId) 18324bfefa74SGunnar Mills { 18334bfefa74SGunnar Mills foundImage = true; 18344bfefa74SGunnar Mills break; 18354bfefa74SGunnar Mills } 18364bfefa74SGunnar Mills } 18374bfefa74SGunnar Mills 18384bfefa74SGunnar Mills if (!foundImage) 18394bfefa74SGunnar Mills { 18404bfefa74SGunnar Mills messages::propertyValueNotInList( 18414bfefa74SGunnar Mills aResp->res, runningFirmwareTarget, "@odata.id"); 18424bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "Invalid firmware ID."; 18434bfefa74SGunnar Mills return; 18444bfefa74SGunnar Mills } 18454bfefa74SGunnar Mills 18467e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 18477e860f15SJohn Edward Broadbent << "Setting firmware version " + firmwareId + " to priority 0."; 18484bfefa74SGunnar Mills 18494bfefa74SGunnar Mills // Only support Immediate 18504bfefa74SGunnar Mills // An addition could be a Redfish Setting like 18514bfefa74SGunnar Mills // ActiveSoftwareImageApplyTime and support OnReset 18524bfefa74SGunnar Mills crow::connections::systemBus->async_method_call( 18534bfefa74SGunnar Mills [aResp](const boost::system::error_code ec) { 18544bfefa74SGunnar Mills if (ec) 18554bfefa74SGunnar Mills { 18564bfefa74SGunnar Mills BMCWEB_LOG_DEBUG << "D-Bus response error setting."; 18574bfefa74SGunnar Mills messages::internalError(aResp->res); 18584bfefa74SGunnar Mills return; 18594bfefa74SGunnar Mills } 18604bfefa74SGunnar Mills doBMCGracefulRestart(aResp); 18614bfefa74SGunnar Mills }, 18624bfefa74SGunnar Mills 18634bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18644bfefa74SGunnar Mills "/xyz/openbmc_project/software/" + firmwareId, 18654bfefa74SGunnar Mills "org.freedesktop.DBus.Properties", "Set", 18667e860f15SJohn Edward Broadbent "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 18677e860f15SJohn Edward Broadbent std::variant<uint8_t>(static_cast<uint8_t>(0))); 18684bfefa74SGunnar Mills }, 18694bfefa74SGunnar Mills "xyz.openbmc_project.Software.BMC.Updater", 18707e860f15SJohn Edward Broadbent "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager", 18717e860f15SJohn Edward Broadbent "GetManagedObjects"); 18724bfefa74SGunnar Mills } 18734bfefa74SGunnar Mills 18747e860f15SJohn Edward Broadbent inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp, 18757e860f15SJohn Edward Broadbent std::string datetime) 1876af5d6058SSantosh Puranik { 1877af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Set date time: " << datetime; 1878af5d6058SSantosh Puranik 1879af5d6058SSantosh Puranik std::stringstream stream(datetime); 1880af5d6058SSantosh Puranik // Convert from ISO 8601 to boost local_time 1881af5d6058SSantosh Puranik // (BMC only has time in UTC) 1882af5d6058SSantosh Puranik boost::posix_time::ptime posixTime; 1883af5d6058SSantosh Puranik boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1)); 1884af5d6058SSantosh Puranik // Facet gets deleted with the stringsteam 1885af5d6058SSantosh Puranik auto ifc = std::make_unique<boost::local_time::local_time_input_facet>( 1886af5d6058SSantosh Puranik "%Y-%m-%d %H:%M:%S%F %ZP"); 1887af5d6058SSantosh Puranik stream.imbue(std::locale(stream.getloc(), ifc.release())); 1888af5d6058SSantosh Puranik 18897e860f15SJohn Edward Broadbent boost::local_time::local_date_time ldt(boost::local_time::not_a_date_time); 1890af5d6058SSantosh Puranik 1891af5d6058SSantosh Puranik if (stream >> ldt) 1892af5d6058SSantosh Puranik { 1893af5d6058SSantosh Puranik posixTime = ldt.utc_time(); 1894af5d6058SSantosh Puranik boost::posix_time::time_duration dur = posixTime - epoch; 18957e860f15SJohn Edward Broadbent uint64_t durMicroSecs = static_cast<uint64_t>(dur.total_microseconds()); 1896af5d6058SSantosh Puranik crow::connections::systemBus->async_method_call( 1897af5d6058SSantosh Puranik [aResp{std::move(aResp)}, datetime{std::move(datetime)}]( 1898af5d6058SSantosh Puranik const boost::system::error_code ec) { 1899af5d6058SSantosh Puranik if (ec) 1900af5d6058SSantosh Puranik { 1901af5d6058SSantosh Puranik BMCWEB_LOG_DEBUG << "Failed to set elapsed time. " 1902af5d6058SSantosh Puranik "DBUS response error " 1903af5d6058SSantosh Puranik << ec; 1904af5d6058SSantosh Puranik messages::internalError(aResp->res); 1905af5d6058SSantosh Puranik return; 1906af5d6058SSantosh Puranik } 1907af5d6058SSantosh Puranik aResp->res.jsonValue["DateTime"] = datetime; 1908af5d6058SSantosh Puranik }, 19097e860f15SJohn Edward Broadbent "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc", 1910af5d6058SSantosh Puranik "org.freedesktop.DBus.Properties", "Set", 1911af5d6058SSantosh Puranik "xyz.openbmc_project.Time.EpochTime", "Elapsed", 1912af5d6058SSantosh Puranik std::variant<uint64_t>(durMicroSecs)); 1913af5d6058SSantosh Puranik } 1914af5d6058SSantosh Puranik else 1915af5d6058SSantosh Puranik { 19167e860f15SJohn Edward Broadbent messages::propertyValueFormatError(aResp->res, datetime, "DateTime"); 1917af5d6058SSantosh Puranik return; 1918af5d6058SSantosh Puranik } 191983ff9ab6SJames Feist } 19209c310685SBorawski.Lukasz 19217e860f15SJohn Edward Broadbent inline void requestRoutesManager(App& app) 19227e860f15SJohn Edward Broadbent { 19237e860f15SJohn Edward Broadbent std::string uuid = persistent_data::getConfig().systemUuid; 19249c310685SBorawski.Lukasz 19257e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 1926*432a890cSEd Tanous .privileges({{"Login"}}) 19277e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)([uuid](const crow::Request&, 19287e860f15SJohn Edward Broadbent const std::shared_ptr< 19297e860f15SJohn Edward Broadbent bmcweb::AsyncResp>& 19307e860f15SJohn Edward Broadbent asyncResp) { 19317e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc"; 19327e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["@odata.type"] = 19337e860f15SJohn Edward Broadbent "#Manager.v1_11_0.Manager"; 19347e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Id"] = "bmc"; 19357e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 19367e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Description"] = 19377e860f15SJohn Edward Broadbent "Baseboard Management Controller"; 19387e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["PowerState"] = "On"; 19397e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Status"] = {{"State", "Enabled"}, 19407e860f15SJohn Edward Broadbent {"Health", "OK"}}; 19417e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ManagerType"] = "BMC"; 19427e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 19437e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 19447e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Model"] = 19457e860f15SJohn Edward Broadbent "OpenBmc"; // TODO(ed), get model 19467e860f15SJohn Edward Broadbent 19477e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["LogServices"] = { 19487e860f15SJohn Edward Broadbent {"@odata.id", "/redfish/v1/Managers/bmc/LogServices"}}; 19497e860f15SJohn Edward Broadbent 19507e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["NetworkProtocol"] = { 19517e860f15SJohn Edward Broadbent {"@odata.id", "/redfish/v1/Managers/bmc/NetworkProtocol"}}; 19527e860f15SJohn Edward Broadbent 19537e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["EthernetInterfaces"] = { 19547e860f15SJohn Edward Broadbent {"@odata.id", "/redfish/v1/Managers/bmc/EthernetInterfaces"}}; 19557e860f15SJohn Edward Broadbent 19567e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_VM_NBDPROXY 19577e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["VirtualMedia"] = { 19587e860f15SJohn Edward Broadbent {"@odata.id", "/redfish/v1/Managers/bmc/VirtualMedia"}}; 19597e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_VM_NBDPROXY 19607e860f15SJohn Edward Broadbent 19617e860f15SJohn Edward Broadbent // default oem data 19627e860f15SJohn Edward Broadbent nlohmann::json& oem = asyncResp->res.jsonValue["Oem"]; 19637e860f15SJohn Edward Broadbent nlohmann::json& oemOpenbmc = oem["OpenBmc"]; 19647e860f15SJohn Edward Broadbent oem["@odata.type"] = "#OemManager.Oem"; 19657e860f15SJohn Edward Broadbent oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem"; 19667e860f15SJohn Edward Broadbent oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc"; 19677e860f15SJohn Edward Broadbent oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc"; 19687e860f15SJohn Edward Broadbent oemOpenbmc["Certificates"] = { 19697e860f15SJohn Edward Broadbent {"@odata.id", 19707e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Truststore/Certificates"}}; 19717e860f15SJohn Edward Broadbent 19727e860f15SJohn Edward Broadbent // Manager.Reset (an action) can be many values, OpenBMC only 19737e860f15SJohn Edward Broadbent // supports BMC reboot. 19747e860f15SJohn Edward Broadbent nlohmann::json& managerReset = 19757e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 19767e860f15SJohn Edward Broadbent managerReset["target"] = 19777e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.Reset"; 19787e860f15SJohn Edward Broadbent managerReset["@Redfish.ActionInfo"] = 19797e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/ResetActionInfo"; 19807e860f15SJohn Edward Broadbent 19817e860f15SJohn Edward Broadbent // ResetToDefaults (Factory Reset) has values like 19827e860f15SJohn Edward Broadbent // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 19837e860f15SJohn Edward Broadbent // on OpenBMC 19847e860f15SJohn Edward Broadbent nlohmann::json& resetToDefaults = 19857e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 19867e860f15SJohn Edward Broadbent resetToDefaults["target"] = 19877e860f15SJohn Edward Broadbent "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults"; 19887e860f15SJohn Edward Broadbent resetToDefaults["ResetType@Redfish.AllowableValues"] = {"ResetAll"}; 19897e860f15SJohn Edward Broadbent 19907e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["DateTime"] = crow::utility::dateTimeNow(); 19917e860f15SJohn Edward Broadbent 19927e860f15SJohn Edward Broadbent // Fill in SerialConsole info 19937e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true; 19947e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 19957e860f15SJohn Edward Broadbent 15; 19967e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] = 19977e860f15SJohn Edward Broadbent {"IPMI", "SSH"}; 19987e860f15SJohn Edward Broadbent #ifdef BMCWEB_ENABLE_KVM 19997e860f15SJohn Edward Broadbent // Fill in GraphicalConsole info 20007e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = 20017e860f15SJohn Edward Broadbent true; 20027e860f15SJohn Edward Broadbent asyncResp->res 20037e860f15SJohn Edward Broadbent .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; 20047e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["GraphicalConsole"] 20057e860f15SJohn Edward Broadbent ["ConnectTypesSupported"] = {"KVMIP"}; 20067e860f15SJohn Edward Broadbent #endif // BMCWEB_ENABLE_KVM 20077e860f15SJohn Edward Broadbent 20087e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 20097e860f15SJohn Edward Broadbent 1; 20107e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Links"]["ManagerForServers"] = { 20117e860f15SJohn Edward Broadbent {{"@odata.id", "/redfish/v1/Systems/system"}}}; 20127e860f15SJohn Edward Broadbent 20137e860f15SJohn Edward Broadbent auto health = std::make_shared<HealthPopulate>(asyncResp); 20147e860f15SJohn Edward Broadbent health->isManagersHealth = true; 20157e860f15SJohn Edward Broadbent health->populate(); 20167e860f15SJohn Edward Broadbent 20177e860f15SJohn Edward Broadbent fw_util::populateFirmwareInformation(asyncResp, fw_util::bmcPurpose, 20187e860f15SJohn Edward Broadbent "FirmwareVersion", true); 20197e860f15SJohn Edward Broadbent 20207e860f15SJohn Edward Broadbent managerGetLastResetTime(asyncResp); 20217e860f15SJohn Edward Broadbent 20227e860f15SJohn Edward Broadbent auto pids = std::make_shared<GetPIDValues>(asyncResp); 20237e860f15SJohn Edward Broadbent pids->run(); 20247e860f15SJohn Edward Broadbent 20257e860f15SJohn Edward Broadbent getMainChassisId( 20267e860f15SJohn Edward Broadbent asyncResp, [](const std::string& chassisId, 20277e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { 20287e860f15SJohn Edward Broadbent aRsp->res 20297e860f15SJohn Edward Broadbent .jsonValue["Links"]["ManagerForChassis@odata.count"] = 20307e860f15SJohn Edward Broadbent 1; 20317e860f15SJohn Edward Broadbent aRsp->res.jsonValue["Links"]["ManagerForChassis"] = { 20327e860f15SJohn Edward Broadbent {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; 20337e860f15SJohn Edward Broadbent aRsp->res.jsonValue["Links"]["ManagerInChassis"] = { 20347e860f15SJohn Edward Broadbent {"@odata.id", "/redfish/v1/Chassis/" + chassisId}}; 20357e860f15SJohn Edward Broadbent }); 20367e860f15SJohn Edward Broadbent 20377e860f15SJohn Edward Broadbent static bool started = false; 20387e860f15SJohn Edward Broadbent 20397e860f15SJohn Edward Broadbent if (!started) 20401abe55efSEd Tanous { 20417e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 20427e860f15SJohn Edward Broadbent [asyncResp](const boost::system::error_code ec, 20437e860f15SJohn Edward Broadbent const std::variant<double>& resp) { 20447e860f15SJohn Edward Broadbent if (ec) 20451abe55efSEd Tanous { 20467e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR << "Error while getting progress"; 20477e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20487e860f15SJohn Edward Broadbent return; 20497e860f15SJohn Edward Broadbent } 20507e860f15SJohn Edward Broadbent const double* val = std::get_if<double>(&resp); 20517e860f15SJohn Edward Broadbent if (val == nullptr) 20527e860f15SJohn Edward Broadbent { 20537e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR 20547e860f15SJohn Edward Broadbent << "Invalid response while getting progress"; 20557e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20567e860f15SJohn Edward Broadbent return; 20577e860f15SJohn Edward Broadbent } 20587e860f15SJohn Edward Broadbent if (*val < 1.0) 20597e860f15SJohn Edward Broadbent { 20607e860f15SJohn Edward Broadbent asyncResp->res.jsonValue["Status"]["State"] = 20617e860f15SJohn Edward Broadbent "Starting"; 20627e860f15SJohn Edward Broadbent started = true; 20637e860f15SJohn Edward Broadbent } 20647e860f15SJohn Edward Broadbent }, 20657e860f15SJohn Edward Broadbent "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 20667e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "Get", 20677e860f15SJohn Edward Broadbent "org.freedesktop.systemd1.Manager", "Progress"); 20689c310685SBorawski.Lukasz } 20699c310685SBorawski.Lukasz 20707e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 20717e860f15SJohn Edward Broadbent [asyncResp]( 20727e860f15SJohn Edward Broadbent const boost::system::error_code ec, 20737e860f15SJohn Edward Broadbent const std::vector< 20747e860f15SJohn Edward Broadbent std::pair<std::string, 20757e860f15SJohn Edward Broadbent std::vector<std::pair< 20767e860f15SJohn Edward Broadbent std::string, std::vector<std::string>>>>>& 20777e860f15SJohn Edward Broadbent subtree) { 20787e860f15SJohn Edward Broadbent if (ec) 20791abe55efSEd Tanous { 20807e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 20817e860f15SJohn Edward Broadbent << "D-Bus response error on GetSubTree " << ec; 20827e860f15SJohn Edward Broadbent return; 20837e860f15SJohn Edward Broadbent } 20847e860f15SJohn Edward Broadbent if (subtree.size() == 0) 20857e860f15SJohn Edward Broadbent { 20867e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!"; 20877e860f15SJohn Edward Broadbent return; 20887e860f15SJohn Edward Broadbent } 20897e860f15SJohn Edward Broadbent // Assume only 1 bmc D-Bus object 20907e860f15SJohn Edward Broadbent // Throw an error if there is more than 1 20917e860f15SJohn Edward Broadbent if (subtree.size() > 1) 20927e860f15SJohn Edward Broadbent { 20937e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 20947e860f15SJohn Edward Broadbent << "Found more than 1 bmc D-Bus object!"; 20957e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 20967e860f15SJohn Edward Broadbent return; 20977e860f15SJohn Edward Broadbent } 20987e860f15SJohn Edward Broadbent 20997e860f15SJohn Edward Broadbent if (subtree[0].first.empty() || 21007e860f15SJohn Edward Broadbent subtree[0].second.size() != 1) 21017e860f15SJohn Edward Broadbent { 21027e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!"; 21037e860f15SJohn Edward Broadbent messages::internalError(asyncResp->res); 21047e860f15SJohn Edward Broadbent return; 21057e860f15SJohn Edward Broadbent } 21067e860f15SJohn Edward Broadbent 21077e860f15SJohn Edward Broadbent const std::string& path = subtree[0].first; 21087e860f15SJohn Edward Broadbent const std::string& connectionName = 21097e860f15SJohn Edward Broadbent subtree[0].second[0].first; 21107e860f15SJohn Edward Broadbent 21117e860f15SJohn Edward Broadbent for (const auto& interfaceName : 21127e860f15SJohn Edward Broadbent subtree[0].second[0].second) 21137e860f15SJohn Edward Broadbent { 21147e860f15SJohn Edward Broadbent if (interfaceName == 21157e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator.Asset") 21167e860f15SJohn Edward Broadbent { 21177e860f15SJohn Edward Broadbent crow::connections::systemBus->async_method_call( 21187e860f15SJohn Edward Broadbent [asyncResp]( 21197e860f15SJohn Edward Broadbent const boost::system::error_code ec, 21207e860f15SJohn Edward Broadbent const std::vector< 21217e860f15SJohn Edward Broadbent std::pair<std::string, 21227e860f15SJohn Edward Broadbent std::variant<std::string>>>& 21237e860f15SJohn Edward Broadbent propertiesList) { 21247e860f15SJohn Edward Broadbent if (ec) 21257e860f15SJohn Edward Broadbent { 21267e860f15SJohn Edward Broadbent BMCWEB_LOG_DEBUG 21277e860f15SJohn Edward Broadbent << "Can't get bmc asset!"; 21287e860f15SJohn Edward Broadbent return; 21297e860f15SJohn Edward Broadbent } 21307e860f15SJohn Edward Broadbent for (const std::pair< 21317e860f15SJohn Edward Broadbent std::string, 21327e860f15SJohn Edward Broadbent std::variant<std::string>>& 21337e860f15SJohn Edward Broadbent property : propertiesList) 21347e860f15SJohn Edward Broadbent { 21357e860f15SJohn Edward Broadbent const std::string& propertyName = 21367e860f15SJohn Edward Broadbent property.first; 21377e860f15SJohn Edward Broadbent 21387e860f15SJohn Edward Broadbent if ((propertyName == "PartNumber") || 21397e860f15SJohn Edward Broadbent (propertyName == "SerialNumber") || 21407e860f15SJohn Edward Broadbent (propertyName == "Manufacturer") || 21417e860f15SJohn Edward Broadbent (propertyName == "Model") || 21427e860f15SJohn Edward Broadbent (propertyName == "SparePartNumber")) 21437e860f15SJohn Edward Broadbent { 21447e860f15SJohn Edward Broadbent const std::string* value = 21457e860f15SJohn Edward Broadbent std::get_if<std::string>( 21467e860f15SJohn Edward Broadbent &property.second); 21477e860f15SJohn Edward Broadbent if (value == nullptr) 21487e860f15SJohn Edward Broadbent { 21497e860f15SJohn Edward Broadbent // illegal property 21507e860f15SJohn Edward Broadbent messages::internalError( 21517e860f15SJohn Edward Broadbent asyncResp->res); 21527e860f15SJohn Edward Broadbent return; 21537e860f15SJohn Edward Broadbent } 21547e860f15SJohn Edward Broadbent asyncResp->res 21557e860f15SJohn Edward Broadbent .jsonValue[propertyName] = 21567e860f15SJohn Edward Broadbent *value; 21577e860f15SJohn Edward Broadbent } 21587e860f15SJohn Edward Broadbent } 21597e860f15SJohn Edward Broadbent }, 21607e860f15SJohn Edward Broadbent connectionName, path, 21617e860f15SJohn Edward Broadbent "org.freedesktop.DBus.Properties", "GetAll", 21627e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Decorator." 21637e860f15SJohn Edward Broadbent "Asset"); 21647e860f15SJohn Edward Broadbent } 21657e860f15SJohn Edward Broadbent else if (interfaceName == 21667e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory." 21677e860f15SJohn Edward Broadbent "Decorator.LocationCode") 21687e860f15SJohn Edward Broadbent { 21697e860f15SJohn Edward Broadbent getLocation(asyncResp, connectionName, path); 21707e860f15SJohn Edward Broadbent } 21717e860f15SJohn Edward Broadbent } 21727e860f15SJohn Edward Broadbent }, 21737e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", 21747e860f15SJohn Edward Broadbent "/xyz/openbmc_project/object_mapper", 21757e860f15SJohn Edward Broadbent "xyz.openbmc_project.ObjectMapper", "GetSubTree", 21767e860f15SJohn Edward Broadbent "/xyz/openbmc_project/inventory", int32_t(0), 21777e860f15SJohn Edward Broadbent std::array<const char*, 1>{ 21787e860f15SJohn Edward Broadbent "xyz.openbmc_project.Inventory.Item.Bmc"}); 21797e860f15SJohn Edward Broadbent }); 21807e860f15SJohn Edward Broadbent 21817e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/") 2182*432a890cSEd Tanous .privileges({{"ConfigureManager"}}) 21837e860f15SJohn Edward Broadbent .methods( 21847e860f15SJohn Edward Broadbent boost::beast::http::verb:: 21857e860f15SJohn Edward Broadbent patch)([](const crow::Request& req, 21867e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 21877e860f15SJohn Edward Broadbent std::optional<nlohmann::json> oem; 21887e860f15SJohn Edward Broadbent std::optional<nlohmann::json> links; 21897e860f15SJohn Edward Broadbent std::optional<std::string> datetime; 21907e860f15SJohn Edward Broadbent 21917e860f15SJohn Edward Broadbent if (!json_util::readJson(req, asyncResp->res, "Oem", oem, 21927e860f15SJohn Edward Broadbent "DateTime", datetime, "Links", links)) 21937e860f15SJohn Edward Broadbent { 21947e860f15SJohn Edward Broadbent return; 21957e860f15SJohn Edward Broadbent } 21967e860f15SJohn Edward Broadbent 21977e860f15SJohn Edward Broadbent if (oem) 21987e860f15SJohn Edward Broadbent { 21997e860f15SJohn Edward Broadbent std::optional<nlohmann::json> openbmc; 22007e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*oem, asyncResp->res, 22017e860f15SJohn Edward Broadbent "OpenBmc", openbmc)) 22027e860f15SJohn Edward Broadbent { 22037e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR 22047e860f15SJohn Edward Broadbent << "Illegal Property " 22057e860f15SJohn Edward Broadbent << oem->dump(2, ' ', true, 22067e860f15SJohn Edward Broadbent nlohmann::json::error_handler_t::replace); 22077e860f15SJohn Edward Broadbent return; 22087e860f15SJohn Edward Broadbent } 22097e860f15SJohn Edward Broadbent if (openbmc) 22107e860f15SJohn Edward Broadbent { 22117e860f15SJohn Edward Broadbent std::optional<nlohmann::json> fan; 22127e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*openbmc, asyncResp->res, 22137e860f15SJohn Edward Broadbent "Fan", fan)) 22147e860f15SJohn Edward Broadbent { 22157e860f15SJohn Edward Broadbent BMCWEB_LOG_ERROR 22167e860f15SJohn Edward Broadbent << "Illegal Property " 22177e860f15SJohn Edward Broadbent << openbmc->dump( 22187e860f15SJohn Edward Broadbent 2, ' ', true, 22197e860f15SJohn Edward Broadbent nlohmann::json::error_handler_t::replace); 22207e860f15SJohn Edward Broadbent return; 22217e860f15SJohn Edward Broadbent } 22227e860f15SJohn Edward Broadbent if (fan) 22237e860f15SJohn Edward Broadbent { 22247e860f15SJohn Edward Broadbent auto pid = 22257e860f15SJohn Edward Broadbent std::make_shared<SetPIDValues>(asyncResp, *fan); 22267e860f15SJohn Edward Broadbent pid->run(); 22277e860f15SJohn Edward Broadbent } 22287e860f15SJohn Edward Broadbent } 22297e860f15SJohn Edward Broadbent } 22307e860f15SJohn Edward Broadbent if (links) 22317e860f15SJohn Edward Broadbent { 22327e860f15SJohn Edward Broadbent std::optional<nlohmann::json> activeSoftwareImage; 22337e860f15SJohn Edward Broadbent if (!redfish::json_util::readJson(*links, asyncResp->res, 22347e860f15SJohn Edward Broadbent "ActiveSoftwareImage", 22357e860f15SJohn Edward Broadbent activeSoftwareImage)) 22367e860f15SJohn Edward Broadbent { 22377e860f15SJohn Edward Broadbent return; 22387e860f15SJohn Edward Broadbent } 22397e860f15SJohn Edward Broadbent if (activeSoftwareImage) 22407e860f15SJohn Edward Broadbent { 22417e860f15SJohn Edward Broadbent std::optional<std::string> odataId; 22427e860f15SJohn Edward Broadbent if (!json_util::readJson(*activeSoftwareImage, 22437e860f15SJohn Edward Broadbent asyncResp->res, "@odata.id", 22447e860f15SJohn Edward Broadbent odataId)) 22457e860f15SJohn Edward Broadbent { 22467e860f15SJohn Edward Broadbent return; 22477e860f15SJohn Edward Broadbent } 22487e860f15SJohn Edward Broadbent 22497e860f15SJohn Edward Broadbent if (odataId) 22507e860f15SJohn Edward Broadbent { 22517e860f15SJohn Edward Broadbent setActiveFirmwareImage(asyncResp, *odataId); 22527e860f15SJohn Edward Broadbent } 22537e860f15SJohn Edward Broadbent } 22547e860f15SJohn Edward Broadbent } 22557e860f15SJohn Edward Broadbent if (datetime) 22567e860f15SJohn Edward Broadbent { 22577e860f15SJohn Edward Broadbent setDateTime(asyncResp, std::move(*datetime)); 22587e860f15SJohn Edward Broadbent } 22597e860f15SJohn Edward Broadbent }); 22607e860f15SJohn Edward Broadbent } 22617e860f15SJohn Edward Broadbent 22627e860f15SJohn Edward Broadbent inline void requestRoutesManagerCollection(App& app) 22637e860f15SJohn Edward Broadbent { 22647e860f15SJohn Edward Broadbent BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 2265*432a890cSEd Tanous .privileges({{"Login"}}) 22667e860f15SJohn Edward Broadbent .methods(boost::beast::http::verb::get)( 22677e860f15SJohn Edward Broadbent [](const crow::Request&, 22687e860f15SJohn Edward Broadbent const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 226983ff9ab6SJames Feist // Collections don't include the static data added by SubRoute 227083ff9ab6SJames Feist // because it has a duplicate entry for members 22718d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 22728d1b46d7Szhanghch05 asyncResp->res.jsonValue["@odata.type"] = 22738d1b46d7Szhanghch05 "#ManagerCollection.ManagerCollection"; 22748d1b46d7Szhanghch05 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 22758d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members@odata.count"] = 1; 22768d1b46d7Szhanghch05 asyncResp->res.jsonValue["Members"] = { 22775b4aa86bSJames Feist {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; 22787e860f15SJohn Edward Broadbent }); 22799c310685SBorawski.Lukasz } 22809c310685SBorawski.Lukasz } // namespace redfish 2281