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