Ed Tanous | 40e9b92 | 2024-09-10 13:50:16 -0700 | [diff] [blame] | 1 | // SPDX-License-Identifier: Apache-2.0 |
| 2 | // SPDX-FileCopyrightText: Copyright OpenBMC Authors |
| 3 | // SPDX-FileCopyrightText: Copyright 2018 Intel Corporation |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 4 | #pragma once |
| 5 | |
Willy Tu | 13451e3 | 2023-05-24 16:08:18 -0700 | [diff] [blame] | 6 | #include "bmcweb_config.h" |
| 7 | |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 8 | #include "app.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 9 | #include "async_resp.hpp" |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 10 | #include "dbus_singleton.hpp" |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 11 | #include "dbus_utility.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 12 | #include "error_messages.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 13 | #include "generated/enums/action_info.hpp" |
Ed Tanous | 8d69c66 | 2023-06-21 10:29:06 -0700 | [diff] [blame] | 14 | #include "generated/enums/computer_system.hpp" |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 15 | #include "generated/enums/open_bmc_computer_system.hpp" |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 16 | #include "generated/enums/resource.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 17 | #include "http_request.hpp" |
Asmitha Karunanithi | 746b56f | 2023-02-27 23:29:49 -0600 | [diff] [blame] | 18 | #include "hypervisor_system.hpp" |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 19 | #include "led.hpp" |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 20 | #include "logging.hpp" |
Ed Tanous | f4c99e7 | 2021-10-04 17:02:43 -0700 | [diff] [blame] | 21 | #include "query.hpp" |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 22 | #include "redfish_util.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 23 | #include "registries/privilege_registry.hpp" |
| 24 | #include "utils/dbus_utils.hpp" |
| 25 | #include "utils/json_utils.hpp" |
Lakshmi Yadlapati | 472bd20 | 2023-03-22 09:57:05 -0500 | [diff] [blame] | 26 | #include "utils/pcie_util.hpp" |
Ed Tanous | 3ccb3ad | 2023-01-13 17:40:03 -0800 | [diff] [blame] | 27 | #include "utils/sw_utils.hpp" |
Oliver Brewka | fc5ae94 | 2024-08-12 15:04:41 +0200 | [diff] [blame] | 28 | #include "utils/systems_utils.hpp" |
Ed Tanous | 2b82937 | 2022-08-03 14:22:34 -0700 | [diff] [blame] | 29 | #include "utils/time_utils.hpp" |
Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 30 | |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 31 | #include <asm-generic/errno.h> |
| 32 | |
Andrew Geissler | fc903b3 | 2023-05-31 14:15:42 -0400 | [diff] [blame] | 33 | #include <boost/asio/error.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 34 | #include <boost/beast/http/field.hpp> |
| 35 | #include <boost/beast/http/status.hpp> |
| 36 | #include <boost/beast/http/verb.hpp> |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 37 | #include <boost/system/error_code.hpp> |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 38 | #include <boost/system/linux_error.hpp> |
Ed Tanous | ef4c65b | 2023-04-24 15:28:50 -0700 | [diff] [blame] | 39 | #include <boost/url/format.hpp> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 40 | #include <nlohmann/json.hpp> |
| 41 | #include <sdbusplus/message/native_types.hpp> |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 42 | #include <sdbusplus/unpack_properties.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 43 | |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 44 | #include <array> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 45 | #include <chrono> |
| 46 | #include <cstddef> |
| 47 | #include <cstdint> |
| 48 | #include <functional> |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 49 | #include <memory> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 50 | #include <optional> |
| 51 | #include <ratio> |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 52 | #include <string> |
George Liu | 7a1dbc4 | 2022-12-07 16:03:22 +0800 | [diff] [blame] | 53 | #include <string_view> |
Ed Tanous | d785720 | 2025-01-28 15:32:26 -0800 | [diff] [blame] | 54 | #include <tuple> |
Ed Tanous | 20fa6a2 | 2024-05-20 18:02:58 -0700 | [diff] [blame] | 55 | #include <utility> |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 56 | #include <vector> |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 57 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 58 | namespace redfish |
| 59 | { |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 60 | |
Abhishek Patel | 5c3e927 | 2021-06-24 10:11:33 -0500 | [diff] [blame] | 61 | const static std::array<std::pair<std::string_view, std::string_view>, 2> |
| 62 | protocolToDBusForSystems{ |
| 63 | {{"SSH", "obmc-console-ssh"}, {"IPMI", "phosphor-ipmi-net"}}}; |
| 64 | |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 65 | /** |
| 66 | * @brief Updates the Functional State of DIMMs |
| 67 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 68 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 69 | * @param[in] dimmState Dimm's Functional state, true/false |
| 70 | * |
| 71 | * @return None. |
| 72 | */ |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 73 | inline void updateDimmProperties( |
| 74 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isDimmFunctional) |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 75 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 76 | BMCWEB_LOG_DEBUG("Dimm Functional: {}", isDimmFunctional); |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 77 | |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 78 | // Set it as Enabled if at least one DIMM is functional |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 79 | // Update STATE only if previous State was DISABLED and current Dimm is |
| 80 | // ENABLED. |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 81 | const nlohmann::json& prevMemSummary = |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 82 | asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"]; |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 83 | if (prevMemSummary == "Disabled") |
| 84 | { |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 85 | if (isDimmFunctional) |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 86 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 87 | asyncResp->res.jsonValue["MemorySummary"]["Status"]["State"] = |
Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 88 | "Enabled"; |
| 89 | } |
| 90 | } |
| 91 | } |
| 92 | |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 93 | /* |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 94 | * @brief Update "ProcessorSummary" "Status" "State" based on |
| 95 | * CPU Functional State |
| 96 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 97 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 98 | * @param[in] cpuFunctionalState is CPU functional true/false |
| 99 | * |
| 100 | * @return None. |
| 101 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 102 | inline void modifyCpuFunctionalState( |
| 103 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuFunctional) |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 104 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 105 | BMCWEB_LOG_DEBUG("Cpu Functional: {}", isCpuFunctional); |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 106 | |
Ed Tanous | 02cad96 | 2022-06-30 16:50:15 -0700 | [diff] [blame] | 107 | const nlohmann::json& prevProcState = |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 108 | asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 109 | |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 110 | // Set it as Enabled if at least one CPU is functional |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 111 | // Update STATE only if previous State was Non_Functional and current CPU is |
| 112 | // Functional. |
| 113 | if (prevProcState == "Disabled") |
| 114 | { |
Ed Tanous | e05aec5 | 2022-01-25 10:28:56 -0800 | [diff] [blame] | 115 | if (isCpuFunctional) |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 116 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 117 | asyncResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 118 | "Enabled"; |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 123 | /* |
| 124 | * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState |
| 125 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 126 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 127 | * @param[in] cpuPresenceState CPU present or not |
| 128 | * |
| 129 | * @return None. |
| 130 | */ |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 131 | inline void modifyCpuPresenceState( |
| 132 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, bool isCpuPresent) |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 133 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 134 | BMCWEB_LOG_DEBUG("Cpu Present: {}", isCpuPresent); |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 135 | |
| 136 | if (isCpuPresent) |
| 137 | { |
| 138 | nlohmann::json& procCount = |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 139 | asyncResp->res.jsonValue["ProcessorSummary"]["Count"]; |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 140 | auto* procCountPtr = |
| 141 | procCount.get_ptr<nlohmann::json::number_integer_t*>(); |
| 142 | if (procCountPtr != nullptr) |
| 143 | { |
| 144 | // shouldn't be possible to be nullptr |
| 145 | *procCountPtr += 1; |
| 146 | } |
| 147 | } |
| 148 | } |
| 149 | |
Ali Ahmed | 382d647 | 2021-09-03 16:53:53 -0500 | [diff] [blame] | 150 | inline void getProcessorProperties( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 151 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ali Ahmed | 382d647 | 2021-09-03 16:53:53 -0500 | [diff] [blame] | 152 | const std::vector<std::pair<std::string, dbus::utility::DbusVariantType>>& |
| 153 | properties) |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 154 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 155 | BMCWEB_LOG_DEBUG("Got {} Cpu properties.", properties.size()); |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 156 | |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 157 | // TODO: Get Model |
| 158 | |
| 159 | const uint16_t* coreCount = nullptr; |
| 160 | |
| 161 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 162 | dbus_utils::UnpackErrorPrinter(), properties, "CoreCount", coreCount); |
| 163 | |
| 164 | if (!success) |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 165 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 166 | messages::internalError(asyncResp->res); |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 167 | return; |
| 168 | } |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 169 | |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 170 | if (coreCount != nullptr) |
| 171 | { |
| 172 | nlohmann::json& coreCountJson = |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 173 | asyncResp->res.jsonValue["ProcessorSummary"]["CoreCount"]; |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 174 | uint64_t* coreCountJsonPtr = coreCountJson.get_ptr<uint64_t*>(); |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 175 | |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 176 | if (coreCountJsonPtr == nullptr) |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 177 | { |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 178 | coreCountJson = *coreCount; |
| 179 | } |
| 180 | else |
| 181 | { |
| 182 | *coreCountJsonPtr += *coreCount; |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 183 | } |
| 184 | } |
| 185 | } |
| 186 | |
| 187 | /* |
| 188 | * @brief Get ProcessorSummary fields |
| 189 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 190 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 191 | * @param[in] service dbus service for Cpu Information |
| 192 | * @param[in] path dbus path for Cpu |
| 193 | * |
| 194 | * @return None. |
| 195 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 196 | inline void getProcessorSummary( |
| 197 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 198 | const std::string& service, const std::string& path) |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 199 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 200 | auto getCpuPresenceState = [asyncResp](const boost::system::error_code& ec3, |
| 201 | const bool cpuPresenceCheck) { |
Ali Ahmed | 382d647 | 2021-09-03 16:53:53 -0500 | [diff] [blame] | 202 | if (ec3) |
| 203 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 204 | BMCWEB_LOG_ERROR("DBUS response error {}", ec3); |
Ali Ahmed | 382d647 | 2021-09-03 16:53:53 -0500 | [diff] [blame] | 205 | return; |
| 206 | } |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 207 | modifyCpuPresenceState(asyncResp, cpuPresenceCheck); |
Ali Ahmed | 382d647 | 2021-09-03 16:53:53 -0500 | [diff] [blame] | 208 | }; |
| 209 | |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 210 | // Get the Presence of CPU |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 211 | dbus::utility::getProperty<bool>(*crow::connections::systemBus, service, |
| 212 | path, "xyz.openbmc_project.Inventory.Item", |
| 213 | "Present", std::move(getCpuPresenceState)); |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 214 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 215 | dbus::utility::getAllProperties( |
| 216 | service, path, "xyz.openbmc_project.Inventory.Item.Cpu", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 217 | [asyncResp, service, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 218 | path](const boost::system::error_code& ec2, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 219 | const dbus::utility::DBusPropertiesMap& properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 220 | if (ec2) |
| 221 | { |
| 222 | BMCWEB_LOG_ERROR("DBUS response error {}", ec2); |
| 223 | messages::internalError(asyncResp->res); |
| 224 | return; |
| 225 | } |
| 226 | getProcessorProperties(asyncResp, properties); |
| 227 | }); |
Ali Ahmed | 03fbed9 | 2021-09-03 02:33:43 -0500 | [diff] [blame] | 228 | } |
| 229 | |
Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 230 | /* |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 231 | * @brief processMemoryProperties fields |
| 232 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 233 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 234 | * @param[in] DBUS properties for memory |
| 235 | * |
| 236 | * @return None. |
| 237 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 238 | inline void processMemoryProperties( |
| 239 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 240 | const dbus::utility::DBusPropertiesMap& properties) |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 241 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 242 | BMCWEB_LOG_DEBUG("Got {} Dimm properties.", properties.size()); |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 243 | |
| 244 | if (properties.empty()) |
| 245 | { |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 246 | return; |
| 247 | } |
| 248 | |
| 249 | const size_t* memorySizeInKB = nullptr; |
| 250 | |
| 251 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 252 | dbus_utils::UnpackErrorPrinter(), properties, "MemorySizeInKB", |
| 253 | memorySizeInKB); |
| 254 | |
| 255 | if (!success) |
| 256 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 257 | messages::internalError(asyncResp->res); |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 258 | return; |
| 259 | } |
| 260 | |
| 261 | if (memorySizeInKB != nullptr) |
| 262 | { |
| 263 | nlohmann::json& totalMemory = |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 264 | asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"]; |
Priyanga Ramasamy | dfb2b40 | 2023-07-06 08:37:08 -0500 | [diff] [blame] | 265 | const double* preValue = totalMemory.get_ptr<const double*>(); |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 266 | if (preValue == nullptr) |
| 267 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 268 | asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = |
Priyanga Ramasamy | dfb2b40 | 2023-07-06 08:37:08 -0500 | [diff] [blame] | 269 | static_cast<double>(*memorySizeInKB) / (1024 * 1024); |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 270 | } |
| 271 | else |
| 272 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 273 | asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = |
Priyanga Ramasamy | dfb2b40 | 2023-07-06 08:37:08 -0500 | [diff] [blame] | 274 | static_cast<double>(*memorySizeInKB) / (1024 * 1024) + |
| 275 | *preValue; |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 276 | } |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 277 | } |
| 278 | } |
| 279 | |
| 280 | /* |
| 281 | * @brief Get getMemorySummary fields |
| 282 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 283 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 284 | * @param[in] service dbus service for memory Information |
| 285 | * @param[in] path dbus path for memory |
| 286 | * |
| 287 | * @return None. |
| 288 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 289 | inline void getMemorySummary( |
| 290 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 291 | const std::string& service, const std::string& path) |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 292 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 293 | dbus::utility::getAllProperties( |
| 294 | service, path, "xyz.openbmc_project.Inventory.Item.Dimm", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 295 | [asyncResp, service, |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 296 | path](const boost::system::error_code& ec2, |
| 297 | const dbus::utility::DBusPropertiesMap& properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 298 | if (ec2) |
| 299 | { |
| 300 | BMCWEB_LOG_ERROR("DBUS response error {}", ec2); |
| 301 | messages::internalError(asyncResp->res); |
| 302 | return; |
| 303 | } |
| 304 | processMemoryProperties(asyncResp, properties); |
| 305 | }); |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 306 | } |
| 307 | |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 308 | inline void afterGetUUID(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 309 | const boost::system::error_code& ec, |
| 310 | const dbus::utility::DBusPropertiesMap& properties) |
| 311 | { |
| 312 | if (ec) |
| 313 | { |
| 314 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 315 | messages::internalError(asyncResp->res); |
| 316 | return; |
| 317 | } |
| 318 | BMCWEB_LOG_DEBUG("Got {} UUID properties.", properties.size()); |
| 319 | |
| 320 | const std::string* uUID = nullptr; |
| 321 | |
| 322 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 323 | dbus_utils::UnpackErrorPrinter(), properties, "UUID", uUID); |
| 324 | |
| 325 | if (!success) |
| 326 | { |
| 327 | messages::internalError(asyncResp->res); |
| 328 | return; |
| 329 | } |
| 330 | |
| 331 | if (uUID != nullptr) |
| 332 | { |
| 333 | std::string valueStr = *uUID; |
| 334 | if (valueStr.size() == 32) |
| 335 | { |
| 336 | valueStr.insert(8, 1, '-'); |
| 337 | valueStr.insert(13, 1, '-'); |
| 338 | valueStr.insert(18, 1, '-'); |
| 339 | valueStr.insert(23, 1, '-'); |
| 340 | } |
| 341 | BMCWEB_LOG_DEBUG("UUID = {}", valueStr); |
| 342 | asyncResp->res.jsonValue["UUID"] = valueStr; |
| 343 | } |
| 344 | } |
| 345 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 346 | inline void afterGetInventory( |
| 347 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 348 | const boost::system::error_code& ec, |
| 349 | const dbus::utility::DBusPropertiesMap& propertiesList) |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 350 | { |
| 351 | if (ec) |
| 352 | { |
| 353 | // doesn't have to include this |
| 354 | // interface |
| 355 | return; |
| 356 | } |
| 357 | BMCWEB_LOG_DEBUG("Got {} properties for system", propertiesList.size()); |
| 358 | |
| 359 | const std::string* partNumber = nullptr; |
| 360 | const std::string* serialNumber = nullptr; |
| 361 | const std::string* manufacturer = nullptr; |
| 362 | const std::string* model = nullptr; |
| 363 | const std::string* subModel = nullptr; |
| 364 | |
| 365 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 366 | dbus_utils::UnpackErrorPrinter(), propertiesList, "PartNumber", |
| 367 | partNumber, "SerialNumber", serialNumber, "Manufacturer", manufacturer, |
| 368 | "Model", model, "SubModel", subModel); |
| 369 | |
| 370 | if (!success) |
| 371 | { |
| 372 | messages::internalError(asyncResp->res); |
| 373 | return; |
| 374 | } |
| 375 | |
| 376 | if (partNumber != nullptr) |
| 377 | { |
| 378 | asyncResp->res.jsonValue["PartNumber"] = *partNumber; |
| 379 | } |
| 380 | |
| 381 | if (serialNumber != nullptr) |
| 382 | { |
| 383 | asyncResp->res.jsonValue["SerialNumber"] = *serialNumber; |
| 384 | } |
| 385 | |
| 386 | if (manufacturer != nullptr) |
| 387 | { |
| 388 | asyncResp->res.jsonValue["Manufacturer"] = *manufacturer; |
| 389 | } |
| 390 | |
| 391 | if (model != nullptr) |
| 392 | { |
| 393 | asyncResp->res.jsonValue["Model"] = *model; |
| 394 | } |
| 395 | |
| 396 | if (subModel != nullptr) |
| 397 | { |
| 398 | asyncResp->res.jsonValue["SubModel"] = *subModel; |
| 399 | } |
| 400 | |
| 401 | // Grab the bios version |
| 402 | sw_util::populateSoftwareInformation(asyncResp, sw_util::biosPurpose, |
| 403 | "BiosVersion", false); |
| 404 | } |
| 405 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 406 | inline void afterGetAssetTag( |
| 407 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 408 | const boost::system::error_code& ec, const std::string& value) |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 409 | { |
| 410 | if (ec) |
| 411 | { |
| 412 | // doesn't have to include this |
| 413 | // interface |
| 414 | return; |
| 415 | } |
| 416 | |
| 417 | asyncResp->res.jsonValue["AssetTag"] = value; |
| 418 | } |
| 419 | |
| 420 | inline void afterSystemGetSubTree( |
| 421 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 422 | const boost::system::error_code& ec, |
| 423 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 424 | { |
| 425 | if (ec) |
| 426 | { |
| 427 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 428 | messages::internalError(asyncResp->res); |
| 429 | return; |
| 430 | } |
| 431 | // Iterate over all retrieved ObjectPaths. |
| 432 | for (const std::pair< |
| 433 | std::string, |
| 434 | std::vector<std::pair<std::string, std::vector<std::string>>>>& |
| 435 | object : subtree) |
| 436 | { |
| 437 | const std::string& path = object.first; |
| 438 | BMCWEB_LOG_DEBUG("Got path: {}", path); |
| 439 | const std::vector<std::pair<std::string, std::vector<std::string>>>& |
| 440 | connectionNames = object.second; |
| 441 | if (connectionNames.empty()) |
| 442 | { |
| 443 | continue; |
| 444 | } |
| 445 | |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 446 | // This is not system, so check if it's cpu, dimm, UUID or |
| 447 | // BiosVer |
| 448 | for (const auto& connection : connectionNames) |
| 449 | { |
| 450 | for (const auto& interfaceName : connection.second) |
| 451 | { |
| 452 | if (interfaceName == "xyz.openbmc_project.Inventory.Item.Dimm") |
| 453 | { |
| 454 | BMCWEB_LOG_DEBUG("Found Dimm, now get its properties."); |
| 455 | |
| 456 | getMemorySummary(asyncResp, connection.first, path); |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 457 | } |
| 458 | else if (interfaceName == |
| 459 | "xyz.openbmc_project.Inventory.Item.Cpu") |
| 460 | { |
| 461 | BMCWEB_LOG_DEBUG("Found Cpu, now get its properties."); |
| 462 | |
| 463 | getProcessorSummary(asyncResp, connection.first, path); |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 464 | } |
| 465 | else if (interfaceName == "xyz.openbmc_project.Common.UUID") |
| 466 | { |
| 467 | BMCWEB_LOG_DEBUG("Found UUID, now get its properties."); |
| 468 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 469 | dbus::utility::getAllProperties( |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 470 | *crow::connections::systemBus, connection.first, path, |
| 471 | "xyz.openbmc_project.Common.UUID", |
| 472 | [asyncResp](const boost::system::error_code& ec3, |
| 473 | const dbus::utility::DBusPropertiesMap& |
| 474 | properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 475 | afterGetUUID(asyncResp, ec3, properties); |
| 476 | }); |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 477 | } |
| 478 | else if (interfaceName == |
| 479 | "xyz.openbmc_project.Inventory.Item.System") |
| 480 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 481 | dbus::utility::getAllProperties( |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 482 | *crow::connections::systemBus, connection.first, path, |
| 483 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 484 | [asyncResp](const boost::system::error_code& ec3, |
| 485 | const dbus::utility::DBusPropertiesMap& |
| 486 | properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 487 | afterGetInventory(asyncResp, ec3, properties); |
| 488 | }); |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 489 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 490 | dbus::utility::getProperty<std::string>( |
| 491 | connection.first, path, |
Lakshmi Yadlapati | a974c13 | 2023-10-25 15:31:25 -0500 | [diff] [blame] | 492 | "xyz.openbmc_project.Inventory.Decorator." |
| 493 | "AssetTag", |
| 494 | "AssetTag", |
| 495 | std::bind_front(afterGetAssetTag, asyncResp)); |
| 496 | } |
| 497 | } |
| 498 | } |
| 499 | } |
| 500 | } |
| 501 | |
Ninad Palsule | cf0e004 | 2023-05-18 17:18:09 -0500 | [diff] [blame] | 502 | /* |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 503 | * @brief Retrieves computer system properties over dbus |
| 504 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 505 | * @param[in] asyncResp Shared pointer for completing asynchronous calls |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 506 | * |
| 507 | * @return None. |
| 508 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 509 | inline void getComputerSystem( |
| 510 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 511 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 512 | BMCWEB_LOG_DEBUG("Get available system components."); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 513 | constexpr std::array<std::string_view, 5> interfaces = { |
| 514 | "xyz.openbmc_project.Inventory.Decorator.Asset", |
| 515 | "xyz.openbmc_project.Inventory.Item.Cpu", |
| 516 | "xyz.openbmc_project.Inventory.Item.Dimm", |
| 517 | "xyz.openbmc_project.Inventory.Item.System", |
| 518 | "xyz.openbmc_project.Common.UUID", |
| 519 | }; |
| 520 | dbus::utility::getSubTree( |
| 521 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Gunnar Mills | 51bd2d8 | 2024-04-01 15:25:51 -0500 | [diff] [blame] | 522 | std::bind_front(afterSystemGetSubTree, asyncResp)); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 523 | } |
| 524 | |
| 525 | /** |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 526 | * @brief Retrieves host state properties over dbus |
| 527 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 528 | * @param[in] asyncResp Shared pointer for completing asynchronous calls. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 529 | * @param[in] computerSystemIndex Index associated with the requested system |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 530 | * |
| 531 | * @return None. |
| 532 | */ |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 533 | inline void getHostState(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 534 | const uint64_t computerSystemIndex) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 535 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 536 | BMCWEB_LOG_DEBUG("Get host information."); |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 537 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 538 | dbus::utility::getProperty<std::string>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 539 | getHostStateServiceName(computerSystemIndex), |
| 540 | getHostStateObjectPath(computerSystemIndex), |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 541 | "xyz.openbmc_project.State.Host", "CurrentHostState", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 542 | [asyncResp](const boost::system::error_code& ec, |
| 543 | const std::string& hostState) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 544 | if (ec) |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 545 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 546 | if (ec == boost::system::errc::host_unreachable) |
| 547 | { |
| 548 | // Service not available, no error, just don't return |
| 549 | // host state info |
| 550 | BMCWEB_LOG_DEBUG("Service not available {}", ec); |
| 551 | return; |
| 552 | } |
| 553 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 554 | messages::internalError(asyncResp->res); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 555 | return; |
| 556 | } |
Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 557 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 558 | BMCWEB_LOG_DEBUG("Host state: {}", hostState); |
| 559 | // Verify Host State |
| 560 | if (hostState == "xyz.openbmc_project.State.Host.HostState.Running") |
| 561 | { |
| 562 | asyncResp->res.jsonValue["PowerState"] = |
| 563 | resource::PowerState::On; |
| 564 | asyncResp->res.jsonValue["Status"]["State"] = |
| 565 | resource::State::Enabled; |
| 566 | } |
| 567 | else if (hostState == |
| 568 | "xyz.openbmc_project.State.Host.HostState.Quiesced") |
| 569 | { |
| 570 | asyncResp->res.jsonValue["PowerState"] = |
| 571 | resource::PowerState::On; |
| 572 | asyncResp->res.jsonValue["Status"]["State"] = |
| 573 | resource::State::Quiesced; |
| 574 | } |
| 575 | else if (hostState == |
| 576 | "xyz.openbmc_project.State.Host.HostState.DiagnosticMode") |
| 577 | { |
| 578 | asyncResp->res.jsonValue["PowerState"] = |
| 579 | resource::PowerState::On; |
| 580 | asyncResp->res.jsonValue["Status"]["State"] = |
| 581 | resource::State::InTest; |
| 582 | } |
| 583 | else if ( |
| 584 | hostState == |
| 585 | "xyz.openbmc_project.State.Host.HostState.TransitioningToRunning") |
| 586 | { |
| 587 | asyncResp->res.jsonValue["PowerState"] = |
| 588 | resource::PowerState::PoweringOn; |
| 589 | asyncResp->res.jsonValue["Status"]["State"] = |
| 590 | resource::State::Starting; |
| 591 | } |
| 592 | else if ( |
| 593 | hostState == |
| 594 | "xyz.openbmc_project.State.Host.HostState.TransitioningToOff") |
| 595 | { |
| 596 | asyncResp->res.jsonValue["PowerState"] = |
| 597 | resource::PowerState::PoweringOff; |
| 598 | asyncResp->res.jsonValue["Status"]["State"] = |
| 599 | resource::State::Disabled; |
| 600 | } |
| 601 | else |
| 602 | { |
| 603 | asyncResp->res.jsonValue["PowerState"] = |
| 604 | resource::PowerState::Off; |
| 605 | asyncResp->res.jsonValue["Status"]["State"] = |
| 606 | resource::State::Disabled; |
| 607 | } |
| 608 | }); |
Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 609 | } |
| 610 | |
| 611 | /** |
Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 612 | * @brief Translates boot source DBUS property value to redfish. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 613 | * |
| 614 | * @param[in] dbusSource The boot source in DBUS speak. |
| 615 | * |
| 616 | * @return Returns as a string, the boot source in Redfish terms. If translation |
| 617 | * cannot be done, returns an empty string. |
| 618 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 619 | inline std::string dbusToRfBootSource(const std::string& dbusSource) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 620 | { |
| 621 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") |
| 622 | { |
| 623 | return "None"; |
| 624 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 625 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 626 | { |
| 627 | return "Hdd"; |
| 628 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 629 | if (dbusSource == |
| 630 | "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 631 | { |
| 632 | return "Cd"; |
| 633 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 634 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 635 | { |
| 636 | return "Pxe"; |
| 637 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 638 | if (dbusSource == |
| 639 | "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") |
Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 640 | { |
| 641 | return "Usb"; |
| 642 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 643 | return ""; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 644 | } |
| 645 | |
| 646 | /** |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 647 | * @brief Translates boot type DBUS property value to redfish. |
| 648 | * |
| 649 | * @param[in] dbusType The boot type in DBUS speak. |
| 650 | * |
| 651 | * @return Returns as a string, the boot type in Redfish terms. If translation |
| 652 | * cannot be done, returns an empty string. |
| 653 | */ |
| 654 | inline std::string dbusToRfBootType(const std::string& dbusType) |
| 655 | { |
| 656 | if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.Legacy") |
| 657 | { |
| 658 | return "Legacy"; |
| 659 | } |
| 660 | if (dbusType == "xyz.openbmc_project.Control.Boot.Type.Types.EFI") |
| 661 | { |
| 662 | return "UEFI"; |
| 663 | } |
| 664 | return ""; |
| 665 | } |
| 666 | |
| 667 | /** |
Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 668 | * @brief Translates boot mode DBUS property value to redfish. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 669 | * |
| 670 | * @param[in] dbusMode The boot mode in DBUS speak. |
| 671 | * |
| 672 | * @return Returns as a string, the boot mode in Redfish terms. If translation |
| 673 | * cannot be done, returns an empty string. |
| 674 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 675 | inline std::string dbusToRfBootMode(const std::string& dbusMode) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 676 | { |
| 677 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") |
| 678 | { |
| 679 | return "None"; |
| 680 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 681 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 682 | { |
| 683 | return "Diags"; |
| 684 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 685 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 686 | { |
| 687 | return "BiosSetup"; |
| 688 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 689 | return ""; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 690 | } |
| 691 | |
| 692 | /** |
Andrew Geissler | e43914b | 2022-01-06 13:59:39 -0600 | [diff] [blame] | 693 | * @brief Translates boot progress DBUS property value to redfish. |
| 694 | * |
| 695 | * @param[in] dbusBootProgress The boot progress in DBUS speak. |
| 696 | * |
| 697 | * @return Returns as a string, the boot progress in Redfish terms. If |
| 698 | * translation cannot be done, returns "None". |
| 699 | */ |
| 700 | inline std::string dbusToRfBootProgress(const std::string& dbusBootProgress) |
| 701 | { |
| 702 | // Now convert the D-Bus BootProgress to the appropriate Redfish |
| 703 | // enum |
| 704 | std::string rfBpLastState = "None"; |
| 705 | if (dbusBootProgress == "xyz.openbmc_project.State.Boot.Progress." |
| 706 | "ProgressStages.Unspecified") |
| 707 | { |
| 708 | rfBpLastState = "None"; |
| 709 | } |
| 710 | else if (dbusBootProgress == |
| 711 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 712 | "PrimaryProcInit") |
| 713 | { |
| 714 | rfBpLastState = "PrimaryProcessorInitializationStarted"; |
| 715 | } |
| 716 | else if (dbusBootProgress == |
| 717 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 718 | "BusInit") |
| 719 | { |
| 720 | rfBpLastState = "BusInitializationStarted"; |
| 721 | } |
| 722 | else if (dbusBootProgress == |
| 723 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 724 | "MemoryInit") |
| 725 | { |
| 726 | rfBpLastState = "MemoryInitializationStarted"; |
| 727 | } |
| 728 | else if (dbusBootProgress == |
| 729 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 730 | "SecondaryProcInit") |
| 731 | { |
| 732 | rfBpLastState = "SecondaryProcessorInitializationStarted"; |
| 733 | } |
| 734 | else if (dbusBootProgress == |
| 735 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 736 | "PCIInit") |
| 737 | { |
| 738 | rfBpLastState = "PCIResourceConfigStarted"; |
| 739 | } |
| 740 | else if (dbusBootProgress == |
| 741 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 742 | "SystemSetup") |
| 743 | { |
| 744 | rfBpLastState = "SetupEntered"; |
| 745 | } |
| 746 | else if (dbusBootProgress == |
| 747 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 748 | "SystemInitComplete") |
| 749 | { |
| 750 | rfBpLastState = "SystemHardwareInitializationComplete"; |
| 751 | } |
| 752 | else if (dbusBootProgress == |
| 753 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 754 | "OSStart") |
| 755 | { |
| 756 | rfBpLastState = "OSBootStarted"; |
| 757 | } |
| 758 | else if (dbusBootProgress == |
| 759 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." |
| 760 | "OSRunning") |
| 761 | { |
| 762 | rfBpLastState = "OSRunning"; |
| 763 | } |
| 764 | else |
| 765 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 766 | BMCWEB_LOG_DEBUG("Unsupported D-Bus BootProgress {}", dbusBootProgress); |
Andrew Geissler | e43914b | 2022-01-06 13:59:39 -0600 | [diff] [blame] | 767 | // Just return the default |
| 768 | } |
| 769 | return rfBpLastState; |
| 770 | } |
| 771 | |
| 772 | /** |
Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 773 | * @brief Translates boot source from Redfish to the DBus boot paths. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 774 | * |
| 775 | * @param[in] rfSource The boot source in Redfish. |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 776 | * @param[out] bootSource The DBus source |
| 777 | * @param[out] bootMode the DBus boot mode |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 778 | * |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 779 | * @return Integer error code. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 780 | */ |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 781 | inline int assignBootParameters( |
| 782 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 783 | const std::string& rfSource, std::string& bootSource, std::string& bootMode) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 784 | { |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 785 | bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; |
| 786 | bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 787 | |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 788 | if (rfSource == "None") |
| 789 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 790 | return 0; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 791 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 792 | if (rfSource == "Pxe") |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 793 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 794 | bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; |
| 795 | } |
| 796 | else if (rfSource == "Hdd") |
| 797 | { |
| 798 | bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; |
| 799 | } |
| 800 | else if (rfSource == "Diags") |
| 801 | { |
| 802 | bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; |
| 803 | } |
| 804 | else if (rfSource == "Cd") |
| 805 | { |
| 806 | bootSource = |
| 807 | "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; |
| 808 | } |
| 809 | else if (rfSource == "BiosSetup") |
| 810 | { |
| 811 | bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 812 | } |
Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 813 | else if (rfSource == "Usb") |
| 814 | { |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 815 | bootSource = |
| 816 | "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; |
Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 817 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 818 | else |
| 819 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 820 | BMCWEB_LOG_DEBUG( |
| 821 | "Invalid property value for BootSourceOverrideTarget: {}", |
| 822 | bootSource); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 823 | messages::propertyValueNotInList(asyncResp->res, rfSource, |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 824 | "BootSourceTargetOverride"); |
| 825 | return -1; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 826 | } |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 827 | return 0; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 828 | } |
Ali Ahmed | 1981771 | 2021-06-29 17:01:52 -0500 | [diff] [blame] | 829 | |
Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 830 | /** |
| 831 | * @brief Retrieves boot progress of the system |
| 832 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 833 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 834 | * @param[in] computerSystemIndex Index associated with the requested system |
Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 835 | * |
| 836 | * @return None. |
| 837 | */ |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 838 | inline void getBootProgress(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 839 | const uint64_t computerSystemIndex) |
Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 840 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 841 | dbus::utility::getProperty<std::string>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 842 | getHostStateServiceName(computerSystemIndex), |
| 843 | getHostStateObjectPath(computerSystemIndex), |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 844 | "xyz.openbmc_project.State.Boot.Progress", "BootProgress", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 845 | [asyncResp](const boost::system::error_code& ec, |
| 846 | const std::string& bootProgressStr) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 847 | if (ec) |
| 848 | { |
| 849 | // BootProgress is an optional object so just do nothing if |
| 850 | // not found |
| 851 | return; |
| 852 | } |
Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 853 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 854 | BMCWEB_LOG_DEBUG("Boot Progress: {}", bootProgressStr); |
Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 855 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 856 | asyncResp->res.jsonValue["BootProgress"]["LastState"] = |
| 857 | dbusToRfBootProgress(bootProgressStr); |
| 858 | }); |
Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 859 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 860 | |
| 861 | /** |
Hieu Huynh | b6d5d45 | 2022-10-07 09:41:46 +0000 | [diff] [blame] | 862 | * @brief Retrieves boot progress Last Update of the system |
| 863 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 864 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 865 | * @param[in] computerSystemIndex Index associated with the requested system |
Hieu Huynh | b6d5d45 | 2022-10-07 09:41:46 +0000 | [diff] [blame] | 866 | * |
| 867 | * @return None. |
| 868 | */ |
| 869 | inline void getBootProgressLastStateTime( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 870 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 871 | const uint64_t computerSystemIndex) |
Hieu Huynh | b6d5d45 | 2022-10-07 09:41:46 +0000 | [diff] [blame] | 872 | { |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 873 | dbus::utility::getProperty<uint64_t>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 874 | getHostStateServiceName(computerSystemIndex), |
| 875 | getHostStateObjectPath(computerSystemIndex), |
Hieu Huynh | b6d5d45 | 2022-10-07 09:41:46 +0000 | [diff] [blame] | 876 | "xyz.openbmc_project.State.Boot.Progress", "BootProgressLastUpdate", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 877 | [asyncResp](const boost::system::error_code& ec, |
| 878 | const uint64_t lastStateTime) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 879 | if (ec) |
| 880 | { |
| 881 | BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); |
| 882 | return; |
| 883 | } |
Hieu Huynh | b6d5d45 | 2022-10-07 09:41:46 +0000 | [diff] [blame] | 884 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 885 | // BootProgressLastUpdate is the last time the BootProgress property |
| 886 | // was updated. The time is the Epoch time, number of microseconds |
| 887 | // since 1 Jan 1970 00::00::00 UTC." |
| 888 | // https://github.com/openbmc/phosphor-dbus-interfaces/blob/master/ |
| 889 | // yaml/xyz/openbmc_project/State/Boot/Progress.interface.yaml#L11 |
Hieu Huynh | b6d5d45 | 2022-10-07 09:41:46 +0000 | [diff] [blame] | 890 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 891 | // Convert to ISO 8601 standard |
| 892 | asyncResp->res.jsonValue["BootProgress"]["LastStateTime"] = |
| 893 | redfish::time_utils::getDateTimeUintUs(lastStateTime); |
| 894 | }); |
Hieu Huynh | b6d5d45 | 2022-10-07 09:41:46 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /** |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 898 | * @brief Retrieves boot override type over DBUS and fills out the response |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 899 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 900 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 901 | * @param[in] computerSystemIndex Index associated with the requested system |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 902 | * |
| 903 | * @return None. |
| 904 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 905 | inline void getBootOverrideType( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 906 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 907 | const uint64_t computerSystemIndex) |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 908 | { |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 909 | sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + |
| 910 | std::to_string(computerSystemIndex)); |
| 911 | path /= "boot"; |
| 912 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 913 | dbus::utility::getProperty<std::string>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 914 | "xyz.openbmc_project.Settings", path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 915 | "xyz.openbmc_project.Control.Boot.Type", "BootType", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 916 | [asyncResp](const boost::system::error_code& ec, |
| 917 | const std::string& bootType) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 918 | if (ec) |
| 919 | { |
| 920 | // not an error, don't have to have the interface |
| 921 | return; |
| 922 | } |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 923 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 924 | BMCWEB_LOG_DEBUG("Boot type: {}", bootType); |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 925 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 926 | asyncResp->res |
| 927 | .jsonValue["Boot"] |
| 928 | ["BootSourceOverrideMode@Redfish.AllowableValues"] = |
| 929 | nlohmann::json::array_t({"Legacy", "UEFI"}); |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 930 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 931 | auto rfType = dbusToRfBootType(bootType); |
| 932 | if (rfType.empty()) |
| 933 | { |
| 934 | messages::internalError(asyncResp->res); |
| 935 | return; |
| 936 | } |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 937 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 938 | asyncResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = rfType; |
| 939 | }); |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 940 | } |
| 941 | |
| 942 | /** |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 943 | * @brief Retrieves boot override mode over DBUS and fills out the response |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 944 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 945 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 946 | * @param[in] computerSystemIndex Index associated with the requested system |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 947 | * |
| 948 | * @return None. |
| 949 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 950 | inline void getBootOverrideMode( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 951 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 952 | const uint64_t computerSystemIndex) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 953 | { |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 954 | sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + |
| 955 | std::to_string(computerSystemIndex)); |
| 956 | path /= "boot"; |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 957 | dbus::utility::getProperty<std::string>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 958 | "xyz.openbmc_project.Settings", path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 959 | "xyz.openbmc_project.Control.Boot.Mode", "BootMode", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 960 | [asyncResp](const boost::system::error_code& ec, |
| 961 | const std::string& bootModeStr) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 962 | if (ec) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 963 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 964 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 965 | messages::internalError(asyncResp->res); |
| 966 | return; |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 967 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 968 | |
| 969 | BMCWEB_LOG_DEBUG("Boot mode: {}", bootModeStr); |
| 970 | |
| 971 | nlohmann::json::array_t allowed; |
| 972 | allowed.emplace_back("None"); |
| 973 | allowed.emplace_back("Pxe"); |
| 974 | allowed.emplace_back("Hdd"); |
| 975 | allowed.emplace_back("Cd"); |
| 976 | allowed.emplace_back("Diags"); |
| 977 | allowed.emplace_back("BiosSetup"); |
| 978 | allowed.emplace_back("Usb"); |
| 979 | |
| 980 | asyncResp->res |
| 981 | .jsonValue["Boot"] |
| 982 | ["BootSourceOverrideTarget@Redfish.AllowableValues"] = |
| 983 | std::move(allowed); |
| 984 | if (bootModeStr != |
| 985 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") |
| 986 | { |
| 987 | auto rfMode = dbusToRfBootMode(bootModeStr); |
| 988 | if (!rfMode.empty()) |
| 989 | { |
| 990 | asyncResp->res |
| 991 | .jsonValue["Boot"]["BootSourceOverrideTarget"] = rfMode; |
| 992 | } |
| 993 | } |
| 994 | }); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 995 | } |
| 996 | |
| 997 | /** |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 998 | * @brief Retrieves boot override source over DBUS |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 999 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1000 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1001 | * @param[in] computerSystemIndex Index associated with the requested system |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1002 | * |
| 1003 | * @return None. |
| 1004 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1005 | inline void getBootOverrideSource( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1006 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1007 | const uint64_t computerSystemIndex) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1008 | { |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1009 | sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + |
| 1010 | std::to_string(computerSystemIndex)); |
| 1011 | path /= "boot"; |
| 1012 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1013 | dbus::utility::getProperty<std::string>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1014 | "xyz.openbmc_project.Settings", path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1015 | "xyz.openbmc_project.Control.Boot.Source", "BootSource", |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1016 | [asyncResp, computerSystemIndex](const boost::system::error_code& ec, |
| 1017 | const std::string& bootSourceStr) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1018 | if (ec) |
Nan Zhou | 5ef735c | 2022-06-22 05:24:21 +0000 | [diff] [blame] | 1019 | { |
Allen.Wang | 8f1a35b | 2025-06-17 20:39:56 +0800 | [diff] [blame] | 1020 | // Service not available, no error, just don't return |
| 1021 | // Boot Override Source information |
| 1022 | if (ec.value() != EBADR && |
| 1023 | ec.value() != boost::asio::error::host_unreachable) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1024 | { |
Allen.Wang | 8f1a35b | 2025-06-17 20:39:56 +0800 | [diff] [blame] | 1025 | BMCWEB_LOG_ERROR("D-Bus response error: {}", ec); |
| 1026 | messages::internalError(asyncResp->res); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1027 | } |
Nan Zhou | 5ef735c | 2022-06-22 05:24:21 +0000 | [diff] [blame] | 1028 | return; |
| 1029 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1030 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1031 | BMCWEB_LOG_DEBUG("Boot source: {}", bootSourceStr); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1032 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1033 | auto rfSource = dbusToRfBootSource(bootSourceStr); |
| 1034 | if (!rfSource.empty()) |
| 1035 | { |
| 1036 | asyncResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = |
| 1037 | rfSource; |
| 1038 | } |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1039 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1040 | // Get BootMode as BootSourceOverrideTarget is constructed |
| 1041 | // from both BootSource and BootMode |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1042 | getBootOverrideMode(asyncResp, computerSystemIndex); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1043 | }); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1044 | } |
| 1045 | |
| 1046 | /** |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1047 | * @brief This functions abstracts all the logic behind getting a |
| 1048 | * "BootSourceOverrideEnabled" property from an overall boot override enable |
| 1049 | * state |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1050 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1051 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1052 | * @param[in] computerSystemIndex Index associated with the requested system |
| 1053 | * @param[in] bootOverrideEnableSetting |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1054 | * |
| 1055 | * @return None. |
| 1056 | */ |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1057 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1058 | inline void processBootOverrideEnable( |
| 1059 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1060 | const uint64_t computerSystemIndex, const bool bootOverrideEnableSetting) |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1061 | { |
| 1062 | if (!bootOverrideEnableSetting) |
| 1063 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1064 | asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = |
| 1065 | "Disabled"; |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1066 | return; |
| 1067 | } |
| 1068 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1069 | sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + |
| 1070 | std::to_string(computerSystemIndex)); |
| 1071 | path /= "boot"; |
| 1072 | path /= "one_time"; |
| 1073 | |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1074 | // If boot source override is enabled, we need to check 'one_time' |
| 1075 | // property to set a correct value for the "BootSourceOverrideEnabled" |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1076 | dbus::utility::getProperty<bool>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1077 | "xyz.openbmc_project.Settings", path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1078 | "xyz.openbmc_project.Object.Enable", "Enabled", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1079 | [asyncResp](const boost::system::error_code& ec, bool oneTimeSetting) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1080 | if (ec) |
| 1081 | { |
| 1082 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 1083 | messages::internalError(asyncResp->res); |
| 1084 | return; |
| 1085 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1086 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1087 | if (oneTimeSetting) |
| 1088 | { |
| 1089 | asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = |
| 1090 | "Once"; |
| 1091 | } |
| 1092 | else |
| 1093 | { |
| 1094 | asyncResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = |
| 1095 | "Continuous"; |
| 1096 | } |
| 1097 | }); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1098 | } |
| 1099 | |
| 1100 | /** |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1101 | * @brief Retrieves boot override enable over DBUS |
| 1102 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1103 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1104 | * @param[in] computerSystemIndex Index associated with the requested system |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1105 | * |
| 1106 | * @return None. |
| 1107 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1108 | inline void getBootOverrideEnable( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1109 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1110 | const uint64_t computerSystemIndex) |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1111 | { |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1112 | sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + |
| 1113 | std::to_string(computerSystemIndex)); |
| 1114 | path /= "boot"; |
| 1115 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1116 | dbus::utility::getProperty<bool>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1117 | "xyz.openbmc_project.Settings", path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1118 | "xyz.openbmc_project.Object.Enable", "Enabled", |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1119 | [asyncResp, computerSystemIndex](const boost::system::error_code& ec, |
| 1120 | const bool bootOverrideEnable) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1121 | if (ec) |
Nan Zhou | 5ef735c | 2022-06-22 05:24:21 +0000 | [diff] [blame] | 1122 | { |
Allen.Wang | 8f1a35b | 2025-06-17 20:39:56 +0800 | [diff] [blame] | 1123 | // Service not available, no error, just don't return |
| 1124 | // Boot Override Enable information |
| 1125 | if (ec.value() != EBADR && |
| 1126 | ec.value() != boost::asio::error::host_unreachable) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1127 | { |
Allen.Wang | 8f1a35b | 2025-06-17 20:39:56 +0800 | [diff] [blame] | 1128 | BMCWEB_LOG_ERROR("D-Bus response error: {}", ec); |
| 1129 | messages::internalError(asyncResp->res); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1130 | } |
Nan Zhou | 5ef735c | 2022-06-22 05:24:21 +0000 | [diff] [blame] | 1131 | return; |
| 1132 | } |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1133 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1134 | processBootOverrideEnable(asyncResp, computerSystemIndex, |
| 1135 | bootOverrideEnable); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1136 | }); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1137 | } |
| 1138 | |
| 1139 | /** |
| 1140 | * @brief Retrieves boot source override properties |
| 1141 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1142 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1143 | * @param[in] computerSystemIndex Index associated with the requested system |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1144 | * |
| 1145 | * @return None. |
| 1146 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1147 | inline void getBootProperties( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1148 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1149 | const uint64_t computerSystemIndex) |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1150 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1151 | BMCWEB_LOG_DEBUG("Get boot information."); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1152 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1153 | getBootOverrideSource(asyncResp, computerSystemIndex); |
| 1154 | getBootOverrideType(asyncResp, computerSystemIndex); |
| 1155 | getBootOverrideEnable(asyncResp, computerSystemIndex); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | /** |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1159 | * @brief Retrieves the Last Reset Time |
| 1160 | * |
| 1161 | * "Reset" is an overloaded term in Redfish, "Reset" includes power on |
| 1162 | * and power off. Even though this is the "system" Redfish object look at the |
| 1163 | * chassis D-Bus interface for the LastStateChangeTime since this has the |
| 1164 | * last power operation time. |
| 1165 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1166 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1167 | * |
| 1168 | * @return None. |
| 1169 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1170 | inline void getLastResetTime( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1171 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1172 | const uint64_t computerSystemIndex) |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1173 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1174 | BMCWEB_LOG_DEBUG("Getting System Last Reset Time"); |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1175 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1176 | dbus::utility::getProperty<uint64_t>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1177 | getChassisStateServiceName(computerSystemIndex), |
| 1178 | getChassisStateObjectPath(computerSystemIndex), |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1179 | "xyz.openbmc_project.State.Chassis", "LastStateChangeTime", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1180 | [asyncResp](const boost::system::error_code& ec, |
| 1181 | uint64_t lastResetTime) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1182 | if (ec) |
| 1183 | { |
| 1184 | BMCWEB_LOG_DEBUG("D-BUS response error {}", ec); |
| 1185 | return; |
| 1186 | } |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1187 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1188 | // LastStateChangeTime is epoch time, in milliseconds |
| 1189 | // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 |
| 1190 | uint64_t lastResetTimeStamp = lastResetTime / 1000; |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1191 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1192 | // Convert to ISO 8601 standard |
| 1193 | asyncResp->res.jsonValue["LastResetTime"] = |
| 1194 | redfish::time_utils::getDateTimeUint(lastResetTimeStamp); |
| 1195 | }); |
Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1196 | } |
| 1197 | |
| 1198 | /** |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1199 | * @brief Retrieves the number of automatic boot Retry attempts allowed/left. |
| 1200 | * |
| 1201 | * The total number of automatic reboot retries allowed "RetryAttempts" and its |
| 1202 | * corresponding property "AttemptsLeft" that keeps track of the amount of |
| 1203 | * automatic retry attempts left are hosted in phosphor-state-manager through |
| 1204 | * dbus. |
| 1205 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1206 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1207 | * @param[in] computerSystemIndex Index associated with the requested system |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1208 | * |
| 1209 | * @return None. |
| 1210 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1211 | inline void getAutomaticRebootAttempts( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1212 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1213 | const uint64_t computerSystemIndex) |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1214 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1215 | BMCWEB_LOG_DEBUG("Get Automatic Retry policy"); |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1216 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1217 | dbus::utility::getAllProperties( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1218 | getHostStateServiceName(computerSystemIndex), |
| 1219 | getHostStateObjectPath(computerSystemIndex), |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1220 | "xyz.openbmc_project.Control.Boot.RebootAttempts", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1221 | [asyncResp{asyncResp}]( |
| 1222 | const boost::system::error_code& ec, |
| 1223 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1224 | if (ec) |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1225 | { |
Aishwary Joshi | d39a8c2 | 2025-05-08 19:18:43 +0530 | [diff] [blame] | 1226 | if (ec.value() != EBADR && |
| 1227 | ec.value() != boost::asio::error::host_unreachable) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1228 | { |
Aishwary Joshi | d39a8c2 | 2025-05-08 19:18:43 +0530 | [diff] [blame] | 1229 | // Service not available, no error, just don't return |
| 1230 | // RebootAttempts information |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1231 | BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); |
| 1232 | messages::internalError(asyncResp->res); |
| 1233 | } |
| 1234 | return; |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1235 | } |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1236 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1237 | const uint32_t* attemptsLeft = nullptr; |
| 1238 | const uint32_t* retryAttempts = nullptr; |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1239 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1240 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 1241 | dbus_utils::UnpackErrorPrinter(), propertiesList, |
| 1242 | "AttemptsLeft", attemptsLeft, "RetryAttempts", retryAttempts); |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1243 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1244 | if (!success) |
| 1245 | { |
| 1246 | messages::internalError(asyncResp->res); |
| 1247 | return; |
| 1248 | } |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1249 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1250 | if (attemptsLeft != nullptr) |
| 1251 | { |
| 1252 | asyncResp->res |
| 1253 | .jsonValue["Boot"]["RemainingAutomaticRetryAttempts"] = |
| 1254 | *attemptsLeft; |
| 1255 | } |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1256 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1257 | if (retryAttempts != nullptr) |
| 1258 | { |
| 1259 | asyncResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = |
| 1260 | *retryAttempts; |
| 1261 | } |
| 1262 | }); |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1263 | } |
| 1264 | |
| 1265 | /** |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1266 | * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. |
| 1267 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1268 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1269 | * @param[in] computerSystemIndex Index associated with the requested system |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1270 | * |
| 1271 | * @return None. |
| 1272 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1273 | inline void getAutomaticRetryPolicy( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1274 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1275 | const uint64_t computerSystemIndex) |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1276 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1277 | BMCWEB_LOG_DEBUG("Get Automatic Retry policy"); |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1278 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1279 | sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + |
| 1280 | std::to_string(computerSystemIndex)); |
| 1281 | path /= "auto_reboot"; |
| 1282 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1283 | dbus::utility::getProperty<bool>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1284 | "xyz.openbmc_project.Settings", path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1285 | "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1286 | [asyncResp, computerSystemIndex](const boost::system::error_code& ec, |
| 1287 | bool autoRebootEnabled) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1288 | if (ec) |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1289 | { |
Aishwary Joshi | d39a8c2 | 2025-05-08 19:18:43 +0530 | [diff] [blame] | 1290 | // Service not available, no error, just don't return |
| 1291 | // AutoReboot information |
| 1292 | if (ec.value() != EBADR && |
| 1293 | ec.value() != boost::asio::error::host_unreachable) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1294 | { |
| 1295 | BMCWEB_LOG_ERROR("D-Bus responses error: {}", ec); |
| 1296 | messages::internalError(asyncResp->res); |
| 1297 | } |
| 1298 | return; |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1299 | } |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1300 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1301 | BMCWEB_LOG_DEBUG("Auto Reboot: {}", autoRebootEnabled); |
| 1302 | if (autoRebootEnabled) |
| 1303 | { |
| 1304 | asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = |
| 1305 | "RetryAttempts"; |
| 1306 | } |
| 1307 | else |
| 1308 | { |
| 1309 | asyncResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = |
| 1310 | "Disabled"; |
| 1311 | } |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1312 | getAutomaticRebootAttempts(asyncResp, computerSystemIndex); |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1313 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1314 | // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, |
| 1315 | // and RetryAttempts. OpenBMC only supports Disabled and |
| 1316 | // RetryAttempts. |
| 1317 | nlohmann::json::array_t allowed; |
| 1318 | allowed.emplace_back("Disabled"); |
| 1319 | allowed.emplace_back("RetryAttempts"); |
| 1320 | asyncResp->res |
| 1321 | .jsonValue["Boot"] |
| 1322 | ["AutomaticRetryConfig@Redfish.AllowableValues"] = |
| 1323 | std::move(allowed); |
| 1324 | }); |
Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1325 | } |
| 1326 | |
| 1327 | /** |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1328 | * @brief Sets RetryAttempts |
| 1329 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1330 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1331 | * @param[in] computerSystemIndex Index associated with the requested system |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1332 | * @param[in] retryAttempts "AutomaticRetryAttempts" from request. |
| 1333 | * |
| 1334 | *@return None. |
| 1335 | */ |
| 1336 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1337 | inline void setAutomaticRetryAttempts( |
| 1338 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1339 | const uint32_t retryAttempts) |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1340 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1341 | BMCWEB_LOG_DEBUG("Set Automatic Retry Attempts."); |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1342 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1343 | asyncResp, "Boot/AutomaticRetryAttempts", |
| 1344 | "xyz.openbmc_project.State.Host", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1345 | sdbusplus::message::object_path("/xyz/openbmc_project/state/host0"), |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1346 | "xyz.openbmc_project.Control.Boot.RebootAttempts", "RetryAttempts", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1347 | retryAttempts); |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1348 | } |
| 1349 | |
Ed Tanous | 8d69c66 | 2023-06-21 10:29:06 -0700 | [diff] [blame] | 1350 | inline computer_system::PowerRestorePolicyTypes |
| 1351 | redfishPowerRestorePolicyFromDbus(std::string_view value) |
| 1352 | { |
| 1353 | if (value == |
| 1354 | "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn") |
| 1355 | { |
| 1356 | return computer_system::PowerRestorePolicyTypes::AlwaysOn; |
| 1357 | } |
| 1358 | if (value == |
| 1359 | "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff") |
| 1360 | { |
| 1361 | return computer_system::PowerRestorePolicyTypes::AlwaysOff; |
| 1362 | } |
| 1363 | if (value == |
Gunnar Mills | 3a34b74 | 2023-07-28 10:17:14 -0500 | [diff] [blame] | 1364 | "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore") |
Ed Tanous | 8d69c66 | 2023-06-21 10:29:06 -0700 | [diff] [blame] | 1365 | { |
| 1366 | return computer_system::PowerRestorePolicyTypes::LastState; |
| 1367 | } |
| 1368 | if (value == "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.None") |
| 1369 | { |
| 1370 | return computer_system::PowerRestorePolicyTypes::AlwaysOff; |
| 1371 | } |
| 1372 | return computer_system::PowerRestorePolicyTypes::Invalid; |
| 1373 | } |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 1374 | /** |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1375 | * @brief Retrieves power restore policy over DBUS. |
| 1376 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1377 | * @param[in] asyncResp Shared pointer for generating response message. |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1378 | * |
| 1379 | * @return None. |
| 1380 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1381 | inline void getPowerRestorePolicy( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1382 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1383 | const uint64_t computerSystemIndex) |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1384 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1385 | BMCWEB_LOG_DEBUG("Get power restore policy"); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1386 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1387 | sdbusplus::message::object_path path("/xyz/openbmc_project/control/host" + |
| 1388 | std::to_string(computerSystemIndex)); |
| 1389 | path /= "power_restore_policy"; |
| 1390 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1391 | dbus::utility::getProperty<std::string>( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1392 | "xyz.openbmc_project.Settings", path, |
Jonathan Doman | 1e1e598 | 2021-06-11 09:36:17 -0700 | [diff] [blame] | 1393 | "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1394 | [asyncResp](const boost::system::error_code& ec, |
| 1395 | const std::string& policy) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1396 | if (ec) |
| 1397 | { |
| 1398 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
| 1399 | return; |
| 1400 | } |
| 1401 | computer_system::PowerRestorePolicyTypes restore = |
| 1402 | redfishPowerRestorePolicyFromDbus(policy); |
| 1403 | if (restore == computer_system::PowerRestorePolicyTypes::Invalid) |
| 1404 | { |
| 1405 | messages::internalError(asyncResp->res); |
| 1406 | return; |
| 1407 | } |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1408 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1409 | asyncResp->res.jsonValue["PowerRestorePolicy"] = restore; |
| 1410 | }); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1411 | } |
| 1412 | |
| 1413 | /** |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1414 | * @brief Stop Boot On Fault over DBUS. |
| 1415 | * |
| 1416 | * @param[in] asyncResp Shared pointer for generating response message. |
| 1417 | * |
| 1418 | * @return None. |
| 1419 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1420 | inline void getStopBootOnFault( |
| 1421 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1422 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1423 | BMCWEB_LOG_DEBUG("Get Stop Boot On Fault"); |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1424 | |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 1425 | dbus::utility::getProperty<bool>( |
| 1426 | "xyz.openbmc_project.Settings", "/xyz/openbmc_project/logging/settings", |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1427 | "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", |
| 1428 | [asyncResp](const boost::system::error_code& ec, bool value) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1429 | if (ec) |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1430 | { |
Aishwary Joshi | d39a8c2 | 2025-05-08 19:18:43 +0530 | [diff] [blame] | 1431 | // Service not available, no error, just don't return |
| 1432 | // StopBootOnFault information |
| 1433 | if (ec.value() != EBADR || |
| 1434 | ec.value() != boost::asio::error::host_unreachable) |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1435 | { |
| 1436 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 1437 | messages::internalError(asyncResp->res); |
| 1438 | } |
| 1439 | return; |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1440 | } |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1441 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1442 | if (value) |
| 1443 | { |
| 1444 | asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = |
| 1445 | computer_system::StopBootOnFault::AnyFault; |
| 1446 | } |
| 1447 | else |
| 1448 | { |
| 1449 | asyncResp->res.jsonValue["Boot"]["StopBootOnFault"] = |
| 1450 | computer_system::StopBootOnFault::Never; |
| 1451 | } |
| 1452 | }); |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1453 | } |
| 1454 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1455 | inline void getTrustedModuleRequiredToBootCallback( |
| 1456 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1457 | const uint64_t computerSystemIndex, const boost::system::error_code& ec, |
| 1458 | const dbus::utility::MapperGetSubTreeResponse& subtree) |
| 1459 | { |
| 1460 | if (ec) |
| 1461 | { |
| 1462 | BMCWEB_LOG_DEBUG("DBUS response error on TPM.Policy GetSubTree{}", ec); |
| 1463 | // This is an optional D-Bus object so just return if |
| 1464 | // error occurs |
| 1465 | return; |
| 1466 | } |
| 1467 | if (subtree.empty()) |
| 1468 | { |
| 1469 | // As noted above, this is an optional interface so just return |
| 1470 | // if there is no instance found |
| 1471 | return; |
| 1472 | } |
| 1473 | |
| 1474 | std::string path; |
| 1475 | std::string service; |
| 1476 | |
| 1477 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 1478 | { |
| 1479 | if (!indexMatchingSubTreeMapObjectPath(asyncResp, computerSystemIndex, |
| 1480 | subtree, path, service)) |
| 1481 | { |
| 1482 | return; |
| 1483 | } |
| 1484 | } |
| 1485 | else |
| 1486 | { |
| 1487 | // Make sure the Dbus response map has a service and objectPath |
| 1488 | // field |
| 1489 | if (subtree[0].first.empty() || subtree[0].second.size() != 1) |
| 1490 | { |
| 1491 | BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); |
| 1492 | messages::internalError(asyncResp->res); |
| 1493 | return; |
| 1494 | } |
| 1495 | |
| 1496 | path = subtree[0].first; |
| 1497 | service = subtree[0].second.begin()->first; |
| 1498 | } |
| 1499 | |
| 1500 | BMCWEB_LOG_DEBUG("found tpm service {}", service); |
| 1501 | BMCWEB_LOG_DEBUG("found tpm path {}", path); |
| 1502 | |
| 1503 | // Valid TPM Enable object found, now reading the current value |
| 1504 | dbus::utility::getProperty<bool>( |
| 1505 | service, path, "xyz.openbmc_project.Control.TPM.Policy", "TPMEnable", |
| 1506 | [asyncResp](const boost::system::error_code& ec2, bool tpmRequired) { |
| 1507 | if (ec2) |
| 1508 | { |
| 1509 | BMCWEB_LOG_ERROR("D-BUS response error on TPM.Policy Get{}", |
| 1510 | ec2); |
| 1511 | messages::internalError(asyncResp->res); |
| 1512 | return; |
| 1513 | } |
| 1514 | |
| 1515 | if (tpmRequired) |
| 1516 | { |
| 1517 | asyncResp->res |
| 1518 | .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = |
| 1519 | "Required"; |
| 1520 | } |
| 1521 | else |
| 1522 | { |
| 1523 | asyncResp->res |
| 1524 | .jsonValue["Boot"]["TrustedModuleRequiredToBoot"] = |
| 1525 | "Disabled"; |
| 1526 | } |
| 1527 | }); |
| 1528 | } |
| 1529 | |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1530 | /** |
Ali Ahmed | 1981771 | 2021-06-29 17:01:52 -0500 | [diff] [blame] | 1531 | * @brief Get TrustedModuleRequiredToBoot property. Determines whether or not |
| 1532 | * TPM is required for booting the host. |
| 1533 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1534 | * @param[in] asyncResp Shared pointer for generating response message. |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1535 | * @param[in] computerSystemIndex Index associated with the requested system |
Ali Ahmed | 1981771 | 2021-06-29 17:01:52 -0500 | [diff] [blame] | 1536 | * |
| 1537 | * @return None. |
| 1538 | */ |
| 1539 | inline void getTrustedModuleRequiredToBoot( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1540 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1541 | const uint64_t computerSystemIndex) |
Ali Ahmed | 1981771 | 2021-06-29 17:01:52 -0500 | [diff] [blame] | 1542 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1543 | BMCWEB_LOG_DEBUG("Get TPM required to boot."); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1544 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1545 | "xyz.openbmc_project.Control.TPM.Policy"}; |
| 1546 | dbus::utility::getSubTree( |
| 1547 | "/", 0, interfaces, |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 1548 | std::bind_front(getTrustedModuleRequiredToBootCallback, asyncResp, |
| 1549 | computerSystemIndex)); |
Ali Ahmed | 1981771 | 2021-06-29 17:01:52 -0500 | [diff] [blame] | 1550 | } |
| 1551 | |
| 1552 | /** |
Ali Ahmed | 1c05dae | 2021-06-29 17:49:22 -0500 | [diff] [blame] | 1553 | * @brief Set TrustedModuleRequiredToBoot property. Determines whether or not |
| 1554 | * TPM is required for booting the host. |
| 1555 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1556 | * @param[in] asyncResp Shared pointer for generating response message. |
Ali Ahmed | 1c05dae | 2021-06-29 17:49:22 -0500 | [diff] [blame] | 1557 | * @param[in] tpmRequired Value to set TPM Required To Boot property to. |
| 1558 | * |
| 1559 | * @return None. |
| 1560 | */ |
| 1561 | inline void setTrustedModuleRequiredToBoot( |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1562 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, const bool tpmRequired) |
Ali Ahmed | 1c05dae | 2021-06-29 17:49:22 -0500 | [diff] [blame] | 1563 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1564 | BMCWEB_LOG_DEBUG("Set TrustedModuleRequiredToBoot."); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1565 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1566 | "xyz.openbmc_project.Control.TPM.Policy"}; |
| 1567 | dbus::utility::getSubTree( |
| 1568 | "/", 0, interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1569 | [asyncResp, |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1570 | tpmRequired](const boost::system::error_code& ec, |
| 1571 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1572 | if (ec) |
| 1573 | { |
| 1574 | BMCWEB_LOG_ERROR( |
| 1575 | "DBUS response error on TPM.Policy GetSubTree{}", ec); |
| 1576 | messages::internalError(asyncResp->res); |
| 1577 | return; |
| 1578 | } |
| 1579 | if (subtree.empty()) |
| 1580 | { |
| 1581 | messages::propertyValueNotInList(asyncResp->res, |
| 1582 | "ComputerSystem", |
| 1583 | "TrustedModuleRequiredToBoot"); |
| 1584 | return; |
| 1585 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1586 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1587 | /* When there is more than one TPMEnable object... */ |
| 1588 | if (subtree.size() > 1) |
| 1589 | { |
| 1590 | BMCWEB_LOG_DEBUG( |
| 1591 | "DBUS response has more than 1 TPM Enable object:{}", |
| 1592 | subtree.size()); |
| 1593 | // Throw an internal Error and return |
| 1594 | messages::internalError(asyncResp->res); |
| 1595 | return; |
| 1596 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1597 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1598 | // Make sure the Dbus response map has a service and objectPath |
| 1599 | // field |
| 1600 | if (subtree[0].first.empty() || subtree[0].second.size() != 1) |
| 1601 | { |
| 1602 | BMCWEB_LOG_DEBUG("TPM.Policy mapper error!"); |
| 1603 | messages::internalError(asyncResp->res); |
| 1604 | return; |
| 1605 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1606 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1607 | const std::string& path = subtree[0].first; |
| 1608 | const std::string& serv = subtree[0].second.begin()->first; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1609 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1610 | if (serv.empty()) |
| 1611 | { |
| 1612 | BMCWEB_LOG_DEBUG("TPM.Policy service mapper error!"); |
| 1613 | messages::internalError(asyncResp->res); |
| 1614 | return; |
| 1615 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1616 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1617 | // Valid TPM Enable object found, now setting the value |
| 1618 | setDbusProperty(asyncResp, "Boot/TrustedModuleRequiredToBoot", serv, |
| 1619 | path, "xyz.openbmc_project.Control.TPM.Policy", |
| 1620 | "TPMEnable", tpmRequired); |
| 1621 | }); |
Ali Ahmed | 1c05dae | 2021-06-29 17:49:22 -0500 | [diff] [blame] | 1622 | } |
| 1623 | |
| 1624 | /** |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1625 | * @brief Sets boot properties into DBUS object(s). |
| 1626 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1627 | * @param[in] asyncResp Shared pointer for generating response message. |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1628 | * @param[in] bootType The boot type to set. |
| 1629 | * @return Integer error code. |
| 1630 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1631 | inline void setBootType(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1632 | const std::optional<std::string>& bootType) |
| 1633 | { |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1634 | std::string bootTypeStr; |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1635 | |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1636 | if (!bootType) |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1637 | { |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1638 | return; |
| 1639 | } |
| 1640 | |
| 1641 | // Source target specified |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1642 | BMCWEB_LOG_DEBUG("Boot type: {}", *bootType); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1643 | // Figure out which DBUS interface and property to use |
| 1644 | if (*bootType == "Legacy") |
| 1645 | { |
| 1646 | bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.Legacy"; |
| 1647 | } |
| 1648 | else if (*bootType == "UEFI") |
| 1649 | { |
| 1650 | bootTypeStr = "xyz.openbmc_project.Control.Boot.Type.Types.EFI"; |
| 1651 | } |
| 1652 | else |
| 1653 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1654 | BMCWEB_LOG_DEBUG("Invalid property value for " |
| 1655 | "BootSourceOverrideMode: {}", |
| 1656 | *bootType); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1657 | messages::propertyValueNotInList(asyncResp->res, *bootType, |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1658 | "BootSourceOverrideMode"); |
| 1659 | return; |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1660 | } |
| 1661 | |
| 1662 | // Act on validated parameters |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1663 | BMCWEB_LOG_DEBUG("DBUS boot type: {}", bootTypeStr); |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1664 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1665 | setDbusProperty(asyncResp, "Boot/BootSourceOverrideMode", |
| 1666 | "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1667 | sdbusplus::message::object_path( |
| 1668 | "/xyz/openbmc_project/control/host0/boot"), |
| 1669 | "xyz.openbmc_project.Control.Boot.Type", "BootType", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1670 | bootTypeStr); |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1671 | } |
| 1672 | |
| 1673 | /** |
| 1674 | * @brief Sets boot properties into DBUS object(s). |
| 1675 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1676 | * @param[in] asyncResp Shared pointer for generating response |
| 1677 | * message. |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1678 | * @param[in] bootType The boot type to set. |
| 1679 | * @return Integer error code. |
| 1680 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1681 | inline void setBootEnable(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1682 | const std::optional<std::string>& bootEnable) |
| 1683 | { |
| 1684 | if (!bootEnable) |
| 1685 | { |
| 1686 | return; |
| 1687 | } |
| 1688 | // Source target specified |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1689 | BMCWEB_LOG_DEBUG("Boot enable: {}", *bootEnable); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1690 | |
| 1691 | bool bootOverrideEnable = false; |
| 1692 | bool bootOverridePersistent = false; |
| 1693 | // Figure out which DBUS interface and property to use |
| 1694 | if (*bootEnable == "Disabled") |
| 1695 | { |
| 1696 | bootOverrideEnable = false; |
| 1697 | } |
| 1698 | else if (*bootEnable == "Once") |
| 1699 | { |
| 1700 | bootOverrideEnable = true; |
| 1701 | bootOverridePersistent = false; |
| 1702 | } |
| 1703 | else if (*bootEnable == "Continuous") |
| 1704 | { |
| 1705 | bootOverrideEnable = true; |
| 1706 | bootOverridePersistent = true; |
| 1707 | } |
| 1708 | else |
| 1709 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1710 | BMCWEB_LOG_DEBUG( |
| 1711 | "Invalid property value for BootSourceOverrideEnabled: {}", |
| 1712 | *bootEnable); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1713 | messages::propertyValueNotInList(asyncResp->res, *bootEnable, |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1714 | "BootSourceOverrideEnabled"); |
| 1715 | return; |
| 1716 | } |
| 1717 | |
| 1718 | // Act on validated parameters |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1719 | BMCWEB_LOG_DEBUG("DBUS boot override enable: {}", bootOverrideEnable); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1720 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1721 | setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled", |
| 1722 | "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1723 | sdbusplus::message::object_path( |
| 1724 | "/xyz/openbmc_project/control/host0/boot"), |
| 1725 | "xyz.openbmc_project.Object.Enable", "Enabled", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1726 | bootOverrideEnable); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1727 | |
| 1728 | if (!bootOverrideEnable) |
| 1729 | { |
| 1730 | return; |
| 1731 | } |
| 1732 | |
| 1733 | // In case boot override is enabled we need to set correct value for the |
| 1734 | // 'one_time' enable DBus interface |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1735 | BMCWEB_LOG_DEBUG("DBUS boot override persistent: {}", |
| 1736 | bootOverridePersistent); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1737 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1738 | setDbusProperty(asyncResp, "Boot/BootSourceOverrideEnabled", |
| 1739 | "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1740 | sdbusplus::message::object_path( |
| 1741 | "/xyz/openbmc_project/control/host0/boot/one_time"), |
| 1742 | "xyz.openbmc_project.Object.Enable", "Enabled", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1743 | !bootOverridePersistent); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1744 | } |
| 1745 | |
| 1746 | /** |
| 1747 | * @brief Sets boot properties into DBUS object(s). |
| 1748 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1749 | * @param[in] asyncResp Shared pointer for generating response message. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1750 | * @param[in] bootSource The boot source to set. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1751 | * |
Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1752 | * @return Integer error code. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1753 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1754 | inline void setBootModeOrSource( |
| 1755 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1756 | const std::optional<std::string>& bootSource) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1757 | { |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1758 | std::string bootSourceStr; |
| 1759 | std::string bootModeStr; |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1760 | |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1761 | if (!bootSource) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1762 | { |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1763 | return; |
| 1764 | } |
| 1765 | |
| 1766 | // Source target specified |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1767 | BMCWEB_LOG_DEBUG("Boot source: {}", *bootSource); |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1768 | // Figure out which DBUS interface and property to use |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1769 | if (assignBootParameters(asyncResp, *bootSource, bootSourceStr, |
| 1770 | bootModeStr) != 0) |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1771 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1772 | BMCWEB_LOG_DEBUG( |
| 1773 | "Invalid property value for BootSourceOverrideTarget: {}", |
| 1774 | *bootSource); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1775 | messages::propertyValueNotInList(asyncResp->res, *bootSource, |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1776 | "BootSourceTargetOverride"); |
| 1777 | return; |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1778 | } |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1779 | |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1780 | // Act on validated parameters |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1781 | BMCWEB_LOG_DEBUG("DBUS boot source: {}", bootSourceStr); |
| 1782 | BMCWEB_LOG_DEBUG("DBUS boot mode: {}", bootModeStr); |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1783 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1784 | setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget", |
| 1785 | "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1786 | sdbusplus::message::object_path( |
| 1787 | "/xyz/openbmc_project/control/host0/boot"), |
| 1788 | "xyz.openbmc_project.Control.Boot.Source", "BootSource", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1789 | bootSourceStr); |
| 1790 | setDbusProperty(asyncResp, "Boot/BootSourceOverrideTarget", |
| 1791 | "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1792 | sdbusplus::message::object_path( |
| 1793 | "/xyz/openbmc_project/control/host0/boot"), |
| 1794 | "xyz.openbmc_project.Control.Boot.Mode", "BootMode", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1795 | bootModeStr); |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1796 | } |
Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1797 | |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1798 | /** |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1799 | * @brief Sets Boot source override properties. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1800 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1801 | * @param[in] asyncResp Shared pointer for generating response message. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1802 | * @param[in] bootSource The boot source from incoming RF request. |
Konstantin Aladyshev | cd9a466 | 2021-02-26 12:37:07 +0300 | [diff] [blame] | 1803 | * @param[in] bootType The boot type from incoming RF request. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1804 | * @param[in] bootEnable The boot override enable from incoming RF request. |
| 1805 | * |
Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1806 | * @return Integer error code. |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1807 | */ |
Konstantin Aladyshev | c21865c | 2021-06-21 14:49:16 +0300 | [diff] [blame] | 1808 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1809 | inline void setBootProperties( |
| 1810 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1811 | const std::optional<std::string>& bootSource, |
| 1812 | const std::optional<std::string>& bootType, |
| 1813 | const std::optional<std::string>& bootEnable) |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1814 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1815 | BMCWEB_LOG_DEBUG("Set boot information."); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1816 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1817 | setBootModeOrSource(asyncResp, bootSource); |
| 1818 | setBootType(asyncResp, bootType); |
| 1819 | setBootEnable(asyncResp, bootEnable); |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1820 | } |
| 1821 | |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1822 | /** |
Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 1823 | * @brief Sets AssetTag |
| 1824 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1825 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 1826 | * @param[in] assetTag "AssetTag" from request. |
| 1827 | * |
| 1828 | * @return None. |
| 1829 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1830 | inline void setAssetTag(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 1831 | const std::string& assetTag) |
| 1832 | { |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1833 | constexpr std::array<std::string_view, 1> interfaces = { |
| 1834 | "xyz.openbmc_project.Inventory.Item.System"}; |
| 1835 | dbus::utility::getSubTree( |
| 1836 | "/xyz/openbmc_project/inventory", 0, interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1837 | [asyncResp, |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 1838 | assetTag](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 1839 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1840 | if (ec) |
| 1841 | { |
| 1842 | BMCWEB_LOG_DEBUG("D-Bus response error on GetSubTree {}", ec); |
| 1843 | messages::internalError(asyncResp->res); |
| 1844 | return; |
| 1845 | } |
| 1846 | if (subtree.empty()) |
| 1847 | { |
| 1848 | BMCWEB_LOG_DEBUG("Can't find system D-Bus object!"); |
| 1849 | messages::internalError(asyncResp->res); |
| 1850 | return; |
| 1851 | } |
| 1852 | // Assume only 1 system D-Bus object |
| 1853 | // Throw an error if there is more than 1 |
| 1854 | if (subtree.size() > 1) |
| 1855 | { |
| 1856 | BMCWEB_LOG_DEBUG("Found more than 1 system D-Bus object!"); |
| 1857 | messages::internalError(asyncResp->res); |
| 1858 | return; |
| 1859 | } |
| 1860 | if (subtree[0].first.empty() || subtree[0].second.size() != 1) |
| 1861 | { |
| 1862 | BMCWEB_LOG_DEBUG("Asset Tag Set mapper error!"); |
| 1863 | messages::internalError(asyncResp->res); |
| 1864 | return; |
| 1865 | } |
Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 1866 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1867 | const std::string& path = subtree[0].first; |
| 1868 | const std::string& service = subtree[0].second.begin()->first; |
Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 1869 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1870 | if (service.empty()) |
| 1871 | { |
| 1872 | BMCWEB_LOG_DEBUG("Asset Tag Set service mapper error!"); |
| 1873 | messages::internalError(asyncResp->res); |
| 1874 | return; |
| 1875 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 1876 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 1877 | setDbusProperty(asyncResp, "AssetTag", service, path, |
| 1878 | "xyz.openbmc_project.Inventory.Decorator.AssetTag", |
| 1879 | "AssetTag", assetTag); |
| 1880 | }); |
Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 1881 | } |
| 1882 | |
| 1883 | /** |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1884 | * @brief Validate the specified stopBootOnFault is valid and return the |
| 1885 | * stopBootOnFault name associated with that string |
| 1886 | * |
| 1887 | * @param[in] stopBootOnFaultString String representing the desired |
| 1888 | * stopBootOnFault |
| 1889 | * |
| 1890 | * @return stopBootOnFault value or empty if incoming value is not valid |
| 1891 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1892 | inline std::optional<bool> validstopBootOnFault( |
| 1893 | const std::string& stopBootOnFaultString) |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1894 | { |
| 1895 | if (stopBootOnFaultString == "AnyFault") |
| 1896 | { |
| 1897 | return true; |
| 1898 | } |
| 1899 | |
| 1900 | if (stopBootOnFaultString == "Never") |
| 1901 | { |
| 1902 | return false; |
| 1903 | } |
| 1904 | |
| 1905 | return std::nullopt; |
| 1906 | } |
| 1907 | |
| 1908 | /** |
| 1909 | * @brief Sets stopBootOnFault |
| 1910 | * |
Ed Tanous | fc3edfd | 2023-07-20 12:41:30 -0700 | [diff] [blame] | 1911 | * @param[in] asyncResp Shared pointer for generating response message. |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1912 | * @param[in] stopBootOnFault "StopBootOnFault" from request. |
| 1913 | * |
| 1914 | * @return None. |
| 1915 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1916 | inline void setStopBootOnFault( |
| 1917 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1918 | const std::string& stopBootOnFault) |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1919 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1920 | BMCWEB_LOG_DEBUG("Set Stop Boot On Fault."); |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1921 | |
| 1922 | std::optional<bool> stopBootEnabled = validstopBootOnFault(stopBootOnFault); |
| 1923 | if (!stopBootEnabled) |
| 1924 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1925 | BMCWEB_LOG_DEBUG("Invalid property value for StopBootOnFault: {}", |
| 1926 | stopBootOnFault); |
Ed Tanous | fc3edfd | 2023-07-20 12:41:30 -0700 | [diff] [blame] | 1927 | messages::propertyValueNotInList(asyncResp->res, stopBootOnFault, |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1928 | "StopBootOnFault"); |
| 1929 | return; |
| 1930 | } |
| 1931 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1932 | setDbusProperty(asyncResp, "Boot/StopBootOnFault", |
| 1933 | "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1934 | sdbusplus::message::object_path( |
| 1935 | "/xyz/openbmc_project/logging/settings"), |
| 1936 | "xyz.openbmc_project.Logging.Settings", "QuiesceOnHwError", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1937 | *stopBootEnabled); |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 1938 | } |
| 1939 | |
| 1940 | /** |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1941 | * @brief Sets automaticRetry (Auto Reboot) |
| 1942 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1943 | * @param[in] asyncResp Shared pointer for generating response message. |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1944 | * @param[in] automaticRetryConfig "AutomaticRetryConfig" from request. |
| 1945 | * |
| 1946 | * @return None. |
| 1947 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 1948 | inline void setAutomaticRetry( |
| 1949 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 1950 | const std::string& automaticRetryConfig) |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1951 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1952 | BMCWEB_LOG_DEBUG("Set Automatic Retry."); |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1953 | |
| 1954 | // OpenBMC only supports "Disabled" and "RetryAttempts". |
Ed Tanous | 543f440 | 2022-01-06 13:12:53 -0800 | [diff] [blame] | 1955 | bool autoRebootEnabled = false; |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1956 | |
| 1957 | if (automaticRetryConfig == "Disabled") |
| 1958 | { |
| 1959 | autoRebootEnabled = false; |
| 1960 | } |
| 1961 | else if (automaticRetryConfig == "RetryAttempts") |
| 1962 | { |
| 1963 | autoRebootEnabled = true; |
| 1964 | } |
| 1965 | else |
| 1966 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 1967 | BMCWEB_LOG_DEBUG("Invalid property value for AutomaticRetryConfig: {}", |
| 1968 | automaticRetryConfig); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 1969 | messages::propertyValueNotInList(asyncResp->res, automaticRetryConfig, |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1970 | "AutomaticRetryConfig"); |
| 1971 | return; |
| 1972 | } |
| 1973 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1974 | setDbusProperty(asyncResp, "Boot/AutomaticRetryConfig", |
| 1975 | "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 1976 | sdbusplus::message::object_path( |
| 1977 | "/xyz/openbmc_project/control/host0/auto_reboot"), |
| 1978 | "xyz.openbmc_project.Control.Boot.RebootPolicy", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 1979 | "AutoReboot", autoRebootEnabled); |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1980 | } |
| 1981 | |
Ed Tanous | 8d69c66 | 2023-06-21 10:29:06 -0700 | [diff] [blame] | 1982 | inline std::string dbusPowerRestorePolicyFromRedfish(std::string_view policy) |
| 1983 | { |
| 1984 | if (policy == "AlwaysOn") |
| 1985 | { |
| 1986 | return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOn"; |
| 1987 | } |
| 1988 | if (policy == "AlwaysOff") |
| 1989 | { |
| 1990 | return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.AlwaysOff"; |
| 1991 | } |
| 1992 | if (policy == "LastState") |
| 1993 | { |
| 1994 | return "xyz.openbmc_project.Control.Power.RestorePolicy.Policy.Restore"; |
| 1995 | } |
| 1996 | return ""; |
| 1997 | } |
| 1998 | |
Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1999 | /** |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2000 | * @brief Sets power restore policy properties. |
| 2001 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2002 | * @param[in] asyncResp Shared pointer for generating response message. |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2003 | * @param[in] policy power restore policy properties from request. |
| 2004 | * |
| 2005 | * @return None. |
| 2006 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2007 | inline void setPowerRestorePolicy( |
| 2008 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2009 | std::string_view policy) |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2010 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2011 | BMCWEB_LOG_DEBUG("Set power restore policy."); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2012 | |
Ed Tanous | 8d69c66 | 2023-06-21 10:29:06 -0700 | [diff] [blame] | 2013 | std::string powerRestorePolicy = dbusPowerRestorePolicyFromRedfish(policy); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2014 | |
Ed Tanous | 8d69c66 | 2023-06-21 10:29:06 -0700 | [diff] [blame] | 2015 | if (powerRestorePolicy.empty()) |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2016 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2017 | messages::propertyValueNotInList(asyncResp->res, policy, |
Gunnar Mills | 4e69c90 | 2021-01-05 19:50:11 -0600 | [diff] [blame] | 2018 | "PowerRestorePolicy"); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2019 | return; |
| 2020 | } |
| 2021 | |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 2022 | setDbusProperty( |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2023 | asyncResp, "PowerRestorePolicy", "xyz.openbmc_project.Settings", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 2024 | sdbusplus::message::object_path( |
| 2025 | "/xyz/openbmc_project/control/host0/power_restore_policy"), |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2026 | "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2027 | powerRestorePolicy); |
George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2028 | } |
| 2029 | |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2030 | /** |
| 2031 | * @brief Retrieves provisioning status |
| 2032 | * |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2033 | * @param[in] asyncResp Shared pointer for completing asynchronous |
| 2034 | * calls. |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2035 | * |
| 2036 | * @return None. |
| 2037 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2038 | inline void getProvisioningStatus( |
| 2039 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2040 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2041 | BMCWEB_LOG_DEBUG("Get OEM information."); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2042 | dbus::utility::getAllProperties( |
| 2043 | "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", |
| 2044 | "xyz.openbmc_project.PFR.Attributes", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2045 | [asyncResp](const boost::system::error_code& ec, |
| 2046 | const dbus::utility::DBusPropertiesMap& propertiesList) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2047 | nlohmann::json& oemPFR = |
| 2048 | asyncResp->res |
| 2049 | .jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; |
| 2050 | asyncResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = |
| 2051 | "#OpenBMCComputerSystem.v1_0_0.OpenBmc"; |
| 2052 | oemPFR["@odata.type"] = |
| 2053 | "#OpenBMCComputerSystem.FirmwareProvisioning"; |
James Feist | 50626f4 | 2020-09-23 14:40:47 -0700 | [diff] [blame] | 2054 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2055 | if (ec) |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2056 | { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2057 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
| 2058 | // not an error, don't have to have the interface |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2059 | oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2060 | FirmwareProvisioningStatus::NotProvisioned; |
| 2061 | return; |
| 2062 | } |
| 2063 | |
| 2064 | const bool* provState = nullptr; |
| 2065 | const bool* lockState = nullptr; |
| 2066 | |
| 2067 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 2068 | dbus_utils::UnpackErrorPrinter(), propertiesList, |
| 2069 | "UfmProvisioned", provState, "UfmLocked", lockState); |
| 2070 | |
| 2071 | if (!success) |
| 2072 | { |
| 2073 | messages::internalError(asyncResp->res); |
| 2074 | return; |
| 2075 | } |
| 2076 | |
| 2077 | if ((provState == nullptr) || (lockState == nullptr)) |
| 2078 | { |
| 2079 | BMCWEB_LOG_DEBUG("Unable to get PFR attributes."); |
| 2080 | messages::internalError(asyncResp->res); |
| 2081 | return; |
| 2082 | } |
| 2083 | |
| 2084 | if (*provState) |
| 2085 | { |
| 2086 | if (*lockState) |
| 2087 | { |
| 2088 | oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: |
| 2089 | FirmwareProvisioningStatus::ProvisionedAndLocked; |
| 2090 | } |
| 2091 | else |
| 2092 | { |
| 2093 | oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: |
| 2094 | FirmwareProvisioningStatus::ProvisionedButNotLocked; |
| 2095 | } |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2096 | } |
| 2097 | else |
| 2098 | { |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 2099 | oemPFR["ProvisioningStatus"] = open_bmc_computer_system:: |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2100 | FirmwareProvisioningStatus::NotProvisioned; |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2101 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2102 | }); |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2103 | } |
AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2104 | |
Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2105 | /** |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2106 | * @brief Translate the PowerMode string to enum value |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2107 | * |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2108 | * @param[in] modeString PowerMode string to be translated |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2109 | * |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2110 | * @return PowerMode enum |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2111 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2112 | inline computer_system::PowerMode translatePowerModeString( |
| 2113 | const std::string& modeString) |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2114 | { |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2115 | using PowerMode = computer_system::PowerMode; |
| 2116 | |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2117 | if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static") |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2118 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2119 | return PowerMode::Static; |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2120 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2121 | if (modeString == |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2122 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance") |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2123 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2124 | return PowerMode::MaximumPerformance; |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2125 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2126 | if (modeString == |
| 2127 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving") |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2128 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2129 | return PowerMode::PowerSaving; |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2130 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2131 | if (modeString == |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2132 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance") |
| 2133 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2134 | return PowerMode::BalancedPerformance; |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2135 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2136 | if (modeString == |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2137 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance") |
| 2138 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2139 | return PowerMode::EfficiencyFavorPerformance; |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2140 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2141 | if (modeString == |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2142 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower") |
| 2143 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2144 | return PowerMode::EfficiencyFavorPower; |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2145 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2146 | if (modeString == "xyz.openbmc_project.Control.Power.Mode.PowerMode.OEM") |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2147 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2148 | return PowerMode::OEM; |
| 2149 | } |
| 2150 | // Any other values would be invalid |
| 2151 | BMCWEB_LOG_ERROR("PowerMode value was not valid: {}", modeString); |
| 2152 | return PowerMode::Invalid; |
| 2153 | } |
| 2154 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2155 | inline void afterGetPowerMode( |
| 2156 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2157 | const boost::system::error_code& ec, |
| 2158 | const dbus::utility::DBusPropertiesMap& properties) |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2159 | { |
| 2160 | if (ec) |
| 2161 | { |
| 2162 | BMCWEB_LOG_ERROR("DBUS response error on PowerMode GetAll: {}", ec); |
| 2163 | messages::internalError(asyncResp->res); |
| 2164 | return; |
| 2165 | } |
| 2166 | |
| 2167 | std::string powerMode; |
| 2168 | const std::vector<std::string>* allowedModes = nullptr; |
| 2169 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 2170 | dbus_utils::UnpackErrorPrinter(), properties, "PowerMode", powerMode, |
| 2171 | "AllowedPowerModes", allowedModes); |
| 2172 | |
| 2173 | if (!success) |
| 2174 | { |
| 2175 | messages::internalError(asyncResp->res); |
| 2176 | return; |
| 2177 | } |
| 2178 | |
| 2179 | nlohmann::json::array_t modeList; |
| 2180 | if (allowedModes == nullptr) |
| 2181 | { |
| 2182 | modeList.emplace_back("Static"); |
| 2183 | modeList.emplace_back("MaximumPerformance"); |
| 2184 | modeList.emplace_back("PowerSaving"); |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2185 | } |
| 2186 | else |
| 2187 | { |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2188 | for (const auto& aMode : *allowedModes) |
| 2189 | { |
| 2190 | computer_system::PowerMode modeValue = |
| 2191 | translatePowerModeString(aMode); |
| 2192 | if (modeValue == computer_system::PowerMode::Invalid) |
| 2193 | { |
| 2194 | messages::internalError(asyncResp->res); |
| 2195 | continue; |
| 2196 | } |
| 2197 | modeList.emplace_back(modeValue); |
| 2198 | } |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2199 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2200 | asyncResp->res.jsonValue["PowerMode@Redfish.AllowableValues"] = modeList; |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2201 | |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2202 | BMCWEB_LOG_DEBUG("Current power mode: {}", powerMode); |
| 2203 | const computer_system::PowerMode modeValue = |
| 2204 | translatePowerModeString(powerMode); |
| 2205 | if (modeValue == computer_system::PowerMode::Invalid) |
| 2206 | { |
| 2207 | messages::internalError(asyncResp->res); |
| 2208 | return; |
| 2209 | } |
| 2210 | asyncResp->res.jsonValue["PowerMode"] = modeValue; |
| 2211 | } |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2212 | /** |
| 2213 | * @brief Retrieves system power mode |
| 2214 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2215 | * @param[in] asyncResp Shared pointer for generating response message. |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2216 | * |
| 2217 | * @return None. |
| 2218 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2219 | inline void getPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2220 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2221 | BMCWEB_LOG_DEBUG("Get power mode."); |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2222 | |
| 2223 | // Get Power Mode object path: |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2224 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2225 | "xyz.openbmc_project.Control.Power.Mode"}; |
| 2226 | dbus::utility::getSubTree( |
| 2227 | "/", 0, interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2228 | [asyncResp](const boost::system::error_code& ec, |
| 2229 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2230 | if (ec) |
| 2231 | { |
| 2232 | BMCWEB_LOG_DEBUG( |
| 2233 | "DBUS response error on Power.Mode GetSubTree {}", ec); |
| 2234 | // This is an optional D-Bus object so just return if |
| 2235 | // error occurs |
| 2236 | return; |
| 2237 | } |
| 2238 | if (subtree.empty()) |
| 2239 | { |
| 2240 | // As noted above, this is an optional interface so just return |
| 2241 | // if there is no instance found |
| 2242 | return; |
| 2243 | } |
| 2244 | if (subtree.size() > 1) |
| 2245 | { |
| 2246 | // More then one PowerMode object is not supported and is an |
| 2247 | // error |
| 2248 | BMCWEB_LOG_DEBUG( |
| 2249 | "Found more than 1 system D-Bus Power.Mode objects: {}", |
| 2250 | subtree.size()); |
| 2251 | messages::internalError(asyncResp->res); |
| 2252 | return; |
| 2253 | } |
| 2254 | if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) |
| 2255 | { |
| 2256 | BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); |
| 2257 | messages::internalError(asyncResp->res); |
| 2258 | return; |
| 2259 | } |
| 2260 | const std::string& path = subtree[0].first; |
| 2261 | const std::string& service = subtree[0].second.begin()->first; |
| 2262 | if (service.empty()) |
| 2263 | { |
| 2264 | BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); |
| 2265 | messages::internalError(asyncResp->res); |
| 2266 | return; |
| 2267 | } |
Chris Cain | 6b9ac4f | 2024-02-15 12:59:32 -0600 | [diff] [blame] | 2268 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2269 | // Valid Power Mode object found, now read the mode properties |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2270 | dbus::utility::getAllProperties( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2271 | *crow::connections::systemBus, service, path, |
| 2272 | "xyz.openbmc_project.Control.Power.Mode", |
| 2273 | [asyncResp]( |
| 2274 | const boost::system::error_code& ec2, |
| 2275 | const dbus::utility::DBusPropertiesMap& properties) { |
| 2276 | afterGetPowerMode(asyncResp, ec2, properties); |
| 2277 | }); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2278 | }); |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2279 | } |
| 2280 | |
| 2281 | /** |
| 2282 | * @brief Validate the specified mode is valid and return the PowerMode |
| 2283 | * name associated with that string |
| 2284 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2285 | * @param[in] asyncResp Shared pointer for generating response message. |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2286 | * @param[in] modeValue String representing the desired PowerMode |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2287 | * |
| 2288 | * @return PowerMode value or empty string if mode is not valid |
| 2289 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2290 | inline std::string validatePowerMode( |
| 2291 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2292 | const nlohmann::json& modeValue) |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2293 | { |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2294 | using PowerMode = computer_system::PowerMode; |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2295 | std::string mode; |
| 2296 | |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2297 | if (modeValue == PowerMode::Static) |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2298 | { |
| 2299 | mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.Static"; |
| 2300 | } |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2301 | else if (modeValue == PowerMode::MaximumPerformance) |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2302 | { |
George Liu | 0fda0f1 | 2021-11-16 10:06:17 +0800 | [diff] [blame] | 2303 | mode = |
| 2304 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.MaximumPerformance"; |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2305 | } |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2306 | else if (modeValue == PowerMode::PowerSaving) |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2307 | { |
| 2308 | mode = "xyz.openbmc_project.Control.Power.Mode.PowerMode.PowerSaving"; |
| 2309 | } |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2310 | else if (modeValue == PowerMode::BalancedPerformance) |
| 2311 | { |
| 2312 | mode = |
| 2313 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.BalancedPerformance"; |
| 2314 | } |
| 2315 | else if (modeValue == PowerMode::EfficiencyFavorPerformance) |
| 2316 | { |
| 2317 | mode = |
| 2318 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPerformance"; |
| 2319 | } |
| 2320 | else if (modeValue == PowerMode::EfficiencyFavorPower) |
| 2321 | { |
| 2322 | mode = |
| 2323 | "xyz.openbmc_project.Control.Power.Mode.PowerMode.EfficiencyFavorPower"; |
| 2324 | } |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2325 | else |
| 2326 | { |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 2327 | messages::propertyValueNotInList(asyncResp->res, modeValue.dump(), |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2328 | "PowerMode"); |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2329 | } |
| 2330 | return mode; |
| 2331 | } |
| 2332 | |
| 2333 | /** |
| 2334 | * @brief Sets system power mode. |
| 2335 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2336 | * @param[in] asyncResp Shared pointer for generating response message. |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2337 | * @param[in] pmode System power mode from request. |
| 2338 | * |
| 2339 | * @return None. |
| 2340 | */ |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2341 | inline void setPowerMode(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2342 | const std::string& pmode) |
| 2343 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2344 | BMCWEB_LOG_DEBUG("Set power mode."); |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2345 | |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2346 | std::string powerMode = validatePowerMode(asyncResp, pmode); |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2347 | if (powerMode.empty()) |
| 2348 | { |
| 2349 | return; |
| 2350 | } |
| 2351 | |
| 2352 | // Get Power Mode object path: |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2353 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2354 | "xyz.openbmc_project.Control.Power.Mode"}; |
| 2355 | dbus::utility::getSubTree( |
| 2356 | "/", 0, interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2357 | [asyncResp, |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2358 | powerMode](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2359 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2360 | if (ec) |
| 2361 | { |
| 2362 | BMCWEB_LOG_ERROR( |
| 2363 | "DBUS response error on Power.Mode GetSubTree {}", ec); |
| 2364 | // This is an optional D-Bus object, but user attempted to patch |
| 2365 | messages::internalError(asyncResp->res); |
| 2366 | return; |
| 2367 | } |
| 2368 | if (subtree.empty()) |
| 2369 | { |
| 2370 | // This is an optional D-Bus object, but user attempted to patch |
| 2371 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2372 | "PowerMode"); |
| 2373 | return; |
| 2374 | } |
| 2375 | if (subtree.size() > 1) |
| 2376 | { |
| 2377 | // More then one PowerMode object is not supported and is an |
| 2378 | // error |
| 2379 | BMCWEB_LOG_DEBUG( |
| 2380 | "Found more than 1 system D-Bus Power.Mode objects: {}", |
| 2381 | subtree.size()); |
| 2382 | messages::internalError(asyncResp->res); |
| 2383 | return; |
| 2384 | } |
| 2385 | if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) |
| 2386 | { |
| 2387 | BMCWEB_LOG_DEBUG("Power.Mode mapper error!"); |
| 2388 | messages::internalError(asyncResp->res); |
| 2389 | return; |
| 2390 | } |
| 2391 | const std::string& path = subtree[0].first; |
| 2392 | const std::string& service = subtree[0].second.begin()->first; |
| 2393 | if (service.empty()) |
| 2394 | { |
| 2395 | BMCWEB_LOG_DEBUG("Power.Mode service mapper error!"); |
| 2396 | messages::internalError(asyncResp->res); |
| 2397 | return; |
| 2398 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2399 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2400 | BMCWEB_LOG_DEBUG("Setting power mode({}) -> {}", powerMode, path); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2401 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2402 | // Set the Power Mode property |
| 2403 | setDbusProperty(asyncResp, "PowerMode", service, path, |
| 2404 | "xyz.openbmc_project.Control.Power.Mode", |
| 2405 | "PowerMode", powerMode); |
| 2406 | }); |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 2407 | } |
| 2408 | |
| 2409 | /** |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2410 | * @brief Translates watchdog timeout action DBUS property value to redfish. |
| 2411 | * |
| 2412 | * @param[in] dbusAction The watchdog timeout action in D-BUS. |
| 2413 | * |
| 2414 | * @return Returns as a string, the timeout action in Redfish terms. If |
| 2415 | * translation cannot be done, returns an empty string. |
| 2416 | */ |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2417 | inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2418 | { |
| 2419 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") |
| 2420 | { |
| 2421 | return "None"; |
| 2422 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 2423 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2424 | { |
| 2425 | return "ResetSystem"; |
| 2426 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 2427 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2428 | { |
| 2429 | return "PowerDown"; |
| 2430 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 2431 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2432 | { |
| 2433 | return "PowerCycle"; |
| 2434 | } |
| 2435 | |
| 2436 | return ""; |
| 2437 | } |
| 2438 | |
| 2439 | /** |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2440 | *@brief Translates timeout action from Redfish to DBUS property value. |
| 2441 | * |
| 2442 | *@param[in] rfAction The timeout action in Redfish. |
| 2443 | * |
| 2444 | *@return Returns as a string, the time_out action as expected by DBUS. |
| 2445 | *If translation cannot be done, returns an empty string. |
| 2446 | */ |
| 2447 | |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 2448 | inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2449 | { |
| 2450 | if (rfAction == "None") |
| 2451 | { |
| 2452 | return "xyz.openbmc_project.State.Watchdog.Action.None"; |
| 2453 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 2454 | if (rfAction == "PowerCycle") |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2455 | { |
| 2456 | return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; |
| 2457 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 2458 | if (rfAction == "PowerDown") |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2459 | { |
| 2460 | return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; |
| 2461 | } |
Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 2462 | if (rfAction == "ResetSystem") |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2463 | { |
| 2464 | return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; |
| 2465 | } |
| 2466 | |
| 2467 | return ""; |
| 2468 | } |
| 2469 | |
| 2470 | /** |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2471 | * @brief Retrieves host watchdog timer properties over DBUS |
| 2472 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2473 | * @param[in] asyncResp Shared pointer for completing asynchronous calls. |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2474 | * |
| 2475 | * @return None. |
| 2476 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2477 | inline void getHostWatchdogTimer( |
| 2478 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2479 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2480 | BMCWEB_LOG_DEBUG("Get host watchodg"); |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2481 | dbus::utility::getAllProperties( |
| 2482 | "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2483 | "xyz.openbmc_project.State.Watchdog", |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2484 | [asyncResp](const boost::system::error_code& ec, |
| 2485 | const dbus::utility::DBusPropertiesMap& properties) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2486 | if (ec) |
| 2487 | { |
| 2488 | // watchdog service is stopped |
| 2489 | BMCWEB_LOG_DEBUG("DBUS response error {}", ec); |
| 2490 | return; |
| 2491 | } |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2492 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2493 | BMCWEB_LOG_DEBUG("Got {} wdt prop.", properties.size()); |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2494 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2495 | nlohmann::json& hostWatchdogTimer = |
| 2496 | asyncResp->res.jsonValue["HostWatchdogTimer"]; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2497 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2498 | // watchdog service is running/enabled |
| 2499 | hostWatchdogTimer["Status"]["State"] = resource::State::Enabled; |
Ed Tanous | 002d39b | 2022-05-31 08:59:27 -0700 | [diff] [blame] | 2500 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2501 | const bool* enabled = nullptr; |
| 2502 | const std::string* expireAction = nullptr; |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2503 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2504 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 2505 | dbus_utils::UnpackErrorPrinter(), properties, "Enabled", |
| 2506 | enabled, "ExpireAction", expireAction); |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2507 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2508 | if (!success) |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2509 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2510 | messages::internalError(asyncResp->res); |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2511 | return; |
| 2512 | } |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2513 | |
| 2514 | if (enabled != nullptr) |
| 2515 | { |
| 2516 | hostWatchdogTimer["FunctionEnabled"] = *enabled; |
| 2517 | } |
| 2518 | |
| 2519 | if (expireAction != nullptr) |
| 2520 | { |
| 2521 | std::string action = dbusToRfWatchdogAction(*expireAction); |
| 2522 | if (action.empty()) |
| 2523 | { |
| 2524 | messages::internalError(asyncResp->res); |
| 2525 | return; |
| 2526 | } |
| 2527 | hostWatchdogTimer["TimeoutAction"] = action; |
| 2528 | } |
| 2529 | }); |
Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2530 | } |
| 2531 | |
| 2532 | /** |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2533 | * @brief Sets Host WatchDog Timer properties. |
| 2534 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2535 | * @param[in] asyncResp Shared pointer for generating response message. |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2536 | * @param[in] wdtEnable The WDTimer Enable value (true/false) from incoming |
| 2537 | * RF request. |
| 2538 | * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. |
| 2539 | * |
| 2540 | * @return None. |
| 2541 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2542 | inline void setWDTProperties( |
| 2543 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2544 | const std::optional<bool> wdtEnable, |
| 2545 | const std::optional<std::string>& wdtTimeOutAction) |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2546 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2547 | BMCWEB_LOG_DEBUG("Set host watchdog"); |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2548 | |
| 2549 | if (wdtTimeOutAction) |
| 2550 | { |
| 2551 | std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); |
| 2552 | // check if TimeOut Action is Valid |
| 2553 | if (wdtTimeOutActStr.empty()) |
| 2554 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2555 | BMCWEB_LOG_DEBUG("Unsupported value for TimeoutAction: {}", |
| 2556 | *wdtTimeOutAction); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2557 | messages::propertyValueNotInList(asyncResp->res, *wdtTimeOutAction, |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2558 | "TimeoutAction"); |
| 2559 | return; |
| 2560 | } |
| 2561 | |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2562 | setDbusProperty(asyncResp, "HostWatchdogTimer/TimeoutAction", |
| 2563 | "xyz.openbmc_project.Watchdog", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 2564 | sdbusplus::message::object_path( |
| 2565 | "/xyz/openbmc_project/watchdog/host0"), |
| 2566 | "xyz.openbmc_project.State.Watchdog", "ExpireAction", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2567 | wdtTimeOutActStr); |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2568 | } |
| 2569 | |
| 2570 | if (wdtEnable) |
| 2571 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2572 | setDbusProperty(asyncResp, "HostWatchdogTimer/FunctionEnabled", |
| 2573 | "xyz.openbmc_project.Watchdog", |
Asmitha Karunanithi | 87c4496 | 2024-04-04 18:28:33 +0000 | [diff] [blame] | 2574 | sdbusplus::message::object_path( |
| 2575 | "/xyz/openbmc_project/watchdog/host0"), |
| 2576 | "xyz.openbmc_project.State.Watchdog", "Enabled", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2577 | *wdtEnable); |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2578 | } |
| 2579 | } |
| 2580 | |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2581 | /** |
| 2582 | * @brief Parse the Idle Power Saver properties into json |
| 2583 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2584 | * @param[in] asyncResp Shared pointer for completing asynchronous calls. |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2585 | * @param[in] properties IPS property data from DBus. |
| 2586 | * |
| 2587 | * @return true if successful |
| 2588 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2589 | inline bool parseIpsProperties( |
| 2590 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2591 | const dbus::utility::DBusPropertiesMap& properties) |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2592 | { |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2593 | const bool* enabled = nullptr; |
| 2594 | const uint8_t* enterUtilizationPercent = nullptr; |
| 2595 | const uint64_t* enterDwellTime = nullptr; |
| 2596 | const uint8_t* exitUtilizationPercent = nullptr; |
| 2597 | const uint64_t* exitDwellTime = nullptr; |
| 2598 | |
| 2599 | const bool success = sdbusplus::unpackPropertiesNoThrow( |
| 2600 | dbus_utils::UnpackErrorPrinter(), properties, "Enabled", enabled, |
Chris Cain | 2661b72 | 2023-03-22 08:53:21 -0500 | [diff] [blame] | 2601 | "EnterUtilizationPercent", enterUtilizationPercent, "EnterDwellTime", |
| 2602 | enterDwellTime, "ExitUtilizationPercent", exitUtilizationPercent, |
| 2603 | "ExitDwellTime", exitDwellTime); |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2604 | |
| 2605 | if (!success) |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2606 | { |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2607 | return false; |
| 2608 | } |
| 2609 | |
| 2610 | if (enabled != nullptr) |
| 2611 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2612 | asyncResp->res.jsonValue["IdlePowerSaver"]["Enabled"] = *enabled; |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2613 | } |
| 2614 | |
| 2615 | if (enterUtilizationPercent != nullptr) |
| 2616 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2617 | asyncResp->res.jsonValue["IdlePowerSaver"]["EnterUtilizationPercent"] = |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2618 | *enterUtilizationPercent; |
| 2619 | } |
| 2620 | |
| 2621 | if (enterDwellTime != nullptr) |
| 2622 | { |
| 2623 | const std::chrono::duration<uint64_t, std::milli> ms(*enterDwellTime); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2624 | asyncResp->res.jsonValue["IdlePowerSaver"]["EnterDwellTimeSeconds"] = |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2625 | std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) |
| 2626 | .count(); |
| 2627 | } |
| 2628 | |
| 2629 | if (exitUtilizationPercent != nullptr) |
| 2630 | { |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2631 | asyncResp->res.jsonValue["IdlePowerSaver"]["ExitUtilizationPercent"] = |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2632 | *exitUtilizationPercent; |
| 2633 | } |
| 2634 | |
| 2635 | if (exitDwellTime != nullptr) |
| 2636 | { |
| 2637 | const std::chrono::duration<uint64_t, std::milli> ms(*exitDwellTime); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2638 | asyncResp->res.jsonValue["IdlePowerSaver"]["ExitDwellTimeSeconds"] = |
Krzysztof Grobelny | bc1d29d | 2022-08-09 14:17:34 +0200 | [diff] [blame] | 2639 | std::chrono::duration_cast<std::chrono::duration<uint64_t>>(ms) |
| 2640 | .count(); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2641 | } |
| 2642 | |
| 2643 | return true; |
| 2644 | } |
| 2645 | |
| 2646 | /** |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 2647 | * @brief Retrieves idle power saver properties over DBUS |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2648 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2649 | * @param[in] asyncResp Shared pointer for completing asynchronous calls. |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2650 | * |
| 2651 | * @return None. |
| 2652 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 2653 | inline void getIdlePowerSaver( |
| 2654 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2655 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2656 | BMCWEB_LOG_DEBUG("Get idle power saver parameters"); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2657 | |
| 2658 | // Get IdlePowerSaver object path: |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2659 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2660 | "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; |
| 2661 | dbus::utility::getSubTree( |
| 2662 | "/", 0, interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2663 | [asyncResp](const boost::system::error_code& ec, |
| 2664 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2665 | if (ec) |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2666 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2667 | BMCWEB_LOG_ERROR( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2668 | "DBUS response error on Power.IdlePowerSaver GetSubTree {}", |
| 2669 | ec); |
| 2670 | messages::internalError(asyncResp->res); |
| 2671 | return; |
| 2672 | } |
| 2673 | if (subtree.empty()) |
| 2674 | { |
| 2675 | // This is an optional interface so just return |
| 2676 | // if there is no instance found |
| 2677 | BMCWEB_LOG_DEBUG("No instances found"); |
| 2678 | return; |
| 2679 | } |
| 2680 | if (subtree.size() > 1) |
| 2681 | { |
| 2682 | // More then one PowerIdlePowerSaver object is not supported and |
| 2683 | // is an error |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 2684 | BMCWEB_LOG_DEBUG( |
| 2685 | "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}", |
| 2686 | subtree.size()); |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2687 | messages::internalError(asyncResp->res); |
| 2688 | return; |
| 2689 | } |
| 2690 | if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) |
| 2691 | { |
| 2692 | BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); |
| 2693 | messages::internalError(asyncResp->res); |
| 2694 | return; |
| 2695 | } |
| 2696 | const std::string& path = subtree[0].first; |
| 2697 | const std::string& service = subtree[0].second.begin()->first; |
| 2698 | if (service.empty()) |
| 2699 | { |
| 2700 | BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2701 | messages::internalError(asyncResp->res); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2702 | return; |
| 2703 | } |
| 2704 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2705 | // Valid IdlePowerSaver object found, now read the current values |
Ed Tanous | deae6a7 | 2024-11-11 21:58:57 -0800 | [diff] [blame] | 2706 | dbus::utility::getAllProperties( |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2707 | *crow::connections::systemBus, service, path, |
| 2708 | "xyz.openbmc_project.Control.Power.IdlePowerSaver", |
| 2709 | [asyncResp]( |
| 2710 | const boost::system::error_code& ec2, |
| 2711 | const dbus::utility::DBusPropertiesMap& properties) { |
| 2712 | if (ec2) |
| 2713 | { |
| 2714 | BMCWEB_LOG_ERROR( |
| 2715 | "DBUS response error on IdlePowerSaver GetAll: {}", |
| 2716 | ec2); |
| 2717 | messages::internalError(asyncResp->res); |
| 2718 | return; |
| 2719 | } |
| 2720 | |
| 2721 | if (!parseIpsProperties(asyncResp, properties)) |
| 2722 | { |
| 2723 | messages::internalError(asyncResp->res); |
| 2724 | return; |
| 2725 | } |
| 2726 | }); |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2727 | }); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2728 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2729 | BMCWEB_LOG_DEBUG("EXIT: Get idle power saver parameters"); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2730 | } |
| 2731 | |
| 2732 | /** |
| 2733 | * @brief Sets Idle Power Saver properties. |
| 2734 | * |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2735 | * @param[in] asyncResp Shared pointer for generating response message. |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2736 | * @param[in] ipsEnable The IPS Enable value (true/false) from incoming |
| 2737 | * RF request. |
| 2738 | * @param[in] ipsEnterUtil The utilization limit to enter idle state. |
| 2739 | * @param[in] ipsEnterTime The time the utilization must be below ipsEnterUtil |
| 2740 | * before entering idle state. |
| 2741 | * @param[in] ipsExitUtil The utilization limit when exiting idle state. |
| 2742 | * @param[in] ipsExitTime The time the utilization must be above ipsExutUtil |
| 2743 | * before exiting idle state |
| 2744 | * |
| 2745 | * @return None. |
| 2746 | */ |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2747 | inline void setIdlePowerSaver( |
| 2748 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2749 | const std::optional<bool> ipsEnable, |
| 2750 | const std::optional<uint8_t> ipsEnterUtil, |
| 2751 | const std::optional<uint64_t> ipsEnterTime, |
| 2752 | const std::optional<uint8_t> ipsExitUtil, |
| 2753 | const std::optional<uint64_t> ipsExitTime) |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2754 | { |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2755 | BMCWEB_LOG_DEBUG("Set idle power saver properties"); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2756 | |
| 2757 | // Get IdlePowerSaver object path: |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2758 | constexpr std::array<std::string_view, 1> interfaces = { |
| 2759 | "xyz.openbmc_project.Control.Power.IdlePowerSaver"}; |
| 2760 | dbus::utility::getSubTree( |
| 2761 | "/", 0, interfaces, |
Ed Tanous | ac106bf | 2023-06-07 09:24:59 -0700 | [diff] [blame] | 2762 | [asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, ipsExitUtil, |
George Liu | e99073f | 2022-12-09 11:06:16 +0800 | [diff] [blame] | 2763 | ipsExitTime](const boost::system::error_code& ec, |
Ed Tanous | b9d36b4 | 2022-02-26 21:42:46 -0800 | [diff] [blame] | 2764 | const dbus::utility::MapperGetSubTreeResponse& subtree) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2765 | if (ec) |
| 2766 | { |
| 2767 | BMCWEB_LOG_ERROR( |
| 2768 | "DBUS response error on Power.IdlePowerSaver GetSubTree {}", |
| 2769 | ec); |
| 2770 | messages::internalError(asyncResp->res); |
| 2771 | return; |
| 2772 | } |
| 2773 | if (subtree.empty()) |
| 2774 | { |
| 2775 | // This is an optional D-Bus object, but user attempted to patch |
| 2776 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2777 | "IdlePowerSaver"); |
| 2778 | return; |
| 2779 | } |
| 2780 | if (subtree.size() > 1) |
| 2781 | { |
| 2782 | // More then one PowerIdlePowerSaver object is not supported and |
| 2783 | // is an error |
| 2784 | BMCWEB_LOG_DEBUG( |
| 2785 | "Found more than 1 system D-Bus Power.IdlePowerSaver objects: {}", |
| 2786 | subtree.size()); |
| 2787 | messages::internalError(asyncResp->res); |
| 2788 | return; |
| 2789 | } |
| 2790 | if ((subtree[0].first.empty()) || (subtree[0].second.size() != 1)) |
| 2791 | { |
| 2792 | BMCWEB_LOG_DEBUG("Power.IdlePowerSaver mapper error!"); |
| 2793 | messages::internalError(asyncResp->res); |
| 2794 | return; |
| 2795 | } |
| 2796 | const std::string& path = subtree[0].first; |
| 2797 | const std::string& service = subtree[0].second.begin()->first; |
| 2798 | if (service.empty()) |
| 2799 | { |
| 2800 | BMCWEB_LOG_DEBUG("Power.IdlePowerSaver service mapper error!"); |
| 2801 | messages::internalError(asyncResp->res); |
| 2802 | return; |
| 2803 | } |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2804 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2805 | // Valid Power IdlePowerSaver object found, now set any values that |
| 2806 | // need to be updated |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2807 | |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2808 | if (ipsEnable) |
| 2809 | { |
| 2810 | setDbusProperty( |
| 2811 | asyncResp, "IdlePowerSaver/Enabled", service, path, |
| 2812 | "xyz.openbmc_project.Control.Power.IdlePowerSaver", |
| 2813 | "Enabled", *ipsEnable); |
| 2814 | } |
| 2815 | if (ipsEnterUtil) |
| 2816 | { |
| 2817 | setDbusProperty( |
| 2818 | asyncResp, "IdlePowerSaver/EnterUtilizationPercent", |
| 2819 | service, path, |
| 2820 | "xyz.openbmc_project.Control.Power.IdlePowerSaver", |
| 2821 | "EnterUtilizationPercent", *ipsEnterUtil); |
| 2822 | } |
| 2823 | if (ipsEnterTime) |
| 2824 | { |
| 2825 | // Convert from seconds into milliseconds for DBus |
| 2826 | const uint64_t timeMilliseconds = *ipsEnterTime * 1000; |
| 2827 | setDbusProperty( |
| 2828 | asyncResp, "IdlePowerSaver/EnterDwellTimeSeconds", service, |
| 2829 | path, "xyz.openbmc_project.Control.Power.IdlePowerSaver", |
| 2830 | "EnterDwellTime", timeMilliseconds); |
| 2831 | } |
| 2832 | if (ipsExitUtil) |
| 2833 | { |
| 2834 | setDbusProperty( |
| 2835 | asyncResp, "IdlePowerSaver/ExitUtilizationPercent", service, |
| 2836 | path, "xyz.openbmc_project.Control.Power.IdlePowerSaver", |
| 2837 | "ExitUtilizationPercent", *ipsExitUtil); |
| 2838 | } |
| 2839 | if (ipsExitTime) |
| 2840 | { |
| 2841 | // Convert from seconds into milliseconds for DBus |
| 2842 | const uint64_t timeMilliseconds = *ipsExitTime * 1000; |
| 2843 | setDbusProperty( |
| 2844 | asyncResp, "IdlePowerSaver/ExitDwellTimeSeconds", service, |
| 2845 | path, "xyz.openbmc_project.Control.Power.IdlePowerSaver", |
| 2846 | "ExitDwellTime", timeMilliseconds); |
| 2847 | } |
| 2848 | }); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2849 | |
Ed Tanous | 62598e3 | 2023-07-17 17:06:25 -0700 | [diff] [blame] | 2850 | BMCWEB_LOG_DEBUG("EXIT: Set idle power saver parameters"); |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 2851 | } |
| 2852 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 2853 | inline void handleComputerSystemCollectionHead( |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 2854 | crow::App& app, const crow::Request& req, |
| 2855 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 2856 | { |
| 2857 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2858 | { |
| 2859 | return; |
| 2860 | } |
| 2861 | asyncResp->res.addHeader( |
| 2862 | boost::beast::http::field::link, |
| 2863 | "</redfish/v1/JsonSchemas/ComputerSystemCollection/ComputerSystemCollection.json>; rel=describedby"); |
| 2864 | } |
| 2865 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 2866 | inline void handleComputerSystemCollectionGet( |
| 2867 | crow::App& app, const crow::Request& req, |
| 2868 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
| 2869 | { |
| 2870 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2871 | { |
| 2872 | return; |
| 2873 | } |
| 2874 | |
| 2875 | asyncResp->res.addHeader( |
| 2876 | boost::beast::http::field::link, |
| 2877 | "</redfish/v1/JsonSchemas/ComputerSystemCollection.json>; rel=describedby"); |
| 2878 | asyncResp->res.jsonValue["@odata.type"] = |
| 2879 | "#ComputerSystemCollection.ComputerSystemCollection"; |
| 2880 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; |
| 2881 | asyncResp->res.jsonValue["Name"] = "Computer System Collection"; |
| 2882 | |
Oliver Brewka | fc5ae94 | 2024-08-12 15:04:41 +0200 | [diff] [blame] | 2883 | getSystemCollectionMembers(asyncResp); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 2884 | } |
| 2885 | |
Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2886 | /** |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2887 | * Function transceives data with dbus directly. |
| 2888 | */ |
Ed Tanous | 4f48d5f | 2021-06-21 08:27:45 -0700 | [diff] [blame] | 2889 | inline void doNMI(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2890 | { |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 2891 | constexpr const char* serviceName = "xyz.openbmc_project.Control.Host.NMI"; |
| 2892 | constexpr const char* objectPath = "/xyz/openbmc_project/control/host0/nmi"; |
| 2893 | constexpr const char* interfaceName = |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2894 | "xyz.openbmc_project.Control.Host.NMI"; |
Patrick Williams | 89492a1 | 2023-05-10 07:51:34 -0500 | [diff] [blame] | 2895 | constexpr const char* method = "NMI"; |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2896 | |
Ed Tanous | 177612a | 2025-02-14 15:16:09 -0800 | [diff] [blame] | 2897 | dbus::utility::async_method_call( |
| 2898 | asyncResp, |
Ed Tanous | 5e7e2dc | 2023-02-16 10:37:01 -0800 | [diff] [blame] | 2899 | [asyncResp](const boost::system::error_code& ec) { |
Patrick Williams | bd79bce | 2024-08-16 15:22:20 -0400 | [diff] [blame] | 2900 | if (ec) |
| 2901 | { |
| 2902 | BMCWEB_LOG_ERROR(" Bad D-Bus request error: {}", ec); |
| 2903 | messages::internalError(asyncResp->res); |
| 2904 | return; |
| 2905 | } |
| 2906 | messages::success(asyncResp->res); |
| 2907 | }, |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 2908 | serviceName, objectPath, interfaceName, method); |
| 2909 | } |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2910 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 2911 | inline void handleComputerSystemResetActionPost( |
| 2912 | crow::App& app, const crow::Request& req, |
| 2913 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 2914 | const std::string& systemName) |
| 2915 | { |
| 2916 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 2917 | { |
| 2918 | return; |
| 2919 | } |
Gunnar Mills | dd7090e | 2024-07-30 15:23:05 -0500 | [diff] [blame] | 2920 | |
| 2921 | if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM) |
| 2922 | { |
| 2923 | if (systemName == "hypervisor") |
| 2924 | { |
| 2925 | handleHypervisorSystemResetPost(req, asyncResp); |
| 2926 | return; |
| 2927 | } |
| 2928 | } |
| 2929 | |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 2930 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 2931 | { |
| 2932 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2933 | systemName); |
| 2934 | return; |
| 2935 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 2936 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 2937 | { |
| 2938 | // Option currently returns no systems. TBD |
| 2939 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 2940 | systemName); |
| 2941 | return; |
| 2942 | } |
| 2943 | std::string resetType; |
| 2944 | if (!json_util::readJsonAction(req, asyncResp->res, "ResetType", resetType)) |
| 2945 | { |
| 2946 | return; |
| 2947 | } |
| 2948 | |
| 2949 | // Get the command and host vs. chassis |
| 2950 | std::string command; |
| 2951 | bool hostCommand = true; |
| 2952 | if ((resetType == "On") || (resetType == "ForceOn")) |
| 2953 | { |
| 2954 | command = "xyz.openbmc_project.State.Host.Transition.On"; |
| 2955 | hostCommand = true; |
| 2956 | } |
| 2957 | else if (resetType == "ForceOff") |
| 2958 | { |
| 2959 | command = "xyz.openbmc_project.State.Chassis.Transition.Off"; |
| 2960 | hostCommand = false; |
| 2961 | } |
| 2962 | else if (resetType == "ForceRestart") |
| 2963 | { |
| 2964 | command = "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; |
| 2965 | hostCommand = true; |
| 2966 | } |
| 2967 | else if (resetType == "GracefulShutdown") |
| 2968 | { |
| 2969 | command = "xyz.openbmc_project.State.Host.Transition.Off"; |
| 2970 | hostCommand = true; |
| 2971 | } |
| 2972 | else if (resetType == "GracefulRestart") |
| 2973 | { |
| 2974 | command = |
| 2975 | "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; |
| 2976 | hostCommand = true; |
| 2977 | } |
| 2978 | else if (resetType == "PowerCycle") |
| 2979 | { |
| 2980 | command = "xyz.openbmc_project.State.Host.Transition.Reboot"; |
| 2981 | hostCommand = true; |
| 2982 | } |
| 2983 | else if (resetType == "Nmi") |
| 2984 | { |
| 2985 | doNMI(asyncResp); |
| 2986 | return; |
| 2987 | } |
| 2988 | else |
| 2989 | { |
| 2990 | messages::actionParameterUnknown(asyncResp->res, "Reset", resetType); |
| 2991 | return; |
| 2992 | } |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 2993 | sdbusplus::message::object_path statePath("/xyz/openbmc_project/state"); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 2994 | |
| 2995 | if (hostCommand) |
| 2996 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2997 | setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Host", |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 2998 | statePath / "host0", "xyz.openbmc_project.State.Host", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 2999 | "RequestedHostTransition", command); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3000 | } |
| 3001 | else |
| 3002 | { |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 3003 | setDbusProperty(asyncResp, "Reset", "xyz.openbmc_project.State.Chassis", |
Ed Tanous | d02aad3 | 2024-02-13 14:43:34 -0800 | [diff] [blame] | 3004 | statePath / "chassis0", |
| 3005 | "xyz.openbmc_project.State.Chassis", |
Ginu George | e93abac | 2024-06-14 17:35:27 +0530 | [diff] [blame] | 3006 | "RequestedPowerTransition", command); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3007 | } |
| 3008 | } |
| 3009 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3010 | inline void handleComputerSystemHead( |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 3011 | App& app, const crow::Request& req, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 3012 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3013 | const std::string& /*systemName*/) |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 3014 | { |
| 3015 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3016 | { |
| 3017 | return; |
| 3018 | } |
| 3019 | |
| 3020 | asyncResp->res.addHeader( |
| 3021 | boost::beast::http::field::link, |
| 3022 | "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); |
| 3023 | } |
| 3024 | |
Abhishek Patel | 5c3e927 | 2021-06-24 10:11:33 -0500 | [diff] [blame] | 3025 | inline void afterPortRequest( |
| 3026 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3027 | const boost::system::error_code& ec, |
| 3028 | const std::vector<std::tuple<std::string, std::string, bool>>& socketData) |
| 3029 | { |
| 3030 | if (ec) |
| 3031 | { |
Gunnar Mills | b3e86cb | 2023-08-31 13:01:14 -0500 | [diff] [blame] | 3032 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
Abhishek Patel | 5c3e927 | 2021-06-24 10:11:33 -0500 | [diff] [blame] | 3033 | messages::internalError(asyncResp->res); |
| 3034 | return; |
| 3035 | } |
| 3036 | for (const auto& data : socketData) |
| 3037 | { |
| 3038 | const std::string& socketPath = get<0>(data); |
| 3039 | const std::string& protocolName = get<1>(data); |
| 3040 | bool isProtocolEnabled = get<2>(data); |
| 3041 | nlohmann::json& dataJson = asyncResp->res.jsonValue["SerialConsole"]; |
| 3042 | dataJson[protocolName]["ServiceEnabled"] = isProtocolEnabled; |
| 3043 | // need to retrieve port number for |
| 3044 | // obmc-console-ssh service |
| 3045 | if (protocolName == "SSH") |
| 3046 | { |
| 3047 | getPortNumber(socketPath, [asyncResp, protocolName]( |
Ed Tanous | 81c4e33 | 2023-05-18 10:30:34 -0700 | [diff] [blame] | 3048 | const boost::system::error_code& ec1, |
Abhishek Patel | 5c3e927 | 2021-06-24 10:11:33 -0500 | [diff] [blame] | 3049 | int portNumber) { |
| 3050 | if (ec1) |
| 3051 | { |
Gunnar Mills | b3e86cb | 2023-08-31 13:01:14 -0500 | [diff] [blame] | 3052 | BMCWEB_LOG_ERROR("DBUS response error {}", ec1); |
Abhishek Patel | 5c3e927 | 2021-06-24 10:11:33 -0500 | [diff] [blame] | 3053 | messages::internalError(asyncResp->res); |
| 3054 | return; |
| 3055 | } |
| 3056 | nlohmann::json& dataJson1 = |
| 3057 | asyncResp->res.jsonValue["SerialConsole"]; |
| 3058 | dataJson1[protocolName]["Port"] = portNumber; |
| 3059 | }); |
| 3060 | } |
| 3061 | } |
| 3062 | } |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3063 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3064 | /** |
| 3065 | * @brief process the GET request after getting the computerSystemIndex |
| 3066 | * |
| 3067 | * @param[in] asyncResp Shared pointer for completing asynchronous |
| 3068 | * calls |
| 3069 | * @param[in] systemName Name of the requested system |
| 3070 | * @param[in] computerSystemIndex Index associated with the requested system |
| 3071 | * |
| 3072 | * @return None |
| 3073 | */ |
| 3074 | inline void processComputerSystemGet( |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 3075 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3076 | const std::string& systemName, const uint64_t computerSystemIndex) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 3077 | { |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3078 | asyncResp->res.addHeader( |
| 3079 | boost::beast::http::field::link, |
| 3080 | "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); |
| 3081 | asyncResp->res.jsonValue["@odata.type"] = |
Chris Cain | b665510 | 2024-02-01 14:35:33 -0600 | [diff] [blame] | 3082 | "#ComputerSystem.v1_22_0.ComputerSystem"; |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3083 | asyncResp->res.jsonValue["Name"] = systemName; |
| 3084 | asyncResp->res.jsonValue["Id"] = systemName; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 3085 | asyncResp->res.jsonValue["SystemType"] = |
| 3086 | computer_system::SystemType::Physical; |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3087 | asyncResp->res.jsonValue["Description"] = "Computer System"; |
| 3088 | asyncResp->res.jsonValue["ProcessorSummary"]["Count"] = 0; |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3089 | asyncResp->res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = |
Priyanga Ramasamy | dfb2b40 | 2023-07-06 08:37:08 -0500 | [diff] [blame] | 3090 | double(0); |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3091 | asyncResp->res.jsonValue["@odata.id"] = |
| 3092 | boost::urls::format("/redfish/v1/Systems/{}", systemName); |
Ed Tanous | 04a258f | 2018-10-15 08:00:41 -0700 | [diff] [blame] | 3093 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3094 | // Currently not supported on multi-host. TBD |
| 3095 | if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3096 | { |
| 3097 | asyncResp->res.jsonValue["Bios"]["@odata.id"] = |
| 3098 | boost::urls::format("/redfish/v1/Systems/{}/Bios", systemName); |
| 3099 | asyncResp->res.jsonValue["Processors"]["@odata.id"] = |
| 3100 | boost::urls::format("/redfish/v1/Systems/{}/Processors", |
| 3101 | systemName); |
| 3102 | asyncResp->res.jsonValue["Memory"]["@odata.id"] = |
| 3103 | boost::urls::format("/redfish/v1/Systems/{}/Memory", systemName); |
| 3104 | asyncResp->res.jsonValue["Storage"]["@odata.id"] = |
| 3105 | boost::urls::format("/redfish/v1/Systems/{}/Storage", systemName); |
| 3106 | asyncResp->res.jsonValue["FabricAdapters"]["@odata.id"] = |
| 3107 | boost::urls::format("/redfish/v1/Systems/{}/FabricAdapters", |
| 3108 | systemName); |
| 3109 | } |
Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 3110 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3111 | asyncResp->res.jsonValue["Actions"]["#ComputerSystem.Reset"]["target"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 3112 | boost::urls::format( |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3113 | "/redfish/v1/Systems/{}/Actions/ComputerSystem.Reset", systemName); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3114 | asyncResp->res |
| 3115 | .jsonValue["Actions"]["#ComputerSystem.Reset"]["@Redfish.ActionInfo"] = |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 3116 | boost::urls::format("/redfish/v1/Systems/{}/ResetActionInfo", |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3117 | systemName); |
Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 3118 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3119 | asyncResp->res.jsonValue["LogServices"]["@odata.id"] = |
| 3120 | boost::urls::format("/redfish/v1/Systems/{}/LogServices", systemName); |
Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 3121 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3122 | nlohmann::json::array_t managedBy; |
| 3123 | nlohmann::json& manager = managedBy.emplace_back(); |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 3124 | manager["@odata.id"] = boost::urls::format("/redfish/v1/Managers/{}", |
| 3125 | BMCWEB_REDFISH_MANAGER_URI_NAME); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3126 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = std::move(managedBy); |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 3127 | asyncResp->res.jsonValue["Status"]["Health"] = resource::Health::OK; |
| 3128 | asyncResp->res.jsonValue["Status"]["State"] = resource::State::Enabled; |
Gunnar Mills | 0e8ac5e | 2020-11-06 15:33:24 -0600 | [diff] [blame] | 3129 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3130 | // Fill in SerialConsole info |
| 3131 | asyncResp->res.jsonValue["SerialConsole"]["MaxConcurrentSessions"] = 15; |
| 3132 | asyncResp->res.jsonValue["SerialConsole"]["IPMI"]["ServiceEnabled"] = true; |
Ed Tanous | 1476687 | 2022-03-15 10:44:42 -0700 | [diff] [blame] | 3133 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3134 | asyncResp->res.jsonValue["SerialConsole"]["SSH"]["ServiceEnabled"] = true; |
| 3135 | asyncResp->res.jsonValue["SerialConsole"]["SSH"]["Port"] = 2200; |
| 3136 | asyncResp->res.jsonValue["SerialConsole"]["SSH"]["HotKeySequenceDisplay"] = |
| 3137 | "Press ~. to exit console"; |
| 3138 | getPortStatusAndPath(std::span{protocolToDBusForSystems}, |
| 3139 | std::bind_front(afterPortRequest, asyncResp)); |
Gunnar Mills | 0e8ac5e | 2020-11-06 15:33:24 -0600 | [diff] [blame] | 3140 | |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 3141 | if constexpr (BMCWEB_KVM) |
| 3142 | { |
| 3143 | // Fill in GraphicalConsole info |
| 3144 | asyncResp->res.jsonValue["GraphicalConsole"]["ServiceEnabled"] = true; |
| 3145 | asyncResp->res.jsonValue["GraphicalConsole"]["MaxConcurrentSessions"] = |
| 3146 | 4; |
| 3147 | asyncResp->res.jsonValue["GraphicalConsole"]["ConnectTypesSupported"] = |
| 3148 | nlohmann::json::array_t({"KVMIP"}); |
| 3149 | } |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 3150 | |
Janet Adkins | 2eaa927 | 2025-04-17 10:30:43 -0500 | [diff] [blame] | 3151 | systems_utils::getValidSystemsPath( |
| 3152 | asyncResp, systemName, |
| 3153 | [asyncResp, |
| 3154 | systemName](const std::optional<std::string>& validSystemsPath) { |
| 3155 | if (validSystemsPath) |
| 3156 | { |
| 3157 | getLocationIndicatorActive(asyncResp, *validSystemsPath); |
| 3158 | } |
| 3159 | }); |
| 3160 | |
Janet Adkins | f664fd8 | 2025-07-23 14:01:43 -0500 | [diff] [blame] | 3161 | if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED) |
| 3162 | { |
| 3163 | getIndicatorLedState(asyncResp); |
| 3164 | } |
| 3165 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3166 | // Currently not supported on multi-host. |
| 3167 | if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3168 | { |
| 3169 | getComputerSystem(asyncResp); |
| 3170 | // Todo: chassis matching could be handled by patch |
| 3171 | // https://gerrit.openbmc.org/c/openbmc/bmcweb/+/60793 |
| 3172 | getMainChassisId( |
| 3173 | asyncResp, [](const std::string& chassisId, |
| 3174 | const std::shared_ptr<bmcweb::AsyncResp>& aRsp) { |
| 3175 | nlohmann::json::array_t chassisArray; |
| 3176 | nlohmann::json& chassis = chassisArray.emplace_back(); |
| 3177 | chassis["@odata.id"] = |
| 3178 | boost::urls::format("/redfish/v1/Chassis/{}", chassisId); |
| 3179 | aRsp->res.jsonValue["Links"]["Chassis"] = |
| 3180 | std::move(chassisArray); |
| 3181 | }); |
| 3182 | |
| 3183 | pcie_util::getPCIeDeviceList( |
| 3184 | asyncResp, nlohmann::json::json_pointer("/PCIeDevices")); |
| 3185 | } |
| 3186 | getHostState(asyncResp, computerSystemIndex); |
| 3187 | getBootProperties(asyncResp, computerSystemIndex); |
| 3188 | getBootProgress(asyncResp, computerSystemIndex); |
| 3189 | getBootProgressLastStateTime(asyncResp, computerSystemIndex); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3190 | getHostWatchdogTimer(asyncResp); |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3191 | getPowerRestorePolicy(asyncResp, computerSystemIndex); |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 3192 | getStopBootOnFault(asyncResp); |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3193 | getAutomaticRetryPolicy(asyncResp, computerSystemIndex); |
| 3194 | getLastResetTime(asyncResp, computerSystemIndex); |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 3195 | if constexpr (BMCWEB_REDFISH_PROVISIONING_FEATURE) |
| 3196 | { |
| 3197 | getProvisioningStatus(asyncResp); |
| 3198 | } |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3199 | getTrustedModuleRequiredToBoot(asyncResp, computerSystemIndex); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3200 | getPowerMode(asyncResp); |
| 3201 | getIdlePowerSaver(asyncResp); |
| 3202 | } |
Jiaqing Zhao | 550a6bf | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 3203 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3204 | inline void handleComputerSystemGet( |
| 3205 | crow::App& app, const crow::Request& req, |
| 3206 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3207 | const std::string& systemName) |
| 3208 | { |
| 3209 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3210 | { |
| 3211 | return; |
| 3212 | } |
| 3213 | |
| 3214 | if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM) |
| 3215 | { |
| 3216 | if (systemName == "hypervisor") |
| 3217 | { |
| 3218 | handleHypervisorSystemGet(asyncResp); |
| 3219 | return; |
| 3220 | } |
| 3221 | } |
| 3222 | |
| 3223 | if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
| 3224 | { |
| 3225 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3226 | { |
| 3227 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3228 | systemName); |
| 3229 | return; |
| 3230 | } |
| 3231 | } |
| 3232 | |
| 3233 | BMCWEB_LOG_DEBUG("requested system = {}", systemName); |
| 3234 | getComputerSystemIndex( |
| 3235 | asyncResp, systemName, |
| 3236 | std::bind_front(processComputerSystemGet, asyncResp, systemName)); |
| 3237 | } |
| 3238 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3239 | inline void handleComputerSystemPatch( |
| 3240 | crow::App& app, const crow::Request& req, |
| 3241 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3242 | const std::string& systemName) |
| 3243 | { |
| 3244 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3245 | { |
| 3246 | return; |
| 3247 | } |
Ed Tanous | 25b54db | 2024-04-17 15:40:31 -0700 | [diff] [blame] | 3248 | if constexpr (BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3249 | { |
| 3250 | // Option currently returns no systems. TBD |
| 3251 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3252 | systemName); |
| 3253 | return; |
| 3254 | } |
Ed Tanous | 253f11b | 2024-05-16 09:38:31 -0700 | [diff] [blame] | 3255 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3256 | { |
| 3257 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3258 | systemName); |
| 3259 | return; |
| 3260 | } |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3261 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3262 | asyncResp->res.addHeader( |
| 3263 | boost::beast::http::field::link, |
| 3264 | "</redfish/v1/JsonSchemas/ComputerSystem/ComputerSystem.json>; rel=describedby"); |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 3265 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3266 | std::optional<bool> locationIndicatorActive; |
| 3267 | std::optional<std::string> indicatorLed; |
| 3268 | std::optional<std::string> assetTag; |
| 3269 | std::optional<std::string> powerRestorePolicy; |
| 3270 | std::optional<std::string> powerMode; |
| 3271 | std::optional<bool> wdtEnable; |
| 3272 | std::optional<std::string> wdtTimeOutAction; |
| 3273 | std::optional<std::string> bootSource; |
| 3274 | std::optional<std::string> bootType; |
| 3275 | std::optional<std::string> bootEnable; |
| 3276 | std::optional<std::string> bootAutomaticRetry; |
| 3277 | std::optional<uint32_t> bootAutomaticRetryAttempts; |
| 3278 | std::optional<bool> bootTrustedModuleRequired; |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 3279 | std::optional<std::string> stopBootOnFault; |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3280 | std::optional<bool> ipsEnable; |
| 3281 | std::optional<uint8_t> ipsEnterUtil; |
| 3282 | std::optional<uint64_t> ipsEnterTime; |
| 3283 | std::optional<uint8_t> ipsExitUtil; |
| 3284 | std::optional<uint64_t> ipsExitTime; |
Jiaqing Zhao | 550a6bf | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 3285 | |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 3286 | if (!json_util::readJsonPatch( // |
| 3287 | req, asyncResp->res, // |
| 3288 | "AssetTag", assetTag, // |
| 3289 | "Boot/AutomaticRetryAttempts", bootAutomaticRetryAttempts, // |
| 3290 | "Boot/AutomaticRetryConfig", bootAutomaticRetry, // |
| 3291 | "Boot/BootSourceOverrideEnabled", bootEnable, // |
| 3292 | "Boot/BootSourceOverrideMode", bootType, // |
| 3293 | "Boot/BootSourceOverrideTarget", bootSource, // |
| 3294 | "Boot/StopBootOnFault", stopBootOnFault, // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 3295 | "Boot/TrustedModuleRequiredToBoot", bootTrustedModuleRequired, // |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 3296 | "HostWatchdogTimer/FunctionEnabled", wdtEnable, // |
| 3297 | "HostWatchdogTimer/TimeoutAction", wdtTimeOutAction, // |
| 3298 | "IdlePowerSaver/Enabled", ipsEnable, // |
| 3299 | "IdlePowerSaver/EnterDwellTimeSeconds", ipsEnterTime, // |
| 3300 | "IdlePowerSaver/EnterUtilizationPercent", ipsEnterUtil, // |
| 3301 | "IdlePowerSaver/ExitDwellTimeSeconds", ipsExitTime, // |
| 3302 | "IdlePowerSaver/ExitUtilizationPercent", ipsExitUtil, // |
| 3303 | "IndicatorLED", indicatorLed, // |
| 3304 | "LocationIndicatorActive", locationIndicatorActive, // |
| 3305 | "PowerMode", powerMode, // |
| 3306 | "PowerRestorePolicy", powerRestorePolicy // |
Myung Bae | afc474a | 2024-10-09 00:53:29 -0700 | [diff] [blame] | 3307 | )) |
Ed Tanous | ab34422 | 2024-08-07 18:01:23 -0700 | [diff] [blame] | 3308 | { |
| 3309 | return; |
| 3310 | } |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 3311 | |
Janet Adkins | f664fd8 | 2025-07-23 14:01:43 -0500 | [diff] [blame] | 3312 | if constexpr (!BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED) |
| 3313 | { |
| 3314 | if (indicatorLed) |
| 3315 | { |
| 3316 | messages::propertyUnknown(asyncResp->res, "IndicatorLED"); |
| 3317 | return; |
| 3318 | } |
| 3319 | } |
| 3320 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3321 | if (assetTag) |
| 3322 | { |
| 3323 | setAssetTag(asyncResp, *assetTag); |
| 3324 | } |
James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 3325 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3326 | if (wdtEnable || wdtTimeOutAction) |
| 3327 | { |
| 3328 | setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); |
| 3329 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3330 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3331 | if (bootSource || bootType || bootEnable) |
| 3332 | { |
| 3333 | setBootProperties(asyncResp, bootSource, bootType, bootEnable); |
| 3334 | } |
| 3335 | if (bootAutomaticRetry) |
| 3336 | { |
| 3337 | setAutomaticRetry(asyncResp, *bootAutomaticRetry); |
| 3338 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3339 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3340 | if (bootAutomaticRetryAttempts) |
| 3341 | { |
| 3342 | setAutomaticRetryAttempts(asyncResp, |
| 3343 | bootAutomaticRetryAttempts.value()); |
| 3344 | } |
Corey Hardesty | 797d5da | 2022-04-26 17:54:52 +0800 | [diff] [blame] | 3345 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3346 | if (bootTrustedModuleRequired) |
| 3347 | { |
| 3348 | setTrustedModuleRequiredToBoot(asyncResp, *bootTrustedModuleRequired); |
| 3349 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3350 | |
Albert Zhang | 9dcfe8c | 2021-07-05 09:38:06 +0800 | [diff] [blame] | 3351 | if (stopBootOnFault) |
| 3352 | { |
| 3353 | setStopBootOnFault(asyncResp, *stopBootOnFault); |
| 3354 | } |
| 3355 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3356 | if (locationIndicatorActive) |
| 3357 | { |
Janet Adkins | 2eaa927 | 2025-04-17 10:30:43 -0500 | [diff] [blame] | 3358 | systems_utils::getValidSystemsPath( |
| 3359 | asyncResp, systemName, |
| 3360 | [asyncResp, systemName, |
| 3361 | locationIndicatorActive{*locationIndicatorActive}]( |
| 3362 | const std::optional<std::string>& validSystemsPath) { |
| 3363 | if (!validSystemsPath) |
| 3364 | { |
| 3365 | messages::resourceNotFound(asyncResp->res, "Systems", |
| 3366 | systemName); |
| 3367 | return; |
| 3368 | } |
| 3369 | setLocationIndicatorActive(asyncResp, *validSystemsPath, |
| 3370 | locationIndicatorActive); |
| 3371 | }); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3372 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3373 | |
Janet Adkins | f664fd8 | 2025-07-23 14:01:43 -0500 | [diff] [blame] | 3374 | if constexpr (BMCWEB_REDFISH_ALLOW_DEPRECATED_INDICATORLED) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3375 | { |
Janet Adkins | f664fd8 | 2025-07-23 14:01:43 -0500 | [diff] [blame] | 3376 | if (indicatorLed) |
| 3377 | { |
| 3378 | setIndicatorLedState(asyncResp, *indicatorLed); |
| 3379 | asyncResp->res.addHeader(boost::beast::http::field::warning, |
| 3380 | "299 - \"IndicatorLED is deprecated. Use " |
| 3381 | "LocationIndicatorActive instead.\""); |
| 3382 | } |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3383 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3384 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3385 | if (powerRestorePolicy) |
| 3386 | { |
| 3387 | setPowerRestorePolicy(asyncResp, *powerRestorePolicy); |
| 3388 | } |
Chris Cain | 3a2d0424 | 2021-05-28 16:57:10 -0500 | [diff] [blame] | 3389 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3390 | if (powerMode) |
| 3391 | { |
| 3392 | setPowerMode(asyncResp, *powerMode); |
| 3393 | } |
Chris Cain | 37bbf98 | 2021-09-20 10:53:09 -0500 | [diff] [blame] | 3394 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3395 | if (ipsEnable || ipsEnterUtil || ipsEnterTime || ipsExitUtil || ipsExitTime) |
| 3396 | { |
| 3397 | setIdlePowerSaver(asyncResp, ipsEnable, ipsEnterUtil, ipsEnterTime, |
| 3398 | ipsExitUtil, ipsExitTime); |
| 3399 | } |
| 3400 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 3401 | |
Ed Tanous | 38c8a6f | 2022-09-01 16:37:27 -0700 | [diff] [blame] | 3402 | inline void handleSystemCollectionResetActionHead( |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 3403 | crow::App& app, const crow::Request& req, |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 3404 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3405 | const std::string& /*systemName*/) |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 3406 | { |
| 3407 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3408 | { |
| 3409 | return; |
| 3410 | } |
| 3411 | asyncResp->res.addHeader( |
| 3412 | boost::beast::http::field::link, |
| 3413 | "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); |
| 3414 | } |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 3415 | |
| 3416 | /** |
| 3417 | * @brief Translates allowed host transitions to redfish string |
| 3418 | * |
| 3419 | * @param[in] dbusAllowedHostTran The allowed host transition on dbus |
| 3420 | * @param[out] allowableValues The translated host transition(s) |
| 3421 | * |
Manojkiran Eda | efff2b5 | 2024-06-18 18:01:46 +0530 | [diff] [blame] | 3422 | * @return Emplaces corresponding Redfish translated value(s) in |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 3423 | * allowableValues. If translation not possible, does nothing to |
| 3424 | * allowableValues. |
| 3425 | */ |
Patrick Williams | 504af5a | 2025-02-03 14:29:03 -0500 | [diff] [blame] | 3426 | inline void dbusToRfAllowedHostTransitions( |
| 3427 | const std::string& dbusAllowedHostTran, |
| 3428 | nlohmann::json::array_t& allowableValues) |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 3429 | { |
| 3430 | if (dbusAllowedHostTran == "xyz.openbmc_project.State.Host.Transition.On") |
| 3431 | { |
| 3432 | allowableValues.emplace_back(resource::ResetType::On); |
| 3433 | allowableValues.emplace_back(resource::ResetType::ForceOn); |
| 3434 | } |
| 3435 | else if (dbusAllowedHostTran == |
| 3436 | "xyz.openbmc_project.State.Host.Transition.Off") |
| 3437 | { |
| 3438 | allowableValues.emplace_back(resource::ResetType::GracefulShutdown); |
| 3439 | } |
| 3440 | else if (dbusAllowedHostTran == |
| 3441 | "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot") |
| 3442 | { |
| 3443 | allowableValues.emplace_back(resource::ResetType::GracefulRestart); |
| 3444 | } |
| 3445 | else if (dbusAllowedHostTran == |
| 3446 | "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot") |
| 3447 | { |
| 3448 | allowableValues.emplace_back(resource::ResetType::ForceRestart); |
| 3449 | } |
| 3450 | else |
| 3451 | { |
| 3452 | BMCWEB_LOG_WARNING("Unsupported host tran {}", dbusAllowedHostTran); |
| 3453 | } |
| 3454 | } |
| 3455 | |
| 3456 | inline void afterGetAllowedHostTransitions( |
| 3457 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3458 | const boost::system::error_code& ec, |
| 3459 | const std::vector<std::string>& allowedHostTransitions) |
| 3460 | { |
| 3461 | nlohmann::json::array_t allowableValues; |
| 3462 | |
| 3463 | // Supported on all systems currently |
| 3464 | allowableValues.emplace_back(resource::ResetType::ForceOff); |
| 3465 | allowableValues.emplace_back(resource::ResetType::PowerCycle); |
| 3466 | allowableValues.emplace_back(resource::ResetType::Nmi); |
| 3467 | |
| 3468 | if (ec) |
| 3469 | { |
Ed Tanous | e715d14 | 2024-03-07 15:47:37 -0800 | [diff] [blame] | 3470 | if ((ec.value() == |
| 3471 | boost::system::linux_error::bad_request_descriptor) || |
| 3472 | (ec.value() == boost::asio::error::basic_errors::host_unreachable)) |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 3473 | { |
| 3474 | // Property not implemented so just return defaults |
| 3475 | BMCWEB_LOG_DEBUG("Property not available {}", ec); |
| 3476 | allowableValues.emplace_back(resource::ResetType::On); |
| 3477 | allowableValues.emplace_back(resource::ResetType::ForceOn); |
| 3478 | allowableValues.emplace_back(resource::ResetType::ForceRestart); |
| 3479 | allowableValues.emplace_back(resource::ResetType::GracefulRestart); |
| 3480 | allowableValues.emplace_back(resource::ResetType::GracefulShutdown); |
| 3481 | } |
| 3482 | else |
| 3483 | { |
| 3484 | BMCWEB_LOG_ERROR("DBUS response error {}", ec); |
| 3485 | messages::internalError(asyncResp->res); |
| 3486 | return; |
| 3487 | } |
| 3488 | } |
| 3489 | else |
| 3490 | { |
| 3491 | for (const std::string& transition : allowedHostTransitions) |
| 3492 | { |
| 3493 | BMCWEB_LOG_DEBUG("Found allowed host tran {}", transition); |
| 3494 | dbusToRfAllowedHostTransitions(transition, allowableValues); |
| 3495 | } |
| 3496 | } |
| 3497 | |
| 3498 | nlohmann::json::object_t parameter; |
| 3499 | parameter["Name"] = "ResetType"; |
| 3500 | parameter["Required"] = true; |
Ed Tanous | 539d8c6 | 2024-06-19 14:38:27 -0700 | [diff] [blame] | 3501 | parameter["DataType"] = action_info::ParameterTypes::String; |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 3502 | parameter["AllowableValues"] = std::move(allowableValues); |
| 3503 | nlohmann::json::array_t parameters; |
| 3504 | parameters.emplace_back(std::move(parameter)); |
| 3505 | asyncResp->res.jsonValue["Parameters"] = std::move(parameters); |
| 3506 | } |
| 3507 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3508 | inline void getAllowedHostTransitions( |
| 3509 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3510 | const uint64_t computerSystemIndex) |
| 3511 | { |
| 3512 | dbus::utility::getProperty<std::vector<std::string>>( |
| 3513 | getHostStateServiceName(computerSystemIndex), |
| 3514 | getHostStateObjectPath(computerSystemIndex), |
| 3515 | "xyz.openbmc_project.State.Host", "AllowedHostTransitions", |
| 3516 | std::bind_front(afterGetAllowedHostTransitions, asyncResp)); |
| 3517 | } |
| 3518 | |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3519 | inline void handleSystemCollectionResetActionGet( |
| 3520 | crow::App& app, const crow::Request& req, |
| 3521 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 3522 | const std::string& systemName) |
| 3523 | { |
| 3524 | if (!redfish::setUpRedfishRoute(app, req, asyncResp)) |
| 3525 | { |
| 3526 | return; |
| 3527 | } |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 3528 | |
Gunnar Mills | 6889620 | 2024-08-21 11:34:20 -0500 | [diff] [blame] | 3529 | if constexpr (BMCWEB_HYPERVISOR_COMPUTER_SYSTEM) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3530 | { |
Gunnar Mills | 6889620 | 2024-08-21 11:34:20 -0500 | [diff] [blame] | 3531 | if (systemName == "hypervisor") |
| 3532 | { |
| 3533 | handleHypervisorResetActionGet(asyncResp); |
| 3534 | return; |
| 3535 | } |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3536 | } |
| 3537 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3538 | if constexpr (!BMCWEB_EXPERIMENTAL_REDFISH_MULTI_COMPUTER_SYSTEM) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3539 | { |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3540 | if (systemName != BMCWEB_REDFISH_SYSTEM_URI_NAME) |
| 3541 | { |
| 3542 | messages::resourceNotFound(asyncResp->res, "ComputerSystem", |
| 3543 | systemName); |
| 3544 | return; |
| 3545 | } |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3546 | } |
| 3547 | |
| 3548 | asyncResp->res.addHeader( |
| 3549 | boost::beast::http::field::link, |
| 3550 | "</redfish/v1/JsonSchemas/ActionInfo/ActionInfo.json>; rel=describedby"); |
| 3551 | |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3552 | asyncResp->res.jsonValue["@odata.id"] = boost::urls::format( |
| 3553 | "/redfish/v1/Systems/{}/ResetActionInfo", systemName); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3554 | asyncResp->res.jsonValue["@odata.type"] = "#ActionInfo.v1_1_2.ActionInfo"; |
| 3555 | asyncResp->res.jsonValue["Name"] = "Reset Action Info"; |
| 3556 | asyncResp->res.jsonValue["Id"] = "ResetActionInfo"; |
| 3557 | |
Andrew Geissler | 33e1f12 | 2024-02-26 21:10:16 -0600 | [diff] [blame] | 3558 | // Look to see if system defines AllowedHostTransitions |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3559 | getComputerSystemIndex( |
| 3560 | asyncResp, systemName, |
| 3561 | std::bind_front(getAllowedHostTransitions, asyncResp)); |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3562 | } |
Oliver Brewka | 5e7c1f3 | 2025-07-23 16:38:05 +0200 | [diff] [blame^] | 3563 | |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 3564 | /** |
| 3565 | * SystemResetActionInfo derived class for delivering Computer Systems |
| 3566 | * ResetType AllowableValues using ResetInfo schema. |
| 3567 | */ |
Ed Tanous | 100afe5 | 2023-06-07 13:30:46 -0700 | [diff] [blame] | 3568 | inline void requestRoutesSystems(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 3569 | { |
Ed Tanous | 100afe5 | 2023-06-07 13:30:46 -0700 | [diff] [blame] | 3570 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/") |
| 3571 | .privileges(redfish::privileges::headComputerSystemCollection) |
| 3572 | .methods(boost::beast::http::verb::head)( |
| 3573 | std::bind_front(handleComputerSystemCollectionHead, std::ref(app))); |
| 3574 | |
| 3575 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/") |
| 3576 | .privileges(redfish::privileges::getComputerSystemCollection) |
| 3577 | .methods(boost::beast::http::verb::get)( |
| 3578 | std::bind_front(handleComputerSystemCollectionGet, std::ref(app))); |
| 3579 | |
| 3580 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") |
| 3581 | .privileges(redfish::privileges::headComputerSystem) |
| 3582 | .methods(boost::beast::http::verb::head)( |
| 3583 | std::bind_front(handleComputerSystemHead, std::ref(app))); |
| 3584 | |
| 3585 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") |
| 3586 | .privileges(redfish::privileges::getComputerSystem) |
| 3587 | .methods(boost::beast::http::verb::get)( |
| 3588 | std::bind_front(handleComputerSystemGet, std::ref(app))); |
| 3589 | |
| 3590 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/") |
| 3591 | .privileges(redfish::privileges::patchComputerSystem) |
| 3592 | .methods(boost::beast::http::verb::patch)( |
| 3593 | std::bind_front(handleComputerSystemPatch, std::ref(app))); |
| 3594 | |
| 3595 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/Actions/ComputerSystem.Reset/") |
| 3596 | .privileges(redfish::privileges::postComputerSystem) |
| 3597 | .methods(boost::beast::http::verb::post)(std::bind_front( |
| 3598 | handleComputerSystemResetActionPost, std::ref(app))); |
| 3599 | |
Ed Tanous | 7f3e84a | 2022-12-28 16:22:54 -0800 | [diff] [blame] | 3600 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") |
Ed Tanous | dd60b9e | 2022-07-07 17:03:54 -0700 | [diff] [blame] | 3601 | .privileges(redfish::privileges::headActionInfo) |
| 3602 | .methods(boost::beast::http::verb::head)(std::bind_front( |
| 3603 | handleSystemCollectionResetActionHead, std::ref(app))); |
Ed Tanous | 22d268c | 2022-05-19 09:39:07 -0700 | [diff] [blame] | 3604 | BMCWEB_ROUTE(app, "/redfish/v1/Systems/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 3605 | .privileges(redfish::privileges::getActionInfo) |
Ed Tanous | c1e219d | 2023-06-07 10:34:33 -0700 | [diff] [blame] | 3606 | .methods(boost::beast::http::verb::get)(std::bind_front( |
| 3607 | handleSystemCollectionResetActionGet, std::ref(app))); |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 3608 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 3609 | } // namespace redfish |