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 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 22 | #include <fmt/format.h> |
| 23 | |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 24 | #include <fstream> |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 25 | #include <iterator> |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 26 | #include <phosphor-logging/log.hpp> |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 27 | #include <xyz/openbmc_project/State/Boot/Progress/server.hpp> |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 28 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 29 | namespace openpower |
| 30 | { |
| 31 | namespace pels |
| 32 | { |
| 33 | |
| 34 | namespace service_name |
| 35 | { |
| 36 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 37 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 38 | constexpr auto ledGroupManager = "xyz.openbmc_project.LED.GroupManager"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 39 | constexpr auto logSetting = "xyz.openbmc_project.Settings"; |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 40 | constexpr auto hwIsolation = "org.open_power.HardwareIsolation"; |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 41 | constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 42 | } // namespace service_name |
| 43 | |
| 44 | namespace object_path |
| 45 | { |
| 46 | constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper"; |
| 47 | constexpr auto systemInv = "/xyz/openbmc_project/inventory/system"; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 48 | constexpr auto chassisInv = "/xyz/openbmc_project/inventory/system/chassis"; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 49 | constexpr auto motherBoardInv = |
| 50 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 51 | constexpr auto baseInv = "/xyz/openbmc_project/inventory"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 52 | constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0"; |
| 53 | constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0"; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 54 | constexpr auto hostState = "/xyz/openbmc_project/state/host0"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 55 | constexpr auto pldm = "/xyz/openbmc_project/pldm"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 56 | constexpr auto enableHostPELs = |
| 57 | "/xyz/openbmc_project/logging/send_event_logs_to_host"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 58 | constexpr auto vpdManager = "/com/ibm/VPD/Manager"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 59 | constexpr auto logSetting = "/xyz/openbmc_project/logging/settings"; |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 60 | constexpr auto hwIsolation = "/xyz/openbmc_project/hardware_isolation"; |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 61 | constexpr auto bootRawSetting = "/xyz/openbmc_project/state/boot/raw0"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 62 | } // namespace object_path |
| 63 | |
| 64 | namespace interface |
| 65 | { |
| 66 | constexpr auto dbusProperty = "org.freedesktop.DBus.Properties"; |
| 67 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
| 68 | constexpr auto invAsset = "xyz.openbmc_project.Inventory.Decorator.Asset"; |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 69 | constexpr auto bootProgress = "xyz.openbmc_project.State.Boot.Progress"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 70 | constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 71 | constexpr auto enable = "xyz.openbmc_project.Object.Enable"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 72 | constexpr auto bmcState = "xyz.openbmc_project.State.BMC"; |
| 73 | constexpr auto chassisState = "xyz.openbmc_project.State.Chassis"; |
| 74 | constexpr auto hostState = "xyz.openbmc_project.State.Host"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 75 | constexpr auto invMotherboard = |
| 76 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"; |
| 77 | constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI"; |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 78 | constexpr auto vsbpRecordVPD = "com.ibm.ipzvpd.VSBP"; |
Matt Spinler | cc8b111 | 2021-12-15 09:30:35 -0600 | [diff] [blame] | 79 | constexpr auto locCode = "xyz.openbmc_project.Inventory.Decorator.LocationCode"; |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 80 | constexpr auto compatible = |
| 81 | "xyz.openbmc_project.Configuration.IBMCompatibleSystem"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 82 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 83 | constexpr auto ledGroup = "xyz.openbmc_project.Led.Group"; |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 84 | constexpr auto operationalStatus = |
| 85 | "xyz.openbmc_project.State.Decorator.OperationalStatus"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 86 | constexpr auto logSetting = "xyz.openbmc_project.Logging.Settings"; |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 87 | constexpr auto associationDef = "xyz.openbmc_project.Association.Definitions"; |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 88 | constexpr auto dumpEntry = "xyz.openbmc_project.Dump.Entry"; |
| 89 | constexpr auto dumpProgress = "xyz.openbmc_project.Common.Progress"; |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 90 | constexpr auto hwIsolationCreate = "org.open_power.HardwareIsolation.Create"; |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 91 | constexpr auto bootRawProgress = "xyz.openbmc_project.State.Boot.Raw"; |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 92 | constexpr auto hwIsolationEntry = "xyz.openbmc_project.HardwareIsolation.Entry"; |
| 93 | constexpr auto association = "xyz.openbmc_project.Association"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 94 | } // namespace interface |
| 95 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 96 | using namespace sdbusplus::xyz::openbmc_project::State::Boot::server; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 97 | using namespace phosphor::logging; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 98 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 99 | std::pair<std::string, std::string> |
| 100 | DataInterfaceBase::extractConnectorFromLocCode( |
| 101 | const std::string& locationCode) |
| 102 | { |
| 103 | auto base = locationCode; |
| 104 | std::string connector{}; |
| 105 | |
| 106 | auto pos = base.find("-T"); |
| 107 | if (pos != std::string::npos) |
| 108 | { |
| 109 | connector = base.substr(pos); |
| 110 | base = base.substr(0, pos); |
| 111 | } |
| 112 | |
| 113 | return {base, connector}; |
| 114 | } |
| 115 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 116 | DataInterface::DataInterface(sdbusplus::bus::bus& bus) : _bus(bus) |
| 117 | { |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 118 | readBMCFWVersion(); |
| 119 | readServerFWVersion(); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 120 | readBMCFWVersionID(); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 121 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 122 | // Watch the BootProgress property |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 123 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 124 | bus, object_path::hostState, interface::bootProgress, "BootProgress", |
| 125 | *this, [this](const auto& value) { |
Sumit Kumar | 2c36fdd | 2021-09-21 03:12:11 -0500 | [diff] [blame] | 126 | this->_bootState = std::get<std::string>(value); |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 127 | auto status = Progress::convertProgressStagesFromString( |
| 128 | std::get<std::string>(value)); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 129 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 130 | if ((status == Progress::ProgressStages::SystemInitComplete) || |
| 131 | (status == Progress::ProgressStages::OSStart) || |
| 132 | (status == Progress::ProgressStages::OSRunning)) |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 133 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 134 | setHostUp(true); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 135 | } |
| 136 | else |
| 137 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 138 | setHostUp(false); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 139 | } |
| 140 | })); |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 141 | |
| 142 | // Watch the host PEL enable property |
| 143 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 144 | bus, object_path::enableHostPELs, interface::enable, "Enabled", *this, |
| 145 | [this](const auto& value) { |
Matt Spinler | c6ee7c5 | 2022-01-14 13:21:53 -0600 | [diff] [blame] | 146 | if (std::get<bool>(value) != this->_sendPELsToHost) |
| 147 | { |
| 148 | log<level::INFO>( |
| 149 | fmt::format("The send PELs to host setting changed to {}", |
| 150 | std::get<bool>(value)) |
| 151 | .c_str()); |
| 152 | } |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 153 | this->_sendPELsToHost = std::get<bool>(value); |
| 154 | })); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 155 | |
| 156 | // Watch the BMCState property |
| 157 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 158 | bus, object_path::bmcState, interface::bmcState, "CurrentBMCState", |
| 159 | *this, [this](const auto& value) { |
| 160 | this->_bmcState = std::get<std::string>(value); |
| 161 | })); |
| 162 | |
| 163 | // Watch the chassis current and requested power state properties |
| 164 | _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>( |
| 165 | bus, object_path::chassisState, interface::chassisState, *this, |
| 166 | [this](const auto& properties) { |
| 167 | auto state = properties.find("CurrentPowerState"); |
| 168 | if (state != properties.end()) |
| 169 | { |
| 170 | this->_chassisState = std::get<std::string>(state->second); |
| 171 | } |
| 172 | |
| 173 | auto trans = properties.find("RequestedPowerTransition"); |
| 174 | if (trans != properties.end()) |
| 175 | { |
| 176 | this->_chassisTransition = std::get<std::string>(trans->second); |
| 177 | } |
| 178 | })); |
| 179 | |
| 180 | // Watch the CurrentHostState property |
| 181 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 182 | bus, object_path::hostState, interface::hostState, "CurrentHostState", |
| 183 | *this, [this](const auto& value) { |
| 184 | this->_hostState = std::get<std::string>(value); |
| 185 | })); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 186 | } |
| 187 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 188 | DBusPropertyMap |
| 189 | DataInterface::getAllProperties(const std::string& service, |
| 190 | const std::string& objectPath, |
| 191 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 192 | { |
| 193 | DBusPropertyMap properties; |
| 194 | |
| 195 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 196 | interface::dbusProperty, "GetAll"); |
| 197 | method.append(interface); |
| 198 | auto reply = _bus.call(method); |
| 199 | |
| 200 | reply.read(properties); |
| 201 | |
| 202 | return properties; |
| 203 | } |
| 204 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 205 | void DataInterface::getProperty(const std::string& service, |
| 206 | const std::string& objectPath, |
| 207 | const std::string& interface, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 208 | const std::string& property, |
| 209 | DBusValue& value) const |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 210 | { |
| 211 | |
| 212 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 213 | interface::dbusProperty, "Get"); |
| 214 | method.append(interface, property); |
| 215 | auto reply = _bus.call(method); |
| 216 | |
| 217 | reply.read(value); |
| 218 | } |
| 219 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 220 | DBusPathList DataInterface::getPaths(const DBusInterfaceList& interfaces) const |
| 221 | { |
| 222 | |
| 223 | auto method = _bus.new_method_call( |
| 224 | service_name::objectMapper, object_path::objectMapper, |
| 225 | interface::objectMapper, "GetSubTreePaths"); |
| 226 | |
| 227 | method.append(std::string{"/"}, 0, interfaces); |
| 228 | |
| 229 | auto reply = _bus.call(method); |
| 230 | |
| 231 | DBusPathList paths; |
| 232 | reply.read(paths); |
| 233 | |
| 234 | return paths; |
| 235 | } |
| 236 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 237 | DBusService DataInterface::getService(const std::string& objectPath, |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 238 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 239 | { |
| 240 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 241 | object_path::objectMapper, |
| 242 | interface::objectMapper, "GetObject"); |
| 243 | |
| 244 | method.append(objectPath, std::vector<std::string>({interface})); |
| 245 | |
| 246 | auto reply = _bus.call(method); |
| 247 | |
| 248 | std::map<DBusService, DBusInterfaceList> response; |
| 249 | reply.read(response); |
| 250 | |
| 251 | if (!response.empty()) |
| 252 | { |
| 253 | return response.begin()->first; |
| 254 | } |
| 255 | |
| 256 | return std::string{}; |
| 257 | } |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 258 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 259 | void DataInterface::readBMCFWVersion() |
| 260 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 261 | _bmcFWVersion = |
| 262 | phosphor::logging::util::getOSReleaseValue("VERSION").value_or(""); |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 263 | } |
| 264 | |
| 265 | void DataInterface::readServerFWVersion() |
| 266 | { |
Sumit Kumar | cad1620 | 2021-05-13 04:06:15 -0500 | [diff] [blame] | 267 | auto value = |
| 268 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
| 269 | if ((value != "") && (value.find_last_of(')') != std::string::npos)) |
| 270 | { |
| 271 | std::size_t pos = value.find_first_of('(') + 1; |
| 272 | _serverFWVersion = value.substr(pos, value.find_last_of(')') - pos); |
| 273 | } |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 274 | } |
| 275 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 276 | void DataInterface::readBMCFWVersionID() |
| 277 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 278 | _bmcFWVersionID = |
| 279 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 280 | } |
| 281 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 282 | std::string DataInterface::getMachineTypeModel() const |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 283 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 284 | std::string model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 285 | try |
| 286 | { |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 287 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 288 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 289 | if (!service.empty()) |
| 290 | { |
| 291 | DBusValue value; |
| 292 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 293 | "Model", value); |
| 294 | |
| 295 | model = std::get<std::string>(value); |
| 296 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 297 | } |
| 298 | catch (const std::exception& e) |
| 299 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 300 | log<level::WARNING>(fmt::format("Failed reading Model property from " |
| 301 | "Interface: {} exception: {}", |
| 302 | interface::invAsset, e.what()) |
| 303 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 304 | } |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 305 | |
| 306 | return model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 307 | } |
| 308 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 309 | std::string DataInterface::getMachineSerialNumber() const |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 310 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 311 | std::string sn; |
| 312 | try |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 313 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 314 | |
| 315 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 316 | if (!service.empty()) |
| 317 | { |
| 318 | DBusValue value; |
| 319 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 320 | "SerialNumber", value); |
| 321 | |
| 322 | sn = std::get<std::string>(value); |
| 323 | } |
| 324 | } |
| 325 | catch (const std::exception& e) |
| 326 | { |
| 327 | log<level::WARNING>( |
| 328 | fmt::format("Failed reading SerialNumber property from " |
| 329 | "Interface: {} exception: {}", |
| 330 | interface::invAsset, e.what()) |
| 331 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 332 | } |
| 333 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 334 | return sn; |
| 335 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 336 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 337 | std::string DataInterface::getMotherboardCCIN() const |
| 338 | { |
| 339 | std::string ccin; |
| 340 | |
| 341 | try |
| 342 | { |
| 343 | auto service = |
| 344 | getService(object_path::motherBoardInv, interface::viniRecordVPD); |
| 345 | if (!service.empty()) |
| 346 | { |
| 347 | DBusValue value; |
| 348 | getProperty(service, object_path::motherBoardInv, |
| 349 | interface::viniRecordVPD, "CC", value); |
| 350 | |
| 351 | auto cc = std::get<std::vector<uint8_t>>(value); |
| 352 | ccin = std::string{cc.begin(), cc.end()}; |
| 353 | } |
| 354 | } |
| 355 | catch (const std::exception& e) |
| 356 | { |
| 357 | log<level::WARNING>( |
| 358 | fmt::format("Failed reading Motherboard CCIN property from " |
| 359 | "Interface: {} exception: {}", |
| 360 | interface::viniRecordVPD, e.what()) |
| 361 | .c_str()); |
| 362 | } |
| 363 | |
| 364 | return ccin; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 365 | } |
| 366 | |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 367 | std::vector<uint8_t> DataInterface::getSystemIMKeyword() const |
| 368 | { |
| 369 | std::vector<uint8_t> systemIM; |
| 370 | |
| 371 | try |
| 372 | { |
| 373 | auto service = |
| 374 | getService(object_path::motherBoardInv, interface::vsbpRecordVPD); |
| 375 | if (!service.empty()) |
| 376 | { |
| 377 | DBusValue value; |
| 378 | getProperty(service, object_path::motherBoardInv, |
| 379 | interface::vsbpRecordVPD, "IM", value); |
| 380 | |
| 381 | systemIM = std::get<std::vector<uint8_t>>(value); |
| 382 | } |
| 383 | } |
| 384 | catch (const std::exception& e) |
| 385 | { |
| 386 | log<level::WARNING>( |
| 387 | fmt::format("Failed reading System IM property from " |
| 388 | "Interface: {} exception: {}", |
| 389 | interface::vsbpRecordVPD, e.what()) |
| 390 | .c_str()); |
| 391 | } |
| 392 | |
| 393 | return systemIM; |
| 394 | } |
| 395 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 396 | void DataInterface::getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 397 | std::string& fruPartNumber, |
| 398 | std::string& ccin, |
| 399 | std::string& serialNumber) const |
| 400 | { |
| 401 | // For now, attempt to get all of the properties directly on the path |
| 402 | // passed in. In the future, may need to make use of an algorithm |
| 403 | // to figure out which inventory objects actually hold these |
| 404 | // interfaces in the case of non FRUs, or possibly another service |
| 405 | // will provide this info. Any missing interfaces will result |
| 406 | // in exceptions being thrown. |
| 407 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 408 | auto service = getService(inventoryPath, interface::viniRecordVPD); |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 409 | |
| 410 | auto properties = |
| 411 | getAllProperties(service, inventoryPath, interface::viniRecordVPD); |
| 412 | |
| 413 | auto value = std::get<std::vector<uint8_t>>(properties["FN"]); |
| 414 | fruPartNumber = std::string{value.begin(), value.end()}; |
| 415 | |
| 416 | value = std::get<std::vector<uint8_t>>(properties["CC"]); |
| 417 | ccin = std::string{value.begin(), value.end()}; |
| 418 | |
| 419 | value = std::get<std::vector<uint8_t>>(properties["SN"]); |
| 420 | serialNumber = std::string{value.begin(), value.end()}; |
| 421 | } |
| 422 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 423 | std::string |
| 424 | DataInterface::getLocationCode(const std::string& inventoryPath) const |
| 425 | { |
| 426 | auto service = getService(inventoryPath, interface::locCode); |
| 427 | |
| 428 | DBusValue locCode; |
| 429 | getProperty(service, inventoryPath, interface::locCode, "LocationCode", |
| 430 | locCode); |
| 431 | |
| 432 | return std::get<std::string>(locCode); |
| 433 | } |
| 434 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 435 | std::string |
| 436 | DataInterface::addLocationCodePrefix(const std::string& locationCode) |
| 437 | { |
| 438 | static const std::string locationCodePrefix{"Ufcs-"}; |
| 439 | |
Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 440 | // Technically there are 2 location code prefixes, Ufcs and Umts, so |
| 441 | // if it already starts with a U then don't need to do anything. |
| 442 | if (locationCode.front() != 'U') |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 443 | { |
| 444 | return locationCodePrefix + locationCode; |
| 445 | } |
| 446 | |
| 447 | return locationCode; |
| 448 | } |
| 449 | |
| 450 | std::string DataInterface::expandLocationCode(const std::string& locationCode, |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 451 | uint16_t /*node*/) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 452 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 453 | // Location codes for connectors are the location code of the FRU they are |
| 454 | // on, plus a '-Tx' segment. Remove this last segment before expanding it |
| 455 | // and then add it back in afterwards. This way, the connector doesn't have |
| 456 | // to be in the model just so that it can be expanded. |
| 457 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 458 | |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 459 | auto method = |
| 460 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 461 | interface::vpdManager, "GetExpandedLocationCode"); |
| 462 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 463 | method.append(addLocationCodePrefix(baseLoc), static_cast<uint16_t>(0)); |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 464 | |
| 465 | auto reply = _bus.call(method); |
| 466 | |
| 467 | std::string expandedLocationCode; |
| 468 | reply.read(expandedLocationCode); |
| 469 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 470 | if (!connectorLoc.empty()) |
| 471 | { |
| 472 | expandedLocationCode += connectorLoc; |
| 473 | } |
| 474 | |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 475 | return expandedLocationCode; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 476 | } |
| 477 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 478 | std::string |
| 479 | DataInterface::getInventoryFromLocCode(const std::string& locationCode, |
| 480 | uint16_t node, bool expanded) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 481 | { |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 482 | std::string methodName = expanded ? "GetFRUsByExpandedLocationCode" |
| 483 | : "GetFRUsByUnexpandedLocationCode"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 484 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 485 | // Remove the connector segment, if present, so that this method call |
| 486 | // returns an inventory path that getHWCalloutFields() can be used with. |
| 487 | // (The serial number, etc, aren't stored on the connector in the |
| 488 | // inventory, and may not even be modeled.) |
| 489 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 490 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 491 | auto method = |
| 492 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 493 | interface::vpdManager, methodName.c_str()); |
| 494 | |
| 495 | if (expanded) |
| 496 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 497 | method.append(baseLoc); |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 498 | } |
| 499 | else |
| 500 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 501 | method.append(addLocationCodePrefix(baseLoc), node); |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 502 | } |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 503 | |
| 504 | auto reply = _bus.call(method); |
| 505 | |
| 506 | std::vector<sdbusplus::message::object_path> entries; |
| 507 | reply.read(entries); |
| 508 | |
| 509 | // Get the shortest entry from the paths received, as this |
| 510 | // would be the path furthest up the inventory hierarchy so |
| 511 | // would be the parent FRU. There is guaranteed to at least |
| 512 | // be one entry if the call didn't fail. |
| 513 | std::string shortest{entries[0]}; |
| 514 | |
| 515 | std::for_each(entries.begin(), entries.end(), |
| 516 | [&shortest](const auto& path) { |
| 517 | if (path.str.size() < shortest.size()) |
| 518 | { |
| 519 | shortest = path; |
| 520 | } |
| 521 | }); |
| 522 | |
| 523 | return shortest; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 524 | } |
| 525 | |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 526 | void DataInterface::assertLEDGroup(const std::string& ledGroup, |
| 527 | bool value) const |
| 528 | { |
| 529 | DBusValue variant = value; |
| 530 | auto method = |
| 531 | _bus.new_method_call(service_name::ledGroupManager, ledGroup.c_str(), |
| 532 | interface::dbusProperty, "Set"); |
| 533 | method.append(interface::ledGroup, "Asserted", variant); |
| 534 | _bus.call(method); |
| 535 | } |
| 536 | |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 537 | void DataInterface::setFunctional(const std::string& objectPath, |
| 538 | bool value) const |
| 539 | { |
| 540 | DBusValue variant = value; |
| 541 | auto service = getService(objectPath, interface::operationalStatus); |
| 542 | |
| 543 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 544 | interface::dbusProperty, "Set"); |
| 545 | |
| 546 | method.append(interface::operationalStatus, "Functional", variant); |
| 547 | _bus.call(method); |
| 548 | } |
| 549 | |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 550 | using AssociationTuple = std::tuple<std::string, std::string, std::string>; |
| 551 | using AssociationsProperty = std::vector<AssociationTuple>; |
| 552 | |
| 553 | void DataInterface::setCriticalAssociation(const std::string& objectPath) const |
| 554 | { |
| 555 | DBusValue getAssociationValue; |
| 556 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 557 | auto service = getService(objectPath, interface::associationDef); |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 558 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 559 | getProperty(service, objectPath, interface::associationDef, "Associations", |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 560 | getAssociationValue); |
| 561 | |
| 562 | auto association = std::get<AssociationsProperty>(getAssociationValue); |
| 563 | |
| 564 | AssociationTuple critAssociation{ |
| 565 | "health_rollup", "critical", |
| 566 | "/xyz/openbmc_project/inventory/system/chassis"}; |
| 567 | |
| 568 | if (std::find(association.begin(), association.end(), critAssociation) == |
| 569 | association.end()) |
| 570 | { |
| 571 | association.push_back(critAssociation); |
| 572 | DBusValue setAssociationValue = association; |
| 573 | |
| 574 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 575 | interface::dbusProperty, "Set"); |
| 576 | |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 577 | method.append(interface::associationDef, "Associations", |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 578 | setAssociationValue); |
| 579 | _bus.call(method); |
| 580 | } |
| 581 | } |
| 582 | |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 583 | std::vector<std::string> DataInterface::getSystemNames() const |
| 584 | { |
| 585 | DBusSubTree subtree; |
| 586 | DBusValue names; |
| 587 | |
| 588 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 589 | object_path::objectMapper, |
| 590 | interface::objectMapper, "GetSubTree"); |
| 591 | method.append(std::string{"/"}, 0, |
| 592 | std::vector<std::string>{interface::compatible}); |
| 593 | auto reply = _bus.call(method); |
| 594 | |
| 595 | reply.read(subtree); |
| 596 | if (subtree.empty()) |
| 597 | { |
| 598 | throw std::runtime_error("Compatible interface not on D-Bus"); |
| 599 | } |
| 600 | |
| 601 | const auto& object = *(subtree.begin()); |
| 602 | const auto& path = object.first; |
| 603 | const auto& service = object.second.begin()->first; |
| 604 | |
| 605 | getProperty(service, path, interface::compatible, "Names", names); |
| 606 | |
| 607 | return std::get<std::vector<std::string>>(names); |
| 608 | } |
| 609 | |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 610 | bool DataInterface::getQuiesceOnError() const |
| 611 | { |
| 612 | bool ret = false; |
| 613 | |
| 614 | try |
| 615 | { |
| 616 | auto service = |
| 617 | getService(object_path::logSetting, interface::logSetting); |
| 618 | if (!service.empty()) |
| 619 | { |
| 620 | DBusValue value; |
| 621 | getProperty(service, object_path::logSetting, interface::logSetting, |
| 622 | "QuiesceOnHwError", value); |
| 623 | |
| 624 | ret = std::get<bool>(value); |
| 625 | } |
| 626 | } |
| 627 | catch (const std::exception& e) |
| 628 | { |
| 629 | log<level::WARNING>( |
| 630 | fmt::format("Failed reading QuiesceOnHwError property from " |
| 631 | "Interface: {} exception: {}", |
| 632 | interface::logSetting, e.what()) |
| 633 | .c_str()); |
| 634 | } |
| 635 | |
| 636 | return ret; |
| 637 | } |
| 638 | |
Sumit Kumar | 9d43a72 | 2021-08-24 09:46:19 -0500 | [diff] [blame] | 639 | std::vector<bool> |
| 640 | DataInterface::checkDumpStatus(const std::vector<std::string>& type) const |
| 641 | { |
| 642 | DBusSubTree subtree; |
| 643 | std::vector<bool> result(type.size(), false); |
| 644 | |
| 645 | // Query GetSubTree for the availability of dump interface |
| 646 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 647 | object_path::objectMapper, |
| 648 | interface::objectMapper, "GetSubTree"); |
| 649 | method.append(std::string{"/"}, 0, |
| 650 | std::vector<std::string>{interface::dumpEntry}); |
| 651 | auto reply = _bus.call(method); |
| 652 | |
| 653 | reply.read(subtree); |
| 654 | |
| 655 | if (subtree.empty()) |
| 656 | { |
| 657 | return result; |
| 658 | } |
| 659 | |
| 660 | std::vector<bool>::iterator itDumpStatus = result.begin(); |
| 661 | uint8_t count = 0; |
| 662 | for (const auto& [path, serviceInfo] : subtree) |
| 663 | { |
| 664 | const auto& service = serviceInfo.begin()->first; |
| 665 | // Check for dump type on the object path |
| 666 | for (const auto& it : type) |
| 667 | { |
| 668 | if (path.find(it) != std::string::npos) |
| 669 | { |
| 670 | DBusValue value, progress; |
| 671 | |
| 672 | // If dump type status is already available go for next path |
| 673 | if (*itDumpStatus) |
| 674 | { |
| 675 | break; |
| 676 | } |
| 677 | |
| 678 | // Check for valid dump to be available if following |
| 679 | // conditions are met for the dump entry path - |
| 680 | // Offloaded == false and Status == Completed |
| 681 | getProperty(service, path, interface::dumpEntry, "Offloaded", |
| 682 | value); |
| 683 | getProperty(service, path, interface::dumpProgress, "Status", |
| 684 | progress); |
| 685 | auto offload = std::get<bool>(value); |
| 686 | auto status = std::get<std::string>(progress); |
| 687 | if (!offload && (status.find("Completed") != std::string::npos)) |
| 688 | { |
| 689 | *itDumpStatus = true; |
| 690 | count++; |
| 691 | if (count >= type.size()) |
| 692 | { |
| 693 | return result; |
| 694 | } |
| 695 | break; |
| 696 | } |
| 697 | } |
| 698 | itDumpStatus++; |
| 699 | } |
| 700 | itDumpStatus = result.begin(); |
| 701 | } |
| 702 | |
| 703 | return result; |
| 704 | } |
| 705 | |
Jayanth Othayoth | ecaa2fc | 2021-11-05 02:02:52 -0500 | [diff] [blame] | 706 | void DataInterface::createGuardRecord(const std::vector<uint8_t>& binPath, |
| 707 | const std::string& type, |
| 708 | const std::string& logPath) const |
| 709 | { |
| 710 | try |
| 711 | { |
| 712 | auto method = _bus.new_method_call( |
| 713 | service_name::hwIsolation, object_path::hwIsolation, |
| 714 | interface::hwIsolationCreate, "CreateWithEntityPath"); |
| 715 | method.append(binPath, type, sdbusplus::message::object_path(logPath)); |
| 716 | // Note: hw isolation "CreateWithEntityPath" got dependency on logging |
| 717 | // api's. Making d-bus call no reply type to avoid cyclic dependency. |
| 718 | // Added minimal timeout to catch initial failures. |
| 719 | // Need to revisit this design later to avoid cyclic dependency. |
| 720 | constexpr auto dbusTimeout = 100000; // in micro seconds |
| 721 | _bus.call_noreply(method, dbusTimeout); |
| 722 | } |
| 723 | |
| 724 | catch (const sdbusplus::exception::exception& e) |
| 725 | { |
| 726 | std::string errName = e.name(); |
| 727 | // SD_BUS_ERROR_TIMEOUT error is expected, due to PEL api dependency |
| 728 | // mentioned above. Ignoring the error. |
| 729 | if (errName != SD_BUS_ERROR_TIMEOUT) |
| 730 | { |
| 731 | log<level::ERR>( |
| 732 | fmt::format("GUARD D-Bus call exception" |
| 733 | "OBJPATH={}, INTERFACE={}, EXCEPTION={}", |
| 734 | object_path::hwIsolation, |
| 735 | interface::hwIsolationCreate, e.what()) |
| 736 | .c_str()); |
| 737 | } |
| 738 | } |
| 739 | } |
Sumit Kumar | 3e27443 | 2021-09-14 06:37:56 -0500 | [diff] [blame] | 740 | |
| 741 | void DataInterface::createProgressSRC( |
| 742 | const uint64_t& priSRC, const std::vector<uint8_t>& srcStruct) const |
| 743 | { |
| 744 | DBusValue variant = std::make_tuple(priSRC, srcStruct); |
| 745 | |
| 746 | auto method = _bus.new_method_call(service_name::bootRawProgress, |
| 747 | object_path::bootRawSetting, |
| 748 | interface::dbusProperty, "Set"); |
| 749 | |
| 750 | method.append(interface::bootRawProgress, "Value", variant); |
| 751 | |
| 752 | _bus.call(method); |
| 753 | } |
Sumit Kumar | 027bf28 | 2022-01-24 11:25:19 -0600 | [diff] [blame] | 754 | |
| 755 | std::vector<uint32_t> DataInterface::getLogIDWithHwIsolation() const |
| 756 | { |
| 757 | std::vector<std::string> association = {"xyz.openbmc_project.Association"}; |
| 758 | std::string hwErrorLog = "/isolated_hw_errorlog"; |
| 759 | std::string errorLog = "/error_log"; |
| 760 | DBusPathList paths; |
| 761 | std::vector<uint32_t> ids; |
| 762 | |
| 763 | // Get all latest mapper associations |
| 764 | paths = getPaths(association); |
| 765 | for (auto& path : paths) |
| 766 | { |
| 767 | // Look for object path with hardware isolation entry if any |
| 768 | size_t pos = path.find(hwErrorLog); |
| 769 | if (pos != std::string::npos) |
| 770 | { |
| 771 | // Get the object path |
| 772 | std::string ph = path; |
| 773 | ph.erase(pos, hwErrorLog.length()); |
| 774 | auto service = getService(ph, interface::hwIsolationEntry); |
| 775 | if (!service.empty()) |
| 776 | { |
| 777 | bool status; |
| 778 | DBusValue value; |
| 779 | |
| 780 | // Read the Resolved property from object path |
| 781 | getProperty(service, ph, interface::hwIsolationEntry, |
| 782 | "Resolved", value); |
| 783 | |
| 784 | status = std::get<bool>(value); |
| 785 | |
| 786 | // If the entry isn't resolved |
| 787 | if (!status) |
| 788 | { |
| 789 | auto service = getService(path, interface::association); |
| 790 | if (!service.empty()) |
| 791 | { |
| 792 | DBusValue value; |
| 793 | |
| 794 | // Read Endpoints property |
| 795 | getProperty(service, path, interface::association, |
| 796 | "endpoints", value); |
| 797 | |
| 798 | auto logPath = |
| 799 | std::get<std::vector<std::string>>(value); |
| 800 | if (!logPath.empty()) |
| 801 | { |
| 802 | // Get OpenBMC event log Id |
| 803 | uint32_t id = stoi(logPath[0].substr( |
| 804 | logPath[0].find_last_of('/') + 1)); |
| 805 | ids.push_back(id); |
| 806 | } |
| 807 | } |
| 808 | } |
| 809 | } |
| 810 | } |
| 811 | |
| 812 | // Look for object path with error_log entry if any |
| 813 | pos = path.find(errorLog); |
| 814 | if (pos != std::string::npos) |
| 815 | { |
| 816 | auto service = getService(path, interface::association); |
| 817 | if (!service.empty()) |
| 818 | { |
| 819 | DBusValue value; |
| 820 | |
| 821 | // Read Endpoints property |
| 822 | getProperty(service, path, interface::association, "endpoints", |
| 823 | value); |
| 824 | |
| 825 | auto logPath = std::get<std::vector<std::string>>(value); |
| 826 | if (!logPath.empty()) |
| 827 | { |
| 828 | // Get OpenBMC event log Id |
| 829 | uint32_t id = stoi( |
| 830 | logPath[0].substr(logPath[0].find_last_of('/') + 1)); |
| 831 | ids.push_back(id); |
| 832 | } |
| 833 | } |
| 834 | } |
| 835 | } |
| 836 | |
| 837 | if (ids.size() > 1) |
| 838 | { |
| 839 | // remove duplicates to have only unique ids |
| 840 | std::sort(ids.begin(), ids.end()); |
| 841 | ids.erase(std::unique(ids.begin(), ids.end()), ids.end()); |
| 842 | } |
| 843 | return ids; |
| 844 | } |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 845 | } // namespace pels |
| 846 | } // namespace openpower |