Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 1 | #include "fru.hpp" |
| 2 | |
Deepak Kodihalli | d130e1a | 2020-06-17 05:55:32 -0500 | [diff] [blame] | 3 | #include "common/utils.hpp" |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 4 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 5 | #include <libpldm/entity.h> |
| 6 | #include <libpldm/utils.h> |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 7 | #include <systemd/sd-journal.h> |
| 8 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 9 | #include <phosphor-logging/lg2.hpp> |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 10 | #include <sdbusplus/bus.hpp> |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 11 | |
George Liu | 6492f52 | 2020-06-16 10:34:05 +0800 | [diff] [blame] | 12 | #include <iostream> |
| 13 | #include <set> |
George Liu | 077fea2 | 2020-04-08 16:47:14 +0800 | [diff] [blame] | 14 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 15 | PHOSPHOR_LOG2_USING; |
| 16 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 17 | namespace pldm |
| 18 | { |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 19 | namespace responder |
| 20 | { |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 21 | void FruImpl::buildFRUTable() |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 22 | { |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 23 | if (isBuilt) |
| 24 | { |
| 25 | return; |
| 26 | } |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 27 | |
Tom Joseph | f007633 | 2020-02-06 10:18:50 +0530 | [diff] [blame] | 28 | fru_parser::DBusLookupInfo dbusInfo; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 29 | // Read the all the inventory D-Bus objects |
| 30 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 31 | dbus::ObjectValueTree objects; |
| 32 | |
| 33 | try |
| 34 | { |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 35 | dbusInfo = parser.inventoryLookup(); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 36 | auto method = bus.new_method_call( |
| 37 | std::get<0>(dbusInfo).c_str(), std::get<1>(dbusInfo).c_str(), |
| 38 | "org.freedesktop.DBus.ObjectManager", "GetManagedObjects"); |
vkaverap@in.ibm.com | 9138c20 | 2023-05-19 07:50:47 -0500 | [diff] [blame] | 39 | auto reply = bus.call( |
| 40 | method, |
| 41 | std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count()); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 42 | reply.read(objects); |
| 43 | } |
| 44 | catch (const std::exception& e) |
| 45 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 46 | error( |
| 47 | "Look up of inventory objects failed and PLDM FRU table creation failed"); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 48 | return; |
| 49 | } |
| 50 | |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 51 | auto itemIntfsLookup = std::get<2>(dbusInfo); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 52 | |
| 53 | for (const auto& object : objects) |
| 54 | { |
| 55 | const auto& interfaces = object.second; |
Sridevi Ramesh | eefe49b | 2022-06-27 11:51:02 -0500 | [diff] [blame] | 56 | bool isPresent = pldm::utils::checkForFruPresence(object.first.str); |
| 57 | // Do not create fru record if fru is not present. |
| 58 | // Pick up the next available fru. |
| 59 | if (!isPresent) |
| 60 | { |
| 61 | continue; |
| 62 | } |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 63 | for (const auto& interface : interfaces) |
| 64 | { |
| 65 | if (itemIntfsLookup.find(interface.first) != itemIntfsLookup.end()) |
| 66 | { |
| 67 | // An exception will be thrown by getRecordInfo, if the item |
| 68 | // D-Bus interface name specified in FRU_Master.json does |
| 69 | // not have corresponding config jsons |
| 70 | try |
| 71 | { |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 72 | pldm_entity entity{}; |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 73 | entity.entity_type = parser.getEntityType(interface.first); |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 74 | pldm_entity_node* parent = nullptr; |
| 75 | auto parentObj = pldm::utils::findParent(object.first.str); |
| 76 | // To add a FRU to the entity association tree, we need to |
| 77 | // determine if the FRU has a parent (D-Bus object). For eg |
| 78 | // /system/backplane's parent is /system. /system has no |
| 79 | // parent. Some D-Bus pathnames might just be namespaces |
| 80 | // (not D-Bus objects), so we need to iterate upwards until |
| 81 | // a parent is found, or we reach the root ("/"). |
| 82 | // Parents are always added first before children in the |
| 83 | // entity association tree. We're relying on the fact that |
| 84 | // the std::map containing object paths from the |
| 85 | // GetManagedObjects call will have a sorted pathname list. |
| 86 | do |
| 87 | { |
| 88 | auto iter = objToEntityNode.find(parentObj); |
| 89 | if (iter != objToEntityNode.end()) |
| 90 | { |
| 91 | parent = iter->second; |
| 92 | break; |
| 93 | } |
| 94 | parentObj = pldm::utils::findParent(parentObj); |
| 95 | } while (parentObj != "/"); |
| 96 | |
| 97 | auto node = pldm_entity_association_tree_add( |
George Liu | 64a8f0f | 2021-06-12 10:56:11 +0800 | [diff] [blame] | 98 | entityTree, &entity, 0xFFFF, parent, |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 99 | PLDM_ENTITY_ASSOCIAION_PHYSICAL); |
| 100 | objToEntityNode[object.first.str] = node; |
| 101 | |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 102 | auto recordInfos = parser.getRecordInfo(interface.first); |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 103 | populateRecords(interfaces, recordInfos, entity); |
George Liu | c4ea6a9 | 2020-07-14 15:48:44 +0800 | [diff] [blame] | 104 | |
| 105 | associatedEntityMap.emplace(object.first, entity); |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 106 | break; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 107 | } |
| 108 | catch (const std::exception& e) |
| 109 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 110 | info( |
| 111 | "Config JSONs missing for the item interface type, interface = {INTF}", |
| 112 | "INTF", interface.first); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 113 | break; |
| 114 | } |
| 115 | } |
| 116 | } |
| 117 | } |
| 118 | |
Andrew Jeffery | b0ba34d | 2023-07-17 17:47:16 +0930 | [diff] [blame] | 119 | int rc = pldm_entity_association_pdr_add_check(entityTree, pdrRepo, false, |
| 120 | TERMINUS_HANDLE); |
| 121 | if (rc < 0) |
| 122 | { |
| 123 | // pldm_entity_assocation_pdr_add() assert()ed on failure |
| 124 | error("Failed to add PLDM entity association PDR: {LIBPLDM_ERROR}", |
| 125 | "LIBPLDM_ERROR", rc); |
| 126 | throw std::runtime_error("Failed to add PLDM entity association PDR"); |
| 127 | } |
| 128 | |
Sampa Misra | c073a20 | 2021-05-08 10:56:05 -0500 | [diff] [blame] | 129 | // save a copy of bmc's entity association tree |
| 130 | pldm_entity_association_tree_copy_root(entityTree, bmcEntityTree); |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 131 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 132 | if (table.size()) |
| 133 | { |
Sridevi Ramesh | eefe49b | 2022-06-27 11:51:02 -0500 | [diff] [blame] | 134 | padBytes = pldm::utils::getNumPadBytes(table.size()); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 135 | table.resize(table.size() + padBytes, 0); |
| 136 | |
| 137 | // Calculate the checksum |
George Liu | 077fea2 | 2020-04-08 16:47:14 +0800 | [diff] [blame] | 138 | checksum = crc32(table.data(), table.size()); |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 139 | } |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 140 | isBuilt = true; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 141 | } |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 142 | std::string FruImpl::populatefwVersion() |
| 143 | { |
| 144 | static constexpr auto fwFunctionalObjPath = |
| 145 | "/xyz/openbmc_project/software/functional"; |
| 146 | auto& bus = pldm::utils::DBusHandler::getBus(); |
| 147 | std::string currentBmcVersion; |
| 148 | try |
| 149 | { |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 150 | auto method = bus.new_method_call(pldm::utils::mapperService, |
| 151 | fwFunctionalObjPath, |
| 152 | pldm::utils::dbusProperties, "Get"); |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 153 | method.append("xyz.openbmc_project.Association", "endpoints"); |
| 154 | std::variant<std::vector<std::string>> paths; |
vkaverap@in.ibm.com | 9138c20 | 2023-05-19 07:50:47 -0500 | [diff] [blame] | 155 | auto reply = bus.call( |
| 156 | method, |
| 157 | std::chrono::duration_cast<microsec>(sec(DBUS_TIMEOUT)).count()); |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 158 | reply.read(paths); |
| 159 | auto fwRunningVersion = std::get<std::vector<std::string>>(paths)[0]; |
| 160 | constexpr auto versionIntf = "xyz.openbmc_project.Software.Version"; |
| 161 | auto version = pldm::utils::DBusHandler().getDbusPropertyVariant( |
| 162 | fwRunningVersion.c_str(), "Version", versionIntf); |
| 163 | currentBmcVersion = std::get<std::string>(version); |
| 164 | } |
| 165 | catch (const std::exception& e) |
| 166 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 167 | error("failed to make a d-bus call Asociation, ERROR= {ERR_EXCEP}", |
| 168 | "ERR_EXCEP", e.what()); |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 169 | return {}; |
| 170 | } |
| 171 | return currentBmcVersion; |
| 172 | } |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 173 | void FruImpl::populateRecords( |
| 174 | const pldm::responder::dbus::InterfaceMap& interfaces, |
Deepak Kodihalli | 3cd6181 | 2020-03-10 06:38:45 -0500 | [diff] [blame] | 175 | const fru_parser::FruRecordInfos& recordInfos, const pldm_entity& entity) |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 176 | { |
| 177 | // recordSetIdentifier for the FRU will be set when the first record gets |
| 178 | // added for the FRU |
| 179 | uint16_t recordSetIdentifier = 0; |
| 180 | auto numRecsCount = numRecs; |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 181 | static uint32_t bmc_record_handle = 0; |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 182 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 183 | for (const auto& [recType, encType, fieldInfos] : recordInfos) |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 184 | { |
| 185 | std::vector<uint8_t> tlvs; |
| 186 | uint8_t numFRUFields = 0; |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 187 | for (const auto& [intf, prop, propType, fieldTypeNum] : fieldInfos) |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 188 | { |
| 189 | try |
| 190 | { |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 191 | pldm::responder::dbus::Value propValue; |
Manojkiran Eda | 2b7c1bf | 2021-09-09 12:26:00 +0530 | [diff] [blame] | 192 | |
| 193 | // Assuming that 0 container Id is assigned to the System (as |
| 194 | // that should be the top most container as per dbus hierarchy) |
| 195 | if (entity.entity_container_id == 0 && prop == "Version") |
Pavithra Barithaya | 47180ac | 2020-10-28 02:12:05 -0500 | [diff] [blame] | 196 | { |
| 197 | propValue = populatefwVersion(); |
| 198 | } |
| 199 | else |
| 200 | { |
| 201 | propValue = interfaces.at(intf).at(prop); |
| 202 | } |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 203 | if (propType == "bytearray") |
| 204 | { |
| 205 | auto byteArray = std::get<std::vector<uint8_t>>(propValue); |
| 206 | if (!byteArray.size()) |
| 207 | { |
| 208 | continue; |
| 209 | } |
| 210 | |
| 211 | numFRUFields++; |
| 212 | tlvs.emplace_back(fieldTypeNum); |
| 213 | tlvs.emplace_back(byteArray.size()); |
| 214 | std::move(std::begin(byteArray), std::end(byteArray), |
| 215 | std::back_inserter(tlvs)); |
| 216 | } |
| 217 | else if (propType == "string") |
| 218 | { |
| 219 | auto str = std::get<std::string>(propValue); |
| 220 | if (!str.size()) |
| 221 | { |
| 222 | continue; |
| 223 | } |
| 224 | |
| 225 | numFRUFields++; |
| 226 | tlvs.emplace_back(fieldTypeNum); |
| 227 | tlvs.emplace_back(str.size()); |
| 228 | std::move(std::begin(str), std::end(str), |
| 229 | std::back_inserter(tlvs)); |
| 230 | } |
| 231 | } |
| 232 | catch (const std::out_of_range& e) |
| 233 | { |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 234 | continue; |
| 235 | } |
| 236 | } |
| 237 | |
| 238 | if (tlvs.size()) |
| 239 | { |
| 240 | if (numRecs == numRecsCount) |
| 241 | { |
| 242 | recordSetIdentifier = nextRSI(); |
Pavithra Barithaya | 4f2538a | 2021-03-05 07:32:15 -0600 | [diff] [blame] | 243 | bmc_record_handle = nextRecordHandle(); |
Andrew Jeffery | 2e248e8 | 2023-07-03 17:23:24 +0930 | [diff] [blame] | 244 | int rc = pldm_pdr_add_fru_record_set_check( |
Manojkiran Eda | cc5f158 | 2021-09-29 17:03:06 +0530 | [diff] [blame] | 245 | pdrRepo, TERMINUS_HANDLE, recordSetIdentifier, |
| 246 | entity.entity_type, entity.entity_instance_num, |
Andrew Jeffery | 2e248e8 | 2023-07-03 17:23:24 +0930 | [diff] [blame] | 247 | entity.entity_container_id, &bmc_record_handle); |
| 248 | if (rc) |
| 249 | { |
| 250 | // pldm_pdr_add_fru_record_set() assert()ed on failure |
| 251 | throw std::runtime_error( |
| 252 | "Failed to add PDR FRU record set"); |
| 253 | } |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 254 | } |
| 255 | auto curSize = table.size(); |
| 256 | table.resize(curSize + recHeaderSize + tlvs.size()); |
| 257 | encode_fru_record(table.data(), table.size(), &curSize, |
| 258 | recordSetIdentifier, recType, numFRUFields, |
| 259 | encType, tlvs.data(), tlvs.size()); |
| 260 | numRecs++; |
| 261 | } |
| 262 | } |
| 263 | } |
| 264 | |
| 265 | void FruImpl::getFRUTable(Response& response) |
| 266 | { |
| 267 | auto hdrSize = response.size(); |
| 268 | |
| 269 | response.resize(hdrSize + table.size() + sizeof(checksum), 0); |
| 270 | std::copy(table.begin(), table.end(), response.begin() + hdrSize); |
| 271 | |
| 272 | // Copy the checksum to response data |
| 273 | auto iter = response.begin() + hdrSize + table.size(); |
| 274 | std::copy_n(reinterpret_cast<const uint8_t*>(&checksum), sizeof(checksum), |
| 275 | iter); |
| 276 | } |
| 277 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 278 | int FruImpl::getFRURecordByOption(std::vector<uint8_t>& fruData, |
| 279 | uint16_t /* fruTableHandle */, |
| 280 | uint16_t recordSetIdentifer, |
| 281 | uint8_t recordType, uint8_t fieldType) |
| 282 | { |
Manojkiran Eda | 31a7844 | 2021-09-12 15:18:25 +0530 | [diff] [blame] | 283 | using sum = uint32_t; |
| 284 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 285 | // FRU table is built lazily, build if not done. |
| 286 | buildFRUTable(); |
| 287 | |
| 288 | /* 7 is sizeof(checksum,4) + padBytesMax(3) |
| 289 | * We can not know size of the record table got by options in advance, but |
| 290 | * it must be less than the source table. So it's safe to use sizeof the |
| 291 | * source table + 7 as the buffer length |
| 292 | */ |
| 293 | size_t recordTableSize = table.size() - padBytes + 7; |
| 294 | fruData.resize(recordTableSize, 0); |
| 295 | |
Andrew Jeffery | 663783b | 2023-07-03 12:58:14 +0930 | [diff] [blame] | 296 | int rc = get_fru_record_by_option_check( |
| 297 | table.data(), table.size() - padBytes, fruData.data(), &recordTableSize, |
| 298 | recordSetIdentifer, recordType, fieldType); |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 299 | |
Andrew Jeffery | 663783b | 2023-07-03 12:58:14 +0930 | [diff] [blame] | 300 | if (rc != PLDM_SUCCESS || recordTableSize == 0) |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 301 | { |
| 302 | return PLDM_FRU_DATA_STRUCTURE_TABLE_UNAVAILABLE; |
| 303 | } |
| 304 | |
Sridevi Ramesh | eefe49b | 2022-06-27 11:51:02 -0500 | [diff] [blame] | 305 | auto pads = pldm::utils::getNumPadBytes(recordTableSize); |
Manojkiran Eda | 31a7844 | 2021-09-12 15:18:25 +0530 | [diff] [blame] | 306 | crc32(fruData.data(), recordTableSize + pads); |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 307 | |
| 308 | auto iter = fruData.begin() + recordTableSize + pads; |
| 309 | std::copy_n(reinterpret_cast<const uint8_t*>(&checksum), sizeof(checksum), |
| 310 | iter); |
| 311 | fruData.resize(recordTableSize + pads + sizeof(sum)); |
| 312 | |
| 313 | return PLDM_SUCCESS; |
| 314 | } |
| 315 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 316 | namespace fru |
| 317 | { |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 318 | Response Handler::getFRURecordTableMetadata(const pldm_msg* request, |
| 319 | size_t /*payloadLength*/) |
| 320 | { |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 321 | // FRU table is built lazily, build if not done. |
| 322 | buildFRUTable(); |
| 323 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 324 | constexpr uint8_t major = 0x01; |
| 325 | constexpr uint8_t minor = 0x00; |
| 326 | constexpr uint32_t maxSize = 0xFFFFFFFF; |
| 327 | |
| 328 | Response response(sizeof(pldm_msg_hdr) + |
| 329 | PLDM_GET_FRU_RECORD_TABLE_METADATA_RESP_BYTES, |
| 330 | 0); |
| 331 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 332 | |
| 333 | auto rc = encode_get_fru_record_table_metadata_resp( |
| 334 | request->hdr.instance_id, PLDM_SUCCESS, major, minor, maxSize, |
| 335 | impl.size(), impl.numRSI(), impl.numRecords(), impl.checkSum(), |
| 336 | responsePtr); |
| 337 | if (rc != PLDM_SUCCESS) |
| 338 | { |
| 339 | return ccOnlyResponse(request, rc); |
| 340 | } |
| 341 | |
| 342 | return response; |
| 343 | } |
| 344 | |
| 345 | Response Handler::getFRURecordTable(const pldm_msg* request, |
| 346 | size_t payloadLength) |
| 347 | { |
Tom Joseph | 33e9c7e | 2020-06-11 22:09:52 +0530 | [diff] [blame] | 348 | // FRU table is built lazily, build if not done. |
| 349 | buildFRUTable(); |
| 350 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 351 | if (payloadLength != PLDM_GET_FRU_RECORD_TABLE_REQ_BYTES) |
| 352 | { |
| 353 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 354 | } |
| 355 | |
| 356 | Response response( |
| 357 | sizeof(pldm_msg_hdr) + PLDM_GET_FRU_RECORD_TABLE_MIN_RESP_BYTES, 0); |
| 358 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 359 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 360 | auto rc = encode_get_fru_record_table_resp(request->hdr.instance_id, |
| 361 | PLDM_SUCCESS, 0, |
| 362 | PLDM_START_AND_END, responsePtr); |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 363 | if (rc != PLDM_SUCCESS) |
| 364 | { |
| 365 | return ccOnlyResponse(request, rc); |
| 366 | } |
| 367 | |
| 368 | impl.getFRUTable(response); |
| 369 | |
| 370 | return response; |
| 371 | } |
| 372 | |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 373 | Response Handler::getFRURecordByOption(const pldm_msg* request, |
| 374 | size_t payloadLength) |
| 375 | { |
| 376 | if (payloadLength != sizeof(pldm_get_fru_record_by_option_req)) |
| 377 | { |
| 378 | return ccOnlyResponse(request, PLDM_ERROR_INVALID_LENGTH); |
| 379 | } |
| 380 | |
| 381 | uint32_t retDataTransferHandle{}; |
| 382 | uint16_t retFruTableHandle{}; |
| 383 | uint16_t retRecordSetIdentifier{}; |
| 384 | uint8_t retRecordType{}; |
| 385 | uint8_t retFieldType{}; |
| 386 | uint8_t retTransferOpFlag{}; |
| 387 | |
| 388 | auto rc = decode_get_fru_record_by_option_req( |
| 389 | request, payloadLength, &retDataTransferHandle, &retFruTableHandle, |
| 390 | &retRecordSetIdentifier, &retRecordType, &retFieldType, |
| 391 | &retTransferOpFlag); |
| 392 | |
| 393 | if (rc != PLDM_SUCCESS) |
| 394 | { |
| 395 | return ccOnlyResponse(request, rc); |
| 396 | } |
| 397 | |
| 398 | std::vector<uint8_t> fruData; |
| 399 | rc = impl.getFRURecordByOption(fruData, retFruTableHandle, |
| 400 | retRecordSetIdentifier, retRecordType, |
| 401 | retFieldType); |
| 402 | if (rc != PLDM_SUCCESS) |
| 403 | { |
| 404 | return ccOnlyResponse(request, rc); |
| 405 | } |
| 406 | |
Patrick Williams | 6da4f91 | 2023-05-10 07:50:53 -0500 | [diff] [blame] | 407 | auto respPayloadLength = PLDM_GET_FRU_RECORD_BY_OPTION_MIN_RESP_BYTES + |
| 408 | fruData.size(); |
John Wang | 9e82ad1 | 2020-06-12 10:53:32 +0800 | [diff] [blame] | 409 | Response response(sizeof(pldm_msg_hdr) + respPayloadLength, 0); |
| 410 | auto responsePtr = reinterpret_cast<pldm_msg*>(response.data()); |
| 411 | |
| 412 | rc = encode_get_fru_record_by_option_resp( |
| 413 | request->hdr.instance_id, PLDM_SUCCESS, 0, PLDM_START_AND_END, |
| 414 | fruData.data(), fruData.size(), responsePtr, respPayloadLength); |
| 415 | |
| 416 | if (rc != PLDM_SUCCESS) |
| 417 | { |
| 418 | return ccOnlyResponse(request, rc); |
| 419 | } |
| 420 | |
| 421 | return response; |
| 422 | } |
| 423 | |
Deepak Kodihalli | e60c582 | 2019-10-23 03:26:15 -0500 | [diff] [blame] | 424 | } // namespace fru |
| 425 | |
Deepak Kodihalli | 70e8db0 | 2019-10-21 00:59:46 -0500 | [diff] [blame] | 426 | } // namespace responder |
| 427 | |
| 428 | } // namespace pldm |