Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 3 | #include "fru_parser.hpp" |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 4 | #include "libpldmresponder/pdr_utils.hpp" |
| 5 | #include "oem_handler.hpp" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 6 | #include "pldmd/handler.hpp" |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 7 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 8 | #include <libpldm/fru.h> |
| 9 | #include <libpldm/pdr.h> |
| 10 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 11 | #include <sdbusplus/message.hpp> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 12 | |
| 13 | #include <map> |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 14 | #include <string> |
| 15 | #include <variant> |
| 16 | #include <vector> |
| 17 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 18 | namespace pldm |
| 19 | { |
| 20 | |
| 21 | namespace responder |
| 22 | { |
| 23 | |
| 24 | namespace dbus |
| 25 | { |
| 26 | |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 27 | using Value = std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, |
| 28 | int64_t, uint64_t, double, std::string, |
| 29 | std::vector<uint8_t>, std::vector<std::string>>; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 30 | using PropertyMap = std::map<Property, Value>; |
| 31 | using InterfaceMap = std::map<Interface, PropertyMap>; |
| 32 | using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 33 | using ObjectPath = std::string; |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 34 | using AssociatedEntityMap = std::map<ObjectPath, pldm_entity>; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 35 | |
| 36 | } // namespace dbus |
| 37 | |
| 38 | /** @class FruImpl |
| 39 | * |
| 40 | * @brief Builds the PLDM FRU table containing the FRU records |
| 41 | */ |
| 42 | class FruImpl |
| 43 | { |
| 44 | public: |
| 45 | /* @brief Header size for FRU record, it includes the FRU record set |
| 46 | * identifier, FRU record type, Number of FRU fields, Encoding type |
| 47 | * of FRU fields |
| 48 | */ |
| 49 | static constexpr size_t recHeaderSize = |
| 50 | sizeof(struct pldm_fru_record_data_format) - |
| 51 | sizeof(struct pldm_fru_record_tlv); |
| 52 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 53 | /** @brief Constructor for FruImpl, the configPath is consumed to build the |
| 54 | * FruParser object. |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 55 | * |
| 56 | * @param[in] configPath - path to the directory containing config files |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 57 | * for PLDM FRU |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 58 | * @param[in] fruMasterJsonPath - path to the file containing the FRU D-Bus |
| 59 | * Lookup Map |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 60 | * @param[in] pdrRepo - opaque pointer to PDR repository |
| 61 | * @param[in] entityTree - opaque pointer to the entity association tree |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 62 | * @param[in] bmcEntityTree - opaque pointer to bmc's entity association |
| 63 | * tree |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 64 | * @param[in] oemFruHandler - OEM fru handler |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 65 | */ |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 66 | FruImpl(const std::string& configPath, |
| 67 | const std::filesystem::path& fruMasterJsonPath, pldm_pdr* pdrRepo, |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 68 | pldm_entity_association_tree* entityTree, |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 69 | pldm_entity_association_tree* bmcEntityTree) : |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 70 | parser(configPath, fruMasterJsonPath), |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 71 | pdrRepo(pdrRepo), entityTree(entityTree), bmcEntityTree(bmcEntityTree) |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 72 | {} |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 73 | |
Pavithra Barithaya | 9e6631e | 2024-01-22 00:46:32 -0600 | [diff] [blame] | 74 | /** @brief Total length of the FRU table in bytes, this includes the pad |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 75 | * bytes and the checksum. |
| 76 | * |
| 77 | * @return size of the FRU table |
| 78 | */ |
| 79 | uint32_t size() const |
| 80 | { |
Pavithra Barithaya | 9e6631e | 2024-01-22 00:46:32 -0600 | [diff] [blame] | 81 | return table.size(); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 82 | } |
| 83 | |
| 84 | /** @brief The checksum of the contents of the FRU table |
| 85 | * |
| 86 | * @return checksum |
| 87 | */ |
| 88 | uint32_t checkSum() const |
| 89 | { |
| 90 | return checksum; |
| 91 | } |
| 92 | |
| 93 | /** @brief Number of record set identifiers in the FRU tables |
| 94 | * |
| 95 | * @return number of record set identifiers |
| 96 | */ |
| 97 | uint16_t numRSI() const |
| 98 | { |
| 99 | return rsi; |
| 100 | } |
| 101 | |
| 102 | /** @brief The number of FRU records in the table |
| 103 | * |
| 104 | * @return number of FRU records |
| 105 | */ |
| 106 | uint16_t numRecords() const |
| 107 | { |
| 108 | return numRecs; |
| 109 | } |
| 110 | |
| 111 | /** @brief Get the FRU table |
| 112 | * |
| 113 | * @param[out] - Populate response with the FRU table |
| 114 | */ |
| 115 | void getFRUTable(Response& response); |
| 116 | |
Pavithra Barithaya | 9e6631e | 2024-01-22 00:46:32 -0600 | [diff] [blame] | 117 | /** @brief Get the Fru Table MetaData |
| 118 | * |
| 119 | */ |
| 120 | void getFRURecordTableMetadata(); |
| 121 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 122 | /** @brief Get FRU Record Table By Option |
| 123 | * @param[out] response - Populate response with the FRU table got by |
| 124 | * options |
| 125 | * @param[in] fruTableHandle - The fru table handle |
| 126 | * @param[in] recordSetIdentifer - The record set identifier |
| 127 | * @param[in] recordType - The record type |
| 128 | * @param[in] fieldType - The field type |
| 129 | */ |
| 130 | int getFRURecordByOption(Response& response, uint16_t fruTableHandle, |
| 131 | uint16_t recordSetIdentifer, uint8_t recordType, |
| 132 | uint8_t fieldType); |
| 133 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 134 | /** @brief FRU table is built by processing the D-Bus inventory namespace |
| 135 | * based on the config files for FRU. The table is populated based |
| 136 | * on the isBuilt flag. |
| 137 | */ |
| 138 | void buildFRUTable(); |
| 139 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 140 | /** @brief Get std::map associated with the entity |
| 141 | * key: object path |
| 142 | * value: pldm_entity |
| 143 | * |
| 144 | * @return std::map<ObjectPath, pldm_entity> |
| 145 | */ |
| 146 | inline const pldm::responder::dbus::AssociatedEntityMap& |
| 147 | getAssociateEntityMap() const |
| 148 | { |
| 149 | return associatedEntityMap; |
| 150 | } |
| 151 | |
George Liu | 5bfb0dc | 2021-05-01 14:28:41 +0800 | [diff] [blame] | 152 | /** @brief Get pldm entity by the object path |
| 153 | * |
| 154 | * @param[in] intfMaps - D-Bus interfaces and the associated property |
| 155 | * values for the FRU |
| 156 | * |
| 157 | * @return pldm_entity |
| 158 | */ |
| 159 | std::optional<pldm_entity> |
| 160 | getEntityByObjectPath(const dbus::InterfaceMap& intfMaps); |
| 161 | |
| 162 | /** @brief Update pldm entity to association tree |
| 163 | * |
| 164 | * @param[in] objects - std::map The object value tree |
| 165 | * @param[in] path - Object path |
| 166 | * |
| 167 | * Ex: Input path = |
| 168 | * "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0" |
| 169 | * |
| 170 | * Get the parent class in turn and store it in a temporary vector |
| 171 | * |
| 172 | * Output tmpObjPaths = { |
| 173 | * "/xyz/openbmc_project/inventory/system", |
| 174 | * "/xyz/openbmc_project/inventory/system/chassis/", |
| 175 | * "/xyz/openbmc_project/inventory/system/chassis/motherboard", |
| 176 | * "/xyz/openbmc_project/inventory/system/chassis/motherboard/powersupply0"} |
| 177 | * |
| 178 | */ |
| 179 | void updateAssociationTree(const dbus::ObjectValueTree& objects, |
| 180 | const std::string& path); |
| 181 | |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 182 | /* @brief Method to populate the firmware version ID |
| 183 | * |
| 184 | * @return firmware version ID |
| 185 | */ |
| 186 | std::string populatefwVersion(); |
| 187 | |
Pavithra Barithaya | 9e6631e | 2024-01-22 00:46:32 -0600 | [diff] [blame] | 188 | /* @brief Method to resize the table |
| 189 | * |
| 190 | * @return resized table |
| 191 | */ |
| 192 | std::vector<uint8_t> tableResize(); |
| 193 | |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 194 | /* @brief set FRU Record Table |
| 195 | * |
| 196 | * @param[in] fruData - the data of the fru |
| 197 | * |
| 198 | * @return PLDM completion code |
| 199 | */ |
| 200 | int setFRUTable(const std::vector<uint8_t>& fruData); |
| 201 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 202 | /* @brief Method to set the oem platform handler in fru handler class |
| 203 | * |
| 204 | * @param[in] handler - oem fru handler |
| 205 | */ |
| 206 | inline void setOemFruHandler(pldm::responder::oem_fru::Handler* handler) |
| 207 | { |
| 208 | oemFruHandler = handler; |
| 209 | } |
| 210 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 211 | private: |
| 212 | uint16_t nextRSI() |
| 213 | { |
| 214 | return ++rsi; |
| 215 | } |
| 216 | |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 217 | uint32_t nextRecordHandle() |
| 218 | { |
| 219 | return ++rh; |
| 220 | } |
| 221 | |
| 222 | uint32_t rh = 0; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 223 | uint16_t rsi = 0; |
| 224 | uint16_t numRecs = 0; |
| 225 | uint8_t padBytes = 0; |
| 226 | std::vector<uint8_t> table; |
| 227 | uint32_t checksum = 0; |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 228 | bool isBuilt = false; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 229 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 230 | fru_parser::FruParser parser; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 231 | pldm_pdr* pdrRepo; |
| 232 | pldm_entity_association_tree* entityTree; |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 233 | pldm_entity_association_tree* bmcEntityTree; |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 234 | pldm::responder::oem_fru::Handler* oemFruHandler = nullptr; |
Riya Dixit | 754041d | 2024-02-20 06:15:49 -0600 | [diff] [blame] | 235 | dbus::ObjectValueTree objects; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 236 | |
| 237 | std::map<dbus::ObjectPath, pldm_entity_node*> objToEntityNode{}; |
| 238 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 239 | /** @brief populateRecord builds the FRU records for an instance of FRU and |
| 240 | * updates the FRU table with the FRU records. |
| 241 | * |
| 242 | * @param[in] interfaces - D-Bus interfaces and the associated property |
| 243 | * values for the FRU |
| 244 | * @param[in] recordInfos - FRU record info to build the FRU records |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 245 | * @param[in/out] entity - PLDM entity corresponding to FRU instance |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 246 | */ |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 247 | void populateRecords(const dbus::InterfaceMap& interfaces, |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 248 | const fru_parser::FruRecordInfos& recordInfos, |
| 249 | const pldm_entity& entity); |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 250 | |
| 251 | /** @brief Associate sensor/effecter to FRU entity |
| 252 | */ |
| 253 | dbus::AssociatedEntityMap associatedEntityMap; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 254 | }; |
| 255 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 256 | namespace fru |
| 257 | { |
| 258 | |
| 259 | class Handler : public CmdHandler |
| 260 | { |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 261 | public: |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 262 | Handler(const std::string& configPath, |
| 263 | const std::filesystem::path& fruMasterJsonPath, pldm_pdr* pdrRepo, |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 264 | pldm_entity_association_tree* entityTree, |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 265 | pldm_entity_association_tree* bmcEntityTree) : |
| 266 | impl(configPath, fruMasterJsonPath, pdrRepo, entityTree, bmcEntityTree) |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 267 | { |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 268 | handlers.emplace( |
| 269 | PLDM_GET_FRU_RECORD_TABLE_METADATA, |
| 270 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 271 | return this->getFRURecordTableMetadata(request, payloadLength); |
| 272 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 273 | handlers.emplace( |
| 274 | PLDM_GET_FRU_RECORD_TABLE, |
| 275 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 276 | return this->getFRURecordTable(request, payloadLength); |
| 277 | }); |
Delphine CC Chiu | d2e4899 | 2023-12-05 16:29:51 +0800 | [diff] [blame] | 278 | handlers.emplace( |
| 279 | PLDM_GET_FRU_RECORD_BY_OPTION, |
| 280 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 281 | return this->getFRURecordByOption(request, payloadLength); |
| 282 | }); |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 283 | handlers.emplace( |
| 284 | PLDM_SET_FRU_RECORD_TABLE, |
| 285 | [this](pldm_tid_t, const pldm_msg* request, size_t payloadLength) { |
| 286 | return this->setFRURecordTable(request, payloadLength); |
| 287 | }); |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 288 | } |
| 289 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 290 | /** @brief Handler for Get FRURecordTableMetadata |
| 291 | * |
| 292 | * @param[in] request - Request message payload |
| 293 | * @param[in] payloadLength - Request payload length |
| 294 | * |
| 295 | * @return PLDM response message |
| 296 | */ |
| 297 | Response getFRURecordTableMetadata(const pldm_msg* request, |
| 298 | size_t payloadLength); |
| 299 | |
| 300 | /** @brief Handler for GetFRURecordTable |
| 301 | * |
| 302 | * @param[in] request - Request message payload |
| 303 | * @param[in] payloadLength - Request payload length |
| 304 | * |
| 305 | * @return PLDM response message |
| 306 | */ |
| 307 | Response getFRURecordTable(const pldm_msg* request, size_t payloadLength); |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 308 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 309 | /** @brief Build FRU table is bnot already built |
| 310 | * |
| 311 | */ |
| 312 | void buildFRUTable() |
| 313 | { |
| 314 | impl.buildFRUTable(); |
| 315 | } |
| 316 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 317 | /** @brief Get std::map associated with the entity |
| 318 | * key: object path |
| 319 | * value: pldm_entity |
| 320 | * |
| 321 | * @return std::map<ObjectPath, pldm_entity> |
| 322 | */ |
| 323 | const pldm::responder::dbus::AssociatedEntityMap& |
| 324 | getAssociateEntityMap() const |
| 325 | { |
| 326 | return impl.getAssociateEntityMap(); |
| 327 | } |
| 328 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 329 | /** @brief Handler for GetFRURecordByOption |
| 330 | * |
| 331 | * @param[in] request - Request message payload |
| 332 | * @param[in] payloadLength - Request payload length |
| 333 | * |
| 334 | * @return PLDM response message |
| 335 | */ |
| 336 | Response getFRURecordByOption(const pldm_msg* request, |
| 337 | size_t payloadLength); |
| 338 | |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 339 | /** @brief Handler for SetFRURecordTable |
| 340 | * |
| 341 | * @param[in] request - Request message |
| 342 | * @param[in] payloadLength - Request payload length |
| 343 | * |
| 344 | * @return PLDM response message |
| 345 | */ |
| 346 | Response setFRURecordTable(const pldm_msg* request, size_t payloadLength); |
| 347 | |
George Liu | a881c17 | 2021-06-21 18:28:11 +0800 | [diff] [blame] | 348 | /* @brief Method to set the oem platform handler in fru handler class |
| 349 | * |
| 350 | * @param[in] handler - oem fru handler |
| 351 | */ |
| 352 | void setOemFruHandler(pldm::responder::oem_fru::Handler* handler) |
| 353 | { |
| 354 | impl.setOemFruHandler(handler); |
| 355 | } |
| 356 | |
Pavithra Barithaya | a410c65 | 2021-07-22 01:32:47 -0500 | [diff] [blame] | 357 | using Table = std::vector<uint8_t>; |
| 358 | |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 359 | private: |
| 360 | FruImpl impl; |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 361 | }; |
| 362 | |
| 363 | } // namespace fru |
| 364 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 365 | } // namespace responder |
| 366 | |
| 367 | } // namespace pldm |