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"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 38 | } // namespace service_name |
| 39 | |
| 40 | namespace object_path |
| 41 | { |
| 42 | constexpr auto objectMapper = "/xyz/openbmc_project/object_mapper"; |
| 43 | constexpr auto systemInv = "/xyz/openbmc_project/inventory/system"; |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 44 | constexpr auto chassisInv = "/xyz/openbmc_project/inventory/system/chassis"; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 45 | constexpr auto motherBoardInv = |
| 46 | "/xyz/openbmc_project/inventory/system/chassis/motherboard"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 47 | constexpr auto baseInv = "/xyz/openbmc_project/inventory"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 48 | constexpr auto bmcState = "/xyz/openbmc_project/state/bmc0"; |
| 49 | constexpr auto chassisState = "/xyz/openbmc_project/state/chassis0"; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 50 | constexpr auto hostState = "/xyz/openbmc_project/state/host0"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 51 | constexpr auto pldm = "/xyz/openbmc_project/pldm"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 52 | constexpr auto enableHostPELs = |
| 53 | "/xyz/openbmc_project/logging/send_event_logs_to_host"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 54 | constexpr auto vpdManager = "/com/ibm/VPD/Manager"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 55 | } // namespace object_path |
| 56 | |
| 57 | namespace interface |
| 58 | { |
| 59 | constexpr auto dbusProperty = "org.freedesktop.DBus.Properties"; |
| 60 | constexpr auto objectMapper = "xyz.openbmc_project.ObjectMapper"; |
| 61 | constexpr auto invAsset = "xyz.openbmc_project.Inventory.Decorator.Asset"; |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 62 | constexpr auto bootProgress = "xyz.openbmc_project.State.Boot.Progress"; |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 63 | constexpr auto pldmRequester = "xyz.openbmc_project.PLDM.Requester"; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 64 | constexpr auto enable = "xyz.openbmc_project.Object.Enable"; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 65 | constexpr auto bmcState = "xyz.openbmc_project.State.BMC"; |
| 66 | constexpr auto chassisState = "xyz.openbmc_project.State.Chassis"; |
| 67 | constexpr auto hostState = "xyz.openbmc_project.State.Host"; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 68 | constexpr auto invMotherboard = |
| 69 | "xyz.openbmc_project.Inventory.Item.Board.Motherboard"; |
| 70 | constexpr auto viniRecordVPD = "com.ibm.ipzvpd.VINI"; |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 71 | constexpr auto locCode = "com.ibm.ipzvpd.Location"; |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 72 | constexpr auto compatible = |
| 73 | "xyz.openbmc_project.Configuration.IBMCompatibleSystem"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 74 | constexpr auto vpdManager = "com.ibm.VPD.Manager"; |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 75 | constexpr auto ledGroup = "xyz.openbmc_project.Led.Group"; |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 76 | constexpr auto operationalStatus = |
| 77 | "xyz.openbmc_project.State.Decorator.OperationalStatus"; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 78 | } // namespace interface |
| 79 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 80 | using namespace sdbusplus::xyz::openbmc_project::State::Boot::server; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 81 | using sdbusplus::exception::SdBusError; |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 82 | using namespace phosphor::logging; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 83 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 84 | DataInterface::DataInterface(sdbusplus::bus::bus& bus) : _bus(bus) |
| 85 | { |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 86 | readBMCFWVersion(); |
| 87 | readServerFWVersion(); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 88 | readBMCFWVersionID(); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 89 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 90 | // Watch the BootProgress property |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 91 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 92 | bus, object_path::hostState, interface::bootProgress, "BootProgress", |
| 93 | *this, [this](const auto& value) { |
| 94 | auto status = Progress::convertProgressStagesFromString( |
| 95 | std::get<std::string>(value)); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 96 | |
Matt Spinler | f10068d | 2020-12-02 10:44:08 -0600 | [diff] [blame] | 97 | if ((status == Progress::ProgressStages::SystemInitComplete) || |
| 98 | (status == Progress::ProgressStages::OSStart) || |
| 99 | (status == Progress::ProgressStages::OSRunning)) |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 100 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 101 | setHostUp(true); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 102 | } |
| 103 | else |
| 104 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 105 | setHostUp(false); |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 106 | } |
| 107 | })); |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 108 | |
| 109 | // Watch the host PEL enable property |
| 110 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 111 | bus, object_path::enableHostPELs, interface::enable, "Enabled", *this, |
| 112 | [this](const auto& value) { |
| 113 | this->_sendPELsToHost = std::get<bool>(value); |
| 114 | })); |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 115 | |
| 116 | // Watch the BMCState property |
| 117 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 118 | bus, object_path::bmcState, interface::bmcState, "CurrentBMCState", |
| 119 | *this, [this](const auto& value) { |
| 120 | this->_bmcState = std::get<std::string>(value); |
| 121 | })); |
| 122 | |
| 123 | // Watch the chassis current and requested power state properties |
| 124 | _properties.emplace_back(std::make_unique<InterfaceWatcher<DataInterface>>( |
| 125 | bus, object_path::chassisState, interface::chassisState, *this, |
| 126 | [this](const auto& properties) { |
| 127 | auto state = properties.find("CurrentPowerState"); |
| 128 | if (state != properties.end()) |
| 129 | { |
| 130 | this->_chassisState = std::get<std::string>(state->second); |
| 131 | } |
| 132 | |
| 133 | auto trans = properties.find("RequestedPowerTransition"); |
| 134 | if (trans != properties.end()) |
| 135 | { |
| 136 | this->_chassisTransition = std::get<std::string>(trans->second); |
| 137 | } |
| 138 | })); |
| 139 | |
| 140 | // Watch the CurrentHostState property |
| 141 | _properties.emplace_back(std::make_unique<PropertyWatcher<DataInterface>>( |
| 142 | bus, object_path::hostState, interface::hostState, "CurrentHostState", |
| 143 | *this, [this](const auto& value) { |
| 144 | this->_hostState = std::get<std::string>(value); |
| 145 | })); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 146 | } |
| 147 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 148 | DBusPropertyMap |
| 149 | DataInterface::getAllProperties(const std::string& service, |
| 150 | const std::string& objectPath, |
| 151 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 152 | { |
| 153 | DBusPropertyMap properties; |
| 154 | |
| 155 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 156 | interface::dbusProperty, "GetAll"); |
| 157 | method.append(interface); |
| 158 | auto reply = _bus.call(method); |
| 159 | |
| 160 | reply.read(properties); |
| 161 | |
| 162 | return properties; |
| 163 | } |
| 164 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 165 | void DataInterface::getProperty(const std::string& service, |
| 166 | const std::string& objectPath, |
| 167 | const std::string& interface, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 168 | const std::string& property, |
| 169 | DBusValue& value) const |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 170 | { |
| 171 | |
| 172 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 173 | interface::dbusProperty, "Get"); |
| 174 | method.append(interface, property); |
| 175 | auto reply = _bus.call(method); |
| 176 | |
| 177 | reply.read(value); |
| 178 | } |
| 179 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 180 | DBusPathList DataInterface::getPaths(const DBusInterfaceList& interfaces) const |
| 181 | { |
| 182 | |
| 183 | auto method = _bus.new_method_call( |
| 184 | service_name::objectMapper, object_path::objectMapper, |
| 185 | interface::objectMapper, "GetSubTreePaths"); |
| 186 | |
| 187 | method.append(std::string{"/"}, 0, interfaces); |
| 188 | |
| 189 | auto reply = _bus.call(method); |
| 190 | |
| 191 | DBusPathList paths; |
| 192 | reply.read(paths); |
| 193 | |
| 194 | return paths; |
| 195 | } |
| 196 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 197 | DBusService DataInterface::getService(const std::string& objectPath, |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 198 | const std::string& interface) const |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 199 | { |
| 200 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 201 | object_path::objectMapper, |
| 202 | interface::objectMapper, "GetObject"); |
| 203 | |
| 204 | method.append(objectPath, std::vector<std::string>({interface})); |
| 205 | |
| 206 | auto reply = _bus.call(method); |
| 207 | |
| 208 | std::map<DBusService, DBusInterfaceList> response; |
| 209 | reply.read(response); |
| 210 | |
| 211 | if (!response.empty()) |
| 212 | { |
| 213 | return response.begin()->first; |
| 214 | } |
| 215 | |
| 216 | return std::string{}; |
| 217 | } |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 218 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 219 | void DataInterface::readBMCFWVersion() |
| 220 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 221 | _bmcFWVersion = |
| 222 | phosphor::logging::util::getOSReleaseValue("VERSION").value_or(""); |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 223 | } |
| 224 | |
| 225 | void DataInterface::readServerFWVersion() |
| 226 | { |
| 227 | // Not available yet |
| 228 | } |
| 229 | |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 230 | void DataInterface::readBMCFWVersionID() |
| 231 | { |
Matt Spinler | f61f292 | 2020-06-23 11:32:49 -0500 | [diff] [blame] | 232 | _bmcFWVersionID = |
| 233 | phosphor::logging::util::getOSReleaseValue("VERSION_ID").value_or(""); |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 234 | } |
| 235 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 236 | std::string DataInterface::getMachineTypeModel() const |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 237 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 238 | std::string model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 239 | try |
| 240 | { |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 241 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 242 | auto service = getService(object_path::systemInv, interface::invAsset); |
| 243 | if (!service.empty()) |
| 244 | { |
| 245 | DBusValue value; |
| 246 | getProperty(service, object_path::systemInv, interface::invAsset, |
| 247 | "Model", value); |
| 248 | |
| 249 | model = std::get<std::string>(value); |
| 250 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 251 | } |
| 252 | catch (const std::exception& e) |
| 253 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 254 | log<level::WARNING>(fmt::format("Failed reading Model property from " |
| 255 | "Interface: {} exception: {}", |
| 256 | interface::invAsset, e.what()) |
| 257 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 258 | } |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 259 | |
| 260 | return model; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 261 | } |
| 262 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 263 | std::string DataInterface::getMachineSerialNumber() 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 sn; |
| 266 | try |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 267 | { |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 268 | |
| 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 | "SerialNumber", value); |
| 275 | |
| 276 | sn = std::get<std::string>(value); |
| 277 | } |
| 278 | } |
| 279 | catch (const std::exception& e) |
| 280 | { |
| 281 | log<level::WARNING>( |
| 282 | fmt::format("Failed reading SerialNumber property from " |
| 283 | "Interface: {} exception: {}", |
| 284 | interface::invAsset, e.what()) |
| 285 | .c_str()); |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 286 | } |
| 287 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 288 | return sn; |
| 289 | } |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 290 | |
Vijay Lobo | 81b4dca | 2021-04-29 00:04:00 -0500 | [diff] [blame] | 291 | std::string DataInterface::getMotherboardCCIN() const |
| 292 | { |
| 293 | std::string ccin; |
| 294 | |
| 295 | try |
| 296 | { |
| 297 | auto service = |
| 298 | getService(object_path::motherBoardInv, interface::viniRecordVPD); |
| 299 | if (!service.empty()) |
| 300 | { |
| 301 | DBusValue value; |
| 302 | getProperty(service, object_path::motherBoardInv, |
| 303 | interface::viniRecordVPD, "CC", value); |
| 304 | |
| 305 | auto cc = std::get<std::vector<uint8_t>>(value); |
| 306 | ccin = std::string{cc.begin(), cc.end()}; |
| 307 | } |
| 308 | } |
| 309 | catch (const std::exception& e) |
| 310 | { |
| 311 | log<level::WARNING>( |
| 312 | fmt::format("Failed reading Motherboard CCIN property from " |
| 313 | "Interface: {} exception: {}", |
| 314 | interface::viniRecordVPD, e.what()) |
| 315 | .c_str()); |
| 316 | } |
| 317 | |
| 318 | return ccin; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 319 | } |
| 320 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 321 | void DataInterface::getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 322 | std::string& fruPartNumber, |
| 323 | std::string& ccin, |
| 324 | std::string& serialNumber) const |
| 325 | { |
| 326 | // For now, attempt to get all of the properties directly on the path |
| 327 | // passed in. In the future, may need to make use of an algorithm |
| 328 | // to figure out which inventory objects actually hold these |
| 329 | // interfaces in the case of non FRUs, or possibly another service |
| 330 | // will provide this info. Any missing interfaces will result |
| 331 | // in exceptions being thrown. |
| 332 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 333 | auto service = getService(inventoryPath, interface::viniRecordVPD); |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 334 | |
| 335 | auto properties = |
| 336 | getAllProperties(service, inventoryPath, interface::viniRecordVPD); |
| 337 | |
| 338 | auto value = std::get<std::vector<uint8_t>>(properties["FN"]); |
| 339 | fruPartNumber = std::string{value.begin(), value.end()}; |
| 340 | |
| 341 | value = std::get<std::vector<uint8_t>>(properties["CC"]); |
| 342 | ccin = std::string{value.begin(), value.end()}; |
| 343 | |
| 344 | value = std::get<std::vector<uint8_t>>(properties["SN"]); |
| 345 | serialNumber = std::string{value.begin(), value.end()}; |
| 346 | } |
| 347 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 348 | std::string |
| 349 | DataInterface::getLocationCode(const std::string& inventoryPath) const |
| 350 | { |
| 351 | auto service = getService(inventoryPath, interface::locCode); |
| 352 | |
| 353 | DBusValue locCode; |
| 354 | getProperty(service, inventoryPath, interface::locCode, "LocationCode", |
| 355 | locCode); |
| 356 | |
| 357 | return std::get<std::string>(locCode); |
| 358 | } |
| 359 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 360 | std::string |
| 361 | DataInterface::addLocationCodePrefix(const std::string& locationCode) |
| 362 | { |
| 363 | static const std::string locationCodePrefix{"Ufcs-"}; |
| 364 | |
Matt Spinler | 0e4d72e | 2020-08-05 12:36:53 -0500 | [diff] [blame] | 365 | // Technically there are 2 location code prefixes, Ufcs and Umts, so |
| 366 | // if it already starts with a U then don't need to do anything. |
| 367 | if (locationCode.front() != 'U') |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 368 | { |
| 369 | return locationCodePrefix + locationCode; |
| 370 | } |
| 371 | |
| 372 | return locationCode; |
| 373 | } |
| 374 | |
| 375 | std::string DataInterface::expandLocationCode(const std::string& locationCode, |
Patrick Williams | d26fa3e | 2021-04-21 15:22:23 -0500 | [diff] [blame] | 376 | uint16_t /*node*/) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 377 | { |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 378 | auto method = |
| 379 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 380 | interface::vpdManager, "GetExpandedLocationCode"); |
| 381 | |
| 382 | method.append(addLocationCodePrefix(locationCode), |
| 383 | static_cast<uint16_t>(0)); |
| 384 | |
| 385 | auto reply = _bus.call(method); |
| 386 | |
| 387 | std::string expandedLocationCode; |
| 388 | reply.read(expandedLocationCode); |
| 389 | |
| 390 | return expandedLocationCode; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 391 | } |
| 392 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 393 | std::string |
| 394 | DataInterface::getInventoryFromLocCode(const std::string& locationCode, |
| 395 | uint16_t node, bool expanded) const |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 396 | { |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 397 | std::string methodName = expanded ? "GetFRUsByExpandedLocationCode" |
| 398 | : "GetFRUsByUnexpandedLocationCode"; |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 399 | |
Matt Spinler | 2f9225a | 2020-08-05 12:58:49 -0500 | [diff] [blame] | 400 | auto method = |
| 401 | _bus.new_method_call(service_name::vpdManager, object_path::vpdManager, |
| 402 | interface::vpdManager, methodName.c_str()); |
| 403 | |
| 404 | if (expanded) |
| 405 | { |
| 406 | method.append(locationCode); |
| 407 | } |
| 408 | else |
| 409 | { |
| 410 | method.append(addLocationCodePrefix(locationCode), node); |
| 411 | } |
Matt Spinler | fcf9a3f | 2020-07-28 13:21:07 -0500 | [diff] [blame] | 412 | |
| 413 | auto reply = _bus.call(method); |
| 414 | |
| 415 | std::vector<sdbusplus::message::object_path> entries; |
| 416 | reply.read(entries); |
| 417 | |
| 418 | // Get the shortest entry from the paths received, as this |
| 419 | // would be the path furthest up the inventory hierarchy so |
| 420 | // would be the parent FRU. There is guaranteed to at least |
| 421 | // be one entry if the call didn't fail. |
| 422 | std::string shortest{entries[0]}; |
| 423 | |
| 424 | std::for_each(entries.begin(), entries.end(), |
| 425 | [&shortest](const auto& path) { |
| 426 | if (path.str.size() < shortest.size()) |
| 427 | { |
| 428 | shortest = path; |
| 429 | } |
| 430 | }); |
| 431 | |
| 432 | return shortest; |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 433 | } |
| 434 | |
Matt Spinler | 34a904c | 2020-08-05 14:53:28 -0500 | [diff] [blame] | 435 | void DataInterface::assertLEDGroup(const std::string& ledGroup, |
| 436 | bool value) const |
| 437 | { |
| 438 | DBusValue variant = value; |
| 439 | auto method = |
| 440 | _bus.new_method_call(service_name::ledGroupManager, ledGroup.c_str(), |
| 441 | interface::dbusProperty, "Set"); |
| 442 | method.append(interface::ledGroup, "Asserted", variant); |
| 443 | _bus.call(method); |
| 444 | } |
| 445 | |
Matt Spinler | 993168d | 2021-04-07 16:05:03 -0500 | [diff] [blame] | 446 | void DataInterface::setFunctional(const std::string& objectPath, |
| 447 | bool value) const |
| 448 | { |
| 449 | DBusValue variant = value; |
| 450 | auto service = getService(objectPath, interface::operationalStatus); |
| 451 | |
| 452 | auto method = _bus.new_method_call(service.c_str(), objectPath.c_str(), |
| 453 | interface::dbusProperty, "Set"); |
| 454 | |
| 455 | method.append(interface::operationalStatus, "Functional", variant); |
| 456 | _bus.call(method); |
| 457 | } |
| 458 | |
Matt Spinler | 1ab6696 | 2020-10-29 13:21:44 -0500 | [diff] [blame] | 459 | std::vector<std::string> DataInterface::getSystemNames() const |
| 460 | { |
| 461 | DBusSubTree subtree; |
| 462 | DBusValue names; |
| 463 | |
| 464 | auto method = _bus.new_method_call(service_name::objectMapper, |
| 465 | object_path::objectMapper, |
| 466 | interface::objectMapper, "GetSubTree"); |
| 467 | method.append(std::string{"/"}, 0, |
| 468 | std::vector<std::string>{interface::compatible}); |
| 469 | auto reply = _bus.call(method); |
| 470 | |
| 471 | reply.read(subtree); |
| 472 | if (subtree.empty()) |
| 473 | { |
| 474 | throw std::runtime_error("Compatible interface not on D-Bus"); |
| 475 | } |
| 476 | |
| 477 | const auto& object = *(subtree.begin()); |
| 478 | const auto& path = object.first; |
| 479 | const auto& service = object.second.begin()->first; |
| 480 | |
| 481 | getProperty(service, path, interface::compatible, "Names", names); |
| 482 | |
| 483 | return std::get<std::vector<std::string>>(names); |
| 484 | } |
| 485 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 486 | } // namespace pels |
| 487 | } // namespace openpower |