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