blob: 55c3949cae3471fb76ff12d47286b4eca72a6cef [file] [log] [blame]
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001/*
2// Copyright (c) 2018 Intel Corporation
3//
4// Licensed under the Apache License, Version 2.0 (the "License");
5// you may not use this file except in compliance with the License.
6// You may obtain a copy of the License at
7//
8// http://www.apache.org/licenses/LICENSE-2.0
9//
10// Unless required by applicable law or agreed to in writing, software
11// distributed under the License is distributed on an "AS IS" BASIS,
12// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13// See the License for the specific language governing permissions and
14// limitations under the License.
15*/
16#pragma once
17
Sui Chena51fc2d2022-07-14 17:21:53 -070018#include "app.hpp"
19#include "dbus_utility.hpp"
James Feistb49ac872019-05-21 15:12:01 -070020#include "health.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070021#include "query.hpp"
Jennifer Leec5d03ff2019-03-08 15:42:58 -080022#include "redfish_util.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070023#include "registries/privilege_registry.hpp"
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020024#include "utils/dbus_utils.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070025#include "utils/sw_utils.hpp"
26#include "utils/systemd_utils.hpp"
Ed Tanous2b829372022-08-03 14:22:34 -070027#include "utils/time_utils.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010028
Santosh Puranikaf5d60582019-03-20 18:16:36 +053029#include <boost/date_time.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020030#include <sdbusplus/asio/property.hpp>
31#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050032
Ed Tanousa170f272022-06-30 21:53:27 -070033#include <algorithm>
Gunnar Mills4bfefa72020-07-30 13:54:29 -050034#include <cstdint>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050035#include <memory>
36#include <sstream>
Ed Tanousabf2add2019-01-22 16:40:12 -080037#include <variant>
James Feist5b4aa862018-08-16 14:07:01 -070038
Ed Tanous1abe55e2018-09-05 08:30:59 -070039namespace redfish
40{
Jennifer Leeed5befb2018-08-10 11:29:45 -070041
42/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -050043 * Function reboots the BMC.
44 *
45 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -070046 */
zhanghch058d1b46d2021-04-01 11:18:24 +080047inline void
48 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -050049{
50 const char* processName = "xyz.openbmc_project.State.BMC";
51 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
52 const char* interfaceName = "xyz.openbmc_project.State.BMC";
53 const std::string& propertyValue =
54 "xyz.openbmc_project.State.BMC.Transition.Reboot";
55 const char* destProperty = "RequestedBMCTransition";
56
57 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080058 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050059
60 crow::connections::systemBus->async_method_call(
61 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070062 // Use "Set" method to set the property value.
63 if (ec)
64 {
65 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
66 messages::internalError(asyncResp->res);
67 return;
68 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -050069
Ed Tanous002d39b2022-05-31 08:59:27 -070070 messages::success(asyncResp->res);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050071 },
72 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
73 interfaceName, destProperty, dbusPropertyValue);
74}
75
zhanghch058d1b46d2021-04-01 11:18:24 +080076inline void
77 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000078{
79 const char* processName = "xyz.openbmc_project.State.BMC";
80 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
81 const char* interfaceName = "xyz.openbmc_project.State.BMC";
82 const std::string& propertyValue =
83 "xyz.openbmc_project.State.BMC.Transition.HardReboot";
84 const char* destProperty = "RequestedBMCTransition";
85
86 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080087 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000088
89 crow::connections::systemBus->async_method_call(
90 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070091 // Use "Set" method to set the property value.
92 if (ec)
93 {
94 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
95 messages::internalError(asyncResp->res);
96 return;
97 }
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000098
Ed Tanous002d39b2022-05-31 08:59:27 -070099 messages::success(asyncResp->res);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000100 },
101 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
102 interfaceName, destProperty, dbusPropertyValue);
103}
104
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500105/**
106 * ManagerResetAction class supports the POST method for the Reset (reboot)
107 * action.
108 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700109inline void requestRoutesManagerResetAction(App& app)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700110{
Jennifer Leeed5befb2018-08-10 11:29:45 -0700111 /**
Jennifer Leeed5befb2018-08-10 11:29:45 -0700112 * Function handles POST method request.
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500113 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000114 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Jennifer Leeed5befb2018-08-10 11:29:45 -0700115 */
Jennifer Leeed5befb2018-08-10 11:29:45 -0700116
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700117 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700118 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700119 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700120 [&app](const crow::Request& req,
121 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000122 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700123 {
124 return;
125 }
126 BMCWEB_LOG_DEBUG << "Post Manager Reset.";
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500127
Ed Tanous002d39b2022-05-31 08:59:27 -0700128 std::string resetType;
Jennifer Leeed5befb2018-08-10 11:29:45 -0700129
Ed Tanous002d39b2022-05-31 08:59:27 -0700130 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
131 resetType))
132 {
133 return;
134 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500135
Ed Tanous002d39b2022-05-31 08:59:27 -0700136 if (resetType == "GracefulRestart")
137 {
138 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
139 doBMCGracefulRestart(asyncResp);
140 return;
141 }
142 if (resetType == "ForceRestart")
143 {
144 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
145 doBMCForceRestart(asyncResp);
146 return;
147 }
148 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
149 << resetType;
150 messages::actionParameterNotSupported(asyncResp->res, resetType,
151 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700152
Ed Tanous002d39b2022-05-31 08:59:27 -0700153 return;
154 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700155}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700156
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500157/**
158 * ManagerResetToDefaultsAction class supports POST method for factory reset
159 * action.
160 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700161inline void requestRoutesManagerResetToDefaultsAction(App& app)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500162{
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500163
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500164 /**
165 * Function handles ResetToDefaults POST method request.
166 *
167 * Analyzes POST body message and factory resets BMC by calling
168 * BMC code updater factory reset followed by a BMC reboot.
169 *
170 * BMC code updater factory reset wipes the whole BMC read-write
171 * filesystem which includes things like the network settings.
172 *
173 * OpenBMC only supports ResetToDefaultsType "ResetAll".
174 */
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500175
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700176 BMCWEB_ROUTE(app,
177 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/")
Ed Tanoused398212021-06-09 17:05:54 -0700178 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700179 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700180 [&app](const crow::Request& req,
181 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000182 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700183 {
184 return;
185 }
186 BMCWEB_LOG_DEBUG << "Post ResetToDefaults.";
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500187
Ed Tanous002d39b2022-05-31 08:59:27 -0700188 std::string resetType;
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500189
Ed Tanous002d39b2022-05-31 08:59:27 -0700190 if (!json_util::readJsonAction(req, asyncResp->res,
191 "ResetToDefaultsType", resetType))
192 {
193 BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700194
Ed Tanous002d39b2022-05-31 08:59:27 -0700195 messages::actionParameterMissing(asyncResp->res, "ResetToDefaults",
196 "ResetToDefaultsType");
197 return;
198 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700199
Ed Tanous002d39b2022-05-31 08:59:27 -0700200 if (resetType != "ResetAll")
201 {
202 BMCWEB_LOG_DEBUG
203 << "Invalid property value for ResetToDefaultsType: "
204 << resetType;
205 messages::actionParameterNotSupported(asyncResp->res, resetType,
206 "ResetToDefaultsType");
207 return;
208 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700209
Ed Tanous002d39b2022-05-31 08:59:27 -0700210 crow::connections::systemBus->async_method_call(
211 [asyncResp](const boost::system::error_code ec) {
212 if (ec)
213 {
214 BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec;
215 messages::internalError(asyncResp->res);
216 return;
217 }
218 // Factory Reset doesn't actually happen until a reboot
219 // Can't erase what the BMC is running on
220 doBMCGracefulRestart(asyncResp);
221 },
222 "xyz.openbmc_project.Software.BMC.Updater",
223 "/xyz/openbmc_project/software",
224 "xyz.openbmc_project.Common.FactoryReset", "Reset");
225 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700226}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500227
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530228/**
229 * ManagerResetActionInfo derived class for delivering Manager
230 * ResetType AllowableValues using ResetInfo schema.
231 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700232inline void requestRoutesManagerResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530233{
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530234 /**
235 * Functions triggers appropriate requests on DBus
236 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700237
238 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700239 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700240 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700241 [&app](const crow::Request& req,
242 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000243 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700244 {
245 return;
246 }
Ed Tanous14766872022-03-15 10:44:42 -0700247
Ed Tanous002d39b2022-05-31 08:59:27 -0700248 asyncResp->res.jsonValue["@odata.type"] =
249 "#ActionInfo.v1_1_2.ActionInfo";
250 asyncResp->res.jsonValue["@odata.id"] =
251 "/redfish/v1/Managers/bmc/ResetActionInfo";
252 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
253 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
254 nlohmann::json::object_t parameter;
255 parameter["Name"] = "ResetType";
256 parameter["Required"] = true;
257 parameter["DataType"] = "String";
Ed Tanous14766872022-03-15 10:44:42 -0700258
Ed Tanous002d39b2022-05-31 08:59:27 -0700259 nlohmann::json::array_t allowableValues;
260 allowableValues.push_back("GracefulRestart");
261 allowableValues.push_back("ForceRestart");
262 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700263
Ed Tanous002d39b2022-05-31 08:59:27 -0700264 nlohmann::json::array_t parameters;
265 parameters.push_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700266
Ed Tanous002d39b2022-05-31 08:59:27 -0700267 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
268 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700269}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530270
James Feist5b4aa862018-08-16 14:07:01 -0700271static constexpr const char* objectManagerIface =
272 "org.freedesktop.DBus.ObjectManager";
273static constexpr const char* pidConfigurationIface =
274 "xyz.openbmc_project.Configuration.Pid";
275static constexpr const char* pidZoneConfigurationIface =
276 "xyz.openbmc_project.Configuration.Pid.Zone";
James Feistb7a08d02018-12-11 14:55:37 -0800277static constexpr const char* stepwiseConfigurationIface =
278 "xyz.openbmc_project.Configuration.Stepwise";
James Feist73df0db2019-03-25 15:29:35 -0700279static constexpr const char* thermalModeIface =
280 "xyz.openbmc_project.Control.ThermalMode";
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100281
zhanghch058d1b46d2021-04-01 11:18:24 +0800282inline void
283 asyncPopulatePid(const std::string& connection, const std::string& path,
284 const std::string& currentProfile,
285 const std::vector<std::string>& supportedProfiles,
286 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist5b4aa862018-08-16 14:07:01 -0700287{
288
289 crow::connections::systemBus->async_method_call(
James Feist73df0db2019-03-25 15:29:35 -0700290 [asyncResp, currentProfile, supportedProfiles](
291 const boost::system::error_code ec,
292 const dbus::utility::ManagedObjectType& managedObj) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700293 if (ec)
294 {
295 BMCWEB_LOG_ERROR << ec;
296 asyncResp->res.jsonValue.clear();
297 messages::internalError(asyncResp->res);
298 return;
299 }
300 nlohmann::json& configRoot =
301 asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"];
302 nlohmann::json& fans = configRoot["FanControllers"];
303 fans["@odata.type"] = "#OemManager.FanControllers";
304 fans["@odata.id"] =
305 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers";
306
307 nlohmann::json& pids = configRoot["PidControllers"];
308 pids["@odata.type"] = "#OemManager.PidControllers";
309 pids["@odata.id"] =
310 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers";
311
312 nlohmann::json& stepwise = configRoot["StepwiseControllers"];
313 stepwise["@odata.type"] = "#OemManager.StepwiseControllers";
314 stepwise["@odata.id"] =
315 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers";
316
317 nlohmann::json& zones = configRoot["FanZones"];
318 zones["@odata.id"] =
319 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones";
320 zones["@odata.type"] = "#OemManager.FanZones";
321 configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan";
322 configRoot["@odata.type"] = "#OemManager.Fan";
323 configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles;
324
325 if (!currentProfile.empty())
326 {
327 configRoot["Profile"] = currentProfile;
328 }
329 BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !";
330
331 for (const auto& pathPair : managedObj)
332 {
333 for (const auto& intfPair : pathPair.second)
James Feist5b4aa862018-08-16 14:07:01 -0700334 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700335 if (intfPair.first != pidConfigurationIface &&
336 intfPair.first != pidZoneConfigurationIface &&
337 intfPair.first != stepwiseConfigurationIface)
James Feist5b4aa862018-08-16 14:07:01 -0700338 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700339 continue;
340 }
James Feist73df0db2019-03-25 15:29:35 -0700341
Ed Tanous002d39b2022-05-31 08:59:27 -0700342 std::string name;
James Feist73df0db2019-03-25 15:29:35 -0700343
Ed Tanous002d39b2022-05-31 08:59:27 -0700344 for (const std::pair<std::string,
345 dbus::utility::DbusVariantType>& propPair :
346 intfPair.second)
347 {
348 if (propPair.first == "Name")
James Feist73df0db2019-03-25 15:29:35 -0700349 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700350 const std::string* namePtr =
351 std::get_if<std::string>(&propPair.second);
352 if (namePtr == nullptr)
James Feist73df0db2019-03-25 15:29:35 -0700353 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700354 BMCWEB_LOG_ERROR << "Pid Name Field illegal";
James Feistc33a90e2019-03-01 10:17:44 -0800355 messages::internalError(asyncResp->res);
356 return;
357 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700358 name = *namePtr;
359 dbus::utility::escapePathForDbus(name);
James Feistb7a08d02018-12-11 14:55:37 -0800360 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700361 else if (propPair.first == "Profiles")
James Feistb7a08d02018-12-11 14:55:37 -0800362 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700363 const std::vector<std::string>* profiles =
364 std::get_if<std::vector<std::string>>(
365 &propPair.second);
366 if (profiles == nullptr)
James Feistb7a08d02018-12-11 14:55:37 -0800367 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700368 BMCWEB_LOG_ERROR << "Pid Profiles Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800369 messages::internalError(asyncResp->res);
370 return;
371 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700372 if (std::find(profiles->begin(), profiles->end(),
373 currentProfile) == profiles->end())
James Feistb7a08d02018-12-11 14:55:37 -0800374 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700375 BMCWEB_LOG_INFO
376 << name << " not supported in current profile";
377 continue;
James Feistb7a08d02018-12-11 14:55:37 -0800378 }
379 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700380 }
381 nlohmann::json* config = nullptr;
382 const std::string* classPtr = nullptr;
383
384 for (const std::pair<std::string,
385 dbus::utility::DbusVariantType>& propPair :
386 intfPair.second)
387 {
388 if (propPair.first == "Class")
James Feistb7a08d02018-12-11 14:55:37 -0800389 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700390 classPtr = std::get_if<std::string>(&propPair.second);
391 }
392 }
393
394 if (intfPair.first == pidZoneConfigurationIface)
395 {
396 std::string chassis;
397 if (!dbus::utility::getNthStringFromPath(pathPair.first.str,
398 5, chassis))
399 {
400 chassis = "#IllegalValue";
401 }
402 nlohmann::json& zone = zones[name];
Ed Tanous613dabe2022-07-09 11:17:36 -0700403 zone["Chassis"]["@odata.id"] =
404 "/redfish/v1/Chassis/" + chassis;
Ed Tanous002d39b2022-05-31 08:59:27 -0700405 zone["@odata.id"] =
406 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
407 name;
408 zone["@odata.type"] = "#OemManager.FanZone";
409 config = &zone;
410 }
411
412 else if (intfPair.first == stepwiseConfigurationIface)
413 {
414 if (classPtr == nullptr)
415 {
416 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800417 messages::internalError(asyncResp->res);
418 return;
419 }
420
Ed Tanous002d39b2022-05-31 08:59:27 -0700421 nlohmann::json& controller = stepwise[name];
422 config = &controller;
James Feistb7a08d02018-12-11 14:55:37 -0800423
Ed Tanous002d39b2022-05-31 08:59:27 -0700424 controller["@odata.id"] =
425 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers/" +
426 name;
427 controller["@odata.type"] =
428 "#OemManager.StepwiseController";
429
430 controller["Direction"] = *classPtr;
431 }
432
433 // pid and fans are off the same configuration
434 else if (intfPair.first == pidConfigurationIface)
435 {
436
437 if (classPtr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700438 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700439 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
440 messages::internalError(asyncResp->res);
441 return;
442 }
443 bool isFan = *classPtr == "fan";
444 nlohmann::json& element = isFan ? fans[name] : pids[name];
445 config = &element;
446 if (isFan)
447 {
448 element["@odata.id"] =
449 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers/" +
450 name;
451 element["@odata.type"] = "#OemManager.FanController";
452 }
453 else
454 {
455 element["@odata.id"] =
456 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers/" +
457 name;
458 element["@odata.type"] = "#OemManager.PidController";
459 }
460 }
461 else
462 {
463 BMCWEB_LOG_ERROR << "Unexpected configuration";
464 messages::internalError(asyncResp->res);
465 return;
466 }
James Feist5b4aa862018-08-16 14:07:01 -0700467
Ed Tanous002d39b2022-05-31 08:59:27 -0700468 // used for making maps out of 2 vectors
469 const std::vector<double>* keys = nullptr;
470 const std::vector<double>* values = nullptr;
471
472 for (const auto& propertyPair : intfPair.second)
473 {
474 if (propertyPair.first == "Type" ||
475 propertyPair.first == "Class" ||
476 propertyPair.first == "Name")
477 {
478 continue;
479 }
480
481 // zones
482 if (intfPair.first == pidZoneConfigurationIface)
483 {
484 const double* ptr =
485 std::get_if<double>(&propertyPair.second);
486 if (ptr == nullptr)
487 {
488 BMCWEB_LOG_ERROR << "Field Illegal "
489 << propertyPair.first;
490 messages::internalError(asyncResp->res);
491 return;
492 }
493 (*config)[propertyPair.first] = *ptr;
494 }
495
496 if (intfPair.first == stepwiseConfigurationIface)
497 {
498 if (propertyPair.first == "Reading" ||
499 propertyPair.first == "Output")
500 {
501 const std::vector<double>* ptr =
502 std::get_if<std::vector<double>>(
503 &propertyPair.second);
504
505 if (ptr == nullptr)
506 {
507 BMCWEB_LOG_ERROR << "Field Illegal "
508 << propertyPair.first;
509 messages::internalError(asyncResp->res);
510 return;
511 }
512
513 if (propertyPair.first == "Reading")
514 {
515 keys = ptr;
516 }
517 else
518 {
519 values = ptr;
520 }
521 if (keys != nullptr && values != nullptr)
522 {
523 if (keys->size() != values->size())
524 {
525 BMCWEB_LOG_ERROR
526 << "Reading and Output size don't match ";
527 messages::internalError(asyncResp->res);
528 return;
529 }
530 nlohmann::json& steps = (*config)["Steps"];
531 steps = nlohmann::json::array();
532 for (size_t ii = 0; ii < keys->size(); ii++)
533 {
534 nlohmann::json::object_t step;
535 step["Target"] = (*keys)[ii];
536 step["Output"] = (*values)[ii];
537 steps.push_back(std::move(step));
538 }
539 }
540 }
541 if (propertyPair.first == "NegativeHysteresis" ||
542 propertyPair.first == "PositiveHysteresis")
James Feist5b4aa862018-08-16 14:07:01 -0700543 {
Ed Tanous1b6b96c2018-11-30 11:35:41 -0800544 const double* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800545 std::get_if<double>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700546 if (ptr == nullptr)
547 {
548 BMCWEB_LOG_ERROR << "Field Illegal "
549 << propertyPair.first;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700550 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700551 return;
552 }
James Feistb7a08d02018-12-11 14:55:37 -0800553 (*config)[propertyPair.first] = *ptr;
554 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700555 }
James Feistb7a08d02018-12-11 14:55:37 -0800556
Ed Tanous002d39b2022-05-31 08:59:27 -0700557 // pid and fans are off the same configuration
558 if (intfPair.first == pidConfigurationIface ||
559 intfPair.first == stepwiseConfigurationIface)
560 {
561
562 if (propertyPair.first == "Zones")
James Feistb7a08d02018-12-11 14:55:37 -0800563 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700564 const std::vector<std::string>* inputs =
565 std::get_if<std::vector<std::string>>(
566 &propertyPair.second);
567
568 if (inputs == nullptr)
James Feistb7a08d02018-12-11 14:55:37 -0800569 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700570 BMCWEB_LOG_ERROR << "Zones Pid Field Illegal";
571 messages::internalError(asyncResp->res);
572 return;
James Feistb7a08d02018-12-11 14:55:37 -0800573 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700574 auto& data = (*config)[propertyPair.first];
575 data = nlohmann::json::array();
576 for (std::string itemCopy : *inputs)
James Feistb7a08d02018-12-11 14:55:37 -0800577 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700578 dbus::utility::escapePathForDbus(itemCopy);
579 nlohmann::json::object_t input;
580 input["@odata.id"] =
581 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
582 itemCopy;
583 data.push_back(std::move(input));
James Feistb7a08d02018-12-11 14:55:37 -0800584 }
James Feist5b4aa862018-08-16 14:07:01 -0700585 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700586 // todo(james): may never happen, but this
587 // assumes configuration data referenced in the
588 // PID config is provided by the same daemon, we
589 // could add another loop to cover all cases,
590 // but I'm okay kicking this can down the road a
591 // bit
James Feist5b4aa862018-08-16 14:07:01 -0700592
Ed Tanous002d39b2022-05-31 08:59:27 -0700593 else if (propertyPair.first == "Inputs" ||
594 propertyPair.first == "Outputs")
James Feist5b4aa862018-08-16 14:07:01 -0700595 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700596 auto& data = (*config)[propertyPair.first];
597 const std::vector<std::string>* inputs =
598 std::get_if<std::vector<std::string>>(
599 &propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700600
Ed Tanous002d39b2022-05-31 08:59:27 -0700601 if (inputs == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700602 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700603 BMCWEB_LOG_ERROR << "Field Illegal "
604 << propertyPair.first;
605 messages::internalError(asyncResp->res);
606 return;
James Feist5b4aa862018-08-16 14:07:01 -0700607 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700608 data = *inputs;
609 }
610 else if (propertyPair.first == "SetPointOffset")
611 {
612 const std::string* ptr =
613 std::get_if<std::string>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700614
Ed Tanous002d39b2022-05-31 08:59:27 -0700615 if (ptr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700616 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700617 BMCWEB_LOG_ERROR << "Field Illegal "
618 << propertyPair.first;
619 messages::internalError(asyncResp->res);
620 return;
James Feistb943aae2019-07-11 16:33:56 -0700621 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700622 // translate from dbus to redfish
623 if (*ptr == "WarningHigh")
James Feistb943aae2019-07-11 16:33:56 -0700624 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700625 (*config)["SetPointOffset"] =
626 "UpperThresholdNonCritical";
James Feistb943aae2019-07-11 16:33:56 -0700627 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700628 else if (*ptr == "WarningLow")
James Feist5b4aa862018-08-16 14:07:01 -0700629 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700630 (*config)["SetPointOffset"] =
631 "LowerThresholdNonCritical";
James Feist5b4aa862018-08-16 14:07:01 -0700632 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700633 else if (*ptr == "CriticalHigh")
634 {
635 (*config)["SetPointOffset"] =
636 "UpperThresholdCritical";
637 }
638 else if (*ptr == "CriticalLow")
639 {
640 (*config)["SetPointOffset"] =
641 "LowerThresholdCritical";
642 }
643 else
644 {
645 BMCWEB_LOG_ERROR << "Value Illegal " << *ptr;
646 messages::internalError(asyncResp->res);
647 return;
648 }
649 }
650 // doubles
651 else if (propertyPair.first == "FFGainCoefficient" ||
652 propertyPair.first == "FFOffCoefficient" ||
653 propertyPair.first == "ICoefficient" ||
654 propertyPair.first == "ILimitMax" ||
655 propertyPair.first == "ILimitMin" ||
656 propertyPair.first == "PositiveHysteresis" ||
657 propertyPair.first == "NegativeHysteresis" ||
658 propertyPair.first == "OutLimitMax" ||
659 propertyPair.first == "OutLimitMin" ||
660 propertyPair.first == "PCoefficient" ||
661 propertyPair.first == "SetPoint" ||
662 propertyPair.first == "SlewNeg" ||
663 propertyPair.first == "SlewPos")
664 {
665 const double* ptr =
666 std::get_if<double>(&propertyPair.second);
667 if (ptr == nullptr)
668 {
669 BMCWEB_LOG_ERROR << "Field Illegal "
670 << propertyPair.first;
671 messages::internalError(asyncResp->res);
672 return;
673 }
674 (*config)[propertyPair.first] = *ptr;
James Feist5b4aa862018-08-16 14:07:01 -0700675 }
676 }
677 }
678 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700679 }
James Feist5b4aa862018-08-16 14:07:01 -0700680 },
681 connection, path, objectManagerIface, "GetManagedObjects");
682}
Jennifer Leeca537922018-08-10 10:07:30 -0700683
James Feist83ff9ab2018-08-31 10:18:24 -0700684enum class CreatePIDRet
685{
686 fail,
687 del,
688 patch
689};
690
zhanghch058d1b46d2021-04-01 11:18:24 +0800691inline bool
692 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response,
693 std::vector<nlohmann::json>& config,
694 std::vector<std::string>& zones)
James Feist5f2caae2018-12-12 14:08:25 -0800695{
James Feistb6baeaa2019-02-21 10:41:40 -0800696 if (config.empty())
697 {
698 BMCWEB_LOG_ERROR << "Empty Zones";
Ed Tanous1668ce62022-02-07 23:44:31 -0800699 messages::propertyValueFormatError(response->res, "[]", "Zones");
James Feistb6baeaa2019-02-21 10:41:40 -0800700 return false;
701 }
James Feist5f2caae2018-12-12 14:08:25 -0800702 for (auto& odata : config)
703 {
704 std::string path;
705 if (!redfish::json_util::readJson(odata, response->res, "@odata.id",
706 path))
707 {
708 return false;
709 }
710 std::string input;
James Feist61adbda2019-03-25 13:03:51 -0700711
712 // 8 below comes from
713 // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left
714 // 0 1 2 3 4 5 6 7 8
715 if (!dbus::utility::getNthStringFromPath(path, 8, input))
James Feist5f2caae2018-12-12 14:08:25 -0800716 {
717 BMCWEB_LOG_ERROR << "Got invalid path " << path;
718 BMCWEB_LOG_ERROR << "Illegal Type Zones";
719 messages::propertyValueFormatError(response->res, odata.dump(),
720 "Zones");
721 return false;
722 }
Ed Tanousa170f272022-06-30 21:53:27 -0700723 std::replace(input.begin(), input.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -0800724 zones.emplace_back(std::move(input));
725 }
726 return true;
727}
728
Ed Tanous711ac7a2021-12-20 09:34:41 -0800729inline const dbus::utility::ManagedObjectType::value_type*
James Feist73df0db2019-03-25 15:29:35 -0700730 findChassis(const dbus::utility::ManagedObjectType& managedObj,
731 const std::string& value, std::string& chassis)
James Feistb6baeaa2019-02-21 10:41:40 -0800732{
733 BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n";
734
Ed Tanousa170f272022-06-30 21:53:27 -0700735 std::string escaped = value;
736 std::replace(escaped.begin(), escaped.end(), '_', ' ');
James Feistb6baeaa2019-02-21 10:41:40 -0800737 escaped = "/" + escaped;
Ed Tanous002d39b2022-05-31 08:59:27 -0700738 auto it = std::find_if(managedObj.begin(), managedObj.end(),
739 [&escaped](const auto& obj) {
740 if (boost::algorithm::ends_with(obj.first.str, escaped))
741 {
742 BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n";
743 return true;
744 }
745 return false;
746 });
James Feistb6baeaa2019-02-21 10:41:40 -0800747
748 if (it == managedObj.end())
749 {
James Feist73df0db2019-03-25 15:29:35 -0700750 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800751 }
752 // 5 comes from <chassis-name> being the 5th element
753 // /xyz/openbmc_project/inventory/system/chassis/<chassis-name>
James Feist73df0db2019-03-25 15:29:35 -0700754 if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis))
755 {
756 return &(*it);
757 }
758
759 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800760}
761
Ed Tanous23a21a12020-07-25 04:45:05 +0000762inline CreatePIDRet createPidInterface(
zhanghch058d1b46d2021-04-01 11:18:24 +0800763 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type,
Ed Tanousb5a76932020-09-29 16:16:58 -0700764 const nlohmann::json::iterator& it, const std::string& path,
James Feist83ff9ab2018-08-31 10:18:24 -0700765 const dbus::utility::ManagedObjectType& managedObj, bool createNewObject,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800766 dbus::utility::DBusPropertiesMap& output, std::string& chassis,
767 const std::string& profile)
James Feist83ff9ab2018-08-31 10:18:24 -0700768{
769
James Feist5f2caae2018-12-12 14:08:25 -0800770 // common deleter
James Feistb6baeaa2019-02-21 10:41:40 -0800771 if (it.value() == nullptr)
James Feist5f2caae2018-12-12 14:08:25 -0800772 {
773 std::string iface;
774 if (type == "PidControllers" || type == "FanControllers")
775 {
776 iface = pidConfigurationIface;
777 }
778 else if (type == "FanZones")
779 {
780 iface = pidZoneConfigurationIface;
781 }
782 else if (type == "StepwiseControllers")
783 {
784 iface = stepwiseConfigurationIface;
785 }
786 else
787 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600788 BMCWEB_LOG_ERROR << "Illegal Type " << type;
James Feist5f2caae2018-12-12 14:08:25 -0800789 messages::propertyUnknown(response->res, type);
790 return CreatePIDRet::fail;
791 }
James Feist6ee7f772020-02-06 16:25:27 -0800792
793 BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n";
James Feist5f2caae2018-12-12 14:08:25 -0800794 // delete interface
795 crow::connections::systemBus->async_method_call(
796 [response, path](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700797 if (ec)
798 {
799 BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec;
800 messages::internalError(response->res);
801 return;
802 }
803 messages::success(response->res);
James Feist5f2caae2018-12-12 14:08:25 -0800804 },
805 "xyz.openbmc_project.EntityManager", path, iface, "Delete");
806 return CreatePIDRet::del;
807 }
808
Ed Tanous711ac7a2021-12-20 09:34:41 -0800809 const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800810 if (!createNewObject)
811 {
812 // if we aren't creating a new object, we should be able to find it on
813 // d-bus
James Feist73df0db2019-03-25 15:29:35 -0700814 managedItem = findChassis(managedObj, it.key(), chassis);
815 if (managedItem == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800816 {
817 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700818 messages::invalidObject(response->res,
819 crow::utility::urlFromPieces(
820 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800821 return CreatePIDRet::fail;
822 }
823 }
824
Ed Tanous26f69762022-01-25 09:49:11 -0800825 if (!profile.empty() &&
James Feist73df0db2019-03-25 15:29:35 -0700826 (type == "PidControllers" || type == "FanControllers" ||
827 type == "StepwiseControllers"))
828 {
829 if (managedItem == nullptr)
830 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800831 output.emplace_back("Profiles", std::vector<std::string>{profile});
James Feist73df0db2019-03-25 15:29:35 -0700832 }
833 else
834 {
835 std::string interface;
836 if (type == "StepwiseControllers")
837 {
838 interface = stepwiseConfigurationIface;
839 }
840 else
841 {
842 interface = pidConfigurationIface;
843 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800844 bool ifaceFound = false;
845 for (const auto& iface : managedItem->second)
846 {
847 if (iface.first == interface)
848 {
849 ifaceFound = true;
850 for (const auto& prop : iface.second)
851 {
852 if (prop.first == "Profiles")
853 {
854 const std::vector<std::string>* curProfiles =
855 std::get_if<std::vector<std::string>>(
856 &(prop.second));
857 if (curProfiles == nullptr)
858 {
859 BMCWEB_LOG_ERROR
860 << "Illegal profiles in managed object";
861 messages::internalError(response->res);
862 return CreatePIDRet::fail;
863 }
864 if (std::find(curProfiles->begin(),
865 curProfiles->end(),
866 profile) == curProfiles->end())
867 {
868 std::vector<std::string> newProfiles =
869 *curProfiles;
870 newProfiles.push_back(profile);
Ed Tanousb9d36b42022-02-26 21:42:46 -0800871 output.emplace_back("Profiles", newProfiles);
Ed Tanous711ac7a2021-12-20 09:34:41 -0800872 }
873 }
874 }
875 }
876 }
877
878 if (!ifaceFound)
James Feist73df0db2019-03-25 15:29:35 -0700879 {
880 BMCWEB_LOG_ERROR
881 << "Failed to find interface in managed object";
882 messages::internalError(response->res);
883 return CreatePIDRet::fail;
884 }
James Feist73df0db2019-03-25 15:29:35 -0700885 }
886 }
887
James Feist83ff9ab2018-08-31 10:18:24 -0700888 if (type == "PidControllers" || type == "FanControllers")
889 {
890 if (createNewObject)
891 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800892 output.emplace_back("Class",
893 type == "PidControllers" ? "temp" : "fan");
894 output.emplace_back("Type", "Pid");
James Feist83ff9ab2018-08-31 10:18:24 -0700895 }
James Feist5f2caae2018-12-12 14:08:25 -0800896
897 std::optional<std::vector<nlohmann::json>> zones;
898 std::optional<std::vector<std::string>> inputs;
899 std::optional<std::vector<std::string>> outputs;
900 std::map<std::string, std::optional<double>> doubles;
James Feistb943aae2019-07-11 16:33:56 -0700901 std::optional<std::string> setpointOffset;
James Feist5f2caae2018-12-12 14:08:25 -0800902 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -0800903 it.value(), response->res, "Inputs", inputs, "Outputs", outputs,
James Feist5f2caae2018-12-12 14:08:25 -0800904 "Zones", zones, "FFGainCoefficient",
905 doubles["FFGainCoefficient"], "FFOffCoefficient",
906 doubles["FFOffCoefficient"], "ICoefficient",
907 doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"],
908 "ILimitMin", doubles["ILimitMin"], "OutLimitMax",
909 doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"],
910 "PCoefficient", doubles["PCoefficient"], "SetPoint",
James Feistb943aae2019-07-11 16:33:56 -0700911 doubles["SetPoint"], "SetPointOffset", setpointOffset,
912 "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"],
913 "PositiveHysteresis", doubles["PositiveHysteresis"],
914 "NegativeHysteresis", doubles["NegativeHysteresis"]))
James Feist83ff9ab2018-08-31 10:18:24 -0700915 {
Ed Tanous71f52d92021-02-19 08:51:17 -0800916 BMCWEB_LOG_ERROR
917 << "Illegal Property "
918 << it.value().dump(2, ' ', true,
919 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -0800920 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700921 }
James Feist5f2caae2018-12-12 14:08:25 -0800922 if (zones)
James Feist83ff9ab2018-08-31 10:18:24 -0700923 {
James Feist5f2caae2018-12-12 14:08:25 -0800924 std::vector<std::string> zonesStr;
925 if (!getZonesFromJsonReq(response, *zones, zonesStr))
James Feist83ff9ab2018-08-31 10:18:24 -0700926 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600927 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -0800928 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700929 }
James Feistb6baeaa2019-02-21 10:41:40 -0800930 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -0800931 findChassis(managedObj, zonesStr[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800932 {
933 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700934 messages::invalidObject(
935 response->res, crow::utility::urlFromPieces(
936 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800937 return CreatePIDRet::fail;
938 }
Ed Tanousb9d36b42022-02-26 21:42:46 -0800939 output.emplace_back("Zones", std::move(zonesStr));
James Feist5f2caae2018-12-12 14:08:25 -0800940 }
941 if (inputs || outputs)
942 {
Ed Tanous02cad962022-06-30 16:50:15 -0700943 std::array<
944 std::reference_wrapper<std::optional<std::vector<std::string>>>,
945 2>
946 containers = {inputs, outputs};
James Feist5f2caae2018-12-12 14:08:25 -0800947 size_t index = 0;
Ed Tanous02cad962022-06-30 16:50:15 -0700948 for (std::optional<std::vector<std::string>>& container :
949 containers)
James Feist83ff9ab2018-08-31 10:18:24 -0700950 {
James Feist5f2caae2018-12-12 14:08:25 -0800951 if (!container)
James Feist83ff9ab2018-08-31 10:18:24 -0700952 {
James Feist5f2caae2018-12-12 14:08:25 -0800953 index++;
954 continue;
James Feist83ff9ab2018-08-31 10:18:24 -0700955 }
James Feist5f2caae2018-12-12 14:08:25 -0800956 for (std::string& value : *container)
James Feist83ff9ab2018-08-31 10:18:24 -0700957 {
Ed Tanousa170f272022-06-30 21:53:27 -0700958 std::replace(value.begin(), value.end(), '_', ' ');
James Feist83ff9ab2018-08-31 10:18:24 -0700959 }
James Feist5f2caae2018-12-12 14:08:25 -0800960 std::string key;
961 if (index == 0)
James Feist83ff9ab2018-08-31 10:18:24 -0700962 {
James Feist5f2caae2018-12-12 14:08:25 -0800963 key = "Inputs";
James Feist83ff9ab2018-08-31 10:18:24 -0700964 }
James Feist5f2caae2018-12-12 14:08:25 -0800965 else
966 {
967 key = "Outputs";
968 }
Ed Tanousb9d36b42022-02-26 21:42:46 -0800969 output.emplace_back(key, *container);
James Feist5f2caae2018-12-12 14:08:25 -0800970 index++;
James Feist83ff9ab2018-08-31 10:18:24 -0700971 }
James Feist5f2caae2018-12-12 14:08:25 -0800972 }
James Feist83ff9ab2018-08-31 10:18:24 -0700973
James Feistb943aae2019-07-11 16:33:56 -0700974 if (setpointOffset)
975 {
976 // translate between redfish and dbus names
977 if (*setpointOffset == "UpperThresholdNonCritical")
978 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800979 output.emplace_back("SetPointOffset", "WarningLow");
James Feistb943aae2019-07-11 16:33:56 -0700980 }
981 else if (*setpointOffset == "LowerThresholdNonCritical")
982 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800983 output.emplace_back("SetPointOffset", "WarningHigh");
James Feistb943aae2019-07-11 16:33:56 -0700984 }
985 else if (*setpointOffset == "LowerThresholdCritical")
986 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800987 output.emplace_back("SetPointOffset", "CriticalLow");
James Feistb943aae2019-07-11 16:33:56 -0700988 }
989 else if (*setpointOffset == "UpperThresholdCritical")
990 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800991 output.emplace_back("SetPointOffset", "CriticalHigh");
James Feistb943aae2019-07-11 16:33:56 -0700992 }
993 else
994 {
995 BMCWEB_LOG_ERROR << "Invalid setpointoffset "
996 << *setpointOffset;
Ed Tanousace85d62021-10-26 12:45:59 -0700997 messages::propertyValueNotInList(response->res, it.key(),
998 "SetPointOffset");
James Feistb943aae2019-07-11 16:33:56 -0700999 return CreatePIDRet::fail;
1000 }
1001 }
1002
James Feist5f2caae2018-12-12 14:08:25 -08001003 // doubles
1004 for (const auto& pairs : doubles)
1005 {
1006 if (!pairs.second)
James Feist83ff9ab2018-08-31 10:18:24 -07001007 {
James Feist5f2caae2018-12-12 14:08:25 -08001008 continue;
James Feist83ff9ab2018-08-31 10:18:24 -07001009 }
James Feist5f2caae2018-12-12 14:08:25 -08001010 BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second;
Ed Tanousb9d36b42022-02-26 21:42:46 -08001011 output.emplace_back(pairs.first, *pairs.second);
James Feist83ff9ab2018-08-31 10:18:24 -07001012 }
1013 }
James Feist5f2caae2018-12-12 14:08:25 -08001014
James Feist83ff9ab2018-08-31 10:18:24 -07001015 else if (type == "FanZones")
1016 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001017 output.emplace_back("Type", "Pid.Zone");
James Feist83ff9ab2018-08-31 10:18:24 -07001018
James Feist5f2caae2018-12-12 14:08:25 -08001019 std::optional<nlohmann::json> chassisContainer;
1020 std::optional<double> failSafePercent;
James Feistd3ec07f2019-02-25 14:51:15 -08001021 std::optional<double> minThermalOutput;
James Feistb6baeaa2019-02-21 10:41:40 -08001022 if (!redfish::json_util::readJson(it.value(), response->res, "Chassis",
James Feist5f2caae2018-12-12 14:08:25 -08001023 chassisContainer, "FailSafePercent",
James Feistd3ec07f2019-02-25 14:51:15 -08001024 failSafePercent, "MinThermalOutput",
1025 minThermalOutput))
James Feist83ff9ab2018-08-31 10:18:24 -07001026 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001027 BMCWEB_LOG_ERROR
1028 << "Illegal Property "
1029 << it.value().dump(2, ' ', true,
1030 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001031 return CreatePIDRet::fail;
1032 }
James Feist83ff9ab2018-08-31 10:18:24 -07001033
James Feist5f2caae2018-12-12 14:08:25 -08001034 if (chassisContainer)
1035 {
1036
1037 std::string chassisId;
1038 if (!redfish::json_util::readJson(*chassisContainer, response->res,
1039 "@odata.id", chassisId))
James Feist83ff9ab2018-08-31 10:18:24 -07001040 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001041 BMCWEB_LOG_ERROR
1042 << "Illegal Property "
1043 << chassisContainer->dump(
1044 2, ' ', true,
1045 nlohmann::json::error_handler_t::replace);
James Feist83ff9ab2018-08-31 10:18:24 -07001046 return CreatePIDRet::fail;
1047 }
James Feist5f2caae2018-12-12 14:08:25 -08001048
AppaRao Puli717794d2019-10-18 22:54:53 +05301049 // /redfish/v1/chassis/chassis_name/
James Feist5f2caae2018-12-12 14:08:25 -08001050 if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis))
1051 {
1052 BMCWEB_LOG_ERROR << "Got invalid path " << chassisId;
Ed Tanousace85d62021-10-26 12:45:59 -07001053 messages::invalidObject(
1054 response->res, crow::utility::urlFromPieces(
1055 "redfish", "v1", "Chassis", chassisId));
James Feist5f2caae2018-12-12 14:08:25 -08001056 return CreatePIDRet::fail;
1057 }
1058 }
James Feistd3ec07f2019-02-25 14:51:15 -08001059 if (minThermalOutput)
James Feist5f2caae2018-12-12 14:08:25 -08001060 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001061 output.emplace_back("MinThermalOutput", *minThermalOutput);
James Feist5f2caae2018-12-12 14:08:25 -08001062 }
1063 if (failSafePercent)
1064 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001065 output.emplace_back("FailSafePercent", *failSafePercent);
James Feist5f2caae2018-12-12 14:08:25 -08001066 }
1067 }
1068 else if (type == "StepwiseControllers")
1069 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001070 output.emplace_back("Type", "Stepwise");
James Feist5f2caae2018-12-12 14:08:25 -08001071
1072 std::optional<std::vector<nlohmann::json>> zones;
1073 std::optional<std::vector<nlohmann::json>> steps;
1074 std::optional<std::vector<std::string>> inputs;
1075 std::optional<double> positiveHysteresis;
1076 std::optional<double> negativeHysteresis;
James Feistc33a90e2019-03-01 10:17:44 -08001077 std::optional<std::string> direction; // upper clipping curve vs lower
James Feist5f2caae2018-12-12 14:08:25 -08001078 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -08001079 it.value(), response->res, "Zones", zones, "Steps", steps,
1080 "Inputs", inputs, "PositiveHysteresis", positiveHysteresis,
James Feistc33a90e2019-03-01 10:17:44 -08001081 "NegativeHysteresis", negativeHysteresis, "Direction",
1082 direction))
James Feist5f2caae2018-12-12 14:08:25 -08001083 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001084 BMCWEB_LOG_ERROR
1085 << "Illegal Property "
1086 << it.value().dump(2, ' ', true,
1087 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001088 return CreatePIDRet::fail;
1089 }
1090
1091 if (zones)
1092 {
James Feistb6baeaa2019-02-21 10:41:40 -08001093 std::vector<std::string> zonesStrs;
1094 if (!getZonesFromJsonReq(response, *zones, zonesStrs))
James Feist5f2caae2018-12-12 14:08:25 -08001095 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001096 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -08001097 return CreatePIDRet::fail;
1098 }
James Feistb6baeaa2019-02-21 10:41:40 -08001099 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -08001100 findChassis(managedObj, zonesStrs[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -08001101 {
1102 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -07001103 messages::invalidObject(
1104 response->res, crow::utility::urlFromPieces(
1105 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -08001106 return CreatePIDRet::fail;
1107 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001108 output.emplace_back("Zones", std::move(zonesStrs));
James Feist5f2caae2018-12-12 14:08:25 -08001109 }
1110 if (steps)
1111 {
1112 std::vector<double> readings;
1113 std::vector<double> outputs;
1114 for (auto& step : *steps)
1115 {
Ed Tanous543f4402022-01-06 13:12:53 -08001116 double target = 0.0;
1117 double out = 0.0;
James Feist5f2caae2018-12-12 14:08:25 -08001118
1119 if (!redfish::json_util::readJson(step, response->res, "Target",
Ed Tanous23a21a12020-07-25 04:45:05 +00001120 target, "Output", out))
James Feist5f2caae2018-12-12 14:08:25 -08001121 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001122 BMCWEB_LOG_ERROR
1123 << "Illegal Property "
1124 << it.value().dump(
1125 2, ' ', true,
1126 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001127 return CreatePIDRet::fail;
1128 }
1129 readings.emplace_back(target);
Ed Tanous23a21a12020-07-25 04:45:05 +00001130 outputs.emplace_back(out);
James Feist5f2caae2018-12-12 14:08:25 -08001131 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001132 output.emplace_back("Reading", std::move(readings));
1133 output.emplace_back("Output", std::move(outputs));
James Feist5f2caae2018-12-12 14:08:25 -08001134 }
1135 if (inputs)
1136 {
1137 for (std::string& value : *inputs)
1138 {
Ed Tanousa170f272022-06-30 21:53:27 -07001139
1140 std::replace(value.begin(), value.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -08001141 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001142 output.emplace_back("Inputs", std::move(*inputs));
James Feist5f2caae2018-12-12 14:08:25 -08001143 }
1144 if (negativeHysteresis)
1145 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001146 output.emplace_back("NegativeHysteresis", *negativeHysteresis);
James Feist5f2caae2018-12-12 14:08:25 -08001147 }
1148 if (positiveHysteresis)
1149 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001150 output.emplace_back("PositiveHysteresis", *positiveHysteresis);
James Feist83ff9ab2018-08-31 10:18:24 -07001151 }
James Feistc33a90e2019-03-01 10:17:44 -08001152 if (direction)
1153 {
1154 constexpr const std::array<const char*, 2> allowedDirections = {
1155 "Ceiling", "Floor"};
1156 if (std::find(allowedDirections.begin(), allowedDirections.end(),
1157 *direction) == allowedDirections.end())
1158 {
1159 messages::propertyValueTypeError(response->res, "Direction",
1160 *direction);
1161 return CreatePIDRet::fail;
1162 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001163 output.emplace_back("Class", *direction);
James Feistc33a90e2019-03-01 10:17:44 -08001164 }
James Feist83ff9ab2018-08-31 10:18:24 -07001165 }
1166 else
1167 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001168 BMCWEB_LOG_ERROR << "Illegal Type " << type;
Jason M. Bills35a62c72018-10-09 12:45:45 -07001169 messages::propertyUnknown(response->res, type);
James Feist83ff9ab2018-08-31 10:18:24 -07001170 return CreatePIDRet::fail;
1171 }
1172 return CreatePIDRet::patch;
1173}
James Feist73df0db2019-03-25 15:29:35 -07001174struct GetPIDValues : std::enable_shared_from_this<GetPIDValues>
1175{
Ed Tanous6936afe2022-09-08 15:10:39 -07001176 struct CompletionValues
1177 {
1178 std::vector<std::string> supportedProfiles;
1179 std::string currentProfile;
1180 dbus::utility::MapperGetSubTreeResponse subtree;
1181 };
James Feist73df0db2019-03-25 15:29:35 -07001182
Ed Tanous4e23a442022-06-06 09:57:26 -07001183 explicit GetPIDValues(
1184 const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) :
Ed Tanous23a21a12020-07-25 04:45:05 +00001185 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001186
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001187 {}
James Feist73df0db2019-03-25 15:29:35 -07001188
1189 void run()
1190 {
1191 std::shared_ptr<GetPIDValues> self = shared_from_this();
1192
1193 // get all configurations
1194 crow::connections::systemBus->async_method_call(
Ed Tanousb9d36b42022-02-26 21:42:46 -08001195 [self](
1196 const boost::system::error_code ec,
1197 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001198 if (ec)
1199 {
1200 BMCWEB_LOG_ERROR << ec;
1201 messages::internalError(self->asyncResp->res);
1202 return;
1203 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001204 self->complete.subtree = subtreeLocal;
James Feist73df0db2019-03-25 15:29:35 -07001205 },
1206 "xyz.openbmc_project.ObjectMapper",
1207 "/xyz/openbmc_project/object_mapper",
1208 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1209 std::array<const char*, 4>{
1210 pidConfigurationIface, pidZoneConfigurationIface,
1211 objectManagerIface, stepwiseConfigurationIface});
1212
1213 // at the same time get the selected profile
1214 crow::connections::systemBus->async_method_call(
Ed Tanousb9d36b42022-02-26 21:42:46 -08001215 [self](
1216 const boost::system::error_code ec,
1217 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001218 if (ec || subtreeLocal.empty())
1219 {
1220 return;
1221 }
1222 if (subtreeLocal[0].second.size() != 1)
1223 {
1224 // invalid mapper response, should never happen
1225 BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error";
1226 messages::internalError(self->asyncResp->res);
1227 return;
1228 }
1229
1230 const std::string& path = subtreeLocal[0].first;
1231 const std::string& owner = subtreeLocal[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001232
1233 sdbusplus::asio::getAllProperties(
1234 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous002d39b2022-05-31 08:59:27 -07001235 [path, owner,
1236 self](const boost::system::error_code ec2,
1237 const dbus::utility::DBusPropertiesMap& resp) {
1238 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001239 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001240 BMCWEB_LOG_ERROR
1241 << "GetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001242 messages::internalError(self->asyncResp->res);
1243 return;
1244 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001245
Ed Tanous002d39b2022-05-31 08:59:27 -07001246 const std::string* current = nullptr;
1247 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001248
1249 const bool success = sdbusplus::unpackPropertiesNoThrow(
1250 dbus_utils::UnpackErrorPrinter(), resp, "Current", current,
1251 "Supported", supported);
1252
1253 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001254 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001255 messages::internalError(self->asyncResp->res);
1256 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001257 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001258
Ed Tanous002d39b2022-05-31 08:59:27 -07001259 if (current == nullptr || supported == nullptr)
1260 {
1261 BMCWEB_LOG_ERROR
1262 << "GetPIDValues: thermal mode iface invalid " << path;
1263 messages::internalError(self->asyncResp->res);
1264 return;
1265 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001266 self->complete.currentProfile = *current;
1267 self->complete.supportedProfiles = *supported;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001268 });
James Feist73df0db2019-03-25 15:29:35 -07001269 },
1270 "xyz.openbmc_project.ObjectMapper",
1271 "/xyz/openbmc_project/object_mapper",
1272 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1273 std::array<const char*, 1>{thermalModeIface});
1274 }
1275
Ed Tanous6936afe2022-09-08 15:10:39 -07001276 static void
1277 processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1278 const CompletionValues& completion)
James Feist73df0db2019-03-25 15:29:35 -07001279 {
1280 if (asyncResp->res.result() != boost::beast::http::status::ok)
1281 {
1282 return;
1283 }
1284 // create map of <connection, path to objMgr>>
Ed Tanous6936afe2022-09-08 15:10:39 -07001285 boost::container::flat_map<
1286 std::string, std::string, std::less<>,
1287 std::vector<std::pair<std::string, std::string>>>
1288 objectMgrPaths;
1289 boost::container::flat_set<std::string, std::less<>,
1290 std::vector<std::string>>
1291 calledConnections;
1292 for (const auto& pathGroup : completion.subtree)
James Feist73df0db2019-03-25 15:29:35 -07001293 {
1294 for (const auto& connectionGroup : pathGroup.second)
1295 {
1296 auto findConnection =
1297 calledConnections.find(connectionGroup.first);
1298 if (findConnection != calledConnections.end())
1299 {
1300 break;
1301 }
1302 for (const std::string& interface : connectionGroup.second)
1303 {
1304 if (interface == objectManagerIface)
1305 {
1306 objectMgrPaths[connectionGroup.first] = pathGroup.first;
1307 }
1308 // this list is alphabetical, so we
1309 // should have found the objMgr by now
1310 if (interface == pidConfigurationIface ||
1311 interface == pidZoneConfigurationIface ||
1312 interface == stepwiseConfigurationIface)
1313 {
1314 auto findObjMgr =
1315 objectMgrPaths.find(connectionGroup.first);
1316 if (findObjMgr == objectMgrPaths.end())
1317 {
1318 BMCWEB_LOG_DEBUG << connectionGroup.first
1319 << "Has no Object Manager";
1320 continue;
1321 }
1322
1323 calledConnections.insert(connectionGroup.first);
1324
1325 asyncPopulatePid(findObjMgr->first, findObjMgr->second,
Ed Tanous6936afe2022-09-08 15:10:39 -07001326 completion.currentProfile,
1327 completion.supportedProfiles,
James Feist73df0db2019-03-25 15:29:35 -07001328 asyncResp);
1329 break;
1330 }
1331 }
1332 }
1333 }
1334 }
1335
Ed Tanous6936afe2022-09-08 15:10:39 -07001336 ~GetPIDValues()
1337 {
1338 boost::asio::post(crow::connections::systemBus->get_io_context(),
1339 std::bind_front(&processingComplete, asyncResp,
1340 std::move(complete)));
1341 }
1342
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001343 GetPIDValues(const GetPIDValues&) = delete;
1344 GetPIDValues(GetPIDValues&&) = delete;
1345 GetPIDValues& operator=(const GetPIDValues&) = delete;
1346 GetPIDValues& operator=(GetPIDValues&&) = delete;
1347
zhanghch058d1b46d2021-04-01 11:18:24 +08001348 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
Ed Tanous6936afe2022-09-08 15:10:39 -07001349 CompletionValues complete;
James Feist73df0db2019-03-25 15:29:35 -07001350};
1351
1352struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
1353{
1354
zhanghch058d1b46d2021-04-01 11:18:24 +08001355 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn,
James Feist73df0db2019-03-25 15:29:35 -07001356 nlohmann::json& data) :
Ed Tanous271584a2019-07-09 16:24:22 -07001357 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001358 {
1359
1360 std::optional<nlohmann::json> pidControllers;
1361 std::optional<nlohmann::json> fanControllers;
1362 std::optional<nlohmann::json> fanZones;
1363 std::optional<nlohmann::json> stepwiseControllers;
1364
1365 if (!redfish::json_util::readJson(
1366 data, asyncResp->res, "PidControllers", pidControllers,
1367 "FanControllers", fanControllers, "FanZones", fanZones,
1368 "StepwiseControllers", stepwiseControllers, "Profile", profile))
1369 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001370 BMCWEB_LOG_ERROR
1371 << "Illegal Property "
1372 << data.dump(2, ' ', true,
1373 nlohmann::json::error_handler_t::replace);
James Feist73df0db2019-03-25 15:29:35 -07001374 return;
1375 }
1376 configuration.emplace_back("PidControllers", std::move(pidControllers));
1377 configuration.emplace_back("FanControllers", std::move(fanControllers));
1378 configuration.emplace_back("FanZones", std::move(fanZones));
1379 configuration.emplace_back("StepwiseControllers",
1380 std::move(stepwiseControllers));
1381 }
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001382
1383 SetPIDValues(const SetPIDValues&) = delete;
1384 SetPIDValues(SetPIDValues&&) = delete;
1385 SetPIDValues& operator=(const SetPIDValues&) = delete;
1386 SetPIDValues& operator=(SetPIDValues&&) = delete;
1387
James Feist73df0db2019-03-25 15:29:35 -07001388 void run()
1389 {
1390 if (asyncResp->res.result() != boost::beast::http::status::ok)
1391 {
1392 return;
1393 }
1394
1395 std::shared_ptr<SetPIDValues> self = shared_from_this();
1396
1397 // todo(james): might make sense to do a mapper call here if this
1398 // interface gets more traction
1399 crow::connections::systemBus->async_method_call(
1400 [self](const boost::system::error_code ec,
Ed Tanous914e2d52022-01-07 11:38:34 -08001401 const dbus::utility::ManagedObjectType& mObj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001402 if (ec)
1403 {
1404 BMCWEB_LOG_ERROR << "Error communicating to Entity Manager";
1405 messages::internalError(self->asyncResp->res);
1406 return;
1407 }
1408 const std::array<const char*, 3> configurations = {
1409 pidConfigurationIface, pidZoneConfigurationIface,
1410 stepwiseConfigurationIface};
James Feiste69d9de2020-02-07 12:23:27 -08001411
Ed Tanous002d39b2022-05-31 08:59:27 -07001412 for (const auto& [path, object] : mObj)
1413 {
1414 for (const auto& [interface, _] : object)
James Feiste69d9de2020-02-07 12:23:27 -08001415 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001416 if (std::find(configurations.begin(), configurations.end(),
1417 interface) != configurations.end())
James Feiste69d9de2020-02-07 12:23:27 -08001418 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001419 self->objectCount++;
1420 break;
James Feiste69d9de2020-02-07 12:23:27 -08001421 }
James Feiste69d9de2020-02-07 12:23:27 -08001422 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001423 }
1424 self->managedObj = mObj;
James Feist73df0db2019-03-25 15:29:35 -07001425 },
Nan Zhouc106b672022-09-20 22:35:31 +00001426 "xyz.openbmc_project.EntityManager",
1427 "/xyz/openbmc_project/inventory", objectManagerIface,
James Feist73df0db2019-03-25 15:29:35 -07001428 "GetManagedObjects");
1429
1430 // at the same time get the profile information
1431 crow::connections::systemBus->async_method_call(
1432 [self](const boost::system::error_code ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001433 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001434 if (ec || subtree.empty())
1435 {
1436 return;
1437 }
1438 if (subtree[0].second.empty())
1439 {
1440 // invalid mapper response, should never happen
1441 BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error";
1442 messages::internalError(self->asyncResp->res);
1443 return;
1444 }
1445
1446 const std::string& path = subtree[0].first;
1447 const std::string& owner = subtree[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001448 sdbusplus::asio::getAllProperties(
1449 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous002d39b2022-05-31 08:59:27 -07001450 [self, path, owner](const boost::system::error_code ec2,
1451 const dbus::utility::DBusPropertiesMap& r) {
1452 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001453 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001454 BMCWEB_LOG_ERROR
1455 << "SetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001456 messages::internalError(self->asyncResp->res);
1457 return;
1458 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001459 const std::string* current = nullptr;
1460 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001461
1462 const bool success = sdbusplus::unpackPropertiesNoThrow(
1463 dbus_utils::UnpackErrorPrinter(), r, "Current", current,
1464 "Supported", supported);
1465
1466 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001467 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001468 messages::internalError(self->asyncResp->res);
1469 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001470 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001471
Ed Tanous002d39b2022-05-31 08:59:27 -07001472 if (current == nullptr || supported == nullptr)
1473 {
1474 BMCWEB_LOG_ERROR
1475 << "SetPIDValues: thermal mode iface invalid " << path;
1476 messages::internalError(self->asyncResp->res);
1477 return;
1478 }
1479 self->currentProfile = *current;
1480 self->supportedProfiles = *supported;
1481 self->profileConnection = owner;
1482 self->profilePath = path;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001483 });
James Feist73df0db2019-03-25 15:29:35 -07001484 },
1485 "xyz.openbmc_project.ObjectMapper",
1486 "/xyz/openbmc_project/object_mapper",
1487 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1488 std::array<const char*, 1>{thermalModeIface});
1489 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001490 void pidSetDone()
James Feist73df0db2019-03-25 15:29:35 -07001491 {
1492 if (asyncResp->res.result() != boost::beast::http::status::ok)
1493 {
1494 return;
1495 }
zhanghch058d1b46d2021-04-01 11:18:24 +08001496 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001497 if (profile)
1498 {
1499 if (std::find(supportedProfiles.begin(), supportedProfiles.end(),
1500 *profile) == supportedProfiles.end())
1501 {
1502 messages::actionParameterUnknown(response->res, "Profile",
1503 *profile);
1504 return;
1505 }
1506 currentProfile = *profile;
1507 crow::connections::systemBus->async_method_call(
1508 [response](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001509 if (ec)
1510 {
1511 BMCWEB_LOG_ERROR << "Error patching profile" << ec;
1512 messages::internalError(response->res);
1513 }
James Feist73df0db2019-03-25 15:29:35 -07001514 },
1515 profileConnection, profilePath,
1516 "org.freedesktop.DBus.Properties", "Set", thermalModeIface,
Ed Tanous168e20c2021-12-13 14:39:53 -08001517 "Current", dbus::utility::DbusVariantType(*profile));
James Feist73df0db2019-03-25 15:29:35 -07001518 }
1519
1520 for (auto& containerPair : configuration)
1521 {
1522 auto& container = containerPair.second;
1523 if (!container)
1524 {
1525 continue;
1526 }
James Feist6ee7f772020-02-06 16:25:27 -08001527 BMCWEB_LOG_DEBUG << *container;
1528
Ed Tanous02cad962022-06-30 16:50:15 -07001529 const std::string& type = containerPair.first;
James Feist73df0db2019-03-25 15:29:35 -07001530
1531 for (nlohmann::json::iterator it = container->begin();
Manojkiran Eda17a897d2020-09-12 15:31:58 +05301532 it != container->end(); ++it)
James Feist73df0db2019-03-25 15:29:35 -07001533 {
1534 const auto& name = it.key();
James Feist6ee7f772020-02-06 16:25:27 -08001535 BMCWEB_LOG_DEBUG << "looking for " << name;
1536
James Feist73df0db2019-03-25 15:29:35 -07001537 auto pathItr =
1538 std::find_if(managedObj.begin(), managedObj.end(),
1539 [&name](const auto& obj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001540 return boost::algorithm::ends_with(obj.first.str,
1541 "/" + name);
1542 });
Ed Tanousb9d36b42022-02-26 21:42:46 -08001543 dbus::utility::DBusPropertiesMap output;
James Feist73df0db2019-03-25 15:29:35 -07001544
1545 output.reserve(16); // The pid interface length
1546
1547 // determines if we're patching entity-manager or
1548 // creating a new object
1549 bool createNewObject = (pathItr == managedObj.end());
James Feist6ee7f772020-02-06 16:25:27 -08001550 BMCWEB_LOG_DEBUG << "Found = " << !createNewObject;
1551
James Feist73df0db2019-03-25 15:29:35 -07001552 std::string iface;
Ed Tanousea2b6702022-03-07 16:48:38 -08001553 if (!createNewObject)
James Feist73df0db2019-03-25 15:29:35 -07001554 {
Potin Lai8be2b5b2022-11-22 13:27:16 +08001555 bool findInterface = false;
Ed Tanousea2b6702022-03-07 16:48:38 -08001556 for (const auto& interface : pathItr->second)
James Feist73df0db2019-03-25 15:29:35 -07001557 {
Ed Tanousea2b6702022-03-07 16:48:38 -08001558 if (interface.first == pidConfigurationIface)
1559 {
1560 if (type == "PidControllers" ||
1561 type == "FanControllers")
1562 {
1563 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001564 findInterface = true;
1565 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001566 }
1567 }
1568 else if (interface.first == pidZoneConfigurationIface)
1569 {
1570 if (type == "FanZones")
1571 {
1572 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001573 findInterface = true;
1574 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001575 }
1576 }
1577 else if (interface.first == stepwiseConfigurationIface)
1578 {
1579 if (type == "StepwiseControllers")
1580 {
1581 iface = stepwiseConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001582 findInterface = true;
1583 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001584 }
1585 }
James Feist73df0db2019-03-25 15:29:35 -07001586 }
Potin Lai8be2b5b2022-11-22 13:27:16 +08001587
1588 // create new object if interface not found
1589 if (!findInterface)
1590 {
1591 createNewObject = true;
1592 }
James Feist73df0db2019-03-25 15:29:35 -07001593 }
James Feist6ee7f772020-02-06 16:25:27 -08001594
1595 if (createNewObject && it.value() == nullptr)
1596 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -05001597 // can't delete a non-existent object
Ed Tanous1668ce62022-02-07 23:44:31 -08001598 messages::propertyValueNotInList(response->res,
1599 it.value().dump(), name);
James Feist6ee7f772020-02-06 16:25:27 -08001600 continue;
1601 }
1602
1603 std::string path;
1604 if (pathItr != managedObj.end())
1605 {
1606 path = pathItr->first.str;
1607 }
1608
James Feist73df0db2019-03-25 15:29:35 -07001609 BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n";
James Feiste69d9de2020-02-07 12:23:27 -08001610
1611 // arbitrary limit to avoid attacks
1612 constexpr const size_t controllerLimit = 500;
James Feist14b0b8d2020-02-12 11:52:07 -08001613 if (createNewObject && objectCount >= controllerLimit)
James Feiste69d9de2020-02-07 12:23:27 -08001614 {
1615 messages::resourceExhaustion(response->res, type);
1616 continue;
1617 }
Ed Tanousa170f272022-06-30 21:53:27 -07001618 std::string escaped = name;
1619 std::replace(escaped.begin(), escaped.end(), '_', ' ');
1620 output.emplace_back("Name", escaped);
James Feist73df0db2019-03-25 15:29:35 -07001621
1622 std::string chassis;
1623 CreatePIDRet ret = createPidInterface(
James Feist6ee7f772020-02-06 16:25:27 -08001624 response, type, it, path, managedObj, createNewObject,
1625 output, chassis, currentProfile);
James Feist73df0db2019-03-25 15:29:35 -07001626 if (ret == CreatePIDRet::fail)
1627 {
1628 return;
1629 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001630 if (ret == CreatePIDRet::del)
James Feist73df0db2019-03-25 15:29:35 -07001631 {
1632 continue;
1633 }
1634
1635 if (!createNewObject)
1636 {
1637 for (const auto& property : output)
1638 {
1639 crow::connections::systemBus->async_method_call(
1640 [response,
1641 propertyName{std::string(property.first)}](
1642 const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001643 if (ec)
1644 {
1645 BMCWEB_LOG_ERROR << "Error patching "
1646 << propertyName << ": " << ec;
1647 messages::internalError(response->res);
1648 return;
1649 }
1650 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001651 },
James Feist6ee7f772020-02-06 16:25:27 -08001652 "xyz.openbmc_project.EntityManager", path,
James Feist73df0db2019-03-25 15:29:35 -07001653 "org.freedesktop.DBus.Properties", "Set", iface,
1654 property.first, property.second);
1655 }
1656 }
1657 else
1658 {
1659 if (chassis.empty())
1660 {
1661 BMCWEB_LOG_ERROR << "Failed to get chassis from config";
Ed Tanousace85d62021-10-26 12:45:59 -07001662 messages::internalError(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001663 return;
1664 }
1665
1666 bool foundChassis = false;
1667 for (const auto& obj : managedObj)
1668 {
1669 if (boost::algorithm::ends_with(obj.first.str, chassis))
1670 {
1671 chassis = obj.first.str;
1672 foundChassis = true;
1673 break;
1674 }
1675 }
1676 if (!foundChassis)
1677 {
1678 BMCWEB_LOG_ERROR << "Failed to find chassis on dbus";
1679 messages::resourceMissingAtURI(
Ed Tanousace85d62021-10-26 12:45:59 -07001680 response->res,
1681 crow::utility::urlFromPieces("redfish", "v1",
1682 "Chassis", chassis));
James Feist73df0db2019-03-25 15:29:35 -07001683 return;
1684 }
1685
1686 crow::connections::systemBus->async_method_call(
1687 [response](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001688 if (ec)
1689 {
1690 BMCWEB_LOG_ERROR << "Error Adding Pid Object "
1691 << ec;
1692 messages::internalError(response->res);
1693 return;
1694 }
1695 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001696 },
1697 "xyz.openbmc_project.EntityManager", chassis,
1698 "xyz.openbmc_project.AddObject", "AddObject", output);
1699 }
1700 }
1701 }
1702 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001703
1704 ~SetPIDValues()
1705 {
1706 try
1707 {
1708 pidSetDone();
1709 }
1710 catch (...)
1711 {
1712 BMCWEB_LOG_CRITICAL << "pidSetDone threw exception";
1713 }
1714 }
1715
zhanghch058d1b46d2021-04-01 11:18:24 +08001716 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001717 std::vector<std::pair<std::string, std::optional<nlohmann::json>>>
1718 configuration;
1719 std::optional<std::string> profile;
1720 dbus::utility::ManagedObjectType managedObj;
1721 std::vector<std::string> supportedProfiles;
1722 std::string currentProfile;
1723 std::string profileConnection;
1724 std::string profilePath;
James Feist14b0b8d2020-02-12 11:52:07 -08001725 size_t objectCount = 0;
James Feist73df0db2019-03-25 15:29:35 -07001726};
James Feist83ff9ab2018-08-31 10:18:24 -07001727
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001728/**
1729 * @brief Retrieves BMC manager location data over DBus
1730 *
1731 * @param[in] aResp Shared pointer for completing asynchronous calls
1732 * @param[in] connectionName - service name
1733 * @param[in] path - object path
1734 * @return none
1735 */
zhanghch058d1b46d2021-04-01 11:18:24 +08001736inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001737 const std::string& connectionName,
1738 const std::string& path)
1739{
1740 BMCWEB_LOG_DEBUG << "Get BMC manager Location data.";
1741
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001742 sdbusplus::asio::getProperty<std::string>(
1743 *crow::connections::systemBus, connectionName, path,
1744 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001745 [aResp](const boost::system::error_code ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001746 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001747 if (ec)
1748 {
1749 BMCWEB_LOG_DEBUG << "DBUS response error for "
1750 "Location";
1751 messages::internalError(aResp->res);
1752 return;
1753 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001754
Ed Tanous002d39b2022-05-31 08:59:27 -07001755 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
1756 property;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001757 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001758}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001759// avoid name collision systems.hpp
1760inline void
1761 managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001762{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001763 BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time";
Ed Tanous52cc1122020-07-18 13:51:21 -07001764
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001765 sdbusplus::asio::getProperty<uint64_t>(
1766 *crow::connections::systemBus, "xyz.openbmc_project.State.BMC",
1767 "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC",
1768 "LastRebootTime",
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001769 [aResp](const boost::system::error_code ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001770 const uint64_t lastResetTime) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001771 if (ec)
1772 {
1773 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1774 return;
1775 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001776
Ed Tanous002d39b2022-05-31 08:59:27 -07001777 // LastRebootTime is epoch time, in milliseconds
1778 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
1779 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001780
Ed Tanous002d39b2022-05-31 08:59:27 -07001781 // Convert to ISO 8601 standard
1782 aResp->res.jsonValue["LastResetTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001783 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001784 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001785}
1786
1787/**
1788 * @brief Set the running firmware image
1789 *
1790 * @param[i,o] aResp - Async response object
1791 * @param[i] runningFirmwareTarget - Image to make the running image
1792 *
1793 * @return void
1794 */
1795inline void
1796 setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1797 const std::string& runningFirmwareTarget)
1798{
1799 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
1800 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
1801 if (idPos == std::string::npos)
1802 {
1803 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1804 "@odata.id");
1805 BMCWEB_LOG_DEBUG << "Can't parse firmware ID!";
1806 return;
1807 }
1808 idPos++;
1809 if (idPos >= runningFirmwareTarget.size())
1810 {
1811 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1812 "@odata.id");
1813 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1814 return;
1815 }
1816 std::string firmwareId = runningFirmwareTarget.substr(idPos);
1817
1818 // Make sure the image is valid before setting priority
1819 crow::connections::systemBus->async_method_call(
Ed Tanous711ac7a2021-12-20 09:34:41 -08001820 [aResp, firmwareId,
1821 runningFirmwareTarget](const boost::system::error_code ec,
1822 dbus::utility::ManagedObjectType& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001823 if (ec)
1824 {
1825 BMCWEB_LOG_DEBUG << "D-Bus response error getting objects.";
1826 messages::internalError(aResp->res);
1827 return;
1828 }
1829
1830 if (subtree.empty())
1831 {
1832 BMCWEB_LOG_DEBUG << "Can't find image!";
1833 messages::internalError(aResp->res);
1834 return;
1835 }
1836
1837 bool foundImage = false;
Ed Tanous02cad962022-06-30 16:50:15 -07001838 for (const auto& object : subtree)
Ed Tanous002d39b2022-05-31 08:59:27 -07001839 {
1840 const std::string& path =
1841 static_cast<const std::string&>(object.first);
1842 std::size_t idPos2 = path.rfind('/');
1843
1844 if (idPos2 == std::string::npos)
1845 {
1846 continue;
1847 }
1848
1849 idPos2++;
1850 if (idPos2 >= path.size())
1851 {
1852 continue;
1853 }
1854
1855 if (path.substr(idPos2) == firmwareId)
1856 {
1857 foundImage = true;
1858 break;
1859 }
1860 }
1861
1862 if (!foundImage)
1863 {
1864 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1865 "@odata.id");
1866 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1867 return;
1868 }
1869
1870 BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId
1871 << " to priority 0.";
1872
1873 // Only support Immediate
1874 // An addition could be a Redfish Setting like
1875 // ActiveSoftwareImageApplyTime and support OnReset
1876 crow::connections::systemBus->async_method_call(
Ed Tanous8a592812022-06-04 09:06:59 -07001877 [aResp](const boost::system::error_code ec2) {
1878 if (ec2)
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001879 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001880 BMCWEB_LOG_DEBUG << "D-Bus response error setting.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001881 messages::internalError(aResp->res);
1882 return;
1883 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001884 doBMCGracefulRestart(aResp);
1885 },
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001886
Ed Tanous002d39b2022-05-31 08:59:27 -07001887 "xyz.openbmc_project.Software.BMC.Updater",
1888 "/xyz/openbmc_project/software/" + firmwareId,
1889 "org.freedesktop.DBus.Properties", "Set",
1890 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
1891 dbus::utility::DbusVariantType(static_cast<uint8_t>(0)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001892 },
1893 "xyz.openbmc_project.Software.BMC.Updater",
1894 "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager",
1895 "GetManagedObjects");
1896}
Ed Tanous1abe55e2018-09-05 08:30:59 -07001897
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001898inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp,
1899 std::string datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001900{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001901 BMCWEB_LOG_DEBUG << "Set date time: " << datetime;
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001902
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001903 std::stringstream stream(datetime);
1904 // Convert from ISO 8601 to boost local_time
1905 // (BMC only has time in UTC)
1906 boost::posix_time::ptime posixTime;
1907 boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
1908 // Facet gets deleted with the stringsteam
1909 auto ifc = std::make_unique<boost::local_time::local_time_input_facet>(
1910 "%Y-%m-%d %H:%M:%S%F %ZP");
1911 stream.imbue(std::locale(stream.getloc(), ifc.release()));
1912
1913 boost::local_time::local_date_time ldt(boost::local_time::not_a_date_time);
1914
1915 if (stream >> ldt)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001916 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001917 posixTime = ldt.utc_time();
1918 boost::posix_time::time_duration dur = posixTime - epoch;
1919 uint64_t durMicroSecs = static_cast<uint64_t>(dur.total_microseconds());
1920 crow::connections::systemBus->async_method_call(
1921 [aResp{std::move(aResp)}, datetime{std::move(datetime)}](
1922 const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001923 if (ec)
1924 {
1925 BMCWEB_LOG_DEBUG << "Failed to set elapsed time. "
1926 "DBUS response error "
1927 << ec;
1928 messages::internalError(aResp->res);
1929 return;
1930 }
1931 aResp->res.jsonValue["DateTime"] = datetime;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001932 },
1933 "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc",
1934 "org.freedesktop.DBus.Properties", "Set",
1935 "xyz.openbmc_project.Time.EpochTime", "Elapsed",
Ed Tanous168e20c2021-12-13 14:39:53 -08001936 dbus::utility::DbusVariantType(durMicroSecs));
Ed Tanous1abe55e2018-09-05 08:30:59 -07001937 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001938 else
1939 {
1940 messages::propertyValueFormatError(aResp->res, datetime, "DateTime");
1941 return;
1942 }
1943}
1944
1945inline void requestRoutesManager(App& app)
1946{
1947 std::string uuid = persistent_data::getConfig().systemUuid;
1948
1949 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07001950 .privileges(redfish::privileges::getManager)
Ed Tanous002d39b2022-05-31 08:59:27 -07001951 .methods(boost::beast::http::verb::get)(
1952 [&app, uuid](const crow::Request& req,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001953 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001954 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001955 {
1956 return;
1957 }
1958 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc";
Sui Chena51fc2d2022-07-14 17:21:53 -07001959 asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager";
Ed Tanous002d39b2022-05-31 08:59:27 -07001960 asyncResp->res.jsonValue["Id"] = "bmc";
1961 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
1962 asyncResp->res.jsonValue["Description"] =
1963 "Baseboard Management Controller";
1964 asyncResp->res.jsonValue["PowerState"] = "On";
1965 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
1966 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
Ed Tanous14766872022-03-15 10:44:42 -07001967
Ed Tanous002d39b2022-05-31 08:59:27 -07001968 asyncResp->res.jsonValue["ManagerType"] = "BMC";
1969 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
1970 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
1971 asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001972
Ed Tanous002d39b2022-05-31 08:59:27 -07001973 asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
1974 "/redfish/v1/Managers/bmc/LogServices";
1975 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
1976 "/redfish/v1/Managers/bmc/NetworkProtocol";
1977 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
1978 "/redfish/v1/Managers/bmc/EthernetInterfaces";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001979
1980#ifdef BMCWEB_ENABLE_VM_NBDPROXY
Ed Tanous002d39b2022-05-31 08:59:27 -07001981 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
1982 "/redfish/v1/Managers/bmc/VirtualMedia";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001983#endif // BMCWEB_ENABLE_VM_NBDPROXY
1984
Ed Tanous002d39b2022-05-31 08:59:27 -07001985 // default oem data
1986 nlohmann::json& oem = asyncResp->res.jsonValue["Oem"];
1987 nlohmann::json& oemOpenbmc = oem["OpenBmc"];
1988 oem["@odata.type"] = "#OemManager.Oem";
1989 oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem";
1990 oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc";
1991 oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc";
Ed Tanous14766872022-03-15 10:44:42 -07001992
Ed Tanous002d39b2022-05-31 08:59:27 -07001993 nlohmann::json::object_t certificates;
1994 certificates["@odata.id"] =
1995 "/redfish/v1/Managers/bmc/Truststore/Certificates";
1996 oemOpenbmc["Certificates"] = std::move(certificates);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001997
Ed Tanous002d39b2022-05-31 08:59:27 -07001998 // Manager.Reset (an action) can be many values, OpenBMC only
1999 // supports BMC reboot.
2000 nlohmann::json& managerReset =
2001 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
2002 managerReset["target"] =
2003 "/redfish/v1/Managers/bmc/Actions/Manager.Reset";
2004 managerReset["@Redfish.ActionInfo"] =
2005 "/redfish/v1/Managers/bmc/ResetActionInfo";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002006
Ed Tanous002d39b2022-05-31 08:59:27 -07002007 // ResetToDefaults (Factory Reset) has values like
2008 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
2009 // on OpenBMC
2010 nlohmann::json& resetToDefaults =
2011 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
2012 resetToDefaults["target"] =
2013 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults";
Ed Tanous613dabe2022-07-09 11:17:36 -07002014 resetToDefaults["ResetType@Redfish.AllowableValues"] =
2015 nlohmann::json::array_t({"ResetAll"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002016
Ed Tanous002d39b2022-05-31 08:59:27 -07002017 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002018 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05302019
Ed Tanous002d39b2022-05-31 08:59:27 -07002020 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2021 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2022 redfishDateTimeOffset.second;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002023
Ed Tanous002d39b2022-05-31 08:59:27 -07002024 // TODO (Gunnar): Remove these one day since moved to ComputerSystem
2025 // Still used by OCP profiles
2026 // https://github.com/opencomputeproject/OCP-Profiles/issues/23
2027 // Fill in SerialConsole info
2028 asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true;
2029 asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
Ed Tanous613dabe2022-07-09 11:17:36 -07002030 asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] =
2031 nlohmann::json::array_t({"IPMI", "SSH"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002032#ifdef BMCWEB_ENABLE_KVM
Ed Tanous002d39b2022-05-31 08:59:27 -07002033 // Fill in GraphicalConsole info
2034 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
2035 asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
2036 4;
Ed Tanous613dabe2022-07-09 11:17:36 -07002037 asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
2038 nlohmann::json::array_t({"KVMIP"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002039#endif // BMCWEB_ENABLE_KVM
2040
Ed Tanous002d39b2022-05-31 08:59:27 -07002041 asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
Ed Tanous14766872022-03-15 10:44:42 -07002042
Ed Tanous002d39b2022-05-31 08:59:27 -07002043 nlohmann::json::array_t managerForServers;
2044 nlohmann::json::object_t manager;
2045 manager["@odata.id"] = "/redfish/v1/Systems/system";
2046 managerForServers.push_back(std::move(manager));
2047
2048 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
2049 std::move(managerForServers);
2050
2051 auto health = std::make_shared<HealthPopulate>(asyncResp);
2052 health->isManagersHealth = true;
2053 health->populate();
2054
Willy Tueee00132022-06-14 14:53:17 -07002055 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
Ed Tanous002d39b2022-05-31 08:59:27 -07002056 "FirmwareVersion", true);
2057
2058 managerGetLastResetTime(asyncResp);
2059
Sui Chena51fc2d2022-07-14 17:21:53 -07002060 // ManagerDiagnosticData is added for all BMCs.
2061 nlohmann::json& managerDiagnosticData =
2062 asyncResp->res.jsonValue["ManagerDiagnosticData"];
2063 managerDiagnosticData["@odata.id"] =
2064 "/redfish/v1/Managers/bmc/ManagerDiagnosticData";
2065
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002066#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002067 auto pids = std::make_shared<GetPIDValues>(asyncResp);
2068 pids->run();
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002069#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002070
2071 getMainChassisId(asyncResp,
2072 [](const std::string& chassisId,
2073 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
2074 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
2075 nlohmann::json::array_t managerForChassis;
Ed Tanous8a592812022-06-04 09:06:59 -07002076 nlohmann::json::object_t managerObj;
2077 managerObj["@odata.id"] = "/redfish/v1/Chassis/" + chassisId;
2078 managerForChassis.push_back(std::move(managerObj));
Ed Tanous002d39b2022-05-31 08:59:27 -07002079 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
2080 std::move(managerForChassis);
2081 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
2082 "/redfish/v1/Chassis/" + chassisId;
2083 });
Ed Tanous14766872022-03-15 10:44:42 -07002084
Ed Tanous002d39b2022-05-31 08:59:27 -07002085 static bool started = false;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002086
Ed Tanous002d39b2022-05-31 08:59:27 -07002087 if (!started)
2088 {
2089 sdbusplus::asio::getProperty<double>(
2090 *crow::connections::systemBus, "org.freedesktop.systemd1",
2091 "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
2092 "Progress",
2093 [asyncResp](const boost::system::error_code ec,
2094 const double& val) {
2095 if (ec)
2096 {
2097 BMCWEB_LOG_ERROR << "Error while getting progress";
2098 messages::internalError(asyncResp->res);
2099 return;
2100 }
2101 if (val < 1.0)
2102 {
2103 asyncResp->res.jsonValue["Status"]["State"] = "Starting";
2104 started = true;
2105 }
2106 });
2107 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002108
Ed Tanous002d39b2022-05-31 08:59:27 -07002109 crow::connections::systemBus->async_method_call(
2110 [asyncResp](
2111 const boost::system::error_code ec,
2112 const dbus::utility::MapperGetSubTreeResponse& subtree) {
2113 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002114 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002115 BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec;
2116 return;
2117 }
2118 if (subtree.empty())
2119 {
2120 BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!";
2121 return;
2122 }
2123 // Assume only 1 bmc D-Bus object
2124 // Throw an error if there is more than 1
2125 if (subtree.size() > 1)
2126 {
2127 BMCWEB_LOG_DEBUG << "Found more than 1 bmc D-Bus object!";
2128 messages::internalError(asyncResp->res);
2129 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002130 }
2131
Ed Tanous002d39b2022-05-31 08:59:27 -07002132 if (subtree[0].first.empty() || subtree[0].second.size() != 1)
2133 {
2134 BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!";
2135 messages::internalError(asyncResp->res);
2136 return;
2137 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002138
Ed Tanous002d39b2022-05-31 08:59:27 -07002139 const std::string& path = subtree[0].first;
2140 const std::string& connectionName = subtree[0].second[0].first;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002141
Ed Tanous002d39b2022-05-31 08:59:27 -07002142 for (const auto& interfaceName : subtree[0].second[0].second)
2143 {
2144 if (interfaceName ==
2145 "xyz.openbmc_project.Inventory.Decorator.Asset")
2146 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002147
2148 sdbusplus::asio::getAllProperties(
2149 *crow::connections::systemBus, connectionName, path,
2150 "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanous8a592812022-06-04 09:06:59 -07002151 [asyncResp](const boost::system::error_code ec2,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002152 const dbus::utility::DBusPropertiesMap&
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002153 propertiesList) {
Ed Tanous8a592812022-06-04 09:06:59 -07002154 if (ec2)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002155 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002156 BMCWEB_LOG_DEBUG << "Can't get bmc asset!";
2157 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002158 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002159
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002160 const std::string* partNumber = nullptr;
2161 const std::string* serialNumber = nullptr;
2162 const std::string* manufacturer = nullptr;
2163 const std::string* model = nullptr;
2164 const std::string* sparePartNumber = nullptr;
2165
2166 const bool success = sdbusplus::unpackPropertiesNoThrow(
2167 dbus_utils::UnpackErrorPrinter(), propertiesList,
2168 "PartNumber", partNumber, "SerialNumber",
2169 serialNumber, "Manufacturer", manufacturer, "Model",
2170 model, "SparePartNumber", sparePartNumber);
2171
2172 if (!success)
2173 {
2174 messages::internalError(asyncResp->res);
2175 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002176 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002177
2178 if (partNumber != nullptr)
2179 {
2180 asyncResp->res.jsonValue["PartNumber"] =
2181 *partNumber;
2182 }
2183
2184 if (serialNumber != nullptr)
2185 {
2186 asyncResp->res.jsonValue["SerialNumber"] =
2187 *serialNumber;
2188 }
2189
2190 if (manufacturer != nullptr)
2191 {
2192 asyncResp->res.jsonValue["Manufacturer"] =
2193 *manufacturer;
2194 }
2195
2196 if (model != nullptr)
2197 {
2198 asyncResp->res.jsonValue["Model"] = *model;
2199 }
2200
2201 if (sparePartNumber != nullptr)
2202 {
2203 asyncResp->res.jsonValue["SparePartNumber"] =
2204 *sparePartNumber;
2205 }
2206 });
Ed Tanous002d39b2022-05-31 08:59:27 -07002207 }
2208 else if (interfaceName ==
2209 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
2210 {
2211 getLocation(asyncResp, connectionName, path);
2212 }
2213 }
2214 },
2215 "xyz.openbmc_project.ObjectMapper",
2216 "/xyz/openbmc_project/object_mapper",
2217 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
2218 "/xyz/openbmc_project/inventory", int32_t(0),
2219 std::array<const char*, 1>{
2220 "xyz.openbmc_project.Inventory.Item.Bmc"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002221 });
2222
2223 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07002224 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002225 .methods(boost::beast::http::verb::patch)(
2226 [&app](const crow::Request& req,
2227 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002228 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002229 {
2230 return;
2231 }
2232 std::optional<nlohmann::json> oem;
2233 std::optional<nlohmann::json> links;
2234 std::optional<std::string> datetime;
2235
2236 if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem,
2237 "DateTime", datetime, "Links", links))
2238 {
2239 return;
2240 }
2241
2242 if (oem)
2243 {
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002244#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002245 std::optional<nlohmann::json> openbmc;
2246 if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc",
2247 openbmc))
2248 {
2249 BMCWEB_LOG_ERROR
2250 << "Illegal Property "
2251 << oem->dump(2, ' ', true,
2252 nlohmann::json::error_handler_t::replace);
2253 return;
2254 }
2255 if (openbmc)
2256 {
2257 std::optional<nlohmann::json> fan;
2258 if (!redfish::json_util::readJson(*openbmc, asyncResp->res,
2259 "Fan", fan))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002260 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002261 BMCWEB_LOG_ERROR
2262 << "Illegal Property "
2263 << openbmc->dump(
2264 2, ' ', true,
2265 nlohmann::json::error_handler_t::replace);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002266 return;
2267 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002268 if (fan)
2269 {
2270 auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan);
2271 pid->run();
2272 }
2273 }
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002274#else
2275 messages::propertyUnknown(asyncResp->res, "Oem");
2276 return;
2277#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002278 }
2279 if (links)
2280 {
2281 std::optional<nlohmann::json> activeSoftwareImage;
2282 if (!redfish::json_util::readJson(*links, asyncResp->res,
2283 "ActiveSoftwareImage",
2284 activeSoftwareImage))
2285 {
2286 return;
2287 }
2288 if (activeSoftwareImage)
2289 {
2290 std::optional<std::string> odataId;
2291 if (!json_util::readJson(*activeSoftwareImage, asyncResp->res,
2292 "@odata.id", odataId))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002293 {
Ed Tanous45ca1b82022-03-25 13:07:27 -07002294 return;
2295 }
2296
Ed Tanous002d39b2022-05-31 08:59:27 -07002297 if (odataId)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002298 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002299 setActiveFirmwareImage(asyncResp, *odataId);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002300 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002301 }
2302 }
2303 if (datetime)
2304 {
2305 setDateTime(asyncResp, std::move(*datetime));
2306 }
2307 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002308}
2309
2310inline void requestRoutesManagerCollection(App& app)
2311{
2312 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -07002313 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002314 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002315 [&app](const crow::Request& req,
2316 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002317 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002318 {
2319 return;
2320 }
2321 // Collections don't include the static data added by SubRoute
2322 // because it has a duplicate entry for members
2323 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
2324 asyncResp->res.jsonValue["@odata.type"] =
2325 "#ManagerCollection.ManagerCollection";
2326 asyncResp->res.jsonValue["Name"] = "Manager Collection";
2327 asyncResp->res.jsonValue["Members@odata.count"] = 1;
2328 nlohmann::json::array_t members;
2329 nlohmann::json& bmc = members.emplace_back();
2330 bmc["@odata.id"] = "/redfish/v1/Managers/bmc";
2331 asyncResp->res.jsonValue["Members"] = std::move(members);
2332 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002333}
Ed Tanous1abe55e2018-09-05 08:30:59 -07002334} // namespace redfish