blob: 1319eca53ef9139ed071de7cbf09a86f85786808 [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"
Ed Tanous3ccb3ad2023-01-13 17:40:03 -080025#include "utils/json_utils.hpp"
Sui Chena51fc2d2022-07-14 17:21:53 -070026#include "utils/sw_utils.hpp"
27#include "utils/systemd_utils.hpp"
Ed Tanous2b829372022-08-03 14:22:34 -070028#include "utils/time_utils.hpp"
Borawski.Lukasz9c3106852018-02-09 15:24:22 +010029
George Liue99073f2022-12-09 11:06:16 +080030#include <boost/system/error_code.hpp>
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +020031#include <sdbusplus/asio/property.hpp>
32#include <sdbusplus/unpack_properties.hpp>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050033
Ed Tanousa170f272022-06-30 21:53:27 -070034#include <algorithm>
George Liue99073f2022-12-09 11:06:16 +080035#include <array>
Gunnar Mills4bfefa72020-07-30 13:54:29 -050036#include <cstdint>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050037#include <memory>
38#include <sstream>
George Liue99073f2022-12-09 11:06:16 +080039#include <string_view>
Ed Tanousabf2add2019-01-22 16:40:12 -080040#include <variant>
James Feist5b4aa862018-08-16 14:07:01 -070041
Ed Tanous1abe55e2018-09-05 08:30:59 -070042namespace redfish
43{
Jennifer Leeed5befb2018-08-10 11:29:45 -070044
45/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -050046 * Function reboots the BMC.
47 *
48 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -070049 */
zhanghch058d1b46d2021-04-01 11:18:24 +080050inline void
51 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -050052{
53 const char* processName = "xyz.openbmc_project.State.BMC";
54 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
55 const char* interfaceName = "xyz.openbmc_project.State.BMC";
56 const std::string& propertyValue =
57 "xyz.openbmc_project.State.BMC.Transition.Reboot";
58 const char* destProperty = "RequestedBMCTransition";
59
60 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080061 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050062
63 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080064 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070065 // Use "Set" method to set the property value.
66 if (ec)
67 {
68 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
69 messages::internalError(asyncResp->res);
70 return;
71 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -050072
Ed Tanous002d39b2022-05-31 08:59:27 -070073 messages::success(asyncResp->res);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050074 },
75 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
76 interfaceName, destProperty, dbusPropertyValue);
77}
78
zhanghch058d1b46d2021-04-01 11:18:24 +080079inline void
80 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000081{
82 const char* processName = "xyz.openbmc_project.State.BMC";
83 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
84 const char* interfaceName = "xyz.openbmc_project.State.BMC";
85 const std::string& propertyValue =
86 "xyz.openbmc_project.State.BMC.Transition.HardReboot";
87 const char* destProperty = "RequestedBMCTransition";
88
89 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080090 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000091
92 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -080093 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070094 // Use "Set" method to set the property value.
95 if (ec)
96 {
97 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
98 messages::internalError(asyncResp->res);
99 return;
100 }
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000101
Ed Tanous002d39b2022-05-31 08:59:27 -0700102 messages::success(asyncResp->res);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000103 },
104 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
105 interfaceName, destProperty, dbusPropertyValue);
106}
107
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500108/**
109 * ManagerResetAction class supports the POST method for the Reset (reboot)
110 * action.
111 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700112inline void requestRoutesManagerResetAction(App& app)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700113{
Jennifer Leeed5befb2018-08-10 11:29:45 -0700114 /**
Jennifer Leeed5befb2018-08-10 11:29:45 -0700115 * Function handles POST method request.
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500116 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000117 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Jennifer Leeed5befb2018-08-10 11:29:45 -0700118 */
Jennifer Leeed5befb2018-08-10 11:29:45 -0700119
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700120 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700121 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700122 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700123 [&app](const crow::Request& req,
124 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000125 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700126 {
127 return;
128 }
129 BMCWEB_LOG_DEBUG << "Post Manager Reset.";
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500130
Ed Tanous002d39b2022-05-31 08:59:27 -0700131 std::string resetType;
Jennifer Leeed5befb2018-08-10 11:29:45 -0700132
Ed Tanous002d39b2022-05-31 08:59:27 -0700133 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
134 resetType))
135 {
136 return;
137 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500138
Ed Tanous002d39b2022-05-31 08:59:27 -0700139 if (resetType == "GracefulRestart")
140 {
141 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
142 doBMCGracefulRestart(asyncResp);
143 return;
144 }
145 if (resetType == "ForceRestart")
146 {
147 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
148 doBMCForceRestart(asyncResp);
149 return;
150 }
151 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
152 << resetType;
153 messages::actionParameterNotSupported(asyncResp->res, resetType,
154 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700155
Ed Tanous002d39b2022-05-31 08:59:27 -0700156 return;
157 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700158}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700159
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500160/**
161 * ManagerResetToDefaultsAction class supports POST method for factory reset
162 * action.
163 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700164inline void requestRoutesManagerResetToDefaultsAction(App& app)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500165{
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500166 /**
167 * Function handles ResetToDefaults POST method request.
168 *
169 * Analyzes POST body message and factory resets BMC by calling
170 * BMC code updater factory reset followed by a BMC reboot.
171 *
172 * BMC code updater factory reset wipes the whole BMC read-write
173 * filesystem which includes things like the network settings.
174 *
175 * OpenBMC only supports ResetToDefaultsType "ResetAll".
176 */
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500177
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700178 BMCWEB_ROUTE(app,
179 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/")
Ed Tanoused398212021-06-09 17:05:54 -0700180 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700181 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700182 [&app](const crow::Request& req,
183 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000184 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700185 {
186 return;
187 }
188 BMCWEB_LOG_DEBUG << "Post ResetToDefaults.";
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500189
Ed Tanous002d39b2022-05-31 08:59:27 -0700190 std::string resetType;
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500191
Ed Tanous002d39b2022-05-31 08:59:27 -0700192 if (!json_util::readJsonAction(req, asyncResp->res,
193 "ResetToDefaultsType", resetType))
194 {
195 BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700196
Ed Tanous002d39b2022-05-31 08:59:27 -0700197 messages::actionParameterMissing(asyncResp->res, "ResetToDefaults",
198 "ResetToDefaultsType");
199 return;
200 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700201
Ed Tanous002d39b2022-05-31 08:59:27 -0700202 if (resetType != "ResetAll")
203 {
204 BMCWEB_LOG_DEBUG
205 << "Invalid property value for ResetToDefaultsType: "
206 << resetType;
207 messages::actionParameterNotSupported(asyncResp->res, resetType,
208 "ResetToDefaultsType");
209 return;
210 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700211
Ed Tanous002d39b2022-05-31 08:59:27 -0700212 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800213 [asyncResp](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700214 if (ec)
215 {
216 BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec;
217 messages::internalError(asyncResp->res);
218 return;
219 }
220 // Factory Reset doesn't actually happen until a reboot
221 // Can't erase what the BMC is running on
222 doBMCGracefulRestart(asyncResp);
223 },
224 "xyz.openbmc_project.Software.BMC.Updater",
225 "/xyz/openbmc_project/software",
226 "xyz.openbmc_project.Common.FactoryReset", "Reset");
227 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700228}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500229
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530230/**
231 * ManagerResetActionInfo derived class for delivering Manager
232 * ResetType AllowableValues using ResetInfo schema.
233 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700234inline void requestRoutesManagerResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530235{
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530236 /**
237 * Functions triggers appropriate requests on DBus
238 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700239
240 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700241 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700242 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700243 [&app](const crow::Request& req,
244 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000245 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700246 {
247 return;
248 }
Ed Tanous14766872022-03-15 10:44:42 -0700249
Ed Tanous002d39b2022-05-31 08:59:27 -0700250 asyncResp->res.jsonValue["@odata.type"] =
251 "#ActionInfo.v1_1_2.ActionInfo";
252 asyncResp->res.jsonValue["@odata.id"] =
253 "/redfish/v1/Managers/bmc/ResetActionInfo";
254 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
255 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
256 nlohmann::json::object_t parameter;
257 parameter["Name"] = "ResetType";
258 parameter["Required"] = true;
259 parameter["DataType"] = "String";
Ed Tanous14766872022-03-15 10:44:42 -0700260
Ed Tanous002d39b2022-05-31 08:59:27 -0700261 nlohmann::json::array_t allowableValues;
Patrick Williamsad539542023-05-12 10:10:08 -0500262 allowableValues.emplace_back("GracefulRestart");
263 allowableValues.emplace_back("ForceRestart");
Ed Tanous002d39b2022-05-31 08:59:27 -0700264 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700265
Ed Tanous002d39b2022-05-31 08:59:27 -0700266 nlohmann::json::array_t parameters;
Patrick Williamsad539542023-05-12 10:10:08 -0500267 parameters.emplace_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700268
Ed Tanous002d39b2022-05-31 08:59:27 -0700269 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
270 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700271}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530272
James Feist5b4aa862018-08-16 14:07:01 -0700273static constexpr const char* objectManagerIface =
274 "org.freedesktop.DBus.ObjectManager";
275static constexpr const char* pidConfigurationIface =
276 "xyz.openbmc_project.Configuration.Pid";
277static constexpr const char* pidZoneConfigurationIface =
278 "xyz.openbmc_project.Configuration.Pid.Zone";
James Feistb7a08d02018-12-11 14:55:37 -0800279static constexpr const char* stepwiseConfigurationIface =
280 "xyz.openbmc_project.Configuration.Stepwise";
James Feist73df0db2019-03-25 15:29:35 -0700281static constexpr const char* thermalModeIface =
282 "xyz.openbmc_project.Control.ThermalMode";
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100283
zhanghch058d1b46d2021-04-01 11:18:24 +0800284inline void
285 asyncPopulatePid(const std::string& connection, const std::string& path,
286 const std::string& currentProfile,
287 const std::vector<std::string>& supportedProfiles,
288 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist5b4aa862018-08-16 14:07:01 -0700289{
James Feist5b4aa862018-08-16 14:07:01 -0700290 crow::connections::systemBus->async_method_call(
James Feist73df0db2019-03-25 15:29:35 -0700291 [asyncResp, currentProfile, supportedProfiles](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800292 const boost::system::error_code& ec,
James Feist73df0db2019-03-25 15:29:35 -0700293 const dbus::utility::ManagedObjectType& managedObj) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700294 if (ec)
295 {
296 BMCWEB_LOG_ERROR << ec;
297 asyncResp->res.jsonValue.clear();
298 messages::internalError(asyncResp->res);
299 return;
300 }
301 nlohmann::json& configRoot =
302 asyncResp->res.jsonValue["Oem"]["OpenBmc"]["Fan"];
303 nlohmann::json& fans = configRoot["FanControllers"];
304 fans["@odata.type"] = "#OemManager.FanControllers";
305 fans["@odata.id"] =
306 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers";
307
308 nlohmann::json& pids = configRoot["PidControllers"];
309 pids["@odata.type"] = "#OemManager.PidControllers";
310 pids["@odata.id"] =
311 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers";
312
313 nlohmann::json& stepwise = configRoot["StepwiseControllers"];
314 stepwise["@odata.type"] = "#OemManager.StepwiseControllers";
315 stepwise["@odata.id"] =
316 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers";
317
318 nlohmann::json& zones = configRoot["FanZones"];
319 zones["@odata.id"] =
320 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones";
321 zones["@odata.type"] = "#OemManager.FanZones";
322 configRoot["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan";
323 configRoot["@odata.type"] = "#OemManager.Fan";
324 configRoot["Profile@Redfish.AllowableValues"] = supportedProfiles;
325
326 if (!currentProfile.empty())
327 {
328 configRoot["Profile"] = currentProfile;
329 }
330 BMCWEB_LOG_ERROR << "profile = " << currentProfile << " !";
331
332 for (const auto& pathPair : managedObj)
333 {
334 for (const auto& intfPair : pathPair.second)
James Feist5b4aa862018-08-16 14:07:01 -0700335 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700336 if (intfPair.first != pidConfigurationIface &&
337 intfPair.first != pidZoneConfigurationIface &&
338 intfPair.first != stepwiseConfigurationIface)
James Feist5b4aa862018-08-16 14:07:01 -0700339 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700340 continue;
341 }
James Feist73df0db2019-03-25 15:29:35 -0700342
Ed Tanous002d39b2022-05-31 08:59:27 -0700343 std::string name;
James Feist73df0db2019-03-25 15:29:35 -0700344
Ed Tanous002d39b2022-05-31 08:59:27 -0700345 for (const std::pair<std::string,
346 dbus::utility::DbusVariantType>& propPair :
347 intfPair.second)
348 {
349 if (propPair.first == "Name")
James Feist73df0db2019-03-25 15:29:35 -0700350 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700351 const std::string* namePtr =
352 std::get_if<std::string>(&propPair.second);
353 if (namePtr == nullptr)
James Feist73df0db2019-03-25 15:29:35 -0700354 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700355 BMCWEB_LOG_ERROR << "Pid Name Field illegal";
James Feistc33a90e2019-03-01 10:17:44 -0800356 messages::internalError(asyncResp->res);
357 return;
358 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700359 name = *namePtr;
360 dbus::utility::escapePathForDbus(name);
James Feistb7a08d02018-12-11 14:55:37 -0800361 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700362 else if (propPair.first == "Profiles")
James Feistb7a08d02018-12-11 14:55:37 -0800363 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700364 const std::vector<std::string>* profiles =
365 std::get_if<std::vector<std::string>>(
366 &propPair.second);
367 if (profiles == nullptr)
James Feistb7a08d02018-12-11 14:55:37 -0800368 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700369 BMCWEB_LOG_ERROR << "Pid Profiles Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800370 messages::internalError(asyncResp->res);
371 return;
372 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700373 if (std::find(profiles->begin(), profiles->end(),
374 currentProfile) == profiles->end())
James Feistb7a08d02018-12-11 14:55:37 -0800375 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700376 BMCWEB_LOG_INFO
377 << name << " not supported in current profile";
378 continue;
James Feistb7a08d02018-12-11 14:55:37 -0800379 }
380 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700381 }
382 nlohmann::json* config = nullptr;
383 const std::string* classPtr = nullptr;
384
385 for (const std::pair<std::string,
386 dbus::utility::DbusVariantType>& propPair :
387 intfPair.second)
388 {
389 if (propPair.first == "Class")
James Feistb7a08d02018-12-11 14:55:37 -0800390 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700391 classPtr = std::get_if<std::string>(&propPair.second);
392 }
393 }
394
Willy Tueddfc432022-09-26 16:46:38 +0000395 boost::urls::url url = crow::utility::urlFromPieces(
396 "redfish", "v1", "Managers", "bmc");
Ed Tanous002d39b2022-05-31 08:59:27 -0700397 if (intfPair.first == pidZoneConfigurationIface)
398 {
399 std::string chassis;
400 if (!dbus::utility::getNthStringFromPath(pathPair.first.str,
401 5, chassis))
402 {
403 chassis = "#IllegalValue";
404 }
405 nlohmann::json& zone = zones[name];
Willy Tueddfc432022-09-26 16:46:38 +0000406 zone["Chassis"]["@odata.id"] = crow::utility::urlFromPieces(
407 "redfish", "v1", "Chassis", chassis);
408 url.set_fragment(
409 ("/Oem/OpenBmc/Fan/FanZones"_json_pointer / name)
410 .to_string());
411 zone["@odata.id"] = std::move(url);
Ed Tanous002d39b2022-05-31 08:59:27 -0700412 zone["@odata.type"] = "#OemManager.FanZone";
413 config = &zone;
414 }
415
416 else if (intfPair.first == stepwiseConfigurationIface)
417 {
418 if (classPtr == nullptr)
419 {
420 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800421 messages::internalError(asyncResp->res);
422 return;
423 }
424
Ed Tanous002d39b2022-05-31 08:59:27 -0700425 nlohmann::json& controller = stepwise[name];
426 config = &controller;
Willy Tueddfc432022-09-26 16:46:38 +0000427 url.set_fragment(
428 ("/Oem/OpenBmc/Fan/StepwiseControllers"_json_pointer /
429 name)
430 .to_string());
431 controller["@odata.id"] = std::move(url);
Ed Tanous002d39b2022-05-31 08:59:27 -0700432 controller["@odata.type"] =
433 "#OemManager.StepwiseController";
434
435 controller["Direction"] = *classPtr;
436 }
437
438 // pid and fans are off the same configuration
439 else if (intfPair.first == pidConfigurationIface)
440 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700441 if (classPtr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700442 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700443 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
444 messages::internalError(asyncResp->res);
445 return;
446 }
447 bool isFan = *classPtr == "fan";
448 nlohmann::json& element = isFan ? fans[name] : pids[name];
449 config = &element;
450 if (isFan)
451 {
Willy Tueddfc432022-09-26 16:46:38 +0000452 url.set_fragment(
453 ("/Oem/OpenBmc/Fan/FanControllers"_json_pointer /
454 name)
455 .to_string());
456 element["@odata.id"] = std::move(url);
Ed Tanous002d39b2022-05-31 08:59:27 -0700457 element["@odata.type"] = "#OemManager.FanController";
458 }
459 else
460 {
Willy Tueddfc432022-09-26 16:46:38 +0000461 url.set_fragment(
462 ("/Oem/OpenBmc/Fan/PidControllers"_json_pointer /
463 name)
464 .to_string());
465 element["@odata.id"] = std::move(url);
Ed Tanous002d39b2022-05-31 08:59:27 -0700466 element["@odata.type"] = "#OemManager.PidController";
467 }
468 }
469 else
470 {
471 BMCWEB_LOG_ERROR << "Unexpected configuration";
472 messages::internalError(asyncResp->res);
473 return;
474 }
James Feist5b4aa862018-08-16 14:07:01 -0700475
Ed Tanous002d39b2022-05-31 08:59:27 -0700476 // used for making maps out of 2 vectors
477 const std::vector<double>* keys = nullptr;
478 const std::vector<double>* values = nullptr;
479
480 for (const auto& propertyPair : intfPair.second)
481 {
482 if (propertyPair.first == "Type" ||
483 propertyPair.first == "Class" ||
484 propertyPair.first == "Name")
485 {
486 continue;
487 }
488
489 // zones
490 if (intfPair.first == pidZoneConfigurationIface)
491 {
492 const double* ptr =
493 std::get_if<double>(&propertyPair.second);
494 if (ptr == nullptr)
495 {
496 BMCWEB_LOG_ERROR << "Field Illegal "
497 << propertyPair.first;
498 messages::internalError(asyncResp->res);
499 return;
500 }
501 (*config)[propertyPair.first] = *ptr;
502 }
503
504 if (intfPair.first == stepwiseConfigurationIface)
505 {
506 if (propertyPair.first == "Reading" ||
507 propertyPair.first == "Output")
508 {
509 const std::vector<double>* ptr =
510 std::get_if<std::vector<double>>(
511 &propertyPair.second);
512
513 if (ptr == nullptr)
514 {
515 BMCWEB_LOG_ERROR << "Field Illegal "
516 << propertyPair.first;
517 messages::internalError(asyncResp->res);
518 return;
519 }
520
521 if (propertyPair.first == "Reading")
522 {
523 keys = ptr;
524 }
525 else
526 {
527 values = ptr;
528 }
529 if (keys != nullptr && values != nullptr)
530 {
531 if (keys->size() != values->size())
532 {
533 BMCWEB_LOG_ERROR
534 << "Reading and Output size don't match ";
535 messages::internalError(asyncResp->res);
536 return;
537 }
538 nlohmann::json& steps = (*config)["Steps"];
539 steps = nlohmann::json::array();
540 for (size_t ii = 0; ii < keys->size(); ii++)
541 {
542 nlohmann::json::object_t step;
543 step["Target"] = (*keys)[ii];
544 step["Output"] = (*values)[ii];
545 steps.push_back(std::move(step));
546 }
547 }
548 }
549 if (propertyPair.first == "NegativeHysteresis" ||
550 propertyPair.first == "PositiveHysteresis")
James Feist5b4aa862018-08-16 14:07:01 -0700551 {
Ed Tanous1b6b96c2018-11-30 11:35:41 -0800552 const double* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800553 std::get_if<double>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700554 if (ptr == nullptr)
555 {
556 BMCWEB_LOG_ERROR << "Field Illegal "
557 << propertyPair.first;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700558 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700559 return;
560 }
James Feistb7a08d02018-12-11 14:55:37 -0800561 (*config)[propertyPair.first] = *ptr;
562 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700563 }
James Feistb7a08d02018-12-11 14:55:37 -0800564
Ed Tanous002d39b2022-05-31 08:59:27 -0700565 // pid and fans are off the same configuration
566 if (intfPair.first == pidConfigurationIface ||
567 intfPair.first == stepwiseConfigurationIface)
568 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700569 if (propertyPair.first == "Zones")
James Feistb7a08d02018-12-11 14:55:37 -0800570 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700571 const std::vector<std::string>* inputs =
572 std::get_if<std::vector<std::string>>(
573 &propertyPair.second);
574
575 if (inputs == nullptr)
James Feistb7a08d02018-12-11 14:55:37 -0800576 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700577 BMCWEB_LOG_ERROR << "Zones Pid Field Illegal";
578 messages::internalError(asyncResp->res);
579 return;
James Feistb7a08d02018-12-11 14:55:37 -0800580 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700581 auto& data = (*config)[propertyPair.first];
582 data = nlohmann::json::array();
583 for (std::string itemCopy : *inputs)
James Feistb7a08d02018-12-11 14:55:37 -0800584 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700585 dbus::utility::escapePathForDbus(itemCopy);
586 nlohmann::json::object_t input;
Willy Tueddfc432022-09-26 16:46:38 +0000587 boost::urls::url managerUrl =
588 crow::utility::urlFromPieces(
589 "redfish", "v1", "Managers", "bmc");
590 managerUrl.set_fragment(
591 ("/Oem/OpenBmc/Fan/FanZones"_json_pointer /
592 itemCopy)
593 .to_string());
594 input["@odata.id"] = std::move(managerUrl);
Ed Tanous002d39b2022-05-31 08:59:27 -0700595 data.push_back(std::move(input));
James Feistb7a08d02018-12-11 14:55:37 -0800596 }
James Feist5b4aa862018-08-16 14:07:01 -0700597 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700598 // todo(james): may never happen, but this
599 // assumes configuration data referenced in the
600 // PID config is provided by the same daemon, we
601 // could add another loop to cover all cases,
602 // but I'm okay kicking this can down the road a
603 // bit
James Feist5b4aa862018-08-16 14:07:01 -0700604
Ed Tanous002d39b2022-05-31 08:59:27 -0700605 else if (propertyPair.first == "Inputs" ||
606 propertyPair.first == "Outputs")
James Feist5b4aa862018-08-16 14:07:01 -0700607 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700608 auto& data = (*config)[propertyPair.first];
609 const std::vector<std::string>* inputs =
610 std::get_if<std::vector<std::string>>(
611 &propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700612
Ed Tanous002d39b2022-05-31 08:59:27 -0700613 if (inputs == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700614 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700615 BMCWEB_LOG_ERROR << "Field Illegal "
616 << propertyPair.first;
617 messages::internalError(asyncResp->res);
618 return;
James Feist5b4aa862018-08-16 14:07:01 -0700619 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700620 data = *inputs;
621 }
622 else if (propertyPair.first == "SetPointOffset")
623 {
624 const std::string* ptr =
625 std::get_if<std::string>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700626
Ed Tanous002d39b2022-05-31 08:59:27 -0700627 if (ptr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700628 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700629 BMCWEB_LOG_ERROR << "Field Illegal "
630 << propertyPair.first;
631 messages::internalError(asyncResp->res);
632 return;
James Feistb943aae2019-07-11 16:33:56 -0700633 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700634 // translate from dbus to redfish
635 if (*ptr == "WarningHigh")
James Feistb943aae2019-07-11 16:33:56 -0700636 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700637 (*config)["SetPointOffset"] =
638 "UpperThresholdNonCritical";
James Feistb943aae2019-07-11 16:33:56 -0700639 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700640 else if (*ptr == "WarningLow")
James Feist5b4aa862018-08-16 14:07:01 -0700641 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700642 (*config)["SetPointOffset"] =
643 "LowerThresholdNonCritical";
James Feist5b4aa862018-08-16 14:07:01 -0700644 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700645 else if (*ptr == "CriticalHigh")
646 {
647 (*config)["SetPointOffset"] =
648 "UpperThresholdCritical";
649 }
650 else if (*ptr == "CriticalLow")
651 {
652 (*config)["SetPointOffset"] =
653 "LowerThresholdCritical";
654 }
655 else
656 {
657 BMCWEB_LOG_ERROR << "Value Illegal " << *ptr;
658 messages::internalError(asyncResp->res);
659 return;
660 }
661 }
662 // doubles
663 else if (propertyPair.first == "FFGainCoefficient" ||
664 propertyPair.first == "FFOffCoefficient" ||
665 propertyPair.first == "ICoefficient" ||
666 propertyPair.first == "ILimitMax" ||
667 propertyPair.first == "ILimitMin" ||
668 propertyPair.first == "PositiveHysteresis" ||
669 propertyPair.first == "NegativeHysteresis" ||
670 propertyPair.first == "OutLimitMax" ||
671 propertyPair.first == "OutLimitMin" ||
672 propertyPair.first == "PCoefficient" ||
673 propertyPair.first == "SetPoint" ||
674 propertyPair.first == "SlewNeg" ||
675 propertyPair.first == "SlewPos")
676 {
677 const double* ptr =
678 std::get_if<double>(&propertyPair.second);
679 if (ptr == nullptr)
680 {
681 BMCWEB_LOG_ERROR << "Field Illegal "
682 << propertyPair.first;
683 messages::internalError(asyncResp->res);
684 return;
685 }
686 (*config)[propertyPair.first] = *ptr;
James Feist5b4aa862018-08-16 14:07:01 -0700687 }
688 }
689 }
690 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700691 }
James Feist5b4aa862018-08-16 14:07:01 -0700692 },
693 connection, path, objectManagerIface, "GetManagedObjects");
694}
Jennifer Leeca537922018-08-10 10:07:30 -0700695
James Feist83ff9ab2018-08-31 10:18:24 -0700696enum class CreatePIDRet
697{
698 fail,
699 del,
700 patch
701};
702
zhanghch058d1b46d2021-04-01 11:18:24 +0800703inline bool
704 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response,
705 std::vector<nlohmann::json>& config,
706 std::vector<std::string>& zones)
James Feist5f2caae2018-12-12 14:08:25 -0800707{
James Feistb6baeaa2019-02-21 10:41:40 -0800708 if (config.empty())
709 {
710 BMCWEB_LOG_ERROR << "Empty Zones";
Ed Tanous1668ce62022-02-07 23:44:31 -0800711 messages::propertyValueFormatError(response->res, "[]", "Zones");
James Feistb6baeaa2019-02-21 10:41:40 -0800712 return false;
713 }
James Feist5f2caae2018-12-12 14:08:25 -0800714 for (auto& odata : config)
715 {
716 std::string path;
717 if (!redfish::json_util::readJson(odata, response->res, "@odata.id",
718 path))
719 {
720 return false;
721 }
722 std::string input;
James Feist61adbda2019-03-25 13:03:51 -0700723
724 // 8 below comes from
725 // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left
726 // 0 1 2 3 4 5 6 7 8
727 if (!dbus::utility::getNthStringFromPath(path, 8, input))
James Feist5f2caae2018-12-12 14:08:25 -0800728 {
729 BMCWEB_LOG_ERROR << "Got invalid path " << path;
730 BMCWEB_LOG_ERROR << "Illegal Type Zones";
731 messages::propertyValueFormatError(response->res, odata.dump(),
732 "Zones");
733 return false;
734 }
Ed Tanousa170f272022-06-30 21:53:27 -0700735 std::replace(input.begin(), input.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -0800736 zones.emplace_back(std::move(input));
737 }
738 return true;
739}
740
Ed Tanous711ac7a2021-12-20 09:34:41 -0800741inline const dbus::utility::ManagedObjectType::value_type*
James Feist73df0db2019-03-25 15:29:35 -0700742 findChassis(const dbus::utility::ManagedObjectType& managedObj,
743 const std::string& value, std::string& chassis)
James Feistb6baeaa2019-02-21 10:41:40 -0800744{
745 BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n";
746
Ed Tanousa170f272022-06-30 21:53:27 -0700747 std::string escaped = value;
Yaswanth Reddy M6ce82fa2023-03-10 07:29:45 +0000748 std::replace(escaped.begin(), escaped.end(), ' ', '_');
James Feistb6baeaa2019-02-21 10:41:40 -0800749 escaped = "/" + escaped;
Ed Tanous002d39b2022-05-31 08:59:27 -0700750 auto it = std::find_if(managedObj.begin(), managedObj.end(),
751 [&escaped](const auto& obj) {
752 if (boost::algorithm::ends_with(obj.first.str, escaped))
753 {
754 BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n";
755 return true;
756 }
757 return false;
758 });
James Feistb6baeaa2019-02-21 10:41:40 -0800759
760 if (it == managedObj.end())
761 {
James Feist73df0db2019-03-25 15:29:35 -0700762 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800763 }
764 // 5 comes from <chassis-name> being the 5th element
765 // /xyz/openbmc_project/inventory/system/chassis/<chassis-name>
James Feist73df0db2019-03-25 15:29:35 -0700766 if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis))
767 {
768 return &(*it);
769 }
770
771 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800772}
773
Ed Tanous23a21a12020-07-25 04:45:05 +0000774inline CreatePIDRet createPidInterface(
zhanghch058d1b46d2021-04-01 11:18:24 +0800775 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type,
Ed Tanousb5a76932020-09-29 16:16:58 -0700776 const nlohmann::json::iterator& it, const std::string& path,
James Feist83ff9ab2018-08-31 10:18:24 -0700777 const dbus::utility::ManagedObjectType& managedObj, bool createNewObject,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800778 dbus::utility::DBusPropertiesMap& output, std::string& chassis,
779 const std::string& profile)
James Feist83ff9ab2018-08-31 10:18:24 -0700780{
James Feist5f2caae2018-12-12 14:08:25 -0800781 // common deleter
James Feistb6baeaa2019-02-21 10:41:40 -0800782 if (it.value() == nullptr)
James Feist5f2caae2018-12-12 14:08:25 -0800783 {
784 std::string iface;
785 if (type == "PidControllers" || type == "FanControllers")
786 {
787 iface = pidConfigurationIface;
788 }
789 else if (type == "FanZones")
790 {
791 iface = pidZoneConfigurationIface;
792 }
793 else if (type == "StepwiseControllers")
794 {
795 iface = stepwiseConfigurationIface;
796 }
797 else
798 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600799 BMCWEB_LOG_ERROR << "Illegal Type " << type;
James Feist5f2caae2018-12-12 14:08:25 -0800800 messages::propertyUnknown(response->res, type);
801 return CreatePIDRet::fail;
802 }
James Feist6ee7f772020-02-06 16:25:27 -0800803
804 BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n";
James Feist5f2caae2018-12-12 14:08:25 -0800805 // delete interface
806 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -0800807 [response, path](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700808 if (ec)
809 {
810 BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec;
811 messages::internalError(response->res);
812 return;
813 }
814 messages::success(response->res);
James Feist5f2caae2018-12-12 14:08:25 -0800815 },
816 "xyz.openbmc_project.EntityManager", path, iface, "Delete");
817 return CreatePIDRet::del;
818 }
819
Ed Tanous711ac7a2021-12-20 09:34:41 -0800820 const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800821 if (!createNewObject)
822 {
823 // if we aren't creating a new object, we should be able to find it on
824 // d-bus
James Feist73df0db2019-03-25 15:29:35 -0700825 managedItem = findChassis(managedObj, it.key(), chassis);
826 if (managedItem == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800827 {
828 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700829 messages::invalidObject(response->res,
830 crow::utility::urlFromPieces(
831 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800832 return CreatePIDRet::fail;
833 }
834 }
835
Ed Tanous26f69762022-01-25 09:49:11 -0800836 if (!profile.empty() &&
James Feist73df0db2019-03-25 15:29:35 -0700837 (type == "PidControllers" || type == "FanControllers" ||
838 type == "StepwiseControllers"))
839 {
840 if (managedItem == nullptr)
841 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800842 output.emplace_back("Profiles", std::vector<std::string>{profile});
James Feist73df0db2019-03-25 15:29:35 -0700843 }
844 else
845 {
846 std::string interface;
847 if (type == "StepwiseControllers")
848 {
849 interface = stepwiseConfigurationIface;
850 }
851 else
852 {
853 interface = pidConfigurationIface;
854 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800855 bool ifaceFound = false;
856 for (const auto& iface : managedItem->second)
857 {
858 if (iface.first == interface)
859 {
860 ifaceFound = true;
861 for (const auto& prop : iface.second)
862 {
863 if (prop.first == "Profiles")
864 {
865 const std::vector<std::string>* curProfiles =
866 std::get_if<std::vector<std::string>>(
867 &(prop.second));
868 if (curProfiles == nullptr)
869 {
870 BMCWEB_LOG_ERROR
871 << "Illegal profiles in managed object";
872 messages::internalError(response->res);
873 return CreatePIDRet::fail;
874 }
875 if (std::find(curProfiles->begin(),
876 curProfiles->end(),
877 profile) == curProfiles->end())
878 {
879 std::vector<std::string> newProfiles =
880 *curProfiles;
881 newProfiles.push_back(profile);
Ed Tanousb9d36b42022-02-26 21:42:46 -0800882 output.emplace_back("Profiles", newProfiles);
Ed Tanous711ac7a2021-12-20 09:34:41 -0800883 }
884 }
885 }
886 }
887 }
888
889 if (!ifaceFound)
James Feist73df0db2019-03-25 15:29:35 -0700890 {
891 BMCWEB_LOG_ERROR
892 << "Failed to find interface in managed object";
893 messages::internalError(response->res);
894 return CreatePIDRet::fail;
895 }
James Feist73df0db2019-03-25 15:29:35 -0700896 }
897 }
898
James Feist83ff9ab2018-08-31 10:18:24 -0700899 if (type == "PidControllers" || type == "FanControllers")
900 {
901 if (createNewObject)
902 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800903 output.emplace_back("Class",
904 type == "PidControllers" ? "temp" : "fan");
905 output.emplace_back("Type", "Pid");
James Feist83ff9ab2018-08-31 10:18:24 -0700906 }
James Feist5f2caae2018-12-12 14:08:25 -0800907
908 std::optional<std::vector<nlohmann::json>> zones;
909 std::optional<std::vector<std::string>> inputs;
910 std::optional<std::vector<std::string>> outputs;
911 std::map<std::string, std::optional<double>> doubles;
James Feistb943aae2019-07-11 16:33:56 -0700912 std::optional<std::string> setpointOffset;
James Feist5f2caae2018-12-12 14:08:25 -0800913 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -0800914 it.value(), response->res, "Inputs", inputs, "Outputs", outputs,
James Feist5f2caae2018-12-12 14:08:25 -0800915 "Zones", zones, "FFGainCoefficient",
916 doubles["FFGainCoefficient"], "FFOffCoefficient",
917 doubles["FFOffCoefficient"], "ICoefficient",
918 doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"],
919 "ILimitMin", doubles["ILimitMin"], "OutLimitMax",
920 doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"],
921 "PCoefficient", doubles["PCoefficient"], "SetPoint",
James Feistb943aae2019-07-11 16:33:56 -0700922 doubles["SetPoint"], "SetPointOffset", setpointOffset,
923 "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"],
924 "PositiveHysteresis", doubles["PositiveHysteresis"],
925 "NegativeHysteresis", doubles["NegativeHysteresis"]))
James Feist83ff9ab2018-08-31 10:18:24 -0700926 {
James Feist5f2caae2018-12-12 14:08:25 -0800927 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700928 }
James Feist5f2caae2018-12-12 14:08:25 -0800929 if (zones)
James Feist83ff9ab2018-08-31 10:18:24 -0700930 {
James Feist5f2caae2018-12-12 14:08:25 -0800931 std::vector<std::string> zonesStr;
932 if (!getZonesFromJsonReq(response, *zones, zonesStr))
James Feist83ff9ab2018-08-31 10:18:24 -0700933 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600934 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -0800935 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700936 }
James Feistb6baeaa2019-02-21 10:41:40 -0800937 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -0800938 findChassis(managedObj, zonesStr[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800939 {
940 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700941 messages::invalidObject(
942 response->res, crow::utility::urlFromPieces(
943 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800944 return CreatePIDRet::fail;
945 }
Ed Tanousb9d36b42022-02-26 21:42:46 -0800946 output.emplace_back("Zones", std::move(zonesStr));
James Feist5f2caae2018-12-12 14:08:25 -0800947 }
Ed Tanousafb9ee02022-12-21 11:59:17 -0800948
949 if (inputs)
James Feist5f2caae2018-12-12 14:08:25 -0800950 {
Ed Tanousafb9ee02022-12-21 11:59:17 -0800951 for (std::string& value : *inputs)
James Feist83ff9ab2018-08-31 10:18:24 -0700952 {
Ed Tanousafb9ee02022-12-21 11:59:17 -0800953 std::replace(value.begin(), value.end(), '_', ' ');
James Feist83ff9ab2018-08-31 10:18:24 -0700954 }
Ed Tanousafb9ee02022-12-21 11:59:17 -0800955 output.emplace_back("Inputs", *inputs);
956 }
957
958 if (outputs)
959 {
960 for (std::string& value : *outputs)
961 {
962 std::replace(value.begin(), value.end(), '_', ' ');
963 }
964 output.emplace_back("Outputs", *outputs);
James Feist5f2caae2018-12-12 14:08:25 -0800965 }
James Feist83ff9ab2018-08-31 10:18:24 -0700966
James Feistb943aae2019-07-11 16:33:56 -0700967 if (setpointOffset)
968 {
969 // translate between redfish and dbus names
970 if (*setpointOffset == "UpperThresholdNonCritical")
971 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800972 output.emplace_back("SetPointOffset", "WarningLow");
James Feistb943aae2019-07-11 16:33:56 -0700973 }
974 else if (*setpointOffset == "LowerThresholdNonCritical")
975 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800976 output.emplace_back("SetPointOffset", "WarningHigh");
James Feistb943aae2019-07-11 16:33:56 -0700977 }
978 else if (*setpointOffset == "LowerThresholdCritical")
979 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800980 output.emplace_back("SetPointOffset", "CriticalLow");
James Feistb943aae2019-07-11 16:33:56 -0700981 }
982 else if (*setpointOffset == "UpperThresholdCritical")
983 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800984 output.emplace_back("SetPointOffset", "CriticalHigh");
James Feistb943aae2019-07-11 16:33:56 -0700985 }
986 else
987 {
988 BMCWEB_LOG_ERROR << "Invalid setpointoffset "
989 << *setpointOffset;
Ed Tanousace85d62021-10-26 12:45:59 -0700990 messages::propertyValueNotInList(response->res, it.key(),
991 "SetPointOffset");
James Feistb943aae2019-07-11 16:33:56 -0700992 return CreatePIDRet::fail;
993 }
994 }
995
James Feist5f2caae2018-12-12 14:08:25 -0800996 // doubles
997 for (const auto& pairs : doubles)
998 {
999 if (!pairs.second)
James Feist83ff9ab2018-08-31 10:18:24 -07001000 {
James Feist5f2caae2018-12-12 14:08:25 -08001001 continue;
James Feist83ff9ab2018-08-31 10:18:24 -07001002 }
James Feist5f2caae2018-12-12 14:08:25 -08001003 BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second;
Ed Tanousb9d36b42022-02-26 21:42:46 -08001004 output.emplace_back(pairs.first, *pairs.second);
James Feist83ff9ab2018-08-31 10:18:24 -07001005 }
1006 }
James Feist5f2caae2018-12-12 14:08:25 -08001007
James Feist83ff9ab2018-08-31 10:18:24 -07001008 else if (type == "FanZones")
1009 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001010 output.emplace_back("Type", "Pid.Zone");
James Feist83ff9ab2018-08-31 10:18:24 -07001011
James Feist5f2caae2018-12-12 14:08:25 -08001012 std::optional<nlohmann::json> chassisContainer;
1013 std::optional<double> failSafePercent;
James Feistd3ec07f2019-02-25 14:51:15 -08001014 std::optional<double> minThermalOutput;
James Feistb6baeaa2019-02-21 10:41:40 -08001015 if (!redfish::json_util::readJson(it.value(), response->res, "Chassis",
James Feist5f2caae2018-12-12 14:08:25 -08001016 chassisContainer, "FailSafePercent",
James Feistd3ec07f2019-02-25 14:51:15 -08001017 failSafePercent, "MinThermalOutput",
1018 minThermalOutput))
James Feist83ff9ab2018-08-31 10:18:24 -07001019 {
James Feist5f2caae2018-12-12 14:08:25 -08001020 return CreatePIDRet::fail;
1021 }
James Feist83ff9ab2018-08-31 10:18:24 -07001022
James Feist5f2caae2018-12-12 14:08:25 -08001023 if (chassisContainer)
1024 {
James Feist5f2caae2018-12-12 14:08:25 -08001025 std::string chassisId;
1026 if (!redfish::json_util::readJson(*chassisContainer, response->res,
1027 "@odata.id", chassisId))
James Feist83ff9ab2018-08-31 10:18:24 -07001028 {
James Feist83ff9ab2018-08-31 10:18:24 -07001029 return CreatePIDRet::fail;
1030 }
James Feist5f2caae2018-12-12 14:08:25 -08001031
AppaRao Puli717794d2019-10-18 22:54:53 +05301032 // /redfish/v1/chassis/chassis_name/
James Feist5f2caae2018-12-12 14:08:25 -08001033 if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis))
1034 {
1035 BMCWEB_LOG_ERROR << "Got invalid path " << chassisId;
Ed Tanousace85d62021-10-26 12:45:59 -07001036 messages::invalidObject(
1037 response->res, crow::utility::urlFromPieces(
1038 "redfish", "v1", "Chassis", chassisId));
James Feist5f2caae2018-12-12 14:08:25 -08001039 return CreatePIDRet::fail;
1040 }
1041 }
James Feistd3ec07f2019-02-25 14:51:15 -08001042 if (minThermalOutput)
James Feist5f2caae2018-12-12 14:08:25 -08001043 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001044 output.emplace_back("MinThermalOutput", *minThermalOutput);
James Feist5f2caae2018-12-12 14:08:25 -08001045 }
1046 if (failSafePercent)
1047 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001048 output.emplace_back("FailSafePercent", *failSafePercent);
James Feist5f2caae2018-12-12 14:08:25 -08001049 }
1050 }
1051 else if (type == "StepwiseControllers")
1052 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001053 output.emplace_back("Type", "Stepwise");
James Feist5f2caae2018-12-12 14:08:25 -08001054
1055 std::optional<std::vector<nlohmann::json>> zones;
1056 std::optional<std::vector<nlohmann::json>> steps;
1057 std::optional<std::vector<std::string>> inputs;
1058 std::optional<double> positiveHysteresis;
1059 std::optional<double> negativeHysteresis;
James Feistc33a90e2019-03-01 10:17:44 -08001060 std::optional<std::string> direction; // upper clipping curve vs lower
James Feist5f2caae2018-12-12 14:08:25 -08001061 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -08001062 it.value(), response->res, "Zones", zones, "Steps", steps,
1063 "Inputs", inputs, "PositiveHysteresis", positiveHysteresis,
James Feistc33a90e2019-03-01 10:17:44 -08001064 "NegativeHysteresis", negativeHysteresis, "Direction",
1065 direction))
James Feist5f2caae2018-12-12 14:08:25 -08001066 {
James Feist5f2caae2018-12-12 14:08:25 -08001067 return CreatePIDRet::fail;
1068 }
1069
1070 if (zones)
1071 {
James Feistb6baeaa2019-02-21 10:41:40 -08001072 std::vector<std::string> zonesStrs;
1073 if (!getZonesFromJsonReq(response, *zones, zonesStrs))
James Feist5f2caae2018-12-12 14:08:25 -08001074 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001075 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -08001076 return CreatePIDRet::fail;
1077 }
James Feistb6baeaa2019-02-21 10:41:40 -08001078 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -08001079 findChassis(managedObj, zonesStrs[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -08001080 {
1081 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -07001082 messages::invalidObject(
1083 response->res, crow::utility::urlFromPieces(
1084 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -08001085 return CreatePIDRet::fail;
1086 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001087 output.emplace_back("Zones", std::move(zonesStrs));
James Feist5f2caae2018-12-12 14:08:25 -08001088 }
1089 if (steps)
1090 {
1091 std::vector<double> readings;
1092 std::vector<double> outputs;
1093 for (auto& step : *steps)
1094 {
Ed Tanous543f4402022-01-06 13:12:53 -08001095 double target = 0.0;
1096 double out = 0.0;
James Feist5f2caae2018-12-12 14:08:25 -08001097
1098 if (!redfish::json_util::readJson(step, response->res, "Target",
Ed Tanous23a21a12020-07-25 04:45:05 +00001099 target, "Output", out))
James Feist5f2caae2018-12-12 14:08:25 -08001100 {
James Feist5f2caae2018-12-12 14:08:25 -08001101 return CreatePIDRet::fail;
1102 }
1103 readings.emplace_back(target);
Ed Tanous23a21a12020-07-25 04:45:05 +00001104 outputs.emplace_back(out);
James Feist5f2caae2018-12-12 14:08:25 -08001105 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001106 output.emplace_back("Reading", std::move(readings));
1107 output.emplace_back("Output", std::move(outputs));
James Feist5f2caae2018-12-12 14:08:25 -08001108 }
1109 if (inputs)
1110 {
1111 for (std::string& value : *inputs)
1112 {
Ed Tanousa170f272022-06-30 21:53:27 -07001113 std::replace(value.begin(), value.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -08001114 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001115 output.emplace_back("Inputs", std::move(*inputs));
James Feist5f2caae2018-12-12 14:08:25 -08001116 }
1117 if (negativeHysteresis)
1118 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001119 output.emplace_back("NegativeHysteresis", *negativeHysteresis);
James Feist5f2caae2018-12-12 14:08:25 -08001120 }
1121 if (positiveHysteresis)
1122 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001123 output.emplace_back("PositiveHysteresis", *positiveHysteresis);
James Feist83ff9ab2018-08-31 10:18:24 -07001124 }
James Feistc33a90e2019-03-01 10:17:44 -08001125 if (direction)
1126 {
1127 constexpr const std::array<const char*, 2> allowedDirections = {
1128 "Ceiling", "Floor"};
1129 if (std::find(allowedDirections.begin(), allowedDirections.end(),
1130 *direction) == allowedDirections.end())
1131 {
1132 messages::propertyValueTypeError(response->res, "Direction",
1133 *direction);
1134 return CreatePIDRet::fail;
1135 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001136 output.emplace_back("Class", *direction);
James Feistc33a90e2019-03-01 10:17:44 -08001137 }
James Feist83ff9ab2018-08-31 10:18:24 -07001138 }
1139 else
1140 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001141 BMCWEB_LOG_ERROR << "Illegal Type " << type;
Jason M. Bills35a62c72018-10-09 12:45:45 -07001142 messages::propertyUnknown(response->res, type);
James Feist83ff9ab2018-08-31 10:18:24 -07001143 return CreatePIDRet::fail;
1144 }
1145 return CreatePIDRet::patch;
1146}
James Feist73df0db2019-03-25 15:29:35 -07001147struct GetPIDValues : std::enable_shared_from_this<GetPIDValues>
1148{
Ed Tanous6936afe2022-09-08 15:10:39 -07001149 struct CompletionValues
1150 {
1151 std::vector<std::string> supportedProfiles;
1152 std::string currentProfile;
1153 dbus::utility::MapperGetSubTreeResponse subtree;
1154 };
James Feist73df0db2019-03-25 15:29:35 -07001155
Ed Tanous4e23a442022-06-06 09:57:26 -07001156 explicit GetPIDValues(
1157 const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) :
Ed Tanous23a21a12020-07-25 04:45:05 +00001158 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001159
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001160 {}
James Feist73df0db2019-03-25 15:29:35 -07001161
1162 void run()
1163 {
1164 std::shared_ptr<GetPIDValues> self = shared_from_this();
1165
1166 // get all configurations
George Liue99073f2022-12-09 11:06:16 +08001167 constexpr std::array<std::string_view, 4> interfaces = {
1168 pidConfigurationIface, pidZoneConfigurationIface,
1169 objectManagerIface, stepwiseConfigurationIface};
1170 dbus::utility::getSubTree(
1171 "/", 0, interfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001172 [self](
George Liue99073f2022-12-09 11:06:16 +08001173 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001174 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001175 if (ec)
1176 {
1177 BMCWEB_LOG_ERROR << ec;
1178 messages::internalError(self->asyncResp->res);
1179 return;
1180 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001181 self->complete.subtree = subtreeLocal;
George Liue99073f2022-12-09 11:06:16 +08001182 });
James Feist73df0db2019-03-25 15:29:35 -07001183
1184 // at the same time get the selected profile
George Liue99073f2022-12-09 11:06:16 +08001185 constexpr std::array<std::string_view, 1> thermalModeIfaces = {
1186 thermalModeIface};
1187 dbus::utility::getSubTree(
1188 "/", 0, thermalModeIfaces,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001189 [self](
George Liue99073f2022-12-09 11:06:16 +08001190 const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001191 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001192 if (ec || subtreeLocal.empty())
1193 {
1194 return;
1195 }
1196 if (subtreeLocal[0].second.size() != 1)
1197 {
1198 // invalid mapper response, should never happen
1199 BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error";
1200 messages::internalError(self->asyncResp->res);
1201 return;
1202 }
1203
1204 const std::string& path = subtreeLocal[0].first;
1205 const std::string& owner = subtreeLocal[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001206
1207 sdbusplus::asio::getAllProperties(
1208 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous002d39b2022-05-31 08:59:27 -07001209 [path, owner,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001210 self](const boost::system::error_code& ec2,
Ed Tanous002d39b2022-05-31 08:59:27 -07001211 const dbus::utility::DBusPropertiesMap& resp) {
1212 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001213 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001214 BMCWEB_LOG_ERROR
1215 << "GetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001216 messages::internalError(self->asyncResp->res);
1217 return;
1218 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001219
Ed Tanous002d39b2022-05-31 08:59:27 -07001220 const std::string* current = nullptr;
1221 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001222
1223 const bool success = sdbusplus::unpackPropertiesNoThrow(
1224 dbus_utils::UnpackErrorPrinter(), resp, "Current", current,
1225 "Supported", supported);
1226
1227 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001228 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001229 messages::internalError(self->asyncResp->res);
1230 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001231 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001232
Ed Tanous002d39b2022-05-31 08:59:27 -07001233 if (current == nullptr || supported == nullptr)
1234 {
1235 BMCWEB_LOG_ERROR
1236 << "GetPIDValues: thermal mode iface invalid " << path;
1237 messages::internalError(self->asyncResp->res);
1238 return;
1239 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001240 self->complete.currentProfile = *current;
1241 self->complete.supportedProfiles = *supported;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001242 });
George Liue99073f2022-12-09 11:06:16 +08001243 });
James Feist73df0db2019-03-25 15:29:35 -07001244 }
1245
Ed Tanous6936afe2022-09-08 15:10:39 -07001246 static void
1247 processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1248 const CompletionValues& completion)
James Feist73df0db2019-03-25 15:29:35 -07001249 {
1250 if (asyncResp->res.result() != boost::beast::http::status::ok)
1251 {
1252 return;
1253 }
1254 // create map of <connection, path to objMgr>>
Ed Tanous6936afe2022-09-08 15:10:39 -07001255 boost::container::flat_map<
1256 std::string, std::string, std::less<>,
1257 std::vector<std::pair<std::string, std::string>>>
1258 objectMgrPaths;
1259 boost::container::flat_set<std::string, std::less<>,
1260 std::vector<std::string>>
1261 calledConnections;
1262 for (const auto& pathGroup : completion.subtree)
James Feist73df0db2019-03-25 15:29:35 -07001263 {
1264 for (const auto& connectionGroup : pathGroup.second)
1265 {
1266 auto findConnection =
1267 calledConnections.find(connectionGroup.first);
1268 if (findConnection != calledConnections.end())
1269 {
1270 break;
1271 }
1272 for (const std::string& interface : connectionGroup.second)
1273 {
1274 if (interface == objectManagerIface)
1275 {
1276 objectMgrPaths[connectionGroup.first] = pathGroup.first;
1277 }
1278 // this list is alphabetical, so we
1279 // should have found the objMgr by now
1280 if (interface == pidConfigurationIface ||
1281 interface == pidZoneConfigurationIface ||
1282 interface == stepwiseConfigurationIface)
1283 {
1284 auto findObjMgr =
1285 objectMgrPaths.find(connectionGroup.first);
1286 if (findObjMgr == objectMgrPaths.end())
1287 {
1288 BMCWEB_LOG_DEBUG << connectionGroup.first
1289 << "Has no Object Manager";
1290 continue;
1291 }
1292
1293 calledConnections.insert(connectionGroup.first);
1294
1295 asyncPopulatePid(findObjMgr->first, findObjMgr->second,
Ed Tanous6936afe2022-09-08 15:10:39 -07001296 completion.currentProfile,
1297 completion.supportedProfiles,
James Feist73df0db2019-03-25 15:29:35 -07001298 asyncResp);
1299 break;
1300 }
1301 }
1302 }
1303 }
1304 }
1305
Ed Tanous6936afe2022-09-08 15:10:39 -07001306 ~GetPIDValues()
1307 {
1308 boost::asio::post(crow::connections::systemBus->get_io_context(),
1309 std::bind_front(&processingComplete, asyncResp,
1310 std::move(complete)));
1311 }
1312
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001313 GetPIDValues(const GetPIDValues&) = delete;
1314 GetPIDValues(GetPIDValues&&) = delete;
1315 GetPIDValues& operator=(const GetPIDValues&) = delete;
1316 GetPIDValues& operator=(GetPIDValues&&) = delete;
1317
zhanghch058d1b46d2021-04-01 11:18:24 +08001318 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
Ed Tanous6936afe2022-09-08 15:10:39 -07001319 CompletionValues complete;
James Feist73df0db2019-03-25 15:29:35 -07001320};
1321
1322struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
1323{
zhanghch058d1b46d2021-04-01 11:18:24 +08001324 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn,
James Feist73df0db2019-03-25 15:29:35 -07001325 nlohmann::json& data) :
Ed Tanous271584a2019-07-09 16:24:22 -07001326 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001327 {
James Feist73df0db2019-03-25 15:29:35 -07001328 std::optional<nlohmann::json> pidControllers;
1329 std::optional<nlohmann::json> fanControllers;
1330 std::optional<nlohmann::json> fanZones;
1331 std::optional<nlohmann::json> stepwiseControllers;
1332
1333 if (!redfish::json_util::readJson(
1334 data, asyncResp->res, "PidControllers", pidControllers,
1335 "FanControllers", fanControllers, "FanZones", fanZones,
1336 "StepwiseControllers", stepwiseControllers, "Profile", profile))
1337 {
James Feist73df0db2019-03-25 15:29:35 -07001338 return;
1339 }
1340 configuration.emplace_back("PidControllers", std::move(pidControllers));
1341 configuration.emplace_back("FanControllers", std::move(fanControllers));
1342 configuration.emplace_back("FanZones", std::move(fanZones));
1343 configuration.emplace_back("StepwiseControllers",
1344 std::move(stepwiseControllers));
1345 }
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001346
1347 SetPIDValues(const SetPIDValues&) = delete;
1348 SetPIDValues(SetPIDValues&&) = delete;
1349 SetPIDValues& operator=(const SetPIDValues&) = delete;
1350 SetPIDValues& operator=(SetPIDValues&&) = delete;
1351
James Feist73df0db2019-03-25 15:29:35 -07001352 void run()
1353 {
1354 if (asyncResp->res.result() != boost::beast::http::status::ok)
1355 {
1356 return;
1357 }
1358
1359 std::shared_ptr<SetPIDValues> self = shared_from_this();
1360
1361 // todo(james): might make sense to do a mapper call here if this
1362 // interface gets more traction
1363 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001364 [self](const boost::system::error_code& ec,
Ed Tanous914e2d52022-01-07 11:38:34 -08001365 const dbus::utility::ManagedObjectType& mObj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001366 if (ec)
1367 {
1368 BMCWEB_LOG_ERROR << "Error communicating to Entity Manager";
1369 messages::internalError(self->asyncResp->res);
1370 return;
1371 }
1372 const std::array<const char*, 3> configurations = {
1373 pidConfigurationIface, pidZoneConfigurationIface,
1374 stepwiseConfigurationIface};
James Feiste69d9de2020-02-07 12:23:27 -08001375
Ed Tanous002d39b2022-05-31 08:59:27 -07001376 for (const auto& [path, object] : mObj)
1377 {
1378 for (const auto& [interface, _] : object)
James Feiste69d9de2020-02-07 12:23:27 -08001379 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001380 if (std::find(configurations.begin(), configurations.end(),
1381 interface) != configurations.end())
James Feiste69d9de2020-02-07 12:23:27 -08001382 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001383 self->objectCount++;
1384 break;
James Feiste69d9de2020-02-07 12:23:27 -08001385 }
James Feiste69d9de2020-02-07 12:23:27 -08001386 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001387 }
1388 self->managedObj = mObj;
James Feist73df0db2019-03-25 15:29:35 -07001389 },
Nan Zhouc106b672022-09-20 22:35:31 +00001390 "xyz.openbmc_project.EntityManager",
1391 "/xyz/openbmc_project/inventory", objectManagerIface,
James Feist73df0db2019-03-25 15:29:35 -07001392 "GetManagedObjects");
1393
1394 // at the same time get the profile information
George Liue99073f2022-12-09 11:06:16 +08001395 constexpr std::array<std::string_view, 1> thermalModeIfaces = {
1396 thermalModeIface};
1397 dbus::utility::getSubTree(
1398 "/", 0, thermalModeIfaces,
1399 [self](const boost::system::error_code& ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001400 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001401 if (ec || subtree.empty())
1402 {
1403 return;
1404 }
1405 if (subtree[0].second.empty())
1406 {
1407 // invalid mapper response, should never happen
1408 BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error";
1409 messages::internalError(self->asyncResp->res);
1410 return;
1411 }
1412
1413 const std::string& path = subtree[0].first;
1414 const std::string& owner = subtree[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001415 sdbusplus::asio::getAllProperties(
1416 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001417 [self, path, owner](const boost::system::error_code& ec2,
Ed Tanous002d39b2022-05-31 08:59:27 -07001418 const dbus::utility::DBusPropertiesMap& r) {
1419 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001420 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001421 BMCWEB_LOG_ERROR
1422 << "SetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001423 messages::internalError(self->asyncResp->res);
1424 return;
1425 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001426 const std::string* current = nullptr;
1427 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001428
1429 const bool success = sdbusplus::unpackPropertiesNoThrow(
1430 dbus_utils::UnpackErrorPrinter(), r, "Current", current,
1431 "Supported", supported);
1432
1433 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001434 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001435 messages::internalError(self->asyncResp->res);
1436 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001437 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001438
Ed Tanous002d39b2022-05-31 08:59:27 -07001439 if (current == nullptr || supported == nullptr)
1440 {
1441 BMCWEB_LOG_ERROR
1442 << "SetPIDValues: thermal mode iface invalid " << path;
1443 messages::internalError(self->asyncResp->res);
1444 return;
1445 }
1446 self->currentProfile = *current;
1447 self->supportedProfiles = *supported;
1448 self->profileConnection = owner;
1449 self->profilePath = path;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001450 });
George Liue99073f2022-12-09 11:06:16 +08001451 });
James Feist73df0db2019-03-25 15:29:35 -07001452 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001453 void pidSetDone()
James Feist73df0db2019-03-25 15:29:35 -07001454 {
1455 if (asyncResp->res.result() != boost::beast::http::status::ok)
1456 {
1457 return;
1458 }
zhanghch058d1b46d2021-04-01 11:18:24 +08001459 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001460 if (profile)
1461 {
1462 if (std::find(supportedProfiles.begin(), supportedProfiles.end(),
1463 *profile) == supportedProfiles.end())
1464 {
1465 messages::actionParameterUnknown(response->res, "Profile",
1466 *profile);
1467 return;
1468 }
1469 currentProfile = *profile;
1470 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001471 [response](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001472 if (ec)
1473 {
1474 BMCWEB_LOG_ERROR << "Error patching profile" << ec;
1475 messages::internalError(response->res);
1476 }
James Feist73df0db2019-03-25 15:29:35 -07001477 },
1478 profileConnection, profilePath,
1479 "org.freedesktop.DBus.Properties", "Set", thermalModeIface,
Ed Tanous168e20c2021-12-13 14:39:53 -08001480 "Current", dbus::utility::DbusVariantType(*profile));
James Feist73df0db2019-03-25 15:29:35 -07001481 }
1482
1483 for (auto& containerPair : configuration)
1484 {
1485 auto& container = containerPair.second;
1486 if (!container)
1487 {
1488 continue;
1489 }
James Feist6ee7f772020-02-06 16:25:27 -08001490 BMCWEB_LOG_DEBUG << *container;
1491
Ed Tanous02cad962022-06-30 16:50:15 -07001492 const std::string& type = containerPair.first;
James Feist73df0db2019-03-25 15:29:35 -07001493
1494 for (nlohmann::json::iterator it = container->begin();
Manojkiran Eda17a897d2020-09-12 15:31:58 +05301495 it != container->end(); ++it)
James Feist73df0db2019-03-25 15:29:35 -07001496 {
1497 const auto& name = it.key();
Potin Laicddbf3d2023-02-14 14:28:58 +08001498 std::string dbusObjName = name;
1499 std::replace(dbusObjName.begin(), dbusObjName.end(), ' ', '_');
James Feist6ee7f772020-02-06 16:25:27 -08001500 BMCWEB_LOG_DEBUG << "looking for " << name;
1501
Patrick Williams89492a12023-05-10 07:51:34 -05001502 auto pathItr = std::find_if(managedObj.begin(),
1503 managedObj.end(),
1504 [&dbusObjName](const auto& obj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001505 return boost::algorithm::ends_with(obj.first.str,
Potin Laicddbf3d2023-02-14 14:28:58 +08001506 "/" + dbusObjName);
Patrick Williams89492a12023-05-10 07:51:34 -05001507 });
Ed Tanousb9d36b42022-02-26 21:42:46 -08001508 dbus::utility::DBusPropertiesMap output;
James Feist73df0db2019-03-25 15:29:35 -07001509
1510 output.reserve(16); // The pid interface length
1511
1512 // determines if we're patching entity-manager or
1513 // creating a new object
1514 bool createNewObject = (pathItr == managedObj.end());
James Feist6ee7f772020-02-06 16:25:27 -08001515 BMCWEB_LOG_DEBUG << "Found = " << !createNewObject;
1516
James Feist73df0db2019-03-25 15:29:35 -07001517 std::string iface;
Ed Tanousea2b6702022-03-07 16:48:38 -08001518 if (!createNewObject)
James Feist73df0db2019-03-25 15:29:35 -07001519 {
Potin Lai8be2b5b2022-11-22 13:27:16 +08001520 bool findInterface = false;
Ed Tanousea2b6702022-03-07 16:48:38 -08001521 for (const auto& interface : pathItr->second)
James Feist73df0db2019-03-25 15:29:35 -07001522 {
Ed Tanousea2b6702022-03-07 16:48:38 -08001523 if (interface.first == pidConfigurationIface)
1524 {
1525 if (type == "PidControllers" ||
1526 type == "FanControllers")
1527 {
1528 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001529 findInterface = true;
1530 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001531 }
1532 }
1533 else if (interface.first == pidZoneConfigurationIface)
1534 {
1535 if (type == "FanZones")
1536 {
1537 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001538 findInterface = true;
1539 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001540 }
1541 }
1542 else if (interface.first == stepwiseConfigurationIface)
1543 {
1544 if (type == "StepwiseControllers")
1545 {
1546 iface = stepwiseConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001547 findInterface = true;
1548 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001549 }
1550 }
James Feist73df0db2019-03-25 15:29:35 -07001551 }
Potin Lai8be2b5b2022-11-22 13:27:16 +08001552
1553 // create new object if interface not found
1554 if (!findInterface)
1555 {
1556 createNewObject = true;
1557 }
James Feist73df0db2019-03-25 15:29:35 -07001558 }
James Feist6ee7f772020-02-06 16:25:27 -08001559
1560 if (createNewObject && it.value() == nullptr)
1561 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -05001562 // can't delete a non-existent object
Ed Tanous1668ce62022-02-07 23:44:31 -08001563 messages::propertyValueNotInList(response->res,
1564 it.value().dump(), name);
James Feist6ee7f772020-02-06 16:25:27 -08001565 continue;
1566 }
1567
1568 std::string path;
1569 if (pathItr != managedObj.end())
1570 {
1571 path = pathItr->first.str;
1572 }
1573
James Feist73df0db2019-03-25 15:29:35 -07001574 BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n";
James Feiste69d9de2020-02-07 12:23:27 -08001575
1576 // arbitrary limit to avoid attacks
1577 constexpr const size_t controllerLimit = 500;
James Feist14b0b8d2020-02-12 11:52:07 -08001578 if (createNewObject && objectCount >= controllerLimit)
James Feiste69d9de2020-02-07 12:23:27 -08001579 {
1580 messages::resourceExhaustion(response->res, type);
1581 continue;
1582 }
Ed Tanousa170f272022-06-30 21:53:27 -07001583 std::string escaped = name;
1584 std::replace(escaped.begin(), escaped.end(), '_', ' ');
1585 output.emplace_back("Name", escaped);
James Feist73df0db2019-03-25 15:29:35 -07001586
1587 std::string chassis;
1588 CreatePIDRet ret = createPidInterface(
James Feist6ee7f772020-02-06 16:25:27 -08001589 response, type, it, path, managedObj, createNewObject,
1590 output, chassis, currentProfile);
James Feist73df0db2019-03-25 15:29:35 -07001591 if (ret == CreatePIDRet::fail)
1592 {
1593 return;
1594 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001595 if (ret == CreatePIDRet::del)
James Feist73df0db2019-03-25 15:29:35 -07001596 {
1597 continue;
1598 }
1599
1600 if (!createNewObject)
1601 {
1602 for (const auto& property : output)
1603 {
1604 crow::connections::systemBus->async_method_call(
1605 [response,
1606 propertyName{std::string(property.first)}](
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001607 const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001608 if (ec)
1609 {
1610 BMCWEB_LOG_ERROR << "Error patching "
1611 << propertyName << ": " << ec;
1612 messages::internalError(response->res);
1613 return;
1614 }
1615 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001616 },
James Feist6ee7f772020-02-06 16:25:27 -08001617 "xyz.openbmc_project.EntityManager", path,
James Feist73df0db2019-03-25 15:29:35 -07001618 "org.freedesktop.DBus.Properties", "Set", iface,
1619 property.first, property.second);
1620 }
1621 }
1622 else
1623 {
1624 if (chassis.empty())
1625 {
1626 BMCWEB_LOG_ERROR << "Failed to get chassis from config";
Ed Tanousace85d62021-10-26 12:45:59 -07001627 messages::internalError(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001628 return;
1629 }
1630
1631 bool foundChassis = false;
1632 for (const auto& obj : managedObj)
1633 {
1634 if (boost::algorithm::ends_with(obj.first.str, chassis))
1635 {
1636 chassis = obj.first.str;
1637 foundChassis = true;
1638 break;
1639 }
1640 }
1641 if (!foundChassis)
1642 {
1643 BMCWEB_LOG_ERROR << "Failed to find chassis on dbus";
1644 messages::resourceMissingAtURI(
Ed Tanousace85d62021-10-26 12:45:59 -07001645 response->res,
1646 crow::utility::urlFromPieces("redfish", "v1",
1647 "Chassis", chassis));
James Feist73df0db2019-03-25 15:29:35 -07001648 return;
1649 }
1650
1651 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001652 [response](const boost::system::error_code& ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001653 if (ec)
1654 {
1655 BMCWEB_LOG_ERROR << "Error Adding Pid Object "
1656 << ec;
1657 messages::internalError(response->res);
1658 return;
1659 }
1660 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001661 },
1662 "xyz.openbmc_project.EntityManager", chassis,
1663 "xyz.openbmc_project.AddObject", "AddObject", output);
1664 }
1665 }
1666 }
1667 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001668
1669 ~SetPIDValues()
1670 {
1671 try
1672 {
1673 pidSetDone();
1674 }
1675 catch (...)
1676 {
1677 BMCWEB_LOG_CRITICAL << "pidSetDone threw exception";
1678 }
1679 }
1680
zhanghch058d1b46d2021-04-01 11:18:24 +08001681 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001682 std::vector<std::pair<std::string, std::optional<nlohmann::json>>>
1683 configuration;
1684 std::optional<std::string> profile;
1685 dbus::utility::ManagedObjectType managedObj;
1686 std::vector<std::string> supportedProfiles;
1687 std::string currentProfile;
1688 std::string profileConnection;
1689 std::string profilePath;
James Feist14b0b8d2020-02-12 11:52:07 -08001690 size_t objectCount = 0;
James Feist73df0db2019-03-25 15:29:35 -07001691};
James Feist83ff9ab2018-08-31 10:18:24 -07001692
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001693/**
1694 * @brief Retrieves BMC manager location data over DBus
1695 *
1696 * @param[in] aResp Shared pointer for completing asynchronous calls
1697 * @param[in] connectionName - service name
1698 * @param[in] path - object path
1699 * @return none
1700 */
zhanghch058d1b46d2021-04-01 11:18:24 +08001701inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001702 const std::string& connectionName,
1703 const std::string& path)
1704{
1705 BMCWEB_LOG_DEBUG << "Get BMC manager Location data.";
1706
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001707 sdbusplus::asio::getProperty<std::string>(
1708 *crow::connections::systemBus, connectionName, path,
1709 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001710 [aResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001711 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001712 if (ec)
1713 {
1714 BMCWEB_LOG_DEBUG << "DBUS response error for "
1715 "Location";
1716 messages::internalError(aResp->res);
1717 return;
1718 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001719
Ed Tanous002d39b2022-05-31 08:59:27 -07001720 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
1721 property;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001722 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001723}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001724// avoid name collision systems.hpp
1725inline void
1726 managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001727{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001728 BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time";
Ed Tanous52cc1122020-07-18 13:51:21 -07001729
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001730 sdbusplus::asio::getProperty<uint64_t>(
1731 *crow::connections::systemBus, "xyz.openbmc_project.State.BMC",
1732 "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC",
1733 "LastRebootTime",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001734 [aResp](const boost::system::error_code& ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001735 const uint64_t lastResetTime) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001736 if (ec)
1737 {
1738 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1739 return;
1740 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001741
Ed Tanous002d39b2022-05-31 08:59:27 -07001742 // LastRebootTime is epoch time, in milliseconds
1743 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
1744 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001745
Ed Tanous002d39b2022-05-31 08:59:27 -07001746 // Convert to ISO 8601 standard
1747 aResp->res.jsonValue["LastResetTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001748 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001749 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001750}
1751
1752/**
1753 * @brief Set the running firmware image
1754 *
1755 * @param[i,o] aResp - Async response object
1756 * @param[i] runningFirmwareTarget - Image to make the running image
1757 *
1758 * @return void
1759 */
1760inline void
1761 setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1762 const std::string& runningFirmwareTarget)
1763{
1764 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
1765 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
1766 if (idPos == std::string::npos)
1767 {
1768 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1769 "@odata.id");
1770 BMCWEB_LOG_DEBUG << "Can't parse firmware ID!";
1771 return;
1772 }
1773 idPos++;
1774 if (idPos >= runningFirmwareTarget.size())
1775 {
1776 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1777 "@odata.id");
1778 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1779 return;
1780 }
1781 std::string firmwareId = runningFirmwareTarget.substr(idPos);
1782
1783 // Make sure the image is valid before setting priority
1784 crow::connections::systemBus->async_method_call(
Ed Tanous711ac7a2021-12-20 09:34:41 -08001785 [aResp, firmwareId,
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001786 runningFirmwareTarget](const boost::system::error_code& ec,
Ed Tanous711ac7a2021-12-20 09:34:41 -08001787 dbus::utility::ManagedObjectType& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001788 if (ec)
1789 {
1790 BMCWEB_LOG_DEBUG << "D-Bus response error getting objects.";
1791 messages::internalError(aResp->res);
1792 return;
1793 }
1794
1795 if (subtree.empty())
1796 {
1797 BMCWEB_LOG_DEBUG << "Can't find image!";
1798 messages::internalError(aResp->res);
1799 return;
1800 }
1801
1802 bool foundImage = false;
Ed Tanous02cad962022-06-30 16:50:15 -07001803 for (const auto& object : subtree)
Ed Tanous002d39b2022-05-31 08:59:27 -07001804 {
1805 const std::string& path =
1806 static_cast<const std::string&>(object.first);
1807 std::size_t idPos2 = path.rfind('/');
1808
1809 if (idPos2 == std::string::npos)
1810 {
1811 continue;
1812 }
1813
1814 idPos2++;
1815 if (idPos2 >= path.size())
1816 {
1817 continue;
1818 }
1819
1820 if (path.substr(idPos2) == firmwareId)
1821 {
1822 foundImage = true;
1823 break;
1824 }
1825 }
1826
1827 if (!foundImage)
1828 {
1829 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1830 "@odata.id");
1831 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1832 return;
1833 }
1834
1835 BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId
1836 << " to priority 0.";
1837
1838 // Only support Immediate
1839 // An addition could be a Redfish Setting like
1840 // ActiveSoftwareImageApplyTime and support OnReset
1841 crow::connections::systemBus->async_method_call(
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001842 [aResp](const boost::system::error_code& ec2) {
Ed Tanous8a592812022-06-04 09:06:59 -07001843 if (ec2)
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001844 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001845 BMCWEB_LOG_DEBUG << "D-Bus response error setting.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001846 messages::internalError(aResp->res);
1847 return;
1848 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001849 doBMCGracefulRestart(aResp);
1850 },
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001851
Ed Tanous002d39b2022-05-31 08:59:27 -07001852 "xyz.openbmc_project.Software.BMC.Updater",
1853 "/xyz/openbmc_project/software/" + firmwareId,
1854 "org.freedesktop.DBus.Properties", "Set",
1855 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
1856 dbus::utility::DbusVariantType(static_cast<uint8_t>(0)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001857 },
1858 "xyz.openbmc_project.Software.BMC.Updater",
1859 "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager",
1860 "GetManagedObjects");
1861}
Ed Tanous1abe55e2018-09-05 08:30:59 -07001862
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001863inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp,
1864 std::string datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001865{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001866 BMCWEB_LOG_DEBUG << "Set date time: " << datetime;
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001867
Ed Tanousc2e32002023-01-07 22:05:08 -08001868 std::optional<redfish::time_utils::usSinceEpoch> us =
1869 redfish::time_utils::dateStringToEpoch(datetime);
1870 if (!us)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001871 {
1872 messages::propertyValueFormatError(aResp->res, datetime, "DateTime");
1873 return;
1874 }
Ed Tanousc2e32002023-01-07 22:05:08 -08001875 crow::connections::systemBus->async_method_call(
1876 [aResp{std::move(aResp)},
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08001877 datetime{std::move(datetime)}](const boost::system::error_code& ec) {
Ed Tanousc2e32002023-01-07 22:05:08 -08001878 if (ec)
1879 {
1880 BMCWEB_LOG_DEBUG << "Failed to set elapsed time. "
1881 "DBUS response error "
1882 << ec;
1883 messages::internalError(aResp->res);
1884 return;
1885 }
1886 aResp->res.jsonValue["DateTime"] = datetime;
1887 },
1888 "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc",
1889 "org.freedesktop.DBus.Properties", "Set",
1890 "xyz.openbmc_project.Time.EpochTime", "Elapsed",
1891 dbus::utility::DbusVariantType(us->count()));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001892}
1893
1894inline void requestRoutesManager(App& app)
1895{
1896 std::string uuid = persistent_data::getConfig().systemUuid;
1897
1898 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07001899 .privileges(redfish::privileges::getManager)
Ed Tanous002d39b2022-05-31 08:59:27 -07001900 .methods(boost::beast::http::verb::get)(
1901 [&app, uuid](const crow::Request& req,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001902 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001903 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001904 {
1905 return;
1906 }
1907 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc";
Sui Chena51fc2d2022-07-14 17:21:53 -07001908 asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager";
Ed Tanous002d39b2022-05-31 08:59:27 -07001909 asyncResp->res.jsonValue["Id"] = "bmc";
1910 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
1911 asyncResp->res.jsonValue["Description"] =
1912 "Baseboard Management Controller";
1913 asyncResp->res.jsonValue["PowerState"] = "On";
1914 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
1915 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
Ed Tanous14766872022-03-15 10:44:42 -07001916
Ed Tanous002d39b2022-05-31 08:59:27 -07001917 asyncResp->res.jsonValue["ManagerType"] = "BMC";
1918 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
1919 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
1920 asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001921
Ed Tanous002d39b2022-05-31 08:59:27 -07001922 asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
1923 "/redfish/v1/Managers/bmc/LogServices";
1924 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
1925 "/redfish/v1/Managers/bmc/NetworkProtocol";
1926 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
1927 "/redfish/v1/Managers/bmc/EthernetInterfaces";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001928
1929#ifdef BMCWEB_ENABLE_VM_NBDPROXY
Ed Tanous002d39b2022-05-31 08:59:27 -07001930 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
1931 "/redfish/v1/Managers/bmc/VirtualMedia";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001932#endif // BMCWEB_ENABLE_VM_NBDPROXY
1933
Ed Tanous002d39b2022-05-31 08:59:27 -07001934 // default oem data
1935 nlohmann::json& oem = asyncResp->res.jsonValue["Oem"];
1936 nlohmann::json& oemOpenbmc = oem["OpenBmc"];
1937 oem["@odata.type"] = "#OemManager.Oem";
1938 oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem";
1939 oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc";
1940 oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc";
Ed Tanous14766872022-03-15 10:44:42 -07001941
Ed Tanous002d39b2022-05-31 08:59:27 -07001942 nlohmann::json::object_t certificates;
1943 certificates["@odata.id"] =
1944 "/redfish/v1/Managers/bmc/Truststore/Certificates";
1945 oemOpenbmc["Certificates"] = std::move(certificates);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001946
Ed Tanous002d39b2022-05-31 08:59:27 -07001947 // Manager.Reset (an action) can be many values, OpenBMC only
1948 // supports BMC reboot.
1949 nlohmann::json& managerReset =
1950 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
1951 managerReset["target"] =
1952 "/redfish/v1/Managers/bmc/Actions/Manager.Reset";
1953 managerReset["@Redfish.ActionInfo"] =
1954 "/redfish/v1/Managers/bmc/ResetActionInfo";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001955
Ed Tanous002d39b2022-05-31 08:59:27 -07001956 // ResetToDefaults (Factory Reset) has values like
1957 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
1958 // on OpenBMC
1959 nlohmann::json& resetToDefaults =
1960 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
1961 resetToDefaults["target"] =
1962 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults";
Ed Tanous613dabe2022-07-09 11:17:36 -07001963 resetToDefaults["ResetType@Redfish.AllowableValues"] =
1964 nlohmann::json::array_t({"ResetAll"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001965
Ed Tanous002d39b2022-05-31 08:59:27 -07001966 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07001967 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05301968
Ed Tanous002d39b2022-05-31 08:59:27 -07001969 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
1970 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
1971 redfishDateTimeOffset.second;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001972
Ed Tanous002d39b2022-05-31 08:59:27 -07001973 // TODO (Gunnar): Remove these one day since moved to ComputerSystem
1974 // Still used by OCP profiles
1975 // https://github.com/opencomputeproject/OCP-Profiles/issues/23
1976 // Fill in SerialConsole info
1977 asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true;
1978 asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
Ed Tanous613dabe2022-07-09 11:17:36 -07001979 asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] =
1980 nlohmann::json::array_t({"IPMI", "SSH"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001981#ifdef BMCWEB_ENABLE_KVM
Ed Tanous002d39b2022-05-31 08:59:27 -07001982 // Fill in GraphicalConsole info
1983 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
1984 asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
1985 4;
Ed Tanous613dabe2022-07-09 11:17:36 -07001986 asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
1987 nlohmann::json::array_t({"KVMIP"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001988#endif // BMCWEB_ENABLE_KVM
1989
Ed Tanous002d39b2022-05-31 08:59:27 -07001990 asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
Ed Tanous14766872022-03-15 10:44:42 -07001991
Ed Tanous002d39b2022-05-31 08:59:27 -07001992 nlohmann::json::array_t managerForServers;
1993 nlohmann::json::object_t manager;
1994 manager["@odata.id"] = "/redfish/v1/Systems/system";
Patrick Williamsad539542023-05-12 10:10:08 -05001995 managerForServers.emplace_back(std::move(manager));
Ed Tanous002d39b2022-05-31 08:59:27 -07001996
1997 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
1998 std::move(managerForServers);
1999
2000 auto health = std::make_shared<HealthPopulate>(asyncResp);
2001 health->isManagersHealth = true;
2002 health->populate();
2003
Willy Tueee00132022-06-14 14:53:17 -07002004 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
Ed Tanous002d39b2022-05-31 08:59:27 -07002005 "FirmwareVersion", true);
2006
2007 managerGetLastResetTime(asyncResp);
2008
Sui Chena51fc2d2022-07-14 17:21:53 -07002009 // ManagerDiagnosticData is added for all BMCs.
2010 nlohmann::json& managerDiagnosticData =
2011 asyncResp->res.jsonValue["ManagerDiagnosticData"];
2012 managerDiagnosticData["@odata.id"] =
2013 "/redfish/v1/Managers/bmc/ManagerDiagnosticData";
2014
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002015#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002016 auto pids = std::make_shared<GetPIDValues>(asyncResp);
2017 pids->run();
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002018#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002019
2020 getMainChassisId(asyncResp,
2021 [](const std::string& chassisId,
2022 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
2023 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
2024 nlohmann::json::array_t managerForChassis;
Ed Tanous8a592812022-06-04 09:06:59 -07002025 nlohmann::json::object_t managerObj;
Willy Tueddfc432022-09-26 16:46:38 +00002026 boost::urls::url chassiUrl = crow::utility::urlFromPieces(
2027 "redfish", "v1", "Chassis", chassisId);
2028 managerObj["@odata.id"] = chassiUrl;
Patrick Williamsad539542023-05-12 10:10:08 -05002029 managerForChassis.emplace_back(std::move(managerObj));
Ed Tanous002d39b2022-05-31 08:59:27 -07002030 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
2031 std::move(managerForChassis);
2032 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
Willy Tueddfc432022-09-26 16:46:38 +00002033 chassiUrl;
Ed Tanous002d39b2022-05-31 08:59:27 -07002034 });
Ed Tanous14766872022-03-15 10:44:42 -07002035
Ed Tanous002d39b2022-05-31 08:59:27 -07002036 static bool started = false;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002037
Ed Tanous002d39b2022-05-31 08:59:27 -07002038 if (!started)
2039 {
2040 sdbusplus::asio::getProperty<double>(
2041 *crow::connections::systemBus, "org.freedesktop.systemd1",
2042 "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
2043 "Progress",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002044 [asyncResp](const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07002045 const double& val) {
2046 if (ec)
2047 {
2048 BMCWEB_LOG_ERROR << "Error while getting progress";
2049 messages::internalError(asyncResp->res);
2050 return;
2051 }
2052 if (val < 1.0)
2053 {
2054 asyncResp->res.jsonValue["Status"]["State"] = "Starting";
2055 started = true;
2056 }
2057 });
2058 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002059
George Liue99073f2022-12-09 11:06:16 +08002060 constexpr std::array<std::string_view, 1> interfaces = {
2061 "xyz.openbmc_project.Inventory.Item.Bmc"};
2062 dbus::utility::getSubTree(
2063 "/xyz/openbmc_project/inventory", 0, interfaces,
Ed Tanous002d39b2022-05-31 08:59:27 -07002064 [asyncResp](
George Liue99073f2022-12-09 11:06:16 +08002065 const boost::system::error_code& ec,
Ed Tanous002d39b2022-05-31 08:59:27 -07002066 const dbus::utility::MapperGetSubTreeResponse& subtree) {
2067 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002068 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002069 BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec;
2070 return;
2071 }
2072 if (subtree.empty())
2073 {
2074 BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!";
2075 return;
2076 }
2077 // Assume only 1 bmc D-Bus object
2078 // Throw an error if there is more than 1
2079 if (subtree.size() > 1)
2080 {
2081 BMCWEB_LOG_DEBUG << "Found more than 1 bmc D-Bus object!";
2082 messages::internalError(asyncResp->res);
2083 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002084 }
2085
Ed Tanous002d39b2022-05-31 08:59:27 -07002086 if (subtree[0].first.empty() || subtree[0].second.size() != 1)
2087 {
2088 BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!";
2089 messages::internalError(asyncResp->res);
2090 return;
2091 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002092
Ed Tanous002d39b2022-05-31 08:59:27 -07002093 const std::string& path = subtree[0].first;
2094 const std::string& connectionName = subtree[0].second[0].first;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002095
Ed Tanous002d39b2022-05-31 08:59:27 -07002096 for (const auto& interfaceName : subtree[0].second[0].second)
2097 {
2098 if (interfaceName ==
2099 "xyz.openbmc_project.Inventory.Decorator.Asset")
2100 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002101 sdbusplus::asio::getAllProperties(
2102 *crow::connections::systemBus, connectionName, path,
2103 "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanous5e7e2dc2023-02-16 10:37:01 -08002104 [asyncResp](const boost::system::error_code& ec2,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002105 const dbus::utility::DBusPropertiesMap&
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002106 propertiesList) {
Ed Tanous8a592812022-06-04 09:06:59 -07002107 if (ec2)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002108 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002109 BMCWEB_LOG_DEBUG << "Can't get bmc asset!";
2110 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002111 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002112
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002113 const std::string* partNumber = nullptr;
2114 const std::string* serialNumber = nullptr;
2115 const std::string* manufacturer = nullptr;
2116 const std::string* model = nullptr;
2117 const std::string* sparePartNumber = nullptr;
2118
2119 const bool success = sdbusplus::unpackPropertiesNoThrow(
2120 dbus_utils::UnpackErrorPrinter(), propertiesList,
2121 "PartNumber", partNumber, "SerialNumber",
2122 serialNumber, "Manufacturer", manufacturer, "Model",
2123 model, "SparePartNumber", sparePartNumber);
2124
2125 if (!success)
2126 {
2127 messages::internalError(asyncResp->res);
2128 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002129 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002130
2131 if (partNumber != nullptr)
2132 {
2133 asyncResp->res.jsonValue["PartNumber"] =
2134 *partNumber;
2135 }
2136
2137 if (serialNumber != nullptr)
2138 {
2139 asyncResp->res.jsonValue["SerialNumber"] =
2140 *serialNumber;
2141 }
2142
2143 if (manufacturer != nullptr)
2144 {
2145 asyncResp->res.jsonValue["Manufacturer"] =
2146 *manufacturer;
2147 }
2148
2149 if (model != nullptr)
2150 {
2151 asyncResp->res.jsonValue["Model"] = *model;
2152 }
2153
2154 if (sparePartNumber != nullptr)
2155 {
2156 asyncResp->res.jsonValue["SparePartNumber"] =
2157 *sparePartNumber;
2158 }
2159 });
Ed Tanous002d39b2022-05-31 08:59:27 -07002160 }
2161 else if (interfaceName ==
2162 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
2163 {
2164 getLocation(asyncResp, connectionName, path);
2165 }
2166 }
George Liue99073f2022-12-09 11:06:16 +08002167 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002168 });
2169
2170 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07002171 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002172 .methods(boost::beast::http::verb::patch)(
2173 [&app](const crow::Request& req,
2174 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002175 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002176 {
2177 return;
2178 }
2179 std::optional<nlohmann::json> oem;
2180 std::optional<nlohmann::json> links;
2181 std::optional<std::string> datetime;
2182
2183 if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem,
2184 "DateTime", datetime, "Links", links))
2185 {
2186 return;
2187 }
2188
2189 if (oem)
2190 {
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002191#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002192 std::optional<nlohmann::json> openbmc;
2193 if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc",
2194 openbmc))
2195 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002196 return;
2197 }
2198 if (openbmc)
2199 {
2200 std::optional<nlohmann::json> fan;
2201 if (!redfish::json_util::readJson(*openbmc, asyncResp->res,
2202 "Fan", fan))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002203 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002204 return;
2205 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002206 if (fan)
2207 {
2208 auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan);
2209 pid->run();
2210 }
2211 }
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002212#else
2213 messages::propertyUnknown(asyncResp->res, "Oem");
2214 return;
2215#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002216 }
2217 if (links)
2218 {
2219 std::optional<nlohmann::json> activeSoftwareImage;
2220 if (!redfish::json_util::readJson(*links, asyncResp->res,
2221 "ActiveSoftwareImage",
2222 activeSoftwareImage))
2223 {
2224 return;
2225 }
2226 if (activeSoftwareImage)
2227 {
2228 std::optional<std::string> odataId;
2229 if (!json_util::readJson(*activeSoftwareImage, asyncResp->res,
2230 "@odata.id", odataId))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002231 {
Ed Tanous45ca1b82022-03-25 13:07:27 -07002232 return;
2233 }
2234
Ed Tanous002d39b2022-05-31 08:59:27 -07002235 if (odataId)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002236 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002237 setActiveFirmwareImage(asyncResp, *odataId);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002238 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002239 }
2240 }
2241 if (datetime)
2242 {
2243 setDateTime(asyncResp, std::move(*datetime));
2244 }
2245 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002246}
2247
2248inline void requestRoutesManagerCollection(App& app)
2249{
2250 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -07002251 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002252 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002253 [&app](const crow::Request& req,
2254 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002255 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002256 {
2257 return;
2258 }
2259 // Collections don't include the static data added by SubRoute
2260 // because it has a duplicate entry for members
2261 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
2262 asyncResp->res.jsonValue["@odata.type"] =
2263 "#ManagerCollection.ManagerCollection";
2264 asyncResp->res.jsonValue["Name"] = "Manager Collection";
2265 asyncResp->res.jsonValue["Members@odata.count"] = 1;
2266 nlohmann::json::array_t members;
2267 nlohmann::json& bmc = members.emplace_back();
2268 bmc["@odata.id"] = "/redfish/v1/Managers/bmc";
2269 asyncResp->res.jsonValue["Members"] = std::move(members);
2270 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002271}
Ed Tanous1abe55e2018-09-05 08:30:59 -07002272} // namespace redfish