Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [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" |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 20 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 21 | #include <app.hpp> |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 22 | #include <boost/container/flat_map.hpp> |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 23 | #include <registries/privilege_registry.hpp> |
Gunnar Mills | 02f6ff1 | 2020-10-14 15:59:58 -0500 | [diff] [blame] | 24 | #include <utils/collection.hpp> |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 25 | |
Ed Tanous | abf2add | 2019-01-22 16:40:12 -0800 | [diff] [blame] | 26 | #include <variant> |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 27 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 28 | namespace redfish |
| 29 | { |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 30 | |
| 31 | /** |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 32 | * @brief Retrieves chassis state properties over dbus |
| 33 | * |
| 34 | * @param[in] aResp - Shared pointer for completing asynchronous calls. |
| 35 | * |
| 36 | * @return None. |
| 37 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 38 | inline void getChassisState(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 39 | { |
| 40 | crow::connections::systemBus->async_method_call( |
| 41 | [aResp{std::move(aResp)}]( |
| 42 | const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 43 | const std::variant<std::string>& chassisState) { |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 44 | if (ec) |
| 45 | { |
| 46 | BMCWEB_LOG_DEBUG << "DBUS response error " << ec; |
| 47 | messages::internalError(aResp->res); |
| 48 | return; |
| 49 | } |
| 50 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 51 | const std::string* s = std::get_if<std::string>(&chassisState); |
Gunnar Mills | beeca0a | 2019-02-14 16:30:45 -0600 | [diff] [blame] | 52 | BMCWEB_LOG_DEBUG << "Chassis state: " << *s; |
| 53 | if (s != nullptr) |
| 54 | { |
| 55 | // Verify Chassis State |
| 56 | if (*s == "xyz.openbmc_project.State.Chassis.PowerState.On") |
| 57 | { |
| 58 | aResp->res.jsonValue["PowerState"] = "On"; |
| 59 | aResp->res.jsonValue["Status"]["State"] = "Enabled"; |
| 60 | } |
| 61 | else if (*s == |
| 62 | "xyz.openbmc_project.State.Chassis.PowerState.Off") |
| 63 | { |
| 64 | aResp->res.jsonValue["PowerState"] = "Off"; |
| 65 | aResp->res.jsonValue["Status"]["State"] = "StandbyOffline"; |
| 66 | } |
| 67 | } |
| 68 | }, |
| 69 | "xyz.openbmc_project.State.Chassis", |
| 70 | "/xyz/openbmc_project/state/chassis0", |
| 71 | "org.freedesktop.DBus.Properties", "Get", |
| 72 | "xyz.openbmc_project.State.Chassis", "CurrentPowerState"); |
| 73 | } |
| 74 | |
| 75 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 76 | * DBus types primitives for several generic DBus interfaces |
| 77 | * TODO(Pawel) consider move this to separate file into boost::dbus |
| 78 | */ |
Ed Tanous | 55c7b7a | 2018-05-22 15:27:24 -0700 | [diff] [blame] | 79 | // Note, this is not a very useful Variant, but because it isn't used to get |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 80 | // values, it should be as simple as possible |
| 81 | // TODO(ed) invent a nullvariant type |
Cheng C Yang | 5fd7ba6 | 2019-11-28 15:58:08 +0800 | [diff] [blame] | 82 | using VariantType = std::variant<bool, std::string, uint64_t, uint32_t>; |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 83 | using ManagedObjectsType = std::vector<std::pair< |
| 84 | sdbusplus::message::object_path, |
| 85 | std::vector<std::pair<std::string, |
| 86 | std::vector<std::pair<std::string, VariantType>>>>>>; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 87 | |
Ed Tanous | aa2e59c | 2018-04-12 12:17:20 -0700 | [diff] [blame] | 88 | using PropertiesType = boost::container::flat_map<std::string, VariantType>; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 89 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 90 | inline void getIntrusionByService(std::shared_ptr<bmcweb::AsyncResp> aResp, |
Ed Tanous | 23a21a1 | 2020-07-25 04:45:05 +0000 | [diff] [blame] | 91 | const std::string& service, |
| 92 | const std::string& objPath) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 93 | { |
| 94 | BMCWEB_LOG_DEBUG << "Get intrusion status by service \n"; |
| 95 | |
| 96 | crow::connections::systemBus->async_method_call( |
| 97 | [aResp{std::move(aResp)}](const boost::system::error_code ec, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 98 | const std::variant<std::string>& value) { |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 99 | if (ec) |
| 100 | { |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 101 | // do not add err msg in redfish response, because this is not |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 102 | // mandatory property |
| 103 | BMCWEB_LOG_ERROR << "DBUS response error " << ec << "\n"; |
| 104 | return; |
| 105 | } |
| 106 | |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 107 | const std::string* status = std::get_if<std::string>(&value); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 108 | |
| 109 | if (status == nullptr) |
| 110 | { |
| 111 | BMCWEB_LOG_ERROR << "intrusion status read error \n"; |
| 112 | return; |
| 113 | } |
| 114 | |
| 115 | aResp->res.jsonValue["PhysicalSecurity"] = { |
| 116 | {"IntrusionSensorNumber", 1}, {"IntrusionSensor", *status}}; |
| 117 | }, |
| 118 | service, objPath, "org.freedesktop.DBus.Properties", "Get", |
| 119 | "xyz.openbmc_project.Chassis.Intrusion", "Status"); |
| 120 | } |
| 121 | |
| 122 | /** |
| 123 | * Retrieves physical security properties over dbus |
| 124 | */ |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 125 | inline void getPhysicalSecurityData(std::shared_ptr<bmcweb::AsyncResp> aResp) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 126 | { |
| 127 | crow::connections::systemBus->async_method_call( |
| 128 | [aResp{std::move(aResp)}]( |
| 129 | const boost::system::error_code ec, |
| 130 | const std::vector<std::pair< |
| 131 | std::string, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 132 | std::vector<std::pair<std::string, std::vector<std::string>>>>>& |
| 133 | subtree) { |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 134 | if (ec) |
| 135 | { |
Gunnar Mills | 4e0453b | 2020-07-08 14:00:30 -0500 | [diff] [blame] | 136 | // do not add err msg in redfish response, because this is not |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 137 | // mandatory property |
Andrew Geissler | 54fbf17 | 2021-11-11 15:59:30 -0600 | [diff] [blame] | 138 | BMCWEB_LOG_INFO << "DBUS error: no matched iface " << ec |
| 139 | << "\n"; |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 140 | return; |
| 141 | } |
| 142 | // Iterate over all retrieved ObjectPaths. |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 143 | for (const auto& object : subtree) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 144 | { |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 145 | for (const auto& service : object.second) |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 146 | { |
| 147 | getIntrusionByService(aResp, service.first, object.first); |
| 148 | return; |
| 149 | } |
| 150 | } |
| 151 | }, |
| 152 | "xyz.openbmc_project.ObjectMapper", |
| 153 | "/xyz/openbmc_project/object_mapper", |
| 154 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
Ed Tanous | 271584a | 2019-07-09 16:24:22 -0700 | [diff] [blame] | 155 | "/xyz/openbmc_project/Intrusion", 1, |
Gunnar Mills | 1214b7e | 2020-06-04 10:11:30 -0500 | [diff] [blame] | 156 | std::array<const char*, 1>{"xyz.openbmc_project.Chassis.Intrusion"}); |
Qiang XU | c181942 | 2019-02-27 13:51:32 +0800 | [diff] [blame] | 157 | } |
| 158 | |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 159 | /** |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 160 | * ChassisCollection derived class for delivering Chassis Collection Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 161 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 162 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 163 | inline void requestRoutesChassisCollection(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 164 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 165 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 166 | .privileges(redfish::privileges::getChassisCollection) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 167 | .methods(boost::beast::http::verb::get)( |
| 168 | [](const crow::Request&, |
| 169 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) { |
| 170 | asyncResp->res.jsonValue["@odata.type"] = |
| 171 | "#ChassisCollection.ChassisCollection"; |
| 172 | asyncResp->res.jsonValue["@odata.id"] = "/redfish/v1/Chassis"; |
| 173 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 174 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 175 | collection_util::getCollectionMembers( |
| 176 | asyncResp, "/redfish/v1/Chassis", |
| 177 | {"xyz.openbmc_project.Inventory.Item.Board", |
| 178 | "xyz.openbmc_project.Inventory.Item.Chassis"}); |
| 179 | }); |
| 180 | } |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 181 | |
| 182 | /** |
| 183 | * Chassis override class for delivering Chassis Schema |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 184 | * Functions triggers appropriate requests on DBus |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 185 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 186 | inline void requestRoutesChassis(App& app) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 187 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 188 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 189 | .privileges(redfish::privileges::getChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 190 | .methods( |
| 191 | boost::beast::http::verb::get)([](const crow::Request&, |
| 192 | const std::shared_ptr< |
| 193 | bmcweb::AsyncResp>& asyncResp, |
| 194 | const std::string& chassisId) { |
| 195 | const std::array<const char*, 2> interfaces = { |
| 196 | "xyz.openbmc_project.Inventory.Item.Board", |
| 197 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
Rapkiewicz, Pawel | e37f845 | 2018-03-09 13:49:50 +0100 | [diff] [blame] | 198 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 199 | crow::connections::systemBus->async_method_call( |
| 200 | [asyncResp, chassisId(std::string(chassisId))]( |
| 201 | const boost::system::error_code ec, |
| 202 | const crow::openbmc_mapper::GetSubTreeType& subtree) { |
| 203 | if (ec) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 204 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 205 | messages::internalError(asyncResp->res); |
| 206 | return; |
Ed Tanous | daf36e2 | 2018-04-20 16:01:36 -0700 | [diff] [blame] | 207 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 208 | // Iterate over all retrieved ObjectPaths. |
| 209 | for (const std::pair< |
| 210 | std::string, |
| 211 | std::vector<std::pair<std::string, |
| 212 | std::vector<std::string>>>>& |
| 213 | object : subtree) |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 214 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 215 | const std::string& path = object.first; |
| 216 | const std::vector< |
| 217 | std::pair<std::string, std::vector<std::string>>>& |
| 218 | connectionNames = object.second; |
Ed Tanous | e0d918b | 2018-03-27 17:41:04 -0700 | [diff] [blame] | 219 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 220 | if (!boost::ends_with(path, chassisId)) |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 221 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 222 | continue; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 223 | } |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 224 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 225 | auto health = |
| 226 | std::make_shared<HealthPopulate>(asyncResp); |
| 227 | |
| 228 | crow::connections::systemBus->async_method_call( |
| 229 | [health]( |
| 230 | const boost::system::error_code ec2, |
| 231 | std::variant<std::vector<std::string>>& resp) { |
| 232 | if (ec2) |
| 233 | { |
| 234 | return; // no sensors = no failures |
| 235 | } |
| 236 | std::vector<std::string>* data = |
| 237 | std::get_if<std::vector<std::string>>( |
| 238 | &resp); |
| 239 | if (data == nullptr) |
| 240 | { |
| 241 | return; |
| 242 | } |
| 243 | health->inventory = std::move(*data); |
| 244 | }, |
| 245 | "xyz.openbmc_project.ObjectMapper", |
| 246 | path + "/all_sensors", |
| 247 | "org.freedesktop.DBus.Properties", "Get", |
| 248 | "xyz.openbmc_project.Association", "endpoints"); |
| 249 | |
| 250 | health->populate(); |
| 251 | |
| 252 | if (connectionNames.size() < 1) |
| 253 | { |
| 254 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 255 | continue; |
| 256 | } |
| 257 | |
| 258 | asyncResp->res.jsonValue["@odata.type"] = |
| 259 | "#Chassis.v1_14_0.Chassis"; |
| 260 | asyncResp->res.jsonValue["@odata.id"] = |
| 261 | "/redfish/v1/Chassis/" + chassisId; |
| 262 | asyncResp->res.jsonValue["Name"] = "Chassis Collection"; |
| 263 | asyncResp->res.jsonValue["ChassisType"] = "RackMount"; |
| 264 | asyncResp->res.jsonValue["Actions"]["#Chassis.Reset"] = |
| 265 | {{"target", "/redfish/v1/Chassis/" + chassisId + |
| 266 | "/Actions/Chassis.Reset"}, |
| 267 | {"@Redfish.ActionInfo", "/redfish/v1/Chassis/" + |
| 268 | chassisId + |
| 269 | "/ResetActionInfo"}}; |
| 270 | asyncResp->res.jsonValue["PCIeDevices"] = { |
| 271 | {"@odata.id", |
| 272 | "/redfish/v1/Systems/system/PCIeDevices"}}; |
| 273 | |
| 274 | const std::string& connectionName = |
| 275 | connectionNames[0].first; |
| 276 | |
| 277 | const std::vector<std::string>& interfaces2 = |
| 278 | connectionNames[0].second; |
| 279 | const std::array<const char*, 2> hasIndicatorLed = { |
| 280 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 281 | "xyz.openbmc_project.Inventory.Item.Board." |
| 282 | "Motherboard"}; |
| 283 | |
Tejas Patil | 476b9cc | 2021-06-04 17:09:14 +0530 | [diff] [blame] | 284 | const std::string assetTagInterface = |
| 285 | "xyz.openbmc_project.Inventory.Decorator." |
| 286 | "AssetTag"; |
| 287 | if (std::find(interfaces2.begin(), interfaces2.end(), |
| 288 | assetTagInterface) != interfaces2.end()) |
| 289 | { |
| 290 | crow::connections::systemBus->async_method_call( |
| 291 | [asyncResp, chassisId(std::string(chassisId))]( |
| 292 | const boost::system::error_code ec, |
| 293 | const std::variant<std::string>& property) { |
| 294 | if (ec) |
| 295 | { |
| 296 | BMCWEB_LOG_DEBUG |
| 297 | << "DBus response error for " |
| 298 | "AssetTag"; |
| 299 | messages::internalError(asyncResp->res); |
| 300 | return; |
| 301 | } |
| 302 | |
| 303 | const std::string* assetTag = |
| 304 | std::get_if<std::string>(&property); |
| 305 | if (assetTag == nullptr) |
| 306 | { |
| 307 | BMCWEB_LOG_DEBUG |
| 308 | << "Null value returned " |
| 309 | "for Chassis AssetTag"; |
| 310 | messages::internalError(asyncResp->res); |
| 311 | return; |
| 312 | } |
| 313 | asyncResp->res.jsonValue["AssetTag"] = |
| 314 | *assetTag; |
| 315 | }, |
| 316 | connectionName, path, |
| 317 | "org.freedesktop.DBus.Properties", "Get", |
| 318 | assetTagInterface, "AssetTag"); |
| 319 | } |
| 320 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 321 | for (const char* interface : hasIndicatorLed) |
| 322 | { |
| 323 | if (std::find(interfaces2.begin(), |
| 324 | interfaces2.end(), |
| 325 | interface) != interfaces2.end()) |
| 326 | { |
| 327 | getIndicatorLedState(asyncResp); |
| 328 | getLocationIndicatorActive(asyncResp); |
| 329 | break; |
| 330 | } |
| 331 | } |
| 332 | |
| 333 | const std::string locationInterface = |
| 334 | "xyz.openbmc_project.Inventory.Decorator." |
| 335 | "LocationCode"; |
| 336 | if (std::find(interfaces2.begin(), interfaces2.end(), |
| 337 | locationInterface) != interfaces2.end()) |
| 338 | { |
| 339 | crow::connections::systemBus->async_method_call( |
| 340 | [asyncResp, chassisId(std::string(chassisId))]( |
| 341 | const boost::system::error_code ec, |
| 342 | const std::variant<std::string>& property) { |
| 343 | if (ec) |
| 344 | { |
| 345 | BMCWEB_LOG_DEBUG |
| 346 | << "DBUS response error for " |
| 347 | "Location"; |
| 348 | messages::internalError(asyncResp->res); |
| 349 | return; |
| 350 | } |
| 351 | |
| 352 | const std::string* value = |
| 353 | std::get_if<std::string>(&property); |
| 354 | if (value == nullptr) |
| 355 | { |
| 356 | BMCWEB_LOG_DEBUG |
| 357 | << "Null value returned " |
| 358 | "for locaton code"; |
| 359 | messages::internalError(asyncResp->res); |
| 360 | return; |
| 361 | } |
| 362 | asyncResp->res |
| 363 | .jsonValue["Location"]["PartLocation"] |
| 364 | ["ServiceLabel"] = *value; |
| 365 | }, |
| 366 | connectionName, path, |
| 367 | "org.freedesktop.DBus.Properties", "Get", |
| 368 | locationInterface, "LocationCode"); |
| 369 | } |
| 370 | |
SunnySrivastava1984 | 88ad7f0 | 2020-12-03 10:27:52 -0600 | [diff] [blame] | 371 | crow::connections::systemBus->async_method_call( |
| 372 | [asyncResp, chassisId(std::string(chassisId))]( |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 373 | const boost::system::error_code /*ec2*/, |
| 374 | const std::vector< |
| 375 | std::pair<std::string, VariantType>>& |
| 376 | propertiesList) { |
| 377 | for (const std::pair<std::string, VariantType>& |
| 378 | property : propertiesList) |
SunnySrivastava1984 | 88ad7f0 | 2020-12-03 10:27:52 -0600 | [diff] [blame] | 379 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 380 | // Store DBus properties that are also |
| 381 | // Redfish properties with same name and a |
| 382 | // string value |
| 383 | const std::string& propertyName = |
| 384 | property.first; |
| 385 | if ((propertyName == "PartNumber") || |
| 386 | (propertyName == "SerialNumber") || |
| 387 | (propertyName == "Manufacturer") || |
| 388 | (propertyName == "Model")) |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 389 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 390 | const std::string* value = |
| 391 | std::get_if<std::string>( |
| 392 | &property.second); |
| 393 | if (value != nullptr) |
| 394 | { |
| 395 | asyncResp->res |
| 396 | .jsonValue[propertyName] = |
| 397 | *value; |
| 398 | } |
Shawn McCarney | 99cffd7 | 2019-03-01 10:46:20 -0600 | [diff] [blame] | 399 | } |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 400 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 401 | asyncResp->res.jsonValue["Name"] = chassisId; |
| 402 | asyncResp->res.jsonValue["Id"] = chassisId; |
zhanghch05 | 0256b69 | 2021-06-12 10:26:52 +0800 | [diff] [blame] | 403 | #ifdef BMCWEB_ALLOW_DEPRECATED_POWER_THERMAL |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 404 | asyncResp->res.jsonValue["Thermal"] = { |
| 405 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 406 | chassisId + "/Thermal"}}; |
| 407 | // Power object |
| 408 | asyncResp->res.jsonValue["Power"] = { |
| 409 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 410 | chassisId + "/Power"}}; |
zhanghch05 | 0256b69 | 2021-06-12 10:26:52 +0800 | [diff] [blame] | 411 | #endif |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 412 | // SensorCollection |
| 413 | asyncResp->res.jsonValue["Sensors"] = { |
| 414 | {"@odata.id", "/redfish/v1/Chassis/" + |
| 415 | chassisId + "/Sensors"}}; |
| 416 | asyncResp->res.jsonValue["Status"] = { |
| 417 | {"State", "Enabled"}, |
| 418 | }; |
| 419 | |
| 420 | asyncResp->res |
| 421 | .jsonValue["Links"]["ComputerSystems"] = { |
| 422 | {{"@odata.id", |
| 423 | "/redfish/v1/Systems/system"}}}; |
| 424 | asyncResp->res.jsonValue["Links"]["ManagedBy"] = |
| 425 | {{{"@odata.id", |
| 426 | "/redfish/v1/Managers/bmc"}}}; |
| 427 | getChassisState(asyncResp); |
| 428 | }, |
| 429 | connectionName, path, |
| 430 | "org.freedesktop.DBus.Properties", "GetAll", |
| 431 | "xyz.openbmc_project.Inventory.Decorator.Asset"); |
Sharad Yadav | 2c37b4b | 2021-05-10 12:53:38 +0530 | [diff] [blame] | 432 | |
| 433 | // Chassis UUID |
| 434 | const std::string uuidInterface = |
| 435 | "xyz.openbmc_project.Common.UUID"; |
| 436 | if (std::find(interfaces2.begin(), interfaces2.end(), |
| 437 | uuidInterface) != interfaces2.end()) |
| 438 | { |
| 439 | crow::connections::systemBus->async_method_call( |
| 440 | [asyncResp](const boost::system::error_code ec, |
| 441 | const std::variant<std::string>& |
| 442 | chassisUUID) { |
| 443 | if (ec) |
| 444 | { |
| 445 | BMCWEB_LOG_DEBUG |
| 446 | << "DBUS response error for " |
| 447 | "UUID"; |
| 448 | messages::internalError(asyncResp->res); |
| 449 | return; |
| 450 | } |
| 451 | const std::string* value = |
| 452 | std::get_if<std::string>(&chassisUUID); |
| 453 | if (value == nullptr) |
| 454 | { |
| 455 | BMCWEB_LOG_DEBUG |
| 456 | << "Null value returned " |
| 457 | "for UUID"; |
| 458 | messages::internalError(asyncResp->res); |
| 459 | return; |
| 460 | } |
| 461 | asyncResp->res.jsonValue["UUID"] = *value; |
| 462 | }, |
| 463 | connectionName, path, |
| 464 | "org.freedesktop.DBus.Properties", "Get", |
| 465 | uuidInterface, "UUID"); |
| 466 | } |
| 467 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 468 | return; |
| 469 | } |
| 470 | |
| 471 | // Couldn't find an object with that name. return an error |
| 472 | messages::resourceNotFound( |
| 473 | asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); |
| 474 | }, |
| 475 | "xyz.openbmc_project.ObjectMapper", |
| 476 | "/xyz/openbmc_project/object_mapper", |
| 477 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 478 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 479 | |
| 480 | getPhysicalSecurityData(asyncResp); |
| 481 | }); |
| 482 | |
| 483 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 484 | .privileges(redfish::privileges::patchChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 485 | .methods( |
| 486 | boost::beast::http::verb:: |
| 487 | patch)([](const crow::Request& req, |
| 488 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 489 | const std::string& param) { |
| 490 | std::optional<bool> locationIndicatorActive; |
| 491 | std::optional<std::string> indicatorLed; |
| 492 | |
| 493 | if (param.empty()) |
| 494 | { |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | if (!json_util::readJson( |
| 499 | req, asyncResp->res, "LocationIndicatorActive", |
| 500 | locationIndicatorActive, "IndicatorLED", indicatorLed)) |
| 501 | { |
| 502 | return; |
| 503 | } |
| 504 | |
| 505 | // TODO (Gunnar): Remove IndicatorLED after enough time has passed |
| 506 | if (!locationIndicatorActive && !indicatorLed) |
| 507 | { |
| 508 | return; // delete this when we support more patch properties |
| 509 | } |
| 510 | if (indicatorLed) |
| 511 | { |
| 512 | asyncResp->res.addHeader( |
| 513 | boost::beast::http::field::warning, |
| 514 | "299 - \"IndicatorLED is deprecated. Use " |
| 515 | "LocationIndicatorActive instead.\""); |
| 516 | } |
| 517 | |
| 518 | const std::array<const char*, 2> interfaces = { |
| 519 | "xyz.openbmc_project.Inventory.Item.Board", |
| 520 | "xyz.openbmc_project.Inventory.Item.Chassis"}; |
| 521 | |
| 522 | const std::string& chassisId = param; |
| 523 | |
| 524 | crow::connections::systemBus->async_method_call( |
| 525 | [asyncResp, chassisId, locationIndicatorActive, indicatorLed]( |
| 526 | const boost::system::error_code ec, |
| 527 | const crow::openbmc_mapper::GetSubTreeType& subtree) { |
| 528 | if (ec) |
| 529 | { |
| 530 | messages::internalError(asyncResp->res); |
| 531 | return; |
| 532 | } |
| 533 | |
| 534 | // Iterate over all retrieved ObjectPaths. |
| 535 | for (const std::pair< |
| 536 | std::string, |
| 537 | std::vector<std::pair<std::string, |
| 538 | std::vector<std::string>>>>& |
| 539 | object : subtree) |
| 540 | { |
| 541 | const std::string& path = object.first; |
| 542 | const std::vector< |
| 543 | std::pair<std::string, std::vector<std::string>>>& |
| 544 | connectionNames = object.second; |
| 545 | |
| 546 | if (!boost::ends_with(path, chassisId)) |
| 547 | { |
| 548 | continue; |
| 549 | } |
| 550 | |
| 551 | if (connectionNames.size() < 1) |
| 552 | { |
| 553 | BMCWEB_LOG_ERROR << "Got 0 Connection names"; |
| 554 | continue; |
| 555 | } |
| 556 | |
| 557 | const std::vector<std::string>& interfaces3 = |
| 558 | connectionNames[0].second; |
| 559 | |
| 560 | const std::array<const char*, 2> hasIndicatorLed = { |
| 561 | "xyz.openbmc_project.Inventory.Item.Panel", |
| 562 | "xyz.openbmc_project.Inventory.Item.Board." |
| 563 | "Motherboard"}; |
| 564 | bool indicatorChassis = false; |
| 565 | for (const char* interface : hasIndicatorLed) |
| 566 | { |
| 567 | if (std::find(interfaces3.begin(), |
| 568 | interfaces3.end(), |
| 569 | interface) != interfaces3.end()) |
| 570 | { |
| 571 | indicatorChassis = true; |
| 572 | break; |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 573 | } |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 574 | } |
| 575 | if (locationIndicatorActive) |
| 576 | { |
| 577 | if (indicatorChassis) |
| 578 | { |
| 579 | setLocationIndicatorActive( |
| 580 | asyncResp, *locationIndicatorActive); |
| 581 | } |
| 582 | else |
| 583 | { |
| 584 | messages::propertyUnknown( |
| 585 | asyncResp->res, "LocationIndicatorActive"); |
| 586 | } |
| 587 | } |
| 588 | if (indicatorLed) |
| 589 | { |
| 590 | if (indicatorChassis) |
| 591 | { |
| 592 | setIndicatorLedState(asyncResp, *indicatorLed); |
| 593 | } |
| 594 | else |
| 595 | { |
| 596 | messages::propertyUnknown(asyncResp->res, |
| 597 | "IndicatorLED"); |
| 598 | } |
| 599 | } |
| 600 | return; |
James Feist | 1c8fba9 | 2019-12-20 15:12:07 -0800 | [diff] [blame] | 601 | } |
| 602 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 603 | messages::resourceNotFound( |
| 604 | asyncResp->res, "#Chassis.v1_14_0.Chassis", chassisId); |
| 605 | }, |
| 606 | "xyz.openbmc_project.ObjectMapper", |
| 607 | "/xyz/openbmc_project/object_mapper", |
| 608 | "xyz.openbmc_project.ObjectMapper", "GetSubTree", |
| 609 | "/xyz/openbmc_project/inventory", 0, interfaces); |
| 610 | }); |
| 611 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 612 | |
zhanghch05 | 8d1b46d | 2021-04-01 11:18:24 +0800 | [diff] [blame] | 613 | inline void |
| 614 | doChassisPowerCycle(const std::shared_ptr<bmcweb::AsyncResp>& asyncResp) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 615 | { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 616 | const char* busName = "xyz.openbmc_project.ObjectMapper"; |
| 617 | const char* path = "/xyz/openbmc_project/object_mapper"; |
| 618 | const char* interface = "xyz.openbmc_project.ObjectMapper"; |
| 619 | const char* method = "GetSubTreePaths"; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 620 | |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 621 | const std::array<const char*, 1> interfaces = { |
| 622 | "xyz.openbmc_project.State.Chassis"}; |
| 623 | |
| 624 | // Use mapper to get subtree paths. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 625 | crow::connections::systemBus->async_method_call( |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 626 | [asyncResp](const boost::system::error_code ec, |
| 627 | const std::vector<std::string>& chassisList) { |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 628 | if (ec) |
| 629 | { |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 630 | BMCWEB_LOG_DEBUG << "[mapper] Bad D-Bus request error: " << ec; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 631 | messages::internalError(asyncResp->res); |
| 632 | return; |
| 633 | } |
| 634 | |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 635 | const char* processName = "xyz.openbmc_project.State.Chassis"; |
| 636 | const char* interfaceName = "xyz.openbmc_project.State.Chassis"; |
| 637 | const char* destProperty = "RequestedPowerTransition"; |
| 638 | const std::string propertyValue = |
| 639 | "xyz.openbmc_project.State.Chassis.Transition.PowerCycle"; |
| 640 | std::string objectPath = |
| 641 | "/xyz/openbmc_project/state/chassis_system0"; |
| 642 | |
| 643 | /* Look for system reset chassis path */ |
| 644 | if ((std::find(chassisList.begin(), chassisList.end(), |
| 645 | objectPath)) == chassisList.end()) |
| 646 | { |
| 647 | /* We prefer to reset the full chassis_system, but if it doesn't |
| 648 | * exist on some platforms, fall back to a host-only power reset |
| 649 | */ |
| 650 | objectPath = "/xyz/openbmc_project/state/chassis0"; |
| 651 | } |
| 652 | |
| 653 | crow::connections::systemBus->async_method_call( |
| 654 | [asyncResp](const boost::system::error_code ec) { |
| 655 | // Use "Set" method to set the property value. |
| 656 | if (ec) |
| 657 | { |
| 658 | BMCWEB_LOG_DEBUG << "[Set] Bad D-Bus request error: " |
| 659 | << ec; |
| 660 | messages::internalError(asyncResp->res); |
| 661 | return; |
| 662 | } |
| 663 | |
| 664 | messages::success(asyncResp->res); |
| 665 | }, |
| 666 | processName, objectPath, "org.freedesktop.DBus.Properties", |
| 667 | "Set", interfaceName, destProperty, |
| 668 | std::variant<std::string>{propertyValue}); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 669 | }, |
Vijay Khemka | c3b3c92 | 2020-09-22 23:00:12 -0700 | [diff] [blame] | 670 | busName, path, interface, method, "/", 0, interfaces); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 671 | } |
| 672 | |
| 673 | /** |
| 674 | * ChassisResetAction class supports the POST method for the Reset |
| 675 | * action. |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 676 | * Function handles POST method request. |
| 677 | * Analyzes POST body before sending Reset request data to D-Bus. |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 678 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 679 | |
| 680 | inline void requestRoutesChassisResetAction(App& app) |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 681 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 682 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/Actions/Chassis.Reset/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 683 | .privileges(redfish::privileges::postChassis) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 684 | .methods(boost::beast::http::verb::post)( |
| 685 | [](const crow::Request& req, |
| 686 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 687 | const std::string&) { |
| 688 | BMCWEB_LOG_DEBUG << "Post Chassis Reset."; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 689 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 690 | std::string resetType; |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 691 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 692 | if (!json_util::readJson(req, asyncResp->res, "ResetType", |
| 693 | resetType)) |
| 694 | { |
| 695 | return; |
| 696 | } |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 697 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 698 | if (resetType != "PowerCycle") |
| 699 | { |
| 700 | BMCWEB_LOG_DEBUG << "Invalid property value for ResetType: " |
| 701 | << resetType; |
| 702 | messages::actionParameterNotSupported( |
| 703 | asyncResp->res, resetType, "ResetType"); |
P.K. Lee | dd99e04 | 2020-06-17 19:43:16 +0800 | [diff] [blame] | 704 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 705 | return; |
| 706 | } |
| 707 | doChassisPowerCycle(asyncResp); |
| 708 | }); |
| 709 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 710 | |
| 711 | /** |
| 712 | * ChassisResetActionInfo derived class for delivering Chassis |
| 713 | * ResetType AllowableValues using ResetInfo schema. |
| 714 | */ |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 715 | inline void requestRoutesChassisResetActionInfo(App& app) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 716 | { |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 717 | BMCWEB_ROUTE(app, "/redfish/v1/Chassis/<str>/ResetActionInfo/") |
Ed Tanous | ed39821 | 2021-06-09 17:05:54 -0700 | [diff] [blame] | 718 | .privileges(redfish::privileges::getActionInfo) |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 719 | .methods(boost::beast::http::verb::get)( |
| 720 | [](const crow::Request&, |
| 721 | const std::shared_ptr<bmcweb::AsyncResp>& asyncResp, |
| 722 | const std::string& chassisId) |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 723 | |
John Edward Broadbent | 7e860f1 | 2021-04-08 15:57:16 -0700 | [diff] [blame] | 724 | { |
| 725 | asyncResp->res.jsonValue = { |
| 726 | {"@odata.type", "#ActionInfo.v1_1_2.ActionInfo"}, |
| 727 | {"@odata.id", |
| 728 | "/redfish/v1/Chassis/" + chassisId + "/ResetActionInfo"}, |
| 729 | {"Name", "Reset Action Info"}, |
| 730 | {"Id", "ResetActionInfo"}, |
| 731 | {"Parameters", |
| 732 | {{{"Name", "ResetType"}, |
| 733 | {"Required", true}, |
| 734 | {"DataType", "String"}, |
| 735 | {"AllowableValues", {"PowerCycle"}}}}}}; |
| 736 | }); |
| 737 | } |
AppaRao Puli | 1cb1a9e | 2020-07-17 23:38:57 +0530 | [diff] [blame] | 738 | |
Ed Tanous | 1abe55e | 2018-09-05 08:30:59 -0700 | [diff] [blame] | 739 | } // namespace redfish |