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