blob: 74008cb40ad225d9f265984ffd0507fedee603da [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
Santosh Puranikaf5d60582019-03-20 18:16:36 +053030#include <boost/date_time.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>
Gunnar Mills4bfefa72020-07-30 13:54:29 -050035#include <cstdint>
Gunnar Mills1214b7e2020-06-04 10:11:30 -050036#include <memory>
37#include <sstream>
Ed Tanousabf2add2019-01-22 16:40:12 -080038#include <variant>
James Feist5b4aa862018-08-16 14:07:01 -070039
Ed Tanous1abe55e2018-09-05 08:30:59 -070040namespace redfish
41{
Jennifer Leeed5befb2018-08-10 11:29:45 -070042
43/**
Gunnar Mills2a5c4402020-05-19 09:07:24 -050044 * Function reboots the BMC.
45 *
46 * @param[in] asyncResp - Shared pointer for completing asynchronous calls
Jennifer Leeed5befb2018-08-10 11:29:45 -070047 */
zhanghch058d1b46d2021-04-01 11:18:24 +080048inline void
49 doBMCGracefulRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Gunnar Mills2a5c4402020-05-19 09:07:24 -050050{
51 const char* processName = "xyz.openbmc_project.State.BMC";
52 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
53 const char* interfaceName = "xyz.openbmc_project.State.BMC";
54 const std::string& propertyValue =
55 "xyz.openbmc_project.State.BMC.Transition.Reboot";
56 const char* destProperty = "RequestedBMCTransition";
57
58 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080059 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050060
61 crow::connections::systemBus->async_method_call(
62 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070063 // Use "Set" method to set the property value.
64 if (ec)
65 {
66 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
67 messages::internalError(asyncResp->res);
68 return;
69 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -050070
Ed Tanous002d39b2022-05-31 08:59:27 -070071 messages::success(asyncResp->res);
Gunnar Mills2a5c4402020-05-19 09:07:24 -050072 },
73 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
74 interfaceName, destProperty, dbusPropertyValue);
75}
76
zhanghch058d1b46d2021-04-01 11:18:24 +080077inline void
78 doBMCForceRestart(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000079{
80 const char* processName = "xyz.openbmc_project.State.BMC";
81 const char* objectPath = "/xyz/openbmc_project/state/bmc0";
82 const char* interfaceName = "xyz.openbmc_project.State.BMC";
83 const std::string& propertyValue =
84 "xyz.openbmc_project.State.BMC.Transition.HardReboot";
85 const char* destProperty = "RequestedBMCTransition";
86
87 // Create the D-Bus variant for D-Bus call.
Ed Tanous168e20c2021-12-13 14:39:53 -080088 dbus::utility::DbusVariantType dbusPropertyValue(propertyValue);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000089
90 crow::connections::systemBus->async_method_call(
91 [asyncResp](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -070092 // Use "Set" method to set the property value.
93 if (ec)
94 {
95 BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " << ec;
96 messages::internalError(asyncResp->res);
97 return;
98 }
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +000099
Ed Tanous002d39b2022-05-31 08:59:27 -0700100 messages::success(asyncResp->res);
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000101 },
102 processName, objectPath, "org.freedesktop.DBus.Properties", "Set",
103 interfaceName, destProperty, dbusPropertyValue);
104}
105
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500106/**
107 * ManagerResetAction class supports the POST method for the Reset (reboot)
108 * action.
109 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700110inline void requestRoutesManagerResetAction(App& app)
Jennifer Leeed5befb2018-08-10 11:29:45 -0700111{
Jennifer Leeed5befb2018-08-10 11:29:45 -0700112 /**
Jennifer Leeed5befb2018-08-10 11:29:45 -0700113 * Function handles POST method request.
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500114 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus.
Jayaprakash Mutyalaf92af382020-06-16 23:29:41 +0000115 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart".
Jennifer Leeed5befb2018-08-10 11:29:45 -0700116 */
Jennifer Leeed5befb2018-08-10 11:29:45 -0700117
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700118 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/Actions/Manager.Reset/")
Ed Tanoused398212021-06-09 17:05:54 -0700119 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700120 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700121 [&app](const crow::Request& req,
122 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000123 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700124 {
125 return;
126 }
127 BMCWEB_LOG_DEBUG << "Post Manager Reset.";
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500128
Ed Tanous002d39b2022-05-31 08:59:27 -0700129 std::string resetType;
Jennifer Leeed5befb2018-08-10 11:29:45 -0700130
Ed Tanous002d39b2022-05-31 08:59:27 -0700131 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType",
132 resetType))
133 {
134 return;
135 }
Gunnar Mills2a5c4402020-05-19 09:07:24 -0500136
Ed Tanous002d39b2022-05-31 08:59:27 -0700137 if (resetType == "GracefulRestart")
138 {
139 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
140 doBMCGracefulRestart(asyncResp);
141 return;
142 }
143 if (resetType == "ForceRestart")
144 {
145 BMCWEB_LOG_DEBUG << "Proceeding with " << resetType;
146 doBMCForceRestart(asyncResp);
147 return;
148 }
149 BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: "
150 << resetType;
151 messages::actionParameterNotSupported(asyncResp->res, resetType,
152 "ResetType");
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700153
Ed Tanous002d39b2022-05-31 08:59:27 -0700154 return;
155 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700156}
Jennifer Leeed5befb2018-08-10 11:29:45 -0700157
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500158/**
159 * ManagerResetToDefaultsAction class supports POST method for factory reset
160 * action.
161 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700162inline void requestRoutesManagerResetToDefaultsAction(App& app)
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500163{
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500164
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500165 /**
166 * Function handles ResetToDefaults POST method request.
167 *
168 * Analyzes POST body message and factory resets BMC by calling
169 * BMC code updater factory reset followed by a BMC reboot.
170 *
171 * BMC code updater factory reset wipes the whole BMC read-write
172 * filesystem which includes things like the network settings.
173 *
174 * OpenBMC only supports ResetToDefaultsType "ResetAll".
175 */
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500176
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700177 BMCWEB_ROUTE(app,
178 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults/")
Ed Tanoused398212021-06-09 17:05:54 -0700179 .privileges(redfish::privileges::postManager)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700180 .methods(boost::beast::http::verb::post)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700181 [&app](const crow::Request& req,
182 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000183 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700184 {
185 return;
186 }
187 BMCWEB_LOG_DEBUG << "Post ResetToDefaults.";
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500188
Ed Tanous002d39b2022-05-31 08:59:27 -0700189 std::string resetType;
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500190
Ed Tanous002d39b2022-05-31 08:59:27 -0700191 if (!json_util::readJsonAction(req, asyncResp->res,
192 "ResetToDefaultsType", resetType))
193 {
194 BMCWEB_LOG_DEBUG << "Missing property ResetToDefaultsType.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700195
Ed Tanous002d39b2022-05-31 08:59:27 -0700196 messages::actionParameterMissing(asyncResp->res, "ResetToDefaults",
197 "ResetToDefaultsType");
198 return;
199 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700200
Ed Tanous002d39b2022-05-31 08:59:27 -0700201 if (resetType != "ResetAll")
202 {
203 BMCWEB_LOG_DEBUG
204 << "Invalid property value for ResetToDefaultsType: "
205 << resetType;
206 messages::actionParameterNotSupported(asyncResp->res, resetType,
207 "ResetToDefaultsType");
208 return;
209 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700210
Ed Tanous002d39b2022-05-31 08:59:27 -0700211 crow::connections::systemBus->async_method_call(
212 [asyncResp](const boost::system::error_code ec) {
213 if (ec)
214 {
215 BMCWEB_LOG_DEBUG << "Failed to ResetToDefaults: " << ec;
216 messages::internalError(asyncResp->res);
217 return;
218 }
219 // Factory Reset doesn't actually happen until a reboot
220 // Can't erase what the BMC is running on
221 doBMCGracefulRestart(asyncResp);
222 },
223 "xyz.openbmc_project.Software.BMC.Updater",
224 "/xyz/openbmc_project/software",
225 "xyz.openbmc_project.Common.FactoryReset", "Reset");
226 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700227}
Gunnar Mills3e40fc72020-05-19 19:18:17 -0500228
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530229/**
230 * ManagerResetActionInfo derived class for delivering Manager
231 * ResetType AllowableValues using ResetInfo schema.
232 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700233inline void requestRoutesManagerResetActionInfo(App& app)
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530234{
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530235 /**
236 * Functions triggers appropriate requests on DBus
237 */
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700238
239 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/ResetActionInfo/")
Ed Tanoused398212021-06-09 17:05:54 -0700240 .privileges(redfish::privileges::getActionInfo)
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700241 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -0700242 [&app](const crow::Request& req,
243 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +0000244 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -0700245 {
246 return;
247 }
Ed Tanous14766872022-03-15 10:44:42 -0700248
Ed Tanous002d39b2022-05-31 08:59:27 -0700249 asyncResp->res.jsonValue["@odata.type"] =
250 "#ActionInfo.v1_1_2.ActionInfo";
251 asyncResp->res.jsonValue["@odata.id"] =
252 "/redfish/v1/Managers/bmc/ResetActionInfo";
253 asyncResp->res.jsonValue["Name"] = "Reset Action Info";
254 asyncResp->res.jsonValue["Id"] = "ResetActionInfo";
255 nlohmann::json::object_t parameter;
256 parameter["Name"] = "ResetType";
257 parameter["Required"] = true;
258 parameter["DataType"] = "String";
Ed Tanous14766872022-03-15 10:44:42 -0700259
Ed Tanous002d39b2022-05-31 08:59:27 -0700260 nlohmann::json::array_t allowableValues;
261 allowableValues.push_back("GracefulRestart");
262 allowableValues.push_back("ForceRestart");
263 parameter["AllowableValues"] = std::move(allowableValues);
Ed Tanous14766872022-03-15 10:44:42 -0700264
Ed Tanous002d39b2022-05-31 08:59:27 -0700265 nlohmann::json::array_t parameters;
266 parameters.push_back(std::move(parameter));
Ed Tanous14766872022-03-15 10:44:42 -0700267
Ed Tanous002d39b2022-05-31 08:59:27 -0700268 asyncResp->res.jsonValue["Parameters"] = std::move(parameters);
269 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -0700270}
AppaRao Puli1cb1a9e2020-07-17 23:38:57 +0530271
James Feist5b4aa862018-08-16 14:07:01 -0700272static constexpr const char* objectManagerIface =
273 "org.freedesktop.DBus.ObjectManager";
274static constexpr const char* pidConfigurationIface =
275 "xyz.openbmc_project.Configuration.Pid";
276static constexpr const char* pidZoneConfigurationIface =
277 "xyz.openbmc_project.Configuration.Pid.Zone";
James Feistb7a08d02018-12-11 14:55:37 -0800278static constexpr const char* stepwiseConfigurationIface =
279 "xyz.openbmc_project.Configuration.Stepwise";
James Feist73df0db2019-03-25 15:29:35 -0700280static constexpr const char* thermalModeIface =
281 "xyz.openbmc_project.Control.ThermalMode";
Borawski.Lukasz9c3106852018-02-09 15:24:22 +0100282
zhanghch058d1b46d2021-04-01 11:18:24 +0800283inline void
284 asyncPopulatePid(const std::string& connection, const std::string& path,
285 const std::string& currentProfile,
286 const std::vector<std::string>& supportedProfiles,
287 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp)
James Feist5b4aa862018-08-16 14:07:01 -0700288{
289
290 crow::connections::systemBus->async_method_call(
James Feist73df0db2019-03-25 15:29:35 -0700291 [asyncResp, currentProfile, supportedProfiles](
292 const boost::system::error_code ec,
293 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
395 if (intfPair.first == pidZoneConfigurationIface)
396 {
397 std::string chassis;
398 if (!dbus::utility::getNthStringFromPath(pathPair.first.str,
399 5, chassis))
400 {
401 chassis = "#IllegalValue";
402 }
403 nlohmann::json& zone = zones[name];
Ed Tanous613dabe2022-07-09 11:17:36 -0700404 zone["Chassis"]["@odata.id"] =
405 "/redfish/v1/Chassis/" + chassis;
Ed Tanous002d39b2022-05-31 08:59:27 -0700406 zone["@odata.id"] =
407 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
408 name;
409 zone["@odata.type"] = "#OemManager.FanZone";
410 config = &zone;
411 }
412
413 else if (intfPair.first == stepwiseConfigurationIface)
414 {
415 if (classPtr == nullptr)
416 {
417 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
James Feistb7a08d02018-12-11 14:55:37 -0800418 messages::internalError(asyncResp->res);
419 return;
420 }
421
Ed Tanous002d39b2022-05-31 08:59:27 -0700422 nlohmann::json& controller = stepwise[name];
423 config = &controller;
James Feistb7a08d02018-12-11 14:55:37 -0800424
Ed Tanous002d39b2022-05-31 08:59:27 -0700425 controller["@odata.id"] =
426 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/StepwiseControllers/" +
427 name;
428 controller["@odata.type"] =
429 "#OemManager.StepwiseController";
430
431 controller["Direction"] = *classPtr;
432 }
433
434 // pid and fans are off the same configuration
435 else if (intfPair.first == pidConfigurationIface)
436 {
437
438 if (classPtr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700439 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700440 BMCWEB_LOG_ERROR << "Pid Class Field illegal";
441 messages::internalError(asyncResp->res);
442 return;
443 }
444 bool isFan = *classPtr == "fan";
445 nlohmann::json& element = isFan ? fans[name] : pids[name];
446 config = &element;
447 if (isFan)
448 {
449 element["@odata.id"] =
450 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanControllers/" +
451 name;
452 element["@odata.type"] = "#OemManager.FanController";
453 }
454 else
455 {
456 element["@odata.id"] =
457 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/PidControllers/" +
458 name;
459 element["@odata.type"] = "#OemManager.PidController";
460 }
461 }
462 else
463 {
464 BMCWEB_LOG_ERROR << "Unexpected configuration";
465 messages::internalError(asyncResp->res);
466 return;
467 }
James Feist5b4aa862018-08-16 14:07:01 -0700468
Ed Tanous002d39b2022-05-31 08:59:27 -0700469 // used for making maps out of 2 vectors
470 const std::vector<double>* keys = nullptr;
471 const std::vector<double>* values = nullptr;
472
473 for (const auto& propertyPair : intfPair.second)
474 {
475 if (propertyPair.first == "Type" ||
476 propertyPair.first == "Class" ||
477 propertyPair.first == "Name")
478 {
479 continue;
480 }
481
482 // zones
483 if (intfPair.first == pidZoneConfigurationIface)
484 {
485 const double* ptr =
486 std::get_if<double>(&propertyPair.second);
487 if (ptr == nullptr)
488 {
489 BMCWEB_LOG_ERROR << "Field Illegal "
490 << propertyPair.first;
491 messages::internalError(asyncResp->res);
492 return;
493 }
494 (*config)[propertyPair.first] = *ptr;
495 }
496
497 if (intfPair.first == stepwiseConfigurationIface)
498 {
499 if (propertyPair.first == "Reading" ||
500 propertyPair.first == "Output")
501 {
502 const std::vector<double>* ptr =
503 std::get_if<std::vector<double>>(
504 &propertyPair.second);
505
506 if (ptr == nullptr)
507 {
508 BMCWEB_LOG_ERROR << "Field Illegal "
509 << propertyPair.first;
510 messages::internalError(asyncResp->res);
511 return;
512 }
513
514 if (propertyPair.first == "Reading")
515 {
516 keys = ptr;
517 }
518 else
519 {
520 values = ptr;
521 }
522 if (keys != nullptr && values != nullptr)
523 {
524 if (keys->size() != values->size())
525 {
526 BMCWEB_LOG_ERROR
527 << "Reading and Output size don't match ";
528 messages::internalError(asyncResp->res);
529 return;
530 }
531 nlohmann::json& steps = (*config)["Steps"];
532 steps = nlohmann::json::array();
533 for (size_t ii = 0; ii < keys->size(); ii++)
534 {
535 nlohmann::json::object_t step;
536 step["Target"] = (*keys)[ii];
537 step["Output"] = (*values)[ii];
538 steps.push_back(std::move(step));
539 }
540 }
541 }
542 if (propertyPair.first == "NegativeHysteresis" ||
543 propertyPair.first == "PositiveHysteresis")
James Feist5b4aa862018-08-16 14:07:01 -0700544 {
Ed Tanous1b6b96c2018-11-30 11:35:41 -0800545 const double* ptr =
Ed Tanousabf2add2019-01-22 16:40:12 -0800546 std::get_if<double>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700547 if (ptr == nullptr)
548 {
549 BMCWEB_LOG_ERROR << "Field Illegal "
550 << propertyPair.first;
Jason M. Billsf12894f2018-10-09 12:45:45 -0700551 messages::internalError(asyncResp->res);
James Feist5b4aa862018-08-16 14:07:01 -0700552 return;
553 }
James Feistb7a08d02018-12-11 14:55:37 -0800554 (*config)[propertyPair.first] = *ptr;
555 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700556 }
James Feistb7a08d02018-12-11 14:55:37 -0800557
Ed Tanous002d39b2022-05-31 08:59:27 -0700558 // pid and fans are off the same configuration
559 if (intfPair.first == pidConfigurationIface ||
560 intfPair.first == stepwiseConfigurationIface)
561 {
562
563 if (propertyPair.first == "Zones")
James Feistb7a08d02018-12-11 14:55:37 -0800564 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700565 const std::vector<std::string>* inputs =
566 std::get_if<std::vector<std::string>>(
567 &propertyPair.second);
568
569 if (inputs == nullptr)
James Feistb7a08d02018-12-11 14:55:37 -0800570 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700571 BMCWEB_LOG_ERROR << "Zones Pid Field Illegal";
572 messages::internalError(asyncResp->res);
573 return;
James Feistb7a08d02018-12-11 14:55:37 -0800574 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700575 auto& data = (*config)[propertyPair.first];
576 data = nlohmann::json::array();
577 for (std::string itemCopy : *inputs)
James Feistb7a08d02018-12-11 14:55:37 -0800578 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700579 dbus::utility::escapePathForDbus(itemCopy);
580 nlohmann::json::object_t input;
581 input["@odata.id"] =
582 "/redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/" +
583 itemCopy;
584 data.push_back(std::move(input));
James Feistb7a08d02018-12-11 14:55:37 -0800585 }
James Feist5b4aa862018-08-16 14:07:01 -0700586 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700587 // todo(james): may never happen, but this
588 // assumes configuration data referenced in the
589 // PID config is provided by the same daemon, we
590 // could add another loop to cover all cases,
591 // but I'm okay kicking this can down the road a
592 // bit
James Feist5b4aa862018-08-16 14:07:01 -0700593
Ed Tanous002d39b2022-05-31 08:59:27 -0700594 else if (propertyPair.first == "Inputs" ||
595 propertyPair.first == "Outputs")
James Feist5b4aa862018-08-16 14:07:01 -0700596 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700597 auto& data = (*config)[propertyPair.first];
598 const std::vector<std::string>* inputs =
599 std::get_if<std::vector<std::string>>(
600 &propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700601
Ed Tanous002d39b2022-05-31 08:59:27 -0700602 if (inputs == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700603 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700604 BMCWEB_LOG_ERROR << "Field Illegal "
605 << propertyPair.first;
606 messages::internalError(asyncResp->res);
607 return;
James Feist5b4aa862018-08-16 14:07:01 -0700608 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700609 data = *inputs;
610 }
611 else if (propertyPair.first == "SetPointOffset")
612 {
613 const std::string* ptr =
614 std::get_if<std::string>(&propertyPair.second);
James Feist5b4aa862018-08-16 14:07:01 -0700615
Ed Tanous002d39b2022-05-31 08:59:27 -0700616 if (ptr == nullptr)
James Feist5b4aa862018-08-16 14:07:01 -0700617 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700618 BMCWEB_LOG_ERROR << "Field Illegal "
619 << propertyPair.first;
620 messages::internalError(asyncResp->res);
621 return;
James Feistb943aae2019-07-11 16:33:56 -0700622 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700623 // translate from dbus to redfish
624 if (*ptr == "WarningHigh")
James Feistb943aae2019-07-11 16:33:56 -0700625 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700626 (*config)["SetPointOffset"] =
627 "UpperThresholdNonCritical";
James Feistb943aae2019-07-11 16:33:56 -0700628 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700629 else if (*ptr == "WarningLow")
James Feist5b4aa862018-08-16 14:07:01 -0700630 {
Ed Tanous002d39b2022-05-31 08:59:27 -0700631 (*config)["SetPointOffset"] =
632 "LowerThresholdNonCritical";
James Feist5b4aa862018-08-16 14:07:01 -0700633 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700634 else if (*ptr == "CriticalHigh")
635 {
636 (*config)["SetPointOffset"] =
637 "UpperThresholdCritical";
638 }
639 else if (*ptr == "CriticalLow")
640 {
641 (*config)["SetPointOffset"] =
642 "LowerThresholdCritical";
643 }
644 else
645 {
646 BMCWEB_LOG_ERROR << "Value Illegal " << *ptr;
647 messages::internalError(asyncResp->res);
648 return;
649 }
650 }
651 // doubles
652 else if (propertyPair.first == "FFGainCoefficient" ||
653 propertyPair.first == "FFOffCoefficient" ||
654 propertyPair.first == "ICoefficient" ||
655 propertyPair.first == "ILimitMax" ||
656 propertyPair.first == "ILimitMin" ||
657 propertyPair.first == "PositiveHysteresis" ||
658 propertyPair.first == "NegativeHysteresis" ||
659 propertyPair.first == "OutLimitMax" ||
660 propertyPair.first == "OutLimitMin" ||
661 propertyPair.first == "PCoefficient" ||
662 propertyPair.first == "SetPoint" ||
663 propertyPair.first == "SlewNeg" ||
664 propertyPair.first == "SlewPos")
665 {
666 const double* ptr =
667 std::get_if<double>(&propertyPair.second);
668 if (ptr == nullptr)
669 {
670 BMCWEB_LOG_ERROR << "Field Illegal "
671 << propertyPair.first;
672 messages::internalError(asyncResp->res);
673 return;
674 }
675 (*config)[propertyPair.first] = *ptr;
James Feist5b4aa862018-08-16 14:07:01 -0700676 }
677 }
678 }
679 }
Ed Tanous002d39b2022-05-31 08:59:27 -0700680 }
James Feist5b4aa862018-08-16 14:07:01 -0700681 },
682 connection, path, objectManagerIface, "GetManagedObjects");
683}
Jennifer Leeca537922018-08-10 10:07:30 -0700684
James Feist83ff9ab2018-08-31 10:18:24 -0700685enum class CreatePIDRet
686{
687 fail,
688 del,
689 patch
690};
691
zhanghch058d1b46d2021-04-01 11:18:24 +0800692inline bool
693 getZonesFromJsonReq(const std::shared_ptr<bmcweb::AsyncResp>& response,
694 std::vector<nlohmann::json>& config,
695 std::vector<std::string>& zones)
James Feist5f2caae2018-12-12 14:08:25 -0800696{
James Feistb6baeaa2019-02-21 10:41:40 -0800697 if (config.empty())
698 {
699 BMCWEB_LOG_ERROR << "Empty Zones";
Ed Tanous1668ce62022-02-07 23:44:31 -0800700 messages::propertyValueFormatError(response->res, "[]", "Zones");
James Feistb6baeaa2019-02-21 10:41:40 -0800701 return false;
702 }
James Feist5f2caae2018-12-12 14:08:25 -0800703 for (auto& odata : config)
704 {
705 std::string path;
706 if (!redfish::json_util::readJson(odata, response->res, "@odata.id",
707 path))
708 {
709 return false;
710 }
711 std::string input;
James Feist61adbda2019-03-25 13:03:51 -0700712
713 // 8 below comes from
714 // /redfish/v1/Managers/bmc#/Oem/OpenBmc/Fan/FanZones/Left
715 // 0 1 2 3 4 5 6 7 8
716 if (!dbus::utility::getNthStringFromPath(path, 8, input))
James Feist5f2caae2018-12-12 14:08:25 -0800717 {
718 BMCWEB_LOG_ERROR << "Got invalid path " << path;
719 BMCWEB_LOG_ERROR << "Illegal Type Zones";
720 messages::propertyValueFormatError(response->res, odata.dump(),
721 "Zones");
722 return false;
723 }
Ed Tanousa170f272022-06-30 21:53:27 -0700724 std::replace(input.begin(), input.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -0800725 zones.emplace_back(std::move(input));
726 }
727 return true;
728}
729
Ed Tanous711ac7a2021-12-20 09:34:41 -0800730inline const dbus::utility::ManagedObjectType::value_type*
James Feist73df0db2019-03-25 15:29:35 -0700731 findChassis(const dbus::utility::ManagedObjectType& managedObj,
732 const std::string& value, std::string& chassis)
James Feistb6baeaa2019-02-21 10:41:40 -0800733{
734 BMCWEB_LOG_DEBUG << "Find Chassis: " << value << "\n";
735
Ed Tanousa170f272022-06-30 21:53:27 -0700736 std::string escaped = value;
737 std::replace(escaped.begin(), escaped.end(), '_', ' ');
James Feistb6baeaa2019-02-21 10:41:40 -0800738 escaped = "/" + escaped;
Ed Tanous002d39b2022-05-31 08:59:27 -0700739 auto it = std::find_if(managedObj.begin(), managedObj.end(),
740 [&escaped](const auto& obj) {
741 if (boost::algorithm::ends_with(obj.first.str, escaped))
742 {
743 BMCWEB_LOG_DEBUG << "Matched " << obj.first.str << "\n";
744 return true;
745 }
746 return false;
747 });
James Feistb6baeaa2019-02-21 10:41:40 -0800748
749 if (it == managedObj.end())
750 {
James Feist73df0db2019-03-25 15:29:35 -0700751 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800752 }
753 // 5 comes from <chassis-name> being the 5th element
754 // /xyz/openbmc_project/inventory/system/chassis/<chassis-name>
James Feist73df0db2019-03-25 15:29:35 -0700755 if (dbus::utility::getNthStringFromPath(it->first.str, 5, chassis))
756 {
757 return &(*it);
758 }
759
760 return nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800761}
762
Ed Tanous23a21a12020-07-25 04:45:05 +0000763inline CreatePIDRet createPidInterface(
zhanghch058d1b46d2021-04-01 11:18:24 +0800764 const std::shared_ptr<bmcweb::AsyncResp>& response, const std::string& type,
Ed Tanousb5a76932020-09-29 16:16:58 -0700765 const nlohmann::json::iterator& it, const std::string& path,
James Feist83ff9ab2018-08-31 10:18:24 -0700766 const dbus::utility::ManagedObjectType& managedObj, bool createNewObject,
Ed Tanousb9d36b42022-02-26 21:42:46 -0800767 dbus::utility::DBusPropertiesMap& output, std::string& chassis,
768 const std::string& profile)
James Feist83ff9ab2018-08-31 10:18:24 -0700769{
770
James Feist5f2caae2018-12-12 14:08:25 -0800771 // common deleter
James Feistb6baeaa2019-02-21 10:41:40 -0800772 if (it.value() == nullptr)
James Feist5f2caae2018-12-12 14:08:25 -0800773 {
774 std::string iface;
775 if (type == "PidControllers" || type == "FanControllers")
776 {
777 iface = pidConfigurationIface;
778 }
779 else if (type == "FanZones")
780 {
781 iface = pidZoneConfigurationIface;
782 }
783 else if (type == "StepwiseControllers")
784 {
785 iface = stepwiseConfigurationIface;
786 }
787 else
788 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600789 BMCWEB_LOG_ERROR << "Illegal Type " << type;
James Feist5f2caae2018-12-12 14:08:25 -0800790 messages::propertyUnknown(response->res, type);
791 return CreatePIDRet::fail;
792 }
James Feist6ee7f772020-02-06 16:25:27 -0800793
794 BMCWEB_LOG_DEBUG << "del " << path << " " << iface << "\n";
James Feist5f2caae2018-12-12 14:08:25 -0800795 // delete interface
796 crow::connections::systemBus->async_method_call(
797 [response, path](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -0700798 if (ec)
799 {
800 BMCWEB_LOG_ERROR << "Error patching " << path << ": " << ec;
801 messages::internalError(response->res);
802 return;
803 }
804 messages::success(response->res);
James Feist5f2caae2018-12-12 14:08:25 -0800805 },
806 "xyz.openbmc_project.EntityManager", path, iface, "Delete");
807 return CreatePIDRet::del;
808 }
809
Ed Tanous711ac7a2021-12-20 09:34:41 -0800810 const dbus::utility::ManagedObjectType::value_type* managedItem = nullptr;
James Feistb6baeaa2019-02-21 10:41:40 -0800811 if (!createNewObject)
812 {
813 // if we aren't creating a new object, we should be able to find it on
814 // d-bus
James Feist73df0db2019-03-25 15:29:35 -0700815 managedItem = findChassis(managedObj, it.key(), chassis);
816 if (managedItem == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800817 {
818 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700819 messages::invalidObject(response->res,
820 crow::utility::urlFromPieces(
821 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800822 return CreatePIDRet::fail;
823 }
824 }
825
Ed Tanous26f69762022-01-25 09:49:11 -0800826 if (!profile.empty() &&
James Feist73df0db2019-03-25 15:29:35 -0700827 (type == "PidControllers" || type == "FanControllers" ||
828 type == "StepwiseControllers"))
829 {
830 if (managedItem == nullptr)
831 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800832 output.emplace_back("Profiles", std::vector<std::string>{profile});
James Feist73df0db2019-03-25 15:29:35 -0700833 }
834 else
835 {
836 std::string interface;
837 if (type == "StepwiseControllers")
838 {
839 interface = stepwiseConfigurationIface;
840 }
841 else
842 {
843 interface = pidConfigurationIface;
844 }
Ed Tanous711ac7a2021-12-20 09:34:41 -0800845 bool ifaceFound = false;
846 for (const auto& iface : managedItem->second)
847 {
848 if (iface.first == interface)
849 {
850 ifaceFound = true;
851 for (const auto& prop : iface.second)
852 {
853 if (prop.first == "Profiles")
854 {
855 const std::vector<std::string>* curProfiles =
856 std::get_if<std::vector<std::string>>(
857 &(prop.second));
858 if (curProfiles == nullptr)
859 {
860 BMCWEB_LOG_ERROR
861 << "Illegal profiles in managed object";
862 messages::internalError(response->res);
863 return CreatePIDRet::fail;
864 }
865 if (std::find(curProfiles->begin(),
866 curProfiles->end(),
867 profile) == curProfiles->end())
868 {
869 std::vector<std::string> newProfiles =
870 *curProfiles;
871 newProfiles.push_back(profile);
Ed Tanousb9d36b42022-02-26 21:42:46 -0800872 output.emplace_back("Profiles", newProfiles);
Ed Tanous711ac7a2021-12-20 09:34:41 -0800873 }
874 }
875 }
876 }
877 }
878
879 if (!ifaceFound)
James Feist73df0db2019-03-25 15:29:35 -0700880 {
881 BMCWEB_LOG_ERROR
882 << "Failed to find interface in managed object";
883 messages::internalError(response->res);
884 return CreatePIDRet::fail;
885 }
James Feist73df0db2019-03-25 15:29:35 -0700886 }
887 }
888
James Feist83ff9ab2018-08-31 10:18:24 -0700889 if (type == "PidControllers" || type == "FanControllers")
890 {
891 if (createNewObject)
892 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800893 output.emplace_back("Class",
894 type == "PidControllers" ? "temp" : "fan");
895 output.emplace_back("Type", "Pid");
James Feist83ff9ab2018-08-31 10:18:24 -0700896 }
James Feist5f2caae2018-12-12 14:08:25 -0800897
898 std::optional<std::vector<nlohmann::json>> zones;
899 std::optional<std::vector<std::string>> inputs;
900 std::optional<std::vector<std::string>> outputs;
901 std::map<std::string, std::optional<double>> doubles;
James Feistb943aae2019-07-11 16:33:56 -0700902 std::optional<std::string> setpointOffset;
James Feist5f2caae2018-12-12 14:08:25 -0800903 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -0800904 it.value(), response->res, "Inputs", inputs, "Outputs", outputs,
James Feist5f2caae2018-12-12 14:08:25 -0800905 "Zones", zones, "FFGainCoefficient",
906 doubles["FFGainCoefficient"], "FFOffCoefficient",
907 doubles["FFOffCoefficient"], "ICoefficient",
908 doubles["ICoefficient"], "ILimitMax", doubles["ILimitMax"],
909 "ILimitMin", doubles["ILimitMin"], "OutLimitMax",
910 doubles["OutLimitMax"], "OutLimitMin", doubles["OutLimitMin"],
911 "PCoefficient", doubles["PCoefficient"], "SetPoint",
James Feistb943aae2019-07-11 16:33:56 -0700912 doubles["SetPoint"], "SetPointOffset", setpointOffset,
913 "SlewNeg", doubles["SlewNeg"], "SlewPos", doubles["SlewPos"],
914 "PositiveHysteresis", doubles["PositiveHysteresis"],
915 "NegativeHysteresis", doubles["NegativeHysteresis"]))
James Feist83ff9ab2018-08-31 10:18:24 -0700916 {
Ed Tanous71f52d92021-02-19 08:51:17 -0800917 BMCWEB_LOG_ERROR
918 << "Illegal Property "
919 << it.value().dump(2, ' ', true,
920 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -0800921 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700922 }
James Feist5f2caae2018-12-12 14:08:25 -0800923 if (zones)
James Feist83ff9ab2018-08-31 10:18:24 -0700924 {
James Feist5f2caae2018-12-12 14:08:25 -0800925 std::vector<std::string> zonesStr;
926 if (!getZonesFromJsonReq(response, *zones, zonesStr))
James Feist83ff9ab2018-08-31 10:18:24 -0700927 {
Gunnar Millsa0744d32020-11-09 15:40:45 -0600928 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -0800929 return CreatePIDRet::fail;
James Feist83ff9ab2018-08-31 10:18:24 -0700930 }
James Feistb6baeaa2019-02-21 10:41:40 -0800931 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -0800932 findChassis(managedObj, zonesStr[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -0800933 {
934 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -0700935 messages::invalidObject(
936 response->res, crow::utility::urlFromPieces(
937 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -0800938 return CreatePIDRet::fail;
939 }
Ed Tanousb9d36b42022-02-26 21:42:46 -0800940 output.emplace_back("Zones", std::move(zonesStr));
James Feist5f2caae2018-12-12 14:08:25 -0800941 }
Ed Tanousafb9ee02022-12-21 11:59:17 -0800942
943 if (inputs)
James Feist5f2caae2018-12-12 14:08:25 -0800944 {
Ed Tanousafb9ee02022-12-21 11:59:17 -0800945 for (std::string& value : *inputs)
James Feist83ff9ab2018-08-31 10:18:24 -0700946 {
Ed Tanousafb9ee02022-12-21 11:59:17 -0800947 std::replace(value.begin(), value.end(), '_', ' ');
James Feist83ff9ab2018-08-31 10:18:24 -0700948 }
Ed Tanousafb9ee02022-12-21 11:59:17 -0800949 output.emplace_back("Inputs", *inputs);
950 }
951
952 if (outputs)
953 {
954 for (std::string& value : *outputs)
955 {
956 std::replace(value.begin(), value.end(), '_', ' ');
957 }
958 output.emplace_back("Outputs", *outputs);
James Feist5f2caae2018-12-12 14:08:25 -0800959 }
James Feist83ff9ab2018-08-31 10:18:24 -0700960
James Feistb943aae2019-07-11 16:33:56 -0700961 if (setpointOffset)
962 {
963 // translate between redfish and dbus names
964 if (*setpointOffset == "UpperThresholdNonCritical")
965 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800966 output.emplace_back("SetPointOffset", "WarningLow");
James Feistb943aae2019-07-11 16:33:56 -0700967 }
968 else if (*setpointOffset == "LowerThresholdNonCritical")
969 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800970 output.emplace_back("SetPointOffset", "WarningHigh");
James Feistb943aae2019-07-11 16:33:56 -0700971 }
972 else if (*setpointOffset == "LowerThresholdCritical")
973 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800974 output.emplace_back("SetPointOffset", "CriticalLow");
James Feistb943aae2019-07-11 16:33:56 -0700975 }
976 else if (*setpointOffset == "UpperThresholdCritical")
977 {
Ed Tanousb9d36b42022-02-26 21:42:46 -0800978 output.emplace_back("SetPointOffset", "CriticalHigh");
James Feistb943aae2019-07-11 16:33:56 -0700979 }
980 else
981 {
982 BMCWEB_LOG_ERROR << "Invalid setpointoffset "
983 << *setpointOffset;
Ed Tanousace85d62021-10-26 12:45:59 -0700984 messages::propertyValueNotInList(response->res, it.key(),
985 "SetPointOffset");
James Feistb943aae2019-07-11 16:33:56 -0700986 return CreatePIDRet::fail;
987 }
988 }
989
James Feist5f2caae2018-12-12 14:08:25 -0800990 // doubles
991 for (const auto& pairs : doubles)
992 {
993 if (!pairs.second)
James Feist83ff9ab2018-08-31 10:18:24 -0700994 {
James Feist5f2caae2018-12-12 14:08:25 -0800995 continue;
James Feist83ff9ab2018-08-31 10:18:24 -0700996 }
James Feist5f2caae2018-12-12 14:08:25 -0800997 BMCWEB_LOG_DEBUG << pairs.first << " = " << *pairs.second;
Ed Tanousb9d36b42022-02-26 21:42:46 -0800998 output.emplace_back(pairs.first, *pairs.second);
James Feist83ff9ab2018-08-31 10:18:24 -0700999 }
1000 }
James Feist5f2caae2018-12-12 14:08:25 -08001001
James Feist83ff9ab2018-08-31 10:18:24 -07001002 else if (type == "FanZones")
1003 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001004 output.emplace_back("Type", "Pid.Zone");
James Feist83ff9ab2018-08-31 10:18:24 -07001005
James Feist5f2caae2018-12-12 14:08:25 -08001006 std::optional<nlohmann::json> chassisContainer;
1007 std::optional<double> failSafePercent;
James Feistd3ec07f2019-02-25 14:51:15 -08001008 std::optional<double> minThermalOutput;
James Feistb6baeaa2019-02-21 10:41:40 -08001009 if (!redfish::json_util::readJson(it.value(), response->res, "Chassis",
James Feist5f2caae2018-12-12 14:08:25 -08001010 chassisContainer, "FailSafePercent",
James Feistd3ec07f2019-02-25 14:51:15 -08001011 failSafePercent, "MinThermalOutput",
1012 minThermalOutput))
James Feist83ff9ab2018-08-31 10:18:24 -07001013 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001014 BMCWEB_LOG_ERROR
1015 << "Illegal Property "
1016 << it.value().dump(2, ' ', true,
1017 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001018 return CreatePIDRet::fail;
1019 }
James Feist83ff9ab2018-08-31 10:18:24 -07001020
James Feist5f2caae2018-12-12 14:08:25 -08001021 if (chassisContainer)
1022 {
1023
1024 std::string chassisId;
1025 if (!redfish::json_util::readJson(*chassisContainer, response->res,
1026 "@odata.id", chassisId))
James Feist83ff9ab2018-08-31 10:18:24 -07001027 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001028 BMCWEB_LOG_ERROR
1029 << "Illegal Property "
1030 << chassisContainer->dump(
1031 2, ' ', true,
1032 nlohmann::json::error_handler_t::replace);
James Feist83ff9ab2018-08-31 10:18:24 -07001033 return CreatePIDRet::fail;
1034 }
James Feist5f2caae2018-12-12 14:08:25 -08001035
AppaRao Puli717794d2019-10-18 22:54:53 +05301036 // /redfish/v1/chassis/chassis_name/
James Feist5f2caae2018-12-12 14:08:25 -08001037 if (!dbus::utility::getNthStringFromPath(chassisId, 3, chassis))
1038 {
1039 BMCWEB_LOG_ERROR << "Got invalid path " << chassisId;
Ed Tanousace85d62021-10-26 12:45:59 -07001040 messages::invalidObject(
1041 response->res, crow::utility::urlFromPieces(
1042 "redfish", "v1", "Chassis", chassisId));
James Feist5f2caae2018-12-12 14:08:25 -08001043 return CreatePIDRet::fail;
1044 }
1045 }
James Feistd3ec07f2019-02-25 14:51:15 -08001046 if (minThermalOutput)
James Feist5f2caae2018-12-12 14:08:25 -08001047 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001048 output.emplace_back("MinThermalOutput", *minThermalOutput);
James Feist5f2caae2018-12-12 14:08:25 -08001049 }
1050 if (failSafePercent)
1051 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001052 output.emplace_back("FailSafePercent", *failSafePercent);
James Feist5f2caae2018-12-12 14:08:25 -08001053 }
1054 }
1055 else if (type == "StepwiseControllers")
1056 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001057 output.emplace_back("Type", "Stepwise");
James Feist5f2caae2018-12-12 14:08:25 -08001058
1059 std::optional<std::vector<nlohmann::json>> zones;
1060 std::optional<std::vector<nlohmann::json>> steps;
1061 std::optional<std::vector<std::string>> inputs;
1062 std::optional<double> positiveHysteresis;
1063 std::optional<double> negativeHysteresis;
James Feistc33a90e2019-03-01 10:17:44 -08001064 std::optional<std::string> direction; // upper clipping curve vs lower
James Feist5f2caae2018-12-12 14:08:25 -08001065 if (!redfish::json_util::readJson(
James Feistb6baeaa2019-02-21 10:41:40 -08001066 it.value(), response->res, "Zones", zones, "Steps", steps,
1067 "Inputs", inputs, "PositiveHysteresis", positiveHysteresis,
James Feistc33a90e2019-03-01 10:17:44 -08001068 "NegativeHysteresis", negativeHysteresis, "Direction",
1069 direction))
James Feist5f2caae2018-12-12 14:08:25 -08001070 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001071 BMCWEB_LOG_ERROR
1072 << "Illegal Property "
1073 << it.value().dump(2, ' ', true,
1074 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001075 return CreatePIDRet::fail;
1076 }
1077
1078 if (zones)
1079 {
James Feistb6baeaa2019-02-21 10:41:40 -08001080 std::vector<std::string> zonesStrs;
1081 if (!getZonesFromJsonReq(response, *zones, zonesStrs))
James Feist5f2caae2018-12-12 14:08:25 -08001082 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001083 BMCWEB_LOG_ERROR << "Illegal Zones";
James Feist5f2caae2018-12-12 14:08:25 -08001084 return CreatePIDRet::fail;
1085 }
James Feistb6baeaa2019-02-21 10:41:40 -08001086 if (chassis.empty() &&
Ed Tanouse662eae2022-01-25 10:39:19 -08001087 findChassis(managedObj, zonesStrs[0], chassis) == nullptr)
James Feistb6baeaa2019-02-21 10:41:40 -08001088 {
1089 BMCWEB_LOG_ERROR << "Failed to get chassis from config patch";
Ed Tanousace85d62021-10-26 12:45:59 -07001090 messages::invalidObject(
1091 response->res, crow::utility::urlFromPieces(
1092 "redfish", "v1", "Chassis", chassis));
James Feistb6baeaa2019-02-21 10:41:40 -08001093 return CreatePIDRet::fail;
1094 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001095 output.emplace_back("Zones", std::move(zonesStrs));
James Feist5f2caae2018-12-12 14:08:25 -08001096 }
1097 if (steps)
1098 {
1099 std::vector<double> readings;
1100 std::vector<double> outputs;
1101 for (auto& step : *steps)
1102 {
Ed Tanous543f4402022-01-06 13:12:53 -08001103 double target = 0.0;
1104 double out = 0.0;
James Feist5f2caae2018-12-12 14:08:25 -08001105
1106 if (!redfish::json_util::readJson(step, response->res, "Target",
Ed Tanous23a21a12020-07-25 04:45:05 +00001107 target, "Output", out))
James Feist5f2caae2018-12-12 14:08:25 -08001108 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001109 BMCWEB_LOG_ERROR
1110 << "Illegal Property "
1111 << it.value().dump(
1112 2, ' ', true,
1113 nlohmann::json::error_handler_t::replace);
James Feist5f2caae2018-12-12 14:08:25 -08001114 return CreatePIDRet::fail;
1115 }
1116 readings.emplace_back(target);
Ed Tanous23a21a12020-07-25 04:45:05 +00001117 outputs.emplace_back(out);
James Feist5f2caae2018-12-12 14:08:25 -08001118 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001119 output.emplace_back("Reading", std::move(readings));
1120 output.emplace_back("Output", std::move(outputs));
James Feist5f2caae2018-12-12 14:08:25 -08001121 }
1122 if (inputs)
1123 {
1124 for (std::string& value : *inputs)
1125 {
Ed Tanousa170f272022-06-30 21:53:27 -07001126
1127 std::replace(value.begin(), value.end(), '_', ' ');
James Feist5f2caae2018-12-12 14:08:25 -08001128 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001129 output.emplace_back("Inputs", std::move(*inputs));
James Feist5f2caae2018-12-12 14:08:25 -08001130 }
1131 if (negativeHysteresis)
1132 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001133 output.emplace_back("NegativeHysteresis", *negativeHysteresis);
James Feist5f2caae2018-12-12 14:08:25 -08001134 }
1135 if (positiveHysteresis)
1136 {
Ed Tanousb9d36b42022-02-26 21:42:46 -08001137 output.emplace_back("PositiveHysteresis", *positiveHysteresis);
James Feist83ff9ab2018-08-31 10:18:24 -07001138 }
James Feistc33a90e2019-03-01 10:17:44 -08001139 if (direction)
1140 {
1141 constexpr const std::array<const char*, 2> allowedDirections = {
1142 "Ceiling", "Floor"};
1143 if (std::find(allowedDirections.begin(), allowedDirections.end(),
1144 *direction) == allowedDirections.end())
1145 {
1146 messages::propertyValueTypeError(response->res, "Direction",
1147 *direction);
1148 return CreatePIDRet::fail;
1149 }
Ed Tanousb9d36b42022-02-26 21:42:46 -08001150 output.emplace_back("Class", *direction);
James Feistc33a90e2019-03-01 10:17:44 -08001151 }
James Feist83ff9ab2018-08-31 10:18:24 -07001152 }
1153 else
1154 {
Gunnar Millsa0744d32020-11-09 15:40:45 -06001155 BMCWEB_LOG_ERROR << "Illegal Type " << type;
Jason M. Bills35a62c72018-10-09 12:45:45 -07001156 messages::propertyUnknown(response->res, type);
James Feist83ff9ab2018-08-31 10:18:24 -07001157 return CreatePIDRet::fail;
1158 }
1159 return CreatePIDRet::patch;
1160}
James Feist73df0db2019-03-25 15:29:35 -07001161struct GetPIDValues : std::enable_shared_from_this<GetPIDValues>
1162{
Ed Tanous6936afe2022-09-08 15:10:39 -07001163 struct CompletionValues
1164 {
1165 std::vector<std::string> supportedProfiles;
1166 std::string currentProfile;
1167 dbus::utility::MapperGetSubTreeResponse subtree;
1168 };
James Feist73df0db2019-03-25 15:29:35 -07001169
Ed Tanous4e23a442022-06-06 09:57:26 -07001170 explicit GetPIDValues(
1171 const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn) :
Ed Tanous23a21a12020-07-25 04:45:05 +00001172 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001173
Gunnar Mills1214b7e2020-06-04 10:11:30 -05001174 {}
James Feist73df0db2019-03-25 15:29:35 -07001175
1176 void run()
1177 {
1178 std::shared_ptr<GetPIDValues> self = shared_from_this();
1179
1180 // get all configurations
1181 crow::connections::systemBus->async_method_call(
Ed Tanousb9d36b42022-02-26 21:42:46 -08001182 [self](
1183 const boost::system::error_code ec,
1184 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001185 if (ec)
1186 {
1187 BMCWEB_LOG_ERROR << ec;
1188 messages::internalError(self->asyncResp->res);
1189 return;
1190 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001191 self->complete.subtree = subtreeLocal;
James Feist73df0db2019-03-25 15:29:35 -07001192 },
1193 "xyz.openbmc_project.ObjectMapper",
1194 "/xyz/openbmc_project/object_mapper",
1195 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1196 std::array<const char*, 4>{
1197 pidConfigurationIface, pidZoneConfigurationIface,
1198 objectManagerIface, stepwiseConfigurationIface});
1199
1200 // at the same time get the selected profile
1201 crow::connections::systemBus->async_method_call(
Ed Tanousb9d36b42022-02-26 21:42:46 -08001202 [self](
1203 const boost::system::error_code ec,
1204 const dbus::utility::MapperGetSubTreeResponse& subtreeLocal) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001205 if (ec || subtreeLocal.empty())
1206 {
1207 return;
1208 }
1209 if (subtreeLocal[0].second.size() != 1)
1210 {
1211 // invalid mapper response, should never happen
1212 BMCWEB_LOG_ERROR << "GetPIDValues: Mapper Error";
1213 messages::internalError(self->asyncResp->res);
1214 return;
1215 }
1216
1217 const std::string& path = subtreeLocal[0].first;
1218 const std::string& owner = subtreeLocal[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001219
1220 sdbusplus::asio::getAllProperties(
1221 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous002d39b2022-05-31 08:59:27 -07001222 [path, owner,
1223 self](const boost::system::error_code ec2,
1224 const dbus::utility::DBusPropertiesMap& resp) {
1225 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001226 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001227 BMCWEB_LOG_ERROR
1228 << "GetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001229 messages::internalError(self->asyncResp->res);
1230 return;
1231 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001232
Ed Tanous002d39b2022-05-31 08:59:27 -07001233 const std::string* current = nullptr;
1234 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001235
1236 const bool success = sdbusplus::unpackPropertiesNoThrow(
1237 dbus_utils::UnpackErrorPrinter(), resp, "Current", current,
1238 "Supported", supported);
1239
1240 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001241 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001242 messages::internalError(self->asyncResp->res);
1243 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001244 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001245
Ed Tanous002d39b2022-05-31 08:59:27 -07001246 if (current == nullptr || supported == nullptr)
1247 {
1248 BMCWEB_LOG_ERROR
1249 << "GetPIDValues: thermal mode iface invalid " << path;
1250 messages::internalError(self->asyncResp->res);
1251 return;
1252 }
Ed Tanous6936afe2022-09-08 15:10:39 -07001253 self->complete.currentProfile = *current;
1254 self->complete.supportedProfiles = *supported;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001255 });
James Feist73df0db2019-03-25 15:29:35 -07001256 },
1257 "xyz.openbmc_project.ObjectMapper",
1258 "/xyz/openbmc_project/object_mapper",
1259 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1260 std::array<const char*, 1>{thermalModeIface});
1261 }
1262
Ed Tanous6936afe2022-09-08 15:10:39 -07001263 static void
1264 processingComplete(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp,
1265 const CompletionValues& completion)
James Feist73df0db2019-03-25 15:29:35 -07001266 {
1267 if (asyncResp->res.result() != boost::beast::http::status::ok)
1268 {
1269 return;
1270 }
1271 // create map of <connection, path to objMgr>>
Ed Tanous6936afe2022-09-08 15:10:39 -07001272 boost::container::flat_map<
1273 std::string, std::string, std::less<>,
1274 std::vector<std::pair<std::string, std::string>>>
1275 objectMgrPaths;
1276 boost::container::flat_set<std::string, std::less<>,
1277 std::vector<std::string>>
1278 calledConnections;
1279 for (const auto& pathGroup : completion.subtree)
James Feist73df0db2019-03-25 15:29:35 -07001280 {
1281 for (const auto& connectionGroup : pathGroup.second)
1282 {
1283 auto findConnection =
1284 calledConnections.find(connectionGroup.first);
1285 if (findConnection != calledConnections.end())
1286 {
1287 break;
1288 }
1289 for (const std::string& interface : connectionGroup.second)
1290 {
1291 if (interface == objectManagerIface)
1292 {
1293 objectMgrPaths[connectionGroup.first] = pathGroup.first;
1294 }
1295 // this list is alphabetical, so we
1296 // should have found the objMgr by now
1297 if (interface == pidConfigurationIface ||
1298 interface == pidZoneConfigurationIface ||
1299 interface == stepwiseConfigurationIface)
1300 {
1301 auto findObjMgr =
1302 objectMgrPaths.find(connectionGroup.first);
1303 if (findObjMgr == objectMgrPaths.end())
1304 {
1305 BMCWEB_LOG_DEBUG << connectionGroup.first
1306 << "Has no Object Manager";
1307 continue;
1308 }
1309
1310 calledConnections.insert(connectionGroup.first);
1311
1312 asyncPopulatePid(findObjMgr->first, findObjMgr->second,
Ed Tanous6936afe2022-09-08 15:10:39 -07001313 completion.currentProfile,
1314 completion.supportedProfiles,
James Feist73df0db2019-03-25 15:29:35 -07001315 asyncResp);
1316 break;
1317 }
1318 }
1319 }
1320 }
1321 }
1322
Ed Tanous6936afe2022-09-08 15:10:39 -07001323 ~GetPIDValues()
1324 {
1325 boost::asio::post(crow::connections::systemBus->get_io_context(),
1326 std::bind_front(&processingComplete, asyncResp,
1327 std::move(complete)));
1328 }
1329
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001330 GetPIDValues(const GetPIDValues&) = delete;
1331 GetPIDValues(GetPIDValues&&) = delete;
1332 GetPIDValues& operator=(const GetPIDValues&) = delete;
1333 GetPIDValues& operator=(GetPIDValues&&) = delete;
1334
zhanghch058d1b46d2021-04-01 11:18:24 +08001335 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
Ed Tanous6936afe2022-09-08 15:10:39 -07001336 CompletionValues complete;
James Feist73df0db2019-03-25 15:29:35 -07001337};
1338
1339struct SetPIDValues : std::enable_shared_from_this<SetPIDValues>
1340{
1341
zhanghch058d1b46d2021-04-01 11:18:24 +08001342 SetPIDValues(const std::shared_ptr<bmcweb::AsyncResp>& asyncRespIn,
James Feist73df0db2019-03-25 15:29:35 -07001343 nlohmann::json& data) :
Ed Tanous271584a2019-07-09 16:24:22 -07001344 asyncResp(asyncRespIn)
James Feist73df0db2019-03-25 15:29:35 -07001345 {
1346
1347 std::optional<nlohmann::json> pidControllers;
1348 std::optional<nlohmann::json> fanControllers;
1349 std::optional<nlohmann::json> fanZones;
1350 std::optional<nlohmann::json> stepwiseControllers;
1351
1352 if (!redfish::json_util::readJson(
1353 data, asyncResp->res, "PidControllers", pidControllers,
1354 "FanControllers", fanControllers, "FanZones", fanZones,
1355 "StepwiseControllers", stepwiseControllers, "Profile", profile))
1356 {
Ed Tanous71f52d92021-02-19 08:51:17 -08001357 BMCWEB_LOG_ERROR
1358 << "Illegal Property "
1359 << data.dump(2, ' ', true,
1360 nlohmann::json::error_handler_t::replace);
James Feist73df0db2019-03-25 15:29:35 -07001361 return;
1362 }
1363 configuration.emplace_back("PidControllers", std::move(pidControllers));
1364 configuration.emplace_back("FanControllers", std::move(fanControllers));
1365 configuration.emplace_back("FanZones", std::move(fanZones));
1366 configuration.emplace_back("StepwiseControllers",
1367 std::move(stepwiseControllers));
1368 }
Ed Tanousecd6a3a2022-01-07 09:18:40 -08001369
1370 SetPIDValues(const SetPIDValues&) = delete;
1371 SetPIDValues(SetPIDValues&&) = delete;
1372 SetPIDValues& operator=(const SetPIDValues&) = delete;
1373 SetPIDValues& operator=(SetPIDValues&&) = delete;
1374
James Feist73df0db2019-03-25 15:29:35 -07001375 void run()
1376 {
1377 if (asyncResp->res.result() != boost::beast::http::status::ok)
1378 {
1379 return;
1380 }
1381
1382 std::shared_ptr<SetPIDValues> self = shared_from_this();
1383
1384 // todo(james): might make sense to do a mapper call here if this
1385 // interface gets more traction
1386 crow::connections::systemBus->async_method_call(
1387 [self](const boost::system::error_code ec,
Ed Tanous914e2d52022-01-07 11:38:34 -08001388 const dbus::utility::ManagedObjectType& mObj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001389 if (ec)
1390 {
1391 BMCWEB_LOG_ERROR << "Error communicating to Entity Manager";
1392 messages::internalError(self->asyncResp->res);
1393 return;
1394 }
1395 const std::array<const char*, 3> configurations = {
1396 pidConfigurationIface, pidZoneConfigurationIface,
1397 stepwiseConfigurationIface};
James Feiste69d9de2020-02-07 12:23:27 -08001398
Ed Tanous002d39b2022-05-31 08:59:27 -07001399 for (const auto& [path, object] : mObj)
1400 {
1401 for (const auto& [interface, _] : object)
James Feiste69d9de2020-02-07 12:23:27 -08001402 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001403 if (std::find(configurations.begin(), configurations.end(),
1404 interface) != configurations.end())
James Feiste69d9de2020-02-07 12:23:27 -08001405 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001406 self->objectCount++;
1407 break;
James Feiste69d9de2020-02-07 12:23:27 -08001408 }
James Feiste69d9de2020-02-07 12:23:27 -08001409 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001410 }
1411 self->managedObj = mObj;
James Feist73df0db2019-03-25 15:29:35 -07001412 },
Nan Zhouc106b672022-09-20 22:35:31 +00001413 "xyz.openbmc_project.EntityManager",
1414 "/xyz/openbmc_project/inventory", objectManagerIface,
James Feist73df0db2019-03-25 15:29:35 -07001415 "GetManagedObjects");
1416
1417 // at the same time get the profile information
1418 crow::connections::systemBus->async_method_call(
1419 [self](const boost::system::error_code ec,
Ed Tanousb9d36b42022-02-26 21:42:46 -08001420 const dbus::utility::MapperGetSubTreeResponse& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001421 if (ec || subtree.empty())
1422 {
1423 return;
1424 }
1425 if (subtree[0].second.empty())
1426 {
1427 // invalid mapper response, should never happen
1428 BMCWEB_LOG_ERROR << "SetPIDValues: Mapper Error";
1429 messages::internalError(self->asyncResp->res);
1430 return;
1431 }
1432
1433 const std::string& path = subtree[0].first;
1434 const std::string& owner = subtree[0].second[0].first;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001435 sdbusplus::asio::getAllProperties(
1436 *crow::connections::systemBus, owner, path, thermalModeIface,
Ed Tanous002d39b2022-05-31 08:59:27 -07001437 [self, path, owner](const boost::system::error_code ec2,
1438 const dbus::utility::DBusPropertiesMap& r) {
1439 if (ec2)
James Feist73df0db2019-03-25 15:29:35 -07001440 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001441 BMCWEB_LOG_ERROR
1442 << "SetPIDValues: Can't get thermalModeIface " << path;
James Feist73df0db2019-03-25 15:29:35 -07001443 messages::internalError(self->asyncResp->res);
1444 return;
1445 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001446 const std::string* current = nullptr;
1447 const std::vector<std::string>* supported = nullptr;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001448
1449 const bool success = sdbusplus::unpackPropertiesNoThrow(
1450 dbus_utils::UnpackErrorPrinter(), r, "Current", current,
1451 "Supported", supported);
1452
1453 if (!success)
Ed Tanous002d39b2022-05-31 08:59:27 -07001454 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001455 messages::internalError(self->asyncResp->res);
1456 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07001457 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001458
Ed Tanous002d39b2022-05-31 08:59:27 -07001459 if (current == nullptr || supported == nullptr)
1460 {
1461 BMCWEB_LOG_ERROR
1462 << "SetPIDValues: thermal mode iface invalid " << path;
1463 messages::internalError(self->asyncResp->res);
1464 return;
1465 }
1466 self->currentProfile = *current;
1467 self->supportedProfiles = *supported;
1468 self->profileConnection = owner;
1469 self->profilePath = path;
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02001470 });
James Feist73df0db2019-03-25 15:29:35 -07001471 },
1472 "xyz.openbmc_project.ObjectMapper",
1473 "/xyz/openbmc_project/object_mapper",
1474 "xyz.openbmc_project.ObjectMapper", "GetSubTree", "/", 0,
1475 std::array<const char*, 1>{thermalModeIface});
1476 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001477 void pidSetDone()
James Feist73df0db2019-03-25 15:29:35 -07001478 {
1479 if (asyncResp->res.result() != boost::beast::http::status::ok)
1480 {
1481 return;
1482 }
zhanghch058d1b46d2021-04-01 11:18:24 +08001483 std::shared_ptr<bmcweb::AsyncResp> response = asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001484 if (profile)
1485 {
1486 if (std::find(supportedProfiles.begin(), supportedProfiles.end(),
1487 *profile) == supportedProfiles.end())
1488 {
1489 messages::actionParameterUnknown(response->res, "Profile",
1490 *profile);
1491 return;
1492 }
1493 currentProfile = *profile;
1494 crow::connections::systemBus->async_method_call(
1495 [response](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001496 if (ec)
1497 {
1498 BMCWEB_LOG_ERROR << "Error patching profile" << ec;
1499 messages::internalError(response->res);
1500 }
James Feist73df0db2019-03-25 15:29:35 -07001501 },
1502 profileConnection, profilePath,
1503 "org.freedesktop.DBus.Properties", "Set", thermalModeIface,
Ed Tanous168e20c2021-12-13 14:39:53 -08001504 "Current", dbus::utility::DbusVariantType(*profile));
James Feist73df0db2019-03-25 15:29:35 -07001505 }
1506
1507 for (auto& containerPair : configuration)
1508 {
1509 auto& container = containerPair.second;
1510 if (!container)
1511 {
1512 continue;
1513 }
James Feist6ee7f772020-02-06 16:25:27 -08001514 BMCWEB_LOG_DEBUG << *container;
1515
Ed Tanous02cad962022-06-30 16:50:15 -07001516 const std::string& type = containerPair.first;
James Feist73df0db2019-03-25 15:29:35 -07001517
1518 for (nlohmann::json::iterator it = container->begin();
Manojkiran Eda17a897d2020-09-12 15:31:58 +05301519 it != container->end(); ++it)
James Feist73df0db2019-03-25 15:29:35 -07001520 {
1521 const auto& name = it.key();
James Feist6ee7f772020-02-06 16:25:27 -08001522 BMCWEB_LOG_DEBUG << "looking for " << name;
1523
James Feist73df0db2019-03-25 15:29:35 -07001524 auto pathItr =
1525 std::find_if(managedObj.begin(), managedObj.end(),
1526 [&name](const auto& obj) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001527 return boost::algorithm::ends_with(obj.first.str,
1528 "/" + name);
1529 });
Ed Tanousb9d36b42022-02-26 21:42:46 -08001530 dbus::utility::DBusPropertiesMap output;
James Feist73df0db2019-03-25 15:29:35 -07001531
1532 output.reserve(16); // The pid interface length
1533
1534 // determines if we're patching entity-manager or
1535 // creating a new object
1536 bool createNewObject = (pathItr == managedObj.end());
James Feist6ee7f772020-02-06 16:25:27 -08001537 BMCWEB_LOG_DEBUG << "Found = " << !createNewObject;
1538
James Feist73df0db2019-03-25 15:29:35 -07001539 std::string iface;
Ed Tanousea2b6702022-03-07 16:48:38 -08001540 if (!createNewObject)
James Feist73df0db2019-03-25 15:29:35 -07001541 {
Potin Lai8be2b5b2022-11-22 13:27:16 +08001542 bool findInterface = false;
Ed Tanousea2b6702022-03-07 16:48:38 -08001543 for (const auto& interface : pathItr->second)
James Feist73df0db2019-03-25 15:29:35 -07001544 {
Ed Tanousea2b6702022-03-07 16:48:38 -08001545 if (interface.first == pidConfigurationIface)
1546 {
1547 if (type == "PidControllers" ||
1548 type == "FanControllers")
1549 {
1550 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001551 findInterface = true;
1552 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001553 }
1554 }
1555 else if (interface.first == pidZoneConfigurationIface)
1556 {
1557 if (type == "FanZones")
1558 {
1559 iface = pidConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001560 findInterface = true;
1561 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001562 }
1563 }
1564 else if (interface.first == stepwiseConfigurationIface)
1565 {
1566 if (type == "StepwiseControllers")
1567 {
1568 iface = stepwiseConfigurationIface;
Potin Lai8be2b5b2022-11-22 13:27:16 +08001569 findInterface = true;
1570 break;
Ed Tanousea2b6702022-03-07 16:48:38 -08001571 }
1572 }
James Feist73df0db2019-03-25 15:29:35 -07001573 }
Potin Lai8be2b5b2022-11-22 13:27:16 +08001574
1575 // create new object if interface not found
1576 if (!findInterface)
1577 {
1578 createNewObject = true;
1579 }
James Feist73df0db2019-03-25 15:29:35 -07001580 }
James Feist6ee7f772020-02-06 16:25:27 -08001581
1582 if (createNewObject && it.value() == nullptr)
1583 {
Gunnar Mills4e0453b2020-07-08 14:00:30 -05001584 // can't delete a non-existent object
Ed Tanous1668ce62022-02-07 23:44:31 -08001585 messages::propertyValueNotInList(response->res,
1586 it.value().dump(), name);
James Feist6ee7f772020-02-06 16:25:27 -08001587 continue;
1588 }
1589
1590 std::string path;
1591 if (pathItr != managedObj.end())
1592 {
1593 path = pathItr->first.str;
1594 }
1595
James Feist73df0db2019-03-25 15:29:35 -07001596 BMCWEB_LOG_DEBUG << "Create new = " << createNewObject << "\n";
James Feiste69d9de2020-02-07 12:23:27 -08001597
1598 // arbitrary limit to avoid attacks
1599 constexpr const size_t controllerLimit = 500;
James Feist14b0b8d2020-02-12 11:52:07 -08001600 if (createNewObject && objectCount >= controllerLimit)
James Feiste69d9de2020-02-07 12:23:27 -08001601 {
1602 messages::resourceExhaustion(response->res, type);
1603 continue;
1604 }
Ed Tanousa170f272022-06-30 21:53:27 -07001605 std::string escaped = name;
1606 std::replace(escaped.begin(), escaped.end(), '_', ' ');
1607 output.emplace_back("Name", escaped);
James Feist73df0db2019-03-25 15:29:35 -07001608
1609 std::string chassis;
1610 CreatePIDRet ret = createPidInterface(
James Feist6ee7f772020-02-06 16:25:27 -08001611 response, type, it, path, managedObj, createNewObject,
1612 output, chassis, currentProfile);
James Feist73df0db2019-03-25 15:29:35 -07001613 if (ret == CreatePIDRet::fail)
1614 {
1615 return;
1616 }
Ed Tanous3174e4d2020-10-07 11:41:22 -07001617 if (ret == CreatePIDRet::del)
James Feist73df0db2019-03-25 15:29:35 -07001618 {
1619 continue;
1620 }
1621
1622 if (!createNewObject)
1623 {
1624 for (const auto& property : output)
1625 {
1626 crow::connections::systemBus->async_method_call(
1627 [response,
1628 propertyName{std::string(property.first)}](
1629 const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001630 if (ec)
1631 {
1632 BMCWEB_LOG_ERROR << "Error patching "
1633 << propertyName << ": " << ec;
1634 messages::internalError(response->res);
1635 return;
1636 }
1637 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001638 },
James Feist6ee7f772020-02-06 16:25:27 -08001639 "xyz.openbmc_project.EntityManager", path,
James Feist73df0db2019-03-25 15:29:35 -07001640 "org.freedesktop.DBus.Properties", "Set", iface,
1641 property.first, property.second);
1642 }
1643 }
1644 else
1645 {
1646 if (chassis.empty())
1647 {
1648 BMCWEB_LOG_ERROR << "Failed to get chassis from config";
Ed Tanousace85d62021-10-26 12:45:59 -07001649 messages::internalError(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001650 return;
1651 }
1652
1653 bool foundChassis = false;
1654 for (const auto& obj : managedObj)
1655 {
1656 if (boost::algorithm::ends_with(obj.first.str, chassis))
1657 {
1658 chassis = obj.first.str;
1659 foundChassis = true;
1660 break;
1661 }
1662 }
1663 if (!foundChassis)
1664 {
1665 BMCWEB_LOG_ERROR << "Failed to find chassis on dbus";
1666 messages::resourceMissingAtURI(
Ed Tanousace85d62021-10-26 12:45:59 -07001667 response->res,
1668 crow::utility::urlFromPieces("redfish", "v1",
1669 "Chassis", chassis));
James Feist73df0db2019-03-25 15:29:35 -07001670 return;
1671 }
1672
1673 crow::connections::systemBus->async_method_call(
1674 [response](const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001675 if (ec)
1676 {
1677 BMCWEB_LOG_ERROR << "Error Adding Pid Object "
1678 << ec;
1679 messages::internalError(response->res);
1680 return;
1681 }
1682 messages::success(response->res);
James Feist73df0db2019-03-25 15:29:35 -07001683 },
1684 "xyz.openbmc_project.EntityManager", chassis,
1685 "xyz.openbmc_project.AddObject", "AddObject", output);
1686 }
1687 }
1688 }
1689 }
Ed Tanous24b2fe82022-01-06 12:45:54 -08001690
1691 ~SetPIDValues()
1692 {
1693 try
1694 {
1695 pidSetDone();
1696 }
1697 catch (...)
1698 {
1699 BMCWEB_LOG_CRITICAL << "pidSetDone threw exception";
1700 }
1701 }
1702
zhanghch058d1b46d2021-04-01 11:18:24 +08001703 std::shared_ptr<bmcweb::AsyncResp> asyncResp;
James Feist73df0db2019-03-25 15:29:35 -07001704 std::vector<std::pair<std::string, std::optional<nlohmann::json>>>
1705 configuration;
1706 std::optional<std::string> profile;
1707 dbus::utility::ManagedObjectType managedObj;
1708 std::vector<std::string> supportedProfiles;
1709 std::string currentProfile;
1710 std::string profileConnection;
1711 std::string profilePath;
James Feist14b0b8d2020-02-12 11:52:07 -08001712 size_t objectCount = 0;
James Feist73df0db2019-03-25 15:29:35 -07001713};
James Feist83ff9ab2018-08-31 10:18:24 -07001714
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001715/**
1716 * @brief Retrieves BMC manager location data over DBus
1717 *
1718 * @param[in] aResp Shared pointer for completing asynchronous calls
1719 * @param[in] connectionName - service name
1720 * @param[in] path - object path
1721 * @return none
1722 */
zhanghch058d1b46d2021-04-01 11:18:24 +08001723inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001724 const std::string& connectionName,
1725 const std::string& path)
1726{
1727 BMCWEB_LOG_DEBUG << "Get BMC manager Location data.";
1728
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001729 sdbusplus::asio::getProperty<std::string>(
1730 *crow::connections::systemBus, connectionName, path,
1731 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode",
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001732 [aResp](const boost::system::error_code ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001733 const std::string& property) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001734 if (ec)
1735 {
1736 BMCWEB_LOG_DEBUG << "DBUS response error for "
1737 "Location";
1738 messages::internalError(aResp->res);
1739 return;
1740 }
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001741
Ed Tanous002d39b2022-05-31 08:59:27 -07001742 aResp->res.jsonValue["Location"]["PartLocation"]["ServiceLabel"] =
1743 property;
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001744 });
SunnySrivastava1984071d8fd2020-10-28 02:20:30 -05001745}
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001746// avoid name collision systems.hpp
1747inline void
1748 managerGetLastResetTime(const std::shared_ptr<bmcweb::AsyncResp>& aResp)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001749{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001750 BMCWEB_LOG_DEBUG << "Getting Manager Last Reset Time";
Ed Tanous52cc1122020-07-18 13:51:21 -07001751
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001752 sdbusplus::asio::getProperty<uint64_t>(
1753 *crow::connections::systemBus, "xyz.openbmc_project.State.BMC",
1754 "/xyz/openbmc_project/state/bmc0", "xyz.openbmc_project.State.BMC",
1755 "LastRebootTime",
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001756 [aResp](const boost::system::error_code ec,
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001757 const uint64_t lastResetTime) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001758 if (ec)
1759 {
1760 BMCWEB_LOG_DEBUG << "D-BUS response error " << ec;
1761 return;
1762 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001763
Ed Tanous002d39b2022-05-31 08:59:27 -07001764 // LastRebootTime is epoch time, in milliseconds
1765 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19
1766 uint64_t lastResetTimeStamp = lastResetTime / 1000;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001767
Ed Tanous002d39b2022-05-31 08:59:27 -07001768 // Convert to ISO 8601 standard
1769 aResp->res.jsonValue["LastResetTime"] =
Ed Tanous2b829372022-08-03 14:22:34 -07001770 redfish::time_utils::getDateTimeUint(lastResetTimeStamp);
Jonathan Doman1e1e5982021-06-11 09:36:17 -07001771 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001772}
1773
1774/**
1775 * @brief Set the running firmware image
1776 *
1777 * @param[i,o] aResp - Async response object
1778 * @param[i] runningFirmwareTarget - Image to make the running image
1779 *
1780 * @return void
1781 */
1782inline void
1783 setActiveFirmwareImage(const std::shared_ptr<bmcweb::AsyncResp>& aResp,
1784 const std::string& runningFirmwareTarget)
1785{
1786 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id>
1787 std::string::size_type idPos = runningFirmwareTarget.rfind('/');
1788 if (idPos == std::string::npos)
1789 {
1790 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1791 "@odata.id");
1792 BMCWEB_LOG_DEBUG << "Can't parse firmware ID!";
1793 return;
1794 }
1795 idPos++;
1796 if (idPos >= runningFirmwareTarget.size())
1797 {
1798 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1799 "@odata.id");
1800 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1801 return;
1802 }
1803 std::string firmwareId = runningFirmwareTarget.substr(idPos);
1804
1805 // Make sure the image is valid before setting priority
1806 crow::connections::systemBus->async_method_call(
Ed Tanous711ac7a2021-12-20 09:34:41 -08001807 [aResp, firmwareId,
1808 runningFirmwareTarget](const boost::system::error_code ec,
1809 dbus::utility::ManagedObjectType& subtree) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001810 if (ec)
1811 {
1812 BMCWEB_LOG_DEBUG << "D-Bus response error getting objects.";
1813 messages::internalError(aResp->res);
1814 return;
1815 }
1816
1817 if (subtree.empty())
1818 {
1819 BMCWEB_LOG_DEBUG << "Can't find image!";
1820 messages::internalError(aResp->res);
1821 return;
1822 }
1823
1824 bool foundImage = false;
Ed Tanous02cad962022-06-30 16:50:15 -07001825 for (const auto& object : subtree)
Ed Tanous002d39b2022-05-31 08:59:27 -07001826 {
1827 const std::string& path =
1828 static_cast<const std::string&>(object.first);
1829 std::size_t idPos2 = path.rfind('/');
1830
1831 if (idPos2 == std::string::npos)
1832 {
1833 continue;
1834 }
1835
1836 idPos2++;
1837 if (idPos2 >= path.size())
1838 {
1839 continue;
1840 }
1841
1842 if (path.substr(idPos2) == firmwareId)
1843 {
1844 foundImage = true;
1845 break;
1846 }
1847 }
1848
1849 if (!foundImage)
1850 {
1851 messages::propertyValueNotInList(aResp->res, runningFirmwareTarget,
1852 "@odata.id");
1853 BMCWEB_LOG_DEBUG << "Invalid firmware ID.";
1854 return;
1855 }
1856
1857 BMCWEB_LOG_DEBUG << "Setting firmware version " << firmwareId
1858 << " to priority 0.";
1859
1860 // Only support Immediate
1861 // An addition could be a Redfish Setting like
1862 // ActiveSoftwareImageApplyTime and support OnReset
1863 crow::connections::systemBus->async_method_call(
Ed Tanous8a592812022-06-04 09:06:59 -07001864 [aResp](const boost::system::error_code ec2) {
1865 if (ec2)
Gunnar Mills4bfefa72020-07-30 13:54:29 -05001866 {
Ed Tanous002d39b2022-05-31 08:59:27 -07001867 BMCWEB_LOG_DEBUG << "D-Bus response error setting.";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001868 messages::internalError(aResp->res);
1869 return;
1870 }
Ed Tanous002d39b2022-05-31 08:59:27 -07001871 doBMCGracefulRestart(aResp);
1872 },
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001873
Ed Tanous002d39b2022-05-31 08:59:27 -07001874 "xyz.openbmc_project.Software.BMC.Updater",
1875 "/xyz/openbmc_project/software/" + firmwareId,
1876 "org.freedesktop.DBus.Properties", "Set",
1877 "xyz.openbmc_project.Software.RedundancyPriority", "Priority",
1878 dbus::utility::DbusVariantType(static_cast<uint8_t>(0)));
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001879 },
1880 "xyz.openbmc_project.Software.BMC.Updater",
1881 "/xyz/openbmc_project/software", "org.freedesktop.DBus.ObjectManager",
1882 "GetManagedObjects");
1883}
Ed Tanous1abe55e2018-09-05 08:30:59 -07001884
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001885inline void setDateTime(std::shared_ptr<bmcweb::AsyncResp> aResp,
1886 std::string datetime)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001887{
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001888 BMCWEB_LOG_DEBUG << "Set date time: " << datetime;
Borawski.Lukasz9c3106852018-02-09 15:24:22 +01001889
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001890 std::stringstream stream(datetime);
1891 // Convert from ISO 8601 to boost local_time
1892 // (BMC only has time in UTC)
1893 boost::posix_time::ptime posixTime;
1894 boost::posix_time::ptime epoch(boost::gregorian::date(1970, 1, 1));
1895 // Facet gets deleted with the stringsteam
1896 auto ifc = std::make_unique<boost::local_time::local_time_input_facet>(
1897 "%Y-%m-%d %H:%M:%S%F %ZP");
1898 stream.imbue(std::locale(stream.getloc(), ifc.release()));
1899
1900 boost::local_time::local_date_time ldt(boost::local_time::not_a_date_time);
1901
1902 if (stream >> ldt)
Ed Tanous1abe55e2018-09-05 08:30:59 -07001903 {
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001904 posixTime = ldt.utc_time();
1905 boost::posix_time::time_duration dur = posixTime - epoch;
1906 uint64_t durMicroSecs = static_cast<uint64_t>(dur.total_microseconds());
1907 crow::connections::systemBus->async_method_call(
1908 [aResp{std::move(aResp)}, datetime{std::move(datetime)}](
1909 const boost::system::error_code ec) {
Ed Tanous002d39b2022-05-31 08:59:27 -07001910 if (ec)
1911 {
1912 BMCWEB_LOG_DEBUG << "Failed to set elapsed time. "
1913 "DBUS response error "
1914 << ec;
1915 messages::internalError(aResp->res);
1916 return;
1917 }
1918 aResp->res.jsonValue["DateTime"] = datetime;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001919 },
1920 "xyz.openbmc_project.Time.Manager", "/xyz/openbmc_project/time/bmc",
1921 "org.freedesktop.DBus.Properties", "Set",
1922 "xyz.openbmc_project.Time.EpochTime", "Elapsed",
Ed Tanous168e20c2021-12-13 14:39:53 -08001923 dbus::utility::DbusVariantType(durMicroSecs));
Ed Tanous1abe55e2018-09-05 08:30:59 -07001924 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001925 else
1926 {
1927 messages::propertyValueFormatError(aResp->res, datetime, "DateTime");
1928 return;
1929 }
1930}
1931
1932inline void requestRoutesManager(App& app)
1933{
1934 std::string uuid = persistent_data::getConfig().systemUuid;
1935
1936 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07001937 .privileges(redfish::privileges::getManager)
Ed Tanous002d39b2022-05-31 08:59:27 -07001938 .methods(boost::beast::http::verb::get)(
1939 [&app, uuid](const crow::Request& req,
Ed Tanous45ca1b82022-03-25 13:07:27 -07001940 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00001941 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07001942 {
1943 return;
1944 }
1945 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers/bmc";
Sui Chena51fc2d2022-07-14 17:21:53 -07001946 asyncResp->res.jsonValue["@odata.type"] = "#Manager.v1_14_0.Manager";
Ed Tanous002d39b2022-05-31 08:59:27 -07001947 asyncResp->res.jsonValue["Id"] = "bmc";
1948 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager";
1949 asyncResp->res.jsonValue["Description"] =
1950 "Baseboard Management Controller";
1951 asyncResp->res.jsonValue["PowerState"] = "On";
1952 asyncResp->res.jsonValue["Status"]["State"] = "Enabled";
1953 asyncResp->res.jsonValue["Status"]["Health"] = "OK";
Ed Tanous14766872022-03-15 10:44:42 -07001954
Ed Tanous002d39b2022-05-31 08:59:27 -07001955 asyncResp->res.jsonValue["ManagerType"] = "BMC";
1956 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid();
1957 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid;
1958 asyncResp->res.jsonValue["Model"] = "OpenBmc"; // TODO(ed), get model
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001959
Ed Tanous002d39b2022-05-31 08:59:27 -07001960 asyncResp->res.jsonValue["LogServices"]["@odata.id"] =
1961 "/redfish/v1/Managers/bmc/LogServices";
1962 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] =
1963 "/redfish/v1/Managers/bmc/NetworkProtocol";
1964 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] =
1965 "/redfish/v1/Managers/bmc/EthernetInterfaces";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001966
1967#ifdef BMCWEB_ENABLE_VM_NBDPROXY
Ed Tanous002d39b2022-05-31 08:59:27 -07001968 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] =
1969 "/redfish/v1/Managers/bmc/VirtualMedia";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001970#endif // BMCWEB_ENABLE_VM_NBDPROXY
1971
Ed Tanous002d39b2022-05-31 08:59:27 -07001972 // default oem data
1973 nlohmann::json& oem = asyncResp->res.jsonValue["Oem"];
1974 nlohmann::json& oemOpenbmc = oem["OpenBmc"];
1975 oem["@odata.type"] = "#OemManager.Oem";
1976 oem["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem";
1977 oemOpenbmc["@odata.type"] = "#OemManager.OpenBmc";
1978 oemOpenbmc["@odata.id"] = "/redfish/v1/Managers/bmc#/Oem/OpenBmc";
Ed Tanous14766872022-03-15 10:44:42 -07001979
Ed Tanous002d39b2022-05-31 08:59:27 -07001980 nlohmann::json::object_t certificates;
1981 certificates["@odata.id"] =
1982 "/redfish/v1/Managers/bmc/Truststore/Certificates";
1983 oemOpenbmc["Certificates"] = std::move(certificates);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001984
Ed Tanous002d39b2022-05-31 08:59:27 -07001985 // Manager.Reset (an action) can be many values, OpenBMC only
1986 // supports BMC reboot.
1987 nlohmann::json& managerReset =
1988 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"];
1989 managerReset["target"] =
1990 "/redfish/v1/Managers/bmc/Actions/Manager.Reset";
1991 managerReset["@Redfish.ActionInfo"] =
1992 "/redfish/v1/Managers/bmc/ResetActionInfo";
John Edward Broadbent7e860f12021-04-08 15:57:16 -07001993
Ed Tanous002d39b2022-05-31 08:59:27 -07001994 // ResetToDefaults (Factory Reset) has values like
1995 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported
1996 // on OpenBMC
1997 nlohmann::json& resetToDefaults =
1998 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"];
1999 resetToDefaults["target"] =
2000 "/redfish/v1/Managers/bmc/Actions/Manager.ResetToDefaults";
Ed Tanous613dabe2022-07-09 11:17:36 -07002001 resetToDefaults["ResetType@Redfish.AllowableValues"] =
2002 nlohmann::json::array_t({"ResetAll"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002003
Ed Tanous002d39b2022-05-31 08:59:27 -07002004 std::pair<std::string, std::string> redfishDateTimeOffset =
Ed Tanous2b829372022-08-03 14:22:34 -07002005 redfish::time_utils::getDateTimeOffsetNow();
Tejas Patil7c8c4052021-06-04 17:43:14 +05302006
Ed Tanous002d39b2022-05-31 08:59:27 -07002007 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first;
2008 asyncResp->res.jsonValue["DateTimeLocalOffset"] =
2009 redfishDateTimeOffset.second;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002010
Ed Tanous002d39b2022-05-31 08:59:27 -07002011 // TODO (Gunnar): Remove these one day since moved to ComputerSystem
2012 // Still used by OCP profiles
2013 // https://github.com/opencomputeproject/OCP-Profiles/issues/23
2014 // Fill in SerialConsole info
2015 asyncResp->res.jsonValue["SerialConsole"]["ServiceEnabled"] = true;
2016 asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15;
Ed Tanous613dabe2022-07-09 11:17:36 -07002017 asyncResp->res.jsonValue["SerialConsole"]["ConnectTypesSupported"] =
2018 nlohmann::json::array_t({"IPMI", "SSH"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002019#ifdef BMCWEB_ENABLE_KVM
Ed Tanous002d39b2022-05-31 08:59:27 -07002020 // Fill in GraphicalConsole info
2021 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true;
2022 asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] =
2023 4;
Ed Tanous613dabe2022-07-09 11:17:36 -07002024 asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] =
2025 nlohmann::json::array_t({"KVMIP"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002026#endif // BMCWEB_ENABLE_KVM
2027
Ed Tanous002d39b2022-05-31 08:59:27 -07002028 asyncResp->res.jsonValue["Links"]["ManagerForServers@odata.count"] = 1;
Ed Tanous14766872022-03-15 10:44:42 -07002029
Ed Tanous002d39b2022-05-31 08:59:27 -07002030 nlohmann::json::array_t managerForServers;
2031 nlohmann::json::object_t manager;
2032 manager["@odata.id"] = "/redfish/v1/Systems/system";
2033 managerForServers.push_back(std::move(manager));
2034
2035 asyncResp->res.jsonValue["Links"]["ManagerForServers"] =
2036 std::move(managerForServers);
2037
2038 auto health = std::make_shared<HealthPopulate>(asyncResp);
2039 health->isManagersHealth = true;
2040 health->populate();
2041
Willy Tueee00132022-06-14 14:53:17 -07002042 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose,
Ed Tanous002d39b2022-05-31 08:59:27 -07002043 "FirmwareVersion", true);
2044
2045 managerGetLastResetTime(asyncResp);
2046
Sui Chena51fc2d2022-07-14 17:21:53 -07002047 // ManagerDiagnosticData is added for all BMCs.
2048 nlohmann::json& managerDiagnosticData =
2049 asyncResp->res.jsonValue["ManagerDiagnosticData"];
2050 managerDiagnosticData["@odata.id"] =
2051 "/redfish/v1/Managers/bmc/ManagerDiagnosticData";
2052
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002053#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002054 auto pids = std::make_shared<GetPIDValues>(asyncResp);
2055 pids->run();
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002056#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002057
2058 getMainChassisId(asyncResp,
2059 [](const std::string& chassisId,
2060 const std::shared_ptr<bmcweb::AsyncResp>& aRsp) {
2061 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 1;
2062 nlohmann::json::array_t managerForChassis;
Ed Tanous8a592812022-06-04 09:06:59 -07002063 nlohmann::json::object_t managerObj;
2064 managerObj["@odata.id"] = "/redfish/v1/Chassis/" + chassisId;
2065 managerForChassis.push_back(std::move(managerObj));
Ed Tanous002d39b2022-05-31 08:59:27 -07002066 aRsp->res.jsonValue["Links"]["ManagerForChassis"] =
2067 std::move(managerForChassis);
2068 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] =
2069 "/redfish/v1/Chassis/" + chassisId;
2070 });
Ed Tanous14766872022-03-15 10:44:42 -07002071
Ed Tanous002d39b2022-05-31 08:59:27 -07002072 static bool started = false;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002073
Ed Tanous002d39b2022-05-31 08:59:27 -07002074 if (!started)
2075 {
2076 sdbusplus::asio::getProperty<double>(
2077 *crow::connections::systemBus, "org.freedesktop.systemd1",
2078 "/org/freedesktop/systemd1", "org.freedesktop.systemd1.Manager",
2079 "Progress",
2080 [asyncResp](const boost::system::error_code ec,
2081 const double& val) {
2082 if (ec)
2083 {
2084 BMCWEB_LOG_ERROR << "Error while getting progress";
2085 messages::internalError(asyncResp->res);
2086 return;
2087 }
2088 if (val < 1.0)
2089 {
2090 asyncResp->res.jsonValue["Status"]["State"] = "Starting";
2091 started = true;
2092 }
2093 });
2094 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002095
Ed Tanous002d39b2022-05-31 08:59:27 -07002096 crow::connections::systemBus->async_method_call(
2097 [asyncResp](
2098 const boost::system::error_code ec,
2099 const dbus::utility::MapperGetSubTreeResponse& subtree) {
2100 if (ec)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002101 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002102 BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec;
2103 return;
2104 }
2105 if (subtree.empty())
2106 {
2107 BMCWEB_LOG_DEBUG << "Can't find bmc D-Bus object!";
2108 return;
2109 }
2110 // Assume only 1 bmc D-Bus object
2111 // Throw an error if there is more than 1
2112 if (subtree.size() > 1)
2113 {
2114 BMCWEB_LOG_DEBUG << "Found more than 1 bmc D-Bus object!";
2115 messages::internalError(asyncResp->res);
2116 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002117 }
2118
Ed Tanous002d39b2022-05-31 08:59:27 -07002119 if (subtree[0].first.empty() || subtree[0].second.size() != 1)
2120 {
2121 BMCWEB_LOG_DEBUG << "Error getting bmc D-Bus object!";
2122 messages::internalError(asyncResp->res);
2123 return;
2124 }
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002125
Ed Tanous002d39b2022-05-31 08:59:27 -07002126 const std::string& path = subtree[0].first;
2127 const std::string& connectionName = subtree[0].second[0].first;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002128
Ed Tanous002d39b2022-05-31 08:59:27 -07002129 for (const auto& interfaceName : subtree[0].second[0].second)
2130 {
2131 if (interfaceName ==
2132 "xyz.openbmc_project.Inventory.Decorator.Asset")
2133 {
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002134
2135 sdbusplus::asio::getAllProperties(
2136 *crow::connections::systemBus, connectionName, path,
2137 "xyz.openbmc_project.Inventory.Decorator.Asset",
Ed Tanous8a592812022-06-04 09:06:59 -07002138 [asyncResp](const boost::system::error_code ec2,
Ed Tanousb9d36b42022-02-26 21:42:46 -08002139 const dbus::utility::DBusPropertiesMap&
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002140 propertiesList) {
Ed Tanous8a592812022-06-04 09:06:59 -07002141 if (ec2)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002142 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002143 BMCWEB_LOG_DEBUG << "Can't get bmc asset!";
2144 return;
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002145 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002146
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002147 const std::string* partNumber = nullptr;
2148 const std::string* serialNumber = nullptr;
2149 const std::string* manufacturer = nullptr;
2150 const std::string* model = nullptr;
2151 const std::string* sparePartNumber = nullptr;
2152
2153 const bool success = sdbusplus::unpackPropertiesNoThrow(
2154 dbus_utils::UnpackErrorPrinter(), propertiesList,
2155 "PartNumber", partNumber, "SerialNumber",
2156 serialNumber, "Manufacturer", manufacturer, "Model",
2157 model, "SparePartNumber", sparePartNumber);
2158
2159 if (!success)
2160 {
2161 messages::internalError(asyncResp->res);
2162 return;
Ed Tanous002d39b2022-05-31 08:59:27 -07002163 }
Krzysztof Grobelnyfac6e532022-08-04 12:42:45 +02002164
2165 if (partNumber != nullptr)
2166 {
2167 asyncResp->res.jsonValue["PartNumber"] =
2168 *partNumber;
2169 }
2170
2171 if (serialNumber != nullptr)
2172 {
2173 asyncResp->res.jsonValue["SerialNumber"] =
2174 *serialNumber;
2175 }
2176
2177 if (manufacturer != nullptr)
2178 {
2179 asyncResp->res.jsonValue["Manufacturer"] =
2180 *manufacturer;
2181 }
2182
2183 if (model != nullptr)
2184 {
2185 asyncResp->res.jsonValue["Model"] = *model;
2186 }
2187
2188 if (sparePartNumber != nullptr)
2189 {
2190 asyncResp->res.jsonValue["SparePartNumber"] =
2191 *sparePartNumber;
2192 }
2193 });
Ed Tanous002d39b2022-05-31 08:59:27 -07002194 }
2195 else if (interfaceName ==
2196 "xyz.openbmc_project.Inventory.Decorator.LocationCode")
2197 {
2198 getLocation(asyncResp, connectionName, path);
2199 }
2200 }
2201 },
2202 "xyz.openbmc_project.ObjectMapper",
2203 "/xyz/openbmc_project/object_mapper",
2204 "xyz.openbmc_project.ObjectMapper", "GetSubTree",
2205 "/xyz/openbmc_project/inventory", int32_t(0),
2206 std::array<const char*, 1>{
2207 "xyz.openbmc_project.Inventory.Item.Bmc"});
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002208 });
2209
2210 BMCWEB_ROUTE(app, "/redfish/v1/Managers/bmc/")
Ed Tanoused398212021-06-09 17:05:54 -07002211 .privileges(redfish::privileges::patchManager)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002212 .methods(boost::beast::http::verb::patch)(
2213 [&app](const crow::Request& req,
2214 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002215 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002216 {
2217 return;
2218 }
2219 std::optional<nlohmann::json> oem;
2220 std::optional<nlohmann::json> links;
2221 std::optional<std::string> datetime;
2222
2223 if (!json_util::readJsonPatch(req, asyncResp->res, "Oem", oem,
2224 "DateTime", datetime, "Links", links))
2225 {
2226 return;
2227 }
2228
2229 if (oem)
2230 {
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002231#ifdef BMCWEB_ENABLE_REDFISH_OEM_MANAGER_FAN_DATA
Ed Tanous002d39b2022-05-31 08:59:27 -07002232 std::optional<nlohmann::json> openbmc;
2233 if (!redfish::json_util::readJson(*oem, asyncResp->res, "OpenBmc",
2234 openbmc))
2235 {
2236 BMCWEB_LOG_ERROR
2237 << "Illegal Property "
2238 << oem->dump(2, ' ', true,
2239 nlohmann::json::error_handler_t::replace);
2240 return;
2241 }
2242 if (openbmc)
2243 {
2244 std::optional<nlohmann::json> fan;
2245 if (!redfish::json_util::readJson(*openbmc, asyncResp->res,
2246 "Fan", fan))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002247 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002248 BMCWEB_LOG_ERROR
2249 << "Illegal Property "
2250 << openbmc->dump(
2251 2, ' ', true,
2252 nlohmann::json::error_handler_t::replace);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002253 return;
2254 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002255 if (fan)
2256 {
2257 auto pid = std::make_shared<SetPIDValues>(asyncResp, *fan);
2258 pid->run();
2259 }
2260 }
Gunnar Mills54dce7f2022-08-05 17:01:32 +00002261#else
2262 messages::propertyUnknown(asyncResp->res, "Oem");
2263 return;
2264#endif
Ed Tanous002d39b2022-05-31 08:59:27 -07002265 }
2266 if (links)
2267 {
2268 std::optional<nlohmann::json> activeSoftwareImage;
2269 if (!redfish::json_util::readJson(*links, asyncResp->res,
2270 "ActiveSoftwareImage",
2271 activeSoftwareImage))
2272 {
2273 return;
2274 }
2275 if (activeSoftwareImage)
2276 {
2277 std::optional<std::string> odataId;
2278 if (!json_util::readJson(*activeSoftwareImage, asyncResp->res,
2279 "@odata.id", odataId))
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002280 {
Ed Tanous45ca1b82022-03-25 13:07:27 -07002281 return;
2282 }
2283
Ed Tanous002d39b2022-05-31 08:59:27 -07002284 if (odataId)
Ed Tanous45ca1b82022-03-25 13:07:27 -07002285 {
Ed Tanous002d39b2022-05-31 08:59:27 -07002286 setActiveFirmwareImage(asyncResp, *odataId);
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002287 }
Ed Tanous002d39b2022-05-31 08:59:27 -07002288 }
2289 }
2290 if (datetime)
2291 {
2292 setDateTime(asyncResp, std::move(*datetime));
2293 }
2294 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002295}
2296
2297inline void requestRoutesManagerCollection(App& app)
2298{
2299 BMCWEB_ROUTE(app, "/redfish/v1/Managers/")
Ed Tanoused398212021-06-09 17:05:54 -07002300 .privileges(redfish::privileges::getManagerCollection)
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002301 .methods(boost::beast::http::verb::get)(
Ed Tanous45ca1b82022-03-25 13:07:27 -07002302 [&app](const crow::Request& req,
2303 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) {
Carson Labrado3ba00072022-06-06 19:40:56 +00002304 if (!redfish::setUpRedfishRoute(app, req, asyncResp))
Ed Tanous002d39b2022-05-31 08:59:27 -07002305 {
2306 return;
2307 }
2308 // Collections don't include the static data added by SubRoute
2309 // because it has a duplicate entry for members
2310 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers";
2311 asyncResp->res.jsonValue["@odata.type"] =
2312 "#ManagerCollection.ManagerCollection";
2313 asyncResp->res.jsonValue["Name"] = "Manager Collection";
2314 asyncResp->res.jsonValue["Members@odata.count"] = 1;
2315 nlohmann::json::array_t members;
2316 nlohmann::json& bmc = members.emplace_back();
2317 bmc["@odata.id"] = "/redfish/v1/Managers/bmc";
2318 asyncResp->res.jsonValue["Members"] = std::move(members);
2319 });
John Edward Broadbent7e860f12021-04-08 15:57:16 -07002320}
Ed Tanous1abe55e2018-09-05 08:30:59 -07002321} // namespace redfish