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