Matt Spinler | 711d51d | 2019-11-06 09:36:51 -0600 | [diff] [blame] | 1 | /** |
| 2 | * Copyright © 2019 IBM 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 | */ |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 16 | #include "config.h" |
| 17 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 18 | #include "data_interface.hpp" |
| 19 | |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 20 | #include "util.hpp" |
| 21 | |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 22 | #include <fstream> |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 23 | #include <xyz/openbmc_project/State/OperatingSystem/Status/server.hpp> |
| 24 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 25 | namespace openpower |
| 26 | { |
| 27 | namespace pels |
| 28 | { |
| 29 | |
| 30 | namespace service_name |
| 31 | { |
| 32 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 33 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 34 | } // namespace service_name |
| 35 | |
| 36 | namespace object_path |
| 37 | { |
| 38 | constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper"; |
| 39 | constexpr auto systemInv = "/xyz/openbmc_project/inventory/system"; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 40 | constexpr auto chassisInv = "/xyz/openbmc_project/inventory/system/chassis"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 41 | constexpr auto baseInv = "/xyz/openbmc_project/inventory"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 42 | constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0"; |
| 43 | constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0"; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 44 | constexpr auto hostState = "/xyz/openbmc_project/state/host0"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 45 | constexpr auto pldm = "/xyz/openbmc_project/pldm"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 46 | constexpr auto enableHostPELs = |
| 47 | "/xyz/openbmc_project/logging/send_event_logs_to_host"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 48 | constexpr auto vpdManager = "/com/ibm/VPD/Manager"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 49 | } // namespace object_path |
| 50 | |
| 51 | namespace interface |
| 52 | { |
| 53 | constexpr auto dbusProperty = "org.freedesktop.DBus.Properties"; |
| 54 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
| 55 | constexpr auto invAsset = "xyz.openbmc_project.Inventory.Decorator.Asset"; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 56 | constexpr auto osStatus = "xyz.openbmc_project.State.OperatingSystem.Status"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 57 | constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 58 | constexpr auto enable = "xyz.openbmc_project.Object.Enable"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 59 | constexpr auto bmcState = "xyz.openbmc_project.State.BMC"; |
| 60 | constexpr auto chassisState = "xyz.openbmc_project.State.Chassis"; |
| 61 | constexpr auto hostState = "xyz.openbmc_project.State.Host"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 62 | constexpr auto invMotherboard = |
| 63 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"; |
| 64 | constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI"; |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 65 | constexpr auto locCode = "com.ibm.ipzvpd.Location"; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 66 | constexpr auto invCompatible = |
| 67 | "xyz.openbmc_project.Inventory.Decorator.Compatible"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 68 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 69 | } // namespace interface |
| 70 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 71 | using namespace sdbusplus::xyz::openbmc_project::State::OperatingSystem::server; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 72 | using sdbusplus::exception::SdBusError; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 73 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 74 | DataInterface::DataInterface(sdbusplus::bus::bus& bus) : _bus(bus) |
| 75 | { |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 76 | readBMCFWVersion(); |
| 77 | readServerFWVersion(); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 78 | readBMCFWVersionID(); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 79 | readMotherboardCCIN(); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 80 | |
| 81 | // Watch both the Model and SN properties on the system's Asset iface |
| 82 | _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>( |
| 83 | bus, object_path::systemInv, interface::invAsset, *this, |
| 84 | [this](const auto& properties) { |
| 85 | auto model = properties.find("Model"); |
| 86 | if (model != properties.end()) |
| 87 | { |
| 88 | this->_machineTypeModel = std::get<std::string>(model->second); |
| 89 | } |
| 90 | |
| 91 | auto sn = properties.find("SerialNumber"); |
| 92 | if (sn != properties.end()) |
| 93 | { |
| 94 | this->_machineSerialNumber = std::get<std::string>(sn->second); |
| 95 | } |
| 96 | })); |
| 97 | |
| 98 | // Watch the OperatingSystemState property |
| 99 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 100 | bus, object_path::hostState, interface::osStatus, |
| 101 | "OperatingSystemState", *this, [this](const auto& value) { |
| 102 | auto status = |
| 103 | Status::convertOSStatusFromString(std::get<std::string>(value)); |
| 104 | |
| 105 | if ((status == Status::OSStatus::BootComplete) || |
| 106 | (status == Status::OSStatus::Standby)) |
| 107 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 108 | setHostUp(true); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 109 | } |
| 110 | else |
| 111 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 112 | setHostUp(false); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 113 | } |
| 114 | })); |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 115 | |
| 116 | // Watch the host PEL enable property |
| 117 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 118 | bus, object_path::enableHostPELs, interface::enable, "Enabled", *this, |
| 119 | [this](const auto& value) { |
| 120 | this->_sendPELsToHost = std::get<bool>(value); |
| 121 | })); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 122 | |
| 123 | // Watch the BMCState property |
| 124 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 125 | bus, object_path::bmcState, interface::bmcState, "CurrentBMCState", |
| 126 | *this, [this](const auto& value) { |
| 127 | this->_bmcState = std::get<std::string>(value); |
| 128 | })); |
| 129 | |
| 130 | // Watch the chassis current and requested power state properties |
| 131 | _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>( |
| 132 | bus, object_path::chassisState, interface::chassisState, *this, |
| 133 | [this](const auto& properties) { |
| 134 | auto state = properties.find("CurrentPowerState"); |
| 135 | if (state != properties.end()) |
| 136 | { |
| 137 | this->_chassisState = std::get<std::string>(state->second); |
| 138 | } |
| 139 | |
| 140 | auto trans = properties.find("RequestedPowerTransition"); |
| 141 | if (trans != properties.end()) |
| 142 | { |
| 143 | this->_chassisTransition = std::get<std::string>(trans->second); |
| 144 | } |
| 145 | })); |
| 146 | |
| 147 | // Watch the CurrentHostState property |
| 148 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 149 | bus, object_path::hostState, interface::hostState, "CurrentHostState", |
| 150 | *this, [this](const auto& value) { |
| 151 | this->_hostState = std::get<std::string>(value); |
| 152 | })); |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 153 | |
| 154 | // Watch the compatible system names property |
| 155 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 156 | bus, object_path::chassisInv, interface::invCompatible, "Names", *this, |
| 157 | [this](const auto& value) { |
| 158 | this->_systemNames = std::get<std::vector<std::string>>(value); |
| 159 | })); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 160 | } |
| 161 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 162 | DBusPropertyMap |
| 163 | DataInterface::getAllProperties(const std::string& service, |
| 164 | const std::string& objectPath, |
| 165 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 166 | { |
| 167 | DBusPropertyMap properties; |
| 168 | |
| 169 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 170 | interface::dbusProperty, "GetAll"); |
| 171 | method.append(interface); |
| 172 | auto reply = _bus.call(method); |
| 173 | |
| 174 | reply.read(properties); |
| 175 | |
| 176 | return properties; |
| 177 | } |
| 178 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 179 | void DataInterface::getProperty(const std::string& service, |
| 180 | const std::string& objectPath, |
| 181 | const std::string& interface, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 182 | const std::string& property, |
| 183 | DBusValue& value) const |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 184 | { |
| 185 | |
| 186 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 187 | interface::dbusProperty, "Get"); |
| 188 | method.append(interface, property); |
| 189 | auto reply = _bus.call(method); |
| 190 | |
| 191 | reply.read(value); |
| 192 | } |
| 193 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 194 | DBusPathList DataInterface::getPaths(const DBusInterfaceList& interfaces) const |
| 195 | { |
| 196 | |
| 197 | auto method = _bus.new_method_call( |
| 198 | service_name::objectMapper, object_path::objectMapper, |
| 199 | interface::objectMapper, "GetSubTreePaths"); |
| 200 | |
| 201 | method.append(std::string{"/"}, 0, interfaces); |
| 202 | |
| 203 | auto reply = _bus.call(method); |
| 204 | |
| 205 | DBusPathList paths; |
| 206 | reply.read(paths); |
| 207 | |
| 208 | return paths; |
| 209 | } |
| 210 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 211 | DBusService DataInterface::getService(const std::string& objectPath, |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 212 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 213 | { |
| 214 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 215 | object_path::objectMapper, |
| 216 | interface::objectMapper, "GetObject"); |
| 217 | |
| 218 | method.append(objectPath, std::vector<std::string>({interface})); |
| 219 | |
| 220 | auto reply = _bus.call(method); |
| 221 | |
| 222 | std::map<DBusService, DBusInterfaceList> response; |
| 223 | reply.read(response); |
| 224 | |
| 225 | if (!response.empty()) |
| 226 | { |
| 227 | return response.begin()->first; |
| 228 | } |
| 229 | |
| 230 | return std::string{}; |
| 231 | } |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 232 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 233 | void DataInterface::readBMCFWVersion() |
| 234 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 235 | _bmcFWVersion = |
| 236 | phosphor::logging::util::getOSReleaseValue("VERSION").value_or(""); |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 237 | } |
| 238 | |
| 239 | void DataInterface::readServerFWVersion() |
| 240 | { |
| 241 | // Not available yet |
| 242 | } |
| 243 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 244 | void DataInterface::readBMCFWVersionID() |
| 245 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 246 | _bmcFWVersionID = |
| 247 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 248 | } |
| 249 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 250 | void DataInterface::readMotherboardCCIN() |
| 251 | { |
| 252 | try |
| 253 | { |
| 254 | // First, try to find the motherboard |
| 255 | auto motherboards = getPaths({interface::invMotherboard}); |
| 256 | if (motherboards.empty()) |
| 257 | { |
| 258 | throw std::runtime_error("No motherboards yet"); |
| 259 | } |
| 260 | |
| 261 | // Found it, so now get the CCIN |
| 262 | _properties.emplace_back( |
| 263 | std::make_unique<PropertyWatcher<DataInterface>>( |
| 264 | _bus, motherboards.front(), interface::viniRecordVPD, "CC", |
| 265 | *this, |
| 266 | [this](const auto& ccin) { this->setMotherboardCCIN(ccin); })); |
| 267 | } |
| 268 | catch (const std::exception& e) |
| 269 | { |
| 270 | // No motherboard in the inventory yet - watch for it |
| 271 | _inventoryIfacesAddedMatch = std::make_unique<sdbusplus::bus::match_t>( |
| 272 | _bus, match_rules::interfacesAdded(object_path::baseInv), |
| 273 | std::bind(std::mem_fn(&DataInterface::motherboardIfaceAdded), this, |
| 274 | std::placeholders::_1)); |
| 275 | } |
| 276 | } |
| 277 | |
| 278 | void DataInterface::motherboardIfaceAdded(sdbusplus::message::message& msg) |
| 279 | { |
| 280 | sdbusplus::message::object_path path; |
| 281 | DBusInterfaceMap interfaces; |
| 282 | |
| 283 | msg.read(path, interfaces); |
| 284 | |
| 285 | // This is watching the whole inventory, so check if it's what we want |
| 286 | if (interfaces.find(interface::invMotherboard) == interfaces.end()) |
| 287 | { |
| 288 | return; |
| 289 | } |
| 290 | |
| 291 | // Done watching for any new inventory interfaces |
| 292 | _inventoryIfacesAddedMatch.reset(); |
| 293 | |
| 294 | // Watch the motherboard CCIN, using the service from this signal |
| 295 | // for the initial property read. |
| 296 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 297 | _bus, path, interface::viniRecordVPD, "CC", msg.get_sender(), *this, |
| 298 | [this](const auto& ccin) { this->setMotherboardCCIN(ccin); })); |
| 299 | } |
| 300 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 301 | void DataInterface::getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 302 | std::string& fruPartNumber, |
| 303 | std::string& ccin, |
| 304 | std::string& serialNumber) const |
| 305 | { |
| 306 | // For now, attempt to get all of the properties directly on the path |
| 307 | // passed in. In the future, may need to make use of an algorithm |
| 308 | // to figure out which inventory objects actually hold these |
| 309 | // interfaces in the case of non FRUs, or possibly another service |
| 310 | // will provide this info. Any missing interfaces will result |
| 311 | // in exceptions being thrown. |
| 312 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 313 | auto service = getService(inventoryPath, interface::viniRecordVPD); |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 314 | |
| 315 | auto properties = |
| 316 | getAllProperties(service, inventoryPath, interface::viniRecordVPD); |
| 317 | |
| 318 | auto value = std::get<std::vector<uint8_t>>(properties["FN"]); |
| 319 | fruPartNumber = std::string{value.begin(), value.end()}; |
| 320 | |
| 321 | value = std::get<std::vector<uint8_t>>(properties["CC"]); |
| 322 | ccin = std::string{value.begin(), value.end()}; |
| 323 | |
| 324 | value = std::get<std::vector<uint8_t>>(properties["SN"]); |
| 325 | serialNumber = std::string{value.begin(), value.end()}; |
| 326 | } |
| 327 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 328 | std::string |
| 329 | DataInterface::getLocationCode(const std::string& inventoryPath) const |
| 330 | { |
| 331 | auto service = getService(inventoryPath, interface::locCode); |
| 332 | |
| 333 | DBusValue locCode; |
| 334 | getProperty(service, inventoryPath, interface::locCode, "LocationCode", |
| 335 | locCode); |
| 336 | |
| 337 | return std::get<std::string>(locCode); |
| 338 | } |
| 339 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 340 | std::string |
| 341 | DataInterface::addLocationCodePrefix(const std::string& locationCode) |
| 342 | { |
| 343 | static const std::string locationCodePrefix{"Ufcs-"}; |
| 344 | |
Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 345 | // Technically there are 2 location code prefixes, Ufcs and Umts, so |
| 346 | // if it already starts with a U then don't need to do anything. |
| 347 | if (locationCode.front() != 'U') |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 348 | { |
| 349 | return locationCodePrefix + locationCode; |
| 350 | } |
| 351 | |
| 352 | return locationCode; |
| 353 | } |
| 354 | |
| 355 | std::string DataInterface::expandLocationCode(const std::string& locationCode, |
| 356 | uint16_t node) const |
| 357 | { |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 358 | auto method = |
| 359 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 360 | interface::vpdManager, "GetExpandedLocationCode"); |
| 361 | |
| 362 | method.append(addLocationCodePrefix(locationCode), |
| 363 | static_cast<uint16_t>(0)); |
| 364 | |
| 365 | auto reply = _bus.call(method); |
| 366 | |
| 367 | std::string expandedLocationCode; |
| 368 | reply.read(expandedLocationCode); |
| 369 | |
| 370 | return expandedLocationCode; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 371 | } |
| 372 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 373 | std::string |
| 374 | DataInterface::getInventoryFromLocCode(const std::string& locationCode, |
| 375 | uint16_t node, bool expanded) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 376 | { |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 377 | std::string methodName = expanded ? "GetFRUsByExpandedLocationCode" |
| 378 | : "GetFRUsByUnexpandedLocationCode"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 379 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 380 | auto method = |
| 381 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 382 | interface::vpdManager, methodName.c_str()); |
| 383 | |
| 384 | if (expanded) |
| 385 | { |
| 386 | method.append(locationCode); |
| 387 | } |
| 388 | else |
| 389 | { |
| 390 | method.append(addLocationCodePrefix(locationCode), node); |
| 391 | } |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 392 | |
| 393 | auto reply = _bus.call(method); |
| 394 | |
| 395 | std::vector<sdbusplus::message::object_path> entries; |
| 396 | reply.read(entries); |
| 397 | |
| 398 | // Get the shortest entry from the paths received, as this |
| 399 | // would be the path furthest up the inventory hierarchy so |
| 400 | // would be the parent FRU. There is guaranteed to at least |
| 401 | // be one entry if the call didn't fail. |
| 402 | std::string shortest{entries[0]}; |
| 403 | |
| 404 | std::for_each(entries.begin(), entries.end(), |
| 405 | [&shortest](const auto& path) { |
| 406 | if (path.str.size() < shortest.size()) |
| 407 | { |
| 408 | shortest = path; |
| 409 | } |
| 410 | }); |
| 411 | |
| 412 | return shortest; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 413 | } |
| 414 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 415 | } // namespace pels |
| 416 | } // namespace openpower |