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