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