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