| 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 |  | 
| James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 18 | #include "health.hpp" | 
| James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 19 | #include "led.hpp" | 
| Jason M. Bills | f5c9f8b | 2018-12-18 16:51:18 -0800 | [diff] [blame] | 20 | #include "pcie.hpp" | 
| Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 21 | #include "redfish_util.hpp" | 
|  | 22 |  | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 23 | #include <boost/container/flat_map.hpp> | 
|  | 24 | #include <node.hpp> | 
| Andrew Geissler | cb7e1e7 | 2019-02-19 13:05:38 -0600 | [diff] [blame] | 25 | #include <utils/fw_utils.hpp> | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 26 | #include <utils/json_utils.hpp> | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 27 |  | 
| Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 28 | #include <variant> | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 29 |  | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 30 | namespace redfish | 
|  | 31 | { | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 32 |  | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 33 | /** | 
|  | 34 | * @brief Updates the Functional State of DIMMs | 
|  | 35 | * | 
|  | 36 | * @param[in] aResp Shared pointer for completing asynchronous calls | 
|  | 37 | * @param[in] dimmState Dimm's Functional state, true/false | 
|  | 38 | * | 
|  | 39 | * @return None. | 
|  | 40 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 41 | inline void updateDimmProperties(const std::shared_ptr<AsyncResp>& aResp, | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 42 | const std::variant<bool>& dimmState) | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 43 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 44 | const bool* isDimmFunctional = std::get_if<bool>(&dimmState); | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 45 | if (isDimmFunctional == nullptr) | 
|  | 46 | { | 
|  | 47 | messages::internalError(aResp->res); | 
|  | 48 | return; | 
|  | 49 | } | 
| Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 50 | BMCWEB_LOG_DEBUG << "Dimm Functional: " << *isDimmFunctional; | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 51 |  | 
| Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 52 | // Set it as Enabled if at least one DIMM is functional | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 53 | // Update STATE only if previous State was DISABLED and current Dimm is | 
|  | 54 | // ENABLED. | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 55 | nlohmann::json& prevMemSummary = | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 56 | aResp->res.jsonValue["MemorySummary"]["Status"]["State"]; | 
|  | 57 | if (prevMemSummary == "Disabled") | 
|  | 58 | { | 
|  | 59 | if (*isDimmFunctional == true) | 
|  | 60 | { | 
|  | 61 | aResp->res.jsonValue["MemorySummary"]["Status"]["State"] = | 
|  | 62 | "Enabled"; | 
|  | 63 | } | 
|  | 64 | } | 
|  | 65 | } | 
|  | 66 |  | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 67 | /* | 
|  | 68 | * @brief Update "ProcessorSummary" "Count" based on Cpu PresenceState | 
|  | 69 | * | 
|  | 70 | * @param[in] aResp Shared pointer for completing asynchronous calls | 
|  | 71 | * @param[in] cpuPresenceState CPU present or not | 
|  | 72 | * | 
|  | 73 | * @return None. | 
|  | 74 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 75 | inline void modifyCpuPresenceState(const std::shared_ptr<AsyncResp>& aResp, | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 76 | const std::variant<bool>& cpuPresenceState) | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 77 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 78 | const bool* isCpuPresent = std::get_if<bool>(&cpuPresenceState); | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 79 |  | 
|  | 80 | if (isCpuPresent == nullptr) | 
|  | 81 | { | 
|  | 82 | messages::internalError(aResp->res); | 
|  | 83 | return; | 
|  | 84 | } | 
| Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 85 | BMCWEB_LOG_DEBUG << "Cpu Present: " << *isCpuPresent; | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 86 |  | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 87 | if (*isCpuPresent == true) | 
|  | 88 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 89 | nlohmann::json& procCount = | 
| James Feist | b4b9595 | 2019-12-05 15:01:55 -0800 | [diff] [blame] | 90 | aResp->res.jsonValue["ProcessorSummary"]["Count"]; | 
|  | 91 | auto procCountPtr = | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 92 | procCount.get_ptr<nlohmann::json::number_integer_t*>(); | 
| James Feist | b4b9595 | 2019-12-05 15:01:55 -0800 | [diff] [blame] | 93 | if (procCountPtr != nullptr) | 
|  | 94 | { | 
|  | 95 | // shouldn't be possible to be nullptr | 
|  | 96 | *procCountPtr += 1; | 
|  | 97 | } | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 98 | } | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 99 | } | 
|  | 100 |  | 
|  | 101 | /* | 
|  | 102 | * @brief Update "ProcessorSummary" "Status" "State" based on | 
|  | 103 | *        CPU Functional State | 
|  | 104 | * | 
|  | 105 | * @param[in] aResp Shared pointer for completing asynchronous calls | 
|  | 106 | * @param[in] cpuFunctionalState is CPU functional true/false | 
|  | 107 | * | 
|  | 108 | * @return None. | 
|  | 109 | */ | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 110 | inline void | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 111 | modifyCpuFunctionalState(const std::shared_ptr<AsyncResp>& aResp, | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 112 | const std::variant<bool>& cpuFunctionalState) | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 113 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 114 | const bool* isCpuFunctional = std::get_if<bool>(&cpuFunctionalState); | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 115 |  | 
|  | 116 | if (isCpuFunctional == nullptr) | 
|  | 117 | { | 
|  | 118 | messages::internalError(aResp->res); | 
|  | 119 | return; | 
|  | 120 | } | 
| Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 121 | BMCWEB_LOG_DEBUG << "Cpu Functional: " << *isCpuFunctional; | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 122 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 123 | nlohmann::json& prevProcState = | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 124 | aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"]; | 
|  | 125 |  | 
| Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 126 | // Set it as Enabled if at least one CPU is functional | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 127 | // Update STATE only if previous State was Non_Functional and current CPU is | 
|  | 128 | // Functional. | 
|  | 129 | if (prevProcState == "Disabled") | 
|  | 130 | { | 
|  | 131 | if (*isCpuFunctional == true) | 
|  | 132 | { | 
|  | 133 | aResp->res.jsonValue["ProcessorSummary"]["Status"]["State"] = | 
|  | 134 | "Enabled"; | 
|  | 135 | } | 
|  | 136 | } | 
|  | 137 | } | 
|  | 138 |  | 
|  | 139 | /* | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 140 | * @brief Retrieves computer system properties over dbus | 
|  | 141 | * | 
|  | 142 | * @param[in] aResp Shared pointer for completing asynchronous calls | 
| Gunnar Mills | 8f9ee3c | 2020-10-30 16:15:13 -0500 | [diff] [blame] | 143 | * @param[in] systemHealth  Shared HealthPopulate pointer | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 144 | * | 
|  | 145 | * @return None. | 
|  | 146 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 147 | inline void | 
|  | 148 | getComputerSystem(const std::shared_ptr<AsyncResp>& aResp, | 
|  | 149 | const std::shared_ptr<HealthPopulate>& systemHealth) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 150 | { | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 151 | BMCWEB_LOG_DEBUG << "Get available system components."; | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 152 |  | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 153 | crow::connections::systemBus->async_method_call( | 
| James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 154 | [aResp, systemHealth]( | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 155 | const boost::system::error_code ec, | 
|  | 156 | const std::vector<std::pair< | 
|  | 157 | std::string, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 158 | std::vector<std::pair<std::string, std::vector<std::string>>>>>& | 
|  | 159 | subtree) { | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 160 | if (ec) | 
|  | 161 | { | 
|  | 162 | BMCWEB_LOG_DEBUG << "DBUS response error"; | 
| Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 163 | messages::internalError(aResp->res); | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 164 | return; | 
|  | 165 | } | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 166 | // Iterate over all retrieved ObjectPaths. | 
|  | 167 | for (const std::pair<std::string, | 
|  | 168 | std::vector<std::pair< | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 169 | std::string, std::vector<std::string>>>>& | 
|  | 170 | object : subtree) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 171 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 172 | const std::string& path = object.first; | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 173 | BMCWEB_LOG_DEBUG << "Got path: " << path; | 
|  | 174 | const std::vector< | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 175 | std::pair<std::string, std::vector<std::string>>>& | 
|  | 176 | connectionNames = object.second; | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 177 | if (connectionNames.size() < 1) | 
|  | 178 | { | 
|  | 179 | continue; | 
|  | 180 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 181 |  | 
| James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 182 | auto memoryHealth = std::make_shared<HealthPopulate>( | 
|  | 183 | aResp, aResp->res.jsonValue["MemorySummary"]["Status"]); | 
|  | 184 |  | 
|  | 185 | auto cpuHealth = std::make_shared<HealthPopulate>( | 
|  | 186 | aResp, aResp->res.jsonValue["ProcessorSummary"]["Status"]); | 
|  | 187 |  | 
|  | 188 | systemHealth->children.emplace_back(memoryHealth); | 
|  | 189 | systemHealth->children.emplace_back(cpuHealth); | 
|  | 190 |  | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 191 | // This is not system, so check if it's cpu, dimm, UUID or | 
|  | 192 | // BiosVer | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 193 | for (const auto& connection : connectionNames) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 194 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 195 | for (const auto& interfaceName : connection.second) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 196 | { | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 197 | if (interfaceName == | 
|  | 198 | "xyz.openbmc_project.Inventory.Item.Dimm") | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 199 | { | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 200 | BMCWEB_LOG_DEBUG | 
|  | 201 | << "Found Dimm, now get its properties."; | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 202 |  | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 203 | crow::connections::systemBus->async_method_call( | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 204 | [aResp, service{connection.first}, | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 205 | path](const boost::system::error_code ec2, | 
|  | 206 | const std::vector< | 
|  | 207 | std::pair<std::string, VariantType>>& | 
|  | 208 | properties) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 209 | if (ec2) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 210 | { | 
|  | 211 | BMCWEB_LOG_ERROR | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 212 | << "DBUS response error " << ec2; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 213 | messages::internalError(aResp->res); | 
|  | 214 | return; | 
|  | 215 | } | 
|  | 216 | BMCWEB_LOG_DEBUG << "Got " | 
|  | 217 | << properties.size() | 
| Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 218 | << " Dimm properties."; | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 219 |  | 
|  | 220 | if (properties.size() > 0) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 221 | { | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 222 | for (const std::pair<std::string, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 223 | VariantType>& | 
|  | 224 | property : properties) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 225 | { | 
| Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 226 | if (property.first != | 
|  | 227 | "MemorySizeInKB") | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 228 | { | 
| Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 229 | continue; | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 230 | } | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 231 | const uint32_t* value = | 
| Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 232 | std::get_if<uint32_t>( | 
|  | 233 | &property.second); | 
| Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 234 | if (value == nullptr) | 
|  | 235 | { | 
|  | 236 | BMCWEB_LOG_DEBUG | 
|  | 237 | << "Find incorrect type of " | 
|  | 238 | "MemorySize"; | 
|  | 239 | continue; | 
|  | 240 | } | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 241 | nlohmann::json& totalMemory = | 
| Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 242 | aResp->res | 
|  | 243 | .jsonValue["MemorySummar" | 
|  | 244 | "y"] | 
|  | 245 | ["TotalSystemMe" | 
|  | 246 | "moryGiB"]; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 247 | uint64_t* preValue = | 
| Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 248 | totalMemory | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 249 | .get_ptr<uint64_t*>(); | 
| Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 250 | if (preValue == nullptr) | 
|  | 251 | { | 
|  | 252 | continue; | 
|  | 253 | } | 
|  | 254 | aResp->res | 
|  | 255 | .jsonValue["MemorySummary"] | 
|  | 256 | ["TotalSystemMemoryGi" | 
|  | 257 | "B"] = | 
|  | 258 | *value / (1024 * 1024) + | 
|  | 259 | *preValue; | 
|  | 260 | aResp->res | 
|  | 261 | .jsonValue["MemorySummary"] | 
|  | 262 | ["Status"]["State"] = | 
|  | 263 | "Enabled"; | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 264 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 265 | } | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 266 | else | 
|  | 267 | { | 
|  | 268 | auto getDimmProperties = | 
|  | 269 | [aResp]( | 
|  | 270 | const boost::system::error_code | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 271 | ec3, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 272 | const std::variant<bool>& | 
|  | 273 | dimmState) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 274 | if (ec3) | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 275 | { | 
|  | 276 | BMCWEB_LOG_ERROR | 
|  | 277 | << "DBUS response " | 
|  | 278 | "error " | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 279 | << ec3; | 
| Alpana Kumari | 9d3ae10 | 2019-04-12 06:49:32 -0500 | [diff] [blame] | 280 | return; | 
|  | 281 | } | 
|  | 282 | updateDimmProperties(aResp, | 
|  | 283 | dimmState); | 
|  | 284 | }; | 
|  | 285 | crow::connections::systemBus | 
|  | 286 | ->async_method_call( | 
|  | 287 | std::move(getDimmProperties), | 
|  | 288 | service, path, | 
|  | 289 | "org.freedesktop.DBus." | 
|  | 290 | "Properties", | 
|  | 291 | "Get", | 
|  | 292 | "xyz.openbmc_project.State." | 
|  | 293 | "Decorator.OperationalStatus", | 
|  | 294 | "Functional"); | 
|  | 295 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 296 | }, | 
|  | 297 | connection.first, path, | 
|  | 298 | "org.freedesktop.DBus.Properties", "GetAll", | 
|  | 299 | "xyz.openbmc_project.Inventory.Item.Dimm"); | 
| James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 300 |  | 
|  | 301 | memoryHealth->inventory.emplace_back(path); | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 302 | } | 
|  | 303 | else if (interfaceName == | 
|  | 304 | "xyz.openbmc_project.Inventory.Item.Cpu") | 
|  | 305 | { | 
|  | 306 | BMCWEB_LOG_DEBUG | 
|  | 307 | << "Found Cpu, now get its properties."; | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 308 |  | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 309 | crow::connections::systemBus->async_method_call( | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 310 | [aResp, service{connection.first}, | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 311 | path](const boost::system::error_code ec2, | 
|  | 312 | const std::vector< | 
|  | 313 | std::pair<std::string, VariantType>>& | 
|  | 314 | properties) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 315 | if (ec2) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 316 | { | 
|  | 317 | BMCWEB_LOG_ERROR | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 318 | << "DBUS response error " << ec2; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 319 | messages::internalError(aResp->res); | 
|  | 320 | return; | 
|  | 321 | } | 
|  | 322 | BMCWEB_LOG_DEBUG << "Got " | 
|  | 323 | << properties.size() | 
| Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 324 | << " Cpu properties."; | 
| Ed Tanous | 04a258f | 2018-10-15 08:00:41 -0700 | [diff] [blame] | 325 |  | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 326 | if (properties.size() > 0) | 
|  | 327 | { | 
| Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 328 | const uint64_t* processorId = nullptr; | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 329 | const std::string* procFamily = nullptr; | 
|  | 330 | nlohmann::json& procSummary = | 
|  | 331 | aResp->res.jsonValue["ProcessorSumm" | 
|  | 332 | "ary"]; | 
|  | 333 | nlohmann::json& procCount = | 
|  | 334 | procSummary["Count"]; | 
|  | 335 |  | 
|  | 336 | auto procCountPtr = procCount.get_ptr< | 
|  | 337 | nlohmann::json:: | 
|  | 338 | number_integer_t*>(); | 
|  | 339 | if (procCountPtr == nullptr) | 
|  | 340 | { | 
|  | 341 | messages::internalError(aResp->res); | 
|  | 342 | return; | 
|  | 343 | } | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 344 | for (const auto& property : properties) | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 345 | { | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 346 |  | 
| Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 347 | if (property.first == "Id") | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 348 | { | 
|  | 349 | processorId = | 
| Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 350 | std::get_if<uint64_t>( | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 351 | &property.second); | 
|  | 352 | if (nullptr != procFamily) | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 353 | { | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 354 | break; | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 355 | } | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 356 | continue; | 
|  | 357 | } | 
|  | 358 |  | 
| Zhikui Ren | 9cf2152 | 2020-09-10 11:13:14 -0700 | [diff] [blame] | 359 | if (property.first == "Family") | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 360 | { | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 361 | procFamily = | 
| Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 362 | std::get_if<std::string>( | 
|  | 363 | &property.second); | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 364 | if (nullptr != processorId) | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 365 | { | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 366 | break; | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 367 | } | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 368 | continue; | 
|  | 369 | } | 
|  | 370 | } | 
| James Feist | b4b9595 | 2019-12-05 15:01:55 -0800 | [diff] [blame] | 371 |  | 
| Zhikui Ren | 029cc1f | 2020-08-25 15:21:41 -0700 | [diff] [blame] | 372 | if (procFamily != nullptr && | 
|  | 373 | processorId != nullptr) | 
|  | 374 | { | 
|  | 375 | if (procCountPtr != nullptr && | 
|  | 376 | *processorId != 0) | 
|  | 377 | { | 
|  | 378 | *procCountPtr += 1; | 
|  | 379 | procSummary["Status"]["State"] = | 
|  | 380 | "Enabled"; | 
|  | 381 |  | 
|  | 382 | procSummary["Model"] = | 
|  | 383 | *procFamily; | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 384 | } | 
|  | 385 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 386 | } | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 387 | else | 
|  | 388 | { | 
|  | 389 | auto getCpuPresenceState = | 
|  | 390 | [aResp]( | 
|  | 391 | const boost::system::error_code | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 392 | ec3, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 393 | const std::variant<bool>& | 
|  | 394 | cpuPresenceCheck) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 395 | if (ec3) | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 396 | { | 
|  | 397 | BMCWEB_LOG_ERROR | 
|  | 398 | << "DBUS response " | 
|  | 399 | "error " | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 400 | << ec3; | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 401 | return; | 
|  | 402 | } | 
|  | 403 | modifyCpuPresenceState( | 
|  | 404 | aResp, cpuPresenceCheck); | 
|  | 405 | }; | 
|  | 406 |  | 
|  | 407 | auto getCpuFunctionalState = | 
|  | 408 | [aResp]( | 
|  | 409 | const boost::system::error_code | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 410 | ec3, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 411 | const std::variant<bool>& | 
|  | 412 | cpuFunctionalCheck) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 413 | if (ec3) | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 414 | { | 
|  | 415 | BMCWEB_LOG_ERROR | 
|  | 416 | << "DBUS response " | 
|  | 417 | "error " | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 418 | << ec3; | 
| Alpana Kumari | 57e8c9b | 2019-04-15 01:09:36 -0500 | [diff] [blame] | 419 | return; | 
|  | 420 | } | 
|  | 421 | modifyCpuFunctionalState( | 
|  | 422 | aResp, cpuFunctionalCheck); | 
|  | 423 | }; | 
|  | 424 | // Get the Presence of CPU | 
|  | 425 | crow::connections::systemBus | 
|  | 426 | ->async_method_call( | 
|  | 427 | std::move(getCpuPresenceState), | 
|  | 428 | service, path, | 
|  | 429 | "org.freedesktop.DBus." | 
|  | 430 | "Properties", | 
|  | 431 | "Get", | 
|  | 432 | "xyz.openbmc_project.Inventory." | 
|  | 433 | "Item", | 
|  | 434 | "Present"); | 
|  | 435 |  | 
|  | 436 | // Get the Functional State | 
|  | 437 | crow::connections::systemBus | 
|  | 438 | ->async_method_call( | 
|  | 439 | std::move( | 
|  | 440 | getCpuFunctionalState), | 
|  | 441 | service, path, | 
|  | 442 | "org.freedesktop.DBus." | 
|  | 443 | "Properties", | 
|  | 444 | "Get", | 
|  | 445 | "xyz.openbmc_project.State." | 
|  | 446 | "Decorator." | 
|  | 447 | "OperationalStatus", | 
|  | 448 | "Functional"); | 
|  | 449 |  | 
|  | 450 | // Get the MODEL from | 
|  | 451 | // xyz.openbmc_project.Inventory.Decorator.Asset | 
|  | 452 | // support it later as Model  is Empty | 
|  | 453 | // currently. | 
|  | 454 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 455 | }, | 
|  | 456 | connection.first, path, | 
|  | 457 | "org.freedesktop.DBus.Properties", "GetAll", | 
|  | 458 | "xyz.openbmc_project.Inventory.Item.Cpu"); | 
| James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 459 |  | 
|  | 460 | cpuHealth->inventory.emplace_back(path); | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 461 | } | 
|  | 462 | else if (interfaceName == | 
|  | 463 | "xyz.openbmc_project.Common.UUID") | 
|  | 464 | { | 
|  | 465 | BMCWEB_LOG_DEBUG | 
|  | 466 | << "Found UUID, now get its properties."; | 
|  | 467 | crow::connections::systemBus->async_method_call( | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 468 | [aResp]( | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 469 | const boost::system::error_code ec3, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 470 | const std::vector< | 
|  | 471 | std::pair<std::string, VariantType>>& | 
|  | 472 | properties) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 473 | if (ec3) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 474 | { | 
|  | 475 | BMCWEB_LOG_DEBUG | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 476 | << "DBUS response error " << ec3; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 477 | messages::internalError(aResp->res); | 
|  | 478 | return; | 
|  | 479 | } | 
|  | 480 | BMCWEB_LOG_DEBUG << "Got " | 
|  | 481 | << properties.size() | 
| Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 482 | << " UUID properties."; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 483 | for (const std::pair<std::string, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 484 | VariantType>& | 
|  | 485 | property : properties) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 486 | { | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 487 | if (property.first == "UUID") | 
|  | 488 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 489 | const std::string* value = | 
| Patrick Williams | 8d78b7a | 2020-05-13 11:24:20 -0500 | [diff] [blame] | 490 | std::get_if<std::string>( | 
|  | 491 | &property.second); | 
| Ed Tanous | 04a258f | 2018-10-15 08:00:41 -0700 | [diff] [blame] | 492 |  | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 493 | if (value != nullptr) | 
|  | 494 | { | 
|  | 495 | std::string valueStr = *value; | 
|  | 496 | if (valueStr.size() == 32) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 497 | { | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 498 | valueStr.insert(8, 1, '-'); | 
|  | 499 | valueStr.insert(13, 1, '-'); | 
|  | 500 | valueStr.insert(18, 1, '-'); | 
|  | 501 | valueStr.insert(23, 1, '-'); | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 502 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 503 | BMCWEB_LOG_DEBUG << "UUID = " | 
|  | 504 | << valueStr; | 
|  | 505 | aResp->res.jsonValue["UUID"] = | 
|  | 506 | valueStr; | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 507 | } | 
|  | 508 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 509 | } | 
|  | 510 | }, | 
|  | 511 | connection.first, path, | 
|  | 512 | "org.freedesktop.DBus.Properties", "GetAll", | 
|  | 513 | "xyz.openbmc_project.Common.UUID"); | 
|  | 514 | } | 
|  | 515 | else if (interfaceName == | 
|  | 516 | "xyz.openbmc_project.Inventory.Item.System") | 
|  | 517 | { | 
|  | 518 | crow::connections::systemBus->async_method_call( | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 519 | [aResp]( | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 520 | const boost::system::error_code ec2, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 521 | const std::vector< | 
|  | 522 | std::pair<std::string, VariantType>>& | 
|  | 523 | propertiesList) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 524 | if (ec2) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 525 | { | 
| James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 526 | // doesn't have to include this | 
|  | 527 | // interface | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 528 | return; | 
|  | 529 | } | 
| Gunnar Mills | 698654b | 2019-10-16 13:17:37 -0500 | [diff] [blame] | 530 | BMCWEB_LOG_DEBUG | 
|  | 531 | << "Got " << propertiesList.size() | 
|  | 532 | << " properties for system"; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 533 | for (const std::pair<std::string, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 534 | VariantType>& | 
|  | 535 | property : propertiesList) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 536 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 537 | const std::string& propertyName = | 
| beccabroek | fc5afcf | 2019-03-05 14:35:15 -0600 | [diff] [blame] | 538 | property.first; | 
|  | 539 | if ((propertyName == "PartNumber") || | 
|  | 540 | (propertyName == "SerialNumber") || | 
|  | 541 | (propertyName == "Manufacturer") || | 
| SunnySrivastava1984 | 5235d96 | 2020-06-30 03:09:00 -0500 | [diff] [blame] | 542 | (propertyName == "Model") || | 
|  | 543 | (propertyName == "SubModel")) | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 544 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 545 | const std::string* value = | 
| beccabroek | fc5afcf | 2019-03-05 14:35:15 -0600 | [diff] [blame] | 546 | std::get_if<std::string>( | 
|  | 547 | &property.second); | 
|  | 548 | if (value != nullptr) | 
|  | 549 | { | 
|  | 550 | aResp->res | 
|  | 551 | .jsonValue[propertyName] = | 
|  | 552 | *value; | 
|  | 553 | } | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 554 | } | 
|  | 555 | } | 
| Gunnar Mills | c1e236a | 2020-04-14 21:36:33 -0500 | [diff] [blame] | 556 |  | 
| Andrew Geissler | cb7e1e7 | 2019-02-19 13:05:38 -0600 | [diff] [blame] | 557 | // Grab the bios version | 
| Gunnar Mills | f97ddba | 2020-08-20 15:57:40 -0500 | [diff] [blame] | 558 | fw_util::populateFirmwareInformation( | 
| Andrew Geissler | cb7e1e7 | 2019-02-19 13:05:38 -0600 | [diff] [blame] | 559 | aResp, fw_util::biosPurpose, | 
| Gunnar Mills | 72d566d | 2020-07-21 12:44:00 -0500 | [diff] [blame] | 560 | "BiosVersion", false); | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 561 | }, | 
|  | 562 | connection.first, path, | 
|  | 563 | "org.freedesktop.DBus.Properties", "GetAll", | 
|  | 564 | "xyz.openbmc_project.Inventory.Decorator." | 
|  | 565 | "Asset"); | 
| James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 566 |  | 
|  | 567 | crow::connections::systemBus->async_method_call( | 
|  | 568 | [aResp]( | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 569 | const boost::system::error_code ec2, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 570 | const std::variant<std::string>& property) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 571 | if (ec2) | 
| James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 572 | { | 
|  | 573 | // doesn't have to include this | 
|  | 574 | // interface | 
|  | 575 | return; | 
|  | 576 | } | 
|  | 577 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 578 | const std::string* value = | 
| James Feist | e4a4b9a | 2019-06-20 14:08:07 -0700 | [diff] [blame] | 579 | std::get_if<std::string>(&property); | 
|  | 580 | if (value != nullptr) | 
|  | 581 | { | 
|  | 582 | aResp->res.jsonValue["AssetTag"] = | 
|  | 583 | *value; | 
|  | 584 | } | 
|  | 585 | }, | 
|  | 586 | connection.first, path, | 
|  | 587 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 588 | "xyz.openbmc_project.Inventory.Decorator." | 
|  | 589 | "AssetTag", | 
|  | 590 | "AssetTag"); | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 591 | } | 
|  | 592 | } | 
|  | 593 | } | 
|  | 594 | } | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 595 | }, | 
|  | 596 | "xyz.openbmc_project.ObjectMapper", | 
|  | 597 | "/xyz/openbmc_project/object_mapper", | 
|  | 598 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 599 | "/xyz/openbmc_project/inventory", int32_t(0), | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 600 | std::array<const char*, 5>{ | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 601 | "xyz.openbmc_project.Inventory.Decorator.Asset", | 
|  | 602 | "xyz.openbmc_project.Inventory.Item.Cpu", | 
|  | 603 | "xyz.openbmc_project.Inventory.Item.Dimm", | 
|  | 604 | "xyz.openbmc_project.Inventory.Item.System", | 
|  | 605 | "xyz.openbmc_project.Common.UUID", | 
|  | 606 | }); | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 607 | } | 
|  | 608 |  | 
|  | 609 | /** | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 610 | * @brief Retrieves host state properties over dbus | 
|  | 611 | * | 
|  | 612 | * @param[in] aResp     Shared pointer for completing asynchronous calls. | 
|  | 613 | * | 
|  | 614 | * @return None. | 
|  | 615 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 616 | inline void getHostState(const std::shared_ptr<AsyncResp>& aResp) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 617 | { | 
|  | 618 | BMCWEB_LOG_DEBUG << "Get host information."; | 
|  | 619 | crow::connections::systemBus->async_method_call( | 
| Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 620 | [aResp](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 621 | const std::variant<std::string>& hostState) { | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 622 | if (ec) | 
|  | 623 | { | 
|  | 624 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
| Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 625 | messages::internalError(aResp->res); | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 626 | return; | 
|  | 627 | } | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 628 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 629 | const std::string* s = std::get_if<std::string>(&hostState); | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 630 | BMCWEB_LOG_DEBUG << "Host state: " << *s; | 
|  | 631 | if (s != nullptr) | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 632 | { | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 633 | // Verify Host State | 
| Andrew Geissler | 9473266 | 2019-01-08 19:32:16 -0800 | [diff] [blame] | 634 | if (*s == "xyz.openbmc_project.State.Host.HostState.Running") | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 635 | { | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 636 | aResp->res.jsonValue["PowerState"] = "On"; | 
|  | 637 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; | 
|  | 638 | } | 
| Andrew Geissler | 83935af | 2020-02-13 10:24:53 -0600 | [diff] [blame] | 639 | else if (*s == "xyz.openbmc_project.State.Host.HostState." | 
| Gunnar Mills | 8c88860 | 2020-05-01 14:25:09 -0500 | [diff] [blame] | 640 | "Quiesced") | 
|  | 641 | { | 
|  | 642 | aResp->res.jsonValue["PowerState"] = "On"; | 
|  | 643 | aResp->res.jsonValue["Status"]["State"] = "Quiesced"; | 
|  | 644 | } | 
|  | 645 | else if (*s == "xyz.openbmc_project.State.Host.HostState." | 
| Andrew Geissler | 83935af | 2020-02-13 10:24:53 -0600 | [diff] [blame] | 646 | "DiagnosticMode") | 
|  | 647 | { | 
|  | 648 | aResp->res.jsonValue["PowerState"] = "On"; | 
|  | 649 | aResp->res.jsonValue["Status"]["State"] = "InTest"; | 
|  | 650 | } | 
| Andrew Geissler | 1a2a143 | 2021-01-06 13:48:57 -0600 | [diff] [blame] | 651 | else if (*s == "xyz.openbmc_project.State.Host.HostState." | 
|  | 652 | "TransitioningToRunning") | 
|  | 653 | { | 
|  | 654 | aResp->res.jsonValue["PowerState"] = "PoweringOn"; | 
|  | 655 | aResp->res.jsonValue["Status"]["State"] = "Disabled"; | 
|  | 656 | } | 
|  | 657 | else if (*s == "xyz.openbmc_project.State.Host.HostState." | 
|  | 658 | "TransitioningToOff") | 
|  | 659 | { | 
|  | 660 | aResp->res.jsonValue["PowerState"] = "PoweringOff"; | 
|  | 661 | aResp->res.jsonValue["Status"]["State"] = "Disabled"; | 
|  | 662 | } | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 663 | else | 
|  | 664 | { | 
|  | 665 | aResp->res.jsonValue["PowerState"] = "Off"; | 
|  | 666 | aResp->res.jsonValue["Status"]["State"] = "Disabled"; | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 667 | } | 
|  | 668 | } | 
|  | 669 | }, | 
|  | 670 | "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 671 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 672 | "xyz.openbmc_project.State.Host", "CurrentHostState"); | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 673 | } | 
|  | 674 |  | 
|  | 675 | /** | 
| Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 676 | * @brief Translates boot source DBUS property value to redfish. | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 677 | * | 
|  | 678 | * @param[in] dbusSource    The boot source in DBUS speak. | 
|  | 679 | * | 
|  | 680 | * @return Returns as a string, the boot source in Redfish terms. If translation | 
|  | 681 | * cannot be done, returns an empty string. | 
|  | 682 | */ | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 683 | inline std::string dbusToRfBootSource(const std::string& dbusSource) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 684 | { | 
|  | 685 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Default") | 
|  | 686 | { | 
|  | 687 | return "None"; | 
|  | 688 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 689 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Disk") | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 690 | { | 
|  | 691 | return "Hdd"; | 
|  | 692 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 693 | if (dbusSource == | 
|  | 694 | "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia") | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 695 | { | 
|  | 696 | return "Cd"; | 
|  | 697 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 698 | if (dbusSource == "xyz.openbmc_project.Control.Boot.Source.Sources.Network") | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 699 | { | 
|  | 700 | return "Pxe"; | 
|  | 701 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 702 | if (dbusSource == | 
|  | 703 | "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia") | 
| Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 704 | { | 
|  | 705 | return "Usb"; | 
|  | 706 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 707 | return ""; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 708 | } | 
|  | 709 |  | 
|  | 710 | /** | 
| Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 711 | * @brief Translates boot mode DBUS property value to redfish. | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 712 | * | 
|  | 713 | * @param[in] dbusMode    The boot mode in DBUS speak. | 
|  | 714 | * | 
|  | 715 | * @return Returns as a string, the boot mode in Redfish terms. If translation | 
|  | 716 | * cannot be done, returns an empty string. | 
|  | 717 | */ | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 718 | inline std::string dbusToRfBootMode(const std::string& dbusMode) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 719 | { | 
|  | 720 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") | 
|  | 721 | { | 
|  | 722 | return "None"; | 
|  | 723 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 724 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe") | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 725 | { | 
|  | 726 | return "Diags"; | 
|  | 727 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 728 | if (dbusMode == "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup") | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 729 | { | 
|  | 730 | return "BiosSetup"; | 
|  | 731 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 732 | return ""; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 733 | } | 
|  | 734 |  | 
|  | 735 | /** | 
| Gunnar Mills | 786d0f6 | 2020-07-08 13:43:15 -0500 | [diff] [blame] | 736 | * @brief Translates boot source from Redfish to the DBus boot paths. | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 737 | * | 
|  | 738 | * @param[in] rfSource    The boot source in Redfish. | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 739 | * @param[out] bootSource The DBus source | 
|  | 740 | * @param[out] bootMode   the DBus boot mode | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 741 | * | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 742 | * @return Integer error code. | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 743 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 744 | inline int assignBootParameters(const std::shared_ptr<AsyncResp>& aResp, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 745 | const std::string& rfSource, | 
|  | 746 | std::string& bootSource, std::string& bootMode) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 747 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 748 | // The caller has initialized the bootSource and bootMode to: | 
|  | 749 | // bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; | 
|  | 750 | // bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; | 
|  | 751 | // Only modify the bootSource/bootMode variable needed to achieve the | 
|  | 752 | // desired boot action. | 
|  | 753 |  | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 754 | if (rfSource == "None") | 
|  | 755 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 756 | return 0; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 757 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 758 | if (rfSource == "Pxe") | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 759 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 760 | bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Network"; | 
|  | 761 | } | 
|  | 762 | else if (rfSource == "Hdd") | 
|  | 763 | { | 
|  | 764 | bootSource = "xyz.openbmc_project.Control.Boot.Source.Sources.Disk"; | 
|  | 765 | } | 
|  | 766 | else if (rfSource == "Diags") | 
|  | 767 | { | 
|  | 768 | bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Safe"; | 
|  | 769 | } | 
|  | 770 | else if (rfSource == "Cd") | 
|  | 771 | { | 
|  | 772 | bootSource = | 
|  | 773 | "xyz.openbmc_project.Control.Boot.Source.Sources.ExternalMedia"; | 
|  | 774 | } | 
|  | 775 | else if (rfSource == "BiosSetup") | 
|  | 776 | { | 
|  | 777 | bootMode = "xyz.openbmc_project.Control.Boot.Mode.Modes.Setup"; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 778 | } | 
| Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 779 | else if (rfSource == "Usb") | 
|  | 780 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 781 | bootSource = | 
|  | 782 | "xyz.openbmc_project.Control.Boot.Source.Sources.RemovableMedia"; | 
| Jennifer Lee | 9f16b2c | 2019-04-19 15:33:48 -0700 | [diff] [blame] | 783 | } | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 784 | else | 
|  | 785 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 786 | BMCWEB_LOG_DEBUG << "Invalid property value for " | 
|  | 787 | "BootSourceOverrideTarget: " | 
|  | 788 | << bootSource; | 
|  | 789 | messages::propertyValueNotInList(aResp->res, rfSource, | 
|  | 790 | "BootSourceTargetOverride"); | 
|  | 791 | return -1; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 792 | } | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 793 | return 0; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 794 | } | 
| Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 795 | /** | 
|  | 796 | * @brief Retrieves boot progress of the system | 
|  | 797 | * | 
|  | 798 | * @param[in] aResp  Shared pointer for generating response message. | 
|  | 799 | * | 
|  | 800 | * @return None. | 
|  | 801 | */ | 
|  | 802 | inline void getBootProgress(const std::shared_ptr<AsyncResp>& aResp) | 
|  | 803 | { | 
|  | 804 | crow::connections::systemBus->async_method_call( | 
|  | 805 | [aResp](const boost::system::error_code ec, | 
|  | 806 | const std::variant<std::string>& bootProgress) { | 
|  | 807 | if (ec) | 
|  | 808 | { | 
|  | 809 | // BootProgress is an optional object so just do nothing if | 
|  | 810 | // not found | 
|  | 811 | return; | 
|  | 812 | } | 
|  | 813 |  | 
|  | 814 | const std::string* bootProgressStr = | 
|  | 815 | std::get_if<std::string>(&bootProgress); | 
|  | 816 |  | 
|  | 817 | if (!bootProgressStr) | 
|  | 818 | { | 
|  | 819 | // Interface implemented but property not found, return error | 
|  | 820 | // for that | 
|  | 821 | messages::internalError(aResp->res); | 
|  | 822 | return; | 
|  | 823 | } | 
|  | 824 |  | 
|  | 825 | BMCWEB_LOG_DEBUG << "Boot Progress: " << *bootProgressStr; | 
|  | 826 |  | 
|  | 827 | // Now convert the D-Bus BootProgress to the appropriate Redfish | 
|  | 828 | // enum | 
|  | 829 | std::string rfBpLastState = "None"; | 
|  | 830 | if (*bootProgressStr == "xyz.openbmc_project.State.Boot.Progress." | 
|  | 831 | "ProgressStages.Unspecified") | 
|  | 832 | { | 
|  | 833 | rfBpLastState = "None"; | 
|  | 834 | } | 
|  | 835 | else if (*bootProgressStr == | 
|  | 836 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 837 | "PrimaryProcInit") | 
|  | 838 | { | 
|  | 839 | rfBpLastState = "PrimaryProcessorInitializationStarted"; | 
|  | 840 | } | 
|  | 841 | else if (*bootProgressStr == | 
|  | 842 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 843 | "BusInit") | 
|  | 844 | { | 
|  | 845 | rfBpLastState = "BusInitializationStarted"; | 
|  | 846 | } | 
|  | 847 | else if (*bootProgressStr == | 
|  | 848 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 849 | "MemoryInit") | 
|  | 850 | { | 
|  | 851 | rfBpLastState = "MemoryInitializationStarted"; | 
|  | 852 | } | 
|  | 853 | else if (*bootProgressStr == | 
|  | 854 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 855 | "SecondaryProcInit") | 
|  | 856 | { | 
|  | 857 | rfBpLastState = "SecondaryProcessorInitializationStarted"; | 
|  | 858 | } | 
|  | 859 | else if (*bootProgressStr == | 
|  | 860 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 861 | "PCIInit") | 
|  | 862 | { | 
|  | 863 | rfBpLastState = "PCIResourceConfigStarted"; | 
|  | 864 | } | 
|  | 865 | else if (*bootProgressStr == | 
|  | 866 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 867 | "SystemInitComplete") | 
|  | 868 | { | 
|  | 869 | rfBpLastState = "SystemHardwareInitializationComplete"; | 
|  | 870 | } | 
|  | 871 | else if (*bootProgressStr == | 
|  | 872 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 873 | "OSStart") | 
|  | 874 | { | 
|  | 875 | rfBpLastState = "OSBootStarted"; | 
|  | 876 | } | 
|  | 877 | else if (*bootProgressStr == | 
|  | 878 | "xyz.openbmc_project.State.Boot.Progress.ProgressStages." | 
|  | 879 | "OSRunning") | 
|  | 880 | { | 
|  | 881 | rfBpLastState = "OSRunning"; | 
|  | 882 | } | 
|  | 883 | else | 
|  | 884 | { | 
|  | 885 | BMCWEB_LOG_DEBUG << "Unsupported D-Bus BootProgress " | 
|  | 886 | << *bootProgressStr; | 
|  | 887 | // Just return the default | 
|  | 888 | } | 
|  | 889 |  | 
|  | 890 | aResp->res.jsonValue["BootProgress"]["LastState"] = rfBpLastState; | 
|  | 891 | }, | 
|  | 892 | "xyz.openbmc_project.State.Host", "/xyz/openbmc_project/state/host0", | 
|  | 893 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 894 | "xyz.openbmc_project.State.Boot.Progress", "BootProgress"); | 
|  | 895 | } | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 896 |  | 
|  | 897 | /** | 
|  | 898 | * @brief Retrieves boot mode over DBUS and fills out the response | 
|  | 899 | * | 
|  | 900 | * @param[in] aResp         Shared pointer for generating response message. | 
|  | 901 | * @param[in] bootDbusObj   The dbus object to query for boot properties. | 
|  | 902 | * | 
|  | 903 | * @return None. | 
|  | 904 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 905 | inline void getBootMode(const std::shared_ptr<AsyncResp>& aResp, | 
|  | 906 | const std::string& bootDbusObj) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 907 | { | 
|  | 908 | crow::connections::systemBus->async_method_call( | 
|  | 909 | [aResp](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 910 | const std::variant<std::string>& bootMode) { | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 911 | if (ec) | 
|  | 912 | { | 
|  | 913 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 914 | messages::internalError(aResp->res); | 
|  | 915 | return; | 
|  | 916 | } | 
|  | 917 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 918 | const std::string* bootModeStr = | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 919 | std::get_if<std::string>(&bootMode); | 
|  | 920 |  | 
|  | 921 | if (!bootModeStr) | 
|  | 922 | { | 
|  | 923 | messages::internalError(aResp->res); | 
|  | 924 | return; | 
|  | 925 | } | 
|  | 926 |  | 
|  | 927 | BMCWEB_LOG_DEBUG << "Boot mode: " << *bootModeStr; | 
|  | 928 |  | 
|  | 929 | // TODO (Santosh): Do we need to support override mode? | 
|  | 930 | aResp->res.jsonValue["Boot"]["BootSourceOverrideMode"] = "Legacy"; | 
|  | 931 | aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget@Redfish." | 
|  | 932 | "AllowableValues"] = { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 933 | "None", "Pxe", "Hdd", "Cd", "Diags", "BiosSetup", "Usb"}; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 934 |  | 
|  | 935 | if (*bootModeStr != | 
|  | 936 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular") | 
|  | 937 | { | 
|  | 938 | auto rfMode = dbusToRfBootMode(*bootModeStr); | 
|  | 939 | if (!rfMode.empty()) | 
|  | 940 | { | 
|  | 941 | aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = | 
|  | 942 | rfMode; | 
|  | 943 | } | 
|  | 944 | } | 
|  | 945 |  | 
|  | 946 | // If the BootSourceOverrideTarget is still "None" at the end, | 
|  | 947 | // reset the BootSourceOverrideEnabled to indicate that | 
|  | 948 | // overrides are disabled | 
|  | 949 | if (aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] == | 
|  | 950 | "None") | 
|  | 951 | { | 
|  | 952 | aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = | 
|  | 953 | "Disabled"; | 
|  | 954 | } | 
|  | 955 | }, | 
|  | 956 | "xyz.openbmc_project.Settings", bootDbusObj, | 
|  | 957 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 958 | "xyz.openbmc_project.Control.Boot.Mode", "BootMode"); | 
|  | 959 | } | 
|  | 960 |  | 
|  | 961 | /** | 
|  | 962 | * @brief Retrieves boot source over DBUS | 
|  | 963 | * | 
|  | 964 | * @param[in] aResp         Shared pointer for generating response message. | 
|  | 965 | * @param[in] oneTimeEnable Boolean to indicate boot properties are one-time. | 
|  | 966 | * | 
|  | 967 | * @return None. | 
|  | 968 | */ | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 969 | inline void getBootSource(const std::shared_ptr<AsyncResp>& aResp, | 
|  | 970 | bool oneTimeEnabled) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 971 | { | 
|  | 972 | std::string bootDbusObj = | 
|  | 973 | oneTimeEnabled ? "/xyz/openbmc_project/control/host0/boot/one_time" | 
|  | 974 | : "/xyz/openbmc_project/control/host0/boot"; | 
|  | 975 |  | 
|  | 976 | BMCWEB_LOG_DEBUG << "Is one time: " << oneTimeEnabled; | 
|  | 977 | aResp->res.jsonValue["Boot"]["BootSourceOverrideEnabled"] = | 
|  | 978 | (oneTimeEnabled) ? "Once" : "Continuous"; | 
|  | 979 |  | 
|  | 980 | crow::connections::systemBus->async_method_call( | 
|  | 981 | [aResp, bootDbusObj](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 982 | const std::variant<std::string>& bootSource) { | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 983 | if (ec) | 
|  | 984 | { | 
|  | 985 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 986 | messages::internalError(aResp->res); | 
|  | 987 | return; | 
|  | 988 | } | 
|  | 989 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 990 | const std::string* bootSourceStr = | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 991 | std::get_if<std::string>(&bootSource); | 
|  | 992 |  | 
|  | 993 | if (!bootSourceStr) | 
|  | 994 | { | 
|  | 995 | messages::internalError(aResp->res); | 
|  | 996 | return; | 
|  | 997 | } | 
|  | 998 | BMCWEB_LOG_DEBUG << "Boot source: " << *bootSourceStr; | 
|  | 999 |  | 
|  | 1000 | auto rfSource = dbusToRfBootSource(*bootSourceStr); | 
|  | 1001 | if (!rfSource.empty()) | 
|  | 1002 | { | 
|  | 1003 | aResp->res.jsonValue["Boot"]["BootSourceOverrideTarget"] = | 
|  | 1004 | rfSource; | 
|  | 1005 | } | 
|  | 1006 | }, | 
|  | 1007 | "xyz.openbmc_project.Settings", bootDbusObj, | 
|  | 1008 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1009 | "xyz.openbmc_project.Control.Boot.Source", "BootSource"); | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1010 | getBootMode(aResp, bootDbusObj); | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1011 | } | 
|  | 1012 |  | 
|  | 1013 | /** | 
|  | 1014 | * @brief Retrieves "One time" enabled setting over DBUS and calls function to | 
|  | 1015 | * get boot source and boot mode. | 
|  | 1016 | * | 
|  | 1017 | * @param[in] aResp     Shared pointer for generating response message. | 
|  | 1018 | * | 
|  | 1019 | * @return None. | 
|  | 1020 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1021 | inline void getBootProperties(const std::shared_ptr<AsyncResp>& aResp) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1022 | { | 
|  | 1023 | BMCWEB_LOG_DEBUG << "Get boot information."; | 
|  | 1024 |  | 
|  | 1025 | crow::connections::systemBus->async_method_call( | 
| Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 1026 | [aResp](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1027 | const std::variant<bool>& oneTime) { | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1028 | if (ec) | 
|  | 1029 | { | 
|  | 1030 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
| James Feist | 2a833c7 | 2019-07-19 10:17:13 -0700 | [diff] [blame] | 1031 | // not an error, don't have to have the interface | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1032 | return; | 
|  | 1033 | } | 
|  | 1034 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1035 | const bool* oneTimePtr = std::get_if<bool>(&oneTime); | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1036 |  | 
|  | 1037 | if (!oneTimePtr) | 
|  | 1038 | { | 
|  | 1039 | messages::internalError(aResp->res); | 
|  | 1040 | return; | 
|  | 1041 | } | 
|  | 1042 | getBootSource(aResp, *oneTimePtr); | 
|  | 1043 | }, | 
|  | 1044 | "xyz.openbmc_project.Settings", | 
|  | 1045 | "/xyz/openbmc_project/control/host0/boot/one_time", | 
|  | 1046 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1047 | "xyz.openbmc_project.Object.Enable", "Enabled"); | 
|  | 1048 | } | 
|  | 1049 |  | 
|  | 1050 | /** | 
| Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1051 | * @brief Retrieves the Last Reset Time | 
|  | 1052 | * | 
|  | 1053 | * "Reset" is an overloaded term in Redfish, "Reset" includes power on | 
|  | 1054 | * and power off. Even though this is the "system" Redfish object look at the | 
|  | 1055 | * chassis D-Bus interface for the LastStateChangeTime since this has the | 
|  | 1056 | * last power operation time. | 
|  | 1057 | * | 
|  | 1058 | * @param[in] aResp     Shared pointer for generating response message. | 
|  | 1059 | * | 
|  | 1060 | * @return None. | 
|  | 1061 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1062 | inline void getLastResetTime(const std::shared_ptr<AsyncResp>& aResp) | 
| Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 1063 | { | 
|  | 1064 | BMCWEB_LOG_DEBUG << "Getting System Last Reset Time"; | 
|  | 1065 |  | 
|  | 1066 | crow::connections::systemBus->async_method_call( | 
|  | 1067 | [aResp](const boost::system::error_code ec, | 
|  | 1068 | std::variant<uint64_t>& lastResetTime) { | 
|  | 1069 | if (ec) | 
|  | 1070 | { | 
|  | 1071 | BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; | 
|  | 1072 | return; | 
|  | 1073 | } | 
|  | 1074 |  | 
|  | 1075 | const uint64_t* lastResetTimePtr = | 
|  | 1076 | std::get_if<uint64_t>(&lastResetTime); | 
|  | 1077 |  | 
|  | 1078 | if (!lastResetTimePtr) | 
|  | 1079 | { | 
|  | 1080 | messages::internalError(aResp->res); | 
|  | 1081 | return; | 
|  | 1082 | } | 
|  | 1083 | // LastStateChangeTime is epoch time, in milliseconds | 
|  | 1084 | // https://github.com/openbmc/phosphor-dbus-interfaces/blob/33e8e1dd64da53a66e888d33dc82001305cd0bf9/xyz/openbmc_project/State/Chassis.interface.yaml#L19 | 
|  | 1085 | time_t lastResetTimeStamp = | 
|  | 1086 | static_cast<time_t>(*lastResetTimePtr / 1000); | 
|  | 1087 |  | 
|  | 1088 | // Convert to ISO 8601 standard | 
|  | 1089 | aResp->res.jsonValue["LastResetTime"] = | 
|  | 1090 | crow::utility::getDateTime(lastResetTimeStamp); | 
|  | 1091 | }, | 
|  | 1092 | "xyz.openbmc_project.State.Chassis", | 
|  | 1093 | "/xyz/openbmc_project/state/chassis0", | 
|  | 1094 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1095 | "xyz.openbmc_project.State.Chassis", "LastStateChangeTime"); | 
|  | 1096 | } | 
|  | 1097 |  | 
|  | 1098 | /** | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1099 | * @brief Retrieves Automatic Retry properties. Known on D-Bus as AutoReboot. | 
|  | 1100 | * | 
|  | 1101 | * @param[in] aResp     Shared pointer for generating response message. | 
|  | 1102 | * | 
|  | 1103 | * @return None. | 
|  | 1104 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1105 | inline void getAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp) | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1106 | { | 
|  | 1107 | BMCWEB_LOG_DEBUG << "Get Automatic Retry policy"; | 
|  | 1108 |  | 
|  | 1109 | crow::connections::systemBus->async_method_call( | 
|  | 1110 | [aResp](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1111 | std::variant<bool>& autoRebootEnabled) { | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1112 | if (ec) | 
|  | 1113 | { | 
|  | 1114 | BMCWEB_LOG_DEBUG << "D-BUS response error " << ec; | 
|  | 1115 | return; | 
|  | 1116 | } | 
|  | 1117 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1118 | const bool* autoRebootEnabledPtr = | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1119 | std::get_if<bool>(&autoRebootEnabled); | 
|  | 1120 |  | 
|  | 1121 | if (!autoRebootEnabledPtr) | 
|  | 1122 | { | 
|  | 1123 | messages::internalError(aResp->res); | 
|  | 1124 | return; | 
|  | 1125 | } | 
|  | 1126 |  | 
|  | 1127 | BMCWEB_LOG_DEBUG << "Auto Reboot: " << *autoRebootEnabledPtr; | 
|  | 1128 | if (*autoRebootEnabledPtr == true) | 
|  | 1129 | { | 
|  | 1130 | aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = | 
|  | 1131 | "RetryAttempts"; | 
|  | 1132 | // If AutomaticRetry (AutoReboot) is enabled see how many | 
|  | 1133 | // attempts are left | 
|  | 1134 | crow::connections::systemBus->async_method_call( | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1135 | [aResp](const boost::system::error_code ec2, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1136 | std::variant<uint32_t>& autoRebootAttemptsLeft) { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1137 | if (ec2) | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1138 | { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1139 | BMCWEB_LOG_DEBUG << "D-BUS response error " << ec2; | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1140 | return; | 
|  | 1141 | } | 
|  | 1142 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1143 | const uint32_t* autoRebootAttemptsLeftPtr = | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1144 | std::get_if<uint32_t>(&autoRebootAttemptsLeft); | 
|  | 1145 |  | 
|  | 1146 | if (!autoRebootAttemptsLeftPtr) | 
|  | 1147 | { | 
|  | 1148 | messages::internalError(aResp->res); | 
|  | 1149 | return; | 
|  | 1150 | } | 
|  | 1151 |  | 
|  | 1152 | BMCWEB_LOG_DEBUG << "Auto Reboot Attempts Left: " | 
|  | 1153 | << *autoRebootAttemptsLeftPtr; | 
|  | 1154 |  | 
|  | 1155 | aResp->res | 
|  | 1156 | .jsonValue["Boot"] | 
|  | 1157 | ["RemainingAutomaticRetryAttempts"] = | 
|  | 1158 | *autoRebootAttemptsLeftPtr; | 
|  | 1159 | }, | 
|  | 1160 | "xyz.openbmc_project.State.Host", | 
|  | 1161 | "/xyz/openbmc_project/state/host0", | 
|  | 1162 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1163 | "xyz.openbmc_project.Control.Boot.RebootAttempts", | 
|  | 1164 | "AttemptsLeft"); | 
|  | 1165 | } | 
|  | 1166 | else | 
|  | 1167 | { | 
|  | 1168 | aResp->res.jsonValue["Boot"]["AutomaticRetryConfig"] = | 
|  | 1169 | "Disabled"; | 
|  | 1170 | } | 
|  | 1171 |  | 
|  | 1172 | // Not on D-Bus. Hardcoded here: | 
|  | 1173 | // https://github.com/openbmc/phosphor-state-manager/blob/1dbbef42675e94fb1f78edb87d6b11380260535a/meson_options.txt#L71 | 
|  | 1174 | aResp->res.jsonValue["Boot"]["AutomaticRetryAttempts"] = 3; | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1175 |  | 
|  | 1176 | // "AutomaticRetryConfig" can be 3 values, Disabled, RetryAlways, | 
|  | 1177 | // and RetryAttempts. OpenBMC only supports Disabled and | 
|  | 1178 | // RetryAttempts. | 
|  | 1179 | aResp->res.jsonValue["Boot"]["AutomaticRetryConfig@Redfish." | 
|  | 1180 | "AllowableValues"] = {"Disabled", | 
|  | 1181 | "RetryAttempts"}; | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 1182 | }, | 
|  | 1183 | "xyz.openbmc_project.Settings", | 
|  | 1184 | "/xyz/openbmc_project/control/host0/auto_reboot", | 
|  | 1185 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1186 | "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot"); | 
|  | 1187 | } | 
|  | 1188 |  | 
|  | 1189 | /** | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1190 | * @brief Retrieves power restore policy over DBUS. | 
|  | 1191 | * | 
|  | 1192 | * @param[in] aResp     Shared pointer for generating response message. | 
|  | 1193 | * | 
|  | 1194 | * @return None. | 
|  | 1195 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1196 | inline void getPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp) | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1197 | { | 
|  | 1198 | BMCWEB_LOG_DEBUG << "Get power restore policy"; | 
|  | 1199 |  | 
|  | 1200 | crow::connections::systemBus->async_method_call( | 
|  | 1201 | [aResp](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1202 | std::variant<std::string>& policy) { | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1203 | if (ec) | 
|  | 1204 | { | 
|  | 1205 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1206 | return; | 
|  | 1207 | } | 
|  | 1208 |  | 
|  | 1209 | const boost::container::flat_map<std::string, std::string> | 
|  | 1210 | policyMaps = { | 
|  | 1211 | {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." | 
|  | 1212 | "AlwaysOn", | 
|  | 1213 | "AlwaysOn"}, | 
|  | 1214 | {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." | 
|  | 1215 | "AlwaysOff", | 
|  | 1216 | "AlwaysOff"}, | 
|  | 1217 | {"xyz.openbmc_project.Control.Power.RestorePolicy.Policy." | 
| Gunnar Mills | 37ec907 | 2021-01-05 19:43:44 -0600 | [diff] [blame] | 1218 | "Restore", | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1219 | "LastState"}}; | 
|  | 1220 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1221 | const std::string* policyPtr = std::get_if<std::string>(&policy); | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1222 |  | 
|  | 1223 | if (!policyPtr) | 
|  | 1224 | { | 
|  | 1225 | messages::internalError(aResp->res); | 
|  | 1226 | return; | 
|  | 1227 | } | 
|  | 1228 |  | 
|  | 1229 | auto policyMapsIt = policyMaps.find(*policyPtr); | 
|  | 1230 | if (policyMapsIt == policyMaps.end()) | 
|  | 1231 | { | 
|  | 1232 | messages::internalError(aResp->res); | 
|  | 1233 | return; | 
|  | 1234 | } | 
|  | 1235 |  | 
|  | 1236 | aResp->res.jsonValue["PowerRestorePolicy"] = policyMapsIt->second; | 
|  | 1237 | }, | 
|  | 1238 | "xyz.openbmc_project.Settings", | 
|  | 1239 | "/xyz/openbmc_project/control/host0/power_restore_policy", | 
|  | 1240 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1241 | "xyz.openbmc_project.Control.Power.RestorePolicy", | 
|  | 1242 | "PowerRestorePolicy"); | 
|  | 1243 | } | 
|  | 1244 |  | 
|  | 1245 | /** | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1246 | * @brief Sets boot properties into DBUS object(s). | 
|  | 1247 | * | 
|  | 1248 | * @param[in] aResp           Shared pointer for generating response message. | 
|  | 1249 | * @param[in] oneTimeEnabled  Is "one-time" setting already enabled. | 
|  | 1250 | * @param[in] bootSource      The boot source to set. | 
|  | 1251 | * @param[in] bootEnable      The source override "enable" to set. | 
|  | 1252 | * | 
| Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1253 | * @return Integer error code. | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1254 | */ | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1255 | inline void setBootModeOrSource(std::shared_ptr<AsyncResp> aResp, | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1256 | bool oneTimeEnabled, | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1257 | const std::optional<std::string>& bootSource, | 
|  | 1258 | const std::optional<std::string>& bootEnable) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1259 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1260 | std::string bootSourceStr = | 
|  | 1261 | "xyz.openbmc_project.Control.Boot.Source.Sources.Default"; | 
|  | 1262 | std::string bootModeStr = | 
|  | 1263 | "xyz.openbmc_project.Control.Boot.Mode.Modes.Regular"; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1264 | bool oneTimeSetting = oneTimeEnabled; | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1265 | bool useBootSource = true; | 
|  | 1266 |  | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1267 | // Validate incoming parameters | 
|  | 1268 | if (bootEnable) | 
|  | 1269 | { | 
|  | 1270 | if (*bootEnable == "Once") | 
|  | 1271 | { | 
|  | 1272 | oneTimeSetting = true; | 
|  | 1273 | } | 
|  | 1274 | else if (*bootEnable == "Continuous") | 
|  | 1275 | { | 
|  | 1276 | oneTimeSetting = false; | 
|  | 1277 | } | 
|  | 1278 | else if (*bootEnable == "Disabled") | 
|  | 1279 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1280 | BMCWEB_LOG_DEBUG << "Boot source override will be disabled"; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1281 | oneTimeSetting = false; | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1282 | useBootSource = false; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1283 | } | 
|  | 1284 | else | 
|  | 1285 | { | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1286 | BMCWEB_LOG_DEBUG << "Unsupported value for " | 
|  | 1287 | "BootSourceOverrideEnabled: " | 
|  | 1288 | << *bootEnable; | 
|  | 1289 | messages::propertyValueNotInList(aResp->res, *bootEnable, | 
|  | 1290 | "BootSourceOverrideEnabled"); | 
|  | 1291 | return; | 
|  | 1292 | } | 
|  | 1293 | } | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1294 |  | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1295 | if (bootSource && useBootSource) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1296 | { | 
|  | 1297 | // Source target specified | 
|  | 1298 | BMCWEB_LOG_DEBUG << "Boot source: " << *bootSource; | 
|  | 1299 | // Figure out which DBUS interface and property to use | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1300 | if (assignBootParameters(aResp, *bootSource, bootSourceStr, | 
|  | 1301 | bootModeStr)) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1302 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1303 | BMCWEB_LOG_DEBUG | 
|  | 1304 | << "Invalid property value for BootSourceOverrideTarget: " | 
|  | 1305 | << *bootSource; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1306 | messages::propertyValueNotInList(aResp->res, *bootSource, | 
|  | 1307 | "BootSourceTargetOverride"); | 
|  | 1308 | return; | 
|  | 1309 | } | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1310 | } | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1311 |  | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1312 | // Act on validated parameters | 
|  | 1313 | BMCWEB_LOG_DEBUG << "DBUS boot source: " << bootSourceStr; | 
|  | 1314 | BMCWEB_LOG_DEBUG << "DBUS boot mode: " << bootModeStr; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1315 | const char* bootObj = | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1316 | oneTimeSetting ? "/xyz/openbmc_project/control/host0/boot/one_time" | 
|  | 1317 | : "/xyz/openbmc_project/control/host0/boot"; | 
|  | 1318 |  | 
|  | 1319 | crow::connections::systemBus->async_method_call( | 
|  | 1320 | [aResp](const boost::system::error_code ec) { | 
|  | 1321 | if (ec) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1322 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1323 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1324 | messages::internalError(aResp->res); | 
|  | 1325 | return; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1326 | } | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1327 | BMCWEB_LOG_DEBUG << "Boot source update done."; | 
|  | 1328 | }, | 
|  | 1329 | "xyz.openbmc_project.Settings", bootObj, | 
|  | 1330 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 1331 | "xyz.openbmc_project.Control.Boot.Source", "BootSource", | 
|  | 1332 | std::variant<std::string>(bootSourceStr)); | 
|  | 1333 |  | 
|  | 1334 | crow::connections::systemBus->async_method_call( | 
|  | 1335 | [aResp](const boost::system::error_code ec) { | 
|  | 1336 | if (ec) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1337 | { | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1338 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1339 | messages::internalError(aResp->res); | 
|  | 1340 | return; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1341 | } | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 1342 | BMCWEB_LOG_DEBUG << "Boot mode update done."; | 
|  | 1343 | }, | 
|  | 1344 | "xyz.openbmc_project.Settings", bootObj, | 
|  | 1345 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 1346 | "xyz.openbmc_project.Control.Boot.Mode", "BootMode", | 
|  | 1347 | std::variant<std::string>(bootModeStr)); | 
|  | 1348 |  | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1349 | crow::connections::systemBus->async_method_call( | 
|  | 1350 | [aResp{std::move(aResp)}](const boost::system::error_code ec) { | 
|  | 1351 | if (ec) | 
|  | 1352 | { | 
|  | 1353 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1354 | messages::internalError(aResp->res); | 
|  | 1355 | return; | 
|  | 1356 | } | 
|  | 1357 | BMCWEB_LOG_DEBUG << "Boot enable update done."; | 
|  | 1358 | }, | 
|  | 1359 | "xyz.openbmc_project.Settings", | 
|  | 1360 | "/xyz/openbmc_project/control/host0/boot/one_time", | 
|  | 1361 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 1362 | "xyz.openbmc_project.Object.Enable", "Enabled", | 
|  | 1363 | std::variant<bool>(oneTimeSetting)); | 
|  | 1364 | } | 
|  | 1365 |  | 
|  | 1366 | /** | 
|  | 1367 | * @brief Retrieves "One time" enabled setting over DBUS and calls function to | 
|  | 1368 | * set boot source/boot mode properties. | 
|  | 1369 | * | 
|  | 1370 | * @param[in] aResp      Shared pointer for generating response message. | 
|  | 1371 | * @param[in] bootSource The boot source from incoming RF request. | 
|  | 1372 | * @param[in] bootEnable The boot override enable from incoming RF request. | 
|  | 1373 | * | 
| Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1374 | * @return Integer error code. | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1375 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1376 | inline void setBootSourceProperties(const std::shared_ptr<AsyncResp>& aResp, | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1377 | std::optional<std::string> bootSource, | 
|  | 1378 | std::optional<std::string> bootEnable) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1379 | { | 
|  | 1380 | BMCWEB_LOG_DEBUG << "Set boot information."; | 
|  | 1381 |  | 
|  | 1382 | crow::connections::systemBus->async_method_call( | 
| Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 1383 | [aResp, bootSource{std::move(bootSource)}, | 
| Patrick Williams | 19bd78d | 2020-05-13 17:38:24 -0500 | [diff] [blame] | 1384 | bootEnable{std::move(bootEnable)}](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1385 | const std::variant<bool>& oneTime) { | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1386 | if (ec) | 
|  | 1387 | { | 
|  | 1388 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1389 | messages::internalError(aResp->res); | 
|  | 1390 | return; | 
|  | 1391 | } | 
|  | 1392 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1393 | const bool* oneTimePtr = std::get_if<bool>(&oneTime); | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1394 |  | 
|  | 1395 | if (!oneTimePtr) | 
|  | 1396 | { | 
|  | 1397 | messages::internalError(aResp->res); | 
|  | 1398 | return; | 
|  | 1399 | } | 
|  | 1400 |  | 
|  | 1401 | BMCWEB_LOG_DEBUG << "Got one time: " << *oneTimePtr; | 
|  | 1402 |  | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1403 | setBootModeOrSource(aResp, *oneTimePtr, bootSource, bootEnable); | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1404 | }, | 
|  | 1405 | "xyz.openbmc_project.Settings", | 
|  | 1406 | "/xyz/openbmc_project/control/host0/boot/one_time", | 
|  | 1407 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1408 | "xyz.openbmc_project.Object.Enable", "Enabled"); | 
|  | 1409 | } | 
|  | 1410 |  | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1411 | /** | 
| Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 1412 | * @brief Sets AssetTag | 
|  | 1413 | * | 
|  | 1414 | * @param[in] aResp   Shared pointer for generating response message. | 
|  | 1415 | * @param[in] assetTag  "AssetTag" from request. | 
|  | 1416 | * | 
|  | 1417 | * @return None. | 
|  | 1418 | */ | 
|  | 1419 | inline void setAssetTag(const std::shared_ptr<AsyncResp>& aResp, | 
|  | 1420 | const std::string& assetTag) | 
|  | 1421 | { | 
|  | 1422 | crow::connections::systemBus->async_method_call( | 
|  | 1423 | [aResp, assetTag]( | 
|  | 1424 | const boost::system::error_code ec, | 
|  | 1425 | const std::vector<std::pair< | 
|  | 1426 | std::string, | 
|  | 1427 | std::vector<std::pair<std::string, std::vector<std::string>>>>>& | 
|  | 1428 | subtree) { | 
|  | 1429 | if (ec) | 
|  | 1430 | { | 
|  | 1431 | BMCWEB_LOG_DEBUG << "D-Bus response error on GetSubTree " << ec; | 
|  | 1432 | messages::internalError(aResp->res); | 
|  | 1433 | return; | 
|  | 1434 | } | 
|  | 1435 | if (subtree.size() == 0) | 
|  | 1436 | { | 
|  | 1437 | BMCWEB_LOG_DEBUG << "Can't find system D-Bus object!"; | 
|  | 1438 | messages::internalError(aResp->res); | 
|  | 1439 | return; | 
|  | 1440 | } | 
|  | 1441 | // Assume only 1 system D-Bus object | 
|  | 1442 | // Throw an error if there is more than 1 | 
|  | 1443 | if (subtree.size() > 1) | 
|  | 1444 | { | 
|  | 1445 | BMCWEB_LOG_DEBUG << "Found more than 1 system D-Bus object!"; | 
|  | 1446 | messages::internalError(aResp->res); | 
|  | 1447 | return; | 
|  | 1448 | } | 
|  | 1449 | if (subtree[0].first.empty() || subtree[0].second.size() != 1) | 
|  | 1450 | { | 
|  | 1451 | BMCWEB_LOG_DEBUG << "Asset Tag Set mapper error!"; | 
|  | 1452 | messages::internalError(aResp->res); | 
|  | 1453 | return; | 
|  | 1454 | } | 
|  | 1455 |  | 
|  | 1456 | const std::string& path = subtree[0].first; | 
|  | 1457 | const std::string& service = subtree[0].second.begin()->first; | 
|  | 1458 |  | 
|  | 1459 | if (service.empty()) | 
|  | 1460 | { | 
|  | 1461 | BMCWEB_LOG_DEBUG << "Asset Tag Set service mapper error!"; | 
|  | 1462 | messages::internalError(aResp->res); | 
|  | 1463 | return; | 
|  | 1464 | } | 
|  | 1465 |  | 
|  | 1466 | crow::connections::systemBus->async_method_call( | 
|  | 1467 | [aResp](const boost::system::error_code ec2) { | 
|  | 1468 | if (ec2) | 
|  | 1469 | { | 
|  | 1470 | BMCWEB_LOG_DEBUG | 
|  | 1471 | << "D-Bus response error on AssetTag Set " << ec2; | 
|  | 1472 | messages::internalError(aResp->res); | 
|  | 1473 | return; | 
|  | 1474 | } | 
|  | 1475 | }, | 
|  | 1476 | service, path, "org.freedesktop.DBus.Properties", "Set", | 
|  | 1477 | "xyz.openbmc_project.Inventory.Decorator.AssetTag", "AssetTag", | 
|  | 1478 | std::variant<std::string>(assetTag)); | 
|  | 1479 | }, | 
|  | 1480 | "xyz.openbmc_project.ObjectMapper", | 
|  | 1481 | "/xyz/openbmc_project/object_mapper", | 
|  | 1482 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", | 
|  | 1483 | "/xyz/openbmc_project/inventory", int32_t(0), | 
|  | 1484 | std::array<const char*, 1>{ | 
|  | 1485 | "xyz.openbmc_project.Inventory.Item.System"}); | 
|  | 1486 | } | 
|  | 1487 |  | 
|  | 1488 | /** | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1489 | * @brief Sets automaticRetry (Auto Reboot) | 
|  | 1490 | * | 
|  | 1491 | * @param[in] aResp   Shared pointer for generating response message. | 
|  | 1492 | * @param[in] automaticRetryConfig  "AutomaticRetryConfig" from request. | 
|  | 1493 | * | 
|  | 1494 | * @return None. | 
|  | 1495 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1496 | inline void setAutomaticRetry(const std::shared_ptr<AsyncResp>& aResp, | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 1497 | const std::string& automaticRetryConfig) | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 1498 | { | 
|  | 1499 | BMCWEB_LOG_DEBUG << "Set Automatic Retry."; | 
|  | 1500 |  | 
|  | 1501 | // OpenBMC only supports "Disabled" and "RetryAttempts". | 
|  | 1502 | bool autoRebootEnabled; | 
|  | 1503 |  | 
|  | 1504 | if (automaticRetryConfig == "Disabled") | 
|  | 1505 | { | 
|  | 1506 | autoRebootEnabled = false; | 
|  | 1507 | } | 
|  | 1508 | else if (automaticRetryConfig == "RetryAttempts") | 
|  | 1509 | { | 
|  | 1510 | autoRebootEnabled = true; | 
|  | 1511 | } | 
|  | 1512 | else | 
|  | 1513 | { | 
|  | 1514 | BMCWEB_LOG_DEBUG << "Invalid property value for " | 
|  | 1515 | "AutomaticRetryConfig: " | 
|  | 1516 | << automaticRetryConfig; | 
|  | 1517 | messages::propertyValueNotInList(aResp->res, automaticRetryConfig, | 
|  | 1518 | "AutomaticRetryConfig"); | 
|  | 1519 | return; | 
|  | 1520 | } | 
|  | 1521 |  | 
|  | 1522 | crow::connections::systemBus->async_method_call( | 
|  | 1523 | [aResp](const boost::system::error_code ec) { | 
|  | 1524 | if (ec) | 
|  | 1525 | { | 
|  | 1526 | messages::internalError(aResp->res); | 
|  | 1527 | return; | 
|  | 1528 | } | 
|  | 1529 | }, | 
|  | 1530 | "xyz.openbmc_project.Settings", | 
|  | 1531 | "/xyz/openbmc_project/control/host0/auto_reboot", | 
|  | 1532 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 1533 | "xyz.openbmc_project.Control.Boot.RebootPolicy", "AutoReboot", | 
|  | 1534 | std::variant<bool>(autoRebootEnabled)); | 
|  | 1535 | } | 
|  | 1536 |  | 
|  | 1537 | /** | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1538 | * @brief Sets power restore policy properties. | 
|  | 1539 | * | 
|  | 1540 | * @param[in] aResp   Shared pointer for generating response message. | 
|  | 1541 | * @param[in] policy  power restore policy properties from request. | 
|  | 1542 | * | 
|  | 1543 | * @return None. | 
|  | 1544 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1545 | inline void setPowerRestorePolicy(const std::shared_ptr<AsyncResp>& aResp, | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1546 | std::optional<std::string> policy) | 
|  | 1547 | { | 
|  | 1548 | BMCWEB_LOG_DEBUG << "Set power restore policy."; | 
|  | 1549 |  | 
|  | 1550 | const boost::container::flat_map<std::string, std::string> policyMaps = { | 
|  | 1551 | {"AlwaysOn", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." | 
|  | 1552 | "AlwaysOn"}, | 
|  | 1553 | {"AlwaysOff", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." | 
|  | 1554 | "AlwaysOff"}, | 
|  | 1555 | {"LastState", "xyz.openbmc_project.Control.Power.RestorePolicy.Policy." | 
| Gunnar Mills | 37ec907 | 2021-01-05 19:43:44 -0600 | [diff] [blame] | 1556 | "Restore"}}; | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 1557 |  | 
|  | 1558 | std::string powerRestorPolicy; | 
|  | 1559 |  | 
|  | 1560 | auto policyMapsIt = policyMaps.find(*policy); | 
|  | 1561 | if (policyMapsIt == policyMaps.end()) | 
|  | 1562 | { | 
|  | 1563 | messages::internalError(aResp->res); | 
|  | 1564 | return; | 
|  | 1565 | } | 
|  | 1566 |  | 
|  | 1567 | powerRestorPolicy = policyMapsIt->second; | 
|  | 1568 |  | 
|  | 1569 | crow::connections::systemBus->async_method_call( | 
|  | 1570 | [aResp](const boost::system::error_code ec) { | 
|  | 1571 | if (ec) | 
|  | 1572 | { | 
|  | 1573 | messages::internalError(aResp->res); | 
|  | 1574 | return; | 
|  | 1575 | } | 
|  | 1576 | }, | 
|  | 1577 | "xyz.openbmc_project.Settings", | 
|  | 1578 | "/xyz/openbmc_project/control/host0/power_restore_policy", | 
|  | 1579 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 1580 | "xyz.openbmc_project.Control.Power.RestorePolicy", "PowerRestorePolicy", | 
|  | 1581 | std::variant<std::string>(powerRestorPolicy)); | 
|  | 1582 | } | 
|  | 1583 |  | 
| AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1584 | #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE | 
|  | 1585 | /** | 
|  | 1586 | * @brief Retrieves provisioning status | 
|  | 1587 | * | 
|  | 1588 | * @param[in] aResp     Shared pointer for completing asynchronous calls. | 
|  | 1589 | * | 
|  | 1590 | * @return None. | 
|  | 1591 | */ | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1592 | inline void getProvisioningStatus(std::shared_ptr<AsyncResp> aResp) | 
| AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1593 | { | 
|  | 1594 | BMCWEB_LOG_DEBUG << "Get OEM information."; | 
|  | 1595 | crow::connections::systemBus->async_method_call( | 
|  | 1596 | [aResp](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1597 | const std::vector<std::pair<std::string, VariantType>>& | 
|  | 1598 | propertiesList) { | 
| AppaRao Puli | b99fb1a | 2020-07-08 16:42:48 +0530 | [diff] [blame] | 1599 | nlohmann::json& oemPFR = | 
|  | 1600 | aResp->res.jsonValue["Oem"]["OpenBmc"]["FirmwareProvisioning"]; | 
| James Feist | 50626f4 | 2020-09-23 14:40:47 -0700 | [diff] [blame] | 1601 | aResp->res.jsonValue["Oem"]["OpenBmc"]["@odata.type"] = | 
|  | 1602 | "#OemComputerSystem.OpenBmc"; | 
|  | 1603 | oemPFR["@odata.type"] = "#OemComputerSystem.FirmwareProvisioning"; | 
|  | 1604 |  | 
| AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1605 | if (ec) | 
|  | 1606 | { | 
|  | 1607 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
| AppaRao Puli | b99fb1a | 2020-07-08 16:42:48 +0530 | [diff] [blame] | 1608 | // not an error, don't have to have the interface | 
|  | 1609 | oemPFR["ProvisioningStatus"] = "NotProvisioned"; | 
| AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1610 | return; | 
|  | 1611 | } | 
|  | 1612 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1613 | const bool* provState = nullptr; | 
|  | 1614 | const bool* lockState = nullptr; | 
|  | 1615 | for (const std::pair<std::string, VariantType>& property : | 
| AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1616 | propertiesList) | 
|  | 1617 | { | 
|  | 1618 | if (property.first == "UfmProvisioned") | 
|  | 1619 | { | 
|  | 1620 | provState = std::get_if<bool>(&property.second); | 
|  | 1621 | } | 
|  | 1622 | else if (property.first == "UfmLocked") | 
|  | 1623 | { | 
|  | 1624 | lockState = std::get_if<bool>(&property.second); | 
|  | 1625 | } | 
|  | 1626 | } | 
|  | 1627 |  | 
|  | 1628 | if ((provState == nullptr) || (lockState == nullptr)) | 
|  | 1629 | { | 
|  | 1630 | BMCWEB_LOG_DEBUG << "Unable to get PFR attributes."; | 
|  | 1631 | messages::internalError(aResp->res); | 
|  | 1632 | return; | 
|  | 1633 | } | 
|  | 1634 |  | 
| AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 1635 | if (*provState == true) | 
|  | 1636 | { | 
|  | 1637 | if (*lockState == true) | 
|  | 1638 | { | 
|  | 1639 | oemPFR["ProvisioningStatus"] = "ProvisionedAndLocked"; | 
|  | 1640 | } | 
|  | 1641 | else | 
|  | 1642 | { | 
|  | 1643 | oemPFR["ProvisioningStatus"] = "ProvisionedButNotLocked"; | 
|  | 1644 | } | 
|  | 1645 | } | 
|  | 1646 | else | 
|  | 1647 | { | 
|  | 1648 | oemPFR["ProvisioningStatus"] = "NotProvisioned"; | 
|  | 1649 | } | 
|  | 1650 | }, | 
|  | 1651 | "xyz.openbmc_project.PFR.Manager", "/xyz/openbmc_project/pfr", | 
|  | 1652 | "org.freedesktop.DBus.Properties", "GetAll", | 
|  | 1653 | "xyz.openbmc_project.PFR.Attributes"); | 
|  | 1654 | } | 
|  | 1655 | #endif | 
|  | 1656 |  | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 1657 | /** | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1658 | * @brief Translates watchdog timeout action DBUS property value to redfish. | 
|  | 1659 | * | 
|  | 1660 | * @param[in] dbusAction    The watchdog timeout action in D-BUS. | 
|  | 1661 | * | 
|  | 1662 | * @return Returns as a string, the timeout action in Redfish terms. If | 
|  | 1663 | * translation cannot be done, returns an empty string. | 
|  | 1664 | */ | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1665 | inline std::string dbusToRfWatchdogAction(const std::string& dbusAction) | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1666 | { | 
|  | 1667 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.None") | 
|  | 1668 | { | 
|  | 1669 | return "None"; | 
|  | 1670 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1671 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.HardReset") | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1672 | { | 
|  | 1673 | return "ResetSystem"; | 
|  | 1674 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1675 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerOff") | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1676 | { | 
|  | 1677 | return "PowerDown"; | 
|  | 1678 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1679 | if (dbusAction == "xyz.openbmc_project.State.Watchdog.Action.PowerCycle") | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1680 | { | 
|  | 1681 | return "PowerCycle"; | 
|  | 1682 | } | 
|  | 1683 |  | 
|  | 1684 | return ""; | 
|  | 1685 | } | 
|  | 1686 |  | 
|  | 1687 | /** | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1688 | *@brief Translates timeout action from Redfish to DBUS property value. | 
|  | 1689 | * | 
|  | 1690 | *@param[in] rfAction The timeout action in Redfish. | 
|  | 1691 | * | 
|  | 1692 | *@return Returns as a string, the time_out action as expected by DBUS. | 
|  | 1693 | *If translation cannot be done, returns an empty string. | 
|  | 1694 | */ | 
|  | 1695 |  | 
| Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 1696 | inline std::string rfToDbusWDTTimeOutAct(const std::string& rfAction) | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1697 | { | 
|  | 1698 | if (rfAction == "None") | 
|  | 1699 | { | 
|  | 1700 | return "xyz.openbmc_project.State.Watchdog.Action.None"; | 
|  | 1701 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1702 | if (rfAction == "PowerCycle") | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1703 | { | 
|  | 1704 | return "xyz.openbmc_project.State.Watchdog.Action.PowerCycle"; | 
|  | 1705 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1706 | if (rfAction == "PowerDown") | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1707 | { | 
|  | 1708 | return "xyz.openbmc_project.State.Watchdog.Action.PowerOff"; | 
|  | 1709 | } | 
| Ed Tanous | 3174e4d | 2020-10-07 11:41:22 -0700 | [diff] [blame] | 1710 | if (rfAction == "ResetSystem") | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1711 | { | 
|  | 1712 | return "xyz.openbmc_project.State.Watchdog.Action.HardReset"; | 
|  | 1713 | } | 
|  | 1714 |  | 
|  | 1715 | return ""; | 
|  | 1716 | } | 
|  | 1717 |  | 
|  | 1718 | /** | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1719 | * @brief Retrieves host watchdog timer properties over DBUS | 
|  | 1720 | * | 
|  | 1721 | * @param[in] aResp     Shared pointer for completing asynchronous calls. | 
|  | 1722 | * | 
|  | 1723 | * @return None. | 
|  | 1724 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1725 | inline void getHostWatchdogTimer(const std::shared_ptr<AsyncResp>& aResp) | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1726 | { | 
|  | 1727 | BMCWEB_LOG_DEBUG << "Get host watchodg"; | 
|  | 1728 | crow::connections::systemBus->async_method_call( | 
|  | 1729 | [aResp](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1730 | PropertiesType& properties) { | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1731 | if (ec) | 
|  | 1732 | { | 
|  | 1733 | // watchdog service is stopped | 
|  | 1734 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1735 | return; | 
|  | 1736 | } | 
|  | 1737 |  | 
|  | 1738 | BMCWEB_LOG_DEBUG << "Got " << properties.size() << " wdt prop."; | 
|  | 1739 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1740 | nlohmann::json& hostWatchdogTimer = | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1741 | aResp->res.jsonValue["HostWatchdogTimer"]; | 
|  | 1742 |  | 
|  | 1743 | // watchdog service is running/enabled | 
|  | 1744 | hostWatchdogTimer["Status"]["State"] = "Enabled"; | 
|  | 1745 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1746 | for (const auto& property : properties) | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1747 | { | 
|  | 1748 | BMCWEB_LOG_DEBUG << "prop=" << property.first; | 
|  | 1749 | if (property.first == "Enabled") | 
|  | 1750 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1751 | const bool* state = std::get_if<bool>(&property.second); | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1752 |  | 
|  | 1753 | if (!state) | 
|  | 1754 | { | 
|  | 1755 | messages::internalError(aResp->res); | 
|  | 1756 | continue; | 
|  | 1757 | } | 
|  | 1758 |  | 
|  | 1759 | hostWatchdogTimer["FunctionEnabled"] = *state; | 
|  | 1760 | } | 
|  | 1761 | else if (property.first == "ExpireAction") | 
|  | 1762 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1763 | const std::string* s = | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 1764 | std::get_if<std::string>(&property.second); | 
|  | 1765 | if (!s) | 
|  | 1766 | { | 
|  | 1767 | messages::internalError(aResp->res); | 
|  | 1768 | continue; | 
|  | 1769 | } | 
|  | 1770 |  | 
|  | 1771 | std::string action = dbusToRfWatchdogAction(*s); | 
|  | 1772 | if (action.empty()) | 
|  | 1773 | { | 
|  | 1774 | messages::internalError(aResp->res); | 
|  | 1775 | continue; | 
|  | 1776 | } | 
|  | 1777 | hostWatchdogTimer["TimeoutAction"] = action; | 
|  | 1778 | } | 
|  | 1779 | } | 
|  | 1780 | }, | 
|  | 1781 | "xyz.openbmc_project.Watchdog", "/xyz/openbmc_project/watchdog/host0", | 
|  | 1782 | "org.freedesktop.DBus.Properties", "GetAll", | 
|  | 1783 | "xyz.openbmc_project.State.Watchdog"); | 
|  | 1784 | } | 
|  | 1785 |  | 
|  | 1786 | /** | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1787 | * @brief Sets Host WatchDog Timer properties. | 
|  | 1788 | * | 
|  | 1789 | * @param[in] aResp      Shared pointer for generating response message. | 
|  | 1790 | * @param[in] wdtEnable  The WDTimer Enable value (true/false) from incoming | 
|  | 1791 | *                       RF request. | 
|  | 1792 | * @param[in] wdtTimeOutAction The WDT Timeout action, from incoming RF request. | 
|  | 1793 | * | 
|  | 1794 | * @return None. | 
|  | 1795 | */ | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 1796 | inline void setWDTProperties(const std::shared_ptr<AsyncResp>& aResp, | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1797 | const std::optional<bool> wdtEnable, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1798 | const std::optional<std::string>& wdtTimeOutAction) | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 1799 | { | 
|  | 1800 | BMCWEB_LOG_DEBUG << "Set host watchdog"; | 
|  | 1801 |  | 
|  | 1802 | if (wdtTimeOutAction) | 
|  | 1803 | { | 
|  | 1804 | std::string wdtTimeOutActStr = rfToDbusWDTTimeOutAct(*wdtTimeOutAction); | 
|  | 1805 | // check if TimeOut Action is Valid | 
|  | 1806 | if (wdtTimeOutActStr.empty()) | 
|  | 1807 | { | 
|  | 1808 | BMCWEB_LOG_DEBUG << "Unsupported value for TimeoutAction: " | 
|  | 1809 | << *wdtTimeOutAction; | 
|  | 1810 | messages::propertyValueNotInList(aResp->res, *wdtTimeOutAction, | 
|  | 1811 | "TimeoutAction"); | 
|  | 1812 | return; | 
|  | 1813 | } | 
|  | 1814 |  | 
|  | 1815 | crow::connections::systemBus->async_method_call( | 
|  | 1816 | [aResp](const boost::system::error_code ec) { | 
|  | 1817 | if (ec) | 
|  | 1818 | { | 
|  | 1819 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1820 | messages::internalError(aResp->res); | 
|  | 1821 | return; | 
|  | 1822 | } | 
|  | 1823 | }, | 
|  | 1824 | "xyz.openbmc_project.Watchdog", | 
|  | 1825 | "/xyz/openbmc_project/watchdog/host0", | 
|  | 1826 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 1827 | "xyz.openbmc_project.State.Watchdog", "ExpireAction", | 
|  | 1828 | std::variant<std::string>(wdtTimeOutActStr)); | 
|  | 1829 | } | 
|  | 1830 |  | 
|  | 1831 | if (wdtEnable) | 
|  | 1832 | { | 
|  | 1833 | crow::connections::systemBus->async_method_call( | 
|  | 1834 | [aResp](const boost::system::error_code ec) { | 
|  | 1835 | if (ec) | 
|  | 1836 | { | 
|  | 1837 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; | 
|  | 1838 | messages::internalError(aResp->res); | 
|  | 1839 | return; | 
|  | 1840 | } | 
|  | 1841 | }, | 
|  | 1842 | "xyz.openbmc_project.Watchdog", | 
|  | 1843 | "/xyz/openbmc_project/watchdog/host0", | 
|  | 1844 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 1845 | "xyz.openbmc_project.State.Watchdog", "Enabled", | 
|  | 1846 | std::variant<bool>(*wdtEnable)); | 
|  | 1847 | } | 
|  | 1848 | } | 
|  | 1849 |  | 
|  | 1850 | /** | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1851 | * SystemsCollection derived class for delivering ComputerSystems Collection | 
|  | 1852 | * Schema | 
|  | 1853 | */ | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1854 | class SystemsCollection : public Node | 
|  | 1855 | { | 
|  | 1856 | public: | 
| Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1857 | SystemsCollection(App& app) : Node(app, "/redfish/v1/Systems/") | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1858 | { | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1859 | entityPrivileges = { | 
|  | 1860 | {boost::beast::http::verb::get, {{"Login"}}}, | 
|  | 1861 | {boost::beast::http::verb::head, {{"Login"}}}, | 
|  | 1862 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, | 
|  | 1863 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, | 
|  | 1864 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, | 
|  | 1865 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; | 
|  | 1866 | } | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1867 |  | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1868 | private: | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1869 | void doGet(crow::Response& res, const crow::Request&, | 
|  | 1870 | const std::vector<std::string>&) override | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1871 | { | 
| Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1872 | std::shared_ptr<AsyncResp> asyncResp = std::make_shared<AsyncResp>(res); | 
| Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1873 | res.jsonValue["@odata.type"] = | 
|  | 1874 | "#ComputerSystemCollection.ComputerSystemCollection"; | 
|  | 1875 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems"; | 
| Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 1876 | res.jsonValue["Name"] = "Computer System Collection"; | 
| Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1877 |  | 
|  | 1878 | crow::connections::systemBus->async_method_call( | 
|  | 1879 | [asyncResp](const boost::system::error_code ec, | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1880 | const std::variant<std::string>& /*hostName*/) { | 
| Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1881 | nlohmann::json& ifaceArray = | 
| Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1882 | asyncResp->res.jsonValue["Members"]; | 
| Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1883 | ifaceArray = nlohmann::json::array(); | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1884 | auto& count = asyncResp->res.jsonValue["Members@odata.count"]; | 
| Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1885 | ifaceArray.push_back( | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1886 | {{"@odata.id", "/redfish/v1/Systems/system"}}); | 
| Tim Lee | 94bda60 | 2020-11-19 14:14:27 +0800 | [diff] [blame] | 1887 | count = ifaceArray.size(); | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1888 | if (!ec) | 
| Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1889 | { | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1890 | BMCWEB_LOG_DEBUG << "Hypervisor is available"; | 
| Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1891 | ifaceArray.push_back( | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1892 | {{"@odata.id", "/redfish/v1/Systems/hypervisor"}}); | 
| Ed Tanous | 2c70f80 | 2020-09-28 14:29:23 -0700 | [diff] [blame] | 1893 | count = ifaceArray.size(); | 
| Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1894 | return; | 
|  | 1895 | } | 
| Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1896 | }, | 
| Sunitha Harish | 8e651fb | 2020-06-17 06:06:25 -0500 | [diff] [blame] | 1897 | "xyz.openbmc_project.Settings", | 
|  | 1898 | "/xyz/openbmc_project/network/hypervisor", | 
| Sunitha Harish | 462023a | 2020-02-19 08:34:59 -0600 | [diff] [blame] | 1899 | "org.freedesktop.DBus.Properties", "Get", | 
|  | 1900 | "xyz.openbmc_project.Network.SystemConfiguration", "HostName"); | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 1901 | } | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 1902 | }; | 
|  | 1903 |  | 
|  | 1904 | /** | 
| Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1905 | * SystemActionsReset class supports handle POST method for Reset action. | 
|  | 1906 | * The class retrieves and sends data directly to D-Bus. | 
|  | 1907 | */ | 
|  | 1908 | class SystemActionsReset : public Node | 
|  | 1909 | { | 
|  | 1910 | public: | 
| Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 1911 | SystemActionsReset(App& app) : | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 1912 | Node(app, "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset/") | 
| Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1913 | { | 
|  | 1914 | entityPrivileges = { | 
|  | 1915 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; | 
|  | 1916 | } | 
|  | 1917 |  | 
|  | 1918 | private: | 
|  | 1919 | /** | 
|  | 1920 | * Function handles POST method request. | 
|  | 1921 | * Analyzes POST body message before sends Reset request data to D-Bus. | 
|  | 1922 | */ | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 1923 | void doPost(crow::Response& res, const crow::Request& req, | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 1924 | const std::vector<std::string>&) override | 
| Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1925 | { | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1926 | auto asyncResp = std::make_shared<AsyncResp>(res); | 
|  | 1927 |  | 
|  | 1928 | std::string resetType; | 
|  | 1929 | if (!json_util::readJson(req, res, "ResetType", resetType)) | 
| Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 1930 | { | 
|  | 1931 | return; | 
|  | 1932 | } | 
|  | 1933 |  | 
| Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1934 | // Get the command and host vs. chassis | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1935 | std::string command; | 
| Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1936 | bool hostCommand; | 
| Ed Tanous | d4d2579 | 2020-09-29 15:15:03 -0700 | [diff] [blame] | 1937 | if ((resetType == "On") || (resetType == "ForceOn")) | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1938 | { | 
|  | 1939 | command = "xyz.openbmc_project.State.Host.Transition.On"; | 
| Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1940 | hostCommand = true; | 
|  | 1941 | } | 
|  | 1942 | else if (resetType == "ForceOff") | 
|  | 1943 | { | 
|  | 1944 | command = "xyz.openbmc_project.State.Chassis.Transition.Off"; | 
|  | 1945 | hostCommand = false; | 
|  | 1946 | } | 
| Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1947 | else if (resetType == "ForceRestart") | 
|  | 1948 | { | 
| Jason M. Bills | 86a0851 | 2020-02-04 13:15:49 -0800 | [diff] [blame] | 1949 | command = | 
|  | 1950 | "xyz.openbmc_project.State.Host.Transition.ForceWarmReboot"; | 
|  | 1951 | hostCommand = true; | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1952 | } | 
|  | 1953 | else if (resetType == "GracefulShutdown") | 
|  | 1954 | { | 
|  | 1955 | command = "xyz.openbmc_project.State.Host.Transition.Off"; | 
| Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1956 | hostCommand = true; | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1957 | } | 
|  | 1958 | else if (resetType == "GracefulRestart") | 
|  | 1959 | { | 
| Jason M. Bills | 86a0851 | 2020-02-04 13:15:49 -0800 | [diff] [blame] | 1960 | command = | 
|  | 1961 | "xyz.openbmc_project.State.Host.Transition.GracefulWarmReboot"; | 
| Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1962 | hostCommand = true; | 
|  | 1963 | } | 
|  | 1964 | else if (resetType == "PowerCycle") | 
|  | 1965 | { | 
| Jason M. Bills | 86a0851 | 2020-02-04 13:15:49 -0800 | [diff] [blame] | 1966 | command = "xyz.openbmc_project.State.Host.Transition.Reboot"; | 
|  | 1967 | hostCommand = true; | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1968 | } | 
| Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 1969 | else if (resetType == "Nmi") | 
|  | 1970 | { | 
|  | 1971 | doNMI(asyncResp); | 
|  | 1972 | return; | 
|  | 1973 | } | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1974 | else | 
|  | 1975 | { | 
| Jason M. Bills | f12894f | 2018-10-09 12:45:45 -0700 | [diff] [blame] | 1976 | messages::actionParameterUnknown(res, "Reset", resetType); | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 1977 | return; | 
|  | 1978 | } | 
|  | 1979 |  | 
| Jason M. Bills | d22c839 | 2019-06-03 13:59:03 -0700 | [diff] [blame] | 1980 | if (hostCommand) | 
|  | 1981 | { | 
|  | 1982 | crow::connections::systemBus->async_method_call( | 
|  | 1983 | [asyncResp, resetType](const boost::system::error_code ec) { | 
|  | 1984 | if (ec) | 
|  | 1985 | { | 
|  | 1986 | BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; | 
|  | 1987 | if (ec.value() == boost::asio::error::invalid_argument) | 
|  | 1988 | { | 
|  | 1989 | messages::actionParameterNotSupported( | 
|  | 1990 | asyncResp->res, resetType, "Reset"); | 
|  | 1991 | } | 
|  | 1992 | else | 
|  | 1993 | { | 
|  | 1994 | messages::internalError(asyncResp->res); | 
|  | 1995 | } | 
|  | 1996 | return; | 
|  | 1997 | } | 
|  | 1998 | messages::success(asyncResp->res); | 
|  | 1999 | }, | 
|  | 2000 | "xyz.openbmc_project.State.Host", | 
|  | 2001 | "/xyz/openbmc_project/state/host0", | 
|  | 2002 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 2003 | "xyz.openbmc_project.State.Host", "RequestedHostTransition", | 
|  | 2004 | std::variant<std::string>{command}); | 
|  | 2005 | } | 
|  | 2006 | else | 
|  | 2007 | { | 
|  | 2008 | crow::connections::systemBus->async_method_call( | 
|  | 2009 | [asyncResp, resetType](const boost::system::error_code ec) { | 
|  | 2010 | if (ec) | 
|  | 2011 | { | 
|  | 2012 | BMCWEB_LOG_ERROR << "D-Bus responses error: " << ec; | 
|  | 2013 | if (ec.value() == boost::asio::error::invalid_argument) | 
|  | 2014 | { | 
|  | 2015 | messages::actionParameterNotSupported( | 
|  | 2016 | asyncResp->res, resetType, "Reset"); | 
|  | 2017 | } | 
|  | 2018 | else | 
|  | 2019 | { | 
|  | 2020 | messages::internalError(asyncResp->res); | 
|  | 2021 | } | 
|  | 2022 | return; | 
|  | 2023 | } | 
|  | 2024 | messages::success(asyncResp->res); | 
|  | 2025 | }, | 
|  | 2026 | "xyz.openbmc_project.State.Chassis", | 
|  | 2027 | "/xyz/openbmc_project/state/chassis0", | 
|  | 2028 | "org.freedesktop.DBus.Properties", "Set", | 
|  | 2029 | "xyz.openbmc_project.State.Chassis", "RequestedPowerTransition", | 
|  | 2030 | std::variant<std::string>{command}); | 
|  | 2031 | } | 
| Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 2032 | } | 
| Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 2033 | /** | 
|  | 2034 | * Function transceives data with dbus directly. | 
|  | 2035 | */ | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2036 | void doNMI(const std::shared_ptr<AsyncResp>& asyncResp) | 
| Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 2037 | { | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2038 | constexpr char const* serviceName = | 
| Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 2039 | "xyz.openbmc_project.Control.Host.NMI"; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2040 | constexpr char const* objectPath = | 
| Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 2041 | "/xyz/openbmc_project/control/host0/nmi"; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2042 | constexpr char const* interfaceName = | 
| Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 2043 | "xyz.openbmc_project.Control.Host.NMI"; | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2044 | constexpr char const* method = "NMI"; | 
| Lakshminarayana R. Kammath | bfd5b82 | 2019-06-17 12:11:01 -0500 | [diff] [blame] | 2045 |  | 
|  | 2046 | crow::connections::systemBus->async_method_call( | 
|  | 2047 | [asyncResp](const boost::system::error_code ec) { | 
|  | 2048 | if (ec) | 
|  | 2049 | { | 
|  | 2050 | BMCWEB_LOG_ERROR << " Bad D-Bus request error: " << ec; | 
|  | 2051 | messages::internalError(asyncResp->res); | 
|  | 2052 | return; | 
|  | 2053 | } | 
|  | 2054 | messages::success(asyncResp->res); | 
|  | 2055 | }, | 
|  | 2056 | serviceName, objectPath, interfaceName, method); | 
|  | 2057 | } | 
| Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 2058 | }; | 
|  | 2059 |  | 
|  | 2060 | /** | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 2061 | * Systems derived class for delivering Computer Systems Schema. | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2062 | */ | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2063 | class Systems : public Node | 
|  | 2064 | { | 
|  | 2065 | public: | 
|  | 2066 | /* | 
|  | 2067 | * Default Constructor | 
|  | 2068 | */ | 
| Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 2069 | Systems(App& app) : Node(app, "/redfish/v1/Systems/system/") | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2070 | { | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2071 | entityPrivileges = { | 
|  | 2072 | {boost::beast::http::verb::get, {{"Login"}}}, | 
|  | 2073 | {boost::beast::http::verb::head, {{"Login"}}}, | 
|  | 2074 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, | 
|  | 2075 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, | 
|  | 2076 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, | 
|  | 2077 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2078 | } | 
|  | 2079 |  | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2080 | private: | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2081 | /** | 
|  | 2082 | * Functions triggers appropriate requests on DBus | 
|  | 2083 | */ | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 2084 | void doGet(crow::Response& res, const crow::Request&, | 
|  | 2085 | const std::vector<std::string>&) override | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2086 | { | 
| Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 2087 | res.jsonValue["@odata.type"] = "#ComputerSystem.v1_13_0.ComputerSystem"; | 
| Gunnar Mills | 450a25c | 2020-04-14 21:34:07 -0500 | [diff] [blame] | 2088 | res.jsonValue["Name"] = "system"; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 2089 | res.jsonValue["Id"] = "system"; | 
| Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 2090 | res.jsonValue["SystemType"] = "Physical"; | 
|  | 2091 | res.jsonValue["Description"] = "Computer System"; | 
| Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 2092 | res.jsonValue["ProcessorSummary"]["Count"] = 0; | 
|  | 2093 | res.jsonValue["ProcessorSummary"]["Status"]["State"] = "Disabled"; | 
| Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 2094 | res.jsonValue["MemorySummary"]["TotalSystemMemoryGiB"] = uint64_t(0); | 
| Ed Tanous | 0f74e64 | 2018-11-12 15:17:05 -0800 | [diff] [blame] | 2095 | res.jsonValue["MemorySummary"]["Status"]["State"] = "Disabled"; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 2096 | res.jsonValue["@odata.id"] = "/redfish/v1/Systems/system"; | 
| Ed Tanous | 04a258f | 2018-10-15 08:00:41 -0700 | [diff] [blame] | 2097 |  | 
| Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 2098 | res.jsonValue["Processors"] = { | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 2099 | {"@odata.id", "/redfish/v1/Systems/system/Processors"}}; | 
| Rapkiewicz, Pawel | 443c293 | 2018-10-22 15:08:49 +0200 | [diff] [blame] | 2100 | res.jsonValue["Memory"] = { | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 2101 | {"@odata.id", "/redfish/v1/Systems/system/Memory"}}; | 
| Nikhil Potade | a25aecc | 2019-08-23 16:35:26 -0700 | [diff] [blame] | 2102 | res.jsonValue["Storage"] = { | 
|  | 2103 | {"@odata.id", "/redfish/v1/Systems/system/Storage"}}; | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 2104 |  | 
| Ed Tanous | cc340dd | 2018-08-29 13:43:38 -0700 | [diff] [blame] | 2105 | res.jsonValue["Actions"]["#ComputerSystem.Reset"] = { | 
|  | 2106 | {"target", | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 2107 | "/redfish/v1/Systems/system/Actions/ComputerSystem.Reset"}, | 
| AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 2108 | {"@Redfish.ActionInfo", | 
|  | 2109 | "/redfish/v1/Systems/system/ResetActionInfo"}}; | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2110 |  | 
| Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 2111 | res.jsonValue["LogServices"] = { | 
| Ed Tanous | 029573d | 2019-02-01 10:57:49 -0800 | [diff] [blame] | 2112 | {"@odata.id", "/redfish/v1/Systems/system/LogServices"}}; | 
| Jason M. Bills | c4bf637 | 2018-11-05 13:48:27 -0800 | [diff] [blame] | 2113 |  | 
| Carol Wang | d82a3ac | 2019-11-21 13:56:38 +0800 | [diff] [blame] | 2114 | res.jsonValue["Bios"] = { | 
|  | 2115 | {"@odata.id", "/redfish/v1/Systems/system/Bios"}}; | 
|  | 2116 |  | 
| Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 2117 | res.jsonValue["Links"]["ManagedBy"] = { | 
|  | 2118 | {{"@odata.id", "/redfish/v1/Managers/bmc"}}}; | 
|  | 2119 |  | 
|  | 2120 | res.jsonValue["Status"] = { | 
|  | 2121 | {"Health", "OK"}, | 
|  | 2122 | {"State", "Enabled"}, | 
|  | 2123 | }; | 
| Ed Tanous | a0803ef | 2018-08-29 13:29:23 -0700 | [diff] [blame] | 2124 | auto asyncResp = std::make_shared<AsyncResp>(res); | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2125 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2126 | constexpr const std::array<const char*, 4> inventoryForSystems = { | 
| James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 2127 | "xyz.openbmc_project.Inventory.Item.Dimm", | 
| James Feist | 2ad9c2f | 2019-10-29 16:26:48 -0700 | [diff] [blame] | 2128 | "xyz.openbmc_project.Inventory.Item.Cpu", | 
| James Feist | e284a7c | 2019-11-20 16:20:23 -0800 | [diff] [blame] | 2129 | "xyz.openbmc_project.Inventory.Item.Drive", | 
|  | 2130 | "xyz.openbmc_project.Inventory.Item.StorageController"}; | 
| James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 2131 |  | 
|  | 2132 | auto health = std::make_shared<HealthPopulate>(asyncResp); | 
|  | 2133 | crow::connections::systemBus->async_method_call( | 
|  | 2134 | [health](const boost::system::error_code ec, | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2135 | std::vector<std::string>& resp) { | 
| James Feist | b49ac87 | 2019-05-21 15:12:01 -0700 | [diff] [blame] | 2136 | if (ec) | 
|  | 2137 | { | 
|  | 2138 | // no inventory | 
|  | 2139 | return; | 
|  | 2140 | } | 
|  | 2141 |  | 
|  | 2142 | health->inventory = std::move(resp); | 
|  | 2143 | }, | 
|  | 2144 | "xyz.openbmc_project.ObjectMapper", | 
|  | 2145 | "/xyz/openbmc_project/object_mapper", | 
|  | 2146 | "xyz.openbmc_project.ObjectMapper", "GetSubTreePaths", "/", | 
|  | 2147 | int32_t(0), inventoryForSystems); | 
|  | 2148 |  | 
|  | 2149 | health->populate(); | 
|  | 2150 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2151 | getMainChassisId(asyncResp, [](const std::string& chassisId, | 
| Ed Tanous | b5a7693 | 2020-09-29 16:16:58 -0700 | [diff] [blame] | 2152 | const std::shared_ptr<AsyncResp>& aRsp) { | 
| Jennifer Lee | c5d03ff | 2019-03-08 15:42:58 -0800 | [diff] [blame] | 2153 | aRsp->res.jsonValue["Links"]["Chassis"] = { | 
|  | 2154 | {{"@odata.id", "/redfish/v1/Chassis/" + chassisId}}}; | 
|  | 2155 | }); | 
| AppaRao Puli | a300222 | 2019-11-12 21:32:59 +0530 | [diff] [blame] | 2156 |  | 
| Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 2157 | getLocationIndicatorActive(asyncResp); | 
|  | 2158 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed | 
| AppaRao Puli | a300222 | 2019-11-12 21:32:59 +0530 | [diff] [blame] | 2159 | getIndicatorLedState(asyncResp); | 
| James Feist | 5bc2dc8 | 2019-10-22 14:33:16 -0700 | [diff] [blame] | 2160 | getComputerSystem(asyncResp, health); | 
| Ed Tanous | 6c34de4 | 2018-08-29 13:37:36 -0700 | [diff] [blame] | 2161 | getHostState(asyncResp); | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2162 | getBootProperties(asyncResp); | 
| Andrew Geissler | 978b880 | 2020-11-19 13:36:40 -0600 | [diff] [blame] | 2163 | getBootProgress(asyncResp); | 
| Jason M. Bills | adbe192 | 2019-10-14 15:44:35 -0700 | [diff] [blame] | 2164 | getPCIeDeviceList(asyncResp, "PCIeDevices"); | 
| Yong Li | 51709ff | 2019-09-30 14:13:04 +0800 | [diff] [blame] | 2165 | getHostWatchdogTimer(asyncResp); | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2166 | getPowerRestorePolicy(asyncResp); | 
| Gunnar Mills | 6bd5a8d | 2020-05-16 18:49:33 -0500 | [diff] [blame] | 2167 | getAutomaticRetry(asyncResp); | 
| Gunnar Mills | c0557e1 | 2020-06-30 11:26:20 -0500 | [diff] [blame] | 2168 | getLastResetTime(asyncResp); | 
| AppaRao Puli | a634991 | 2019-10-18 17:16:08 +0530 | [diff] [blame] | 2169 | #ifdef BMCWEB_ENABLE_REDFISH_PROVISIONING_FEATURE | 
|  | 2170 | getProvisioningStatus(asyncResp); | 
|  | 2171 | #endif | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2172 | } | 
|  | 2173 |  | 
| Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 2174 | void doPatch(crow::Response& res, const crow::Request& req, | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 2175 | const std::vector<std::string>&) override | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2176 | { | 
| Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 2177 | std::optional<bool> locationIndicatorActive; | 
| Santosh Puranik | cde19e5 | 2019-02-20 00:10:56 +0530 | [diff] [blame] | 2178 | std::optional<std::string> indicatorLed; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2179 | std::optional<nlohmann::json> bootProps; | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2180 | std::optional<nlohmann::json> wdtTimerProps; | 
| Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 2181 | std::optional<std::string> assetTag; | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2182 | std::optional<std::string> powerRestorePolicy; | 
| Santosh Puranik | 41352c2 | 2019-07-03 05:35:49 -0500 | [diff] [blame] | 2183 | auto asyncResp = std::make_shared<AsyncResp>(res); | 
|  | 2184 |  | 
| Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 2185 | if (!json_util::readJson( | 
|  | 2186 | req, res, "IndicatorLED", indicatorLed, | 
|  | 2187 | "LocationIndicatorActive", locationIndicatorActive, "Boot", | 
|  | 2188 | bootProps, "WatchdogTimer", wdtTimerProps, "PowerRestorePolicy", | 
|  | 2189 | powerRestorePolicy, "AssetTag", assetTag)) | 
| Ed Tanous | 6617338 | 2018-08-15 18:20:59 -0700 | [diff] [blame] | 2190 | { | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 2191 | return; | 
|  | 2192 | } | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2193 |  | 
| Johnathan Mantey | 944ffaf | 2019-08-12 16:16:14 -0700 | [diff] [blame] | 2194 | res.result(boost::beast::http::status::no_content); | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2195 |  | 
| Gunnar Mills | 98e386e | 2020-10-30 14:58:09 -0500 | [diff] [blame] | 2196 | if (assetTag) | 
|  | 2197 | { | 
|  | 2198 | setAssetTag(asyncResp, *assetTag); | 
|  | 2199 | } | 
|  | 2200 |  | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2201 | if (wdtTimerProps) | 
|  | 2202 | { | 
|  | 2203 | std::optional<bool> wdtEnable; | 
|  | 2204 | std::optional<std::string> wdtTimeOutAction; | 
|  | 2205 |  | 
|  | 2206 | if (!json_util::readJson(*wdtTimerProps, asyncResp->res, | 
|  | 2207 | "FunctionEnabled", wdtEnable, | 
|  | 2208 | "TimeoutAction", wdtTimeOutAction)) | 
|  | 2209 | { | 
|  | 2210 | return; | 
|  | 2211 | } | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 2212 | setWDTProperties(asyncResp, wdtEnable, wdtTimeOutAction); | 
| Yong Li | c45f008 | 2019-10-10 14:19:01 +0800 | [diff] [blame] | 2213 | } | 
|  | 2214 |  | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2215 | if (bootProps) | 
|  | 2216 | { | 
|  | 2217 | std::optional<std::string> bootSource; | 
|  | 2218 | std::optional<std::string> bootEnable; | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 2219 | std::optional<std::string> automaticRetryConfig; | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2220 |  | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 2221 | if (!json_util::readJson( | 
|  | 2222 | *bootProps, asyncResp->res, "BootSourceOverrideTarget", | 
|  | 2223 | bootSource, "BootSourceOverrideEnabled", bootEnable, | 
|  | 2224 | "AutomaticRetryConfig", automaticRetryConfig)) | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2225 | { | 
|  | 2226 | return; | 
|  | 2227 | } | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 2228 | if (bootSource || bootEnable) | 
|  | 2229 | { | 
|  | 2230 | setBootSourceProperties(asyncResp, std::move(bootSource), | 
|  | 2231 | std::move(bootEnable)); | 
|  | 2232 | } | 
|  | 2233 | if (automaticRetryConfig) | 
|  | 2234 | { | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 2235 | setAutomaticRetry(asyncResp, *automaticRetryConfig); | 
| Gunnar Mills | 69f3530 | 2020-05-17 16:06:31 -0500 | [diff] [blame] | 2236 | } | 
| Santosh Puranik | 491d8ee | 2019-02-06 19:46:56 +0530 | [diff] [blame] | 2237 | } | 
| Johnathan Mantey | 265c160 | 2019-08-08 11:02:51 -0700 | [diff] [blame] | 2238 |  | 
| Gunnar Mills | 9f8bfa7 | 2020-09-28 13:45:19 -0500 | [diff] [blame] | 2239 | if (locationIndicatorActive) | 
|  | 2240 | { | 
|  | 2241 | setLocationIndicatorActive(asyncResp, *locationIndicatorActive); | 
|  | 2242 | } | 
|  | 2243 |  | 
|  | 2244 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed | 
| Ed Tanous | 9712f8a | 2018-09-21 13:38:49 -0700 | [diff] [blame] | 2245 | if (indicatorLed) | 
|  | 2246 | { | 
| Ed Tanous | f23b729 | 2020-10-15 09:41:17 -0700 | [diff] [blame] | 2247 | setIndicatorLedState(asyncResp, *indicatorLed); | 
| Gunnar Mills | d6aa009 | 2020-11-25 14:17:37 -0600 | [diff] [blame] | 2248 | res.addHeader(boost::beast::http::field::warning, | 
|  | 2249 | "299 - \"IndicatorLED is deprecated. Use " | 
|  | 2250 | "LocationIndicatorActive instead.\""); | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2251 | } | 
| George Liu | c6a620f | 2020-04-10 17:18:11 +0800 | [diff] [blame] | 2252 |  | 
|  | 2253 | if (powerRestorePolicy) | 
|  | 2254 | { | 
|  | 2255 | setPowerRestorePolicy(asyncResp, std::move(*powerRestorePolicy)); | 
|  | 2256 | } | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2257 | } | 
| Lewanczyk, Dawid | c5b2abe | 2018-05-30 16:59:42 +0200 | [diff] [blame] | 2258 | }; | 
| AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 2259 |  | 
|  | 2260 | /** | 
|  | 2261 | * SystemResetActionInfo derived class for delivering Computer Systems | 
|  | 2262 | * ResetType AllowableValues using ResetInfo schema. | 
|  | 2263 | */ | 
|  | 2264 | class SystemResetActionInfo : public Node | 
|  | 2265 | { | 
|  | 2266 | public: | 
|  | 2267 | /* | 
|  | 2268 | * Default Constructor | 
|  | 2269 | */ | 
| Ed Tanous | 52cc112 | 2020-07-18 13:51:21 -0700 | [diff] [blame] | 2270 | SystemResetActionInfo(App& app) : | 
| AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 2271 | Node(app, "/redfish/v1/Systems/system/ResetActionInfo/") | 
|  | 2272 | { | 
|  | 2273 | entityPrivileges = { | 
|  | 2274 | {boost::beast::http::verb::get, {{"Login"}}}, | 
|  | 2275 | {boost::beast::http::verb::head, {{"Login"}}}, | 
|  | 2276 | {boost::beast::http::verb::patch, {{"ConfigureComponents"}}}, | 
|  | 2277 | {boost::beast::http::verb::put, {{"ConfigureComponents"}}}, | 
|  | 2278 | {boost::beast::http::verb::delete_, {{"ConfigureComponents"}}}, | 
|  | 2279 | {boost::beast::http::verb::post, {{"ConfigureComponents"}}}}; | 
|  | 2280 | } | 
|  | 2281 |  | 
|  | 2282 | private: | 
|  | 2283 | /** | 
|  | 2284 | * Functions triggers appropriate requests on DBus | 
|  | 2285 | */ | 
| Ed Tanous | cb13a39 | 2020-07-25 19:02:03 +0000 | [diff] [blame] | 2286 | void doGet(crow::Response& res, const crow::Request&, | 
|  | 2287 | const std::vector<std::string>&) override | 
| AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 2288 | { | 
|  | 2289 | res.jsonValue = { | 
|  | 2290 | {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, | 
|  | 2291 | {"@odata.id", "/redfish/v1/Systems/system/ResetActionInfo"}, | 
|  | 2292 | {"Name", "Reset Action Info"}, | 
|  | 2293 | {"Id", "ResetActionInfo"}, | 
|  | 2294 | {"Parameters", | 
|  | 2295 | {{{"Name", "ResetType"}, | 
|  | 2296 | {"Required", true}, | 
|  | 2297 | {"DataType", "String"}, | 
|  | 2298 | {"AllowableValues", | 
|  | 2299 | {"On", "ForceOff", "ForceOn", "ForceRestart", "GracefulRestart", | 
|  | 2300 | "GracefulShutdown", "PowerCycle", "Nmi"}}}}}}; | 
|  | 2301 | res.end(); | 
|  | 2302 | } | 
|  | 2303 | }; | 
| Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 2304 | } // namespace redfish |