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