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