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> |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 25 | #include <phosphor-logging/log.hpp> |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 26 | #include <xyz/openbmc_project/State/Boot/Progress/server.hpp> |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 27 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 28 | namespace openpower |
| 29 | { |
| 30 | namespace pels |
| 31 | { |
| 32 | |
| 33 | namespace service_name |
| 34 | { |
| 35 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 36 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 37 | constexpr auto ledGroupManager = "xyz.openbmc_project.LED.GroupManager"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 38 | constexpr auto logSetting = "xyz.openbmc_project.Settings"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 39 | } // namespace service_name |
| 40 | |
| 41 | namespace object_path |
| 42 | { |
| 43 | constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper"; |
| 44 | constexpr auto systemInv = "/xyz/openbmc_project/inventory/system"; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 45 | constexpr auto chassisInv = "/xyz/openbmc_project/inventory/system/chassis"; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 46 | constexpr auto motherBoardInv = |
| 47 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 48 | constexpr auto baseInv = "/xyz/openbmc_project/inventory"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 49 | constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0"; |
| 50 | constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0"; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 51 | constexpr auto hostState = "/xyz/openbmc_project/state/host0"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 52 | constexpr auto pldm = "/xyz/openbmc_project/pldm"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 53 | constexpr auto enableHostPELs = |
| 54 | "/xyz/openbmc_project/logging/send_event_logs_to_host"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 55 | constexpr auto vpdManager = "/com/ibm/VPD/Manager"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 56 | constexpr auto logSetting = "/xyz/openbmc_project/logging/settings"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 57 | } // namespace object_path |
| 58 | |
| 59 | namespace interface |
| 60 | { |
| 61 | constexpr auto dbusProperty = "org.freedesktop.DBus.Properties"; |
| 62 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
| 63 | constexpr auto invAsset = "xyz.openbmc_project.Inventory.Decorator.Asset"; |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 64 | constexpr auto bootProgress = "xyz.openbmc_project.State.Boot.Progress"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 65 | constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 66 | constexpr auto enable = "xyz.openbmc_project.Object.Enable"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 67 | constexpr auto bmcState = "xyz.openbmc_project.State.BMC"; |
| 68 | constexpr auto chassisState = "xyz.openbmc_project.State.Chassis"; |
| 69 | constexpr auto hostState = "xyz.openbmc_project.State.Host"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 70 | constexpr auto invMotherboard = |
| 71 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"; |
| 72 | constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI"; |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 73 | constexpr auto vsbpRecordVPD = "com.ibm.ipzvpd.VSBP"; |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 74 | constexpr auto locCode = "com.ibm.ipzvpd.Location"; |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 75 | constexpr auto compatible = |
| 76 | "xyz.openbmc_project.Configuration.IBMCompatibleSystem"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 77 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 78 | constexpr auto ledGroup = "xyz.openbmc_project.Led.Group"; |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 79 | constexpr auto operationalStatus = |
| 80 | "xyz.openbmc_project.State.Decorator.OperationalStatus"; |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 81 | constexpr auto logSetting = "xyz.openbmc_project.Logging.Settings"; |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 82 | constexpr auto association = "xyz.openbmc_project.Association.Definitions"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 83 | } // namespace interface |
| 84 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 85 | using namespace sdbusplus::xyz::openbmc_project::State::Boot::server; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 86 | using namespace phosphor::logging; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 87 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 88 | std::pair<std::string, std::string> |
| 89 | DataInterfaceBase::extractConnectorFromLocCode( |
| 90 | const std::string& locationCode) |
| 91 | { |
| 92 | auto base = locationCode; |
| 93 | std::string connector{}; |
| 94 | |
| 95 | auto pos = base.find("-T"); |
| 96 | if (pos != std::string::npos) |
| 97 | { |
| 98 | connector = base.substr(pos); |
| 99 | base = base.substr(0, pos); |
| 100 | } |
| 101 | |
| 102 | return {base, connector}; |
| 103 | } |
| 104 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 105 | DataInterface::DataInterface(sdbusplus::bus::bus& bus) : _bus(bus) |
| 106 | { |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 107 | readBMCFWVersion(); |
| 108 | readServerFWVersion(); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 109 | readBMCFWVersionID(); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 110 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 111 | // Watch the BootProgress property |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 112 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 113 | bus, object_path::hostState, interface::bootProgress, "BootProgress", |
| 114 | *this, [this](const auto& value) { |
| 115 | auto status = Progress::convertProgressStagesFromString( |
| 116 | std::get<std::string>(value)); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 117 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 118 | if ((status == Progress::ProgressStages::SystemInitComplete) || |
| 119 | (status == Progress::ProgressStages::OSStart) || |
| 120 | (status == Progress::ProgressStages::OSRunning)) |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 121 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 122 | setHostUp(true); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 123 | } |
| 124 | else |
| 125 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 126 | setHostUp(false); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 127 | } |
| 128 | })); |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 129 | |
| 130 | // Watch the host PEL enable property |
| 131 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 132 | bus, object_path::enableHostPELs, interface::enable, "Enabled", *this, |
| 133 | [this](const auto& value) { |
| 134 | this->_sendPELsToHost = std::get<bool>(value); |
| 135 | })); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 136 | |
| 137 | // Watch the BMCState property |
| 138 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 139 | bus, object_path::bmcState, interface::bmcState, "CurrentBMCState", |
| 140 | *this, [this](const auto& value) { |
| 141 | this->_bmcState = std::get<std::string>(value); |
| 142 | })); |
| 143 | |
| 144 | // Watch the chassis current and requested power state properties |
| 145 | _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>( |
| 146 | bus, object_path::chassisState, interface::chassisState, *this, |
| 147 | [this](const auto& properties) { |
| 148 | auto state = properties.find("CurrentPowerState"); |
| 149 | if (state != properties.end()) |
| 150 | { |
| 151 | this->_chassisState = std::get<std::string>(state->second); |
| 152 | } |
| 153 | |
| 154 | auto trans = properties.find("RequestedPowerTransition"); |
| 155 | if (trans != properties.end()) |
| 156 | { |
| 157 | this->_chassisTransition = std::get<std::string>(trans->second); |
| 158 | } |
| 159 | })); |
| 160 | |
| 161 | // Watch the CurrentHostState property |
| 162 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 163 | bus, object_path::hostState, interface::hostState, "CurrentHostState", |
| 164 | *this, [this](const auto& value) { |
| 165 | this->_hostState = std::get<std::string>(value); |
| 166 | })); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 167 | } |
| 168 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 169 | DBusPropertyMap |
| 170 | DataInterface::getAllProperties(const std::string& service, |
| 171 | const std::string& objectPath, |
| 172 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 173 | { |
| 174 | DBusPropertyMap properties; |
| 175 | |
| 176 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 177 | interface::dbusProperty, "GetAll"); |
| 178 | method.append(interface); |
| 179 | auto reply = _bus.call(method); |
| 180 | |
| 181 | reply.read(properties); |
| 182 | |
| 183 | return properties; |
| 184 | } |
| 185 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 186 | void DataInterface::getProperty(const std::string& service, |
| 187 | const std::string& objectPath, |
| 188 | const std::string& interface, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 189 | const std::string& property, |
| 190 | DBusValue& value) const |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 191 | { |
| 192 | |
| 193 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 194 | interface::dbusProperty, "Get"); |
| 195 | method.append(interface, property); |
| 196 | auto reply = _bus.call(method); |
| 197 | |
| 198 | reply.read(value); |
| 199 | } |
| 200 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 201 | DBusPathList DataInterface::getPaths(const DBusInterfaceList& interfaces) const |
| 202 | { |
| 203 | |
| 204 | auto method = _bus.new_method_call( |
| 205 | service_name::objectMapper, object_path::objectMapper, |
| 206 | interface::objectMapper, "GetSubTreePaths"); |
| 207 | |
| 208 | method.append(std::string{"/"}, 0, interfaces); |
| 209 | |
| 210 | auto reply = _bus.call(method); |
| 211 | |
| 212 | DBusPathList paths; |
| 213 | reply.read(paths); |
| 214 | |
| 215 | return paths; |
| 216 | } |
| 217 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 218 | DBusService DataInterface::getService(const std::string& objectPath, |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 219 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 220 | { |
| 221 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 222 | object_path::objectMapper, |
| 223 | interface::objectMapper, "GetObject"); |
| 224 | |
| 225 | method.append(objectPath, std::vector<std::string>({interface})); |
| 226 | |
| 227 | auto reply = _bus.call(method); |
| 228 | |
| 229 | std::map<DBusService, DBusInterfaceList> response; |
| 230 | reply.read(response); |
| 231 | |
| 232 | if (!response.empty()) |
| 233 | { |
| 234 | return response.begin()->first; |
| 235 | } |
| 236 | |
| 237 | return std::string{}; |
| 238 | } |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 239 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 240 | void DataInterface::readBMCFWVersion() |
| 241 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 242 | _bmcFWVersion = |
| 243 | phosphor::logging::util::getOSReleaseValue("VERSION").value_or(""); |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 244 | } |
| 245 | |
| 246 | void DataInterface::readServerFWVersion() |
| 247 | { |
Sumit Kumar | cad1620 | 2021-05-13 04:06:15 -0500 | [diff] [blame] | 248 | auto value = |
| 249 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
| 250 | if ((value != "") && (value.find_last_of(')') != std::string::npos)) |
| 251 | { |
| 252 | std::size_t pos = value.find_first_of('(') + 1; |
| 253 | _serverFWVersion = value.substr(pos, value.find_last_of(')') - pos); |
| 254 | } |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 255 | } |
| 256 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 257 | void DataInterface::readBMCFWVersionID() |
| 258 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 259 | _bmcFWVersionID = |
| 260 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 261 | } |
| 262 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 263 | std::string DataInterface::getMachineTypeModel() const |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 264 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 265 | std::string model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 266 | try |
| 267 | { |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 268 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 269 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 270 | if (!service.empty()) |
| 271 | { |
| 272 | DBusValue value; |
| 273 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 274 | "Model", value); |
| 275 | |
| 276 | model = std::get<std::string>(value); |
| 277 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 278 | } |
| 279 | catch (const std::exception& e) |
| 280 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 281 | log<level::WARNING>(fmt::format("Failed reading Model property from " |
| 282 | "Interface: {} exception: {}", |
| 283 | interface::invAsset, e.what()) |
| 284 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 285 | } |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 286 | |
| 287 | return model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 288 | } |
| 289 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 290 | std::string DataInterface::getMachineSerialNumber() const |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 291 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 292 | std::string sn; |
| 293 | try |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 294 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 295 | |
| 296 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 297 | if (!service.empty()) |
| 298 | { |
| 299 | DBusValue value; |
| 300 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 301 | "SerialNumber", value); |
| 302 | |
| 303 | sn = std::get<std::string>(value); |
| 304 | } |
| 305 | } |
| 306 | catch (const std::exception& e) |
| 307 | { |
| 308 | log<level::WARNING>( |
| 309 | fmt::format("Failed reading SerialNumber property from " |
| 310 | "Interface: {} exception: {}", |
| 311 | interface::invAsset, e.what()) |
| 312 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 313 | } |
| 314 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 315 | return sn; |
| 316 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 317 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 318 | std::string DataInterface::getMotherboardCCIN() const |
| 319 | { |
| 320 | std::string ccin; |
| 321 | |
| 322 | try |
| 323 | { |
| 324 | auto service = |
| 325 | getService(object_path::motherBoardInv, interface::viniRecordVPD); |
| 326 | if (!service.empty()) |
| 327 | { |
| 328 | DBusValue value; |
| 329 | getProperty(service, object_path::motherBoardInv, |
| 330 | interface::viniRecordVPD, "CC", value); |
| 331 | |
| 332 | auto cc = std::get<std::vector<uint8_t>>(value); |
| 333 | ccin = std::string{cc.begin(), cc.end()}; |
| 334 | } |
| 335 | } |
| 336 | catch (const std::exception& e) |
| 337 | { |
| 338 | log<level::WARNING>( |
| 339 | fmt::format("Failed reading Motherboard CCIN property from " |
| 340 | "Interface: {} exception: {}", |
| 341 | interface::viniRecordVPD, e.what()) |
| 342 | .c_str()); |
| 343 | } |
| 344 | |
| 345 | return ccin; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 346 | } |
| 347 | |
Ben Tyner | e32b7e7 | 2021-05-18 12:38:40 -0500 | [diff] [blame] | 348 | std::vector<uint8_t> DataInterface::getSystemIMKeyword() const |
| 349 | { |
| 350 | std::vector<uint8_t> systemIM; |
| 351 | |
| 352 | try |
| 353 | { |
| 354 | auto service = |
| 355 | getService(object_path::motherBoardInv, interface::vsbpRecordVPD); |
| 356 | if (!service.empty()) |
| 357 | { |
| 358 | DBusValue value; |
| 359 | getProperty(service, object_path::motherBoardInv, |
| 360 | interface::vsbpRecordVPD, "IM", value); |
| 361 | |
| 362 | systemIM = std::get<std::vector<uint8_t>>(value); |
| 363 | } |
| 364 | } |
| 365 | catch (const std::exception& e) |
| 366 | { |
| 367 | log<level::WARNING>( |
| 368 | fmt::format("Failed reading System IM property from " |
| 369 | "Interface: {} exception: {}", |
| 370 | interface::vsbpRecordVPD, e.what()) |
| 371 | .c_str()); |
| 372 | } |
| 373 | |
| 374 | return systemIM; |
| 375 | } |
| 376 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 377 | void DataInterface::getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 378 | std::string& fruPartNumber, |
| 379 | std::string& ccin, |
| 380 | std::string& serialNumber) const |
| 381 | { |
| 382 | // For now, attempt to get all of the properties directly on the path |
| 383 | // passed in. In the future, may need to make use of an algorithm |
| 384 | // to figure out which inventory objects actually hold these |
| 385 | // interfaces in the case of non FRUs, or possibly another service |
| 386 | // will provide this info. Any missing interfaces will result |
| 387 | // in exceptions being thrown. |
| 388 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 389 | auto service = getService(inventoryPath, interface::viniRecordVPD); |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 390 | |
| 391 | auto properties = |
| 392 | getAllProperties(service, inventoryPath, interface::viniRecordVPD); |
| 393 | |
| 394 | auto value = std::get<std::vector<uint8_t>>(properties["FN"]); |
| 395 | fruPartNumber = std::string{value.begin(), value.end()}; |
| 396 | |
| 397 | value = std::get<std::vector<uint8_t>>(properties["CC"]); |
| 398 | ccin = std::string{value.begin(), value.end()}; |
| 399 | |
| 400 | value = std::get<std::vector<uint8_t>>(properties["SN"]); |
| 401 | serialNumber = std::string{value.begin(), value.end()}; |
| 402 | } |
| 403 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 404 | std::string |
| 405 | DataInterface::getLocationCode(const std::string& inventoryPath) const |
| 406 | { |
| 407 | auto service = getService(inventoryPath, interface::locCode); |
| 408 | |
| 409 | DBusValue locCode; |
| 410 | getProperty(service, inventoryPath, interface::locCode, "LocationCode", |
| 411 | locCode); |
| 412 | |
| 413 | return std::get<std::string>(locCode); |
| 414 | } |
| 415 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 416 | std::string |
| 417 | DataInterface::addLocationCodePrefix(const std::string& locationCode) |
| 418 | { |
| 419 | static const std::string locationCodePrefix{"Ufcs-"}; |
| 420 | |
Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 421 | // Technically there are 2 location code prefixes, Ufcs and Umts, so |
| 422 | // if it already starts with a U then don't need to do anything. |
| 423 | if (locationCode.front() != 'U') |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 424 | { |
| 425 | return locationCodePrefix + locationCode; |
| 426 | } |
| 427 | |
| 428 | return locationCode; |
| 429 | } |
| 430 | |
| 431 | std::string DataInterface::expandLocationCode(const std::string& locationCode, |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 432 | uint16_t /*node*/) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 433 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 434 | // Location codes for connectors are the location code of the FRU they are |
| 435 | // on, plus a '-Tx' segment. Remove this last segment before expanding it |
| 436 | // and then add it back in afterwards. This way, the connector doesn't have |
| 437 | // to be in the model just so that it can be expanded. |
| 438 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 439 | |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 440 | auto method = |
| 441 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 442 | interface::vpdManager, "GetExpandedLocationCode"); |
| 443 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 444 | method.append(addLocationCodePrefix(baseLoc), static_cast<uint16_t>(0)); |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 445 | |
| 446 | auto reply = _bus.call(method); |
| 447 | |
| 448 | std::string expandedLocationCode; |
| 449 | reply.read(expandedLocationCode); |
| 450 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 451 | if (!connectorLoc.empty()) |
| 452 | { |
| 453 | expandedLocationCode += connectorLoc; |
| 454 | } |
| 455 | |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 456 | return expandedLocationCode; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 457 | } |
| 458 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 459 | std::string |
| 460 | DataInterface::getInventoryFromLocCode(const std::string& locationCode, |
| 461 | uint16_t node, bool expanded) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 462 | { |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 463 | std::string methodName = expanded ? "GetFRUsByExpandedLocationCode" |
| 464 | : "GetFRUsByUnexpandedLocationCode"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 465 | |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 466 | // Remove the connector segment, if present, so that this method call |
| 467 | // returns an inventory path that getHWCalloutFields() can be used with. |
| 468 | // (The serial number, etc, aren't stored on the connector in the |
| 469 | // inventory, and may not even be modeled.) |
| 470 | auto [baseLoc, connectorLoc] = extractConnectorFromLocCode(locationCode); |
| 471 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 472 | auto method = |
| 473 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 474 | interface::vpdManager, methodName.c_str()); |
| 475 | |
| 476 | if (expanded) |
| 477 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 478 | method.append(baseLoc); |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 479 | } |
| 480 | else |
| 481 | { |
Matt Spinler | 0d92b52 | 2021-06-16 13:28:17 -0600 | [diff] [blame] | 482 | method.append(addLocationCodePrefix(baseLoc), node); |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 483 | } |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 484 | |
| 485 | auto reply = _bus.call(method); |
| 486 | |
| 487 | std::vector<sdbusplus::message::object_path> entries; |
| 488 | reply.read(entries); |
| 489 | |
| 490 | // Get the shortest entry from the paths received, as this |
| 491 | // would be the path furthest up the inventory hierarchy so |
| 492 | // would be the parent FRU. There is guaranteed to at least |
| 493 | // be one entry if the call didn't fail. |
| 494 | std::string shortest{entries[0]}; |
| 495 | |
| 496 | std::for_each(entries.begin(), entries.end(), |
| 497 | [&shortest](const auto& path) { |
| 498 | if (path.str.size() < shortest.size()) |
| 499 | { |
| 500 | shortest = path; |
| 501 | } |
| 502 | }); |
| 503 | |
| 504 | return shortest; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 505 | } |
| 506 | |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 507 | void DataInterface::assertLEDGroup(const std::string& ledGroup, |
| 508 | bool value) const |
| 509 | { |
| 510 | DBusValue variant = value; |
| 511 | auto method = |
| 512 | _bus.new_method_call(service_name::ledGroupManager, ledGroup.c_str(), |
| 513 | interface::dbusProperty, "Set"); |
| 514 | method.append(interface::ledGroup, "Asserted", variant); |
| 515 | _bus.call(method); |
| 516 | } |
| 517 | |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 518 | void DataInterface::setFunctional(const std::string& objectPath, |
| 519 | bool value) const |
| 520 | { |
| 521 | DBusValue variant = value; |
| 522 | auto service = getService(objectPath, interface::operationalStatus); |
| 523 | |
| 524 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 525 | interface::dbusProperty, "Set"); |
| 526 | |
| 527 | method.append(interface::operationalStatus, "Functional", variant); |
| 528 | _bus.call(method); |
| 529 | } |
| 530 | |
Sumit Kumar | 76198a2 | 2021-07-15 05:59:57 -0500 | [diff] [blame] | 531 | using AssociationTuple = std::tuple<std::string, std::string, std::string>; |
| 532 | using AssociationsProperty = std::vector<AssociationTuple>; |
| 533 | |
| 534 | void DataInterface::setCriticalAssociation(const std::string& objectPath) const |
| 535 | { |
| 536 | DBusValue getAssociationValue; |
| 537 | |
| 538 | auto service = getService(objectPath, interface::association); |
| 539 | |
| 540 | getProperty(service, objectPath, interface::association, "Associations", |
| 541 | getAssociationValue); |
| 542 | |
| 543 | auto association = std::get<AssociationsProperty>(getAssociationValue); |
| 544 | |
| 545 | AssociationTuple critAssociation{ |
| 546 | "health_rollup", "critical", |
| 547 | "/xyz/openbmc_project/inventory/system/chassis"}; |
| 548 | |
| 549 | if (std::find(association.begin(), association.end(), critAssociation) == |
| 550 | association.end()) |
| 551 | { |
| 552 | association.push_back(critAssociation); |
| 553 | DBusValue setAssociationValue = association; |
| 554 | |
| 555 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 556 | interface::dbusProperty, "Set"); |
| 557 | |
| 558 | method.append(interface::association, "Associations", |
| 559 | setAssociationValue); |
| 560 | _bus.call(method); |
| 561 | } |
| 562 | } |
| 563 | |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 564 | std::vector<std::string> DataInterface::getSystemNames() const |
| 565 | { |
| 566 | DBusSubTree subtree; |
| 567 | DBusValue names; |
| 568 | |
| 569 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 570 | object_path::objectMapper, |
| 571 | interface::objectMapper, "GetSubTree"); |
| 572 | method.append(std::string{"/"}, 0, |
| 573 | std::vector<std::string>{interface::compatible}); |
| 574 | auto reply = _bus.call(method); |
| 575 | |
| 576 | reply.read(subtree); |
| 577 | if (subtree.empty()) |
| 578 | { |
| 579 | throw std::runtime_error("Compatible interface not on D-Bus"); |
| 580 | } |
| 581 | |
| 582 | const auto& object = *(subtree.begin()); |
| 583 | const auto& path = object.first; |
| 584 | const auto& service = object.second.begin()->first; |
| 585 | |
| 586 | getProperty(service, path, interface::compatible, "Names", names); |
| 587 | |
| 588 | return std::get<std::vector<std::string>>(names); |
| 589 | } |
| 590 | |
Sumit Kumar | 3b8ed7f | 2021-05-18 12:38:35 -0500 | [diff] [blame] | 591 | bool DataInterface::getQuiesceOnError() const |
| 592 | { |
| 593 | bool ret = false; |
| 594 | |
| 595 | try |
| 596 | { |
| 597 | auto service = |
| 598 | getService(object_path::logSetting, interface::logSetting); |
| 599 | if (!service.empty()) |
| 600 | { |
| 601 | DBusValue value; |
| 602 | getProperty(service, object_path::logSetting, interface::logSetting, |
| 603 | "QuiesceOnHwError", value); |
| 604 | |
| 605 | ret = std::get<bool>(value); |
| 606 | } |
| 607 | } |
| 608 | catch (const std::exception& e) |
| 609 | { |
| 610 | log<level::WARNING>( |
| 611 | fmt::format("Failed reading QuiesceOnHwError property from " |
| 612 | "Interface: {} exception: {}", |
| 613 | interface::logSetting, e.what()) |
| 614 | .c_str()); |
| 615 | } |
| 616 | |
| 617 | return ret; |
| 618 | } |
| 619 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 620 | } // namespace pels |
| 621 | } // namespace openpower |