1 // SPDX-License-Identifier: Apache-2.0 2 // SPDX-FileCopyrightText: Copyright OpenBMC Authors 3 // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation 4 #pragma once 5 6 #include "bmcweb_config.h" 7 8 #include "app.hpp" 9 #include "async_resp.hpp" 10 #include "dbus_singleton.hpp" 11 #include "dbus_utility.hpp" 12 #include "error_messages.hpp" 13 #include "generated/enums/action_info.hpp" 14 #include "generated/enums/manager.hpp" 15 #include "generated/enums/resource.hpp" 16 #include "http_request.hpp" 17 #include "logging.hpp" 18 #include "persistent_data.hpp" 19 #include "query.hpp" 20 #include "redfish.hpp" 21 #include "redfish_util.hpp" 22 #include "registries/privilege_registry.hpp" 23 #include "utils/dbus_utils.hpp" 24 #include "utils/json_utils.hpp" 25 #include "utils/sw_utils.hpp" 26 #include "utils/systemd_utils.hpp" 27 #include "utils/time_utils.hpp" 28 29 #include <systemd/sd-bus.h> 30 31 #include <boost/beast/http/status.hpp> 32 #include <boost/beast/http/verb.hpp> 33 #include <boost/system/error_code.hpp> 34 #include <boost/url/format.hpp> 35 #include <boost/url/url.hpp> 36 #include <nlohmann/json.hpp> 37 #include <sdbusplus/asio/property.hpp> 38 #include <sdbusplus/message.hpp> 39 #include <sdbusplus/message/native_types.hpp> 40 #include <sdbusplus/unpack_properties.hpp> 41 42 #include <array> 43 #include <cstddef> 44 #include <cstdint> 45 #include <format> 46 #include <functional> 47 #include <map> 48 #include <memory> 49 #include <optional> 50 #include <ranges> 51 #include <string> 52 #include <string_view> 53 #include <utility> 54 #include <vector> 55 56 namespace redfish 57 { 58 59 inline std::string getBMCUpdateServiceName() 60 { 61 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) 62 { 63 return "xyz.openbmc_project.Software.Manager"; 64 } 65 return "xyz.openbmc_project.Software.BMC.Updater"; 66 } 67 68 inline std::string getBMCUpdateServicePath() 69 { 70 if constexpr (BMCWEB_REDFISH_UPDATESERVICE_USE_DBUS) 71 { 72 return "/xyz/openbmc_project/software/bmc"; 73 } 74 return "/xyz/openbmc_project/software"; 75 } 76 77 /** 78 * Function reboots the BMC. 79 * 80 * @param[in] asyncResp - Shared pointer for completing asynchronous calls 81 */ 82 inline void doBMCGracefulRestart( 83 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 84 { 85 const char* processName = "xyz.openbmc_project.State.BMC"; 86 const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 87 const char* interfaceName = "xyz.openbmc_project.State.BMC"; 88 const std::string& propertyValue = 89 "xyz.openbmc_project.State.BMC.Transition.Reboot"; 90 const char* destProperty = "RequestedBMCTransition"; 91 92 // Create the D-Bus variant for D-Bus call. 93 sdbusplus::asio::setProperty( 94 *crow::connections::systemBus, processName, objectPath, interfaceName, 95 destProperty, propertyValue, 96 [asyncResp](const boost::system::error_code& ec) { 97 // Use "Set" method to set the property value. 98 if (ec) 99 { 100 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 101 messages::internalError(asyncResp->res); 102 return; 103 } 104 105 messages::success(asyncResp->res); 106 }); 107 } 108 109 inline void doBMCForceRestart( 110 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 111 { 112 const char* processName = "xyz.openbmc_project.State.BMC"; 113 const char* objectPath = "/xyz/openbmc_project/state/bmc0"; 114 const char* interfaceName = "xyz.openbmc_project.State.BMC"; 115 const std::string& propertyValue = 116 "xyz.openbmc_project.State.BMC.Transition.HardReboot"; 117 const char* destProperty = "RequestedBMCTransition"; 118 119 // Create the D-Bus variant for D-Bus call. 120 sdbusplus::asio::setProperty( 121 *crow::connections::systemBus, processName, objectPath, interfaceName, 122 destProperty, propertyValue, 123 [asyncResp](const boost::system::error_code& ec) { 124 // Use "Set" method to set the property value. 125 if (ec) 126 { 127 BMCWEB_LOG_DEBUG("[Set] Bad D-Bus request error: {}", ec); 128 messages::internalError(asyncResp->res); 129 return; 130 } 131 132 messages::success(asyncResp->res); 133 }); 134 } 135 136 /** 137 * ManagerResetAction class supports the POST method for the Reset (reboot) 138 * action. 139 */ 140 inline void requestRoutesManagerResetAction(App& app) 141 { 142 /** 143 * Function handles POST method request. 144 * Analyzes POST body before sending Reset (Reboot) request data to D-Bus. 145 * OpenBMC supports ResetType "GracefulRestart" and "ForceRestart". 146 */ 147 148 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/Actions/Manager.Reset/") 149 .privileges(redfish::privileges::postManager) 150 .methods(boost::beast::http::verb::post)( 151 [&app](const crow::Request& req, 152 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 153 const std::string& managerId) { 154 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 155 { 156 return; 157 } 158 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 159 { 160 messages::resourceNotFound(asyncResp->res, "Manager", 161 managerId); 162 return; 163 } 164 165 BMCWEB_LOG_DEBUG("Post Manager Reset."); 166 167 std::string resetType; 168 169 if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", 170 resetType)) 171 { 172 return; 173 } 174 175 if (resetType == "GracefulRestart") 176 { 177 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 178 doBMCGracefulRestart(asyncResp); 179 return; 180 } 181 if (resetType == "ForceRestart") 182 { 183 BMCWEB_LOG_DEBUG("Proceeding with {}", resetType); 184 doBMCForceRestart(asyncResp); 185 return; 186 } 187 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", 188 resetType); 189 messages::actionParameterNotSupported(asyncResp->res, resetType, 190 "ResetType"); 191 192 return; 193 }); 194 } 195 196 /** 197 * ManagerResetToDefaultsAction class supports POST method for factory reset 198 * action. 199 */ 200 inline void requestRoutesManagerResetToDefaultsAction(App& app) 201 { 202 /** 203 * Function handles ResetToDefaults POST method request. 204 * 205 * Analyzes POST body message and factory resets BMC by calling 206 * BMC code updater factory reset followed by a BMC reboot. 207 * 208 * BMC code updater factory reset wipes the whole BMC read-write 209 * filesystem which includes things like the network settings. 210 * 211 * OpenBMC only supports ResetType "ResetAll". 212 */ 213 214 BMCWEB_ROUTE(app, 215 "/redfish/v1/Managers/<str>/Actions/Manager.ResetToDefaults/") 216 .privileges(redfish::privileges::postManager) 217 .methods(boost::beast::http::verb::post)( 218 [&app](const crow::Request& req, 219 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 220 const std::string& managerId) { 221 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 222 { 223 return; 224 } 225 226 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 227 { 228 messages::resourceNotFound(asyncResp->res, "Manager", 229 managerId); 230 return; 231 } 232 233 BMCWEB_LOG_DEBUG("Post ResetToDefaults."); 234 235 std::optional<std::string> resetType; 236 237 if (!json_util::readJsonAction( // 238 req, asyncResp->res, // 239 "ResetType", resetType // 240 )) 241 { 242 BMCWEB_LOG_DEBUG("Missing property ResetType."); 243 244 messages::actionParameterMissing( 245 asyncResp->res, "ResetToDefaults", "ResetType"); 246 return; 247 } 248 249 if (resetType != "ResetAll") 250 { 251 BMCWEB_LOG_DEBUG("Invalid property value for ResetType: {}", 252 *resetType); 253 messages::actionParameterNotSupported( 254 asyncResp->res, *resetType, "ResetType"); 255 return; 256 } 257 258 crow::connections::systemBus->async_method_call( 259 [asyncResp](const boost::system::error_code& ec) { 260 if (ec) 261 { 262 BMCWEB_LOG_DEBUG("Failed to ResetToDefaults: {}", 263 ec); 264 messages::internalError(asyncResp->res); 265 return; 266 } 267 // Factory Reset doesn't actually happen until a reboot 268 // Can't erase what the BMC is running on 269 doBMCGracefulRestart(asyncResp); 270 }, 271 getBMCUpdateServiceName(), getBMCUpdateServicePath(), 272 "xyz.openbmc_project.Common.FactoryReset", "Reset"); 273 }); 274 } 275 276 /** 277 * ManagerResetActionInfo derived class for delivering Manager 278 * ResetType AllowableValues using ResetInfo schema. 279 */ 280 inline void requestRoutesManagerResetActionInfo(App& app) 281 { 282 /** 283 * Functions triggers appropriate requests on DBus 284 */ 285 286 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/ResetActionInfo/") 287 .privileges(redfish::privileges::getActionInfo) 288 .methods(boost::beast::http::verb::get)( 289 [&app](const crow::Request& req, 290 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 291 const std::string& managerId) { 292 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 293 { 294 return; 295 } 296 297 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 298 { 299 messages::resourceNotFound(asyncResp->res, "Manager", 300 managerId); 301 return; 302 } 303 304 asyncResp->res.jsonValue["@odata.type"] = 305 "#ActionInfo.v1_1_2.ActionInfo"; 306 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 307 "/redfish/v1/Managers/{}/ResetActionInfo", 308 BMCWEB_REDFISH_MANAGER_URI_NAME); 309 asyncResp->res.jsonValue["Name"] = "Reset Action Info"; 310 asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; 311 nlohmann::json::object_t parameter; 312 parameter["Name"] = "ResetType"; 313 parameter["Required"] = true; 314 parameter["DataType"] = action_info::ParameterTypes::String; 315 316 nlohmann::json::array_t allowableValues; 317 allowableValues.emplace_back("GracefulRestart"); 318 allowableValues.emplace_back("ForceRestart"); 319 parameter["AllowableValues"] = std::move(allowableValues); 320 321 nlohmann::json::array_t parameters; 322 parameters.emplace_back(std::move(parameter)); 323 324 asyncResp->res.jsonValue["Parameters"] = std::move(parameters); 325 }); 326 } 327 328 /** 329 * @brief Retrieves BMC manager location data over DBus 330 * 331 * @param[in] asyncResp Shared pointer for completing asynchronous calls 332 * @param[in] connectionName - service name 333 * @param[in] path - object path 334 * @return none 335 */ 336 inline void getLocation(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 337 const std::string& connectionName, 338 const std::string& path) 339 { 340 BMCWEB_LOG_DEBUG("Get BMC manager Location data."); 341 342 dbus::utility::getProperty<std::string>( 343 connectionName, path, 344 "xyz.openbmc_project.Inventory.Decorator.LocationCode", "LocationCode", 345 [asyncResp](const boost::system::error_code& ec, 346 const std::string& property) { 347 if (ec) 348 { 349 BMCWEB_LOG_DEBUG("DBUS response error for " 350 "Location"); 351 messages::internalError(asyncResp->res); 352 return; 353 } 354 355 asyncResp->res 356 .jsonValue["Location"]["PartLocation"]["ServiceLabel"] = 357 property; 358 }); 359 } 360 // avoid name collision systems.hpp 361 inline void managerGetLastResetTime( 362 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 363 { 364 BMCWEB_LOG_DEBUG("Getting Manager Last Reset Time"); 365 366 dbus::utility::getProperty<uint64_t>( 367 "xyz.openbmc_project.State.BMC", "/xyz/openbmc_project/state/bmc0", 368 "xyz.openbmc_project.State.BMC", "LastRebootTime", 369 [asyncResp](const boost::system::error_code& ec, 370 const uint64_t lastResetTime) { 371 if (ec) 372 { 373 BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); 374 return; 375 } 376 377 // LastRebootTime is epoch time, in milliseconds 378 // https://github.com/openbmc/phosphor-dbus-interfaces/blob/7f9a128eb9296e926422ddc312c148b625890bb6/xyz/openbmc_project/State/BMC.interface.yaml#L19 379 uint64_t lastResetTimeStamp = lastResetTime / 1000; 380 381 // Convert to ISO 8601 standard 382 asyncResp->res.jsonValue["LastResetTime"] = 383 redfish::time_utils::getDateTimeUint(lastResetTimeStamp); 384 }); 385 } 386 387 /** 388 * @brief Set the running firmware image 389 * 390 * @param[i,o] asyncResp - Async response object 391 * @param[i] runningFirmwareTarget - Image to make the running image 392 * 393 * @return void 394 */ 395 inline void setActiveFirmwareImage( 396 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 397 const std::string& runningFirmwareTarget) 398 { 399 // Get the Id from /redfish/v1/UpdateService/FirmwareInventory/<Id> 400 std::string::size_type idPos = runningFirmwareTarget.rfind('/'); 401 if (idPos == std::string::npos) 402 { 403 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 404 "@odata.id"); 405 BMCWEB_LOG_DEBUG("Can't parse firmware ID!"); 406 return; 407 } 408 idPos++; 409 if (idPos >= runningFirmwareTarget.size()) 410 { 411 messages::propertyValueNotInList(asyncResp->res, runningFirmwareTarget, 412 "@odata.id"); 413 BMCWEB_LOG_DEBUG("Invalid firmware ID."); 414 return; 415 } 416 std::string firmwareId = runningFirmwareTarget.substr(idPos); 417 418 // Make sure the image is valid before setting priority 419 sdbusplus::message::object_path objPath("/xyz/openbmc_project/software"); 420 dbus::utility::getManagedObjects( 421 getBMCUpdateServiceName(), objPath, 422 [asyncResp, firmwareId, runningFirmwareTarget]( 423 const boost::system::error_code& ec, 424 const dbus::utility::ManagedObjectType& subtree) { 425 if (ec) 426 { 427 BMCWEB_LOG_DEBUG("D-Bus response error getting objects."); 428 messages::internalError(asyncResp->res); 429 return; 430 } 431 432 if (subtree.empty()) 433 { 434 BMCWEB_LOG_DEBUG("Can't find image!"); 435 messages::internalError(asyncResp->res); 436 return; 437 } 438 439 bool foundImage = false; 440 for (const auto& object : subtree) 441 { 442 const std::string& path = 443 static_cast<const std::string&>(object.first); 444 std::size_t idPos2 = path.rfind('/'); 445 446 if (idPos2 == std::string::npos) 447 { 448 continue; 449 } 450 451 idPos2++; 452 if (idPos2 >= path.size()) 453 { 454 continue; 455 } 456 457 if (path.substr(idPos2) == firmwareId) 458 { 459 foundImage = true; 460 break; 461 } 462 } 463 464 if (!foundImage) 465 { 466 messages::propertyValueNotInList( 467 asyncResp->res, runningFirmwareTarget, "@odata.id"); 468 BMCWEB_LOG_DEBUG("Invalid firmware ID."); 469 return; 470 } 471 472 BMCWEB_LOG_DEBUG("Setting firmware version {} to priority 0.", 473 firmwareId); 474 475 // Only support Immediate 476 // An addition could be a Redfish Setting like 477 // ActiveSoftwareImageApplyTime and support OnReset 478 sdbusplus::asio::setProperty( 479 *crow::connections::systemBus, getBMCUpdateServiceName(), 480 "/xyz/openbmc_project/software/" + firmwareId, 481 "xyz.openbmc_project.Software.RedundancyPriority", "Priority", 482 static_cast<uint8_t>(0), 483 [asyncResp](const boost::system::error_code& ec2) { 484 if (ec2) 485 { 486 BMCWEB_LOG_DEBUG("D-Bus response error setting."); 487 messages::internalError(asyncResp->res); 488 return; 489 } 490 doBMCGracefulRestart(asyncResp); 491 }); 492 }); 493 } 494 495 inline void afterSetDateTime( 496 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 497 const boost::system::error_code& ec, const sdbusplus::message_t& msg) 498 { 499 if (ec) 500 { 501 BMCWEB_LOG_DEBUG("Failed to set elapsed time. DBUS response error {}", 502 ec); 503 const sd_bus_error* dbusError = msg.get_error(); 504 if (dbusError != nullptr) 505 { 506 std::string_view errorName(dbusError->name); 507 if (errorName == 508 "org.freedesktop.timedate1.AutomaticTimeSyncEnabled") 509 { 510 BMCWEB_LOG_DEBUG("Setting conflict"); 511 messages::propertyValueConflict( 512 asyncResp->res, "DateTime", 513 "Managers/NetworkProtocol/NTPProcotolEnabled"); 514 return; 515 } 516 } 517 messages::internalError(asyncResp->res); 518 return; 519 } 520 asyncResp->res.result(boost::beast::http::status::no_content); 521 } 522 523 inline void setDateTime(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 524 const std::string& datetime) 525 { 526 BMCWEB_LOG_DEBUG("Set date time: {}", datetime); 527 528 std::optional<redfish::time_utils::usSinceEpoch> us = 529 redfish::time_utils::dateStringToEpoch(datetime); 530 if (!us) 531 { 532 messages::propertyValueFormatError(asyncResp->res, datetime, 533 "DateTime"); 534 return; 535 } 536 // Set the absolute datetime 537 bool relative = false; 538 bool interactive = false; 539 crow::connections::systemBus->async_method_call( 540 [asyncResp](const boost::system::error_code& ec, 541 const sdbusplus::message_t& msg) { 542 afterSetDateTime(asyncResp, ec, msg); 543 }, 544 "org.freedesktop.timedate1", "/org/freedesktop/timedate1", 545 "org.freedesktop.timedate1", "SetTime", us->count(), relative, 546 interactive); 547 } 548 549 inline void checkForQuiesced( 550 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) 551 { 552 dbus::utility::getProperty<std::string>( 553 "org.freedesktop.systemd1", 554 "/org/freedesktop/systemd1/unit/obmc-bmc-service-quiesce@0.target", 555 "org.freedesktop.systemd1.Unit", "ActiveState", 556 [asyncResp](const boost::system::error_code& ec, 557 const std::string& val) { 558 if (!ec) 559 { 560 if (val == "active") 561 { 562 asyncResp->res.jsonValue["Status"]["Health"] = 563 resource::Health::Critical; 564 asyncResp->res.jsonValue["Status"]["State"] = 565 resource::State::Quiesced; 566 return; 567 } 568 } 569 asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; 570 asyncResp->res.jsonValue["Status"]["State"] = 571 resource::State::Enabled; 572 }); 573 } 574 575 inline void requestRoutesManager(App& app) 576 { 577 std::string uuid = persistent_data::getConfig().systemUuid; 578 579 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") 580 .privileges(redfish::privileges::getManager) 581 .methods( 582 boost::beast::http::verb:: 583 get)([&app, 584 uuid](const crow::Request& req, 585 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 586 const std::string& managerId) { 587 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 588 { 589 return; 590 } 591 592 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 593 { 594 messages::resourceNotFound(asyncResp->res, "Manager", 595 managerId); 596 return; 597 } 598 599 asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( 600 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); 601 asyncResp->res.jsonValue["@odata.type"] = 602 "#Manager.v1_14_0.Manager"; 603 asyncResp->res.jsonValue["Id"] = BMCWEB_REDFISH_MANAGER_URI_NAME; 604 asyncResp->res.jsonValue["Name"] = "OpenBmc Manager"; 605 asyncResp->res.jsonValue["Description"] = 606 "Baseboard Management Controller"; 607 asyncResp->res.jsonValue["PowerState"] = resource::PowerState::On; 608 609 asyncResp->res.jsonValue["ManagerType"] = manager::ManagerType::BMC; 610 asyncResp->res.jsonValue["UUID"] = systemd_utils::getUuid(); 611 asyncResp->res.jsonValue["ServiceEntryPointUUID"] = uuid; 612 asyncResp->res.jsonValue["Model"] = 613 "OpenBmc"; // TODO(ed), get model 614 615 asyncResp->res.jsonValue["LogServices"]["@odata.id"] = 616 boost::urls::format("/redfish/v1/Managers/{}/LogServices", 617 BMCWEB_REDFISH_MANAGER_URI_NAME); 618 asyncResp->res.jsonValue["NetworkProtocol"]["@odata.id"] = 619 boost::urls::format("/redfish/v1/Managers/{}/NetworkProtocol", 620 BMCWEB_REDFISH_MANAGER_URI_NAME); 621 asyncResp->res.jsonValue["EthernetInterfaces"]["@odata.id"] = 622 boost::urls::format( 623 "/redfish/v1/Managers/{}/EthernetInterfaces", 624 BMCWEB_REDFISH_MANAGER_URI_NAME); 625 626 if constexpr (BMCWEB_VM_NBDPROXY) 627 { 628 asyncResp->res.jsonValue["VirtualMedia"]["@odata.id"] = 629 boost::urls::format("/redfish/v1/Managers/{}/VirtualMedia", 630 BMCWEB_REDFISH_MANAGER_URI_NAME); 631 } 632 633 // Manager.Reset (an action) can be many values, OpenBMC only 634 // supports BMC reboot. 635 nlohmann::json& managerReset = 636 asyncResp->res.jsonValue["Actions"]["#Manager.Reset"]; 637 managerReset["target"] = boost::urls::format( 638 "/redfish/v1/Managers/{}/Actions/Manager.Reset", 639 BMCWEB_REDFISH_MANAGER_URI_NAME); 640 managerReset["@Redfish.ActionInfo"] = 641 boost::urls::format("/redfish/v1/Managers/{}/ResetActionInfo", 642 BMCWEB_REDFISH_MANAGER_URI_NAME); 643 644 // ResetToDefaults (Factory Reset) has values like 645 // PreserveNetworkAndUsers and PreserveNetwork that aren't supported 646 // on OpenBMC 647 nlohmann::json& resetToDefaults = 648 asyncResp->res.jsonValue["Actions"]["#Manager.ResetToDefaults"]; 649 resetToDefaults["target"] = boost::urls::format( 650 "/redfish/v1/Managers/{}/Actions/Manager.ResetToDefaults", 651 BMCWEB_REDFISH_MANAGER_URI_NAME); 652 resetToDefaults["ResetType@Redfish.AllowableValues"] = 653 nlohmann::json::array_t({"ResetAll"}); 654 655 std::pair<std::string, std::string> redfishDateTimeOffset = 656 redfish::time_utils::getDateTimeOffsetNow(); 657 658 asyncResp->res.jsonValue["DateTime"] = redfishDateTimeOffset.first; 659 asyncResp->res.jsonValue["DateTimeLocalOffset"] = 660 redfishDateTimeOffset.second; 661 662 if constexpr (BMCWEB_KVM) 663 { 664 // Fill in GraphicalConsole info 665 asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = 666 true; 667 asyncResp->res 668 .jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = 4; 669 asyncResp->res 670 .jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = 671 nlohmann::json::array_t({"KVMIP"}); 672 } 673 if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) 674 { 675 asyncResp->res 676 .jsonValue["Links"]["ManagerForServers@odata.count"] = 1; 677 678 nlohmann::json::array_t managerForServers; 679 nlohmann::json::object_t manager; 680 manager["@odata.id"] = std::format( 681 "/redfish/v1/Systems/{}", BMCWEB_REDFISH_SYSTEM_URI_NAME); 682 managerForServers.emplace_back(std::move(manager)); 683 684 asyncResp->res.jsonValue["Links"]["ManagerForServers"] = 685 std::move(managerForServers); 686 } 687 688 sw_util::populateSoftwareInformation(asyncResp, sw_util::bmcPurpose, 689 "FirmwareVersion", true); 690 691 managerGetLastResetTime(asyncResp); 692 693 // ManagerDiagnosticData is added for all BMCs. 694 nlohmann::json& managerDiagnosticData = 695 asyncResp->res.jsonValue["ManagerDiagnosticData"]; 696 managerDiagnosticData["@odata.id"] = boost::urls::format( 697 "/redfish/v1/Managers/{}/ManagerDiagnosticData", 698 BMCWEB_REDFISH_MANAGER_URI_NAME); 699 700 getMainChassisId(asyncResp, [](const std::string& chassisId, 701 const std::shared_ptr< 702 bmcweb::AsyncResp>& aRsp) { 703 aRsp->res.jsonValue["Links"]["ManagerForChassis@odata.count"] = 704 1; 705 nlohmann::json::array_t managerForChassis; 706 nlohmann::json::object_t managerObj; 707 boost::urls::url chassiUrl = 708 boost::urls::format("/redfish/v1/Chassis/{}", chassisId); 709 managerObj["@odata.id"] = chassiUrl; 710 managerForChassis.emplace_back(std::move(managerObj)); 711 aRsp->res.jsonValue["Links"]["ManagerForChassis"] = 712 std::move(managerForChassis); 713 aRsp->res.jsonValue["Links"]["ManagerInChassis"]["@odata.id"] = 714 chassiUrl; 715 }); 716 717 dbus::utility::getProperty<double>( 718 "org.freedesktop.systemd1", "/org/freedesktop/systemd1", 719 "org.freedesktop.systemd1.Manager", "Progress", 720 [asyncResp](const boost::system::error_code& ec, double val) { 721 if (ec) 722 { 723 BMCWEB_LOG_ERROR("Error while getting progress"); 724 messages::internalError(asyncResp->res); 725 return; 726 } 727 if (val < 1.0) 728 { 729 asyncResp->res.jsonValue["Status"]["Health"] = 730 resource::Health::OK; 731 asyncResp->res.jsonValue["Status"]["State"] = 732 resource::State::Starting; 733 return; 734 } 735 checkForQuiesced(asyncResp); 736 }); 737 738 constexpr std::array<std::string_view, 1> interfaces = { 739 "xyz.openbmc_project.Inventory.Item.Bmc"}; 740 dbus::utility::getSubTree( 741 "/xyz/openbmc_project/inventory", 0, interfaces, 742 [asyncResp]( 743 const boost::system::error_code& ec, 744 const dbus::utility::MapperGetSubTreeResponse& subtree) { 745 if (ec) 746 { 747 BMCWEB_LOG_DEBUG( 748 "D-Bus response error on GetSubTree {}", ec); 749 return; 750 } 751 if (subtree.empty()) 752 { 753 BMCWEB_LOG_DEBUG("Can't find bmc D-Bus object!"); 754 return; 755 } 756 // Assume only 1 bmc D-Bus object 757 // Throw an error if there is more than 1 758 if (subtree.size() > 1) 759 { 760 BMCWEB_LOG_DEBUG("Found more than 1 bmc D-Bus object!"); 761 messages::internalError(asyncResp->res); 762 return; 763 } 764 765 if (subtree[0].first.empty() || 766 subtree[0].second.size() != 1) 767 { 768 BMCWEB_LOG_DEBUG("Error getting bmc D-Bus object!"); 769 messages::internalError(asyncResp->res); 770 return; 771 } 772 773 const std::string& path = subtree[0].first; 774 const std::string& connectionName = 775 subtree[0].second[0].first; 776 777 for (const auto& interfaceName : 778 subtree[0].second[0].second) 779 { 780 if (interfaceName == 781 "xyz.openbmc_project.Inventory.Decorator.Asset") 782 { 783 dbus::utility::getAllProperties( 784 *crow::connections::systemBus, connectionName, 785 path, 786 "xyz.openbmc_project.Inventory.Decorator.Asset", 787 [asyncResp]( 788 const boost::system::error_code& ec2, 789 const dbus::utility::DBusPropertiesMap& 790 propertiesList) { 791 if (ec2) 792 { 793 BMCWEB_LOG_DEBUG( 794 "Can't get bmc asset!"); 795 return; 796 } 797 798 const std::string* partNumber = nullptr; 799 const std::string* serialNumber = nullptr; 800 const std::string* manufacturer = nullptr; 801 const std::string* model = nullptr; 802 const std::string* sparePartNumber = 803 nullptr; 804 805 const bool success = 806 sdbusplus::unpackPropertiesNoThrow( 807 dbus_utils::UnpackErrorPrinter(), 808 propertiesList, "PartNumber", 809 partNumber, "SerialNumber", 810 serialNumber, "Manufacturer", 811 manufacturer, "Model", model, 812 "SparePartNumber", sparePartNumber); 813 814 if (!success) 815 { 816 messages::internalError(asyncResp->res); 817 return; 818 } 819 820 if (partNumber != nullptr) 821 { 822 asyncResp->res.jsonValue["PartNumber"] = 823 *partNumber; 824 } 825 826 if (serialNumber != nullptr) 827 { 828 asyncResp->res 829 .jsonValue["SerialNumber"] = 830 *serialNumber; 831 } 832 833 if (manufacturer != nullptr) 834 { 835 asyncResp->res 836 .jsonValue["Manufacturer"] = 837 *manufacturer; 838 } 839 840 if (model != nullptr) 841 { 842 asyncResp->res.jsonValue["Model"] = 843 *model; 844 } 845 846 if (sparePartNumber != nullptr) 847 { 848 asyncResp->res 849 .jsonValue["SparePartNumber"] = 850 *sparePartNumber; 851 } 852 }); 853 } 854 else if ( 855 interfaceName == 856 "xyz.openbmc_project.Inventory.Decorator.LocationCode") 857 { 858 getLocation(asyncResp, connectionName, path); 859 } 860 } 861 }); 862 863 RedfishService::getInstance(app).handleSubRoute(req, asyncResp); 864 }); 865 866 BMCWEB_ROUTE(app, "/redfish/v1/Managers/<str>/") 867 .privileges(redfish::privileges::patchManager) 868 .methods(boost::beast::http::verb::patch)( 869 [&app](const crow::Request& req, 870 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, 871 const std::string& managerId) { 872 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 873 { 874 return; 875 } 876 877 if (managerId != BMCWEB_REDFISH_MANAGER_URI_NAME) 878 { 879 messages::resourceNotFound(asyncResp->res, "Manager", 880 managerId); 881 return; 882 } 883 884 std::optional<std::string> activeSoftwareImageOdataId; 885 std::optional<std::string> datetime; 886 std::optional<nlohmann::json::object_t> pidControllers; 887 std::optional<nlohmann::json::object_t> fanControllers; 888 std::optional<nlohmann::json::object_t> fanZones; 889 std::optional<nlohmann::json::object_t> stepwiseControllers; 890 std::optional<std::string> profile; 891 892 if (!json_util::readJsonPatch( // 893 req, asyncResp->res, // 894 "DateTime", datetime, // 895 "Links/ActiveSoftwareImage/@odata.id", 896 activeSoftwareImageOdataId, // 897 "Oem/OpenBmc/Fan/FanControllers", fanControllers, // 898 "Oem/OpenBmc/Fan/FanZones", fanZones, // 899 "Oem/OpenBmc/Fan/PidControllers", pidControllers, // 900 "Oem/OpenBmc/Fan/Profile", profile, // 901 "Oem/OpenBmc/Fan/StepwiseControllers", 902 stepwiseControllers // 903 )) 904 { 905 return; 906 } 907 908 if (activeSoftwareImageOdataId) 909 { 910 setActiveFirmwareImage(asyncResp, 911 *activeSoftwareImageOdataId); 912 } 913 914 if (datetime) 915 { 916 setDateTime(asyncResp, *datetime); 917 } 918 919 RedfishService::getInstance(app).handleSubRoute(req, asyncResp); 920 }); 921 } 922 923 inline void requestRoutesManagerCollection(App& app) 924 { 925 BMCWEB_ROUTE(app, "/redfish/v1/Managers/") 926 .privileges(redfish::privileges::getManagerCollection) 927 .methods(boost::beast::http::verb::get)( 928 [&app](const crow::Request& req, 929 const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { 930 if (!redfish::setUpRedfishRoute(app, req, asyncResp)) 931 { 932 return; 933 } 934 // Collections don't include the static data added by SubRoute 935 // because it has a duplicate entry for members 936 asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Managers"; 937 asyncResp->res.jsonValue["@odata.type"] = 938 "#ManagerCollection.ManagerCollection"; 939 asyncResp->res.jsonValue["Name"] = "Manager Collection"; 940 asyncResp->res.jsonValue["Members@odata.count"] = 1; 941 nlohmann::json::array_t members; 942 nlohmann::json& bmc = members.emplace_back(); 943 bmc["@odata.id"] = boost::urls::format( 944 "/redfish/v1/Managers/{}", BMCWEB_REDFISH_MANAGER_URI_NAME); 945 asyncResp->res.jsonValue["Members"] = std::move(members); 946 }); 947 } 948 } // namespace redfish 949