Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 3 | #include "dbus_types.hpp" |
| 4 | #include "dbus_watcher.hpp" |
| 5 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 6 | #include <filesystem> |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 7 | #include <phosphor-logging/log.hpp> |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 8 | #include <sdbusplus/bus.hpp> |
| 9 | #include <sdbusplus/bus/match.hpp> |
| 10 | |
| 11 | namespace openpower |
| 12 | { |
| 13 | namespace pels |
| 14 | { |
| 15 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 16 | /** |
| 17 | * @class DataInterface |
| 18 | * |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 19 | * A base class for gathering data about the system for use |
| 20 | * in PELs. Implemented this way to facilitate mocking. |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 21 | */ |
| 22 | class DataInterfaceBase |
| 23 | { |
| 24 | public: |
| 25 | DataInterfaceBase() = default; |
| 26 | virtual ~DataInterfaceBase() = default; |
| 27 | DataInterfaceBase(const DataInterfaceBase&) = default; |
| 28 | DataInterfaceBase& operator=(const DataInterfaceBase&) = default; |
| 29 | DataInterfaceBase(DataInterfaceBase&&) = default; |
| 30 | DataInterfaceBase& operator=(DataInterfaceBase&&) = default; |
| 31 | |
| 32 | /** |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 33 | * @brief Returns the machine Type/Model |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 34 | * |
| 35 | * @return string - The machine Type/Model string |
| 36 | */ |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 37 | virtual std::string getMachineTypeModel() const |
| 38 | { |
| 39 | return _machineTypeModel; |
| 40 | } |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 41 | |
| 42 | /** |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 43 | * @brief Returns the machine serial number |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 44 | * |
| 45 | * @return string - The machine serial number |
| 46 | */ |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 47 | virtual std::string getMachineSerialNumber() const |
| 48 | { |
| 49 | return _machineSerialNumber; |
| 50 | } |
| 51 | |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 52 | /** |
Matt Spinler | cce1411 | 2019-12-11 14:20:36 -0600 | [diff] [blame] | 53 | * @brief Says if the system is managed by a hardware |
| 54 | * management console. |
| 55 | * @return bool - If the system is HMC managed |
| 56 | */ |
| 57 | virtual bool isHMCManaged() const |
| 58 | { |
| 59 | return _hmcManaged; |
| 60 | } |
| 61 | |
| 62 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 63 | * @brief Says if the host is up and running |
| 64 | * |
| 65 | * @return bool - If the host is running |
| 66 | */ |
| 67 | virtual bool isHostUp() const |
| 68 | { |
| 69 | return _hostUp; |
| 70 | } |
| 71 | |
| 72 | using HostStateChangeFunc = std::function<void(bool)>; |
| 73 | |
| 74 | /** |
| 75 | * @brief Register a callback function that will get |
| 76 | * called on all host on/off transitions. |
| 77 | * |
| 78 | * The void(bool) function will get passed the new |
| 79 | * value of the host state. |
| 80 | * |
| 81 | * @param[in] name - The subscription name |
| 82 | * @param[in] func - The function to run |
| 83 | */ |
| 84 | void subscribeToHostStateChange(const std::string& name, |
| 85 | HostStateChangeFunc func) |
| 86 | { |
| 87 | _hostChangeCallbacks[name] = func; |
| 88 | } |
| 89 | |
| 90 | /** |
| 91 | * @brief Unsubscribe from host state changes. |
| 92 | * |
| 93 | * @param[in] name - The subscription name |
| 94 | */ |
| 95 | void unsubscribeFromHostStateChange(const std::string& name) |
| 96 | { |
| 97 | _hostChangeCallbacks.erase(name); |
| 98 | } |
| 99 | |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 100 | /** |
| 101 | * @brief Returns the BMC firmware version |
| 102 | * |
| 103 | * @return std::string - The BMC version |
| 104 | */ |
| 105 | virtual std::string getBMCFWVersion() const |
| 106 | { |
| 107 | return _bmcFWVersion; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * @brief Returns the server firmware version |
| 112 | * |
| 113 | * @return std::string - The server firmware version |
| 114 | */ |
| 115 | virtual std::string getServerFWVersion() const |
| 116 | { |
| 117 | return _serverFWVersion; |
| 118 | } |
| 119 | |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 120 | /** |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 121 | * @brief Returns the BMC FW version ID |
| 122 | * |
| 123 | * @return std::string - The BMC FW version ID |
| 124 | */ |
| 125 | virtual std::string getBMCFWVersionID() const |
| 126 | { |
| 127 | return _bmcFWVersionID; |
| 128 | } |
| 129 | |
| 130 | /** |
Matt Spinler | 4dcd3f4 | 2020-01-22 14:55:07 -0600 | [diff] [blame] | 131 | * @brief Returns the process name given its PID. |
| 132 | * |
| 133 | * @param[in] pid - The PID value as a string |
| 134 | * |
| 135 | * @return std::optional<std::string> - The name, or std::nullopt |
| 136 | */ |
| 137 | std::optional<std::string> getProcessName(const std::string& pid) const |
| 138 | { |
| 139 | namespace fs = std::filesystem; |
| 140 | |
| 141 | fs::path path{"/proc"}; |
| 142 | path /= fs::path{pid} / "exe"; |
| 143 | |
| 144 | if (fs::exists(path)) |
| 145 | { |
| 146 | return fs::read_symlink(path); |
| 147 | } |
| 148 | |
| 149 | return std::nullopt; |
| 150 | } |
| 151 | |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 152 | /** |
| 153 | * @brief Returns the 'send event logs to host' setting. |
| 154 | * |
| 155 | * @return bool - If sending PELs to the host is enabled. |
| 156 | */ |
| 157 | virtual bool getHostPELEnablement() const |
| 158 | { |
| 159 | return _sendPELsToHost; |
| 160 | } |
| 161 | |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 162 | /** |
| 163 | * @brief Returns the BMC state |
| 164 | * |
| 165 | * @return std::string - The BMC state property value |
| 166 | */ |
| 167 | virtual std::string getBMCState() const |
| 168 | { |
| 169 | return _bmcState; |
| 170 | } |
| 171 | |
| 172 | /** |
| 173 | * @brief Returns the Chassis state |
| 174 | * |
| 175 | * @return std::string - The chassis state property value |
| 176 | */ |
| 177 | virtual std::string getChassisState() const |
| 178 | { |
| 179 | return _chassisState; |
| 180 | } |
| 181 | |
| 182 | /** |
| 183 | * @brief Returns the chassis requested power |
| 184 | * transition value. |
| 185 | * |
| 186 | * @return std::string - The chassis transition property |
| 187 | */ |
| 188 | virtual std::string getChassisTransition() const |
| 189 | { |
| 190 | return _chassisTransition; |
| 191 | } |
| 192 | |
| 193 | /** |
| 194 | * @brief Returns the Host state |
| 195 | * |
| 196 | * @return std::string - The Host state property value |
| 197 | */ |
| 198 | virtual std::string getHostState() const |
| 199 | { |
| 200 | return _hostState; |
| 201 | } |
| 202 | |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 203 | /** |
| 204 | * @brief Returns the motherboard CCIN |
| 205 | * |
| 206 | * @return std::string The motherboard CCIN |
| 207 | */ |
| 208 | virtual std::string getMotherboardCCIN() const |
| 209 | { |
| 210 | return _motherboardCCIN; |
| 211 | } |
| 212 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 213 | /** |
| 214 | * @brief Get the fields from the inventory necessary for doing |
| 215 | * a callout on an inventory path. |
| 216 | * |
| 217 | * @param[in] inventoryPath - The item to get the data for |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 218 | * @param[out] fruPartNumber - Filled in with the VINI/FN keyword |
| 219 | * @param[out] ccin - Filled in with the VINI/CC keyword |
| 220 | * @param[out] serialNumber - Filled in with the VINI/SN keyword |
| 221 | */ |
| 222 | virtual void getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 223 | std::string& fruPartNumber, |
| 224 | std::string& ccin, |
| 225 | std::string& serialNumber) const = 0; |
| 226 | |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 227 | /** |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 228 | * @brief Get the location code for an inventory item. |
| 229 | * |
| 230 | * @param[in] inventoryPath - The item to get the data for |
| 231 | * |
| 232 | * @return std::string - The location code |
| 233 | */ |
| 234 | virtual std::string |
| 235 | getLocationCode(const std::string& inventoryPath) const = 0; |
| 236 | |
| 237 | /** |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 238 | * @brief Get the list of system type names the system is called. |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 239 | * |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 240 | * @return std::vector<std::string> - The list of names |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 241 | */ |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 242 | virtual const std::vector<std::string>& getSystemNames() const |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 243 | { |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 244 | return _systemNames; |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 245 | } |
| 246 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 247 | /** |
| 248 | * @brief Fills in the placeholder 'Ufcs' in the passed in location |
| 249 | * code with the machine feature code and serial number, which |
| 250 | * is needed to create a valid location code. |
| 251 | * |
| 252 | * @param[in] locationCode - Location code value starting with Ufcs-, and |
| 253 | * if that isn't present it will be added first. |
| 254 | * |
| 255 | * @param[in] node - The node number the location is on. |
| 256 | * |
| 257 | * @return std::string - The expanded location code |
| 258 | */ |
| 259 | virtual std::string expandLocationCode(const std::string& locationCode, |
| 260 | uint16_t node) const = 0; |
| 261 | |
| 262 | /** |
| 263 | * @brief Returns the inventory path for the FRU that the location |
| 264 | * code represents. |
| 265 | * |
| 266 | * @param[in] locationCode - Location code value starting with Ufcs-, and |
| 267 | * if that isn't present it will be added first. |
| 268 | * |
| 269 | * @param[in] node - The node number the location is on. |
| 270 | * |
| 271 | * @return std::string - The inventory D-Bus object |
| 272 | */ |
| 273 | virtual std::string |
| 274 | getInventoryFromLocCode(const std::string& unexpandedLocationCode, |
| 275 | uint16_t node) const = 0; |
| 276 | |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 277 | protected: |
| 278 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 279 | * @brief Sets the host on/off state and runs any |
| 280 | * callback functions (if there was a change). |
| 281 | */ |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 282 | void setHostUp(bool hostUp) |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 283 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 284 | if (_hostUp != hostUp) |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 285 | { |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 286 | _hostUp = hostUp; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 287 | |
| 288 | for (auto& [name, func] : _hostChangeCallbacks) |
| 289 | { |
| 290 | try |
| 291 | { |
| 292 | func(_hostUp); |
| 293 | } |
| 294 | catch (std::exception& e) |
| 295 | { |
| 296 | using namespace phosphor::logging; |
| 297 | log<level::ERR>("A host state change callback threw " |
| 298 | "an exception"); |
| 299 | } |
| 300 | } |
| 301 | } |
| 302 | } |
| 303 | |
| 304 | /** |
Matt Spinler | 19e89ce | 2019-11-06 13:02:23 -0600 | [diff] [blame] | 305 | * @brief The machine type-model. Always kept up to date |
| 306 | */ |
| 307 | std::string _machineTypeModel; |
| 308 | |
| 309 | /** |
| 310 | * @brief The machine serial number. Always kept up to date |
| 311 | */ |
| 312 | std::string _machineSerialNumber; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 313 | |
| 314 | /** |
Matt Spinler | cce1411 | 2019-12-11 14:20:36 -0600 | [diff] [blame] | 315 | * @brief The hardware management console status. Always kept |
| 316 | * up to date. |
| 317 | */ |
| 318 | bool _hmcManaged = false; |
| 319 | |
| 320 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 321 | * @brief The host up status. Always kept up to date. |
| 322 | */ |
| 323 | bool _hostUp = false; |
| 324 | |
| 325 | /** |
| 326 | * @brief The map of host state change subscriber |
| 327 | * names to callback functions. |
| 328 | */ |
| 329 | std::map<std::string, HostStateChangeFunc> _hostChangeCallbacks; |
Matt Spinler | cad9c2b | 2019-12-02 15:42:01 -0600 | [diff] [blame] | 330 | |
| 331 | /** |
| 332 | * @brief The BMC firmware version string |
| 333 | */ |
| 334 | std::string _bmcFWVersion; |
| 335 | |
| 336 | /** |
| 337 | * @brief The server firmware version string |
| 338 | */ |
| 339 | std::string _serverFWVersion; |
Matt Spinler | 677381b | 2020-01-23 10:04:29 -0600 | [diff] [blame] | 340 | |
| 341 | /** |
| 342 | * @brief The BMC firmware version ID string |
| 343 | */ |
| 344 | std::string _bmcFWVersionID; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 345 | |
| 346 | /** |
| 347 | * @brief If sending PELs is enabled. |
| 348 | * |
| 349 | * This is usually set to false in manufacturing test. |
| 350 | */ |
| 351 | bool _sendPELsToHost = true; |
Matt Spinler | 4aa23a1 | 2020-02-03 15:05:09 -0600 | [diff] [blame] | 352 | |
| 353 | /** |
| 354 | * @brief The BMC state property |
| 355 | */ |
| 356 | std::string _bmcState; |
| 357 | |
| 358 | /** |
| 359 | * @brief The Chassis current power state property |
| 360 | */ |
| 361 | std::string _chassisState; |
| 362 | |
| 363 | /** |
| 364 | * @brief The Chassis requested power transition property |
| 365 | */ |
| 366 | std::string _chassisTransition; |
| 367 | |
| 368 | /** |
| 369 | * @brief The host state property |
| 370 | */ |
| 371 | std::string _hostState; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 372 | |
| 373 | /** |
| 374 | * @brief The motherboard CCIN |
| 375 | */ |
| 376 | std::string _motherboardCCIN; |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 377 | |
| 378 | /** |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 379 | * @brief The compatible system names array |
Matt Spinler | 0398458 | 2020-04-09 13:17:58 -0500 | [diff] [blame] | 380 | */ |
Matt Spinler | 6ea4d5f | 2020-05-20 13:31:07 -0500 | [diff] [blame] | 381 | std::vector<std::string> _systemNames; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 382 | }; |
| 383 | |
| 384 | /** |
| 385 | * @class DataInterface |
| 386 | * |
| 387 | * Concrete implementation of DataInterfaceBase. |
| 388 | */ |
| 389 | class DataInterface : public DataInterfaceBase |
| 390 | { |
| 391 | public: |
| 392 | DataInterface() = delete; |
| 393 | ~DataInterface() = default; |
| 394 | DataInterface(const DataInterface&) = default; |
| 395 | DataInterface& operator=(const DataInterface&) = default; |
| 396 | DataInterface(DataInterface&&) = default; |
| 397 | DataInterface& operator=(DataInterface&&) = default; |
| 398 | |
| 399 | /** |
| 400 | * @brief Constructor |
| 401 | * |
| 402 | * @param[in] bus - The sdbusplus bus object |
| 403 | */ |
| 404 | explicit DataInterface(sdbusplus::bus::bus& bus); |
| 405 | |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 406 | /** |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 407 | * @brief Finds the D-Bus service name that hosts the |
| 408 | * passed in path and interface. |
| 409 | * |
| 410 | * @param[in] objectPath - The D-Bus object path |
| 411 | * @param[in] interface - The D-Bus interface |
| 412 | */ |
| 413 | DBusService getService(const std::string& objectPath, |
Matt Spinler | b3f5186 | 2019-12-09 13:55:10 -0600 | [diff] [blame] | 414 | const std::string& interface) const; |
Matt Spinler | 9cf3cfd | 2020-02-03 14:41:55 -0600 | [diff] [blame] | 415 | |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 416 | /** |
| 417 | * @brief Wrapper for the 'GetAll' properties method call |
| 418 | * |
| 419 | * @param[in] service - The D-Bus service to call it on |
| 420 | * @param[in] objectPath - The D-Bus object path |
| 421 | * @param[in] interface - The interface to get the props on |
| 422 | * |
| 423 | * @return DBusPropertyMap - The property results |
| 424 | */ |
| 425 | DBusPropertyMap getAllProperties(const std::string& service, |
| 426 | const std::string& objectPath, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 427 | const std::string& interface) const; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 428 | /** |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 429 | * @brief Wrapper for the 'Get' properties method call |
| 430 | * |
| 431 | * @param[in] service - The D-Bus service to call it on |
| 432 | * @param[in] objectPath - The D-Bus object path |
| 433 | * @param[in] interface - The interface to get the property on |
| 434 | * @param[in] property - The property name |
| 435 | * @param[out] value - Filled in with the property value. |
| 436 | */ |
| 437 | void getProperty(const std::string& service, const std::string& objectPath, |
| 438 | const std::string& interface, const std::string& property, |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 439 | DBusValue& value) const; |
| 440 | |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 441 | /** |
| 442 | * @brief Get the fields from the inventory necessary for doing |
| 443 | * a callout on an inventory path. |
| 444 | * |
| 445 | * @param[in] inventoryPath - The item to get the data for |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 446 | * @param[out] fruPartNumber - Filled in with the VINI/FN keyword |
| 447 | * @param[out] ccin - Filled in with the VINI/CC keyword |
| 448 | * @param[out] serialNumber - Filled in with the VINI/SN keyword |
| 449 | */ |
| 450 | void getHWCalloutFields(const std::string& inventoryPath, |
Matt Spinler | 60c4e79 | 2020-03-13 13:45:36 -0500 | [diff] [blame] | 451 | std::string& fruPartNumber, std::string& ccin, |
| 452 | std::string& serialNumber) const override; |
| 453 | |
Matt Spinler | 9b90e2a | 2020-04-14 10:59:04 -0500 | [diff] [blame] | 454 | /** |
| 455 | * @brief Get the location code for an inventory item. |
| 456 | * |
| 457 | * Throws an exception if the inventory item doesn't have the |
| 458 | * location code interface. |
| 459 | * |
| 460 | * @param[in] inventoryPath - The item to get the data for |
| 461 | * |
| 462 | * @return std::string - The location code |
| 463 | */ |
| 464 | std::string |
| 465 | getLocationCode(const std::string& inventoryPath) const override; |
| 466 | |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 467 | /** |
| 468 | * @brief Fills in the placeholder 'Ufcs' in the passed in location |
| 469 | * code with the machine feature code and serial number, which |
| 470 | * is needed to create a valid location code. |
| 471 | * |
| 472 | * @param[in] locationCode - Location code value starting with Ufcs-, and |
| 473 | * if that isn't present it will be added first. |
| 474 | * |
| 475 | * @param[in] node - The node number the location is one. |
| 476 | * |
| 477 | * @return std::string - The expanded location code |
| 478 | */ |
| 479 | std::string expandLocationCode(const std::string& locationCode, |
| 480 | uint16_t node) const override; |
| 481 | |
| 482 | /** |
| 483 | * @brief Returns the inventory path for the FRU that the location |
| 484 | * code represents. |
| 485 | * |
| 486 | * @param[in] locationCode - Location code value starting with Ufcs-, and |
| 487 | * if that isn't present it will be added first. |
| 488 | * |
| 489 | * @param[in] node - The node number the location is on. |
| 490 | * |
| 491 | * @return std::string - The inventory D-Bus object |
| 492 | */ |
| 493 | std::string getInventoryFromLocCode(const std::string& expandedLocationCode, |
| 494 | uint16_t node) const override; |
| 495 | |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 496 | private: |
| 497 | /** |
| 498 | * @brief Reads the BMC firmware version string and puts it into |
| 499 | * _bmcFWVersion. |
| 500 | */ |
| 501 | void readBMCFWVersion(); |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 502 | |
| 503 | /** |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 504 | * @brief Reads the server firmware version string and puts it into |
| 505 | * _serverFWVersion. |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 506 | */ |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 507 | void readServerFWVersion(); |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 508 | |
| 509 | /** |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 510 | * @brief Reads the BMC firmware version ID and puts it into |
| 511 | * _bmcFWVersionID. |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 512 | */ |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 513 | void readBMCFWVersionID(); |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 514 | |
| 515 | /** |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 516 | * @brief Reads the motherboard CCIN and puts it into _motherboardCCIN. |
| 517 | * |
| 518 | * It finds the motherboard first, possibly having to wait for it to |
| 519 | * show up. |
| 520 | */ |
| 521 | void readMotherboardCCIN(); |
| 522 | |
| 523 | /** |
| 524 | * @brief Finds all D-Bus paths that contain any of the interfaces |
| 525 | * passed in, by using GetSubTreePaths. |
| 526 | * |
| 527 | * @param[in] interfaces - The desired interfaces |
| 528 | * |
| 529 | * @return The D-Bus paths. |
| 530 | */ |
| 531 | DBusPathList getPaths(const DBusInterfaceList& interfaces) const; |
| 532 | |
| 533 | /** |
| 534 | * @brief The interfacesAdded callback used on the inventory to |
| 535 | * find the D-Bus object that has the motherboard interface. |
| 536 | * When the motherboard is found, it then adds a PropertyWatcher |
| 537 | * for the motherboard CCIN. |
| 538 | */ |
| 539 | void motherboardIfaceAdded(sdbusplus::message::message& msg); |
| 540 | |
| 541 | /** |
| 542 | * @brief Set the motherboard CCIN from the DBus variant that |
| 543 | * contains it. |
| 544 | * |
| 545 | * @param[in] ccin - The CCIN variant, a vector<uint8_t>. |
| 546 | */ |
| 547 | void setMotherboardCCIN(const DBusValue& ccin) |
| 548 | { |
| 549 | const auto& c = std::get<std::vector<uint8_t>>(ccin); |
| 550 | _motherboardCCIN = std::string{c.begin(), c.end()}; |
| 551 | } |
| 552 | |
| 553 | /** |
Matt Spinler | 5fb24c1 | 2020-06-04 11:21:33 -0500 | [diff] [blame] | 554 | * @brief Adds the Ufcs- prefix to the location code passed in. |
| 555 | * |
| 556 | * Necessary because the location codes that come back from the |
| 557 | * message registry and device callout JSON don't have it. |
| 558 | * |
| 559 | * @param[in] - The location code without a prefix, like P1-C1 |
| 560 | * |
| 561 | * @return std::string - The location code with the prefix |
| 562 | */ |
| 563 | static std::string addLocationCodePrefix(const std::string& locationCode); |
| 564 | |
| 565 | /** |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 566 | * @brief The D-Bus property or interface watchers that have callbacks |
| 567 | * registered that will set members in this class when |
| 568 | * they change. |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 569 | */ |
Matt Spinler | 2a28c93 | 2020-02-03 14:23:40 -0600 | [diff] [blame] | 570 | std::vector<std::unique_ptr<DBusWatcher>> _properties; |
Matt Spinler | a7d9d96 | 2019-11-06 15:01:25 -0600 | [diff] [blame] | 571 | |
| 572 | /** |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 573 | * @brief The sdbusplus bus object for making D-Bus calls. |
| 574 | */ |
| 575 | sdbusplus::bus::bus& _bus; |
Matt Spinler | b3d488f | 2020-02-21 15:30:46 -0600 | [diff] [blame] | 576 | |
| 577 | /** |
| 578 | * @brief The interfacesAdded match object used to wait for inventory |
| 579 | * interfaces to show up, so that the object with the motherboard |
| 580 | * interface can be found. After it is found, this object is |
| 581 | * deleted. |
| 582 | */ |
| 583 | std::unique_ptr<sdbusplus::bus::match_t> _inventoryIfacesAddedMatch; |
Matt Spinler | c8705e2 | 2019-09-11 12:36:07 -0500 | [diff] [blame] | 584 | }; |
| 585 | |
| 586 | } // namespace pels |
| 587 | } // namespace openpower |