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