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