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" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 4 | #include "pldmd/handler.hpp" |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 5 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 6 | #include <libpldm/fru.h> |
| 7 | #include <libpldm/pdr.h> |
| 8 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 9 | #include <sdbusplus/message.hpp> |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 10 | |
| 11 | #include <map> |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 12 | #include <string> |
| 13 | #include <variant> |
| 14 | #include <vector> |
| 15 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 16 | namespace pldm |
| 17 | { |
| 18 | |
| 19 | namespace responder |
| 20 | { |
| 21 | |
| 22 | namespace dbus |
| 23 | { |
| 24 | |
| 25 | using Value = |
| 26 | std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, |
| 27 | uint64_t, double, std::string, std::vector<uint8_t>>; |
| 28 | using PropertyMap = std::map<Property, Value>; |
| 29 | using InterfaceMap = std::map<Interface, PropertyMap>; |
| 30 | using ObjectValueTree = std::map<sdbusplus::message::object_path, InterfaceMap>; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 31 | using ObjectPath = std::string; |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 32 | using AssociatedEntityMap = std::map<ObjectPath, pldm_entity>; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 33 | |
| 34 | } // namespace dbus |
| 35 | |
| 36 | /** @class FruImpl |
| 37 | * |
| 38 | * @brief Builds the PLDM FRU table containing the FRU records |
| 39 | */ |
| 40 | class FruImpl |
| 41 | { |
| 42 | public: |
| 43 | /* @brief Header size for FRU record, it includes the FRU record set |
| 44 | * identifier, FRU record type, Number of FRU fields, Encoding type |
| 45 | * of FRU fields |
| 46 | */ |
| 47 | static constexpr size_t recHeaderSize = |
| 48 | sizeof(struct pldm_fru_record_data_format) - |
| 49 | sizeof(struct pldm_fru_record_tlv); |
| 50 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 51 | /** @brief Constructor for FruImpl, the configPath is consumed to build the |
| 52 | * FruParser object. |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 53 | * |
| 54 | * @param[in] configPath - path to the directory containing config files |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 55 | * for PLDM FRU |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 56 | * @param[in] fruMasterJsonPath - path to the file containing the FRU D-Bus |
| 57 | * Lookup Map |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 58 | * @param[in] pdrRepo - opaque pointer to PDR repository |
| 59 | * @param[in] entityTree - opaque pointer to the entity association tree |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 60 | * @param[in] bmcEntityTree - opaque pointer to bmc's entity association |
| 61 | * tree |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 62 | */ |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 63 | FruImpl(const std::string& configPath, |
| 64 | const std::filesystem::path& fruMasterJsonPath, pldm_pdr* pdrRepo, |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 65 | pldm_entity_association_tree* entityTree, |
| 66 | pldm_entity_association_tree* bmcEntityTree) : |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 67 | parser(configPath, fruMasterJsonPath), |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 68 | pdrRepo(pdrRepo), entityTree(entityTree), bmcEntityTree(bmcEntityTree) |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 69 | {} |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 70 | |
| 71 | /** @brief Total length of the FRU table in bytes, this excludes the pad |
| 72 | * bytes and the checksum. |
| 73 | * |
| 74 | * @return size of the FRU table |
| 75 | */ |
| 76 | uint32_t size() const |
| 77 | { |
| 78 | return table.size() - padBytes; |
| 79 | } |
| 80 | |
| 81 | /** @brief The checksum of the contents of the FRU table |
| 82 | * |
| 83 | * @return checksum |
| 84 | */ |
| 85 | uint32_t checkSum() const |
| 86 | { |
| 87 | return checksum; |
| 88 | } |
| 89 | |
| 90 | /** @brief Number of record set identifiers in the FRU tables |
| 91 | * |
| 92 | * @return number of record set identifiers |
| 93 | */ |
| 94 | uint16_t numRSI() const |
| 95 | { |
| 96 | return rsi; |
| 97 | } |
| 98 | |
| 99 | /** @brief The number of FRU records in the table |
| 100 | * |
| 101 | * @return number of FRU records |
| 102 | */ |
| 103 | uint16_t numRecords() const |
| 104 | { |
| 105 | return numRecs; |
| 106 | } |
| 107 | |
| 108 | /** @brief Get the FRU table |
| 109 | * |
| 110 | * @param[out] - Populate response with the FRU table |
| 111 | */ |
| 112 | void getFRUTable(Response& response); |
| 113 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 114 | /** @brief Get FRU Record Table By Option |
| 115 | * @param[out] response - Populate response with the FRU table got by |
| 116 | * options |
| 117 | * @param[in] fruTableHandle - The fru table handle |
| 118 | * @param[in] recordSetIdentifer - The record set identifier |
| 119 | * @param[in] recordType - The record type |
| 120 | * @param[in] fieldType - The field type |
| 121 | */ |
| 122 | int getFRURecordByOption(Response& response, uint16_t fruTableHandle, |
| 123 | uint16_t recordSetIdentifer, uint8_t recordType, |
| 124 | uint8_t fieldType); |
| 125 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 126 | /** @brief FRU table is built by processing the D-Bus inventory namespace |
| 127 | * based on the config files for FRU. The table is populated based |
| 128 | * on the isBuilt flag. |
| 129 | */ |
| 130 | void buildFRUTable(); |
| 131 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 132 | /** @brief Get std::map associated with the entity |
| 133 | * key: object path |
| 134 | * value: pldm_entity |
| 135 | * |
| 136 | * @return std::map<ObjectPath, pldm_entity> |
| 137 | */ |
| 138 | inline const pldm::responder::dbus::AssociatedEntityMap& |
| 139 | getAssociateEntityMap() const |
| 140 | { |
| 141 | return associatedEntityMap; |
| 142 | } |
| 143 | |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 144 | /* @brief Method to populate the firmware version ID |
| 145 | * |
| 146 | * @return firmware version ID |
| 147 | */ |
| 148 | std::string populatefwVersion(); |
| 149 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 150 | private: |
| 151 | uint16_t nextRSI() |
| 152 | { |
| 153 | return ++rsi; |
| 154 | } |
| 155 | |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 156 | uint32_t nextRecordHandle() |
| 157 | { |
| 158 | return ++rh; |
| 159 | } |
| 160 | |
| 161 | uint32_t rh = 0; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 162 | uint16_t rsi = 0; |
| 163 | uint16_t numRecs = 0; |
| 164 | uint8_t padBytes = 0; |
| 165 | std::vector<uint8_t> table; |
| 166 | uint32_t checksum = 0; |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 167 | bool isBuilt = false; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 168 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 169 | fru_parser::FruParser parser; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 170 | pldm_pdr* pdrRepo; |
| 171 | pldm_entity_association_tree* entityTree; |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 172 | pldm_entity_association_tree* bmcEntityTree; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 173 | |
| 174 | std::map<dbus::ObjectPath, pldm_entity_node*> objToEntityNode{}; |
| 175 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 176 | /** @brief populateRecord builds the FRU records for an instance of FRU and |
| 177 | * updates the FRU table with the FRU records. |
| 178 | * |
| 179 | * @param[in] interfaces - D-Bus interfaces and the associated property |
| 180 | * values for the FRU |
| 181 | * @param[in] recordInfos - FRU record info to build the FRU records |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 182 | * @param[in/out] entity - PLDM entity corresponding to FRU instance |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 183 | */ |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 184 | void populateRecords(const dbus::InterfaceMap& interfaces, |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 185 | const fru_parser::FruRecordInfos& recordInfos, |
| 186 | const pldm_entity& entity); |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 187 | |
| 188 | /** @brief Associate sensor/effecter to FRU entity |
| 189 | */ |
| 190 | dbus::AssociatedEntityMap associatedEntityMap; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 191 | }; |
| 192 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 193 | namespace fru |
| 194 | { |
| 195 | |
| 196 | class Handler : public CmdHandler |
| 197 | { |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 198 | public: |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 199 | Handler(const std::string& configPath, |
| 200 | const std::filesystem::path& fruMasterJsonPath, pldm_pdr* pdrRepo, |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 201 | pldm_entity_association_tree* entityTree, |
| 202 | pldm_entity_association_tree* bmcEntityTree) : |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 203 | impl(configPath, fruMasterJsonPath, pdrRepo, entityTree, bmcEntityTree) |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 204 | { |
| 205 | handlers.emplace(PLDM_GET_FRU_RECORD_TABLE_METADATA, |
| 206 | [this](const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 207 | return this->getFRURecordTableMetadata(request, payloadLength); |
| 208 | }); |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 209 | |
| 210 | handlers.emplace(PLDM_GET_FRU_RECORD_TABLE, |
| 211 | [this](const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 212 | return this->getFRURecordTable(request, payloadLength); |
| 213 | }); |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 214 | handlers.emplace(PLDM_GET_FRU_RECORD_BY_OPTION, |
| 215 | [this](const pldm_msg* request, size_t payloadLength) { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 216 | return this->getFRURecordByOption(request, payloadLength); |
| 217 | }); |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 218 | } |
| 219 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 220 | /** @brief Handler for Get FRURecordTableMetadata |
| 221 | * |
| 222 | * @param[in] request - Request message payload |
| 223 | * @param[in] payloadLength - Request payload length |
| 224 | * |
| 225 | * @return PLDM response message |
| 226 | */ |
| 227 | Response getFRURecordTableMetadata(const pldm_msg* request, |
| 228 | size_t payloadLength); |
| 229 | |
| 230 | /** @brief Handler for GetFRURecordTable |
| 231 | * |
| 232 | * @param[in] request - Request message payload |
| 233 | * @param[in] payloadLength - Request payload length |
| 234 | * |
| 235 | * @return PLDM response message |
| 236 | */ |
| 237 | Response getFRURecordTable(const pldm_msg* request, size_t payloadLength); |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 238 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 239 | /** @brief Build FRU table is bnot already built |
| 240 | * |
| 241 | */ |
| 242 | void buildFRUTable() |
| 243 | { |
| 244 | impl.buildFRUTable(); |
| 245 | } |
| 246 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 247 | /** @brief Get std::map associated with the entity |
| 248 | * key: object path |
| 249 | * value: pldm_entity |
| 250 | * |
| 251 | * @return std::map<ObjectPath, pldm_entity> |
| 252 | */ |
| 253 | const pldm::responder::dbus::AssociatedEntityMap& |
| 254 | getAssociateEntityMap() const |
| 255 | { |
| 256 | return impl.getAssociateEntityMap(); |
| 257 | } |
| 258 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 259 | /** @brief Handler for GetFRURecordByOption |
| 260 | * |
| 261 | * @param[in] request - Request message payload |
| 262 | * @param[in] payloadLength - Request payload length |
| 263 | * |
| 264 | * @return PLDM response message |
| 265 | */ |
| 266 | Response getFRURecordByOption(const pldm_msg* request, |
| 267 | size_t payloadLength); |
| 268 | |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 269 | private: |
| 270 | FruImpl impl; |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 271 | }; |
| 272 | |
| 273 | } // namespace fru |
| 274 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 275 | } // namespace responder |
| 276 | |
| 277 | } // namespace pldm |