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