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