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