Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 1 | #pragma once |
| 2 | |
| 3 | #include "config.h" |
| 4 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 5 | #include "libpldm/fru.h" |
| 6 | #include "libpldm/pdr.h" |
| 7 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 8 | #include "fru_parser.hpp" |
Deepak Kodihalli | 1521f6d | 2020-06-16 08:51:02 -0500 | [diff] [blame] | 9 | #include "pldmd/handler.hpp" |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 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 | |
| 27 | using Value = |
| 28 | std::variant<bool, uint8_t, int16_t, uint16_t, int32_t, uint32_t, int64_t, |
| 29 | uint64_t, double, std::string, std::vector<uint8_t>>; |
| 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 |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 64 | */ |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 65 | FruImpl(const std::string& configPath, |
| 66 | const std::filesystem::path& fruMasterJsonPath, pldm_pdr* pdrRepo, |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 67 | pldm_entity_association_tree* entityTree, |
| 68 | pldm_entity_association_tree* bmcEntityTree) : |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 69 | parser(configPath, fruMasterJsonPath), |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 70 | pdrRepo(pdrRepo), entityTree(entityTree), bmcEntityTree(bmcEntityTree) |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 71 | {} |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 72 | |
| 73 | /** @brief Total length of the FRU table in bytes, this excludes the pad |
| 74 | * bytes and the checksum. |
| 75 | * |
| 76 | * @return size of the FRU table |
| 77 | */ |
| 78 | uint32_t size() const |
| 79 | { |
| 80 | return table.size() - padBytes; |
| 81 | } |
| 82 | |
| 83 | /** @brief The checksum of the contents of the FRU table |
| 84 | * |
| 85 | * @return checksum |
| 86 | */ |
| 87 | uint32_t checkSum() const |
| 88 | { |
| 89 | return checksum; |
| 90 | } |
| 91 | |
| 92 | /** @brief Number of record set identifiers in the FRU tables |
| 93 | * |
| 94 | * @return number of record set identifiers |
| 95 | */ |
| 96 | uint16_t numRSI() const |
| 97 | { |
| 98 | return rsi; |
| 99 | } |
| 100 | |
| 101 | /** @brief The number of FRU records in the table |
| 102 | * |
| 103 | * @return number of FRU records |
| 104 | */ |
| 105 | uint16_t numRecords() const |
| 106 | { |
| 107 | return numRecs; |
| 108 | } |
| 109 | |
| 110 | /** @brief Get the FRU table |
| 111 | * |
| 112 | * @param[out] - Populate response with the FRU table |
| 113 | */ |
| 114 | void getFRUTable(Response& response); |
| 115 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 116 | /** @brief Get FRU Record Table By Option |
| 117 | * @param[out] response - Populate response with the FRU table got by |
| 118 | * options |
| 119 | * @param[in] fruTableHandle - The fru table handle |
| 120 | * @param[in] recordSetIdentifer - The record set identifier |
| 121 | * @param[in] recordType - The record type |
| 122 | * @param[in] fieldType - The field type |
| 123 | */ |
| 124 | int getFRURecordByOption(Response& response, uint16_t fruTableHandle, |
| 125 | uint16_t recordSetIdentifer, uint8_t recordType, |
| 126 | uint8_t fieldType); |
| 127 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 128 | /** @brief FRU table is built by processing the D-Bus inventory namespace |
| 129 | * based on the config files for FRU. The table is populated based |
| 130 | * on the isBuilt flag. |
| 131 | */ |
| 132 | void buildFRUTable(); |
| 133 | |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 134 | /** @brief Get std::map associated with the entity |
| 135 | * key: object path |
| 136 | * value: pldm_entity |
| 137 | * |
| 138 | * @return std::map<ObjectPath, pldm_entity> |
| 139 | */ |
| 140 | inline const pldm::responder::dbus::AssociatedEntityMap& |
| 141 | getAssociateEntityMap() const |
| 142 | { |
| 143 | return associatedEntityMap; |
| 144 | } |
| 145 | |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 146 | /* @brief Method to populate the firmware version ID |
| 147 | * |
| 148 | * @return firmware version ID |
| 149 | */ |
| 150 | std::string populatefwVersion(); |
| 151 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 152 | private: |
| 153 | uint16_t nextRSI() |
| 154 | { |
| 155 | return ++rsi; |
| 156 | } |
| 157 | |
| 158 | uint16_t rsi = 0; |
| 159 | uint16_t numRecs = 0; |
| 160 | uint8_t padBytes = 0; |
| 161 | std::vector<uint8_t> table; |
| 162 | uint32_t checksum = 0; |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 163 | bool isBuilt = false; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 164 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 165 | fru_parser::FruParser parser; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 166 | pldm_pdr* pdrRepo; |
| 167 | pldm_entity_association_tree* entityTree; |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 168 | pldm_entity_association_tree* bmcEntityTree; |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 169 | |
| 170 | std::map<dbus::ObjectPath, pldm_entity_node*> objToEntityNode{}; |
| 171 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 172 | /** @brief populateRecord builds the FRU records for an instance of FRU and |
| 173 | * updates the FRU table with the FRU records. |
| 174 | * |
| 175 | * @param[in] interfaces - D-Bus interfaces and the associated property |
| 176 | * values for the FRU |
| 177 | * @param[in] recordInfos - FRU record info to build the FRU records |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 178 | * @param[in/out] entity - PLDM entity corresponding to FRU instance |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 179 | */ |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 180 | void populateRecords(const dbus::InterfaceMap& interfaces, |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 181 | const fru_parser::FruRecordInfos& recordInfos, |
| 182 | const pldm_entity& entity); |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 183 | |
| 184 | /** @brief Associate sensor/effecter to FRU entity |
| 185 | */ |
| 186 | dbus::AssociatedEntityMap associatedEntityMap; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 187 | }; |
| 188 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 189 | namespace fru |
| 190 | { |
| 191 | |
| 192 | class Handler : public CmdHandler |
| 193 | { |
| 194 | |
| 195 | public: |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 196 | Handler(const std::string& configPath, |
| 197 | const std::filesystem::path& fruMasterJsonPath, pldm_pdr* pdrRepo, |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 198 | pldm_entity_association_tree* entityTree, |
| 199 | pldm_entity_association_tree* bmcEntityTree) : |
Manojkiran Eda | 03b01ca | 2021-06-29 08:55:09 +0530 | [diff] [blame] | 200 | impl(configPath, fruMasterJsonPath, pdrRepo, entityTree, bmcEntityTree) |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 201 | { |
| 202 | handlers.emplace(PLDM_GET_FRU_RECORD_TABLE_METADATA, |
| 203 | [this](const pldm_msg* request, size_t payloadLength) { |
| 204 | return this->getFRURecordTableMetadata( |
| 205 | request, payloadLength); |
| 206 | }); |
| 207 | |
| 208 | handlers.emplace(PLDM_GET_FRU_RECORD_TABLE, |
| 209 | [this](const pldm_msg* request, size_t payloadLength) { |
| 210 | return this->getFRURecordTable(request, |
| 211 | payloadLength); |
| 212 | }); |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 213 | handlers.emplace(PLDM_GET_FRU_RECORD_BY_OPTION, |
| 214 | [this](const pldm_msg* request, size_t payloadLength) { |
| 215 | return this->getFRURecordByOption(request, |
| 216 | 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 |