Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 1 | #include "inventory_manager.hpp" |
| 2 | |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 3 | #include "common/utils.hpp" |
| 4 | #include "xyz/openbmc_project/Software/Version/server.hpp" |
| 5 | |
George Liu | c453e16 | 2022-12-21 17:16:23 +0800 | [diff] [blame] | 6 | #include <libpldm/firmware_update.h> |
| 7 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 8 | #include <phosphor-logging/lg2.hpp> |
| 9 | |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 10 | #include <functional> |
| 11 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 12 | PHOSPHOR_LOG2_USING; |
| 13 | |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 14 | namespace pldm |
| 15 | { |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 16 | namespace fw_update |
| 17 | { |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 18 | void InventoryManager::discoverFDs(const std::vector<mctp_eid_t>& eids) |
| 19 | { |
| 20 | for (const auto& eid : eids) |
| 21 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 22 | auto instanceId = instanceIdDb.next(eid); |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame^] | 23 | Request requestMsg( |
| 24 | sizeof(pldm_msg_hdr) + PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 25 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 26 | auto rc = encode_query_device_identifiers_req( |
| 27 | instanceId, PLDM_QUERY_DEVICE_IDENTIFIERS_REQ_BYTES, request); |
| 28 | if (rc) |
| 29 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 30 | instanceIdDb.free(eid, instanceId); |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 31 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 32 | "Failed to encode query device identifiers req for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 33 | "EID", eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 34 | continue; |
| 35 | } |
| 36 | |
| 37 | rc = handler.registerRequest( |
| 38 | eid, instanceId, PLDM_FWUP, PLDM_QUERY_DEVICE_IDENTIFIERS, |
| 39 | std::move(requestMsg), |
Andrew Jeffery | c14fb4b | 2024-07-25 22:13:09 +0930 | [diff] [blame] | 40 | std::bind_front(&InventoryManager::queryDeviceIdentifiers, this)); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 41 | if (rc) |
| 42 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 43 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 44 | "Failed to send query device identifiers request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 45 | "EID", eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 46 | } |
| 47 | } |
| 48 | } |
| 49 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame^] | 50 | void InventoryManager::queryDeviceIdentifiers( |
| 51 | mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen) |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 52 | { |
| 53 | if (response == nullptr || !respMsgLen) |
| 54 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 55 | error( |
| 56 | "No response received for query device identifiers for endpoint ID '{EID}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 57 | "EID", eid); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 58 | return; |
| 59 | } |
| 60 | |
| 61 | uint8_t completionCode = PLDM_SUCCESS; |
| 62 | uint32_t deviceIdentifiersLen = 0; |
| 63 | uint8_t descriptorCount = 0; |
| 64 | uint8_t* descriptorPtr = nullptr; |
| 65 | |
| 66 | auto rc = decode_query_device_identifiers_resp( |
| 67 | response, respMsgLen, &completionCode, &deviceIdentifiersLen, |
| 68 | &descriptorCount, &descriptorPtr); |
| 69 | if (rc) |
| 70 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 71 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 72 | "Failed to decode query device identifiers response for endpoint ID '{EID}' and descriptor count '{DESCRIPTOR_COUNT}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 73 | "EID", eid, "DESCRIPTOR_COUNT", descriptorCount, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 74 | return; |
| 75 | } |
| 76 | |
| 77 | if (completionCode) |
| 78 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 79 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 80 | "Failed to query device identifiers response for endpoint ID '{EID}', completion code '{CC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 81 | "EID", eid, "CC", completionCode); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 82 | return; |
| 83 | } |
| 84 | |
| 85 | Descriptors descriptors{}; |
| 86 | while (descriptorCount-- && (deviceIdentifiersLen > 0)) |
| 87 | { |
| 88 | uint16_t descriptorType = 0; |
| 89 | variable_field descriptorData{}; |
| 90 | |
| 91 | rc = decode_descriptor_type_length_value( |
| 92 | descriptorPtr, deviceIdentifiersLen, &descriptorType, |
| 93 | &descriptorData); |
| 94 | if (rc) |
| 95 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 96 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 97 | "Failed to decode descriptor type {TYPE}, length {LENGTH} and value for endpoint ID '{EID}', response code '{RC}'", |
| 98 | "TYPE", descriptorType, "LENGTH", deviceIdentifiersLen, "EID", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 99 | eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 100 | return; |
| 101 | } |
| 102 | |
| 103 | if (descriptorType != PLDM_FWUP_VENDOR_DEFINED) |
| 104 | { |
| 105 | std::vector<uint8_t> descData( |
| 106 | descriptorData.ptr, descriptorData.ptr + descriptorData.length); |
| 107 | descriptors.emplace(descriptorType, std::move(descData)); |
| 108 | } |
| 109 | else |
| 110 | { |
| 111 | uint8_t descriptorTitleStrType = 0; |
| 112 | variable_field descriptorTitleStr{}; |
| 113 | variable_field vendorDefinedDescriptorData{}; |
| 114 | |
| 115 | rc = decode_vendor_defined_descriptor_value( |
| 116 | descriptorData.ptr, descriptorData.length, |
| 117 | &descriptorTitleStrType, &descriptorTitleStr, |
| 118 | &vendorDefinedDescriptorData); |
| 119 | if (rc) |
| 120 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 121 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 122 | "Failed to decode vendor-defined descriptor value for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 123 | "EID", eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 124 | return; |
| 125 | } |
| 126 | |
| 127 | auto vendorDefinedDescriptorTitleStr = |
| 128 | utils::toString(descriptorTitleStr); |
| 129 | std::vector<uint8_t> vendorDescData( |
| 130 | vendorDefinedDescriptorData.ptr, |
| 131 | vendorDefinedDescriptorData.ptr + |
| 132 | vendorDefinedDescriptorData.length); |
| 133 | descriptors.emplace(descriptorType, |
| 134 | std::make_tuple(vendorDefinedDescriptorTitleStr, |
| 135 | vendorDescData)); |
| 136 | } |
| 137 | auto nextDescriptorOffset = |
| 138 | sizeof(pldm_descriptor_tlv().descriptor_type) + |
| 139 | sizeof(pldm_descriptor_tlv().descriptor_length) + |
| 140 | descriptorData.length; |
| 141 | descriptorPtr += nextDescriptorOffset; |
| 142 | deviceIdentifiersLen -= nextDescriptorOffset; |
| 143 | } |
| 144 | |
| 145 | descriptorMap.emplace(eid, std::move(descriptors)); |
| 146 | |
| 147 | // Send GetFirmwareParameters request |
| 148 | sendGetFirmwareParametersRequest(eid); |
| 149 | } |
| 150 | |
| 151 | void InventoryManager::sendGetFirmwareParametersRequest(mctp_eid_t eid) |
| 152 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 153 | auto instanceId = instanceIdDb.next(eid); |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame^] | 154 | Request requestMsg( |
| 155 | sizeof(pldm_msg_hdr) + PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 156 | auto request = reinterpret_cast<pldm_msg*>(requestMsg.data()); |
| 157 | auto rc = encode_get_firmware_parameters_req( |
| 158 | instanceId, PLDM_GET_FIRMWARE_PARAMETERS_REQ_BYTES, request); |
| 159 | if (rc) |
| 160 | { |
Andrew Jeffery | a330b2f | 2023-05-04 14:55:37 +0930 | [diff] [blame] | 161 | instanceIdDb.free(eid, instanceId); |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 162 | error( |
| 163 | "Failed to encode get firmware parameters req for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 164 | "EID", eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 165 | return; |
| 166 | } |
| 167 | |
| 168 | rc = handler.registerRequest( |
| 169 | eid, instanceId, PLDM_FWUP, PLDM_GET_FIRMWARE_PARAMETERS, |
| 170 | std::move(requestMsg), |
Andrew Jeffery | c14fb4b | 2024-07-25 22:13:09 +0930 | [diff] [blame] | 171 | std::bind_front(&InventoryManager::getFirmwareParameters, this)); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 172 | if (rc) |
| 173 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 174 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 175 | "Failed to send get firmware parameters request for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 176 | "EID", eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 177 | } |
| 178 | } |
| 179 | |
Patrick Williams | 16c2a0a | 2024-08-16 15:20:59 -0400 | [diff] [blame^] | 180 | void InventoryManager::getFirmwareParameters( |
| 181 | mctp_eid_t eid, const pldm_msg* response, size_t respMsgLen) |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 182 | { |
| 183 | if (response == nullptr || !respMsgLen) |
| 184 | { |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 185 | error( |
| 186 | "No response received for get firmware parameters for endpoint ID '{EID}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 187 | "EID", eid); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 188 | descriptorMap.erase(eid); |
| 189 | return; |
| 190 | } |
| 191 | |
| 192 | pldm_get_firmware_parameters_resp fwParams{}; |
| 193 | variable_field activeCompImageSetVerStr{}; |
| 194 | variable_field pendingCompImageSetVerStr{}; |
| 195 | variable_field compParamTable{}; |
| 196 | |
| 197 | auto rc = decode_get_firmware_parameters_resp( |
| 198 | response, respMsgLen, &fwParams, &activeCompImageSetVerStr, |
| 199 | &pendingCompImageSetVerStr, &compParamTable); |
| 200 | if (rc) |
| 201 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 202 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 203 | "Failed to decode get firmware parameters response for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 204 | "EID", eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 205 | return; |
| 206 | } |
| 207 | |
| 208 | if (fwParams.completion_code) |
| 209 | { |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 210 | auto fw_param_cc = fwParams.completion_code; |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 211 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 212 | "Failed to get firmware parameters response for endpoint ID '{EID}', completion code '{CC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 213 | "EID", eid, "CC", fw_param_cc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 214 | return; |
| 215 | } |
| 216 | |
| 217 | auto compParamPtr = compParamTable.ptr; |
| 218 | auto compParamTableLen = compParamTable.length; |
| 219 | pldm_component_parameter_entry compEntry{}; |
| 220 | variable_field activeCompVerStr{}; |
| 221 | variable_field pendingCompVerStr{}; |
| 222 | |
| 223 | ComponentInfo componentInfo{}; |
| 224 | while (fwParams.comp_count-- && (compParamTableLen > 0)) |
| 225 | { |
| 226 | auto rc = decode_get_firmware_parameters_resp_comp_entry( |
| 227 | compParamPtr, compParamTableLen, &compEntry, &activeCompVerStr, |
| 228 | &pendingCompVerStr); |
| 229 | if (rc) |
| 230 | { |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 231 | error( |
Riya Dixit | 76f2c60 | 2024-03-28 07:34:12 -0500 | [diff] [blame] | 232 | "Failed to decode component parameter table entry for endpoint ID '{EID}', response code '{RC}'", |
Riya Dixit | 1e5c81e | 2024-05-03 07:54:00 -0500 | [diff] [blame] | 233 | "EID", eid, "RC", rc); |
Tom Joseph | 75356c1 | 2021-06-20 03:52:40 -0700 | [diff] [blame] | 234 | return; |
| 235 | } |
| 236 | |
| 237 | auto compClassification = compEntry.comp_classification; |
| 238 | auto compIdentifier = compEntry.comp_identifier; |
| 239 | componentInfo.emplace( |
| 240 | std::make_pair(compClassification, compIdentifier), |
| 241 | compEntry.comp_classification_index); |
| 242 | compParamPtr += sizeof(pldm_component_parameter_entry) + |
| 243 | activeCompVerStr.length + pendingCompVerStr.length; |
| 244 | compParamTableLen -= sizeof(pldm_component_parameter_entry) + |
| 245 | activeCompVerStr.length + pendingCompVerStr.length; |
| 246 | } |
| 247 | componentInfoMap.emplace(eid, std::move(componentInfo)); |
| 248 | } |
| 249 | |
| 250 | } // namespace fw_update |
| 251 | |
Riya Dixit | 49cfb13 | 2023-03-02 04:26:53 -0600 | [diff] [blame] | 252 | } // namespace pldm |